akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

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

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 10;
struct PT{int x, y;};
struct PT pts[10];

double distPtPt(PT pt1, PT pt2){
	return sqrt((pt1.x - pt2.x) * (pt1.x - pt2.x) + (pt1.y - pt2.y) * (pt1.y - pt2.y));
}

int fact[9];

int main()
{
	init();
	fact[0] = fact[1] = 1;
	lpi(i, 2, 9){
		fact[i] = fact[i-1] * i;
	}
	int  n;
	double ans = 0;
	cin >> n;
	lp(i, n){
		cin >> pts[i].x >> pts[i].y;
		lp(j, i){
			ans += distPtPt(pts[i], pts[j]);
		}
	}
	cout << setprecision(20) << ans*((double)fact[n-1]/fact[n]) * 2;
	return 0;
}


Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    in >> n >> k;
    vector<ll> l(n);
    REP(i, n) in >> l[i];
    SORT(l);
    ll ans = 0;
    REP(i, k){
        ans += l[l.size() - 1 - i];
    }
    out << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, mod = 1e9 + 7;
ll n, a[N], sum, ans;
int main()
{
    std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i], sum += a[i], sum %= mod;
	for(int i = 1; i <= n; i++)
	{
		sum = (sum + mod - a[i]) % mod;
		ans = (ans + sum * a[i] % mod) % mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char S;
  cin >> S;
  
  if(S == 'a' || S == 'i' || S == 'u' || S == 'e' || S == 'o'){
    cout << "vowel" << endl;
  }
  else{
	cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
n, k = gets.chomp.split(' ').map(&:to_i)
d = gets.chomp.split(" ").map(&:to_i)
genzai = n
while true do
  keta = []
  ((Math.log10(genzai)).to_i + 1).times do |i|
    waru = 10 ** i
    keta << (genzai / waru) % 10
  end
  if keta & d == []
    puts genzai
    break
  end
  genzai += 1
end

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 2020;
const int M = 1e5;

int n, p, a[N], force[N];
vi adj[M], fact[M], primes;

void factor(int n, vi &p) {
    for (int d = 2; d*d <= n; d++) if (n%d == 0) {
        p.pb(d);
        while (n%d == 0) n /= d;
    }
    if (n > 1) p.pb(n);
}

bool vis[M], enabled[N];
int dfs(int u) {
    if (vis[u]) return n;
    vis[u] = true;

    int res = n;
    if (u < n && enabled[u]) res = u;
    for (int v : adj[u]) res = min(res, dfs(v));
    return res;
}

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

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

    cin >> n;
    forn(i,n) cin >> a[i];
    sort(a, a+n);

    forn(i,n) {
        factor(a[i], fact[i]);
        for (auto x : fact[i]) primes.pb(x);
    }
    sort(all(primes));
    primes.erase(unique(all(primes)), primes.end());
    p = si(primes);

    forn(u,n) {
        for (auto x : fact[u]) {
            int v = n + lower_bound(all(primes), x) - primes.begin();
            adj[u].pb(v);
            adj[v].pb(u);
        }
    }

    vi res(n);
    fill_n(enabled, n, true);
    forn(i,n) {
        //forn(j,n) if (enabled[j]) cerr << a[j] << ','; cerr << endl;
        fill_n(vis,n+p,false);
        forn(j,i) vis[res[j]] = true;
        res[i] = -1;
        forn(u,n) if (!vis[u]) {
            res[i] = max(res[i], dfs(u));
        }
        forn(j,n) {
            if (gcd(a[res[i]], a[j]) > 1) enabled[j] = true;
            else if (a[j] > a[res[i]]) enabled[j] = false;
        }
        //D(res[i]);
    }
    for (auto x : res) cout << a[x] << ' ';

    return 0;
}


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

int gcd(int a,int b){
	if(b==0)return a;
  	else return gcd(b,a%b);}

signed main(){
	int a,b,c;cin>>a>>b>>c;
  int d=gcd(a,b);
  if(c%d==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
A, B = (int(i) for i in input().split())

card = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

a = card.index(A)
b = card.index(B)

if a > b:
    Ans = 'Alice'
elif b > a:
    Ans = 'Bob'
else:
    Ans = 'Draw'

print(Ans)


Measured memory_bytes: 3060
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
a = Counter(l)
b = a.most_common()
c = []
for i,j in b:
    if j>=4:
        c.append(i)
        c.append(i)
    elif j>=2:c.append(i)
c.sort()
print(c[-1]*c[-2] if len(c)>=2 else 0)

Measured memory_bytes: 21540
#include<iostream>
#include<algorithm>
#include <string>
#include <cstring>
#include<climits>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	if (n == v.size()) {
		cout << "YES" << '\n';
	}
	else cout << "NO" << '\n';





}

Measured memory_bytes: 1400
"""import collections
n=int(input())
a=list(map(int,input().split()))
ac=collections.Counter(a)

for k,i in ac.items():
"""
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
count=0
ans4=0
ans2=[0]*2
for i in range(n-1):
    #print(a[i],i)
    if a[i]==a[i+1]:
        count+=1
    if i==(n-2) or a[i]!=a[i+1]:
        if 1<=count:
            if 3<=count:
                ans4=max(ans4,a[i])
                ans2.append(a[i])
            else:
                ans2.append(a[i])
        count=0
ans2.sort(reverse=True)
#print(ans2)  
print(max(ans4**2,ans4*ans2[0],ans2[0]*ans2[1]))

Measured memory_bytes: 14252
# include <algorithm>
# include <iostream>
# include <queue>
# include <vector>

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int cum[n];
    fill(cum, cum+n, 0);
    for (int i = 0; i < n; i++) {
        if (i == 0) continue;
        if (s[i-1] == 'A' && s[i] == 'C') {
            cum[i] = cum[i-1] + 1;
        } else {
            cum[i] = cum[i-1];
        }
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << cum[r] - cum[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1488
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int cnt_1 = 0;
    int cnt_2 = 0;
    char correct = '1';

    for (int i = 0; i < N; i++) {
        if (S[i] != correct)
            cnt_1 += 1;
        else
            cnt_2 += 1;
        correct = (correct == '0' ? '1' : '0');
    }

    cout << min(cnt_1, cnt_2) << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  ll A[N+1];
  A[0] = 0;
  for(ll i=1;i<=N;++i) cin>>A[i];
  for(ll i=1;i<=N;++i) A[i] += A[i-1];
  vector<ll> arr;
  for(ll i=0;i<=N;++i) {
    for(ll j=i+1;j<=N;++j) {
      arr.push_back(A[j]-A[i]);
    }
  }
  vector<ll> newarr;
  for(ll i=42;i>=0;--i) {
    newarr.clear();
    for(ll j=0;j<arr.size();++j) {
      if((arr[j]&(1ull<<i))!=0) newarr.push_back(arr[j]);
    }
    if(newarr.size()>=K) arr = newarr;
  }
  ll ans = arr[0];
  for(ll i=1;i<K;++i) ans &= arr[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 9024
n, m, q = map(int, input().split())
queries = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
 
def calc_score(p):
    score = 0
    for a, b, c, d in queries:
        if p[b-1] - p[a-1] == c:
            score += d
    return score
 
def f(p):
    if len(p) == n:
        global ans
        ans = max(ans, calc_score(p))
        return
    l = p[-1] if len(p) else 1
    for x in range(l, m+1):
        f(p + [x])
 
f([])
 
print(ans)

Measured memory_bytes: 9092
import bisect
 

N = int(input())
S = list(str(input()))

pos = [[] for _ in range(26)]
for x,s in enumerate(S):
    num = ord(s)-ord("a")
    pos[num].append(x)

q = int(input())
for _ in range(q):
    m,a,b = map(str,input().split())
    if m == "1":
        a = int(a)-1
        if S[a] == b:
            continue
        else:
            popind = bisect.bisect_left(pos[ord(S[a])-ord("a")],a)
            pos[ord(S[a])-ord("a")].pop(popind)
            bisect.insort(pos[ord(b)-ord("a")],a)
            S[a] = b
    else:
        a,b = int(a)-1,int(b)-1
        count = 0
        for i in range(26):
            l = bisect.bisect_left(pos[i],a)
            if l >= len(pos[i]):
                continue
            if pos[i][l] <= b:
                count += 1
        print(count)

Measured memory_bytes: 28552
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  cout << N*N*N	<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

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

    int N;
    cin >> N;

    vector<long double> A;

    for (int i = 0; i < N; ++i)
    {
        long double a;
        cin >> a;
        if (0 == a)
        {
            cout << "0" << endl;
            return 0;
        }
        A.push_back(a);
    }

    long double LIMIT = pow(10, 18);
    //cout << LIMIT << endl;
    long double ans = 1L;

    for (int i = 0; i < N; ++i)
    {
        ans = ans * A[i];
        if (ans < 0)
        {
            cout << "-1" << endl;
            return 0;
        }
    }

    if (ans > LIMIT)
    {
        cout << "-1" << endl;
    }
    else if (ans < 0)
    {
        cout << "-1" << endl;
    }
    else
    {
        //cout << ans << endl;
        cout << std::fixed << setprecision(0) << floor(ans) << endl;
    }

    return 0;
}


Measured memory_bytes: 5404
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,n,x=0;cin>>n;
	while(n--){cin>>a;x+=a%2;}
	cout<<(x?"first":"second")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = 200000;

vector<int>G[MAXN + 5], q1[MAXN + 5], q2[MAXN + 5];
void addedge(int u, int v) {
	G[u].push_back(v), G[v].push_back(u);
}

int mx[MAXN + 5], pos[MAXN + 5];
void dfs1(int x, int f, int m, int p) {
	mx[x] = m, pos[x] = p;
	if( x > m ) {
		for(int i=0;i<G[x].size();i++)
			if( G[x][i] != f ) dfs1(G[x][i], x, x, G[x][i]);
	}
	else {
		for(int i=0;i<G[x].size();i++)
			if( G[x][i] != f ) dfs1(G[x][i], x, m, p);
	}
	if( x != 1 ) {
		q1[mx[x] - 1].push_back(x);
		if( pos[x] == x && mx[mx[x]] > x )
			q2[mx[mx[x]] - 1].push_back(x);
	}
}
int ans[MAXN + 5], g[MAXN + 5];
void dfs2(int x, int f) {
	if( x != 1 ) {
		if( pos[x] == x ) g[x] += ans[mx[x]];
		ans[x] += g[pos[x]];
	}
	for(int i=0;i<G[x].size();i++)
		if( G[x][i] != f ) dfs2(G[x][i], x);
}

bool tag[MAXN + 5]; int fa[MAXN + 5], siz[MAXN + 5];
int find(int x) {return fa[x] = (fa[x] == x ? x : find(fa[x]));}
void unite(int x, int y) {
	int fx = find(x), fy = find(y);
	fa[fx] = fy, siz[fy] += siz[fx];
}
void add(int &sum, int x) {
	x = find(x);
	if( !tag[x] ) {
		tag[x] = true;
		sum += siz[find(x)];
	}
}
void erase(int x) {tag[find(x)] = false;}

int main() {
	int N; scanf("%d", &N);
	for(int i=1;i<N;i++) {
		int u, v; scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	dfs1(1, 0, 0, 1);
	for(int i=1;i<=N;i++) fa[i] = i, siz[i] = 1;
	for(int i=0;i<=N;i++) {
		for(int j=0;j<G[i].size();j++)
			if( G[i][j] <= i ) unite(i, G[i][j]);
		for(int j=0;j<q1[i].size();j++) {
			int x = q1[i][j], s = 0;
			for(int p=0;p<G[x].size();p++)
				if( G[x][p] <= i ) add(s, G[x][p]);
			add(s, x), ans[x] += s;
			
			for(int p=0;p<G[x].size();p++)
				if( G[x][p] <= i ) erase(G[x][p]);
			erase(x);
		}
		for(int j=0;j<q2[i].size();j++) {
			int x = q2[i][j], s = 0;
			for(int p=0;p<G[x].size();p++)
				if( G[x][p] <= i ) add(s, G[x][p]);
			add(s, x), g[x] -= s;
			
			for(int p=0;p<G[x].size();p++)
				if( G[x][p] <= i ) erase(G[x][p]);
			erase(x);
		}
		
	}
	ans[1] = 1; dfs2(1, 0);
	for(int i=2;i<=N;i++)
		printf("%d%c", ans[i] - 1, (i == N ? '\n' : ' '));
}

Measured memory_bytes: 39672
n,m=map(int, input().split())
r = []
flg = []

for i in range(n):
    r.append(str(0))
    flg.append(str(0))

if n == 1 and m == 0:
    print('0')
    exit()
if n == 2 and m == 0:
    print('10')
    exit()
if n == 3 and m == 0:
    print('100')
    exit()

for i in range(m):
    s,c = map(int, input().split())
    if n == 1 and s == 1 and c == 0:
        print('0')
        exit()
    elif n > 1 and s == 1 and c == 0:
        print('-1')
        exit()

    if flg[s-1] == '0':
        r[s-1] = str(c)
        flg[s-1] = '1'
    elif flg[s-1] == '1' and int(r[s-1]) == c:
        r[s-1] = str(c)
    else:
        print('-1')
        exit()

if n > 1 and r[0] == '0':
    r[0] = '1'
    print(''.join(r))
else:
    print(''.join(r))



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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,a,b;cin>>n>>a>>b;
  cout<<min(a*n,b)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int R[55][4];
int X[11];
int N,M,Q;
int Ans;
void dfs(int x)
{
	if(x>N)
	{
		int Cnt=0;
		for(int i=0;i<Q;i++)
			if(X[R[i][1]]-X[R[i][0]]==R[i][2])
				Cnt+=R[i][3];
		Ans=max(Ans,Cnt);
		return ;
	}
	for(int i=X[x-1];i<=M;i++)
	{
		X[x]=i;
		dfs(x+1);
	}
	return ;
}
int main()
{
	cin>>N>>M>>Q;
	for(int i=0;i<Q;i++)
		for(int j=0;j<4;j++)
			cin>>R[i][j];
	X[0]=1;
	dfs(1);
	cout<<Ans<<endl;
	return 0;
}

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

using namespace std;

constexpr long long INF64 = 1e18;

using Weight=long long;

struct Edge{
    int src,dst;
    Edge(int src,int dst):
    src(src),dst(dst){}
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;

vector<int> tarjan(const Graph& g) {
	int n = g.size(), idx = 0, k = 0, s = 0;
	vector<int>ord(n, -1), low(n), onS(n), cmp(n), stk(n);
	function<void(int)>dfs;
	dfs = [&](int v) {
		ord[v] = low[v] = idx++;
		stk[s++] = v;
		onS[v] = true;
		for (auto &e : g[v]) {
			int w = e.dst;
			if (ord[w] == -1) {
				dfs(w);
				low[v] = min(low[v], low[w]);
			}
			else if (onS[w]) {
				low[v] = min(low[v], ord[w]);
			}
		}
		if (low[v] == ord[v]) {
			while (1) {
				int w = stk[--s];
				onS[w] = false;
				cmp[w] = k;
				if (w == v)break;
			}
			++k;
		}
	};
	for (int v = 0; v<n; ++v)
		if (ord[v] == -1)dfs(v);
	return cmp;
}

int dfs(const Graph &g,int s,vector<int> &memo){
	int ret=1;
	if(memo[s])return memo[s];
	for(auto e:g[s]){
		ret=max(dfs(g,e.dst,memo)+1,ret);
	}
	return memo[s]=ret;
}

int main(){
	int n;
	cin>>n;
	Graph g(n);
	vector<pair<int,int>>contri(n);
	vector<vector<pair<int,int>>>friends(n);
	for(int i=0;i<n;++i){
		int a;
		cin>>a;
		contri[i]=make_pair(a,i);
		friends[i].push_back(contri[i]);
	}
	int m;
	cin>>m;
	for(int i=0;i<m;++i){
		int a,b;
		cin>>a>>b;
		--a;
		--b;
		friends[a].push_back(contri[b]);
		friends[b].push_back(contri[a]);
	}
	for(auto x:friends){
		sort(x.begin(),x.end(),greater<pair<int,int>>());
		for(int i=0;i<x.size()-1;++i){
			g[x[i].second].emplace_back(x[i].second,x[i+1].second);
			if(x[i].first==x[i+1].first){
				g[x[i+1].second].emplace_back(x[i+1].second,x[i].second);
			}
		}
	}
	vector<int>idx=tarjan(g);
	Graph ng(n);
	for(auto es:g){
		for(auto e:es){
			if(idx[e.src]==idx[e.dst])continue;
			ng[idx[e.src]].emplace_back(idx[e.src],idx[e.dst]);
		}
	}
	vector<int>memo(n,0);
	for(auto es:ng){
		if(es.size()>=1)dfs(ng,es[0].src,memo);
	}
	Weight ans=0;
	for(auto x:idx){
		if(!memo[x])memo[x]=1;
		ans+=memo[x];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 31292
N, A, B = map(int, input().split())

if A > B:
    print(0)
    exit()
elif A == B:
    print(1)
    exit()
else:
    if N == 1:
        print(0)
        exit()

ans = (B * (N - 1) + A) - (A * (N - 1) + B) + 1
print(ans)


Measured memory_bytes: 9052
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    string s;
    cin >> s;
    bool odd_flag = true, even_flag = true;
    REP(i, s.length()) {
        if (i % 2 == 0) {
            if (s[i] == 'L')
                odd_flag = false;
        } else {
            if (s[i] == 'R')
                even_flag = false;
        }
        if (!odd_flag && !even_flag)
            break;
    }
    //cout << odd_flag << " " << even_flag << endl;
    if (odd_flag && even_flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> H(N+1);
    for (int i = 1; i <= N; i++) cin >> H[i];
    vector<ll> nxt(N+1, 0);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        nxt[A] = max(nxt[A], H[B]);
        nxt[B] = max(nxt[B], H[A]);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (H[i] > nxt[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844
open Batteries
open Printf
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in

  let rec aux i =
    if i*7 > n then "No" else
      (
        if (n - i*7) mod 4 = 0 then "Yes" else 
          aux (i+1)
      )
  in
  Printf.printf "%s\n" @@
  aux 0



Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (const auto &item : s) {
        if (item == '1') {
            cnt++;
        }
    }

    printf("%d", cnt);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
using namespace std;

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2*N -1],dneg[2*N -1];

bool X[N][N];

void initialize(){
    for (int i=0; i<N; i++){
        row[i] = FREE;
        col[i] = FREE;
    }
    for(int i=0; i<2*N - 1; i++ ){
         dpos[i] = FREE;
        dneg[i] = FREE;
    }
}

void printBoard(){
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(X[i][j]){
                if(row[i] != j) return;
            }
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
          cout << ((row[i] == j) ? "Q" : ".");
        }
        cout << endl;
    }
}

void recursive(int i){
    if(i==N){
        printBoard();
        return ;
    }
    
    for(int j=0; j<N; j++){
        if(NOT_FREE == col[j] ||
           NOT_FREE == dpos[i+j] ||
           NOT_FREE == dneg[i-j + N -1]) continue;
        
        row[i]=j;
        col[j]=dpos[i+j] = dneg[i-j + N-1] = NOT_FREE;
        recursive(i+1);
        row[i]=col[j] = dpos[i+j] =dneg[i-j+N-1] =FREE;
    }
    }

int main(){
    initialize();
    
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++) X[i][j] =false;
    }
    
    int k;
    cin >> k;
    for(int i=0; i<k; i++){
        int r,c;
        cin >> r >>c;
        X[r][c]=true;
    }
    recursive(0);
    
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  string S;
  cin >> S;
  sort(ALL(S));
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String st = br.readLine();
            String[] s = st.split(" ", 0);
            int N = Integer.parseInt(s[0]);
            int A = Integer.parseInt(s[1]);
            int B = Integer.parseInt(s[2]);
            int j = 0;
            for(int i = 0; i < N; i++){
                int x = Integer.parseInt(br.readLine());
                if(x<A||B-1<x) j++;
            }
            System.out.println(j);
        } catch (IOException ex) {
        }
    }
}

Measured memory_bytes: 8148
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;


int main() {
    int n;

    cin >> n;

    vector<int> a(n);
    vector<int> b(n);

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

    int j = 0;
    for(int i = n - 1; i >= 0; i = i - 2) {
        b[j] = a[i];
        j++;
    }

    int i = 0;
    if(n % 2 == 1) {
        i = 1;
    }
    for(; i < n; i = i + 2) {
        b[j] = a[i];
        j++;
    }

    for(int i = 0; i < n; i++) {
        cout << b[i];
        if(i != n - 1) cout << " ";
    }
    cout << endl;
}

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

bool neighbor_sub(vector<vector<char>> &map, int h, int w, int x, int y) {
    if (x < 0 || x >= w) {
      return false;
    }
    if (y < 0 || y >= h) {
      return false;
    }
    return map[x][y] == '#';
}

bool neighbor(vector<vector<char>> &map, int h, int w, int x, int y) {
    return neighbor_sub(map, h, w, x - 1, y)
      || neighbor_sub(map, h, w, x + 1, y)
      || neighbor_sub(map, h, w, x, y - 1)
      || neighbor_sub(map, h, w, x, y + 1);
}

int main() {
  int h, w;
  cin >> h;
  cin >> w;
  vector<vector<char>> map;
  map.reserve(w);
  for(int i = 0; i < w; i++) {
    map[i].reserve(h);
  }
  for(int y = 0; y < h; y++) {
    for(int x = 0; x < w; x++) {
      cin >> map[x][y];
    }
  }
  for(int y = 0; y < h; y++) {
    for(int x = 0; x < w; x++) {
      if (map[x][y] == '#' && !neighbor(map, h, w, x, y)) {
	cout << "No";
	return 0;
      }
    }
  }  
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
import sys, math,os
from io import BytesIO, IOBase
#data = BytesIO(os.read(0,os.fstat(0).st_size)).readline
# from bisect import bisect_left as bl, bisect_right as br, insort
# from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
# from decimal import Decimal
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
#sys.setrecursionlimit(100000 + 1)
INF = 10**9
mod = 998244353

n=int(data())
d=dd(int)
for i in range(n):
    s=data()
    d[s]+=1
print('AC x', d["AC"])
print('WA x', d["WA"])
print('TLE x', d["TLE"])
print('RE x', d["RE"])








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

int main(void) {
	int n, acc = 0, wac = 0, tlec = 0, rec = 0, i;
	char s[4];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {

		scanf("%s", s);

		if (strcmp(s, "AC") == 0) {
			acc++;
		}
		else if (strcmp(s, "WA") == 0) {
			wac++;
		}
		else if (strcmp(s, "TLE") == 0) {
			tlec++;
		}
		else if (strcmp(s, "RE") == 0) {
			rec++;
		}
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", acc, wac, tlec, rec);
}


Measured memory_bytes: 1716
n = gets.to_i
x = []

n.times do
  x << gets.chomp.to_s
end
x = x.sort
x = x.group_by(&:itself).map{ |key, value| [key, value.count]}.to_h
max = x.values.max
x.each { |key, value|
  if (value == max) then
    puts "#{key}"
  end
}


Measured memory_bytes: 78684
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{

  int t;
  t = 1;
  //cin >> t;
  while (t--)
  {
     string s;
     cin>>s;
     int i,sum=0,x;
      for(i=0;i<s.size();i++)
      {
        sum+=(s[i]-'0');
      }
      if(sum%9==0) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;

  }
}

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

main(void){
  
  int a[36],i,j,tempo,N,b[36],mini;
  char c[36],tempo2,dummy,d[36];

  scanf("%d%c",&N,&dummy);
  for(i=0;i<N;i++){
    scanf("%c%d%c",&c[i],&a[i],&dummy);
    d[i]=c[i];
    b[i]=a[i];
  }
  
  for(i=0;i<N-1;i++){
    for(j=N-1;j>i;j--){
      if(a[j]<a[j-1]){
	tempo=a[j];
	tempo2=c[j];
	a[j]=a[j-1];
	c[j]=c[j-1];
	a[j-1]=tempo;
	c[j-1]=tempo2;
      }
    }
  }

  for(i=0;i<=N-1;i++){
    mini=i;
    for(j=i;j<=N-1;j++){
      if(b[j]<b[mini])mini=j;
    }
    tempo=b[i];
    tempo2=d[i];
    b[i]=b[mini];
    d[i]=d[mini];
    b[mini]=tempo;
    d[mini]=tempo2;
  }
    


  for(i=0;i<N;i++){
    if(i==N-1)printf("%c%d\n",c[i],a[i]);
    else printf("%c%d ",c[i],a[i]);
  }
  printf("Stable\n");

  for(i=0;i<N;i++){
    if(i==N-1)printf("%c%d\n",d[i],b[i]);
    else printf("%c%d ",d[i],b[i]);
  }
  for(i=0;i<N;i++){
    if(c[i]!=d[i]){
      printf("Not stable\n");
      break;
    }
    else if(i==N-1)printf("Stable\n");
  }
    
  
  return 0;
}

Measured memory_bytes: 608
// Author:: Mohammad Faisal
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  long long res =a*b;
  (res&1) ? cout<<"Odd": cout<<"Even";
  return 0;
}

Measured memory_bytes: 256
class UnionFindTree:
    def __init__(self, N):
        self.root = [i for i in range(N)]
        self.friendcount = [1] * N

    def getroot(self, x):
        node = self.root[x]
        if node == x:
            return x
        self.root[x] = self.getroot(node)
        return self.root[x]

    def unite(self, x, y):
        xroot = self.getroot(x)
        yroot = self.getroot(y)
        if xroot == yroot:
            return
        if xroot > yroot:
            self.root[xroot] = yroot
            self.friendcount[yroot] += self.friendcount[xroot]
        else:
            self.root[yroot] = xroot
            self.friendcount[xroot] += self.friendcount[yroot]

    def getfriendcount(self, x):
        xroot = self.getroot(x)
        return self.friendcount[xroot]

    def same(self, x, y):
        if self.getroot(x) == self.getroot(y):
            return True
        return False


N, M, K = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * K
D = [0] * K

for i in range(M):
    A[i], B[i] = map(int, input().split())
for i in range(K):
    C[i], D[i] = map(int, input().split())

tree = UnionFindTree(N + 1)
for i in range(M):
    tree.unite(A[i], B[i])

friendscount = [0] * (N + 1)
blockcount = [0] * (N + 1)
for i in range(M):
    friendscount[A[i]] += 1
    friendscount[B[i]] += 1
for i in range(K):
    if tree.same(C[i], D[i]):
        blockcount[C[i]] += 1
        blockcount[D[i]] += 1

result = [str(tree.getfriendcount(i) - 1 - friendscount[i] - blockcount[i]) for i in range(1, N + 1)]
print(" ".join(result))


Measured memory_bytes: 33072
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n, m;
  scanf("%d%d",&n,&m);
  vi a(m);
  cin >> a;
  for (int i = n;;++i) {
    bool ok = true;
    int x = i;
    while (x) {
      rep(j,m) if (x%10 == a[j]) ok = false;
      x /= 10;
    }
    if (ok) {
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}







Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int euclid(int i, int j){
  if(i%j==0) return j;
  return euclid(j,i%j);
}

int main(){
  int K;
  cin >> K;
  long long sum=0;
  
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
	int tmp=euclid(max(a,b),min(a,b));
	sum+=euclid(max(tmp,c),min(tmp,c));
      }
    }
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> a(n+1),b(n+1),c(n);
  rep(i,n) cin>>a[i+1];
  rep(i,n) cin>>b[i+1];
  rep(i,n-1) cin>>c[i+1];
  int ans=0;
  int now=a[1];
  FOR(i,1,n+1){
    ans+=b[a[i]];
    if(now==a[i]-1){
      ans+=c[now];
    }
    now=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#include "atcoder/all"
using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

using mint = modint998244353;

struct S{
	mint a;
	int size;
};
S op(S l, S r) {
	return S{l.a + r.a, l.size + r.size};
}

S e() {
	return S{0, 0};
}

struct F{
	mint a, b;
};
S mapping(F l, S r) {
	return S{r.a * l.a + r.size * l.b, r.size};
}
F composition(F l, F r) {
	return F{l.a * r.a, l.a * r.b + l.b};
}

F id() {
	return F{1, 0};
}

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

signed main(){
	IOS();
	int N, Q;
	cin >> N >> Q;
	vector<int>a(N);
	cin >> a;

	lazy_segtree<S, op, e, F, mapping, composition, id> seg(N);
	REP(i, N) {
		seg.set(i, S{a[i], 1});
	}
	REP(_, Q) {
		int t;
		cin >> t;
		if(t == 0) {
			int l, r, c, d;
			cin >> l >> r >> c >> d;
			seg.apply(l, r, F{c, d});
		} else {
			int l, r;
			cin >> l >> r;
			out(seg.prod(l, r).a.val());
		}
	}
}

Measured memory_bytes: 35348
#include <stdio.h>

int main(void){
    int num;
    scanf("%d",&num);
    int p[num], i = 0, flag = 0, index[3], j = 0;
    while(i<num){
        scanf("%d",&p[i]);
        if(flag<=2&&p[i]!=i+1){
            flag++;
            index[j] = i;
            j++;
        }
        i++;
    }
    if(!flag)
        printf("YES");
    else if(flag>2)
        printf("NO");
    else{
        if(p[index[0]]==index[1]+1)
            printf("YES");
        else
            printf("NO");
    }
    return 0;
}

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

int main()
{
    int a = 0;
    int b = 0;
    string str;
    cin >> str;

    for (int i = 0; i < (int)str.size(); ++i)
    {
        if (i % 2)
        {
            if (str[i] == '0')
            {
                a++;
            }

            if (str[i] == '1')
            {
                b++;
            }
        }
        else
        {
            if (str[i] == '1')
            {
                a++;
            }

            if (str[i] == '0')
            {
                b++;
            }
        }
    }

    if (a < b)
    {
        cout << a << endl;
    }
    else
    {
        cout << b << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] != 'B') t.push_back(s[i]);
		else if(!t.empty()) t.pop_back();
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,a;
  cin >> n >> a;

  cout << (n%500<=a ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int n, p[128];
int memo[128][8][8];
int solve(int d, int p1, int p2){
  if(memo[d][p1][p2]) return memo[d][p1][p2];
  if(p[d] == p1 && p1 == p2) return memo[d][p1][p2] = 0;
  if(d == n + 1) return memo[d][p1][p2] = 1;
  if(p[d]) return memo[d][p1][p2] = solve(d + 1, p[d], p1);
  int ret = 0;
  if(!(p1 == p2 && p1 == 1))
    ret += solve(d + 1, 1, p1);
  if(!(p1 == p2 && p1 == 2))
    ret += solve(d + 1, 2, p1);
  if(!(p1 == p2 && p1 == 3))
    ret += solve(d + 1, 3, p1);
  return memo[d][p1][p2] = ret % 10000;
}
int main(void){
  int k, a, b;
  scanf("%d %d", &n, &k);
  for(int i = 0;i < k; i++){
    scanf("%d %d", &a, &b);
    p[a] = b;
  }
  printf("%d\n", solve(1, 5, 5));
}


Measured memory_bytes: 1060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) cin >> s[i];
    int x[h][w], y[h][w];
    rep(i, h){
        int num = 0;
        rep(j, w){
            if (s[i][j] == '.'){
                num++;
            }else{
                num = 0;
            }
            x[i][j] = num;
        }
    }
    rep(i, h){
        for (int j = w - 2; j >= 0; j--){
            if (s[i][j+1] == '.' && s[i][j] == '.'){
                x[i][j] = x[i][j+1];
            }
        }
    }

    rep(j, w){
        int num = 0;
        rep(i, h){
            if (s[i][j] == '.'){
                num++;
            }else{
                num = 0;
            }
            y[i][j] = num;
        }
    }
    rep(j, w){
        for (int i = h - 2; i >= 0; i--){
            if (s[i+1][j] == '.' && s[i][j] == '.'){
                y[i][j] = y[i+1][j];
            }
        }
    }
    int ans = 0;
    rep(i, h)rep(j, w){
        if (s[i][j] == '.'){
            ans = max(x[i][j] + y[i][j] - 1, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 35584
#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); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    vector<string> vec(H);
    rep(i,H) cin >> vec[i];
    vector<bool> allcake(H, true);
    rep(i,H){
        rep(j,W){
            if (vec[i][j] == '#') allcake[i] = false;
        }
    }
    vector<int> cakecut(H);
    rep(i,H){
        int minnotallcake = i;
        int maxnotallcake = i;
        while(true){
            if (minnotallcake == -1) break;
            if (!allcake[minnotallcake]) break;
            minnotallcake--;
        }
        while(true){
            if (maxnotallcake == H) break;
            if (!allcake[maxnotallcake]) break;
            maxnotallcake++;
        }
        if (minnotallcake == -1) cakecut[i] = maxnotallcake;
        else cakecut[i] = minnotallcake;
    }
    int next = 1;
    vector<vector<int> > ans(H, vector<int> (W));
    rep(i,H){
        int times = 0;
        rep(j,W){
            if (vec[i][j] == '#'){
                if (times >= 1) next++;
                times++;
            }
            ans[i][j] = next;
        }
        if (!allcake[i]) next++;
    }
    rep(i,H){
        rep(j,W){
            cout << ans[cakecut[i]][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 4156
def isin(x,y):
    if S(x1,y1,x2,y2,x,y)+S(x1,y1,x3,y3,x,y)+S(x3,y3,x2,y2,x,y)-S(x1,y1,x2,y2,x3,y3) != 0:
        return False
    else:
        return True

def S(x1,y1,x2,y2,x3,y3):
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))

for roop in range(int(raw_input())):
    x1,y1,x2,y2,x3,y3,xk,yk,xs,ys = map(int,raw_input().split())
    print "OK" if isin(xk,yk) != isin(xs,ys) else "NG"

Measured memory_bytes: 4532
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
zero = 0
one = 0
for i in range(n):
    if a[i] % 2 == 0:
        zero += 1
    else:
        one += 1

if p == 0:
    count = 1
    r = 2
else:
    count = 0
    r = 1

while r <= one:
    count += comb(one, r)
    r += 2

print(2**zero*count)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

// UF{{{
struct UF{ 

    // Number , Parent , Rank
    int N;
    vector<int> P;
    vector<int> R;

    UF ( int _N ):N(_N){
        init(_N);
    }

    void init( int _N ){
        P.assign( _N,0 );
        for (int i = 0; i < _N; i++) P[i] = i;
        R.assign( _N,0 );
    }

    int find( int x ){
        if( P[x] == x ) return x;
        else return P[x] = find(P[x]);
    }

    bool unite( int a, int b ){
        a = find(a);
        b = find(b);
        if( a == b ) return false;
        else{
            if( R[a] < R[b] ){
                P[a] = b;
            }else{
                P[b] = a;
                if( R[a] == R[b] ) R[a]++;
            }
        }
        return true;
    }

    bool same( int a, int b ){
        return find(a) == find(b);
    }

};
// }}}

int main() {

    int N,M;
    Scd2(N,M);

    UF uf(N);

    int x,y,z;
    Rep(i,M){
        Scd3(x,y,z);
        uf.unite(--x,--y);
    }

    vector<bool> ans(N);
    Rep(i,N){
        ans[uf.find(i)] = true;
    }
    int answ = 0;
    Rep(i,N){
        answ += ans[i];
    }

    printf ("%d\n", answ );

    return 0;
}



Measured memory_bytes: 1024
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    // 休みの総数
    int vacation = sc.nextInt();

    // 宿題の数
    int homework = sc.nextInt();

    int count = 0;
    int totalDays = 0;
    while (count < homework) {
      // かかる日数
      totalDays += sc.nextInt();
      count++;
    }
    int result = vacation - totalDays;
    if (result >= 0) {
	    System.out.println(result);
    } else {
	    System.out.println("-1");
    }
  }
}

Measured memory_bytes: 46384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;
typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	string s,t;
	cin>>s>>t;
	int ct = 0;
	for(int i=0;i<3;i++)
	{
		if(s[i] == t[i])
		ct++;	
	}
	cout<<ct<<"\n";
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;
	while(T--)
	solve(T);
	return 0;
}

Measured memory_bytes: 256