akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

u64 dp[60][60][2600];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  int n, a;
  cin >> n >> a;
  vu64 x(n);
  rep(i, n) cin >> x[i];
  dp[0][0][0] = 1;
  rep(i, n) rep(j, i + 1) rep(k, 2500) {
    dp[i + 1][j][k] += dp[i][j][k];
    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
  }
  u64 ans = 0;
  reps(i, n) ans += dp[n][i][i * a];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 61696
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string x;
	cin>>x;
	int count=0,maxi=0;
    int i;
	for(i=0;i<3;i++)
	{
		if(x[i]=='R')
		count+=1;
		else
		{
			maxi=max(maxi,count);
			count=0;
		}
	}
	if(count>0)
	maxi=max(maxi,count);
	cout<<maxi;
}

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

int main(){
  int N;
  cin >> N;
  
  int A,B;
  cin >> A >> B;
  int I = B - A - 1;
  
  if(I % 2 == 0) cout << "Borys";
  else cout << "Alice";
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
vector <int > T,A,H;

vector <bool> M;



int main()
{

	cin >> N;

	T.resize(N);
	A.resize(N);
	H.resize(N);
	M.resize(N);
	REP(i,N){
		cin >> T[i];
		M[i] = true;
	}
	REP(i,N){
		cin >> A[i];
	}
	long long ans = 1;
	if(T[0] > A[0] || T[N-1] < A[N-1] || T[N-1] != A[0] ){
		cout <<0;
		return 0;
	}
	FOR(i,1,N-1){
		if(T[i] <= T[i-1]) {
			M[i] = false;
			H[i] = T[i];
		} else {
			if(T[i] > A[i]){
				cout << 0;
				return 0;
			}
		}
	}
	RFOR(i,0,N-1){
		if(M[i]){
			continue;
		} else if(A[i] <= A[i+1]) {
			M[i] = false;
			H[i] = min(T[i],A[i]);
		} else {
			M[i] = true;
			if(T[i] < A[i]){
				cout << 0;
				return 0;
			}
		}
	}



	REP(i,N) {
		if(!M[i]) {
			ans = (H[i] * ans) % 1000000007;
		}
	}

	cout << ans;

}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int ans = 0;
  int rain = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i]=='R') {
      rain++;
    } else {
      ans = max(ans, rain);
      rain = 0;
    }
  }
  ans = max(ans, rain);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
int main(){
  int data[5], a=0, b, i;
  for(i=0;i<5;i++){
    scanf("%d", &data[i]);
    if(data[i] < 40){
      data[i]=40;
    }
    a += data[i];
  }
  b = a/5;
  printf("%d\n", b);
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    ll n,m;
    while(cin >> n >> m,n) {
        vector<ll> a(n);
        REP(i,n) cin >> a[i];
        sort(ALL(a),greater<ll>());
        ll ans = -1;
        REP(i,n) REP(j,n) {
            if (a[i]+a[j] <= m) {
                if (i == j) continue;
                ans = max(a[i]+a[j],ans);
            }
        }
        if (ans == -1) {
            cout << "NONE" << endl;
            continue;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main()
{
  long long n;cin>>n;
  vector<long long> a(n);
  int i,j;
  for(i=0;i<n;i++)cin>>a.at(i);
  vector<long long> sum1(60,0);
  long long ans=0;
  for(i=0;i<60;i++)
  {
    for(j=0;j<n;j++)
    {
      if(((long long)1<<i)&a.at(j))sum1.at(i)++;
    }
  }
  long long ks=1;
  for(i=0;i<60;i++)
  {
    ans=(ans+(sum1.at(i)*(n-sum1.at(i)))%MOD*ks)%MOD;
    ks=(ks*2)%MOD;
  }
  cout<<ans%MOD<<endl;
}


Measured memory_bytes: 2560
import sys
input=sys.stdin.readline

N,M = map(int, input().split())

A = []
for i in range(N):
    a,b = map(int, input().split())
    A.append([a,b])
A.sort()

x = 0
for a in A:
    if M == 0:
        break
    while a[1] > 0:
        a[1] -= 1
        M -= 1
        x += a[0]
        if M == 0:
            break
print(x)


Measured memory_bytes: 20072
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>

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

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

    long long count = 0;
    int num = 0;

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            num = gcd(i, j);
            for(int k=1; k<=n; k++) {
                count += gcd(num, k);
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
set <char> st;
int main ()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		st.insert(c);
	}
	if(st.size() == 3)
	{
		cout << "Three";
	}
	else 
	{
		cout << "Four";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    string ans="No";
    int a,b,c,d,e,f,g,h,i;cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
    if(b-a==e-d&&e-d==h-g){
        if(c-b==f-e&&f-e==i-h){
            if(d-a==e-b&&e-b==f-c){
                if(g-d==h-e&&h-e==i-f){
                    ans="Yes";
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

int n, K;
int a[101010];

int ans = 0;
vector<int> g[101010];

int dfs(int curr, int d) {
	int h = 0;
	for (int next : g[curr]) {
		h = max(h, dfs(next, d + 1) + 1);
	}
	if (d > 1 && h == K - 1) {
		ans++;
		return -1;
	}
	return h;
}

int main() {
	cin >> n >> K;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	if (a[0] != 0) {
		a[0] = 0;
		ans++;
	}
	
	for (int i = 1; i < n; i++) {
		g[a[i]].push_back(i);
	}

	dfs(0, 0);
	cout << ans << endl;
}

Measured memory_bytes: 10752
#2009_A
"""
def solve(n,p):
    a = [0]*n
    for _ in range(1000000):
        for i in range(n):
            if p:
                p -= 1
                a[i] += 1
                if p == 0:
                    if sum(a)-a[i] == 0:
                        return i
            else:
                p += a[i]
                a[i] = 0

while 1:
    n,p = [int(x) for x in input().split()]
    if n == 0:
        break
    print(solve(n,p))
"""

#2008_A
def solve(n,m):
    s = [int(input()) for i in range(n)]
    t = [int(input()) for i in range(m)]
    s_s = sum(s)
    s_t = sum(t)
    ans = (-1,float("inf"))
    for i in range(n):
        for j in range(m):
            a = s_t-s_s-2*t[j]+2*s[i]
            if a == 0:
                if s[i]+t[j] < sum(ans):
                    ans = (s[i],t[j])
    if ans[0] < 0:
        print(-1)
    else:
        print(*ans)
while 1:
    n,m = [int(x) for x in input().split()]
    if n == 0:
        break
    solve(n,m)



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

#define fastio  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug   cout << "\there\t";
#define all(a)  a.begin(), a.end()
#define sz(a)   (int)a.size()
#define M       1000000007
#define pb      push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;

const int N = 100005;
int n,m;
vector<vi> aj(N);
vi dis(N);

int dfs(int u){
    if(dis[u]!=-1){return dis[u];}
    int mp = 0;
    for(auto v: aj[u]){
        mp = max(mp,1+dfs(v));
    }
    dis[u] = mp;
    return mp;
}

void solve(){
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int x,y; cin >> x >> y;
        aj[x].pb(y);
    }
    for(int i=1;i<=n;i++){dis[i] = -1;}
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(dis[i]==-1){
            dfs(i);
            ans = max(ans,dis[i]);
        }
    }
    cout << ans <<"\n";
}

int32_t main(){
    fastio;
    solve();
    return 0;
}

Measured memory_bytes: 11108
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;

int n;
vector<int> ans;

int main(){
	cin>>n;
	cout<<n<<':';
	for(int i=2;i*i<=n;i++){
		for(;n%i==0;){
			ans.push_back(i);
			n/=i;
		}
	}
	if(n!=1) ans.push_back(n);
	int tmp=ans.size();
	for(int i=0;i<tmp;i++){
		cout<<' '<<ans[i];
	}
	cout<<endl;
}

Measured memory_bytes: 1216
s=input()
num=len(s)
a=""
for i in range(num):
  if (i%2==0):
    a=a+"1"
  else:
    a=a+"0"
ans=0
for i in range(num):
  if (a[i]==s[i]):
    ans+=1
print(min(ans,num-ans))

Measured memory_bytes: 3188
n,k = map(int,input().split())
a=list(map(int,input().split()))
#input

from collections import defaultdict
counter=defaultdict(int)
#桁ごとに１の数を数える辞書型、aのデータ整理で使う

def makebit(a):
    return bin(a)[2:]
#数値型から２進数の文字列型を返す関数

def count(a):
    l=len(a)
    for i in range(1,l+1):
        if a[-i]=='1':
            counter[i]+=1
    return
#２進数の文字列型から、１の場所と数を数える関数

for i in range(len(a)):
    count(makebit(a[i]))
#inputしたリストaをcounterに整理する
#ここでcounterは、〇桁目：１がｘ回登場という辞書になっている。
#0回しか登場していない場合はkeyが存在しない(後述)

kbit=makebit(k)
#kの2進数表記



#この下結構ぬけがあって苦戦した箇所

if len(counter)>0:
    maxlenth=max(counter)
elif len(counter)==0:
    maxlenth=0
#counterが空の場合len()が使えないことに注意する

maxlenth=max(maxlenth,len(kbit))    
#最終的に調べる長さmaxlenthを求める。


for i in range(1,1+maxlenth):
    if counter[i]==0:
        counter[i]=0
#counterのmaxlenth以下のkeyが存在するように0を与える。

kbit='0'*(maxlenth-len(kbit))+kbit
#Aのほうが長い場合はkbitの頭に0をつける


kaijo=[]
kaiji=1
for i in range(maxlenth+1):
    kaijo.append(kaiji)
    kaiji*=2
#f(x)を求めるときに使用するため、2の階乗を羅列したリストを作成しておく
#長さは0からmaxlenth、たぶん-1でいいけど大目に作っておいた

#メインとなるループ関数
def search(kbit,default,ans,before,counter):
    #終了条件①：kbitに1がない場合
    if kbit.count('1')==0:
        dlenth=0
        #0桁目より大きい範囲、つまり全範囲0としてnowの計算を行う
        
    elif kbit.index('1')==len(kbit)-1:
        dlenth=1
        #1の位以外は0で、1の位は自由に取れるため最適化
        for keta in counter:
            if keta>=before:continue
            elif keta>dlenth:
                default+=counter[keta]*kaijo[keta-1]
            elif keta==dlenth:
                default+=max(n-counter[keta],counter[keta])*kaijo[keta-1]
        if default>ans:ans=default
        return ans
    
    
    #以下一般の場合のループ内容
    
    elif kbit.count('1')>0:dlenth=len(kbit)-kbit.index('1')
    #左から見て最初の1の位置が何ケタ目なのか、調べる桁と呼ぶ
    
    now=default
    #調べる桁を0としたときの最適値、defaultは1として更新する
    
    newcounter=counter.copy()
    #次のループで使うcounter辞書。処理を軽くするために既に調べた桁の情報は削除する
       
    for keta in counter:
        if keta>before:continue
        elif keta>dlenth:
            #調べる桁より上の位は0にしなければkを超えてしまう
            #nowもdefaultも更新
            default+=counter[keta]*kaijo[keta-1]
            now+=counter[keta]*kaijo[keta-1]
            newcounter.pop(keta)
            
        elif keta==dlenth:
            #調べる桁では、nowは0、defaultは1として更新
            default+=(n-counter[keta])*kaijo[keta-1]
            now+=counter[keta]*kaijo[keta-1]
            newcounter.pop(keta)
            
        elif keta<dlenth:
            #調べる桁より下の位はnowで最適値を求める。defaultは更新しない
            now+=max(n-counter[keta],counter[keta])*kaijo[keta-1]
    
    if now>ans:ans=now
    if dlenth==0:return ans
    #kbitの更新
    idx=kbit.index('1')
    kbit=kbit[idx+1:]
    
    #終了条件②：kbitの最初の1が1の位にある場合
    
    
    #ループ
    return search(kbit,default,ans,dlenth,newcounter)
    
print(search(kbit,0,0,maxlenth+1,counter))

Measured memory_bytes: 14748
N = int(input())
B = list(map(int, input().split()))
A = [ 0 for x in range(N) ]

A[N - 1] = B[-1]
A[N - 2] = B[-1]

for n in reversed(range(0, len(B))):
  A[n] = B[n]
  A[n+1] = B[n] if B[n] < A[n+1] else A[n+1]  

print(sum(A))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a;
    cin >> a;
    if (a<1200){
        cout << "ABC" << endl;
        return 0;
    }
    if (a<2800){
        cout << "ARC" << endl;
        return 0;
    }
    cout << "AGC" << endl;
    return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<ll,int> P;
struct edge{int to; ll cost;};

const int N=100001;
const ll INF=12345678901234LL;

ll cost[N][10];
vector<edge> G[N];

int main()
{
    int n,m,r,Q;
    scanf(" %d %d %d %d", &n, &m, &r, &Q);

    while(m--)
    {
        int a,b,c;
        scanf(" %d %d %d", &a, &b, &c);
        G[b].pb(edge{a,c});
    }

    fill(cost[0],cost[N],INF);

    rep(i,r)
    {
        priority_queue<P,vector<P>,greater<P>> pq;
        for(int j=i; j<=n; j+=r)
        {
            cost[j][i]=0;
            pq.push(P(0,j));
        }

        while(!pq.empty())
        {
            P p = pq.top();
            pq.pop();

            int v=p.se;
            if(cost[p.se][i]<p.fi) continue;
            for(edge &e:G[v])
            {
                if(cost[e.to][i] > cost[v][i]+e.cost)
                {
                    cost[e.to][i] = cost[v][i]+e.cost;
                    pq.push(P(cost[e.to][i], e.to));
                }
            }

        }
    }

    ll ans=0;
    while(Q--)
    {
        int x,y,z;
        scanf(" %d %d %d", &x, &y, &z);

        ll mincost=INF;
        rep(i,r) mincost = min(mincost, cost[x][i]+cost[y][i]);

        if(z>mincost) ans+=z-mincost;
    }

    printf("%lld\n", ans);
    return 0;
}

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

int main(){
    int N ,sum=0; cin >> N;
    vector<int> a(N);

    for (int i=0; i < N ; i++) {
        cin >> a.at(i);
        sum+=a.at(i);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(),a.end());

    int Alice=0, Bob;

    for (int i=0; i < N ; i+=2 ) Alice+=a.at(i);

    Bob=sum-Alice;

    cout << Alice-Bob << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


const int nmax = 105 , kmax = 100005 ;
int a[nmax],dp[2][kmax];
int n,k;

int solve(int I,int k)
{
	if( dp[I][k]!=-1 )return dp[I][k];
	dp[I][k]=0;
	for(int i=0;i<n && a[i]<=k ;i++)
	dp[I][k]|=( solve(I^1,k-a[i])^1 );
	return dp[I][k];
}

int32_t main()
{
	IOS
	memset(dp,-1,sizeof(dp));
	
	cin>>n>>k;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	
	cout << ( solve(0,k) ? "First" : "Second" ) << endl;
	
}


Measured memory_bytes: 6528
using System;

	public class Class1
	{
		public static void Main(String[] args)
		{
			double r =double.Parse(Console.ReadLine());
			double b=2d*r*Math.PI;
			double a=r*r*Math.PI;
			Console.WriteLine("{0:f5} {1:f5}",a,b);
			
			
			
		}
	}

Measured memory_bytes: 9192
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    ans = 0
    for i in range(N//2):
        if S[i] != S[N-i-1]:
            ans += 1
    return ans


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 9068
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int ctoi(char c){return c - '0';}

bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}

bool dfs(int n,int tmp,vector<vector<int>> a){
  if(n >= a.size())return tmp;
  bool isOk = true;
  rep(i,a[0].size()){
    isOk &= dfs(n+1,(tmp == 0)?a[n][i]:a[n][i]^tmp,a);
  }
  return isOk;
}

int main() {
  //cin.tie(0); ios::sync_with_stdio(0);
  int n,m;cin>>n>>m;
  vector<int> a(m);
  vector<string> s(m);rep(i,m)cin>>a[i]>>s[i];
  vector<bool> ok(n,false);
  vector<int> was(n,0);
  int wa = 0;
  int ac = 0;

  rep(i,m){
    if(ok[a[i]-1])continue;
    if(s[i] == "WA")was[a[i]-1]++;
    else {
      ok[a[i]-1] = true;
      ac++;
    }
  }
  rep(i,n)if(ok[i])wa += was[i];
  cout<<ac<<' '<<wa<<endl;
  return 0;
}

Measured memory_bytes: 7040
import sys
input = sys.stdin.readline

def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)

  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1

def Same(x, y, par):
  return Find(x, par) == Find(y, par)

def Size(x, par):
  return -par[Find(x, par)]

n, m = map(int, input().split())
P = list(map(int, input().split()))
P = [p-1 for p in P]

par = [-1]* n
rank = [0]*n

for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    Unite(x, y, par, rank)

ans = 0
for i in range(n):
    if P[i] == i:
        ans += 1
    else:
        if Same(i, P[i], par):
            ans += 1
print(ans)

Measured memory_bytes: 13876
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    pq(a);
    cin >> n >> m;
    REP(i,m){
        int t;
        cin >> t;
        a.push(t);
    }
    while(a.size()>1){
        int s = a.top();
        a.pop();
        int t = a.top();
        a.pop();
        a.push(s-t);
    }
    cout << max(a.top()-1,(int)0) << endl;

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>

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

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    int n;
    double d;
    cin >> n >> d;

    int cnt = 0;
    rep(i,n){
        double x,y;
        cin >> x >> y;
        if(sqrt(x*x+y*y) <= d) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3772
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    cnt = 0
    is_not_found = True
    while is_not_found:
        for i in range(N):
            if As[i] % 2 == 0:
                As[i] //= 2
            else:
                is_not_found = False
                break
        else:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9016
mod = 10**9+7
rng = 101001
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
from collections import Counter
N,M = map(int,input().split())
if M == 1:
  print(1)
  exit()
pf = []
while M != 1:
  for i in range(2,int(M**0.5+1)):
    if M%i == 0:
      pf.append(i)
      M = M//i
      break
  else:
    pf.append(M)
    M = 1
cpf = list(Counter(pf).values())
ans = 1
for i in cpf:
  ans = (ans*cmb(N+i-1,i))%mod
print(ans)

Measured memory_bytes: 11408
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <stdio.h>
#include <map>
#include <iomanip>
#include <sstream>
//#include <boost/math/common_factor_rt.hpp>
#include<fstream>
#define EPS (1e-7)
using namespace std;
#define ll long long



class Employee {
public:
	int id;
	int parent;
	vector<int> children;
	int salary;

	Employee() {
		
	}

	Employee(int num, int nparent) {
		id = num;
		parent = nparent;
		salary = -1;
	}



};



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



int main() {

	int N, W;
	cin >> N >> W;

	vector<pair<ll,ll>> objs(N);


	vector<ll> inner(W+1, 0);


	vector<vector<ll>> dp(N+1,inner);

	int temp1, temp2;
	for (auto i = 0; i < N; i++) {
		cin >> temp1 >> temp2;
		objs[i] = make_pair(temp1, temp2);
	}

	for (auto i = 0; i < N; i++) {
		for (auto weight = 0; weight < W+1; weight++) {

			if ((weight - objs[i].first) > -1)chmax(dp[i + 1][weight], dp[i][(weight - objs[i].first)] + objs[i].second);
			chmax(dp[i + 1][weight], dp[i][(weight)]);
		}
	}


	cout << dp[N][W] << endl;

	

	return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
    
    int n,m,l;
    
    cin>>n>>m>>l;
        
    int A[n][m];
    int B[m][l];
    long long int C[n][l];
    
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<m;++i){
        for(int j=0;j<l;++j){
            cin>>B[i][j];
        }
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<l;++j){
            C[i][j]=0;
        }
    }
    
    for(int i=0;i<n;++i){
        for(int j=0;j<l;++j){
            for(int k=0;k<m;++k){
             C[i][j] += A[i][k]*B[k][j];   
            }
        }
    }

	for(int i = 0; i < n; i++){
		for(int j = 0; j < l-1; j++){
			printf("%lld ",C[i][j]);
		}
		printf("%lld\n",C[i][l-1]);
	}
	return 0;
}



Measured memory_bytes: 3236
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  int N,M,s,t;
  map<int,int>a,b;
  in(N);
  rep(i,N){
    in(s);
    a[s]++;
  }
  in(M);
  vector<int>T(M);
  rep(i,M){
    in(T[i]);
    b[T[i]]++;
  }
  rep(i,M){
    if(a[T[i]]<b[T[i]]){
      out("NO");
      return;
    }
  }
  out("YES");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 19840
//
//AtCoder Beginner Contest 146
//B - ROT N
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <functional>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

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

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n;
    string s;

    cin >> n >> s;

    REP(i, s.size()) {
        s[i] = s[i]+n <= 'Z' ? s[i]+n : s[i]+n -1 - 'Z' + 'A' ;
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define sz(x) 			(int)x.size()
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
#define watch(x) 		cout << #x << " = " << x << endl
#define trace(x) 		cerr << #x << " = " << x << endl
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e4;
const double pi = acos(-1);

void solve(){
    
	int n; cin>>n;
	int arr[n+1];
	mem(arr, 0);
	for(int x = 1;x*x<N;x++){
		for(int y = 1;y*y<N;y++){
			for(int z = 1;z*z<N;z++){
				int temp = (x+y+z)*(x+y+z) - (x*y + z*x + z*y);
				if(temp<=n and temp>=1) arr[temp-1] = arr[temp-1] + 1;
			}
		}
	}
	for(int i = 0;i<n;i++){
		cout<<arr[i]<<"\n";
	}
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3692
N, K, S = map(int, input().split())

A = [0] * N
for i in range(N):
    if i < K:
        A[i] = S
    else:
        if S == 10 ** 9:
            A[i] = 1
        else:
            A[i] = 10 ** 9

print(" ".join(map(str, A)))

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define ALL(v) v.begin(),v.end()
#define FI first
#define SE second

typedef long long ll;
typedef pair<ll, ll> P;
ll n, q, l, r;

ll seica(ll num, vector<pair<P, P>> &que) {
    REP(i, q){
        ll x = que[i].FI.SE;
        ll s = que[i].SE.FI;
        ll t = que[i].SE.SE;
        if(que[i].FI.FI == 1){
            if(num >= x){
                num = t * (num + s);
            }
        }
        else {
            if(num <= x){
                num = (num - s) / t;
            }
        }
    }
    return num;
}

bool checkMIN(ll num, vector<pair<P, P>> &que) {
    num = seica(num, que);
    return num < l;
}

bool checkMAX(ll num, vector<pair<P, P>> &que) {
    num = seica(num, que);
    return num <= r;
}

int main() {
    cin >> n >> q >> l >> r;
    vector<ll> v(n);REP(i, n)cin >> v[i];
    vector<pair<P, P>> que(q);
    REP(i, q){
        cin >> que[i].FI.FI >> que[i].FI.SE >> que[i].SE.FI >> que[i].SE.SE;
    }

    sort(ALL(v));
    ll L = -1, R = n;
    while(R - L > 1){
        ll mid = (L + R) / 2;
        //cout << "mim " << L << " " << R << " " << mid << endl;
        if(checkMIN(v[mid], que))L = mid;
        else R = mid;
    }
    ll ans_l = L;
    L = -1;R = n;
    while(R - L > 1){
        ll mid = (L + R) / 2;
        //cout << "mim " << L << " " << R << " " << mid << endl;
        if(checkMAX(v[mid], que))L = mid;
        else R = mid;
    }
    ll ans_r = L;
    //cout << "ans " << ans_l << " " << ans_r << endl;

    cout << max(0LL, ans_r - ans_l) << endl;
    return 0;
}



Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
ll power(ll a,ll b)
{ll result=1;
while(b>0)
{if(b%2==1)
 result*=a;
 a*=a;
 b/=2;
}
return result;
}
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n,count=0;
cin>>n;
ll a[n];
for(int i=0;i<n;i++)
cin>>a[i];
if(n<=2)
cout<<0;
else
{for(int i=0;i<n;i++)
 {for(int j=i+1;j<n;j++)
	{ if(a[j]!=a[i])
		{for(int k=j+1;k<n;k++)
		{if((a[i]+a[j]>a[k])&&(a[j]+a[k]>a[i])&&(a[i]+a[k]>a[j])&&a[k]!=a[j]&&a[k]!=a[i])
			{count++;
			 //cout<<i+1<<j+1<<k+1;
		 }
		}
	}
	}
}
cout<<count;
}
}


Measured memory_bytes: 3656
def DepthFirst_search(S,pre) :
    global out
    #print(pre)
    #print(out)
    if len(S) == 1 :
        for i in range(len(pre)) :
            if i == len(pre)-1 :
                out += pre[i]*10 + int(S[0]) + pre[i] + int(S[0])
            else :
                out += 2*pre[i]
        return False

    pre.append(int(S[0]))
    if DepthFirst_search(S[1:len(S):],pre) :
        return False
    pre.pop()
    if len(pre) != 0:
        pre.append(pre.pop()*10 + int(S[0]))
        if DepthFirst_search(S[1:len(S):],pre):
            return False

    return False

out = 0
pre = []
S = input()
if len(S) == 1:
    out = int(S[0])
else :
    DepthFirst_search(S,pre)

print(out)


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

int main()
{
	int n, q, c, u, v;
	scanf("%d%d", &n, &q);
	dsu d(n);
	while (q--) {
		scanf("%d%d%d", &c, &u, &v);
		if (c) {
			printf("%d\n", d.same(u, v));
		}
		else {
			d.merge(u, v);
		}
	}
}

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

ll dp[101][100001];

int main() {
  int n, W;
  cin >> n >> W;
  rep(i, n) {
    int w, v;
    cin >> w >> v;
    rep(j, W + 1) dp[i + 1][j] =
        max(dp[i][j], j < w ? 0 : dp[i][max(0, j - w)] + v);
  }
  cout << dp[n][W] << endl;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i).first;
    a.at(i).second=i+1;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++)cout<<a.at(i).second<<" ";
  cout<<endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>

unsigned int d;
unsigned int w;
std::vector<std::vector<int> > input;

void mainCall();
int calcEdge(int x, int y, int w, int h);
int calcPond(int x, int y, int w, int h, int e);

int main(int argc, char const *argv[]) {


    std::cin >> d;
    std::cin >> w;

    while (d>2 && w>2) {
	int max_capacity = 0;
	    input.resize(w);
	    for (int i = 0; i < w; i++) {
	        input[i].resize(d);
	    }

	    for (int i = 0; i < d; i++) {
	        for (int j = 0; j < w; j++) {
	            std::cin >> input[j][i];
	        }
	    }

	    for (int i = 0; i < w-2; i++) {
	        for (int j = 0; j < d-2; j++) {
	            for (int k = 2; k < w-i; k++) {
	                for (int l = 2; l < d-j; l++) {
	                    int e = calcEdge(i,j,k,l);
	                    int c = calcPond(i,j,k,l,e);
	                    if (max_capacity < c) {
	                        max_capacity = c;
	                    }
	                }
	            }
	        }
	    }

	    std::cout << max_capacity <<std::endl;

	    std::cin >> d;
    	std::cin >> w;
	}
	return 0;
}


int calcEdge(int x, int y, int w, int h) {
    int min = input[x][y];
    for (int i = 0; i <= w; i++) {
        if (min > input[x+i][y]) {
            min = input[x+i][y];
        }
        if (min > input[x+i][y+h]) {
            min = input[x+i][y+h];
        }
    }
    for (int i = 0; i <= h; i++) {
        if (min > input[x][y+i]) {
            min = input[x][y+i];
        }
        if (min > input[x+w][y+i]) {
            min = input[x+w][y+i];
        }
    }
    return min;
}

int calcPond(int x, int y, int w, int h, int e) {
    int sum = 0;
    for (int i = 1; i <= w-1; i++) {
        for (int j = 1; j <= h-1; j++) {
            if (input[x+i][y+j] < e) {
                sum += e - input[x+i][y+j];
            } else {
                return -1;
            }
        }
    }
    return sum;
}



Measured memory_bytes: 3168
import sys
import collections
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))


def solve(count):
    ret = 0
    for a in sorted(count, reverse=True):
        cnt = count[a]
        if cnt <= 0:
            continue
        maxn = 1 << a.bit_length()
        b = maxn - a
        if b in count and count[b] > 0:
            if a == b:
                c = cnt // 2
            else:
                c = min(cnt, count[b])
                count[b] -= c
            ret += c
    return ret


count_even = collections.defaultdict(lambda: 0)
count_odd = collections.defaultdict(lambda: 0)

for a in A:
    if a % 2 == 0:
        count_even[a] += 1
    else:
        count_odd[a] += 1

print(solve(count_even) + solve(count_odd))


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

int main(){
	int x,n,m,k,i;
	for(;scanf("%d",&n),n;){
		vector<set<int> >v;
		for(i=0;i<n;i++){
			set<int>s;
			for(scanf("%d",&m),k=0;k<m;k++)
				scanf("%d",&x),s.insert(x);
			v.push_back(s);
		}
		set<int>t;
		for(scanf("%d",&k),m=0;m<k;m++)
			scanf("%d",&x),t.insert(x);
		vector<int>w;
		for(k=0;k<n;k++){
			set<int>s;
			set_intersection(v[k].begin(),v[k].end(),t.begin(),t.end(),inserter(s,s.end()));
			if(s.size()==t.size())w.push_back(k);
			if(w.size()>1)break;
		}
		printf("%d\n",w.size()==1?w[0]+1:-1);
	}
}

Measured memory_bytes: 1092
#include<iostream>
using namespace std;
int main(){
    int a,b,c,A,B,C;
    cin>>a>>b>>c;
    if(a==b&&b==c){cout<<(a%2?0:-1)<<endl;return 0;}
    for(int cnt=0;;a=A,b=B,c=C,cnt++){
        if(a%2|b%2|c%2){cout<<cnt<<endl;return 0;}
        A=(b+c)/2,B=(a+c)/2,C=(a+b)/2;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val T = sc.nextLong()

  println(Range(0, n).map(_ => sc.nextLong)
    .foldLeft((0L, -2L * T)) {
      case ((sum, ct), t) => (sum - math.max(T - (t - ct), 0L) + T, t)
    }._1)
}


Measured memory_bytes: 77200
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

ll a, b, c, d;

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

main(){
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);a--;
    ll ans = b - a, l = lcm(c, d);
    ans = ans - (b/c - a/c) - (b/d - a/d) + (b/l - a/l);
    printf("%lld\n", ans);
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin>>s;
  ll n=s.size();

  ll remind=0;
  ll base=1;
  map<ll,ll> m;
  m[0]+=1;
  for(ll i=n-1; i>=0; i--){
    remind=(remind+(s[i]-'0')*base)%2019;
    m[remind]+=1;
    base=base*10%2019;
  }

  ll ans=0;
  REP(i,2019)ans+=m[i]*(m[i]-1)/2;
  cout<<ans<<endl;

}



Measured memory_bytes: 3792
#include<cmath>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline int ksm(int x,int y){
	int z=1;for(;y;y>>=1,x=1ll*x*x%P)
	if(y&1)z=1ll*z*x%P;return z;
}
int q[N],r,n,a[N],du[N],f[N],ans,s[N],fac[N],inv[N],pw[N],ipw[N];
void dfs(int x){du[x]--;q[++r]=x;if(du[a[x]])dfs(a[x]);}
inline int C(int n,int m){return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;}
int main(){
	int i,l,x,la,fr,re;
	n=read();ans=1;
	for(i=1;i<=n;i++)a[i]=read(),du[a[i]]++;
	for(i=1;i<=n;i++){
		if(!du[i])q[++r]=i;
		if(du[i]>2)goto fuck;
	}
	for(l=1;l<=r;l++){
		x=q[l];if(f[a[x]])goto fuck;
		f[a[x]]=f[x]+1;if(!(--du[a[x]]))q[++r]=a[x];
	}
	for(l=1;l<=n;l++)if(du[l]){
		r=la=0;dfs(l);re=1;
		for(i=1;i<=r;i++)
		if(f[x=q[i]]){
			if(!la){fr=la=i;continue;}
			if(i-la<f[x])goto fuck;
			if(i-la>f[x])re=(re+re)%P;la=i;
		}
		if(!la){s[r]++;continue;}
		x=q[fr];fr=fr+r;
		if(fr-la<f[x])goto fuck;
		if(fr-la>f[x])re=(re+re)%P;
		ans=1ll*ans*re%P;
	}
	fac[0]=inv[0]=pw[0]=ipw[0]=1;
	pw[1]=2;ipw[1]=(P+1)/2;
	for(i=1;i<=n;i++){
		fac[i]=1ll*fac[i-1]*i%P;
		inv[i]=ksm(fac[i],P-2);
		pw[i]=1ll*pw[i-1]*pw[1]%P;
		ipw[i]=1ll*ipw[i-1]*ipw[1]%P;
	}
	for(l=1;l<=n;l++)if(s[l]){
		re=0;for(i=0;i+i<=s[l];i++){
			x=1ll*C(s[l],i+i)*fac[i+i]%P*inv[i]%P*ipw[i]%P*ksm(l,i)%P;
			if(l>1&&(l&1)){x=1ll*x*pw[s[l]-i-i]%P;}re=(re+x)%P;
		}ans=1ll*ans*re%P;
	}printf("%d\n",ans);
	return 0;fuck:puts("0");;
}

Measured memory_bytes: 20992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int W, H, x, y, r;
	bool ans = true;

	cin >> W >> H >> x >> y >> r;

	if (x - r < 0 || W < x + r) ans = false;
	if (y - r < 0 || H < y + r) ans = false;

	cout << (ans ? "Yes" : "No") << endl;







	return 0;
}



Measured memory_bytes: 3096
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if (A==5 && B==7 && C==5) {
      System.out.println("YES");
    } else if (A==7 && B==5 && C==5) {
      System.out.println("YES");
    } else if (A==5 && B==5 && C==7) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
// order_of_key and *find_by_order
int32_t main()
{
	fast;
	string s;
	cin >> s;
	if (s == "ABC")
		cout << "ARC";
	else
		cout << "ABC";




}

Measured memory_bytes: 3612
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end

N, M = gets.split.map(&:to_i)
AB = N.times.map{gets.split.map(&:to_i)}.sort_by{|a,b|[a,b]}
LR = M.times.map{gets.split.map(&:to_i)}

#N = 10 ** 5
#M = 2 * 10 ** 5 - 1
#AB = N.times.map{[rand(1..10**9), rand(0..1)]}.sort_by{|a,b|[a,b]}
#LR = M.times.map{[rand(1..10**8), rand(1..10**8)].sort}

A = AB.transpose[0] + [10 ** 9 + 1]
B = AB.transpose[1].unshift(0).push(0)

@ab = Array.new(N + 1)
lr = Array.new(M){[]}

(N + 1).times do |i|
  @ab[i] = B[i] ^ B[i + 1]
end

M.times do |i|
  fst, snd = LR[i]
  lr[i] = [A.bsearch_index{|x| x >= fst}, A.bsearch_index{|x| x > snd}]
end


@graph = Array.new(N + 1){[]}
M.times do |i|
  l, r = lr[i]
  next if l == r
  @graph[l] << [r, i + 1]
  @graph[r] << [l, i + 1]
end


@ans = []
@used = Array.new(N + 1, false)
def dfs(i)
  @used[i] = true
  @graph[i].each do |ni, e|
    next if @used[ni]
    flag = dfs(ni)
    if flag
      @ab[i] ^= 1
      @ab[ni] ^= 1
      @ans << e
    end
  end
  return @ab[i] == 1 ? true : false
end


(N + 1).times do |i|
  next if @used[i]
  dfs(i)
end

if @ab.inject(:+) > 0
  puts -1
else
  puts @ans.size
  puts @ans.sort.join(" ")
end


Measured memory_bytes: 215032