akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a >= 13)
    {
        cout << b << endl;
    }
    else if (a >= 6)
    {
        cout << b / 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
Sstr = list(input())
S = [int(i) for i in Sstr]

bit=[]
for i in range(0,len(S)-2):
    bit.append([abs(7-S[i]),i])


bit.sort(key=lambda x : x[0])

j=0
start=[]

for j in range(len(bit)):
    if bit[0][0] == bit[j][0]:
        start.append(bit[j][1])
        j+=1
    else:
        break

test=0
ans=1000
for st in start:
    if len(S)-st >= 3:
        test=abs(753-(S[st]*100+S[st+1]*10+S[st+2]))
        if ans > test:
            ans=test
print(ans)

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

int main()
{
	int n;
	int a[16][16];

	while (cin >> n, n){
		
		memset(a, 0, sizeof(a));

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> a[i][j];
			}
		}

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				a[i][n] += a[i][j];
			}
		}

		for (int i = 0; i < n; i++){
			for (int j = 0; j <= n; j++){
				a[n][j] += a[i][j];
			}
		}

		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= n; j++){
				printf("%5d", a[i][j]);
			}
			puts("");
		}
	}
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9+7;
const ll A = 13;
ll dp[A],nu[A];
int main() {
	ios::sync_with_stdio(0);
	memset(dp,0,sizeof(dp));
	string s;
	cin >> s;
	int n = s.size();
	dp[0] = 1;
	for(int i=0;i<n;i++) {
		memset(nu,0,sizeof(nu));
		ll val = s[i]-'0';
		for(int j=0;j<A;j++) {
			ll nx = (10*j)%A;
			if(s[i] == '?') {
				for(int k=0;k<10;k++) {
					ll nt = (nx+k)%A;
					nu[nt] += dp[j];
				}
			} else {
				ll nt = (nx+val)%A;
				nu[nt] += dp[j];
			}
		}
		for(int j=0;j<A;j++) {
			dp[j] = nu[j]%M;
		}
	}
	cout << dp[5]%M << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    fastio;
    ll ans=0;
    ll K, N;
    cin >> K >> N;
    vector<int> a(N);
    vector<int> d(N);
    rep(i,N) cin >> a[i];
    d[0] = a[0] + K - a[N-1];
    for (int i=1; i<N; ++i) {
        d[i] = a[i] - a[i-1];
    }
    ans = K - *max_element(begin(d), end(d));
    cout << ans << endl;
}


Measured memory_bytes: 4728
#include <iostream>
using namespace std;
bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i*i <=p; i++) {
		if (p%i == 0) return false;
	}
	return true;
}

int n;

int main() {
	cin >> n;
	for (int i = 31; i <= 55555; i += 30) {
		if (isprime(i) == true) {
			if (i != 31) cout << " ";
			cout << i; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
 
using namespace std;
typedef long long ll;

int main()
{
	char S[256];
	scanf("%s", S);
	
	int A = 0;
	
	for(int i = 0; i < 3; i++){
		if(S[i] == 'A'){
			A++;
		}
	}
	
	if(A > 0 && A < 3){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;

typedef long long ll;

int main(int argc, char **argv)
{
    int N, M;
    cin >> N >> M;
    cout << (N * (N - 1) + M * (M - 1)) / 2 << endl;
    return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<int> V;
typedef vector<V> VV;
//The number of outdegree of vertex in graph "in" is 1
struct sunny_graph{
    int size;
    VV g,in;
    V S,R;
    int getloop(int v){
        return S[v];
    }
    int getroot(int v){
        return R[v];
    }
    int dfs(int v,V& out,int id,V &loop){
        S[v]=-2;
        int u=out[v];
        if(S[u]>=0){
            S[v]=size;
            return -1;
        }
        if(S[u]==-2||(u=dfs(u,out,id,loop))>=0){
            S[v]=id;
            R[v]=v;
            loop.pb(v);
            if(v==u)return -1;
            else return u;
        }
        S[v]=size;
        return -1;
    }
    void dfs2(int v){
        for(auto &u:in[v]){
            S[u]=S[v];
            R[u]=R[v];
            dfs2(u);
        }            
    }
    sunny_graph(V out){
        size=out.size();
        in.resize(size);
        S.resize(size,-1);
        R.resize(size);
        int id=0;
        REP(v,size){
            V L;
            if(S[v]==-1)dfs(v,out,id,L);
            if(L.size()){
                g.pb(L);
                id++;
            }
        }
        REP(v,size)if(S[v]==size)in[out[v]].pb(v);
        for(auto &s:g)for(auto &v:s)dfs2(v);
    }
};
const int mod=1e9+7;
LL f(int v,VV &g){
    LL res=1;
    for(auto &u:g[v]){
        res*=f(u,g);
        res%=mod;
    }
    return (res+1)%mod;

}
int N,M;
int main(){
    cin>>N>>M;
    V a(N);
    REP(i,N)a[i]=i;
    REP(i,M){
        int x,y;
        cin>>x>>y;
        a[x-1]=y-1;
    }
    sunny_graph sg(a);
    LL ans=1;
    for(auto &it:sg.g){
        LL res=1;
        for(auto &v:it)
            for(auto &u:sg.in[v])
                (res*=f(u,sg.in))%=mod;
        ans*=(res+1)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
ll n,c=0;
string s;
cin>>s;
stack<char> st;
st.push('x');
for (int i = 0; i < s.length(); ++i)
{
        if(st.top()=='x')
        {
          st.push(s[i]);
         // c++;
        }
        else if(st.top()=='0')
        {
          if(s[i]=='1')
          {
            st.pop();
            c++;
          }
          else st.push(s[i]);
        }
          else if(st.top()=='1')
        {
          if(s[i]=='0')
          {
            st.pop();
            c++;
          }
          else st.push(s[i]);
        }
}
c(2*c);

}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "No\n"; return;}

const int N = 2e5 + 7;

int a[N];

void solve() {
    int n; cin >> n;
    loop(i, n - 1) {
        int x; cin >> x;
        ++a[x];
    }
    loop1(i, n)
        cout << a[i] << "\n";
}

signed main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   //int t; cin >> t; loop(i, t)
   solve();
   return 0;
}

Measured memory_bytes: 5220
k = int(input())
ls = [
    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,
]
print(ls[k - 1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define inf 998244353
using namespace std;
int main()
{
    int n,tmp1=1;
    ll a[100009],b[100009],ans=1;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%lld",&a[i]),b[i]=a[i];
    if(a[1]!=0)
        printf("0");
    else
    {
        for(int i=2; i<=n; i++)
            if(a[i]==0)
            {
                printf("0");
                return 0;
            }
        sort(a+1,a+n+1);
        sort(b+1,b+n+1);
        int len=unique(b+1,b+n+1)-b-1;
        //printf("%d\n",len);
        for(int i=2; i<=len; i++)
            if(b[i]-b[i-1]!=1)
            {
                printf("0");
                return 0;
            }
        for(int i=2; i<=n;)
        {
            ll tmp=a[i],num=0;
            while(i<=n&&a[i]==tmp)
                (ans*=tmp1)%=inf,i++,num++;
            tmp1=num;
        }
        printf("%lld",ans);
    }
    return 0;
}


Measured memory_bytes: 1792
def main():
    n = input()
    n_int = int(n)
    n_li = list(map(int, list(n)))
    n_sum = sum(n_li)

    if n_int % n_sum == 0:
        ans = 'Yes'
    else:
        ans = 'No'

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int dp[55555];

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int w, n;
	while (cin >> w >> n, w)
	{
		vi x(n); cin >> x;
		vi s(n + 1);
		REP(i, n) s[i + 1] = s[i] + x[i];
		int lb = 0, ub = w;
		while (ub - lb > 1)
		{
			int k = (ub + lb) / 2;
			MS(dp, 0);
			deque<int> que;
			for (int i = n - 1; i >= 0; i--)
			{
				if (s[n] - s[i] + (n - i - 1) <= w)
				{
					dp[i] = 1;
					que.push_back(i);
				}
				else
				{
					break;
				}
			}
			for (int i = n - 1; i >= 0; i--)
			{
				if (dp[i]) continue;
				while (!que.empty())
				{
					int t = que.front();
					if (t == i + 1) break;
					if (s[t] - s[i] + (t - i - 1) > w)
					{
						que.pop_front();
					}
					else
					{
						break;
					}
				}
				for (auto t : que)
				{
					if (t == i + 1) continue;
					int sp = w - (s[t] - s[i]);
					if (ceil(ld(sp) / (t - i - 1)) <= k)
					{
						dp[i] = true;
						que.push_back(i);
						break;
					}
				}
			}
			if (dp[0]) ub = k;
			else lb = k;
		}
		cout << ub << endl;
	}
	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int H1,M1,H2,M2,K;
  cin>>H1>>M1>>H2>>M2>>K;
  int t1=H1*60+M1;
  int t2=H2*60+M2;
  cout<<max((t2-t1)-K,0)<<endl;

  return 0;
}


Measured memory_bytes: 3652
import sys
input=sys.stdin.readline
n=int(input())
s=input().rstrip()
start=['SS','SW','WS','WW']
import sys
for k in range(4):
    ans=start[k]
    for i in range(2,n):
        if (ans[i-2:i]=='SS' and s[i-1]=='o') or (ans[i-2:i]=='SW' and s[i-1]=='x') or (ans[i-2:i]=='WS' and s[i-1]=='x') or (ans[i-2:i]=='WW' and s[i-1]=='o'):
            ans=ans+'S'
        else:
            ans=ans+'W'
    if (s[0]=='o' and ans[0]=='S') or (s[0]=='x' and ans[0]=='W'):
        if ans[1]==ans[n-1]:
            pass
        else:
            continue
    else:
        if ans[1]==ans[n-1]:
            continue
    if (s[n-1]=='o' and ans[n-1]=='S') or (s[n-1]=='x' and ans[n-1]=='W'):
        if ans[0]==ans[n-2]:
            pass
        else:
            continue
    else:
        if ans[0]==ans[n-2]:
            continue
    print(ans)
    sys.exit()
print(-1)
    




Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int n, p, ans=0;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v.at(i);
  vector<int> g(n);
  rep(i,n) cin >> g.at(i);
  rep(i,n) {
    p = v.at(i) - g.at(i);
    ans += max(0,p);
  }
  cout << ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		if (a < b)
			System.out.println("a < b");
		else if (a > b)
			System.out.println("a > b");
		else
			System.out.println("a == b");
	}
}


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

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

#define INF 2e9
#define ALL(v) v.begin(), v.end()

int main(){
  int N;
  int d[110];
  cin>>N;
  rep(i,N){
    cin>>d[i];
  }
  int num[110]={0};
  rep(i,N){
    num[d[i]]++;
  }
  int res=0;
  rep(i,100+1){
    if(num[i])res++;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
in_list = input().split(' ')

target_list = [int(s) for s in in_list]
max_num = max([s%2 for s in target_list])

counter = 0
while max_num==0:
    target_list = [int(s)/2 for s in target_list]
    max_num = max([s%2 for s in target_list])
    counter += 1

print(counter)

Measured memory_bytes: 9188
#include <iostream>
#include <set>

using namespace std;

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

    set<int> s;
    for (int i = a; i < a + k && i <= b; i++) {
        s.insert(i);
    }

    for (int i = b; i > b - k && i >= a; i--) {
        s.insert(i);
    }

    for (int x : s) {
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<list>
using namespace std;
int main()
{
	while (true)
	{
		int n;
		list<int> L;
		cin >> n;
		if (!n)
			break;
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			int x;
			cin >> x;
			sum += x;
			L.push_back(x);
		}
		L.sort();
		sum -= (L.front() + L.back());
		cout << sum / (n - 2)<<endl;
	}		
}


Measured memory_bytes: 3108
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        _n: usize,
        k: usize,
        mut s: chars,
    }
    match s[k - 1] {
        'A' => s[k - 1] = 'a',
        'B' => s[k - 1] = 'b',
        'C' => s[k - 1] = 'c',
        _ => {}
    }
    println!("{}", s.iter().map(|x| x.to_string()).collect::<String>());
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    if (S=="abc" || S=="acb"|| S=="bac"|| S=="bca"|| S=="cba"|| S=="cab"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 764
#include <stdio.h>

int main(){
  int i,d=0,s=1,n,data[251];
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&data[i]);
for(i=1;i<=n;i++){
printf("node %d: key = %d, ",i,data[i]);
if(i/2)
printf("parent key = %d, ",data[i/2]);
if(2*i<=n)
printf("left key = %d, ",data[2*i]);
if(2*i+1<=n)
printf("right key = %d, ",data[2*i+1]);
printf("\n");
}

return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 5e5 + 10;
vector<ll>a(55);
vector<ll>p(55);
ll dfs(ll n,ll k){
   if(n==0) return 1;
   else if(k<=n) return 0;
   else if(k<=a[n-1]+1) return dfs(n-1,k-1);
   else if(k==a[n-1]+2) return p[n-1]+1;
   else return p[n-1]+dfs(n-1,k-a[n-1]-2)+1;
}

void solve(){
     ll n,k;cin >> n >> k;
     a[0] = 1;p[0] = 1;
     for(int i = 1;i<=n;i++){
        a[i] = a[i-1]*2+3;
        p[i] = p[i-1]*2+1;
     }
     cout << dfs(n,k);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3660
import sys

input_data = []
input_pointer = 0

output_data = []

def input_scan():
    global input_data
    input_data = sys.stdin.readlines()
    input_data = [x[:-1] for x in input_data]

def next_line():
    global input_pointer
    global input_data
    if input_pointer < len(input_data):
        input_pointer += 1
        return input_data[input_pointer - 1]
    else:
        return ""

def append_output(string):
    global output_data
    output_data.append(string)

def print_output():
    global output_data
    output_data.append("")
    sys.stdout.write("\n".join(output_data))

# Problem A
# alpha = input()
# if alpha.isupper():
#     print("A")
# else:
#     print("a")

# Problem B
# input_scan()
# [n, k] = [int(x) for x in next_line().split(" ")]
# fruits = sorted([int(x) for x in next_line().split(" ")])
# print(sum(fruits[:k]))

# Problem C
num = int(input())

dictionary = "abcdefghijklmnopqrstuvwxyz"

def convert_to_alpha(num):
    if num == 0:
        return ""
    quot = num // 26
    rem = num % 26
    if rem == 0:
        return "z" + convert_to_alpha(quot - 1)
    else:
        return dictionary[rem - 1] + convert_to_alpha(quot)

name = ""
print("".join(reversed(convert_to_alpha(num))))


Measured memory_bytes: 9216
N = int(input())
L = list(map(int, input().split()))
vlist = []
ans = 0

for i in range(N):
  a = max(L)
  L.remove(a)
  b = max(L)
  L.remove(b)
  if a < b:
    vlist.append(a)
  else:
    vlist.append(b)

for i in range(N):
  ans += vlist[i]
  
print(ans)

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

int main() {
  string S;
  cin >> S;
  bool ans = true;
  int count = 0;

  if(S.at(0)!='A') ans=false;
  for (int i = 1; i < S.size(); i++) {
      if(2<=i&&i<S.size()-1&&S.at(i)=='C') count++;
      else if(S.at(i)<'a') {
          ans = false;
          break;
      }
  }
  if(count!=1) ans = false;
  
  if(ans) puts("AC");
  else puts("WA");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int kaikyuu[6]={0};
	int seitonum;
	int i,j;
	int sei,syou;
	scanf("%d",&seitonum);
	for(i=0;i<seitonum;i++) {
		scanf("%d.%d",&sei,&syou);
		sei=sei*10+syou;
		if(sei<1650)kaikyuu[0]++;
		else if(sei<1700)kaikyuu[1]++;
		else if(sei<1750)kaikyuu[2]++;
		else if(sei<1800)kaikyuu[3]++;
		else if(sei<1850)kaikyuu[4]++;
		else kaikyuu[5]++;
	}
	for(i=0;i<6;i++) {
		printf("%d:",i+1);
		for(j=0;j<kaikyuu[i];j++)putchar('*');
		puts("");
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int v[n];
  int c[n];
  vector<int>v_c;
  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++){
    v_c.push_back(v[i]-c[i]);
  }
  sort(v_c.begin(),v_c.end());

  int ans = 0;
  for(int i = n-1;i >= 0;i--){
    if(v_c[i] >= 0){
      ans += v_c[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

bool ok(int a, int b) {
	return abs(a - b) <= 1;
}

vector<vector<int>>memo(1000, vector<int>(1000,-1));

int solve(const int l,const int r, vector<int>&v) {
	if (memo[l][r] != -1)return memo[l][r];
	if (l == r)return memo[l][r] = 0;
	else if (l + 1 == r)return memo[l][r] = 0;
	else if (l + 2 == r) {
		if (ok(v[l],v[l+1]))return memo[l][r] = 2;
		else return memo[l][r] = 0;
	}
	else {
		int ans = 0;
		for (int k = l + 1; k <= r - 1; ++k) {
			ans = max(ans, solve(l, k, v) + solve(k, r, v));
		}
		if (ok(v[l], v[r - 1]) && solve(l + 1, r - 1, v) == (r - l - 2)) {
			ans = r - l;
		}
		return memo[l][r]=ans;
	}
	
}

int main() {
	while (1) {
		memo = vector<vector<int>>(1000, vector<int>(1000, -1));
		int N; cin >> N;
		vector<int>v(N);
		for (int i = 0; i < N; ++i)cin >> v[i];
		if (!N)break;
		int ans = solve(0, N, v);
		cout << ans << endl;
	}
	return 0;
}

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

class A {
    static int[] Q = Console.ReadLine().Split(' ').Select(w => int.Parse(w)).ToArray();
    static int[] W = Console.ReadLine().Split(' ').Select(w => int.Parse(w)).ToArray();

    static void Main() {
       for(int i = Q[0]; true; i++) {
            if (C(i)) {
                Console.WriteLine(i);
                return;
            }
        }
    }
    static bool C(int i) {
        string s = i.ToString();
  for(int j = 0; j < Q[1]; j++) {
            if (s.IndexOf(W[j].ToString()) != -1) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 7256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    int N; cin >> N;
    vecl A(N),B(N);
    REP(i,N) cin >> A[i];
    REP(i,N) cin >> B[i];
    ll total = 0;
    priority_queue<ll> differ;
    int ans = 0;
    REP(i,N) {
        if(A[i] < B[i]) {
            ans++;
            total += B[i]-A[i];
        } else if(A[i] > B[i]) differ.push(A[i]-B[i]);
    }
    if(total == 0) {
        cout << 0 << endl;
        return 0;
    }
    while(1) {
        if(differ.empty()) {
            cout << -1 << endl;
            return 0;
        }
        total -= differ.top();
        ans++;
        if(total <= 0) break;
        differ.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 5444
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

long long inversion_count(vector<long long> &A) {
    auto N = (int) A.size();

    vector<pair<long long, int>> B(N);
    for (int i = 0; i < N; i++) B[i] = make_pair(A[i], i);
    sort(B.begin(), B.end());

    vector<int> idxs(N);
    for (int i = 0; i < N; i++) idxs[B[i].second] = i + 1;

    vector<int> BIT(N+1, 0);
    auto sum = [&](int i) {
        long long s = 0;
        while (i > 0) {
            s += BIT[i];
            i -= i & -i;
        }
        return s;
    };
    auto add_to = [&](int i, int x) {
        while (i <= N) {
            BIT[i] += x;
            i += i & -i;
        }
    };

    long long ret = 0;
    for (int j = 0; j < N; j++) {
        ret += j - sum(idxs[j]);
        add_to(idxs[j], 1);
    }

    return ret;
}

// Validation: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D
signed main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    cout << inversion_count(A) << endl;
    return 0;
}


Measured memory_bytes: 9144
#include <stdio.h>

#define MAX 100009
#define NIL -1

typedef struct node{
  int p,l,r;
} Node;

Node T[MAX];
int N,D[MAX];

void print(int);
int rec(int,int);

int main(){
  int i,j,k,id,c,l,r;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for(i=0;i<N;i++){
    scanf("%d %d",&id,&k);

    for(j=0;j<k;j++){
      scanf("%d",&c);

      if(j==0) T[id].l = c;
      else T[l].r = c;

      l = c;
      T[c].p = id;
    }
  }

  for(i=0;i<N;i++){
    if(T[i].p == NIL) r = i;
  }

  rec(r,0);

  for(i=0;i<N;i++)print(i);

  return 0;
}


void print(int n){
  int i,cnt;

  printf("node %d: parent = %d, depth = %d, ",n,T[n].p,D[n]);

  if(T[n].p == NIL)printf("root, ");

  else if(T[n].l == NIL)printf("leaf, ");

  else printf("internal node, ");

  printf("[");

  for(i=0, cnt = T[n].l; cnt != NIL; i++, cnt = T[cnt].r){
    if(i)printf(", ");
    printf("%d",cnt);
  }

  printf("]\n");
}

int rec(int n,int p){
  D[n] = p;

  if(T[n].r != NIL) rec(T[n].r,p);
  if(T[n].l != NIL) rec(T[n].l,p + 1);
}
 



Measured memory_bytes: 6396
#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<stack>
#include<algorithm>
#include<string>
#include<string.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ull;
typedef long long ll;
typedef pair<ll,ll> ii;

const ll BASE = 31;
const int N = 1e5;

ull png[N + 5];

string s; 
bool can(int len){
	set<ull> ls;
	ull cur = 0;
	for(int i = 0; i < len; ++i){
		cur *= 31LL;
		cur += s[i] - 'a';
	}
	ls.insert(cur);
	for(int i = len; i < s.length(); ++i){
		cur -= png[len - 1] * (s[i - len] - 'a');
		cur *= 31LL;
		cur += s[i] - 'a';
		if(ls.count(cur))return false;
		ls.insert(cur);
	}

	return true;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	png[0] = 1;
	for(int i = 1; i < N + 5; ++i){
		png[i] = png[i - 1] * BASE;
	}

	cin >> s;
	int l = 1, r = s.length();
	while(l < r){
		int m = (l + r) / 2;
		if(can(m))r = m;
		else l = m + 1;
	}

	cout << s.length() - l + 1 << endl;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n;
  cin>>n;
  int p[n];
  int flag=0;
  int tmp;
  REP(i,n){
    cin>>p[i];
    if(i+1!=p[i]){
      flag++;
      tmp=i;
    }
  }
  if(flag>2){
    cout<<"NO"<<endl;
  }else if(flag==2){
    if(p[p[tmp]-1]==tmp+1){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }else{
    cout<<"YES"<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 123456;
int bg[2 * MAXN], ed[2 * MAXN], a[MAXN];
LL red[2 * MAXN], offs[2 * MAXN];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    LL cost = 0;
    for (int i = 1; i < n; i++) {
        int pre = a[i - 1], cur = a[i];
        if (cur < pre) cur += m;
        cost += (cur - pre);
        bg[pre]++, ed[cur]++;
        offs[cur] += (cur - pre);
    }
    LL cnt = 0, sum = 0;
    for (int i = 1; i <= 2 * m; i++) {
        red[i] = sum - cnt;
        cnt = cnt - ed[i] + bg[i];
        sum += cnt - offs[i];
    }
    LL ans = cost;
    for (int i = 1; i <= m; i++) {
        LL tmp = red[i] + red[i + m];
        ans = min(ans, cost - tmp);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5248
first_num = gets.chomp.to_i
numbers = gets.split.map(&:to_i)
answer = 0

def check_even?(first_num, numbers)
  even_count = 0
  numbers.each do |num|
    even_count += 1 if num.even?
  end
  even_count == first_num ? true : false
end

while check_even?(first_num, numbers) do
  numbers.map! do |num|
    num / 2
  end
  answer += 1
end

p answer


Measured memory_bytes: 14320
#include <iostream>
#include <algorithm>  
#include <vector>
#include <map> 

using namespace std;
#include <math.h>    // for sqrt
#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

int main() {
    int a,b; cin >> a >> b;
    int ans = a-b-b;
    if (ans < 0) {
      cout << "0" << endl;
    } else {
      cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
int main() {
  int N, usa[1000000], ans = 0;
  cin >> N;
  rep(i, N) cin >> usa[i];
  rep(i, N) if (usa[usa[i] - 1] == i + 1) ans++;
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int h = Integer.parseInt(sc.next());
        System.out.println((a + b) * h / 2);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;


int main() 
{
	int n;
	cin>>n;
	while(n){
		if(n%10==7){
			cout<<"Yes";
			return 0;
		}
		n/=10;
	}

	cout<<"No";
	return 0;

}


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

int main() {
 int a,b,c,k;
 cin >> a >> b >> c >> k;
 int cc = k-(a+b);
 if(a+b>=k){
   if(a>=k){
     cout << k << endl;
   }
   else{
     cout << a << endl;
   }
 }
 else{
   cout << a-cc << endl;
 }
}

Measured memory_bytes: 3636
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n,m=map(int,input().split())
    p = list(map(int,input().split()))
    uf = UnionFind(n)
    res = 0
    for _ in range(m):
        x,y=map(int,input().split())
        uf.union(x-1,y-1)
    for i in range(n):
        if uf.same(p[i]-1,i):
            res += 1
    print(res)

main()

Measured memory_bytes: 13940
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var N = IO.RLong;

            var rem = N / 11;

            var a = (rem + 1) * 2;
            if (N % 11 == 0) a -= 2;
            else if (N % 11 <= 6) a -= 1;
            WriteLine(a);
            
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17592
#include<stdio.h>
int main(void){
  int n,t,keiro=-1,min=1000000;
  scanf("%d%d",&n,&t);
  int a[n],b[n],i;
  for(i=0;i<n;i++){
     scanf("%d%d",&a[i],&b[i]);
  if(b[i]<=t&&a[i]<min){
    keiro=b[i];
    min=a[i];
  }
  }
  if(keiro==-1){
    printf("TLE");
    return 0;
  }
  else printf("%d",min);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

def sol(S):
    ret = 0
    for a in A[1:]:
        b = a
        if S * (S + b) > 0:
            b = (abs(S) + 1) * (1 if S < 0 else -1)
        if S + b == 0:
            b = b - 1 if S > 0 else b + 1
        ret += abs(b - a)
        S += b
    return ret

if A[0] == 0:
    ans = min(sol(1), sol(-1)) + 1
else:
    ans = min(sol(A[0]), sol(-A[0] // abs(A[0])) + abs(A[0]) + 1)
print(ans)


Measured memory_bytes: 14644
n, y = map(int, input().split())

ans = [-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        sm = 10000 * i + 5000 * j + 1000 * k
        if sm == y:
            ans = [i, j, k]

print(*ans)


Measured memory_bytes: 2940
// C - Flip,Flip, and Flip......
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, m, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n >> m;
  if (n == 1 && m == 1)
  {
    cout << 1 << endl;
  }

  else
  {
    if (n != 1 && m != 1)
    {
      ans = n * m - (2 * n + 2 * m - 4);
      cout << ans << endl;
    }
    else if (n == 1 || m == 1)
    {
      ans = n * m - 2;
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <queue>
#include <utility>
#include <algorithm>

const int MaxN = 1000 + 5;

int X, Y, Z, K;
long long A[MaxN], B[MaxN], C[MaxN];
int lst[MaxN][MaxN];
std::priority_queue< std::pair< long long, std::pair<int, int> > > pq;

void init() {
  scanf("%d %d %d %d", &X, &Y, &Z, &K);
  for (int i = 1; i <= X; ++i) scanf("%lld", &A[i]);
  for (int i = 1; i <= Y; ++i) scanf("%lld", &B[i]);
  for (int i = 1; i <= Z; ++i) scanf("%lld", &C[i]);
}

void solve() {
  std::sort(C + 1, C + 1 + Z, [](long long x, long long y){ return x > y; });

  for (int i = 1; i <= X; ++i) for (int j = 1; j <= Y; ++j) {
    lst[i][j] = 1;
    pq.push( std::make_pair(A[i] + B[j] + C[lst[i][j]], std::make_pair(i, j)) );
  }

  for (int i = 1; i <= K; ++i) {
    std::pair< long long, std::pair<int, int> > p = pq.top(); pq.pop();
    printf("%lld\n", p.first);
    lst[p.second.first][p.second.second]++;
    if (lst[p.second.first][p.second.second] <= Z) pq.push( std::make_pair(A[p.second.first] + B[p.second.second] + C[lst[p.second.first][p.second.second]], p.second) );
  }
}

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


Measured memory_bytes: 20584
#include <bits/stdc++.h>
using namespace std;
/**
	sum i = 0..m ncr(x, i)
  **/
namespace modular_space {
	long long mod;
	struct umod {
		long long val;
		umod(): val(0ll){}
		umod(long long x){ x %= mod; if(x < 0) x += mod; val = x; }
		umod& operator += (umod oth){ val += oth.val; if(val >= mod) val -= mod; return *this; }
		umod& operator -= (umod oth){ val -= oth.val; if(val < 0) val += mod; return *this; }
		umod& operator *= (umod oth){ val = val * oth.val % mod; return *this; }
		umod& operator /= (umod oth){ return *this *= oth.inverse(); }
		umod& operator ^= (long long oth){ return *this = pwr(*this, oth); }
		umod operator + (umod oth) const { return umod(*this) += oth; }
	       	umod operator - (umod oth) const { return umod(*this) -= oth; }
		umod operator * (umod oth) const { return umod(*this) *= oth; }
		umod operator / (umod oth) const { return umod(*this) /= oth; }
		umod operator ^ (long long oth) const { return umod(*this) ^= oth; }
		bool operator < (umod oth) const { return val < oth.val; }
		bool operator > (umod oth) const { return val > oth.val; }
		bool operator <= (umod oth) const { return val <= oth.val; }
		bool operator >= (umod oth) const { return val >= oth.val; }
		bool operator == (umod oth) const { return val == oth.val; }
		bool operator != (umod oth) const { return val != oth.val; }
		umod pwr(umod a, long long b) const {
			umod r = 1;
			for(; b; a *= a, b >>= 1)
				if(b&1)
					r *= a;
			return r;
		}
		umod inverse() const {
			long long a = val, b = mod, u = 1, v = 0;
			while(b){
				long long t = a/b;
				a -= t * b; swap(a, b);
				u -= t * v; swap(u, v);
			}
			if(u < 0)
				u += mod;
			return u;
		}
		friend istream& operator >> (istream &is, umod &oth);
		friend ostream& operator << (ostream &os, const umod& oth);
	};
	ostream& operator << (ostream &os, const umod &oth){
		os << oth.val;
		return os;
	}
	istream& operator >> (istream &is, umod &oth){
		long long x; is >> x;
		oth = umod(x);
		return is;
	}
	struct binprime_kit {
		int sz;
		vector<umod> fat, ifat;
		void init(int s){
			sz = s;
			fat.resize(sz + 1);
			ifat.resize(sz + 1);
			fat[0] = 1;
			for(int i = 1; i <= sz; i++) fat[i] = fat[i - 1] * i;
			ifat[sz] = fat[sz] ^ (mod - 2);
			for(int i = sz - 1; i >= 0; i--) ifat[i] = ifat[i + 1] * (i + 1);
		}
		umod coef(int n, int r){
			if(n < r) return 0;
			return fat[n] * ifat[r] * ifat[n - r];
		}
	};
};
const int maxn = 1000100;
using umod = modular_space::umod;
using kit = modular_space::binprime_kit;
umod f[maxn], p3[maxn];
int main(){
	modular_space::mod = 1'000'000'007;
	kit K;
	K.init(maxn);
	int n, m, k; cin >> n >> m >> k;
	f[0] = 1;
	for(int i = 1; i <= m + k; i++){
		f[i] = f[i - 1] * 2;
		if(i > m){
			f[i] -= K.coef(i - 1, m);
		}
		if(i > k){
			f[i] -= K.coef(i - 1, k);
		}
	}
	umod ans = 0;
	int l = n + m + k;
	p3[0] = 1;
	for(int i = 1; i <= l; i++)
		p3[i] = p3[i - 1] * 3;
	for(int i = n; i <= l; i++){
		ans += K.coef(i - 1, n - 1) * f[i - n] * p3[l - i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> vec(3);
int m,n,x,y;
int main() {
	cin>>m>>n>>x>>y;
	int X[m];
	int Y[n];
	for(int i=0;i<m;i++)cin>>X[i];
	for(int i=0;i<n;i++)cin>>Y[i];
	sort(X,X+m);
	sort(Y,Y+n);
	if(max(X[m-1],x)<min(Y[0],y))cout<<"No War"<<endl;
	else cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

struct Dijkstra{
  int n,i;
  vector<vector<pair<int,int> > > edge; //cost,to
  vector<int> distance;
  vector<int> prev;

  void init(int v){
    n=v;
    edge.resize(n);
    distance.resize(n);
    prev.resize(n);
  }

  void input(int from,int to,int cost){
    edge[from].push_back({cost,to});
  }

  void calc(int start){
    for(i=0;i<n;i++){
      distance[i]=1e9+7;
      prev[i]=-1;
    }
    distance[start]=0;

    priority_queue<pair<int,int> > q; //distance,n
    pair<int,int> node;
    int from,to,tmp;
    q.push({0,start});

    while(!q.empty()){
      node=q.top();
      from=node.second;
      q.pop();
      if(node.first>distance[node.second]){
        continue;
      }

      for(i=0;i<edge[from].size();i++){
        to=edge[from][i].second;
        tmp=distance[from]+edge[from][i].first;
        if(distance[to]>tmp){
          distance[to]=tmp;
          prev[to]=from;
          q.push({tmp*-1,to}); //greater
        }
      }
    }
  }
};

int main(void){
  int n,u,k,v,c,i,j;
  Dijkstra graph;
  cin>>n;
  graph.init(n);
  for(i=0;i<n;i++){
    cin>>u>>k;
    for(j=0;j<k;j++){
      cin>>v>>c;
      graph.input(u,v,c);
    }
  }
  graph.calc(0);

  for(i=0;i<n;i++){
    cout<<i<<" "<<graph.distance[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 7784
n = gets.chomp.to_i

kyori = {}
hen = Array.new(n+1){Array.new()}
(n-1).times do
  u,v,w = gets.chomp.split().map(&:to_i)
  kyori[[u,v]] = w
  kyori[[v,u]] = w
  hen[u].push v
  hen[v].push u
end

ans = Array.new(n+1, nil)
ans[1] = 1
q = [1]
while !q.empty?
  ten = q.shift
  hen[ten].each do |i|
    next unless ans[i].nil?
    q.push i if
      if ans[ten] == 1 && kyori[[ten,i]].even?
        ans[i] = 1
      elsif ans[ten] == 1 && kyori[[ten,i]].odd?
        ans[i] = 0
      elsif ans[ten] == 0 && kyori[[ten,i]].even?
        ans[i] = 0
      elsif ans[ten] == 0 && kyori[[ten,i]].odd?
        ans[i] = 1
      end
  end
end

ans.each do |an|
  puts an
end


Measured memory_bytes: 41340
N, M = map(int, input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = 1
for i in make_divisors(M):
    work1 = i * N
    work2 = M - work1
    if work2 >= 0 and work2 % i == 0:
        ans = max(i, ans)
# print(make_divisors(M))
print(ans)

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

vector<vector<int>> tree;
vector<int> cnt;

void dfs(int v, int p = -1){
    for(int u: tree[v]){
        if(u == p) continue;
        cnt[u] += cnt[v];
        dfs(u,v);
    }
}


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,q;
    cin >> n >> q;
    
    tree.resize(n);
    cnt.resize(n,0);
    
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    rep(i,q){
        int p,x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }
    
    dfs(0);
    rep(i,n) cout << cnt[i] << endl;
    
}


Measured memory_bytes: 23552