akhauriyash/Code-Regression huggingface dataset:
// @author : Shubham Kalani

#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define len(a) (int)a.size()
#define all(a) (a).begin(), (a).end()
#define pq priority_queue
#define FASTIO  ios::sync_with_stdio(false); cin.tie(0);

using namespace std ;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
   return '"' + s + '"';
}

string to_string(const char* s) {
   return to_string((string) s);
}

string to_string(bool b) {
   return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
   bool first = true;
   string res = "{";
   for (int i = 0; i < static_cast<int>(v.size()); i++) {
         if (!first) {
            res += ", ";
         }
   first = false;
   res += to_string(v[i]);
   }
   res += "}";
   return res;
}

template <size_t N>
string to_string(bitset<N> v) {
   string res = "";
   for (size_t i = 0; i < N; i++) {
         res += static_cast<char>('0' + v[i]);
   }
   return res;
}

template <typename A>
string to_string(A v) {
   bool first = true;
   string res = "{";
   for (const auto &x : v) {
         if (!first) {
               res += ", ";
         }
    first = false;
    res += to_string(x);
   }
   res += "}";
   return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
   return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
   return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
   return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
   cerr << " " << to_string(H);
   debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr<<"LINE ("<< __LINE__ << ") : [" << #__VA_ARGS__ << "] -> ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve(int id){
    string n;
    cin >> n;
    for (int i = 0; i < 3; ++i){
        if(n[i] == '1')
            n[i] = '9'; 
        else if(n[i] == '9') n[i] = '1' ; 
    }
    cout << n ; 
}

int main(){
   FASTIO 
   //freopen("in1.txt" , "r" , stdin) ; 

   int T = 1;
   //cin >> T ;
   for (int id = 1; id <= T; ++id){
      solve(id);
   }

   cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
   return 0 ;
}




Measured memory_bytes: 3844
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    char S[1002][1002] = {};
    rep(i, 0, H){
        rep(j, 0, W){
            cin >> S[i][j];
        }
    }
    int dp[1002][1002];
    rep(i, 0, H+1){
       rep(j, 0, W+1){
          dp[i][j] = 0; 
       }
    }
    dp[1][0] = 1;

    rep(i, 1, H+1){
        rep(j, 1, W+1){
            if(S[i-1][j-1] == '.'){
                dp[i][j] = dp[i-1][j] % MOD + dp[i][j-1] % MOD; 
                dp[i][j] = dp[i][j] % MOD;
            }
        }
    }
    cout << dp[H][W] << endl;
    
    return 0;
}




Measured memory_bytes: 5120
#include<stdio.h>
int main(void){
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);
	d = a/b;
	r = a%b;
	f = (double)a/(double)b;
	printf("%d %d %f\n", d, r, f);
	return 0;
	}
		

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

using namespace std;

struct S{
	int stay_time;
	string stay_name;
};

int main(){

	int N,T;
	int fhh,fmm,thh,tmm;
	char gav;
	string fname,tname;
	int stay;
	S tmp;
	vector<S> ans;

	cin>>N>>T;

	cin>>fhh>>gav>>fmm>>fname;
	for(int i=0;i<N-1;i++){
		cin>>fhh>>gav>>fmm>>fname>>thh>>gav>>tmm>>tname;
		stay=(thh-fhh)*60+tmm-fmm;
		if(stay>=T){
			tmp.stay_time=stay;
			tmp.stay_name=fname;
			ans.push_back(tmp);
		}
	}

	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].stay_name<<" "<<ans[i].stay_time<<endl;
	}

	return 0;
}

Measured memory_bytes: 1220
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BModerateDifferences solver = new BModerateDifferences();
        solver.solve(1, in, out);
        out.close();
    }

    static class BModerateDifferences {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt() - 1;
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();
            long dif = Math.abs(a - b);
            for (int i = 0; i <= n; i++) {
                // 右にi回,左にn-i回
                if (c * i - d * (n - i) <= dif && dif <= d * i - c * (n - i)) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
        }

    }
}



Measured memory_bytes: 35892
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h,n;
  cin >> h >> n;
  vector<int>a(n);
  for(int i = 0;i<n;i++) cin >> a.at(i);
  int sum = 0;
  for(int i = 0;i < a.size();i++) sum += a.at(i);
  if(sum >= h) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3668
N, K = map(int, input().split())
h = list(map(int, input().split()))

tmp = [int(1e9)] * (N+10)
for i in range(K):
    if i < len(h):
        tmp[i] = abs(h[i] - h[0])

for i in range(K, N):
    m = int(1e9)
    for j in range(K):
        if i - K >= 0:
            m = min(m, tmp[i-j-1]+abs(h[i]-h[i-j-1]))
            tmp[i] = m


print(tmp[N-1])

Measured memory_bytes: 52448
n = gets.to_i

a = gets.to_i
b = gets.to_i

can = b-a

if n==2 then
puts can

else

if a>b then
left = b
else
left = a
end

m = n-2


m.times{
right = gets.to_i
d = right - left
if d>can then
can = d
end
if right < left then
left = right
end
}

puts can

end


Measured memory_bytes: 6880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class State
{

    public struct AB
    {
        public int A;
        public int B;

        public AB(int a,int b)
        {
            this.A = a;
            this.B = b;

        }
    }

    public static void Main()
    {
        int N, M;
        var split = Console.ReadLine().Split().Select(int.Parse).ToArray();
        N = split[0];
        M = split[1];
        AB[] ab = new AB[N];
        for (long i = 0; i < N; i++)
        {
            split = Console.ReadLine().Split().Select(int.Parse).ToArray();

            ab[i] = new AB(split[0], split[1]);
        }
        Array.Sort(ab,comparer);
        long store = 0;
        int need = M;
        int[] buy = new int[N];

        while (need >0)
        {
            if (ab[store].B <= need)
            {
                buy[store] = ab[store].B;
                need -= ab[store].B;
                store++;
            }
            else
            {
                buy[store] = need;
                break;
            }
        }
        long pay = 0;
        for (int i = 0; i < N; i++)
        {
            if (buy[i] == 0) break;
            long temp = ab[i].A;
            temp *= buy[i];
            pay += temp;
        }
        Console.WriteLine(pay);

    }

    public static int comparer(AB a,AB b)
    {
        if (a.A > b.A) return 1;
      	if(a.A==b.A) return 0;
        else return -1;
    }



}



Measured memory_bytes: 18492
using System;
using System.Linq;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] B = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int sum = 0;
            int[] A = new int[N];
            A[0] = B[0];
            A[1] = B[0];
            sum = A[0] + A[1];
            for (int i=2;i<N;i++)
            {
                A[i] = B[i - 1];
                if (A[i - 1] > B[i - 1])
                {
                    sum -= A[i - 1];
                    A[i - 1] = B[i - 1];
                    sum += A[i - 1];
                }
                sum += A[i];
            }
            Console.WriteLine(sum);
            
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int n,m,a[210],k=0,s=0;
long long sum,sum1,p[300010],Mod=1e9+7;
long long ksm(long long aa,long long bb)
{
	long long an=1;
	for (;bb;bb>>=1)
	{
		if (bb&1) an=an*aa%Mod;
		aa=aa*aa%Mod;
    }
    return an;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=2;i*i<=m;++i)
	{
		if (m%i==0)  k++;
		while (m%i==0) a[k]++,m/=i,s++;
    }
    if (m>1) a[++k]=1,s++;
    p[0]=1;
    for (int i=1;i<=n+s;i++)
      p[i]=p[i-1]*i%Mod;
    sum=1;
    for (int i=1;i<=k;i++)
    	sum=sum*p[a[i]+n-1]%Mod*ksm(p[a[i]]*p[n-1]%Mod,Mod-2)%Mod; 
    cout<<sum;
} 



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
bool ok=true;
vector<pair<int,ll>> G[MAX];
vector<int> visited(MAX);
ll T;

void DFS(int u,int p){
    int cnt=0;
    for(int i=0;i<G[u].size();i++){
        int a=G[u][i].first;
        ll b=G[u][i].second;
        if(a==p) continue;
        cnt++;
        G[u][i].second-=T*cnt;
        DFS(a,u);
    }
}

void DFS2(int u,int p,int goal,bool &ok){
    for(int i=0;i<G[u].size();i++){
        int a=G[u][i].first;
        if(a==p) continue;
        if(a==goal){
            ok=true;
            break;
        }
        DFS2(a,u,goal,ok);
    }
    if(ok){
        if(p==-1) return;
        for(int i=0;i<G[p].size();i++){
            if(G[p][i].first==u){
                G[p][i].second+=T;
                break;
            }
        }
    }
}

bool compare(pair<int,ll> a,pair<int,ll> b){
    if(a.second==b.second) return a.first<b.first;
    return a.second<b.second;
}

int main(){

    int N,S,E;cin>>N>>T>>S>>E;
    S--;E--;
    
    for(int i=0;i<N-1;i++){
        int a,b;
        ll c;cin>>a>>b>>c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    
    for(int i=0;i<N;i++){
        sort(all(G[i]),compare);
    }
    
    bool aaa=false;
    DFS(S,-1);
    
    DFS2(S,-1,E,aaa);
    
    bool ok=true;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<G[i].size();j++){
            if(G[i][j].second<=0) ok=false;
            //cout<<G[i][j].second<<endl;
        }
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}






Measured memory_bytes: 13596
def divisors(n):
    res = 0
    for i in range(1, n + 1):
        if n % i == 0:
            res += 1
    return res


def main():
    n = int(input())
    res = 0
    for i in range(1, n + 1, 2):
        d = divisors(i)
        if d == 8:
            res += 1
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  vector<int>v(n),c(n);
  for(int i=0;i<n;i++){
    cin>>v[i];}
    for(int i=0;i<n;i++){
    cin>>c[i];}
    for(int i=0;i<n;i++){
    if(v[i]>c[i]){
      ans += (v[i]-c[i]);
      }else{
        continue;
      }
    }
    cout<<ans<<endl;
}
 

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

#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 1e5+10;
vi g[N];
vi dis(N,0),vis(N,0);

int ans =0;

vi top;

void dfs(int node)
{
    vis[node] = 1;
    
    for(auto x : g[node])
        if(!vis[x]) dfs(x);
        
    top.pb(node);
}

void dfs2(int node,int par = -1)
{ 
   vis[node] = 1;

    for(auto x : g[node])
    {
     if(!vis[node]) dfs2(x,node);
     dis[node] = max(dis[node],dis[x]);    
    } 
        
    dis[node]++;
}

void solve()
{
 int n,m,a,b;
    cin >> n >> m;
    
 f(i,m)
 {
     cin >> a >> b;
     g[a].pb(b);
 }
    
 for(int i=1;i<=n;i++)
    if(!vis[i]) dfs(i);
    
 for(int i=1;i<=n;i++) vis[i] = 0;   
     
 for(auto x : top)    
   if(vis[x]==0) dfs2(x);   
       
 for(int i=1;i<=n;i++) ans=max(ans,dis[i]);
 cout << ans-1;   
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N,M;
int nor, bip, sing, done[MX];
ll ans;
vi adj[MX];
bool ok = 1;

ll sq(ll x) { return x*x; };

void dfs(int x, int y) {
    if (done[x]) {
        if (done[x] != y) ok = 0;
        return;
    }
    // cout << "HUH " << x << "\n";
    done[x] = y;
    for (int i: adj[x]) dfs(i,y^3);
}

void solve(int x) {
    if (sz(adj[x]) == 0) {
        sing ++;
        return;
    }
    ok = 1;
    dfs(x,1); // cout << "OOPS " << x << "\n";
    if (ok) bip ++;
    else nor ++;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    F0R(i,M) {
        int u,v; cin >> u >> v;
        adj[u].pb(v), adj[v].pb(u);
    }
    FOR(i,1,N+1) if (!done[i]) {
        //cout << i << "\n";
        solve(i);
    }
    //cout << nor << " " << bip << " " << sing << "\n";
    F0R(i,sing) {
        ans += 2*N-1; N --;
    }
    //cout << ans << "\n";
    ans += sq(bip);
    ans += sq(nor+bip);
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

typedef long long ll;

int main() {
    int H, W, M, h, w;
    cin >> H >> W >> M;
    vector<int> R(H, 0), C(W, 0);
    set<pair<int, int>> st;
    rep(i, M) {
        cin >> h >> w;
        h--;
        w--;
        R[h]++;
        C[w]++;
        st.insert(make_pair(h, w));
    }
    int maxR = 0, maxC = 0;
    rep(i, H) maxR = max(maxR, R[i]);
    rep(i, W) maxC = max(maxC, C[i]);
    vector<int> rs, cs;
    rep(i, H) if (R[i] == maxR) rs.push_back(i);
    rep(i, W) if (C[i] == maxC) cs.push_back(i);
    rep(i, rs.size()) {
        rep(j, cs.size()) {
            if (st.count(make_pair(rs[i], cs[j]))) continue;
            cout << maxR + maxC << "\n";
            return 0;
        }
    }
    cout << maxR + maxC - 1 << "\n";
}

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

using namespace std;

int main()
{
    int a[5];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    int t1=0,t2=0;
    for(int i=0;i<3;++i){
        if(a[i]==7) t1++;
        else if(a[i]==5) t2++;
    }
    if(t1==1&&t2==2) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 char ch;
  cin>>ch;
  if(ch >= 'A' && ch <= 'Z')
  {
   cout<<'A'; 
  }
  else if(ch >= 'a' && ch <= 'z')
  {
    cout<<'a';
  }
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  vector<int> H(N);
  for (int i = 0; i < N; i++)
  {
    cin >> H.at(i);
  }
  
  H.at(0)--;

  string ans = "Yes";
  for (int i = 1; i < N; i++)
  {
    if (H.at(i) != H.at(i - 1)) H.at(i)--;
    if (H.at(i) < H.at(i - 1))
    {
      ans = "No";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
h = int(input())

temp = 0
for i in range(1, 50):
    temp = 2**i
    if temp <= h:
        continue
    else:
        N = i
        break

#二乗の和を繰り返す回数
ans = 0
for i in range(N):
    ans += 2**i
    #print("ans: ", ans)
print(ans)




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int ans[125252];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s;
	cin>>s;
	int n=s.size();
	int odd=0, even=0;
	bool flag=true;
	REP(i, n){
		if(flag && s[i]=='L'){
			if(i&1){
				ans[i-1]+=even;
				ans[i]+=odd+1;
			}
			else{
				ans[i-1]+=odd;
				ans[i]+=even+1;
			}
			flag=false;
			odd=0;
			even=0;
		}
		else if(s[i]=='R'){
			flag=true;
			if(i&1){
				++odd;
			}
			else{
				++even;
			}
		}
	}
	// REP(i, n){
	// 	cout<<ans[i]<<" \n"[i==n-1];
	// }
	odd=0;
	even=0;
	flag=true;
	FORR(i, 0, n){
		if(flag && s[i]=='R'){
			if((n-1-i)&1){
				ans[i]+=odd;
				ans[i+1]+=even-1;
			}
			else{
				ans[i]+=even;
				ans[i+1]+=odd-1;
			}
			flag=false;
			odd=0;
			even=0;
		}
		else if(s[i]=='L'){
			flag=true;
			if((n-1-i)&1){
				++odd;
			}
			else{
				++even;
			}
		}
	}
	REP(i, n){
		cout<<ans[i]<<" \n"[i==n-1];
	}
	return 0;
}


Measured memory_bytes: 1104
x,n=map(int,input().split())
try:
 P = list(map(int,input().split()))
except EOFError:
  print(x)
else:
  ans1 = x
  ans2 = x
  if x not in P:
    print(x)
  else:
    while True:
        ans1 += 1
        ans2 -= 1
        if ans1 not in P and ans2 not in P:
          print(ans2)
          break
        elif ans1 in P and ans2 not in P:
          print(ans2)
          break
        elif ans2 in P and ans1 not in P:
          print(ans1)
          break

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int d[100001];

int main() {
	cin >> N;
	for(int i = 0; i < N; i++) cin >> d[i];
	sort(d, d + N);
	cout << d[N / 2] - d[N / 2 - 1]; 
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, t[100], m, s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> t[i];
    s += t[i];
  }
  cin >> m;
  FOR(i, 0, m){
    int p, x;
    cin >> p >> x;
    cout << s-t[p-1]+x << endl;
  }
}

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

using namespace std;

int main()
{
    string s; cin >> s;
    reverse(s.begin(), s.end());
    string ans = "YES";

    vector<string> t{"dream", "dreamer", "erase", "eraser"};
    for (int i = 0; i < t.size(); ++i) {
        reverse(t[i].begin(), t[i].end());
    }

    size_t pos = 0;
    while (pos < s.size()) {
        bool f = false;
        for (int i = 0; i < t.size(); ++i) {
            int size = t[i].length();
            if (s.compare(pos, size, t[i]) == 0) {
                pos += size;
                f = true;
                break;
            }
        }
        if (!f) {
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B < C+D) {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

ll mod=1000000007;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<int> a(N);
	for(int i=0; i<N; ++i) cin >> a[i];
	ll ans=0, sum=(K*(K-1)/2)%mod;
	for(int i=0; i<N; ++i){
	    ll bef=0, aft=0;
	    for(int j=0; j<N; ++j){
	        if(a[i]>a[j]){
	            if(j<i) ++bef;
	            else ++aft;
	        }
	    }
	    ans=(ans+(aft*K)%mod+((bef+aft)*sum)%mod)%mod;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  int N;
  int Y=0;
  string S;

  cin >> N;
  
  for (int i=0;i<N;i++)
  {
    cin >> S;
    if (S=="Y")
      Y = 1;
  }
  
  if ( Y == 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}


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

int main (){
	int N;cin>>N;
	int *H = new int[N];
	for(int i=0;i<N;++i)cin>>H[i];
	int count=1;
	int max=H[0];
	for(int i=1;i<N;++i){
		if(max<=H[i]){
			count++;
			max=H[i];
			}
	}
	cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
from copy import deepcopy

if __name__ == '__main__':
    a,b  = map(int, input().split())
    count = [0]*a
    count2 = [-1]*a

    ans1 = 0
    ans2 =0
    for i in range(b):
        s = input()
        s = s.split(" ",)
        s1 = int(s[0])-1
        s2 = s[1]
        if count[s1]  >-1:
            if s2 == "AC":
                count2[s1] = deepcopy(count[s1])
                count[s1] = -1
            else:
                count[s1] = count[s1] +1

    for i in count2:
        if i > -1:
            ans1 = ans1+1
            ans2 = ans2 + i
    print(str(ans1) + " "+str(ans2) )



Measured memory_bytes: 4980
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_C

???????§????????????????II
"""
from enum import Enum
from heapq import heappush, heappop, heapify


class Sssp(object):
    """ single source shortest path """
    INFINITY = 999999999
    class Status(Enum):
        """ ?????????????¨??????¶??? """
        white = 1  # ????¨????
        gray = 2  # ?¨???????
        black = 3  #?¨???????

    def __init__(self, data):
        num_of_nodes = len(data)
        self.color = [Sssp.Status.white] * num_of_nodes  # ????????????????¨??????¶???
        self.d = [Sssp.INFINITY] * num_of_nodes  # ?§???????????????????
        self.p = [-1] * num_of_nodes  # ????????????????????????????¨?????????????????????????
        self.adj = [[] for _ in range(num_of_nodes)]
        self.make_adj(data)


    def make_adj(self, data):
        # ??£??\??????????????????
        for d in data:
            my_id = d[0]
            d = d[2:]
            while len(d) > 1:
                to_node, cost = d[0], d[1]
                self.adj[my_id].insert(0, (to_node, cost))
                d = d[2:]


    def dijkstra(self, start):
        self.d[start] = 0
        pq = []
        heappush(pq, (0, 0))

        while pq:
            cost, u = heappop(pq)
            self.color[u] = Sssp.Status.black
            if self.d[u] < cost:
                continue

            for v, cost in self.adj[u]:
                if self.color[v] == Sssp.Status.black:
                    continue
                if self.d[v] > self.d[u] + cost:
                    self.d[v] = self.d[u] + cost
                    heappush(pq, (self.d[v], v))
                    self.color[v] = Sssp.Status.gray


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = []
    for i in range(num):
        data.append(list(map(int, input().split(' '))))

    # ???????????¢?´¢
    s = Sssp(data)
    s.dijkstra(0)

    # ???????????¨???
    for i in range(num):
        print('{0} {1}'.format(i, s.d[i]))

Measured memory_bytes: 78648
#include<bits/stdc++.h>
#define ll long long
#define mo 1000000007
using namespace std;
int n,x,y,ans;
int main(){
	scanf("%d",&n);
	while (n--){
		int x,y;
		scanf("%d%d",&x,&y);
		for (;x%y&&x>=y;){
			int v1=x%y,v2=x/y+1;
			x-=v2*(v1/v2);
			if (!(x%y)) break;
			x-=x/y+1;
		};
		ans^=x/y;
	} 
	puts(ans?"Takahashi":"Aoki");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int temp, max1=-1, max2=-1, max3=-1;
	// max3 < max2 < max1
	int i;
	for(i=0;i<10;i++) {
		scanf("%d", &temp);
		if(temp>max1) {
			max3 = max2;
			max2 = max1;
			max1 = temp;
		} else if (temp>max2) {
			max3 = max2;
			max2 = temp;
		} else if (temp > max3) {
			max3 = temp;
		}
	}
	printf("%d\n%d\n%d\n", max1, max2, max3);
	return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

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

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

ll f(ll b, ll x) {
    ll ans = 0;
    while (x > 0) {
        ans += x % b;
        x /= b;
    }
    return ans;
}

void solve() {
    ll n, s;
    cin >> n >> s;
    if (s == n){
        cout << n + 1 << '\n';
        return;
    }
    ll ans = 1e18;
    for1(b, 2, 1e6){
        if (f(b, n) == s){
            cout << b << '\n';
            return;
        }
    }
    ll X = n - s;
    for (ll x = 1; x * x <= X; ++x){
        if (X % x == 0){
            ll y = X / x;
            ll b1 = x + 1, b2 = y + 1;
            if (f(b1, n) == s) ans = min(ans, b1);
            if (f(b2, n) == s) ans = min(ans, b2);
        }
    }
    cout << (ans == 1e18 ? -1 : ans) << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3656
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;
template <class Q>
void clearQueue(Q & q) {
    q=Q();
}
void solve(){
	int n;cin>>n;
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i].first>>v[i].second;
	}
	int res=0;
	vector<int>P={-1,1};
	int curr=0;
	for(int p:P){
		for(int q:P){
			int smallest=p*v[0].first+q*v[0].second;
			for(int i=1;i<n;i++){
				curr=p*v[i].first+q*v[i].second;
				res=max(res,curr-smallest);
				smallest=min(smallest,curr);
			}
		}
	}
	cout<<res;
}	
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  ll N,D,A; cin >>N >>D >>A;
  // 敵の数、爆弾の片側範囲、爆弾の攻撃力
  vector<pair<int,int>> enemy(N);
  rep(i,N) cin >>enemy.at(i).first >>enemy.at(i).second;
  // 爆弾は片方の座標を指定するとそこから2D離れた地点まで爆撃できる。
  // 爆弾を座標xを指定して[x,x+2D]を爆撃するように考えれば、端っこのヤツから順に爆撃すればいい。
  sort(all(enemy));

  queue<int> X,Tim;
  ll timestotal = 0;
  ll ans = 0;
  for (int i=0; i<N; i++){
    while (!X.empty()){
      if (X.front() + 2*D < enemy.at(i).first){
        timestotal -= Tim.front();
        X.pop(); Tim.pop();
      }else{
        break;
      }
    }
    enemy.at(i).second -= timestotal * A;

    if (enemy.at(i).second > 0){
      ll times = (enemy.at(i).second + A-1) / A;
      ans += times;
      X.push(enemy.at(i).first);
      Tim.push(times);
      timestotal += times;
    }
  }

  cout <<ans <<endl;
}

Measured memory_bytes: 2688
n,k,q=map(int,input().split())
ans=[k-q]*n
a=[0]*q
for i in range(q):
  a[i]=int(input())
for i in range(q):
  ans[a[i]-1]=ans[a[i]-1]+1
for i in range(n):
  if ans[i]<=0:
    print("No")
  else:
    print("Yes")


Measured memory_bytes: 10480
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  ans = max(a - 2*b, 0);
  printf("%d\n", ans);
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=n-i; j>=0; j--){
            bool ok = true;
            string t = s.substr(i, j);
            for(char c: t){
                if(c != 'A' && c != 'C' && c != 'G' && c != 'T') ok = false;
            }
            if(ok) ans = max(ans, (int)t.size());
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int k;
  int c;
  int sum;

  while (cin >> k && k != 0){
    int i = (k * (k - 1)) / 2;
    sum = 0;
    while (i--){
      cin >> c;
      sum += c;
    }
    cout << sum / (k - 1) << endl;
  }
}

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

int main() {
    int N;
  	cin >> N;
  	switch (N) {
      case 1:
        cout << "Hello World" << endl;
        break;
      case 2:
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
        break;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n,c[4];
vector<string> s;

void input() { 
  cin >> n;
  s.resize(n);
  rep(i, n) { cin >> s[i]; }
}

void solve() {
  rep(i,4){
    c[i]=0;
  }
  rep(i,n){
    if (s[i]=="AC"){
      c[0]++;
    } else if (s[i]=="WA"){
      c[1]++;
    } else if (s[i]=="TLE"){
      c[2]++;
    } else if (s[i]=="RE"){
      c[3]++;
    }
  }
  cout << "AC x " << c[0] << endl;
  cout << "WA x " << c[1] << endl;
  cout << "TLE x " << c[2] << endl;
  cout << "RE x " << c[3] << endl;
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 6348
import math

X = int(input())

ans = 0
while ans == 0:
    ans = X
    for i in range(2, int(math.sqrt(X)) + 1 ):
        if X % i == 0:
            ans = 0
            break
    
    if ans == X:
        break

    X = X + 1

print(ans)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    d = min(a[i], b[i])
    a[i] -= d
    b[i] -= d
    cnt += d

    d = min(a[i+1], b[i])
    a[i+1] -= d
    b[i] -= d
    cnt += d
print(cnt)


Measured memory_bytes: 18624
import java.awt.Stroke;
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        String N=sc.nextLine();
        char[] NN=new char[N.length()];
        for(int i=0;i<N.length();i++){
            NN[i]=N.charAt(i);

        }
        int sum=0;
        for(int i=0;i<N.length();i++){
            int a=Integer.parseInt(""+NN[i]);
            sum=sum+a;
        }
        int x=Integer.parseInt(N);
        if(x%sum==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
        
        

    }
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << a[K-1] << endl;
  
}


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x, n, p[110];
    cin >> x >> n;
    rep(i, n) cin >> p[i];
    set s(begin(p), begin(p) + n);

    rep(i, 110) {
        if (!s.count(x - i)) {
            print(x - i);
            return 0;
        }
        if (!s.count(x + i)) {
            print(x + i);
            return 0;
        }
    }


    return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cctype>
using namespace std;

int main(){
    int n = 0;
    string W,T;
    cin >> W;
    string X,Y;
    X = W;
    transform(X.begin(),X.end(),X.begin(),::toupper);
    for(;;) {
        cin >> T;
        Y = T;
        transform(Y.begin(),Y.end(),Y.begin(),::toupper);
        if ( Y == X ) {
            n += 1;
        } else if (T == "END_OF_TEXT"){
            cout << n << endl;
            break;
        }
    }
}


Measured memory_bytes: 3152
S = list(input())

flag = True
if S != S[::-1]:
    flag = False

N = len(S)

tmp = S[:(N - 1) // 2]

if tmp != tmp[::-1]:
    flag = False

tmp = S[(N + 3) // 2 - 1:]

if tmp != tmp[::-1]:
    flag = False

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

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

int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  for(int i=0;i<N;i++)cin >> W[i];
  int sum=0;
  for(int i=0;i<N;i++)sum+=W[i];
  int s=0; int ans=100000000;
  for(int i=0;i<N;i++){
    s+=W[i];
    ans=min(ans,abs(s-(sum-s)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def dice_rotation(dice, command):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	#S:1->2,2->6,6->5,5->1
	if command == 'S':
		dice[0] = tmp_dice[4]
		dice[4] = tmp_dice[5]
		dice[5] = tmp_dice[1]
		dice[1] = tmp_dice[0]
	#N:1->5,5->6,6->2,2->1
	elif command == 'N':
		dice[0] = tmp_dice[1]
		dice[1] = tmp_dice[5]
		dice[5] = tmp_dice[4]
		dice[4] = tmp_dice[0]
	#W:1->4,4->6,6->3,3->1
	elif command == 'W':
		dice[0] = tmp_dice[2]
		dice[2] = tmp_dice[5]
		dice[5] = tmp_dice[3]
		dice[3] = tmp_dice[0]
	#E:1->3,3->6,6->4,4->1
	elif command == 'E':
		dice[0] = tmp_dice[3]
		dice[3] = tmp_dice[5]
		dice[5] = tmp_dice[2]
		dice[2] = tmp_dice[0]

def dice_spinning(dice):

	tmp_dice = []
	
	for i in range(6):
		tmp_dice.append(dice[i])

	dice[1] = tmp_dice[2]
	dice[2] = tmp_dice[4]
	dice[4] = tmp_dice[3]
	dice[3] = tmp_dice[1]

def comparison_dices(Dice1,Dice2):

	yes_counter = 0
	for j in range(6):
		if Dice1[j] == Dice2[j]:
			yes_counter += 1
	if yes_counter == 6:
		return True

	return False

def full_validation_dices(Dice1,Dice2):

	judgement_result = False

	#1st direction
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'S')

	#2nd direction
	for i in range(4):
		for j in range(4):
			if comparison_dices(Dice1,Dice2) == True:
				judgement_result = True
				break
			else:
				dice_spinning(Dice2)

		if judgement_result == True:
			break
		else:
			dice_rotation(Dice2,'W')

	if judgement_result == True:
		return True
	else:
		return False


def test():

	n = int(input())

	Dices = []

	result = True

	for i in range(n):

		tmp_dice = list(map(int,input().split()))
		Dices.append(tmp_dice)
	
	for i in range(n-1):
		for j in range(i+1,n):
			if full_validation_dices(Dices[i],Dices[j]) == True:
				result = False
				break
		if result == False:
			break

	if result == True:
		print("Yes")
	else:
		print("No")


if __name__ == "__main__":
	test()




Measured memory_bytes: 5616
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    int c = 0;
    while (n >= 5) {
      c += n / 5;
      n /= 5;
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 2952
#include<iostream>
using namespace std;
 
 int main(){
   int H, W;
 
 
   while (1){
     cin >> H >> W;
     if ( H == 0 && W == 0 ) break;
 
     for ( int i = 0; i < H; i++ ){
       for (int j = 0; j < W; j++ ){
         if ( i == 0 || i == H-1 || j == 0 || j == W-1 ){
          cout << "#";
         } else {
           cout << ".";
         }
       }
       cout << "\n";
     }
     cout << endl;
   }
 
   return 0;
}   

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    ll d = abs(A-B);
    if (W >= V) {
        cout << "NO" << '\n';
    }else {
        ll v = V - W;
        if ((d + v - 1) / v <= T){
            cout << "YES" << '\n';
        }else {
            cout << "NO" << '\n';
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3656
N = int(input())
A = list(int(input()) for i in range(N))
B = A[0]
cnt = 1
a = False
for i in range(N):
    if B == 2:
        a = True
        print(cnt)
        break
    else:
        B = A[B-1]
        cnt += 1
if a == False:
    print(-1)

Measured memory_bytes: 49496