akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new java.util.Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] sNumbers = sc.nextLine().split(" ");
    Map<Integer, Integer> numbers = new HashMap<>();
    for (Integer i = 0; i < sNumbers.length; i++) {
      numbers.put(Integer.parseInt(sNumbers[i]), i);
    }
    if (numbers.size() == N) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

const int M = 100100;

int n, k;
ll f[M], g[M];
ll a[M], s[M];
ll l[M], r[M];

void read() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    s[i + 1] = s[i] + a[i];
  }
}

void kill() {
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    l[i + 1] = l[i] + max<ll>(0, a[i]);
  }
  for (int i = n - 1; i >= 0; --i) {
    r[i] = r[i + 1] + max<ll>(0, a[i]);
  }

  for (int i = 0; i + k <= n; ++i) {
    ll sum = max<ll>(0, s[i + k] - s[i]);
    ans = max(ans, sum + l[i] + r[i + k]);
  }

  cout << ans << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();

}



Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#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-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;
int dx[8] = { -1,-1,-1,0,0,1,1,1, };
int dy[8] = { 1,0,-1,1,-1,1,0,-1 };


void solve() {
	int N; cin >> N;
	vector<int>v(N);
	vector<int>a, b;
	REP(i, N) {
		cin >> v[i];
		if (i % 2 == 0)a.push_back(v[i]);
		else b.push_back(v[i]);
	}
	map<int, int>mp1, mp2;
	REP(i, N / 2) {
		mp1[a[i]]++;
		mp2[b[i]]++;
	}
	mp1[0] = 0;
	mp2[0] = 0;
	vector<P>v1, v2;
	for (auto x : mp1) {
		v1.push_back({ x.second, x.first });
	}
	for (auto x : mp2) {
		v2.push_back({x.second, x.first});
	}
	VSORT(v1); VREVERSE(v1);
	VSORT(v2); VREVERSE(v2);
	int ans1 = N / 2 - v1[0].first;
	if (v2[0].second != v1[0].second)ans1 += N / 2 - v2[0].first;
	else ans1 += N / 2 - v2[1].first;
	int ans2 = N / 2 - v2[0].first;
	if (v2[0].second != v1[0].second)ans2 += N / 2 - v1[0].first;
	else ans2 += N / 2 - v1[1].first;
	print(min(ans1, ans2));
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 10352
H, W = map(int, input().split(' '))
campus = ['.' + input() + '.' for _ in range(H)]
campus.insert(0, '.' * (W + 2))
campus.append('.' * (W + 2))
flag = 0
for i in range(H):
    for j in range(W):
        if campus[i][j] == '#' \
            and campus[i-1][j] == '.' \
            and campus[i][j-1] == '.' \
            and campus[i+1][j] == '.' \
            and campus[i][j+1] == '.':
            flag = 1
            break
if flag == 0:
    print('Yes')
else:
    print('No')

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) ((n)*(n))

using namespace std;
using ll = long long;

vector<ll> primes = {2};

void gen(int n) {
    int i, j;

    vector<bool> s(n, 1);

    for (i = 3; sq(i) <= n; i += 2) {
        if (!s[i]) continue;
        for (j = sq(i); j <= n; j += i) s[j] = 0;
    }

    for (i = 3; i <= n; i += 2) {
        if (s[i]) primes.push_back(i);
    }
}


ll num (ll n) {
    ll l = 1, r = 10000, m, ans = 0;

    while (l <= r) {
        m = (l+r)/2;

        if (m*(m+1)/2 <= n) {
            ans = m;
            l = m+1;
        } else {
            r = m-1;
        }
    }

    return ans;
}

int main() {
    FAST;

    ll n, i, sz, cc, t, ans = 0;

    gen(1000005);
    sz = primes.size();

    cin >> n;

    for (i = 0; i < sz; ++i) {
        if (n % primes[i]) continue;

        cc = 0;
        while (n % primes[i] == 0) {
            n /= primes[i];
            ++cc;
        }

        t = num(cc);
        ans += t;

        if (n == 1) break;
    }
    if (n > 1) ++ans;

    cout << ans;

    return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

bool DEBUG=0;
const int MAXN = 100005;

ll a[MAXN],b[MAXN];
vi eve[MAXN];
multiset<ll,greater<ll>> s;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,m; cin>>n>>m;
	forn(i,0,n){
		cin>>a[i]>>b[i];
		if(a[i]>m) continue;
		eve[m-a[i]].pb(b[i]);
	}
	ll ans=0;
	
	for(int i=m-1;i>=0;i--){
		for(ll x: eve[i]){
			s.insert(x);
		}
		if(s.size()){
			ans+=*s.begin();
			s.erase(s.begin());
		}
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 12812
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll w,ll a,ll b){
    int res;
    int c = min(a,b);
    int d = max(a,b);
    c += w;
    res = d-c<0 ? 0:d-c;
    return res;
}

int main(){
    ll w,a,b;cin>>w>>a>>b;
    ll out = solve(w,a,b);
    cout<<out;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int cnt=0;
    if(i%2!=0){
     for(int j=1;j<=i;j++){
       if(i%j==0) cnt++;
     }
     if(cnt==8)ans++;
    }
  }
  cout << ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> A >> B;
	N = B - A;
	ll sum = -A;
	for (int i = 1; i < N; i++) {
		sum += i;
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
# 未完成
H,W = map(int,input().split())
field = []

for i in range(H):
    coins = list(map(int,input().split()))
    field.append(coins)

field_route = []
is_left_to_right = False
for i in range(H):
    is_left_to_right = not is_left_to_right
    for j in range(W):
        if is_left_to_right:
            field_route.append((j,i))
        else:
            field_route.append((W-j-1,i))


ans_ls = []
for i,next_xy in enumerate(field_route[:-1]):
    tx,ty = next_xy
    x,y = field_route[i+1]
    if field[ty][tx] == 0:
        tx,ty = x,y
        continue
    if field[ty][tx] %2 == 1:
        field[y][x] += 1
        ans_ls.append([ty+1,tx+1,y+1,x+1])
    tx,ty = x,y
print(len(ans_ls))
for l in ans_ls:
    print(l[0],l[1],l[2],l[3])

Measured memory_bytes: 52004
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
 
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 
 
using namespace std;
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();  	
}

const int MAXN = 2e5 + 10, INF = 1e18, MOD = 1e9 + 7;

void solve() {                     
	int h, w, a, b;
	cin >> h >> w >> a >> b;

	if (h < b || w < a) {
	 	cout << -1 << endl;
	 	return;
	}
	
	vector<vector<int>> res(h, vector<int>(w));
	for (int i = 0; i < b; ++i) {
		for (int j = 0; j < a; ++j) {
		    res[i][j] = 1;
		}	
	}

	for (int i = b; i < h; ++i) {
	    for (int j = a; j < w; ++j) {
	     	res[i][j] = 1;
	    }
	}	

	for (int i = 0; i < h; ++i) {
	 	for (int j = 0; j < w; ++j) {
	 	 	cout << res[i][j];
	 	}
	 	cout << endl;
	}
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double INF = 1e9;
 
ll a,b,c,d,e,f;
 
int main(){
    cin >> a >> b >> c >> d >> e >> f;
    //step1
    vector<bool>water(3010,false);
    for(int i=0;i*100*a<=f;i++){
        for(int j=0;j*100*b<=f;j++){
            if(i*100+j*100>f)continue;
            water[i*a*100+j*b*100]=true;
        }
    }
    vector<bool>sugar(3010,false);
    for(int i=0;i*c<=f;i++){
        for(int j=0;j*d<=f;j++){
            if(i*c+j*d>f)continue;
            sugar[i*c+j*d]=true;
        }
    }
 
    //step2
    double M = -1;
    P ans = {-1,-1};
    for(int i=1;i<=f;i++){
        for(int j=0;j<=f;j++){
            if(!water[i])continue;
            if(!sugar[j])continue;
            if(i+j>f)continue;
            if((100+e)*(100*j)>100*e*(i+j))continue;
            double now = 100.0*j;
            now = now/(i+j);
            if(chmax(M,now)){
                ans.first=i+j;
                ans.second=j;
            }
        }
    }
    cout << ans.first << ' ' << ans.second << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
  ll n, k, x, y;
  scanf("%lld %lld %lld %lld", &n, &k, &x, &y);
  if(k > n) k = n;
  ll sum = (k * x) + ((n - k) * y);
  printf("%lld\n", sum);
  return 0;
}


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

const long long int MOD = 1e9+7;
#define pb push_back
typedef long long ll;
const long long int N = 1e5;



int main(){
    int n;
    cin>>n;
    vector<vector<ll>> dp(n+5,vector<ll>(n+5,0));
    ll a[n+5];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n;i>=1;i--){
        for(int j=i;j<=n;j++){
            dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }
    cout<<dp[1][n];
    return 0;
}

Measured memory_bytes: 74016
N,D = map(int,input().split())
XY = []
for _ in range(N):
    X ,Y = map(int,input().split())
    XY.append((X,Y))
res = 0
D2 = D * D
for k in XY:
    if k[0] **2 + k[1]**2 <= D2:
        res += 1
print(res)

Measured memory_bytes: 35992
N = int(input())
if N==2:
    print(-1)
    exit()
if N==3:
    print("""aa.
..b
..b""")
    exit()
P4 = """abcc
abdd
ccab
ddab"""
P5 = """abbaa
a..db
b..db
bcc.a
aabba"""
P6 = """aa.ccd
..bd.d
..bdcc
ccdaa.
d.d..b
dcc..b"""
P7 = """.ccbbaa
c...ccd
c...d.d
b...dcc
bccd...
ad.d...
adcc..."""
P = [P4, P5, P6, P7]
def construct(L):
    P_split = [p.split() for p in P]
    ans = []
    offset = 0
    for l in L:
        r = N-offset-l
        for p in P_split[l-4]:
            ans.append("."*offset + p + "."*r)
        offset += l
    return "\n".join(ans)
def sep(n):  # 4 と 5 に分ける
    if n==6:
        return [6]
    elif n==7:
        return [7]
    elif n==11:
        return [5, 6]
    res = [4] * (n//4)
    for i in range(n%4):
        res[i] += 1
    return res
print(construct(sep(N)))


Measured memory_bytes: 6116
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
from collections import defaultdict
def ddprint(x):
  if DBG:
    print(x)

a = ins()
h = defaultdict(int)
for i in range(len(a)):
    h[a[i]] += 1
sm = 1
keys = list(h.keys())
for i,x in enumerate(keys):
    for j in range(i+1,len(keys)):
        sm += h[keys[i]]*h[keys[j]]
print(sm)


Measured memory_bytes: 40048
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

int powm(int a, int b, int mod) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

vi gra[200005];
vi pol[3];
void dfs(int fr, int at, int lev) {
	if(lev==0||lev==3)
		pol[0].pb(at);
	else if(lev==1||lev==5)
		pol[1].pb(at);
	else
		pol[2].pb(at);
	for(int i:gra[at])
		if(i!=fr)
			dfs(at,i,(lev+1)%6);
}
vi polo[3];
int perm[200005];
void solve() {
	int n=100000;
	cin>>n;
	fr(i,2,n) {
		int u,v;
		cin>>u>>v;
		gra[u].pb(v);
		gra[v].pb(u);
	}
	fr(i,1,n)
		polo[i%3].pb(i);
	while(1) {
		rep(i,0,3)
			pol[i].clear();
		int from=rng(n)+1;
		trace(from);
		dfs(0,from,rng(6));
		if(sz(pol[1])>=sz(polo[1])+sz(polo[2])) {
			while(sz(polo[1])) {
				perm[pol[1].back()]=polo[1].back();
				pol[1].pop_back();
				polo[1].pop_back();
			}
			while(sz(polo[2])) {
				perm[pol[1].back()]=polo[2].back();
				pol[1].pop_back();
				polo[2].pop_back();
			}
			rep(i,0,3) {
				while(sz(pol[i])>0) {
					perm[pol[i].back()]=polo[0].back();
					pol[i].pop_back();
					polo[0].pop_back();
				}
			}
			fr(i,1,n) {
				cout<<perm[i]<<" ";
			}
			return;
		}
		if(sz(pol[1])<sz(polo[1])||sz(pol[2])<sz(polo[2]))
			continue;
		break;
	}
	trace(pol[0],polo[0]);
	trace(pol[1],polo[1]);
	trace(pol[2],polo[2]);
	fr(i,1,2) {
		while(sz(polo[i])>0) {
			perm[pol[i].back()]=polo[i].back();
			polo[i].pop_back();
			pol[i].pop_back();
		}
	}
	rep(i,0,3) {
		while(sz(pol[i])>0) {
			perm[pol[i].back()]=polo[0].back();
			pol[i].pop_back();
			polo[0].pop_back();
		}
	}
	fr(i,1,n) {
		cout<<perm[i]<<" ";
	}
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 23016
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static class FenwickTree {
	    int n;
	    long x[];
	    public FenwickTree(int N) {
	    	this.n = N;
	    	x = new long[N + 1] ;
		}
	    int size()  { return n; }
	    long sum(int r) {
	        long S = 0;
	        for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
	        return S;
	    }
	    long sum(int l, int r)  { return sum(r) - sum(l); }
	    void add(int k, long a) {
	        for (; k < n; k |= k + 1) {
	        	x[k] += a;
	        }
	    }
	    void set(int k, long a) { add(k, a - sum(k, k + 1)); }
	};
	static void solve(int A[] , int K){
		int N = A.length;
		FenwickTree ft = new FenwickTree(N);
		for(int i = 0 ; i < N ; ++i){
			int a = A[i];
			if(a == 0){
				continue;
			}
			ft.add(i,   a);
			ft.add(i + 1, - a);
		}
		for(int i = 0 ; i < K ; ++i){
			FenwickTree L = new FenwickTree(N);
			for(int j = 0 ; j < A.length ; ++j){
				int a = (int)ft.sum(0, j + 1);
				int l = j - a;
				int r = j + a;
				if(l < 0){
					l = 0;
				}
				if(r >= N){
					r = N - 1;
				}
				L.add(l, 1);
				L.add(r + 1, -1);
			}
			ft = L;
			boolean f = true;
			for(int j = 0 ; j < A.length ; ++j){
				int a = (int)ft.sum(0, j + 1);
				if(a != N){
					f = false;
					break;
				}
			}
			if(f){
				break;
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int j = 0 ; j < A.length ; ++j){
			if(sb.length() > 0){
				sb.append(' ');
			}
			int a = (int)ft.sum(0, j + 1);
			sb.append(a);
		}
		System.out.println(sb.toString());
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int A[] = new int[N];
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextInt();
		}
		solve(A, K);
	}
}


Measured memory_bytes: 65404
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=new int[](n);
  foreach(i; 0..n) rd(a[i]);

  auto s=a.sum;
  if(s%10>0){
    writeln(s);
    return;
  }
  auto all=reduce!((r, e)=>r&&(e%10==0))(true, a);
  if(all){
    writeln(0);
    return;
  }
  int mn=1000000000;
  foreach(e; a){
    if(e%10>0){
      mn=min(mn, e);
    }
  }
  import std.exception;
  if(mn<1000000000){
    writeln(s-mn);
  }else{
    enforce(false);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	int N; cin >> N;
	vector<int> v(N, 0);

	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		ans ^= v[i];
	}

	for (int i = 0; i < N; i++) {
		cout << (int)(ans^v[i]) << " ";
	}

	return 0;
}

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

int N,M,K;
int A[105];

vector<int> B;

int main(){
	int i,cnt;
	scanf("%d%d",&N,&M);
	for(i=1;i<=M;i++)
		scanf("%d",&A[i]);
	if(M<2){
		B.push_back(N-1);
		B.push_back(1);
	}
	else{
		for(i=1;i<=M;i++)
			cnt+=A[i]&1;
		if(cnt>2){
			puts("Impossible");
			return 0;
		}
		for(i=1;i<=M;i++)
			if(A[i]&1)
				swap(A[A[1]&1?M:1],A[i]);
		for(i=1;i<=M;i++)
			B.push_back(A[i]+(i<2?-1:(i==M)));
	}
	for(i=1;i<=M;i++)
		printf("%d ",A[i]);
	puts("");
	printf("%d\n",B.size()-!B[0]);
	for(i=!B[0];i<B.size();i++)
		printf("%d ",B[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define fr(i,x,n) for(int i=x;i<=n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define PB push_back
#define X first
#define Y second
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=1E5+5;
const int maxm=1E5+5;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const LL mod=1E9+7;
const double eps=1E-6;
const double PI=acos(-1.0);
vector<int> G[maxn];
int dp[maxn];
int dfs(int u){
    if(dp[u]) return dp[u];
    rep(i,(int)G[u].size()){
        dp[u]=max(dp[u],dfs(G[u][i])+1);
    }
    return dp[u];
}
void solve(){
    int n,m,u,v;
    cin>>n>>m;
    rep(i,m) cin>>u>>v,G[u].PB(v);
    rep1(i,n) dfs(i);
    cout<<*max_element(dp+1,dp+1+n)<<"\n";
}
int main(){
    IOS;
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 11400
import java.io.{PrintWriter, _}
import java.util
import java.util._

import scala.collection.mutable


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  def ?(item: Boolean, first: Object, second: Object): Object = if (item) first else second
  
  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val n = in.nextInt
      val map = mutable.HashMap(25 -> "Christmas", 24 -> "Christmas Eve", 23 -> "Christmas Eve Eve",
        22 -> "Christmas Eve Eve Eve")
      out.println(map(n))
    }
  }


  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    string st;
    cin >> st;
    string en;
    cin >> en;
    

    rep(i, n) {
        bool fl = true;
        rep(j, n-i) {
            if (st[i + j] != en[j]) fl = false;
        }
        if (fl) {
            std::cout << n + i << std::endl;
            return 0;
        }
    }

    std::cout << n + n << std::endl;

    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
int main () {
  int n,m;
  int arr1[100][100];
  int arr2[100];
  int i,j;
  int input;
  int res[100];
  int sum;

  scanf("%d %d",&n,&m);
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      scanf("%d",&input);
      arr1[i][j] = input;
    }
  }
  for(i = 0; i < m; i++){
    scanf("%d",&input);
    arr2[i] = input;
  }
  for(i = 0; i < n; i++){
    sum = 0;
    for(j = 0; j < m; j++){
      sum += arr1[i][j] *arr2[j];
    }
    res[i] = sum;
  }

  for(i = 0; i < n; i++){
    printf("%d\n",res[i]);
  }
  return 0;
}


Measured memory_bytes: 2144
// not finished triangles triangles triangles triangles triangles triangles 

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

string a, b;

int main(){

    cin >> a >> b;

    vector<char> v;

    for(int i = 0; i < max(a.length(), b.length()); i++){
        if(i < a.length()){
            cout << a[i];
        }
        if(i < b.length()){
            cout << b[i];
        }
    }





}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 25 )
int main(){
  int n, dp[5001];
  const int price[] = { 380, 550, 850, 1520, 1870, 2244};
  const int more[] = { 200, 300, 500, 1000, 1200, 1500};
  fill_n( dp, 5001, INF);
  dp[0] = 0;
  for(int i = 0 ; i < 5001 ; i++ ){
    for(int j = 0 ; j < 6 ; j++ ){
      if(i + more[j] < 5001) dp[i + more[j]] = min( dp[i + more[j]], dp[i] + price[j]);
    }
  }
  while(cin >> n , n) cout << dp[n] << endl;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>

using namespace std;

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

	vector<long long> L(N + 1);
	L[0] = 2;
	L[1] = 1;
	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}

	cout << L[N] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
//#include<algorithm>
#include<set>
using namespace std;
set<int> s;
int main()
{
    int n, tmp;
    scanf("%d", &n);
    while(n--)
    {
        scanf("%d", &tmp);
        if(s.count(tmp) == 1)
            s.erase(tmp);
        else
            s.insert(tmp);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 4864
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n;
string a, b;
int main() {
    DAU
    cin >> n >> a >> b;
    for (int i = 0; i < n; ++i)
        cout << a[i] << b[i];
    PLEC
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h> //qsort
#include<string.h> //strcmp

int cmp(const void *a, const void *b); //比較関数

int main(){
  int n,ans=1;
  int i;
  scanf("%d",&n);
  char item[n][11];
  for(i=0;i<n;i++){
    scanf("%s",item[i]);
  }

  qsort(item,n,sizeof(item[0]),cmp); //qsortで辞書順にソートする

  for(i=1;i<n;i++){
    if(strcmp(item[i-1],item[i])!=0) //strcmpが0なら2つの文字列は同じ
      ans++;
  }
    
  printf("%d",ans);
}

int cmp(const void *a, const void *b){ //比較関数
  return strcmp((char *)a,(char *)b); //数字の大小を返す
}

Measured memory_bytes: 5716
#include <iostream>

using namespace std;

int main(void) {
    string s, t;
    cin>>s>>t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s.compare(t) < 0) {
        cout<<"Yes";
    } else {
        cout<<"No";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


const int maxn = 2e5+5;
vector<int> g[maxn];
int p[maxn], q[maxn], pa[maxn], vis[maxn], n, pm[maxn];

void dfs0(int x) {
  for (auto t : g[x]) if (t != pa[x]) {
    pa[t] = x;
    pm[t] = max(pm[x], pa[x]);
    dfs0(t);
  }
}

void dfs2(int x, int pa, int pm) {
  int sum = 0;
  for (auto t : g[x]) if (t != pa) {
    sum += p[t];
  }
  q[x] = sum + pm + 1;
  //cout << "q " << x << " " << pm << ' ' << q[x] << endl;
  for (auto t : g[x]) if (t != pa) {
    dfs2(t, x, pm + sum + 1 - p[t]);
  }
}


void dfs1(int x, int up) {
  p[x] = x < up;
  for (auto t : g[x]) if (t != pa[x] && !vis[t]) {
    dfs1(t, up);
    if (p[x] > 0) {
      p[x] += p[t];
    }
  }
}
int dfs3(int x, int up) {
  int res = x < up;
  if (res == 0) 
    return res;
  for (auto t : g[x]) if (t != pa[x] && t < up && !vis[t]) {
    res += dfs3(t, up);
  }
  return res;
}


void mark(int x) {
  vis[x] = 1;
  for (int t : g[x]) if (t != pa[x] && !vis[t]) {
    mark(t);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs0(1);

  for (int i = n; i >= 1; i --) if (!vis[i]) {
    for (int x : g[i]) if (x != pa[i] && !vis[x]) {
      for (int t : g[x]) if (t != pa[x] && !vis[t]) {
        dfs1(t, i);
      }
    }
    for (int x : g[i]) if (x != pa[i] && !vis[x]) {
      p[x] = dfs3(x, pm[x]);
    }
    mark(i);
  }

  dfs2(1, 0, 0);

  rep(i, 2, n + 1) {
    printf("%d ", q[i] - 1);
  }

  return 0;
}


Measured memory_bytes: 25856
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, Z, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    AB = [a + b for a in A[:K] for b in B[:K]]
    AB.sort(reverse=True)

    ABC = [ab + c for ab in AB[:K] for c in C[:K]]
    ABC.sort(reverse=True)

    print(*ABC[:K], sep='\n')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 248372
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		String ans;

		if (a == c) {
			ans = "Yes";
		} else if (a < c){
			if (c-a <= d){
				ans = "Yes";
			} else if (a <= b && b <= c){
				if (c-b <= d && b-a <=d){
					ans = "Yes";
				} else {
					ans = "No";
				}
			} else {
				ans = "No";
			}
		} else if (c < a) {
			if (a-c <= d){
				ans = "Yes";
			} else if (c <= b && b <= a){
				if (a-b <= d && b-c <=d){
					ans = "Yes";
				} else {
					ans = "No";
				}
			} else {
				ans = "No";
			}
		} else {
			ans = "No";
		}
		// 出力
		System.out.println(ans);
	}
}


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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

signed main(){
    int N;cin >> N;
    vector<double> vec;
    for(int i = 0;i < N;i++){
        int a;cin >> a;
        vec.push_back(a);
    }
    double ans = -1e9;
    sort(vec.begin(), vec.end());
    for(int i = 0;i < N-1;i++){
        for(int j = i+1;j < N;j++){
            int cnt = 0;
            double sum = 0;
            for(int k = N-1;k >= 0;k--){
                if(cnt >= 2)break;
                if(i == k || j == k){
                    continue;
                }else{
                    cnt++;
                    sum += vec[k];
                }
            }
            ans = max(ans, sum / (vec[j] - vec[i]));
        }
    }
    cout<<setprecision(20)<<ans<<endl;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
vll seen;
vvll graph;
vll indeg;
vll ret;


void init(ll n){
  graph.resize(n);
  indeg.resize(n,0);
  seen.resize(n,0);
  ret.resize(0);
}

void bfs(ll s){
  queue<ll> que;
  que.push(s);
  seen[s] = 1;

  while(!que.empty()){
    ll u = que.front(); que.pop();
    ret.push_back(u);
    for(ll i=0;i<graph[u].size();i++){
      ll v = graph[u][i];
      indeg[v]--;
      if(indeg[v] == 0 && seen[v] == 0){
        seen[v] = 1;
        que.push(v);
      }
    }
  }
}

void T_sort(ll n){
  for(ll i=0;i<n;i++){
    for(ll j=0;j<graph[i].size();j++){
      ll v = graph[i][j];
      indeg[v]++;
    }
  }
  for(ll i=0;i<n;i++){
    if(indeg[i] == 0 && seen[i] == 0){
      bfs(i);
    }
  }
}

ll dp[100000+10];

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, m;
  cin >> n >> m;
  init(n);
  REP(i,m){
    ll x, y;
    cin >> x >> y;
    graph[x-1].push_back(y-1);
  }
  T_sort(n);
  REP(i,n) dp[i] = 0;

  for(ll i=0;i<n;i++){
    ll u = ret[i];
    for(ll j=0;j<graph[u].size();j++){
      ll v = graph[u][j];
      dp[v] = max(dp[v],dp[u]+1);
    }
  }

  ll ans = 0;
  REP(i,n) ans = max(ans,dp[i]);
  cout << ans <<endl;
    
    
  return 0;
}



Measured memory_bytes: 11728
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
int w, h, k, dis[808][808];
pair < int , int > d[4] = {{1 , 0} , {-1 , 0} , {0 , 1} , {0 , -1}};
bool mark[808][808];
char a[808][808];
queue < pii > q;
bool isval(int x , int y){
	return (x >= 0 && x < w && y >= 0 && y < h && !mark[x][y] && a[x][y] != '#');
}
void bfs(){
	while(sz(q)){
		auto v = q.front();
		q.pop();
		for(int i = 0; i < 4; i++){
			int x = v.f + d[i].f , y = v.s + d[i].s;
			if(isval(x , y)){
				dis[x][y] = dis[v.f][v.s] + 1;
				q.push({x , y});
				mark[x][y] = 1;
			}
		}
	}
	return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	cin >> w >> h >> k;
	int xs, ys;
	for(int i = 0; i < w; i++)
		for(int j = 0; j < h; j++){
			cin >> a[i][j];
			if(a[i][j] == 'S')
				xs = i, ys = j;
		}
	memset(dis , 63 , sizeof dis);
	dis[xs][ys] = 0;
	mark[xs][ys] = 1;
	q.push({xs , ys});
	bfs();
	int mini , ans = INT_MAX;
	for(int i = 0; i < w; i++)
		for(int j = 0; j < h; j++)
			if(dis[i][j] <= k){
				mini = min(min(i , j) , min(w - i - 1, h - j - 1));
				ans = min(ans , 1 + (mini + k - 1) / k);
			}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
int a[100005];
int ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++){
        if(i==a[a[i]]){
            ans++;
        }
    }
    cout<<ans/2<<endl;

}



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

int main(){
  int n;
  vector<string> names;
  vector<int> nums;
  cin >> n;
  for(int i = 0; i < n; i++){
    string name;
    int num;
    bool f = false;
    cin >> name >> num;
    for(int i = 0; i < names.size(); i++){
      if(name == names[i]){
        nums[i] += num;
        f = true;
      }
    }
    if(!f){
      names.push_back(name);
      nums.push_back(num);
    }
  }
  string sbuf;
  int ibuf;
  for(int i = 0; i < names.size(); i++){
    for(int j = i + 1; j < names.size(); j++){
      bool change = false;
      if(names[i].size() > names[j].size()) change = true;
      else if(names[i].size() == names[j].size() && names[i] > names[j]) change = true;
      if(change){
       sbuf = names[i];
        names[i] = names[j];
        names[j] = sbuf;
        ibuf = nums[i];
        nums[i] = nums[j];
        nums[j] = ibuf;
      }
    }
  }

  for(int i= 0; i < names.size(); i++){
    cout << names[i] << " " << nums[i] << endl;
  }
  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    set<string> s[5];
    int a[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
    int b[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
    int c[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
    rep(i, n)
    {

        string t;
        cin >> t;
        if (t[0] == 'M')
            s[0].insert(t);
        if (t[0] == 'A')
            s[1].insert(t);
        if (t[0] == 'R')
            s[2].insert(t);
        if (t[0] == 'C')
            s[3].insert(t);
        if (t[0] == 'H')
            s[4].insert(t);
    }
    ll d[5];
    rep(i, 5) d[i] = s[i].size();

    ll sum = 0;
    rep(i, 10) sum += d[a[i]] * d[b[i]] * d[c[i]];

    OP(sum);

    return 0;
}

Measured memory_bytes: 9600
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld ans=0,cou=0;
lld n;
lld pre[21][21],pre1[22][22];
lld dp[22][1<<21];
vector<lld> ma[22];
lld bits(lld n)
{
    lld cou=0;
    while(n)
    {
        cou+=(n&1);
        n=n>>1;
    }
    return cou;
}
lld rec(lld man,lld mask)
{
    if(mask==0&&man==-1)
    {
        return 1;
    }
    if(dp[man][mask]!=-1)
        return dp[man][mask];
    lld ans=0;
    rep(j,0,n-1)
    {
       if((pre[man][j])&&(mask&(1<<j)))
       {
           ans=(ans+(rec(man-1,mask^(1<<j))))%mod;
          // cout<<mask<<"  "<<i<<" "<<j<<" "<<ans<<endl;
       }
    }
    return dp[man][mask]=ans;//dp[mask]=ans;
}
int main()
{
     ios;
     cin>>n;
     memset(dp,0,sizeof(dp));
     rep(i,0,n-1)
     {
         rep(j,0,n-1)
            {
                cin>>pre[i][j];
                pre1[i+1][j]=pre[i][j];
            }
     }
     //ans=rec(n-1,(1<<n)-1);
     //cout<<ans<<endl;
     dp[0][0]=1;
     rep(i,1,(1<<n)-1)
     {
         ma[bits(i)].pb(i);
     }
     rep(i,1,n)
     {
         for(auto mask:ma[i])
         {
             rep(k,0,n-1)
             {
                if((pre1[i][k])&&((mask&(1<<k))))
                {
                    dp[i][mask]=(dp[i-1][mask^(1<<k)]+dp[i][mask])%mod;

                }
             }
             //cout<<i<<" "<<mask<<" "<<dp[i][mask]<<endl;
         }
     }
     cout<<dp[n][(1<<(n))-1]<<endl;
    return 0;
}


Measured memory_bytes: 385316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int f(int n){
    if(n%2) return 3*n+1;
    else return n/2;
}
int main(){
    string s;
    cin >> s;
    int m = 999;
    int num;
    int ans;
    for(int i = 2; i < sz(s); i++){
        string a = "";
        a += s[i-2];
        a += s[i-1];
        a += s[i];
        num = stoi(a);
        ans = abs(num - 753);
        if(m > ans) m = ans;
    }
    cout << m << endl;
    return 0;
}

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

int main() {
	// your code goes here
	long n, W;
	cin>>n>>W;
	long w[n+1];
	long  v[n+1];
	for(long i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	long dp[n+1][W+1];
	memset(dp, 0, sizeof(dp));
	for(long i=1;i<=n;i++) {
		for(long j=1;j<=W;j++) {
			if(j-w[i] >=0 ){
				dp[i][j] = max((dp[i-1][j-w[i]] + v[i]), dp[i-1][j]);
			}else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	long ans = -1;
	for(long i=0;i<=W;i++){
		ans = max(ans, dp[n][i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

typedef string::const_iterator State;
string s;
ll t[4];

ll has(State &begin);
ll let(State &begin){
    if(*begin=='a'){begin++;
        return t[0];
    }else if(*begin=='b'){begin++;
        return t[1];
    }
    ll k=*begin-'a';
    begin++;
    return t[k];
}
string ope="+*^";
ll has(State &begin){
    if(*begin=='['){
        begin++;
        ll op=-1;
        rep(i,0,2)if(*begin==ope[i])op=i;
        begin++;
        ll a=has(begin);
        ll b=has(begin);
        begin++;
        if(op==0){
            return a|b;
        }else if(op==1){
            return a&b;
        }else{
            return a^b;
        }
    }else{
        return let(begin);
    }
}

int main(){fastio
    
    while(1){
        cin>>s;
        if(s[0]=='.')break;
        ll ans[10000];memset(ans,-1,sizeof(ans));
        
        rep(i,0,9999){
            State begin=s.begin();
            ll ni=i;
            for(ll j=3;j>=0;j--){
                t[j]=ni%10;
                ni/=10;
            }
            ans[i]=has(begin);
        }
        
        ll k;cin>>k;
        ll p=ans[k];
        ll c=0;rep(i,0,9999)if(ans[i]==p)c++;
        cout<<p<<" "<<c<<endl;
    }
    return 0;
}



Measured memory_bytes: 3196
N, M, K = map(int, input().split())
ans = -1
for i in range(N + 1):
    for j in range(M + 1):
        if K == M * i + N * j - i * j * 2:
            ans = 1
            break
if ans == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
n, u, v = gets.split.map(&:to_i)

edge = Array.new(n+1){[]}
(n-1).times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

aoki = Array.new(n+1)
aoki[v] = 0
que = [v]
while x = que.shift
    edge[x].each do |y|
        next if aoki[y]
        aoki[y] = aoki[x] + 1
        que << y
    end
end

taka = Array.new(n+1)
taka[u] = 0
que = [u]
node = []
while x = que.shift
    if edge[x].size == 1
        node << x
    end

    edge[x].each do |y|
        next if taka[y] || taka[x] + 1 >= aoki[y]
        taka[y] = taka[x] + 1
        que << y
    end
end

puts aoki[node.max_by{|e| aoki[e]}] - 1

Measured memory_bytes: 13572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    const int c = 1e6+1;
    int flag[c];
    bool f[c];
    for(int i=0; i<c; i++)
    {
        flag[i] = 0;
        f[i] = false;
    }
    vector<int> v;
    for(int i=0; i<n; i++)
    {
        int y;
        cin>>y;
        flag[y] += 1;
        v.push_back(y);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i=0; i<n; i++)
    {
        // for(int j = v[i]; j<=1e6; j*=)
        // cout<<"vector ith pos = "<<v[i]<<'\n';
        int mult = 1;
        int j = v[i]*mult;
        if(f[j]==false)
        {
            while(j<=1e6)
            {
                // cout<<"multiple of v[i] = "<<j<<" "<<flag[j]<<'\n';
                if(j==v[i] and flag[j]>1)
                {
                    f[j] = true;
                    // break;
                }
                else if(j!=v[i] && flag[j])
                {
                    f[j] = true;
                    // break;
                }
                mult += 1;
                j = v[i]*mult;
            }
        }
    }
    for(int i=0; i<n; i++)
    {
        if(f[v[i]]==false)
        {
            ans +=1;
        }
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 9120
#include<iostream>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<cmath>
#define N 1000
using namespace std;
int n,C[N],tans;


int ans(int i,int A,int B)
{
  if(i == n)
    {
      tans = min(tans,abs(A-B)); 
    }
  else
    {
      ans(i+1,A+C[i],B);
      ans(i+1,A,B+C[i]);
    }

  return tans;

}


int main()
{
  while(1)
    {
      cin >> n;
      if(n == 0)break;
      for(int i=0;i<n;i++)
	{
	  cin >> C[i];
	}
       tans = INT_MAX;
      cout << ans(0,0,0) << endl;

    }



}

Measured memory_bytes: 0