akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <list>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int h;
        scanf("%d", &h);
        if (h == 0) {
            break;
        }

        vector<vector<int>> v;
        v.resize(h);
        for (auto&& r : v) {
            r.resize(5);
            for (auto i = 0; i < 5; ++i) {
                int x;
                scanf("%d", &x);
                r[i] = x;
            }
        }

        int p = 0;
        bool change = false;
        do {
            // printf("debug\n");
            // for (auto&& r : v) {
            //    for (auto&& i : r) {
            //        printf("%2d ", i);
            //    }
            //    printf("\n");
            //}
            change = false;
            for (auto&& r : v) {
                // 5
                if (r[0] > 0 && r[0] == r[1] && r[1] == r[2] && r[2] == r[3] &&
                    r[3] == r[4]) {
                    p += r[0] * 5;
                    r[0] = r[1] = r[2] = r[3] = r[4] = -1;
                    change = true;
                }
                // 4
                if (r[0] > 0 && r[0] == r[1] && r[1] == r[2] && r[2] == r[3]) {
                    p += r[0] * 4;
                    r[0] = r[1] = r[2] = r[3] = -1;
                    change = true;
                }
                if (r[1] > 0 && r[1] == r[2] && r[2] == r[3] && r[3] == r[4]) {
                    p += r[1] * 4;
                    r[1] = r[2] = r[3] = r[4] = -1;
                    change = true;
                }
                // 3
                if (r[0] > 0 && r[0] == r[1] && r[1] == r[2]) {
                    p += r[0] * 3;
                    r[0] = r[1] = r[2] = -1;
                    change = true;
                }
                if (r[1] > 0 && r[1] == r[2] && r[2] == r[3]) {
                    p += r[1] * 3;
                    r[1] = r[2] = r[3] = -1;
                    change = true;
                }
                if (r[2] > 0 && r[2] == r[3] && r[3] == r[4]) {
                    p += r[2] * 3;
                    r[2] = r[3] = r[4] = -1;
                    change = true;
                }
            }

            for (int i = 0; i < 5; ++i) {
                vector<int> t;
                for (size_t j = 0; j < v.size(); ++j) {
                    if (v[j][i] > 0) {
                        t.push_back(v[j][i]);
                    }
                }
                // printf("t size %d\n", t.size());
                // for (auto&& s : t) {
                //    printf("%d ", s);
                //}
                // putchar('\n');
                for (size_t j = 0; j < t.size(); ++j) {
                    v[h - t.size() + j][i] = t[j];
                }
                for (size_t j = 0; j < h - t.size(); ++j) {
                    v[j][i] = -1;
                }
            }
        } while (change);
        printf("%d\n", p);
    }
}

Measured memory_bytes: 2740
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;


public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int n = Integer.parseInt(br.readLine());
            StringTokenizer str = new StringTokenizer(br.readLine(), " ");
            long[] A = new long[n];
            for(int i = 0; i < n ; i++) {
                A[i] = Integer.parseInt(str.nextToken());
            }
            long c = func(A,n);
            System.out.println(c);
        } catch (IOException e) {
            System.out.println("error");
        }
    }
    static long func(long[] A,int n){
        long sum = 0;
        long c1 = 0,c2 = 0;
        for(int i = 0; i < n; i++){
            if(i%2==0 && sum+A[i]>=0){   //次は負
                c1 += (sum+A[i] + 1);
                sum = -1;
            }
            else if(i%2!=0 && sum+A[i]<=0){
                c1 += 1+(-sum-A[i]);
                sum = 1;
            }
            else{
                sum+=A[i];
            }
        }
        sum = 0;
        for(int i = 0; i < n; i++){
            if(i%2==0 && sum+A[i]<=0){   //次は負
                c2 += (-sum-A[i] + 1);
                sum = 1;
            }
            else if(i%2!=0 && sum+A[i]>=0){
                c2 += 1+sum+A[i];
                sum = -1;
            }
            else{
                sum+=A[i];
            }
        }

        return Math.min(c1,c2);
    }
}

Measured memory_bytes: 38204
import sys
K=int(input())

graph=[[] for _ in range(K)]
for i in range(K):
  graph[i].append(((i+1)%K,1))
  graph[i].append(((10*i)%K,0))
#print(graph)

dist=[-1]*K
s,t=1,0
queue=[s]
d=0
while queue:
  new_queue=set()
  
  while queue:
    q=queue.pop()  
    if dist[q]==-1:
      dist[q]=d
      for v,w in graph[q]:
        if w==0:
          queue.append(v)
        else:
          new_queue.add(v)
  
  d+=1
  queue=list(new_queue)
  
#print(dist)
print(dist[0]+1)

Measured memory_bytes: 41488
// AtCoderIsFucking.cpp

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

using namespace std;


long long N,K,Q,A[100000+10] ;

int main()
{
	cin >> N >> K >> Q;
	for (int i = 0; i < Q; i++)cin >> A[i];
	
	long long B[100000 + 10] = {0};
	for (int i = 0; i < Q; i++)B[A[i]-1]++;

	for (int j = 0; j < N; j++)cout<<(B[j]+K-Q>0?"Yes":"No") << "\n";
}



Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    String A = scanner.nextLine();
    String B = scanner.nextLine();
    String C = scanner.nextLine();

   System.out.printf("%c%c%c\n", A.charAt(0), B.charAt(1), C.charAt(2));
  }

}

Measured memory_bytes: 21460
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int p=1e9+7;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
int cnt[64];
signed main(void)
{
	int n;
	reg int x;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		read(x);
		for(int k=0;k<61;++k)
			if(x&(1ll<<k))
				++cnt[k];
	}
	reg int ans=0;
	for(int k=0;k<61;++k)
		ans+=cnt[k]*(n-cnt[k])%p*((1ll<<k)%p)%p,ans%=p;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 384
list = []
for i in range(3):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)

# print(list)
cnt = [list.count(i) for i in range(1,5)]
cnt = sorted(cnt)
if cnt == [1,1,2,2]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
#include<string.h>
#include<sstream>
using namespace std;

int N;
vector<int> leaf;
vector<long long> min0,max0;

int main(){
    cin>>N;
    leaf.resize(N+1);
    min0.resize(N+1);
    max0.resize(N+1);
    for(int i=0;i<N+1;++i){
        cin>>leaf[i];
    }
    min0[N]=leaf[N];
    max0[N]=leaf[N];
    for(int i=N-1;i>=0;--i){
        min0[i]=(min0[i+1]+1)/2+leaf[i];
        max0[i]=max0[i+1]+leaf[i];
    }
    if(min0[0]>1)cout<<-1<<endl;
    else{
        long long cur=1;
        long long vertex=0;
        for(int i=0;i<N+1;++i){
            vertex+=cur;
            cur-=leaf[i];
            if(i<N)cur=min(cur*2,max0[i+1]);
        }
        cout<<vertex<<endl;
    }
    return 0;
}


Measured memory_bytes: 5028
X,N=map(int,input().split())
p=list(map(int,input().split()))
i=0
j=0
while X+i in p:
    i+=1
while X-j in p:
    j+=1
if i>j:
    print(X-j)
elif i<j:
    print(X+i)
else:
    print(min([X+i,X-j]))


Measured memory_bytes: 79808
match = [0,2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
a=list(map(int,input().split()))
dp=[-1]*(n+11451)
dp[0]=0
for i in range(n+1):
    if dp[i]==-1:
        continue
    else:
        for j in a:
            dp[i+match[j]]=max(dp[i+match[j]],dp[i]*10+j)

print(dp[n])

Measured memory_bytes: 51164
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
ll x,y;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>x>>y;
    if(abs(x-y)<=1)cout<<"Brown"<<endl;
    else cout<<"Alice"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, C;
    cin >> n >> C;

    vector<ll> D(C * C);
    rep(i, C * C) cin >> D[i];
    vector<ll> c(n * n);
    rep(i, n * n) cin >> c[i];
    
    vector<vector<ll>> cnt(3, vector<ll>(31));

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            ll ind = (i-1) * n + (j-1);
            cnt[(i+j)%3][c[ind]]++;
        }
    }

    ll res = 1e18;
    for (int p = 1; p <= C; p++) {
        for (int q = 1; q <= C; q++) {
            for (int r = 1; r <= C; r++) {
                if (p == q || q == r || r == p) {
                    continue;
                }

                // %3=0をp, 1をq, 2をr
                ll v = 0;
                vector<ll> colors = {p, q, r};
                rep(k, 3) {
                    repi(i, cnt[k].size()) {
                        ll from = i;
                        ll count = cnt[k][i];
                        ll to = colors[k];
                        ll ind = (from-1) * C + (to-1);
                        if (count >= 1) {
                            v += D[ind] * count;
                        }
                    }
                }
                res = min(res, v);
            }
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 5348
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,j,x,num=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		if(x!=i+1)
		{
			num++;
		}
	}
	if(num<=2)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int D;
  int x, y;
  char a, b, c;
  int e;
  int p[100] = {0}, q[100] = {0};
  int sc = 0;

  cin >> D;
  cin >> x;
  for(int i = 0; i < x; i++){
    cin >> a >> e;
    if(a == 'D'){
      //a[i] = d;
      p[i] = e;
    }
  }
  /* for(int i = 0; i < x; i++){
    cout << p[i] << endl;
    }*/

  cin >> y;
  for(int i = 0; i < y; i++){
    cin >> b >> c >> e;
    if(b == 'D' && c == 'D'){
      q[i] = e;
    }
  }

    sort(p, p + x);

    /*for(int i = 0; i < x; i++){
    cout << p[i] << endl;
    }*/

    sort(q, q + y);
    x--;
    y--;
    while(D){
      if(x >= 1){
	if(p[x] + p[x - 1] >= q[y] || y < 0){
	  sc += p[x];
	  x--;
	  D--;
	}
	else{
	  if(D < 2){
	    sc += p[x];
	    break;
	  }
	  sc += q[y];
	  y--;
	  D -= 2;
	}
      }
      else{//x = 0
	if(p[x] >= q[y] && x == 0){
	sc += p[x];
	x--;
	D--;
	//break;
	}
	else{
	  if(D < 2){
	    if(x == 0){
	      sc += p[x];
	      break;
	    }
	    else break;
	  }
	  sc += q[y];
	  y--;
	  D -= 2;
	}
      }
    }
    if(sc < 0) sc = 0;

  cout << sc << endl;
 
 return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;

char str[13];

void solve()
{
    scanf("%s", str);
    int n=strlen(str);
    int i;
    int ans=0;
    int cnt=0;
    for(i=0; i<n; i++) {
        if(str[i]=='A' || str[i]=='C' || str[i]=='G' || str[i]=='T') {
            cnt++;
        }
        else {
            cnt=0;
        }
        ans=MAX(ans,cnt);
    }
    printf("%d\n", ans);
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI1(x) scanf("%d",&x);
#define inI2(x,y) scanf("%d %d",&x,&y);
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z);
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
int n,nn[105],ans,k;
int main()
{
    inI1(n);
    ans=imx;
    for(int i=1;i<=n;i++)
    {
        inI1(nn[i]);
    }
    for(int j=-100;j<=100;j++)
    {
        k=0;
        for(int i=1;i<=n;i++)
        {
            k+=(nn[i]-j)*(nn[i]-j);
        }
        ans=min(ans,k);
    }
    printf("%d",ans);
}


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

using namespace std;

int main() {

	int N;
	int K;
	int Q;

	cin >> N;
	cin >> K;
	cin >> Q;
	int x;
	vector<int> score(N,0);

	for (int i = 0; i < Q; i++)
	{
		cin >> x;
		score[x-1] += 1;
	}

	for (int i = 0; i < N; i++)
	{
		if (score[i] + K - Q > 0)
		{
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 1024
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
ll s;
ll fun(ll a)
{
	if(a==0)
	return 0;
	return a+fun(a-1);
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;

#define MAXN   10000001 
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (ll i=3; i*i<MAXN; i++) 
    {
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
set<ll> getFactorization(ll x) 
{ 
    set<ll> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=-10000000000,t=0,q=0,x,y=100000000000,m;
  	cin>>n>>m>>k;
  	ll a[n];
  	ll b[m];
  	for(i=0;i<n;i++)
  	cin>>a[i];
  	for(i=0;i<m;i++)
  	cin>>b[i];
  	for(i=1;i<n;i++)
	a[i]=a[i]+a[i-1];
	for(j=1;j<m;j++)
	b[j]=b[j]+b[j-1];
	l=0;
	for(i=0;i<n;i++)
	{
		t=k-a[i];
		if(t>=0)
		{
		q=upper_bound(b,b+m,t)-b;
		l=max(l,i+q+1);
	}
	}
	for(i=0;i<m;i++)
	{
		t=k-b[i];
		if(t>=0)
		{
		q=upper_bound(a,a+n,t)-a;
		l=max(l,i+q+1);
	}
	}
	cout<<l<<endl;
  	}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  

Measured memory_bytes: 6788
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define MAX 100000

static const int N =1000;

int lcs(string X,string Y){
  int c[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int ans=0;
  X= ' '+X;
  Y= ' '+Y;
  for(int i;i<=m;i++)c[i][0]=0;
  for(int j;j<=n;j++)c[0][j]=0;

  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(X[i]==Y[j]){
        c[i][j]=c[i-1][j-1]+1;
      }
      else{
        c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      ans=max(ans,c[i][j]);
    }
  
  }
  return ans;
}

int main(){
  string s1,s2;
  int n; cin >> n;
  for(int i=0;i<n;i++){
    cin >> s1>> s2;
    cout << lcs(s1,s2) << endl;
  }
  return 0;
}


Measured memory_bytes: 7068
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>

#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

int main(void) {

	vector<ll> x = vector<ll>();
	vector<ll> y = vector<ll>();
	vector<ll> z = vector<ll>();
	int xn, yn, zn, k;
	cin >> xn >> yn >> zn >> k;
	rep(0, xn) {
		ll inp;
		cin >> inp;
		x.push_back(inp);
	}
	rep(0, yn) {
		ll inp;
		cin >> inp;
		y.push_back(inp);
	}
	rep(0, zn) {
		ll inp;
		cin >> inp;
		z.push_back(inp);
	}
	sort(x.rbegin(), x.rend());
	sort(y.rbegin(), y.rend());
	sort(z.rbegin(), z.rend());
	
	vector<ll> xy = vector<ll>();
	rep(0, x.size()) {
		for (int j = 0; j < y.size(); j++) {
			xy.push_back(x[i] + y[j]);
		}
	}
	sort(xy.rbegin(), xy.rend());
	vector<ll> ans = vector<ll>();
	int xysize = xy.size();
	int roop = min(k, xysize);
	rep(0, roop) {
		for (int j = 0; j < z.size(); j++) {
			ans.push_back(xy[i] + z[j]);
		}
	}
	sort(ans.rbegin(), ans.rend());
	rep(0, k) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 43256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ds(n); cin >> ds;
    if(ds[0]){
        cout << 0 << '\n';
        return 0;
    }
    sort(ds.begin(), ds.end());
    int len = 1;
    ll ans = 1;
    int prev = 1;
    for(int i = 1; i < n; ){
        int cnt = 0;
        while(i < n && ds[i] == len){
            i++;
            cnt++;
            ans = ans * prev % 998244353;
        }
        if(cnt == 0){
            ans = 0;
            break;
        }
        printde(i, cnt, len, ans);
        len++;
        prev = cnt;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<long, long>;

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
}; 

int main()
{
    int N; cin >> N;
    string s[105];
    REP(i, N) cin >> s[i];
    int M; cin >> M;
    string t[105];
    REP(i, M) cin >> t[i];

    map<string, int> red, blue;
    red.insert(make_pair(s[0], 1));
    REP(i, N-1){
        auto itr = red.find(s[i+1]);
        if(itr != red.end())
            (*itr).second++;
        else
            red.insert(make_pair(s[i+1], 1));
    }

    blue.insert(make_pair(t[0], 1));
    REP(i, M-1){
        auto itr = blue.find(t[i+1]);
        if(itr != blue.end())
            (*itr).second++;
        else
            blue.insert(make_pair(t[i+1], 1));
    }

    int ans = 0;
    for(auto itr : red){
        if(blue.find(itr.first) != blue.end())
            ans = max(ans, itr.second - (*blue.find(itr.first)).second);
        else ans = max(ans, itr.second);
    }
    cout << ans << endl;

    
    return 0;
}



Measured memory_bytes: 256
def sort(num):
   l = len(num)
   for i in range(0,l):
        for j in range(0,l-i-1):
            if num[j] < num[j+1]:
               temp = num[j]
               num[j] = num[j+1]
               num[j+1]=temp
   print(num[0],end='')
   for i in range(1,len(num)-1):
       print('',num[i],end='')
   print('',num[i+1])

a , b , c , d , e = map(int,input().split())
num = []
num.append(a)
num.append(b)
num.append(c)
num.append(d)
num.append(e)
sort(num)

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

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		string a, b; cin >> a >> b;
		if (a == "0")break;
		else {
			vector<int>nums(10,-1);
			for (int i = 0; i < 4; ++i) {
				nums[a[i] - '0'] = i;
			}
			int hit = 0, blow = 0;
			for (int i = 0; i < 4; ++i) {
				if (nums[b[i] - '0']!=-1) {
					if (nums[b[i] - '0'] == i)hit++;
					else blow++;
				}
				
			}

			cout << hit << " " << blow << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

 
int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<int>> c(10,vector<int>(10)), a(h,vector<int>(w));
  REP(i,10){
    REP(j,10){
      cin>>c[i][j];
    }
  }

  REP(i,h){
    REP(j,w){
      cin>>a[i][j];
    }
  }

  vector<int> cost(10,1001);/*iから1に書き換えるコスト*/
  cost[1]=0;
  REP(v,10){
    REP(i,10){
      REP(j,10){
        cost[i]=min(cost[i], cost[j]+c[i][j]);
      }
    }
  }

  int ans=0;
  REP(i,h){
    REP(j,w){
      if(a[i][j]!=-1){
        ans+=cost[a[i][j]];
      }
    }
  }
     
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    int i,j;
    int n;
    int midasi[10] = {0};
    double x;
    scanf("%d",&n);
    for(i = 0; i < n; i++){
        scanf("%lf",&x);
        if(x < 165.0) midasi[1]++;
        if(x >= 165.0 && x < 170.0) midasi[2]++;
        if(x >= 170.0 && x < 175.0) midasi[3]++;
        if(x >= 175.0 && x < 180.0) midasi[4]++;
        if(x >= 180.0 && x < 185.0) midasi[5]++;
        if(x >= 185.0) midasi[6]++;
    }
    for(i = 1; i <= 6; i++){
        printf("%d:",i);
        for(j = 0; j < midasi[i]; j++){
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	int i,n,count = 0,prime[10001]={2};
	long x;
	
	for( x = 3; count < 10000; x += 2 ){
		for( i = 1;; i++ ){
			if( prime[i] == 0 ){
				prime[i] = x;
				count++;
				break;
			}
			if( x % prime[i] == 0 ) break;
		}
	}
	
	while( scanf("%d", &n), n != 0 ){
		long total = 0;
		for( i = 0; i < n; i++ ) total += prime[i];
		printf("%ld\n", total);
	}
	return 0;
}

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

const int MAX = 100010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  COMinit();
  ll n,ans=0,sum=0;cin>>n;
  V<ll> v(n);
  rep(i,0,n)cin>>v[i];

  rep(i,0,n-1){
    sum+=inv[i+1];
    ans+=((v[i+1]-v[i])*sum)%mod;
    ans%=mod;
  }
  ans*=fac[n-1];
  ans%=mod;
  cout<<ans<<ENDL;

}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3328
def backtrace(dp, col_str):
    res = []
    r, c = len(dp) - 1, len(dp[0]) - 1
    while dp[r][c] != 0:
        if dp[r-1][c] == dp[r][c]:
            r -= 1
        elif dp[r][c-1] == dp[r][c]:
            c -= 1
        elif dp[r-1][c-1] + 1 == dp[r][c]:
            res.append(col_str[c-1])
            r -= 1
            c -= 1

    if res == []:
        return ""
    else:
        return "".join(map(str, res[::-1]))

def solve(s, t):
    len_s, len_t = len(s), len(t)
    dp = [[0] * (len_t+1) for _ in range(len_s+1) ]

    for r in range(1, len_s+1):
        for c in range(1, len_t+1):
            if s[r-1] == t[c-1]:
                dp[r][c] = dp[r-1][c-1] + 1
            else:
                dp[r][c] = max(dp[r-1][c], dp[r][c-1])
    
    #for r in dp:
        #print(r)

    return backtrace(dp, t)

s = input()
t = input()

print(solve(s, t))


Measured memory_bytes: 111836
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;
bool valid(int a, int b) {
	return a == b || a > 2 * b;
}
bool vis[60][60];
set <ll> dp[69][69];
void merge(set <ll> &G, set <ll> lel, int val) {
	for(auto u : lel) {
		G.insert(u | (1LL << val));
	}
}
set <ll> solve(int a, int b) {
	if(a == b) return {0};
	if(vis[a][b]) return dp[a][b];
	if(!valid(a, b)) return {};
	vis[a][b] = 1;
	for(int m = b + 1; m <= a; m++) {
		merge(dp[a][b], solve(a % m, b), m);
	}
	return dp[a][b];
}

int main() {fio;
	int n;
	cin >> n;
	vector <int> a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector <set <ll> > hue(n);
	for(int i = 0; i < n; i++) {
		cin >> b[i];
		hue[i] = solve(a[i], b[i]);
		if(hue[i].empty()) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	for(int i = 50; i >= 1; i--) {
		bool ok = 1;
		for(int j = 0; j < n; j++) {
			bool g = 0;
			for(auto u : hue[j]) {
				if((u | ans) < (ans | (1LL << i))) {
					g = 1;
				}
			}
			ok &= g;
		}
		if(!ok) ans |= 1LL << i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4900
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;

int main() {

	cin >> K >> N;
	vector<LL> v(N),vv(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < N-1; i++) {
		vv[i] = v[i + 1] - v[i];
	}
	vv[N - 1] = v[0] + (K - v[N - 1]);
	sort(vv.begin(), vv.end());
	ans = 0;
	for (int i = 0; i < N-1; i++) {
		ans += vv[i];
	}
	cout << ans<<endl;
	return 0;
}



Measured memory_bytes: 3328
class UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        
    def find(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] = self.par[y] + self.par[x]
        self.par[y] = x

    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.par[self.find(x)]
    
    

n, m, k = map(int, input().split())
U = UnionFind(n)
fl = [0] * n
bl = [0] * n

for _ in range(m):
    a, b = map(int, input().split())
    U.union(a - 1, b - 1)
    fl[a - 1] += 1
    fl[b - 1] += 1

for _ in range(k):
    c, d = map(int, input().split())
    if U.same_check(c - 1, d - 1):
        bl[c - 1] += 1
        bl[d - 1] += 1

ans_list = []
for i in range(n):
    ans = -U.size(i) - fl[i] - bl[i] - 1
    ans_list.append(ans)
print(*ans_list)

Measured memory_bytes: 14884
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");

        int m1 = Integer.valueOf(arr01[0]);
        int d1 = Integer.valueOf(arr01[1]);
        int m2 = Integer.valueOf(arr02[0]);
        int d2 = Integer.valueOf(arr02[1]);

        Boolean chkflg = false;
        switch (m1) {
        case 1:
            if (d1 == 31) {
                chkflg = true;
            }
            break;
        case 2:
            if (d1 == 28) {
                chkflg = true;

            }
            break;
        case 3:
            if (d1 == 31) {
                chkflg = true;

            }
            break;
        case 4:

            if (d1 == 30) {
                chkflg = true;

            }
            break;
        case 5:
            if (d1 == 31) {
                chkflg = true;

            }
            break;
        case 6:
            if (d1 == 30) {
                chkflg = true;

            }
            break;
        case 7:
            if (d1 == 31) {
                chkflg = true;

            }
            break;
        case 8:
            if (d1 == 31) {
                chkflg = true;

            }
            break;
        case 9:
            if (d1 == 30) {
                chkflg = true;

            }
            break;
        case 10:
            if (d1 == 31) {
                chkflg = true;

            }
            break;
        case 11:
            if (d1 == 30) {
                chkflg = true;

            }
            break;
        case 12:
            if (d1 == 31) {
                chkflg = true;

            }
            break;
        }

        if (chkflg) {
            System.out.println("1");
        } else {
            System.out.println("0");

        }

    }

}


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

int main()
{
    int input_01[255];
    int input_02[255];
    int input_id = 0;
    while(1) {
        cin >> input_01[input_id] >> input_02[input_id];
        if(input_01[input_id] == 0 && input_02[input_id] == 0) break;
        input_id++;
    }

    int draw_id = 0;
    while(draw_id < input_id) {
        for(int i = 0; i < input_01[draw_id]; i++) {
            for(int j = 0; j < input_02[draw_id]; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        draw_id++;
    }

    return 0;
}

Measured memory_bytes: 1152
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

int main()
{
	fast
	int n,k;
	cin>>n>>k;
	vector <int> arr(n);
	REP(i,n)
		cin>>arr[i];
	vector <int> dp(n,INT_MAX);
	if(k >= n)
	{
		dp[0] = 0;
		FOR(i,1,n)
		{
			REP(j,i)
			{
				int temp =  abs(arr[i]-arr[j])+dp[j];
				dp[i] = min(temp,dp[i]);
			}
		}
	}
	else
	{
		dp[0] = 0;
		FOR(i,1,k)
		{
			REP(j,i)
			{
				int temp =  abs(arr[i]-arr[j])+dp[j];
				dp[i] = min(temp,dp[i]);
			}
		}
		//displaySingle(dp);
		FOR(i,k,n)
		{
			FOR(j,i-k,i)
			{
				int temp = abs(arr[i]-arr[j])+dp[j];
				dp[i] = min(temp,dp[i]);
			}
		}
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 3984
x = int(input())
for a in range(1000):
    for b in range(1000):
        if a**5 - b**5 == x:
            print(f"{a} {b}")
            break
        elif a**5 - (-b)**5 == x:
            print(f"{a} {-b}")
            break
    else:
        continue
    break


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

int count(int i,int n, int k,vector<int> &a, vector<int> &dp)
{
  if(dp[i]!=-1)
  {
      return dp[i];
  }
  
  int m=INT_MAX;
  for(int j=i+1;j<n && j<=i+k;j++)
  {
      
      int t=count(j,n,k,a,dp)+abs(a[i]-a[j]);
      if(t<m)
      m=t;
  }
  dp[i]=m;
  return m;
  
}
int main()
{
  int n,k,i;
  cin>>n;
  cin>>k;
  
  vector<int>dp(n);
  for(i=0;i<n;i++)
  dp[i]=-1;
  
  vector<int>a(n);
  for(i=0;i<n;i++)
    cin>>a[i];
    
  dp[n-1]=0;
  dp[n-2]=abs(a[n-1]-a[n-2]);
  i=0;
  int res=count(i,n,k,a,dp);
  cout<<res<<endl;
  
}

Measured memory_bytes: 8832
s = input()
t = input()
ans = 10000000
for i in range(len(s)-len(t)+1):
    tnp = 0
    for j in range(len(t)):
        if (s[j+i]!=t[j]):
            tnp += 1
    ans = min(ans,tnp)
print(ans)

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

int partition(vector<int> &A, int p, int r) {
    int x, i;
    x = A.at(r);
    i = p - 1;
    for (int j = p; j < r; j++) {
        if (A.at(j) <= x) {
            swap(A.at(++i), A.at(j));
        }
    }
    swap(A.at(++i), A.at(r));

    return i;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A.at(i));
    }

    int j = partition(A, 0, n - 1);

    for (int i = 0; i < n - 1; i++) {
        if (i == j) {
            printf("[%d] ", A.at(i));
        } else {
            printf("%d ", A.at(i));
        }
    }
    printf("%d\n", A.at(n - 1));
}


Measured memory_bytes: 3248
def main():
  N=int(input())
  S=[1 if x=='R' else (2 if x=='G' else 3) for x in [*input()]]

  t=S.count(1)*S.count(2)*S.count(3)
  for i in range(N-2):
    j=1
    while i+2*j<N:
      if S[i]*S[i+j]*S[i+2*j]==6:
        t-=1
      j+=1

  print(t)

main()


Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long int lont;
int main() {
	vector<int>veca(10);
	for (int ia = 0; ia < 10; ia++) {
		cin >> veca.at(ia);
	}
	sort(veca.begin(), veca.end());
	reverse(veca.begin(), veca.end());
	for (int ib = 0; ib < 3; ib++) {
		cout << veca.at(ib) << endl;
	}
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> ans;
    ans.push_back(abs(a - b));
    ans.push_back(abs(a - c));
    ans.push_back(abs(c - b));
    sort(ALL(ans));
    cout << ans[0] + ans[1] << endl;
}


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

#define MAX 30
int W, H;
int S[MAX][MAX];
int C[4];


typedef pair<int,int> pi;
int B[MAX][MAX][4];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int main()
{
  
  while(true)
    {
      scanf("%d%d",&W,&H);
      if(W==0&&H==0)return 0;
      rep(i,H)
	{
	  rep(j,W)
	    {
	      scanf("%d",&S[i][j]);
	      rep(k,4)
		{
		  B[i][j][k]=114514;
		}
	    }
	}
      rep(i,4)
	{
	  scanf("%d", &C[i]);
	}
      //int dir = 0;

      queue<pi> Q;
      B[0][0][0]=0;
      Q.push(pi(0,0));
      queue<int> R;
      R.push(0);
      int ans = 114514;
      while(!Q.empty())
	{
	  int y = Q.front().first;
	  int x = Q.front().second;
	  Q.pop();
	  int r = R.front();
	  R.pop();
	  if(y==H-1 && x==W-1)
	    {
	      ans=min(ans,B[y][x][r]);
	      continue;
	    }
	  
	  int cost;
	  rep(i,4)
	    {
	      if(S[y][x]==i)cost=0;
	      else cost = C[i];

	      int dir = (r+i)%4;
	      int ty = y + dy[dir];
	      int tx = x + dx[dir];
	      if(ty<0 || ty>=H || tx<0 || tx>=W)continue;
	      if(B[ty][tx][dir]>B[y][x][r]+cost)
		{
		  Q.push(pi(ty,tx));
		  R.push(dir);
		  B[ty][tx][dir]=B[y][x][r]+cost;
		  //printf("ty=%d,tx=%d,dis=%d,dir=%d,y=%d,x=%d,r=%d\n",ty,tx,B[ty][tx][dir],dir,y,x,r);
		}
	    }
	 
	  
	}
      printf("%d\n",ans);
    }
}

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

int main(){
    char X;
    int A[26] = {};

    while(cin >> X){
        if(isalpha(X)){
            if(isupper(X)){
                X = tolower(X);
            }
            int num = X - 'a';
            for(int i = 0;i <26;i++){
                if(i == num){
                    A[i]+=1;
                }
            }
            
        }    
    }
    for(int k = 0;k < 26;k++){
        printf("%c : %d\n",k+'a',A[k]);

    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int h, w, m;
    cin >> h >> w >> m;
    map<int, int> hnum, wnum;
    map<PII, bool> mp;
    rep(i, m)
    {
        int y, x;
        cin >> y >> x;
        y--;
        x--;
        hnum[y]++;
        wnum[x]++;
        mp[{y, x}] = true;
    }
    priority_queue<PII> pque_x, pque_y;
    rep(i, w)
    {
        pque_x.push({wnum[i], i});
    }
    rep(i, h)
    {
        pque_y.push({hnum[i], i});
    }
    int ans = pque_x.top().first + pque_y.top().first - 1;

    VI candid_x;
    int tmp = pque_x.top().first;
    while (pque_x.empty() == false && pque_x.top().first == tmp)
    {
        candid_x.push_back(pque_x.top().second);
        pque_x.pop();
    }

    VI candid_y;
    tmp = pque_y.top().first;
    while (pque_y.empty() == false && pque_y.top().first == tmp)
    {
        candid_y.push_back(pque_y.top().second);
        pque_y.pop();
    }

        for (auto &&y : candid_y)
    {
        for (auto &&x : candid_x)
        {
            if (mp[{y, x}] == false)
            {
                cout << ans + 1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B){
    if(A < 10 && B < 10) {
        cout <<  A * B << endl;
    } else {
        cout << -1 << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int min(int,int);
int getPowerDiff(int,int,int,int[20]);

int main(){
  int n,i,a[20];
  while(1){
    scanf("%d",&n);
    if(n == 0){ break; }
    for(i = 0 ; i < n ; i++){
      scanf("%d",&a[i]);
    }
    printf("%d\n",getPowerDiff(0,0,n-1,a));
  }
  return 0;
}


/*
  aテ」ツ?ィbテ」ツ?ョテヲツ慊?・ツーツ湘・ツ?、テ」ツつ津ィツソツ氾」ツ??
 */
int min(int a,int b){
  if(a < b){
    return a;
  }else{
    return b;
  }
}

/*
  aテ」ツ?ィbテ」ツ?ョテ・ツキツョテ」ツ?ョテァツオツカテ・ツッツセテ・ツ?、テ」ツつ津ィツソツ氾」ツ??
 */
int myAbs(int a,int b){
  if(a < b){
    return b - a;
  }else{
    return a - b;
  }
}

/*
  Aテ」ツ?ッテ」ツつーテ」ツδォテ」ツδシテ」ツδ輸テ」ツ?ョテヲツ按ヲテゥツ猟佚・ツ環崚」ツ?ョテ・ツ青暗ィツィツ暗・ツ?、.
  Bテ」ツ?ッテ」ツつーテ」ツδォテ」ツδシテ」ツδ唯テ」ツ?ョテヲツ按ヲテゥツ猟佚・ツ環崚」ツ?ョテ・ツ青暗ィツィツ暗・ツ?、.
  iテ」ツ?ッテ、ツサツ甘」ツ?ゥテ」ツ?ョテァツ卍サテゥツ個イティツ??」ツつ津・ツッツセティツアツ。テ」ツ?ィテ」ツ?療」ツ?ヲテ」ツ??」ツつ凝」ツ??
 */
int getPowerDiff(int A,int B,int i,int a[20]){
  /*
    i == -1テ」ツ?ィテ」ツ?ェテ」ツつ凝」ツ?ィテ」ツ??
    テ・ツ?ィテ」ツ?ヲテ」ツ?ョテァツ卍サテゥツ個イティツ??」ツつ津」ツつーテ」ツδォテ」ツδシテ」ツδ輸テ」ツ?セテ」ツ?淌」ツ?ッBテ」ツ?ォテ・ツ按?」ツ?妥」ツ?淌」ツ?ョテ」ツ?ァ
    テ」ツ?敕」ツ?ョテ」ツ?ィテ」ツ?催」ツ?ョテヲツ按ヲテゥツ猟佚・ツ環崚」ツ?ョテ・ツキツョテ」ツ?ョテァツオツカテ・ツッツセテ・ツ?、テ」ツつ津ィツソツ氾」ツ??
   */
  if(i == -1){
    return myAbs(A,B);
  }
  
  /*
    iテァツ閉ェテァツ崢ョテ」ツ?ョテァツ卍サテゥツ個イティツ??」ツつ津」ツつーテ」ツδォテ」ツδシテ」ツδ輸テ」ツ?ォテ・ツ環?」ツ?暗」ツつ凝」ツ?凝」ツ??」ツつーテ」ツδォテ」ツδシテ」ツδ唯テ」ツ?ォテ・ツ環?」ツ?暗」ツつ凝」ツ??
   */
  return min(getPowerDiff(A+a[i],B,i-1,a),
             getPowerDiff(A,B+a[i],i-1,a));
}

Measured memory_bytes: 1028
function main(lines) {
  const [X, N] = splitN(lines[0]);
  if (N == 0) return console.log(X);
  const ps = splitN(lines[1]);

  let res, n = 0;
  while (true) {
    if (!ps.includes(X-n)) {
      res = X-n;
      break;
    }
    if (!ps.includes(X+n)) {
      res = X+n;
      break;
    }
    n++;
  }
  
  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 29636
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()

dic = defaultdict(int)
ans = 0
for i in range(n):
    ans += dic[i - a[i]]
    dic[a[i] + i] += 1

print(ans)

Measured memory_bytes: 61272
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<ll>x(n),y(n),p(n); 
  rep(i,n) cin >> x[i] >> y[i] >> p[i]; 
  vector<ll>ans(n+1,1e18);
  
  vector<vector<ll>> distx(1<<n,vector<ll>(n));
  vector<vector<ll>> disty(1<<n,vector<ll>(n));
  for(int bit=0;bit<(1<<n);bit++){
    rep(i,n){
      distx[bit][i]=abs(x[i]);
      disty[bit][i]=abs(y[i]);
      rep(j,n){
        if(bit&(1<<j)){
          distx[bit][i]=min(distx[bit][i],abs(x[i]-x[j]));
          disty[bit][i]=min(disty[bit][i],abs(y[i]-y[j]));
        }
      }
    }
  }
  for(int bit=0;bit<pow(3,n);++bit){
    int now=bit;
    vector<int>num(n);
    rep(i,n){
      num[i]=now%3;
      now/=3;
    }
    int cnt = 0;
    rep(i,n)if(num[i])cnt++;
    int bitx=0,bity=0;
    rep(i,n){
      if(num[i]==1)bitx|=1<<i;
      if(num[i]==2)bity|=1<<i;
    }
    ll cost=0;
    rep(i,n){
      if(!num[i]){
        cost += min(distx[bitx][i],disty[bity][i])*p[i];
      }
    }
    chmin(ans[cnt],cost);
  }
  rep(i,n+1) cout << ans[i] << endl;
  return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  string S;
  cin >> N >> S;
  int l = (int)S.length();
  REP(i, l) { cout << (char)((S.at(i) - 'A' + N) % 26 + 'A'); }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256