akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1e9+7
typedef pair<int,int> P;
typedef pair<int,P> PP;

int d[111111];
string s;

int dfs(int l,int r){
  int res=0;
  if(s[l+1]=='['){
    vector<int> v;
    l++;
    while(1){
	 v.pb(dfs(l,d[l]));
	 l=d[l]+1;
	 if(l==r)break;
    }
    sort(all(v));
    for(int i=0;i<v.size()/2+1;i++){
	 res+=v[i];
    }
    return res;
  }
  int t=1;
  for(int i=r-1;i>l;i--){
    res+=t*(int)(s[i]-'0');
    t*=10;
  }  
  return (res+1)/2;
}

signed main(){
  int q;
  cin>>q;
  while(q--){
    fill_n(d,111111,-1);
    cin>>s;
    int n=s.size();
    stack<int> st;
    for(int i=0;i<n;i++){
	 if(s[i]=='[')st.push(i);
	 if(s[i]==']'){
	   d[st.top()]=i;
	   st.pop();
	 }
    }
    cout<<dfs(0,n-1)<<endl;
  }
  return 0;
}



Measured memory_bytes: 4100
using DataStructures

function main()
    H, W = parse.(Int, split(readline()))
    Ch, Cw = parse.(Int, split(readline()))
    Dh, Dw = parse.(Int, split(readline()))
    S = Vector{String}(undef, H) 
    for i in 1:H
        S[i] = readline()
    end

    dx = [0,  0, 1, -1]
    dy = [1, -1, 0,  0]

    mdx = [-2, -1, 0, 1, 2,
            -2, -1, 1, 2,
            -2, 2,
            -2, -1, 1, 2,
            -2, -1, 0, 1, 2]
    mdy = [2, 2, 2, 2, 2,
           1, 1, 1, 1,
           0, 0,
           -1, -1, -1, -1,
           -2, -2, -2, -2, -2]

    dist = fill!(zeros(Int, H, W), typemax(Int))
    dist[Ch, Cw] = 0
    q = Deque{Tuple{Int, Int}}()
    pushfirst!(q, (Ch, Cw))
    while !isempty(q)
        y, x = popfirst!(q)
        d = dist[y, x]

        for i in 1:4
            nx = x + dx[i]
            ny = y + dy[i]
            1 <= nx <= W || continue
            1 <= ny <= H || continue
            S[ny][nx] == '#' && continue
            dist[ny, nx] <= d && continue;
            dist[ny, nx] = d
            pushfirst!(q, (ny, nx))
        end

        for i in 1:length(mdx)
            nx = x + mdx[i]
            ny = y + mdy[i]
            1 <= nx <= W || continue
            1 <= ny <= H || continue
            S[ny][nx] == '#' && continue
            dist[ny, nx] <= d + 1 && continue;
            dist[ny, nx] = d + 1 
            push!(q, (ny, nx))
        end
    end

    ans = ifelse(dist[Dh, Dw]==typemax(Int), -1, dist[Dh, Dw])
    println(ans)
end

main()

Measured memory_bytes: 228872
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	const int D = 6;
	int enc(int a, int b, int c){
		return a * D * D + b * D + c;
	}
	public void Solve(){
		
		A = Math.Min(2, A);
		B = Math.Min(2, B);
		C = Math.Min(2, C);
		

		int[][] dp = new int[N + 1][];
		for(int i=0;i<=N;i++){
			dp[i] = new int[D * D * D];
			for(int j=0;j<D * D * D;j++) dp[i][j] = -1;
		}
		dp[0][enc(A,B,C)] = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<D * D * D;j++){
				if(dp[i][j] == -1) continue;
				int a = j / (D * D);
				int b = (j / D) % D;
				int c = j % D;
				if(S[i] == "AB"){
					if(a + 1 <= 4 && b - 1 >= 0){
						dp[i + 1][enc(a + 1, b - 1, c)] = j;
					}
					if(a - 1 >= 0 && b + 1 <= 4){
						dp[i + 1][enc(a - 1, b + 1, c)] = j;
					}
					
					
				} else if(S[i] == "AC"){
					if(a + 1 <= 4 && c - 1 >= 0){
						dp[i + 1][enc(a + 1, b, c - 1)] = j;
					}
					if(a - 1 >= 0 && c + 1 <= 4){
						dp[i + 1][enc(a - 1, b, c + 1)] = j;
					}
				} else if(S[i] == "BC"){
					if(b + 1 <= 4 && c - 1 >= 0){
						dp[i + 1][enc(a, b + 1, c - 1)] = j;
					}
					if(b - 1 >= 0 && c + 1 <= 4){
						dp[i + 1][enc(a, b - 1, c + 1)] = j;
					}
				}
			}
		}
		
		int last = -1;
		for(int j=0;j<D * D * D;j++){
			if(dp[N][j] != -1){
				last = j;
				break;
			}
		}
		
		if(last == -1){
			Console.WriteLine("No");
			return;
		}
		
		List<char> L = new List<char>();
		for(int i=N;i>=1;i--){
			int prev = dp[i][last];
			if(prev < 0 || prev >= D * D * D){
				Console.WriteLine("No");
				return;
			}
			int pa = prev / (D * D);
			int pb = (prev / D) % D;
			int pc = prev % D;
			int a = last / (D * D);
			int b = (last / D) % D;
			int c = last % D;
			if(pa < a) L.Add('A');
			else if(pb < b) L.Add('B');
			else if(pc < c) L.Add('C');
			last = prev;
		}
		
		L.Reverse();
		var sb = new StringBuilder();
		sb.AppendLine("Yes");
		foreach(var c in L){
			sb.AppendLine(c.ToString());
		}
		Console.Write(sb.ToString());
		
	}
	int N,A,B,C;
	String[] S;
	public Sol(){
		var d = ria();
		N = d[0]; A = d[1]; B = d[2]; C = d[3];
		S = new String[N];
		for(int i=0;i<N;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 124508
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef long long ll;
#define range(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) range(i,0,n)
#define INF 10000000000 //10^10
#define PI 3.141592

int main(){
    int n;
    cin >> n;
    vector<vint> A(n,vint(n,0));
    rep(i,n){
        int u,k;
        cin >> u >> k;
        rep(j,k){
            int v;
            cin >> v;
            A[u-1][v-1]=1;
        }
    }
    rep(i,n){
        rep(j,n){
            cout << A[i][j];
            if(j<n-1) cout << ' ';
        }
        cout << endl;
    }
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back

#define N 1000000

#define int long long
int arr[N];

void eratosthenes(){
    rep(i,N){
        arr[i]=1;
    }
 
    for(int i=2;i<sqrt(N);i++){
        if(arr[i]){
            for(int j=0;i*(j+2)<N;j++){
                arr[i*(j+2)]=0;
            }
        }
    }

    arr[0]=0;
    arr[1]=0;
}

signed main(){

	eratosthenes();

	// for(int i=0;i<100;i++){
	// 	cout<<i<<" "<<arr[i]<<endl;
	// }

	int count;
	int a,d,n;
	while(1){

		cin>>a>>d>>n;

		if(a==0&&d==0&&n==0)break;
		
		count=0;
				
		
		for(int i=a;i<1000000;i+=d){
			// if(count>220)break;

				if(arr[i]==1){
				
					// cout<<arr[i]<<":"<<count<<":"<<i<<endl;
					if(count==n-1){
						cout<<i<<endl;
						break;
					}
				count++;
				

			}
				
		}


		// rep(i,100){
		// 	cout<<i<<" "<<v[i]<<endl;

		// }

		// cout<<v[n-1]<<endl;

		// rep(i,100){
		// 	cout<<v[i]<<endl;
		// }
		// cout<<v[n-1]<<endl;

	}
}

Measured memory_bytes: 10900
DAY_OF_WEEK = ['Sunday', 'Monday', 'Tuesday',
               'Wednesday', 'Thursday', 'Friday', 'Saturday']
def day_of_week(y, m, d):
    # ?????\?????????(?????§???????????¬???)
    # ??\?????\???0,????????\???6
    # Zeller's congruence
    if m == 1 or m == 2:
        m += 12
        y -= 1
    h = (y + y // 4 - y // 100 + y // 400 + (13 * m + 8) // 5 + d) % 7
    return h

while True:
    m,d = map(int, input().split())
    if m==0:
        exit()
    print(DAY_OF_WEEK[day_of_week(2004,m,d)])

Measured memory_bytes: 7660
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int time = 0;
		int[][][] map = new int[5][5][4];

		for (int[][] a : map) {
			a = new int[5][4];
		}

		for (int[][] a : map) {
			for (int[] b : a) {
				b = new int[4];
			}
		}

		while (time < 9) {
			String inputData = sc.nextLine();

			if (time % 2 == 0) {
				for (int i = 0; i < 4; i++) {
					map[time / 2][i][0] = Integer.parseInt(String
							.valueOf(inputData.charAt(i)));
				}

				for (int i = 1; i < 5; i++) {
					map[time / 2][i][2] = Integer.parseInt(String
							.valueOf(inputData.charAt(i - 1)));
				}
			} else {
				for (int i = 0; i < 5; i++) {
					map[time / 2][i][1] = Integer.parseInt(String
							.valueOf(inputData.charAt(i)));
				}

				for (int i = 0; i < 5; i++) {
					map[time / 2 + 1][i][3] = Integer.parseInt(String
							.valueOf(inputData.charAt(i)));
				}
			}

			time++;
		}

		int dir = 0;
		int x = 1, y = 0;

		System.out.print("R");

		while (x != 0 || y != 0) {

			if (dir == 0) {
				if (map[y][x][3] == 1) {
					dir = 3;
					y--;

					System.out.print("U");

					continue;
				} else if (map[y][x][0] == 1) {
					dir = 0;
					x++;

					System.out.print("R");

					continue;
				} else if (map[y][x][1] == 1) {
					dir = 1;
					y++;

					System.out.print("D");

					continue;
				} else {
					dir = 2;
					x--;

					System.out.print("L");

					continue;
				}
			} else if (dir == 1) {
				if (map[y][x][0] == 1) {
					dir = 0;
					x++;

					System.out.print("R");

					continue;
				} else if (map[y][x][1] == 1) {
					dir = 1;
					y++;

					System.out.print("D");

					continue;
				} else if (map[y][x][2] == 1) {
					dir = 2;
					x--;

					System.out.print("L");

					continue;
				} else {
					dir = 3;
					y--;

					System.out.print("U");

					continue;
				}
			} else if (dir == 2) {
				if (map[y][x][1] == 1) {
					dir = 1;
					y++;

					System.out.print("D");

					continue;
				} else if (map[y][x][2] == 1) {
					dir = 2;
					x--;

					System.out.print("L");

					continue;
				} else if (map[y][x][3] == 1) {
					dir = 3;
					y--;

					System.out.print("U");

					continue;
				} else {
					dir = 0;
					x++;

					System.out.print("R");

					continue;
				}
			} else if (dir == 3) {
				if (map[y][x][2] == 1) {
					dir = 2;
					x--;

					System.out.print("L");

					continue;
				} else if (map[y][x][3] == 1) {
					dir = 3;
					y--;

					System.out.print("U");

					continue;
				} else if (map[y][x][0] == 1) {
					dir = 0;
					x++;

					System.out.print("R");

					continue;
				} else {
					dir = 1;
					y++;

					System.out.print("D");

					continue;
				}
			}
		}

		System.out.println("");
	}
}

Measured memory_bytes: 26012
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
int fast_pow(int a, int n) {
	int sum = 1;
	while (n > 0) {
		if (n & 1) sum = 1LL * sum * a % MOD;
		a = 1LL * a * a % MOD;
		n >>= 1;
	}
	return sum;
}
int fact(int n) {
	int res = 1;
	for (int i = 2; i <= n; i++) res = 1LL * res * i % MOD;
	return res;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int N, M, K;
	scanf("%d %d %d", &N, &M, &K);
	int res = 0;
	int comb = 1LL * fact(N * M - 2) * fast_pow(fact(K - 2), MOD - 2) % MOD * fast_pow(fact(N * M - K), MOD - 2) % MOD;
	for (int d = 1; d < N; d++) {
		int ways = 1LL * d * M % MOD * M % MOD * (N - d) % MOD;
		res = (res + ways) % MOD;
	}
	for (int d = 1; d < M; d++) {
		int ways = 1LL * d * N % MOD * N % MOD * (M - d) % MOD;
		res = (res + ways) % MOD;
	}
	res = 1LL * res * comb % MOD;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
e = 0
for i in s:
    if i == 'E':
        e += 1
left = 0
right = e
ans = left + right
for i in range(n):
    if s[i] == 'E':
        right -= 1
    ans = min(ans,left+right)
    if s[i] == 'W':
        left += 1
print(ans)

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

#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-7);
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

ll mod=109 + 7;

const int N=50 + 5;
char arr[N][N];
char temp[N][N];
int n,m;

int sm(int n){
	if(!n)
		return 0;
	return n%10+sm(n/10);
}


int main(){
	scanf("%d%d",&n,&m);
	
	for(int i=0;i<n;++i)
		scanf("%s",arr+i);
		
	for(int i=0;i<m;++i)
		scanf("%s",temp+i);
		
	for(int i=0;i<n-m+1;++i){
		for(int j=0;j<n-m+1;++j){
			bool flage=true;
			
			for(int x=0;x<m;++x){
				for(int y=0;y<m;++y){
					if(temp[x][y] != arr[x+i][y+j])
						flage=false;
				}
			}
			
			if(flage == true){
				puts("Yes");
				return 0;	
			}
			
		}
	}
	
	puts("No");
		
		
	
}
















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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
string s[2005];
int u[2005][2005],d[2005][2005],l[2005][2005],r[2005][2005];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int ans =0;
    for(int i=0;i<n;i++){
        int cnt =0;
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')cnt=0;
            else cnt++;
            l[i][j]=cnt;
        }
        cnt=0;
        for(int j=m-1;j>=0;j--){
            if(s[i][j]=='#')cnt=0;
            else cnt++;
            r[i][j]=cnt;
        }
    }
    for(int i=0;i<m;i++){
        int cnt =0;
        for(int j=0;j<n;j++){
            if(s[j][i]=='#')cnt=0;
            else cnt++;
            d[j][i]=cnt;
        }
        cnt=0;
        for(int j=n-1;j>=0;j--){
            if(s[j][i]=='#')cnt=0;
            else cnt++;
            u[j][i]=cnt;
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')continue;
            int res = u[i][j]+d[i][j]+l[i][j]+r[i][j]-3;
            ans=max(ans,res);
        }
    }
    printf("%d",ans);
    return 0;
}

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

typedef long long ll;
ll p[2] = {1, -1};
const ll INF = 1LL << 60;

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    ll ans = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                vector<vector<ll>> dp(1010, vector<ll>(1010, -INF));
                dp[0][0] = 0;
                for (int n = 0; n < N; n++) {
                    ll X = x[n] * p[i], Y = y[n] * p[j], Z = z[n] * p[k];
                    ll sum = X + Y + Z;
                    for (int m = 0; m <= M; m++) {
                        if (dp[n][m] == -INF) continue;
                        chmax(dp[n + 1][m + 1], dp[n][m] + sum);
                        chmax(dp[n + 1][m], dp[n][m]);
                    }
                }
                chmax(ans, dp[N][M]);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 8372
/// In the name of God
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

#define y1 def1
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)


main(){
    int x, y;
    cin >> x >> y;
    if(abs(x - y) > 1)
        cout << "Alice" << endl;
    else
        cout << "Brown" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
int main(){
   int N,K;
   std::cin >> N >> K;
   int p[N];
   int ptmp;
  for (int i =0;i< N; i++)
  {
    std::cin >> ptmp;
    p[i] = ptmp;
  }
  
  std::sort(p,p+N);
  int sum = 0;
  for (int j = 0; j < K; j++){
      sum += p[j];
  }
  std::cout << sum;
  
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
 ll n, k;
 cin >> n >> k;
 vector<ll> A(n) ;
 rep(i,n) cin >> A[i] ;
 rep(i,n) A[i] -- ;
 vector<ll> B(n) ;
 ll loop =0 ;
 rep2(i,1,n){
  if(i==1){
   B[i] =A[0] ;
  }else {
   B[i]=A[B[i-1]] ;
   } 
 }
 rep2(i,1,n-1){
loop++ ;
if(B[n]==B[n-i])
break ;
 }
  ll ko=(k-n)%loop ;
 if(k<=n)
  cout << B[k]+1 <<endl ;
 else
  cout <<B[n+ko-loop]+1 <<endl ;
     return 0;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

constexpr auto kInvalid = std::numeric_limits<int64_t>::min();

bool dfs(const vector<vector<pair<int, int>>>& links, int src, vector<int64_t>* pos) {
    for (const auto& link : links[src]) {
        auto dst = link.first;
        auto distance = link.second;
        if ((*pos)[dst] != kInvalid) {
            if ((*pos)[dst] != (*pos)[src] + distance) {
                return false;
            }

            continue;
        }

        (*pos)[dst] = (*pos)[src] + distance;
        if (!dfs(links, dst, pos)) {
            return false;
        }
    }

    return true;
}

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

    vector<vector<pair<int, int>>> links(n);

    for (auto i : irange(0, m)) {
        int l, r, d;
        cin >> l >> r >> d;
        links[l - 1].emplace_back(r - 1, d);
        links[r - 1].emplace_back(l - 1, -d);
    }

    vector<int64_t> pos(n, kInvalid);
    for (auto i : irange(0, n)) {
        if (pos[i] != kInvalid) {
            continue;
        }

        pos[i] = 0;
        if (!dfs(links, i, &pos)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 13312
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    string S,T;
    cin>>S>>T;
    bool ok=true;
    ll N=S.length();
    FORI(i,0,N)
    {
        if(S[i]!=T[i])
        {
            ok=false;
        }
    }
    if(ok)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3864
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll x;
  cin>>x;
  ll ans;
  if(x%11==0) {
    ans = x/11*2;
  }
  else if(x%11>6) ans = x/11*2+2;
  else ans = x/11*2+1;
  cout<<ans<<endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;

    // 「1 の個数」「0 の個数」を交互に記録していく
    vector<int> nums;    
    if (S[0] == '0') nums.push_back(0); // 先頭が 0 だったら
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i]) ++j; // S[i] の数値がどこまで続くか
        nums.push_back(j - i);
        i = j;
    }
    if (S.back() == '0') nums.push_back(0); // 最後尾が 0 だったら

    // 累積和
    vector<int> sums((int)nums.size() + 1, 0);
    for (int i = 0; i < nums.size(); ++i) sums[i+1] = sums[i] + nums[i];

    // 偶数番目の添字から始まる、長さ 2K+1 (以下) の区間の総和のうち、最大値を求める
    int res = 0;
    for (int left = 0; left < sums.size(); left += 2) {
        int right = left + K*2+1;
        if (right >= sums.size()) right = (int)sums.size() - 1;
        res = max(res, sums[right] - sums[left]);
    }
    cout << res << endl;
}



Measured memory_bytes: 1272
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split('\n');

    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i] === '0 0') {
            break;
        }
        var input = inputs[i].split(' ')
            .map(Number).sort(function(a,b) {
                return a - b;
            })
            .join(' ');

        console.log(input);
    }

});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 19488
#include <stdio.h>
int main (void)
{
	int n,m;
	scanf("%d %d",&n,&m);
	int a[n][m];
	  // ここの−１でのリセットはOK!//
    for (int i =0; i < n; i ++)	{
      for (int j = 0; j < m; j++)	{
        a[i][j] = -1;
      }
	}
	int k[n];
    for (int i = 0; i <  n; i = i +1)	{
      scanf("%d", &k[i]);
      	for (int j = 0; j < k[i] ; j = j+1)	{
          scanf("%d", &a[i][j]);
        }
    }
	// ここまで受け取り，ここからは出力//
   int ch[m];
   // vecot chを0ベクトルにする//
   for (int i =0; i < m; i++)	{
     ch[i] = 0;
   }
   for (int i = 0; i < m; i++)	{
     for (int j =0; j < n; j ++)	{
       for (int l = 0; l < k[j]; l++)	{
		   if (a[j][l] == i+1)	ch[i] ++;
	   }
     }
   }
   int ans = 0;
   for (int i = 0; i <m; i ++)	{
     if (ch[i] == n)	ans ++;
   }
   printf("%d", ans);
}

Measured memory_bytes: 128
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,M = map(int,input().split())
start = [0 for i in range(N)]
for i in range(N):
    start[i] = [int(i) for i in input().split()]

goal = [[] for i in range(M)]
for i in range(M):
    goal[i] = [int(i) for i in input().split()]

# print(start,goal)
ans = [0 for i in range(N)]
for i in range(N):
    tmp = mod
    for j in range(M):
        if tmp > abs(start[i][0]-goal[j][0])+abs(start[i][1]-goal[j][1]):
            ans[i] = j+1
            tmp = abs(start[i][0]-goal[j][0])+abs(start[i][1]-goal[j][1])
for i in range(N):
    print(ans[i])


Measured memory_bytes: 5524
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

void solve() {
	int h, w, a, b; cin >> h >> w >> a >> b;
    int s[2000][2000];
    rep(i, h) {
        rep(j, w) {
            if((i <= b - 1 && j <= a - 1) || (i > b - 1 && j > a - 1)) {
                s[i][j] = 1;
            } else {
                s[i][j] = 0;
            }
        }
    }

    rep(i, h) {
        rep(j, w) {
            cout << s[i][j];
        }
        cout << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 10880
#------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#------------------------------------------------------
H,W = map(int, input().split())			
# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7
M = list( list(input()) for _ in range(H) )
'''
#=> [['.', '.', '.', '.'],
     ['.', 'S', 'S', '.'],
     ['.', '.', 'S', '.'],
     ['.', '.', '.', '.']]
'''
INF  = float("inf") # 正の無限大
L = [[[INF,-1] for _c in range(W)] for _r in range(H)]
if M[0][0]=='.':
	L[0][0]=[0,0]
else:
	L[0][0]=[1,1]
h=0
w=0
for h in range(1,H):
	l = [ L[h-1][0][0], 0]
	if M[h][0]=='#':
		l[0] += (0 if L[h-1][0][1] else 1)
		l[1] = 1
	L[h][0] = l
for w in range(1,W):
	l = [ L[0][w-1][0], 0]
	if M[0][w]=='#':
		l[0] += (0 if L[0][w-1][1] else 1)
		l[1] = 1
	L[0][w] = l
#p(M)
#p(L)
for h in range(1,H):
	for w in range(1,W):
		l = [ L[h][w-1][0], 0]
		t = [ L[h-1][w][0], 0]
		if M[h][w]=='#':
			l[0] += (0 if L[h][w-1][1] else 1)
			t[0] += (0 if L[h-1][w][1] else 1)
			l[1] = t[1] = 1		
		L[h][w] = (l if l[0]<t[0] else t)
#p(M)
#p(L)
print(L[H-1][W-1][0])

Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> G(n);
    vector<pair<int, int>> vp;
    
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a, b);
    } 
    
    map<pair<int, int>, int> mp;
    vector<int> cs(n);  // cs[i] : 頂点iとiの親を結ぶ辺の色
    vector<int> used(n);  // used[i] : 頂点iを訪れたかどうか
    queue<int> Q;

    Q.emplace(0);
    used[0] = 1;
    int K = 0;

    while(!Q.empty()) {

        int v = Q.front();
        Q.pop();

        if(K < (int)G[v].size()) {
            K = G[v].size();
        }

        int cur = 1;
        for(auto u : G[v]) {
            if(used[u]) {
                continue;
            }
            if(cur == cs[v]) {
                cur++;
            }
            cs[u] = mp[make_pair(u, v)] = mp[make_pair(v, u)] = cur++;
            used[u] = 1;
            Q.emplace(u);
        }
    }

    cout << K << "\n";

    for(auto p : vp) {
        cout << mp[p] << "\n";
    }

    return 0;
}

Measured memory_bytes: 20084
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int main(){
	int a;
	vector<string> s;
	vector<int> c;
	cin>>a;
	long long ans=0;
	for(int i=0;i<a;i++){
		string ss;
		int cc;
		cin>>ss>>cc;
		s.push_back(ss);
		c.push_back(cc);
		ans+=cc;
	}
	string x;
	cin>>x;
	for(int i=0;i<a;i++){
		if(x != s[i]){
			ans-=c[i];
		}
		else{
			ans-=c[i]; 
			break;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
from copy import deepcopy
n = int(input())
s = []
for i in range(n):
    s.append(list(input()))

alp = []
for i in range(ord("a"), ord("z")+1):
    alp.append(chr(i))

ans = ""
for a in alp:
    cnt = 10000
    for i in range(n):
        cnt = min(cnt, s[i].count(a))
    ans += a * cnt
print(ans)

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int main(){
  string s;
  ll k;
  string ans = "1";

  cin >> s >> k;
  
  int i = 0;
  while(ans == "1" && i < k){
    ans = s.substr(i, 1);
    i++;
  }

  cout << ans << endl;
  
}


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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int a, b;
    cin >> a >> b;
    int ans = max(a+b, a-b);
  ans = max(ans, a*b);
    cout <<  ans << endl;
    return 0;
}


Measured memory_bytes: 256
r, c = map(int, input().split())
arr = [0]*c
for i in range(r):
    table = list(map(int,input().split()))
    for j in range(c):
        arr[j] += table[j]
    table.append(sum(table))
    table = [str(s) for s in table]
    print(' '.join(table))
arr.append(sum(arr))
arr = [str(s) for s in arr]
print(' '.join(arr))





Measured memory_bytes: 5616
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    string x, y;
    cin >> x >>y;
    if (x < y) printf("<\n");
    else if (x == y) {
        printf("=\n");
    } else {
        printf(">\n");
    }
    return 0;
}


Measured memory_bytes: 256
;; #!/usr/bin/env sbcl --script

(defun main ()
  (let* ((n (read))
         (k (read))
         (a (make-array n :element-type 'fixnum))
         (dp (make-array n :element-type 'fixnum :initial-element (floor most-positive-fixnum 2))))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (flet ((relax (from to)
             (let* ((from-val (aref dp from))
                    (to-val (aref dp to))
                    (diff (abs (- (aref a to) (aref a from)))))
               (setf (aref dp to) (min to-val (+ from-val diff))))))
      (setf (aref dp 0) 0)
      (dotimes (i n)
        (dotimes (j k)
          (when (< (+ i (1+ j)) n) (relax i (+ i (1+ j)))))))
    (format t "~a~%" (aref dp (- n 1)))))

(main)


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

using namespace std;

typedef vector<int> Vec;
typedef vector<Vec> Mat;
const int INF=1e9+10;

int main()
{
    int n,m;

    while(cin>>n>>m)
    {
        Vec v(m),dp(n+1);

        for(int i=0;i<m;i++)
        {
            cin>>v[i];
        }

        fill(dp.begin(),dp.end(),INF);
        dp[0]=0;

        for(int i=0;i<m;i++)
        {
            for(int j=0;j<=n;j++)
            {
                if(j-v[i]>=0)
                {
                    dp[j]=min(dp[j],dp[j-v[i]]+1);
                }
            }
        }
        cout<<dp[n]<<endl;
    }

    return 0;
}



Measured memory_bytes: 3192
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]
stack = [[0,0]]
S[0][0] = 0

total_dot = 0
for sss in S:
    for s in sss:
        if s == ".":
            total_dot += 1

move = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 1
while stack:
    cur_stack = stack
    stack = []
    for si,sj in cur_stack:
        for mi,mj in move:
            i,j = si+mi,sj+mj
            if 0 > i or i >= h or 0 > j or j >= w:
                continue
            next_mass = S[i][j]
            if next_mass == "#":
                continue
            elif next_mass == ".":
                S[i][j] = cnt
                stack.append([i,j])
    cnt += 1
# [print(s) for s in S]
print(total_dot-S[-1][-1]) if S[-1][-1] != "." else print(-1)

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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    const string yes = "APPROVED";
    const string no = "DENIED";

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    string ans = yes;
    for (auto a:A){
        if (a%2==0){
            if(a%3==0 || a%5==0);
            else ans = no;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,i;
    scanf("%d%d",&a,&b);
    if(a>=b)
    {
        for(i=0;i<a;i++)
        {
            printf("%d",b);
        }
    }
    else
    {
        for(i=0;i<b;i++)
        {
            printf("%d",a); 
        }
    }
    return 0;
}

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


int a[110];
int n;


int main()
{
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		 cin >> a[i];
	}

	for (int i = n - 1; i >= 0;i--)
	{
		cout << a[i];
		if (i != 0) cout << ' ';
	}
	cout << endl;


	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

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

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

class UnionFind{
public:
  vector<int> p;		// 親
  vector<int> rank;	// サイズ・各集合の根のみ有効
  UnionFind(int n){
    p.resize(n, -1);
    rank.resize(n, 1);
  }
  int root(int x){
    if(p[x] == -1)return x;
    else return p[x] = root(p[x]); // 深さを 1 にしている
  }
  void unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y)return;
    if(rank[x] > rank[y]) swap(x, y); // rankの小さいものを下につける
    rank[y] += rank[x];
    p[x] = y;
  }
  //xが属すグループのサイズ
  int size(int x){ return rank[root(x)]; }
  bool same(int x, int y){ return (root(x) == root(y)); }
};

void solve()
{
  ll n, m, a, b;
  cin >> n >> m;
  vector<P> br(m);
  for(int i = 0; i < m; ++i)
  {
    cin >> a >> b;
    a--; b--;
    br[i] = P(a, b);
  }

  reverse(br.begin(), br.end());
  UnionFind uf(n);

  stack<ll> ans;
  ll e_cnt = n * (n - 1) / 2;
  for(const auto& p : br)
  {
    //cout << "(" << p.first << ", " << p.second << ")";

    ans.push(e_cnt);
    if (!uf.same(p.first, p.second))
    {

      //cout << " | " << uf.size(p.first) << ", " << uf.size(p.second);

      e_cnt -= uf.size(p.first) * uf.size(p.second);
      uf.unite(p.first, p.second);
      if (uf.size(p.first) == n) e_cnt = 0;
    }
    //cout << endl;
  }

  while(!ans.empty())
  {
    cout << ans.top() << endl;
    ans.pop();
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  int min_a = *min_element(all(a)), max_a = *max_element(all(a));
  int min_cost = 1 << 29, cost;

  FOR(i,min_a,max_a + 1){
    cost = 0;
    rep(j,n) cost += (a[j] - i) * (a[j] - i);
    min_cost = min(min_cost, cost);
  }
  cout << min_cost << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	int N;
	get(N);

	int lsb = N % 10;

	const char* ans = "hon";
	if (lsb == 3) {
		ans = "bon";
	}
	else if (lsb == 0 || lsb == 1 || lsb == 6 || lsb == 8) {
		ans = "pon";
	}
	printf("%s\n", ans);
}


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

using namespace std;

string S, T;
int q;
int s[100050], t[100050];
int main(){
	cin >> S >> T;
	for(int i=0; i<S.length(); ++i){
		if(S[i] == 'A') s[i+1] = 1;
		else s[i+1] = 2;
		s[i+1] += s[i];
	}
	for(int i=0; i<T.length(); ++i){
		if(T[i] == 'A') t[i+1] = 1;
		else t[i+1] = 2;
		t[i+1] += t[i];
	}
	cin >> q;
	while(q--){
		int a,b,c,d; cin >> a >> b >> c >> d;
		if((s[b]-s[a-1])%3 == (t[d]-t[c-1])%3) cout << "YES\n";
		else cout << "NO\n";
	}
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
ll d[MAXN]; bool vis[MAXN]; map <ll, int> home;
vector <int> a[MAXN]; pair <ll, int> b[MAXN];
int f[MAXN], s[MAXN], size[MAXN];
void dfs(int pos, int fa) {
	size[pos] = 1;
	for (auto x : a[pos])
		if (x != fa) {
			dfs(x, pos);
			size[pos] += size[x];
		}
}
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		read(d[i]);
		f[i] = i, s[i] = 1;
		b[i] = make_pair(d[i], i);
		home[d[i]] = i;
	}
	sort(b + 1, b + n + 1);
	reverse(b + 1, b + n + 1);
	for (int i = 1; i <= n - 1; i++) {
		int pos = b[i].second; vis[pos] = true;
		ll another = b[i].first + s[pos] - (n - s[pos]);
		if (home.count(another) == 0 || vis[home[another]]) {
			puts("-1");
			return 0;
		}
		int res = home[another];
		f[pos] = f[res], s[res] += s[pos];
	}
	for (int i = 1; i <= n; i++)
		if (vis[i]) {
			a[i].push_back(f[i]);
			a[f[i]].push_back(i);
		}
	dfs(1, 0);
	ll res = 0;
	for (int i = 2; i <= n; i++)
		res += size[i];
	if (res == d[1]) {
		for (int i = 1; i <= n; i++)
			if (vis[i]) printf("%d %d\n", i, f[i]);
	} else puts("-1");
	return 0;
}

Measured memory_bytes: 27136
(* --------------Encoder-------------- *)
(* -----function----- *)
(*
let encoder = 0
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Decoder-------------- *)
(* -----function----- *)
(*
let decoder ans = ""
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Processor-------------- *)
(* -----function----- *)
(*
let processor dat = 0
*)

(* -------test------- *)
(* ----------------------------------- *)


(* ----------------main---------------- *)
(*
let () = print_endline (decoder (processor encoder))
*)
(* ------------------------------------ *)
let () = Scanf.scanf "%1d %1d %1d" (fun a b c -> 
                        List.fold_right (+) (List.filter (fun x -> x = 1) [a; b; c]) 0 
                        |> Printf.printf "%d\n"
)



Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
//using namespace atcoder;

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i,N){
        cin >> h[i];
    }
    ll L = 0;
    ll R = 1e9+1;
    ll C = A-B;
    rep(i,200){
        ll X = (L+R)/2;
        ll an = X;
        rep(i,N){
            ll t = h[i] - B*X;
            if(t <= 0) continue;
            an -= (t+C-1)/C;
        }
        if(an < 0){
            L = X;
        }else{
            R = X;
        }
    }
    cout << R << endl;
}

Measured memory_bytes: 4024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }

int dp[101010][2];

int main() {
    string s;
    cin >> s;
    dp[0][0] = 1;
    int N = s.size();
    rep(i, N){
        { // (a+b)[i] = 0
            if(s[i] == '0'){
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            } else {
                dp[i+1][1] = (dp[i][0]+dp[i][1]) % MOD;
            }
        }
        { // (a+b)[i] = 1
            if(s[i] == '0'){
                (dp[i+1][1] += dp[i][1]*2 % MOD) %= MOD;
            } else {
                (dp[i+1][0] += dp[i][0]*2 % MOD) %= MOD;
                (dp[i+1][1] += dp[i][1]*2 % MOD) %= MOD; 
            }
        }
    }
    int ans = (dp[N][0] + dp[N][1]) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
from collections import deque
n = int(input())
nodes = []
siblings = [-1]*n
parents = [-1]*n
degrees = [0]*n
depths = [-1]*n
heights = [-1]*n
roles = ['leaf']*n
children = []

infs = []
for i in range(n):
    inf = list(map(int, input().split()))
    infs.append(inf)
infs.sort()

for i in range(n):
    inf = infs[i]
    node = inf[0]
    sibling = inf[1:]
    nodes.append(node)
    children.append(sibling)
    a, b = sibling[0], sibling[1]
    if a==-1 and b==-1:
        heights[i] = 0
    elif b == -1:
        parents[a] = i
        degrees[i] = 2-sibling.count(-1)
        roles[i] = 'internal node'
    elif a== -1:
        parents[b] = i
        degrees[i] = 2-sibling.count(-1)
        roles[i] = 'internal node'
    else:
        parents[a], parents[b] = i, i
        siblings[a], siblings[b] = b, a
        degrees[i] = 2-sibling.count(-1)
        roles[i] = 'internal node'
        
for i in range(n):
    if parents[i] == -1:
        roles[i] = 'root'
        depths[i] = 0

nums = deque([i for i in range(n)])
while len(nums) > 0:
    t = nums[0]
    nums.popleft()
    if depths[t]>=0 and degrees[t]>0:
        a, b = children[t][0], children[t][1]
        depths[a], depths[b] = depths[t]+1, depths[t]+1
    elif degrees[t]>0:
        nums.append(t)
    
            
nums = [i for i in range(n)]
i = 0
while len(nums) > 0:
    l = []
    for t in nums:
        if heights[t] == i:
            p = parents[t]
            if p == -1:
                continue
            heights[p] = i+1
            if p not in l:
              l.append(p)
        else:
            l.append(t)
    i += 1
    nums = l
        
for i in range(n):
    print('node', i, end='')
    print(': parent =', parents[i], end='')
    print(', sibling =', siblings[i], end='')
    print(', degree =', degrees[i], end='')
    print(', depth =', depths[i], end='')
    print(', height =', heights[i], end='')
    print(',', roles[i])


Measured memory_bytes: 6048
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  double A,B;
  cin >> A >> B;

  for(int i = 1;i <= 1010;i++) {
    double p = i;
    double a = p*0.08,b = p*0.1;
    if((int)a == A && (int)b == B) {
      cout << (int)p << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
count=0
ans=[]
for i in range(n):
  ans.append(abs(a[i]))
  if a[i]<0:
    count+=1

if count%2==0:
  print(sum(ans))
else:
  print(sum(ans)-2*min(ans))
  

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

const int INF = 1 << 28;

int T, t[30];
int f[100];
int dp[100][30];

int calc(int d, int c)
{
	if (d == 100) return 0;
	if (~dp[d][c]) return dp[d][c];
	int vl = f[d] < t[c] ? INF : calc(d + 1, (c + 1) % T);
	int vr = f[d] < t[0] ? INF : 1 + calc(d + 1, 1 % T);
	return dp[d][c] = min(vl, vr);
}

int main()
{
	while (cin >> T, T){
		fill_n(f, 100, 9999);
		memset(dp, -1, sizeof(dp));
		for (int i = 0; i < T; i++){
			cin >> t[i];
		}
		int n;
		cin >> n;
		for (int i = 0; i < n; i++){
			int d, m;
			cin >> d >> m;
			f[d - 1] = min(f[d - 1], m);
		}
		cout << calc(0, 0) << endl;
	}
}

Measured memory_bytes: 1180