akhauriyash/Code-Regression huggingface dataset:
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#define log(args...)
#else
#define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); logf(_it, args); }
void logf(istream_iterator<string> it) {
}
template<typename T, typename ... Args>
void logf(istream_iterator<string> it, T a, Args ... args) {
	cout << *it << " = " << a << endl;
	logf(++it, args...);
}
#endif

#define forn(i,k,n) for(ll i=(k); i<(n); i++)

const double PI = acos(-1);
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
	cinll(h);
	cinll(w);
	ll ans = -1;

	if (w == 1 || h == 1)
		ans = 1;
	else {
		ans = w * h;
		if (ans & 1)
			ans = ans / 2 + 1;
		else
			ans = ans / 2;
	}

	cout << ans << endl;

}

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



Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        String ans = "No";
        for(int i = 1; i < 10; i++){
            for(int j = 1; j < 10; j++){
                if(i*j==n){
                    ans = "Yes";
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
def main():
    N, M = map(int, input().split())
    d = []
    i = 1
    while i * i <= M:
        if M % i == 0:
            d.append(i)
            if M // i != i:
                d.append(M // i)
        i += 1
    d.sort(reverse=True)
    for i in d:
        if M // i >= N:
            print(i)
            return
    print(1)
main()


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

#define P pair<int, int>

int main(){
	int n;
	cin>>n;
	int a[200000];
	rep(i, n) cin>>a[i];
	vector<int> e[200000];
	rep(i, n-1){
		int u, v;
		cin>>u>>v; u--; v--;
		e[u].push_back(v);
		e[v].push_back(u);
	}

	int mm[200000];
	rep(i, n) mm[i]=INT_MAX;
	vector< P > ope;
	vector<int> nxt;
	vector<int> pre;
	int c=0;
	int mx[200000]={0};
	nxt.push_back(0);
	mm[0]=a[0];
	while(1){
		if(nxt.back() < e[c].size()){
			int nc=e[c][nxt.back()];
			nxt.back()++;
			if(pre.empty() || nc!=pre.back()){
				pre.push_back(c);
				nxt.push_back(0);

				//add new num
				int *p=lower_bound(mm, mm+n, a[nc]);
				int l=p-mm;
				mx[nc] = max(mx[c], l);
				ope.push_back(make_pair(l, *p));
				*p = a[nc];

				c=nc;
			}

		}
		else{
			if(pre.size()==0) break;
			c=pre.back();
			pre.pop_back();
			nxt.pop_back();

			//back num
			int l=ope.back().first, pc=ope.back().second;
			mm[l] = pc;
			ope.pop_back();
		}
	}

	rep(i, n) cout<<mx[i]+1<<endl;

	return 0;
}


Measured memory_bytes: 19680
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
#define FF first
#define SS second
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

#define N 2005

void solve()
{
    lli n,m,k;
    cin>>n>>m>>k;

    vll a,b;

    lli sum=0;
    loopl(i,0,n) 
    {
        lli x;
        cin>>x;

        sum += x;
        a.pb(sum);
    }

    sum=0;
    loopl(j,0,m)
    {
        lli x;
        cin>>x;
        sum+=x;
        b.pb(sum);
    }

    lli p1=0,p2=m-1;

    lli ans=0;

    loopl(i,0,n)
    {
        if(a[i] <= k) ans = max(ans , i+1);
    }

    loopl(i,0,m)
    {
        if(b[i] <= k) ans = max(ans , i+1);
    }

    while(p1<n && p2>=0)
    {
        while(p2 >= 0 && a[p1]+b[p2] > k)
            p2--;

        lli cnt=0;
        if(p1>=0 && p1<n) cnt+=a[p1];
        if(p2>=0 && p2<m) cnt+=b[p2];

        if(cnt <= k) ans = max(ans , p1+p2+2);

        p1++;
    }

    cout<<ans;
}   

int main()
{
////////////////////////////////////////////   
    fastio;
////////////////////////////////////////////
    lli t;
    t=1;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  cout << (c>=a && c<=b ? "Yes" : "No") << endl;
  
}



Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)





int main() {

	long long dp[51][51][51*51];

	int n, a;
	cin >> n >> a;

	VI x(n+1);
    x[0]=0;
	FOR(i,1, n) {
		cin >> x[i];
	}


	VI y(x);
	SORT(y);
	int X = max(a, y[n]);

	FOR(j,0, n) {
		FOR(k, 0, n) {
			FOR(s, 0, n * X) {
				if (j == 0 && k == 0 && s == 0) {
					dp[j][k][s] = 1;
				}
				else if (j >= 1 && s < x[j]) {
					dp[j][k][s] = dp[j - 1][k][s];
				}
				else if (j >= 1 && k >= 1 && s >= x[j]) {
					dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
				}
				else {
					dp[j][k][s] = 0;
				}
			}
		}
	}

	long long ans = 0;
	FOR(k, 1, n) {
		ans += dp[n][k][k*a];
	}
	ANS(ans);


	return 0;
}



Measured memory_bytes: 53120
import sys
raw_input = sys.stdin.readline
N = int(raw_input())
L = map(int, raw_input().split())
nm = 0
for i in xrange(N):
	if L[i] < 0:
		nm += 1
		L[i] = abs(L[i])

if nm % 2 == 1 :
	print sum(L) - 2 * min(L)
else:
	print sum(L)

Measured memory_bytes: 41900
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
    using mint = ModInt<MOD>;
    int n;
    cin >> n;
    vector<int> c(n);
    for (auto&e : c) cin >> e;
    sort(c.rbegin(), c.rend());
    
    mint t = 2; t = t.pow(2*n-1);
    mint p = (t / 2);
    mint ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (t * c[i]);
        t += p;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
use proconio::input;
use std::collections::HashSet;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        S: [String; N],
    }
    let mut set = HashSet::new();
    for s in S {
        set.insert(s);
    }

    println!("{}", set.len());
}


Measured memory_bytes: 24824
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N;
vector<string> ans;

void dfs(string& s, int i, int k) {
    if (i == N) {
        ans.push_back(s);
        return;
    }
    rep(j, k) {
        s[i] = 'a' + j;
        dfs(s, i + 1, k);
    }
    s[i] = 'a' + k;
    dfs(s, i + 1, k + 1);
}

int main() {
    cin >> N;
    string s(N, ' ');
    dfs(s, 0, 0);
    for (auto& s : ans) write(s);
}

Measured memory_bytes: 7796
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <map>
#include <cmath>
#include <climits>
#include <queue> 
#include <cstdio>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct Edge {
  int src,dst,weight;
};

struct Data {
  int cur,weight;
  bool operator < ( const Data &data ) const {
    return weight > data.weight;
  }
};

const int IINF = INT_MAX;
const int MAXV = 1010;
int V,E,k,sp,s[10],t[10];
vector<Edge> G[MAXV];
int mindist[MAXV][MAXV];
vector<int> vs;

void dijkstra(int a){ // a -> start point
  rep(i,V) mindist[a][i] = IINF;
  priority_queue<Data> Q;
  Q.push((Data){a,0});
  mindist[a][a] = 0;
  while( !Q.empty() ){
    Data data = Q.top(); Q.pop();
    if( mindist[a][data.cur] < data.weight ) continue;
    rep(i,G[data.cur].size()){
      int next = G[data.cur][i].dst;
      if( mindist[a][next] > data.weight + G[data.cur][i].weight ) {
	mindist[a][next] = data.weight + G[data.cur][i].weight;
	Q.push((Data){next,mindist[a][next]});
      }
    }
  }
}

struct Data2 {
  int cur,weight,took,fin;
  bool operator < ( const Data2 &data ) const {
    if( weight != data.weight ) return weight > data.weight;
    if( cur != data.cur ) return cur > data.cur;
    if( fin != data.fin ) return fin > data.fin;
    return took > data.took;
  }
};

int mindist2[20][1<<7][1<<7];

void dijkstra2(){

  rep(i,vs.size()) rep(j,1<<7) rep(k,1<<7) mindist2[i][j][k] = IINF;

  map<int,int> mp[2],vsmp;

  rep(i,vs.size()) vsmp[vs[i]] = i;
  rep(i,k) {
    mp[0][s[i]] = i;
    mp[1][t[i]] = i;
  } 

  priority_queue<Data2> Q;
  int temp1 = 0, temp2 = 0;
  Q.push((Data2){sp,0,temp1,temp2});

  bool success = true;
  rep(i,k) if( mindist[sp][t[i]] == IINF || mindist[sp][s[i]] == IINF ) {
    success = false;
    break;
  }
  if( !success ) {
    puts("Cannot deliver");
    return;
  }
  while( !Q.empty() ){
    Data2 data = Q.top(); Q.pop();

    if( data.fin == ((1<<k)-1) ) {
      cout << data.weight << endl;
      return;
    }

    if( mindist2[vsmp[data.cur]][data.took][data.fin] < data.weight ) continue;
 
   rep(i,vs.size()){
      int next = vs[i];
      if( next == data.cur ) continue;
      int took = data.took, fin = data.fin;
      if( mp[0].count(next) ) took |= (1<<mp[0][next]);
      if( mp[1].count(next) && ( ( took >> mp[1][next] ) & 1 ) ) fin  |= (1<<mp[1][next]);

      if( mindist2[vsmp[next]][took][fin] > data.weight + mindist[data.cur][next] ) {

	mindist2[vsmp[next]][took][fin] = data.weight + mindist[data.cur][next];
	Q.push((Data2){next,mindist2[vsmp[next]][took][fin],took,fin});
      }
    }

  }
  puts("Cannot deliver");
}

void compute(){
  rep(i,vs.size()) dijkstra(vs[i]);
  dijkstra2();
}

int main(){

  cin >> V >> E >> k >> sp;
  --sp;
  rep(i,E){
    int x,y,w;
    cin >> x >> y >> w;
    --x, --y;
    G[x].push_back((Edge){x,y,w});
    G[y].push_back((Edge){y,x,w});
  }

  vs.push_back(sp);
  rep(i,k){
    cin >> s[i] >> t[i];
    --s[i], --t[i];
    vs.push_back(s[i]);
    vs.push_back(t[i]);
  }

  sort(vs.begin(),vs.end());
  vs.erase(unique(vs.begin(),vs.end()),vs.end());

  compute();

  return 0;
}

Measured memory_bytes: 4400
#include <stdio.h>
int main(){
	char s[5];
	if(scanf("%s",s)==-1){
		return 1;
	};
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
		printf("%s","Bad");
		}
	else{
		printf("%s","Good");
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  cout << (S.at(0)!=S.at(1)&&S.at(1)!=S.at(2)&&S.at(2)!=S.at(0) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import numpy as np
K = int(input())
table = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
c = 9
result = []
for i in table:
  runrun = i
  if runrun[-1] == '0':
    table.extend([runrun + str(int(runrun[-1])), 
                   runrun + str(int(runrun[-1])+1)])
    c += 2
  elif runrun[-1] == '9':
    table.extend([runrun + str(int(runrun[-1])-1), 
                   runrun + str(int(runrun[-1]))])
    c += 2
  else:
    table.extend([runrun + str(int(runrun[-1])-1), 
                   runrun + str(int(runrun[-1])), 
                   runrun + str(int(runrun[-1])+1)])
    c += 3
  if c>=K:
    print(table[K-1])
    exit()


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

typedef long long int ll;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimize ("-fno-defer-pop")


int main()
{

    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n;
    cin>>n;

    ll arr[n+1];

    for(ll i=0;i<n;i++)cin>>arr[i];

    ll ans = INT_MAX;

    for(ll i=0;i<n;i++)
    {
        ll s1 = 0;
        ll s2 = 0;
        for(ll j=i;j>=0;j--)
        {
            s1+=arr[j];
        }
        for(ll j=i+1;j<n;j++){
            s2+=arr[j];
        }
        //cout<<s1<<" "<<s2<<endl;
        ans = min(ans,abs(s1-s2));
    }

    cout<<ans<<endl;


}










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

#define NM_MAX 1002

using namespace std;

int n, m;

bool ma[NM_MAX][NM_MAX];

queue <pair <int, int> > q;

int d[NM_MAX][NM_MAX];

int dl[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};

bool inside (int a, int b)
{
    return (a >= 1 && a <= n && b >= 1 && b <= m);
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            char c;
            cin >> c;
            if(c == '#')
            {
                ma[i][j] = true;
                d[i][j] = 0;
                q.push(make_pair(i, j));
            }
        }
    int mx = 0;
    while(!q.empty())
    {
        pair <int, int> f = q.front();
        mx = max(mx, d[f.first][f.second]);
        q.pop();
        for(int i = 0; i < 4; i++)
        {
            int a = f.first + dl[i], b = f.second + dc[i];
            if(inside(a, b) && ma[a][b] == false)
            {
                q.push(make_pair(a, b));
                d[a][b] = d[f.first][f.second] + 1;
                ma[a][b] = true;
            }
        }
    }
    cout << mx << "\n";
    return 0;
}


Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#define gap cout<<endl;
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

int main(){
	int n;
	cin>>n;
	int arr[n+1];
	fo(i,n) cin>>arr[i];
	int taken[n+1];
	fo(i,n+1) taken[i]=0;
	taken[0]=1;
	int ans=0;
	FOR(i,0,n-1){
		if(taken[arr[i]-1]) {ans=arr[i]; taken[arr[i]]=1;}
	}
	if(ans==0) cout<<-1<<endl;
	else cout<<(n-ans)<<endl;
}

Measured memory_bytes: 1792
s = input()
switch = []
ans = [0] * (len(s))
# R→L or L→Rの変化部分を保存
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        switch.append(i + 1)

# switch[i]: iが偶数なら　R→L
#            iが奇数なら　L→Rの境目番号
start = 0
for i in range(0, len(switch), 2):
    # for文終了時のエラー処理
    if i == len(switch) - 1:
        end = len(s)
    else:
        end = switch[i + 1]
    #  ...RL...LR部分においてカウントする
    for num in range(start, end):
        #　境目部分の偶奇と一致すれば、最終的にその場所に位置する
        if num % 2 == switch[i] % 2:
            ans[switch[i]] += 1
        else:
            ans[switch[i] - 1] += 1
    start = end
print(*ans)


Measured memory_bytes: 10224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << (x) << endl;
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

vector<string> v(8);

char check(int y, int x){
	if(x < 0 || x >= 8 || y < 0 || y >= 8) return '0';
	return v[y][x];
}

int main(){
	vector<string> fig(7);
	fig[0] = "110110000";
	fig[1] = "100100100";
	fig[2] = "111000000";
	fig[3] = "100100000";
	fig[4] = "110011000";
	fig[5] = "100110010";
	fig[6] = "110100000";

	while(1){
		rep(i, 8) if(!(cin >> v[i])) return 0;

		rep(i, 8){
			rep(j, 8){
				if(v[i][j] != '1') continue;
				string s;
				for(int k = 0; k < 3; k++){
					for(int l = 0; l < 3; l++){
						s += check(i+k, j+l);
					}
				}
				rep(k, fig.size()){
					if(s == fig[k]){
						cout << "ABCDEFG"[k] << endl;
						goto nextloop;
					}
				}
			}
		}
nextloop:
		;
	}

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e3 + 5;

int n,m,sx,sy,ex,ey;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int vis[N][N];
char a[N][N];

struct node{
	int x,y,z;
	bool operator <(const node &T) const{
		return z>T.z;
	}
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>sx>>sy>>ex>>ey;
    for(int i=1;i<=n;i++) cin>>a[i]+1;
    priority_queue<node> q;
	memset(vis,-1,sizeof(vis));
    vis[sx][sy]=0;
    q.push({sx,sy,0});
    while(q.size()){
    	node t=q.top();q.pop();
    	// cout<<"t.x="<<t.x<<" t.y="<<t.y<<" t.z="<<t.z<<'\n';
    	if(t.z>=vis[ex][ey] and vis[ex][ey]!=-1) break;
    	// if(t.x==ex and t.y==ey){cout<<t.z<<'\n';return 0;}
    	int x=t.x,y=t.y,z=t.z;
    	for(int i=0;i<4;i++){
    		int tx=x+dx[i];
    		int ty=y+dy[i];
    		// cout<<"tx="<<tx<<" ty="<<ty<<" vis["<<tx<<"]["<<ty<<"]="<<vis[tx][ty]<<" a["<<tx<<"]["<<ty<<"]="<<a[tx][ty]<<'\n';
    		if(tx>=1 and tx<=n and ty>=1 and ty<=m and a[tx][ty]=='.' and (vis[tx][ty]==-1 || z<vis[tx][ty])){
    			vis[tx][ty]=z;
    			q.push({tx,ty,z});
    		}
    	}
    	for(int i=-2;i<=2;i++){
    		for(int j=-2;j<=2;j++){
    			int tx=x+i;
    			int ty=y+j;
    			if(tx>=1 and tx<=n and ty>=1 and ty<=m and a[tx][ty]=='.' and (vis[tx][ty]==-1 || z+1<vis[tx][ty])){
	    			vis[tx][ty]=z+1;
	    			q.push({tx,ty,z+1});
	    		}
    		}
    	}
    }
    cout<<vis[ex][ey]<<'\n';
    return 0;
}

Measured memory_bytes: 8548
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin >> n;
        string s;
        cin >> s;
        int i,j;
        int ans=0;
        for(i=0; i<n-2; i++){
            if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
                ans++;
            }
        }
        cout << ans;

        

}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,m,a[maxn];


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

  cin>>n>>m;
  for (int i=1; i<=m; i++) {
    int l,r; cin>>l>>r;
    a[l]++; a[r+1]--;
  }

  int ans = 0;

  for (int i=1; i<=n; i++) {
    a[i] = a[i] + a[i-1];
  }


  for (int i=1; i<=n; i++) {
    if (a[i] == m) ans++;
  }

  out(ans);


    

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll a[3];rep(i,0,2)cin>>a[i];
    cout<<a[2]<<' '<<a[0]<<' '<<a[1]<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 1e6+6;
const ll inf =1e9;

ll a[MAX],mod=1e9+7;
int main(){
	fastio;
	ll tc,n,m,b,k;
	tc=1;
//	cin>>tc;
	while(tc--){
		cin>>n>>k;
		ll sum=0;
		f(i,k,n+2){
			ll ini=((i-1)*i)/2;
			ll fin= n*i-ini;
			sum+=(fin-ini+1)%mod;
		}
		cout<<sum%mod<<endl;
	}
}

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

int main(){
  int n,_max;
  cin>>n;
  vector<vector<int>> abc(n, vector<int>(3));
  for(int i=0;i<n;i++){
    for(int g=0;g<3;g++){
      cin>>abc.at(i).at(g);
    }
  }
  
  for(int i=1;i<n;i++){
    abc[i][0]=abc[i][0]+max(abc[i-1][1],abc[i-1][2]);
    abc[i][1]=abc[i][1]+max(abc[i-1][0],abc[i-1][2]);
    abc[i][2]=abc[i][2]+max(abc[i-1][0],abc[i-1][1]);
  }
  _max = *max_element(abc[n-1].begin(), abc[n-1].end());
  cout<<_max<<endl;
  return 0;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
ll solve(int d, ll n) {
	if (n <= 1) return 0;
	ll sum = n / 2;
	if (d >= 5) sum += n / 2;
	int d2= (2 * d) % 9;
	if (d2 == 0 && d > 0) d2 = 9;
	sum += solve(d2, n / 2);
	if (n % 2) {
		int d3 = d2 * (n / 2) % 9;
		if (d3 == 0 && d2 > 0) d3 = 9;
		sum++;
		if (d3 + d >= 10) sum++;
	}
	return sum;
}
int main() {
	int M;
	cin >> M;
	ll ans = 0;
	deque<int> que;
	for (int i = 0; i < M; i++) {
		int d;
		ll c;
		cin >> d >> c;
		ans += solve(d, c);
		int d2 = (d*c) % 9;
		if (d2 == 0 && d > 0) d2 = 9;
		que.emplace_back(d2);
	}
	while (que.size() > 1) {
		int d1 = que.front(); que.pop_front();
		int d2 = que.front(); que.pop_front();
		ans++;
		if (d1 + d2 >= 10) ans++;
		int d3 = (d1 + d2) % 9;
		if (d3 == 0 && (d1 > 0 || d2 > 0)) d3 = 9;
		que.push_front(d3);
	}
	cout << ans << endl;
}


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

int main()
{
  int n, x;
  long long max = -1000000;
  long long min = 1000000;
  long long sum = 0;

  cin >> n;

  for( int i = 1; i <= n; i++)
  {
    cin >> x;
    if(x > max) max = x;
    if(x < min) min = x;
    sum += x;
  }

  cout << min << " " << max << " " << sum << endl;

  return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> A(M);
  for(int i=0; i<M; i++) cin >> A.at(i);
  
  int Asum = 0;
  for(int i=0; i<M; i++) Asum += A.at(i);
  
  int ans = max(N - Asum, -1);
  
  cout << ans << endl;
}
  

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    //月曜土曜素数を予め求めておこう
    bool prime[300001];
    rep(i, 300001) prime[i] = true;
    int mon = 8, sat = 6;
    for(int i = 0;; i++){
        int val;
        int inc;
        if(i % 2){
            val = mon;
            mon += 7;
        }
        else{
            val = sat;
            sat += 7;
        }
        if(val > 1000) break;
        for(int j = (val << 1); j <= 300000; j += val) prime[j] = false;
    }
    vector<int> work;
    for(int i = 6; i < 300000; i+=7) if(prime[i]) work.push_back(i);
    for(int i = 8; i < 300000; i+=7) if(prime[i]) work.push_back(i);
    sort(work.begin(), work.end());
    
    while(true){
        int temp; cin >> temp;
        if(temp == 1) break;
        cout << temp << ":";
        rep(i, work.size()){
            if(temp % work[i] == 0) cout << " " << work[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3460
#include <stdio.h>

int main() {
	int a[3][3], c[3][3] = {{0}}, n, b, bingo = 0, t[3], i, j, k;
	for(i = 0; i < 3; i++)
		for(j = 0; j < 3; j++)
			scanf("%d", &a[i][j]);
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d", &b);
		for(j = 0; j < 3; j++)
			for(k = 0; k < 3; k++)
				if(a[j][k] == b) {
					c[j][k] = 1;
					break;
				}
	}
	
	for(i = 0; i < 3; i++)
		t[i] = 1;
	for(i = 0; i < 3; i++)
		for(j = 0; j < 3; j++)
			t[j] &= c[i][j];
	bingo |= t[0] || t[1] || t[2];
	for(i = 0; i < 3; i++)
		t[i] = 1;
	for(i = 0; i < 3; i++)
		for(j = 0; j < 3; j++)
			t[j] &= c[j][i];
	bingo |= t[0] || t[1] || t[2];
	t[0] = 1;
	t[1] = 1;
	for(i = 0; i < 3; i++) {
		t[0] &= c[i][i];
		t[1] &= c[2 - i][i];
	}
	bingo |= t[0] || t[1];
	
	printf(bingo ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    ll n;
    cin >> n;
    print(180 * (n - 2));
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
n, i = STDIN.readline.strip.split(' ').map(&:to_i)
x = STDIN.readline.strip.split(' ').map(&:to_i)
d = x.map{|xi| (xi - i).abs }
def gcd(a)
  a.inject(&:gcd)
end
puts gcd(d)


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    string S; cin >> S;
    stack<int> S1;  // S1は現在扱っている水溜りの面積、S2はこれまで計算してきた水溜りの蓄積
    stack<pair<int,int> > S2;
    int sum;
    rep(i,S.size()){
        char s = S[i];
        if(s == '\\'){
            S1.push(i);
        }else if(s == '/'){
            if(!S1.empty()){
                int j = S1.top(); S1.pop();
                sum += i-j;
                int a = i-j;
                while(S2.size() > 0 && S2.top().first > j){
                    a += S2.top().second; S2.pop();
                }
                S2.push(make_pair(j,a));
            }
        }
    }
    // スタックは上からしか要素を取り出せないため
    vector<int> ans;
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i=0; i<ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3308
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

class UnionFind {
    private:
        vi par;    // x の親ノード
        vi rank;   // 木の高さ
        vi mem;    // メンバの数
        int sz;             // 集合の個数
    public:
        UnionFind(int n) :
            par(n, -1), rank(n, 0), mem(n, 1), sz(n) {
            REP(i,n) par[i] = i;
        }
    
    int size() { return sz; }

    // 集合の追加
    void makeset() {
        par.pb(par.size());
        rank.pb(0);
        mem.pb(1);
        sz++;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }

    int member(int x){
        x = find(x);
        return mem[x];
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]){
            par[x] = y;
            mem[x] += mem[y];
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
            mem[y] += mem[x];
        }
        sz--;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int n,xi,yi;
vpi x,y;


int main(){
    I(n);
    x.resize(n);
    y.resize(n);
    REP(i,n){
        I(xi); I(yi);
        x[i] = mp(xi,i);
        y[i] = mp(yi,i);        
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    priority_queue< pair<int,pi>, vector<pair<int,pi>>,greater<pair<int,pi>>> pq;
    REP(i,n-1){
        pq.push(mp(x[i+1].first-x[i].first,mp(x[i].second,x[i+1].second)));
        pq.push(mp(y[i+1].first-y[i].first,mp(y[i].second,y[i+1].second)));
    }
    UnionFind uf = UnionFind(n);
    ll ret = 0;
    while(n-1){
        auto pqtop = pq.top();
        pq.pop();
        xi = pqtop.second.first;
        yi = pqtop.second.second;
        if(!uf.same(xi,yi)){
            uf.unite(xi,yi);
            n--;
            ret += pqtop.first;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 6388
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial,sqrt
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    h,w,m=MI()
    lis1=[]
    lis2=[]
    for i in range(m):
        a,b=MI()
        lis1.append(a)
        lis2.append(b)
    c1=Counter(lis1)
    X=c1.most_common()
    #print(c1)
    c2=Counter(lis2)
    Y=c2.most_common()
    #print(c2)
    cand1=[]
    cand2=[]
    s=X[0][1]
    for a,b in X:
        if b==s:
            cand1.append(a)
        else:
            break
    #print(cand1)
    t=Y[0][1]
    for a,b in Y:
        if b==t:
            
            cand2.append(a)
        else:
            break
    #print(cand2)
    cand1.sort()
    cand2.sort()
    rest=len(cand1)*len(cand2)
    for i in range(m):
        x,y=lis1[i],lis2[i]
        if cand1[bisect_right(cand1,x)-1]==x and cand2[bisect_right(cand2,y)-1]==y:
            rest-=1
    if rest>0:
        print(s+t)
    else:
        print(s+t-1)
    
            
    

if __name__=="__main__":
    main()



Measured memory_bytes: 219364
N = int(input())
MOD = 10**9+7
u,d = input(),input()
ans,i = 0,0
if u[0]==d[0]:
    ans = 3
    i = 1
else:
    ans = 6
    i = 2
while i<N:
    if u[i-1]==d[i-1]:
        ans *= 2
        if u[i]==d[i]:
            i += 1
        else:
            i += 2
    else:
        if u[i]==d[i]:
            ans *= 1
            i += 1
        else:
            ans *= 3
            i += 2
print(ans%MOD)


Measured memory_bytes: 38384
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cp_n = n;
        int sum = 0;
        String ns = ""+n;
        for(int i=(int)(Math.pow(10,ns.length()-1)); i>=10; i/=10){
            sum += n/i;
            n = n-n/i*i;
        }
        sum += n;
        if(cp_n%sum == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
    
}

Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll a[1 << 17];
int main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	int chk = 0; int out = 1;
	rep(i, n - 1) {
		int memo;
		if (a[i] == a[i + 1])continue;
		if (a[i] < a[i + 1]) {
			memo = 1;
		}
		else {
			memo = -1;
		}
		if (!chk)chk = memo;
		else if (memo != chk) {
			out++; chk = 0;
		}
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

class AIDU0013
    {
        public static void Main(){
            Stack<uint> Copula= new Stack<uint>();
            Queue<uint> Gone = new Queue<uint>();
            string s;
            uint n;
            while(true) {
                s=Console.ReadLine();
                if(string.IsNullOrEmpty(s))break;
                n=uint.Parse(s);
                if(n!=0) { Copula.Push(uint.Parse(s));
                } else Gone.Enqueue(Copula.Pop());
            }
            while(Gone.Count>0) {
                Console.WriteLine(Gone.Dequeue());
            }
        }
    }

Measured memory_bytes: 10040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  ll n, k;
  cin >> n >> k;
  vector<P> a(n);
  ll count = 0;
  rep(i, n) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  ll ans;
  rep(i, n){
    k -= a[i].second;
    if(k <= 0) {
      ans = a[i].first;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int counts = 0;
void bubbleSort(int A[],int N){
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j=0;j<N-1;j++){
            if(A[j]>A[j+1]){
                int temp = A[j];
                A[j] = A[j+1];
                A[j+1] = temp;
                counts++;
                flag = 1;
            }
        }
    }
}
int main()
{
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    bubbleSort(A,n);
    for(int i=0;i<n;i++){
        if(i>0) cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<counts<<endl;
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int cnt = 0;
	int n;
	cin >> n;
	int a[n];
	long long int sum = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int flag = 1;
	long long b[n];
	b[0] = a[0];
	for (int i = 1; i < n; i++) {
		b[i] = b[i - 1] + a[i];
	}
	if (b[0] == 0){
		sum += 1;
		cnt ++;
	}
	else if(b[0] < 0){
		sum += 1 - b[0];
		cnt += 1 - b[0];
	}
	flag = 1;
	long long c;
	//cout << cnt << " ";
	for (int i = 1; i < n; i++){
		c = b[i] + sum;
		//cout << b[i] << " ";
		//cout << b[i] << " ";
		if (flag == 1){
			if (c >= 0){
				cnt += c + 1;
				sum -= c + 1;
			}
		}
		else{
			if (c <= 0){
				cnt += 1 - c;
				sum += 1 - c;
			}
		}
		flag *= -1;
		//cout << sum << " "<< b[i] << " ";
	}
	//cout << cnt << " ";
	sum = 0;
	long long cntt = 0;
	if (b[0] == 0){
		sum = -1;
		cntt ++;
	}
	else if(b[0] > 0){
		sum -= b[0] + 1;
		cntt += b[0] + 1;
	} 
	flag = -1;
	for (int i = 1; i < n; i++){
		b[i] = b[i] + sum;
		//cout << b[i] << " ";
		//cout << b[i] << " ";
		if (flag == 1){
			if (b[i] >= 0){
				cntt += b[i] + 1;
				sum -= b[i] + 1;
			}
		}
		else{
			if (b[i] <= 0){
				cntt += 1 - b[i];
				sum += 1 - b[i];
			}
		}
		flag *= -1;
		//cout << sum << " "<< b[i] << " ";
	}
	cout << min(cnt, cntt);
}


Measured memory_bytes: 1408
#include<iostream>
#include <stdio.h>
using namespace std;

int main() {
    int a, b;
    cin >> a;
    cin >> b;

    if (a == b)
        cout << "a == b" << endl;
    if (a > b)
        cout << "a > b" << endl;
    if (a < b)
        cout << "a < b" << endl;

    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,maxn=0;
	char b[110];
	cin>>a;
	for(int i=1;i<=a;i++){
		cin>>b[i];
	}
	for(int i=1;i<=a;i++){
		int ans=0;
		int c[110]={0};
		for(int j=1;j<=i;j++){
			for(int k=1+i;k<=a;k++){
				if(b[j]==b[k]&&c[b[j]-96]==0){
					ans++;
					c[b[j]-96]=1;
				}
			}
		}
		if(ans>maxn) maxn=ans;
	}
	cout<<maxn<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<ll,ll>a;
	ll kari=n;
	for(ll i=2;i<=sqrt(n);i++){
		ll cnt=0;
		while(kari%i==0){
			cnt++;
			kari/=i;
		}
		if(cnt!=0){
			a[i]=cnt;
		}
	}
	if(kari!=1){
		a[kari]++;
	}
	ll ans=0;
	for(auto itr=a.begin();itr!=a.end();itr++){
		ll num=itr->first;
		ll val=itr->second;
//		cout << num << " "<<val<<endl;
        
		ll sum=0;
		ll j=1;
		while(sum+j<=val){
			ans++;
			sum+=j;
			j++;
//			cout <<sum<<endl;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

inline int xor128() {
    static int x = 123456789;
    static int y = 362436069;
    static int z = 521288629;
    static int w = 88675123;
    int t;
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}


const int D = 365;
const int M = 26;
vec<int> C(M);
vvec<int> S(D,vec<int>(M));

using arr = array<int,M>;

struct state{
    vec<int> res;
    int day;
    arr last;
    int score;
    state(){
        last = {};
        score = 0;
        day = 0;
    }
    void add(int type){
        day++;
        score += S[(int) res.size()][type];
        res.push_back(type);
        last[type] = day;
        for(int i=0;i<M;i++) if(i!=type) score -= C[i]*(day-last[i]);
    }

    bool operator<(const state& R)const{
        return score>R.score;
    }
};

const int width = 800;
const int lower = 10000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    for(auto& x:C) cin >> x;
    for(auto& v:S) for(auto& x:v) cin >> x;
    state init;
    vec<state> states;
    states.push_back(init);
    for(int d=0;d<D;d++){
        vec<state> neS;
        for(auto& now:states){
            vec<state> comp;
            for(int i=0;i<M;i++) if(S[d][i]>lower){
                state ne = now;
                ne.add(i);
                comp.push_back(ne);
            }
            sort(comp.begin(),comp.end());
            if(comp.size()>7) comp.resize(7);
            for(auto& x:comp) neS.push_back(x);
        }
        sort(neS.begin(),neS.end());
        if(neS.size()>width) neS.resize(width);
        states.swap(neS);
    }
    auto ans = states[0].res;
    for(int i=0;i<D;i++) cout << ans[i]+1 << "\n";
}

Measured memory_bytes: 17572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

ll gcd(ll a,ll b){
	if(a<b) return gcd(b,a);
	ll r;
	while(r=a%b){
		a=b;
		b=r;
	}
	return b;
}

bool isPrime(ll x){
	if(x==1||x==2||x==3) return true;
	else{
		for(ll i=2;i*i<=x;i++){
			if(x%i==0) return false;
		}
		return true;
	}
}

int main(){
	ll a,b;cin>>a>>b;
	vector<ll> vec;
	ll c=gcd(a,b);
	ll ans=0;
	//cout<<c<<"\n";
	for(ll i=1;i*i<=c;i++){
		if(c==i*i&&isPrime(i)) ans++;
		else if(c%i==0){
			if(isPrime(i)) ans++;
			if(isPrime(c/i)) ans++;
		}
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std; 
int main()
{
	string n; 
	cin >> n;  
	int ans = 0;
	for (int i = 0; i < n.size(); i++)
	{
		if (n.at(i)=='2')
		{
			ans++;
		}
	} 
	cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[200005],dp[200005],n,k;

ll dfs(ll x,ll c)
{
	if(x>n)
		return ass;
	if(dp[x]!=-1)
		return dp[x]+abs(arr[x]-c);
	if(x==n)
		return abs(arr[x]-c);
	dp[x]=dfs(x+1,arr[x]);
	for(ll i=2;i<=k;i++)
		dp[x]=min(dfs(x+i,arr[x]),dp[x]);
	return dp[x]+abs(arr[x]-c);
}

int main()
{
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i];
		dp[i]=-1;
	}
	dp[1]=dfs(1+1,arr[1]);
	for(ll i=2;i<=k;i++)
		dp[1]=min(dfs(1+i,arr[1]),dp[1]);
	cout<<dp[1];
	return 0;
}


Measured memory_bytes: 4992
import string

n = int(input())
s = str(input())

S =[]
al = []
new = []

for l in s:
    S.append(l)

for x in string.ascii_uppercase:
    al.append(x)

for i in range(len(s)):
    ind = al.index(S[i])
    new_ind = (ind + n) % 26
    new_s = al[new_ind]
    new.append(new_s)

ans = ''.join(new)
print(ans)

 

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

using namespace std;

int main()
{
    long long s;
    cin>>s;
    long long x1,y1,x2,y2,x3,y3;
    x1=0,y1=0;
    x2=1000000000,y2=1;
    x3=(1000000000-s%1000000000)%1000000000,y3=(s+x3)/1000000000;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3;
    getchar();getchar();
    return 0;
}

Measured memory_bytes: 256