akhauriyash/Code-Regression huggingface dataset:
n,m = map(int, input().split())
height = list(map(int, input().split()))

roads = [[] for i in range(n)]
for i in range(m):
    x,y = map(int, input().split())
    roads[x-1].append(y-1)
    roads[y-1].append(x-1)

bestcount = 0

for i in range(n):
    best = 1 # 良い展望台なら1
    for j in roads[i]:
        if (height[j] >= height[i]):
            best = 0
            break
    if(best == 1):
        bestcount += 1

print(str(bestcount))

Measured memory_bytes: 29400
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
auto const inf = numeric_limits<int>::max() / 8;

using Capacity = int;

struct Dinic {
public:
    Dinic(int n_) : n(n_), g(n_) {}
    Capacity maximumFlow(int s_, int t_) {
        this->t = t_, this->s = s_;
        Capacity res = 0;
        while (levelize()) {
            prog.assign(n, 0);
            res += augment(s, inf);
        }
        return res;
    }
    void addEdge(int u, int v, Capacity c) {
        g[u].push_back({ u,v,c,0,(int)g[v].size() });
        g[v].push_back({ v,u,c,c,(int)g[u].size() - 1 });
    }

private:
    struct Edge {
        int s, d;
        Capacity c, f;
        int r;
    };
    vector<vector<Edge>> g;
    int n, s, t;
    vector<int> level, prog;
    bool levelize() {
        queue<int> q;
        q.push(s);
        level.assign(n, -1); 
        level[s] = 0; 
        while (q.size()) {
            int v = q.front();
            q.pop();
            if (v == t) break;
            for (auto &e : g[v]) {
                int d = e.d;
                if (level[d] == -1 && residue(e) != 0) {
                    level[d] = level[v] + 1;
                    q.push(d);
                }
            }
        }
        return level[t] != -1;
    }
    Capacity augment(int v, Capacity lim) {
        Capacity res = 0;
        if (v == t) return lim;
        for (int &i = prog[v]; i < (int)g[v].size(); i++) {
            if (lim == 0) break;
            auto &e = g[v][i];
            int d = e.d;
            if (residue(e) == 0 || level[v] >= level[d]) continue;
            Capacity aug = augment(d, min(lim, residue(e)));
            e.f += aug;
            reverse(e).f -= aug;
            res += aug; 
            lim -= aug;
        }
        return res;
    }
    inline Capacity residue(const Edge& e) { return e.c - e.f; }
    inline Edge &reverse(const Edge &e) { return g[e.d][e.r]; }
};

int main() {
    int N, M;
    cin >> N >> M;
    Dinic g(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        g.addEdge(a, b, c);
    }
    Dinic d(g);
    cout << d.maximumFlow(0, N - 1) << endl;
}

Measured memory_bytes: 3244
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class D
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Console.ReadLine();
            var answer = S.Length % 2 == 0 ^ S[0] == S[S.Length - 1];
            Console.WriteLine(answer ? "Second" : "First");
        }
    }
}


Measured memory_bytes: 26096
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double


using namespace std;
const int N = 1e5 + 5;


int main(){
    string s; cin >> s;
    ll sum = 0;
    for(auto e : s){
        sum += (int)e - '0';
        sum = sum % 9;
    }
    if(sum % 9)
        cout << "No";
    else cout << "Yes";
    return 0;
}


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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    bool f = 1;
    map<char, char> mps, mpt;
    int n = s.size();
    for(int i = 0; i < n; i++) {
        if(mps.count(s[i]) && mps[s[i]] != t[i]) {
            f = 0;
        }
        if(mpt.count(t[i]) && mpt[t[i]] != s[i]) {
            f = 0;
        }
        mps[s[i]] = t[i];
        mpt[t[i]] = s[i];
    }
    cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 916
from fractions import gcd
A, B, C, D = map( int, input().split() )

# 方針
# 入力例1をよくみてみる。
# 1 2 3 4 5 6 7 8 9 10 11... に対して範囲[ 4, 9 ]の間で2の倍数を(),3の倍数を{}で示す
# 1 (2) {3} | (4) 5 {(6)} 7 (8) {9} | (10) 11.. となる。
# 範囲[1,9]の間の倍数で"ない"ものの個数と範囲[1,3]の間の倍数で"ない"ものの個数がわかれば良いことがわかる

# 範囲[ 1, upper ]の倍数で"ない"ものの個数
# Cの倍数とDの倍数を足してCDの最小公倍数を引く。それらが倍数で"ある"ものの個数。
# よって戻り値は全体から倍数で"ある"ものの個数を引く
def get_non_div_cnt_with_range( upper ):
  num_of_range_with_C  = ( upper // C )
  num_of_range_with_D  = ( upper // D )
  num_of_range_with_CD = ( upper // ( C * D // gcd( C, D ) ))
  return upper - ( num_of_range_with_C + num_of_range_with_D - num_of_range_with_CD )

upper_limit = B
lower_limit = A - 1
  
print( get_non_div_cnt_with_range( upper_limit ) - get_non_div_cnt_with_range( lower_limit ) )


Measured memory_bytes: 5304
#include <stdio.h>
int main(void) {
	int a, b;
	char op;
	int f = 0;

	while (f == 0)
	{
		scanf("%d %c %d", &a, &op, &b);

		if (op == '?') {
			break;
		}
		else if (op == '+') {
			printf("%d\n", a + b);
		}
		else if (op == '-') {
			printf("%d\n", a - b);
		}
		else if (op == '*') {
			printf("%d\n", a * b);
		}
		else if (op == '/') {
			if (b != 0) {
				printf("%d\n", a / b);
			}
		}

	}
	return 0;
}

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

total = 0
for _a in a:
    total += _a

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()

    return divisors[::-1] # larget -> small

d_all = make_divisors(total)

for d in d_all:
    resid = []
    for i in range(n):
        resid.append(a[i] % d)
    resid_sum = sum(resid)
    resid.sort()
    x = resid_sum // d

    if x > 0:
        resid_sum2 = sum(resid[:-x]) + x * d - sum(resid[-x:])
        if resid_sum2 <= k * 2: 
            ans = d
            break
    else:
        ans = d
        break

print(ans)


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

ans=n
for i in range(n+1):
  cnt=0
  t=i
  while t>0:
    cnt+=t%6
    t//=6
  j=n-i
  while j>0:
    cnt+=j%9
    j//=9
  ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;



double dist(pii i, pii j){
    return sqrt( pow( i.first - j.first, 2 ) + pow( i.second - j.second, 2));
}

int main(){
    int n;
    cin >> n;
    vector<pii> towns(n);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        towns[i] = mp(x,y);
    }
    vint v(n);
    iota(v.begin(), v.end(), 0);
    double ans = 0;
    double p_count=0;
    do{
        p_count++;
        rep(i,n-1){
            ans += dist(towns[v[i]], towns[v[i+1]]);
        }
    } while ( next_permutation(v.begin(), v.end()) );
    ans = ans / p_count;
    fcout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x,y;
    while(1){
        scanf( "%d%d", &x, &y );
        if ( x == 0 && y == 0 ) break;
        if( x <= y ){
            printf( "%d %d\n", x,y );
        } else {
            printf( "%d %d\n",y,x );
        }
    }
    return 0;
}

Measured memory_bytes: 1760
#include <iostream>
#include <vector>
using namespace std;
vector<long long> memo(87,-1);

  
long long lucas_number(int n){
  if(memo[n]!=-1) return memo[n];
  return memo[n] = lucas_number(n-1)+lucas_number(n-2);
}

int main(){
  memo[0]=2;
  memo[1]=1;
  int N;
  cin >> N;
  cout << lucas_number(N) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>


using namespace std;

struct country_point{
    string country;
    int num;
    int point;
};

bool country_point_compare(country_point l, country_point r){
    if(l.point>r.point)return true;
    if(l.point<r.point)return false;
    if(l.num<r.num)return true;
    return false;
}

int main(){
    int n;
    bool flag=false;
    while(cin>>n){
        if(n==0)break;
        if(flag)cout<<endl;
        flag = true;

        country_point all_country[10];
        for(int i=0; i<n; i++){
            string c;
            cin>>c;
            all_country[i].country = c;
            int win, loss, drow;
            cin>>win;
            all_country[i].point=win*3;
            cin>>loss;
            cin>>drow;
            all_country[i].point+=drow;
            all_country[i].num = i;
        }
        
        sort(all_country, all_country+n, country_point_compare);
        
        for(int i=0; i<n; i++){
            cout<<all_country[i].country<<","<<all_country[i].point<<endl;
        }
    }
    
}

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

using namespace std;

int main(){
	int n=0;
	int k=0;
	int x=0;
	int y=0;
	cin >> n >> k >> x >> y;
	if(n<=k){
		cout << n*x << endl;
	}else{
		cout << k*x+(n-k)*y << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

li = [-1]*N #グー、チョキ、パー
se = set(["r","s","p"])
dic = {"r":"p","s":"r","p":"s"}
score = {"r":0,"s":0,"p":0}
#iはあまりでi+k*a
num = N//K
for i in range(K):
    for a in range(num+1):
        nex = i + K*a
        if nex>N-1:
            break 

        rival = T[nex]
        kati = dic[rival]
        
         
        if nex<K:
            li[nex]=kati
            score[kati]+=1
        elif not kati==li[nex-K]:
            li[nex]=kati
            score[kati]+=1
        #elif kati==li[nex-k]:
        # if nex+k>N-1:
        # else:
print(score["r"]*R+score["s"]*S+score["p"]*P)



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

int main() {
  int long long  n,a,b;
  cin>>n>>a>>b;
  int long long x=n/(a+b);
  int long long y=n%(a+b);
  if(y>=a){
    cout<<x*a+a<<endl;
  }
  else{
    cout<<x*a+y<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin>>n;
    ll sum,ans=0;
    sum=(n*(n+1)/2);
    for(ll i=1;i<=n;i++){
        if(i%3==0||i%5==0){
            ans+=i;
        }
    }
    cout<<sum-ans<<endl;
}

Measured memory_bytes: 3640
N,K=map(int,input().split())
A=[int(x)-1 for x in input().split()]

dist={0:0}
t=i=0
while K>0:
    K-=1
    i+=1
    t=A[t]
    if t in dist:
        K%=i-dist[t]
    else:
        dist[t]=i

print(t+1)


Measured memory_bytes: 111012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100500;
const int MOD = 1e9 + 7;

int mul(int a, int b)
{
	return (long long) a * b % MOD;
}

int arr[MAXN];
int fac[MAXN];
int n;

int main()
{
	fac[0] = 1;
	for (int i = 0; i < MAXN - 1; i++)
		fac[i + 1] = mul(fac[i], i + 1);

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i++)
		arr[i] = min(arr[i], 2 * i + 1);
	ll cnt = 0;
	ll res = 1;
	for (int i = 0; i < n; i++)
	{		
		if (arr[i] < 2 * cnt + 1)
			res = mul(res, cnt + 1);
		else
			cnt++;
	}
	
	res = mul(res, fac[cnt]);
	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 1024
import math

n,d = map(int,input().split())
l = [0]*n
for i in range(n):
    l[i] = list(map(int,input().split()))

res = 0
for i in range(n-1):
    for j in range(i+1,n):
        sumdiff = 0
        for k in range(d):
            sumdiff += (l[i][k]-l[j][k])**2
        else:
            if math.sqrt(sumdiff) == math.sqrt(sumdiff)//1:
                res += 1
else:
    print(res)


Measured memory_bytes: 3064
#!ruby -pal
p,q=$F.map &:to_i
a=[]
m=[]
(m<<p
p*=10
a<<p/q)while !(((n=m.index(p%=q))||p<1)&&$_=a*""+(n ??\n+" "*n+?^*(m.size-n):""))

Measured memory_bytes: 6112
void main() {
	auto ip = readAs!(long[]), a = ip[0], b = ip[1];
	if(a <= 0 && b >= 0) {
		writeln("Zero");
		return;
	}
	if(a > 0) {
		writeln("Positive");
		return;
	}
	if(abs(a-b) % 2 == 1) {
		writeln("Positive");
		return;
	} else writeln("Negative");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

using namespace std;

#define LL long long
#define u64 unsigned long long
#define u32 unsigned int
#define reg register
#define Raed Read
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,x) for(reg int i=Head[x]; i; i=Nxt[i])

inline int Read() {
	int res = 0, f = 1;
	char c;
	while (c = getchar(), c < 48 || c > 57)if (c == '-')f = 0;
	do res = (res << 3) + (res << 1) + (c ^ 48);
	while (c = getchar(), c >= 48 && c <= 57);
	return f ? res : -res;
}

template<class T>inline bool Min(T &a, T const&b) {
	return a > b ? a = b, 1 : 0;
}
template<class T>inline bool Max(T &a, T const&b) {
	return a < b ? a = b, 1 : 0;
}

const int N=1e5+5,M=1e5+5,mod=1e9+7;

bool MOP1;

int A[N],flag;

bool MOP2;

bool check(int x){
	int tot=0;
	while(x)x/=10,tot++;
	return tot&1;
}

inline void _main(void) {
	int n=Raed();
	int tot=0;
	rep(i,1,n)if(check(i))tot++;
	cout<<tot;
}

signed main() {
#define offline1
#ifdef offline
	freopen("chessboard.in", "r", stdin);
	freopen("chessboard.out", "w", stdout);
	_main();
	fclose(stdin);
	fclose(stdout);
#else
	_main();
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 100005
#define mod (int)(1e18+7)
#define sp fixed<<setprecision(12)
using namespace std;

/*
vector<int> primes;
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    
}

int power(int a,int n,int p){
    int res=1;
    while(n){
        if(n&1){
            res=(res*a)%p;
            n--;
        }else{
            a=(a*a)%p;
            n/=2;
        }
    }
    return res;
}
*/


int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;

    int t=1;
    //cin>>t;
    //int it=1;
    while(t--){
        int n,m,k;
        cin>>n;
        priority_queue<int> pq;
        for(int i=0;i<n;i++){
            int no;
            cin>>no;
            pq.push(no);
        }
        int ct=1;
        int ans=pq.top();
        pq.pop();
        while(ct<(n-1)){
            int t=pq.top();
            pq.pop();
            if(ct<(n-1)){
                ans+=t;
                ct++;
            }
            if(ct<(n-1)){
                ans+=t;
                ct++;
            }
        }
        cout<<ans<<"\n";
    }

    return 0;
    
}

Measured memory_bytes: 5332
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll k,a,b;
int main(){FAST;
cin>>k;
cin>>a>>b;
if(b/k-(a-1)/k){
  cout<<"OK";
}
else cout<<"NG";
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3648
#include <stdio.h>

int main(void)          
{
	int r, c, rc[100][100], csum[101], rsum[101];
	int i, j;
	scanf("%d %d", &r, &c);

	for (i = 0; i < r; i++)
	{	
		csum[i] = 0;
		for (j = 0; j < c; j++)
		{
			scanf("%d", &rc[i][j]);
			csum[i] += rc[i][j];
		}
	}

	for (i = 0; i <= c; i++)
	{
		rsum[i] = 0;
	}
	for (i = 0; i < c; i++) 
	{
		for (j = 0; j < r; j++)
		{
			rsum[i] += rc[j][i];
		}
	}
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			printf("%d ", rc[i][j]);
			if (j == c - 1) printf("%d\n", csum[i]);
		}
	}
	
	for (i = 0; i < c; i++) 
	{
		printf("%d ", rsum[i]);
		rsum[c] += rsum[i];
		if (i == c - 1) printf("%d\n", rsum[c]);
	}
	return 0;
}

Measured memory_bytes: 640
n,k = gets.chomp.split(" ").map(&:to_i)

div = 10**9 + 7
m = n-k
op = m+1
puts op
for i in 1..k-1 do
    if i <= m then
        op *= m+1-i
        op *= k-i
        op /= i+1
        op /= i
        puts op % div
    else
        puts "0"
    end
end

Measured memory_bytes: 2172
#include <iostream>
#include <set>
using namespace std;
int main(){
  int n,m,q;
  cin >> n;
  set<int> S;
  for(int i = 0 ; i < n ;i++){
    cin >> m;
    S.insert(m);
  }
  cin >> q;
  int ans=0;
  for(int i = 0; i< q ;++i){
    cin >> m;
    if(S.count(m)==1) ans++;

  }
  cout << ans << endl;

}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

#define REP(i,m,M) for(int i=m; i<M; i++)
#define REPR(i,M,m) for(int i=M; i>m; i—-)
#define REPLL(i,m,M) for(ll i=m; i<M; i++)
#define REPLLR(i,M,m) for(ll i=M; i>m; i—-)
#define ALL(v) v.begin(),v.end()

int Length(int A)
{
    if (A == 0) return 0;
    if (A == 1) return 1;
    else return 1 + Length(A >>= 1);
}

int main(int argc, const char * argv[]) {
    int N;
    int A[200001];
    int L[200001];
    cin >> N;
    int NumNZ = 0;
    L[0] = 0;
    int Tmp;
    for (int n=0; n<N; ++n) {
        cin >> Tmp;
        if (Tmp == 0) L[NumNZ]++;
        else {
            A[NumNZ] = Tmp;
            NumNZ++;
            L[NumNZ] = 0;
        }
    }

    ll Res = 0;
    for (int n=0; n<=NumNZ; ++n) {
        Res += (ll) L[n] * (L[n] + 1) / 2;
    }
    for (int l=0; l<NumNZ; ++l) {
        int TmpXor = A[l];
        int TmpSum = A[l];
        Res += (ll) (L[l] + 1) * (L[l+1] + 1);
        for (int r=l+1; r<NumNZ; ++r) {
            TmpXor ^= A[r];
            TmpSum += A[r];
            if (TmpXor == TmpSum) Res += (ll) (L[l] + 1) * (L[r+1] + 1);
            else break;
        }
    }

    cout << Res << endl;
    return 0;
}


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

using namespace std;

#define MAX 514
#define INF 1145141919
typedef pair<int, int> pii;

int main()
{
    int N, M;
    while (cin >> N, N) {
        vector<pii> v;
        int a, b;        
        for (int i = 0; i < N; i++) {
            cin >> a >> b;
            v.push_back(pii(a, -b));
        }
        cin >> M;
        for (int i = 0; i < M; i++) {
            cin >> a >> b;
            v.push_back(pii(a, -b));
        }

        N += M;

        sort(v.begin(), v.end());
        int dp[MAX];
        fill(dp, dp + MAX, INF);
        for (int i = 0; i < N; i++) {
            int c = -v[i].second;
            *lower_bound(dp, dp + N, c) = c;
        }
        cout << (lower_bound(dp, dp + N, INF) - dp) << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
X,K,D=map(int,input().split())
X=abs(X)
count=0

if X-K*D>=0:
	print(X-K*D)
else:
	s=int(X/D)
	kaisuu=K-s
	if kaisuu%2==0:
		print(abs(X-s*D))
	else:
		print(abs(X-(s+1)*D))
		


Measured memory_bytes: 9104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


public class Main {
	public static void main( String[] args ) throws IOException
    {
        BufferedReader br = new BufferedReader(
                                new InputStreamReader( System.in ) );
        String  s = br.readLine();
        List<Integer> l = new ArrayList<>();
        char c[] = s.toCharArray();
        int co = 0;
        for(int i=0;i<c.length;i++){
        	if(c[i] == 48){
        		l.add(0);
        		co++;
        	} else if(c[i] == 49){
        		l.add(1);
        		co++;
        	} else if(c[i] == 66){
        		if(co == 0){
        		} else {
        			l.remove(co-1);
        			co--;
        		}
        	}
        }
        for(int i=0 ; i < l.size(); i++){
        	Integer I = i;
        	System.out.print(l.get(I));
        }
        System.out.println();
	}

}

Measured memory_bytes: 7892
n = gets.to_i
pr = []
n.times do
  a = gets.to_i
  hs = Hash.new
  a.times do
    x, y = gets.chomp.split.map(&:to_i)
    hs[x - 1] = y
  end
  pr.push(hs)
end

res = 0
(2 ** n - 1).step(0, -1) do |b|
  ok = true
  0.step(n - 1) do |i|
    if b & (1 << i) == 0 # 不親切
      next
    end

    pr[i].each do |x, y|
      if (b & (1 << x) != 0 && y == 0) || (b & (1 << x) == 0 && y == 1)
        ok = false
        break
      end
    end

    if !ok
      break
    end
  end
  
  if ok
    cnt = ("%b" % [b]).count("1")
    res = cnt if cnt > res
  end
end
puts res

Measured memory_bytes: 14172
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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

int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	
	string s;
	cin >> s;

	deque<char> dq;

	for (int i = 0; i < s.size(); i++)
	{
		dq.push_back(s[i]);
	}


	int q;
	cin >> q;


	bool flag = true;

	//flagがtrue： 1で前，2で後ろ
	//flagがfalse： 1で後ろ，２で前

	for (int i = 0; i < q; i++)
	{
		int c;
		cin >> c;

		if (c == 1) {

			//反転
			flag = !flag;

		}
		else
		{
			int f;
			char p;
			cin >> f >> p;

			if (flag) {

				if (f == 1) {
					dq.push_front(p);
				}
				else
				{
					dq.push_back(p);
				}

			}
			else
			{
				if (f == 1) {
					dq.push_back(p);
				}
				else
				{
					dq.push_front(p);
				}
			}

		}


	}

	string ans;
	for (auto itr : dq) {
		ans.push_back(itr);
	}

	if (flag) {
		cout << ans << endl;
	}
	else
	{
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 1368
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int a[3];

int main()
{
	in >> a[0] >> a[1] >> a[2];
	std::sort(a, a + 3);
	out << a[0] + a[1] << std::endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = []
for  i in range(n):
    a,b = map(int,input().split())
    ab.append([b,a])

ab.sort()
s = 0
flg = 0
##print(ab)
for i in range(n):
    s += ab[i][1]
    if s>ab[i][0]:
        flg = 1
        break

if flg == 0:
    print("Yes")

else:
    print("No")
    


Measured memory_bytes: 35608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    rep(i,3)
    {
        string s;
        cin >>s;
        printf("%c", s[0]-'a'+'A');
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = LLONG_MAX;
int main() {
	cin >> N >> C;
	vector<vector<int>>D(C, vector<int>(C));
	vector<vector<pair<ll, int>>>sum(3, vector<pair<ll, int>>(C, make_pair(0, 0)));
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int c;
			cin >> c;
			for (int k = 0; k < C; k++) {
				sum[(i + j) % 3][k].first += D[c - 1][k];
				sum[(i + j) % 3][k].second = k;
			}
		}
	}
	for (int i = 0; i < 3; i++)sort(sum[i].begin(), sum[i].end());
	int tmp = C;
	if (N == 1)ans = sum[0][0].first;
	else {
		for (int i = 0; i < tmp; i++) {
			for (int j = 0; j < tmp; j++) {
				for (int k = 0; k < tmp; k++) {
					int p = sum[0][i].second, q = sum[1][j].second, r = sum[2][k].second;
					if (p == q || q == r || r == p)continue;
					ans = min(ans, sum[0][i].first + sum[1][j].first + sum[2][k].first);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N=list(map(int, input().split()))
N=N[0]
a=list(map(int, input().split()))
b=[0]*(N+1)
ball=0
for i in range(N,0,-1):
    ans=0
    index=i*2
    while index<=N:
        ans+=b[index]
        index+=i
    if ans%2!=a[i-1]:
        b[i]=1
        ball+=1

print(ball)
moji=""
for i in range(1,N+1):
    if b[i]==1:
        moji+=str(i)+" "
print(moji)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	ll n, k;
	cin >> n >> k;
	cout << min(n % k, abs(k - n % k)) << endl;
    
    return 0;
}

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

using namespace std;
int k[100005];
int main(){
	int n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i]=='C'&&s[i-1]=='A')k[i]=k[i-1]+1;
		else k[i]=k[i-1];
	}
	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		cout<<k[b]-k[a]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <queue>
#define N 110
using namespace std;
struct num
{
    int x,y,op;
}a[1000000];
int b[N][N],Top = 0;
bool ch[N][N][5];
int chv[N][N][5];
char s1[N];
int pt[500];
int X[]={-1,0,1,0};
int Y[]={0,1,0,-1};
int main()
{
    int n,m;
    long long int k;
    while(scanf("%d %d %lld",&n,&m,&k)!=EOF)
    {
        if(n==0&&m==0&&k==0)
        {
            break;
        }
        int x,y;
        int op;
        memset(b,0,sizeof(b));
        pt['N'] = 0;
        pt['E'] = 1;
        pt['S'] = 2;
        pt['W'] = 3;
        for(int i=0;i<=n-1;i++)
        {
            scanf("%s",s1);
            int l = strlen(s1);
            for(int j=0;j<=l-1;j++)
            {
                if(s1[j]!='#')
                {
                    b[i][j] = 1;
                }
                if(s1[j]=='N'||s1[j]=='E'||s1[j]=='S'||s1[j]=='W')
                {
                    x = i;
                    y = j;
                    op = pt[s1[j]];
                }
            }
        }
        Top = 0;
        memset(ch,false,sizeof(ch));
        int uv = 0;
        while(!ch[x][y][op])
        {
            if(uv)
            {
                chv[x][y][op] = Top;
                a[Top].x = x;
                a[Top].y = y;
                a[Top++].op = op;
                ch[x][y][op] = true;
            }
            int op2=op;
            for(int i=0;i<=3;i++)
            {
                int x1 = x+X[op2];
                int y1 = y+Y[op2];
                if(x1>=0&&x1<=n-1&&y1>=0&&y1<=m-1&&b[x1][y1]!=0)
                {
                    x = x1;
                    y = y1;
                    op = op2;
                    break;
                }else
                {
                    op2 =(op2+1)%4;
                }
            }
            uv = 1;
        }
        int pos=chv[x][y][op];
        int sum = Top-pos;
        int sum2=Top-sum;
        if((long long int)sum2>=k)
        {
            pos = k-1;
        }else
        {
            k = k-(long long int)sum2;
            pos = k%(long long int)sum;
            if(pos==0)
            {
                pos = Top-1;
            }else
            {
                pos =  sum2-1+pos;
            }
        }
        printf("%d %d ",a[pos].x+1,a[pos].y+1);
        op = a[pos].op;
        char c;
        if(op==0)
        {
            c = 'N';
        }else if(op==1)
        {
            c = 'E';
        }else if(op==2)
        {
            c = 'S';
        }else
        {
            c = 'W';
        }
        printf("%c\n",c);
    }
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> vec;
    rep(i, n){
        int v; cin >> v;
        vec.push_back(v);
    }
    sort(vec.begin(), vec.end());

    double ans = vec[0];
    REP(i, 1, n){
        ans = (ans + vec[i]) / 2;
    }
    OP(ans);
}


Measured memory_bytes: 256
deglist = raw_input().split(" ")
W = int(deglist[0])
H = int(deglist[1])
x = int(deglist[2])
y = int(deglist[3])
r = int(deglist[4])

if x >= r and x <= (W - r) and r <= y and y <= (H - r):
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 6452
#include <iostream>
using namespace std;
int c2i[256];

void init() {
  c2i['I'] = 1;
  c2i['V'] = 5;
  c2i['X'] = 10;
  c2i['L'] = 50;
  c2i['C'] = 100;
  c2i['D'] = 500;
  c2i['M'] = 1000;
}

int main() {
  init();

  string str;
  while(getline(cin, str)) {
    int res = 0;
    for(int i=0; i<str.size(); i++) {
      if(c2i[str[i]] < c2i[str[i+1]]) {
	res -= c2i[str[i]];
      } else {
	res += c2i[str[i]];
      }
    }
    cout << res << endl;
  }
  
  return 0;
}

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

int main(){
    int A, B, C, K, ans = 0;
    cin >> A >> B >> C >> K;

    if(K <= A){
        ans += K;
        cout << ans << endl;
        return 0;
    } else if(A < K){
        ans += A;
        K -= A;
    }

    if(K <= B){
        cout << ans << endl;
        return 0;
    } else if(B < K){
        K -= B;
    }

    ans -= K;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;

public class ABC163B {
	private static void Main(string[] args) {
		var input = ReadIntsAsArray();
		var n = input[0];
		var a = ReadIntsAsArray();

		var answer = Math.Max(-1, n - a.Sum());
		Console.WriteLine(answer);
	}

	private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

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

using namespace std;

int N;
long A[50] = {0};

int main() {
#ifdef __APPLE__
    freopen("input3.txt", "r", stdin);
#endif
    cin >> N;

    long abs_max = 0;
    int abs_max_idx = 0;
    bool has_negative = false;
    bool has_positive = false;

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] > 0) has_positive = true;
        if (A[i] < 0) has_negative = true;
        if (abs_max < abs(A[i])) {
            abs_max = abs(A[i]);
            abs_max_idx = i;
        }
    }

    int ans_count = 0;
    vector<pair<int, int>> ans_operations;

    if (has_negative && has_positive) {
        if (abs_max == A[abs_max_idx]) {
            for (int i = 0; i < N; ++i) {
                if (A[i] < 0) {
                    A[i] += abs_max;
                    ++ans_count;
                    ans_operations.push_back({abs_max_idx+1, i+1});
                }
            }
        } else { // abs_max < 0
            for (int i = 0; i < N; ++i) {
                if (A[i] > 0) {
                    A[i] -= abs_max;
                    ++ans_count;
                    ans_operations.push_back({abs_max_idx+1, i+1});
                }
            }
        }
    }

    if (A[abs_max_idx] == abs_max) {
        for (int i = 1; i < N; ++i) {
            if (A[i-1] > A[i]) {
                A[i] += A[i-1];
                ++ans_count;
                ans_operations.push_back({i, i+1});
            }
        }
    } else {
        for (int i = N-1; i > 0; --i) {
            if (A[i] < A[i-1]) {
                A[i-1] += A[i];
                ++ans_count;
                ans_operations.push_back({i+1, i});
            }
        }
    }

    cout << ans_count << endl;
    for (int j = 0; j < ans_count; ++j) {
        cout << ans_operations[j].first << " " << ans_operations[j].second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def solve(x):
    if(x<2):
        return 0
    k=1
    s=0
    while True:
        if(x%k==0):
            i=(x//k)-1
            if (x//i==x%i):
                s+=i
        k+=1
        if k*k>x:
            break
    return s
        

x=int(input())
print(solve(x))

Measured memory_bytes: 3060
n = int(input())
a_list = [0]
for _ in range(n):
    a_list.append(int(input()))
counter = 0
current_number = 1
already_pushed_list = set()

while(True):
    counter += 1
    already_pushed_list.add(current_number)
    current_number = a_list[current_number]
    if current_number in already_pushed_list:
        print(-1)
        break
    if current_number == 2:
        print(counter)
        break


Measured memory_bytes: 13216
k=int(input())
a=[int(j) for j in input().split()]
if a[-1]!=2:
    print(-1)
    exit()

import math

amin=2
amax=2
for i in range(k)[::-1]:
    amin+=(-amin)%a[i]
    amax-=amax%a[i]
    amax+=a[i]-1

if amin>amax:
    print(-1)
else:
    print(amin,amax)





Measured memory_bytes: 14252
#include <iostream>

using namespace std;

long comb(long n, long k) {
  if (n < k) { return 0; }
  long res = 1;
  for (int i = n; i > n - k; i--) { res *= i; }
  for (int i = 1; i <= k; i++) { res /= i; }
  return res;
}

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

  long res = 0;
  res += comb(n, 2);
  res += comb(m, 2);

  cout << res << endl;
}


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

int main()
{
	string s;
	int i,l;
	getline(cin, s);
	l = s.length();

	for (size_t i = 0; i < l; i++)
	{
		s.replace(i, 1, "x");
	}
	cout << s;

}



Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	float r;
	cin >> r;
	cout << r * 2 * 3.14159265358979 << endl;
	return 0;
}

Measured memory_bytes: 3788
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll cul(ll a,ll b,ll x){
    ll l=0,r=b+1;
    while(r-l>1){
        ll m=l+(r-l)/2;
        if(m*x>a || m>b || (b-m)/x>a-(m*x)){r=m;}
        else{l=m;}
    }
    return l;
}

//1-indexed
string cul(ll a,ll b,ll c,ll d){
    string ret;
    ll x=(a+b)/(b+1);
    if(a==b || x==1){
        for(ll i=c;i<=d;i++){ret.push_back(i&1?'A':'B');}
        return ret;
    }
    ll L=cul(a,b,x),R=cul(b,a,x);
    for(ll i=c;i<=d;i++){
        if(i<=L*(x+1)){
            ret.push_back(i%(x+1)?'A':'B');
        }
        else if(a+b-i+1<=R*(x+1)){
            ret.push_back((a+b-i+1)%(x+1)?'B':'A');
        }
        else{
            ll I=i-(x+1)*L;
            ll A=a-L*x-R;
            ll B=b-L-R*x;
            //cout<<i<<" "<<L<<" "<<R<<" "<<A<<" "<<B<<endl;
            assert((A<x && B<x) || (A==x && R==0) || (B==x && L==0));
            ret.push_back(I<=A?'A':'B');
        }
    }
    return ret;
}


int main(){
    ll q;
    cin>>q;
    while(q--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        string ans;
        if(a>b){
            ans=cul(a,b,c,d);
        }
        else{
            ans=cul(b,a,a+b-d+1,a+b-c+1);
            reverse(ans.begin(),ans.end());
            for(auto &I:ans){I=(I=='A'?'B':'A');}
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}


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

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

  int p[5000];
  for(int i=0; i<N; i++){
    cin >> p[i];
  }

  int min_sum = 20000;

  for(int I=0; I<=p[0]; I++){
    int q[5000];
    for(int i=0; i<N; i++){
      q[i] = p[i];
    }

    int sum = I;
    q[0] -= I;

    for(int i=0; i<=N-2; i++){
      if(q[i]<=0)
        continue;

      sum += q[i]*2;
      q[i+1] -= q[i];
    }

    if(q[N-1]>0){
      sum  += q[N-1];
    }
    min_sum = min(min_sum, sum);
  }
  cout << min_sum << endl;
  return 0;
}



Measured memory_bytes: 3140
n = input()
if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9":
  print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
  print("pon")
elif n[-1] == "3":
  print("bon")

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

int main(){
    int n; //重りの個数
    cin >> n;

    int weights[n];
    for(int i=0; i<n; i++) cin >> weights[i];

    int front = 0;
    int back = n-1;
    int s1 = 0;
    int s2 = 0;
    while(back - front >= 0){
        if(s1 > s2){
            s2 += weights[back];
            back -= 1;
        }else{
            s1 += weights[front];
            front += 1;
        }
    }

    cout << abs(s1 - s2) << endl;
}

Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let s = read_line () |> split_string

let cnt = List.fold_left (fun acc n ->
  match acc with
    | [] -> [(n, 1)]
    | (v, cnt) as t :: xs -> if v = n then (v, cnt + 1) :: xs else (n, 1) :: t :: xs
) [] @@ List.sort compare s

let () = 
  if List.length cnt < 3 then
    print_endline "0"
  else begin
    let s = Array.of_list s in
    let ans = ref @@ List.fold_left ( * ) 1 @@ List.map snd cnt in
    for i = 0 to n - 2 do
      for j = i + 1 to n - 1 do
        let k = j + (j - i) in
        if k < n && s.(i) <> s.(j) && s.(j) <> s.(k) && s.(i) <> s.(k) then ans := !ans - 1
      done
    done;
    Printf.printf "%d\n" !ans
  end

Measured memory_bytes: 6088
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	X := ReadInt()
	n5 := make([]int, 0)
	for i := 0; i*i*i*i*i < 1<<61; i++ {
		n5 = append(n5, i*i*i*i*i)
	}

	for a := 0; a < len(n5); a++ {
		for b := 0; b < len(n5); b++ {
			if n5[a]-n5[b] == X {
				fmt.Printf("%d %d\n", a, b)
				return
			}
			if n5[a]+n5[b] == X {
				fmt.Printf("%d %d\n", a, -b)
				return
			}
			if -n5[a]-n5[b] == X {
				fmt.Printf("%d %d\n", -a, b)
				return
			}
			if -n5[a]+n5[b] == X {
				fmt.Printf("%d %d\n", -a, -b)
				return
			}
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

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

	cin >> n >> m;

	vi a(n);

	for(int& x : a) 
		cin >> x;

	ll g = a[0];
	int count = 0;

	for(int k = 1; k < n; ++k) {
		int gcd = __gcd(g, 1LL * a[k]);
		if(LLONG_MAX / g < a[k] / gcd) {
			cout << 0 << '\n';
			return 0;
		}
		g *= a[k] / gcd;	
	}

	for(int k = 0; k < n; ++k) {
		if(!(g / a[k] & 1)) {
			cout << 0 << '\n';
			return 0;
		}
	}

	cout << ((2LL * m / g) + 1LL) / 2 << '\n';
    return 0;
}



Measured memory_bytes: 640
I=lambda:map(int,input().split())
n,q=I()
e=[[]for _ in range(n)]
d=[0]*n
for _ in range(n-1):
    a,b=I()
    e[a-1]+=b-1,
    e[b-1]+=a-1,
for _ in range(q):
    p,x=I()
    d[p-1]+=x
f=[1]+[0]*n
q=[0]
while q:
    v=q.pop()
    for w in e[v]:
        if f[w]:continue
        f[w]=1
        d[w]+=d[v]
        q+=w,
print(*d)

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

int main() {
  ll a,b,x; cin >> a >> b >> x;
  ll ans;
  if (a == 0) {
    ans = b / x + 1;
  } else {
    ans = b / x - (a - 1) / x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
const int max_n = 200000+10;

map<int,int> DA;
int A[max_n];

int main(void) {
    cin>>N;

    for(int i = 1;i <= N;i++) {
        cin>>A[i];
        DA[A[i]]++;
    }

    for(int i = 1;i <= N;i++) {
        auto it = DA.rbegin();
        if(it->first == A[i]) {
            if(it->second == 1) {
                it++;
                cout<<it->first<<endl;
            } else {
                cout<<it->first<<endl;
            }
        } else {
            cout<<it->first<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, H[MAX_N], diff[MAX_N];
int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> H[i];

    diff[0] = H[0];
    for(int i = 1; i < N; ++i)
        diff[i] = H[i] - H[i - 1];
    
    int res = 0;
    int cur = 0;
    for(int i = 0; i < N; ++i) {
        if(diff[i] <= 0) {
            ++cur;
            res = max(res, cur);
        } else {
            cur = 0;
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    int k;
    cin >> k;
    int a, b, c, sum = 0;
    for(a = 1; a <= k; a++){
        for(b = 1; b <= k; b++){
            for(c = 1; c <= k; c++){
                sum += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
	char b;
	scanf("%c",&b);
	if(b=='A'){
		printf("T\n");
	}
	else if(b=='T'){
		printf("A\n");
	}
	else if(b=='C'){
		printf("G\n");
	}
	else if(b=='G'){
		printf("C\n");
	}
	return 0;
}

Measured memory_bytes: 128