akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    string s;
    cin >> s;

    s.push_back('T');
    int n = s.size();

    int x, y;
    cin >> x >> y;

    vector<int> a[2];
    int c = 0, d = 0, f = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'F') {
            c++;
        } else {
            if (f == 0) {
                x -= c;
                f = 1;
            } else {
                a[d].push_back(c);
            }
            c = 0;
            d ^= 1;
        }
    }

    int b = 0;
    for (int d = 0; d < 2; d++) {
        vector<int> dp(8000);
        dp[0] = 1;

        int m = a[d].size();
        for (int i = 0; i < m; i++) {
            int a1 = a[d][i];
            for (int j = 0; j < 8000; j++) {
                if (dp[j] & 1) {
                    dp[abs(j - a1)] |= 2;
                    dp[j + a1] |= 2;
                }
            }
            for (int j = 0; j < 8000; j++) {
                dp[j] >>= 1;
            }
        }

        if (dp[abs(d == 0 ? x : y)]) b++;
    }

    cout << (b == 2 ? "Yes" : "No") << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

vector<ll> G[202020];
vector<ll> acc(202020, 0);
vector<ll> res(202020, 0);

void dfs(ll now, ll par, ll val){
	//dump(now)
	val += acc[now];
	res[now] = val;
	REP(i, G[now].size()){
		ll next = G[now][i];
		if(next == par) continue;
		dfs(next, now, val);
	}
	return;
}

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

    ll N, Q;
    cin >> N >> Q;
    REP(i, N-1){
    	ll a, b;
    	cin >> a >> b;
    	a--, b--;
    	G[a].push_back(b);
    	G[b].push_back(a);
    }

    while(Q--){
    	ll p, x;
    	cin >> p >> x;
    	p--;
    	acc[p] += x;
    }
    dfs(0, -1, 0);

    REP(i, N) cout << res[i] << " ";
    cout <<endl;

    return 0;
}

Measured memory_bytes: 32128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
char s[200005];
int main(){
	scanf("%s",&s);
	int n = strlen(s);
	int c = 0;
	ll ans = 0;
	for(int i=0;i<n;i++){
		c += (s[i] == 'W');
	}
	for(int i=0;i<n;i++){
		if(s[i] == 'B') ans += c;
		else c --;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
import sys
from collections import deque
import time
import bisect
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=[int(input()) for i in range(n)]
# print(a)
ans=deque([a[0]])
for i in range(1,n):
    loc=bisect.bisect_left(ans,a[i])
    if loc==0:
        ans.appendleft(a[i])
    else:
        ans[loc-1]=a[i]
# print(ans)
print(len(ans))

Measured memory_bytes: 47704
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

using Graph = vector<vector<int>>;

int main() {
	int N, M, U, V; cin >> N >> U >> V;
	M = N - 1;
	U--; V--;

	Graph G(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<int> distU(N, -1), distV(N, -1);
	queue<int> que;
	distU[U] = 0;
	que.push(U);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (auto nv : G[v]) {
			if (distU[nv] == -1) {
					distU[nv] = distU[v] + 1;
					que.push(nv);
			}
		}
	}
	queue<int>().swap(que);
	distV[V] = 0;
	que.push(V);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (auto nv : G[v]) {
			if (distV[nv] == -1) {
					distV[nv] = distV[v] + 1;
					que.push(nv);
			}
		}
	}

	int cmax = 0;
	rep(i, N) {
		if (distU[i] >= distV[i]) continue;
		cmax = max(distV[i], cmax);
	}
	cout << (cmax - 1) << endl;
}

Measured memory_bytes: 6656
import sys

stdin = sys.stdin

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

ques = ord('?')

def Z_algo2(s):
    ls = len(s)
    lcp = [0]*ls
    lcp[0] = ls
    i,j = 1,0
    while i < ls:
        while i+j < ls and (s[j] == s[i+j] or s[j] == '?' or s[i+j] == '?'):
            j += 1
        lcp[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < ls and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp

def Z_algo(s,t):
  l = [0]*len(t)
  for i in range(len(t)):
    j = 0
    while j < len(s) and i+j < len(t) and (s[j] == t[i+j] or s[j] == ques or t[i+j] == ques):
      j += 1
    l[i] = j
  return l

a = list(map(ord, list(ns())))
b = list(map(ord, list(ns())))
c = list(map(ord, list(ns())))

l = [a, b, c]
g = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if i != j:
            g[i][j] = Z_algo(l[i],l[j])
            # print(i,j,g[i][j])
ans = sum(len(x) for x in l)
for i in range(3):
    for j in range(3):
        if i == j: continue
        k = 3-i-j
        li = [ii for ii in range(len(l[i])) if g[j][i][ii] >= min(len(l[i]) - ii, len(l[j]))]
        lj = [ii for ii in range(len(l[j])) if g[k][j][ii] >= min(len(l[j]) - ii, len(l[k]))]
        lk = [ii for ii in range(len(l[i])) if g[k][i][ii] >= min(len(l[i]) - ii, len(l[k]))]

        for ii in li:
            for jj in lj:
                kk = ii + jj
                if kk >= len(l[i]) or g[k][i][kk] >= min(len(l[i]) - kk, len(l[k])):
                    c = max(len(l[i]), ii + len(l[j]), kk + len(l[k]))
                    if ans > c: ans = c
        for ii in li:
            for kk in lk:
                if kk < ii + len(l[j]): continue
                c = max(len(l[i]), ii + len(l[j]), kk + len(l[k]))
                if ans > c: ans = c
print(ans)


Measured memory_bytes: 53980
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main(){
  int a,b;
  cin>>a>>b;
  for(int i=1;i<1000000;i++){
    if((i*8)/100==a&&(i*10)/100==b){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
char data[101][101];
bool flag[101][101] = { 0 };
int a, b;
int cnt;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int flag2=0;
int HH,WW;

int dfs(int H,int W,char C,int aa,int bb,int flag2){
	if(flag[H][W]==1){return flag2;}
	else{flag[H][W]=1;flag2=1;}
	for (int i = 0; i < 4; ++i) {
		HH=dy[i]+H;
		WW=dx[i]+W;
		if((HH>=0&&HH<aa&&WW>=0&&WW<bb)&&data[HH][WW]==C){
			dfs(HH,WW,C,aa,bb,flag2);
		}
	}
	return flag2;
}

int main(void) {
	while (cin >> a >> b) {
		if (a == 0 && b == 0) {
			break;
		}
		for (int i = 0; i < a; ++i) {
			cin >> data[i];
		}
		cnt=0;
		flag2=0;
		for (int i = 0; i < 101; ++i) {
			for (int j = 0; j < 101; ++j) {
				flag[i][j] = 0;
			}
		}

		for (int i = 0; i < a; ++i) {
			for (int j = 0; j < b; ++j) {
				if(dfs(i,j,data[i][j],a,b,0)==1)cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 3840
n = int(input())

inAB = 0
B_A = 0
x_A = 0
B_x = 0

for _ in range(n):
    s = input()
    if s[0] == "B" and s[-1] == "A":
        B_A += 1
    elif s[0] == "B":
        B_x += 1
    elif s[-1] == "A":
        x_A += 1
    inAB += s.count("AB")

ans = inAB
ans += min(x_A, B_x)
if B_A != 0:
    if x_A == 0 and B_x == 0:
        ans += B_A - 1
    else:
        ans += B_A

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a.at(i);
    int q;
    cin >> q;
    vector<int> b(q), c(q);
    REP(i, q) cin >> b.at(i) >> c.at(i);
    ll sum = 0;
    REP(i, n) sum += a.at(i);

    vector<int> numcounter(100005);
    REP(i, n) numcounter.at(a.at(i))++;

    REP(i, q) {
        sum += numcounter.at(b.at(i)) * (c.at(i) - b.at(i));
        numcounter.at(c.at(i)) += numcounter.at(b.at(i));
        numcounter.at(b.at(i)) = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 4792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int N = in.nextInt();
		int Q = in.nextInt();
		char[] S = in.next().toCharArray();

		long[] count = new long[N];
		Arrays.fill(count, 0);

		for (int i = 1; i < N; i++) {
			if (S[i - 1] == 'A' && S[i] == 'C') {
				count[i] = count[i - 1] + 1;
			} else {
				count[i] = count[i - 1];
			}
		}

		for (int i = 0; i < Q; i++) {
			int l = in.nextInt();
			int r = in.nextInt();
			System.out.println(count[r - 1] - count[l - 1]);
		}
	}
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
    int K,S;
    int ans = 0;
    cin >> K >> S;
    rep(i,K + 1){
        rep(j,K + 1){
            if (S - (i + j) <= K && S - (i + j) >= 0) ans++;
        }
    }
    printf ("%d\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)  //  rep
#define repr(i,a,n) for(int i=a;i>n;i--)  //  repリバース
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9000000000000000000 //  巨大数INF
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max({a,b,c}) - min({a,b,c}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};

int dirs[300];
bool avils[4];

bool adira(int c) {
  if(c==0)
    return true;
  if(c < 0 && avils[1])
    return true;
  if(c > 0 && avils[3])
    return true;
  return false;
}

int main() {
  bool ans = false;
  dirs['N'] = 0;
  dirs['S'] = 2;
  dirs['E'] = 1;
  dirs['W'] = 3;
  string S ;
  cin >> S ;
  int r = 0, c = 0;
  for(char s : S) {
    int d = dirs[(int) s];
    r += dr[d];
    c += dc[d];
    avils[d] = true;
  }
  if(r==0 && c==0)
    ans |= true;
  else if(r==0)
    ans |= adira(c);
  else if(r < 0 && avils[2])
    ans |= adira(c);
  else if(r > 0 && avils[0])
    ans |= adira(c);
  printf("%s\n", ans? "Yes" : "No");  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1000100

int num[1100][1100] ={};
int place_y[SIZE], place_x[SIZE];

const int MAX_P = SIZE; //max
bool prime[MAX_P+1];

void Eratosthenes(void){
  for(int i=2;i<=MAX_P;i++)
    prime[i]=true;
  
  for(int i=2;i*i<=MAX_P;i++)
    if(prime[i])  
      for(int j=i;i*j<=MAX_P;j++)
        prime[i*j]=false;
}

int dp1[1100][1100], dp2[1100][1100], visited[1100][1100];

bool solve(){
  int m,n;
  scanf("%d%d",&m,&n);

  if(m == 0) return false;
  
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  memset(visited, 0, sizeof(visited));

  dp1[place_y[n]][place_x[n]] = prime[n];

  if(prime[n])
    dp2[place_y[n]][place_x[n]] = n;
  else
    dp2[place_y[n]][place_x[n]] = 0;

  visited[place_y[n]][place_x[n]] = true;

  int max_dp1 = 0, max_dp2 = 0;
  
  for(int i=0;i<1070;i++){
    for(int j=1;j<1100-1;j++){
      if(num[i][j] <= 0 || num[i][j] > m || !visited[i][j]) continue;
      
      if(max_dp1 < dp1[i][j]){
        max_dp1 = dp1[i][j];
        max_dp2 = dp2[i][j];
      }else if(max_dp1 == dp1[i][j]){
        max_dp2 = max(max_dp2,dp2[i][j]);
      }
      
      for(int k=-1;k<=1;k++){
        if(dp1[i+1][j+k] < dp1[i][j] + prime[num[i+1][j+k]]){
          dp1[i+1][j+k] = dp1[i][j] + prime[num[i+1][j+k]];
          
          if(prime[num[i+1][j+k]])
            dp2[i+1][j+k] = num[i+1][j+k];
          else
            dp2[i+1][j+k] = dp2[i][j];

        }else if(dp1[i+1][j+k] == dp1[i][j] + prime[num[i+1][j+k]]){
          
          if(prime[num[i+1][j+k]])
            dp2[i+1][j+k] = num[i+1][j+k];
          else
            dp2[i+1][j+k] = max(dp2[i+1][j+k], dp2[i][j]);
        }

        visited[i+1][j+k] = true;
      }
      
    }
  }

  printf("%d %d\n",max_dp1, max_dp2);
  
  return true;
}


int main(){

  int max_x = 560, min_x = 560, max_y = 560, min_y = 560;
  int x = 560, y = 560;
  int d = 0;

  int dx[8] = {1,0,-1,0};
  int dy[8] = {0,-1,0,1};
  
  for(int i=1;i<=1000000;i++){
    place_x[i] = x;
    place_y[i] = y;

    num[y][x] = i;
    
    int next_x = x + dx[d];
    int next_y = y + dy[d];
    
    if(next_x < min_x || max_x < next_x || next_y < min_y || max_y < next_y){
      d = (d+1)%4;
    }

    min_x = min(min_x,next_x);
    max_x = max(max_x,next_x);
    min_y = min(min_y,next_y);
    max_y = max(max_y,next_y);

    x = next_x;
    y = next_y;
  }

  Eratosthenes();

  while(solve());
  
  return 0;
}

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

int main()
{
ll k , q ;
cin >> k >> q ;
vector<ll> d(k);
rep(i, k){
  cin >> d[i];
}
vector<vector<ll>> v(q, vector<ll>(3,0) );
rep(i,q){
  cin >> v[i][0] >> v[i][1] >> v[i][2];
  v[i][0]--;
  v[i][1]%=v[i][2];
}
rep(i,q){
  ll zero=0,sum=0,ans=0;
  rep(j,k){
    sum+=d[j]%v[i][2];
    if(d[j]%v[i][2]==0)zero++;
  }
  ans+=v[i][0]/k*(k-zero)-(v[i][1]+(v[i][0]/k)*sum)/v[i][2];
  ll st=(v[i][1]+v[i][0]/k*sum)%v[i][2];
  rep(j,(v[i][0])%k){
    if(st<(st+d[j])%v[i][2])ans++;
    st=(st+d[j])%v[i][2];
  }
  cout << ans << endl;
}
return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
ll a[maxn];
ll s, x[maxn];

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

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
    s += a[i];
  }
  a[n+1]=a[1];

  x[1]=s;
  for (int i=2; i<=n; i+=2) {
    x[1] -= 2LL*a[i];
  }


  for (int i=2; i<=n; i++) {
    x[i] = 2LL*a[i-1] - x[i-1];
  }

  for (int i=1; i<=n; i++) {
    cout<<x[i]<<" ";
  }
  cout<<endl;  

  return 0;
}


Measured memory_bytes: 6272
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define inf 200000000000
const int maxnodes=1005;
#define ll long long
#define N 2501
#define EPS 0.01
#define ld long double






int32_t main()
{
    IOS;

    string s;
    cin >> s;
    int cnt = 1;
    bool ch = 1;
    int n = s.length();
    for(int i = 1;i < n;i++)
    {
        if(s[i] == s[i-1] and ch)
        {
            if(i < n - 1)
            {
                cnt++;
                i++;
                ch = 0;
            }

        }
        else
        {
            ch = 1;
            cnt++;
        }
        // cerr <<  i << " " 
    }
    cout << cnt;

}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int is_sosuu(int n);
int main()
{
    int n;
    cin >> n;
    while ( n!=0 ) 
    {
        int count=0;
        for (int i = n+1; i <= 2*n; i++) 
        {
            if (is_sosuu(i) == 1) 
            {
                count++;
            } 
        }
        
        cout << count << endl;
        cin >> n;
    }
    return 0;
}
//nが素数なら1を返す
int is_sosuu(int n)
{
    if(n == 1)
    {
        return 0;
    }
    for (int i = 2; i <= sqrt( (double)n ) ; i++) 
    {
        if( (n % i) == 0) 
        {
            return 0;
        }
    }
    return 1;
}

Measured memory_bytes: 1160
<?php
fscanf(STDIN, "%d", $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($a);
$ans_1 = max($a);
$diff = $prev = PHP_INT_MAX;
for ($i = 0; $i < $n; $i++) {
    $tmp = abs($ans_1 / 2 - $a[$i]);
    if ($diff > $tmp) {
        if ($a[$i] === $ans_1) continue;
        $ans_2 = $a[$i];
        $diff = $tmp;
    }
    if ($prev < $tmp) break;
    $prev = $tmp;
}
printf("%d %d", $ans_1, $ans_2);


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

int main()
{
	int N;
	cin >> N;
	vector<string> S(N);
	int AC=0, WA=0, TLE=0, RE=0;
	for (int i = 0; i < N; ++i)
	{
		cin >> S[i];

		if (S[i] == "AC") ++AC;
		else if (S[i] == "WA")++WA;
		else if (S[i] == "TLE")++TLE;
		else if (S[i] == "RE")++RE;
	}
	
	cout << "AC x " << AC << endl;
	cout << "WA x " << WA << endl;
	cout << "TLE x " << TLE << endl;
	cout << "RE x " << RE << endl;
}

Measured memory_bytes: 6412
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import Counter

h, w = map(int, input().split())
field = []
ans = []
for hgt in range(h):
    line = [int(item) for item in input().split()]
    ret = []
    for i in range(1, w):
        if line[i-1] % 2 == 1:
            line[i-1] -= 1
            line[i] += 1
            ans.append((hgt+1, i, hgt+1, i+1))
    field.append(line)

for i in range(1, h):
    if field[i-1][w-1] % 2 == 1:
        field[i-1][w-1] -= 1
        field[i][w-1] += 1
        ans.append((i, w, i+1, w))

print(len(ans))
for line in ans:
    print(*line)

Measured memory_bytes: 26972
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: usize,
        M: usize,
        A: [usize; M],
    }

    let S: usize = A.iter().sum();

    if S > N {
        println!("-1");
    } else {
        println!("{}", N - S);
    }

}


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

char dict[30600000];

long encode(const char *key){
  int n=strlen(key),i;
  long sum=0;
  long keta=1;
  for(i=0;i<n;i++){
    if (key[i]=='A')      sum = sum + keta;
    else if (key[i]=='C') sum = sum + (keta << 1);
    else if (key[i]=='G') sum = sum + (keta << 1) + keta;
    else if (key[i]=='T') sum = sum + (keta << 2);
    keta=keta*5;
  }
  return (sum);
}

void insert(const char *key2) {
  long key=encode(key2);
  long keta=key/8;
  dict[keta]=(dict[keta]|(1<<(key%8)));
}

int find_h(const char *key2) {
  long key=encode(key2);
  return (dict[key/8] & 1<<(key%8));
}

int main(void) {
  long n,i;
  scanf("%ld\n",&n);
  for(i=0;i<n;i++){
    char cmd[8], str[14]; scanf("%s %s\n",cmd, str);
    if(cmd[0]=='i') {
      insert(str);
    }
    else {
      if(find_h(str)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1432
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  long a, b, c;
  readf("%s %s %s\n", &a, &b, &c);

  auto res = long.max;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    res = 0;
  } else {
    if (a != 1) {
      res = min(res, b * c);
    }
    if (b != 1) {
      res = min(res, a * c);
    }
    if (c != 1) {
      res = min(res, a * b);
    }
  }
  res.writeln;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

int main(void) {
    ll K;
    cin >> K;
    ll a[100001];
    ll i, j;
    for(i=0; i<K; i++) {
        cin >> a[i];
    }
    ll L=2, R=3;
    for(i=K-1; i>=0; i--) {
        L=(L+a[i]-1)/a[i]*a[i];
        R=(R+a[i]-1)/a[i]*a[i];
    }
    if(L==R)
        prin(-1);
    else
        cout << L << " " << R-1 << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]

import heapq
f1 = []; f2 = []
heapq.heapify(f1); heapq.heapify(f2)
f1_sum = 0; f2_sum = 0

for i in range(n):
  heapq.heappush(f1,a[i])
  f1_sum += a[i]
  heapq.heappush(f2,-a[3*n-1-i])
  f2_sum += a[3*n-1-i]
  
L = [f1_sum]
R = [f2_sum]

from collections import deque
L = deque(L)
R = deque(R)

for i in range(n,2*n):
  heapq.heappush(f1,a[i])
  f1_sum += a[i]
  f1_sum -= heapq.heappop(f1)
  L.append(f1_sum)
  
  heapq.heappush(f2,-a[3*n-1-i])
  f2_sum += a[3*n-1-i]
  f2_sum -= -heapq.heappop(f2)
  R.append(f2_sum)

ans = -float('inf')
for i in range(n+1):
  ans = max(ans,L.pop()-R.popleft())
print(ans)

Measured memory_bytes: 121232
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int n,arr[100005],ans=0;
int main()
{
	scan(n);
	for(int i=1;i<=n;i++)
		scan(arr[i]);
	for(int i=1;i<=n;i++)
	{
		if(arr[i]==i)
		{
			if(i!=n&&arr[i+1]==i+1)
				swap(arr[i],arr[i+1]);
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
n, m, v, p = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

def ok(x):
    if x == -1:
        return False
    if x >= n-p:
        return True
    cnt = 0
    for i in range(x+1, n-p):
        cnt += max((A[x]+m)-A[i], 0)
    cnt += m*x
    cnt += m*(p-1)
    if max(m*(v-1) - cnt, 0)+A[n-p] <= A[x]+m:
        return True
    else:
        return False

l = -1
r = n-1
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(n-r)

Measured memory_bytes: 62576
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const double eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=2e6+10;
	
	double a[N];
	void main()
	{
		int n=qread(),k=qread();fo(i,1,n) a[i]=(qread()+1)/2.0;
		double ans=0;fo(i,1,k) ans+=a[i];double now=ans;
		fo(i,k+1,n) now+=a[i]-a[i-k],chmax(ans,now);printf("%lf",ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	#endif
	srand(time(0));
	mine::main();
	if(DD) cerr<<"Time: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

Measured memory_bytes: 1792
#include <stdio.h>
 
int main(void){
    int x,i,j,r,c,A[200][200]={0};
    scanf("%d %d",&r,&c);
    for(j=0;j<r;j++){
        for(i=0;i<c;i++){
            scanf("%d",&x);
            A[i][j]+=x;
        }
    }
    for(j=0;j<r;j++){
        for(i=0;i<c;i++){
            A[c][j]+=A[i][j];
        }
    }
    for(i=0;i<=c;i++){
        for(j=0;j<r;j++){
            A[i][r]+=A[i][j];
        }
    }
    for(j=0;j<=r;j++){
        for(i=0;i<=c;i++){
            printf("%d", A[i][j]);
            if(i!=c) printf(" ");
        }
        printf("\n");
    }
     
    return 0;
}


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

const ll INF = 1LL << 60;

ll dist[310][310];
ll dist2[310][310];
ll N, M, L;
ll Q;
int main() {
    cin >> N >> M >> L;

    rep(i, N)rep(j, N) {
        if (i == j) dist[i][j] = 0;
        else dist[i][j] = INF;
    }
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    cin >> Q;

    rep(k, N)rep(i, N)rep(j, N) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    // <= L で通過できるか
    rep(i, N)rep(j, N) dist2[i][j] = INF;
    rep(i, N)rep(j, N) {
        if (dist[i][j] <= L) dist2[i][j] = 1;
    }
    rep(k, N)rep(i, N)rep(j, N) {
        dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
    }

    rep(i, Q) {
        ll s, t;
        cin >> s >> t;
        s--; t--;
        // if (dist[s][t] == INF) {
        //     cout << -1 << endl;
        //     continue;
        // }
        // cout << dist[s][t] << endl;
        ll ans = dist2[s][t] - 1;
        if (dist2[s][t] == INF) ans = -1;
        cout << ans << endl;
    }
}

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

using namespace std;
#define BUF (1000)
#define ll long long 
#define INF 1000

int n;


typedef struct {
	int x;int y;
}P;

P red[BUF];
P blue[BUF];
int cnt_r[BUF];
int cnt_b[BUF];

int A[BUF][BUF];

int main(void){
	cin >> n;

	for(int i=1;i<=n;i++){
		int a,b;
		cin >> a>> b;
		red[i] = {a,b};	
	}

	for(int i=1;i<=n;i++){
		int a,b;
		cin >> a>> b;
		blue[i] = {a,b};	
	}
	int cnt = 0;

	while(1){
		int mn = INF;
		int mni=0;
		for (int i = 1; i <= n; i++)
		{
			if (mn > blue[i].x)
			{
				mni = i;
				mn = blue[i].x;
			}
		}
		
		int ymn = -INF;
		int ymni=0;
		for (int j = 1; j <= n; j++)
		{
			if (red[j].x < blue[mni].x && red[j].y < blue[mni].y){
				if (ymn < red[j].y)
				{
					ymni = j;
					ymn = red[j].y;
				}
			}
		}
		red[ymni].y=INF;
		blue[mni].x=INF;

		if(mn==INF)break;
		if (ymn != -INF)
		{
			cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import heapq
n,m = map(int,input().split())
A = list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)

for i in range(m):
    tmp_min = heapq.heappop(A)
    heapq.heappush(A, (-1)*(-tmp_min//2))
print(-sum(A))

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> num(n+3, 0);
  rep(i, n+3) num[i] = i;
  rep(i, n+2) num[i+1] += num[i];
  int ans = distance(num.begin(), lower_bound(ALL(num), n));
  for(int i = 1; i <= ans; ++i) {
    if(i == num[ans]-n) continue;
    cout << i << endl;
  }
}

Measured memory_bytes: 78336
#include<stdio.h>
#include<iostream>

using namespace std;
int resarch(int *A ,int X, int Y,int N);

int main(){

    int X,Y,Z;
    int A[7] = {1,3,5,7,8,10,12};
    int B[4] = {4,6,9,11};
    int C[1] = {2};


    cin  >> X  >> Y;

    Z = resarch(A,X,Y,7);
    Z = Z + resarch(B,X,Y,3);

    if(Z == 1) cout << "Yes" << endl;
    else cout << "No" <<endl;

}
//線形サーチ



int resarch(int *A ,int X, int Y,int N)
{

  int c = 0;
  for(int i = 0; i < N; i++)
  {

    if( A[i] == X )  c++;
    if( A[i] == Y)   c++;
  }

  if(c == 2){
    c = 1;
    return c;
  }
  else{
    c = 0;
    return c;
  }

}


Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    H,W,K = LMIIS()
    table = []
    for i in range(H):
        table.append(list(input()))
    ans = 0
    for i in range(2**H):
        for j in range(2**W):
            count_black = 0
            for x in range(H):
                if 2**x & i:
                    for y in range(W):
                        if 2**y & j and table[x][y] == '#':
                            count_black += 1
            if count_black == K:
                ans += 1

    print(ans)





    
main()

Measured memory_bytes: 68680
#include <iostream>
using namespace std;
int num[1000000];
int main() {
	while(true){
		
	int n,m,cont=0,ioi=0;
	cin >> n ;
	if(n==0 )
		break;
	cin >> m;
	for(int i=0;i<m;i++){
		char a;
		cin >> a;
		num[i]=0;
		if(a=='I')
			num[i]++;
		if(cont==0){
			if(num[i])
				cont++;
		}
		else if(num[i]!=num[i-1]){
			cont++;
		}
		else{
			cont=0;
			if(num[i]){
				cont =1;
			}
		}
		if(cont % 2 == 1 && 2*n+1<=cont)
			ioi++;
	}
	cout << ioi << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 5064
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,K = map(int,input().split())
ans = 0
A = list(map(int,input().split()))
for i in range(K,N):
    if A[i] > A[i-K]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 33124
n,*l=map(int,open(0).read().split())
d=sorted([a-b for a,b in zip(l[:n],l[n:])])+[0]
m=[x for x in d if x<0];s=sum(m)
c=~n-1 if sum(d)<0 else len(m)-1
for i in d[::-1]:
	s+=i;c+=1
	if s>=0:
		break
print(c)

Measured memory_bytes: 25076
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
    vector<vector<int>> to(n);
    vector<int> ans(n, -1);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<P> Q;
    Q.emplace(0, 0);
    while(!Q.empty()) {
        P p = Q.front();
        Q.pop();
        if (ans[p.first]!=-1) continue;
        ans[p.first] = p.second;
        for (int nxt: to[p.first]) {
            if (ans[nxt]!=-1) continue;
            Q.emplace(nxt, p.first);
        }
    }
    rep(i,n-1) if(ans[i+1]==-1) {
        cout << "No" << "\n";
        return 0;
    }
    cout << "Yes" << "\n";
    rep(i,n-1) cout << ans[i+1]+1 << "\n";
	return 0;
}


Measured memory_bytes: 10788
n,x,y = gets.chomp.split.map(&:to_i)
ans = Array.new(n-1,0)

(1..n-1).each do |i|
  (i+1..n).each do |j|
    dist = [(i-j).abs, (x-i).abs + (y-j).abs + 1].min
    ans[dist-1] += 1
  end
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define endl '\n'
const int mod=1e9+7,u=1e5+5;

vector<int> adj[u];

bool mark[u];
vector<int> dis(u),val(u);
void dfs(int v){
    mark[v]=true;
    for(int i:adj[v]){
        dis[i]=max(dis[v]+1,dis[i]);
        val[i]--;
        if(!val[i]){
            dfs(i);
        }
    }
    return;
}

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

    int n,m;
    cin>>n>>m;
    set<int> s;
    while(m--){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        val[y]++;
    }    

    for(int i=1;i<=n;i++){
        if(!mark[i] and !val[i]){
            dfs(i);
        }
    }
    cout<<*max_element(all(dis));

    return 0;
}

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

vector<long long> trial_division(long long n) {
	vector<long long> factorization;
	while (n % 2 == 0) { 
		factorization.push_back(2); 
		n /= 2; 
	}
	return factorization; 
}

int main() 
{
    long long n, sum=0;
    cin >> n;
    for (long long i=0; i<n; i++)
    {
        long long a; cin >> a;
        vector<long long> v = trial_division(a);
        sum += v.size();
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
#include <set>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	vector<int> dp(10005,0);
	dp[0]=true;
	int n;
	cin>>n;
	vector<int> v;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		v.push_back(a);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=10000;j>=0;j--)
		{
			if(dp[j])
				dp[j+v[i]]=true;
		}
	}
	int maxi=0;
	for(int i=10000;i>=0;i--)
	{
		if(i%10!=0&&dp[i])
		{
			maxi=i;
			break;
		}
	}
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,C,v;
	while(cin>>N>>C) {
		VVI D(C, VI(C));
		VVI co(3, VI(C));
		REP(y, C) REP(x, C) cin>>D[y][x];
		REP(y, N) REP(x, N) {
			cin>>v;
			co[(x+y)%3][v-1]++;
		}
//		DD(D);DD(co);
		ll ans = INF;
		REP(a, C) REP(b, C) REP(c, C) if(a!=b && a!=c && b!=c) {
			ll lans = 0;
			REP(i, C) lans += D[i][a]*co[0][i];
			REP(i, C) lans += D[i][b]*co[1][i];
			REP(i, C) lans += D[i][c]*co[2][i];
			ans = min(ans, lans);
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define N 100010
int n,a[N];
char str[N];
inline bool check(){
	for(int i=2;i<n;++i){
		if(a[i]==0){
			if(str[i]=='o') a[i+1]=a[i-1];
			else a[i+1]=a[i-1]^1;
		}else {
			if(str[i]=='o') a[i+1]=a[i-1]^1;
			else a[i+1]=a[i-1];
		}
	}
	if(a[1]==0){
		if(str[1]=='o'){
			if(a[2]!=a[n]) return false;
		}else{
			if(a[2]==a[n]) return false;
		}
	}else{
		if(str[1]=='o'){
			if(a[2]==a[n]) return false;
		}else{
			if(a[2]!=a[n]) return false;
		}
	}
	if(a[n]==0){
		if(str[n]=='o'){
			if(a[1]!=a[n-1]) return false;
		}else{
			if(a[1]==a[n-1]) return false;
		}
	}else{
		if(str[n]=='o'){
			if(a[1]==a[n-1]) return false;
		}else{
			if(a[1]!=a[n-1]) return false;
		}
	}
	for(int i=1;i<=n;++i) 
		if(!a[i]) printf("S");
		else printf("W");
	puts("");
	return true;
}
int main(){
	scanf("%d%s",&n,str+1);
	a[1]=0;a[2]=0;
	if(check()) return 0;
	a[1]=0;a[2]=1;
	if(check()) return 0;
	a[1]=1;a[2]=0;
	if(check()) return 0;
	a[1]=1;a[2]=1;
	if(check()) return 0;
	puts("-1");
	return 0;
}

Measured memory_bytes: 768
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, m = tin()
	#s = input()
	dd=[0]*(n+1)
	for _ in range(m):
		a, b = tin()
		dd[a] += 1
		dd[b] += 1
	for v in dd:
		if v % 2 == 1:
			return 'NO'
	else:
		return 'YES'
		
	
	
#+++++
isTest=False

def pa(*vl):
	if not isTest:
		return
	for v in vl:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 70604
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<utility>
using namespace std;
#define ll long long;
long long mod=1000000007;





bool isPrime(long long n)
{

    if (n <= 1)
        return false;


    for (long long i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}






bool isPalindrome(string s)
{

    int l = 0;
    int h = s.size()-1;


    while (h > l)
    {
        if (s[l++] != s[h--])
        {

            return false;
        }
    }
   return true;
}







int ternarySearch(int l, int r, int key, int ar[])

{
    while (r >= l) {

        // Find the mid1 and mid2
        int mid1 = l + (r - l) / 3;
        int mid2 = r - (r - l) / 3;

        // Check if key is present at any mid
        if (ar[mid1] == key) {
            return mid1;
        }
        if (ar[mid2] == key) {
            return mid2;
        }

        // Since key is not present at mid,
        // check in which region it is present
        // then repeat the Search operation
        // in that region

        if (key < ar[mid1]) {

            // The key lies in between l and mid1
            r = mid1 - 1;
        }
        else if (key > ar[mid2]) {

            // The key lies in between mid2 and r
            l = mid2 + 1;
        }
        else {

            // The key lies in between mid1 and mid2
            l = mid1 + 1;
            r = mid2 - 1;
        }
    }

    // Key not found
    return -1;
}






  int binarySearch(int arr[], int l, int r, int x)
{
    while (l <= r) {
        int m = l + (r - l) / 2;

        // Check if x is present at mid
        if (arr[m] == x)
            return m;

        // If x greater, ignore left half
        if (arr[m] < x)
            l = m + 1;

        // If x is smaller, ignore right half
        else
            r = m - 1;
    }

    // if we reach here, then element was
    // not present
    return -1;
}





int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
int x;
cin>>x;
if(x>=30){
   cout<<"Yes"<<endl;
}else{
   cout<<"No"<<endl;
}
 return 0;   
}

Measured memory_bytes: 3648
#define ll long long int
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	ll n;
	cin >> n;
	vector <ll> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	vector <ll> dp(n);
	dp[0] = 0; dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1792