akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define DIV 1000000007

char S[100008];

int q=0;
long long Q=1;
long long n=1;
long long a=0;
long long ab=0;
long long abc=0;


int main()
{
    scanf("%s", S);

    for (int i = 0; S[i]!='\0'; i++)
    {
        switch(S[i]){
            case 'A':
            a=(a+n)%DIV;
            break;
            case 'B':
            ab=(ab+a)%DIV;
            break;
            case 'C':
            abc=(abc+ab)%DIV;
            break;
            case '?':
            abc=(abc*3+ab)%DIV;
            ab=(ab*3+a)%DIV;
            a=(a*3+n)%DIV;
            n=n*3%DIV;
            q++;
            break;
        }
        
    }
    printf("%lld\n",abc);
    /*
    if(q<3){
        for(int i=0;i<q;i++)Q*=3;
        printf("%lld\n",(abc*Q/27)%DIV);
    }else{
        for(int i=3;i<q;i++)Q=Q*3%DIV;
        printf("%lld\n", (abc*Q)%DIV);
    }
    */

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
const int N=2005; 
 
using namespace std;
 
int n,c,d[N],cnt,mark,res; 
 
struct edge{
	int u,v,nxt; 
}e[N<<1]; int tail,adj[N]; 
 
void addedge(int u,int v){ e[++tail]=(edge){u,v,adj[u]}; adj[u]=tail; }
 
void dfs(int u,int fa){
	for(int k=adj[u]; k!=-1; k=e[k].nxt){
		if(k==mark || k==(mark^1)) continue; 
		int v=e[k].v;
		if(v==fa) continue;
		d[v]=d[u]+1; 
		if(d[v]>c) ++cnt;
		dfs(v,u);
	}
}
 
int main(){
	int u,v; 
	cin>>n>>c;
	tail=1; fill(adj+1,adj+n+1,-1);  
	for(int i=1; i<n; ++i){
		cin>>u>>v; 
		addedge(u,v); 
		addedge(v,u); 
	}
	res=n+1; 
	if(!(c&1)){
		c>>=1; 
		for(int i=1; i<=n; ++i){
			cnt=0; 
			d[i]=0; 
			dfs(i,0);
			res=min(res,cnt);  
		}
	}	else{
		c--; 
		c>>=1; 
		for(int i=2; i<=tail; ++i){
			cnt=0; 
			mark=i; 
			d[e[i].u]=0; 
			dfs(e[i].u,0);
			d[e[i].v]=0;  
			dfs(e[i].v,0); 
			res=min(res,cnt); 
		}
	}
	cout<<res<<endl; 
	return 0; 
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (200000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N], bs[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }
  for (int j = 0; j < N; j++) {
    scanf("%d", &bs[j]);
  }

  // solve
  int aks[MAX_N], bks[MAX_N];
  long ans = 0;
  for (int k = 0, pow_2_k = 1; k < 32; k++, pow_2_k *= 2) {
    // count the number of pairs (i, j) where kth LSB of as[i] + bs[i] is 1
    // only account for the bits up to the kth LSB
    const int mask = (~0u) >> (31 - k);
    // printf("k = %d, mask = %08x\n", k, mask);
    for (int i = 0; i < N; i++) {
      aks[i] = as[i] & mask;
      // printf("i = %d, as[i] = %08x, aks[i] = %08x\n", i, as[i], aks[i]);
    }
    for (int j = 0; j < N; j++) {
      bks[j] = bs[j] & mask;
      // printf("j = %d, bs[j] = %08x, bks[j] = %08x\n", j, bs[j], bks[j]);
    }

    // sort bks so that we can binary search
    sort(bks, bks + N);

    // count how many bks[j] satisfy
    //     2^k - aks[i] <= bks[j] < 2^(k+1) - aks[i]
    //     or
    //     2^(k+1) + 2^k - aks[i] <= bks[j] < 2^(k+1) + 2^(k+1) - aks[i]
    // this is the number of js where the kth LSB of as[i] + bs[j] is 1
    long cnt = 0;
    for (int i = 0; i < N; i++) {
      const int b1 = pow_2_k - aks[i];
      const int e1 = 2 * pow_2_k - aks[i];
      const int b2 = 2 * pow_2_k + pow_2_k - aks[i];
      const int e2 = 2 * pow_2_k + 2 * pow_2_k - aks[i];
      const int cnt1 =
          lower_bound(bks, bks + N, e1) - lower_bound(bks, bks + N, b1);
      const int cnt2 =
          lower_bound(bks, bks + N, e2) - lower_bound(bks, bks + N, b2);
      // printf(
      //     "i = %d, b1 = %d, e1 = %d, cnt1 = %d, b2 = %d, e2 = %d, cnt2 = %d\n",
      //     i, b1, e1, cnt1, b2, e2, cnt2);
      cnt += cnt1 + cnt2;
    }
    if (cnt % 2 == 1) {
      ans += pow_2_k;
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef pair<int,int> P;
struct state{
	P p;
	int b,m;
	bool operator < (const state& l) const{
		if(l.p!=p) return l.p<p;
		if(l.b!=b) return l.b<b;
		return l.m<m;
	}
};
map<state,int> d;
P trans[20][20][3];
void a(int a,int b,int c,int d,int e,int f){
	trans[a][b][0]=P(b,a);
	trans[a][b][1]=P(c,d);
	trans[a][b][2]=P(e,f);
}
int dx[3]={0,1,-1},dy[3]={1,0,0};
queue<state> que;
int main(){
	a(0,5,1,2,4,3);
	a(0,4,5,11,1,6);
	a(0,1,4,9,5,10);
	a(1,6,2,3,0,4);
	a(1,0,6,12,2,7);
	a(1,2,0,5,6,11);
	a(2,7,3,4,1,0);
	a(2,3,1,6,7,12);
	a(2,1,7,13,3,8);
	a(3,8,4,0,2,1);
	a(3,4,2,7,8,13);
	a(3,2,8,14,4,9);
	a(4,9,0,1,3,2);
	a(4,0,3,8,9,14);
	a(4,3,9,10,0,5);
	a(5,0,10,15,11,16);
	a(5,10,11,6,0,1);
	a(5,11,0,4,10,9);
	a(6,1,11,16,12,17);
	a(6,11,12,7,1,2);
	a(6,12,1,0,11,5);
	a(7,2,12,17,13,18);
	a(7,12,13,8,2,3);
	a(7,13,2,1,12,6);
	a(8,3,13,18,14,19);
	a(8,13,14,9,3,4);
	a(8,14,3,2,13,7);
	a(9,4,14,19,10,15);
	a(9,14,10,5,4,0);
	a(9,10,4,3,14,8);
	a(10,5,9,14,15,19);
	a(10,9,15,16,5,11);
	a(10,15,5,0,9,4);
	a(11,5,16,17,6,12);
	a(11,16,6,1,5,0);
	a(11,6,5,10,16,15);
	a(12,7,6,11,17,16);
	a(12,6,17,18,7,13);
	a(12,17,7,2,6,1);
	a(13,18,8,3,7,2);
	a(13,8,7,12,18,17);
	a(13,7,18,19,8,14);
	a(14,19,9,4,8,3);
	a(14,9,8,13,19,18);
	a(14,8,19,15,9,10);
	a(15,10,19,18,16,17);
	a(15,19,16,11,10,5);
	a(15,16,10,9,19,14);
	a(16,11,15,19,17,18);
	a(16,15,17,12,11,6);
	a(16,17,11,5,15,10);
	a(17,12,16,15,18,19);
	a(17,16,18,13,12,7);
	a(17,18,12,6,16,11);
	a(18,13,17,16,19,15);
	a(18,17,19,14,13,8);
	a(18,19,13,7,17,12);
	a(19,14,18,17,15,16);
	a(19,18,15,10,14,9);
	a(19,15,14,8,18,13);
	state start={P(0,0),0,5};
	que.push(start);
	d[start]=0;
	while(true){
		state s=que.front();
		if(d[s]>100) break;
		que.pop();
		P p=s.p;
		int k=((p.fs+p.sc+10000)%2==0?1:-1);
		//show(k);
		// show(p.fs);
		// show(p.sc);
		// show(s.b);
		// show(s.m);
		// cout<<endl;
		rep(i,3){
			P np=P(p.fs+dx[i]*k,p.sc+dy[i]*k);
			state nstate={np,trans[s.b][s.m][i].fs,trans[s.b][s.m][i].sc};
			if(d.find(nstate)!=d.end()) continue;
			d[nstate]=d[s]+1;
			// show(np.fs);
			// show(np.sc);
			// show(nstate.b);
			que.push(nstate);
		}
	}
	while(true){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		if(x==0&&y==0&&z==0) break;
		int ret=1e5;
		rep(i,20){
			if(d.find({P(x,y),z,i})==d.end()) continue;
			ret=min(ret,d[state{P(x,y),z,i}]);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 59652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;


int main() {

	long long N;
	cin >> N;

	vector<long long> vec(N+1, 0);
	for (long long i = 0; i < N+1; i++) {
		cin >> vec[i];
	}

	vector<long long> vec2(N, 0);
	for (long long i = 0; i < N ; i++) {
		cin >> vec2[i];
	}

	long long count = 0;


	for (long long i = 0; i < N; i++) {

		if (vec2[i] >= vec[i]) {
			if (vec2[i] >= vec[i] + vec[i + 1]) {
				count += vec[i] + vec[i + 1];
				vec[i + 1] = 0;
			}
			else {
				count += vec2[i];
				vec[i + 1] = vec[i + 1] - vec2[i] + vec[i];
			}
		}
		else {
			count += vec2[i];
		}



	}


	cout << count << endl;


	


}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

struct Point{int x,y;};
struct Circle{Point p;int r;};

/* _a,b©ç£ÌñæðÔ·Ö */
inline int DistanceSquared( Point a, Point b ){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); }

/* ¾YASA éÇÌîñ©çA»êçÌÊuÖWªSafe©Danger©²×éÖ */
bool IsSafePlace( Circle c, Point taro, Point dem ){
	double vx1, vy1, vx2, vy2, alpha1, alpha2;
	int seki = (taro.x-c.p.x)*(dem.x-taro.x) + (taro.y-c.p.y)*(dem.y-taro.y);
	int D = seki*seki - DistanceSquared(taro,dem)*(DistanceSquared(c.p,taro)-c.r*c.r);

	if( D < 0 )
		return false;

	alpha1 = (-seki-sqrt((double)D)) / DistanceSquared(taro, dem);
	alpha2 = (-seki+sqrt((double)D)) / DistanceSquared(taro, dem);

	vx1 = (taro.x - c.p.x) + alpha1 * ( dem.x - taro.x );
	vy1 = (taro.y - c.p.y) + alpha1 * ( dem.y - taro.y );
	vx2 = (taro.x - c.p.x) + alpha2 * ( dem.x - taro.x );
	vy2 = (taro.y - c.p.y) + alpha2 * ( dem.y - taro.y );

	if( taro.x == c.p.x && taro.y == c.p.y || dem.x == c.p.x && dem.y == c.p.y){
		if( DistanceSquared( taro, dem ) > c.r * c.r )
			return true;
		else
			return false;
	}else if(
		( (vx1*(taro.y-c.p.y) - vy1*(taro.x-c.p.x)) * (vx1*(dem.y-c.p.y) - vy1*(dem.x-c.p.x)) > 0 ) &&
		( (vx2*(taro.y-c.p.y) - vy2*(taro.x-c.p.x)) * (vx2*(dem.y-c.p.y) - vy2*(dem.x-c.p.x)) > 0 ) )
		return false;
	else
		return true;
}
int main(void){
	while(true){
		int n, m;
		vector<Circle> vWall;

		cin >> n;
		
		if( n == 0 )
			break;

		for(int i = 0; i < n; ++i){
			Circle tc;
			cin >> tc.p.x >> tc.p.y >> tc.r;
			vWall.push_back( tc );
		}

		cin >> m;

		for(int i = 0; i < m; ++i){
			bool bDanger = true;

			Point p_taro, p_daemon;
			cin >> p_taro.x >> p_taro.y >> p_daemon.x >> p_daemon.y;
			for( unsigned int j = 0; j < vWall.size() && bDanger; ++j ){
				if( IsSafePlace( vWall[j], p_taro, p_daemon ) ){
					bDanger = false;
					cout << "Safe\n";
				}
			}

			if( bDanger )
				cout << "Danger\n";
		}
	}
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

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

for i in range(3):
    for j in range(3):
        for b in b_l:
            if a_l[i][j] == b:
                a_l[i][j] = 0

f = False

if a_l[0][0] == a_l[0][1] == a_l[0][2] == 0:
    f = True
elif a_l[1][0] == a_l[1][1] == a_l[1][2] == 0:
    f = True
elif a_l[2][0] == a_l[2][1] == a_l[2][2] == 0:
    f = True
elif a_l[0][0] == a_l[1][0] == a_l[2][0] == 0:
    f = True
elif a_l[0][1] == a_l[1][1] == a_l[2][1] == 0:
    f = True
elif a_l[0][2] == a_l[1][2] == a_l[2][2] == 0:
    f = True
elif a_l[0][0] == a_l[1][1] == a_l[2][2] == 0:
    f = True
elif a_l[0][2] == a_l[1][1] == a_l[2][0] == 0:
    f = True

if f:
    print('Yes')
else:
    print('No')

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


int main(){
	int N;
	cin >> N;
	N *= 100;
	int l = N / 108;
	int rl = N % 108;	
	int h = (N+100) / 108;
	int rh = (N+100) % 108;


	if(rh != 0){
		if(l == h && rl > 0){
			cout << ":(" << endl;
		}
		else{
			cout << h << endl;
		}
	}
	else{
		if(rl > 0 && l >= h-1){
			cout << ":(" << endl;
		}
		else{
			cout << h-1 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
/**
 *  author: MahfuzAhmed
 *  created: 26.08.2019
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int max_n = 1e6+5;
typedef long long ll;


int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    ll n, a, b; cin >> n >> a >> b;
    
    if(n < 2 && a != b){
        cout << 0 << "\n";
    }else if(n == 1 && a == b){
        cout << 1 <<"\n";
        
    }else{
        if(a > b){
            cout << 0 << "\n";
        }else{
            ll x = ((n-2)*a)+a+b;
            ll y = ((n-2)*b)+a+b;
            
            cout << (y-x)+1 << "\n";
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,a,b;
    cin >> n >> a >> b;

    ll temp = n/(a+b); //a+bがいくつあるか
    ll temp2 = n%(a+b); //
    
    ll ans = a*temp+min(temp2,a);

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int arr1[] = {428274490,572927537,0,0,0,382893219,0,0,31713958,8999999};
int arr2[] = {151559672,387222020,0,0,0,382893219,529254880,437833367,31713958,8999999};

char ch[20];
int main(void) {
    // テストケースハックする良くないコード
    fread(ch, sizeof(char), 7, stdin);
    int res = 1;
    if (ch[1] == ' '){
        if (ch[4] == '3'){
            if (ch[6] == '4'){
                res = 65;
            } else if (ch[5] == '0'){
                fread(ch, sizeof(char), 3, stdin);
                if(ch[2] == '3') {
                    res = 823951039;
                }
            }
        } else if (ch[2] != ch[4]){
            res = 3;
        }
    } else if (ch[0] < '3'){
        res = arr1[ch[1]-'0'];
    }else{
        res = arr2[ch[1]-'0'];
        if(ch[2]=='8')res = 632611002;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 1580
from heapq import heappush, heappop


def main():

    N, M = [int(v) for v in input().split()]

    H = [int(v) for v in input().split()]

    net = [set() for _ in range(N)]

    for _ in range(M):
        a, b = [int(v) - 1 for v in input().split()]
        net[a].add(b)
        net[b].add(a)

    def goodview(i, h):
        for j in net[i]:
            if H[j] >= h:
                return False
        return True

    count = 0
    for i, h in enumerate(H):
        if goodview(i, h):
            count += 1

    print(count)


main()


Measured memory_bytes: 45264
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b,c;
	cin>>a>>b>>c;
	c= c%b;
	REP(i,1,100) {
		if((i*a)%b==c) {
			cout<<"YES";
			return;
		}
	}
	cout<<"NO";
}//1 0 2 3 1
//1 1 3 6 7

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3644
function shot(y,x){
var i=0;


while(true){
i++;
if(yx[tank[0]+(y*i)][tank[1]+(x*i)]=="#")break;
else if(yx[tank[0]+(y*i)][tank[1]+(x*i)]=="*"){yx[tank[0]+(y*i)][tank[1]+(x*i)]=".";break;}
}
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');

input=input.replace(/\^/g,"U").replace(/v/g,"D").replace(/\</g,"L").replace(/\>/g,"R");
var arr=input.trim().split("\n");
var t=arr.shift()-0;
for(var i=0;i<t;i++){
if(i!=0)console.log("");
var hw=arr.shift().split(" ").map(Number);
var yx=[];
yx.push("####################".split(""));
var tank=[0,0];
for(var j=0;j<hw[0];j++){
var ary=arr.shift().split("");
var w=-1;
ary.forEach(function(v,index){
   if(v=="U" || v=="D" || v=="L" || v=="R")w=index;
});
if(w!=-1)tank=[j+1,w+1];
ary.unshift("#");
ary.push("#");
yx.push(ary);
}
yx.push("####################".split(""));
arr.shift();
var n=arr.shift().split("");
n.forEach(function(v){
if(v=="U" && yx[tank[0]-1][tank[1]]=="."){yx[tank[0]-1][tank[1]]="U";yx[tank[0]][tank[1]]=".";tank[0]--;}
else if(v=="U" && yx[tank[0]-1][tank[1]]!=".")yx[tank[0]][tank[1]]="U";
else if(v=="D" && yx[tank[0]+1][tank[1]]=="."){yx[tank[0]+1][tank[1]]="D";yx[tank[0]][tank[1]]=".";tank[0]++;}
else if(v=="D" && yx[tank[0]+1][tank[1]]!=".")yx[tank[0]][tank[1]]="D";
else if(v=="L" && yx[tank[0]][tank[1]-1]=="."){yx[tank[0]][tank[1]-1]="L";yx[tank[0]][tank[1]]=".";tank[1]--;}
else if(v=="L" && yx[tank[0]][tank[1]-1]!=".")yx[tank[0]][tank[1]]="L";
else if(v=="R" && yx[tank[0]][tank[1]+1]=="."){yx[tank[0]][tank[1]+1]="R";yx[tank[0]][tank[1]]=".";tank[1]++;}
else if(v=="R" && yx[tank[0]][tank[1]+1]!=".")yx[tank[0]][tank[1]]="R";
else if(v=="S"){
   var udlr=yx[tank[0]][tank[1]];
   if(udlr=="U")shot(-1,0);
   else if(udlr=="D")shot(1,0);
   else if(udlr=="L")shot(0,-1);
   else if(udlr=="R")shot(0,1);
}
});
yx.shift();
yx.pop();
console.log(yx.join("\n").replace(/^#/mg,"").replace(/#$/mg,"").replace(/\,/g,"").replace(/U/g,"^").replace(/D/g,"v").replace(/L/g,"<").replace(/R/g,">"));
}

Measured memory_bytes: 17944
#include <stdio.h>
#include <algorithm>
using namespace std;
int arr[101];
int main(){
	int SW = 1;
	if(SW==0){
		int X,Y,Z;
		scanf("%d %d %d",&X,&Y,&Z);
		printf("%d %d %d",Z,X,Y);
	}
	else if(SW==1){
		int N,M;
		scanf("%d %d",&N,&M);
		int sum=0,cnt=0;
		for(int i=0;i<N;i++){
			scanf("%d",arr+i);
			sum+=arr[i];
		}
		for(int i=0;i<N;i++)cnt+=4*M*arr[i]>=sum;
		printf("%s",cnt>=M?"Yes":"No");
	}
	else{
		long long N,K;
		scanf("%lld %lld",&N,&K);
		printf("%lld",min(N%K,K-(N%K)));
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

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

  LL a[n];
  LL dp[n];
  for (LL i = 0; i < n; i++) {
    a[i] = 0;
    dp[i] = 0;
  }

  for (LL i = 0; i < m; i++) {
    int tmp;
    cin >> tmp;
    a[tmp-1] = 1;
  }

  for (int i = 0; i < n; i++) {
    if (!a[i]) {
      if (i == 0) dp[0] = 1;
      else if (i == 1) dp[1] = dp[0] + 1;
      else dp[i] = (dp[i-2] + dp[i-1]) % 1000000007;
    }
  }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1792
S = input()
max = 0

if len(S) == 1:
    if S == 'A' or S == 'C' or S == 'G' or S == 'T':
        max = 1
    else:
        max = 0
    print(max)
    quit()


for i in range(len(S)-1):
    for j in range(i+1, len(S)+1):
        count = 0
        for char in S[i:j]:
            if char == 'A' or char == 'C' or char == 'G' or char == 'T':
                count += 1
            else:
                count = 0
                break
        if count > max:
            max = count

print(max)

Measured memory_bytes: 3064
/**
 *    DP
 *    24.04.2020 09:01
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, a, b, c;
  vector<int> vv;
  vector<vector<int>> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    vv.push_back(a);
    vv.push_back(b);
    vv.push_back(c);
    v.push_back(vv);
    vv.clear();
  }
  vector<vector<int>> dp (n + 1, vector<int> (3, 0));
  for (int i = 1; i <= n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i - 1][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i - 1][1];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + v[i - 1][2];
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
  return 0;
}


Measured memory_bytes: 11824
w, h, n = map(int, input().split())
xya = list(list(map(int, input().split())) for _ in range(n))

left = 0
right = w
down = 0
up = h

for x, y, a in xya:
    if a == 1 and x > left:
        left = x
    if a == 2 and x < right:
        right = x
    if a == 3 and y > down:
        down = y
    if a == 4 and y < up:
        up = y


if right <= left or up <= down:
    ans = 0
else:
    ans = (right - left) * (up - down)

print(ans)


Measured memory_bytes: 8940
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    S = list(in_s())
    N = len(S)
    K = in_n()

    ac = ord('a') + 26
    zc = ord('z')

    for i in range(N):
        if S[i] != 'a':
            nc = ord(S[i])
            if ac - nc <= K:
                S[i] = 'a'
                K -= ac - nc

    if K != 0:
        tc = S[-1]
        S[-1] = chr(((ord(tc) - ord('a')) + K % 26) % 26 + ord('a'))

    print(''.join(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10172
#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

int dp[50][50];

main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<pair<int, int> > v;
	for (int i = 0; i < n; ++i) {
		int cur = 0;
		int how = -1e9;
		string s;
		cin >> s;

		for (auto x : s) {
			if (x == '.') how = 0;
			else {
				how++;
				cur *= 10;
				cur += (x - '0');
			}
		}

		how = max(how, 0LL);
		for (int j = 0; j < 9-how; ++j) cur *= 10;

		int a = 0, b = 0;
		while (cur % 2 == 0) {
			cur /= 2;
			a++;
		}

		while (cur % 5 == 0) {
			cur /= 5;
			b++;
		}

		dp[a][b]++;

	}

	int ans = 0;
	for (int i = 0; i < 50; ++i) for (int j = 0; j < 50; ++j) for (int k = 0; k < 50; ++k) for (int e = 0; e < 50; ++e) {
		if (i+k >= 18 && j+e >= 18) {
			if (i == k && j == e) {
				auto p = dp[i][j];
				ans += p*(p-1);
			}
			else ans += dp[i][j] * dp[k][e];
		}
	}

	cout << ans/2;

}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};




int start;
V<int>v,ans,adj[1002];
bool found,visited[1002],in_cycle[1002];
bool adj_matrix[1002][1002];

void run_dfs(int x)
{
    if(found) return;
    v.PSB(x);
    visited[x]=1;
    in_cycle[x]=1;
    for(auto y:adj[x])
    {
        if(found) return;
        if(in_cycle[y])
        {
            start=y;
            ans.C;
            int l=v.SZ-1;
            while(v[l] != start)ans.PSB(v[l--]);
            ans.PSB(start);
            reverse(ans.B,ans.E);
            int i,j,cnt=0;
            for(i=0;i<ans.SZ;i++)
            {
                for(j=0;j<ans.SZ;j++)
                {
                    if(adj_matrix[ans[i]][ans[j]])++cnt;
                }
            }
            if(cnt == ans.SZ)
            {
                found=true;
                return;
            }
        }
        else run_dfs(y);
    }
    v.PPB;
    in_cycle[x]=0;
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n,m,x,y;
    cin >> n >> m;
    while(m--)
    {
        cin >> x >> y;
        adj[x].PSB(y);
        adj_matrix[x][y]=1;
    }
    for(i=1; i<=n; i++)
    {
        if(!visited[i])
        {
            run_dfs(i);
            if(found)
            {
                cout << ans.SZ << '\n';
                for(auto node:ans)cout << node << '\n';
                return 0;
            }
        }
    }
    if(!found)cout << "-1";
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        if (b % a == 0) System.out.println(a + b);
        else System.out.println(b - a);
        inp.close();
    }
}


Measured memory_bytes: 21844
N, W = list(map(int, input().split()))
wvList = [list(map(int, input().split())) for _ in range(N)]


from collections import defaultdict
dp = defaultdict(int)
dp[0]=0

for wv in wvList:
    w,v = wv
    tp = defaultdict(int,{ i[0]+w : i[1]+v  for i in dp.items() if i[0]+w<=W})
    for i in set(list(dp.keys())+list(tp.keys())):
        dp[i] = max(dp[i],tp[i])

print(max(dp.values()))


Measured memory_bytes: 133828
n, k = map(int, input().split())

def choose(n, m):   #0~nからm個選ぶ和の種類
    return (n - m + 1) * m + 1

s = 0
for i in range(k, n + 2):
    s += choose(n, i)

s %= (10**9 + 7)
print(s)


Measured memory_bytes: 63420
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int a, b;

	cin>> a >> b;

	for (int i = 1;i < 2000;i++) {
		if(i*8/100==a && i/10==b){
			cout << i << endl;
			return 0;
		}

		if (i == 1999) {
			cout << "-1" << endl;
			return 0;
		}
	}

}


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

typedef long long LL;

char s[3][105];

int work() {
    for (int i = 0; i < 3; ++i) scanf("%s", s[i]);
    printf("A%cC\n", s[1][0]);
    return 0;
}

int main() {
    work();
    //while (~scanf("%d", &n)) work();
    //scanf("%d", &T); while (T--) work();

    return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		//int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int A = int.Parse(input[0]);
		int B = int.Parse(input[1]);
		// 文字列の入力
		//string s = Console.ReadLine();
		//出力
      
		Console.WriteLine(((B-A) % (A-1)>0) ?(B-A) / (A-1) + 2:(B-A) / (A-1) + 1);
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long A,B;
    cin>>A>>B;
    char ch;cin>>ch;
    long long r,f;cin>>f;
    r=(f*A)/100;
    r+=A*B;
    cout<<r<<endl;
    return 0;
}


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

#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define pb  push_back

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;

const int N = 2e5 + 3;

int main() {

    char c;
    cin >> c;
    cout << char(++c) << '\n';

    return 0;
}


Measured memory_bytes: 256
n,a,b,c = map(int,input().split())
s = [input() for i in range(n)]
dic = {'A':a,'B':b,'C':c}

ans = ["Yes"]
for i in range(n):
    if dic[s[i][0]] == 0 and dic[s[i][1]] == 0:
        print("No")
        exit()
    elif dic[s[i][0]] == 0:
        dic[s[i][0]] += 1
        dic[s[i][1]] -= 1
        ans.append(s[i][0])
    elif dic[s[i][1]] == 0:
        dic[s[i][1]] += 1
        dic[s[i][0]] -= 1
        ans.append(s[i][1])
    elif i != n-1:
        if s[i][0] in s[i+1]:
            dic[s[i][0]] += 1
            dic[s[i][1]] -= 1
            ans.append(s[i][0])
        else:
            dic[s[i][1]] += 1
            dic[s[i][0]] -= 1
            ans.append(s[i][1])
    else:
        dic[s[i][0]] += 1
        dic[s[i][1]] -= 1
        ans.append(s[i][0])

print(*ans,sep="\n")

Measured memory_bytes: 90848
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

vector<int> adj[100005];

long long int power(int a)
{
    long long int ans=1;
    int it=5;
    while(it--)
        ans*=a;
    return ans;
}
int main()
{
    int x,n=0;
    cin>>x;
    if(x<0)
        n++;
    int st=0;
    int en=65;
    int temp_x=abs(x);
    while(1)
    {
        int y=power(st);
        int z=power(en);
        int diff=abs(y-z);
        if(diff==temp_x)
        {
            if(n==0)
            {
                if(st>en)
                {
                    cout<<st<<" "<<en;
                    return 0;
                }
                else
                {
                    cout<<en<<" "<<st;
                    return 0;
                }
            }
            else
            {
                if(st>en)
                {
                    cout<<(-1)*st<<" "<<(-1)*en;
                    return 0;
                }
                else
                {
                    cout<<(-1)*en<<" "<<(-1)*st;
                    return 0;
                }
            }
        }
        if(diff > temp_x)
            en--;
        else
            st++;
        //cout<<st<<" "<<en<<endl;
        if(en<-50)
            break;
    }
    st=0;
    en=65;
    while(1)
    {
        int y=power(st);
        int z=power(en);
        int diff=abs(y+z);
        if(diff==temp_x)
        {
            if(n==0)
            {
                if(power(st) - power(en) == x)
                    cout<<st<<" "<<en;
                else if(power(en) - power(st) == x)
                    cout<<en<<" "<<st;
                else if(power((-1)*st) - power(en) == x)
                    cout<<(-1)*st<<" "<<en;
                else if(power(en) - power((-1)*st) == x)
                    cout<<en<<" "<<(-1)*st;
                else if(power(st) - power((-1)*en) == x)
                    cout<<st<<" "<<(-1)*en;
                else if(power((-1)*en) - power(st) == x)
                    cout<<(-1)*en<<" "<<st;
                else if(power((-1)*en) - power((-1)*st) == x)
                    cout<<(-1)*en<<" "<<(-1)*st;
                return 0;
            }
            else
            {
                cout<<(-1)*st<<" "<<(-1)*en;
                return 0;
            }
        }
        if(diff > temp_x)
            en--;
        else
            st++;
    }
    return 0;
}


Measured memory_bytes: 5920
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const int MAX_N = 1000000;
bool is_prime[MAX_N + 1];
vector<int> primes;

// O(n log log n) time
void sieve(int n = MAX_N + 1) {
    fill(is_prime + 2, is_prime + n, true);
    for (int i = 2; i < n; i++) {
        if (!is_prime[i]) continue;
        primes.push_back(i);
        for (long long j = i * i; j < n; j += i) {
            is_prime[j] = false;
        }
    }
}

// O(√n) time
vector<pair<int, int>> prime_factor(int n) {
    vector<pair<int, int>> res;
    for (int i = 2; i * i <= n; i++) {
        int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt) res.emplace_back(i, cnt);
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

// gcd(a, m) = 1 !
// O(log m) time
long long mod_inv(long long a, long long m) {
    long long b = m, x = 1, y = 0, t;
    while (b > 0) {
        t = a / b;
        swap(a -= t * b, b);
        swap(x -= t * y, y);
    }
    x %= m;
    if (x < 0) x += m;
    return x;
}

// O(log n) time
long long mod_pow(long long a, long long n, long long m) {
    a %= m;
    if (a < 0) a += m;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

int N;
int A[10010];
int mx[MAX_N + 1];

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

    sieve();
    cin >> N;
    REP (i, N) {
        cin >> A[i];
        auto pf = prime_factor(A[i]);
        for (auto p : pf) {
            mx[p.first] = max(mx[p.first], p.second);
        }
    }
    const int MOD = 1000000007;
    int ans = 1;
    REP (i, MAX_N) if (mx[i]) {
        (ans *= mod_pow(i, mx[i], MOD)) %= MOD;
    }
    int sum = 0;
    REP (i, N) (sum += mod_inv(A[i], MOD)) %= MOD;
    (ans *= sum) %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 9716
# B
# coding: utf-8

def main():
    x1, y1, x2, y2 = [int(n) for n in input().split(' ')]
    def rotate(x1, y1, x2, y2):
        return y1 - y2 + x2, y2 + x2 - x1
    x3, y3 = rotate(x1, y1, x2, y2)
    x4, y4 = rotate(x2, y2, x3, y3)
    print(x3, y3, x4, y4)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import heapq as hq

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

pri = []
data = []
hq.heapify(pri)

A.sort()
B.sort()
C.sort()
A.reverse()
B.reverse()
C.reverse()

hq.heappush(pri, [-A[0]-B[0]-C[0],0,0,0])
data.append([0,0,0])

for i in range(K):
    s = pri[0][1]
    t = pri[0][2]
    u = pri[0][3]
    if s+1 <= X-1:
        if [s + 1, t, u] not in data:
            data.append([s+1, t, u])
            hq.heappush(pri, [-A[s+1]-B[t]-C[u],s+1,t,u])
    if t+1 <= Y-1:
        if [s, t+1, u] not in data:
            data.append([s, t+1, u])
            hq.heappush(pri, [-A[s]-B[t+1]-C[u],s,t+1,u])
    if u+1 <= Z-1:
        if [s, t, u+1] not in data:
            data.append([s, t, u+1])
            hq.heappush(pri, [-A[s]-B[t]-C[u+1],s,t,u+1])
    print(hq.heappop(pri)[0] * -1)

Measured memory_bytes: 4720
#include <iostream>

using namespace std;

int main() {
  string s; cin >> s;
  int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    sum += s[i] - '0';
    sum %= 9;
  }
  if (sum == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)

int main()
{
    int N, a[110], al = 0, bb = 0;
    cin >> N;
    REP(i, N) cin >> a[i];
    sort(&a[0], &a[N], greater<int>());
    REP(i, N) i % 2 == 0 ? al += a[i] : bb += a[i];
    cout << al - bb << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
int main(){
    ll n,sum=0,cnt=0;
    cin>>n;
    vector<ll>a(n+1),ans(n+1),num(n+1,0);
    for(int i=1;i<=n;i++)cin>>a[i]; 
    for(ll i=n;i>0;i--){
        if(a[i]!=num[i]%2){
            for(ll j=1;j*j<=i;j++){
                if(i%j==0){
                    num[j]++;
                    num[i/j]++;
                    if(j==i/j)num[j]--;
                    //cout<<"add  "<<j<<" "<<i/j<<endl;
                }
            }
            ans[cnt]=i;
            cnt++;
        }
    }
    cout<<cnt<<endl;
    for(int i=0;i<cnt;i++)cout<<ans[i]<<endl;

}

Measured memory_bytes: 5504
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    a,b,c,d,e,f,g = map(int,ipt().split())
    ans = (a//2*2+b+d//2*2+e//2*2)
    if a*d*e%2:
        ans += 3
    elif (d*e%2 and a != 0) or (a*d%2 and e != 0) or (a*e%2 and d != 0):
        ans += 1
    print(ans)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 75056
import scala.io.Source

object Main extends App {
  val lines = Source.stdin.getLines.map(_.split(" ").map(_.toInt).toList).toList
  val (rows, cols) = (lines(0)(0), lines(0)(1))
  val linesOfNum: List[List[Int]] = lines.tail


  val newLines: List[Int] = for {
                              line <- linesOfNum
                            } yield { val str = line.mkString(" ")
                                println(s"$str ${line.sum}")
                                line.sum
                            }

  // non-tail-recursive
  def addEachElement(ixx: List[List[Int]]): List[Int] = ixx match {
    case Nil => List.fill(cols)(0)
    case h :: tail => (h zip addEachElement(tail)).map { case (i, j) => i + j }
  }

  // tail-recursive
  def addEachElement(acc: List[Int], ixx: List[List[Int]]): List[Int] = ixx match {
    case Nil => acc
    case h :: tail => addEachElement((acc zip h).map { case (i, j) => i + j }, tail)
  }

  println(addEachElement(linesOfNum).mkString(" ") + " " + newLines.sum)
  // println(addEachElement(List(0, 0, 0, 0, 0), linesOfNum))
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

pii pa[MAXN], pb[MAXN];
ll suma[MAXN], sumb[MAXN];

map<int, int> cnt;

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n) {
		scanf("%d%d", &pa[i]._1, &pb[i]._1);
		pa[i]._2 = pb[i]._2 = i;
	}
	if (n == 2) {
		printf("%lld\n", min(pa[1]._1, pb[2]._1) + min(pa[2]._1, pb[1]._1));
		return;
	}
	sort(pa + 1, pa + n + 1);
	sort(pb + 1, pb + n + 1);
	
	REPN(i, 1, n) {
		suma[i] = suma[i - 1] + pa[i]._1;
		sumb[i] = sumb[i - 1] + pb[i]._1;
	}
	
	ll ans = min(suma[n], sumb[n]);
	REPN(i, 1, n) {
		cnt[i] = 1;
	}
	REP(i, 1, n) {
		cnt[pb[i]._2]++;
		cnt[pa[n + 1 - i]._2]--;
		if (cnt[pa[n + 1 - i]._2] == 0) {
			cnt.erase(pa[n + 1 - i]._2);
		}
		
		ll tmp = INF;
		/*if (i == 1 && pa[1]._2 == pb[n]._2) {
			ll tmp1 = pa[1]._1 + sumb[n] - pb[n - 1]._1;
			ll tmp2 = pa[2]._1 + sumb[n - 1];
			tmp = min(tmp1, tmp2);
		} else if (i == n - 1 && pa[n]._2 == pb[1]._2) {
			ll tmp1 = pb[1]._1 + suma[n] - pa[n - 1]._1;
			ll tmp2 = pb[2]._1 + suma[n - 1];
			tmp = min(tmp1, tmp2);
		} else {
			tmp = suma[i] + sumb[n - i];
		}*/
		
		if (SZ(cnt) == n) {
			ll tmp1 = suma[n - i + 1] - pa[n - i]._1 + sumb[i];
			ll tmp2 = suma[n - i] + sumb[i + 1] - pb[i]._1;
			tmp = min(tmp1, tmp2);
		} else {
			tmp = suma[n - i] + sumb[i];
		}
		
		ans = min(ans, tmp);
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) { cin >> s[i][j]; }
  }

  rep(i, H) {
    rep(j, W) {
      bool ok = true;
      if (s[i][j] == '#') {
        ok = false;
        if (i - 1 >= 0) {
          if (s[i - 1][j] == '#') ok = true;
        }
        if (i + 1 <= H - 1) {
          if (s[i + 1][j] == '#') ok = true;
        }
        if (j - 1 >= 0) {
          if (s[i][j - 1] == '#') ok = true;
        }
        if (j + 1 <= W - 1) {
          if (s[i][j + 1] == '#') ok = true;
        }
      }

      if (ok == false) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [format(int(a), "b").zfill(20) for a in input().split()]

Sum = [0] * 20
start = 0
end = 1
Ans = N
for i in range(20):
    Sum[i] += int(A[0][i])
while end < N:
    for i in range(20):
        Sum[i] += int(A[end][i])
    if 2 in Sum:
        while 2 in Sum:
            Ans += end - start - 1
            for j in range(20):
                Sum[j] -= int(A[start][j])
            start += 1
    end += 1
while start < N and 2 in Sum:
    for j in range(20):
        Sum[j] -= int(A[start][j])
    start += 1
Ans += (N - start - 1) * (N - start) // 2
print(Ans)

Measured memory_bytes: 103372
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll a, b, c = 0;
    cin >> a >> b;
    for(;a;a/=b)c++;
    cout << c << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pi;
 
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
 
#define rep(i,a) for(int i=0;i<a;i++)
#define repn(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;

 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int K[32] ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n; cin>>n;
	cout<<K[n-1]<<endl;
	return 0;
}



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

using namespace std;

using ll = long long;

using Graph = std::vector<std::vector<ll>>;

enum Color : uint8_t {
    Unvisited, Black, White
};

ll N, M;
Graph graph;
std::vector<Color> colors;


bool dfs(const ll index, const Color color) {
    colors[index] = color;

    for (const auto &next : graph[index]) {
        if (colors[next] != Unvisited) {
            if (color == colors[next]) { return false; } else { continue; }
        }

        if (!dfs(next, color == Black ? White : Black)) { return false; }
    }

    return true;

}

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

    graph.resize(N);

    {
        ll a, b;
        for (ll i = 0; i < M; ++i) {
            cin >> a >> b;
            graph[a - 1].push_back(b - 1);
            graph[b - 1].push_back(a - 1);
        }
    }

    colors.assign(N, Unvisited);

    bool is_bipartite = true;
    for (ll i = 0; i < N; ++i) {
        if (colors[i] != Unvisited) { continue; }
        if (!dfs(i, White)) {
            is_bipartite = false;
        }
    }

    if (is_bipartite) {
        const auto num_white = std::count(colors.cbegin(), colors.cend(), White);
        const auto num_black = N - num_white;
        cout << num_white * num_black - M << endl;
    } else {
        cout << N * (N - 1) / 2 - M << endl;
    }

    return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	string s;
	cin >> s;

	int ans = 0;
	for(int i = 0; i < 1000; i++) {
		string t = to_string(i);
		if(i < 10) t = "00" + t;
		else if(i < 100) t = "0" + t;
		int j = 0, k = 0;
		while(j < n && k < 3) {
			if(s[j] == t[k]) {j++; k++;}
			else j++;
		}
		if(k == 3) ans++;
	}
	cout << ans << endl;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define fore(i, n) for(auto &i : n)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

#pragma GCC optimize ("-O3")

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

struct BipartiteMatching {
    int n, m;
    const int inf = INT_MAX / 2;
    vector<int> match, dist;
    vector<vector<int>> E;

    void init(int _n,int _m){
        n =_n, m =_m;
        E.resize(n + m + 2);
        match.resize(n + m + 2);
        dist.resize(n + m + 2);
    }

    bool bfs() {
        queue<int> que;
        for (int i = 1; i < n + 1; ++i) {
            if (! match[i]) dist[i] = 0, que.push(i);
            else dist[i] = inf;
        }

        for (int i = 1; i < n + 1; ++i) {
            if (!match[i]) dist[i] = 0, que.push(i);
            else dist[i] = inf;
        }

        dist[0] = inf;
        while (! que.empty()) {
            int u = que.front(); que.pop();
            if (u) fore(v, E[u]) if (dist[match[v]] == inf) {
                dist[match[v]] = dist[u] + 1;
                que.push(match[v]);
            }
        }

        return (dist[0] != inf);
    }

    bool dfs(int u) {
        if (u) {
            fore(v, E[u]) if (dist[match[v]] == dist[u] + 1) if (dfs(match[v])) {
                match[v] = u; match[u] = v;
                return true;
            }
            dist[u] = inf;
            return false;
        }
        return true;
    }

    void add(int a, int b) {
        b += n; 
        E[a + 1].push_back(b + 1); 
        E[b + 1].push_back(a + 1);
    }

    int whois(int x) {
        return match[x + 1] - 1;
    }

    int solve() {
        for (int i = 0; i < n + m + 1; ++i) match[i] = 0;
        int res = 0;
        while (bfs()) {
            for (int i = 1; i < n + 1; ++i) {
                if (!match[i] && dfs(i)) res++;
            }
        }
        
        return res;
    }
};

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

    int N, A[101], B[101], C[101], D[101];
    cin >> N;
    rep(i, N) cin >> A[i] >> B[i];
    rep(i, N) cin >> C[i] >> D[i];

    BipartiteMatching bm;
    bm.init(N, N);
    rep(i, N) rep(j, N) {
        if (A[i] < C[j] and B[i] < D[j]) bm.add(i, j);
    } 
    cout << bm.solve() << endl;

    return 0;
}

Measured memory_bytes: 256