akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

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

const int INF = 1 << 30;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return ((y%4==0&&y%100!=0)||y%400==0);
}

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%3d", a[i][j]);}puts("");}puts("-----------------------------------------");

int main()
{
	string sent;
	int ans = 0;
	while(cin >> sent)
	{
		string cmp = sent;
		reverse(sent.begin(), sent.end());
		if(sent == cmp)
				ans++;
	}
	cout << ans << endl;
}

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

int main()
{
    double x;
    cin >> x;
    double ans;
    ans = 2 * x;
    ans *= 3.1415;
    cout << ans << endl;
}

Measured memory_bytes: 3788
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s1,s2;
	cin >> s1 >> s2;
	int n1 = s1.length();
	int n2 = s2.length();
	vector <vector<int> > dp(n1+1,vector <int> (n2+1,0));
	for(int i=0;i<n1;i++)
	{
		for(int j=0;j<n2;j++)
		{
			if(s1[i]==s2[j])
			{
				dp[i+1][j+1]=1+dp[i][j];
			}
			else
			{
				dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
			}
		}
	}
	int a=n1;
	int b=n2;
	vector <char> res;
	while (a>0 && b>0)
	{
		if(dp[a][b]==dp[a-1][b])
		{
			a-=1;

		}
		else if(dp[a][b]==dp[a][b-1])
		{
			b-=1;
		}
		else
		{
			a-=1;
			b-=1;
			res.push_back(s1[a]);
		}
	}
	reverse(res.begin(),res.end());
	for(auto a:res)
		cout << a;
}

Measured memory_bytes: 35584
#include<stdio.h>

int main (){

  int a,b,t,y,u;
  
  scanf("%d %d" ,&a,&b);
  
  t=a+b;
  y=a-b;
  u=a*b;
  
  if(t>=y){
    if(t>u)printf("%d",t);
    else{printf("%d",u);}
  }
  
  else if(t<=y){
    if(y>u)printf("%d",y);
    else{printf("%d",u);}
    
  }
  
  return 0;
    
  }


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int asc(const void *b, const void *a) {
  return *(int *)a - *(int *)b;
}

int main()
{
    int n,k,l[50];

    scanf("%d %d",&n,&k);
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d",&l[i]);
    }
    

    qsort(l,n,sizeof(int),asc);
    int ans = 0;
    for (i = 0; i < k; i++)
    {
        ans += l[i];
    }
    
    printf("%d",ans);
}

Measured memory_bytes: 128
s0 = (input())
t = (input())

flag = False

ans = ""
lt = len(t)
for i in range(len(s0)-len(t) + 1):

#	print (i)
#	print (s0[i:i+lt])

	flag2= True
	for j in range(lt):
		if s0[i+j] != t[j] and s0[i+j] != "?":
			flag2 = False
			break
	if flag2:
		flag = True
		temp = s0[:i] + t + s0[i+lt:]
		temp = temp.replace('?', 'a')
		if ans == "" or temp < ans:
			ans = temp

if(flag == False):
	print ("UNRESTORABLE")
else:
	print (ans)


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

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

  int k;cin>>k;
  ll ans=0;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
        ans+=__gcd(__gcd(a,b),c);
      }
    }
  }
  cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 3592
N,K = map(int,input().split())
P = [0 for i in range(N)]
for i in range(K):
    a = int(input())
    b = list(map(int,input().split()))
    for j in range(a):
      P[b[j]-1] = 1 
m = 0   
for i in range(N):
    if P[i] == 0:
        m += 1
print(m)

Measured memory_bytes: 9132
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    while(1)
    {
        int a,b,c={};
        cin>>a>>b>>c;
        if(a==-1&&b==-1&&c==-1) break;
        else if(a==-1||b==-1)cout<<"F"<<endl;
        else if(a+b>=80)cout<<"A"<<endl;
        else if(a+b<80&&a+b>=65)cout<<"B"<<endl;
        else if(a+b<65&&a+b>=50)cout<<"C"<<endl;
        else if(a+b<50&&a+b>=30){
            if(c>=50)cout<<"C"<<endl;
            else cout<<"D"<<endl;
        }
        else cout<<"F"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3108
// B - Grid Compression
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int H,W; cin>>H>>W;
	vector<string> A(H);
	rp(i, 0, H) cin>>A[i];

	vector<bool> row(H, false), col(W, false);
	rp(h, 0, H) rp(w, 0, W)
		if(A[h][w] == '#'){ row[h] = true; break; }
	rp(w, 0, W) rp(h, 0, H)
		if(A[h][w] == '#'){ col[w] = true; break; }

	rp(h, 0, H){
		if(row[h]){
			rp(w, 0, W) if(col[w]) cout<<A[h][w];
			puts("");
		}
	}
}

Measured memory_bytes: 256
import fractions
 
A, B, C, D = map(int, input().split())
 
A -= 1
lcm=C*D // fractions.gcd(C, D)
 
ex = A - (A // C + A // D - A // lcm)
num = B - (B // C + B // D - B // lcm)

print(num-ex)

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

int main() {
  int a;
  int b;
  cin >> a >> b;
  if (a > b){
    for(int i = 0;i < a;i++){
      cout << b;}
  }
 else{
   for(int i = 0;i < b;i++){
      cout << a;}
 }
}

Measured memory_bytes: 256
while 1:
	try:
		s,t = raw_input(),raw_input()
		if len(s) < len(t): s,t = t,s
		ans = 0
		for sp in range(len(t)):
			if len(t) - sp <= ans:
				break
			for L in range(ans+1,len(t)-sp+1):
				if t[sp:sp+L] in s:
					ans = L
				else:
					break
		print ans
	except:
		break

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

const int N = 1005;

int n;
int a[N][N];
int idx[N];

bool waiting[N][N];

int main() {
  scanf("%d", &n);
  
  vector<int> toCheck;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n-1; ++j) {
      scanf("%d", &a[i][j]);
      --a[i][j];
    }
    idx[i] = 0;
    toCheck.push_back(i);
  }
  
  int day = 0;
  bool can = true;
  while (can) {
    can = false;
    
    vector<int> ncheck;
    for (int u: toCheck) {
      int v = a[u][idx[u]];
      if (v < u) swap(u, v);
      
      if (waiting[u][v]) {
        can = true;
        waiting[u][v] = false;
        
        ++idx[u], ++idx[v];
        if (idx[u] < n-1) ncheck.push_back(u);
        if (idx[v] < n-1) ncheck.push_back(v);
      } else {
        waiting[u][v] = true;
      }
    }

    toCheck = ncheck;
    if (can) ++day;
  }
  
  for (int i = 0; i < n; ++i) {
    if (idx[i] != n-1) day = -1;
  }
  
  printf("%d\n", day);
  return 0;
}


Measured memory_bytes: 5120
n = int(input())

a = 0
w = 0
t = 0
r = 0
for _ in range(n):
    s = str(input())
    if s == "AC":
        a += 1
    elif s == "WA":
        w += 1
    elif s == "TLE":
        t += 1
    elif s == "RE":
        r += 1
    
print("AC x "+str(a))
print("WA x "+str(w))
print("TLE x "+str(t))
print("RE x "+str(r))


Measured memory_bytes: 9204
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
char a[7];

int main()
{
	scanf("%s", a);
	int len = strlen(a);
	int flag = 0;
	for (int i = 0; i < len; i++){
		if (a[i] == 'A'){
			if (a[i + 1] == 'C'){
				printf("Yes\n");
				flag = 1;
				break;
			}
		}
	}
	if (!flag)
		printf("No\n");

	return 0;
}

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

import sys
def input(): return sys.stdin.readline().strip()

# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)

N = int(input())
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

memo = [0] * (N+1)
def dfs(cur, prev, dist):
    memo[cur] = dist
    for nxt, cost in nodes[cur]:
        if nxt == prev:
            continue
        dfs(nxt, cur, dist+cost)

Q, K = map(int, input().split())
dfs(K, -1, 0)

for i in range(Q):
    x, y = map(int, input().split())
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print(memo[x] + memo[y])


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

int main() {
	string s;
	cin >> s;
	int a[26] = {0};
	for(int unsigned i=0;i<s.size();i++){
		a[s[i] - 'a']++;
	}
	bool f = true;
	for(int i=0;i<26;i++){
		if(a[i]%2!=0){
			f = false;
		}
	}
	if(f){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;


int main(void) {
	int H, W;
	cin >> H >> W;
	string S[60];
	for (int i = 0; i < H; i++) cin >> S[i];

	int A[60][60] = { 0 };
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (S[i][j] == '#') {
				++A[i][j+1];
				++A[i+2][j+1];
				++A[i+1][j];
				++A[i+1][j + 2];
			}
		}
	}
	bool can = true;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (S[i][j] == '#') {
				if (A[i + 1][j + 1] == 0) can = false;
			}
			//cout << A[i+1][j+1];
		}
		//cout << endl;
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int s;
    cin >> s;
    int n = ceil(sqrt(s));
    if (n * n == s) {
        cout << 0 << " " << 0 << " " << n << " " << 0 << " " << 0 << " " << n << endl;
        return 0;
    }
    int xy = abs(n * n - s);
    for (int i = (int)sqrt(xy); i > 0; i--) {
        if (xy % i == 0) {
            cout << 0 << " " << 0 << " " << n << " " << i << " " << xy/i << " " <<  n << endl;
            return 0;
        }
    }
    cout << 0 << " " << 0 << " " << n << " " << 1 << " " << xy << " " <<  n << endl;
    return 0;
}

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

using namespace std;

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

  int N, M; cin>>N>>M;
  priority_queue<long> Q;
  for (int i = 0; i < N; i++) {
    long a; cin>>a;
    Q.push(a);
  }
  while (M--) {
    auto top = Q.top(); Q.pop();
    Q.push(top/2);
  }
  long sum = 0;
  while (not Q.empty()) {
    sum += Q.top();
    Q.pop();
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h> 
using namespace std; 
typedef long long ll;
int main(){
	int a,b,k;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)if(i%k==0)return puts("OK"),0;
	puts("NG");
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  if(N%2==0){
    int a = N/2;
    cout << (float)a/N << endl;
  }else{
    int a = (N+1)/2;
    cout << (float)a/N << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  int X;
  cin>>X;
  if(X<=599){cout<<8;return 0;}
  if(X<=799){cout<<7;return 0;}
  if(X<=999){cout<<6;return 0;}
  if(X<=1199){cout<<5;return 0;}
  if(X<=1399){cout<<4;return 0;}
  if(X<=1599){cout<<3;return 0;}
  if(X<=1799){cout<<2;return 0;}
  if(X<=1999){cout<<1;return 0;}
}


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

int s[100][100]={0};


int main(void){
    // Your code here!
    int w, h, n;
    cin>>w>>h>>n;
    
    vector<int> x(n), y(n), a(n);
    
    for(int i=0; i<n; i++){
        cin>>x[i]>>y[i]>>a[i];
    }
    
    
    for(int i=0; i<n; i++){
        switch(a[i]){
            case 1:{
                for(int xx=0; xx<x[i]; xx++){
                    for(int yy=0; yy<h; yy++){
                        s[yy][xx]=1;
                    }
                }
                break;
            }
            case 2:{
                for(int xx=x[i]; xx<w; xx++){
                    for(int yy=0; yy<h; yy++){
                        s[yy][xx]=1;
                    }
                }
                break;
            }
            case 3:{
                for(int yy=0; yy<y[i]; yy++){
                    for(int xx=0; xx<w; xx++){
                        s[yy][xx]=1;
                    }
                }
                break;
            }
            case 4:{
                for(int yy=y[i]; yy<h; yy++){
                    for(int xx=0; xx<w; xx++){
                        s[yy][xx]=1;
                    }
                }
                break;
            }
        }
    }
    
    int sum=0;
    for(int yy=0; yy<h; yy++){
        for(int xx=0; xx<w; xx++){
            if(s[yy][xx]==0){
                sum++;
            }
        }
    }
    
    cout<<sum<<endl;
    
}


Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		vector<int> taro(n),hana;
		rep(i,n)cin>>taro[i]; sort(taro.begin(),taro.end());
		rep(i,n*2)if(find(taro.begin(),taro.end(),i+1)==taro.end())hana.push_back(i+1);
		int turn=0,ba=0,pass;
		while(taro.size()&&hana.size()){
			pass=1;
			if(turn){
				rep(i,hana.size())if(hana[i]>ba){
					ba=hana[i];
					hana.erase(hana.begin()+i); pass=0; break;
				}
			}else{
				rep(i,taro.size())if(taro[i]>ba){
					ba=taro[i];
					taro.erase(taro.begin()+i); pass=0; break;
				}
			}
			if(pass)ba=0;
			turn^=1;
		}
		cout<<hana.size()<<endl<<taro.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll n, m, ans;

int main() {
    fast_io; cout_precision;
    cin >> n >> m;
    ans = min(n, m / 2);
    ans += (m - 2 * ans) / 4;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct PRICE{
  long long int A;
  long long int B;
};

int cmp( const void *p, const void *q ) {
    return ((struct PRICE*)p)->A - ((struct PRICE*)q)->A;
}

int main(void){
  int N,M;
  scanf("%d %d", &N, &M);
  struct PRICE* price = (struct PRICE*)malloc(sizeof(struct PRICE) * N);
  for(int i = 0;  i < N; i++){
    scanf("%lld %lld", &price[i].A, &price[i].B);
    //printf("%d %d\n", price[i].A, price[i].B);
  }
  qsort(price, N, sizeof(struct PRICE), cmp);
  int M_cnt = M;
  long long int sum = 0;
  for(int i = 0;  i < N; i++){
    M_cnt -= price[i].B;
    if(M_cnt <= 0){
      sum += price[i].A * (price[i].B + M_cnt);
      break;
    }
    sum += price[i].A * price[i].B;
    //printf("%d %d\n", price[i].A, price[i].B);
  }
  printf("%lld", sum);  
  return 0;
}

Measured memory_bytes: 3324
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long lli;

int n,k,mod;
int cnt[2][2001][2001];

int get(int t,int y1,int x1,int y2,int x2 ){
	if(y1>y2 || x1>x2) return 0;
	return cnt[t][y2][x2] - cnt[t][y1-1][x2] - cnt[t][y2][x1-1] + cnt[t][y1-1][x1-1];
}
int main() {
	int x,y,s;
	char ch;

	scanf("%d%d",&n,&k);
	mod=2*k;
	for(int i=0;i<n;i++) {
		scanf("%d%d %c",&x,&y,&ch);

		if(ch == 'W') s=0;
		else s=1;
		
		cnt[s][y%mod+1][x%mod+1]++;
	}

	for(int t=0;t<2;t++) {
		for(int i=1;i<=mod;i++) for(int j=1;j<=mod;j++) 
			cnt[t][i][j] += cnt[t][i-1][j]+cnt[t][i][j-1]-cnt[t][i-1][j-1];
	}

	int mx=0;
	for(int i=0;i<k;i++) {
		for(int j=0;j<k;j++) {
			int y1=k-i,x1=k-j, y2=2*k-i,x2=2*k-j;

			int s=0;
			s += get(0,1,1,y1,x1); s+=get(1,y1+1,1,y2,x1);
			s += get(1,1,x1+1,y1,x2); s += get(0,y1+1,x1+1,y2,x2);
			s += get(0,y2+1,1,mod,x1); s += get(0,1,x2+1,y1,mod);
			s += get(1,y2+1,x1+1,mod,x2); s+= get(1,y1+1,x2+1,y2,mod);
			s += get(0,y2+1,x2+1,mod,mod);
			mx=max(mx,s);

			s=0;
			s += get(1,1,1,y1,x1); s+=get(0,y1+1,1,y2,x1);
			s += get(0,1,x1+1,y1,x2); s += get(1,y1+1,x1+1,y2,x2);
			s += get(1,y2+1,1,mod,x1); s += get(1,1,x2+1,y1,mod);
			s += get(0,y2+1,x1+1,mod,x2); s+= get(0,y1+1,x2+1,y2,mod);
			s += get(1,y2+1,x2+1,mod,mod);
			mx=max(mx,s);
		}
	}

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


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

using namespace std;

int niz[300050];
vector<int> adj[300050];
int comp[300050];
int ind[100050];


void dfs(int x,int k)
{
    comp[x]=k;
    for(auto y:adj[x])
        if(!comp[y])
            dfs(y,k);
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
       {
            cin>>niz[i];
            ind[niz[i]]=i;
       }
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }


    int br_komp=0;
    for(int i=1;i<=n;i++){
        if(comp[i]==0){
            br_komp++;
            dfs(i,br_komp);
        }
    }
    int res=0;
    for(int i=1;i<=n;i++)if(comp[i]==comp[ind[i]])res++;
    cout<<res;
    return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>
int main() {
  int N, i;
  scanf("%d", &N);
  char S[N+1];
  char T[N+1];
  scanf("%s", S);
  scanf("%s", T);
  for (i = 0; i < N; ++i) {
    printf("%c", S[i]);
    printf("%c", T[i]);
  }
  return 0;
}

Measured memory_bytes: 128
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	h := stdin.ReadInt()

	c := 0
	for h > 0 {
		c++
		h /= 2
	}

	ans := 0
	for i := 0; i < c; i++ {
		ans += Pow(2, i)
	}

	stdout.Println(ans)
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 640
/*input
100 0

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e7+5;
const ll maxlg=__lg(maxn)+2;
int main(){
    int a,n;
    cin>>a>>n;
    set<int> s;
    REP(i,n){
        int x;
        cin>>x;
        s.insert(x);
    }
    int ans=INF;
    for(int i=0;i<=1000;i++){
        if(s.find(i)==s.end()) MNTO(ans,abs(i-a));
    }
    for(int i=0;i<=1000;i++){
        if(s.find(i)==s.end() and ans==(abs(i-a))){
            cout<<i<<'\n';
            return 0;
        }
    }
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main(void) 
{     int w,h,i,t;
 char a[101][101];
    scanf("%d%d",&h,&w);
    for(i=0;i<h;i++)
     scanf("%s",&a[i]);
	for(i=0;i<w+2;i++)
	printf("#");
	printf("\n");
	for(i=0;i<h;i++)
	{
	printf("#");
 printf("%s",a[i]);
	printf("#\n");
	}
	
	for(i=0;i<w+2;i++)
	printf("#");
		
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF  1001001001;
#define PI  3.14159265358979323846;

int main(){
string X;
cin>>X;
int s=0,t=0;
rep(i,X.size()){
    if(X[i]=='S'){
        s++;
    }
    else{
        if(s>0){
            s--;
        }
        else{
            t++;
        }
    }
}
cout<<s+t<<endl;
return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int INF=0x3f3f3f3f;
const int MAXN=1000005;

int n,m,x[MAXN],cnt[20];
int l[20][MAXN],r[20][MAXN],f1[MAXN*2],f2[MAXN*2];
bool ans[MAXN];

int uf(int id,int pos){
	pos++;
	int p=upper_bound(l[id]+1,l[id]+cnt[id]+1,pos)-l[id]-1;
	if(p<=0) return pos;
	return max(r[id][p],pos-1);
}

int lf(int id,int pos){
	pos--;
	int p=lower_bound(r[id]+1,r[id]+cnt[id]+1,pos)-r[id];
	if(p>=cnt[id]+1) return pos;
	return min(l[id][p],pos+1);
}

int main(){

	memset(f2,0x3f,sizeof f2);
	scanf("%d%d",&n,&m);
	int tot=0;
	for(tot=0;(1<<tot)<=m;tot++);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	x[0]=-INF; x[n+1]=INF;
	for(int log=0;log<=tot;log++){
		int d=m>>log;
		cnt[log]=1;
		l[log][1]=1;
		for(int i=1;i<=n;i++){
			r[log][cnt[log]]=i;
			if(x[i+1]-x[i]>d){
				cnt[log]++;
				l[log][cnt[log]]=i+1;
			}
		}
		cnt[log]--;
	}
	if(cnt[0]>tot+1){
		for(int i=1;i<=n;i++) printf("Impossible\n");
		return 0;
	}
	int sum=(1<<(tot+1));
	f1[0]=0,f2[0]=n+1;
	for(int s=0;s<sum;s+=2)
		for(int i=0;i<=tot;i++){
			if(!(s&(1<<i))) continue;
			f1[s]=max(f1[s],uf(i,f1[s-(1<<i)]));
			f2[s]=min(f2[s],lf(i,f2[s-(1<<i)]));
		}
	for(int i=1;i<=cnt[0];i++){
		int ln=l[0][i],rn=r[0][i];
		for(int s1=0;s1<sum;s1+=2){
			int s2=sum-1-s1-1;
			int lpos=f1[s1];
			int rpos=f2[s2];
			if(lpos>=ln-1&&rpos<=rn+1){
				ans[i]=1;
				break;
			}
		}
	}
	int pos=1;
	for(int i=1;i<=n;i++){
		if(ans[pos]) printf("Possible\n");
		else printf("Impossible\n");
		if(x[i+1]-x[i]>m) pos++;
	}

	fclose(stdin);
	fclose(stdout);
}



Measured memory_bytes: 95488
#include <stdio.h>
static const int N = 1000;
 
void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
      printf("%d", A[i]);
  }   
  printf("\n");
}
 
int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);
 
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
   
  trace(A, n);
 
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    trace(A, n);
  }
    
  return 0;
}

Measured memory_bytes: 1808
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

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

	VL A(N); REP(i, N) cin >> A[i];
	
	ll sum = 0,xsum = 0,cnt = 0;
	int i = 0, j = 0;
	while (i < N && j <= N) {
	
		if (i > j) j = i;

		while (i < N && j < N && (sum + A[j]) == (xsum ^ A[j])) {
			sum += A[j];
			xsum ^= A[j];
			j++;
		}
		
		if(sum == xsum)	cnt += j - i;
		
		sum -= A[i];
		xsum ^= A[i];
		i++;
	
	}

	cout << cnt << endl;
	return 0;
}


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

    public static void main(String[] args) {
        Scanner  yomi = new Scanner(System.in);
        int[] n = new int[3];
        for (int i=0;i<3;i++){
            n[i] = yomi.nextInt();
        }
        if (n[0]==n[1]){
            if (n[2]==n[1]){
                System.out.println("No");
            }else System.out.println("Yes");
        }else if (n[0]==n[2]){
            if (n[2]==n[1]){
                System.out.println("No");
            }else System.out.println("Yes");
        }else if (n[1]==n[2]){
            System.out.println("Yes");
        }else System.out.println("No");
        }
    }

Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define P pair<int,int>
using namespace std;

int x[12] = { -2,-2,-2,-1,-1,0,0,1,1,2,2,2 }, y[12] = { -1,0,1,-2,2 ,- 2,2,-2,2,-1,0,1 };
int main()
{
	map<P, bool>U;
	for (int i = 0; i < 12; i++) {
		U[P(x[i], y[i])] = true;
	}
	int a, b;
	while (cin >> a >> b, a | b) {
	      map<int, set<P>>S;
		  S[0].insert(P(a, b));
		  int c; cin >> c;
		  for (int i = 1; i <= c; i++) {
			  int d, e; cin >> d >> e;
			  for (auto k = S[i - 1].begin(); k != S[i - 1].end(); k++) {
				  for (int j = -1; j < 2; j++) {
					  for (int l = -1; l < 2; l++) {
						  if (d + j >= 0 && d + j < 10 && e + l >= 0 && e + l < 10 && U[P(d + j - k->first, e + l - k->second)]) {
							  S[i].insert(P(d + j, e + l));
						  }
					  }
				  }
			  }
		  }
		  if (S[c].size())puts("OK");
		  else puts("NA");
	}
}

Measured memory_bytes: 2996
#include<iostream>
#include<array>
#include<string>
using namespace std;

int main() {
	int num;
	cin >> num;
	int mou;
	int old = 0;
	int see = 0;
	int f = 0;
	int loop = 0;
	while (num--) {
		cin >> mou;
		if (mou >= old && mou >= f)
		{
			see++;
		}
		if (loop == 0) {
			f = mou;
		}
		if(mou>=old){
			old = mou;
		}
		loop++;
	}
	cout << see << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int cta = 0;
    rep(i, n) if (v[i] != i + 1) cta++;
    if (cta > 2)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
}

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

using namespace std;

int main()
{
  int N;
  long long int sum = 0;

  cin >> N;

  vector< pair< long long int, int > > s(N);
  vector< long long int > t(N);
  long long int tmp;
  for(int i = 0; i < N; i++) {
    cin >> tmp;
    s[i].first = tmp; s[i].second = i;
    t[i] = tmp;
  }
  sort(s.begin(), s.end());

  vector< long long int > ans(N);
  for(int i = 0; i < N; i++) {
    if(i < N / 2) ans[s[i].second] = s[N/2].first;
    else ans[s[i].second] = s[N/2-1].first;
  }
  for(auto a : ans) cout << a << endl;

  return 0;
}


Measured memory_bytes: 8448
#include"bits/stdc++.h"
using namespace std;
#define int int64_t
 int ar[11000];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int w,h;cin>>w>>h;
    if(w==1 or h==1)
    {
        cout<<"1\n";
        return 0;
    }
    w*=h;
    w+=1;
    w/=2;
    cout<<w<<"\n";
    return 0;
}


Measured memory_bytes: 256
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll a[N], b[N], c[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, s = 0;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a[i];
    for (ll i = 0; i < n; i++)
        cin >> b[i], s += b[i];
    for (ll i = 0; i < n - 1; i++)
        cin >> c[i];
    for (ll i = 0; i < n - 1; i++)
        if (a[i + 1] == a[i] + 1)
            s += c[a[i] - 1];
    cout << s;
    return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll A, B;
    cin>>A>>B;
    rep(i, 100000){
        if((int)(i*0.08)==A && (int)(i*0.1)==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 4200;
 
int s[maxn], sh;
int h[maxn];
 
int main() {
	int a, b; cin >> a >> b;
	if(a <= b) cout << "Impossible\n";
	else {
		char ans[3];
		sh = 0; s[sh ++] = 0;
		int n = a + b;
		for(int i = 1; i < n; ++ i) {
			if(sh == 0) {
				s[sh ++] = i;
				continue;
			}
			cout << "? " << s[sh - 1] << ' ' << i << endl;
			cin >> ans;
			if(ans[0] == 'Y') s[sh ++] = i;
			else -- sh;
		}
		h[s[sh - 1]] = 1;
		for(int i = 0; i < n; ++ i) {
			if(i != s[sh - 1]) {
				cout << "? " << s[sh - 1] << ' ' << i << endl;
				cin >> ans;
				h[i] = (ans[0] == 'Y');
			}
		}
		cout << "! ";
		for(int i = 0; i < n; ++ i) cout << h[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 724
#include<stdio.h>
int main(void)
{
	int a,flg;
	scanf("%d",&a);
	flg=0;
	if(a%10==7){
		flg=1;
	}
	a=a/10;
	if(a%10==7){
		flg=1;
	}
	a=a/10;
	if(a%10==7){
		flg=1;
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1612
def Judge(a):
  col=[]
  diag1=0
  diag2=0

  for i in range(3):
    if(a[i].count(0)==3):
      return 1
      break
    if(a[i][0]==0):
      col.append(0)
    if(a[i][1]==0):
      col.append(1)
    if(a[i][2]==0):
      col.append(2)
    if(a[i][i]==0):
      diag1+=1
    if(a[i][-(i+1)]==0):
      diag2+=1
  if(diag1==3 or diag2==3):
    return 1
  if(col.count(0)==3 or col.count(1)==3 or col.count(2)==3):
    return 1
  return 0


a=[]
for i in range(3):
  a.append(list(map(int,input().split())))
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if(b==a[j][k]):
        a[j][k]=0
judge=Judge(a)
if(judge==1):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
char str[10001],s[10001];
int now,n,num,num2;
int main()
{
	s[1]='k',s[2]='e',s[3]='y',s[4]='e',s[5]='n',s[6]='c',s[7]='e';
	scanf("%s",str+1);
	n=strlen(str+1);
	num=num2=-1;
	for(int i=1,j=1;j<=7;i++,j++)
	if(str[i]!=s[j]){num=j-1;break;}
	if(num==-1){puts("YES");return 0;}
	for(int i=n,j=1;j<=7;i--,j++)
	if(str[i]!=s[8-j]){num2=j-1;break;}
	if(num2==-1){puts("YES");return 0;}
	if(num+num2>=7){puts("YES");}
	else puts("NO");
}

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

signed main() {
  int x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];

  rep(i, 5) {
    if (x[i] == 0) {
      cout << i+1 << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

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

    int resultMax = min(A, B);
    int resultMin = (A + B) - N;

    if (resultMin < 1) resultMin = 0;
    cout << resultMax  << " " << resultMin << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a =scan.nextInt();
		int b =scan.nextInt();
		
		if(a > b) {
			System.out.println("a > b");
		}
		else if(a < b) {
			System.out.println("a < b");
		}	
		else if(a == b) {
			System.out.println("a == b");
		}
		}
	}




Measured memory_bytes: 26104
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut probabilities: Vec<f64> = vec![];
    for _ in 0..N {
        probabilities.push(read());
    }
    let mut dp: Vec<Vec<f64>> = vec![vec![0.0; N + 1]; N + 1];
    dp[0][0] = 1_f64;
    // 外側のループは何枚表になったか
    for i in 0..N {
        // 内側のループは何枚目まで見るか
        for j in 0..N {
            dp[i + 1][j + 1] += dp[i][j] * probabilities[j];
            dp[i][j + 1] += dp[i][j] * (1.0 - probabilities[j]);
        }
    }
    // dbg!(dp);
    // あとはheadの数が2/1を超えてるものを全部足す
    let mut ans = 0_f64;
    for i in (N / 2) + 1..N + 1 {
        ans += dp[i][N];
    }
    println!("{}", ans);
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int main() {
    std::string S;
    std::cin >> S;

    EACH(c, S) {
        std::cout << (*c == ',' ? ' ' : *c);
    }
    std::cout << std::endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const ll INF = (ll)1e16;

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

  vector<vector<pii>> edge(N, vector<pii>());

  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[a-1].push_back(make_pair(b-1, -c));
  }
  ll dist[N];
  REP(i, N) dist[i] = INF;
  dist[0] = 0;
  REP(i, N-1) REP(from, N) {
    for (const auto& e : edge[from])
      if (dist[from] != INF && dist[e.first] > dist[from] + e.second)
        dist[e.first] = dist[from] + e.second;
  }
  ll ans = dist[N-1];
  bool negative[N];
  REP(i, N) negative[i] = false;
  REP(i, N) REP(from, N) {
    for (const auto& e : edge[from]) {
      if (dist[from] != INF && dist[e.first] > dist[from] + e.second) {
        dist[e.first] = dist[from] + e.second;
        negative[e.first] = true;
      }
      if (negative[from])
        negative[e.first] = true;
    }
  }
  if (negative[N-1])
    printf("inf\n");
  else
    printf("%lld\n", -ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int maxn=5e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=998244353;

ll dp[maxn];
ll a[maxn];
int main(){
	int n,s;
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		dp[0]++;
		for(int j=s;j>=a[i];j--){
			dp[j]=(dp[j]+dp[j-a[i]])%mod;
		}
		ans=(ans+dp[s])%mod;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2304
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=300010;
int n,a,c;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>a;
		if (a==c+1) ++c;
	}
	if (c) cout<<n-c;
	else cout<<-1;
}





Measured memory_bytes: 256
n,x = map(int, input().split())
a = list(map(int, input().split()))

total = 0
for i in range(1,n):
    if a[i-1] > x:
        total += a[i]
        total += (a[i-1] - x)
        
        a[i] = 0
        a[i-1] = x
        
    
    elif a[i-1] + a[i] > x:
        total += (a[i-1] + a[i] - x)
        
        a[i] = x - a[i-1]
    
print(total)

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> v;
    ll ans=1;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        v.pb(a);
        if(a==0){
            ans=0;
        }
    }

    sort(v.begin(),v.end());
    if(ans!=0){
        ans*=v[0];
        ll c=1000000000000000000/ans;
        for(int i=1;i<n;i++){
            ll a=v[i];
            if(a>c){
                ans=-1;
                break;
            }
            else{
                ans*=a;
                c=1000000000000000000/ans;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main () {
  int count = 0;
  string a, b;
  cin >> a >> b;
  rep(i, 3) if(a[i] == b[i]) { count++; }
  cout << count << endl;
}

Measured memory_bytes: 256
a = []
for i in range(3):
    a.append(list(map(int,input().split())))
n = int(input())
b = []
flag = 0
for i in range(n):
    b.append(int(input()))
for i in range(n):
    if b[i] in a[0]:
        a[0][a[0].index(b[i])]=0
    elif b[i] in a[1]:
        a[1][a[1].index(b[i])]=0
    elif b[i] in a[2]:
        a[2][a[2].index(b[i])]=0
if a[0][0] == a[0][1] == a[0][2] == 0:
    print('Yes')
elif  a[1][0] == a[1][1] == a[1][2] == 0:
    print('Yes')
elif  a[2][0] == a[2][1] == a[2][2] == 0:
    print('Yes')
elif  a[0][0] == a[1][0] == a[2][0] == 0:
    print('Yes')
elif  a[0][1] == a[1][1] == a[2][1] == 0:
    print('Yes')
elif  a[0][2] == a[1][2] == a[2][2] == 0:
    print('Yes')
elif  a[0][0] == a[1][1] == a[2][2] == 0:
    print('Yes')
elif  a[0][2] == a[1][1] == a[2][0] == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188
S = input()[::-1]
T = input()[::-1]

flag = False
for i in range(len(S) - len(T) + 1):
    matched = True

    for j in range(len(T)):

        if S[i + j] != "?" and S[i + j] != T[j]:
            matched = False
            break
    
    if matched:
        S = S[:i] + T + S[i + len(T):]
        flag = True
        break

if flag:
    print(S.replace("?", "a")[::-1])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 8992