akhauriyash/Code-Regression huggingface dataset:
n=int(input())
s=list(input())
f=0
b=-1
for d in range(1,n):
  c=0
  for i in range(n-d):
    if s[i]==s[i+d] and c<d:
      if b==-1:b=i
      c+=1
      f=max(f,c)
    else:
      c=0
      b=-1
print(f)

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

using namespace std;

void solve(){
	string s;
	int n,res=0;
	cin >> s;
	n=s.length();
	for(int i=0;i<n;i++)
		res+=s[i]-'0';
	if(res % 9)
		cout<<"No"<<"\n";
	else 
		cout<<"Yes"<<"\n";
}
int main(){
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 3764
#139_C
n = int(input())
h = list(map(int, input().split()))
h_ = [0 for _ in range(n)]
for i in range(1, n):
    if h[i-1] >= h[i]:
        h_[i] = h_[i-1] + 1
    else:
        h_[i] = 0
print(max(h_))

Measured memory_bytes: 14228
n = int(input())
a = [0]*n
s = int(n**(1/2))+1
for i in range(1, s):
    for j in range(1, s):
        for k in range(1, s):
            b = i*i+j*j+k*k+i*j+j*k+k*i-1
            if b < n:
                a[b] += 1
for i in range(n):
    print(a[i])

Measured memory_bytes: 9464
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(vi s(3);cin>>s[0]>>s[1]>>s[2],s[0]|s[1]|s[2];){
		sort(allof(s));
		int n;
		cin>>n;
		rep(i,n){
			int r;
			cin>>r;
			cout<<(4*r*r>s[0]*s[0]+s[1]*s[1]?"OK":"NA")<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
h, w, K = map(int, input().split())
mapi = []
for i in range(h):
    mapi.append(list(map(int,list(input()))))

def judge(num):
    for i in range(2**(h-1)+1):
        jc = 0
        gr = []
        tmp = []
        for j in range(h-1):
            tmp.append(j)
            if (i >> j)&1 == 1:
                gr.append(tmp)
                tmp = []
                jc+=1
        tmp.append(h-1)
        gr.append(tmp)
        if jc > num:
            continue
        xc = 0
        tmpc = [0] * (jc+1)
        brf = False
        for j in range(w):
            di = [0]* (jc+1)
            for k in range(jc+1):
                for l in gr[k]:
                    di[k]+=mapi[l][j]
                    if di[k] > K:
                        brf = True
                        break
                if tmpc[k] + di[k] > K:
                    for m in range(jc+1):
                        tmpc[m] = 0
                    xc+=1
                    if xc + jc > num:
                        brf = True
                        break
                if brf:
                    break
            if brf:
                break
            for l in range(jc+1):
                tmpc[l] += di[l]
        if brf:
            continue
        return True
    return False

mmin = 0
mmax = (h-1)*(w-1)
if judge(mmin) == True:
    print(0)
    exit()
while True:
    mid = (mmin + mmax)//2
    if judge(mid) == True:
        mmax = mid
    else:
        mmin = mid
    if mmin +1 == mmax:
        print(mmax)
        exit()





Measured memory_bytes: 54896
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll MOD = 998244353 ;
const int N = 15;
const int M = 1005;
//EAZY..PIZZIIEE

char a[N][M];
int cur[N], temp[N];

void solve(){
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            cin >> a[i][j];
    
    int ans = 1e9;

    for(int mask = 0; mask < (1 << (n -1 )); mask++ ){
        int cuts = __builtin_popcount(mask);
        memset(cur, 0, sizeof(cur));
        int flag = 1;
        //We are traversing each column
        for(int j = 0; j < m and flag; ++j){
            int idx = 0;
            memset(temp, 0, sizeof(temp) );
            for(int i = 0; i < n; ++i){
                //Temp[idx] -> denotes sum in a particular row
                temp[idx] += (a[i][j] - '0');
                //if current bit is set, then change its row of partition
                //set
                if( mask >> i & 1) 
                    idx++;
            }
            //Now if sum of any partition in only single column
            //is more than k, then 
            //this particular partition is not feasible
            for(int j = 0; j < n; ++j){
                if( temp[j] > k){
                    flag = 0; 
                    break;
                }
            }
            //if sum till current column and single column is
            //is more than k, then we need to do partition
            //at current column 
            bool mark = 0;
            for(int j = 0; j < n; ++j){
                if( cur[j] + temp[j] > k )
                    mark = 1;
            }
            //If mark-> i.e partitioned then increase the count of cuts
            cuts += mark;
            if( mark ){
                for(int j = 0; j < n; ++j) //If partitioned then start new partition count of column
                    cur[j] = temp[j];
            } else {
                for(int j = 0; j < n; ++j) //Else add it to current partition of column
                    cur[j] += temp[j];
            }
        }
        if( flag )
            ans = min(ans, cuts);
    }

    cout << ans << '\n';
    return;
}

int main(){
    //int t; cin >> t;
    //while(t--)
        solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,h[100001],ans[100001],ansn;
int main()
{
	scanf("%d%d",&n,&m);
	ansn=n;
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	for(int i=1;i<=m;i++)
	{
		int s,t;
		scanf("%d%d",&s,&t);
		if(h[s]>=h[t])if(ans[t]==0)--ansn,ans[t]=1;
		if(h[s]<=h[t])if(ans[s]==0)--ansn,ans[s]=1;
	}
	printf("%d",ansn);
	return 0;
}

Measured memory_bytes: 4596
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    Map<Integer, List<Integer>> map = new HashMap<>();
    for (int i = 0; i < k; i++) {
      int d = Integer.parseInt(sc.next());
      for (int j = 0; j < d; j++) {
        int s = Integer.parseInt(sc.next());
        map.computeIfAbsent(s, key -> new ArrayList<>()).add(j);
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!map.containsKey(i)) {
        ans++;
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 41716
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def countSetBits(n): 
    count = 0
    while (n): 
        count += n & 1
        n >>= 1
    return count 

def main():
    N = I()
    mat = [[-1 for __ in range(N)] for _ in range(N)]
    for i, _ in enumerate(range(N)):
        A = I()
        for __ in range(A):
            targ, b = LI()
            mat[i][targ - 1] = b
    ans = 0
    for bit in range(1 << N):
        err = False
        for j in range(N):
            honest_man = (bit & (1<<j))
            if honest_man:
                for k in range(N):
                    r = mat[j][k]
                    if r == -1:
                        continue
                    if (bit >> k) & 1 != r:
                        err = True
        if not err:
            ans = max(ans, countSetBits(bit))
    print(ans)

    '''
    for bit in range(1 << N):
        truth = [-1 for _ in range(N)]
        err = False
        for i in range(N):
            honest_man = (bit & (1<<(N-1-i)))
            if honest_man:
                for j in range(len(mat[i])):
                    con = mat[i][j]
                    targ_ix = j
                    if con != -1:
                        if truth[targ_ix] != con:
                            if truth[targ_ix] != -1:
                                err = True 
                        if (bit & (1<<(N-1-targ_ix))) != con:
                            print('i: {0:{fill}3b}'.format(i, fill='0'))
                            print('bit: {0:{fill}3b}'.format(bit, fill='0'))
                            print("1<<(N-1-targ_ix): {0:{fill}3b}".format(bit & (1<<(N-1-targ_ix)), fill='0'))
                            print("con: ", con)
                            err = True
                        truth[targ_ix] = con
        if not err:
            ans = max(ans, countSetBits(bit))
    '''
main()



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

int main()
{

    ll n,i,j,k,l,a,b,c,d,m,f1,f2;
    string s1,s2;
    cin>>s1;
    cin.ignore();
    cin>>s2;
    for(i=0;i<s2.size();i++)
    {
        s1.push_back(s2[i]);
    }
    stringstream ss;
    ss<<s1;
    ss>>k;
    l=sqrt(k);
    if(l*l==k)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-3;
const int MAXN = 1e5 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;



int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    char s[5];
    scanf("%s",s);
    int sum[3];
    mst(sum,0);
    for(int i=0; i<3; i++) sum[s[i]-'a']++;
    for(int i=0; i<3; i++)
        if(sum[i] != 1) {
            puts("No");
            return 0;
        }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;


int N,Q;
vector<vi> to(200001);
vi px(200001,0),add(200001,0),visited(200001,0);

void dfs(int root){
    visited[root] = 1;
    add[root] += px[root];
    for(auto leaf:to[root]){
        if(visited[leaf]) continue;
        add[leaf] += add[root];
        dfs(leaf);
    }
}

void solve() {
    cin >> N >> Q;
    int a,b;
    rep(i,N-1){
        cin >> a >> b;
        a--;b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    int p,x;
    rep(i,Q){
        cin >> p >> x;
        p--;
        px[p] += x;
    }

    dfs(0);
    rep(i,N){
        if(i!=0) cout << ' ';
        cout << add[i];
    }
    print("");

}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

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

int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    if(a == 0)
        cout << '1' << endl;
    if(b == 0)
        cout << '2' << endl;
    if(c == 0)
        cout << '3' << endl;
    if(d == 0)
        cout << '4' << endl;
    if(e == 0)
        cout << '5' << endl;

    return 0;
} 

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

int main() {
	long long N;
	vector<long long> X, To;
	vector<bool> B;
	vector<vector<long long> > V;
	cin >> N;
	X.assign(N, 0);
	To.assign(N, 0);
	B.assign(N, false);
	V.resize(N);
	for (int i = 0; i < N - 1; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		X[A]++, X[B]++;
		To[A] += B, To[B] += A;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	queue<long long> Q;
	for (int i = 0; i < N; i++) {
		if (X[i] == 1) {
			if (B[i] || B[To[i]]) continue;
			B[i] = B[To[i]] = true;
			Q.push(i);
		}
	}
	while (!Q.empty()) {
		long long P = Q.front();
		Q.pop();
		long long NP = To[P];
		B[P] = B[NP] = true;
		for (long long NNP : V[NP]) {
			if (B[NNP]) continue;
			X[NNP]--;
			To[NNP] -= NP;
			if (X[NNP] == 1 && !B[NNP]) {
				Q.push(NNP);
			}
			if (X[NNP] == 0) {
				cout << "First" << endl;
				return 0;
			}
		}
	}
	cout << "Second" << endl;
}

Measured memory_bytes: 8192
#include<stdio.h>
int main()
{
	double f=0;
	int a,b,i,c=0,x[1000];
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d",&x[i]);
		f=f+x[i];
	}
	for(i=0;i<a;i++){
		if(x[i]>=f/4/b){
			c++;
		}
	}
	if(c>=b){
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1652
#include <stdio.h>
#include <string.h>
#define M 1500000
#define NIL -1
#define L 20

char A[M][L];

int getChar(char c){
  if(c=='A')return 1;
  else if(c=='C')return 2;
  else if(c=='G')return 3;
  else if(c=='T')return 4;
  else return 0;
}

int getKey(char str[]){
  int i,total=0,p=1;
  for(i=0;i<strlen(str);i++){
    total+=p*(getChar(str[i]));
    p*=5;
}
  return total;

}

int h1(int key){
return key%M;
}
int h2(int key){
return 1+(key%(M-1));
}

int find(char str[]){

  int key,h,i;
  key=getKey(str);
  i=0;
  while(1){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(A[h],str)==0)return 1;
    else if(strlen(A[h])==0)return 0;
    i++;
  }
  return 0;

}

int insert(char str[]){


  int key,i,h;
  key=getKey(str);
  i=0;
  while(1){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(A[h],str)==0)return 1;
    else if(strlen(A[h])==0){
      strcpy(A[h],str);
      return 0;

    }
    i++;
  }
  return 0;

}


int main(){
  int i,h,n;
  char str[L],com[9];
  for(i=0;i<M;i++)A[i][0]='\0';
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0]=='i'){
      insert(str);
    }else{
      if(find(str)){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }

  }

  return 0;
}



Measured memory_bytes: 31076
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,M;
	cin >> N >> M;
	int sum = 0;
	for(int i = N - 1;i >= 1;i--)
		sum += i;
	for(int i = M - 1;i >= 1;i--)
		sum += i;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())

v = [0] * N
w = [0] * N
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    v[i], w[i] = map(int, input().split())

for i in range(N - 1, -1, -1):
    for j in range(W + 1):
        if j < w[i]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

print(dp[0][W])

Measured memory_bytes: 26632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,p=1;
	cin>>n;
	string s;
	map<string,int> mp;
	for(i=0;i<n;i++)
	{
		cin>>s;
		mp[s]++;
	}
	int max=0;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		if(max<it->second)
		max=it->second;
	}
	//cout<<max;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		if(max==it->second)
		cout<<it->first<<endl;
	}
	return 0;
	
}

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

#pragma region typedef 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#pragma endregion

#pragma region define
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#pragma endregion

#pragma region const
const ld PI = 3.141592653589793;
#pragma endregion

#pragma region function
template<class T>bool chmax(T &a, const T &b){
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){
  if (b<a) { a=b; return 1; } return 0; }
int sort_3int(int a, int b, int c){
  if (a>b) { swap(a,b); }
  if (a>c) { swap(a,c); }
  if (b>c) { swap(b,c); } return true;}
#pragma endregion

int main(){
  int n, x, t;
  cin >> n >> x >> t;

  cout << (n + x-1) / x * t << endl;
return 0;
}

Measured memory_bytes: 3584
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	getLine
	s <- getLine
	k <- pred <$> readInt
	putStrLn $ replace ( s !! k ) '*' s

replace _ _ [] = []
replace a b (c:s)
	| a == c = c : replace a b s
	| otherwise = b : replace a b s

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int a, b, c, k;
int main() {
	cin>>a>>b>>c>>k;
	int ans = 0;
	ans += min(k, a);
	k = max(0, k - a);
	k = max(0, k - b);
	ans -= min(k, c);
	cout<<ans<<endl;
	return 0;
}

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


int main()
{
    double R, G;
    cin >> R >> G;
    double d = G - R;
    double ans = R + d * 2;
    cout << ans << endl;
    return 0;
}


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

t_org = 0
x_org = 0
y_org = 0
i = 0

for row in range(N):
    INPUT = input()
    t = int(INPUT.split( )[0])
    x = int(INPUT.split( )[1])
    y = int(INPUT.split( )[2])
    
    if t - t_org >= (x - x_org) + (y - y_org) and (t - t_org - (x - x_org) - (y - y_org)) % 2 == 0:
        t_org = t
        x_org = x
        y_org = y
        i += 1
    else:
        break

if i == N:
    print("Yes")
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
const int mod = 1000000007;

int main(){
    int n,m; cin >> n >> m;
    int k[10], s[10][10], p[10];
    rep(i,m){
      cin >> k[i];
      rep(j,k[i]) cin >> s[i][j], s[i][j]--;
    }
    rep(i,m) cin >> p[i];
    
    int ans=0;
    rep(bit,1<<n){
      int light=0;
      rep(i,m){
        int sw_on=0;
        rep(j,k[i]) if(1<<s[i][j] & bit) sw_on++;
        if(sw_on%2 == p[i]) light++;
      }
      if(light==m) ans++;
    }       
    cout << ans;
    

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0;
	int num = 1;
	while(num < b){
		num = num - 1 + a;
		ans++;
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
typedef long long ll;

int main() {
    long long N, K, MOD = 1000000007;
    cin >> N >> K;
    long long ANS = 0;
    for (long long k = K; k <= N + 1; k++) {
        long long int MIN = ( k - 1) * k / 2;
        long long int MAX = ( N + ( N - k + 1 ) ) * k / 2;
        ANS += MAX - MIN + 1;
        ANS %= MOD;
    }
    cout << ANS << endl;
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<string> s(n);
  vector<int> t(n);
  for (int i = 0; i < n; i++) cin >> s.at(i) >> t.at(i);
  
  string x;
  cin >> x;
  
  int ans = 0;
  bool sleep = false;
  for (int i = 0; i < n; i++) {
    if (sleep) ans += t.at(i);
    if (s.at(i) == x) sleep = true;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll N, M, X, Y;
    cin >> N >> M >> X >> Y;

    bool ok = true;
    ll mx_x = X;
    for (ll i = 0; i < N; i++)
    {
        ll xi;
        cin >> xi;
        mx_x = max(mx_x, xi);
    }

    ll mx_y = Y;
    for (ll i = 0; i < M; i++)
    {
        ll yi;
        cin >> yi;
        mx_y = min(mx_y, yi);
    }

    cout << (mx_x < mx_y ? "No War" : "War") << endl;    
}

Measured memory_bytes: 256
N, K, M = map(int, input().split())
# limitの最大値（limitなし）
L = (N+1)//2+1

def even(n, k) :
    # dp[iまでみた][前のj個が連続]
    dp = [[0] * (k+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n) :
        for j in range(k + 1) :
            dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % M
            # 直前にK個連続しているときは追加できない
            if j != k :
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % M
    
    return sum(dp[n]) % M

def loop(x, y) :
    return (2*x >= K+1 and 2*y >= K+3)
  
if K % 2 == 0 :
    print(even(N//2, K//2) * even((N+1)//2, K//2) % M)
    
else :
    # dp[x][y][z]
    # iとパリティが異なる列がx個連続、iとパリティが同じ列がy個連続でかつxとyのどちらかをzまで伸ばせる組み合わせ
    dp0 = [[[0]*(L+1) for _ in range(L+1)] for _ in range(L+1)]
    dp0[0][0][L] = 1
    
    for i in range(N) :
        dp1 = [[[0]*(L+1) for _ in range(L+1)] for _ in range(L+1)]
        for x in range(L+1) :
            for y in range(L+1) :
                if loop(x, y) : continue
                for z in range(max(x, y)+1, L+1) :
                    if dp0[x][y][z] == 0 :
                        continue
                    dp1[y][x+1][z] += dp0[x][y][z]
                    dp1[y][x+1][z] %= M
                    # zの更新
                    # (1) y > x のときはzを引き継ぎ y <= x のときはLにリセット
                    # (2) ↖ みたいな矢印が引ける時 つまり 2*y >= K+3 and x > 0の時 
                    # y - x + K//2 + 1 と (1)との最小値に更新
                    if y > x :
                        zz = z
                    else :
                        zz = L
                    if 2*y >= K+3 and x > 0 :
                        zz = min(zz, 1+y-x+K//2)
                    dp1[y][0][zz] += dp0[x][y][z]
                    dp1[y][0][zz] %= M
        dp0 = dp1
    
    ret = 0
    for x in range(L+1) :
        for y in range(L+1) :
            if loop(x, y) : continue
            for z in range(max(x, y)+1, L+1) :
                ret += dp0[x][y][z]
                ret %= M
                    
    print(ret)

Measured memory_bytes: 163468
n = int(input())
robot = [0]*n
for i in range(n):
  a, b = map(int, input().split())
  robot[i] = [a+b, a-b]

robot.sort()
ans = 0
for i in range(n):
  if i == 0:
    key = robot[0][0]
    ans += 1
    continue
  if robot[i][1] < key:
    continue
  key = robot[i][0]
  ans += 1
print(ans)

Measured memory_bytes: 21976
#include<iostream>
using namespace std;
int main(){
	int m,f,r,sum;
	for(;;){
		cin>>m>>f>>r;
		if(m==-1 && f==-1 && r==-1)break;
		sum=m+f;
		if(m==-1 || f==-1){
			cout<<"F"<<endl;
		}else if(sum>=80){
			cout<<"A"<<endl;
		}else if(sum>=65){
			cout<<"B"<<endl;
		}else if(sum>=50){
			cout<<"C"<<endl;
		}else if(sum<30){
			cout<<"F"<<endl;
		}else{
			if(r>=50){
				cout<<"C"<<endl;
			}else{
				cout<<"D"<<endl;
			}
		}
	}
    return 0;
} 



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;


int main(){
  int n;
  cin >> n;
  vector<int> d(n,0);
  rep(i,n) cin >> d[i];
  sort(all(d));
  int mid = n/2;int bef = mid-1;
  cout << d[mid] - d[bef] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct{
	double x, y;
}typedef Point;

void dfs(int d,Point p1, Point p2){
	if(d==0) return;
	double th = M_PI * 60.0 / 180.0;
	Point s,t,u;
	s.x = (2.0*p1.x+p2.x)/3.0;
	s.y = (2.0*p1.y+p2.y)/3.0;
	t.x = (p1.x+2.0*p2.x)/3.0;
	t.y = (p1.y+2.0*p2.y)/3.0;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;	
	dfs(d-1,p1,s);
	printf("%.8f %.8f\n",s.x,s.y);
	dfs(d-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	dfs(d-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);	
	dfs(d-1,t,p2);
}

int main(){
	int n;
	cin >> n;
	Point p1={0,0}, p2={100,0};
	printf("%.8f %.8f\n",p1.x,p1.y);
	dfs(n,p1,p2);
	printf("%.8f %.8f\n",p2.x,p2.y);	
	return 0;
}

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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 101010
#define DEBUG_OUT true

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


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//BELOW
//-----CODE------//


void solve(void)
{
  //https://kmjp.hatenablog.jp/entry/2018/03/11/1100
  int n,a,b;
  cin>>n>>a>>b;
  if(a + b > n + 1)
  {
    cout<<-1<<endl;
    return;
  }
  if(a*b < n)
  {
    cout<<-1<<endl;
    return;
  }
  vector<int> vec;
  int s = n - a;
  int cur = n;
  for (int i = 0; i < a; i++)
  {
    int num = min(b-1,s) + 1;
    s -= num -1;
    for (int j = 0; j < num; j++)
    {
      vec.push_back(cur - num + 1 +j);
    }
      cur -= num;  
  }
  reverse(ALL(vec));
  for (int i = 0; i < vec.size(); i++)
  {
      if(i != 0)cout<<char(32);
      cout<<vec[i];
  }
  cout<<endl;

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 7392
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;
const int MOD = 1000000007;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

class Edge{
public:
    int to;
    double cost;
    Edge(int to, double cost): to(to), cost(cost){};
};

int N;
double R, T;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    cin >> N;
    cin >> R >> T;
    T = T * M_PI / 180;
    
    vector<P> cities(N);
    for(int i=0; i<N; i++){
        double x, y; cin >> x >> y;
        cities[i] = P(x, y);
    }
    
    vector<vector<vector<Edge>>> G(N, vector<vector<Edge>>(N));
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++) if(i != j){
            for(int k=0; k<N; k++) if(j != k){
                double rad = abs(arg((cities[j]-cities[i])/(cities[k]-cities[j])));
                if(LE(rad, T)){
                    G[i][j].push_back(Edge(k, abs(cities[k]-cities[j])));
                }
            }
        }
    }
    
    //???????????????????????£?????? ??´????????? ????????? ???????°??????¢
    vector<vector<vector<double>>> dp(int(R+1), vector<vector<double>>(N, vector<double>(N, INF)));
    //dp[0][0][0] = 0;
    
    for(int i=1; i<N; i++)
        dp[1][0][i] = abs(cities[i]-cities[0]);
    
    for(int i=1; i<int(R); i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++) if(j != k){
                for(auto edge: G[j][k]){
                    dp[i+1][k][edge.to] = min(dp[i+1][k][edge.to], dp[i][j][k]+edge.cost);
                }
            }
        }
    }
    
    for(int i=R; i>=0; i--){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                if(LE(dp[i][j][k], R)){
                    cout << i << endl;
                    return 0;
                }
            }
        }
    }
    cout << 0 << endl;
    
    return 0;
}

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

int main() {
  int N,Q;
  cin >> N;
  vector<int> s(N);
  for(int i=0;i<N;i++) cin>>s[i];
  cin >> Q;
  vector<int> t(Q);
  for(int i=0;i<Q;i++) cin>>t[i];

  int count=0;
  for(int i=0;i<Q;i++){
    for(int j=0;j<N;j++){
      if(t[i]==s[j]){
        count++;
        break;
      }
    }
  }
cout<<count<<endl;
}



Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint a,b;

void solve(){
  cin >> a;
  int h,m,s;
  h=a/3600;
  a=a%3600;
  m=a/60;
  s=a%60;
  printf("%d:%d:%d\n",h,m,s);
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>

int main(){
	int K,N,i,j;
	double a,sum;
	scanf("%d",&N);
	scanf("%d",&K);
	sum=0;
	for(i=1;i<=N;i++){
		a=(double)1/N;
		for(j=i;j<K;){
			j=j*2;
			a=a/2;
		}
	sum=sum+a;
	}
	printf("%.10lf",sum);
	return 0;
}


Measured memory_bytes: 1684
fn gcd(a: u32, b: u32) -> u32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn func(input_str: &str) -> u32 {
    let mut iter = input_str.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a_s: Vec<u32> = iter.take(n).map(|x| x.parse().unwrap()).collect();
    let mut ans = a_s[0];
    for i in 1..a_s.len() {
        ans = gcd(a_s[i], ans);
    }
    ans
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    println!("{}", func(&buf[..]));
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;
//#define local
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    char s[100010];
    cin>>s;
    int i,flag=0,k=strlen(s);
    for(i=0; i<k; i++)
    {
        if(s[i]==s[i+1])
        {
            printf("%d %d\n",i+1,i+2);
            flag=1;
            break;
        }
        else if(s[i]==s[i+2])
        {
            printf("%d %d\n",i+1,i+3);
            flag=1;
            break;
        }
    }
    if(!flag) printf("-1 -1\n");
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		
		int i = 1;
		while(true) {
			if(i>N) {
				break;
			}
			i *= 2;
		}
		if(i ==1) {
			System.out.println("1");
		}
		else System.out.println(i/2);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vll flag, color; vll path; vl D;
//***********//
vll R;
void dfs(ll i, ll j) {
	stack<pll> S;
	S.push(make_pair(i, j));
	flag[i][j] = 1;
	while (!S.empty()) {
		pll u = S.top();
		S.pop();
		if (u.first == H - 1 && u.second == W - 1) {
			ans = 1;
		}
		if (i != 0) {
			if (flag[i - 1][j] == 0 && R[i-1][j] == 1)dfs(i - 1, j);
		}
		if (i != H-1) {
			if (flag[i + 1][j] == 0 && R[i+1][j] == 1)dfs(i + 1, j);
		}
		if (j != 0) {
			if (flag[i][j-1] == 0 && R[i][j-1] == 1)dfs(i, j-1);
		}
		if (j != W-1) {
			if (flag[i][j+1] == 0 && R[i][j+1] == 1)dfs(i, j+1);
		}
	}
}
int main() {
	cin >> H >> W;
	R.resize(H, vl(W));
	flag.resize(H, vl(W));
	vector<string> S(H);
	vll P(H, vl(W, 0));
	for (i = 0; i < H; i++) {
		cin >> S[i];
		for (j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				P[i][j] = -1;
			}
			else {
				P[i][j] = ctoi(S[i][j]);
			}
		}
	}
	vll Q(H, vl(W, 0));
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			ll key;
			if (i % 4 == 0) {
				if (j % 4 == 0) key = 6;
				if (j % 4 == 1) key = 3;
				if (j % 4 == 2) key = 1;
				if (j % 4 == 3) key = 4;
			}
			if (i % 4 == 1) {
				if (j % 4 == 0) key = 2;
				if (j % 4 == 1) key = 3;
				if (j % 4 == 2) key = 2;
				if (j % 4 == 3) key = 4;
			}
			if (i % 4 == 2) {
				if (j % 4 == 0) key = 1;
				if (j % 4 == 1) key = 3;
				if (j % 4 == 2) key = 6;
				if (j % 4 == 3) key = 4;
			}
			if (i % 4 == 3) {
				if (j % 4 == 0) key = 5;
				if (j % 4 == 1) key = 3;
				if (j % 4 == 2) key = 5;
				if (j % 4 == 3) key = 4;
			}
			Q[i][j] = key;
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (P[i][j] == Q[i][j]) {
				R[i][j] = 1;
			}
			else {
				R[i][j] = 0;
			}
			//cout << R[i][j];
			flag[i][j] = 0;
		}
		//cout << endl;
	}
	dfs(0, 0);
	if (ans)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 7592
roman={"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

try:
    while True:
        x=[]
        line = raw_input()
        tmp = roman[line[0]]
        x.append(tmp)
        for c in line[1:]:
            tmp = roman[c]
            if x[-1]<tmp: x[-1] = -x[-1]
            x.append(tmp)
        print sum(x)
except:
    pass

Measured memory_bytes: 4216
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

        int a, b, c;

        cin >> a >> b >> c;

        int area;

        if (a > b && a > c) {
                area = b*c/2;
        } else if (b > a && b > c) {
                area = c*a/2;
        } else {
                area = a*b/2;
        }

        cout << area << endl;

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod=1000000007;
int main()
{
	int n,m;
	scanf("%d%d\n",&n,&m);
	if (n-m>=2 || m-n>=2)
	{
		printf("0\n");
		return 0;
	} 
	long long ans=0,a=1,b=1;
	for (int i=1;i<=n;i++)
	{
		a=(a*i)%mod;
	}
	for (int i=1;i<=m;i++)
	{
		b=(b*i)%mod;
	}
	ans=(a*b)%mod;
	if (n==m)
	{
		ans=(ans*2)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
def maxvolume( s ): 
  
    # finding length 
    length = (s / 3) 
      
    s -= length 
      
    # finding breadth 
    breadth = s / 2
      
    # finding height 
    height = s - breadth 
      
    return (length * breadth * height) 
l=int(input())
print(maxvolume(l))

Measured memory_bytes: 2940
(setf array (make-array (read) :initial-element -1))

(defun calc (M)
  (dotimes (x M)
    (let ((p-1 (1- (read))) (s (read)))
      (if (< (aref array p-1) 0)
	  (if (string= s "AC")
	      (setf (aref array p-1) (- -1 (aref array p-1)))
	    (setf (aref array p-1) (1- (aref array p-1))))))))

(calc (read)) 
(setf array (remove-if (lambda (x) (< x 0)) array))

(defmacro lst-sum (lst)
  `(reduce #'+ ,lst))

(format t "~A ~A" (length array) (lst-sum array))

Measured memory_bytes: 59880
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n, a, b, c int
	fmt.Fscan(r, &n, &a, &b, &c)
	v := make(map[byte]int)
	v['A'], v['B'], v['C'] = a, b, c
	s := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &s[i])
	}

	ans := make([]byte, 0, n)

	choose := func(s string, i int) {
		v[s[i]]++
		v[s[i^1]]--
		ans = append(ans, s[i])
	}

	chooseAny := func(s string) {
		if v[s[0]] == 0 {
			choose(s, 0)
		} else {
			choose(s, 1)
		}
	}

	for i := 0; i < n; i++ {
		if v[s[i][0]] == 0 && v[s[i][1]] == 0 {
			fmt.Fprintln(w, "No")
			return
		}
		if i == n-1 || v[s[i][0]] == 0 || v[s[i][1]] == 0 {
			chooseAny(s[i])
		} else if s[i] == s[i+1] {
			chooseAny(s[i])
		} else {
			if s[i][0] == s[i+1][0] || s[i][0] == s[i+1][1] {
				choose(s[i], 0)
			} else {
				choose(s[i], 1)
			}
		}
	}

	fmt.Fprintln(w, "Yes")
	for i := 0; i < n; i++ {
		fmt.Fprintf(w, "%c\n", ans[i])
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;


int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string str;cin >> str;int ans = 0;REP(i, str.size())if(str[i] == '2')ans++;cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<int> query(Q+2,-1e9);
  for(int i=1; i<=Q; i++){
    cin >> query.at(i);
  }
  query.at(Q+1) = 1e9+10;
  vector<vector<int>> in(Q+2,vector<int>(0));
  vector<vector<int>> out(Q+2,vector<int>(0)); 
  
  vector<int>::iterator pos;
  int idx;
  for(int i=0; i<N; i++){
    int s = vec.at(i).at(0);
    int e = vec.at(i).at(1);
    int p = vec.at(i).at(2);
    pos = lower_bound(query.begin(),query.end(),s-p);
    idx = distance(query.begin(),pos);
    in.at(idx).push_back(p);
    pos = lower_bound(query.begin(),query.end(),e-p);
    idx = distance(query.begin(),pos);
    out.at(idx).push_back(p);
  }
  
  map<int,int> mp;
  mp[1e9+10] = 1;
  for(int i=0; i<Q+1; i++){
    for(int j=0; j<in.at(i).size(); j++){
      if(mp.count(in.at(i).at(j))){
        mp[in.at(i).at(j)]++;
      }
      else{
        mp[in.at(i).at(j)] = 1;
      }
    }
    for(int j=0; j<out.at(i).size(); j++){
      mp[out.at(i).at(j)]--;
      if(mp[out.at(i).at(j)] == 0){
        mp.erase(out.at(i).at(j));
      }
    }
    if(i != 0){
      int x = mp.begin()->first;
      if(x == 1e9+10){
        cout << -1 << endl;
      }
      else{
        cout << x << endl;
      }
    }
  }
}

Measured memory_bytes: 38772
#include <math.h>
#include <iomanip> // setprecisionを使用するのに必要
#include <iostream>

using namespace std;

int main()
{
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double hv = 2 * M_PI / (12.0 * 60);
  double mv = 2 * M_PI / (60.0);

  // 角度(rad)
  double hr = hv * (h * 60 + m);
  double mr = mv * m;
  //   cout << hr << "," << mr << endl;

  double diff = fabs(hr - mr);
  if (diff > M_PI)
  {
    diff = 2 * M_PI - diff;
  }
  //   cout << diff << endl;

  // 余弦定理
  double c_sq = a * a + b * b - 2 * a * b * cos(diff);
  cout << std::fixed << std::setprecision(20) << sqrt(c_sq) << endl;

  return 0;
}

Measured memory_bytes: 4192
//2019/12/1.
//All search. BS.
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vi;
typedef vector<vi >   vvi;

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	vvi v(10);
	REP(i,n) v[s[i]-'0'].push_back(i);
	
	int ans=0;
	REP(i,1000){
		int c[]={i/100,(i%100)/10,i%10};
		
		if(v[c[0]].empty()) continue;//REP.
		
		int p=v[c[0]][0];
		auto itr=upper_bound(ALL(v[c[1]]),p);
		if(itr==v[c[1]].end()) continue;//REP.
		
		p=*itr;
		auto itrr=upper_bound(ALL(v[c[2]]),p);
		if(itrr==v[c[2]].end()) continue;//REP.
		
		ans++;
	}
	
	cout<<ans<<endl;
}


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

int h, w, s[30][30], g_h, g_w, ans;

void dfs(int hh, int ww, int tim) {
    //cout << hh << " " << ww << " " << tim << endl;
    if (tim < 10) {
        for (int i = hh - 1; i >= 0; i--) {
            if (s[hh - 1][ww] == 1) break;
            if (s[i][ww] == 3) {
                ans = min(ans, tim + 1);
                break;
            }
            if (i > 0 && s[i][ww] == 0 && s[i - 1][ww] == 1) {
                s[i - 1][ww] = 0;
                dfs(i, ww, tim + 1);
                s[i - 1][ww] = 1;
                break;
            }
        }
        for (int i = hh + 1; i <= h - 1; i++) {
            if (s[hh + 1][ww] == 1) break;
            if (s[i][ww] == 3) {
                ans = min(ans, tim + 1);
                break;
            }
            if (i < h - 1 && s[i][ww] == 0 && s[i + 1][ww] == 1) {
                s[i + 1][ww] = 0;
                dfs(i, ww, tim + 1);
                s[i + 1][ww] = 1;
                break;
            }
        }
        for (int i = ww - 1; i >= 0; i--) {
            if (s[hh][ww - 1] == 1) break;
            if (s[hh][i] == 3) {
                ans = min(ans, tim + 1);
                break;
            }
            if (i > 0 && s[hh][i] == 0 && s[hh][i - 1] == 1) {
                s[hh][i - 1] = 0;
                dfs(hh, i, tim + 1);
                s[hh][i - 1] = 1;
                break;
            }
        }
        for (int i = ww + 1; i <= w - 1; i++) {
            if (s[hh][ww + 1] == 1) break;
            if (s[hh][i] == 3) {
                ans = min(ans, tim + 1);
                break;
            }
            if (i < w - 1 && s[hh][i] == 0 &&  s[hh][i + 1] == 1) {
                s[hh][i + 1] = 0;
                dfs(hh, i, tim + 1);
                s[hh][i + 1] = 1;
                break;
            }
        }
    }
}


int main(void){
    while (cin >> w >> h) {
        if (h * w == 0) return 0;
        
        int s_h, s_w;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> s[i][j];
                if (s[i][j] == 2) {
                    s_h = i;  s_w = j;
                    s[i][j] = 0;
                }
            }
        }
        
        ans = 20;
        dfs(s_h, s_w, 0);
        
        if (ans != 20) cout << ans << endl;
        else cout << -1 << endl;
    }
}



Measured memory_bytes: 3060