akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int N,K;
string t[16];
string ans="";
bool used[16];
int f[16];
int INF=1e9+7;

bool check(int key){
  vector<int> v;
  for(int i=0;i<K;i++){
    int id=t[key][i]-'A';
    v.push_back(f[id]);
  }
  for(int i=0;i+1<K;i++)
    if(v[i]>v[i+1])return false;
  return true;
}

void update(int key){
  for(int i=0;i<K;i++){
    int id=t[key][i]-'A';
    f[id]=-100-i;
  }
  vector<int> X;
  for(int i=0;i<N;i++){
    if(f[i]==INF)continue;
    X.push_back(f[i]);
  }
  sort(X.begin(),X.end());
  X.erase( unique( X.begin(),X.end() ), X.end() );
  for(int i=0;i<N;i++){
    if(f[i]==INF)continue;
    f[i]=lower_bound(X.begin(),X.end(),f[i])-X.begin();
  }
}

typedef unsigned long long ull;

ull B=1e9+9;
map< ull, bool >  mp;

bool dfs(int depth=0){
  ull key=0;
  for(int i=0;i<N;i++){
    key*=B;
    if(f[i]==INF) key+= 1999;
    else key+=(f[i]+1);
    key*=B;
    if(used[i])key+=(1<<i);
  }
  if(mp[key])return false;
  mp[key]=true;
  
  if(depth==N)return true;
  int tmp[16];
  for(int i=0;i<N;i++)tmp[i]=f[i];
  
  for(int i=0;i<N;i++){
    if(used[i])continue;
    if(!check(i))continue;
    
    update(i);
    used[i]=true;
    
    if(dfs(depth+1)){
      ans.push_back('A'+i);
      return true;
    }
    
    used[i]=false;
    for(int j=0;j<N;j++)f[j]=tmp[j];
  }
  return false;
}

int main(){
  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>t[i];
  fill(used,used+N,false);
  fill(f,f+N,INF);
  dfs();
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

ll P = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vll c(n);
  for (int i = 0; i < n; i++)
    cin >> c[i];
  vll sum(202020);
  vll dp(202020);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    dp[i + 1] = dp[i];
    ll tmp = dp[i + 1];
    if (i < n && c[i + 1] == c[i])
      continue;
    dp[i + 1] += sum[c[i]];
    dp[i + 1] %= P;
    sum[c[i]] += tmp;
    sum[c[i]] %= P;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> num(10, 0);
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            ++ num[a];
        }

        for(int i=0; i<10; ++i){
            if(num[i] == 0)
                cout << '-' << endl;
            else
                cout << string(num[i], '*') << endl;
        }
    }
}

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

int P[10010];
void init(int N) {
	for (int i = 0; i < N; ++i) P[i] = i;
}
int root(int a) {
	if (P[a] == a) return a;
	return P[a] = root(P[a]);
}
bool is_same_set(int a, int b) {
	return root(a) == root(b);
}
void unite(int a, int b) {
	P[root(a)] = root(b);
}

signed main() {
	int n, q;
	cin >> n >> q;

	init(n);
	
	for (int i = 0; i < q; ++i) {
		int com, x, y;
		cin >> com >> x >> y;

		if (com == 0) {
			unite(x, y);
		}
		else if (com == 1) {
			cout << is_same_set(x, y) << endl;
		}
	}
}



Measured memory_bytes: 3244
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]

if n%3:
    p = a[0]
    for i in a:
        if i != p:
            print("No")
            exit()
    else:
        print("Yes")
        exit()


d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

#print(d)

if len(d) >= 4:
    print("No")
    exit()
elif len(d) == 3:
    res = 0
    for i in d:
         res ^= i
    if res != 0:
        print("No")
        exit()
    for i in d:
        if d[i] != n//3:
            print("No")
            exit()
    else:
        print("Yes")
        exit()
    
elif len(d) == 2:
    a.sort()
    p = a[0]
    q = a[-1]
    cp = d[p]
    cq = d[q]
    if cp != 2*n//3 and cq != 2*n//3:
        print("No")
        exit()
    elif cp == 2*n//3:
        if q != 0:
            print("No")
            exit()
        else:
            print("Yes")
            exit()
    elif cq == 2*n//3:
        if p != 0:
            print("No")
            exit()
        else:
            print("Yes")
            exit()
            
    
elif len(d) == 1:
    if a[0] != 0:
        print("No")
        exit()
    else:
        print("Yes")
        exit()




Measured memory_bytes: 14212
#include <iostream>

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long max = -1;
	long long min = INT32_MAX;
	int n;
	cin >> n;
	int tmp;
	while (n--) {
		cin >> tmp;
		if (tmp < min) min = tmp;
		if (tmp > max) max = tmp;
	}
	
	cout << max - min << endl;
	// system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int A,B,C,ans;
  cin >> A >> B >> C;
  if (A>=B and B>=C)
    ans = A*10+B+C;
  else if (A>=C and C>=B)
    ans = A*10+C+B;
  else if (B>=A and A>=C)
    ans = B*10+A+C;
  else if (B>=C and C>=A)
    ans = B*10+C+A;
  else if (C>=A and A>=B)
    ans = C*10+A+B;
  else if (C>=B and B>=A)
    ans = C*10+B+A;
  cout << ans <<"\n";
}
//ABC ACB BAC BCA CAB CBA 

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
int N;
scanf("%d", &N);

int arr[4] = {N/1000, (N/100)%10,  (N/10)%10, N%10};

int flag = 0;
if (arr[0] == arr[1] && arr[1] == arr[2] ||arr[1] == arr[2] && arr[2] == arr[3]) flag = 1;

if (flag == 1) printf("Yes");
else printf("No");

return 0;

}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		string s=sc.S;
		s=" "+s;
		int[] h=new int[26];
		long[] dp=new long[s.Length];
		long m=0;
		for(int i=s.Length-1;i>0;i--){
			h[s[i]-'a']++;
			dp[i]=(1+m)%mod;
			if(h[s[i]-'a']>1){dp[i]=(dp[i]*Mi(h[s[i]-'a']))%mod;}
			m=(m+dp[i])%mod;
		}
		Console.WriteLine("{0}",m);
	}
	static long Mi(long a){
		long b=mod,u=1,v=0;
		while(b>0){
			long t=a/b;
			a-=t*b;a^=b;b^=a;a^=b;
			u-=t*v;u^=v;v^=u;u^=v;
		}
		u%=mod;
		if(u<0){u+=mod;}
		return u%mod;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}


Measured memory_bytes: 14304
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
vector<long> inputVector(long n)
{
    vector<long> vec(n);
    rep(i, n)
    {
        scanf("%d", &vec.at(i));
    }
    return vec;
}
int main()
{
    long n, k;
    cin >> n >> k;
    long loc = 1;
    set<long> exp;
    vector<long> a = inputVector(n);
    a.insert(a.begin(), 0);
    long ans = 0;
    long num = 0;
    bool check = true;
    exp.insert(1);
    while (check == true)
    {
        loc = a.at(loc);
        check = exp.insert(loc).second;
        num++;
    }
    if (num > k)
    {
        loc = 1;
        rep(i, k)
        {
            loc = a.at(loc);
        }
        cout << loc << endl;
        return 0;
    }
    long num2 = 0;
    long loopbegin = loc;
    loc = 1;
    // cout << num << " " << loopbegin << endl;
    while (loc != loopbegin)
    {
        loc = a.at(loc);
        num2++;
    }
    long loopnum = num - num2;
    k -= num2;
    k %= loopnum;
    rep(i, k)
    {
        loc = a.at(loc);
    }
    cout << loc << endl;
}

Measured memory_bytes: 14132
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, a;
    cin >> n;
    vector<int> arr(n);
    int ind, m;
    m=-1;
    F0R(i,n)
    {
        cin >> arr[i];
        if(arr[i]>m)
        {
            ind=i;
            m=arr[i];
        }
    }
    int se=-1;
    F0R(i,n)
    {
        if(arr[i]>se && i!=ind)
            se=arr[i];
    }
    F0R(i,n)
    {
        if(i==ind)
            cout << se << endl;
        else
            cout << m << endl;
    }

    return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char c[n+2];
    c[0] = 'R'; c[n+1] = 'L';
    rep(i,n) c[i+1] = s[i];
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(c[i] == 'R' && c[i+1] == 'R') ans++;
        if(c[i] == 'L' && c[i-1] == 'L') ans++;
    }

    cout << min(ans+2*k,n-1) << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            bool f = true;
            for(int k = 0; k < n; k++){
                if(k == i){
                    if(k+1 != a[j]) f = false;
                }else if(k == j){
                    if(k+1 != a[i]) f = false;
                }else{
                    if(k+1 != a[k]) f = false;
                }
            }
            if(f){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll a,b,c,x,y; cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if(a+b>2*c){
        ll mn = min(x,y);
        ans += 2 * mn * c;
        x -= mn;
        y -= mn;
        if(x>0){
            ans += x * min(a,2*c);
        }else{
            ans += y * min(b,2*c);
        }
    }else{
        ans = a*x + b*y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define false 0;
#define true 1;

typedef struct{
  char mark;
  int value;
}card;

int isStable(card[],card[],int);

int main()
{
  int N,i,j,c,minj;
  card C[36],t,in[36],C2[36];

  scanf("%d",&N);

  if(N < 1 || N >36) return 0;

  for(i = 0 ; i < N ; i++ )
    {
      scanf(" %c %d",&C[i].mark,&C[i].value);
      in[i] = C[i];
      C2[i] = C[i];
    }

  for(i = 0 ; i <= N-1 ; i++)
    {
      for(j = N-1 ; j >= i+1 ; j--)
	{
	  if(C[j].value < C[j-1].value)
	    {
	      t = C[j];
	      C[j] = C[j-1];
	      C[j-1] = t;
	    }
	}
    }
  for(i = 0 ; i < N ; i++)
    {
      printf("%c%d",C[i].mark,C[i].value);
      if(i < N-1) printf(" ");
    }

  printf("\n");

  if(isStable(in,C,N)) printf("Stable\n");
  else printf("Not stable\n");

  for(i = 0 ; i <= N-1 ; i++)
    {
      minj = i;
      for(j = i ; j <= N-1 ; j++)
	{
	  if(C2[j].value < C2[minj].value)
	    {
	      minj = j;
	    }
	}
      t = C2[i];
      C2[i] = C2[minj];
      C2[minj] = t;
    }

  for(i = 0 ; i < N ; i++)
    {
      printf("%c%d",C2[i].mark,C2[i].value);
      if(i < N-1) printf(" ");
    }
   
  printf("\n");
 
  if(isStable(in,C2,N)) printf("Stable\n");
  else printf("Not stable\n"); 
  
  return 0;
}

int isStable(card *in,card *out,int N)
{
  int i,j,a,b;

  for(i = 0 ; i <= N-1 ; i++)
    {
      for(j = i+1 ; j <= N-1 ; j++)
	{
	  for(a = 0 ; a <= N-1 ; a++)
	    {
	      for(b = a+1 ; b <= N-1 ; b++)
		{
		  if(in[i].value == in[j].value && in[i].value == out[b].value && in[i].mark == out[b].mark && in[j].value == out[a].value && in[j].mark == out[a].mark) return false;
		}
	    }
	}
    }
  
  return true;
}



Measured memory_bytes: 2124
#include <stdio.h>

int main(){
	int W, H, x, y;
	int judge = 0;
	double s;

	scanf("%d %d %d %d", &W, &H, &x, &y);

	if(W == (x * 2) && H == (y * 2))
		judge = 1;

	if(W == 0 || H == 0)
		judge = 1;

	s = (double)W * (double)H / 2;

	printf("%.6lf %d",s, judge);
}

Measured memory_bytes: 128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s,t = map(str,input().split())
    a,b = readInts()
    m = input()
    if m == s:
        print(a-1,b)
    else:
        print(a,b-1)
if __name__ == '__main__':
  main()


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	if(a>c) swap(a,c);
	if(b>c) swap(b,c);
	cout<<(a*b/2)<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        
        int ans = 0;
        for (int i = 0; i < N; i++) {
        	if (A.charAt(i) != B.charAt(i) && A.charAt(i) == C.charAt(i)) {
        		ans+=1;
        	} else if (A.charAt(i) == B.charAt(i) && A.charAt(i) != C.charAt(i)) {
        		ans+=1;
        	} else if (B.charAt(i) == C.charAt(i) && A.charAt(i) != C.charAt(i)) {
        		ans+=1;
        	} else if (A.charAt(i) != B.charAt(i) && A.charAt(i) != C.charAt(i)) {
        		ans+=2;
        	}
        }
        
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 22100
use proconio::input;

fn main() {
  input!{
    n: usize,
    mut x: usize,
    m: usize,
  }
  
  let mut dp = vec![None;m];
  let mut val = x;
  let mut r = 0;
  let mut i = 0;
  while i < n {
    if let Some((c, v)) = dp[val] {
      let w = i - c;
      let l = n / w - 3;
      if l > 3 {
        r += (r-v)*l;
        i += w * l;
      }
      while i < n {
        r += val;
        i += 1;
        val = val * val % m;
      }
    } else {
      dp[val] = Some((i, r));
      r += val;
      i += 1;
      val = val * val % m;
    }
  }
  println!("{}", r);
}

Measured memory_bytes: 4364
N = int(input())
A = list(map(int, input().split()))
Yen = 1000

for i in range(N - 1):
  if A[i] < A[i + 1]:
    Yen = Yen // A[i] * A[i + 1] + Yen % A[i]
  
print(Yen)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	cin >> S;
	ll Q;
	ll C = 0;
	string P, R;
	cin >> Q;
	for (k = 0; k < Q; k++) {
		ll t;
		cin >> t;
		if (t == 1) {
			C++;
		}
		else {
			ll f;
			char c;
			cin >> f >> c;
			if ((C + f) % 2 == 1) {
				P += c;
			}
			else {
				R += c;
			}
		}
	}
	if (C % 2 == 0) {
		reverse(P.begin(), P.end());
		cout << P << S << R;
	}
	else {
		reverse(S.begin(), S.end());
		reverse(R.begin(), R.end());
		cout << R << S << P;
	}
}


Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
stack<int> P;
stack< pair<int,int> > S;
vector<int> ans;
char str[20002];
int main(){
	scanf("%s",str);
	int sum=0;
	for(int i=0;str[i];i++)
		if(str[i]=='\\') P.push(i);
		else if(str[i]=='/' && !P.empty()){ 
			int j = P.top(); P.pop();
			int a = i-j;
			sum += a;
			while(!S.empty() && j<S.top().first){
				a += S.top().second;
				S.pop();
			}
			S.push(make_pair(j,a));
		}
	while(!S.empty()){
		ans.push_back(S.top().second);
		S.pop();
	}
	reverse(ans.begin(),ans.end());
	printf("%d\n",sum);
	printf("%d",ans.size());
	for(int i=0;i<ans.size();i++){
		printf(" %d",ans[i]);
	}
	putchar('\n');
	//system("pause");
    return 0;
}


Measured memory_bytes: 3324
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N; cin >> N;
	int A[200100];
	for (int i = 0; i < N; ++i)cin >> A[i];
	int right = 0;
	ll sum = 0;
	ll res = 0;
	for (int left = 0; left < N; ++left) {
		while (right < N&&(sum^A[right]) == (sum + A[right])) {
			sum += A[right];
			++right;
		}
		res += (right - left);
		if (right == left)++right;
		else sum -= A[left];
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    class Program
    {

        static int[,] stack;
        static int[] last;

        static void Push(int t, int key)
        {
            stack[t, last[t]] = key;            
            last[t]++;
        }


        static void Peek(int t)
        {      
            if(last[t] - 1 < 0)
            {
                return;
            }
            Console.WriteLine(stack[t, last[t] - 1]);
        }

        static void Pop(int t)
        {
            if(last[t] - 1 < 0)
            {
                return;
            }
            last[t]--;
        }


        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int q = int.Parse(input[1]);

            stack = new int[n, q];
            last = new int[n];

            int order;
            int t;
            int x;
            for(int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split(' ');

                order = int.Parse(input[0]);
                t = int.Parse(input[1]);

                if (order == 0)
                {
                    x = int.Parse(input[2]);
                    Push(t, x);
                }
                else if(order == 1)
                {

                    Peek(t);

                }
                else
                {
                    Pop(t);
                }

            }
                  
        }
    }
}



Measured memory_bytes: 798312
k = gets.to_i
a = gets.split.map(&:to_i)

max = 10**18
min = 0
while max-min > 1
    mid = (max+min)/2
    rem = mid*1
    k.times do |i|
        rem -= rem%a[i]
    end
    if rem > 2
        max = mid
    else
        min = mid
    end
end
ans_max = min

max = 10**18
min = 0
while max-min > 1
    mid = (max+min)/2
    rem = mid*1
    k.times do |i|
        rem -= rem%a[i]
    end
    if rem >= 2
        max = mid
    else
        min = mid
    end
end
ans_min = max

puts (ans_max < ans_min) ? "-1" : "#{ans_min} #{ans_max}"       

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;


int main ()
{
  prep();
  int n, d;
  cin >> n >> d;
  d *= 2;
  d++;
  int sum = n/d;
  if (n%d != 0){
      sum++;
  }
  cout << sum;
  return 0; 
}


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

using namespace std;

int main()
{
  int n,m,i,j;
  cin >> n >> m;
  vector <int> v;
  
  for(i=1;i<=n;i++){
    cin >> j;
    v.push_back(j);
  }
  
  int s = accumulate(v.begin(),v.end(),0);
  double bound = s/(4.0*m);
  int k = 0;
  
  for(i=0;i<n;i++){
    if(v[i] >= bound) k++;
  }
  
  if(k >= m) cout << "Yes";
  else cout << "No";
  
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 900000;
const int K = 60;
const int mod = 1e9 + 7;
int a[N], used[N], cnt[N], s[N], n, m, b[N], ip = 1, qq[N], ans[N];
vector < int > q[N];
bool cmp1 (pair < int, int > p1, pair < int, int > p2){
    if ((p1.S > 0 || (p1.S == 0 && p1.F > 0)) && ((p2.F < 0 && p2.S == 0) || p2.S < 0)) return 1;
    if ((p2.S > 0 || (p2.S == 0 && p2.F > 0)) && ((p1.F < 0 && p1.S == 0) || p1.S < 0)) return 0;
    return (p1.S * p2.F > p1.F * p2.S);
}
bool cmp2 (pair < int, int > p1, pair < int, int > p2){
    if ((p1.S > 0 || (p1.S == 0 && p1.F > 0)) && ((p2.F < 0 && p2.S == 0) || p2.S < 0)) return 1;
    if ((p2.S > 0 || (p2.S == 0 && p2.F > 0)) && ((p1.F < 0 && p1.S == 0) || p1.S < 0)) return 0;
    return (p1.S * p2.F < p1.F * p2.S);
}
pair < int, int > p[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> p[i].F >> p[i].S;
    }
    double ans = 0;
    sort(p, p + n, cmp1);
    for (int i = 1; i <= n; i++){
        for (int l = 0; l < n; l++){
            int x = 0;
            int y = 0;
            for (int j = l; j < l + i; j++){
                x += p[j % n].F;
                y += p[j % n].S;
            }
          //  cout << x << " -- " << y << " " << i << " " << l << endl;
            ans = max(ans, (double) (x * x + y * y));
        }
    }
    sort(p, p + n, cmp2);
    for (int i = 1; i <= n; i++){
        for (int l = 0; l < n; l++){
            int x = 0;
            int y = 0;
            for (int j = l; j < l + i; j++){
                x += p[j % n].F;
                y += p[j % n].S;
            }
          //  cout << x << " -- " << y << " " << i << " " << l << endl;
            ans = max(ans, (double) (x * x + y * y));
        }
    }
    cout <<  fixed << setprecision(20) << sqrt(ans);
}


Measured memory_bytes: 24832
#include <utility>
#include <cstdio>
#include <queue>
#define mp std::make_pair
int arr[200005], bit[200005], n; 
std::pair<int, int> st[2][200005][25]; 
inline int query(int l, int r, int x)
{
	x ^= l & 1; 
	int len = bit[r - l + 1]; 
	return std::min(st[x][l][len], st[x][r - (1 << len) + 1][len]).second; 
}
struct data
{
	int l, r, x, y; 
	data(int _l, int _r)
	{
		l = _l; 
		r = _r; 
		x = query(l, r, 0); 
		y = query(x, r, 1); 
		fflush(stdout); 
	}
	inline bool operator <(const data &a) const
	{
		if (arr[x] == arr[a.x])
			return arr[y] > arr[a.y]; 
		return arr[x] > arr[a.x]; 
	}
}; 
std::priority_queue<data> que; 
inline void add(int l, int r)
{
	if (l < r)
		que.push(data(l, r)); 
}
int main()
{
	// freopen("ARC080-E.in", "r", stdin); 
	scanf("%d", &n); 
	for (int i = 0; i < n; i++)
	{
		scanf("%d", arr + i); 
		st[i & 1][i][0] = mp(arr[i], i);
		st[i & 1 ^ 1][i][0] = mp(1e9, i); 
	}
	for (int i = 2; i <= n; i++)
		bit[i] = bit[i >> 1] + 1; 
	for (int x = 0; x < 2; x++)
	{
		for (int j = 1; j < 20; j++)
		{
			for (int i = 0; i < n; i++)
			{
				st[x][i][j] = st[x][i][j - 1]; 
				if (i + (1 << j - 1) < n)
					st[x][i][j] = std::min(st[x][i][j], st[x][i + (1 << j - 1)][j - 1]); 
			}
		}
	}
	que.push(data(0, n - 1)); 
	while (!que.empty())
	{
		data u = que.top(); 
		que.pop(); 
		printf("%d %d ", arr[u.x], arr[u.y]);
		add(u.l, u.x - 1); 
		add(u.x + 1, u.y - 1); 
		add(u.y + 1, u.r); 
	}
	return 0; 
}


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

bool func(int M, vector<int>& A){
    int N = A.size();

    vector<vector<bool>> dp(N+1, vector<bool>(M+1, false));

    dp[0][0] = true;
    for(int i=0; i<N; i++){
        for(int s=0; s<=M; s++){
            dp[i+1][s] = dp[i][s];
            if(s-A[i]>=0)
                dp[i+1][s] = dp[i+1][s] | dp[i][s-A[i]];
        }
    }
    return dp[N][M];
}

void solve(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)
        cin >> A[i];
    int Q;
    cin >> Q;
    while(Q--){
        int M;
        cin >> M;
        if(func(M, A)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}



Measured memory_bytes: 3168
#include <stdio.h>
#include <string.h>


int main (){

    int x;
    int n = 0;
    int big = 0;
    scanf("%d", &x);
    char string[105];
     scanf("%s", string);
    for(int i = 0; i < strlen(string); i++){
        if(string[i] == 'I'){
            n +=1;
            if(big < n) big = n;
        }else n -= 1;
    }
    printf("%d", big);



    return 0;
}

Measured memory_bytes: 1636
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define nmax 200010

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

int k, n;
int a[2 * nmax];

int main()
{
    scanf("%d %d", &k, &n);

    for (int i = 1; i <= n; i++) {

        scanf("%d", &a[i]); a[i + n] = k + a[i];
    }

    int answer = 1e9;

    for (int i = n; i <= 2 * n; i++) answer = min(answer, a[i] - a[i - n + 1]);

    printf("%d", answer);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 1792
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int output = 0;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int j=0;j<n;j++){
		cin>>b[j];
		output+=b[j];
	}
	for(int i=0;i+1<n;i++)cin>>c[i];
	for(int i=0;i+1<n;i++){
		if(a[i+1]==a[i]+1){
			output+=c[a[i]-1];
		}
	}
	cout<<output;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
speed_up;
string s;
int n, i;
cin>>s;
n = s.length();
vector<char> vec;
for(i = 0; i<n; i++)
{
    int a;
    a = s[i];
    if(a == 'B')
    {
        if(vec.size() == 0) continue;
        else vec.pop_back();
    }
    else
        vec.push_back(a);

}
for(i = 0; i<vec.size(); i++)
{
    cout<<vec[i];
}
cout<<endl;



return 0;
}


Measured memory_bytes: 3596
//
// Created by P218024 on 2018/04/20.
//


#include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0; i<(int)(n); i++)
#define REPN(i, m, n) for(int i=(int)m; i<(int)(n); i++)
#define REP_REV(i, n) for(int (i)=(int)n-1; i>=0; i--)
#define debug(x) cout << #x << ": " << x << endl;

using namespace std;

int main() {

//    ifstream in("C:\\Users\\P218024\\Documents\\Cpp Projects\\abc094\\sample.txt");
//    cin.rdbuf(in.rdbuf());

    int n, m, x;
    cin >> n >> m >> x;
    int A[n] = {0};
    int a;
    REP(i, m) {
        cin >> a;
        A[a] = 1;
    }

    int ans1=0, ans2=0;
    REPN(i, x, n) ans1 += A[i];
    REP_REV(i, x) ans2 += A[i];

    cout << ((ans1 < ans2) ? ans1 : ans2) << endl;

    return 0;
}

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

int main() {
	
	int N;
	cin >>N;
	
	vector<int> weights(N);
	
	for(int i=0; i<N; i++){
		
		cin >>weights.at(i);
		
	}
	
	vector<int> diff(N);
	
	for(int i=0; i<N; i++){
		
		int T, former, latter;
		former=0;
		latter=0;
		T=i;
		
		for(int j=0; j<T; j++){
			
			former+=weights.at(j);
			
		}
		for(int j=0; j<N-T; j++){
			
			latter+=weights.at(N-1-j);
			
		}
		
		diff.at(i)=abs(latter-former);
		
	}
	
	cout <<*min_element(diff.begin(),diff.end()) <<endl;
	
	
}

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


int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  for(int i = 0; i < S.size();i++){
    char ans = S.at(i) + N;
    if(ans > 'Z'){
      ans = ans - 'Z' + 'A'-1;
    } 
    cout << ans;
  }
}

Measured memory_bytes: 3636
<?php

$N = trim(fgets(STDIN));
$count = 0;
$len_check = [];
for($i=1; $i<=$N; $i*=10){
    $digit = count(str_split($i));
        
    if($digit%2 == 1){
        if ($digit == 1 ) {
            for($j=1; $j<10; $j++){
                if($N < $j){
                    break;
                }
                $count += 1;
            }
        }else{
            $tmp = 1;
            for($d=1; $d<=($digit-1); $d++){
                $tmp *= 10;
            }
            for($j=$tmp; $j<$tmp*10; $j++){
                if($N < $j){
                    break;
                }
                $count += 1;
            }
        }
        
    }
}
echo $count;
?>

Measured memory_bytes: 16100
import java.util.*

fun main(args: Array<String>) {
  
    val scanner = Scanner(System.`in`)
    val N = scanner.nextLong()
    val M = scanner.nextLong()
    val parsonPositionList = (1..N).map { Pair(scanner.nextLong(), scanner.nextLong()) }.toList()
    val checkPointList = (1..M).map { Pair(scanner.nextLong(), scanner.nextLong()) }.toList()
    for (personPosition in parsonPositionList) {
        var minValue = Long.MAX_VALUE
        var minNum = 0
        checkPointList.forEachIndexed { index, checkPoint ->
            val abs = Math.abs(checkPoint.first - personPosition.first) + Math.abs(checkPoint.second - personPosition.second)
            if (minValue > abs) {
                minValue = abs
                minNum = index + 1
            }
        }
        println(minNum)
    }
}

Measured memory_bytes: 21896
#include<iostream>
using namespace std;
struct card{
	char c;
	int in;
	int number;
};
int partition(card A[], int p, int r){
	int memo=A[r].in;
	int i=p-1;
	for(int j=p; j<r; j++){
		int k=A[j].in;
		if(k<=memo){
			i++;
			card s=A[i];
			A[i]=A[j];
			A[j]=s;
		}
	}
	card m=A[i+1];
	A[i+1]=A[r];
	A[r]=m;
	return i+1;
}
void quickSort(card A[], int p, int r){
	if(p<r){
		int q=partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}
int main(){
	bool flag=true;
	int n,i;
	cin>>n;
	card c[n];
	for(i=0; i<n; i++){
		cin>>c[i].c>>c[i].in;
		c[i].number=i;
	}
	quickSort(c, 0, n-1);
	for(i=0; i<n-1; i++){
		if(c[i].in==c[i+1].in && c[i].number>c[i+1].number){
			flag=false;
			break;
		}
	}
	if(flag==true)
		cout<<"Stable"<<endl;
	else
		cout<<"Not stable"<<endl;
	for(i=0; i<n; i++)
		cout<<c[i].c<<" "<<c[i].in<<endl;
}


Measured memory_bytes: 4252
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int main () {
  long n, a, b;
  cin >> n >> a >> b;
  cout << (n / (a+b)) * a + min((n % (a+b)),a);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
int N, M;
int dp[3010][3010][2][2];
char dango[3010][3010];

int solve(){
    int res = 0;
    for(int j = 1; j <= M; j++){
        for(int i = 1; i <= N; i++){
            dp[i - 1][j + 1][0][0] = max(dp[i][j][0][0], dp[i][j][0][1]);
            dp[i - 1][j + 1][0][1] = max(dp[i][j][1][0], dp[i][j][1][1]);
            if(dango[i][j] == 'R' && dango[i + 1][j] == 'G' && dango[i + 2][j] == 'W'){
                dp[i - 1][j + 1][0][0] = max(dp[i - 1][j + 1][0][0], dp[i][j][0][0] + 1);
            }
            for(int k = 0; k < 2; k++){
                for(int l = 0; l < 2; l++){
                    if(dango[i][j] == 'R' && dango[i][j + 1] == 'G' && dango[i][j + 2] == 'W'){
                        dp[i - 1][j + 1][1][k] = max(dp[i - 1][j + 1][1][k], dp[i][j][k][l] + 1);
                    }
                }
            }
        }
    }

    for(int i = 2; i <= M + 1; i++){
        int add = 0;
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                add = max(add, dp[0][i][j][k]);
            }
        }
        res += add;
    }

    for(int i = 1; i < N; i++){
        int add = 0;
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                add = max(add, dp[i][M + 1][j][k]);
            }
        }
        res += add;
    }
    return res;
}

void init(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            cin >> dango[i][j];
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    init();
    cout << solve() << endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    REP(i, N) cin >> L[i];

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

    long long ans = 0;
    REP(i, N){
        FOR(j, i+1, N){
            int a = L[i], b = L[j];
            auto itr_min = lower_bound(L.begin()+j+1, L.end(), a+b);
            auto itr_max = upper_bound(L.begin()+j+1, L.end(), abs(a-b));
            int idx_min = itr_min-L.begin();
            int idx_max = itr_max-L.begin();
            if(idx_min-idx_max > 0){
                ans += idx_min-idx_max;
                if(idx_min <= i and i <= idx_max) --ans;
                if(idx_min <= j and j <= idx_max) --ans;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n,c,k = map(int, input().split())
t = sorted(list(int(input()) for _ in range(n)))

#Ti以上Ti+k以下のバスに乗る
#定員はC人

T = 0
cnt = 0
bus = 0
for i in range(n):
    if cnt == 0:
        cnt += 1
        T = t[i] + k
    elif T >= t[i]:
        cnt += 1
    elif T < t[i]:
        bus += 1
        cnt = 1
        T = t[i]+k
    if cnt == c:
        bus += 1
        T = 0
        cnt = 0
if cnt != 0: bus += 1
print(bus)

Measured memory_bytes: 14168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, P;
	cin >> A >> P;
	P += A * 3;
	cout << P / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,c;
	cin>>n;
	cin>>b;
	int X[b];
	for(int i = 0;i<b;i++){
		cin>>X[i];
	}
	cin>>c;
	int Y[c];
	for(int i = 0;i<c;i++){
		cin>>Y[i];
	}
	cin>>a;
	int Z[a];
	for(int i = 0;i<a;i++){
		cin>>Z[i];
	}
	int cnt  = a;
for(int i = 0;i<b;i++){
		for(int j = 0;j<c;j++){
			if(X[i] == Y[j]){
				X[i] = n+1;
				break;
			}
		}
	}
	for(int i = 0;i<a;i++){
		for(int j = 0;j<b;j++){
			if(Z[i] == X[j]){
				cnt--;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>
int main(void) {
    int price,change,coin,i;
    while (1) {
        scanf("%d",&price);
        if (price==0) break;
        coin=0;
        change=1000-price;
        while (change!=0) {
            if (change>=500) {
                coin++;
                change%=500;
            } else if (change>=100) {
                coin+=change/100;
                change%=100;
            } else if (change>=50) {
                coin++;
                change%=50;
            } else if (change>=10) {
                coin+=change/10;
                change%=10;
            } else if (change>=5) {
                coin++;
                change%=5;
            } else {
                coin+=change;
                break;
            }
        }
        printf("%d\n",coin);
    }
    return 0;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

struct UnionFind {
  vector<int> parent; // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1) { };
  bool unite(int u, int v) {
    u = root(u); v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v]; parent[v] = u;
    return true;
  }
  bool find(int u, int v) { return root(u) == root(v); }
  int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
  // ランク
  int size(int u) { return -parent[root(u)]; }
};

signed main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<ll> as(m), bs(m);
    rep(i, m){
        cin >> as[i] >> bs[i];
        --as[i];
        --bs[i];
    }
    vector<ll> anss;
    ll ans = (ll)n * (n-1) / 2;
    for(int i = m - 1; i >= 0; --i){
        anss.push_back(ans);
        auto a = as[i];
        auto b = bs[i];
        if (!uf.find(a, b)) {
            ans -= (ll)uf.size(a) * uf.size(b);
        }
        uf.unite(a, b);
    }
    reverse(be(anss));
    for(auto& e: anss) cout << e << nl;
}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
int l[9];
int A,B,C,n;
int dfs(int id,int a,int b,int c)
{
	int r1,r2,r3,r4;
	if(id==n)
	{
		if(a==0||b==0||c==0)
			return 8001;
		return abs(a-A)+abs(b-B)+abs(c-C);
	}
	r1=dfs(id+1,a+l[id+1],b,c)+10;
	r2=dfs(id+1,a,b+l[id+1],c)+10;
	r3=dfs(id+1,a,b,c+l[id+1])+10;
	r4=dfs(id+1,a,b,c);
	return min(r1,min(r2,min(r3,r4)));
}
int main()
{
	int i;
	scanf("%d %d %d %d",&n,&A,&B,&C);
	for(i=1;i<=n;i++)
		scanf("%d",&l[i]);
	printf("%d",dfs(0,0,0,0)-30);
	return 0;
}

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

const int INF = 1 << 20;
int N;
int a[100010], b[100010];
vector<int> G[100010];
int dis[2][100010];

void bfs(int idx, int s) {
  queue<int> que;
  que.emplace(s);
  fill_n((int*)dis[idx], 100010, INF);
  dis[idx][s] = 0;
  while (!que.empty()) {
    int cur = que.front(); que.pop();
    for (int nxt : G[cur]) {
      if (dis[idx][nxt] == INF) {
        dis[idx][nxt] = dis[idx][cur] + 1;
        que.emplace(nxt);
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]].emplace_back(b[i]);
    G[b[i]].emplace_back(a[i]);
  }
  bfs(0, 0);
  bfs(1, N - 1);
  int B = 0, W = 0;
  for (int i = 0; i < N; i++) {
    if (dis[0][i] <= dis[1][i]) B++;
    else W++;
  }
  cout << (B > W ? "Fennec" : "Snuke") << endl;


  return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define ll long long
#define nes ios_base :: sync_with_stdio(0); cin.tie(0);
using namespace std;
int main(){
	nes;
	ll n;
	cin>>n;
	string s="ACL";
	for(int i=0;i<n;++i) cout<<s;
	return 0;
}


Measured memory_bytes: 3608
S = input()
T = input()

N = len(S)
M = len(T)
ans = M
for i in range(N-M+1):
    S_2 = S[i:i+M]
    cnt = 0
    for j in range(M):
        if T[j] != S_2[j]:
            cnt += 1
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 8928
n = gets.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}
sum = a.inject(:+)
now = a[0]
ans = (sum-now-now).abs
for i in 1...(n-1)
  # puts i
  now += a[i]
  ans = [ans, (sum-now - now).abs].min
end
puts ans


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int a = atoi(s.substr(0, 2).c_str());
  int b = atoi(s.substr(2, 4).c_str());
  if (1 <= a && a <= 12 && 1 <= b && b <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if (1 <= a && a <= 12 && !(1 <= b && b <= 12)) {
    cout << "MMYY" << endl;
  } else if (!(1 <= a && a <= 12) && (1 <= b && b <= 12)) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= n; ++k) {
				sum += __gcd(i, __gcd(j, k));
			}
	cout << sum;
}


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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
// #define f(i,a,b) for(int (int)i = (int)a;i<b;i++)
// #define rf((i),(a),(b)) for(int (i) = b; (i)>(a);(i--))
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mp make_pair

int main(void)
{
    ios_base::sync_with_stdio(false);
    ll n,w;
    cin >> n >> w;
    vector<pair<ll,ll>> val;
    for(int i = 0;i<n;i++)
    {
        int temp1,temp2;
        cin >> temp1 >> temp2;
        val.pb(mp(temp1,temp2));
    }
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));//note where the variable name comes here.
    for(int i = 1;i<=n;i++)
        for(int j=1;j<=w;j++)
            if(val[i-1].first<=j)
                dp[i][j] = max((val[i-1].second + dp[i-1][j-val[i-1].first]),dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
    
    cout << dp[n][w];
    return 0;
}

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

typedef long long LL;

int main()
{
    LL a, b;    
    scanf("%lld %lld", &a, &b);
    LL k = (a+b) / 2;
    if(a > b)
    {
        LL tmp = a;
        a = b;
        b = tmp;
    }
    if(a - k == k - b)
        printf("%lld\n", k);
    else
    {
        printf("IMPOSSIBLE\n");
    }
    


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef long long ll;

ll gcd(ll u,ll v) {
  ll r = u % v;
  if( r == 0LL ) return v;
  return gcd(v,r);
}

int main() {
  ll u,v;
  scanf("%lld %lld",&u,&v);
  printf("%lld\n",gcd(u,v));
  return 0;
}

Measured memory_bytes: 596