akhauriyash/Code-Regression huggingface dataset:
using System;


namespace ConsoleApplication20
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] Total = new int[4, 13];
            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 13; i++)
                {
                    Total[j, i] = 0;
                }

            }
            String N = Console.ReadLine();
            int n = int.Parse(N);
            for (int x = 0; x < n; x++)
            {
                String[] card = Console.ReadLine().Split(' ');
                int i = int.Parse(card[1]);
                i = i - 1;
                String S = "S";
                String H = "H";
                String C = "C";
                String D = "D";
                if (card[0].Equals(S))
                {
                    Total[0, i] = 20;
                }
                else if (card[0].Equals(H))
                {
                    Total[1, i] = 20;
                }
                else if (card[0].Equals(C))
                {
                    Total[2, i] = 20;
                }
                else if (card[0].Equals(D))
                {
                    Total[3, i] = 20;
                }
            }
            for ( int j = 0; j < 4; j++ )
            {
                for ( int i = 0; i < 13; i++ )
                {
                    int ans = Total[j, i];
                    if (ans == 0)
                    {
                        if (j == 0)
                        {
                            Console.WriteLine("S" + " " + (i + 1));
                        }
                        else if (j == 1)
                        {
                            Console.WriteLine("H" + " " + (i + 1));
                        }
                        else if (j == 2)
                        {
                            Console.WriteLine("C" + " " + (i + 1));
                        }
                        else if (j == 3)
                        {
                            Console.WriteLine("D" + " " + (i + 1));
                        }
                    }
                    
                }
            }
            
        }
    }
}

Measured memory_bytes: 9032
S = [int(x) for x in input()]
N = len(S)
if S[0] == 0 or S[-1] == 1 or any(S[i] != S[-i - 2] for i in range(N - 1)):
    print(-1)
    quit()

edge = [(1, 2)]
root, now = 2, 3
for i in range(1, N // 2 + 1):
    edge.append((root, now))
    if S[i] == 1:
        root = now
    now += 1
while now <= N:
    edge.append((root, now))
    now += 1
for s, t in edge:
    print(s, t)


Measured memory_bytes: 15572
#include<bits/stdc++.h>
#define rep(i,n) for(int = 0;i < (n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll x ,ll y){
    return y ? gcd(y,x%y) : x;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>> res;
    for(ll i=2;i*i <=n; ++i) {
        //割り切れるかチェック
        if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0){
            n/=i;
            res.back().second++;
        }
    }    
    if(n != 1) res.emplace_back(n,1);
    return res;
    
}
int main(){
    ll a,b;
    cin >> a >> b;
    ll g = gcd(a,b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int n;
    string s;
    
    cin >> n >> s;
    trav(a, s){
        int x = ((a - 'A') + n ) % 26;
        a = 'A' + x;  
    }
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  long long a , b , c , x , y ;
  cin >> a >> b >> c >> x >> y ;
  
  if(a+b<=c*2){
    cout << a*x+b*y << endl;
  }
  else{
    if(c*2<=a&&c*2<=b){
      if(x<=y){
        cout << c*y*2 << endl;
      }
      else{
        cout << c*x*2 << endl;
      }
    }
    else{
      if(x<=y){
        if(b<=c*2){
          cout << c*x*2+b*(y-x) << endl;
        }
        else{
          cout << c*x*2+c*2*(y-x) << endl;
        }
      }
      else{
        if(a<=c*2){
          cout << c*y*2+a*(x-y) << endl;
        }
        else{
          cout << c*y*2+c*2*(x-y) << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
#define MAX_H 1000
#define MAX_W 1000


int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N, M;  cin >> N >> M;
    V s(M), c(M);
    for(int i = 0 ; i < M ; i++)  cin >> s[i] >> c[i];

    for(int i = ((N == 1) ? 0 : pow(10, N - 1)) ; i < pow(10, N)  ; i++){
     	V digits(N);  fill(ALL(digits), 0);
      	int tmp = i;
      	for(int j = 0 ; j < N ; j++){ digits[j] = tmp % 10;  tmp /= 10;  }

      	bool flag = true;
      	for(int j = 0 ; j < M ; j++)
          if(digits[N - s[j]] != c[j])  flag = false;
  
      	if(flag){  cout << i << endl;  return 0;  }
    }
  cout << -1 << endl;
	return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,h[100005],dp[100005];
void solve(){
    cin>>n;
    rep(i,1,n+1) cin>>h[i];
    h[0]=hell;
    rep(i,1,n+1){
        if(i==1) dp[i]=0;
        else dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

char b[1024][1024];
int d[1024][1024];
int n,m,k;

bool valid(int i, int j){
	return i>=0&&i<n&&j>=0&&j<m&&b[i][j]!='#';
}

int asd(int i, int j){
	int r=i;
	r=min(r,j);
	r=min(r,n-1-i);
	r=min(r,m-1-j);
	return r;
}

queue<pair<int,int> > q;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	int xs=-1,ys=-1;
	fore(i,0,n){
		scanf("%s",b[i]);
		fore(j,0,m)if(b[i][j]=='S')xs=i,ys=j;
	}
	memset(d,-1,sizeof(d));
	d[xs][ys]=0;
	q.push(mp(xs,ys));
	while(!q.empty()){
		int x=q.front().fst,y=q.front().snd;q.pop();
		fore(i,-1,2)fore(j,-1,2)if(abs(i)+abs(j)==1){
			int xx=x+i,yy=y+j;
			if(valid(xx,yy)&&d[xx][yy]<0){
				d[xx][yy]=d[x][y]+1;
				q.push(mp(xx,yy));
			}
		}
	}
	int r=1<<20;
	fore(i,0,n)fore(j,0,m)if(d[i][j]>=0&&d[i][j]<=k){
		r=min(r,1+(asd(i,j)+k-1)/k);
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 5248
from collections import deque
h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
s = [list('#'*(w+2)) for i in range(h+2)]
for i in range(h):
    a = '#' + input() + '#'
    s[i+1] = list(a)
queue = deque([[ch,cw]])
s[ch][cw] = 0
l = [[0,-1],[0,1],[-1,0],[1,0]] 
r = [[] for i in range(20)]
k = 0
for i in range(-2,3):
    for j in range(-2,3):
        if i != 0 or j != 0:
            if not [i,j] in l:
                r[k] = [i,j]
                k += 1
while queue:
    x,y = queue.popleft()
    if [x,y] != [dh,dw]:
        for n,m in l:
            new_h,new_w = x+n,y+m 
            if s[new_h][new_w] == '.':
                s[new_h][new_w] = s[x][y]
                queue.appendleft([new_h,new_w])
            elif s[new_h][new_w] != "#":
                if s[new_h][new_w] > s[x][y]:
                    s[new_h][new_w] = s[x][y]
                    queue.appendleft([new_h,new_w])
            else:
                pass
        for n,m in r:
            new_h,new_w = x+n,y+m
            if new_h >= 0 and new_h <= h+1 and new_w >= 0 and new_w <= w+1:
                if s[new_h][new_w] == '.':
                    s[new_h][new_w] = s[x][y]+1
                    queue.append([new_h,new_w])
                elif s[new_h][new_w] != "#":
                    if s[new_h][new_w] > s[x][y]+1:
                        s[new_h][new_w] = s[x][y]+1
                        queue.append([new_h,new_w])
                else:
                    pass
if s[dh][dw] != '.':
    print(s[dh][dw])
else:
    print(-1)

Measured memory_bytes: 173612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
string s;
void MAIN() {
	cin>>s;
	int n=s.length();
	bool f=true;
	rep(i,n/2) {
		if(s[i]!=s[n/2-i-1]) {
			f=false;
		}
		if(s[n/2+i+1]!=s[n-1-i]) {
			f=false;
		}
	}
	rep(i,n) {
		if(s[i]!=s[n-1-i]) {
			f=false;
		}
	}
	cout<<(f?"Yes":"No");
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

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

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

comp(a, b){
    return *(uint*)a -*(uint*)b;
}

int main(){
    uint N;
    scanf("%u", &N);
    uint S[N], i, full = 0;
    REP(i, N){
        scanf("%u", &S[i]);
        full += S[i];
    }
    qsort(S, N, sizeof(uint), comp);
    if(full % 10 == 0){
        REP(i, N){
            if(S[i] % 10 != 0){
                full -= S[i];
                break;
            }
        }
    }
    if(full % 10 == 0){
        printf("0\n");
    }else{
        printf("%u\n", full);
    }
    return 0;
}

Measured memory_bytes: 128
// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

ll n,k;
vll a;

bool ok(double x, int k) {
	int k0;
	for (int d : a) {
		k0 = ceil(d / (x )) - 1;
		if (round(d / (k0 + 1)) > x) {
			k0++;
		}
		k -= k0;
	}
 
	return k >= 0;
}

int main()
{
    io;
    cin>>n>>k;
    cinvg(a,n)
    
    ll l=0,r=(ll)(1e9)+5;
    
    while(r>l+1)
    {
    	ll m=(l+r)/2;
    	if(ok(m, k))
    	{
    		r=m;
    	}
    	else
    	{
    		l=m;
    	}
    }
    
    cout<<r;
    
    return 0;
}



Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, x, arr[101], cnt;
ll lst;
int main() {
    IOS
    cin >> n >> x;
    for (int i = 0; i <= n; ++i) {
        if (i != n) {
            cin >> arr[i];
        }

        if (!i) {
            cnt++;
        } else {
            lst = lst+arr[i-1];
            if (lst <= x) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;


    return 0;


}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main {
  public static void main (String[] args) {
    Scanner scan_ = new Scanner(System.in);
   int h_ = 0;
   int w_ = 0;

   while(scan_.hasNext()) {
      h_ = scan_.nextInt();
      w_ = scan_.nextInt();

      if(h_ != 0 | w_!=0) {
        for( int i = 0; i < h_ ; i++) {
          if(i%2==0){
            for(int n = 0; n < w_ ; n++) {
              if(n%2==0){
              System.out.print("#");
            } else{
               System.out.print(".");
             }
            }
           System.out.println();
          }else if(i%2==1){
            for(int n = 0; n < w_ ; n++) {
              if(n%2==0){
              System.out.print(".");
            } else{
               System.out.print("#");
             }
            }
            System.out.println();
          }
       }
       System.out.println();
      }
   }
  }
}


Measured memory_bytes: 34828
//incorrect

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define rep(i,l) for(int i = 0; i < l; i++)

int nextint(void){int n;scanf("%d",&n);return n;}

int main(void){

    int n = nextint();
    int ans=0;

    rep(i,n){
        int k=nextint();
        if(((i+1)*k)%2!=0)ans++;
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 1708
from sys import setrecursionlimit
from collections import deque

setrecursionlimit(20001)

def read():
    v, e = tuple([int(e) for e in input().split()])
    adj = [[] for _ in range(v)]
    for _ in range(e):
        v_from, v_to = tuple([int(e) for e in input().split()])
        adj[v_from].append(v_to)

    return adj, v


def find_strong_components(adj, n):
    id = [0 for _ in range(n + 1)]
    low_link = [0 for _ in range(n)]
    mark = [False for _ in range(n)]
    in_stack = [False for _ in range(n)]
    st = deque()
    
    for v in range(n):
        if mark[v]: continue
        dfs(v, mark, id, low_link, adj, in_stack, st)
    return low_link

def dfs(v, mark, id, low_link, adj, in_stack, st):
    mark[v] = True
    in_stack[v] = True
    low_link[v] = id[v] = id[-1]
    id[-1]+=1

    st.append(v)
    for n_v in adj[v]:
        if not mark[n_v]:
            dfs(n_v, mark, id, low_link, adj, in_stack, st)
        if in_stack[n_v]:
            low_link[v] = min(low_link[v], low_link[n_v])

    if id[v] == low_link[v]:
        while st:
            top_v = st.pop() 
            low_link[top_v] = id[v]
            in_stack[top_v] = False
            if top_v == v:
                break

def write(low_link):
    q = int(input())
    for _ in range(q):
        v1, v2 = tuple([int(e) for e in input().split()])
        if low_link[v1] == low_link[v2]:
            print('1')
        else:
            print('0')

adj, n = read()
low_link = find_strong_components(adj, n)
write(low_link)


Measured memory_bytes: 19112
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=25000002;
int n,i,las,f[N],a[4],b[4],j;
signed main(){
	scanf("%lld",&n);
	for (i=1;i<=3;i++) scanf("%lld",&a[i]);
	for (i=1;i<=3;i++) scanf("%lld",&b[i]);
	for (i=1;i<=3;i++) if (a[i]<b[i])
		for (j=0;j<=n;j++)
			if (j>=a[i]) f[j]=max(f[j],f[j-a[i]]+b[i]);
	las=0;
	for (i=1;i<=n;i++)
		if (f[i]>f[las]) las=i;
	n=n-las+f[las];
	memset(f,0,sizeof(f));
	for (i=1;i<=3;i++) if (b[i]<a[i])
		for (j=0;j<=n;j++)
			if (j>=b[i]) f[j]=max(f[j],f[j-b[i]]+a[i]);
	las=0;
	for (i=1;i<=n;i++)
		if (f[i]>f[las]) las=i;
	printf("%lld",n-las+f[las]);
}

Measured memory_bytes: 195584
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
  
int main() {
 int a[100][100];
 int b[100];
 int c[100];
 int n,m; cin>>n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
  		cin>>a[i][j];
  	}
  }
  
  	for(int j=0;j<m;j++){
  		cin>>b[j];
        c[j]=0;
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
  		c[i]+=a[i][j]*b[j];
  	}
  }
   for(int j=0;j<n;j++){
        cout<<c[j]<<endl;  
  } 
}
 


Measured memory_bytes: 3144
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String value = scan.nextLine();
    String[] param = value.split(" ");

    int areaFirst  = Integer.parseInt(param[0]) * Integer.parseInt(param[1]);
    int areaSecond = Integer.parseInt(param[2]) * Integer.parseInt(param[3]);

    if (areaFirst > areaSecond){
      System.out.println(areaFirst);
    }
    else{
      System.out.println(areaSecond);
    }
  }
}


Measured memory_bytes: 10192
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}

bool *plfl;

long long lim=3000000;
void sieve_of_erat(){
  plfl=malloc(sizeof(bool)*(lim+5));
  long long i,j;
  for(i=0;i<lim+5;i++){plfl[i]=true;}
  plfl[0]=false;
  plfl[1]=false;
  for(i=2;i<lim;i++){
    if(!plfl[i]){continue;}
    for(j=2*i;j<lim;j+=i){
      plfl[j]=false;
    }
  }
  return;
}

int main(){
  sieve_of_erat();
  int a,d,n;
  while(scanf("%d%d%d",&a,&d,&n),a!=0){
    while(1){
      if(plfl[a]==true){
        n--;
        if(n==0){printf("%d\n",a);break;}
      }
      a+=d;
    }
  }
  return 0;
}



Measured memory_bytes: 4640
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
using db = long double;

 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 


signed main() {
  db a,b,x;
    cin>>a>>b>>x;
  db t=(2*a*a*b-2*x)/a/a;
  db ans=a/t;
  if(t>b){
    t=2*x/a/b;
    ans=t/b;
  }
  db pi=3.14159265;
  db eight=180;
  db nine=90;
  cout<<setprecision(9)<<nine-atanl(ans)*eight/pi<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int N = 13;

int p3[N];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  p3[0] = 1;
  for (int i = 1; i < N; ++i) p3[i] = 3 * p3[i - 1];
  int n;
  string s;
  cin >> n >> s;
  int m = s.size();
  vector <int> go(1);
  vector <int> who(m);
  for (int b = 0; b < n; ++b) {
    int sz = go.size();
    vector <vector <int>> ngo(sz, vector <int> (3));
    
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < 3; ++j) {
        ngo[i][j] = j;
      }
    }

    int sw = 0;

    auto make = [&] (int i) {
      for (int j = 0; j < 3; ++j) {
        if (ngo[i][j] == 0) {
          swap(ngo[i][(j + 1) % 3], ngo[i][(j + 2) % 3]);
        }
      }
    };    

    for (int i = 0; i < m; ++i) {
      if (s[i] == 'S') {
        sw ^= 1;
      } else {
        int id = who[i];
        if (sw) make(id);
        for (int j = 0; j < 3; ++j) {
          if (ngo[id][j] == 2) {
            who[i] = j * sz + id;
          }
        }
        for (int j = 0; j < 3; ++j) {
          ngo[id][j] = (ngo[id][j] + 1) % 3;
        } 
        if (sw) make(id);
      }
    }
    if (sw) for (int i = 0; i < sz; ++i) make(i);
    vector <int> cur(3 * sz);
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < sz; ++j) {
        cur[i * sz + j] = go[j] + ngo[j][i] * p3[b];
      }
    }
    go = cur;
  }
  for (int i = 0; i < p3[n]; ++i) {
    cout << go[i] << ' ';
  }
  cout << '\n';
}



Measured memory_bytes: 18752
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <ctime>
#include <set>
#include <sstream>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,i,t;bool ok;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	t=n;
	ok=0;
	while(t>0)
	{
		if(t%10==9)
		{
			ok=1;
			break;
		}
		t/=10;
	}
	if(ok)
		printf("Yes\n");
	else
		printf("No\n");
    return 0;
}



Measured memory_bytes: 256
gets
count = 0
array = gets.split(" ").map!{|i|i.to_i}

type = array[1] - array[0] < 0 ? "s" : "r" unless array.length == 1
array.each_with_index do |i,ind|
  if ind + 1 == array.length
    count += 1
    break
  end
  if i == array[ind + 1]
    next
  end
  if !type
    type = array[ind+1] - array[ind] < 0 ? "s" : "r" 
    next
  elsif type != (array[ind+1] - array[ind] < 0 ? "s" : "r")
    count += 1
    type = nil
  end
end
puts count

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#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 REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n;
  cin >> n;
  vll h(n);
  REP(i, n) {
    cin >> h[i];
  }
  ll count = 0;
  ll max_count = 0;
  REP(i, n - 1) {
    if (h[i] >= h[i + 1]) {
      count++;
    }
    else {
      max_count = max(max_count, count);
      count = 0;
    }
  }
  max_count = max(max_count, count);
  COUT(max_count);
}


int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*
5
10 4 8 7 3
*/


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

const int INF = 100000;

int main(){
	while(true){
		int n;
		cin>>n;
		if(n==0)break;
		int a[n],b[n],c[n];
		int N = 0;
		for(int i=0;i<n;++i){
			cin>>a[i]>>b[i]>>c[i];
			if(N<a[i]+1)N = a[i]+1;
			if(N<b[i]+1)N = b[i]+1;
		}
		vector<vector<int> > DParr;
		vector<int>tmparr(N,INF);
		for(int i=0;i<N;++i){
			DParr.push_back(tmparr);
			DParr[i][i] = 0;
		}
		for(int i=0;i<n;++i){
			DParr[a[i]][b[i]] = c[i];
			DParr[b[i]][a[i]] = c[i];
		}
		for(int k=0;k<N;++k){
			for(int i=0;i<N;++i){
				for(int j=0;j<N;++j){
					DParr[i][j] = min(DParr[i][j], DParr[i][k] + DParr[k][j]);
				}
			}
		}
		/*
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				cout<<DParr[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
		*/
		int ans=100000;
		int city;
		for(int i=0;i<N;++i){
			int tmpans=0;
			for(int j=0;j<N;++j){
				tmpans+=DParr[i][j];
			}
			if(ans>tmpans){
				ans=tmpans;
				city = i;
			}
		}
		cout<<city<<" "<<ans<<endl;
	}
}


Measured memory_bytes: 3164
S = input()
T = input()

l = len(T)

ind = 51
for i in range(len(S)-l+1):
    flag = 0
    for j in range(l):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag = 1
    if flag==0:
        ind = i

if ind == 51:
    print('UNRESTORABLE')
    exit()

print(S[:ind].replace('?','a')+T+S[ind+l:].replace('?','a'))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    int A[n];
    for (int i = 0; i < n; i++) sc(A[i]);
    int cnt = 0, cnt2 = 0;
    for (int i = 0; i < n; i++){
        if (A[i] % 2 != 0) cnt += 1;
        if (A[i] % 4 == 0) cnt2 += 1;
    }
    if (cnt2 >= cnt) cout << "Yes" <<endl;
    else if (n == cnt + cnt2 && cnt2 == cnt - 1) cout << "Yes" << endl;
    else cout << "No" <<endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  bool X = false;
  if(s[0] == s[1] && s[2] == s[3]) X = true;
  if(s[0] == s[3] && s[2] == s[1]) X = true;
  if(s[0] == s[2] && s[3] == s[1]) X = true;
  if(s[0] == s[1] && s[0] == s[2] && s[0] ==  s[3]) X = false;
  
  
  if(!X) cout << "No" << endl;
  else cout << "Yes" << endl;
  


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll A,B,C,K;
  cin >> A >> B >> C >> K;

  int ans = 0;
  int sum = 0;
  sum += A;
  if(sum >= K){
    ans = K;
    cout << ans << endl;
  }
  else{
  sum += B;
  if(sum >= K){
    ans = A;
    cout << ans << endl;
  }
  else{
  sum += C;
  if(sum >= K){
  int D = K-A-B;
  ans = A-D;
  cout << ans << endl;
  }
  }
  }
}

Measured memory_bytes: 3596
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var A = new long[n];
        var B = new long[n];
        var s = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            A[i] = long.Parse(s[i]);
            B[i] = A[i] - i - 1;
        }

        Array.Sort(B);
        var b = B[n / 2];
        var ans = 0L;
        for (int i = 0; i < n; i++)
        {
            ans += Math.Abs(A[i] - b - i - 1);
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 30492
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
long long inf=(long long)1E17;
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE=1000'010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
  
  invinit();
  long long cg[1000'010]={};
  for(long long g = 1;g<1000'010;g++){
    cg[g] += inv[g];
    cg[g] = mod(cg[g]);
    for(long long i=2;g*i<1000'010;i++){
      cg[g*i] -= cg[g];
      cg[g*i] = mod(cg[g*i]);
    }
  }
  
  int n;
  cin>>n;
  long long a[n];
  long long cnt[1000'010]={};
  REP(i,n){
    cin>>a[i];
    cnt[a[i]]++;
  }
  
  long long ans = 0;
  for(long long g = 1;g<1000'010;g++){
    long long s = 0;
    long long rest = 0;
    for(long long i=1;g*i<1000'010;i++){
      s += mod(cnt[g*i] * g*i);
      s = mod(s);
      rest += mod(mod(cnt[g*i]*(g*i))*(g*i));
      rest = mod(rest);
    }
    s = mod(s*s - rest);
    s *= inv[2];
    s = mod(s);
    ans += mod(cg[g]*s);
    ans = mod(ans);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 40832
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,Q;
#define Maxn 100010
int V[Maxn*10],W[Maxn*10];
int f[512][100010];
int seq1[Maxn],seq2[Maxn],cnt;
int to[Maxn];
int val1[Maxn],val2[Maxn];
void dfs(int u){
	if(u>=512)return;
	if(u>n)return;
		int fa=u/2;
		for(int i=0;i<=100000;++i){
			f[u][i]=f[fa][i];
			if(i>=W[u])f[u][i]=max(f[u][i],f[fa][i-W[u]]+V[u]);
		}
	dfs(u<<1);
	dfs(u<<1|1);
}

int lowbit(int x){return x&(-x);}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&V[i],&W[i]);
	}
	dfs(1);
	scanf("%d",&Q);
	int u,L;
	for(int i=0;i<9;++i)to[(1<<i)]=i;
	while(Q--){
		scanf("%d%d",&u,&L);
		if(u<512)printf("%d\n",f[u][L]);
		else{
			cnt=0;
			while(u>=512){
				seq1[cnt]=W[u];
				seq2[cnt]=V[u];
				u>>=1;
				cnt++;
			}
			int Ans=f[u][L];
			for(int i=1;i<(1<<cnt);++i){
				int d=lowbit(i);
				val1[i]=val1[i^d]+seq1[to[d]];
				val2[i]=val2[i^d]+seq2[to[d]];
				if(val1[i]<=L)Ans=max(Ans,f[u][L-val1[i]]+val2[i]);
			}
			printf("%d\n",Ans);
		}
	}	
	return 0;
}

Measured memory_bytes: 204772
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll A,V,B,W,T;
    cin >> A >> V >> B >> W >> T;
    if((V-W)*T >= abs(A-B)){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long k = sc.nextLong();
		if(k > a) {
			System.out.printf("0 %d",Math.max(b-(k-a),0));
		}else {
			System.out.printf("%d %d",a-k,b);
		}
		sc.close();
	}
}

Measured memory_bytes: 21844
import numpy as np


def check(t_diff, x_diff, y_diff):
    l1 = abs(x_diff) + abs(y_diff)
    if l1 > t_diff:
        return False
    elif (t_diff - l1) % 2 == 1:
        return False
    else:
        return True

N = int(input())
t = np.zeros(N+1,)
x = np.zeros(N+1,)
y = np.zeros(N+1,)
for i in range(N+1):
    if i != 0:
        t[i], x[i], y[i] = tuple(map(int, input().split()))

for j in range(N):
    t_diff = t[j+1] - t[j]
    x_diff = x[j+1] - x[j]
    y_diff = y[j+1] - y[j]
    if not check(t_diff, x_diff, y_diff):
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 21404
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	std::vector<int> h;
	cin >> N;
	h.resize(N);
	for (int i = 0; i < N; i++) cin >> h[i];
	vector<int> ans(N);
	ans[0] = 0;
	for (int i = 1; i < N; i++) {
		if (i == 1) {
			ans[i] = abs(h[i]-h[i - 1]);
		}
		else {
			ans[i] = min(ans[i - 1] + abs(h[i] - h[i - 1]),
						ans[i - 2] + abs(h[i] - h[i - 2]));
		}
	}
	
	cout << ans[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
import itertools

N,M = map(int, sys.stdin.readline().strip().split())
H = list(map(int, sys.stdin.readline().strip().split()))

AB = []
for _ in range(M):
    AB.append(list(map(int, sys.stdin.readline().strip().split())))


ans = N - len(set(itertools.chain.from_iterable(AB)))
n = [[i] for i in range(N)]

for i in AB:
    n[i[0]-1].append(i[1]-1)
    n[i[1]-1].append(i[0]-1)

# print(n)
for i in n:
    me = H[i[0]]
    flag = False
    for j in i[1:]:
        # print(f'{me} > {H[j]}')
        if me > H[j]:
            flag = True
            continue
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)


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

set<int> s;

int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		int a;
		cin >> a;
		if(s.find(a)==s.end())s.insert(a);
		else s.erase(s.find(a));
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=4e5+10;
const double eps=1e-8;
const int mod=1e9+9;
#define ll long long
using namespace std;
struct edge{int t;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y){o->t=y;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}


int n;
int a[MAXN];
vector<int>vec;

typedef struct node{
    int l,r,maxx;
}node;
node d[MAXN*21];

int rt[MAXN],cnt,sz;

void update(int &x,int y,int l,int r,int t,int k){
    x=++cnt;d[x]=d[y];d[x].maxx=max(d[x].maxx,k);
    if(l==r)return ;
    int mid=(l+r)>>1;
    if(t<=mid)update(d[x].l,d[y].l,l,mid,t,k);
    else update(d[x].r,d[y].r,mid+1,r,t,k);
}

int ans;
void query(int x,int l,int r,int ql,int qr){
    if(!x)return ;
    if(ql<=l&&r<=qr){
	ans=max(ans,d[x].maxx);
	return ;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)query(d[x].l,l,mid,ql,qr);
    if(qr>mid)query(d[x].r,mid+1,r,ql,qr);
}
int ans1[MAXN];
void dfs(int x,int y){
    ans=0;
    if(a[x]>1)query(rt[y],1,sz,1,a[x]-1);
    ans++;ans1[x]=max(ans1[y],ans);
    update(rt[x],rt[y],1,sz,a[x],ans);
    link(x){
	if(j->t==y)continue;
	dfs(j->t,x);
    }
}

int main(){
    n=read();
    inc(i,1,n)a[i]=read(),vec.pb(a[i]);
    sort(vec.begin(),vec.end());
    sz=unique(vec.begin(),vec.end())-vec.begin();
    inc(i,1,n)a[i]=lower_bound(vec.begin(),vec.begin()+sz,a[i])-vec.begin()+1;
    int x,y;
    inc(i,1,n-1)x=read(),y=read(),add(x,y),add(y,x);
    dfs(1,0);
    inc(i,1,n){
	printf("%d\n",ans1[i]);
    }
    return 0;
}


Measured memory_bytes: 65664
import java.util.*;
import java.io.*;
import java.util.Arrays; 
import java.util.ArrayList; 
import java.util.Collections; 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try (PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            FastScanner in = new FastScanner(System.in);
            String s = in.next();
            char[] characters = s.toCharArray();

            if(characters[characters.length-1] == 's') {
                out.println(s + "es");
            } else {
                out.println(s + "s");
            }



        } finally {
            //out.close();
        }
        
           
    }
}


class FastScanner {
   private final BufferedReader br;
   private StringTokenizer st;
 
    FastScanner(InputStream InputStream) {
        br = new BufferedReader(new InputStreamReader(InputStream));
    }
    
    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
    
    int nextInt() {
        return Integer.parseInt(next());
    }
    
    long nextLong() {
        return Long.parseLong(next());
    }
    
    double nextDouble() {
        return Double.parseDouble(next());
    }


    
    ArrayList<Integer> nextIntList(int count) {
        ArrayList<Integer> array = new ArrayList<>();
        for (int n = 0; n < count; n++) {
            int number = nextInt();
            array.add(number);
        }
        return array;
    }
    
    int[] nextIntArray(int count) {
        int[] array = new int[count];
        for (int n = 0; n < count; n++) {
            array[n] = nextInt();
        }
        return array;
    }
}

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

int main() {
    ll n;
    cin >> n;
    string ans = "No";
    if(n % 10 == 7){
        ans = "Yes";
    }
    n /= 10;
    if(n % 10 == 7){
        ans = "Yes";
    }
    n /= 10;
    if(n % 10 == 7){
        ans = "Yes";
    }
    cout << ans << endl;
}

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

//int _; 

int x;

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> x;
	for(int i=0;i<1000;i++)
		for(int j=0;j<1000;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(k == 1)
					i=-i;
				if(k == 2)
					j=-j;
				if(i*i*i*i*i-j*j*j*j*j == x)
				{
					cout << i << ' ' << j << endl;
					return 0;
				}
				i=abs(i);
				j=abs(j);
			}
		} 	
	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>


int main (){
    int r,d;
    long long int initx;
    scanf("%d %d %lld",&r,&d,&initx);
    for (int i = 0; i < 10; i++){
        printf("%lld\n",r*initx-d);
        initx=r*initx-d;
    }
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
int count_a, count_b, count_c, count_d;
#define MIN(a, b) ((a) < (b) ? (a) : (b))
void countab(char* str) {
	int len = strlen(str);
	int ans = 0;
	if (str[0] == 'B')count_b++;
	if (str[len - 1] == 'A')count_a++;
	if (str[0] == 'B' && str[len - 1] == 'A') {
		count_c++;
		count_a--;
		count_b--;
	}
	for (int i = 0; i < len-1; i++) {
		if (str[i] == 'A' && str[i + 1] == 'B') {
			count_d++;
		}
	}
}

int main() {
	/*int n, k;
	scanf("%d %d", &n, &k);
	printf("%d\n", n - k + 1);*/
	
	/*
	int r, g, b, N, R, G, B;
	int count = 0;
	scanf("%d %d %d %d", &R, &G, &B, &N);
	if (R < G) {
		SWAP(R, G);
	}
	if (G < B) {
		SWAP(G, B);
		if (R < G) {
			SWAP(R, G);
		}
	}
	for (r = N / R; r >= 0; r--) {
		int rest = N - r * R;
		for (g = rest / G; g >= 0; g--) {
			int rest2 = rest - g * G;
			if (rest2%B == 0)count++;
		}
	}

	printf("%d\n", count);*/
	
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		char str[11];
		scanf("%s", str);
		countab(str);
	}
	if (count_c != 0) {
		//printf("%d\n", count_c - 1 + MIN(count_a, count_b) + (count_a != count_b) + count_d);
		//count_a += count_c;
		//count_b += count_c;
		//printf("%d\n", MIN(count_a, count_b) + count_d);
		int ans = 0;
		ans += count_c - 1;
		if (count_a > 0) {
			count_a--;
			ans++;
		}
		if (count_b > 0) {
			count_b--;
			ans++;
		}
		ans += MIN(count_a, count_b);
		printf("%d\n", ans+count_d);
	}
	else {
		printf("%d\n", MIN(count_a, count_b) + count_d);
	}


	return 0;
}

Measured memory_bytes: 128
#include <unordered_map>
#include <iostream>
#include <cstring>
using namespace std;

long long ans[501][501];
long long prime[1001];
void initprime() {
	int pn=0;
	long long base=2;
	for (int i=0; i<1000;) {
		auto isprime = [&](long long a) {
			for (int k=0; k<i; k++)
				if (a%prime[k] == 0)
					return false;
			return true;
		};
		// cout<<i<<" "<<base<<endl;
		if (isprime(base))
			prime[i++] = base++;
		else
			base++;
	}
}
int main() {
	initprime();
	int tn; cin>>tn;
	int n=500;
	// diagonal from (0,0) to (n-1,n-1);
	auto idxA = [&] (int x, int y) -> int { return x<y?(y-x-1):(x-y); };
	// diagonal from (0,n-1) to (n-1,0);
	auto idxB = [&] (int x, int y) -> int { return 300 + ( (x+y<n)?(x+y):((n-(x+y)/2)*2-1) ); };

	auto isVaild = [&](int x, int y) {
		if (x<0 || x>=n || y<0 || y>=n)
			return false;
		return true;
	};
	for (int i=0; i<n; i++) {
		for (int j=i%2; j<n; j+=2)
			ans[i][j] = prime[idxA(i,j)]*prime[idxB(i,j)];
		for (int j=(i+1)%2; j<n; j+=2) {
			ans[i][j] = 1;
			if (isVaild(i,j+1) || isVaild(i+1,j)) // if ((i+j+1)/2 < n)
				ans[i][j] *= prime[idxB(i,j+1)];
			if (isVaild(i-1,j) || isVaild(i,j-1)) // if (0 <= (i+j-1)/2)
				ans[i][j] *= prime[idxB(i,j-1)];
			if (isVaild(i-1,j) || isVaild(i,j+1)) // if (-n+1 < x-y)
				ans[i][j] *= prime[idxA(i-1,j)];
			if (isVaild(i,j-1) || isVaild(i+1,j)) // if (x-y < n-1)
				ans[i][j] *= prime[idxA(i+1,j)];
			ans[i][j]++;
		}
	}
	long long tmax=0;
	unordered_map<long long, pair<int,int> > hit;
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++) {
			tmax = max(tmax, ans[i][j]);
			if (hit.find(ans[i][j]) != hit.end()) {
				cout<<">>hit "<<i<<","<<j<<" == "<<ans[i][j]<<endl;
				cout<<"\t Collide : "<<hit[ans[i][j]].first<<", "<<hit[ans[i][j]].second<<endl;
				// return 0;
			}else
				hit[ans[i][j]] = make_pair(i,j);
		}
	// cout<<tmax<<endl;
	n=tn;
	for (int i=0; i<n; i++, cout<<endl)
		for (int j=0; j<n; j++)
			cout<<ans[i][j]<<"\t";
	// cout<<"debug "<<ans[258][147]<<" "<<ans[72][397]<<endl;
	return 0;
}


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

typedef long long ll;
const ll mod=1e9+7;
const ll N=3e5+1;
const ll INF=1e10;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	int ans=s.size();
	for(int i=0;i<s.size()-t.size()+1;i++){
		int cnt=0;
		for(int j=0;j<t.size();j++) cnt+=(t[j]!=s[i+j]);
		ans=min(ans,cnt);
	}
	cout<<ans;
} 


Measured memory_bytes: 3648
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    k = int(input())
    A = list(map(int, input().split()))[::-1]

    if A[0] != 2:
        print(-1)
    else:
        prev_min, prev_max = 2, 3
        for i in range(1, k):
            a = A[i]
            if a > prev_max:
                print(-1)
                break
            else:
                if prev_min % a == 0:
                    now_min = prev_min
                else:
                    now_min = (prev_min // a + 1) * a
                if now_min > prev_max:
                    print(-1)
                    break
                diff = prev_max - now_min
                now_max = now_min + (diff // a + 1) * a - 1
                prev_min, prev_max = now_min, now_max
        else:
            print(prev_min, prev_max)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 20176
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;


int main()
{
    ll H;
    cin >> H;
    ll res = 0;
    ll kake = 1;

    while(H != 0)
    {
        res += kake;
        H /= 2;
        kake *= 2;
    }


    cout << res << endl;


    return 0;
}

Measured memory_bytes: 256