akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.algorithm;
import std.range;
import std.typecons;

void main(){
    int h, w;
    while(~scanf("%d%d", &h, &w)){
        auto g = new int[][](h, w);
        alias Tuple!(int,int,int) idx;
        idx[] ds;
        foreach(i; 0..h){
            foreach(j; 0..w){
                scanf("%d", &g[i][j]);
                ds ~= idx(g[i][j], i, j);
            }
        }
        sort(ds);

        auto to = new int[][](h, w);
        foreach(r; to) r[] = -1;

        int ans = 0;
        foreach(t; ds){
            int i = t[1], j = t[2];
            int[] s = [];
            foreach(d; [[0,1],[0,-1],[1,0],[-1,0]]){
                int ni = i + d[0];
                int nj = j + d[1];
                if(0 <= ni && ni < h && 0 <= nj && nj < w){
                    if(g[ni][nj] < g[i][j]){
                        s ~= to[ni][nj];
                    }
                }
            }
            s = uniq(sort(s)).array;
            if(s.length == 0){
                to[i][j] = g[i][j];
            } else if(s.canFind(-10)){
                to[i][j] = -10;
            } else {
                to[i][j] = s.length == 1 ? s[0] : -10;
            }
            ans += to[i][j] == -10;
        }
        writeln(ans);
    }
}

Measured memory_bytes: 26188
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int l;
    cin >> l;

    int n = __lg(l) + 1;
    vector<pair<pii, int>> ans;
    vector<int> ans2;
    int t = l;
    for(int i = 1; i < n; i++){
//        cerr << i << " " << t << "\n";
        if(t % 2) ans2.eb(i), t--;
        ans.eb(mp(mp(i, i + 1), 1 << (i - 1)));
        ans.eb(mp(mp(i, i + 1), 0));
        t /= 2;
    }

    t = 1 << (n - 1);
    for(int i : ans2){
        ans.eb(mp(mp(i, n), t));
        t += 1 << (i - 1);
    }

    cout << n << " " << ans.size() << "\n";
    for(auto i : ans){
        cout << i.F.F << " " << i.F.S << " " << i.S << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;

    int ab = (s[0]-'0') * 10 + (s[1]-'0');
    int cd = (s[2]-'0') * 10 + (s[3]-'0');

    if(1 <= ab && ab <= 12){
        if(1 <= cd && cd <= 12) cout << "AMBIGUOUS" << endl;
        else if(0 <= cd) cout << "MMYY" << endl;
    }
    else if(0 <= ab){
        if(1 <= cd && cd <= 12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

const int MAXN = 100010;

int n;
vector<int> g[100010];

int zeit, dis[MAXN], fin[MAXN], low[MAXN], par[MAXN], dep[MAXN];
int kodat[MAXN], koptr[MAXN + 1];
void dfsInfo(int u,int oy,int d){
	dis[u] = low[u] = zeit++; par[u] = oy; dep[u] = d;
	int v;
	rep(i,sz(g[u])) if((v = g[u][i]) != oy){
		if(!~dis[v]){
			dfsInfo(v, u, d + 1);
			low[u] = min(low[u], low[v]);
		} else {
			low[u] = min(low[u], dis[v]);
		}
	}
	fin[u] = zeit++;
}

void dfsInfos(){
	memset(dis, ~0, n*4); zeit = 0;
	rep(u,n) if(!~dis[u]) dfsInfo(u, -1, 0);
	rep(u,n){
		int &j = koptr[u + 1] = koptr[u];
		rep(i,sz(g[u])) if(u == par[g[u][i]]) kodat[j++] = g[u][i];
	}
}

bool produce(int u,int v){
	return (dis[u] <= dis[v] && fin[u] >= fin[v]);
}

int related(int u,int v){
	int s = koptr[u], e = koptr[u+1], h;
	while(s+1 < e){
		h = (s + e) >> 1;
		(dis[kodat[h]] <= dis[v]) ? s = h : e = h;
	}
	return kodat[s];
}

bool isBridge(int u,int v){
	if(dis[u] > dis[v]) swap(u, v);
	return (u == par[v] && dis[v] <= low[v]);
}

int Count[MAXN];

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

	int m;
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	rep(i,n)sort(g[i].begin(),g[i].end());
	dfsInfos();
	Count[0] = -1;
	rep(i,n)rep2(j,koptr[i],koptr[i+1]){
		Count[i] += dis[i] <= low[kodat[j]];
	}
	rep(i,n){
		if(Count[i] > 0)cout<<i<<endl;
	}
	//rep(i,n)cout<<Count[i]<<" ";cout<<endl;
}

Measured memory_bytes: 6356
#include<stdio.h>
  int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a<=b)&&(b<=c)){
        printf("%d %d %d\n",a,b,c);
    }
    else if((a<=c)&&(c<=b)){
        printf("%d %d %d\n",a,c,b);
    }
    else if((b<=a)&&(a<=c)){
        printf("%d %d %d\n",b,a,c);
    }
    else if((b<=c)&&(c<=a)){
        printf("%d %d %d\n",b,c,a);
    }
    else if((c<=a)&&(a<=b)){
        printf("%d %d %d\n",c,a,b);
    }
    else{
        printf("%d %d %d\n",c,b,a);
    }


    return 0;
    }

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (int)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;

#define MAX 100001

ll a[2][100],n,dp[100][MAX],w;

int main(void){
    cin>>n>>w;
    w++;
    rep(i,n)rep(j,2)cin>>a[j][i];
    rep(i,w-a[0][0])dp[0][a[0][0]+i]=a[1][0];
    rep(i,n-1)rep(j,w){
        if(j-a[0][i+1]<0){dp[i+1][j]=dp[i][j];continue;}
        dp[i+1][j]=max(dp[i][j],dp[i][j-a[0][i+1]]+a[1][i+1]);
    }
    cout<<dp[n-1][w-1]<<endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll mypow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = mypow(a, n/2);
    return res * res;
  }
  return a * mypow(a, n-1);
}

int main(){
  int d, n;
  cin >> d >> n;
  if(n == 100) n++;
  int ans = mypow(100, d) * n;
  cout << ans << endl;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int A, B, a[5001], b[5001];

int main(){
  scanf("%d%d", &A, &B);

  rep(i, A) scanf("%d", a+i);
  rep(i, B) scanf("%d", b+i);
  int res = 0;
  rep(i, B){
    int c = 0, p = 0;
    while(1){
      a[A] = b[i+c];
      while(b[i+c] != a[p]) p++;
      if(p == A) break;
      c++;
      p++;
    }
    res = max(res, c);
  }
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k<=a){
    cout << k << endl;
    exit(0);
  }
  if(k<=a+b){
    cout << a << endl;
    exit(0);
  }
  
  cout << 2*a+b-k << endl;
}

Measured memory_bytes: 3636
package main

import "fmt"

type graph [][]int

func combine(g graph) {
	for i := 1; i < len(g); i++ {
		for j := i + 1; j < len(g); j++ {
			if !contain(j, g[i]) {
				g[i] = append(g[i], j)
				g[j] = append(g[j], i)
				return
			}
		}
	}
}

func contain(n int, s []int) bool {
	for _, v := range s {
		if v == n {
			return true
		}
	}
	return false
}

func glen(g graph) int {
	ans := 0
	for i := 0; i < len(g); i++ {
		for j := 0; j < len(g[i]); j++ {
			if g[i][j] > i {
				ans++
			}
		}
	}
	return ans
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	if k > (n-1)*(n-2)/2 {
		fmt.Println(-1)
		return
	}

	g := make(graph, n)
	for i := 1; i < n; i++ {
		g[0] = append(g[0], i)
		g[i] = append(g[i], 0)
	}
	for i := 0; i < (n-1)*(n-2)/2-k; i++ {
		combine(g)
	}

	fmt.Println(glen(g))
	for i := 0; i < n; i++ {
		for j := 0; j < len(g[i]); j++ {
			if i+1 < g[i][j]+1 {
				fmt.Println(i+1, g[i][j]+1)
			}
		}
	}
}


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


int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;

  long long ans = 0;
  if (K <= A) {
    cout << K << endl;
    return 0;
  }

  ans += A;

  if (K - A <= B) {
    cout << ans << endl;
    return 0;
  }

  ans -= K - A - B;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	int ans = 1, ac = 0;
	for (int i = 1; i <= N; i++)
	{
		int I = i;
		int cnt = 0;
		while (I % 2 == 0 && I > 1)
		{
			I /= 2;
			cnt++;
		}
		if (ac < cnt)
		{
			ac = cnt;
			ans = i;
		}
	}
	cout << ans << endl;
}



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

int main()
{
  int n;
  cin >> n;
  string S[50];
  for(int i = 0; i < n; i++) cin >> S[i];
  for(char c = 'a'; c <= 'z'; c++){
    int m = 100;
    for(int i = 0; i < n; i++)
      m = min(m,(int)count(begin(S[i]),end(S[i]),c));
    for(int i = 0; i < m; i++) cout << c;
  }
  cout << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>

using namespace std;


double pi = 3.141592653532384626;

int main()
{
    int a, b, h, m;
    double kakudo;
    cin >> a >> b >> h >> m;

    kakudo = min(abs(double(6 * m) - (double((h % 12) * 30) + (double)m * 0.5)), 360 - abs(double(6 * m) - (double((h % 12) * 30) + (double)m * 0.5)));


    double answer = double(a * a) + double(b * b) - 2 * double(a) * double(b) * cos(kakudo * pi / 180);

    cout << setprecision(11) << sqrt(answer) << endl;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int, int>> x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i].first;
		x[i].second = i;
	}
	sort(x.begin(), x.end());
	vector<int> y(n);
	for (int i = 0; i < n; i++)
		y[x[i].second] = i;
	for (auto&& yi : y)
		cout << x[n-1-max(n/2-1, min(n/2, yi))].first << '\n';
	return 0;
}


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

int N, A, B, C;
vector<int> l;

int dfs(int a, int b, int c, int i){
 if(i == N){//末端まで探索した時の処理
   if(a == 0 || b == 0 || c == 0) return 1000000;
   return abs(a - A) + abs(b - B) + abs(c - C) - 30;
 }
 //再帰
 int choose_A = dfs(a + l[i], b, c, i + 1) + 10;
 int choose_B = dfs(a, b + l[i], c, i + 1) + 10;
 int choose_C = dfs(a, b, c + l[i], i + 1) + 10;
 int choose_none = dfs(a, b, c, i + 1);
 return min({choose_A, choose_B, choose_C, choose_none});
}

int main(){
 cin >> N >> A >> B >> C;
 l.resize(N);
 for(int i = 0; i < N; ++i)cin >> l[i];
 cout << dfs(0, 0, 0, 0) << endl;
 return 0;
}

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

int n,m;
vector<int> c;
int dp[50001][20];
void sortt(){
	sort(c.begin(),c.end());
	reverse(c.begin(),c.end());
}

void ume(){

	for(int i=0;i<20;++i){
		dp[0][i]=0;
		for(int j=1;j<50001;++j){
			dp[j][i]=100000;
		}
	}
}
void toku(){
	for(int i=1;i<n+1;++i){//??????
		for(int j=0;j<m;++j){//?????¨???????????????
			if(i-c[j]>=0){
				dp[i][j]=dp[i-c[j]][j]+1;
			}
			if(j!=0){

				dp[i][j]=min(dp[i][j],dp[i][j-1]);
			}

		}
	}
}


int main(){
	
	cin>>n>>m;
	
	for(int i=0;i<m;++i){
		int a;
		cin>>a;
		c.emplace_back(a);


	}
	sortt();
	ume();
	toku();

	

	cout<<dp[n][m-1]<<endl;
}

Measured memory_bytes: 5124
from collections import Counter
from scipy.misc import comb

N, M=list(map(int, input().split()))
A=list(map(int, input().split()))

B=[0]
tmp=0
for i in A:
    tmp+=i
    B.append(tmp)
C=[]
for i in B:
    C.append(i%M)
X=Counter(C)
ans=0
for i in X.values():
    ans+=comb(i, 2, 1)
print(ans)


Measured memory_bytes: 29372
#include<iostream>
#include<cstdio>
using namespace std;
int n,ccnt,sum,m;
int fir[1010],to[2020],nxt[2020],fa[1010],dep[1010];
int Lca[101][101],u[101],v[101],cnt[101];
long long f2[1010];
void add(int x,int y)
{
	nxt[++ccnt]=fir[x];fir[x]=ccnt;to[ccnt]=y;
}
void dfs(int x)
{
	dep[x]=dep[fa[x]]+1;
	for(int i=fir[x];i;i=nxt[i])
		if(to[i]!=fa[x])
		{
			fa[to[i]]=x;
			dfs(to[i]);
		}
}
void calc(int x)
{
	for(int i=fir[x];i;i=nxt[i])
		if(to[i]!=fa[x])
		{
			calc(to[i]);
			cnt[x]+=cnt[to[i]];
		}
	if(cnt[x]>0) sum++;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1);
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
		{
			int x=i,y=j;
			if(dep[x]<dep[y]) swap(x,y);
			while(dep[x]>dep[y]) x=fa[x];
			while(x!=y) x=fa[x],y=fa[y];
			Lca[i][j]=Lca[j][i]=x;
		}
	scanf("%d",&m);
	for(int i=1;i<=m;i++) scanf("%d%d",&u[i],&v[i]);
	f2[0]=1;
	for(int i=1;i<=n;i++) f2[i]=f2[i-1]<<1;
	long long ans=0;
	for(int i=0;i<(1<<m);i++)
	{
		long long fl=1;
		for(int j=1;j<=m;j++)
			if((i>>(j-1))&1)
				cnt[u[j]]++,cnt[v[j]]++,cnt[Lca[u[j]][v[j]]]-=2,fl=-fl;
		sum=0;
		calc(1);
		ans+=fl*f2[n-1-sum];
		for(int j=1;j<=n;j++) cnt[j]=0;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  ll x, y;
  cin >> x >> y;
  if( (4 * x - y) < 0 or (4* x - y) % 2 or ((4* x - y) / 2) > x)cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cstdio>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL int
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
#define MAXN 100
#define INF 0x3f3f3f3f
int f[MAXN+5][MAXN+5];
char S[MAXN+5][MAXN+5];
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++)
		scanf("%s",S[i]+1);
	memset(f,0x3f,sizeof(f));
	f[1][1]=(S[1][1]=='#');
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(i==1&&j==1)
				continue;
			if(i>1){
				if(S[i][j]=='#'&&S[i-1][j]=='.')
					f[i][j]=min(f[i][j],f[i-1][j]+1);
				else
					f[i][j]=min(f[i][j],f[i-1][j]);
			}
			if(j>1){
				if(S[i][j]=='#'&&S[i][j-1]=='.')
					f[i][j]=min(f[i][j],f[i][j-1]+1);
				else
					f[i][j]=min(f[i][j],f[i][j-1]);
			}
		}
	printf("%d\n",f[n][m]);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {

  int N,K;
  cin >> N >> K;

  int pattern = 0;

  for(int l = 1; l <= N; l++) {
    if( l + (K-1) <= N ) {
      pattern++;
    } 
  }

  cout << pattern << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

N, W = map(int, sys.stdin.readline().strip().split())

weights = []
for _ in range(N):
    v, w = map(int, sys.stdin.readline().strip().split())
    weights.append((v, w))

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
# print(dp)

for i in range(0, N):
    v, w = weights[i]
    for j in range(W+1):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j - w >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w] + v)

# print(dp)
print(max(dp[N]))


Measured memory_bytes: 25952
#include<stdio.h>

int main() {
    int h1, m1, h2, m2, k, delta;
    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
    delta = (h2 - h1)*60 + (m2 - m1) - k;
    printf("%d", delta);
}

Measured memory_bytes: 1728
import sys

l = []
keys = ['S','H','C','D']
dicts = {}
for i in sys.stdin:
    l.append(i)

for i in range(1,len(l)):
    l[i] = l[i].split()

for i in range(1,len(l)):
    if l[i][0] not in dicts:
        a = []
        a.append(int(l[i][1]))
        dicts[l[i][0]] = a
    else:
        dicts[l[i][0]].append(int(l[i][1]))

for key in dicts:
    dicts[key] = sorted(dicts[key])

for data in keys:
    for j in range(1,14):
        if j not in dicts[data]:
            print(data,j)


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

using namespace std;

template <class T> inline bool chmin(T &a, T b) { /* {{{ */
  if (a > b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  vector<vector<int>> dp(N + 1, vector<int>(H + 1, 1e9));
  dp[0][0] = 0;
  for (int j = 1; j <= A[0]; j++) {
    if (j <= H) {
      dp[0][j] = B[0];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= H; j++) {
      chmin(dp[i + 1][j], dp[i][j]);
      int v = dp[i][j] + B[i];
      if (j + A[i] < H) {
        chmin(dp[i][j + A[i]], v);
        chmin(dp[i + 1][j + A[i]], v);
      } else {
        chmin(dp[i][H], v);
        chmin(dp[i + 1][H], v);
      }
    }
  }
  cout << dp[N][H] << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 39424
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		int C=stdIn.nextInt();
		int D=stdIn.nextInt();
		while(true){
			C-=B;
			if(C<=0){
				System.out.println("Yes");
				System.exit(0);
			}
			A-=D;
			if(A<=0){
				System.out.println("No");
				System.exit(0);
			}
		}
	}
}


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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

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

int main() {
  string S;
  cin >> S;

  ll sum = 0;
  loop(0, S.size(), i) {
    sum += (int)(S[i] - '0');
  }

  if (sum % 9 == 0) {
    print("Yes");
  } else {
    print("No");
  }
}

Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int a[100000];

int exhaustive_search(int n, int i,int key,int all) {
	if (all == key) return 1;
	if (i == n) return 0;
	if (exhaustive_search(n, i + 1, key, all + a[i]))return 1;
	if (exhaustive_search(n, i + 1, key, all))return 1;
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int key;
		cin >> key;
		if (exhaustive_search(n, 0, key,0))cout << "yes" << endl;
		else cout << "no" << endl;
	}
}


Measured memory_bytes: 3100
N=int(input())
SP=[list(map(str, input().split())) for _ in range(N)]
for i in range(N):
    SP[i].append(i+1)
    SP[i][1]=int(SP[i][1])*-1#2列目を降順ソートさせるため、正負をひっくり返す
#print(SP)
SP.sort()#1列目が同じ場合、2列目を基準にソートされる
#print(SP)
for i in range(N):
    print(SP[i][2])


Measured memory_bytes: 3060
#include <stdio.h>

int ReadValue() {
    int value; 
    scanf("%d",&value);
    return value;
}
int GCD(int x,int y) {
    if (x<y) { 
        int temp=x;
        x=y;
        y=temp;
    } 
    if (x%y==0) {
        return y;
    }
    return GCD(y,x%y);
}
void Display(int x,int y) {
    printf("%d\n",GCD(x,y));
}
int main() {
    int x=ReadValue();
    int y=ReadValue();
    Display(x,y);
    return 0;
}



Measured memory_bytes: 2140
// B - Tap Dance

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

bool check(string S) {
	for (int i=0; i<S.size(); i+=2) {
		char s = S[i];
		if (!(s == 'R' || s == 'U' || s == 'D')) return false;
	}

	for (int i=1; i<S.size(); i+=2) {
		char s = S[i];
		if (!(s == 'L' || s == 'U' || s == 'D')) return false;
	}

	return true;
}

int main(){
	string S;
	cin >> S;

	string ans;
	if (check(S)) ans = "Yes";
	else ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string S; cin>>S;
    sort(S.begin(), S.end());
 
    if(S[0]==S[1] && S[2]==S[3] && S[0] != S[2]){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3580
H, W = map(int, input().split())
li = [input() for i in range(H)]
buf = ""
for h in range(H) :
    if h == 0 :
        for w in range(W + 2) :
            buf += "#" 
        print(buf)
    print("#" + li[h] + "#")
    if h == H - 1 :
        print(buf)


Measured memory_bytes: 3060
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

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


class SegmentTree:

    def __init__(self, array, operator, identity):
        self.identity = identity
        self.operator = operator

        self.array_size = len(array)
        self.tree_height = (self.array_size - 1).bit_length()
        self.tree_size = 2 ** (self.tree_height + 1)
        self.leaf_start_index = 2 ** self.tree_height
        self.tree = [self.identity] * self.tree_size

        for i in range(self.array_size):
            x = 1 << (ord(array[i]) - 96)
            self.tree[self.leaf_start_index + i] = x

        for i in range(self.leaf_start_index - 1, 0, -1):
            self.tree[i] = self.operator(self.tree[i << 1], self.tree[i << 1 | 1])

    def update(self, index, val):
        x = 1 << (ord(val) - 96)

        cur_node = self.leaf_start_index + index
        self.tree[cur_node] = x

        while cur_node > 1:
            self.tree[cur_node >> 1] = self.operator(self.tree[cur_node], self.tree[cur_node ^ 1])
            cur_node >>= 1

    def query(self, begin, end):
        if begin < 0:
            begin = 0
        elif begin > self.array_size:
            return self.identity
        if end > self.array_size:
            end = self.array_size
        elif end < 1:
            return self.identity

        res = self.identity

        left = begin + self.leaf_start_index
        right = end + self.leaf_start_index

        while left < right:
            if left & 1:
                res = self.operator(res, self.tree[left])
                left += 1

            if right & 1:
                right -= 1
                res = self.operator(res, self.tree[right])

            left >>= 1
            right >>= 1

        return res


def main():
    from operator import or_
    n = int(input())
    s = input()
    q = int(input())

    seg = SegmentTree(s, or_, 0)

    for i in range(q):
        q1, q2, q3 = readline().split()
        q1, q2 = int(q1), int(q2)
        if q1 == 1:
            seg.update(q2-1, q3.rstrip("\n"))
        else:
            q3 = int(q3)
            print(bin(seg.query(q2-1, q3)).count("1"))


if __name__ == '__main__':
    main()


Measured memory_bytes: 67016
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222





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


  ll a, b, c;
  cin >> a >> b >> c;
  ans = b;
  if (c <= a + b + 1) ans += c;
  else ans += a + b + 1;
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define f first 
# define s second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;

const int inf=1e9,mod=1e9+7,N=2e5+5;

void solve(){
	int n;
	cin>>n;
	vector<int>a(n+1),b(n);
	rep(i,n+1){
		cin>>a[i];
	}
	ll ans=0;
	rep(i,n){
		cin>>b[i];
	}
	rep(i,n){
		if(a[i]>=b[i]){
			ans+=b[i];
		}
		else{
			ans+=a[i];
			int x=a[i+1];
			a[i+1]=max(0,a[i+1]-(b[i]-a[i]));
			ans+=x-a[i+1];
		}
	}
	cout<<ans;

}

int main(){
 	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)solve();
}

Measured memory_bytes: 3876
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char arr[100];
int main(){
	scanf("%s",&arr);
	if(arr[0]=='S'){
		printf("Cloudy");
	}else if(arr[0]=='R'){
		printf("Sunny");
	}else if(arr[0]=='C'){
		printf("Rainy");
	}
	
	return 0;
} 

Measured memory_bytes: 256
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**15
mod = 10**9+7

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():
    t = int(''.join(LS()))
    s = int(t ** 0.5)
    for i in range(s-1,s+2):
        if i**2 == t:
            return 'Yes'

    return 'No'



print(main())




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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;


int N, K;
vector<int> G[2005];

int f(int s) {
    map<int, int> dmap;
    dmap[s] = 0;

    queue<int> q;
    q.push(s);
    while (!q.empty()) {
        int t = q.front();
        q.pop();
        REP(i, G[t].size()) {
            int k = G[t][i];
            if (dmap.count(k) > 0) continue;
            dmap[k] = dmap[t] + 1;
            q.push(k);
        }
    }

    int res = 0;
    for (auto kv : dmap) {
        if (kv.second > K / 2) res++;
    }

    return res;
}

int g(pair<int, int> s) {
    map<int, int> dmap;
    dmap[s.first] = 0;
    dmap[s.second] = 0;

    queue<int> q;
    q.push(s.first);
    q.push(s.second);
    while (!q.empty()) {
        int t = q.front();
        q.pop();
        REP(i, G[t].size()) {
            int k = G[t][i];
            if (dmap.count(k) > 0) continue;
            dmap[k] = dmap[t] + 1;
            q.push(k);
        }
    }

    int res = 0;
    for (auto kv : dmap) {
        if (kv.second > (K - 1) / 2) res++;
    }

    return res;


}


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> N >> K;

    vector<pair<int, int>> edge;
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge.push_back({a, b});
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = INF;
    if (K % 2 == 0) {
        REP(i, N) {
            ans = min(ans, f(i));
        }
    } else {
        REP(i, edge.size()) {
            ans = min(ans, g(edge[i]));
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
  }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N%2==1){
    cout << B.at((N-1)/2)-A.at((N-1)/2)+1 << endl;
  }else{
    cout << (B.at(N/2-1)+B.at(N/2)-A.at(N/2-1)-A.at(N/2))+1 << endl;
  }

}


Measured memory_bytes: 4840
// https://atcoder.jp/contests/abc143/tasks/abc143_c

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll N;
  cin >> N;
  string S;
  cin >> S;

  ll res = 0;

  char prev = S[0];
  res = 1;

  rep(i, 1, N) {
    if (S[i] != prev) {
      res++;
    }

    prev = S[i];
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,k,a[MAXN];
ll pow_mod(ll a,ll i)
{
	ll s=1;
	while(i)
	{
		if(i&1) s=s*a%MOD;
		a=a*a%MOD;
		i>>=1;
	}
	return s;
}
int main()
{
	scanf("%lld",&n);
	if(n==2)
	{
		puts("1");
		return 0;
	}
	ll ans=0;
	if(n&1)
	{
		ll st=3,mult=((n+1)*(n+3)/8)%MOD,addn=7,adds=n/2+2,last=0;
		ll init=2,cf=6,add=6;
		for(ll i=5;i<=n;i+=2)
		{
			init=init*cf%MOD;
			cf=(cf+add)%MOD;
			add=add+2;
		}
		//printf("%lld\n",init);
		ans+=init*((n+1)/2)%MOD;
		last=init;
		for(ll i=(n+1)/2+1;i<=n-1;i++)
		{
			init=init*mult%MOD*pow_mod(st,MOD-2)%MOD;
			//printf("%lld\n",init);
			mult=(mult+adds)%MOD;
			st=(st+addn)%MOD;
			adds++;
			addn+=4;
			ans=(ans+(init-last+MOD)*i)%MOD;
			last=init;
		}
		printf("%lld\n",ans);
	}
	else
	{
		ll st=1,mult=(n*(n+2)/8)%MOD,addn=5,adds=n/2+1,last=0;
		ll init=2,cf=6,add=6;
		for(ll i=6;i<=n;i+=2)
		{
			init=init*cf%MOD;
			cf=(cf+add)%MOD;
			add+=2;
		}
		//printf("%lld\n",init);
		ans+=init*(n/2)%MOD;
		last=init;
		for(ll i=n/2+1;i<=n-1;i++)
		{
			init=init*mult%MOD*pow_mod(st,MOD-2)%MOD;
			//printf("%lld\n",init);
			mult=(mult+adds)%MOD;
			st=(st+addn)%MOD;
			adds++;
			addn+=4;
			ans=(ans+(init-last+MOD)*i)%MOD;
			last=init;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input){
    const S = input.trim();
    const dfs = (t, i) => {
        if(i==S.length-1)
            return t.split("+").map((x) => Number(x)).reduce((a,b) => Number(a)+Number(b));
        return  dfs(t+S[i+1], i+1) + dfs(t+"+"+S[i+1], i+1);
    }
    console.log(dfs(S[0],0));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// https://teratail.com/questions/272708


Measured memory_bytes: 29720
import java.util.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }


fun main(args: Array<String>) {
    val K = readInt()
    val (A, B) = readListInt()

    val ans = if ((B/K - (A-1)/K) > 0) "OK" else "NG"
    println(ans)
}


Measured memory_bytes: 36440
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 1e5+5;
int a[MXN][4], dp[MXN][4];
int N;

int rec(int pos, int type){

    if(pos>N) return 0;

    if(dp[pos][type]!=-1) return dp[pos][type];

    int ret = -1;
    for(int i=1; i<=3; i++)
        if(i!=type)
            ret = max (ret, rec(pos+1,i) + a[pos+1][i]);

    return dp[pos][type] = ret;
}

void read(){

    int i,j;
    cin>>N;
    for(i=1; i<=N; i++)
        for(j=1; j<=3; j++)
            cin>>a[i][j];
}

void solve(){

    memset(dp,-1,sizeof(dp));
    read();
    cout<< rec(0,0) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}



Measured memory_bytes: 12924
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	vector<int> cnt(3, 0);
	ll ans = 1;
	rep(i,n) {
		int c = 0;
		rep(j,3) {
			if (v[i] == cnt[j]) c++;
		}
		ans *= c;
		ans %= MOD;
		rep(j,3) {
			if (v[i] == cnt[j]) {
				cnt[j]++;
				break;
			}
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 3792
/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 2005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());

string a[5];
vector <int> mas = {0, 1, 2};

int dp[3][3][N][N];

int calc() {
    int x = mas[0], y = mas[1], z = mas[2];
    int mn = inf;
    for (int i = 0; i <= (int)a[x].size(); i++) {
        for (int j = i; j <= max( (int)a[x].size(), i + (int)a[y].size() ); j++) {

            if (i < (int)a[x].size() && dp[x][y][i][0] < min( (int)a[y].size(), (int)a[x].size() - i )) {
                continue;
            }

            if (j < (int)a[x].size() && dp[x][z][j][0] < min( (int)a[z].size(), (int)a[x].size() - j )) {
                continue;
            }

            if (j < i + (int)a[y].size() && dp[y][z][j - i][0] < min( (int)a[z].size(), (int)a[y].size() + i - j )) {
                continue;
            }

            int len = max( (int)a[x].size(), i + (int)a[y].size() );
            len = max(len, j + (int)a[z].size());
            mn = min(mn, len);
        }
    }
    return mn;
}

int cmp(char x, char y) {
    if (x == '?' || y == '?') return 1;
    return (x == y);
}

int main() {
    int answ = inf;
    cin >> a[0] >> a[1] >> a[2];

    for (int t1 = 0; t1 <= 2; t1++) {
        for (int t2 = 0; t2 <= 2; t2++) {
            if (t1 == t2) continue;
            for (int i = (int)a[t1].size() - 1; i >= 0; i--) {
                for (int j = (int)a[t2].size() - 1; j >= 0; j--) {
                    if (i == (int)a[t1].size() - 1 || j == (int)a[t2].size() - 1) {
                        dp[t1][t2][i][j] = cmp(a[t1][i], a[t2][j]);
                    } else {
                        if (cmp(a[t1][i], a[t2][j])) {
                            dp[t1][t2][i][j] = dp[t1][t2][i + 1][j + 1] + 1;
                        } else {
                            dp[t1][t2][i][j] = 0;
                        }
                    }
                }
            }
        }
    }

    do {
        answ = min(answ, calc());
    } while (next_permutation(mas.begin(), mas.end()));

    cout << answ << endl;
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

void go(vl &a) {
	ll n = sz(a);
	ll i = 0;
	FOR(j,0,n) if (a[j] > a[i]) i = j;

	a[i] -= n;
	FOR(j,0,n) if (j != i) a[j]++;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll k; cin >> k;
	
	ll q = (k+49)/50;
	ll r = q*50 - k;

	vl a(50,49 + q);
	FOR(i,0,r) go(a);

	cout << 50 << endl;
	FOR(i,0,50) cout << a[i] << " \n"[i==49];

	

}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long ans = 0;
        for (int b = 1; b <= n; b++) {
            int p = n / b;
            int r = n % b;
            ans += p * Math.max(b - k, 0);
            ans += Math.max(r - k + 1, 0);
        }
        if (k == 0) {
            ans -= n;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

vector<ll> a;

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

 // a.reserve(n);
  a.reserve(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(a.begin(), a.begin()+n);
  long long  b;
  if(n%2 == 0) {
    b = a[n/2 -1];
  } else {
    b = a[(n-1)/2];
  }

  long long  r = 0;

  for(int i=0;i<n;i++) {
    r += abs(a[i] - b);
  }

  cout << r << endl;
return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

out = 0
for i in range(n):
  if b[i] >= a[i] + a[i+1]:
    out += a[i] + a[i+1]
    a[i+1] = 0
  elif a[i] <= b[i] < a[i] + a[i+1]:
    out += b[i]
    a[i+1] = a[i]+a[i+1]-b[i]
  else:
    out += b[i]
print(out)

Measured memory_bytes: 19156
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

const int MOD = 1e9 + 7;
std::vector<std::vector<int>> dp, g;
int dfs(int v = 0, int par = -1) {
	i64 A = 1, B = 1;
	for(auto e : g[v]) {
		if(e == par) continue; dfs(e, v);
		A = A * (dp[e][0] + dp[e][1]) % MOD;
		B = B * dp[e][0] % MOD;
	}
	dp[v][0] = A;
	dp[v][1] = B;
}

int main() {
	int n; scanf("%d", &n); dp.resize(n, std::vector<int>(2, 0)); g.resize(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d%d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	dfs();
	printf("%lld\n", (dp[0][0] + dp[0][1]) % MOD);
	return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = int(1e9);
const int MAX = 1000020;
LL N;
LL a[MAX],b[MAX],c[MAX];
void Cin(LL a[]){
    for(int i = 1;i<=N;i++)scanf("%lld",&a[i]);
}
int main(){
    cin>>N;Cin(a),Cin(b),Cin(c);sort(a+1,a+1+N),sort(b+1,b+1+N),sort(c+1,c+1+N);
    LL sum=0;LL ai=0,ci=0;
    for(int i = 1;i<=N;i++){while(a[ai+1]<b[i]&&ai+1<=N)ai++;while(c[ci+1]<=b[i]&&ci+1<=N)ci++;sum+=ai*(N-ci);}
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 9216
#include <cstdio>
#include <vector>

using namespace std;

const int INF = 99999999;

class Edge{
public:
  int from,to,cost,time;
  void swap(){
    int self = from;
    from = to;
    to = self;
  }
  int getvalue(int r){
    if(r == 0){
      return cost;
    }else{
      return time;
    }
  }
};

vector<Edge> edge;
int n,m;

int solve(const int p,const int q,const int r);

int main(){
  edge.clear();
  while(1){
    edge.clear();
    scanf("%d %d",&n,&m);
    if(n==0 && m==0){ break; }
    for(int i=0;i<n;i++){
      Edge ed;
      scanf("%d %d %d %d",&ed.from,&ed.to,&ed.cost,&ed.time);
      edge.push_back(ed);
      ed.swap();
      edge.push_back(ed);
    }
    
    int k;
    scanf("%d",&k);
    for(int i=0;i<k;i++){
      int p,q,r;
      scanf("%d %d",&p,&q);
      if(p==0 && q==0){
        return 0;
      }
      scanf("%d",&r);
      printf("%d\n",solve(p,q,r));
    }
  }
  return 0;
}

int solve(const int p,const int q,const int r){
  int *a = new int[m+1];
  for(int i=0;i<=m;i++){
    a[i] = INF;
  }
  a[p] = 0;
  bool update;
  while(true){
    update = false;
    vector<Edge>::iterator it = edge.begin();
    while(it != edge.end()){
      if(a[(*it).from] != INF && a[(*it).to] > a[(*it).from] + (*it).getvalue(r)){
        a[(*it).to] = a[(*it).from] + (*it).getvalue(r);
        update = true;
      }
      it++;
    }
    if(!update){
      break;
    }
  }
  
  int ans = a[q];
  return a[q];
}

Measured memory_bytes: 2380
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
 
const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;
const int M=2161;
 
ll a[N],need[N],rest[N]; 
int prime[M],tot;
map<pll,int> cnt;
int n;
 
il void init(){
	static bool kicked[M];
	rep(i,2,M-1){
		if(!kicked[i]) prime[++tot]=i;
		rep(j,1,tot){
			if(i*prime[j]>=M) break;
			kicked[i*prime[j]]=true;
			if(i%prime[j]==0) break;
		}
	}
}
 
int main(){
	init();
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%lld",a+i);
		need[i]=rest[i]=1;
		ll tmp=a[i];
		rep(j,1,tot){
			int v=prime[j];
			if(tmp%v!=0) continue;
			int times=0;
			while(tmp%v==0) tmp/=v,++times;
			times%=3;
			if(times==1){
				rest[i]*=v;
				need[i]*=v*v; 
			}else if(times==2){
				rest[i]*=v*v;
				need[i]*=v;
			}
		}
		if(tmp>1){
			ll v=floor(sqrt(tmp));
			if(v*v==tmp){
				rest[i]*=tmp;
				need[i]*=v;
			}else{
				rest[i]*=tmp;
				need[i]*=tmp*tmp;
			}
		}
	//	cerr<<need[i]<<" "<<rest[i]<<endl;
		++cnt[mp(rest[i],need[i])];
	}
	int ans=0;
	while(cnt.begin()!=cnt.end()){
		pll p=cnt.begin()->X,q=mp(p.Y,p.X);
		if(p.X==1) ++ans;
		else{
			ans+=qmax(cnt[p],cnt[q]);
			cnt.erase(q);
		}
		cnt.erase(cnt.begin());
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8832