akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<map>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  char ban[8][8];
  int hantei=1;
  int sx,sy,tate,yoko;
  queue <P> zahyo;
  P p;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<8;j++){
      for(int k=0;k<8;k++){
	cin>>ban[j][k];
      }
    }
    cin>>sx>>sy;
    p.first=sy-1;
    p.second=sx-1;
    zahyo.push(p);
    ban[sy-1][sx-1]='0';
    while(!zahyo.empty()){
      P now=zahyo.front();
      tate=now.first;
      yoko=now.second;
      for(int j=0;j<4;j++){
	for(int k=1;k<=3;k++){
	  if(j==0){
	    if(yoko+k<8 && ban[tate][yoko+k]=='1'){
	      ban[tate][yoko+k]='0';
	      p.first=tate;
	      p.second=yoko+k;
	      zahyo.push(p);
	    }
	  }
	  else if(j==1){
	    if(tate+k<8 && ban[tate+k][yoko]=='1'){
	      ban[tate+k][yoko]='0';
	      p.first=tate+k;
	      p.second=yoko;
	      zahyo.push(p);
	    }
	  }
	  else if(j==2){
	    if(yoko-k>-1 && ban[tate][yoko-k]=='1'){
	      ban[tate][yoko-k]='0';
	      p.first=tate;
	      p.second=yoko-k;
	      zahyo.push(p);
	    }
	  }
	  else if(j==3){
	    if(tate-k>-1 && ban[tate-k][yoko]=='1'){
	      ban[tate-k][yoko]='0';
	      p.first=tate-k;
	      p.second=yoko;
	      zahyo.push(p);
	    }
	  }
	}
      }
      zahyo.pop();
    }
    cout<<"Data "<<i+1<<':'<<endl;
    for(int j=0;j<8;j++){
      for(int k=0;k<8;k++){
	cout<<ban[j][k];
      }
      cout<<endl;
    }
  }
}

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

int main()
{
  string S;
  cin >> S;
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}
template<typename T>
void debug(vector<T> V){
    for(auto x:V){
        cout<<x<<" ";
    }
    cout<<endl;
}
void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //cout<<fixed<<setprecision(8);
    go();
    return 0;
}
/*************************************/
void go(){
    int x,a;
    R(x,a);
    W(x<a?0:10);
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



//メイン関数
int main()
{
	ll N;
	cin >> N;
	vector<vector<ll>> abc(N);
	REP(i, N)
	{
		ll tmp;
		REP(j, 3)
		{
			cin >> tmp;
			abc[i].push_back(tmp);
		}
	}

	vector<vector<ll>> dp(N, vector<ll>(3, 0));
	REP(i, 3)dp[0][i] = abc[0][i];
	REP(i, N - 1)REP(j, 3)
	{
		dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + abc[i + 1][j];
	}
	cout << *max_element(dp.back().begin(), dp.back().end()) << endl;
	cin>>N;
	return 0;
}


Measured memory_bytes: 12800
function main(input) {
  input.split("\n")
  .slice(0,10)
  .map(function(str){
    return parseInt(str);
  })
  .sort(function(a,b){
    return b - a;
  })
  .slice(0,3)
  .map(function(height){
    console.log(height);
  });
}
main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 15504
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main(){
  string s;
  char ch;
  getline(cin,s);

  for(int i=0;i<s.size();i++){
    ch=s[i];
    if(islower(ch))ch=toupper(s[i]);
    else if(isupper(ch))ch=tolower(s[i]);
    cout <<ch;
  }
  cout <<endl;
}

Measured memory_bytes: 1180
#include<iostream>
 
int main(){
  int A[9],N;
  bool bA[9]={};
  int *b=new int[N];
  // input

	 std::cin>>A[0]>>A[1]>>A[2];
	 std::cin>>A[3]>>A[4]>>A[5];
	 std::cin>>A[6]>>A[7]>>A[8];

  std::cin>>N;
  for(int i=0;i<N;i++){
    std::cin>>b[i];
  }
  //
  for(int i=0;i<N;i++){
    for(int j=0;j<9;j++){
      if(A[j]==b[i]){
        bA[j]=true;
      }
    }
  }
  if((bA[0]==true&&bA[1]==true&&bA[2]==true)||
     (bA[3]==true&&bA[4]==true&&bA[5]==true)||
     (bA[6]==true&&bA[7]==true&&bA[8]==true)||
     (bA[0]==true&&bA[3]==true&&bA[6]==true)||
     (bA[1]==true&&bA[4]==true&&bA[7]==true)||
     (bA[2]==true&&bA[5]==true&&bA[8]==true)||
     (bA[0]==true&&bA[4]==true&&bA[8]==true)||
     (bA[2]==true&&bA[4]==true&&bA[6]==true)){
    std::cout<<"Yes";
  }else{
    std::cout<<"No";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

int binary_search(vec_int &vec_to_search, int comp_val){
    //これは何をやるかというと、
    //vec_to_searchが昇順にソートされていることが前提
    //vec_to_search[i-1]<=comp_val<vec_to_search[i]となるiを探す

    int N = vec_to_search.size();
    int lb = -1, ub = N;
    while(ub-lb>1){
        int mid = (ub+lb)/2;
        if(vec_to_search[mid]>comp_val){
            ub=mid;
        }else{
            lb=mid;
        }
    }
    return ub;

}

int main(){
    int N;
    cin>>N;
    vector<int> A(N),B(N),C(N);
    rep(i,N){
        cin>>A.at(i);
    }
    rep(i,N){
        cin>>B.at(i);
    }
    rep(i,N){
        cin>>C.at(i);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());


    ll total_combi_N = 0;
    vector<int> A_B(N), B_C(N);
    rep(i,N){
//        A_B.at(i) = binary_search(B, A.at(i));
//        B_C.at(i) = binary_search(C, B.at(i));
//        auto iter1 =(upper_bound(B.begin(),B.end(), A.at(i))); 
        auto iter1 =(lower_bound(A.begin(),A.end(), B.at(i))); 
//        A_B.at(i) = distance(B.begin(),iter1);
        auto iter2 = (upper_bound(C.begin(),C.end(), B.at(i)));
//        B_C.at(i) = distance(C.begin(),iter2);
//        cout << (N-distance(A.begin(),iter1))<<" "<<(N-distance(C.begin(),iter2))<<endl;

        total_combi_N += (distance(A.begin(),iter1))*(N-distance(C.begin(),iter2));
        //cout<<A_B.at(i) << " "<<B_C.at(i)<<endl;
    }

/*
    vector <int> B_count(N,0);
    B_count.at(N-1) = N-B_C.at(N-1);
    rep(i,N-1){
        //A.at(i)を選択したとき、A_B.at(i)以降のBを選択できる
        //ただし、B.at(j)を選択したときに選べるCの数はB_C.at(j)である
        //したがって、sigma_{A_B.at(i)}^{N} B_C.at(j)を計算しないといけない
        //このためにはBをしっぽのほうから足し算したものが必要になる。
        B_count.at(N-2-i) = (N-B_C.at(N-2-i)) + B_count.at(N-1-i);
    }

    ll total_combi_N = 0;
    rep(i,N){
        //A.at(i)を選択したとき、A_B.at(i)以降のBを選択できる
        if(A_B.at(i)==N)continue;
        total_combi_N += B_count.at(A_B.at(i));
    }
//    rep(i,N){
//        cout<<B_count.at(i)<<endl;
//    }

*/
    cout << (total_combi_N)<<endl;

//    int binary_search(B, a)

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    
    int n; cin >> n;    
    vector<int> num(n + 1, 0); 
    for (int x = 1; x * x <= n; x++) {
        for (int y = 1; y * y <= n; y++) {
            for (int z = 1; z * z <= n; z++) {
                int tmp = 0;
                tmp += x * x + y * y + z * z;
                tmp += x * y + y * z + z * x;
                if (tmp <= n) num[tmp]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << num[i] << endl;
    } 
    return 0;
}

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

class Program {
	static void Main(string[] args) {




		const int INPUT_COUNT = 2;
		var lstInput = new List<string>();
		for (int i = 0; i < INPUT_COUNT; i++) {
			lstInput.Add(Console.ReadLine());
		}

		int result = 0;
		int count = int.Parse(lstInput[0]);
		string[] sary = lstInput[1].Split(' ');
		int[] ary = new int[count];

		for (int i = 0; i < count; i++) {
			ary[i] = int.Parse(sary[i]);
		}

		for (int i = 0; i < count; i++) {
			if ((i + 1) == ary[ary[i] - 1]) {
				result++;
			}
		}


		Console.WriteLine("{0}", result / 2);	



	
	}
}

Measured memory_bytes: 9816
/*
god taekyu
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,w;
int dp[105][100005];
int W[105], V[105];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>w;
    for(int i=1;i<=n;i++) {
        cin>>W[i]>>V[i];
    }
    for(int j=1;j<=100000;j++) {
        dp[0][j] = 1e9 + 1;
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=100000;j++) {
            dp[i][j] = dp[i-1][j];
        }
        for(int j=1;j<=100000;j++) {
            if(j >= V[i]) dp[i][j] = min(dp[i][j], dp[i-1][j-V[i]] + W[i]);
        }
    }
    for(int j=100000;j>=0;j--) {
        if(dp[n][j] <= w) {
            cout<<j;
            return 0;
        }
    }
    return 0;
}

/*
god taekyu
*/


Measured memory_bytes: 41216
def Labeling(terrain):

    label = terrain

    offset = [[-1, 0], [0, -1], [1, 0], [0, 1]]
    signs = ["@", "#", "*"]
    step = 0

    for row in range(1, len(label) - 1):
        for col in range(1, len(label[row]) - 1):
            mark = label[row][col]

            if mark in signs:
                pointStack = [[row, col]]
                label[row][col] = step

                while 0 < len(pointStack):
                    rowIndex, colIndex = pointStack.pop()

                    for x, y in offset:
                        offsetRow, offsetCol = rowIndex + x, colIndex + y

                        if label[offsetRow][offsetCol] == mark:
                            pointStack.append([offsetRow, offsetCol])
                            label[offsetRow][offsetCol] = step

                step += 1

    return step


Sentinel = "1"

while True:
    col, row = [int(item) for item in input().split()]

    if row == 0 and col == 0:
        break

    land = []
    land.append([item for item in Sentinel * row + Sentinel * 2])

    for lp in range(col):
        part = [item for item in input()]
        land.append([])
        land[-1].extend([Sentinel])
        land[-1].extend(part)
        land[-1].extend([Sentinel])

    land.append([item for item in Sentinel * row + Sentinel * 2])

    result = Labeling(land)

    print(result)



Measured memory_bytes: 5992
#include<bits/stdc++.h>
using namespace std;
int ans[100003],n,m,q,do1[100003],do2[100003],do3[100003];
vector<int>v[100005];
bool vis[13][100003];
void dfs(int a,int b,int c){
	if(b==-1)return;
	if(vis[b][a])return;
	for(int i=0;i<=b;i++)
		vis[i][a]=1;
	if(!ans[a])ans[a]=c;
	for(int i=0;i<v[a].size();i++)
		dfs(v[a][i],b-1,c);
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin>>q;
	for(int i=1;i<=q;i++)
		cin>>do1[i]>>do2[i]>>do3[i];
	for(int i=q;i>0;i--){
		dfs(do1[i],do2[i],do3[i]);
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
}

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

int main()
{
	int n,k;

	int suu[100000 + 100] = { 0 };
	int a;
	int i;
	int mx;

	cin >> n >> k;

	while (n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{

			cin >> a;

			suu[i] = a + suu[i - 1];

		}

		for (i = k; i <= n; i++)
		{
			if (mx < suu[i] - suu[i - k])
			{
				mx = suu[i] - suu[i - k];
			}

		}

		cout << mx << endl;


		cin >> n >> k;
		mx = 0;
	}
	return 0;
}

Measured memory_bytes: 3400
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

const int maxn=110;
char mp[maxn][maxn];
bool vis[maxn][maxn];
int to[4][2]={{1,0},{-1,0},{0,-1},{0,1}};
int h,w;

bool bfs(int x,int y,char c)
{
    if (vis[x][y]) return false;
    queue<pair<int,int> > que;
    que.push(make_pair(x,y));
    vis[x][y]=1;
    while (!que.empty())
    {
        pair<int,int> t=que.front(); que.pop();
        for (int i=0;i<4;i++)
        {
            int xx=t.first+to[i][0];
            int yy=t.second+to[i][1];
            if (xx<0||xx>=h||yy<0||yy>=w||mp[xx][yy]!=c||vis[xx][yy])
                continue;
            vis[xx][yy]=1;
            que.push(make_pair(xx,yy));
        }
    }
    return true;
}


int main()
{
    while (cin>>h>>w&&(w||h))
    {
        for (int i=0;i<h;i++)
            for (int j=0;j<w;j++)
                cin>>mp[i][j];

        memset(vis,0,sizeof(vis));
        int ans=0;
        for (int i=0;i<h;i++)
            for (int j=0;j<w;j++)
                if (bfs(i,j,mp[i][j]))
                    ans++;

        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
vector<int> v[15];
int p[15];
int cnt=0;int n,m;
map<int,int> mp;
int cur[15];
int cmp=0;
void check(){
	int sta=0;
	for(int i=1;i<=m;i++){
		sta<<=1;
		if(p[i]==0){
			int fg=1;
			for(int j=0;j<v[i].size();j++){
				if(cur[v[i][j]]){
					fg++;
				}
			}
			if(fg%2){
				sta|=1;
			}
		}
		else{
			int fg=0;
			for(int j=0;j<v[i].size();j++){
				if(cur[v[i][j]]){
					fg++;
				}
			}
			if(fg%2==1){
				sta|=1;
			}
		}
	}
	if(sta==cmp){
		cnt++;
	}
}
void dfs(int pos){
	if(pos<=0){
		check();
		return;
	}
	cur[pos]=1;
	dfs(pos-1);
	cur[pos]=0;
	dfs(pos-1);
	return;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		cmp<<=1;
		cmp|=1;
	}
	for(int i=1;i<=m;i++){
		int k;
		scanf("%d",&k);
		while(k--){
			int tmp;
			scanf("%d",&tmp);
			v[i].push_back(tmp);
		}
	}
	for(int i=1;i<=m;i++){
		scanf("%d",&p[i]);
	}
	dfs(n);
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int ans=0;
  REP(i,3){
    char c;
    cin >> c;
    if(c=='1') ans++;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const A = numList0[0];
    const B = numList0[1];
    const T = numList0[2];

    const result = Math.floor(T / A) * B;

    console.log(result);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    string S; cin >> S;
    if (S == "Sunny") cout << "Cloudy" << endl;
    else if (S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
h,w,d=map(int,input().split())
A=[]
for _ in range(h):
    A.append([int(i) for i in input().split()])
q=int(input())
lr=[]
for _ in range(q):
    l,r = map(int,input().split())
    lr.append((l,r))
D=dict()
for i in range(h):
    for j in range(w):
        D[A[i][j]]=(i,j)

def dist(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])
#ans=[[-1 for _ in range(h*w//d+1)] for _ in range(d)]
res=dict()
for i in range(d):
    j=i+1
    cnt=0
    res[j]=0
    #ans[i][0] = 0
    while j<=h*w-d:
        #ans[i][cnt+1] = ans[i][cnt] + dist(D[j],D[j+d])
        res[j+d] = res[j]+dist(D[j],D[j+d]) #ans[i][cnt]
        j+=d
        cnt+=1
for l,r in lr:
    print(res[r]-res[l])

Measured memory_bytes: 84572
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    map<string, lli> cnt;
    lli n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        (cnt.count(s) ? cnt[s]++ : cnt[s] = 1);
    }
    lli ma = 0;
    for(auto v:cnt){
        ma = max(v.second, ma);
    }
    for(auto v: cnt){
        if(v.second==ma){
            out(v.first);
        }
    }
}

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

using namespace std;

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
#define ar array

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 1e7+1;
const int N=50010;


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--){
int x;
cin>>x;
if(x>=30)cout<<"Yes\n";
else cout<<"No\n";
}
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll n,num[maxn],t[maxn*2+5],p[maxn*2+5],l,r;
void add(ll x,ll v)
{
	for(ll i=x;i<=2*maxn;i+=i&-i)
    	t[i]+=v;
}
ll sum(ll x)
{
    ll ans=0;
    for(ll i=x;i>0;i-=i&-i)
    	ans+=t[i];
    return ans;
}
bool check(ll mid)
{	
	ll ans=0;
	memset(t,0,sizeof(t));
	p[0]=0;
	for(int i=1;i<=n;++i)
	p[i]=p[i-1]+(num[i]>=mid?1:-1);
	for(int i=0;i<=n;++i)
	{
		ans+=sum(p[i]+maxn);
		add(p[i]+maxn,1ll);
	}
	return ans>=n*(n+1)/4;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&num[i]);
	    r=max(r,num[i]);
    }
    while(l<=r)
    {
    	int middle=(l+r)>>1; 
    	if(check(middle))l=middle+1;
		else r=middle-1; 
    }
    printf("%lld",r);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    vector<string> p = {"dream", "dreamer", "erase", "eraser"};
    vector<bool> ok(s.size() + 1, false);
    ok.at(0) = true;
    REP(i, ok.size()){
        if(!ok.at(i)){
            continue;
        }
        for(const string& x : p){
            if(x == s.substr(i, x.size())){
                ok.at(i + x.size()) = true;
            }
        }
    }
    if(ok.back()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

int main() {
    //will try ths question with stack
    stack<char>s1,s2,s3;
    string a1,a2,a3;
    cin>>a1>>a2>>a3;
    for(int i=a1.length();i>=0;i--)s1.push(a1[i]);
    for(int i=a2.length();i>=0;i--)s2.push(a2[i]);
    for(int i=a3.length();i>=0;i--)s3.push(a3[i]);
    char p;
    p=s1.top();
    s1.pop();
    if(s1.empty())cout<<"A"<<endl;
    else{
        while(!s1.empty() && !s2.empty() && !s3.empty()){
            if(p=='a'){
                p=s1.top();
                s1.pop();
            }else if(p=='b'){
                p=s2.top();
                s2.pop();
            }else if(p=='c'){
                p=s3.top();
                s3.pop();
            }
        }
        if(s1.empty())cout<<"A"<<endl;
        else if(s2.empty())cout<<"B"<<endl;
        else if(s3.empty())cout<<"C"<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  int total = 0;
  for (int i = 0; i < 5; i++) total += max(40, in());
  printf("%d\n", total / 5);
  return (0);
}

Measured memory_bytes: 1188
// https://atcoder.jp/contests/abc165/tasks/abc165_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)

int N, M, Q;
int a[50], b[50], c[50], d[50];

int ans = 0;
int tmp[10];
void solve(int n, int bef) {
    if (n == N) {
        int x = 0;
        rep(i, Q) {
            if (tmp[b[i]] - tmp[a[i]] == c[i]) {
                x += d[i];
            }
        }
        ans = max(ans, x);
        return;
    }
    for (int i = bef; i <= M; i++) {
        tmp[n] = i;
        solve(n + 1, i);
    }
}

signed main() {
    cin >> N >> M >> Q;
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    solve(0, 1);
    cout << ans << endl;
}


Measured memory_bytes: 3636
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

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; }
//typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e16;
//Ford-Fulkerson法で最大流を求める O(F|E|)
const int MAX_V = 210;
struct edge { int to, cap, rev; };
vector<edge>G[MAX_V];
bool used[MAX_V];
const int START = 200, GOAL = 201;
void add_edge(int from, int to, int cap) {
	G[from].push_back({ to, cap, G[to].size() });
	G[to].push_back({ from,0,G[from].size() - 1 });
}
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge& e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0) {
			return flow;
		}
		flow += f;
	}
}

char A[202][202];
void solve() {
	
	int H, W; cin >> H >> W;
	REP(i, H)REP(j, W) {
		cin >> A[i][j];
		if (A[i][j] == 'S') {
			add_edge(START, i, INF);
			add_edge(START, j + 100, INF);
		}
		else if (A[i][j] == 'T') {
			add_edge(i, GOAL, INF);
			add_edge(j + 100, GOAL, INF);
		}
		else if(A[i][j]=='o') {
			add_edge(i, j + 100, 1);
			add_edge(j + 100, i, 1);
		}
	}
	ll ans = max_flow(START, GOAL);
	if (ans >= INF) {
		print(-1);
	}
	else print(ans);
}


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

	solve();
}




Measured memory_bytes: 1536
N,K = map(int,input().split())

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

command.sort()

ind = 0
for i in range(N):
    if ind + command[i][1]>=K:
        print(command[i][0])
        exit()
    else:
        ind += command[i][1]


Measured memory_bytes: 90320
#include <bits/stdc++.h>
#define N 6000
#define int long long
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,m,A[N],B[5010][N],ss[5010][N],tpp[5010];
ll tree[N<<2],Add[N<<2];
inline void deal(int ls,int rs,int x,int y)
{
	tree[x]+=y; Add[x]+=y;
}
inline void pushup(int rt)
{
	tree[rt]=max(tree[rt<<1],tree[rt<<1|1]);
}
inline void pushdown(int ls,int rs,int rt)
{
	if(Add[rt])
	{
		deal(ls,rs,rt<<1,Add[rt]);
		deal(ls,rs,rt<<1|1,Add[rt]);
		Add[rt]=0;
	}
}
inline void updata(int L,int R,int x,int l,int r,int rt)
{
	if(L>R) return ;
  	if(L<=l&&r<=R) 
	{
		deal(L,R,rt,x); return ;
	}int mid=(l+r)>>1; pushdown(L,R,rt);
	if(mid>=L) updata(L,R,x,l,mid,rt<<1);
	if(mid<R) updata(L,R,x,mid+1,r,rt<<1|1);
	pushup(rt);
}
inline void built(int l,int r,int rt)
{
	if(l==r){tree[rt]=A[l]; return ;}
	int mid=(l+r)>>1;
	built(l,mid,rt<<1); built(mid+1,r,rt<<1|1);
	pushup(rt);
}
inline ll query(int L,int R,int l,int r,int rt)
{
	if(L>R) return 0;
	if(L<=l&&r<=R) return tree[rt];
	int mid=(l+r)>>1; pushdown(L,R,rt);
	if(mid<L) return query(L,R,mid+1,r,rt<<1|1);
	if(mid>=R) return query(L,R,l,mid,rt<<1);
	return max(query(L,R,l,mid,rt<<1),query(L,R,mid+1,r,rt<<1|1));
}
inline void work(int x,int y)
{
	//cerr <<"SPE:"<< x << " " << y << endl;
	updata(x,x,B[y][x],1,n,1);
	int nw=ss[y][tpp[y]];
	//cerr << "cg:" << endl;
	while(B[y][x]>B[y][ss[y][tpp[y]]]&&tpp[y])
	{
	//	cout << nw << " ";		
		updata(ss[y][tpp[y]-1]+1,nw,B[y][x]-B[y][ss[y][tpp[y]]],1,n,1);
		nw=ss[y][tpp[y]-1]; tpp[y]--;
	}
	//cout << endl;
	ss[y][++tpp[y]]=x;
}
signed main()
{
	//freopen("read.in","r",stdin);
	n=read(); m=read(); A[1]=0; for(int i=2;i<=n;i++) A[i]=read()+A[i-1];
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) 
		B[j][i]=read();
	built(1,n,1); ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) work(i,j);
		ans=max(ans,query(1,i,1,n,1)-1ll*A[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 21248
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;
    vector<char> out;
    for (int i = 0;  i < s.length(); i++) {
        if (s[i] == 'B') {
            if (out.size() > 0){
                out.pop_back();
            }
        }
        else {
            out.push_back(s[i]);
        }
    }

    for (vector<char>::iterator it = out.begin(); it != out.end(); ++it) {
        cout << *it;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N, K;
  std::cin >> N >> K;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll kk = K;
  ll L = 0;
  while (kk > 0) {
    kk /= 2;
    L++;
  }

  std::vector< ll > vcnt(L, 0LL);
  for (ll i = 0; i < N; i++) {
    for (ll j = L-1; j >= 0; j--) {
      if (1LL<<j & va[i]) {
	vcnt[j]++;
      }
    }
  }
  //printVec(vcnt.begin(), vcnt.end());

  ll X = 0;
  for (ll i = L-1; i >= 0; i--) {
    if ((X | (1LL << i)) <= K && vcnt[i] <= N / 2) {
      X |= (1LL << i);
    }
  }
  //print("X", X);

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ans += va[i] ^ X;
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,k;
  cin >> n >> k;
  ll l[n];
  REP(i,n){
    cin >> l[i];
  }
  sort(l,l+n,greater<ll>());
  ll ans = 0;
  REP(i,k){
    ans+=l[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N, cnt=0;
    int flag=0;
    cin >> N;
    vector<int> A(N);
    
    for(int i=0; i<N; i++) cin >> A[i];
    
    while(true){
        for(int i=0; i<N; i++){
            if(A[i]%2 != 0){
                flag = 1;
                break;
            }
            else A[i] /= 2;
        }
        if(flag) break;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import numpy as np

def seachPrimeNum(MAX):
    prime = np.zeros(MAX, np.bool_)
    prime[2] = 1
    prime[3::2] = 1
    for p in range(3, MAX, 2):
        if p * p >= MAX:
            break
        if prime[p]:
            prime[p * p::p + p] = 0
    
    return prime.nonzero()[0]

N = int(input())
n = N
s = 0

prime = np.array(seachPrimeNum(int(np.sqrt(10**12))))
prime = prime[N % prime == 0]

for p in prime:
    e = 1
    while n % p == 0:
        if n % p ** e == 0:
            n = n / p ** e
            e = e + 1
            s += 1
        else:
            n = n / p

if n != 1:
    s += 1

print(s)

Measured memory_bytes: 28532
def main():
    N, M = map(int, input().split())
    p = list(map(int, input().split()))
    for i in range(N):
        p[i] -= 1
    x = [0 for _ in range(M)]
    y = [0 for _ in range(M)]
    for i in range(M):
        x[i], y[i] = map(int, input().split())
        x[i] -= 1
        y[i] -= 1

    def root(x):
        if Parent[x]==x:
            return x
        else:
            Parent[x] = root(Parent[x])
            return Parent[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if x!=y:
            Parent[x] = y

    Parent = [i for i in range(N)]
    for i in range(M):
        unite(x[i], y[i])

    count = 0
    for i in range(N):
        if root(i)==root(p[i]):
            count += 1

    return count

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 19428
using DataStructures
p()=parse.(Int,split(readline()))
function main()
  n,q=p()
  s=IntDisjointSets(n)
  for i=1:q
    t,u,v=p()+[0,1,1]
    if Bool(t)
      println(Int(in_same_set(s,u,v)))
    else
      union!(s,u,v)
    end
  end
end
main()


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

int main() {
  int n; cin>>n;
  int a[n],b[n],c[n];
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  ll ans=0;
  rep(i,n){
      ans+=(lower_bound(a,a+n,b[i])-a)*(n-(upper_bound(c,c+n,b[i])-c));
  }

  cout<<ans<<endl;

}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    bool ym = false, my = false;
    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));
    if (a >= 1 && a <= 12) {
        my = true;
    }
    if (b >= 1 && b <= 12) {
        ym = true;
    }
    if (my) {
        if (ym) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else if (ym) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
w, h, n = gets.split.map(&:to_i)

# 領域上、白は0、黒は1とする

def init_2d_array(height, width, initial="")
  Array.new(height){ Array.new(width, initial) }
end
field = init_2d_array(h, w, 0)

n.times do
  x, y, a = gets.split.map(&:to_i)
  case a
  when 1
    # x < xi の領域を黒くする
    field.map! { |line|
      line.map.with_index { |e, i|
        i < x ? 1 : e
      }
    }
  when 2
    # x > xi の領域を黒くする
    field.map! { |line|
      line.map.with_index { |e, i|
        i >= x ? 1 : e
      }
    }
  when 3
    # y < yi の領域を黒くする
    field.map!.with_index { |line, i|
      line.map { |e|
        i < y ? 1 : e
      }
    }
  when 4
    # y > yi の領域を黒くする
    field.map!.with_index { |line, i|
      line.map { |e|
        i >= y ? 1 : e
      }
    }
  end
end

count_white = 0
field.reverse.each do |line|
  line.map { |e| e == 0 ? count_white += 1 : nil }
end
puts count_white


Measured memory_bytes: 6268
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
long get_long(char *line, int size) {
  if(!fgets(line, size, stdin)) return 0;
  long num;
  sscanf(line, "%ld", &num);
  return num;
}

#define BUF_SIZE 15

long get_digit(long num) {
  long ans = 0;
  while(num) {
    ans++;
    num /= 10;
  }
  return ans;
}

int main(void) {
  char line[BUF_SIZE];
  long num = get_long(line, BUF_SIZE);
  int start = (int)sqrt(num+0.5);
  int i;

  for(i = start; i >= 1; i--) {
    if(num % i == 0) {
      printf("%ld\n", get_digit(num/i));
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 128
# input
A, B, C, X, Y = map(int, input().split())

ans = 0

if A + B >= 2 * C:
    if Y >= X:
        if B >= 2 * C:
            ans = 2 * C * Y
        else:
            ans = 2 * C * X + B * (Y - X)
    else:
        if A >= 2 * C:
            ans = 2 * C * X
        else:
            ans = 2 * C * Y + A * (X - Y)
else:
    ans = A * X + B * Y

print(ans)

Measured memory_bytes: 3064
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        bol = 1
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    bol = 0
        if bol:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9100
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll dp[55][2555],ans;
int n,a,x[55];
int main()
{
	scanf("%d%d",&n,&a);
	for(int i=0;i<n;i++)scanf("%d",&x[i]);
	dp[0][0]=1;
	for(int i=0;i<n;i++)
	for(int k=50;k>=0;k--)
	for(int y=0;y<=2500;y++)
	dp[k+1][y+x[i]]+=dp[k][y];
	for(int i=1;i<=n;i++)
	ans+=dp[i][i*a];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var beforeT = 0;
        var beforeX = 0;
        var beforeY = 0;
        var ans = "Yes";
        for (int i=0;i<N;++i)
        {
            var line = Console.ReadLine().Split(' ').Select(o => Int32.Parse(o)).ToArray();
            var currentT = line[0];
            var currentX = line[1];
            var currentY = line[2];
            var t = currentT - beforeT;
            var x = Math.Abs(beforeX-currentX);
            var y = Math.Abs(beforeY-currentY);
            var sa = x + y;
            if ((t < sa) || (sa % 2 == 0 && t % 2 == 1) || (sa % 2 == 1 && t % 2 == 0))
            {
                ans = "No";
                break;
            }

            { 
                beforeT = currentT;
                beforeX = currentX;
                beforeY = currentY;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 15440
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int N; cin>>N;
  ll m=0,a=0,r=0,c=0,h=0;
  string S;
  for(int i=0;i<N;i++){
    cin>>S;
    if(S[0]=='M')
      m++;
    if(S[0]=='A')
      a++;
    if(S[0]=='R')
      r++;
    if(S[0]=='C')
      c++;
    if(S[0]=='H')
      h++;
  }
  //10通りある
  ll ans=0;
  ans+=m*a*r;
  ans+=m*a*c;
  ans+=m*a*h;
  ans+=m*r*c;
  ans+=m*r*h;
  ans+=m*c*h;
  ans+=a*r*c;
  ans+=a*r*h;
  ans+=a*c*h;
  ans+=r*c*h;
  cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
int n, k;
int a[200005], ans;

bool check(int mid) {
    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] > mid) {
            if (a[i] % mid == 0)
                cnt += 1ll * a[i] / mid - 1;
            else
                cnt += 1ll * a[i] / mid;
        }
    }
    if (cnt > k) return false;
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int l = 1, r = 2e9;
    while (l <= r) {
        int mid = l + r >> 1;
        if (check(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4364
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] arr = new int[n];
      for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
      int[] leftGCD = new int[n];
      leftGCD[0] = arr[0];
      for(int i = 1; i < n; i++) {
        leftGCD[i] = gcd(leftGCD[i - 1], arr[i]);
      }

      int[] rightGCD = new int[n];
      rightGCD[n-1] = arr[n-1];
      for(int i = n-2; i >= 0; i--) {
        rightGCD[i] = gcd(rightGCD[i+1], arr[i]);
      }

      int max = Math.max(rightGCD[1], leftGCD[n-2]);
      for(int i = 1; i < n - 1; i++) {
        max = Math.max(max, gcd(leftGCD[i-1], rightGCD[i+1]));
      }
      System.out.println(max);
  }

  private static int gcd(int a, int b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }
}

Measured memory_bytes: 50944
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int N, A[100005], T, mdp[100005] = { 1000000000 }, diff[100005] = { 0 };

int main() {

	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if(i > 0) mdp[i] = min(mdp[i - 1], A[i]);
		else mdp[i] = A[i];
		
		diff[i] = max(A[i] - mdp[i], 0);
	}

	sort(diff, diff+N);

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (diff[i] == diff[N-1]) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int w,b;

string s[100];

int main(){
	cin >> w >> b;
	rep(i,100){
		rep(j,100){
			if(i < 50)s[i] += ".";
			else s[i] += "#";
		}
	}
	int px = 0,py = 0;
	rep(j,b-1){
		s[py][px] = '#';
		px += 2;
		if(px >= 100){
			px = 0;
			py += 2;
		}
	}
	px = 0,py = 100 - 1;
	rep(j,w-1){
		s[py][px] = '.';
		px += 2;
		if(px >= 100){
			px = 0;
			py -= 2;
		}
	}
	cout << 100 << " " << 100 << endl;
	rep(i,100)cout << s[i] << endl;
}

Measured memory_bytes: 256
n,a,b,c = map(int, input().split())
ans = []
number = dict()
number['A'] = a
number['B'] = b
number['C'] = c
query = [input() for i in range(n)]
for i in range(n):
    s = query[i]
    s_1, s_2 = s[0], s[1]
    if number[s_1] == 0 and number[s_2] == 0:
        print("No")
        exit()
    else:
        if number[s_1] > number[s_2]:
            number[s_1] -= 1
            number[s_2] += 1
            ans.append(s_2)
        elif number[s_1] < number[s_2]:
            number[s_2] -= 1
            number[s_1] += 1
            ans.append(s_1)
        else:
            if i == n-1:
                number[s_2] -= 1
                number[s_1] += 1
                ans.append(s_1)
            else:
                if query[i+1] == s_1 + s_2:
                    number[s_2] -= 1
                    number[s_1] += 1
                    ans.append(s_1)
                else:
                    n_1,n_2 = query[i+1]
                    if s_1 in set([n_1,n_2]):
                        number[s_2] -= 1
                        number[s_1] += 1
                        ans.append(s_1)
                    else:
                        number[s_1] -= 1
                        number[s_2] += 1
                        ans.append(s_2)

    #print("A:{} B:{} C:{}".format(number['A'],number['B'],number['C']))
print("Yes")
for i in range(n):
    print(ans[i])

Measured memory_bytes: 86984
int N;
char s[30300];
int nxt[30300][10];
main()
{
	scanf("%d\n%s",&N,s);
	for(int i=0;i<10;i++)nxt[N][i]=-1;
	for(int i=N;i--;)
	{
		for(int j=0;j<10;j++)nxt[i][j]=nxt[i+1][j];
		nxt[i][s[i]-'0']=i;
	}
	int cnt=0;
	for(int x=0;x<10;x++)for(int y=0;y<10;y++)for(int z=0;z<10;z++)
	{
		int id=0;
		id=nxt[id][x];
		if(id<0)continue;
		id++;
		id=nxt[id][y];
		if(id<0)continue;
		id++;
		id=nxt[id][z];
		if(id<0)continue;
		cnt++;
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define loop0(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define pb push_back
const int MAXN = 2e3+7;
int ans[MAXN];
int dist(int x, int y){return (y>=x) ? y-x : x-y;}
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	loop1(i,n){
		for(int j=i+1; j<=n; j++){
			int di = min(dist(i,j), min( dist(i,a)+1+dist(j,b), dist(i,b)+1+dist(j,a) ) );
			ans[di]++;
		}
	}
	for(int i=1; i<n; i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
bool calc(int n, int a, int b){
	int sum =0;
	while(n>0){
		sum+=n%10;
		n/=10;
	}
	if(sum>=a && sum<=b) return true;
	else return false;
}
int main() {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	loop(i, 1, n+1) if(calc(i, a, b)) ans+=i;
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int price = 700;
  for(int i=0;i<3;i++){
    if( s.at(i) == 'o' ){
      price += 100;
    }
  }
  cout << price << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  const int INIT = 0;
  const int INCR = 1;
  const int DECR = -1;

  int state = INIT;
  int cnt = 1;
  FOR (i, 1, n) {
    if (state == INIT) {
      if (a[i-1] < a[i]) {
        state = INCR;
      } else if (a[i-1] > a[i]) {
        state = DECR;
      }
      continue;
    }
    if (a[i-1] < a[i]) {
      if (state == DECR) {
        state = INIT;
        cnt += 1;
      }
    }
    if (a[i-1] > a[i]) {
      if (state == INCR) {
        state = INIT;
        cnt += 1;
      }
    }
  }

  printf("%d\n", cnt);

  return 0;
}


Measured memory_bytes: 888