akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def solve(input: String): String = {
    val sc: Scanner = new Scanner(input)
    val n = sc.nextInt
    if ((for {
      cake <- 0 to n / 4
      donut <- 0 to (n - cake) / 7
    } yield cake * 4 + donut * 7).contains(n)) "Yes"
    else "No"
  }

  val tests = List(
    """11""".stripMargin -> """Yes""",
    """40""".stripMargin -> """Yes""",
    "3" -> "No"
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}

Measured memory_bytes: 27344
'''
	We can show that if u and v belong to the same connected component, then they are friends w/ each other
	So everyone in a given connected component is friends with one another
	So everyone in a given connected component must be separated into different groups

	If we have a CC of with sz nodes in it, then we need at least sz different groups

	So, the minimum number of groups needed is max sz(CC)
'''
import sys
sys.setrecursionlimit(4*10**5)

n, m = map(int,input().split())
adj = [[] for u in range(n+1)]
for i in range(m):
	u, v = map(int,input().split())
	adj[u].append(v)
	adj[v].append(u)

vis = [False for u in range(n+1)]
def dfs(u):
	if vis[u]:
		return 0
	vis[u] = True

	sz = 1
	for v in adj[u]:
		sz += dfs(v)
	return sz

CCs = []
for u in range(1,n+1):
	if not vis[u]:
		CCs.append(dfs(u))

print(max(CCs))

Measured memory_bytes: 210764
# ABC047D

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


n,t = map(int, input().split())
a = list(map(int, input().split()))

m = a[0]
best = 0
count = 0
for num in a[1:]:
    if m>num:
        m = num
    elif best<num-m:
        best = num - m
        count = 1
    elif best==num-m:
        count += 1
print(count)

Measured memory_bytes: 62704
from collections import deque
a = int(input())
l = [] 
for i in range(a):
    tl = list(map(int,input().split()))
    tl = list(map(lambda x:x-1 ,tl))
    l.append(tl)

q = deque((range(a)))
days=[0]*a
pairs=[-1]*a
while q:
    x = q.popleft()
    if len(l[x]) == 0:continue
    y = l[x].pop(0)
    if pairs[y] == x:
        days[x]=days[y]=max(days[x],days[y])+1
        q.append(x)
        q.append(y)
    else:
        pairs[x]=y
if not any(l):
    print(max(days))
else:
    print(-1)

Measured memory_bytes: 35340
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
struct shu{
int key;
shu *left,*right,*parent;
};
shu* nil;
shu* root;
char s[100];
void charu(int k){
shu* y=nil;
shu* x=root;
shu* z;
z=new shu;
z->key=k;
z->left=nil;
z->right=nil;
while(x!=nil){
    y=x;
    if(z->key < x->key){
       x=x->left;
    }
    else x=x->right;
}
z->parent=y;
if(y==nil)root=z;
else {
      if(z->key < y->key){
         y->left=z;
         }
         else y->right=z;
}
}
void qianxu(shu* u){
    if(u==nil)return ;
    printf(" %d",u->key);
    qianxu(u->left);
    qianxu(u->right);
}
void zhongxu(shu* u){
    if(u==nil)return ;
    zhongxu(u->left);
    printf(" %d",u->key);
    zhongxu(u->right);
}
int main(){
int n;
int m;
scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%s",s);
    if(s[0]=='i'){
        scanf("%d",&m);
        charu(m);
    }
    else if(s[0]=='p'){
        zhongxu(root);
        printf("\n");
        qianxu(root);
        printf("\n");
    }
}
return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h.at(i);
  h.push_back(-1);
  int ans = 0;
  rep(i,101) {
    int cnt = 0;
    rep(j,n) if(h.at(j+1)<=0 && h.at(j)>0)  cnt++;
    rep(j,n) h.at(j)--;
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int n,a=0,b=0,i,ai,bi;
while(1){
scanf("%d",&n);
if(n==0)break;
for(i=0;i<n;i++){
scanf("%d %d",&ai,&bi);
if(ai>bi)a=a+ai+bi;
else if(ai<bi)b=b+ai+bi;
else {a+=ai;
      b+=bi;}
              }
printf("%d %d\n",a,b);
a=0;b=0;}
return 0;
}

Measured memory_bytes: 1700
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int N = reader.nextInt();
		long ans = 0;
		for (int i=0; i<N; i++) {
		    ans += reader.nextInt()-1;
		}
		System.out.println(ans);
	}
	
	public static void solver() {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 21716
a = input()
b = input()
if len(a) > len(b):
	print("GREATER")
elif len(a) < len(b):
	print("LESS")
else:
	for i in range(len(a)):
		if a[i] > b[i]:
			print("GREATER")
			exit()
		elif a[i] < b[i]:
			print("LESS")
			exit()
	print("EQUAL")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int n, k;

bool check(ll d, vector<ll> &a){
    int n = a.size();
    vector<ll> r(n);
    for(int i = 0; i < n; i++){
        r[i] = a[i] % d;
    }
    sort(begin(r), end(r));
    vector<ll> pr(n), prr(n);
    partial_sum(begin(r), end(r), begin(pr));
    for(int i = 0; i < n; i++){
        prr[i] = (d - r[i]) % d;
    }
    partial_sum(rbegin(prr), rend(prr), rbegin(prr));
    for(int i = 0; i < n - 1; i++){
        ll t = 0;
        t = max(pr[i], prr[i + 1]);
        if(t <= k){
            return true;
        }
    }
    return false;
}

int main(){
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int sum = accumulate(begin(a), end(a), 0LL);
    vector<ll> d;
    for(int i = 1; i * i <= sum; i++){
        if(sum % i == 0){
            d.push_back(i);
            if(sum / i != i){
                d.push_back(sum / i);
            }
        }
    }
    ll ans = 0;
    sort(rbegin(d), rend(d));
    for(auto&& i : d){
        if(check(i, a)){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*input
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
set<int> v[26];
int main(){
    int n,q;
    string s;
    cin>>n>>s>>q;
    REP(i,sz(s)){
        v[s[i]-'a'].insert(i);
    }
    while(q--){
        int x,l;
        cin>>x>>l;
        --l;
        if(x==1){
            char z;
            cin>>z;
            v[s[l]-'a'].erase(v[s[l]-'a'].find(l));
            s[l]=z;
            v[s[l]-'a'].insert(l);
        }
        else{
            int r;
            cin>>r;
            --r;
            int ans=0;
            REP(i,26){
                if(v[i].lower_bound(l)==v[i].end()){
                    continue;
                }
                int x=*v[i].lower_bound(l);
                ans+=(x<=r);
            }
            cout<<ans<<'\n';
        }
    }
}

Measured memory_bytes: 24324
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n == 0)  break;
            int[] scores = new int[n];
            for(int i=0; i<scores.length; i++){
                scores[i] = sc.nextInt();
            }
            double average = 0, variance = 0;
             
            for(int i=0; i<n; i++){
                average += scores[i];
            }
            average /= n;
            for(int i=0; i<n; i++){
                variance += (scores[i] - average)*(scores[i] - average);
            }
            variance /= n;
            System.out.println(Math.sqrt(variance));
             
        }
 
    }
 
}


Measured memory_bytes: 31700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int H, W; cin >> H >> W;
    int count = 0;
    vector<string> field(H);
    for (int i = 0; i < H; ++i) {
        cin >> field[i];
    }

    for (int i = 0; i < H; ++i) {
        for (auto j = 0; j < W; ++j){
            if (field[i][j] == '#'){
                ++count;
            }
        }
    }

    if (count == H + W - 1){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		long ans=0;
		for(int i=0; ; i++){
			if(n-(r*i)<0){
				break;
			}
			for(int j=0; ; j++){
				if(n-(r*i+g*j)<0){
					break;
				}
				if(n-(r*i+g*j)>=0 && (n-(r*i+g*j))%b==0){
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int H, W, K;
string S[15];

int C[15][1050];

int sum[15][1050];

int check(vector<int> vec_H, vector<int> vec_W) {

	int M = vec_H.size(); 
	int N = vec_W.size();

	for (int i = 1; i < M; i++) {
		for (int j = 1; j < N; j++) {
			if (sum[vec_H[i]][vec_W[j]] - sum[vec_H[i - 1]][vec_W[j]] - sum[vec_H[i]][vec_W[j - 1]] + sum[vec_H[i - 1]][vec_W[j - 1]] > K) { return -1; }
		}
	}

	return 1;
}

int main(void) {

	cin >> H >> W >> K;

	for (int i = 1; i <= H; i++) {
		cin >> S[i];
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 0; j < W; j++) {
			C[i][j + 1] = S[i][j] - '0';
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + C[i][j];
		}
	}


	/*for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cout << sum[i][j];
		}cout << endl;
	}*/

	long long int ans = 999999999999;

	for (int k = 0; k < (1 << (H - 1)); k++) {
		//cout << k << endl;

		//k = (1 << (H - 1)) - 1;

		vector<int> vec_H;
		vec_H.push_back(0);
		int y = k;
		for (int i = 1; i <= H; i++) { if ((y >> (i - 1)) & 1) { vec_H.push_back(i); } }
		vec_H.push_back(H);
		int num = vec_H.size();
		
		//for (auto y : vec_H) { cout << y << endl; }

		vector<int> vec_W;
	     vec_W.push_back(0);
		int last = 0;
		for (int j = 1; j <= W; j++) {
			for (int u = 1; u < num; u++) {
				if (sum[vec_H[u]][j] - sum[vec_H[u - 1]][j] - sum[vec_H[u]][last] + sum[vec_H[u - 1]][last] > K) { vec_W.push_back(j-1); last = j-1;  break; }
			}
		}
		vec_W.push_back(W);

		//for (auto y : vec_W) { cout << y << endl; }

		if (check(vec_H, vec_W) == 1) { ans = min(ans, (long long int) vec_H.size() - 2 + (long long int)vec_W.size() - 2); }

	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main() {
  int s;
  cin >> s;
  vector<int> v;
  v.push_back( s );
  int i = 1;
  bool flag = 1;

  while( flag ) {
    int a;
    int latest = v.back();
    if( latest % 2 == 0 ) {
      a = latest / 2;
    }
    else {
      a = 3 * latest + 1;
    }
    for( int j = 0; j < v.size(); j++ ) {
      if( v[j] == a ) {
        cout << i + 1 << endl;
        flag = 0;
        break;
      }
    }
    v.push_back( a );
    i++;
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
mo = 1000000007
r = range
    
n = int(input())
    
primes = set()
for i in r(2, 1000):
    for p in primes:
        if i % p == 0:
            break
    else:
        primes.add(i)
    
d = {}
for i in r(2, n+1):
    x = i
    while x != 1:
        for p in primes:
            if x % p != 0:
                continue
            x //= p
            if p not in d:
                d[p] = 0
            d[p] += 1
            break
    
ret = 1
for i in d.values():
    ret *= (i+1)
    ret %= mo
    
print(ret)

Measured memory_bytes: 21308
read n3 a b
sum=0

if (( n3 == 10000 )); then
    n3=9999
    (( a <= 1 && 1 <= b )) && sum=10000
fi

for (( k3 = 0; k3 <= n3; k3 += 1000 )); do
    n2=$(( n3 - k3 < 999 ? n3 - k3 : 999 ))
    for (( k2 = 0; k2 <= n2; k2 += 100 )); do
        n1=$(( n2 - k2 < 99 ? n2 - k2 : 99 ))
        for (( k1 = 0; k1 <= n1; k1 += 10 )); do
            n0=$(( n1 - k1 < 9 ? n1 - k1 : 9 ))
            for (( k0 = 0; k0 <= n0; k0 += 1 )); do
                dsum=$(( k3 / 1000 + k2 / 100 + k1 / 10 + k0 ))
                (( dsum >= a && dsum <= b )) && sum=$(( sum + k3 + k2 + k1 + k0 ))
            done
        done
    done
done
echo ${sum}


Measured memory_bytes: 376
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int N;
	int A[30], B[30], C[30] = {0};	
	cin >> N;

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

	int ans = 0;
	int c;
	for (int i = 1; i <= N; i++) {
		ans += B[A[i]];
		if (A[i] == A[i - 1] + 1) {
			ans += C[A[i - 1]];
		}
	}

	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<pair<int, int>> segments;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	segments.resize(m);
	for (int i = 0; i < m; i++)
	{
		cin >> segments[i].first >> segments[i].second;
		segments[i].first *= 2;
		segments[i].second *= 2;
	}
	sort(segments.begin(), segments.end(), [](pair<int, int> pA, pair<int, int> pB)
	{
		if (pA.second != pB.second)
			return pA.second < pB.second;
		return pA.first < pB.first;
	});
	int cntPoints = 1;
	int point = segments[0].second - 1;
	for (int i = 1; i < m; i++)
	{
		if (point <= segments[i].first || point >= segments[i].second)
		{
			point = segments[i].second - 1;
			cntPoints++;
		}
	}
	cout << cntPoints << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> a(N+1);
  vector<int> ball(N+1,0);
  for(int i=1;i<=N;i++){
    cin >> a.at(i);
  }
  vector<int> result;
  for(int i=N;i>0;i--){
    int ballsum = 0;
    for(int j=1;j<=N/i;j++){
      ballsum += ball.at(j*i);
    }
    if((ballsum ^ a.at(i)) & 1){ //偶奇が一致しない
      ball.at(i) = 1;
      result.push_back(i);
    }
  }
  cout << result.size() << endl;
  for(int i : result){
    cout << i << " " ;
  }
  
  return 0;
}

Measured memory_bytes: 3064
import itertools
r = 110000
s = int(r*0.5)
p = [1] * r
p[0] = 0
for i in range(1,s):
	if p[i]:
		p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
		
while 1:
	N,P = map(int,raw_input().split())
	if N == -1: break
	i = N + 1
	prime = [0]*22
	j = 0
	while j < 22:
		if p[i-1] == 1:
			prime[j] = i
			j += 1
		i += 1
	wa = sorted([sum(comb) for comb in itertools.combinations(prime,2)] + [2*a for a in prime])
	print wa[P-1]

Measured memory_bytes: 9024
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/

int main() {
	vector<ll> x(5 + 1);
	rep(i, 5) {
		cin >> x[i];
	}
	rep(i, 5) {
		if (x[i] == 0) {
			cout << i+1 << endl;
			return 0;
		}
	}
}

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

using namespace std;

int N, Q, X;
string Opstr;
set<int> LeaderInfo;
map<int, int> CountOfTheSameScoreLeader;
int Score[1000001], Temp[1000001];
int TotalTime[100001];


bool judge(int r) {
	int rest;
	int *pMin = NULL;
	int *pMax = Temp + 1;
	set<int>::iterator it;

	rest = N;
	for (it = LeaderInfo.begin(); it != LeaderInfo.end(); ++it) {
		pMin = lower_bound(pMax, Temp + N + 1, *it - r);
		pMax = upper_bound(pMax, Temp + N + 1, *it);
		rest -= (pMax - pMin);
	}

	if (rest > X) {
		return false;
	}
	return true;
}

int solve() {
	int left, right, mid;

	left = 0;
	right = 1e9;
	if (!judge(right)) {
		return -1;
	}

	while (left < right) {
		mid = (left + right) / 2;
		if (judge(mid)) {
			right = mid;
		} else {
			left = mid + 1;
		}
	}

	return left;
}

int main() {
	int ans;

	memset(Score, 0, sizeof(Score));
	//memset(TotalScoreOfTeam, 0, sizeof(TotalScoreOfTeam));
	cin >> N >> Q;
	for (int i = 0; i < N; ++i) {
		cin >> Score[i + 1];
		Temp[i + 1] = Score[i + 1];
	}
	sort(Temp + 1, Temp + N + 1);
	for (int i = 0; i < Q; ++i) {
		cin >> Opstr >> X;
		if (Opstr == "ADD") {
			if (CountOfTheSameScoreLeader[Score[X]] == 0) {
				LeaderInfo.insert(Score[X]);
			}
			++CountOfTheSameScoreLeader[Score[X]];
		}
		else if (Opstr == "REMOVE") {
			--CountOfTheSameScoreLeader[Score[X]];
			if (CountOfTheSameScoreLeader[Score[X]] == 0) {
				LeaderInfo.erase(Score[X]);
			}
		}
		else { // check
			ans = solve();
			if (ans == -1) {
				cout << "NA" << endl;
				continue;
			}
			cout << ans << endl;
		}
	}

	return 0;
}



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

int main(void){

  int d,t;
  double x,y;
  double seta;

  seta = 90;
  x = 0.0;
  y = 0.0;
  while(1){
    scanf("%d,%d",&d,&t);
    if(!d && !t)break;

    x += cos(seta*M_PI/180) * d;
    y += sin(seta*M_PI/180) * d;
    seta -= t;

  }

  printf("%d\n%d\n",(int)x,(int)y);

  return 0;
}

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

#define ll long long 
#define pb push_back
#define pu push
#define in insert
#define f(s,e) for(i=s;i<e;i++)
#define loop(i) while(i--)
#define bg(v) v.begin()
#define ed(v) v.end()
#define sz(v) v.size()
#define len(v) v.length()

int main(){
    ll t,op,i,j,k,n,m,h;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    i=1;
    while(1)
    {
        if(i%2==1)
        {
            c-=b;
            if(c<=0){
                cout<<"Yes";return 0;
            }
        }
        else
        {
            a-=d;
            if(a<=0)
            {
                cout<<"No";
                return 0;
            }
        }
        i++;
    }
	return 0; 
} 

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

using namespace std;
using ll = long long;

ll solve(vector<vector<ll>> &pts, vector<vector<vector<ll>>> &memo, int r = 0,
         int c = 0, int cnt = 0) {
  if (r >= pts.size() || c >= pts.front().size()) {
    return 0;
  }

  if (memo[r][c][cnt] < 0) {
    ll v = pts[r][c];
    if (cnt >= 3) {
      memo[r][c][cnt] =
          max({solve(pts, memo, r + 1, c, 0), solve(pts, memo, r, c + 1, cnt)});
    } else {
      memo[r][c][cnt] =
          max({// 下に移動する
               v + solve(pts, memo, r + 1, c, 0), solve(pts, memo, r + 1, c, 0),
               // 右に移動する
               v + solve(pts, memo, r, c + 1, cnt + (v > 0)),
               solve(pts, memo, r, c + 1, cnt)});
    }
  }

  return memo[r][c][cnt];
}

int main(int argc, const char *argv[]) {
  int r, c, k;
  cin >> r >> c >> k;
  vector<vector<ll>> pts(r, vector<ll>(c, 0));
  for (int i = 0; i < k; ++i) {
    int r, c;
    ll v;
    cin >> r >> c >> v;
    r--;
    c--;
    pts[r][c] = v;
  }

  vector<vector<vector<ll>>> memo(r + 1, vector(c + 1, vector(4, -1ll)));
  cout << solve(pts, memo) << '\n';
  return 0;
}

Measured memory_bytes: 708108
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var s1 = cin.next();
            var s2 = cin.next();
            var s3 = cin.next();
            var ans = s1[0].ToString() + s2[0].ToString() + s3[0].ToString();
            Console.WriteLine(ans.ToUpper());
        }
    }

    class BIT
    {
        long[] bit;
        long n;

        public BIT(int n)
        {
            bit = new long[n];
        }
        // a_i += w
        public void add(long i, long w)
        {
            for (long x = i; x <= n; x += x & -x)
            {
                bit[x] += w;
            }
        }
        
        public long sum(long i)
        {
            long ret = 0;
            for (long x = i; x > 0; x -= x & -x)
            {
                ret += bit[x];
            }
            return ret;
        }
        
        public long sum(long left, long right)
        {
            return sum(right) - sum(left);
        }
    };

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    
}


Measured memory_bytes: 11092
#include<iostream>
#include<bitset>
using namespace std;
int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	bitset<4000005> bs(1);
	cin>>n;
	for(i=0,b=0;i<n;i++){
		cin>>a;
		b+=a;
		bs|=(bs<<a);
	}
	for(i=(b+1)/2;i<b;i++){
		if(bs[i]==1){a=i;break;}
	}
	cout<<a<<endl;
	return 0;
}
	


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


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String hitoketa = n.substring(n.length() - 1, n.length());
		String[] hon = {"2","4","5","7","9"};
		String[] pon = {"0","1","6","8"};
		String[] bon = {"3"};
		
		if(Arrays.asList(hon).contains(hitoketa) ) {
			System.out.println("hon");
		}else if(Arrays.asList(pon).contains(hitoketa)) {
			System.out.println("pon");
		}else if(Arrays.asList(bon).contains(hitoketa)) {
			System.out.println("bon");
		}

		sc.close();
	}

}

Measured memory_bytes: 35780
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	s := readString()
	if strings.Contains(s, "7") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1756
#include<iostream>

using namespace std;

int main(){
  int x[5];
  int mi=10;
  int ans=0;
  for(int i=0;i<5;i++){
    cin>>x[i];
    if(x[i]%10!=0)mi=min(mi,x[i]%10);
  }
  for(int i=0;i<5;i++){
    if(x[i]%10==0)ans+=x[i];
    else ans+=(x[i]/10)*10+10;
  }
  ans=ans-10+mi;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    int cnt = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();
		int C=sc.nextInt();

		int count=0;
		int[] A=new int[M];
		int[] B=new int[M];

		for(int i=0;i<M;i++) {
			B[i]=sc.nextInt();
		}

		for(int i=0;i<N;i++) {
			for(int j=0;j<M;j++) {
				A[j]=sc.nextInt();
			}

			int sum=0;
			for(int k=0;k<M;k++) {
				sum+=A[k]*B[k];
			}
			sum+=C;

			if(sum>0) count++;


		}

		System.out.println(count);

		sc.close();

	}

}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0)cout<<'1';
  else if(x2==0)cout<<'2';
  else if(x3==0)cout<<'3';
  else if(x4==0)cout<<'4';
  else if(x5==0)cout<<'5';



}


Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm> 
int n,k;
long long ans=0;
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=k+1;i<=n;i++)
	{
		int x=n/i,r=n%i;
		ans=ans+1ll*x*(i-k)+std::max(0,r-k+1);
		if (k==0) --ans;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1732
#  --*-coding:utf-8-*--

def main():
    M, D = map(int, input().split())

    x = sum(max(1, min(9, M//a))-1 for a in range(2, D//10))

    if D >= 10:
        x += max(1, min(min(9, D%10), M//(D//10) )) - 1
        
    
    print(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  if (a + b >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define loops(i, s, n) for (int i = s; i < n; i++)
#define loop(i, n) for (int i = 0; i < n; i++)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define init(arr, n , val)  for(int i =0;i<n;i++)  arr[i] = val;
#define even_set 0xAAAAAAAA ...1010101010
#define odd_set 0x55555555  ...01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define nl endl
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
#define init(arr, n , val)  for(int i =0;i<n;i++)  arr[i] = val;
const int mod = 1000000007;
ll dp[100001];

void dfs(vector<int> adj[], int u ,int vis[]){
    vis[u] = 1;
    
    for(auto v : adj[u]){
        if(!vis[v]){
            dfs(adj, v, vis);
        }
        dp[u] = max(dp[u] , dp[v]  +  1);
    }
}

ll longPath(vector<int> adj[], int v){
    int vis[v];
    init(vis ,v, 0);

    int ans = 0;
    for(int i = 0; i < v; i++){
        if( !vis[i])
          dfs(adj ,i, vis);
    }

    ret *max_element(dp ,dp+v);
}

int main()
{

    fastio;

    int v, e;
    cin>>v>>e;
    vector<int> adj[v];

    for(int i =0;i<e;i++){
        int u, v;
        cin>>u>>v;
        u--;
        v--;
        adj[u].push_back(v);
    }

    cout<<longPath(adj, v);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll a[n][n-1];
  rep(i,n)rep(j,n-1) R a[i][j];
  queue<int> que[n];
  rep(i,n) {
    rep(j,n-1) que[i].push(a[i][j]-1);
  }
  queue<int> q;
  rep(i,n) q.push(i);
  for(int ans=1,cnt=0;;ans++) {
    int u[n],f=0;
    mem(u);
    vector<int> v;
    while(!q.empty()) {
      int i=q.front();q.pop();
      if(u[i]||que[i].empty()) continue;
      int x=que[i].front();
      if(u[x]||que[x].empty()) {
        v.pb(i);
        continue;
      }
      if(que[x].front()==i) {
        que[i].pop();
        que[x].pop();
        u[i]=u[x]=1;
        f=1;
        if(que[i].empty()) cnt++;
        else v.pb(i);
        if(que[x].empty()) cnt++;
        else v.pb(x);
      }
    }
    if(!f) {
      pr(-1);
      return;
    }
    if(cnt==n) {
      pr(ans);
      return;
    }
    rep(i,v.size()) q.push(v[i]);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 998244353
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,sum[100005],ans=1LL,res;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
		int x;
		cin>>x;
		sum[x]++;
		if(i==0&&x!=0)ans=0;
	}
	if(sum[0]!=1)ans=0;
	res=n-1;
	for(ll i=1;i<n;i++){
		if(sum[i]==0)break;
		res-=sum[i];
		for(int j=0;j<sum[i];j++)ans=ans*sum[i-1]%M;
	}
	if(res!=0)ans=0;
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int main() {
	ll N, A, B; cin >> N >> A >> B;
	if (abs(A - B) % 2 == 0) {
		cout << abs(A - B) / 2 << endl;
	}
	else {
		ll l = min(A, B);
		ll r = max(A, B);
		ll A = l + (r - l - 1) / 2;
		ll B = N - r + 1 + (r - l - 1) / 2;
		cout << min(A, B) << endl;
	}
	return 0;
}

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

int main() {
  int H,W;
  cin>>H>>W;
  int C[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>C[i][j];
    }
  }

  for(int j=0;j<10;j++){
    for(int k=0;k<10;k++){
      for(int i=0;i<10;i++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   
  for(int j=0;j<10;j++){
    for(int k=0;k<10;k++){
      for(int i=0;i<10;i++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   
  for(int j=0;j<10;j++){
    for(int k=0;k<10;k++){
      for(int i=0;i<10;i++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   
  int temp;
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>temp;
      if(temp != -1) ans+=C[temp][1];
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  while(cin>>n>>x&&(n||x)){
    int cnt=0;
    for(int i=1;i<=n-2;++i)
      for(int j=i+1;j<=n-1;++j)
	for(int k=j+1;k<=n;++k)
	  if(i+j+k==x) ++cnt;
    cout<<cnt<<endl;
  }
  return 0;
}



Measured memory_bytes: 3072
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
constexpr long long int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>K>>L>>R>>N;
	for(int i=0;i<N;i++){
		string s;
		cin>>s;
		if(s=="nobiro"){
			K+=L;
			K=max(K,0LL);
		}
		else if(s=="tidime"){
			K+=R;
			K=max(0LL,K);
		}
		else{
			K=0;
		}
	}
	cout<<K<<endl;
	return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n , m ;
  cin >> n >> m;
  int all = 0;
  vector<int> v(n) ;
  
  rep(i,n) { 
    cin >> v.at(i) ;
    all += v.at(i) ;
  }
  
  int ans = 0;
  rep(i,n){
    if( v.at(i) * 4 * m  >= all ) ans ++ ;
  }
  
  if( ans >= m ) cout << "Yes";
  else          cout << "No";
    

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int x, a, b;
    int ans, distance;

    scanf("%d %d %d", &x, &a, &b);
    
    if (x - a > 0){
        ans = x - a;
    }else{
        ans = -1 * (x - a);
    }

    if (x - b > 0){
        distance = x - b;
    }else{
        distance = -1 * (x - b);
    }

    if (ans > distance){
        printf("B");
    }else{
        printf("A");
    }

    return 0;



}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
using namespace std;
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 105;
const int lim = 1e5 + 5;
const int INF = 1e9 + 19;
int n, W;
int w[maxn], v[maxn];

int dp[maxn][lim];

void ReadInput()
{
    cin >> n >> W;
    for(int i = 1; i <= n; ++i)
        cin >> w[i] >> v[i];
}

void Solve()
{
    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), INF);
    dp[0][0] = 0;
    int ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j < lim; ++j)
            dp[i][j] = dp[i - 1][j];
        for(int j = 0; j < lim - v[i]; ++j)
        {
            dp[i][j + v[i]] = min(dp[i][j + v[i]], dp[i - 1][j] + w[i]);
            if(dp[i][j + v[i]] > INF) dp[i][j + v[i]] = INF;
        }
    }
    for(int j = 0; j < lim; ++j)
        if(dp[n][j] <= W) ans = max(ans, j);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  map<ll,ll> m;
  rep(i,n){
    ll a; cin>>a;
    m[a]++;
  }
  
  ll ans=0;
  for(auto e: m){
    if(e.second>1){
      // cout<<e.first<<" "<<e.second<<endl;
      ans+=e.second-1;
    }
  }
  if(ans%2) ans++;
  cout<<n-(ans)<<endl;
}

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

using namespace std;
using i32 = std::int_fast32_t;
using u64 = std::uint_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string A;
  cin >> A;
  u64 N = static_cast<u64>(A.size());
  vector<u64> cnt(26);
  for (u64 i = 0; i < N; i++) {
    cnt[A[i] - 'a']++;
  }
  u64 res = N * (N - 1) / 2;
  for (i32 i = 0; i < 26; i++) {
    if (cnt[i] > 1) {
      res -= cnt[i] * (cnt[i] - 1) / 2;
    }
  }
  cout << res + 1 << '\n';
  return 0;
}


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

using namespace std;

void abc_150a();

int main()
{
  abc_150a();

}

void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 3620
/*ex4_1
ryo_1129*/
#include<stdio.h>

int main(void){
    int d,n,view,people;//変数宣言
    scanf("%d %d",&n,&d);//入力
    view = 2*d+1;//一人が見れる木の数
    //見る木に被りがない場合、
    if(n%view==0){
        people = n/view;
    //見る木に被りがある場合一人以外被りがないようにして１を足すのが最小人数
    }else{
        people = n/view+1;
    }
    //出力
    printf("%d\n",people);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://agc006.contest.atcoder.jp/tasks/agc006_b>
 問題文============================================================
 N 段のピラミッドがあります。 段は上から順に 1, 2, …, N と番号が振られています。
 各 1≤i≤N について、i 段目には 2i−1 個のブロックが横一列に並んでいます。
 また、各段の中央のブロックに注目すると、これらは縦一列に並んでいます。
 
 すぬけ君は N 段目のブロックに (1, 2, …, 2N−1) を並べ替えたもの（順列）を書き込みました。
 さらに、次のルールに従い、残りすべてのブロックに整数を書き込みました。
 
 あるブロックに書き込まれる整数は、そのブロックの左下、真下、右下のブロックに書き込まれた整数の中央値である。
 
 その後、すぬけ君はすべてのブロックに書き込まれた整数を消してしまいました。
 すぬけ君は、1 段目のブロックに書き込まれた整数が x であったことだけを覚えています。
 
 N 段目のブロックに書き込まれた順列としてあり得るものが存在するか判定し、存在するならばひとつ求めてください。
 =================================================================
 
 解説=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int a[200010] = {0};
    int n,x; cin >> n >> x;
    if(x == 1 || x == 2*n - 1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    if(n == 2){
        cout << 1 << endl;
        cout << 2 << endl;
        cout << 3 << endl;
        return 0;
    }
    if(x == 2){
        a[n] = 2; a[n-1] = 1; a[n-2] = 3; a[n+1] = 4;
        int cnt = 5;
        for(int i = 0; i < n*2 - 1;i++){
            if(a[i] == 0) a[i] = cnt++;
        }
    }else{
        a[n] = x; a[n-1] = x+1; a[n-2] = x-1; a[n+1] = x-2;
        int used[200010] = {false};
        for(int i = x-2; i <= x+1;i++) used[i] = true;
        int cnt = 1;
        for(int i = 0; i < 2*n-1;i++){
            if(a[i] == 0){
                while(used[cnt]) cnt++;
                a[i] = cnt; used[cnt] = true;
            }
        }
    }
    for(int i = 0; i < 2*n - 1;i++){
        cout << a[i] << endl;
    }
    return 0;
}


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

int main(){
  int n; cin>>n;
  string s; cin>>s;
  string base="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<s.size();i++){
    int x=s[i]-'A';
    x+=n;
    cout<<base[x];
  }
  cout<<endl;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

#define get_bit(x, y) ((x >> y) & 1)

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m + 1);
  vector<int> p(m + 1);
  for (int i = 1; i <= m; i++) {
    int k; cin >> k;
    for (int j = 1; j <= k; j++) {
      int t; cin >> t;
      a[i].push_back(t);
    }
  }
  for (int i = 1; i <= m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    int b = 0;
    for (int j = 1; j <= m; j++) {
      int cnt = 0;
      for (auto &k : a[j]) {
        if (get_bit(i, k - 1)) cnt++;
      }
      if (cnt % 2 != p[j]) {
        b = 1;
        break;
      }
    }
    if (b == 0) ans++;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3652