akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(),  b[] = new int[n];
		List<Integer> a=new LinkedList<Integer>();
		for (int i = 0; i < n; i++) {
			a.add(sc.nextInt());
			b[i] = -1;
		}
		for (int i = 0; i < n; i++) {
			if(i%2==0) {
				b[i/2]=a.get(a.size()-1);
				a.remove(a.size()-1);
			}else {
				b[n-1-i/2]=a.get(a.size()-1);
				a.remove(a.size()-1);
			}
		}
		for(int i=0;i<n-1;i++) System.out.print(b[i]+" ");
		System.out.println(b[n-1]);
	}
}

Measured memory_bytes: 70100
n=int(input())
l=[]
for i in range(n):
    w=input()
    if len(l)==0:
        l.append(w)
        old_w=w[-1]
    else:
        if (w in l) or (old_w!=w[0]):
            print("No")
            exit()
        else:
            l.append(w)
            old_w=w[-1]
print("Yes")

Measured memory_bytes: 9100
#define _CRT_SECURE_NO_WARNINGS
#define MaxSize 16777215
#include <stdio.h>
#include <stdlib.h>


void insert(char *D, char s[]) {
	int i = -1;
	char c;
	int p = -1;
	while (c = s[++i]) {
		switch (c) {
		case 'A':
			p <<= 2;
			p += 4;
			break;
		case 'C':
			p <<= 2;
			p += 5;
			break;
		case 'G':
			p <<= 2;
			p += 6;
			break;
		case 'T':
			p <<= 2;
			p += 7;
			break;
		}
	}
	D[p] = 'Y';
}

int find(char *D, char s[]) {
	int i = -1;
	char c;
	int p = -1;
	while (c = s[++i]) {
		switch (c) {
		case 'A':
			p <<= 2;
			p += 4;
			break;
		case 'C':
			p <<= 2;
			p += 5;
			break;
		case 'G':
			p <<= 2;
			p += 6;
			break;
		case 'T':
			p <<= 2;
			p += 7;
			break;
		}
	}
	return D[p] == 'Y';
}

int main() {
	char *D = (char *)malloc(sizeof(char) * MaxSize);
	int i;
	for (i = 0; i < MaxSize; ++i) {
		D[i] = 'N';
	}

	char com[7];
	char s[13];
	int n;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%s%s", com, s);
		if (com[0] == 'i') {
			insert(D, s);
		}
		else {
			if (find(D, s)) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}


	free(D);

	return 0;
}

Measured memory_bytes: 16812
while True:
    (a, op, b) = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    elif op == '+':
        print(a + b)
        pass
    elif op == '-':
        print(a - b)
        pass
    elif op == '*':
        print(a * b)
        pass
    else:
        print(a // b)

Measured memory_bytes: 6728
#include<stdio.h>
#include<string.h>
int main()
{
	char a[10],b[10],c[10];
	scanf("%s%s%s",a,b,c);
	int al=strlen(a)-1;
	int bl=strlen(b)-1;
	if(a[al]==b[0]&&b[bl]==c[0]) printf("YES\n");
	else printf("NO\n");
}

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

using namespace std;

typedef long long ll;

int n, x, y, k;
vector <int> adj[2003];
int anss[2003];
int dist[2003];


void bfs(int v)
{
    for (int i = 1 ; i <= n; i++)
        dist[i] = -1;
    
    queue <int> fila;
    fila.push(v);
    dist[v] = 0;

    int aux;
    while(!fila.empty())
    {
        aux = fila.front();
        fila.pop();

        /* if (aux == destination)
            break; */

        int tam = adj[aux].size();
        for (int x = 0; x < tam; x++)
        {
            int neighboor = adj[aux][x];
            if (dist[neighboor] == -1)
            {
                dist[neighboor] = dist[aux] + 1;
                fila.push(neighboor);
            }
        }
            


    }
}


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

    cin >> n >> x >> y;

    for (int i = 1; i < n; i++){
        adj[i].push_back(i + 1);
        adj[i + 1].push_back(i);
    }

    adj[x].push_back(y);
    adj[y].push_back(x);

    for (int i = 1; i <= n; i++){
        bfs(i);
        for (int i = 1; i <= n; i++){
            anss[dist[i]] += 1;
        }
    }

    for (int i = 1; i < n; i++){
        cout << (anss[i] >> 1) << endl;
    }
    
 
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
using ll = long long;

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

int main(){
  int n;
  ll X;
  cin >> n >> X;
  vector<ll> x(n);
  rep(i,n)cin >> x.at(i);
  vector<ll> dif(n);
  rep(i,n){
    if(i==0)dif.at(i) = abs(x.at(i)-X);
    else dif.at(i) = min(abs(x.at(i)-X),abs(x.at(i)-x.at(i-1)));
  }
  sort(dif.begin(),dif.end());
  ll ans = dif.at(0);
  for(int i = 1; i < n; i++){
    ans = gcd(dif.at(i),ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

ll fact[500005];

ll p(ll x, ll n) {
	ll res=1;
	while(n) {
		if(n&1) res=(res*x)%MOD;
		x=(x*x)%MOD;
		n/=2;
	}
	return res;
}

ll nCr(ll n, ll r) {
	ll ans=1,i;
	//ll cut=(n-r);
	//for(i=n;i>n-r;i--) ans=(ans*i)%MOD;
	ans = (ans*fact[n])%MOD;
	ans = (ans*p(fact[r],MOD-2))%MOD;
	ans=(ans*p(fact[n-r],MOD-2))%MOD;
	return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,k,x,i,sum=0;
    cin >> n >> k;
    fact[0]=1;
    for(i=1;i<500005;i++) fact[i]=(fact[i-1]*i)%MOD;
    for(x=0;x<=min(n-1,k);x++) sum=(sum+(nCr(n-1,x)*nCr(n,x))%MOD)%MOD;
    cout << sum << "\n";
    return 0;
}



Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

pii f(pii a, pii b, int x1, int x2){
    b.first+=x1;
    b.second+=x2;
    
    if(a.first>=b.first && a.second>=b.second)return b;
    if(a.first<=b.first && a.second<=b.second)return a;
    abort();
}

struct state{
    int y,x,dir,bs,s;
};

int main(){
    int h,w,a;
    cin>>h>>w>>a;
    vector<string> vs(h);
    rep(i,h)cin>>vs[i];
    
    pii s,g;
    rep(i,h)rep(j,w){
        if(vs[i][j]=='S')s = pii(i,j);
        if(vs[i][j]=='G')g = pii(i,j);
    }
    
    static int dp[101][101][4][11][11];
    rep(i,101)rep(j,101)rep(k,4)rep(l,11)rep(m,11)dp[i][j][k][l][m] = INF;
    dp[s.first][s.second][0][0][0] = 0;
    
    queue<state> que;
    que.push(state{s.first, s.second, 0, 0, 0});
    
    // '\', '/'
    //テ、ツクツ? テ・ツ渉ウ, テ、ツクツ? テ・ツキツヲ
    int dy[]={1,0,-1,0};
    int dx[]={0,1,0,-1};
    
    while(que.size()){
        state q = que.front();
        que.pop();
        
        for(int k = 1;;k++){
            int ddy = q.y+dy[q.dir]*k;
            int ddx = q.x+dx[q.dir]*k;
            
            if( q.dir == 2 && pii(ddy,ddx)==s)break;
            if(pii(ddy,ddx)==s)continue;
            
            if(ddx<0 || ddy<0 || ddx>=w || ddy>=h)break;
            if(vs[ddy][ddx]=='#')break;
            
            int bsnum,snum;
            
            //テヲツ卍づィツィツ暗・ツ崢榲」ツつ甘・ツ崢榲ィツサツ「
            if(q.dir%2==0)  bsnum = 0, snum = 1;
            else            bsnum = 1, snum = 0;
            if( q.bs+bsnum<=a && q.s+snum<=a ){
                if( dp[ddy][ddx][(q.dir+3)%4][q.bs+bsnum][q.s+snum] == INF ){
                    dp[ddy][ddx][(q.dir+3)%4][q.bs+bsnum][q.s+snum] = dp[q.y][q.x][q.dir][q.bs][q.s] + 1;
                    que.push( state{ddy, ddx, (int)(q.dir+3)%4, q.bs+bsnum, q.s+snum} );
                }
            }
            
            //テ・ツ渉催ヲツ卍づィツィツ暗・ツ崢榲」ツつ甘・ツ崢榲ィツサツ「
            if(q.dir%2==1)  bsnum = 0, snum = 1;
            else            bsnum = 1, snum = 0;
            if( q.bs+bsnum<=a && q.s+snum<=a ){
                if( dp[ddy][ddx][(q.dir+1)%4][q.bs+bsnum][q.s+snum] == INF ){
                    dp[ddy][ddx][(q.dir+1)%4][q.bs+bsnum][q.s+snum] = dp[q.y][q.x][q.dir][q.bs][q.s] + 1;
                    que.push( state{ddy, ddx, (int)(q.dir+1)%4, q.bs+bsnum, q.s+snum} );
                }
            }
        }
    }
    
    int ans = INF;
    rep(i,4){
        for(int k=1;;k++){
            int y,x;
            tie(y,x) = g;
            int ddy = y+dy[i]*k;
            int ddx = x+dx[i]*k;
            
            if(ddx<0 || ddy<0 || ddx>=w || ddy>=h)break;
            if(vs[ddy][ddx]=='#')break;

            if( i == 0 && pii(ddy,ddx)==s)break;

            rep(l,a+1){
                rep(m,a+1){
                    ans = min(ans, dp[ddy][ddx][(i+2)%4][l][m]);
                }
            }
        }
    }
    if(ans>2*a)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 23148
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scanner = new Scanner(System.in);


		// 行と列を取得
		int H = scanner.nextInt();
		int W = scanner.nextInt();

		// キャンバスを保持する配列を生成
		String[][] table = new String[H + 2][W + 2];


		// キャンバスを.で初期化
		for (int i = 0; i <= H + 1; i++) {
			for (int j = 0; j <= W + 1; j++) {
				table[i][j] = ".";
			}
		}

		// 標準入力から読み込んだ値をキャンバスに設定
		for (int i = 1; i <= H; i++) {
			String line = scanner.next();
			for (int j = 1; j <= W; j++) {
				table[i][j] = line.substring(j-1, j);
			}
		}

		// 判定
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if (table[i][j].equals("#")) {
					if (table[i - 1][j].equals(".") && table[i + 1][j].equals(".") && table[i][j - 1].equals(".") && table[i][j + 1].equals(".")) {
						System.out.println("No");
						return;
					}
				}
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 21588
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod=1e9+7;

int main(){
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  rep(i,x) cin >> a[i];
  rep(i,y) cin >> b[i];
  rep(i,z) cin >> c[i];
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  sort(c.rbegin(),c.rend());
  priority_queue<pair<ll,vector<int>>> q;
  map<tuple<int,int,int>,int> m;
  q.push({a[0]+b[0]+c[0],{0,0,0}});
  m[make_tuple(0,0,0)]++;
  for(int i=0; i<k; i++){
    pair<ll,vector<int>> p=q.top();
    q.pop();
    cout << p.first << endl;
    vector<int> t=p.second;
    if(t[0]<x-1 && !m[make_tuple(t[0]+1,t[1],t[2])]){
      q.push({a[t[0]+1]+b[t[1]]+c[t[2]],{t[0]+1,t[1],t[2]}});
      m[make_tuple(t[0]+1,t[1],t[2])]++;
    }
    if(t[1]<y-1 && !m[make_tuple(t[0],t[1]+1,t[2])]){
      q.push({a[t[0]]+b[t[1]+1]+c[t[2]],{t[0],t[1]+1,t[2]}});
      m[make_tuple(t[0],t[1]+1,t[2])]++;
    }
    if(t[2]<z-1 && !m[make_tuple(t[0],t[1],t[2]+1)]){
      q.push({a[t[0]]+b[t[1]]+c[t[2]+1],{t[0],t[1],t[2]+1}});
      m[make_tuple(t[0],t[1],t[2]+1)]++;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
import fractions
a,b,c,d = map(int, input().split())

cnt_c = b // c - (a-1) // c
cnt_d = b // d - (a-1) // d
lcm = c * d // fractions.gcd(c, d)
cnt_cd = b // lcm - (a-1) // lcm

mul = cnt_c + cnt_d - cnt_cd

print(b - a + 1 - mul)

Measured memory_bytes: 5048
import sys


def floor_sum(n, m, a, b):
    ans = n*(b//m)
    b %= m
    while True:
        ans += (n-1)*n*(a//m)//2
        a %= m
        if a*n+b < m:
            return ans
        y_max = (a*n + b)//m
        b -= y_max*m  # now we have x_max = -(b//a)
        ans += (n + b//a)*y_max
        b %= a
        m, a, n = a, m, y_max


def main():
    t = int(sys.stdin.buffer.readline())
    for x in sys.stdin.buffer.readlines():
        n, m, a, b = map(int, x.split())
        res = floor_sum(n, m, a, b)
        print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 78184
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll n,m;
bool f(){
    return (n==0)&&(m==0);
}

bool cmp(const pair<ll,ll> &a,const pair<ll,ll> &b) {
	if(a.second!=b.second)return a.second>b.second;
	else return a.first>b.first;
}

int main(void){
    while(true){
        cin>>n>>m;
        if(f())break;
        vector<P>p(n);
        for(ll i=0;i<n;i++){
            cin>>p[i].first>>p[i].second;
        }
        ll ans = 0;
        sort(p.begin(),p.end(),cmp);
        for(ll i=0;i<n;i++){
            if(m>=p[i].first){
                m-=p[i].first;
            }
            else{
                if(m==0){
                    ans+=p[i].first*p[i].second;
                }
                else{
                    ans+=(p[i].first-m)*p[i].second;
                    m=0;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}



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

bool isZero(int x) {
    return x == 0;
}

int main() {
    constexpr int ROWS = 3;
    constexpr int COLS = 3;

    valarray<int> as(ROWS * COLS);
    copy_n(istream_iterator<int>(cin), as.size(), begin(as));

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;

        for (int& a : as) {
            if (a == b) {
                a = 0;
            }
        }
    }

    bool bingo = false;
    for (int i = 0; i < 3; i++) {
        valarray<int> row = as[slice(i * COLS, ROWS, 1)];
        bingo |= all_of(begin(row), end(row), isZero);
        valarray<int> col = as[slice(i, COLS, ROWS)];
        bingo |= all_of(begin(col), end(col), isZero);
    }
    valarray<int> lt2rb = as[slice(0, ROWS, COLS + 1)];
    bingo |= all_of(begin(lt2rb), end(lt2rb), isZero);
    valarray<int> rt2lb = as[slice(COLS - 1, ROWS, COLS - 1)];
    bingo |= all_of(begin(rt2lb), end(rt2lb), isZero);

    cout << (bingo ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int ss = scanner.nextInt();
        int h = ss / 3600;
        int m = ss % 3600 / 60;
        int s = ss % 3600 % 60;
        System.out.printf("%d:%d:%d\n",h, m, s);
	}

}


Measured memory_bytes: 26352
#include<iostream>
using namespace std;
/*
	1.用NIL结点来表示特殊结点
	2.中序 ： 前 中 右
	3.前序： 中 左 右
*/
struct Tree
{
	int key;
	Tree* parent, * left, * right;
};
Tree* root, * NIL;
int find(int key) {
	Tree* b = root;
	while (b != NIL)
	{
		if (b->key == key) return 1;
		else if (b->key > key) b = b->left;
		else
		{
			b = b->right;
		}
	}
	return 0;
}
void insert(Tree* k) {
	Tree* d = root;
	Tree* m = d;
	while (d != NIL)
	{
		m = d;
		if (k->key > d->key) {
			d = d->right;
		}
		else {
			d = d->left;
		}
	}
	k->parent = m;
	if (k->key > m->key) {
		m->right = k;
	}
	else {
		m->left = k;
	}
}
void midle(Tree* t) {
	if (t == NIL) return;
	midle(t->left);
	cout << " " << t->key;
	midle(t->right);
}
void pre(Tree* t) {
	if (t == NIL) return;
	cout << " " << t->key;
	pre(t->left);
	pre(t->right);
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string m;
		cin >> m;
		if (m == "insert") {
			int key;
			cin >> key;
			Tree* k = new Tree();
			k->left = NIL;
			k->right = NIL;
			k->key = key;
			k->parent = NIL;
			if (root == NULL) {
				root = k;
			}
			else {
				insert(k);
			}
		}
		else if(m=="print"){
			midle(root);
			cout << endl;
			pre(root);
			cout << endl;
		}
		else {
			int n;
			cin >> n;
			if (find(n))cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 21812
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string s;
	ll q;
	cin >> n >> s >> q;
	vector<ll> acm(n, 0);
	acm[0] = 0;
	FOR(i,1,n) {
		acm[i] = acm[i - 1];
		if(s[i] == 'M') acm[i]++;
	}
	REP(i,q) {
		ll k;
		cin >> k;
		queue<ll> q;
		ll ans = 0;
		ll sum = 0;
		REP(j,n) {
			while(!q.empty() && j - q.front() >= k) {
				ll dec = acm[j - 1];
				if(q.front() > 0) dec -= acm[q.front() - 1];
				sum -= dec;
				q.pop();
			}
			if(s[j] == 'D') {
				q.push(j);
			}
			else if(s[j] == 'M') {
				sum += (ll)q.size();
			}
			else if(s[j] == 'C') {
				ans += sum;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 17208
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
long long n,k,he;
int a[10000];
int main()
{
cin>>n>>k;
for(int i=1; i<=n; i++)
{
	cin>>a[i];
	he+=a[i];
}
sort(a+1,a+1+n);
for(int i=1; i<=n-k; i++)
{
	he-=a[i];
}
cout<<he<<endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<std::vector<int>> G(N);
  for(int i = 0; i < N-1; ++i) {
    int a, b; std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int r = -1;
  for(int i = 0; i < N; ++i) if(G[i].size() > 2) {
    r = i; break;
  }
  if(r < 0) fin(1); // line graph
  auto dp = mk2d(2, N, N+1);
  auto dfs = [&](auto&& f, int v, int p)->void {
    int sum1 = N+1, sum = 0, r0 = -1;
    for(int c: G[v]) if(c != p) {
      f(f, c, v);
      r0 = std::max(r0+1, dp[0][c]);
      if(dp[0][c] == 0) sum1 = std::min(sum, sum1+dp[1][c]);
      sum += dp[1][c];
      if(dp[0][c] > 0) sum1 = std::min(sum, sum1+dp[1][c]);
    }
    dp[0][v] = (r0>0? N+1: 0);
    dp[1][v] = (sum==0||sum1==0)? 1: sum1;
  };
  dfs(dfs, r, -1);
  fin(dp[1][r]);
  return 0;
}


Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}

		int count = 0;
		for (int i = 0; i < q; i++) {
			for (int j = 0; j < n; j++) {
				if (t[i] == s[j]) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);

	}

}



Measured memory_bytes: 40508
#include <iostream>
#include <vector>
#include <string>
using namespace	std;
int main(){

  vector <string> a,b;
  string tmp;
  int n,i;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>tmp;
    a.push_back(tmp);
  }
  b.assign(a.begin(),a.end());
  for(i=0;i<n-1;i++) for(int j=n-2;j!=i-1;j--) if(a[j][1]>a[j+1][1]) swap(a[j],a[j+1]);
  for(i=0;i<n-1;i++) cout<<a[i]<<" ";
  cout<<a[n-1]<<endl<<"Stable"<<endl;

  for(i=0;i<n-1;i++){
    int now,minnum=101;
    for(int j=i;j<n;j++) if(minnum>b[j].at(1)-'0'){
        now=j;
        minnum=b[j].at(1)-'0';
      }
    if(i!=now)  swap(b[i],b[now]);
  }

  for(i=0;i<n-1;i++) cout<<b[i]<<" ";
  cout<<b[n-1]<<endl;
  if(a==b) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;

  return 0;

}

Measured memory_bytes: 3196
inputdata = input()
up = int(inputdata[0:2])
down = int(inputdata[2:4])
if 0 < up <= 12:
  if 0 < down <=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 0 < down <= 12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{

  int a,b,c,d,L,R;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  L=a+b;
  R=c+d;
  if(L<R)
    printf("Right\n");
  else if(L>R)
    printf("Left\n");
  else
    printf("Balanced");
  
  return 0;
}


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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n, x, m, ans = 0;
	cin >> n >> x >> m;
	vector <ll> rm (m, -1);
	for (i = 1; i < n && rm[x] == -1; ++i)
		ans += x,
		rm[x] = (x*x)%m,
		x = rm[x];
	if (i == n)
	{
		ans += x;
		cout << ans << '\n';
		return 0;
	}
	ll per = 1, qnt = x, ax = x;
	for (ax = rm[x]; ax != x; ax = rm[ax], ++per)
		qnt += ax;
	ans += qnt*((n-i)/per);
	for (j = 0; j < (n-i)%per; ++j)
		ans += x,
		x = rm[x];
	ans += x;
	cout << ans << '\n';
	//trav (a, rm) cout << a << ' ';
	//cout << '\n';

	return 0;
}



Measured memory_bytes: 3984
from sys import stdin
from itertools import permutations
from collections import Counter


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    graph = []
    for i in range(M):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        graph.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    con = [[] for i in range(N)]
    for a,b in graph:
        a -= 1
        b -= 1
        con[a].append(b)
        con[b].append(a)
    for i, _ in enumerate(con):
        con[i] = Counter(con[i])

    cnt = 0
    for cand in permutations(range(1,N)):
        _cand = (0,)+cand
        mult = 1
        for v,nv in zip(_cand[:-1],_cand[1:]):
            try:
                mult *= con[v][nv]
            except:
                mult = 0
                break
        cnt += mult
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 40304
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
dst = [ [] for i in range(n) ]
for i in range(m):
    a,b = inm()
    a -= 1
    b -= 1
    dst[a].append(b)
    dst[b].append(a)

ddprint(dst)

x = [ len(z)%2 for z in dst ]
if 1 in x:
    print('No')
    exit()

s = sum([ len(z) - 2 for z in dst ])
if s >= 6:
  print('Yes')
  exit()
if s <= 2:
  print('No')
  exit()

# now s == 4
i4 = [ i for i in range(n) if len(dst[i]) >= 4 ]
ddprint('i4:')
ddprint(i4)
if len(i4) == 1:
  print('Yes')
  exit()

# 2 nodes with 4 arcs : A & B
#    1    8
#    |    |
# 2--+4--5+--7
#   A|    |B
#    3    6
# if all paths are A->B, no 3 circuits

a = i4[0]
b = i4[1]
alla2b = True
for i in range(4):
  prev = a
  x = dst[a][i]
  while x not in [a,b]:
    nxt = dst[x][1] if dst[x][0] == prev else dst[x][0]
    prev = x
    x = nxt
  ddprint('dai {} x now {}'.format(dst[a][i],x))
  if x == a:
      alla2b = False
      break

print('Yes' if not alla2b else 'No')


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	VL n(3);
	for (int i = 0; i < 3; i++) {
		cin >> n[i];
	}
	SORT(n);
	int a = 0;
	for (int i = 0; i < 3; i++) {
		a += n[2] - n[i];
	}
	if (a % 2 == 1) {
		a += 3;
	}
	cout << a/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,p=0;
	cin >> N;
	vector<int> A(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	while (true) {
		for (size_t i = 0; i < N; i++)
		{
			if (A.at(i)%2)
			{
				cout << p;
				return 0;
			}
			A.at(i) /= 2;
		}
		p++;
	}
	cout << p;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int count = 0;
  
  for (int i = 0; i <= A; ++i) {
    for (int j = 0; j <= B; ++j) {
      for (int k = 0; k <= C; ++k) {
        int total = i * 500 + j * 100 + k * 50;
        if (X == total) ++count;
      }
    }
  }
  
  cout << count << endl;
}

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

int main(){
    int N;
    int cR =0;
    int cB =0;
    char s;
    cin >> N;
    for(int i =0;i<N;++i){
        cin >> s;
        if(s =='R'){
            ++cR;
        }
        else if(s =='B'){
            ++cB;
        }
    }
    if(cR > cB){
        cout << "Yes" <<endl;
    }
    else {
        cout << "No" <<endl;
    }
}

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

using namespace std;
using ll =long long;
using db = double;

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; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	int n; cin >> n;
	ll a[100100][3];
	rep(i,n){ 
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	vector<vector<ll>> dp(100100,vector<ll> (3));
	dp[0][0] = dp[0][1] = dp[0][2] = 0;
	for(int i =  1; i < n + 1 ; i ++){
		rep(j,3){
			rep(k,3){
				if(j!=k){
					chmax(dp[i][j],dp[i-1][k]+a[i-1][k]);
				}
			}
		}
	}
	ll ans = 0;
	rep(i,3){
		chmax(ans, dp[n][i]);
	}
	cout << ans << endl;

	

}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll, ll>
#define vpl vector<pll>
#define sll set<ll>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define MP(a, b) make_pair(a, b)
#define ff first
#define ss second

using namespace std;

const ll inf = numeric_limits<ll>::max();

int main() {
    ll n, x;
    cin >> n >> x;
    vll v(n); FOR(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    ll res = 0;
    FOR(i, n) {
        res = i;
        if (v[i] > x)
            break;
        else {
            if (v[i] == x) {
                res++;
                break;
            }
            x -= v[i];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n; cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  map<int,int>kazu;
  for(int x:a){
    if(kazu.count(x)){
      kazu[x]++;
    }else{
      kazu[x]=1;
    }
  }
  int count=0;
  auto begin = kazu.begin(), end = kazu.end();
  for (auto iter = begin; iter != end; iter++) {  
    if(iter->second%2==1)count++;
      // first: key, second: value
        //cout << "key = " << iter->first << "\n";
        //cout << "value = " << iter->second << "\n";
    }
  cout<<count<<endl;
  return 0;
}

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

multiset<int> S;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        S.insert(x);
    }
    int ans=0;
    int y;
    while(!S.empty())
    {
        int x=*S.rbegin();
        y=1;
        S.erase(S.find(x));
        while(y<=x)
            y*=2;
        auto it=S.find(y-x);
        if(it!=S.end()){
            S.erase(it);
            ans++;
        }
    }
    cout<<ans;

}


Measured memory_bytes: 9600
#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 argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, P; cin >> N >> P;
    string S; cin >> S;
    map<ll, ll> mp;
    vector<ll> beki10mod(N, 0);

    if (P == 2 || P == 5) {
        ll ans = 0;
        REP(i, N) {
            if ((S[i] - '0') % P == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    REP(i, N) {
        if (i == 0) beki10mod[i] = 1 % P;
        else beki10mod[i] = (beki10mod[i-1] * 10) % P;
    }
    ll ruiseki = 0;
    REP(i, N) {
        ruiseki += ((S[N-1-i] - '0') * beki10mod[i]) % P;
        ruiseki %= P;
        mp[ruiseki]++;
    }
    ll res = mp[0];
    ruiseki = 0;
    REP(i, N) {
        ruiseki += ((S[N-1-i] - '0') * beki10mod[i]) % P;
        ruiseki %= P;
        mp[ruiseki]--;
        res += mp[ruiseki];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2580
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define REP(i, lim) for(int i=0;i<lim;++i)
#define REPP(i, lim) for(int i=1;i<=lim;++i)
#define DEC(i, lim) for(int i=lim;i>=1;--i)
#define FOR(i,l,r)  for(int i=l;i<r;++i)
#define deBug cout<<"==================================="<<endl;
#define clr(s) memset(s, 0, sizeof(s))
#define lowclr(s) memset(s, -1, sizeof(s))
const int MAXN = 1000055;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const db eps = 1e-9;

inline int sgn(db x) { return x<-eps ? -1 : x>eps; }
inline db sqr(db x) { return x*x; }



struct P {
    // information
    P() {}
    P(db _x, db _y) : x(_x), y(_y) {}
    db x, y;

    // operation
    P operator + (P p)   const{ return P(x+p.x, y+p.y); }
    P operator - (P p)   const{ return P(x-p.x, y-p.y); }
    P operator * (db d)  const{ return P(x*d, y*d); }
    P operator / (db d)  const{ return P(x/d, y/d); }

    db dot(P p) { return x * p.x + y * p.y; } // 点积
    db det(P p) { return x * p.y - y + p.x; } // 叉积

    // other
    void input() { scanf("%lf%lf", &x, &y); }
    void print() { printf("(%lf, %lf)\n", x, y); }

    db dis(P p) { return sqrt(sqr(x-p.x) + sqr(y-p.y)); }
    db dis2(P p) { return sqr(dis(p)); }
};

P getProjection(P a, P b, P p) {
    // (p1, q) 在 (p1, q2) 上的投影点
    P dir = b-a;
    return a + dir * ( dir.dot(p-a) / a.dis2(b) );
}

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    std::ios::sync_with_stdio(false); cin.tie(0);

    P a, b;
    a.input(); b.input();
    int Q;
    scanf("%d", &Q);
    while(Q--)
    {
        P p;
        p.input();
        P ans = getProjection(a, b, p);
        printf("%.10lf %.10lf\n", ans.x, ans.y);
    }


    return 0;
}


Measured memory_bytes: 3248
n,k=map(int,input().split())
md=10**9+7
n1=n-k+1
n2=k-1
com1=[]
com2=[]
c1=1
c2=1
for i in range(k+1):
    com1+=[c1]
    com2+=[c2]
    c1=c1*(n1-i)//(i+1)
    c2 = c2 * (n2 - i) // (i + 1)
for i in range(1,k+1):
    ans=com1[i]*com2[i-1]%md
    print(ans)

Measured memory_bytes: 3828
function main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0], 10);
  let ary = args[1].split(' ').map(n => parseInt(n, 10));
  let count = 0;
  let ans = 0;
  
  ary = ary.sort((a, b) => a - b);
  
  if (N === 1) {
  	ans = ary[1];
  } else {
    while(true) {
      // console.log(N + (2 * count));
      ans += ary[N + (2 * count)];
      count++;
      if (count === N) { break; }
    }
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 56716
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	string s;
	vector<pair<char, bool>> c(26);
	c[0].first = 'a';
	for (int i = 1; i <= 25; i++){
		c[i].first = c[0].first + i;
	}
	cin >> s;

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < s.length(); j++) {
			if (c[i].first == s[j]) {
				c[i].second = true;
			}
		}
	}

	for (int i = 0; i < 26; i++) {
		if (c[i].second == false) {
			cout << c[i].first << endl;
			return 0;
		}
	}

	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<string>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    int sqr=(int)sqrt(N)+1;
    int ans=100;
    for(int i=1; i<sqr; i++){
        if(N%i==0){
            int a=N/i;
            string s1=to_string(a);
            string s2=to_string(i);
            int len1 = s1.length();
            int len2 = s2.length();
            if(len1<ans){
                ans=len1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n;

int LinearSearch(vector<int> S, int x) {
	S.push_back(x);
	int i = 0;
	while (S[i] != S[n]) {
		i++;
		if (i == n) {
			return 0;
		}
	}
	S.pop_back();
	return 1;
}


int main() {
	int  q;
	cin >> n;
	vector<int> S;
	vector<int> T;
	int k;
	for (int i = 0; i < n; i++) {
		cin >> k;
		S.push_back(k);
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> k;
		T.push_back(k);
	}
	int ans = 0;
	for (int i = 0; i < T.size(); i++) {
		ans += LinearSearch(S, T[i]);
	}
	cout << ans << endl;

}


Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
vector<int> ans;
vector<vector<PII> >  map;
void func(int place, int bu, int sum){
    ans[place] = sum%2;
    sum%=2;
    REP(i,map[place].size()){
        PII d = map[place][i];
        if(d.first == bu)continue;
        func(d.first, place, d.second+sum);
    } 
}
int main(){
    int N;
    cin >> N;
    ans.resize(N+1);
    map.resize(N+1);
    REP(i, N-1){
        int a, b, c;
        cin >> a >> b >> c;
        map[a].push_back(PII(b, c));
        map[b].push_back(PII(a, c));
    }
    func(1, -1, 0);
    REPA(i, N+1){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8192
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args)throws java.lang.NumberFormatException{
    Scanner scan=new Scanner(System.in);
    Deque<Integer> stack=new ArrayDeque<>();

    while(scan.hasNext()){
      String op=scan.next();
      if(isNum(op)){
        stack.addFirst(Integer.parseInt(op));
      }else if(op.equals("+")){
        int x=stack.removeFirst();
        int y=stack.removeFirst();
        stack.addFirst(y+x);
      }else if(op.equals("-")){
        int x=stack.removeFirst();
        int y=stack.removeFirst();
        stack.addFirst(y-x);
      }else if(op.equals("*")){
        int x=stack.removeFirst();
        int y=stack.removeFirst();
        stack.addFirst(y*x);
      }
    }

    System.out.println(stack.removeFirst());
  }
  static boolean isNum(String s){
    try{
      Integer.parseInt(s);
      return true;
    }catch(NumberFormatException e){
      return false;
    }
  }
}


Measured memory_bytes: 26216
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
using namespace std;

const int INF = 1e+9;
typedef pair<vector<int>, int> P;

int d[] = {-1, 1, 4, -4};

int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
	vector<int> init{0, 1, 2, 3, 4, 5, 6, 7};
	map<vector<int>, int> visited;
	
	queue<P> que;	
	que.push(P(init, 0));
	while(!que.empty()){
		P p = que.front();
		que.pop();
		vector<int> v = p.first;
		if(visited[v])
			continue;
		visited[v] = p.second;
		int zero;
		for(int i = 0; i < 8; ++i){
			if(v[i] == 0){
				zero = i;
				break;
			}
		}
		for(int i = 0; i < 4; ++i){
			if(zero == 3 && i == 1)
				continue;
			if(zero == 4 && i == 0)
				continue;
			int next = zero + d[i];
			if(next >= 0 && next < 8){
				int tmp = v[next];
				v[next] = v[zero];
				v[zero] = tmp;
				que.push(P(v, p.second + 1));
				tmp = v[next];
				v[next] = v[zero];
				v[zero] = tmp;
			}
		}
	}
	vector<int> vec;
	vec.resize(8);
	while(cin >> vec[0]){
		for(int i = 1; i < 8; ++i){
			cin >> vec[i];
		}
		if(vec == init)
			cout << "0" << endl;
		else{
			cout << visited[vec] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3876
a,b,c = [input() for i in range(3)]
sa = 'a'
for i in range(1796):
  try:
    if sa ==  'a':
      sa = a[0]
      a = a[1:]

    elif sa ==  'b':
      sa = b[0]
      b = b[1:]

    elif sa ==  'c':
      sa = c[0]
      c = c[1:]
  except:
    print(sa.upper())
    break

Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int AGC(int a, int b, int c){
	if(a == 0 && b == 2 && c == 1){
		return 1;
	}
	else{
		return 0;
	}
}

int NG(int a, int b, int c, int d){
	return AGC(a, b, c) | AGC(b, c, d);
}

int is_banned(int x){
	int a = x / 64, b = (x % 64) / 16, c = (x % 16) / 4, d = x % 4;
	return NG(a, b, c, d) | NG(b, a, c, d) | NG(a, c, b, d) | NG(a, b, d, c);
}

signed main(){
	int N, i, j, k;
	scanf("%lld", &N);
	if(N == 3){
		printf("61\n");
		return 0;
	}
	vector<vector<int>> dp(N, vector<int>(256, 0));
	for(j = 0; j < 256; j++){
		dp[3][j] = 1 - is_banned(j);
	}
	for(i = 3; i < N - 1; i++){
		for(j = 0; j < 256; j++){
			for(k = 0; k < 4; k++){
				int l = (j * 4 + k) % 256;
				if(is_banned(l) == 0){
					dp[i + 1][l] = MOD(dp[i + 1][l] + dp[i][j]);
				}
			}
		}
	}
/*	for(i = 0; i < N; i++){
		printf("dp[%lld]:\n", i);
		for(j = 0; j < 256; j++){
			int x = j;
			int a = x / 64, b = (x % 64) / 16, c = (x % 16) / 4, d = x % 4;
			printf("(%lld, %lld, %lld, %lld) = %lld\n", a, b, c, d, dp[i][j]);
		}
		printf("\n");
	}
*/	int ans = 0;
	for(j = 0; j < 256; j++){
		ans = MOD(ans + dp[N - 1][j]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int d;
long int g;
int p[10];
int c[10];
int main(){
	cin >> d >> g;
	for(int i = 0;i < d;i++){
		cin >> p[i] >> c[i];
	}
	long int count = 0;
	long int count2 = 0;
	long int ans = 20000000;
	int w;
	int x;
	for(int i = 0;i < (1 << d);i++){
		count = 0;
		count2 = 0;
		for(int j = 0;j < d;j++){
			if((i >> j) & 1){
				count += ((d - j) * 100) * p[d - j - 1] + c[d - j - 1];
				count2 += p[d - j - 1];
			}
		}
		if(count >= g){
			ans = min(ans, count2);
		}else{
			for(int k = 0;k < d;k++){
				if(!((i >> k) & 1)){
					w = k;
					x = ((g - count) - 1) / ((d - w) * 100) + 1;
					if(x < p[d - w - 1]){
						ans = min(ans, count2 + x);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
U = list(input())
input()

mod = 1000000007

if n == 1:
  print(3)
  exit()

idx = 0
li = []
while idx < len(U) - 1:
  if U[idx] == U[idx + 1]:
    li.append(2)
    idx += 1
  else:
    li.append(1)
  idx += 1
if U[-1] != U[-2]:
  li.append(1)

ans = 1
pre = li[0]

if pre == 1:
  ans = ans * 3 % mod
else:
  ans = ans * 6 % mod
  
for i in li[1:]:
  if pre == 1:
    ans = ans * 2 % mod
  else:
    if i == 2:
      ans = ans * 3 % mod
  pre = i

print(ans)

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<set<int>> B(N);
  set<int> mig={512411};
  int a,b;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    a--; b--;
    B[a].insert(b);
  }
  int cnt=0;
  for(int i=0;i<N;i++){
    auto migit=mig.begin();
    if(*migit==i){
      mig={};
      cnt++;
    }
    auto it=B[i].begin();
    int bs=B[i].size();
    while(bs){
      mig.insert(*it);
      it++; bs--;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define db double
#define RE register
#define ll long long
#define P 1000000007
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define pb(x) push_back(x)
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define getc(a) scanf("%s",a+1)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
int main()
{
//	freopen("1.in","r",stdin);
	int a,b;
	get(a);get(b);
	if(b>=a) puts("unsafe");
	else puts("safe");
	return 0;
}





Measured memory_bytes: 3636
#ifdef __cplusplus
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#endif

#define rep(l, end) for(ll l = 0; l < (end); ++l)
#define rep4(l, start, end, step) for (ll l = (start); l < (end); l += (step))
 
#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF_SHORT (1 << 30)
#define INF_SHORT_NEG (INF * -1)
#define INF (1LL << 62)
#define INF_NEG (INF_LONG * -1L)

typedef long long ll;
typedef char str255[256];
ll StrLen(char *s) { for(ll ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
ll StrDel(char *s, ll n) { ll l = StrLen(s); s[l - n + 1] = '\0'; return l - n; }

ll NumDigits(ll l){ char s[32]; return sprintf(s, "%lld", l); }

ll is1stAns = 1;
#ifdef __cplusplus
template <class T> 
void print(T t) { if (is1stAns) cout << t, is1stAns = 0; else cout << " " << t; }
#else
void printI(int    i) { if (is1stAns) printf(  "%d", i), is1stAns = 0; else printf(  " %d", i); }
void printL(ll     l) { if (is1stAns) printf("%lld", l), is1stAns = 0; else printf(" %lld", l); }
void print (ll     l) { if (is1stAns) printf("%lld", l), is1stAns = 0; else printf(" %lld", l); }
void printD(double d) { if (is1stAns) printf("%.9f", d), is1stAns = 0; else printf(" %.9f", d); }
void printC(char   c) { if (is1stAns) printf(  "%c", c), is1stAns = 0; else printf(  " %c", c); }
void printS(char  *s) { if (is1stAns) printf(  "%s", s), is1stAns = 0; else printf(  " %s", s); }
#endif

#ifndef __cplusplus
ll min(ll a, ll b) { if (a < b) return a; else return b; }
ll max(ll a, ll b) { if (a > b) return a; else return b; }
#endif

signed main()
{
#ifdef __cplusplus
    cout << fixed << setprecision(9);
#endif

    ll N; scanf("%lld", &N);
    ll *h = (ll *)malloc(sizeof(ll) * (N + 9)); rep(i, N) scanf("%lld", &h[i]);
    ll *dp = (ll *)malloc(sizeof(ll) * (N + 9)); rep(i, N + 9) dp[i] = INF;
    
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    rep4(i, 2, N, 1){
        ll next1 = dp[i - 1] + abs(h[i] - h[i - 1]);
        ll next2 = dp[i - 2] + abs(h[i] - h[i - 2]);
        dp[i] = min(next1, next2);
    }

    printf("%lld\n", dp[N - 1]);
    
    free(dp);
    free(h);
    
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;
    if (n == 1)
    {
        cout << m;
        return 0;
    }
    ll odp = 1;
    vector<ll> D;
    for (int d = 2; d * d <= m; ++d)
    {
        if (m % d == 0)
        {
            D.push_back(d);
            D.push_back(m / d);
        }
    }
    for (int i = 0; i < D.size(); ++i)
        if (n * D[i] <= m)
            odp = max(odp, D[i]);
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
/////////////////////////(๑•﹏•๑｀)/////////////////////////
int main() {
	int A1,A2,A3;
	SCD3(A1,A2,A3);

	int A,B;
	A = min({A1,A2,A3});
	B = max({A1,A2,A3});
	PRINTD(B-A);
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int mxpass,mxdelay;
int t[MAXN];

void run() {
	scanf("%d%d%d",&n,&mxpass,&mxdelay); REP(i,n) scanf("%d",&t[i]); sort(t,t+n);
	int s=-1,ret=0;
	REP(i,n) {
		if(s==-1||i-s+1>mxpass||t[i]>t[s]+mxdelay) { s=i; ++ret; }
	}
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 640