akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
import copy
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
ans=0
for i in range(m):
    ltmp=copy.deepcopy(l)
    ltmp=ltmp[:i]+ltmp[i+1:]
    UF=UnionFind(n)
    for j in ltmp:
        UF.Unite(j[0]-1,j[1]-1)
    if UF.Count(0)!=n:ans+=1
print(ans)

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

void fnInput(string& rsColor)
{
  cin >> rsColor;
}

int fnMaxRemove(string sColor)
{
  int nCnt0 = 0;
  int nCnt1 = 0;

  for (int i = 0; i < sColor.size(); i++)
  {
    if (sColor[i] == '0') nCnt0++;
    if (sColor[i] == '1') nCnt1++;
  }
  return min(nCnt0, nCnt1) * 2;
}
 
int main()
{
  string sColor;

  fnInput(sColor);
  cout << fnMaxRemove(sColor) << endl;

  return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
int main(void){
	int N=0,all=1,b=1;
	scanf("%d",&N);
	int A_i[N]={0};
	for(int i=0;i<N;i++){
		scanf("%d",&A_i[i]);
		if(A_i[i]==1){
			b++;
			if(all<b){
				all=b;
			}
		}
		else{
			b=1;
		}
	}
	printf("%d\n",all);
	return 0;
}


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

const int N=2e5+20,MOD=1e9+7;

int n,k,zero,neg;
long long x,ans=1;
vector <pair <long long,int>> v;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&x);
		if(x>0) v.push_back({x,+1});
		else if(x<0) v.push_back({-x,-1});
		else v.push_back({x,0});
	}

	sort(v.begin(),v.end(),greater <pair <long long,int>>());
	for(int i=0;i<k;i++)
	{
		ans=(ans*v[i].first)%MOD;
		if(v[i].second==-1) neg++;
	}

	if(neg%2==0) return 0 * printf("%lld",ans);

	int lneg=-1,lpos=-1;
	for(int i=k-1;i>=0;i--)
		if(v[i].second==-1 and lneg==-1) lneg=i;
		else if(v[i].second==1 and lpos==-1) lpos=i;

	int rneg=-1,rpos=-1;
	for(int i=k;i<n;i++)
		if(v[i].second==-1 and rneg==-1) rneg=i;
		else if(v[i].second==1 and rpos==-1) rpos=i;

	bool case1=false,case2=false;
	if(lneg!=-1 and rpos!=-1) case1=true;
	if(lpos!=-1 and rneg!=-1) case2=true;

	if(case1 or case2) ans=1;
	if(case1 and case2)
	{
		if(1ll*v[rpos].first*v[lpos].first>=1ll*v[rneg].first*v[lneg].first)
		{
			for(int i=0;i<k;i++)
				if(i!=lneg) ans=(ans*v[i].first)%MOD;
			ans=(ans*v[rpos].first)%MOD;
		}
		else
		{
			for(int i=0;i<k;i++)
				if(i!=lpos) ans=(ans*v[i].first)%MOD;
			ans=(ans*v[rneg].first)%MOD;
		}
	}
	else if(case1)
	{
		for(int i=0;i<k;i++)
				if(i!=lneg) ans=(ans*v[i].first)%MOD;
			ans=(ans*v[rpos].first)%MOD;
	}
	else if(case2)
	{
		for(int i=0;i<k;i++)
				if(i!=lpos) ans=(ans*v[i].first)%MOD;
			ans=(ans*v[rneg].first)%MOD;
	}
	else
	{
		ans=1;
		for(int i=n-1;i>n-1-k;i--)
			ans=(ans*v[i].first)%MOD;
		ans=(MOD-ans)%MOD;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 7488
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++) {
        if(a+1 != b) a++;
        else {
            cout << "Borys" << endl;
            return 0;
        }
        if(b-1 != a) b--;
        else {
            cout << "Alice" << endl;
            return 0;
        }
    }

    cout << "Drow" << endl;

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<(s.size()-1)/2;i++)
	{
		if(s[i]==s[(s.size()-1)/2-(i+1)]&&s[(s.size()-1)/2+(i+1)]==s[(s.size()-1)-i]&&s[(s.size()-1)/2-(i+1)]==s[(s.size()-1)/2+(i+1)])
			continue;
		else
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

int ary[2010], sorted_ary[2010];

int main(void){
	int n,k,q;
	cin >> n >> k >> q;
	rep(i,n){
		cin >> ary[i];
		sorted_ary[i] = ary[i];
	}

	sort(sorted_ary, sorted_ary + n);

	int ans = 1 << 30;

	rep(i,n){
		bool tmp_ary[2010];
		rep(j,n) tmp_ary[j] = (ary[j] >= sorted_ary[i]);
		tmp_ary[n] = 0;
		vector<int> cand;

		vector<int> tmp;
		rep(j,n+1){
			if(tmp_ary[j]){
				tmp.push_back(ary[j]);
			} else {
				sort(begin(tmp),end(tmp));
				rep(i,tmp.size() - k + 1) cand.push_back(tmp[i]);
				tmp.clear();
			}
		} 

		sort(begin(cand),end(cand));
		if(cand.size() >= q) chmin(ans,cand[q - 1] - cand[0]);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int k = Integer.parseInt(in.next());
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int ans = 0;
            int tmp = 0;

            boolean ok = false;

            for (int i = 1; i < 1100; i++) {
                tmp = k * i;
                if (a <= tmp && tmp <= b) ok = true;
            }


            out.println(ok ? "OK" : "NG");

        }

    }
}



Measured memory_bytes: 35864
def solve():
    N = int(input())
    lfs = list(map(int, input().strip().split()))
    ans = 0
    L = 1 << N
    lo = lfs[-1]
    hi = lfs[-1]
    memo = [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        if lo > L:
            return -1
        memo[i + 1] = hi
        lo = (lo + 1) // 2 + lfs[i]
        hi = hi + lfs[i]
        L = L >> 1

    if lo > L:
        return -1
    memo[0] = hi
    
    curr = 1
    for i in range(N + 1):
        ans += min(memo[i], curr)
        curr = (curr - lfs[i]) << 1
    return ans

print(solve())

Measured memory_bytes: 20048
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	double pi=acos(-1);
	
	int r;
	cin>>r;
	
	double ans=2*r*pi;
	printf("%.10f\n",ans);
}


Measured memory_bytes: 3728
#include <iostream>
#include <vector>
using namespace std;
int main(){
    // make cin faster
    ios_base::sync_with_stdio(0);
    cin.tie();
    //
    string S;
    cin >> S;
    const int MOD = 2019;
    const int size = S.size();
    int answer = 0; //1817181712114
    int power = 1;
    int index = 0;
    vector<int> counts(MOD);
    counts[0]++;
    for (int i=size-1; i>=0; i--){
        int digit = S[i] - '0';
        index = (index + (digit * power)) % MOD;
        power *= 10; power %= MOD;
        answer += counts[index];
        counts[index]++;
    }
    cout << answer << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int N, M; cin >> N >> M;
	vector<bool> one(N, false);
	vector<bool> two(N, false);

	REP(i,M){
		int a, b; cin >> a >> b;
		a--; b--;
		if(a == 0) one[b] = true;
		else if(b == (N-1)) two[a] = true;
	}

	bool ok = false;

	REP(i,N){
		if(one[i] and two[i]) ok = true;
	}

	if(ok) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;


	return 0;

}


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

using namespace std;

const int maxQ=1000000;
set<int> st[26];
int idx[maxQ];
char c[maxQ];
int l[maxQ];
int r[maxQ];
int type[maxQ];
int N,Q;
string S, IString;

void input(){
    cin >> N;
    cin >> S;
    cin >> Q;
    for(int i=0;i<Q;i++){
        cin >> type[i];
        if(type[i]==1){
            cin >> idx[i] >> c[i];
        }else{
            cin >> l[i] >> r[i];
        }
    }
}


void solve(){
    for(int i=0;i<26;i++){
        st[i].clear();
        st[i].insert(N);
    }
    for(int i=0;i<S.size();i++){
        st[(int)(S[i]-'a')].insert(i);
    }
    for(int i=0;i<Q;i++){
        if(type[i]==1){
            st[(int)(S[idx[i]-1]-'a')].erase(idx[i]-1);
            S[idx[i]-1] = c[i];
            st[(int)(S[idx[i]-1]-'a')].insert(idx[i]-1);
        }else{
            int ans=0;
            for(int al=0;al<26;al++){
                auto itr = st[al].lower_bound(l[i]-1);
                if(*itr<=r[i]-1) ans++;
            }
            cout << ans <<endl;
        }
    }

}


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

Measured memory_bytes: 32516
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll res = 0;
  ll rem_max = 0;
  for(ll i=0; i<5; i++) {
    ll temp;
    cin >> temp;
    if(temp % 10 != 0) {
      res += temp - temp % 10 + 10;
    } else {
      res += temp;
    }
    ll rem_temp = 10 - temp % 10;
    if(rem_temp != 10 && rem_temp > rem_max) {
      rem_max = rem_temp;
    }
  }

  cout << res - rem_max << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <map> 
#include <iostream>
#include <cctype>
#include <utility> // 包含pair 
using namespace std;
typedef long long LL;
const int MAXN = 100 + 10;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m, ans;
char maze[MAXN][MAXN];
void dfs(int x, int y, char ch) {
	maze[x][y] = '.';
	for (int i = 0; i < 4; i++) {
		int ux = x + dx[i], uy = y + dy[i];
		if (ux >= 0 && ux < n && uy >= 0 && uy < m && maze[ux][uy] == ch) {
			dfs(ux, uy, ch);
		}
	} 
}

int main() {
	// ios::sync_with_stdio(false);
	while (scanf("%d %d", &n, &m) == 2 && n && m) {
		ans = 0;
		for (int i = 0; i < n; i++) scanf("%s", &maze[i]);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				char u = maze[i][j];
				if (u != '.') {
					dfs(i, j, u);
					ans++;
				}
			}
		}
		printf("%d\n", ans);
	}
	
    return 0;
}


Measured memory_bytes: 3724
#include <cstdio>
#include <algorithm>
using std::sort;
using std::max;

struct shop{
    int l, r;
}shops[1000];
int S;

bool comp(shop a, shop b){
    return a.l < b.l;
}

int main(){
    int N, M;
    scanf("%d %d", &N, &M); N++;
    while(M--){
        int l, r;
        scanf("%d %d", &l, &r);
        if(l < r){
            shops[S].l = l;
            shops[S].r = r;
            S++;
        }
    }
    sort(shops, shops+S, comp);
    int MinL = 0;
    int MaxR = 0;
    for(int i=0;i<S;i++){
        if(shops[i].l > MaxR){
            N += (MaxR - MinL) * 2;
            MinL = shops[i].l;
            MaxR = shops[i].r;
        }
        MaxR = max(MaxR, shops[i].r);
    }
    N += (MaxR - MinL) * 2;
    printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a,b;
  int p;
  for(int i=0;i<n+1;i++){
    cin >> p;
    a.push_back(p);
  }
  for(int i=0;i<n;i++){
    cin >> p;
    b.push_back(p);
  }
  long long cnt = 0;
  int m;
  for(int i=n-1;i>=0;i--){
    m = min(b[i],a[i+1]);
    b[i] -= m;
    cnt += m;
    a[i+1] -= m;
    m = min(b[i],a[i]);
    b[i] -= m;
    cnt += m;
    a[i] -= m;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1400
import sys
si = sys.stdin.readline


def main():
    n = int(si())
    l = [int(e) for e in si().split()]
    s = sum(l)
    l.sort()
    tab = dict()
    for e in l:
        if e not in tab:
            tab[e] = 1
        else:
            tab[e] += 1

    t = int(si())
    for _ in range(t):
        [fr, to] = [int(e) for e in si().split()]
        if fr not in tab:
            print(s)
            continue
        s += (to-fr)*tab[fr]
        if to in tab:
            tab[to] += tab[fr]
        else:
            tab[to] = tab[fr]
        tab[fr] = 0
        print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int m;
vp p,a,b;
int ans=0;
bool used[16];
int u;

void calc(){
    int t=0;
    rep(i,a.size()){
        Rep(j,i+1,a.size()){
            if((a[i].fi-b[i].fi)*(a[j].se-b[j].se)==(a[i].se-b[i].se)*(a[j].fi-b[j].fi)){
                t++;
            }
        }
    }
    ans=max(ans,t);u++;
}

void rec(int k,int i){
    if(k==m/2){
        calc();
        return;
    }
    if(i>=m)return;
    if(used[i]){
        rec(k,i+1);
        return;
    }
    a.pb(p[i]);
    used[i]=true;
    rep(j,m){
        if(used[j])continue;
        b.pb(p[j]);
        used[j]=true;
        rec(k+1,i+1);
        b.pop_back();
        used[j]=false;
    }
    a.pop_back();
    used[i]=false;
}

void run(){
    cin>>m;
    int x,y;
    rep(i,m){
        cin>>x>>y;
        p.pb({x,y});
    }
    rec(0,0);
    cout<<ans<<endl;
}


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int n;
struct Vec{
	int x,y;
	Vec(int xx=0,int yy=0)
	{
		x=xx;
		y=yy;
	}
};
Vec operator +(const Vec& a,const Vec& b)
{
	return Vec(a.x+b.x,a.y+b.y);
}
struct Graph{
	vector<Vec>to;
	int col[610][610];
	int cnt[2];
	Graph()
	{
		to.clear();
		memset(col,-1,sizeof(col));
		cnt[0]=cnt[1]=0;
	}
	void dfs(Vec p,int c)
	{
		col[p.x][p.y]=c;
		cnt[c]++;
		Vec q;
		for(int i=0;i<to.size();i++)
		{
			q=p+to[i];
			if(q.x<0||q.x>=n*2||q.y<0||q.y>=n*2)continue;
			if(col[q.x][q.y]!=-1)continue;
			dfs(q,c^1);
		}
	}
}G1,G2;
int main()
{
	scanf("%d",&n);
	int D1,D2;
	scanf("%d %d",&D1,&D2);
	for(int i=0;i<n*2;i++)
		for(int j=0;j<n*2;j++)
		{
			if(i*i+j*j==D1){
				G1.to.push_back(Vec(i,j));
				G1.to.push_back(Vec(i,-j));
				G1.to.push_back(Vec(-i,j));
				G1.to.push_back(Vec(-i,-j));
			}
			if(i*i+j*j==D2){
				G2.to.push_back(Vec(i,j));
				G2.to.push_back(Vec(i,-j));
				G2.to.push_back(Vec(-i,j));
				G2.to.push_back(Vec(-i,-j));
			}
		}
	for(int i=0;i<n*2;i++)
		for(int j=0;j<n*2;j++)
		{
			if(G1.col[i][j]==-1)
				G1.dfs(Vec(i,j),0);
			if(G2.col[i][j]==-1)
				G2.dfs(Vec(i,j),0);
		}
	int s1=0;
	if(G1.cnt[1]>G1.cnt[0])s1=1;
	int s2=0;
	G2.cnt[0]=G2.cnt[1]=0;
	for(int i=0;i<n*2;i++)
		for(int j=0;j<n*2;j++)
			if(G1.col[i][j]==s1)
				G2.cnt[G2.col[i][j]]++;
	if(G2.cnt[1]>G2.cnt[0])s2=1;
	int cnt=0;
	for(int i=0;i<n*2;i++)
		for(int j=0;j<n*2;j++)
			if(G1.col[i][j]==s1&&G2.col[i][j]==s2)
			{
				cnt++;
				printf("%d %d\n",i,j);
				if(cnt==n*n)return 0;
			}
	return 0;
}

Measured memory_bytes: 20736
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

void solve(long long N, long long M, std::vector<long long> p,
           std::vector<std::string> S) {
  map<int, int> fuga;
  map<int, bool> neko;
  lli ans = 0;
  rep(i, M) {
    if (S[i] == "AC") {
      if (neko[p[i]])
        continue;
      neko[p[i]] = true;
      ans += fuga[p[i]];
    } else {
      fuga[p[i]]++;
    }
  }
  cout << neko.size() << " " << ans << endl;
}

int main() {
  int a;
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> p(M);
  std::vector<std::string> S(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &p[i]);
    std::cin >> S[i];
  }
  solve(N, M, std::move(p), std::move(S));
  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
#define MAXN 100100
using namespace std;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
vector<int> adj[MAXN];
int n,k;
int vis[MAXN];
int level[MAXN];
int visl[MAXN];
int pai[MAXN];

int BFS(){
	memset(vis,false,sizeof(vis));
	memset(level,0,sizeof(level));
	memset(visl,false,sizeof(visl));
	queue<pii> fila;
	fila.push(pii(1,0));
	int ans=1;
	pai[1]=0;
	while(!fila.empty()){
		int d = fila.front().ss;
		int v = fila.front().ff;
		int ja = level[pai[v]];
	//	cout<<v<<" "<<ja<<" "<<pai[v]<<" "<<level[pai[v]]<<endl;
		if(pai[v]!=1 && pai[v]!=0){
			ja++;
		}
		level[v]++;
		level[pai[v]]++;
		ans=mod((k-ja)*ans,M);
		vis[v]=true;
		fila.pop();
		for(int i=0;i<(int)adj[v].size();i++){
			int u = adj[v][i];
			if(vis[u])continue;
			fila.push(pii(u,d+1));
			pai[u]=v;
		}
	}
	   return ans;	
}	
	
int32_t main(){

	cin>>n>>k;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	cout<<BFS()<<endl;
}

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

int main() {  
  int D,N;
  cin >>D>>N;
  
  if(D==0){
    if(N==100){
      cout<<101<<endl;
    }
    else{
      cout<<N<<endl;
    }
  }
  else if(D==1){
    if(N==100){
      cout<<10100<<endl;
    }
    else{
      cout<<N<<"00"<<endl;
    }
  }
  else{
    if(N==100){
      cout<<1010000<<endl;
    }
    else{
      cout<<N<<"0000"<<endl;
    }
  }
  

}

Measured memory_bytes: 256
using System;

class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] datas = str.Split(' ');

            int a = int.Parse(datas[0]);
            int b = int.Parse(datas[1]);

            if ((a * b) % 2 == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");
            }
        }
    }

Measured memory_bytes: 13140
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#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--)
ll A,B,C;

bool done[200][200][200];
ll memo[200][200][200];

ll solve(ll A,ll B,ll C) {
    if(A >= 200 || B >= 200 || C >= 200) {
        return 1000000000;
    }
    if(A == B && B == C) {
        return 0ll;
    }
    if(done[A][B][C]) {
        return memo[A][B][C];
    }

    ll x = solve(A + 1,B + 1,C);
    ll y = solve(A,B + 1,C + 1);
    ll z = solve(A + 1,B,C + 1);
    ll p = solve(A + 2,B,C);
    ll q = solve(A,B + 2,C);
    ll r = solve(A,B,C + 2);

    done[A][B][C] = true;
    return memo[A][B][C] = min(min(min(x,y),z),min(min(p,q),r)) + 1;
}

int main(){
    cin >> A >> B >> C;
    cout << solve(A,B,C) << endl;;
    return 0;
}



Measured memory_bytes: 70656
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    string s[n];
    vector<pair<ll, ll>> inc, dec;
    for(int i = 0; i < n; i++) {
        cin>>s[i];
        stack<char> st;
        for(int j = 0; j < s[i].length(); j++) {
            if(s[i][j] == '(') {
                st.push('(');
            } else { 
                if(!st.empty() && st.top() == '(') {
                    st.pop();
                } else {
                    st.push(')');
                }
            }
        }
        int a = 0, b = 0;
        while(!st.empty() && st.top() == '(') {
            b++;
            st.pop();
        }
        while(!st.empty()) {
            a++;
            st.pop();
        }
        if(b - a > 0) {
            inc.pb(mp(a, i));
        } else {
            dec.pb(mp(-b, i));
        }
    }
    sort(all(inc));
    sort(all(dec));
    ll cnt = 0;
    bool flag = true;
    for(auto u: inc) {
        for(int i = 0; i < s[u.ss].length(); i++) {
            if(s[u.ss][i] == '(') {
                cnt++;
            } else {
                cnt--;
            }
            if(cnt < 0) {
                flag = false;
            }
        }
    }
    for(auto u: dec) {
        for(int i = 0; i < s[u.ss].length(); i++) {
            if(s[u.ss][i] == '(') {
                cnt++;
            } else {
                cnt--;
            }
            if(cnt < 0) {
                flag = false;
            }
        }
    }
    if(!cnt && flag) {
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }
}

Measured memory_bytes: 50208
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    static int mod = 1000000007;
    static int n, k;
    static boolean[] visited;
    static Map<Integer, Set<Integer>> edge;
    public static void main(String[]$) {
        n = scanner.nextInt();
        k = scanner.nextInt();
        edge = new HashMap<>();
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            edge.put(i, new HashSet<>());
        }

        for (int i = 1; i < n; i++) {
            int a = scanner.nextInt() - 1;
            int b = scanner.nextInt() - 1;
            edge.get(a).add(b);
            edge.get(b).add(a);
        }

        visited[0] = true;
        System.out.println(bfs(0, 0, 0));
    }

    static long bfs(int v, int c2, int c1) {
        int d = 0;
        long r = k - c2 - c1;
        for (int i : edge.get(v)) {
            if (!visited[i]) {
                visited[i] = true;
                r = (r * bfs(i, c1 + d, 1)) % mod;
                d++;
            }
        }
        return r;
    }
}

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

typedef pair<int, int> ii;
#define x first
#define y second

const int N = 3e3 + 5;

int n, s[N];
bool check[N];
vector<int> a[N];
vector<ii> d;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		int x; cin >> x; s[i] = x;
		d.push_back(ii(x, i));
	}
	for(int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	sort(d.begin(), d.end());
	for(int i = 0; i < d.size(); ++i) {
		int u = d[i].y; if(check[u]) continue;
		for(int j = 0; j < a[u].size(); ++j) if(s[a[u][j]] > s[u]) check[a[u][j]] = true;
	}
	for(int i = 1; i <= n; ++i) if(check[i]) cout << i << ' ';
}

Measured memory_bytes: 512
N = int(input())
S = input()

pin = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            pin.append(str(i)+str(j)+str(k))

count = 0
for i in range(len(pin)):
    l, m, n = pin[i][0], pin[i][1], pin[i][2]
    l_idx, m_idx, n_idx = -1, -1, -1
    for i in range(N):
        if S[i] == l:
            l_idx = i
            break
    if l_idx != -1:
        for i in range(l_idx+1, N):
            if S[i] == m:
                m_idx = i
                break
    if m_idx != -1:
        for i in range(m_idx+1, N):
            if S[i] == n:
                n_idx = i
                break
    if l_idx != -1 and m_idx != -1 and n_idx != -1:
        count += 1

print(count)

Measured memory_bytes: 74032
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)*}
    };
}

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)*}
    };
}

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn in_digit(mut x: u32, a: u32, b: u32) -> bool {
    let mut sum = 0;
    while x > 0 {
        sum += x % 10;
        x /= 10;
    }
    a <= sum && sum <= b
}

fn main() {
    input!(
        n: u32,
        a: u32,
        b: u32,
    );
    println!(
        "{}",
        (1..n+1)
            .into_iter()
            .filter(|x| in_digit(*x, a, b))
            .sum::<u32>()
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	map<char, int> m;
	int res = 0;
	for(int i = 0; i < s.size(); ++i)m[s[i]]++;
	for(auto x : m)if(x.second >= 2){res++;}
	if(res == 2){
		cout<<"Yes"<<endl;return 0;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  unordered_map<int, int> odds, evens;
  int oddc = 0, evenc = 0;
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    if (i % 2) {
      odds[v]++;
      oddc++;
    } else {
      evens[v]++;
      evenc++;
    }
  }
  vector<pair<int, int>> oddv, evenv;
  oddv.reserve(oddc);
  evenv.reserve(evenc);
  for (auto &it : odds) {
    oddv.emplace_back(make_pair(it.second, it.first));
  }
  for (auto &it : evens) {
    evenv.emplace_back(make_pair(it.second, it.first));
  }
  sort(oddv.rbegin(), oddv.rend());
  sort(evenv.rbegin(), evenv.rend());
  if (oddv[0].second == evenv[0].second) {
    cout << min(oddc - oddv[0].first + evenc - evenv[1].first,
                oddc - oddv[1].first + evenc - evenv[0].first)
         << "\n";
  } else {
    cout << oddc - oddv[0].first + evenc - evenv[0].first << "\n";
  }
}


Measured memory_bytes: 5144
import java.io.*;
import java.math.BigDecimal;
import java.util.*;


// 2011/10/22

//0218 ïÃiwm
public class Main {

	// C return falseÅ¨µÜ¢
	boolean main() throws IOException {

		int[] ir = readIntArray();
		int n = ir[0];
		if (n == 0)
			return false;
		
		for(int i = 0; i < n; i++) {
			ir = readIntArray();
			
			int c = 3; // 3ªC
			
			if (ir[0] + ir[1] + ir[2] >= 210) {
				c = 2; //B
			}
			if (ir[0] + ir[1] + ir[2] >= 150 && (ir[0] >= 80 || ir[1] >= 80)) {
				c = 2; //B
			}
			
			if (ir[0] == 100 || ir[1] == 100 || ir[2] == 100) {
				c = 1; //A
			}
			if (ir[0] + ir[1] >= 180) {
				c = 1; //A
			}
			if (ir[0] + ir[1] + ir[2] >= 240) {
				c = 1; //A
			}
			
			
		// ðÌ\¦
		System.out.printf("%s\n", (c == 1) ? "A" : (c == 2) ? "B" : "C");
		
		}
		
		return true; // ³íI¹ Ö
	}
	

//	private final static boolean DEBUG = true;  // debug
	private final static boolean DEBUG = false; // release

	public static void main(String[] args) throws IOException {

		if (DEBUG) {
			log = System.out;
			
			String inputStr = "29:0:";

			inputStr = inputStr.replace(":", "\n");

			reader = new BufferedReader(new StringReader(inputStr)); 

		}
		else {
			log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
			reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
		}
		
		//int N = readIntArray()[0];

		for(int i = 0; /*i < N*/; i++) {
			boolean b = new Main().main();
			if (!b)
				break;
		}		
		
		reader.close();
	}

	
	static PrintStream log;
	static BufferedReader reader;
	

	// WüÍæè1sªÌXy[XæØèÌ®lðÇÞ
	// EOFÌêÍnullðÔ·
	private static int[] readIntArray() throws IOException {

		String s = null;
		for(;;) {
			s = reader.readLine();
			if (s.length() != 0) // ¦¦¦@Ç¤àËRósðÇÞ±Æª éBÇÝòÎ·Æ¤Ü­¢­çµ¢BBBB
				break;
		}
		
		if (s == null)
			return null;
		s = s.trim();
		String[] sp = s.split(" ");
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}
		
}

Measured memory_bytes: 13000
#include<iostream>
using namespace std;
int main()
{
    int a,i;
    cin>>a;
    int aa[a+5],cost[a+5];
    for(i=0;i<a;i++){
        cin>>aa[i];
        cost[i]=100000;
    }
    cost[0]=0;
    cost[1]=abs(aa[1]-aa[0]);
    for(i=2;i<a;i++)
    {
        cost[i]=min(cost[i-1]+abs(aa[i]-aa[i-1]),cost[i-2]+abs(aa[i]-aa[i-2]));
       // cout<<cost[i]<<endl;
    }
    cout<<cost[a-1]<<endl;
}


Measured memory_bytes: 1024
LARGE = 10 ** 9 + 7


def solve(n, k):
    # singular cases
    if k == 0:
        return 1
    elif k == 1:
        return n * (n - 1)

    # pow
    pow_mod = [1] * (n + 1)
    for i in range(n):
        pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
    pow_mod_inv = [1] * (n + 1)
    pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
    for i in range(n - 1, 0, -1):
        pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE

    res = 0
    for i in range(min(k, n - 1) + 1):
        # find where to set 0
        pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
        # how to assign ones
        assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
        res += pick_zeros * assign_ones
        res %= LARGE
    return res


def main():
    n, k = map(int, input().split())
    res = solve(n, k)
    print(res)


def test():
    assert solve(3, 2) == 10
    assert solve(200000, 1000000000) == 607923868
    assert solve(15, 6) == 22583772


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 20852
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


a, b, c, d = MI()
under_b_cdiv = b // c
under_b_ddiv = b // d
under_b_cddiv = b // LCM(c, d)
B = b - (under_b_cdiv + under_b_ddiv - under_b_cddiv)
under_a1_cdiv = (a - 1) // c
under_a1_ddiv = (a - 1) // d
under_a1_cddiv = (a - 1) // LCM(c, d)
A = (a - 1) - (under_a1_cdiv + under_a1_ddiv - under_a1_cddiv)
print(B - A)



Measured memory_bytes: 67436
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<stack>
#include<climits>
#include<cmath>

using namespace std;

#define int long long
#define MOD (1000000007)
#define MINF (-1*(LLONG_MAX-10))
#define INF (LLONG_MAX-10)

int ketadp(int N){
    int dp[10][2][2][2][2]={{{{{0}}}}};

    int q=0;
    int tmpn=N;
    while(tmpn!=0){
        q++;
        tmpn/=10;
    }
    dp[0][0][0][0][0]=1;
    for(int i=0;i<q;i++){
        int n=N/(int)pow(10,q-i-1)%10;
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                for(int l=0;l<2;l++){
                    for(int m=0;m<2;m++){
                        int t=0;
                        int s=0;
                        if(i==0) s=1;
                        if(m==0) t=n;
                        else t=9;
                        for(int w=s;w<=t;w++){
                            //cout<<i<<","<<j<<","<<k<<","<<l<<","<<m<<","<<w<<","<<dp[i][j][k][l][m]<<endl;
                            int tm=0;
                            if(w!=t||m==1) tm=1;
                            if(w==3){
                                dp[i+1][1][k][l][tm]+=dp[i][j][k][l][m];
                            }
                            else if(w==5){
                                dp[i+1][j][1][l][tm]+=dp[i][j][k][l][m];
                            }
                            else if(w==7){
                                dp[i+1][j][k][1][tm]+=dp[i][j][k][l][m];
                            }
                        }
                    }
                }
            }
        }
    }
    return dp[q][1][1][1][0]+dp[q][1][1][1][1];
}
signed main(){
    int N;
    cin>>N;
    int q=0;
    int tmpn=N;
    while(tmpn!=0){
        q++;
        tmpn/=10;
    }
    int qq=0;
    int ans=0;
    for(int i=0;i<q-1;i++){
        qq*=10;
        qq+=9;
        ans+=ketadp(qq);
    }
    ans+=ketadp(N);
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main() {
  int n,d,x;
  cin >> n >>d >> x;
  vector<int> a(n,0);
  rep(i,n) cin >> a[i];
  int ans = n; 
  for(int i=0;i<n;i++){
    int day = a[i]+1;
    int var = 1;
    while(day <= d){
      ans++;
      var++;
      day = var * a[i] + 1;
      
    }
  }
  cout << ans+x << endl;

}


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

 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A * B > C) {
  	cout << C << endl;
  }
  else{
  	cout << A * B << endl;
  }
  

}

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

using namespace std;

typedef long long LL;
#define N 120000

LL n,m,a[N],b[N],ans,x,lst;

void renew(int x){
	if (!lst){lst=x; return;}
	ans+=abs(a[x]-a[lst]);
	lst=x;
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=n;++i) scanf("%lld%lld",a+i,b+i);
	for (int i=1,j=n;i<=j;){
		if (a[j]<m){renew(i); ++i;}
		else{
			if (a[i]>m){renew(j); --j;}
			else{
				if (b[i]>=b[j]){
					renew(j); b[i]+=b[j]; --j;
				}
				else{
					renew(i); b[j]+=b[i]; ++i;
				}
			}
		}
	}
	ans+=abs(a[lst]-m);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int n = ReadLineInt();
        string[][] stArr = ReadMLineStrArray(n);
        string x = ReadLineStr();
        int rtn = 0;
        bool flg = false;
        for (int i = 0;i < n; i++) {
            if (flg) {rtn += int.Parse(stArr[i][1]);}
            if (x == stArr[i][0]) {flg = true;}
        }
        Console.WriteLine(rtn);
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"};
    static int[] intArray = new int[10];
    static List<int> intList = new List<int>();
    static Dictionary<string, int> myTable = new Dictionary<string, int>();
    static HashSet<int>[] rtnArrAb = null;
    static HashSet<int>[] rtnArrCd = null;
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private List<int> ReadLineIntList() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList();}
    static private List<long> ReadLineLongList() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToList();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string IntToNString(int x, int n) {
        var nstring = "";
        var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int r = 1;
        int q = x;
        while (q > 0) {
            r = q % n;
            nstring += numbers[r];
            q = q / n;
        }
        return string.Join("",nstring.Reverse());
     }
}

Measured memory_bytes: 13536
#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>;
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 ll INF = 1LL << 60;

int main()
{
    ll N;
    cin >> N;
    vector<ll> d;
    rep(i, N)
    {
        ll tmp;
        cin >> tmp;
        d.emplace_back(tmp);
    }

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

    ll ans = d[N / 2] - d[N / 2 - 1];

    cout
        << ans << endl;

    return 0;
}


Measured memory_bytes: 4196
#include <iostream>
using namespace std;
int main(void){
  int h, w, i, j, g, k=0;
  cin >> h >> w;
  string s[h];
  g = h;
  for(i=0;i<h;i++){
    cin >> s[i];
  }
  for(i=0;i<h+2;i++){
    cout << "#";
    for(j=0;j<w+2;j++){
      if(i>=1&&i<=h){
        cout << s[k];
        cout << "#";
        k++;
        break;
      }
      else if(j<w+1) cout << "#";
    }
    cout << endl;
  }
  return 0;
}


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

const int MOD = 10000;

std::string a, b; // <=1e500
int m; // <=500
int dp[2][2][510][510][15][3];

char Ch(int i) {
    return '0' + i;
}

int func(bool lower, bool upper, int mod, int idx, int prev, int stat) {// stat: 0: zero, 1: ?¢???????, 2: ??????
    if(idx >= a.size()) {
        if(lower && upper && mod % m == 0) {
            return true;
        }else {
            return false;
        }
    }

    if(dp[lower][upper][mod][idx][prev][stat] != -1) {
        return dp[lower][upper][mod][idx][prev][stat];
    }

    mod *= 10;

    int ans = 0;
    for(int i = 0; i <= 9; ++i) {
        int nm = (mod + i) % m;
        char c = '0' + i;
        bool newLower;
        bool newUpper;
        int newStat;

        if(lower) {
            newLower = lower;
        }else {
            if(b[idx] < c) {
                continue;
            }

            if(b[idx] == c && idx != a.size() - 1) {
                newLower = false;
            }else {
                newLower = true;
            }
        }

        if(upper) {
            newUpper = true;
        }else {
            if(a[idx] > c) {
                continue;
            }

            if(a[idx] == c && idx != a.size() - 1) {
                newUpper = false;
            }else {
                newUpper = true;
            }
        }

        if(stat == 0) {
            if(prev == 0) {
                newStat = 0;
            }else if(prev > i){
                newStat = 1;
            }else if(prev < i) {
                newStat = 2;
            }else {
                continue;
            }
        }else if(stat == 1) {
            if(i <= prev) {
                continue;
            }

            newStat = 2;
        }else {
            if(i >= prev) {
                continue;
            }

            newStat = 1;
        }

        ans += func(newLower, newUpper, nm, idx + 1, i, newStat);
        ans %= MOD;
    }

    return dp[lower][upper][mod / 10][idx][prev][stat] = ans;
}

int main() {
    std::cin >> a >> b >> m;

    while(a.size() < b.size()) {
        a = std::string("0") + a;
    }

    memset(dp, -1, sizeof(dp));

    std::cout << func(false, false, 0, 0, 0, 0) << std::endl;
}

Measured memory_bytes: 186108
//??¶??´???4s   ?????´???256MB
//?¢????:??¨????£?????????±????????????????????????,??????n?????????,??¨?????¨??±??????di
//????????????????????????,???????¬??????°?????????????????????1?????????,??£????°±?????????
//???????????\???????????????,???????????±??????0
//??????:??´??\?¨????????????????,??°????????????????????????,??°??????????????????????????? 
//????????±?????????,??????????????????????????°???????????????,???????§???¨?????\?°??????¬
//?§???¨??????????£???????,??¶????°???¶????????????,??´??°?????±???
//??????????????????,?????\?°????????????§??±???,???????????°??????,?????\?????°??????
//??????????????±???????????????????????????,??£?°±?°????????????????????§???¨
//??????????????????????????????????????\????????????,????????????????????????????????????
//??????????????????,??£?°±??§????°???????????§???¨ 
//???????????????????¢???????,??????????????±?¢?????????? 
//????????????????¢?????????????,?°±??´??\No,????????¨??????????????????,??£????????????
//?????¶????????????????????±????????????,??????????????±??????????????????????????? 
//???????¢?????????°???,????????????????????´?????°?????°??????,?????\?????????????????????
//????????´??\???????°±?????\???(??¨??????????????????????????????)??????????????´??°??????
//?????±?????±??? 
#include<cstdio>
#include<algorithm>
using namespace std;
int d[1000005];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n;
	scanf("%d",&n);
	int top=0,down=0;
	while(n--){
		int x;
		scanf("%d",&x);
		if(d[0]||x<top){printf("No\n");continue;}		
		if(x==top&&top!=down){printf("No\n");continue;}
		if(x>=1000000){printf("Yes\n");down=max(down,x);continue;}
		d[x]++;down=max(down,x);
		while(d[x]>=2){
			d[x-1]++;
			d[x]=0;
			if(x==down)down--;
			x--;
		}
		for(int i=top+1;d[i]==1;i++)
			top=i;
		printf("Yes\n");
	}
	return 0;
} 

Measured memory_bytes: 4656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int tikai = a[0];
    for (int i = 0; i < n-1; ++i) {
        if(abs(2*a[i] - a[n-1]) < abs(2*tikai - a[n-1])) tikai = a[i];
    }
    cout << a[n-1] << " " << tikai << endl;
    return 0;
}


Measured memory_bytes: 640