akhauriyash/Code-Regression huggingface dataset:
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > G;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
string Psb[2] = {"Impossible", "Possible"};
string psb[2] = {"impossible", "possible"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    vi a(n);
    vi c(2);
    forn(i, n) cin >> a[i], c[a[i] % 2]++;
    cout << YES[c[1] % 2 == 0];
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 640
let cnt = ref 0
let g = ref []

let print_list l =
  List.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) l;
  print_newline ()

let print_array = Array.iter (fun n -> Printf.printf "%d\n" n)

let insertion_sort a n g =
  let rec insert j v =
    if j < 0 || a.(j) <= v then a.(j + g) <- v
    else (a.(j + g) <- a.(j); incr cnt; insert (j - g) v)
  in
  let rec doit i =
    if i < n then (insert (i - g) a.(i); doit (i + 1))
  in
  doit g

let generate_g n =
  let rec doit i g lst =
    if g > n then lst
    else doit (i + 1) (int_of_float (4.**(float_of_int i) +. 3.*.2.**(float_of_int (i - 1)) +. 1.)) (g :: lst)
  in
  doit 1 1 []

let shell_sort a n =
  cnt := 0;
  g := generate_g n;
  let rec doit = function
    | [] -> ()
    | hd :: tl -> (insertion_sort a n hd; doit tl)
  in
  doit !g

let () =
  let n = read_int () in
  let a = Array.make n 0 in
  let rec doit i =
    if i < n then (a.(i) <- read_int (); doit (i + 1))
  in
  doit 0;
  shell_sort a n;
  Printf.printf "%d\n" (List.length !g);
  print_list !g;
  Printf.printf "%d\n" !cnt;
  print_array a

Measured memory_bytes: 12628
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    map<string,int> s;
    REP(i,n) {
        string tmp;
        cin >> tmp;
        s[tmp]++;
    }
    
    cout << SIZE(s) << "\n";
    

    return 0;
}


Measured memory_bytes: 19176
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 105, M = 8;
const int MOD = 1e9 + 7;
int dp[N][M];
int main() {
    int h, w, k;
    scanf("%d %d %d", &h, &w, &k);
    if(w == 1) return 0*puts("1");
    dp[0][0] = 1;
    for (int i = 1; i <= h; i++) {
        for (int k = 0; k < 1<<(w-1); k++) {
            bool f = true;
            for (int j = 0; j < (w-2); j++) {
                if((k&(1<<j)) && (k&(1<<j+1))) {
                    f = false;
                    break;
                }
            }
            if(f) {
                for (int j = 0; j < w; j++) {
                    if(j >= 1 && (k&(1<<j-1))) {
                        dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
                    }
                    else if(j < w-1 && (k&(1<<j))) {
                        dp[i][j] = (dp[i][j] + dp[i-1][j+1]) % MOD;
                    }
                    else {
                        dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
                    }
                }
            }
        }
    }
    printf("%d\n", dp[h][k-1]);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();

		int t = Math.min(A, B);
		int cnt = 0;
		while (cnt < K) {
			if (A % t == 0 && B % t == 0)
				cnt++;
			t--;
		}

		System.out.println(t + 1);

		sc.close();
	}
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<stdlib.h>
int compare(const void *a,const void *b){
if(*(long*)b-*(long*)a>0)
return 1;
else
return -1;
}
int main(){
long n,i,ans=0,a[111111],b[111111],c[111111];
scanf("%ld",&n);
for(i=0;i<n;i++){
scanf("%ld%ld",&a[i],&b[i]);
c[i]=a[i]+b[i];
ans+=a[i];
}
qsort(c,n,sizeof(long),compare);
for(i=0;i<n;i++){
if(i%2==1)
ans-=c[i];
}
printf("%ld\n",ans);
return 0;
}

Measured memory_bytes: 3324
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var i = Console.ReadLine();
        Console.WriteLine(i.Where(x => x == 'a').Count() == 1 &&i.Where(x => x == 'b').Count() == 1 &&i.Where(x => x == 'c').Count() == 1 ? "Yes" : "No");
    }
}

Measured memory_bytes: 13268
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<math.h>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	string str,str2;
	int l,r,n,cnt=0,m;
	while(cin >> str){
		REP(i,str.size()){
			if(str[i]=='@'){
				str2.append(str[i+1]-'0',str[i+2]);
				i=i+2;
			}
			else
				str2.append(1,str[i]);
		}
		cout << str2 << endl;
		str2.clear();
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vll data(N);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }
    ll ans = 0, num = data[0];
    for (int i = 1; i < N; i++) {
        if (data[i] < num) {
            ans += num - data[i];
        }
        else if (data[i] > num) {
            num = data[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4836
N,M = readline.chomp.split.map(&:to_i)

cities = Array.new(N+1) { Hash.new }
M.times do |i|
  p,y = readline.chomp.split.map(&:to_i)
  cities[p][y] = i
end

ids = Array.new(M)

cities.each_with_index do |cs,pref_id|
  years = cs.keys.sort
  years.each_with_index do |y,x|
    ids[ cs[y] ] = sprintf("%06d%06d", pref_id, x+1)
  end
end

puts ids


Measured memory_bytes: 48488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


void solve(long long r){
    cout << r * r << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


Measured memory_bytes: 256
import math
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b,x = IL()

if x <= a*a*b/2:
  print(math.degrees(math.atan(b/(2*x/(a*b)))))
else:
  print(math.degrees(math.atan((b - x/(a*a))*2/a)))

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

vector<ll> A(100000,0);

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    ll B = 0;
    for (int i = 0; i < N; i++) {
        if(i%2 == 0){
            B += A[i];
        }else{
            B -= A[i]; 
        }
    }
    for (int i = 0; i < N; i++) {
        cout << B << " ";
        B = 2*A[i] - B;
    }
    cout << "\n";
}

Measured memory_bytes: 2048
N, M = map(int, input().split())

scList = []

for i in range(M):
    scList.append(list(map(int, input().split())))

if N == 1:
    ans = "0"
else:
    ans = "1" + "0" * (N - 1)

scList.sort()

# check
for i in range(M):
    if i > 0 and scList[i][0] == scList[i-1][0] and scList[i][1] != scList[i-1][1]:
        print("-1")
        exit(0)
    if scList[i][0] == 1 and scList[i][1] == 0 and N != 1:
        print("-1")
        exit(0)

# 代入
for s,c in scList:
    ans = ans[:s - 1] + str(c) + ans[s:]
    #ans[s - 1:s] = str(c)
    #ans[s - 1:s] = chr(c + ord('0'))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
typedef vector<pairs> p;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll c[3][3];
    for(ll i=0;i<3;++i){
        for(ll j=0;j<3;++j){
            cin>>c[i][j];
        }
    }

    string ans = "No";
    for(ll i=0;i<3;++i){
        while(c[i][0] > 0 or c[i][1] > 0 or c[i][2] > 0){
            c[i][0]--;
            c[i][1]--;
            c[i][2]--;
        }
    }
    ll flag = 0;
    for(ll i=0;i<3;++i){
        if(c[0][i] == c[1][i] and c[0][i] == c[2][i] and c[1][i] == c[2][i]){
            flag++;
        }
    }
    if(flag == 3){
        ans = "Yes";
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import math

n, d = map(int, input().split())

con = [list(map(int, input().split())) for i in range(n)]

cnt = 0
sum = 0

for i in range(n-1):

    for j in range(i + 1, n):

        for k in range(d):
            sum += (con[i][k] - con[j][k]) ** 2

        if ((sum**0.5).is_integer()):
            cnt += 1
        sum = 0

print(cnt)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int n,s[100001],t[100000];
long long ans;
int main(void){
    cin>>n;
    for(int i=0;i<=n;i++)cin>>s[i];
    for(int i=0;i<n;i++)cin>>t[i];
    for(int i=0;i<n;i++){
        ans+=min(t[i],s[i]);
        t[i]=max(t[i]-s[i],0);
        ans+=min(t[i],s[i+1]);
        s[i+1]=max(s[i+1]-t[i],0);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	m := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		m[a] = i + 1
	}

	for i := 0; i < n; i++ {
		fmt.Println(m[i+1])
	}
}

Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
const int AMAX = 100000; 
using namespace std;
#define rep(i, n) for (i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define down(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
using LL = long long;
using ULL = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

int main(void) {
    string s1,s2="Sunny",s3="Cloudy",s4="Rainy" ;
    cin >> s1;
    if(s1==s2){
        cout << s3;
    }else if(s1==s3){
        cout << s4;
    }else if(s1==s4){
        cout << s2;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  string S;
  cin>>S;
  char c;
 long long N,K,ans,a,b,f;
a=0;
  b=0;
  f=0;
  N=S.size();
  vector<long long>H(N);
  c='R';
  for(int i=0;i<N-1;i++){
  if(c=='R'&&S[i+1]=='L'){
     b=i;
    c='L';
    continue;
  }
  else if(c=='L'&&S[i+1]=='R'){
     f=i;
    H[b+1]=(b-a)/2+(b-a)%2+(f-b)%2+(f-b)/2;
    H[b]=f-a-H[b+1]+1;
    a=i+1;
    c='R';
    continue;
  }
  
    else{
      H[i]=0;
    }
  }
           f=N-1;
    H[b+1]=(b-a)/2+(b-a)%2+(f-b)%2+(f-b)/2;
    H[b]=f-a-H[b+1]+1;
 for(int i=0;i<N;i++){
   cout<<H[i];
   if(i!=N-1){
     cout<<" ";
   }
 }
      cout<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cout << #x << "--> " << x << endl;
#define int long long
#define pii pair<int, int>
using namespace std;
const int mxn = 1e5 + 5;
vector<pii>graph[mxn];
int vis[mxn], color[mxn];
void bfs(int src)
{
    vis[src] = true;
    color[src] = 0;
    queue<int>q;
    q.push(src);
    while(!q.empty())
    {
        int top = q.front();
        q.pop();
        for(int i = 0; i < graph[top].size(); i++)
        {
            pii node = graph[top][i];
            if(vis[node.first] == false)
            {
                vis[node.first] = true;
                color[node.first] = (node.second % 2) ? (1 ^ color[top]) : color[top];
                q.push(node.first);
            }
        }
    }
}
main()
{
    fastio;
    int n; cin >> n;
    for(int i = 0; i < n-1; i++)
    {
        int u, v, w; cin >> u >> v >> w;
        graph[u].emplace_back(v, w);
        graph[v].emplace_back(u, w);
    }
    memset(color, -1, sizeof color);
    bfs(1);
    for(int i = 1; i <= n; i++) cout << color[i] << endl;
}


Measured memory_bytes: 12552
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	int a = Integer.parseInt(reader.readLine());
	int res = a+a*a+a*a*a;
	System.out.println(res);
	}
}


Measured memory_bytes: 32484
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(){
	double a[1010];
	double b[1010];
	int n;
	double m=0;
	double ans=0;
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&a[i]);
	}
	for(i=0;i<n;i++){
		scanf("%lf",&b[i]);
	}
	for(i=1;i<4;i++){
		m=0;
		for(j=0;j<n;j++){
			m+=pow(abs(a[j]-b[j]),i);
		}
		printf("%lf\n",pow(m,1.0/(double)i));
	}
	m=0;
	for(i=0;i<n;i++){
		m=fmax(m,abs(a[i]-b[i]));
	}
	printf("%lf\n",m);
	return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int n, m;
	cin >> n >> m;

	vvi a(n);
	rep(i, 0, m){
		int k;
		cin >> k;
		rep(j, 0, k){
			int s;
			cin >> s;
			a[s-1].pb(i);
		}
	}

	vi p(m);
	rep(i, 0, m){
		cin >> p[i];
	}

	int ans = 0;
	rep(i, 0, 1<<n){
		vi on(m);
		rep(j, 0, n) if(i & 1<<j){
			for(int x : a[j]) on[x]++;
		}
		bool flag = true;
		rep(i, 0, m){
			if(on[i]%2 != p[i]) flag = false;
		}
		if(flag) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;
ll dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dy[9] = {-1,  0,  1,-1, 0, 1,-1, 0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int mp[13];
    REP(i, 13){
        switch(i){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                mp[i] = 1;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                mp[i] = 2;
                break;
            case 2:
                mp[i] = 3;
        }
    }
    int x, y;
    cin >> x >> y;
    if(mp[x] == mp[y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
 
using namespace std;
int main(){
    int n,T; std::cin >> n>>T;
    int c;
    int ans=1001;
    rep(i,n){
        int t;std::cin >> c>>t;
        if(t<=T)ans=min(ans,c);
    }
    if(ans==1001)std::cout << "TLE" << std::endl;
    else std::cout << ans << std::endl;
    /*std::vector<pair> ct;
    rep(i,n){
        int c,t;std::cin >> c>>t;
        if(t<=T){
            ct.push_back(make_pair(c, t));
        }
    }
    */
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll
const int mod = 1e9+7;
const int N = 2007;
const int inv2 = (mod+1)/2;

int n;

VI G[N];

int sub[N];
int dp[2][N][N][3][2]; //[korzen][ile skladowych][stopien korzenia][parzystosc liczby krawedzi]
int c[N];

void dfs(int v)
{
	sub[v] = 1;

	dp[c[v]][v][1][0][0] = 1;

	for(auto u:G[v])
	{
		dfs(u);

		for(int degv = 2; degv >= 0; --degv)
		{
			for(int sv = sub[v]; sv >= 1; --sv)
			{
				for(int pv = 0; pv < 2; ++pv)
				{
					for(int degu = 2; degu >= 0; --degu)
					{
						for(int su = sub[u]; su >= 1; --su)
						{
							for(int pu = 0; pu < 2; ++pu)
							{
								if(degv<=1 && degu<=1) //uzywam krawedzi
								{
									int ndeg = degv+1;
									int np = (pv+pu+1)%2;
									int ns = sv+su-1;
									int mult = 1;

									if(degv==0 && degu==0)
										mult *= 2;
									else if(degv==1 && degu==1)
										mult *= inv2;

									dp[c[v]^1][v][ns][ndeg][np] += mult*dp[c[v]][v][sv][degv][pv]%mod*dp[c[u]][u][su][degu][pu]%mod;
									dp[c[v]^1][v][ns][ndeg][np] %= mod;
								}

								//nie uzywam krawedzi

								int ndeg = degv;
								int np = (pv+pu)%2;
								int ns = sv+su;

								dp[c[v]^1][v][ns][ndeg][np] += dp[c[v]][v][sv][degv][pv]*dp[c[u]][u][su][degu][pu]%mod;
								dp[c[v]^1][v][ns][ndeg][np] %= mod;
							}
						}
					}

					dp[c[v]][v][sv][degv][pv] = 0;
				}	
			}
		}

		c[v] ^= 1;
		sub[v] += sub[u];
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

	for(int i = 2; i <= n; ++i)
	{
		int x;
		cin >> x;
		G[x].pb(i);
	}

	dfs(1);

	int fact = 1;
	int ans = 0;

	for(int i = 1; i <= n; ++i)
	{
		fact = fact*i%mod;

		for(int deg = 0; deg < 3; ++deg)
		{
			ans -= fact*dp[c[1]][1][i][deg][1]%mod;
			ans += fact*dp[c[1]][1][i][deg][0]%mod;
			ans %= mod;
		}
	}

	ans += mod;
	ans %= mod;

	cout << ans << endl;
}

Measured memory_bytes: 376320
#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;

string minx(const string &a, const string &b) {
    auto n = a.size();
    auto m = b.size();
    if(m > n) {
        //cout << "b is larger" << endl;
        return "~";
    }
    for(int idx = 0; idx < m-1; ++idx) {
        if(b[m-idx-1] != a[n-idx-1]) {
            //cout << "indice " << idx << " caracter: "
            //     << b[idx] << " " << a[n-m-1] << endl;
            return "~";
        }
    }
    return a.substr(0,n-m);
}

int main() {
    string S;
    vector<string> words = 
    {"dream", "dreamer", "erase", "eraser"};
    stack<string> olis;
    string test = "";
    string original;
    cin >> S;
    original = S;
    while(S.size() > 0) {
        bool flag = false;
        for(auto T: words) {
            if(minx(S,T) != "~") {
                flag = true;
                S = minx(S,T);
                olis.push(T);
                //if(S.size() < 100)
                //    cout << S << endl;
                break;
            }
        }
        if(!flag) {
            break;
        }
    }
    while(!olis.empty()) {
        test += olis.top();
        olis.pop();
    }
    //if(test != original)
    //    cout << "omaiga" << endl;
    if(S.size() > 0)
        cout << "NO" << endl;
    else
        if(test != original)
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200 * 1000 + 20;
bool mark[MAXN];
int n, q, x, y, dp[MAXN];
vector <int> gr[MAXN];

void dfs(int v) {
	mark[v] = 1;
	for (int i : gr[v]) {
		if (mark[i] == 0) {
			dp[i] += dp[v];
			dfs(i);
		}
	}	
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		cin >> x >> y;
		gr[x].push_back(y);
		gr[y].push_back(x); 
	}
	for (int i = 0; i < q; i++) {
		cin >> x >> y;
		dp[x] += y;
	}
	dfs(1);
	for (int i = 1; i <= n; i++)
		cout << dp[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXM = 4005, MAXN = 200005, MOD = 1e9 + 7;
void add(int &a, int b) { a += b - MOD, a += a >> 31 & MOD; }
void sub(int &a, int b) { a -= b, a += a >> 31 & MOD; }
int hav[MAXM][MAXM];
int aa[MAXN], bb[MAXN], f[MAXM], n;
LL fac[MAXN], inv[MAXN];

LL modpow(LL a, int b) {
	LL res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = res * a % MOD;
		a = a * a % MOD;
	}
	return res;
}

void init() {
	int n = 2e5;
	for (int i = fac[0] = 1; i <= n; i++) fac[i] = fac[i - 1] * i % MOD;
	inv[n] = modpow(fac[n], MOD - 2);
	for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % MOD;
}

LL binom(int a, int b) { return fac[a] * inv[b] % MOD * inv[a - b] % MOD; }

int main() {
	scanf("%d", &n);
	const int M = 2000;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", aa + i, bb + i);
		++hav[M + aa[i]][M + bb[i]];
		++hav[M - aa[i]][M - bb[i]];
	}
	init();
	int ans = 0;
	for (int i = 0; i <= 4000; i++) {
		f[0] += hav[i][0];
		for (int j = 1; j <= 4000; j++) {
			add(f[j], f[j - 1]);
			if (hav[i][j]) {
				if (i <= M) f[j] += hav[i][j];
				else ans = (ans + (LL)f[j] * hav[i][j]) % MOD;
			}
		}
	}
	for (int i = 1; i <= n; i++)
		sub(ans, binom(aa[i] + bb[i] + aa[i] + bb[i], aa[i] + aa[i]));
	printf("%lld\n", (LL)ans * (MOD + 1) / 2 % MOD);
	return 0;
}

Measured memory_bytes: 67072
#include<iostream>
#include<cstdio>
using namespace std;
char s[4]={ 'R', 'Y', 'G', 'B' };
int main()
{
	int h,w,d;
	cin>>h>>w>>d;
	int x,y;
	for(int i=1;i<=h;i++,putchar('\n'))
	for(int j=1;j<=w;j++)
	{
		x=i+j+w,y=i-j+w;
		putchar(s[((x/d)&1)*2+((y/d)&1)]);
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n;
	int r=0;
	char s;
	cin >> n;
	vector<int> vec(n+1);
	for(int i=1;i<=n;i++){
		cin >> s;
		if(s=='#'){
			vec[i]=vec[i-1];
		}else{
			vec[i]=vec[i-1]+1;
		}
	}
	r= 0 - 2*(vec[0]);
	for(int i=1;i<=n;i++){
		if(r>i-(2*vec[i])){
			r=i-(2*vec[i]);
		}
	}
	cout << r+vec[n];
	return 0;
}


Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a := iScan()
	b := iScan()
	ans := 1
	for i := 0; ; i++ {
		if ans >= b {
			fmt.Println(i)
			break
		} else {
			ans += a - 1
		}
	}
}


Measured memory_bytes: 1772
n=int(input())
h=list(map(int,input().split()))
a=list(map(int,input().split()))

#####segfunc######
def segfunc(x,y):
    return max(x,y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele =0

#num:n以上の最小の2のべき乗
num =2**(n).bit_length()
seg=[ide_ele]*2*num

dp=[0 for i in range(0,n)]
dp[0]=a[0]
update(h[0],dp[0])

for i in range(1,n):
    dp[i]=a[i]+query(0,h[i])
    if dp[i]>query(h[i],h[i]+1):
        update(h[i],dp[i])

print(max(dp))

Measured memory_bytes: 123644
#include <iostream>
using namespace std;

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
ll d[110][100100];
ll weight[110], value[110];

int main()
{
  int n, w;
  cin >> n >> w;
  for (int i = 1; i <= n; ++i)
  {
    cin >> weight[i] >> value[i];
  }

  for (int i = 1; i <= n; ++i)
  {
    for (int sum_w = 0; sum_w <= w; ++sum_w)
    {
      if (sum_w - weight[i] >= 0)
      {
        chmax(d[i][sum_w], d[i - 1][sum_w - weight[i]] + value[i]);
      }
      chmax(d[i][sum_w], d[i - 1][sum_w]);
    }
  }
  cout << d[n][w] << endl;
  
  return 0;
}

Measured memory_bytes: 79360
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	rep(i, N) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	int ans = 1000000000;
	rep(i, N - K + 1) {
		if (h[i + K - 1] - h[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
		else if (h[i + K - 1] - h[i] < ans) {
			ans = h[i + K - 1] - h[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split(' ')))
Q = int(input())
BC = [list(map(int, list(input().split(' ')))) for i in range(Q)]

count = [0] * (10**5 + 5)
for i in range(N):
    count[A[i]] += 1

s = sum(A)
for i in range(Q):
    s = s - BC[i][0] * count[BC[i][0]] + BC[i][1] * count[BC[i][0]]
    count[BC[i][1]] += count[BC[i][0]]
    count[BC[i][0]] = 0
    print(s)


Measured memory_bytes: 96476
#include<stdio.h>

int main()
{
    long long int a,b,x,y,t,gcd,lcm;

    while(scanf("%lld %lld",&x,&y)!=EOF){

    a = x;
    b = y;

    while(b!=0){
        t = b;
        b = a % b;
        a = t;
    }
    gcd = a;
    lcm = (x*y)/gcd;
    printf("%lld %lld\n",gcd,lcm);
    }


    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll l,r;
cin>>l>>r;
if(r-l>2019){
    cout<<0<<endl;
}else{
ll ans=2018;
    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<=r;j++){
            chmin(ans,(ll)(i*j)%2019);
        }
    }
    cout<<ans<<endl;
}
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793)
#define mod 1000000007

int main() {
	int n;
	cin >> n;
	vector<llint>a(n);
	map<int,int>mp;
	for (int i = 0; i < n; i++)cin >> a[i],mp[a[i]]++;
	int ans = 0;
	for (auto p:mp) {
		int x = p.first;
		int y = p.second;
		if (x < y)ans += y - x;
		else if (x > y)ans += y;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, a;
	cin >> N;
	int Alice = 0;
	int Bob = 0;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> a;
		vec.at(i) = a;
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (int j = 0; j < N; j++) {
		if (j % 2 != 0) {
			Bob += vec.at(j);
		}
		else {
			Alice += vec.at(j);
		}
	}
	cout << Alice - Bob << endl;
}


Measured memory_bytes: 3620
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf

solve :: Int -> Int -> Int -> (Int, Int)
solve a b k = go a b k True
  where
    go s t 0 v = (s, t)
    go s t u True
        | even s    = go (s `div` 2) (t + s `div` 2) (u - 1) False
        | otherwise = go ((s - 1) `div` 2) (t + (s - 1) `div` 2) (u - 1) False
    go s t u False
        | even t    = go (s + t `div` 2) (t `div` 2) (u - 1) True
        | otherwise = go ((s + (t - 1) `div` 2)) ((t - 1) `div` 2) (u - 1) True

main :: IO ()
main = do
    [a, b, k] <- fmap read . words <$> getLine :: IO [Int]
    let (s, t) = solve a b k
    printf "%d %d\n" s t

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

vector <lli> value(109);
vector <lli> weight(109);
vector <vector <lli>> dp (109,vector<lli>(100009,-1));
lli N,W;

lli solve(lli index,lli wt){

    if(index == N)
        return 0;
    
    if(dp[index][wt] != -1){
        return dp[index][wt];
    }

    lli ans = solve(index+1,wt);

    if(wt+weight[index] <= W){
        ans = max(ans, solve(index+1, wt + weight[index]) + value[index]);
    }

    return dp[index][wt] = ans;

}

int main(){
    cin >> N >> W;

    for(int i=0;i<N;i++){
        cin >> weight[i] >> value[i];
    }

    cout << solve(0,0) << endl;
}

Measured memory_bytes: 89348
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const ld PI=abs(acos(-1));
int n,a,li[9];

int main(){
	cin >> n;
	REP(i,0,n) cin >> a,li[(a/400>8?8:a/400)]++;
	
	int c=0;
	REP(i,0,8) if(li[i]) c++;
	
	cout << (c?c:1) << " " << c+li[8] << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))

d = defaultdict(int)
rd = defaultdict(int)
d[0] = 0
rd[0] = 0

ll = (n) // 2
rr = (n) // 2

for i in range(n):
    if i % 2 == 0:
        d[ v[i] ] = d[ v[i] ] + 1
    else:
        rd[ v[i]  ] = rd[ v[i] ] + 1

d = list(reversed(sorted(d.items(), key=lambda x: x[1])))
rd= list(reversed(sorted(rd.items(), key=lambda x: x[1])))

i, j = 0, 0

while d[i][0] == rd[j][0] and i < len(d)-1 and j < len(rd)-1:
    if (ll - d[i][1] + rr - rd[j+1][1] < ll - d[i+1][1] + rr - rd[j][1]):
        j += 1
    else:
        i += 1


print(ll - d[i][1] + rr - rd[j][1])


Measured memory_bytes: 19116
package main

import(
    "fmt"
)



func main() {
    var a string
    fmt.Scan(&a)
    ans := "No"
    switch{
        case a[0]==a[1] && a[1]==a[2]:
            ans = "Yes"
        case a[1]==a[2] && a[2]==a[3]:
            ans = "Yes"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	multimap<int, ll> mp;
	for(int i=0; i<n; i++){
		int a;
		ll b;
		scanf("%d %lld", &a, &b);
		mp.insert(make_pair(a, b));
	}
	ll ans=0;
	for(auto p:mp){
		int a=p.first;
		bool e=1;
		for(int j=0; j<30; j++){
			if(((a>>j)&1)==1 && ((k>>j)&1)==0){
				e=0;
				break;
			}
		}
		if(e) ans+=p.second;
	}
	for(int i=29; i>=0; i--){
		if(((k>>i)&1)==0) continue;
		ll ans1=0;
		for(auto p:mp){
			int a=p.first;
			if(((a>>i)&1)==1) continue;
			bool e=1;
			for(int j=i+1; j<30; j++){
				if(((a>>j)&1)==1 && ((k>>j)&1)==0){
					e=0;
					break;
				}
			}
			if(e) ans1+=p.second;
		}
		if(ans<ans1) ans=ans1;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;int x=1200000000;
int n;string S;vector<int>vec;
int main(){
	while(true){
		vec.clear();vec.push_back(1<<30);
		cin>>n;if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>S;
			if(S=="x")vec.push_back(x);
			else{vec.push_back(stoi(S));}
		}
		if(n%2==0)vec.push_back(-1<<30);
		else{vec.push_back(1<<30);}
		int L=-1010101010,R=1010101010;int OK=0;
		for(int i=1;i<=n;i++){
			if(i%2==1 && vec[i-1]<=vec[i] && vec[i]!=x && vec[i-1]!=x)OK=1;
			if(i%2==0 && vec[i-1]>=vec[i] && vec[i]!=x && vec[i-1]!=x)OK=1;
			if(vec[i-1]==x && vec[i]==x)OK=1;
			if(vec[i]==x){
				if(i%2==1)R=min(R,min(vec[i-1],vec[i+1])-1);
				if(i%2==0)L=max(L,max(vec[i-1],vec[i+1])+1);
			}
		}
		if(OK==1 || L>R)cout<<"none"<<endl;
		if(OK==0 && L==R)cout<<L<<endl;
		if(OK==0 && L<R)cout<<"ambiguous"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3004
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int MAXN = 205;


int n;
ll a[MAXN];
string s;


struct BitwiseGauss {
    int B;
    vector<ll> bb;
    BitwiseGauss(int _B) {
        B = _B;
        bb.resize(B);
    }

    void insert(ll x) {
        for (int i = B - 1; i >= 0; --i) {
            if (((x >> i) & 1)) {
                if (bb[i]) {
                    x ^= bb[i];
                } else {
                    bb[i] = x;
                    break;
                }
            }
        }
    }
    bool can(ll x) {
    	for (int i = B - 1; i >= 0; --i) {
    		if (((x >> i) & 1)) {
                if (bb[i]) {
                    x ^= bb[i];
                }
            }
    	}
    	return x == 0;
    }
    void clear() {
        fill(bb.begin(), bb.end(), 0);
    }
};

const int B = 61;




void solve() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> s;
	BitwiseGauss kek(B);
	bool bad = false;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '1') {
			if (!kek.can(a[i])) {
				bad = true;
			}
		} else {
			kek.insert(a[i]);
		}
	}
	if (bad) {
		cout << 1 << '\n';
	} else {
		cout << 0 << '\n';
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0; 	
}


Measured memory_bytes: 3560
def get_maxlen():
    S = input()
    N = len(S)
    for i in range(N, 0, -1):
        for j in range(N - i + 1):
            if set(S[j:j + i]).issubset({'A', 'T', 'C', 'G'}):
                return i
    return 0


print(get_maxlen())

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  if(a >= 13) cout << b << endk;
  else if(a >= 6) cout << b/2 << endk;
  else cout << 0 << endk;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
    
  //最初の行
  for ( int i = 0; i < W + 2; i++ ){
    if ( i == W + 1 ){
      cout << '#' << endl;
    }
    else {
      cout << '#';
    }
  }
  
  //中身を含む行
  for ( int i = 0; i < H; i++ ){
    cout << '#';
    for ( int j = 0; j < W; j++ ){
      char a_ij;
      cin >> a_ij;
      cout << a_ij;
    }
    cout << '#' << endl;
  }
  
  //最後の行
  for ( int i = 0; i < W + 2; i++ ){
    if ( i == W + 1 ){
      cout << '#' << endl;
    }
    else {
      cout << '#';
    }
  }
}
    

Measured memory_bytes: 256