akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int num, b;
    int deck[4][13] = {{}};
    char a;
    cin >> num;
    for (int i = 0; i < num; i++) {

        cin >> a >> b;
        switch(a) {
            case 'S':
                deck[0][b -1] = 1;
                break;
            case 'H':
                deck[1][b -1] = 1;
                break;
            case 'C':
                deck[2][b -1] = 1;
                break;
            case 'D':
                deck[3][b -1] = 1;
                break;
    };
}
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            if (deck[i][j] == 0) {
                switch(i) {
                    case (0):
                        cout << "S " << j%13 + 1 << endl;
                        break;
                    case (1):
                        cout << "H " << j %13  +1<< endl;
                        break;
                    case (2) :
                        cout << "C " << j%13  +1<< endl;
                        break;
                    case (3) :
                        cout << "D " << j%13 + 1 << endl;
                        break;
                }
            }}
        }
    return 0;
}


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

int main(void){
    int n, l=0, r=0;
    string s, ss;
    cin >> n >> s;
    ss = s;
    int poi=0;
    for(int i=0;i<n;++i){
        if(s[i]=='('){
            ++l;
        }else{
            if(l>0) --l;
            else ++r;
        }
    }
    for(int i=0;i<r;++i){
        ss = '(' + ss;
    }
    for(int i=0;i<l;++i){
        ss = ss + ')';
    }
    cout << ss << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std; 
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 200000
long long int MOD=998244353;
long long int INF=1e18;
                                                 /*:-]*/
 
int main()
{
         ios_base::sync_with_stdio(false); 
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
         cin>>a>>b;
         k=__gcd(a,b);
   // cout<<k<<endl;
    cnt=1;
    for(i=2;i<=sqrt(k);i++)
    {
        if(k%i==0)
        {
            cnt++;
        
        while(k%i==0)
        {
            k=k/i;
          }
        }
    }
    if(k!=1)
        cnt++;
    cout<<cnt<<endl;
    
}
    

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

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define ld double
#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 len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

void solve() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    cout << (m1 != m2);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

void toposort(int v, const vector<vector<int>>& es, vector<int>& visited, vector<int>& ret) {
  visited[v] = 1;
  for (int to : es[v]) {
    if (!visited[to]) toposort(to, es, visited, ret);
  }
  ret.push_back(v);
}

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

  vector<vector<int>> es(N);
  vector<int> visited(N), topo;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    es[x].push_back(y);
  }

  for (int v = 0; v < N; v++) {
    toposort(v, es, visited, topo);
  }

  reverse(topo.begin(), topo.end());
  vector<int> dp(N);
  int res = 0;
  for (int u : topo) {
    for (int v : es[u]) {
      dp[v] = max(dp[v], dp[u] + 1);
      res = max(res, dp[v]);
    }
  }
  cout << res << endl;


  return 0;
}

Measured memory_bytes: 9976
import math,sys,itertools

N = int(input())

cnt = 0

base = [3,5,7]
#num = [357,375,537,573,735,753]
num = set(base)
ans = {}
keta = math.log10(N + 1)
keta = math.ceil(keta) 
tmplist = [0]
for i in range(keta):
    newlist = []
    for j in tmplist:
        for k in base:
            newlist += [j + k * 10 ** i]
        
    num |= set(newlist)
    tmplist = newlist

for x in list(num):
    s = str(x)
    flag = [False,False,False]
    for i in s:
        if i == '3':flag[0] = True
        if i == '5':flag[1] = True
        if i == '7':flag[2] = True
        if flag[0] and flag[1] and flag[2] :
            if x <= N:cnt += 1            
            break
    

print(cnt)


        
        

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



int s(int x){
    int sum = 0;
    
    while(x > 0){
        sum += x%10;
        x/=10;
    }
    
    return sum;
}


int main() {
    
    int n;
    cin >> n;
    int sum = s(n);
    
    if(n%sum == 0){
        cout << "Yes\n";
    } else cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [input() for i in range(N)]
row_w = [row.count('.') for row in A]
col_w = [col.count('.') for col in zip(*A)]

if all(w==0 for w in row_w):
    print(0)
    exit()
if all(w==N for w in row_w):
    print(-1)
    exit()
if any(w==0 for w in row_w):
    print(len([1 for w in col_w if w>0]))
    exit()

ng_col = len([1 for w in col_w if w>0])
ans = 10**10
for i,rw in enumerate(row_w):
    tmp = rw + (col_w[i]==N) + ng_col
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 3316
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(true){
            int m = scan.nextInt();
            int f = scan.nextInt();
            int r = scan.nextInt();
            if(m == -1 && f == -1 && r == -1)break;
            if(m == -1 || f == -1) System.out.println("F");
            else if(m + f >= 80) System.out.println("A");
            else if(m + f >= 65) System.out.println("B");
            else if(m + f >= 50) System.out.println("C");
            else if(m + f >= 30) {
                if(r < 50)System.out.println("D");
                else System.out.println("C");
            }
            else System.out.println("F");
        }
    }
}



Measured memory_bytes: 26532
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[10000],B[10000];

string ans = "Yes";

void solve(){
	for(int i=0;i<N;i++){
		if((B[i]-A[i])%2==1 && A[i]<B[i]){
			A[i]+=2;B[i]++;
		}
	}
	LL pos = 0,neg = 0;
	for(int i=0;i<N;i++){
		if(B[i]-A[i]>0) pos += (B[i]-A[i])/2;
		if(B[i]-A[i]<0) neg -= (B[i]-A[i]);
	}
	if(pos<neg) ans = "No";
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];
 
    solve();

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
A,B,C,X,Y = map(int,input().split())

ans = 0

if 2 * C < A + B:
  if X > Y:
    ans = min(Y * 2 * C + (X - Y) * A,C * max(X,Y) * 2)
  else:
    ans = min(X * 2 * C + (Y - X) * B,C * max(X,Y) * 2)
else:
  ans = A * X + B * Y
  
print(ans)


Measured memory_bytes: 3060
import math

N = int(input())

A_max = int(math.sqrt(N) + 1)
A = list(range(2, A_max))

prime_check = [0] * (A_max + 1)
multi_list = []

def multi_x(X, n):
    i = 1
    result = 0
    while X % (n**i) == 0:
        result = i
        i += 1
    return result

for a in A:
    if prime_check[a] == 0:
        i = 2
        x = multi_x(N, a)
        if x != 0:
            multi_list.append(x)
            N = N // a**x
        while a * i <= A_max:
            prime_check[a * i] = 1
            i += 1

if N > A_max:
    ans = 1
else:
    ans = 0

for m in multi_list:
    i = 1
    buf = m
    while buf >= i:
        buf -= i
        i += 1
        ans += 1

print(ans)


Measured memory_bytes: 56268
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    L = list(map(int, readline().split()))

    first = max(L)
    second = sum(L) - max(L)

    if first < second:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61936
def maximal():
    N = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    # length of values is N
    # any number more or equals than 0
    result = []
 
    result.append(B[0])
 
    for i in range(0, len(B) - 1):
        # if value is same put in first one
        compared = B[i]
        if B[i + 1] <= compared:
            result.append(B[i + 1])
        else:
            result.append(B[i])
 
    result.append(B[len(B) - 1])
    return sum(result)
 
 
print(maximal())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);

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

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);

template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<T, T> > > & G){     
  using Pa = pair<T, T>;
  vector<T> D(100010,LINF);//----------------
  priority_queue<Pa,vector<Pa>,greater<Pa> > q;
  D[s]=0;
  q.emplace(D[s],s);//最短距離、ゴール頂点番号

  while(!q.empty()){
    T spath=q.top().first;
    int v=q.top().second;
    q.pop();

    if(D[v]<spath) continue;
    for(auto& e:G[v]){
      int u=e.first;//頂点番号
      T c=e.second;//最短距離
      if(D[u]>D[v]+c){
        D[u]=D[v]+c;
        q.emplace(D[u],u);
      }
    }
  }
  return D;
}

signed main(){
    ll n,m;cin>>n>>m;
    vector<vector<PL>> e(n,vector<PL>(0));

    rep(i,0,m){
        ll l,r,c;cin>>l>>r>>c;
        l--;r--;
        e[l].pb({r,c});
    }
    rep(i,0,n-1){
        e[i+1].pb({i,0});
    }

    vector<ll> dis=dijkstra(0,e);
    if(dis[n-1]>=LINF)cout<<-1<<endl;
    else cout<<dis[n-1]<<endl;
}


//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,output_format?

Measured memory_bytes: 9340
# include <iostream>
# include <cmath>
# include <vector>
# include <algorithm>
# include <string>
# include <set>
# include <map>
# include <bitset>
# include <queue>
# include <iomanip>

# define FILE
using namespace std;

const int N = 2e5 + 100;

int n, q, cnt[N];
vector < int > gr[N];

void dfs( int v, int p ){
    for( auto to: gr[v] ){
        if( to == p ) continue;
        cnt[to] += cnt[v];
        dfs( to, v );
    }
}

int main()
{
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif // FILE
    ios_base::sync_with_stdio( false );
    cin >> n >> q;
    for ( int i = 1; i < n; i ++ ){
        int a, b; cin >> a >> b;
        gr[a].push_back( b );
        gr[b].push_back( a );
    }
    while( q -- ){
        int x, p;
        cin >> p >> x;
        cnt[p] += x;
    }
    dfs( 1, 0 );
    for( int i = 1; i <= n; i ++ ){
        cout << cnt[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int ans=0;
  for(int i=0;i<s.length();i++){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3860
// Problem : E - Simple String Queries
// Contest : AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;

int n;
string s;
	
struct FenwickTree {
    vector<int> bit;  // binary indexed tree
    int n;
	FenwickTree(){
		
	}
    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
    }

    FenwickTree(vector<int> a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

    int sum(int r) {
        int ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

    int sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void add(int idx, int delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};



int32_t main()
{
	IOS;
	cin >> n >> s;
	s = '0' + s;
	FenwickTree *f = new FenwickTree[26];
	for(int i = 0; i < 26; i++) {
		f[i] = FenwickTree(n+2);
	}
	for(int i = 1; i <= n; i++) {
		f[s[i]-'a'].add(i, 1);
	}
	int q; cin >> q;
	for(int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if(t == 1) {
			int ind; char ch;
			cin >> ind >> ch;
			if(s[ind] == ch)
				continue;
			f[s[ind]-'a'].add(ind, -1);
			f[ch-'a'].add(ind, 1);
			s[ind] = ch;
		} else{
			int l, r;
			cin >> l >> r;
			int ans = 0;
			for(int j = 0; j < 26; j++) {
				ans += (f[j].sum(r) - f[j].sum(l-1) >= 1);
			}
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 102576
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

int main(){
    string S;
    cin >> S;
    int n = S.size();
    bool flag1 = false;
    bool flag2 = false;
    rep(i, n) {
        if (S[i] == 'A') {
            flag1 = true;
        } else if (S[i] == 'B') {
            flag2 = true;
        }
    }
    if (flag1 && flag2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// ACM-ICPCà\I2010 F. Ã¢L¯

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

const int INF = 100000000;

int d;
string mes, cur;
vector<string> piece;
vector<int> connect[30][20];
vector<string> ans;
set<string> mem[43];
int dp[43][43];

bool editDist(int s, int e){
	for(int i=s+1;i<=e;i++){
		int m = INF;
		for(int j=max(1,i-d);j<=min((int)mes.size(),i+d);j++){
			if(cur[i-1]==mes[j-1]) dp[i][j] = dp[i-1][j-1];
			else {
				dp[i][j] = dp[i-1][j-1]+1;
				dp[i][j] = min(dp[i][j], dp[i-1][j]+1);
				dp[i][j] = min(dp[i][j], dp[i][j-1]+1);
			}
			m = min(m, dp[i][j]);
		}
		if(m > d) return false;
	}
	return true;
}

void dfs(int pIdx, int p1, int p2){
	int len = piece[0].size();
	int csize = cur.size();
	if(dp[csize][mes.size()] <= d) ans.push_back(cur);
	if(len-1 != min(len-1, csize-p2-1))
		cur += string(len-1-(csize-p2-1), ' ');
	for(int i=min(len-1, csize-p2-1);i>=0;i--){
		int nsize = csize+len-i;
		if(nsize > mes.size() + d) break;
		cur += ' ';
		for(int j=0;j<connect[pIdx][i].size();j++){
			bool flag = true;
			for(int k=i;k<len;k++){
				cur[csize+k-i] = piece[connect[pIdx][i][j]][k];
				if(!editDist(csize+k-i, csize+k-i+1)){
					flag = false;
					break;
				}
			}
			if(!flag) continue;
			if(mem[nsize].count(cur)) continue;
			mem[nsize].insert(cur);
			dfs(connect[pIdx][i][j], nsize, p1);
		}
	}
	cur = cur.substr(0, csize);
}

int main(){
	int n, len;
	for(int i=0;i<=42;i++) dp[i][0] = dp[0][i] = i;
	while(cin >> d >> n, n){
		cin >> mes;
		piece.clear();
		for(int i=0;i<n;i++){
			string str; cin >> str;
			piece.push_back(str);
		}
		sort(piece.begin(), piece.end());
		piece.erase(unique(piece.begin(), piece.end()), piece.end());
		len = piece[0].size();
		for(int i=1;i<=mes.size()+d;i++)
			for(int j=1;j<=mes.size()+d;j++)
				if(abs(i-j) > d) dp[i][j] = INF;
		for(int i=0;i<piece.size();i++){
			for(int j=0;j<len;j++){
				connect[i][j].clear();
				for(int k=0;k<piece.size();k++){
					if(piece[i].substr(len-j) == piece[k].substr(0,j))
						connect[i][j].push_back(k);
				}
			}
		}
		for(int i=0;i<=mes.size()+d;i++)
			mem[i].clear();
		ans.clear();
		for(int i=0;i<piece.size();i++){
			cur = piece[i];
			if(!editDist(0, len)) continue;
			dfs(i, len, 0);
		}
		sort(ans.begin(), ans.end());
		cout << ans.size() << endl;
		if(ans.size() <= 5){
			for(int i=0;i<ans.size();i++)
				cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 15000
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int W,H;
	ll p[100001],q[100001];
	vpll pq;
	scan(W>>H);
	rep(i,W) scan(p[i]),pq.push_back({p[i],0});
	rep(i,H) scan(q[i]),pq.push_back({q[i],1});
	sort(pq.begin(),pq.end());
	ll pqn[2]={H+1,W+1};
	ll ans=0;
	for(auto x:pq){
		ans+=x.first*pqn[x.second];
		pqn[!x.second]--;
	}
	prin(ans);
	return 0;
}


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

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

    long long x, y, z;
    vector<vector<long long>> score(8, vector<long long>(N));
    long long coef[8][3] = {
        {1, 1, 1},
        {1, 1, -1},
        {1, -1, 1},
        {1, -1, -1},
        {-1, 1, 1},
        {-1, 1, -1},
        {-1, -1, 1},
        {-1, -1, -1}};
    for (int i = 0; i < N; i++)
    {
        cin >> x >> y >> z;
        for (int j = 0; j < 8; j++)
        {
            score[j][i] = coef[j][0] * x + coef[j][1] * y + coef[j][2] * z;
        }
    }

    long long ans[8] = {};
    for (int i = 0; i < 8; i++)
    {
        sort(score[i].begin(), score[i].end());
        reverse(score[i].begin(), score[i].end());
        for (int j = 0; j < M; j++)
        {
            ans[i] += score[i][j];
        }
    }
    sort(ans, ans + 8);
    reverse(ans, ans + 8);
    cout << ans[0] << endl;
}


Measured memory_bytes: 256
N = gets.to_i

a = Array.new(N + 1, 0)
(1..N).each_with_index do |n, i|
  count = 0
  loop do
    d, m = n.divmod(2)
    count += 1
    if m == 0
      n = d
    else
      break
    end
  end
  a[i + 1] = count
end

puts(a.index(a.max))

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

using namespace std;

typedef long long ll;

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

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

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

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

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

void debug_out() { cerr << endl; }

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

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  int re = 0;
  if (n % x == 0) {
    re = n / x;
  } else {
    re = (n / x) + 1;
  }
  cout << (t * re) << '\n';
  return 0;
}


Measured memory_bytes: 3656
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct
  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m <> i then begin
        let tmp = t.node.(i) in t.node.(i) <- t.node.(m); t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      if i > 1 && M.compare t.node.(parent i) t.node.(i) < 0 then begin
        let tmp = t.node.(i) in t.node.(i) <- t.node.(parent i); t.node.(parent i) <- tmp;
        doit (parent i)
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size
end

module H = MakeBinaryHeap(struct type t = (int * int) let compare x y = snd x - snd y end)

let dijkstra g n =
  let h = H.make 100000 (0, 0) in
  let d = Array.make n max_int in
  let b = Array.make n false in
  d.(0) <- 0;
  b.(0) <- true;
  H.push (0, 0) h;
  let rec duduwa u = function
    | [] -> ()
    | (v, c) :: tl when b.(v) = true || d.(v) <= d.(u) + c -> duduwa u tl
    | (v, c) :: tl ->
      d.(v) <- d.(u) + c;
      H.push (v, -d.(v)) h;
      duduwa u tl
  and doit () =
    if not (H.empty_p h) then begin
      let (u, x) = H.pop h in
      b.(u) <- true;
      if d.(u) >= -x then duduwa u g.(u);
      doit ()
    end in
  doit ();
  d

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> exit 1

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let g = Array.make n [] in
  let rec read i =
    if i < n then
      match List.map int_of_string (split_on_char ' ' (read_line ())) with
      | u :: _ :: l -> g.(u) <- make_pair [] l; read (i + 1)
      | _ -> exit 1 in
  read 0;
  Array.iteri (fun i e -> Printf.printf "%d %d\n" i e) (dijkstra g n)

Measured memory_bytes: 30604
import java.util.Scanner;

public class Main{

	static final Scanner	s	=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}

	private static void input(){
	}

	private static void solve(){
		int x=0,max=0;
		s.next();
		char in[]=s.next().toCharArray();
		for(char c:in) {
			x+=c=='I'?1:-1;
			max=Math.max(x,max);
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21844
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;

	cout << a + b + c - max({ a, b, c }) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

class UnionFind {
public:
    vector<int> par;
    vector<int> rnk;
    vector<int> sze;

    UnionFind(ll n): par(n), rnk(n, 0), sze(n, 1) {
        for (ll i = 0; i < n; ++i) par[i] = i;
    }

    void init(int n) {
        for (int i = 0; i < n; i++) {
            par.resize(n);
            rnk.assign(n, 0);
            sze.assign(n, 1);
        }
    }

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

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return 0;
        if (rnk[x] < rnk[y]) {
            sze[y] = sze[x] + sze[y];
            par[x] = y;
        }
        else {
            sze[x] = sze[x] + sze[y];
            par[y] = x;
            if (rnk[x] == rnk[y]) rnk[x]++;
        }
        return 1;
    }

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

    bool size(int x) {
        return sze[find(x)];
    }
};


int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf = UnionFind(n);
    vector<int> G[m];
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int l;
            cin >> l;
            G[l - 1].push_back(i);
        }
    }
    for (int i = 0; i < m; i++) {
        if (G[i].size() == 0) continue;
        for (int j = 0; j < G[i].size() - 1; j++) {
            uf.unite(G[i][j], G[i][j + 1]);
        }
    }
    set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(uf.find(i));
    }
    cout << (s.size() == 1 ? "YES" : "NO") << endl;

}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

int n , m;
int d[MAXX];
vector<int> v[MAXX];
bool used[MAXX];

void BFS(int n){
    queue<int> q;
    q.push(n);
    used[n] = true;
    d[n] = 0;
    while(!q.empty()){
        int p = q.front();
        q.pop();
        for(int i = 0; i < v[p].size(); i++){
            int to = v[p][i];
            if(!used[to]){
                d[to] = d[p] + 1;
                used[to] = true;
                q.push(to);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x , y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    BFS(1);
    for(int i = 2; i <= n; i++){
        if(!used[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i = 2; i <= n; i++){
            int l = n;
            int ans = 0;
        for(int j = 0; j < v[i].size(); j++){
            int to = v[i][j];
            if(l > d[to]){
                l = d[to];
                ans = to;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

using namespace std;

int getDigitSum(int num){
  int dst = 0;
  while(num>0){
    dst += num%10;
    num = num/10;
  }

  return dst;
}

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

  int minum=2*9*6;

  for(int A = 1;A<=N/2+1;A++){
    int B = N - A;
    int tmp = getDigitSum(A) + getDigitSum(B);
    if(tmp < minum){
      minum = tmp;
    }
  }

  cout << minum << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
void calc(int x, int y){
    int ans;
    ans = x * y / 2;
    printf("%d", ans);
}
int main(void){
    //int a = 10 ; int b = 8; int c = 4;
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int data[3] = {a,b,c};
    sort(data, data+3);
    calc(data[0], data[1]);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool isok(int a,int b,int c)
{
	int tmp;
	for(int i=0;i<3;i++) 
	{
		if (a>b)  
		{
			tmp=a;a=b; b=tmp;
		}
		if (b>c)
		{
			tmp=b;b=c; c=tmp;
		}
	}
	if (a==b||b==c||a==c) return false;
	if (c<=b-a||c>=a+b) return false;
	return true;
}
int main()
{
	int n,a[105],ans=0;
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++)
	{
		for (int j=i+1;j<n||a[i]==a[j];j++)
		{
			for (int k=j+1;k<n||a[i]==a[k]||a[j]==a[k];k++)
			{
				if (isok(a[i],a[j],a[k]))
				{
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3624
import heapq
N=int(input())
v=input().split()
q=[]
for i in range(N):
    heapq.heappush(q, int(v[i]))
while len(q)>1:
    a=heapq.heappop(q)
    b=heapq.heappop(q)
    heapq.heappush(q, (a+b)/2)
print(q[0])

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
	char a[50], b[50];
	scanf("%s %s", a, b);
	int i,j=0,k=0;
	for(i=0;a[j]!='\0'||b[k]!='\0';i++){
		if(i%2==0){printf("%c",a[j++]);}
		else{printf("%c",b[k++]);}
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  ll D;
  cin >> n >> D;
  vector<ll> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  vector<ll> pos(n + 1), ng(n + 1);
  pos[0] = D;
  ng[n] = 1;
  for (int i = 0; i < n; i++) {
    pos[i + 1] = min(abs(pos[i] - d[i]), pos[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (ng[i + 1] <= d[i] / 2) {
      ng[i] = ng[i + 1];
    } else {
      ng[i] = ng[i + 1] + d[i];
    }
  }

  cin >> q;
  vector<ll> a(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i];
    a[i]--;
    if (pos[a[i]] >= ng[a[i] + 1]) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 17536
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f(n,m):
        n -= 1
        i = 1
        l = 1
        for k in range(1,10):
            if n > 10**(k-1) * 9 * k:
                n -= 10**(k-1) * 9 * k
                i = 10 ** k
                l = k + 1
            else:
                break
        i += n // l
        n %= l
        r = ''
        for j in range(i,i+101):
            r += str(j)
        return r[n:n+m]

    while True:
        n,m = LI()
        if n == 0 and m == 0:
            break
        rr.append(f(n,m))

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 9036
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		int min, max;
		long sum;
		
		int a = scan.nextInt();
		min = a;
		max = a;
		sum = a;
		
		for (int i=1; i<n; i++){
			a = scan.nextInt();
			
			if(a < min){
				min = a;}
			if(a > max){
				max = a;}
			sum += a;
			}
			
		System.out.println(min+" "+max+" "+sum);
	}
}


Measured memory_bytes: 41704
#include <stdio.h>

int main(){
  
  int N,T;
  scanf("%d%d",&N,&T);
  
  int i,c[N + 1],t[N + 1];
  for(i = 1; i <= N; i++){
    scanf("%d%d",&c[i],&t[i]);
  }
  
  int count = 0;
  for(i = 1; i <= N; i++){
    if(t[i] <= T)
      count++;
  }
  
  if(count == 0)
    printf("TLE");
  else{
    for(i = 1; i <= N; i++){
      if(t[i] > T)
        c[i] = 1001;
    }
    
    int ans = c[1];
    for(i = 2; i <= N; i++){
      if(ans > c[i])
        ans = c[i];
    }
    printf("%d",ans);
  }
  
  return 0;
  
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

void warshall_floyd(int n, v2_ll &dist)
{
    irep(i, n) { dist[i][i] = 0; }

    irep(k, n) {
        irep(i, n) {
            irep(j, n) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main(void)
{
    int n, m, r;
    cin >> n >> m >> r;

    v_int vec_r(r);
    irep(i, r) {
        cin >> vec_r[i];
        vec_r[i]--;
    }

    v2_ll dist(n, v_ll(n, LINF));

    irep(i, m) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        dist[a-1][b-1] = c;
        dist[b-1][a-1] = c;
    }
    
    warshall_floyd(n, dist);

    ll ans = LINF;

    v_int index(r);
    irep(i, r) { index[i] = i; }

    do {
        ll d = 0;
        irep(i, r-1) {
            d += dist[vec_r[index[i]]][vec_r[index[i+1]]];  
            //cout << vec_r[i] +1<< "<->" << vec_r[i+1] +1<< "," <<  dist[vec_r[i]][vec_r[i+1]] << ",";  
        }
        ans = min(ans, d);
        //cout << "ans," << ans << endl;
    } while(next_permutation(index.begin(), index.end()));

    cout << ans << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
int mul(int a,int b){return (ll)a*b%mod;}
int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
const int N=2e5+5;
int n,c[N],a[N];
int m;
vector<int> pos[N];
int id[N];
int f[N],g[N];
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i==1||a[i]!=a[i-1])c[++m]=a[i];
	}
	for(int i=1;i<=m;i++){
		pos[c[i]].push_back(i);
		id[i]=pos[c[i]].size()-1;
	}
	f[0]=g[0]=1;
	for(int i=1;i<=m;i++){
		f[i]=f[i-1];
		int t=id[i]-1;
		if(t>=0){
			f[i]=add(f[i],g[pos[c[i]][t]]);
		}
		g[i]=f[i-1];
		if(t>=0)g[i]=add(g[i],g[pos[c[i]][t]]);
	}
	cout<< f[m]<<endl;
}

Measured memory_bytes: 15104
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x:x[1])
t = 0
ans ="Yes"
for i in range(N):
    t += AB[i][0]
    if t > AB[i][1]:
        ans ="No"
print(ans)

Measured memory_bytes: 53728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    reverse(ALL(a));
    int t=0;
    ll ans=0;
    REP(i,n){
        if(!i){
            continue;
        }
        ans+=a[t];
        if(i&1){
            t++;
        }
    }
    cout << ans << endl;
}

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

int main(){ 

  long long N;
  long long A, B, C, D, E;

  cin >> N;
  cin >> A >> B >> C >> D >> E;
  

  long long MinMove = min({A, B, C, D, E});

  long long ans = (( N + MinMove - 1) / MinMove ) + 4;

  cout << ans << endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PIなどの定義を使用するのに必要
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

int A[200005];
int B[200005];

int main()
{
  int64_t N;

  cin >> N;

  for (int i = 2; i <= N; i++) {
    cin >> A[i];
  }

  for (int i = 2; i <= N; i++) {
    B[A[i]]++;
  }

  for (int i = 1; i <= N; i++) {
    cout << B[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 5124
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int k = int.Parse(input[0]);
		int x = int.Parse(input[1]);

		//処理
		string anser="";
		for(int i=x-k+1;i<x+k;i++){
			anser+=i.ToString()+" ";	
		}


		//出力
		Console.WriteLine(anser);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int ans = 0;
    for(int i = min(A,C); i < max(B,D); i++){
        if((A<=i && C<=i) && (i<B && i<D)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int maxn = 110000;

int deg[maxn];

int main(int argc,char * argv[])
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= m;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		deg[u]++;
		deg[v]++;
	}
	bool tf = true;
	for (int i = 1;i <= n;++i)
	{
		if (deg[i] % 2 == 1)
		{
			tf = false;
			break;
		}
	}
	if (tf) printf("YES\n");
	else printf("NO\n");
	return 0;
}
	

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

vector<int> graph[100005];
int dat[100005];
long long up[100005];

void dfs(int t, int p)
{
	vector<long long> vt;

	for (int nxt : graph[t])
	{
		if (nxt == p) continue;
		dfs(nxt, t);
		vt.push_back(up[nxt]);
	}

	if (vt.empty())
	{
		up[t] = dat[t];
		return;
	}

	if (vt.size() == 1)
	{
		if (vt[0] != dat[t])
		{
			printf("NO\n");
			exit(0);
		}
		up[t] = dat[t];
		return;
	}

	sort(vt.begin(), vt.end());

	long long maxmatch = 0;
	long long sum = 0;
	for (int i = 0; i < vt.size() - 1; i++)
	{
		sum += vt[i];
	}

	if (sum <= vt.back()) maxmatch = sum;
	else maxmatch = (sum + vt.back()) / 2;
	sum += vt.back();

	if (dat[t] > sum)
	{
		printf("NO\n");
		exit(0);
	}

	long long diff = sum - dat[t];
	if (diff > maxmatch)
	{
		printf("NO\n");
		exit(0);
	}

	up[t] = dat[t] - diff;
}

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

	for (int i = 1; i < n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	if (n == 2)
	{
		if (dat[0] == dat[1]) printf("YES\n");
		else printf("NO\n");
		return 0;
	}

	for (int i = 0; i < n; i++)
	{
		if (graph[i].size() >= 2)
		{
			dfs(i, -1);

			if (up[i] == 0) printf("YES\n");
			else printf("NO\n");

			return 0;
		}
	}
}

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

int n, x, y;

int dis(int i, int j) {
    if (i < x && j <= x) return j-i;
    else if (i < x && x < j && j <= y) return min(j-i,x-i+y-j+1);
    else if (i < x && y < j) return x-i+j-y+1;
    else if (x <= i && i < y && j < y) return min(j-i,i-x+y-j+1);
    else if (x <= i && i < y && y <= j) return min(j-i,i-x+j-y+1);
    else if (y <= i) return j-i;
    return 0;
}

int main() {
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        for (int j = 1; i+j < n; j++) {
            ans[dis(i,i+j)]++;
        }
    }
    rep(i,n-1) cout << ans[i+1] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
		int j;
		for(int i=1;;i++){
			j = scan.nextInt();
			if(j==0)break;
			System.out.println("Case "+i+": "+j);
		}
	}
}

Measured memory_bytes: 42312
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  string s;
  int K;
  cin>>K;
  cin>>s;
  if(s.size()<=K) cout<<s<<endl;
  else{
    cout<<s.substr(0,K)+"..."<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  int k;
  cin>>k;
  cout<<a[k-1];
  return(0);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

#define N 100
int n;
int d[N];

void bfs(vector<vi> a,int s){
    rep(i,n)d[i]=inf;
    queue<int> q;
    q.push(s);
    d[0]=0;
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int u:a[v]){
            if(d[u]!=inf)continue;
            d[u]=d[v]+1;
            q.push(u);
        }
    }
}

void run(){
    cin>>n;
    vector<vi> a(n);
    rep(i,n){
        int u,k;
        cin>>u>>k;
        u--;
        rep(j,k){
            int v;
            cin>>v;
            v--;
            a[u].pb(v);
        }
    }
    bfs(a,0);
    rep(i,n){
        cout<<i+1<<" "<<(d[i]!=inf?d[i]:-1)<<endl;
    }
}


Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int a,b; cin>>a>>b;
	cout << max(max(a+b,a-b),a*b);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll INF = 1e18;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int k = n%2+1;
  ll dp[200005][4];
  for(int i = 0; i < n+1; i++) {
    for(int j = 0; j < k+1; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[0][0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < k+1; j++) {
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]);
      ll now = dp[i][j];
      if ((i+j)%2 == 0) now += a[i];
      dp[i+1][j] = max(dp[i+1][j], now);
    }
  }

  ll ans = dp[n][k];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10388