akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define F 1

//const int mod[F]={1000000009,1000000021,1000000033,1000000087};
const int mod[F]={5077};

typedef struct hashNode{
  int hash[F];
} node;

node add(node a,node b){
  node x;
  for(int i=0;i<F;i++){
    x.hash[i]=(a.hash[i]+b.hash[i])%mod[i];
  }
  return x;
}

node minus(node a,node b){
  node c;
  for(int i=0;i<F;i++){
    c.hash[i]=(a.hash[i]-b.hash[i]+mod[i])%mod[i];
  }
  return c;
}

int isZero(node a){
  for(int i=0;i<F;i++) if(a.hash[i]>0) return 0;
  return 1;
}

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *a=(int *)calloc(n,sizeof(int));
  int i,j;
  for(i=0;i<n;i++) scanf("%d",a+i);
  node *dp=(node *)calloc(k,sizeof(node));
  for(i=0;i<F;i++) dp[0].hash[i]=1;
  for(i=0;i<n;i++){
    for(j=k-1;j-a[i]>=0;j--){
      dp[j]=add(dp[j],dp[j-a[i]]);
    }
  }
  node *dp2=(node *)calloc(k,sizeof(node));
  int ans=0;
  for(i=0;i<n;i++){
    if(a[i]>=k) continue;
    for(j=0;j<a[i];j++) dp2[j]=dp[j];
    for(j=a[i];j<k;j++){
      dp2[j]=minus(dp[j],dp2[j-a[i]]);
    }
    for(j=k-1;j>=k-a[i];j--) if(!isZero(dp2[j])) break;
    if(j<k-a[i]) ans++;
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


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

bool judge(int n);
int d[10] = { 0 };

int main()
{
	int n, k;

	cin >> n >> k;
	for (int i = 1; i <= k; i++)
	{
		int temp;
		cin >> temp;
		d[temp] = 1;
	}
	while (!judge(n))
	{
		n++;
	}
	cout << n << endl;

	//system("pause");
}

bool judge(int n)
{
	int digit[5];
	if (n >= 10000)
	{
		digit[4] = n / 10000;
		digit[3] = (n % 10000) / 1000;
		digit[2] = (n % 1000) / 100;
		digit[1] = (n % 100) / 10;
		digit[0] = n % 10;
		for (int i = 0; i <= 4; i++)
		{
			if (d[digit[i]] == 1)
				return false;
		}
		return true;
	}
	else if (n >= 1000)
	{
		digit[3] = n / 1000;
		digit[2] = (n % 1000) / 100;
		digit[1] = (n % 100) / 10;
		digit[0] = n % 10;
		for (int i = 0; i <= 3; i++)
		{
			if (d[digit[i]] == 1)
				return false;
		}
		return true;
	}
	else if (n >= 100)
	{
		digit[2] = n / 100;
		digit[1] = (n % 100) / 10;
		digit[0] = n % 10;
		for (int i = 0; i <= 2; i++)
		{
			if (d[digit[i]] == 1)
				return false;
		}
		return true;
	}
	else if (n >= 10)
	{
		digit[1] = n / 10;
		digit[0] = n % 10;
		for (int i = 0; i <= 1; i++)
		{
			if (d[digit[i]] == 1)
				return false;
		}
		return true;
	}
	else
	{
		if (d[n] == 1)
			return false;
		else
		    return true;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
#include<functional>
using namespace std;
long long x,y;
long long mod[50];
long long ans;
long long getw(long long x,long long y,long long m)
{
	long long s0=0,s1=0;
	long long y1=y%m;
	if(y1<m/2)
		s0+=y1+1;
	else
	{
		s0+=m/2;
		s1+=y1-m/2+1;
	}
	y-=y1;
	s0+=y/2;
	s1+=y/2;
	
	x--;
	long long x1=x%m;
	if(x1<m/2)
		s0-=x1+1;
	else
	{
		s0-=m/2;
		s1-=x1-m/2+1;
	}
	x-=x1;
	s0-=x/2;
	s1-=x/2;
	
	s0=0;
	s1=s1%2;
	return s0^s1;
}
int main()
{
	cin>>x>>y;
	mod[0]=1;
	for(int i=1;i<=42;i++)
		mod[i]=mod[i-1]*2;
	int i=lower_bound(mod,mod+42,y)-mod;
	while(i>=0)
	{
		long long t=getw(x,y,mod[i+1]);
		ans=ans+t*mod[i];
		i--;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 100100;
 
int aa[N], bb[N], cc[N];
 
int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	multiset <pair<int, int> > s;
	for (int i = 0; i < a; ++i) {
		cin >> aa[i];
		s.insert(make_pair(-aa[i], 1));
	}
	for (int i = 0; i < b; ++i) {
		cin >> bb[i];
		s.insert(make_pair(-bb[i], 2));
	}
	for (int i = 0; i < c; ++i) {
		cin >> cc[i];
		s.insert(make_pair(-cc[i], 3));
	}
	long long ans = 0;
	int coloress = 0;
	while(!s.empty()) {
		pair<int,int> v = *s.begin();
		s.erase(s.begin());
		if(x + y == coloress)break;
		if(v.second == 1 && x > 0) {
			ans += -v.first;
			x--;
		}
		if(v.second == 2 && y > 0) {
			ans += -v.first;
			y--;
		}
		if(v.second == 3) {
			ans += -v.first;
			coloress++;
		}
	}
	cout << ans << endl;
 
 
}

Measured memory_bytes: 15488
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var M = sc.ReadInt();
        var X = sc.ReadInt();
        var Y = sc.ReadInt();
        var Xs = sc.ReadIntArray(N);
        var Ys = sc.ReadIntArray(M);
        var min = Math.Max(X, Xs.Max());
        var max = Math.Min(Y, Ys.Min());
        if (min < max)
        {
            Console.WriteLine("No War");
        }
        else
        {
            Console.WriteLine("War");
        }
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


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

int     main() {
        long n, m, d;
        cin >>n >>m >>d;
        long N;
        if (0==d)
                N=n;
        else
                N=(n-d)*2;
        double P=N;
        P /=n*n;
        P *=m-1;
        cout <<setprecision(15) <<P <<endl;
        return 0;
};

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
import itertools


def main():
  N, M, X = map(int, input().split(' '))
  mat = np.array([list(map(int, input().split(' '))) for _ in range(N)])

  INT_MAX = 100000000
  min_c = INT_MAX
  for conds in itertools.product([0, 1], repeat=N):
    result = np.dot(conds, mat)
    skills = result[1:]
    if np.all(skills >= X):
      min_c = min(min_c, result[0])

  print(min_c if min_c < INT_MAX else -1)


if __name__ == '__main__':
  main()


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

A=[]
i=0
while len(A)<K:
  if S[i]=='o':
    A.append(i+1)
    i+=(C+1)
  else:
    i+=1
    
B=[]
i=-1
while len(B)<K:
  if S[i]=='o':
    B.append(i)
    i-=(C+1)
  else:
    i-=1
    
B=[N+i+1 for i in B]
B=B[::-1]
for i in range(K):
  if A[i]==B[i]:
    print(A[i])

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

int N;
vector<int> P;

int main() {
    scanf("%d", &N);
    P.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &P[i]);
        P[i]--;
    }

    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(P[i] == i) {
            if(i < N - 1) swap(P[i], P[i + 1]);
            else swap(P[i], P[i - 1]);
            cnt++;
        }
    }
    printf("%d", cnt);
}


Measured memory_bytes: 640
A, B, C, D = map(int, input().split())


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a // gcd(a, b) * b


a = (A-1) - ((A-1) // C + (A-1) // D - (A-1) // lcm(C, D))
b = B - (B // C + B // D - B // lcm(C, D))
print(b-a)

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

const int64_t inf = 1e18 + 37;
const int maxn = 1e5 + 13;

int n;
int64_t c;
int64_t x[maxn], v[maxn];

int64_t solve () {
  int64_t res = -inf, sum = 0;
  vector < int64_t > pref(n + 2, 0), suff(n + 2, 0), max_suff(n + 2, 0);
  for (int i = 1; i <= n; ++i) {
    sum += v[i];
    pref[i] = sum - x[i];
    res = max(res, pref[i]);
  }
  sum = 0;
  for (int i = n; i; --i) {
    sum += v[i];
    suff[i] = sum - (c - x[i]);
    max_suff[i] = max(max_suff[i + 1], suff[i]);
    res = max(res, pref[i] + max_suff[i + 1] - x[i]);
  }
  return res;
}

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

  cin >> n >> c;
  for (int i = 1; i <= n; ++i)
    cin >> x[i] >> v[i];
  int64_t ans = max(int64_t(0), solve());
  reverse(x + 1, x + n + 1);
  reverse(v + 1, v + n + 1);
  for (int i = 1; i <= n; ++i)
    x[i] = c - x[i];
  cout << (ans = max(ans, solve())) << '\n';
}


Measured memory_bytes: 4224
def read_input():
    D = int(input())
    C = input().split()
    C = [int(i) for i in C]
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    return D, C, S, T


def scoring(S, D, T, C):
    res = []
    last = [0 for _ in range(26)]
    final = 0
    for i in range(D):
        dec = 0
        for j in range(26):
            for loc, val in enumerate(T[:i + 1]):
                if val == j + 1:
                    last[j] = loc + 1
            dec += C[j] * (i - last[j] + 1)
        final += S[i][T[i] - 1] - dec
        res.append(final)
    return res


D, C, S, T = read_input()
res = scoring(S, D, T, C)
for x in res:
    print(x)


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

template<typename T>inline void read(T &x)
{
	x=0;T c=getchar(),p=1;
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}

int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int n,a,b;
	cin>>n>>a>>b;
	if(abs(a-b)%2==0)
		printf("Alice");
	else
		printf("Borys");
	return 0;
}



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

using namespace std;

int main()
{
    int N,K;cin>>N>>K;
    vector<int> P(N,1);
    for(int i=0;i<K;i++){
        int d;cin>>d;
        for(int j=0;j<d;j++){
            int a;cin>>a;
            P[a-1]=0;
        }
    }


    int ans = 0;
    for(auto p : P){
        ans += p;
    }
    cout << ans << endl;
    return 0;   
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

long long H, W;

int main() {
	cin >> H >> W;
	long long ans = LLONG_MAX;
	if (H % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else ans = min(ans, H);
	if (W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else ans = min(ans, W);
	for (long long w = 1; w < W; w++) {
		long long h = H/2;
		long long m = min(min(w * H, (W - w) * h), (W - w) * (H - h));
		long long M = max(max(w * H, (W - w) * h), (W - w) * (H - h));
		ans = min(ans, M - m);
	}
	for (long long h = 1; h <H; h++) {
		long long w =W / 2;
		long long m = min(min(h * W, (H - h) *w), (H - h) * (W - w));
		long long M = max(max(h * W, (H - h) * w), (H - h) * (W - w));
		ans = min(ans, M - m);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>     
int main(){
     char number[1001];
     int i, sum;
     while(1){
         scanf("%s", number);
         if(number[0]=='0')break;
         sum=0;
         for(i=0;number[i]!='\0';i++){
             sum+=number[i]-'0';
         }
         printf("%d\n", sum);
     }
     return 0;
}



Measured memory_bytes: 2048
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		List<Integer> A = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			A.add(in.nextInt());
		}

		while (A.size() > 1) {
			int min = A.stream().min(Comparator.naturalOrder()).get();
			A = A.stream().map(n -> n % min).filter(n -> n > 0).collect(Collectors.toList());
			A.add(min);
		}
		System.out.println(A.get(0));
	}
}


Measured memory_bytes: 54376
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


signed main(){
  int a, b, k;
  cin >> a >> b >> k;
  int n = max(a, b);
  vector<int> vec;
  rrep(i,n){
    if(a%i == 0 and b%i == 0)vec.pb(i);
  }
  sort(all(vec), greater<int>());
  cout << vec[k-1] << endl;
  return 0;
}






Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	s = IS()
	ans = 0
	cnt = 0
	for ss in s:
		if ss=="A" or ss=="T" or ss=="G" or ss=="C":
			cnt += 1
		else:
			ans = max(ans,cnt)
			cnt=0
	ans = max(ans,cnt)
	print(ans)

if __name__ == '__main__':
	main()

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

opening_status = []
for _ in range(n):
    F = input().replace(' ', '')
    opening_status.append(int(F, 2))

scores = []
for _ in range(n):
    score = list(map(int, input().split()))
    scores.append(score)


ans = -float('INF')
for pattern in range(1, 2**10):
    candidate = 0
    for idx, status in enumerate(opening_status):
        together = pattern & status
        count = sum([1 if together >> i & 1 else 0 for i in range(10)])
        candidate += scores[idx][count]

    ans = max(ans, candidate)

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    vector<int> table;
    table.emplace_back(1);
    int cur = 6;
    while(cur <= n){
        table.emplace_back(cur);
        cur *= 6;
    }
    cur = 9;
    while(cur <= n){
        table.emplace_back(cur);
        cur *= 9;
    }
    sort(table.rbegin(), table.rend());
    int m = table.size();
    vector<int> dp(n + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < n; ++j){
            if(dp[j] == INF)    continue;
            if(j + table[i] > n)    continue;
            chmin(dp[j + table[i]], dp[j] + 1);
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 3532
# frozen_string_literal: true

h = { 'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0 }

n = readline.strip.to_i

n.times do
  h[readline.strip] += 1
end

h.each do |k, v|
  printf("%s x %d\n", k, v)
end


Measured memory_bytes: 14316
#include<iostream>
using namespace std;
#define ll long long

void solve()
{
	int n,m;
	cin>>n>>m;
	int a=((n-1)*n)/2 + ((m-1)*m)/2;
	cout<<a<<endl;
}
int main()
{
//	int t;cin>>t;
//	while(t--)
	solve();
}


Measured memory_bytes: 256
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;
use std::cmp;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let n:usize = scan.next();
    let w:usize = scan.next();

    let vw:Vec<(usize,usize)> = (0..n).map(|_| (scan.next(),scan.next())).collect();

    let mut dp:Vec<Vec<usize>> = (0..2).map(|_| (0..10001).map(|_| 0).collect()).collect();
	let mut i = 0;

    for &(value,weight)  in &vw {
        for w in 0..(w+1) {
            if w >= weight {
                dp[(i+1)%2][w] = cmp::max(dp[i][w-weight] + value, dp[i][w]);
            } else {
				dp[(i+1)%2][w] = dp[i][w];
			}
        }
		i = (i + 1) % 2;
    }

    println!("{}",dp[i][w]);
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}



Measured memory_bytes: 5032
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    if (a[a[i]] == i) ++ret;
  }
  printf("%d\n", ret / 2);
  return 0;
}


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

int main(){
    int n,y;
    cin >> n >> y;
    y /= 1000;
    for(int i=0; i<=y/10; i++){
        for(int j=0; j<=(y-10*i)/5;j++){
            if(i+j+(y-10*i-5*j) == n){
                cout << i<< " "<<  j <<" "<< y-10*i-5*j  << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 3568
#include<stdio.h>
#include<math.h>

int prime(int n, int m) {
	int count=0;
	int i,j,flag;

	for(i=n+1;i<=m;i++){
		flag = 1;
		if(i==2||i==3)
			count++;
		else{
			for(j=2;j<=sqrt(i);j++) {
				if(i%j==0) {
					flag=0;
					break;
				}
			}
			if(flag) 
				count++;
		}
	}
	return count;
}

int main() {

	int n;
	int Answer[10000],a=0;
	int i;

	for(;;) {
		scanf("%d",&n);
		if(n==0)
			break;
		Answer[a]=prime(n,2*n);
		a++;
	}

	for(i=0;i<a;i++)
		printf("%d\n",Answer[i]);
	return 0;
}

Measured memory_bytes: 608
N,X,Y = map(int,input().split())
X = X -1
Y = Y -1
L = [0]*(N-1)
for i in range(N-1):
  for j in range(i+1,N):
    min_dist = min(abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))
    L[min_dist-1] += 1
for out in L:
  print(out)

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

string to_string(string s) {
	return '"' + s + '"';
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	cout << accumulate(v.begin(), v.begin() + n - 1, 0) + v.back() / 2 << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = n - 1; i > 0; i--){
        cout << a[i] << " ";
    }
    cout << a[0] << endl;
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;


int main ()
{
  prep();
  int n;
  cin >> n;
  char arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  char last = arr[0];
  int cnt = 1;
  for (int i=1; i<n; i++){
      if (arr[i] != last){
          last = arr[i];
          cnt++;
      }
  }
  cout << cnt;
  return 0; 
}


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int calc = N;
  for(int i=0; ; i++){
    if(calc==0) break;
    else {
      sum += calc%10;
      calc /= 10; 
    }
  }
  if(N%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    int N=gi();
	    int[] P = new int[N];

	    int min = Integer.MAX_VALUE;
	    int c=0;
	    for (int i=0; i<N; i++) {
	    	P[i] = gi();
	    	if (min>P[i]) {
	    		min=P[i];
	    		c++;
	    	}
	    }
	    
	    
        System.out.println(c);
//        if (X%Y==0) {
//        	System.out.print("-1");
//        }else{
//        	long c=1;
//        	while(true) {
//        		if (((X*c) %Y) != 0) {
//        			System.out.print(X*c);
//        			return;
//        		}
//        		c++;
//        	}
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 59692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    vector<ll> v = {1,
                    1,
                    1,
                    2,
                    1,
                    2,
                    1,
                    5,
                    2,
                    2,
                    1,
                    5,
                    1,
                    2,
                    1,
                    14,
                    1,
                    5,
                    1,
                    5,
                    2,
                    2,
                    1,
                    15,
                    2,
                    2,
                    5,
                    4,
                    1,
                    4,
                    1,
                    51};

    int k;
    cin >> k;
    cout << v[k - 1] << endl;
}

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


class BIT1():
    """
    Binary Indexed Tree (1-indexed)
    """
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (self.n + 1)
        self.data = [0] * (self.n + 1)

    def add(self, idx, x):
        # add x to idx-th element
        # idx: 1-indexed
        self.data[idx] += x
        while idx <= self.n:
            self.bit[idx] += x
            idx += (idx & (-idx))

    def sum(self, idx):
        # get sum of [1, idx]
        # idx: 1-indexed
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= (idx & (-idx))
        return s


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]
s = [0] * (n + 1)
for i in range(n):
    s[i + 1] = s[i] + a[i]
t = [s[i] - k * i for i in range(n + 1)]

# 座標圧縮
zipped = {}
for i, xi in enumerate(sorted(set(t))):
    zipped[xi] = i + 1
m = len(zipped)
t2 = [0] * (n + 1)
for i in range(n + 1):
    t2[i] = zipped[t[i]]

ans = 0
bit = BIT1(m)
for i in range(n + 1):
    ans += bit.sum(t2[i])
    bit.add(t2[i], 1)
print(ans)


Measured memory_bytes: 62988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    s[m-1]=s[m-1]-'A'+'a';
    out(s);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    class Program0024
    {
        static void Main(string[] args)
        {
            string line;
            var inputs = new Queue<string>();

            while ((line = Console.ReadLine()) != null)
            {
                inputs.Enqueue(line);
            }

            foreach (var input in inputs)
            {
                double breakSpeed = double.Parse(input);
                double breakTime = breakSpeed / 9.8;
                double breakHeight = 4.9 * breakTime * breakTime;

                Console.WriteLine(GetMinFloor(breakHeight));
            }
        }

        static int GetMinFloor(double height)
        {
            int floor = 1;

            while (5 * floor - 5 <= height)
            {
                floor++;
            }

            return floor;
        }
    }
}

Measured memory_bytes: 6056
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

struct UnionFind
{
	vector<int> par;
	UnionFind(int n) :par(n, -1) {}
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	void unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return;
		if (par[y] < par[x]) swap(x, y);
		if (par[x] == par[y]) par[x]--;
		par[y] = x;
		if (find(x) != find(y)) par[find(y)] = x;
	}
	int count()
	{
		int cnt = 0;
		REP(i, par.size()) if (par[i] < 0) cnt++;
		return cnt;
	}
	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
//[const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

int main()
{
	int w, h;
	cin >> w >> h;
	vs fld(h);
	REP(i, h) cin >> fld[i];
	int gx, gy;
	REP(i, h)REP(j, w)
	{
		if (fld[i][j] == 't')
		{
			fld[i][j] = '.';
			gx = i, gy = j;
		}
	}
	int gp = place(gx, gy, w);
	int n; cin >> n;
	vector<pii> v;
	REP(i, n)
	{
		int a, b; cin >> a >> b;
		v.emplace_back(b, a);
	}
	int lb = -1, ub = n + 1;
	while (ub - lb > 1)
	{
		int mid = (lb + ub) / 2;
		vs cp = fld;
		REP(i, mid)
		{
			int a = v[i].first, b = v[i].second;
			cp[a][b] = '.';
		}
		UnionFind uf(h*w);
		REP(i, h)REP(j, w)
		{
			if (cp[i][j] == '#') continue;
			REP(k, 4)
			{
				int nx = i + dx[k], ny = j + dy[k];
				if (!valid(nx, ny, h, w) || cp[nx][ny]=='#') continue;
				uf.unite(place(i, j, w), place(nx, ny, w));
			}
		}
		if (uf.same(0, gp)) ub = mid;
		else lb = mid;
	}
	if (lb == n) puts("-1");
	else cout << lb + 1 << endl;
	return 0;
}

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec.at(i);
	sort(vec.begin(), vec.end());

	vector<int> counter(100000);
	for (int i = 0; i < vec.size(); i++) {
		counter.at(vec.at(i))++;
	}
	int answer = 1;
	for (int i = 0; i < 99998; i++) {
		int zantei = counter.at(i) + counter.at(i + 1) + counter.at(i + 2);
		if (zantei > answer) answer = zantei;
	}
	cout << answer << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;


using namespace std;



const int max_comb = 300000;
vector<ll> fac(max_comb + 1); //n! (mod M)
vector<ll> ifac(max_comb + 1); //k!^(-1) (mod M)

ll mpow(ll x, ll n) { //x^n(mod M)
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % MOD;
		x = x * x % MOD;
		n = n >> 1;
	}
	return ans;
}

ll minv(ll x) {
	return mpow(x, MOD - 2);
}

ll comb(ll n, ll a)
{
	ll tmp1 = 1;
	ll tmp2 = 1;
	int i;
	for (i = n; i >= n - a + 1; i--) {
		tmp1 = tmp1 * i%MOD;
	}
	for (i = 1; i <= a; i++) {
		tmp2 = tmp2 * i%MOD;
	}

	ll ans = tmp1 * minv(tmp2)%MOD;
	return ans;
}

void solve()
{
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);

	ll tmp0=mpow(2, n);
	ll aa = comb(n, a);
	ll bb = comb(n, b);
	ll ans = (tmp0 - 1 - aa - bb + 3 * MOD) % MOD;
	printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 4864
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();

        Map<Character, Character> sToT = new HashMap<>();
        Map<Character, Character> tToS = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            char curr = s.charAt(i);
            if (sToT.containsKey(curr) && t.charAt(i) != sToT.get(curr)) {
                System.out.println("No");
                return;
            }
            else {
                sToT.put(curr, t.charAt(i));
            }
        }

        for (int i = 0; i < t.length();  i++) {
            char curr = t.charAt(i);
            if (tToS.containsKey(curr) && s.charAt(i) != tToS.get(curr)) {
                System.out.println("No");
                return;
            }
            else {
                tToS.put(curr, s.charAt(i));
            }
        }

        System.out.println("Yes");
    }
}


Measured memory_bytes: 27856
from collections import*
n = int(input())
c = Counter(map(int, input().split()))
s = set()
for i in c:
    c[i] -= 1
    for j in range(i, 10**6+1, i):
        if c[j]:
            s.add(j)
    c[i] += 1
r = 0
for i in c:
    r += c[i] * (i not in s)
print(r)

Measured memory_bytes: 128188
N = int(input())

def p_prime(n): 
    prime = [2]
    for i in range(3,n+1):
        flag = 0
        for j in prime:
            if i%j == 0:
                flag = 1
                break
            if i**0.5 < j:
                break
        if flag == 0:
            prime.append(i)
    return prime
A = [2]
prime = p_prime(55555)
for i in prime:
    if i%5 == 1:
        A.append(i)
        
Ans = A[:N]
print(*Ans)

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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b && b!=c){
		cout << "Yes";
	}
	else if(b==c && c!=a){
		cout << "Yes";
	}
	else if(c==a && a!=b){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N; cin >> N;
  VI xs(N*2); REP(i,N*2) cin >> xs[i];
  SORT(xs);

  int ans = 0;
  REP(i,N) ans += xs[i*2];
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N, M; cin >> N >> M;
    ll a,b,c,d;
    vector<pair<ll,ll>> st, ch;
    FOR(i,0,N){
        cin >> a >> b;
        st.push_back(make_pair(a,b));
    }
    FOR(i,0,M) {
        cin >> c >> d;
        ch.push_back(make_pair(c,d));
    }
    vector<ll> v(N,INF);
    vector<int> ans(N,0);
    FOR(i,0,N){
        FOR(j,0,M){
            if(abs(st[i].first-ch[j].first)+abs(st[i].second-ch[j].second)<v[i])
            {
                v[i]=abs(st[i].first-ch[j].first)+abs(st[i].second-ch[j].second);
                ans[i]=j+1;
            }
        }
    }
    FOR(i,0,N){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define _CRT_SECURE_NO_WARNINGS

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

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

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

bool func(int p, int g) {
	if (p + 1 <= g) {
		return true;
	}

	return false;
}

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

	string s;
	cin >> s;

	int pCnt = 0;
	int gCnt = 0;
	int win = 0;
	int lose = 0;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'g') {
			if (func(pCnt, gCnt)) {
				pCnt++;
				win++;

				continue;
			}
			
			gCnt++;
		} else {
			if (func(pCnt, gCnt)) {
			
				pCnt++;
				continue;
			}
			
			gCnt++;
			lose++;
		}
	}

	cout << win - lose << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> a(N+1);
  int i,j;
  
  //N dainyu-
  for(i=1;i<N+1;i++)
    cin >> a.at(i);
  
  int M;
  cin >> M;
  vector<string> b(M+1);
  
  //M dainyu-
  for(i=1;i<M+1;i++)
    cin >> b.at(i);

  //
  int max=0;
    for(i=1;i<N+1;i++){
      int count=1;
        for(j=1;j<N+1;j++){
          if(a.at(i)==a.at(j)&&i!=j){
            count++;
          }
        }
        for(j=1;j<M+1;j++){
          if(a.at(i)==b.at(j))
            count--;
        }
      if(count>max)max=count;
    }
  cout<<max<<endl;

}


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

using namespace std ;

const int MAX = 1e6 + 10 , MAXN = 2e5 + 10 ;

int arr[MAXN] , freq[MAX] ;
int n ;

vector<int>Div[MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	for(int i = 1 ; i < MAX ; ++i)
	{
		for(int j = i+i ; j < MAX ; j += i)
			Div[j].push_back(i) ;
	}
	cin>>n ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>arr[i] ;
		freq[arr[i]]++ ;
	}
	int ans = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(freq[arr[i]] > 1)
			continue ;
		ans++ ;
		for(auto &d : Div[arr[i]])
		{
			if(freq[d])
			{
				ans-- ;
				break ;
			}
		}
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 122372
#include<bits/stdc++.h>
using namespace std;
int a[110];
int main()
{
	long long n,x,sum=0;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum==x)
	{
		cout<<n<<endl;
		return 0;
	}
	sort(a+1,a+n+1);
	int i=1;
	while(i<n)
	{
		x-=a[i];
		if(x<0) break;
		i++;
	}
	cout<<i-1<<endl;
	return 0;
}


Measured memory_bytes: 256
import itertools
import sys

N, Y = map(int,input().split())
rtn = False
 
for i,j in itertools.combinations_with_replacement(range(N+1), 2):
    if Y == 10000 * i + 5000 * (j-i) + 1000 * (N-j):
        print(i, j-i, N-j)
        rtn = True
        break

if not(rtn) :
    print(-1, -1, -1)

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
vector<pair<int,string>> v;
typedef unsigned long long H;
static const H C = 123891739; // arbitrary

// Arithmetic mod 2^64-1. 5x slower than mod 2^64 and more
// code, but works on evil test data (e.g. Thue-Morse).
// "typedef H K;" instead if you think test data is random.
struct K {
		typedef __uint128_t H2;
			H x; K(H x=0) : x(x) {}
				K operator+(K o){ return x + o.x + H(((H2)x + o.x)>>64); }
					K operator*(K o){ return K(x*o.x)+ H(((H2)x * o.x)>>64); }
						H operator-(K o) { K a = *this + ~o.x; return a.x + !~a.x; }
};
vector<K> ha, pw;
int cnt[26];
vector<K> hsh(string& str)   {
	fill(cnt);
	pw.resize(sz(str)+1);
	ha.resize(sz(pw));
	pw[0] = 1;
	rep(i,sz(str)){
		cnt[str[i]-'a']++;
								ha[i+1] = ha[i] * C + str[i],
											pw[i+1] = pw[i] * C;
										}
	return ha;
}
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n){
		string s;cin>>s;
		v.pb(mp(sz(s),s));
	}
	sort(all(v));
	map<pair<H,int>,int> m;
	ll ans = 0;
	trav(i,v){
		reverse(all(i.snd));
		vector<K> h = hsh(i.snd);
		int ix = 0;
		trav(j,h){
			auto it = m.lower_bound(mp(j.x,-1));
			rep(k,26) if(cnt[k]) {
				while(it!=m.end()&&it->fst.snd<k) it++;
				if((*it).fst == mp(j.x,k)) ans+=it->snd;
			}
			if(ix<sz(i.snd)) cnt[i.snd[ix]-'a']--;
			ix++;
		}
		m[mp(h[sz(i.snd)-1].x,i.snd.back()-'a')]++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 27460
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int n;
char s[500010]={};
vector<int> nv;


int cal(){
	int ls=nv.size();
	if(ls==0 || ls==1)return 0;
	vector<int> tv;
	tv.push_back(0);
	vector<vector<int> > dp;
	dp.push_back(vector<int>(4,0));
	rep(i,ls){
		tv.push_back(nv[i]);
		dp.push_back(vector<int>(4,0));
	}
	tv.push_back(0);
	dp.push_back(vector<int>(4,0));
	ls = tv.size();
	reg(i,2,ls-1){
		//printf("%d %d\n",tv[i-1],tv[i]);
		rep(j,4){
			int x=0;
			int p;
			if(j==0)p=0;
			else if(j==1){
				if(tv[i]<=0)continue;
				p=1;
			}
			else if(j==2){
				if(tv[i]<=1)continue;
				p=tv[i]-1;
			}
			else p=tv[i];
			rep(k,4){
				int q;
				if(k==0)q=tv[i-1];
				else if(k==1){
					if(tv[i-1]<=1)continue;
					q=tv[i-1]-1;
				}
				else if(k==2){
					if(tv[i-1]<=0)continue;
					q=1;
				}
				else q=0;
				if(p==0 || q==0)x=max(x,dp[i-1][k]);
				else x=max(x,max(p,q)+dp[i-1][k]);
			}
			dp[i][j]=x;
		}
		
		rep(k,4){
			//printf("%d %d : %d\n",i,k,dp[i][k]);
		}
	}
	
	int ans=0;
	rep(i,4)ans=max(ans,dp[ls-2][i]);
	return ans;
}

int main(void){
	scanf("%d%s",&n,s+2); 
	n = strlen(s+2);
	s[0]=s[1]=s[n+2]=s[n+3]='0';
	n+=4;
	int ans=0;
	int ls=0;
	rep(i,n-1){
			//printf("%d %c %d %d\n",i,s[i],ls,s[i]=='1');
		if(s[i]=='1')ls++;
		else if(s[i]=='0' && ls>0){
			nv.push_back(ls);
			ls=0;
		}
		if(s[i]=='0' && s[i+1]=='0'){
			int ca=cal();
			//printf("sum %d\n",ca);
			ans += ca;
			nv.clear();
		}
	}
	printf("%d\n",ans);
	return 0;
}






Measured memory_bytes: 768