akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scn=new Scanner(System.in);
        int a=scn.nextInt();
        int b=scn.nextInt();
        int h=scn.nextInt();
        int m=scn.nextInt();
        double a_angle=h*(360/12)+m*0.5;
        double b_angle=m*(360/60);
        double c=a_angle-b_angle;
        if(c<0) c+=360;
        
        System.out.println(Math.sqrt(a*a+b*b-2*a*b*Math.cos(Math.toRadians(c))));
    }
}


Measured memory_bytes: 36104
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second

using namespace std;
ll dp[100001]={0},ans[100001]={0},M,dpup[100001]={0};



ll dfs(ll pt,vector < pair< ll,pair<ll,ll> > > adj[],ll old){
	
ll v=1;
vector <ll> vs;
ll zes=0;
ll xas=adj[pt].size();
 for(ll i=0;i<xas;i++){
 	ll ne=adj[pt][i].ff;
	if(ne==old)continue;
	ll sa=dfs(ne,adj,pt);
	v=(v*sa)%M;
 	vs.PB(sa);
 //	cout<<sa<<endl;
 	adj[pt][i].ss.ff=v;
 	}

 ll ze=1;
 ll xa=adj[pt].size();
 ll za=vs.size()-1;
 
for(ll z=xa-1;z>=0;z--){
	ll ne=adj[pt][z].ff;
	if(ne==old)continue;
	
	ze=(ze*vs[za])%M;
	//cout<<ze<<pt<<z<<endl;
	za--;
 	adj[pt][z].ss.ss=ze;}
 	
 dp[pt]=v;
 return (v+1)%M;
}

ll dfs2(ll pt,vector <pair <ll , pair<ll,ll > > > adj[],ll old){

if(old==-1){ans[pt]=dp[pt];}
else{	
    // cout<<dpup[old]<<" "<<dpup[pt]<<endl;
	 dpup[pt]=(dpup[old]*dpup[pt]+1)%M;
	ll an=(dp[pt]*(dpup[pt]))%M;
		ans[pt]=an;
}	


    ll ze=-1;
    ll x=adj[pt].size();
	for(ll i=0;i<x;i++){
		ll ne=adj[pt][i].ff;
		if(ne==old)continue;
        if(ze!=-1){
			ll zx=adj[pt][ze].ff;
			
			dpup[ne]=(adj[pt][ze].ss.ff)%M;
		    dpup[zx]=(dpup[zx]*adj[pt][i].ss.ss)%M;
             //cout<<adj[pt][i].ss.ss<<" "<<i<<" "<<pt<<endl;
        }
		    ze=i;}
		for(ll i=0;i<x;i++){
	    ll ne=adj[pt][i].ff;
		if(ne==old)continue;
    	dfs2(ne,adj,pt);   }
	
}
void run(){
	ll n,m;
	cin>>n>>M;
    vector <pair<ll,pair<ll,ll> > > adj[n+1];
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		ll s=1;
		adj[x].PB(MP(y,MP(s,s)));
		adj[y].PB(MP(x,MP(s,s)));
		dpup[i+1]=1;
	}
	dpup[n]=1;
	dfs(1,adj,-1);

    dfs2(1,adj,-1);
	for(ll j=1;j<=n;j++){
		cout<<ans[j]<<endl;;
	}
}
int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 21632
#ABC 129, B - balance
n = int(input())
W = [int(el) for el in input().split(' ')]

d_min = 100
for i in range(n):
    d = abs(sum(W[0:i+1]) - sum(W[i+1:]))
    if d < d_min:
        d_min = d
print(d_min)


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		s := nextString()
		if s == "-" {
			break
		}
		// fmt.Println(s)
		m, _ := nextInt()
		for i := 0; i < m; i++ {
			hi, _ := nextInt()
			s = s[hi:] + s[:hi]
			// fmt.Println(i, hi, s)
		}
		fmt.Println(s)
	}
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
#define int long long
signed main()
{
    int a[3] ;
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    reverse(a,a+3);
    int ans = 0;
    ans += abs(a[1] - a[0]);
    ans += abs(a[2] - a[1]);
    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

int main() {
    int N;
    bool used[101] = {};

    pair<int, int> ab[101];
    pair<int, int> cd[101];
    cin >> N;

    rep(i, N) cin >> ab[i].second >> ab[i].first;
    rep(i, N) cin >> cd[i].first >> cd[i].second;

    sort(ab, ab + N, greater<pair<int, int>>());//yの高い順に赤色をソート
    sort(cd, cd + N);

    int cou = 0;
    rep(i, N) {
        rep(j, N) {
            if (ab[i].second < cd[j].first && //定義域内である
                ab[i].first < cd[j].second &&
                used[j] == false) {

                used[j] = true;
                cou++;
                break;
            }
        }
    }
    cout << cou << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	int K;
	int A, B, i;
	int M = 0;

	cin >> K;
	cin >> A;
	cin >> B;

	for (i = A; i <= B; i++) {
		if (i % K == 0) {
			M = 1;
			break;
		}
	}

	if (M == 1) {
		cout << "OK";
	}
	else {
		cout << "NG";
	}

	return 0;

}

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

signed main(){
  int N,K;
  cin>>N>>K;
  vector<double> P(N);
  rep(i,N)cin>>P.at(i);
  rep(i,N)P[i]++;
  int mx=0;
  int s=0;
  queue<int> Q;
  rep(i,N){
    s+=P.at(i);
    Q.push(P.at(i));
    if(Q.size()>K){
      s-=Q.front();
      Q.pop();
    }
    if(Q.size()==K){
      mx=max(mx,s);
    }
  }
  double ans=mx;
  ans/=2;
  cout<<fixed<<setprecision(12);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3456
#include <cstdio>

#define INF 10'000'005

long long divisors[INF];

int main(void)
{
    int N;
    scanf("%d", &N);
    for(int i = 0; i <= N; i++) divisors[i] = 1LL;

    long long ans = 1LL;
    int cnt, copy;
    for(int i = 2; i <= N; i++)
    {
        if(divisors[i] == 1LL)
        {
            ans += 2LL * i;
            for(int j = 2 * i; j <= N; j += i)
            {
                cnt = 0, copy = j;
                while(copy % i == 0) 
                {
                    cnt ++;
                    copy /= i;
                }
                divisors[j] *= cnt + 1LL;
            }
        }
        else 
            ans += divisors[i] * i;
    }

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 79860
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int n,q;


//DFS
vector<vector<pair<int, int>>> g;
const int N = 2e5;
int used[N];
int col[N];
int tresumx[N];

void dfs(int i, int c) {
  if(used[i]) return;
  used[i] = 1;
  int myc=c+col[i];
  tresumx[i]=myc;
  for(auto to : g[i]) {
    dfs(to.first, myc);
  }
}

int main() {
  cin>>n>>q;
  g.resize(n);
  for(int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b, 0);
    g[b].emplace_back(a, 0);
  }
  for(int i=0;i<q;i++){
    int p, x;
    cin >> p >> x;
    p--;
    col[p]+=x;
  }

  dfs(0, 0);

  REP(i,n){
    cout<<tresumx[i]<<" ";
  }
    
  return 0;
}

Measured memory_bytes: 21760
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] a = new String[n];
		String[] b = new String[m];
		int x = 0;
		int y = 0;
		boolean end = false;

		for(int i=0; i<n; i++){
			a[i] = sc.next();
		}
		for(int i=0; i<m; i++){
			b[i] = sc.next();
		}
		
		while(true){
			end = true;
			for(int i=0; i<m; i++){
				end = end & b[i].equals( a[i+y].substring(x,x+m) );
			}
			if(end){
				System.out.println("Yes");
				return;
			}else{
				if( x==n-m-1 && y==n-m-1 ){
					System.out.println("No");
					return;
				}else if( x==n-m-1 ){
					x = 0;
					y++;
				}else{
					x++;
				}
			}
		}

	}
}

Measured memory_bytes: 22100
import sys

N = int(input())
Hs = [int(i) for i in input().split()]

ans = "Yes"

if N == 1:
    print("Yes")
    sys.exit()

if N == 2:
    if Hs[0] > Hs[1]:
        Hs[0] -= 1
        if Hs[0] > Hs[1]:
            print("No")
            sys.exit()
    print("Yes")
    sys.exit()
    
for i in range(N-1, 1, -1):
    if Hs[i] < Hs[i-1]:
        Hs[i-1] -= 1
        if Hs[i] < Hs[i-1]:
            print("No")
            sys.exit()

if Hs[-1] < Hs[-2]:
    ans = "No"
if Hs[1] < Hs[0]:
    ans = "No"

print(ans)

Measured memory_bytes: 14480
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;

    map<pair<string, string>, ll> dic;
    rep(mask,1<<N) {
        bitset<20> s(mask);
        string T = "", U = "";
        rep(i,N) {
            if (s.test(i)) T += S[i];
            else U += S[i];
        }
        dic[make_pair(T,U)]++;
    }
    reverse(all(S));
    ll ans = 0;
    rep(mask,1<<N) {
        bitset<20> s(mask);
        string T = "", U = "";
        rep(i,N) {
            if (s.test(i)) T += S[i];
            else U += S[i];
        }
        if (dic.count(make_pair(T,U))) ans += dic[make_pair(T,U)];
    }

    cout << ans << ln;
    
}

Measured memory_bytes: 46080
N = int(input())
m = {}
prv = "!"
ok = True
for i in range(N):
    s = input()
    
    try:
        m[s]
        ok = False
    except:
        m[s] = True
        
        if prv == "!" or prv[-1] == s[0]:
            prv = s
        else:
            ok = False

if ok: print("Yes")
else: print("No")

Measured memory_bytes: 3060
#include <stdio.h>
int ex_search(int a[],int n,int j,int x,int *check_p){
    if(*check_p==1)return 1;
    if(x==0){*check_p=1;return 1;}
    j++;
    if(j<=n) {
        int new_x = x - a[j];
        if(new_x>=0)ex_search(a,n,j,new_x,check_p);
        ex_search(a,n,j,x,check_p);
    }
    return 0;
}

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

  scanf("%d",&m);
  int j;
  int check=0;
  int *check_p=&check;
  for(i=0;i<m;i++){
      j=-1;
      check=0;
      scanf("%d",&x);
      ex_search(a,n,j,x,check_p);
      if(check==1)printf("yes\n");
      if(check==0)printf("no\n");
  }
  return 0;
}


Measured memory_bytes: 2108
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
int v[55];

int calc(int p, int q) {
    vector<int> vec;
    for (int i = 0; i < p; i++) vec.push_back(v[i]);
    for (int i = n-1; i >= q; i--) vec.push_back(v[i]);

    sort(ALL(vec));
    int r = k - (int)vec.size();
    for (int i = 0; i < min(r, (int)vec.size()); i++) {
        if (vec[i] < 0) vec[i] = 0;
    }
    int res = 0;
    for (int u: vec) {
        res += u;
    }
    return res;
}

int solve() {
    int res = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            int g = i + (n-j);
            if (g > k) continue;
            res = max(res, calc(i, j));
        }
    }
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> v[i];
}

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

    input();
    cout << solve() << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int N, A, B, C, l[8];

int dfs(int cur, int a, int b, int c) {
  if (cur == N) {
    if (min({a, b, c}) == 0) return INF;
    return abs(a - A) + abs(b - B) + abs(c - C);
  }

  int ret0 = dfs(cur + 1, a, b, c);
  int ret1 = dfs(cur + 1, a + l[cur], b, c) + (a > 0 ? 10 : 0);
  int ret2 = dfs(cur + 1, a, b + l[cur], c) + (b > 0 ? 10 : 0);
  int ret3 = dfs(cur + 1, a, b, c + l[cur]) + (c > 0 ? 10 : 0);
  return min({ret0, ret1, ret2, ret3});
}

int main() {
  cin >> N >> A >> B >> C;
  for (int i = 0; i < N; ++i) cin >> l[i];

  cout << dfs(0, 0, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)}
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b) cout << c;
    else if(a == c) cout << b;
    else cout << a;
    return 0;
}

Measured memory_bytes: 256
N,M,X = map(int, input().split())
A = []
C = []
for i in range(N) :
    I = list(map(int,input().split()))
    C.append(I[0])
    A.append(I[1:])

ans = 10**12
for iv in range(1 << N) :
    r = [0] * M
    c = 0
    isOk = True
    for i in range(N) :
        if(not iv >> i & 1) :
            continue
        c += C[i]
        for j in range(M) :
            r[j] += A[i][j]
    for i in range(M) :
        if(r[i] < X) :
            isOk = False
    if(isOk) :
        ans = min(ans,c)
if(ans == 10**12) :
    ans = -1
print(ans)
            

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

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

  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  vector<int> P(N);
  rep(i, N) {
    cin >> P.at(i);
  }
  set<int> PS(P.begin(), P.end());


  int x = -1;
  rep(i, 100) {

    if (!PS.count(X - i)) {
      x = X - i;
      break;
    }

    if (!PS.count(X + i)) {
      x = X + i;
      break;
    }
  }
  cout << x << endl;
  // for (auto value : PS) {
  //   cout << value << endl;
  // }
}


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

const int MAX=2e5+9;
int n, a[MAX], ans[MAX];
vector<int> adj[MAX];
set<int> s;

void dfs(int cur, int par=-1) {
    int prv=-1;
    auto it=s.lower_bound(a[cur]);
    if (it!=s.end()) {
        prv=*it;
        s.erase(it);
    }

    s.insert(a[cur]);
    ans[cur]=s.size();
    for (int i=0; i<adj[cur].size(); ++i) {
        int child=adj[cur][i];
        if (child!=par) {
            dfs(child, cur);
        }
    }

    s.erase(a[cur]);
    if (prv!=-1)        s.insert(prv);
}

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

    cin >> n;
    for (int i=1; i<=n; ++i)        cin >> a[i];
    for (int i=0; i<n-1; ++i) {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs(1);
    for (int i=1; i<=n; ++i) {
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 28132
#include <stdio.h>
int main()
{
	int a[200005];
	int b[200005];
	int n, i, t;
	scanf("%d %d", &n, &t);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
		b[i] = a[i] + t;
	}
	for(i = 1 ; i <= n - 1 ; i++)
	{
		if(b[i] > a[i + 1])
		{
			a[i + 1] = b[i];
		}
	}
	int sum = 0;
	for(i = 1; i <= n ; i++)
	{
		sum = sum + b[i] - a[i];
	}
	printf("%d\n",sum);
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n%2!=0) {
    cout << "No" << endl;
    return 0;
  }
  char a[n];
  rep(i,n) cin >> a[i];
  string s="", t="";
  rep(i,n/2) {
    s += a[i];
    t += a[n/2+i];
  }
  cout << (s==t ? "Yes" : "No");
}


Measured memory_bytes: 256
n = int(input())
divAble = [0 for i in range(len(str(n)))]
digit = len(str(n))
count = 0


def search(nowDigit, num, maxDigit, okList):
    if nowDigit < maxDigit:
        search(nowDigit + 1, num * 10 + 3, maxDigit, [1, okList[1], okList[2]])
        search(nowDigit + 1, num * 10 + 5, maxDigit, [okList[0], 1, okList[2]])
        search(nowDigit + 1, num * 10 + 7, maxDigit, [okList[0], okList[1], 1])
    else:
        if num <= n:
            # print("num:{}".format(num))
            global count
            if sum(okList) == 3:
                count += 1
for i in range(digit+1):
    search(0, 0, i, [0, 0, 0])
print(count)
"""
# 7, 5, 3
# nがk桁だとして
# 先頭が1,2,3,4,5,6-> 7は0～k-1つ、7,8,9なら0～kつ
if int(str(n)[0]) >= 7:
    divAble[0] += 1
elif n > 10:
        divAble[1] += 1

if int(str(n)[0]) >= 5:
    divAble[0] += 1
elif n > 10:
        divAble[1] += 1

if int(str(n)[0]) >= 3:
    divAble[0] += 1
elif n > 10:
        divAble[1] += 1

for i in range(1, len(divAble)):
    divAble[i] += divAble[i-1]

print(divAble)
if sum(divAble) == 0:
    print(0)
    exit()
count = 1
for i in range(len(divAble)):
    if divAble[i] > 0:
        count *= divAble[i]
print(count)
"""


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll df(ll a, ll b)
{
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b < 0);
}

ll dc(ll a, ll b)
{
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b > 0);
}

int g[100][100];
const int WHITE = 1;
const int BLACK = 0;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;

    int r = max(1ll, dc(a - 1, 50));
    for (int i = 0; i < r; ++i)
    {
        for (int j = 0; j < 100 && a > 1; j += 2)
            g[2 * i][j] = WHITE, a--;
    }
    for (int i = 2 * r; i < 100; ++i)
        for (int j = 0; j < 100; ++j)
            g[i][j] = WHITE;

    int s = max(1ll, dc(b - 1, 50));
    for (int i = 2 * r + 1; i < 100 && b > 1; i += 2)
        for (int j = 0; j < 100 && b > 1; j += 2)
            g[i][j] = BLACK, b--;

    cout << 100 _ 100 << '\n';
    for (int i = 0; i < 100; ++i)
    {
        for (int j = 0; j < 100; ++j)
            cout << "#."[g[i][j]];
        cout << '\n';
    }
}


Measured memory_bytes: 256
m,n=gets.split.map(&:to_i)
if (m-n).abs>1
  p 0;exit
end
def v(n)
  return n%(10**9+7)
end
def f(n)
  c=1
  n.downto(1).each{|i|c=v(c*i)}
  return c
end
if m==n
  p v(f(m)*f(n)*2)
else
  p v(f(m)*f(n))
end


Measured memory_bytes: 1788
#include <stdio.h>
#define MAX_A 100000
#define MAX_B 50000

int main(){

  int n_1,n_2,i,j,sum=0,key,left,right,mid,flag;
  int a[MAX_A],b[MAX_B];


  scanf("%d",&n_1);
  for( i=0 ; i<n_1 ; i++ ){
    scanf("%d",&a[i]);
  }

  scanf("%d",&n_2);
  for( i=0 ; i<n_2 ; i++ ){
    scanf("%d",&b[i]);
  }

  for( j=0 ; j<n_2 ; j++ ){
    key = b[j];
    left = 0;
    right = n_1;
    while( left < right ){
      mid = (left + right)/2;
      if( key == a[mid] ){
	flag = 1;
	break;
      }
      if( key > a[mid] ) left = mid+1;
      else if( key < a[mid] ) right = mid;
    }
    if( flag == 1 ){
      sum++;
      flag = 0;
    }
  }

  printf("%d\n",sum);
  return 0;

}

Measured memory_bytes: 1184
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
    ll a;
    cin >> a;
    double d = 3.1415926535897;
    cout << 2 * a * d << endl;
}


Measured memory_bytes: 3788
S = input()

ql = []
for i in range(int(input())):
    ql.append(input())

rev = False
add_head = ""
add_tail = ""

for query in ql:
    if query == "1":
        rev = not rev
    else:
        _, tp, s2 = query.split(" ")

        if tp == "1":
            if not rev:
                add_head = s2 + add_head
            if rev:
                add_tail = add_tail + s2[::-1]
        else:
            if not rev:
                add_tail = add_tail + s2
            if rev:
                add_head = s2[::-1] + add_head

S = add_head + S + add_tail
if rev:
    S = S[::-1]

print(S)

Measured memory_bytes: 17104
#include <stdio.h>

int main(){
	
	int i;
	char o[51],e[51];
	
	scanf("%s\n%s",&o,&e);
	
	for(i=0;i<strlen(e);i++){
		printf("%c%c",o[i],e[i]);
	}
	
	if(strlen(o)>strlen(e))printf("%c",o[strlen(o)-1]);
	
	printf("\n");
	
	return 0;
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n, -1);
    vector<vector<int>> e(n, vector<int>());
    int a, b;
    REP(i, m) {
        cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
    }
  
    auto rec = [&](auto rec, auto p) {
        if (v[p] != -1) return v[p];
        int mx = 0;
        for (auto d : e[p]) {
            chmax(mx, rec(rec, d) + 1);
        }
        return v[p] = mx;
    };
  
    int mx = 0;
    REP(i, n) {
        chmax(mx, rec(rec, i));
    }
    cout << mx << endl;
}


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

using namespace std;
using ll = long long;

const ll INF = 1e15;

int main() {
  int n;
  cin >> n;
  vector<ll> v(n), pf(n);
  for (ll &x : v)
    cin >> x;
  pf[0] = v[0];
  for (int i=1; i<n; ++i)
    pf[i] = v[i] + pf[i-1];
  vector<vector<ll>> dp(n, vector<ll> (n, INF));
  for (int i=0; i<n; ++i)
    dp[i][i] = 0;
  for (int a=n-1; a>=0; --a) {
    for (int b=a+1; b<n; ++b) {
      for (int k=a; k<b; ++k) {
        dp[a][b] = min(dp[a][b], dp[a][k] + dp[k+1][b]);
      }
      if (a != b)
        dp[a][b] += pf[b] - (a ? pf[a-1] : 0);
    }
  }
  cout << dp[0][n-1] << '\n';
  return 0;
}


Measured memory_bytes: 1536
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int maxi = *max_element(ALL(a));
    int cnt = 0;
    rep(i, n) {
        if(maxi == a[i]){
            cnt++;
        }
    }

    int sec = 0;
    rep(i, n){
        if(a[i] != maxi){
            sec = max(a[i], sec);
        }
    }

    rep(i, n){
        if(cnt > 1){
            cout << maxi << endl;
            continue;
        }
        if(a[i] == maxi){
            cout << sec << endl;
        }else{
            cout << maxi << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3200
def main():
    h, w = [int(s) for s in input().split()]
    a = []

    for _ in range(h):
        a.append([int(s) for s in input().split()])

    r = []
    for i1, j1, i2, j2 in route(h, w):
        if a[i1][j1] % 2 != 0:
            a[i1][j1] -= 1
            a[i2][j2] += 1
            r.append((i1, j1, i2, j2))

    print(len(r))
    for i1, j1, i2, j2 in r:
        print(i1 + 1, j1 + 1, i2 + 1, j2 + 1)


def route(h, w):
    i = 0
    j = 0

    for _ in range(h * w - 1):
        if i % 2 == 0:
            if j != w - 1:
                # move right
                yield (i, j, i, j + 1)
                j += 1
            else:
                # move down
                yield (i, j, i + 1, j)
                i += 1
        else:
            if j != 0:
                # move left
                yield (i, j, i, j - 1)
                j -= 1
            else:
                # move down
                yield (i, j, i + 1, j)
                i += 1



main()


Measured memory_bytes: 22652
#include<bits/stdc++.h>
#define  lowbit(x) (x&(-x))
#define  ll long long
#define  ull unsigned long long
#define  max(a,b) (a>b?a:b)
#define  min(a,b) (a>b?b:a)
#define  PI acos(-1.0)
#define  fir first
#define  sec second
#define  SZ(x) (x.size())
#define  inf 0x3f3f3f3f
#define  PB push_back
#define  MP make_pair
#define  all(x) (x).begin(),(x).end()
#define  PII pair<int,int>
#define  E 2.7182818284590452353602874713527
using namespace std;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//const ll mod = 10000019;
//const ll phi_mod_prime=mod-1;
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
ll phi(ll n){ ll rea=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ rea=rea-rea/i;while(n%i==0) n/=i;}}if(n>1) rea=rea-rea/n;return rea;}
//a^(b%phi(mod)+phi(mod))%mod;
void exgcd(int a,int b,int &x,int &y,int &d){if(!b){x=1;y=0;d=a;}else exgcd(b,a%b,y,x,d),y-=a/b*x;}
inline int inv(int a,int p){int x,y,d;exgcd(a,p,x,y,d);x=(x%p+p)%p;return x;}
/********************************Head----Template**********************************************/


const int maxn=1e6+7;
int a[maxn];
int n,m,k;

int main (){
    string ss;cin>>ss;
    int o=0,x=0;
    for(char zx:ss){
        if(zx=='o') o++;
        else x++;
    }
    if(x>=8) cout<<"NO";
    else cout<<"YES";/*
    if(o==x&&) cout<<"YES";
    else if(o>x) cout<<"YES";
    else if(o>=8) cout<<"NO";
    else if(x>=8) cout<<"NO";
    else cout<<"NO";*/
    return 0;
}



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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    ll tmp;
    int ans;
    rep(i, 5) {
        cin >> tmp;
        if (tmp == 0) ans = i + 1;
    }

    // Process

    // Output
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n, tenant[4][3][10]{};
    int b, f, r, v;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        tenant[b - 1][f - 1][r - 1] += v;
    }

    for (int i = 0; i < 4 - 1; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                cout << " " << tenant[i][j][k];
            }
            cout << endl;
            // cout << tenant[i][j][9] << endl;
        }
        cout << "####################" << endl;
    }
    for (int j = 0; j < 3; j++)
    {
        for (int k = 0; k < 10; k++)
        {
            cout << " " << tenant[3][j][k];
        }
        cout << endl;
        // cout << tenant[3][j][9] << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
from collections import defaultdict

def dfs(here, p, d, conn, parent, depth, height):
    parent[here] = p
    depth[here] = d
    l_d, r_d = 0, 0
    for c in conn[here]:
        if c[0] >= 0:
            l_d = dfs(c[0], here, d + 1, conn, parent, depth, height)
        if c[1] >= 0:
            r_d = dfs(c[1], here, d + 1, conn, parent, depth, height)
    if len(conn[here]):
        height[here] = max(max(l_d, r_d) - d, 0)
    return max(l_d, r_d, d)

v_num = int(input())
conn = defaultdict(list)
in_v = [0 for n in range(v_num + 1)]
degree = [0 for n in range(v_num)]
for _ in range(v_num):
    v, left, right = (int(n) for n in input().split(" "))
    conn[v].append([left, right])
    in_v[left] += 1
    in_v[right] += 1
    degree[v] += int(left >= 0) + int(right >= 0)
for i, n in enumerate(in_v):
    if not n:
        root = i
        break
parent = [-1 for n in range(v_num)]
depth = [0 for n in range(v_num)]
height = [0 for n in range(v_num)]
dfs(root, -1, 0, conn, parent, depth, height)
sibling = [-1 for n in range(v_num)]
for i in range(v_num):
    for j in range(v_num):
        if i == j:
            continue
        elif parent[i] == parent[j]:
            sibling[i] = j
            break
v_type = ["" for n in range(v_num)]
for i in range(v_num):
    if i == root:
        v_type[i] = "root"
    elif degree[i] != 0:
        v_type[i] = "internal node"
    else:
        v_type[i] = "leaf"
for i in range(v_num):
    print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(i, parent[i], sibling[i], degree[i], depth[i], height[i], v_type[i]))

Measured memory_bytes: 8112
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char s[200000];
ll k,n;
int main(){
	cin >> s;
	cin >> k;
	n = strlen(s);

	REP(i,n) {
		s[i] -= 'a';
	}

	REP(i,n) {
		ll m = (26 - s[i]) % 26;
		if(m <= k) {
			s[i] = 0;
			k -= m;
		}
	}

	if(k > 0) {
		k %= 26;
		s[n - 1] += k;
		s[n - 1] %= 26;
	}

	REP(i,n) {
		s[i] += 'a';
	}
	cout << s << endl;

	return 0;
}


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

int main(){
  int64_t n,ans,cnt=1;
  cin >> n;
  queue<int64_t> q;
  for(int64_t ii=1;ii<10;ii++) q.push(ii);
  for(cnt=1;cnt<=n;cnt++){
    ans = q.front(); q.pop();
    if(ans%10 != 0) q.push(ans*10+(ans%10)-1);
    q.push(10*ans+(ans%10));
    if(ans%10 != 9) q.push(ans*10+(ans%10)+1);
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int a[5];
  for(int i=0;i<5;i++) {
    cin>>a[i];
  }
  for(int i=0;i<5;i++) {
    if(a[i]==0) {
      cout<<++i;
    }
  }
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;

	for (int i = 0; i <= a + b; i++) {
		if (i == a) {
			if (s[i] != '-') {
				cout << "No" << endl;
				return 0;
			}
		} else {
			int c = s[i] - '0';
			if (0 > c || 9 < c) {
				cout << "No" << endl;
				return 0;
			}
		}

	}

	cout << "Yes" << endl;
	return 0;
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<double> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  sort(V.begin(), V.end());

  double s = V[0];
  for (int i = 1; i < N; i++) {
    s = (s + V[i]) / 2;
  }
  cout << fixed << s << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  rep(i, n) cin >> x[i];
  rep(i, m) cin >> y[i];

  vector<ll> cx(n - 1, n - 1), cy(m - 1, m - 1);
  ll resx = 0, resy = 0;
  rep(i, n - 1) {
    cx[i] += i * (n - 2 - i);
    cx[i] %= mod;
    cx[i] = (cx[i] * (x[i + 1] - x[i])) % mod;
    resx = (resx + cx[i]) % mod;
  }
  rep(i, m - 1) {
    cy[i] += i * (m - 2 - i);
    cy[i] %= mod;
    cy[i] = (cy[i] * (y[i + 1] - y[i])) % mod;
    resy = (resy + cy[i]) % mod;
  }

  ll ans = (resx * resy) % mod;
  cout << ans << endl;






  
  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

using namespace std;

void output(int H[3][10]){
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 10; j++){
			printf(" %d",H[i][j]);
		}
		printf("\n");
	}
}


int main(){
	int H1[3][10],H2[3][10],H3[3][10],H4[3][10],n,h_num,f_num,r_num,div_num;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 10; j++){
			H1[i][j] = H2[i][j] = H3[i][j] = H4[i][j] = 0;
		}
	}
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d",&h_num,&f_num,&r_num,&div_num);
		switch(h_num){
		case 1:
			H1[f_num-1][r_num-1] += div_num;
			break;
		case 2:
			H2[f_num-1][r_num-1] += div_num;
			break;
		case 3:
			H3[f_num-1][r_num-1] += div_num;
			break;
		case 4:
			H4[f_num-1][r_num-1] += div_num;
			break;
		}
	}

	output(H1);
	printf("####################\n");
	output(H2);
	printf("####################\n");
	output(H3);
	printf("####################\n");
	output(H4);

}



Measured memory_bytes: 2688
#include <cmath>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 1000030
using namespace std;
inline void read(int &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}
inline void write(int x) {
    static const int maxlen = 100;
    static char s[maxlen];
    if (x < 0) {   putchar('-'); x = -x;}
    if (!x) { putchar('0'); return; }
    int len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';
    for (int i = len - 1; i >= 0; --i) putchar(s[i]);
}


int n,m;
int tot;
int a[maxn];
int g[210][210];
int now=0;
int dy=1;

void dfs(int x,int y){
while (a[now]==0)
    now++;
g[x][y]=now;
a[now]--;

if ( (y==m)&& ( dy==1) )
    {
        y=m;
        x++;
        dy=-1;
    }
else
    if ( (y==1) && (dy==-1) )
        {
            y=1;
            x++;
            dy=1;
        }
    else
        y+=dy;
if (x>n)
    return;
dfs(x,y);
}

int main(){
    read(n); read(m);
    read(tot);
    for (int i=1;i<=tot;i++)
        read(a[i]);
    now=1;
    dfs(1,1);
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<m;j++)
            printf("%d ",g[i][j]);
        printf("%d\n",g[i][m]);
    }
    return 0;
}

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

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

    vector<int> C(S.size() + 1, 0), D(T.size() + 1, 0);
    for(int i=0; i<S.size(); ++i) {
        if(S[i] == 'A') C[i + 1] = (C[i] + 1) % 3;
        else C[i + 1] = (C[i] + 2) % 3;
    }
    for(int i=0; i<T.size(); ++i) {
        if(T[i] == 'A') D[i + 1] = (D[i] + 1) % 3;
        else D[i + 1] = (D[i] + 2) % 3;
    }

    int q;
    cin >> q;
    for(int i=0; i<q; ++i) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        if((C[b] - C[a - 1] + 3) % 3 == (D[d] - D[c - 1] + 3) % 3) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int main() {
    int H,N;
    cin>>H>>N;
    vector<pair<int,int>> val(N);
    vector<int>a;
    for(int i=0;i<N;i++)
        cin>>val[i].first>>val[i].second;
    vector<vector<int>> ans(N,vector<int>(H+1,0));
    for(int i=0;i<N;i++){
        for(int j=1;j<=H;j++){
            if(i==0){
                if(j<=val[i].first)
                    ans[i][j]=val[i].second;
                else
                    ans[i][j]=ans[i][j-val[i].first]+val[i].second;
            }
            else{
                if(j<=val[i].first){
                    ans[i][j]=min(val[i].second,ans[i-1][j]);
                    // a.push_back(val[i].second,ans[i-1][j]);
                }
                else
                    ans[i][j]=min(ans[i][j-val[i].first]+val[i].second,ans[i-1][j]);
            }
        }
    }
        //   for(int i=0;i<N;i++){
        //     for(int j=0;j<=H;j++)
        //         cout<<ans[i][j]<<" ";
        //     cout<<"\n";  
        cout<<ans[N-1][H];
	return 0;
}

Measured memory_bytes: 39424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n, l;
    cin >> n >> l;
    int taste = 0, ans;
    for (int i = 0; i < n; i++) {
        taste += l + i;
    }
    if (l > 0) {
        ans = taste - l;
    } else if (l + n > 0) {
        ans = taste;
    } else {
        ans = taste + abs(l + n - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <list>
#include <algorithm>
using namespace std;

long long int n;
vector<long long int> v;
long int dp[100005];

long long int llmin(long long int a, long long int b){
    return (a < b) ? a : b;
}

long long int frog(int i){
    if(dp[i] != -1) return dp[i];
    if(i == n - 2) dp[i] = abs(v[i] - v[i+1]);
    else if(i == n-1) dp[i] = 0;
    else dp[i] = llmin(abs(v[i] - v[i+1]) + frog(i+1),abs(v[i]-v[i+2])+ frog(i+2));
    return dp[i];
}

int main(){
    cin >> n;
    int t;
    for(int i = 0;i < n;i++) dp[i] = -1;
    for(int i = 0;i < n;i++){cin >> t; v.push_back(t); }
    v.push_back(0);
    v.push_back(0);
    cout << frog(0) << endl;
    return 0;
}

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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<string> S(n);
  vector<int> cnt(26, 50);
  for(int i = 0; i < n; i++){
    cin >> S[i];
    for(int j = 0; j < 26; j++){
      char tmp = 'a' + j;
      int res = 0;
      for(auto x: S[i]){
	if(x == tmp){
	  res++;
	}
      }
      cnt[j] = min(cnt[j], res);
    }
  }
  for(int i = 0; i < 26; i++){
    char buf = 'a' + i;
    for(int j = 0; j < cnt[i]; j++){
      cout << buf ;
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int a,b;char c;cin>>a>>c>>b;
  if(c=='+')cout<<a+b<<endl;
  else cout<<a-b<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector <int> result(4, 0);
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "AC") {
      result[0]++;
    }
    if (S == "WA") {
      result[1]++;
    }
    if (S == "TLE") {
      result[2]++;
    }
    if (S == "RE") {
      result[3]++;
    }
    
  }

  cout << "AC x " << result[0] << endl;
  cout << "WA x " << result[1] << endl;
  cout << "TLE x " << result[2] << endl;
  cout << "RE x " << result[3] << endl;
}

Measured memory_bytes: 3604
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;
	int i=0,j=0;//int[] flag = new int['Z'];
	int oi = 0;
	try{
	    while(null!=(line = br.readLine())){
		line = 'A' + line;
		while((oi = line.indexOf("OI")) != -1){
		    //flag[line.charAt(oi-1)]++;
		    if(line.charAt(oi-1)=='J')j++;
		    if(line.charAt(oi-1)=='I')i++;
		    line = line.substring(oi + 1);
		}
		System.out.println(Integer.toString(j));//flag['J']));
		System.out.println(Integer.toString(i));//flag['I']));
		//flag['J'] = flag['I'] = 0;
		i=j=0;
	    }
	}
	catch(Exception e){
	    System.out.println(e.getMessage() + oi);
	}
    }
}

Measured memory_bytes: 17896
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int D, G;
        cin >> D >> G;
        if (D >= G)
        {
                swap(D, G);
        }

        if ((G - D) % 2 == 1)
        {
                cout << "IMPOSSIBLE" << endl;
                return 0;
        }
        else
        {
                cout << D + ((G - D) / 2) << endl;
                return 0;
        }

        return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

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

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

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

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

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

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

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

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

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

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

fn gcd(a: i64, b: i64) -> i64 {
    if a > b {
        gcd(b, a)
    }
    else if a == 0 {
        b
    }
    else {
        gcd(b%a, a)
    }
}

fn solve() {
    input!(
        a: i64,
        b: i64,
    );

    println!("{}", a * b / gcd(a, b));

}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define sc scanf
#define pf printf

using namespace std;

int main() {
	int arr[3];
	for(int i=0;i<3;i++){
		sc("%d",&arr[i]);
	}
	sort(arr,arr+3);
	int ans=(arr[2]*10)+arr[0]+arr[1];
	pf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1010, inf = 0x3f3f3f3f;
int n;
int dp[N][N * 5], x[N], g[5 * N];
vector<int> G[N]; 
// dp[u]:选不同颜色最少能给这种颜色留下的体积 
void dfs(int u)
{
	memset(dp[u], inf, sizeof(dp[u]));
	dp[u][0] = 0;	
	for(int i = 0; i < G[u].size(); ++i)
	{
		int v = G[u][i];
		dfs(v);
		static int f[N * 5];
		memset(f, inf, sizeof(f));
		for(int i = N * 5 - x[v]; i >= 0; --i) f[i + x[v]] = min(f[i + x[v]], dp[u][i] + g[v]);
		for(int i = N * 5 - g[v]; i >= 0; --i) f[i + g[v]] = min(f[i + g[v]], dp[u][i] + x[v]);
		copy(f, f + N * 5, dp[u]);
	}
	g[u] = inf;
	for(int i = 0; i <= x[u]; ++i) g[u] = min(g[u], dp[u][i]);
}
int main()
{
	scanf("%d", &n);
	for(int i = 2; i <= n; ++i)
	{
		int p;
		scanf("%d", &p);
		G[p].push_back(i);
	}
	for(int i = 1; i <= n; ++i) scanf("%d", &x[i]);
	dfs(1);
	puts(g[1] == inf ? "IMPOSSIBLE" : "POSSIBLE");
	return 0;
}

Measured memory_bytes: 20096
#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef long long LL; 
int atoi(char c){
    return c-'a';
}
int main()
{ 
    string n;
    cin>>n;
    if(atoi(n[0])<26&&atoi(n[0])>=0)
    {cout<<'a'<<endl;}
    else{cout<<'A'<<endl;}
    return 0;
}

Measured memory_bytes: 3616
from sys import stdin, stdout
def gmi(): return map(int, stdin.readline().strip().split())
def gms(): return map(str, stdin.readline().strip().split())
def gari(): return list(map(int, stdin.readline().strip().split()))
def gars(): return list(map(int, stdin.readline().strip().split()))
def gs(): return stdin.readline().strip()
def gls(): return list(stdin.readline())
def gi(): return int(stdin.readline())

s = list(gs())
t = gs()
n, m = len(t), len(s)
ans = 1001
for i in range(m - n + 1):
    M = 0
    for j in range(n):
        if (t[j] != s[i + j]):
            M += 1
    ans = min(M, ans)
print(ans)








Measured memory_bytes: 65448
import bisect
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort()
cc.sort()

cnt = 0
cnt = sum([bisect.bisect_left(aa,b) * (n - bisect.bisect_right(cc,b)) for b in bb])
print(cnt)

Measured memory_bytes: 23360
#include <stdio.h>
#include <stdlib.h>

void swap(long long int x[],int i,int j){
	int tmp=x[i];
	x[i]=x[j];
	x[j]=tmp;
}
void Qsort(long long int x[],int left,int right){
	int i,j;
	int pivot;

	i=left;
	j=right;

	pivot=x[(left+right)/2];

	while(true){
		while(x[i]<pivot)i++;
		while(x[j]>pivot)j--;
		if(i>=j)break;
		swap(x,i,j);
		i++;
		j--;
	}
	if(left<i-1)Qsort(x,left,i-1);
	if(j+1<right)Qsort(x,j+1,right);
}

int main(void){
	int n;
	long long int *t;

	scanf("%d",&n);
	t=(long long int *)malloc(sizeof(long long int)*n);

	for(int i=0; i<n; i++){
		scanf("%lld",&t[i]);
	}
	Qsort(t,0,n-1);

	int ans;
	long long int total=t[0];
	for(int i=0; i<n; i++){
		int j=i+1;
		//printf("Check No.%d\n",i);
		for(;j<n;j++){
			//printf("Now total=%d,index=%d\n",total,j);
			//printf("%d %d\n",total*2,t[j]);
			if(total*2>=t[j]){
				total+=t[j];
			}
			else{
				total+=t[j];
				break;
			}
		}
		if(j==n)ans=n-i;
		i=j-1;
	}

	printf("%d\n",ans);
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  bool echo = true;
  if (N%2==0) {
    for (int i=0; i<N/2; i++) {
      if (S.at(i)!=S.at(i+N/2)) {
        echo = false;
        break;
      }
    }
  }
  string ans = "No";
  if (echo && N%2==0) {
    ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256