akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

string ch[]={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

int main() {
	int n=in();
	while(n--){
		string str;
		cin>>str;
		int i;
		int a=0,b=0;
		for(i=0;i<str.size();i++){
			if(str[i]=='0'){
				if(b!=0)cout<<ch[a][(b-1)%ch[a].size()];
				b=0;
			}else{
				a=str[i]-'1';
				b++;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
a = gets.chomp.split("")# ["1", "2", "3", "4", "5"]
b = ["", "+"]
c = b.repeated_permutation(a.size-1).collect {|a| a}
d = []

c.each{|i|
	x = ""
	i.size.times{|j|
		x += a[j]
		x += i[j]
	}
	x += a.last
	d.push(x)
}

p d.map {|i| eval(i)}.inject(:+)

Measured memory_bytes: 2428
// Problem : D - Anything Goes to Zero
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;

int dp[maxN];
string s;

int solve(int i) {
	if (dp[i] != -1) return dp[i];
	if (i == 0) return 0;
	int x = __builtin_popcount(i);
	dp[i] = solve(i % x) + 1;
	return dp[i];
}

ll pow2(ll a, ll b, ll MOD) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2, MOD);
	d = d * d % MOD;
	if (b % 2) return d * a % MOD;
	return d;	
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	cin >> s;
	dp[0] = 0;
	RI(i, 2e5) dp[i] = -1;
	RI(i, 2e5) {
		dp[i] = solve(i);
	}
	ll popcnt = 0;
	FORD(i, n - 1, 0) {
		popcnt += (s[i] == '1');
	}
	ll ans = 0;
	ll MOD = (popcnt - 1) * (popcnt + 1);
	if (MOD == 0) MOD = 2;
	ll pot = 1;
	FORD(i, n - 1, 0) {
		if (s[i] == '1')
			ans = (ans + pot) % MOD;
		pot = (pot * 2) % MOD;
	}
	pot = 1;
	vector<int> vec;
	FORD(i, n - 1, 0) {
		ll new_cnt = popcnt;
		if (s[i] == '0') {
			new_cnt++;
			ll new_ans = (ans + pot) % MOD;
			vec.pb(1 + dp[new_ans % new_cnt]);	
		} else {
			new_cnt--;
			if (new_cnt == 0) vec.pb(0);
			else {
				ll new_ans = (ans - pot + MOD) % MOD;
				vec.pb( 1 + dp[new_ans % new_cnt]);
			}
		}
		pot = (pot * 2) % MOD;
	}
	reverse(vec.begin(), vec.end());
	for (auto x: vec) {
		cout << x << "\n";
	}
	return 0;
}
 


Measured memory_bytes: 5292
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int d = b - a;
  string ans;
  if(d % 2 == 0) ans = "Alice";
  else ans = "Borys";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);	
		
		String str = scan.next();
		boolean f = true;
		boolean fl = true;
		
		for(int i = 0 ;  i < str.length() ;i++){
			if(f){
				if(str.charAt(i) == 'C'){
					f = false;
				}
			} else {
				if(str.charAt(i) == 'F'){
					System.out.println("Yes");
					fl = false;
					break;
				}
			}
		}
		if(fl){
			System.out.println("No");
		}
		
	}
}



Measured memory_bytes: 10192
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

char S[200500];
vector<int> gph[200500];
int deg[200500][2];
bool chk[200500];

int que[200500 * 4]; int qf, qr;

int main()
{
    int N, M; scanf("%d%d%s", &N, &M, S+1);
    for(int i = 1; i <= N; i++) {
      gph[i].clear();
      S[i] = (S[i] == 'B');
      chk[i] = false;
      deg[i][0] = deg[i][1] = 0;
    }
    for(int i = 1; i <= M; i++) {
      int a, b; scanf("%d%d", &a, &b);
      for(int rep = 0; rep < 2; rep++) {
        gph[a].push_back(b);
        deg[b][S[a]] += 1;
        swap(a, b);
      }
    }

    qf = qr = 0;

    for(int i = 1; i <= N; i++) {
      if(deg[i][0] == 0 || deg[i][1] == 0) {
        que[++qr] = i;
        chk[i] = true;
      }
    }

    while(qf < qr) {
      int u = que[++qf];
      for(int v : gph[u]) {
        deg[v][S[u]] -= 1;
        if(!chk[v] && (deg[v][0] == 0 || deg[v][1] == 0)) {
          que[++qr] = v;
          chk[v] = true;
        }
      }
    }

    puts(qr < N ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 5050,mo=1e9+7;
int n,sz[N],f[N][N],dp[N];Vi e[N];
void dfs(int u, int fa){
	sz[u]=1;f[u][1]=1;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa){
		dfs(e[u][i],u);static int g[N];memset(g,0,sizeof(g));
		rep(j,0,sz[u])rep(k,0,sz[e[u][i]])
			g[j+k]=(g[j+k]+1LL*f[u][j]*f[e[u][i]][k])%mo;
		sz[u]+=sz[e[u][i]];rep(j,0,sz[u])f[u][j]=g[j];
	}
	for(int i=2;i<=sz[u];i+=2)f[u][0]=(f[u][0]+1LL*(mo-f[u][i])*dp[i])%mo;
}
int main() {
	read(n);rep(i,1,n-1){int u,v;read(u);read(v);e[u].pb(v);e[v].pb(u);}
	for(int i=2;i<=n;i+=2){dp[i]=1;for(int j=i-1;j>=1;j-=2)dp[i]=1LL*dp[i]*j%mo;}
	dfs(1,0);cout<<(mo-f[1][0])%mo;
	return 0;
}


Measured memory_bytes: 98688
def c_guess_the_number_brute_force():
    N, M = [int(i) for i in input().split()]
    Conds = [[int(i) for i in input().split()] for j in range(M)]

    for k in range((0 if N == 1 else 10**(N - 1)), 10**N):
        d = [int(ch) for ch in str(k)]
        for s, c in Conds:
            if d[s - 1] != c:
                break
        else:
            return k
    return -1

print(c_guess_the_number_brute_force())

Measured memory_bytes: 3064
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
  return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A == B)
        cout << A + B << endl;
    else
        cout << 2 * std::max(A, B) - 1 << endl;
    return 0;
}

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

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  int ans = 0;
  int cur = 0;
  for(int i = 0; i < n - 1; ++i) {
    if (v[i] >= v[i + 1]) {
      cur++;
    } else {
      ans = max(ans, cur);
      cur = 0;
    }
  }
  ans = max(ans, cur);
  cout << ans << endl;
}

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

Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<stack>
const int N = 101;
std::queue<int> Q[N];
void dfs(int root, int *tt, int d[], int f[]);
int main() {
    int n; scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int k;
        scanf("%d%d", &i, &k); //&i, so i--;
        for (int j = 0; j < k; j++) {
            int v; scanf("%d", &v);
            Q[i].push(v);//remember children
            //i starts from 1!. look scanf above
        }
        i--;
    }
    int d[N] = {0}, f[N] = {0}, tt = 0;
    for (int i = 1; i <= n; i++) if(!d[i]) dfs(i, &tt, d, f);//if cannot reach from 0
    for (int i = 1; i <= n; i++) printf("%d %d %d\n", i, d[i], f[i]);
    return 0;
}
void dfs(int root, int *tt, int d[], int f[]) {//from root search
    std::stack<int> S;
    S.push(root);
    d[root] = ++*tt;
    while (!S.empty() ) {
        int u = S.top();
        if (!Q[u].empty() ) {
            int v = Q[u].front();
            Q[u].pop();
            if (d[v] == 0) {
                d[v] = ++*tt;
                S.push(v);
            }
        } else {
            S.pop();
            f[u] = ++*tt;
        }
        
    }
}



Measured memory_bytes: 2712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  ret[2] = 0;
  ret[3] = 0;
  ret[5] = 0;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{	
    ll n;
    string s;
    ll ans = 1;
    cin >> n >> s;

    vector<ll> count(3, 0);
    REP(i, n){
        if(s[i] == 'R') count[0]++;
        if(s[i] == 'G') count[1]++;
        if(s[i] == 'B') count[2]++;
    }

    REP(i, 3) ans *= count[i];

    REP(i, n){
        FOR(j, i+1, n){
            int k = j + (j-i);
            if(k < n){
                if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
            }
        }
    }
    cout << ans << endl;
}


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

int main(){
    string s;
    cin >> s;
    int cou=0;
    int frg=1;
    for(int i=0;i<s.size();i++){
        if(frg){
            if(s[i]=='A'){
                cou++;
                frg=0;
            }
        }else{
            if(s[i]=='Z'){
                cou++;
                frg=1;
            }
        }
    }

    cou/=2;

    if(cou>=1){
        for(int i=0;i<cou;i++)cout << "AZ";
    }else{
        cout << "-1";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3172
from collections import defaultdict
N=int(input())
alist=list(map(int,input().split()))

bdic=defaultdict(int)
cdic=defaultdict(int)
for i in range(N):
  bdic[alist[i]+i]+=1
  cdic[-alist[i]+i]+=1
#print(bdic)
#print(cdic)

answer=0
for b,bv in bdic.items():
  answer+=bv*cdic[b]
  
print(answer)

Measured memory_bytes: 163928
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	string s;
	cin >> n >> s;

	map<pair<string, string>, int> cnt;
	for (int i = 0; i < (1 << n); i++) {
		string a = "", b = "";
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				a += s[j + n];
			} else {
				b += s[j + n];
			}
		}
		cnt[{a, b}]++;
	}

	ll ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		string a = "", b = "";
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				a = s[j] + a;
			} else {
				b = s[j] + b;
			}
		}

		ans += cnt[{b, a}];
	}

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


Measured memory_bytes: 87040
#define _GLIBCXX_DEBUG
#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.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int alice = 0, bob = 0;
  for (int j=0; j<N; j+=2) {
    alice += A.at(j);
    if (N % 2 == 0 || j != N-1) {
      bob += A.at(j+1);
    }
  }
  cout << alice - bob << endl;
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int[] a = in.ni(5);
        for (int i = 0; i < 5; i++) {
            if(a[i]==0){
                out.println(i+1);
                break;
            }
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;
vector<li> children[100100];

li parent[100100];

set<li> in_links[100100];

int main() {
    cin >> n >> m;
    rep(i, n - 1 + m) {
        li a, b;
        cin >> a >> b;
        a--;
        b--;
        children[a].pb(b);
        in_links[b].insert(a);
    }

    stack<PI> stk;
    rin{
        if (in_links[i].empty()) {
            stk.push({i, -1});
        }
    }
    while (!stk.empty()) {
        li now = stk.top().F;
        li par = stk.top().S;
        stk.pop();
        parent[now] = par;
        for (auto child : children[now]) {
            in_links[child].erase(now);
            if (in_links[child].empty()) {
                stk.push({child, now});
            }
        }
    }



    rin{
        cout << parent[i] + 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 16512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int h = sc.nextInt();
			int w = sc.nextInt();
			sc.nextLine();

			String[][] pic = new String[h][w];
			for (int i = 0; i < h; i++) {
				pic[i] = sc.nextLine().split("");
			}

			int i2 = -1;
			for (int i = 0; i < h * 2; i++) {
				i2 = ((i + 2) / 2) - 1;
				for (int j = 0; j < w; j++) {
					System.out.print(pic[i2][j]);
				}
				System.out.println();
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 31040
#define _GLIBCXX_DEBUG
#include <cstdio>
#include <cstdint>
//#define NDEBUG
#include <cassert>
#include <vector>
#include <algorithm>

int main() {
  auto dsum=[](intmax_t n) {
    int d=0;
    while (n) {
      d += n%10;
      n /= 10;
    }
    return d;
  };

  intmax_t K;
  scanf("%jd", &K);

#if 0
  for (intmax_t i=1; i<=K; ++i) {
    if (i > 9 && i%10 < 9) continue;
    fprintf(stderr, "%jd: %d (%.12f)\n", i, dsum(i), i*1.0/dsum(i));
  }
  return 1;
#endif

  std::vector<intmax_t> res;
  for (int i=1; i<=9; ++i)
    res.push_back(i);

  int d=0;
  for (intmax_t i=10; i<=1e16; i*=10) {
    ++d;
    for (int j=1; j<=9; ++j) {
      if (d >= 3 && j <= d-2) {
        for (int k=1; k<=9; ++k)
          res.push_back(i*j+i/10*k-1);
      }
      if (d >= 14 && j <= d-13) {
        for (int k=1; k<=9; ++k)
          res.push_back(i+i/100*(10*(j-1)+k)-1);
      }
      res.push_back(j*i+i-1);
    }
  }

  std::sort(res.begin(), res.end());

  fprintf(stderr, "%zu\n", res.size());
  assert(std::is_sorted(res.begin(), res.end(), [&](intmax_t x, intmax_t y) {
    return x*1.0/dsum(x) < y*1.0/dsum(y);
  }));
  for (intmax_t i=0; i<K; ++i) {
    fprintf(stderr, "%jd: %d (%.12f)\n", res[i], dsum(res[i]), res[i]*1.0/dsum(res[i]));
    printf("%jd\n", res[i]);
  }
}


Measured memory_bytes: 256
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    L = nl()
    l = max(L)
    L.remove(l)
    if l < sum(L):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
#include <iostream>
#include <vector>
#define T 1001
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
ll func(int);
int N,s,t,j;
string n[T];
vector<int> e[T];
 
main(){
  cin>>N;
  for(j=0;j<N;j++) cin>>n[j];
  while(--N) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
}

ll func(int x){
  ll r=0,i;
  if(!S){
    if(n[x]=="E") return 1;
    return 2;
  }
  if(n[x][0]=='E'){
    r++;
    for(i=0;i<S;i++) r*=func(E);
    if(n[x]=="E?") r++;
  }
  else if(n[x][0]=='A'){
    for(i=0;i<S;i++) r+=func(E);
    if(n[x]=="A?") r++;
  }else{
    r++;
    for(i=0;i<S;i++) r*=(1+func(E));
    if(n[x]=="R") r--;
  }
  return r%M;
}

Measured memory_bytes: 1356
#!/usr/bin/env python3

n, a, b, c = map(int, input().split())
S = []
for _ in range(n):
    S.append(input())

ans = []
for i in range(n):
    if S[i] == "AB":
        if a == b == 0:
            print("No")
            exit(0)
        elif a < b or (a == b and i != n - 1 and "A" in S[i+1]):
            ans.append("A")
            a += 1
            b -= 1
        else:
            ans.append("B")
            a -= 1
            b += 1
    elif S[i] == "BC":
        if b == c == 0:
            print("No")
            exit(0)
        elif c < b or (c == b and i != n - 1 and "C" in S[i+1]):
            ans.append("C")
            c += 1
            b -= 1
        else:
            ans.append("B")
            c -= 1
            b += 1
    else:
        if c == a == 0:
            print("No")
            exit(0)
        elif c < a or (c == a and i != n - 1 and "C" in S[i+1]):
            ans.append("C")
            c += 1
            a -= 1
        else:
            ans.append("A")
            c -= 1
            a += 1
print("Yes")
print("\n".join(ans))
exit(0)

Measured memory_bytes: 17508
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int X,t;
	cin>>X>>t;
	if(t<=X){
		
		cout<<X-t<<endl;
	}
	
	else if(t>=X){
		
		cout<<0<<endl;
	}
	
}

Measured memory_bytes: 256
x=list(input())

if (x[0]==x[1])and(x[2]==x[3])and(x[0]!=x[2]):
    print('Yes')
elif (x[0]==x[2])and(x[1]==x[3])and(x[0]!=x[1]):
    print('Yes')
elif (x[0]==x[3])and(x[1]==x[2])and(x[0]!=x[1]):
    print('Yes')
else :
    print('No')


Measured memory_bytes: 3064
import sys
# input = sys.stdin.readline
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
s = [input() for _ in range(n)]


def bracket(x):
    # f: final sum of brackets '(':+1, ')': -1
    # m: min value of f
    f = m = 0
    for i in range(len(x)):
        if x[i] == '(':
            f += 1
        else:
            f -= 1
        m = min(m, f)
    # m <= 0
    return f, m


l1 = []
l2 = []
for i in range(n):
    fi, mi = bracket(s[i])
    if fi >= 0:
        l1.append((fi, mi))
    else:
        l2.append((fi, mi))

l1.sort(key=lambda x: -x[1])
l2.sort(key=lambda x: -(x[0] - x[1]))
l = l1 + l2
v = 0
for fi, mi in l:
    if v + mi >= 0:
        v += fi
    else:
        v = -1
        break

ans = 'Yes' if v == 0 else 'No'
print(ans)


Measured memory_bytes: 99504
#include<stdio.h>
int main(void)
{
 int i;
 int a;
 char s[100000];
 scanf("%s",s);
 for(i=1;s[i];i++){
     if(s[i]==s[i-1]){
        if(s[i]=='0')
           s[i]='1';
        else
           s[i]='0';
     a++;
     }
 }
 printf("%d",a);
}

Measured memory_bytes: 256
typedef long long llong;

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

int main(void) {
	int n; cin >> n;
	vector<llong> A(n), B(n), C(n);
	for (int i = 0; i < n; i++) scanf("%lld", &A[i]);
	for (int i = 0; i < n; i++) scanf("%lld", &B[i]);
	for (int i = 0; i < n; i++) scanf("%lld", &C[i]);

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	llong res = 0;
	for (int j = 0; j < n; j++) {
		llong key = B[j];
		llong low = lower_bound(A.begin(), A.end(), key) - A.begin();
		llong up = C.begin() + n - upper_bound(C.begin(), C.end(), key);
		res += (up * low);
	}

	cout << res << endl;

	return 0;
}

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

public class Main {

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

		int arrSize = in.nextInt(), array[] = new int[arrSize];
		for(int i = 0; i < arrSize; i++) {
			array[i] = Integer.parseInt(in.next());
		}

		int query = in.nextInt();
		for(int i = 0; i < query; i++) {
			int odr = Integer.parseInt(in.next()), begin = Integer.parseInt(in.next()), end = Integer.parseInt(in.next());

			if(odr == 0) {
				int min = array[begin];
				for(int j = begin + 1; j < end; j++) {
					min = Math.min(array[j], min);
				}
				out.println(min);
			}
			else {
				int max = array[begin];
				for(int j = begin + 1; j < end; j++) {
					max = Math.max(array[j], max);
				}
				out.println(max);
			}
		}
		out.flush();
		in.close();
	}

}



Measured memory_bytes: 34444
n = int(input())
l = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    t1, x1, y1 = l[i]
    t2, x2, y2 = l[i + 1]
    if (abs(x1 - x2) + abs(y1 - y2)) % 2 != (t2 - t1) % 2 or t2 - t1 < abs(x1 - x2) + abs(y1 - y2):
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 61400
#include <iostream>

using namespace std;

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

  int a[n][m];
  int b[m];
  int c[n];
  
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin>>a[i][j];
    }
   }
  
  for(int i=0; i<m; i++){
    cin>>b[i];
  }

   for(int i=0; i<n; i++){
     c[i]=0;
     
     for(int j=0; j<m; j++){                                                         
       c[i]+=(a[i][j]*b[j]);
       //cout <<a[i][j]<<" "<<b[j]<<endl;
    }                                                                               
   }

   for(int i=0; i<n; i++){
     cout <<c[i]<<endl;
   }
  

  return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	else {
		return(gcd(b, a%b));
	}
}
int main() {
	int n;
	cin >> n;
	int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int L[100000];
	for (int i = 1; i < n; i++) {
		L[0] = 0;
		L[i] = gcd(L[i - 1], a[i - 1]);
	}
	int R[100000];
	for (int i = n - 2; i >= 0; i--) {
		R[n - 1] = 0;
		R[i] = gcd(R[i + 1], a[i + 1]);
	}
	int M[100000];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		M[i] = gcd(L[i], R[i]);
		ans = max(ans, M[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdlib>
using namespace std;

const int INF = 2e9;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; ++i) cin >> h[i];

	vector<int> dp(n, INF);
	dp[0] = 0;

	for (int i = 1; i < n; ++i) {
		for (int j = i - 1; j >= max(0, i - k); --j) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}

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


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;

}

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

class Solve {
private:
	using vc = std::vector<char>;
	using vvc = std::vector<vc>;

	using i3 = std::array<int, 3>;
	using i4 = std::array<int, 4>;

	int W, H;
	int calcNum(const i3 &arr)
	{
		return (arr[0] * W + arr[1]) * 2 + arr[2];
	}
	bool isIn(const i4 &arr)
	{
		return 0 <= arr[1] && arr[1] < H && 0 <= arr[2] && arr[2] < W;
	}

public:
	bool is_last_query{};
	Solve()
	{
		scanf("%d%d", &W, &H);
		if (W == 0)
		{
			is_last_query = true;
			return;
		}

		vvc cliff(H, vc(W));
		for (int i{}; i < H; i++)
			for (int j{}; j < W; j++)
				scanf(" %c", &cliff[i][j]);
		
		std::vector<int> distance(H * W * 2, 1 << 30);
		std::priority_queue<i4, std::vector<i4>, std::greater<i4>> dij;
		for (int i{}; i < W; i++)
			if (cliff[H - 1][i] == 'S')
			{
				distance[calcNum({H - 1, i, 0})] = distance[calcNum({H - 1, i, 1})] = 0;
				dij.push({0, H - 1, i, 0});
				dij.push({0, H - 1, i, 1});
			}
		
		while (!dij.empty())
		{
			i4 now{dij.top()};
			dij.pop();
			if (now[0] > distance[calcNum({now[1], now[2], now[3]})])
				continue;
			if (cliff[now[1]][now[2]] == 'T') break;
			for (int h_i{-2}; h_i <= 2; h_i++)
				for (int w_i{1}; w_i + std::abs(h_i) <= 3; w_i++)
				{
					i4 next{now};
					next[1] += h_i;
					if (next[3])
						next[2] += w_i;
					else
						next[2] -= w_i;
					if (!isIn(next)) continue;
					if (cliff[next[1]][next[2]] == 'X' || cliff[next[1]][next[2]] == 'S') continue;
					if (cliff[next[1]][next[2]] != 'T')
						next[0] += cliff[next[1]][next[2]] - '0';
					next[3] ^= 1;
					int id{calcNum({next[1], next[2], next[3]})};
					if (next[0] >= distance[id]) continue;
					distance[id] = next[0];
					dij.push(next);
				}
		}
		int min{1 << 30};
		for (int i{}; i < W; i++)
			if (cliff[0][i] == 'T')
				min = std::min({min, distance[calcNum({0, i, 0})], distance[calcNum({0, i, 1})]});
		if (min == (1 << 30)) puts("-1");
		else printf("%d\n", min);
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;  // 1e9+7
const int INF = 100100100;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T;
  cin >> S >> T;
  int ans = 0;
  REP(i, 3) {
    if (S[i] == T[i]) ans++;
  }
  cout << ans << '\n';
}

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

#ifdef DEBUG
#define watch(x) cout << "DEBUG: " << (#x) << " = " << (x) << endl
#else
#define watch(x) ;
#endif

#define endl "\n"
const int INF = 0x3f3f3f3f;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - (((begin) > (end)) << 1))

#define fi first
#define se second
#define pb push_back
#define all(X) begin(X),end(X)

#define rd1(x) scanf("%d", &x)
#define rd2(x, y) scanf("%d%d", &x, &y)
#define rd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define rdl1(x) scanf("%lld", &x)
#define rdl2(x, y) scanf("%lld%lld", &x, &y)
#define rdl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)

#pragma GCC optimize ("Ofast")
#pragma GCC target("avx,avx2")

#define int long long

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

ii bc[100005];

bool comp (ii i, ii j) {
	return i.se < j.se;
}

int32_t main() {

#ifdef DEBUG
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	rdl2(n,m);

	priority_queue<int, vi, greater<int>> q;
	rep(i,0,n) {
		int tmp;
		rdl1(tmp);
		q.push(tmp);
	}

	rep(i,0,m) {
		rdl2(bc[i].fi,bc[i].se);
	}

	sort(bc, bc+m, comp);
	reverse(bc, bc+m);

	rep(i,0,m) {
		if(bc[i].se < q.top())
			break;
		else {
			int b = bc[i].fi;

			while(b>0){
				if(q.top() < bc[i].se){
					q.pop();
					q.push(bc[i].se);
				} else
					break;

				b--;
			}
		}
	}
	
	int res = 0;
	while(!q.empty()){
		res += q.top();
		q.pop();
	}

	cout << res << endl;

	return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MOD = 1000000007;

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> coord(N + 10, vector<int>(N + 10, 0));
    vector<vector<int>> sum_x(N + 10, vector<int>(N + 10, 0));
    vector<vector<int>> sum_xy(N + 10, vector<int>(N + 10, 0));

    rep(i, M) {
        int l, r;
        cin >> l >> r;
        coord[l][r]++;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            sum_x[i][j] += sum_x[i][j - 1] + coord[i][j];
        }
    }

    for (int j = 1; j <= N; j++) {
        for (int i = 1; i <= N; i++) {
            sum_xy[i][j] += sum_xy[i - 1][j] + sum_x[i][j];
        }
    }

    rep(i, Q) {
        int p, q;
        cin >> p >> q;
        cout << sum_xy[q][q] + sum_xy[p - 1][p - 1] - sum_xy[p - 1][q] - sum_xy[q][p - 1] << endl;
    }

}

Measured memory_bytes: 3968
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr double DINF =100000000000000000.0;
constexpr long long INF = 100000000000000000;
const double PI = acos(-1);

int main() {
	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 8) << endl;
}

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

ll a[200005], b[200005];

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        ll A;
        cin >> A;
        a[i] = a[i - 1] + A;
    }
    for (int i = 1; i <= m; i++) {
        ll B;
        cin >> B;
        b[i] = b[i - 1] + B;
    }

    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (a[i] > k) break;
        int j = upper_bound(b + 1, b + m + 1, k - a[i]) - b - 1;
        ans = max(ans, i + j);
    }

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


Measured memory_bytes: 6752
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

bool eq(vi P, vi Q) {
	rep(i, P.size()) {
		if (P[i] != Q[i]) {
			return false;
		}
	}
	return true;
}

ll gcd(ll a, ll b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

	vi AC(N, false);
	ll ac = 0;
	vi P(N, 0);
	rep(i, M) {
		ll p;
		string s;
		cin >> p >> s;
		p--;
		if (AC[p]) {
			continue;
		}

		if (s == "AC") {
			AC[p] = true;
			ac++;
		}
		else {
			P[p]++;
		}
	}

	ll pena = 0;
	rep(i, N) {
		if (AC[i]) {
			pena += P[i];
		}
	}

	cout << ac << " " << pena << endl;

	return 0;
}


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

int main(){
	int n,q,loop;
	cin >> n;
	vector<int> S(n);
	for(loop=0;loop<n;loop++){
		cin >> S[loop];
	}
	cin >> q;
	vector<int> T(q);
	for(loop=0;loop<q;loop++){
		cin >> T[loop];
	}
	int C=0,bs,bsr,bsl,bss;
	for(loop=0;loop<q;loop++){
		bs=n/2+n%2;
      	bsl=0;
		bsr=n+1;
		while(bsr-bs&&bs-bsl){
			if(S[bs-1]==T[loop]){
				C++;
				break;
			}else if(S[bs-1]>T[loop]){
              	bsr=bs;
				bs=(bs+bsl)/2+(bs+bsl)%2;
			}else{
              	bsl=bs;
				bs=(bsr+bs)/2+(bsr+bs)%2;
			}
		}
	}
	cout << C << endl;
	return 0;
}


Measured memory_bytes: 3336
#include <stdio.h>
int main() {
    int i,n,k,s,count=0;
    int point[200][3]={0};
    int an[200]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
	for(k=0;k<3;k++){
	    scanf("%d",&point[i][k]);
        }
    }
    for(i=0;i<3;i++){
	for(k=0;k<n;k++){
	    for(s=0;s<n;s++){
		if(point[k][i]==point[s][i] && s!=k){
		    count=1;
		    break;
		}
	    }
	    if(count==0)
                an[k] += point[k][i];
		count=0;
        }
    }
    for(k=0;k<n;k++){
        printf("%d\n",an[k]);
    }
    return 0;
}

Measured memory_bytes: 1028
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
b = []
for _ in range(m):
    b.append(int(input()))

for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j]*b[j]

    print(ans)


Measured memory_bytes: 6008
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= print . solve

solve :: [Int] -> Int
solve xs = fst $ foldl' ff (0, y) ys
    where
        (y : ys) = sort xs
        ff (acc, a) b = (acc + b - a, b)

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

vector<ll> Z(400, 0);

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll X; cin >> X;
  map<ll, int> mp;
  REP(i, 400){
    Z[i] = pow(i, 5);
    mp[Z[i]] = i;
  }
  REP(i, 400){
    if(X == Z[i]){
      cout << i << " " << 0 << endl;
      return 0;
    }
    if(mp[abs(X - Z[i])] > 0){
      if(X > Z[i]){
        cout << i << " " << mp[abs(X - Z[i])]*(-1) << endl;
        return 0;
      }else{
        cout << i << " " << mp[abs(X - Z[i])] << endl;
        return 0;
      }
      return 0;
    }
  }


}

Measured memory_bytes: 4116
#include<stdio.h>

struct DICE {
	int data;
	struct DICE *N;
	struct DICE *E;
	struct DICE *S;
	struct DICE *W;
	struct DICE *bottom;
	};

int main(void){
	struct DICE A[6],*NOW,*BEFORE;
	int i;
	char str[105];
	NOW=&A[0];
	for(i=0;i<6;i++){scanf("%d",&A[i].data);}

	A[0].N=&A[4];
	A[0].E=&A[2];
	A[0].S=&A[1];
	A[0].W=&A[3];
	A[0].bottom=&A[5];

	scanf("%s",str);
i=0;
while(str[i]!='\0'){
switch(str[i]){
	case 'S':
		/*S?????¢*/
		BEFORE=NOW;
		NOW=NOW->N;
		NOW->N=BEFORE->bottom;
		NOW->S=BEFORE;
		NOW->E=BEFORE->E;
		NOW->W=BEFORE->W;
		NOW->bottom=BEFORE->S;
		break;
	case 'N':
		/*N?????¢*/
		BEFORE=NOW;
		NOW=NOW->S;
		NOW->N=BEFORE;
		NOW->S=BEFORE->bottom;
		NOW->E=BEFORE->E;
		NOW->W=BEFORE->W;
		NOW->bottom=BEFORE->N;
		break;
	case 'E':
		/*E?????¢*/
		BEFORE=NOW;
		NOW=NOW->W;
		NOW->N=BEFORE->N;
		NOW->S=BEFORE->S;
		NOW->E=BEFORE;
		NOW->W=BEFORE->bottom;
		NOW->bottom=BEFORE->E;
		break;
	case 'W':
		/*W?????¢*/
		BEFORE=NOW;
		NOW=NOW->E;
		NOW->N=BEFORE->N;
		NOW->S=BEFORE->S;
		NOW->E=BEFORE->bottom;
		NOW->W=BEFORE;
		NOW->bottom=BEFORE->W;
		break;
	}
i++;
}
printf("%d\n",NOW->data);
	return 0;
}

Measured memory_bytes: 596
s = input()
t = input()

dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]

for i in range(1, len(s) + 1):
    for j in range(1, len(t) + 1):
        if s[i - 1] == t[j - 1]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

nums = len(s)
numt = len(t)
d = dp[nums][numt]
ans = ""

while True:
    if d == 0:
        break
    if dp[nums][numt - 1] == d:
        numt -= 1
    elif dp[nums - 1][numt] == d:
        nums -= 1
    else:
        ans += s[nums - 1]
        nums -= 1
        numt -= 1
        d -= 1

print(ans[::-1])


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define int long long

string S;
signed main(){
    cin >> S;
    int N = S.length();
    int minimum = INT_MAX;
    rep(i, N-2){
        int t = abs(753-stoi(S.substr(i,3)));
        minimum = min(t,minimum);
    }
    cout << minimum << endl;
}

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

typedef long long int ll;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int ans = 0;
	for (int i = 1; i <= 5; i++){
		int x;
		cin >> x;
		if (x == 0) ans = i;
	}	
	cout << ans << '\n';
}

Measured memory_bytes: 3568
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<complex>
#include<iomanip>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define pi 3.14159265358979

int main(void){

	string x; int n;

	cin >> n;
	rep(i,n){

		cin >> x;

		int s=x.size(),t=0;
		rep(j,s) t+=x[j]-'0';

		int u=(t-1)/9+s-1;
		if(u%2==0) cout << "Audrey wins." << endl;
		else cout << "Fabre wins." << endl;

	}

	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

struct Elem{
	int cost;
	char wh;
	int pos;
	Elem(int c, char w, int p):cost(c), wh(w), pos(p){}
	bool operator < (const Elem& e) const{
		return cost < e.cost;
	}
};

int main(){
	int w, h;
	cin >> w >> h;
	int wcnt = 0, hcnt = 0;
	vector<Elem> pq;
	for(int i=0;i<w;i++){
		int num;
		cin >> num;
		pq.emplace_back(num, 'w', i);
	}
	for(int i=0;i<h;i++){
		int num;
		cin >> num;
		pq.emplace_back(num, 'h', i);
	}
	sort(pq.begin(), pq.end());

	ll ans = 0;
	for(int i=0;i<pq.size();i++){
		int cost = pq[i].cost;
		char wh = pq[i].wh;
		int pos = pq[i].pos;
		if(wh == 'h'){
			wcnt++;
			ll num = w + 1 - hcnt;
			ans += num * cost;
		}else{
			hcnt++;
			ll num = h + 1 - wcnt;
			ans += num * cost;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4076
// AOJ 0298 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0298)
#include<cstdio>
#include<set>
#include<utility>
#define rep(i,a) for(int i=0;i<(a);++i)
#define itr(it,a) for(auto it=(a).begin();it!=(a).end();++it)

typedef std::pair<int, int> P;

int N, M;
std::set<P> s;

int main()
{
	scanf( "%d", &N );
	rep( i, N )
	{
		int h, m;
		scanf( "%d%d", &h, &m );
		s.insert( P( h, m ) );
	}
	scanf( "%d", &M );
	rep( i, M )
	{
		int h, m;
		scanf( "%d%d", &h, &m );
		s.insert( P( h, m ) );
	}

	itr( it, s )
		printf( "%d:%02d%c", it->first, it->second, std::distance(it, s.end())==1?'\n':' ' );

	return 0;
}

Measured memory_bytes: 1032