akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  9 13:24:45 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A = list(map(int,input().split()))
a = ['{:040b}'.format(i) for i in A]
k = '{:040b}'.format(K)
ans = 0
flg = False
for i in range(40):
    counta = 0
    for j in range(N):
        counta += 1 if a[j][i] == '1' else 0
        check = 1 if counta<N/2 else 0
    
    if flg:
        ans += pow(2,39-i)*(N-counta) if check==1 else pow(2,39-i)*counta
        continue
    if check==1 and k[i]=='0':
        ans += pow(2,39-i)*counta
    elif check==0 and k[i]=='1':
        ans += pow(2,39-i)*counta
        flg = True
    else:
        ans += pow(2,39-i)*(N-counta) if check==1 else pow(2,39-i)*counta
print(ans)


Measured memory_bytes: 19820
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))


# 順列を各サイクルに分解する
used = [0] * N
ss = []
for i in range(N):
    if used[i]: continue
    cur = i
    s = []
    while used[cur] == 0:
        used[cur] = 1
        s.append(C[cur])
        cur = P[cur] - 1 # 0-index
    ss.append(s)

# 各サイクルごとに考える
res = -float("inf")
for vec in ss:
    M = len(vec)
    
    # サイクルを2周したものの累積和
    accum = [0] * (2*M+1)
    for i in range(M*2):
        accum[i+1] = accum[i] + vec[i%M]

    # amari[r] := 連続するr個の総和の最大値
    amari = [-float("inf")] * M
    for i in range(M):
        for j in range(M):
            amari[j] = max(amari[j], accum[i+j]-accum[i])

    # あまりの長さで場合分け
    for r in range(M):
        if r > K: continue
        q = (K - r) // M # ループ回数
        if r == 0 and q == 0: continue

        if accum[M] > 0:
            res = max(res, amari[r] + accum[M] * q)
        elif r > 0:
            res = max(res, amari[r])

print(res)




Measured memory_bytes: 75136
#include <algorithm>
#include <iostream>
using namespace std;
int N,R,p,c;
int A[50] = {};
int main(void) {
	while (cin >> N >> R && N) {
		for (int i=0; i<N; ++i) A[i] = N-i;
		for (int i=0; i<R; ++i) {
			cin >> p >> c;
			rotate (A,A+p-1,A+p+c-1);
		}
		cout << A[0] << endl;
	}
}

Measured memory_bytes: 1184
#include <stdarg.h>
#include <stdio.h>

#define DENOM 1000000007LL

int max(int len, ...) {
    int i, _max, num;
    va_list ap;
    va_start(ap, len);

    _max = va_arg(ap, int);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, int);
        if (num > _max)
            _max = num;
    }
    va_end(ap);
    return _max;
}

int min(int len, ...) {
    int i, _min, num;
    va_list ap;
    va_start(ap, len);

    _min = va_arg(ap, int);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, int);
        if (num < _min)
            _min = num;
    }
    va_end(ap);
    return _min;
}

int main(void) {
    int i, j, l, m, N, K, a[110];
    long long dp[110][100010] = {0LL}, cum[100010]={0LL};
    scanf("%d%d", &N, &K);
    for (i=1;i<=N;i++) scanf("%d", &a[i]);

    for (j=0;j<=a[1];j++) {
        dp[1][j] = 1LL;
    }
    m = a[1];
    for (i=2;i<=N;i++) {
        m += a[i];
        cum[0] = 0LL;
        for (l=1;l<=K+1;l++) {
            cum[l] = cum[l-1] + dp[i-1][l-1];
            cum[l] %= DENOM;
        }
        for (j=0;j<=K;j++) {
            dp[i][j] = cum[j+1] - cum[((int) max(2,0,j-a[i]))] + DENOM;
            dp[i][j] %= DENOM;
        }
    }

    printf("%lld\n", dp[N][K]);
    return 0;
}

Measured memory_bytes: 86912
n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)-1

nCa = 1
nCb = 1
for i in range(b):
    nCb *= (n-i)
    nCb %= mod
    nCb *= pow(i+1, mod-2, mod)
    if i == a-1:
        nCa = nCb
ans -= nCa
ans %= mod
ans -= nCb
ans %= mod

print(ans)

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


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

    vector<vector<int>> v;
    for(int bit=0; bit<(1 << n); bit++){
        vector<int> t;
        for(int i=0; i<n; i++){
            if(bit & (1<<i)) t.push_back(1);
            else t.push_back(0);
        }
        v.push_back(t);
    }

    vector<vector<int>> s(m);
    for(int i=0; i<m; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int sw; cin >> sw;
            s[i].push_back(sw);
        }
    }

    vector<int> p(m);
    for(int i=0; i<m; i++) cin >> p[i];


    int ans = 0;
    for(int i=0; i<v.size(); i++){
        int cnt = 0;
        for(int j=0; j<m; j++){
            int tmp = 0;
            for(int l=0; l<s[j].size(); l++){
                if(v[i][s[j][l]-1] == 1) tmp++;
            }
            if(tmp%2 == p[j]) cnt++;
        }
        if(cnt == m) ans++;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 384
N = int(input())
S = input()

alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

metamol = ""

for m in S:
    metamol += alphabet[(alphabet.index(m) + N) % 26]

print(metamol)

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

using namespace std;

typedef pair<int, int> P;

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

int s[1000001];
int d[3000][3000];
int b[3000][3000];
bool f[3000][3000];

int main(){

	int n, m;
	for (long long i = 2; i < 1000001; i++){

		if (!s[i]){
			for (long long j = i * 2; j < 1000001; j += i){
				s[j] = 1;
			}
		}

	}
	s[1] = 1;

	while (cin >> n >> m && n){

		memset(d, 0, sizeof(d));
		memset(b, 0, sizeof(b));
		memset(f, 0, sizeof(f));
		queue<P> q;
		q.push(P(1500, 1500));
		int dir = 0;
		int dist = 1;
		int c = -1;
		int num = 1;
		int sy, sx;
		n++;

		while (q.size()){
			int y = q.front().first, x = q.front().second;
			q.pop();

			if (num == m)sx = x, sy = y;
			d[y][x] = num++;
			if (num == n)goto end;

			if (c == 1){
				c = 0; dist++;
			}
			else{
				c++;
			}
			int ty = y, tx = x;
			for (int i = 1;i < dist;i++){
				ty += dy[dir]; tx += dx[dir];
				if (num == m)sx = tx, sy = ty;
				d[ty][tx] = num++;
				if (num == n)goto end;
			}

			q.push(P(y + dy[dir] * dist, x + dx[dir] * dist));
			dir = (dir + 1) % 4;

		}

	end:;

		q.push(P(sy, sx));
		b[sy][sx] = (s[d[sy][sx]] ? 0 : 1);
		P ans(0,0);
		f[sy][sx] = 1;
		if (!s[d[sy][sx]]){
			ans.first = 1;
			ans.second = d[sy][sx];
		}

		while (q.size()){
			int y = q.front().first, x = q.front().second;
			q.pop();

			int ty = y + 1, tx = x;

			for (tx = x - 1; tx <= x + 1; tx++){
				if (d[ty][tx] == 0)continue;

				if (!f[ty][tx] || b[ty][tx] < b[y][x] + (s[d[ty][tx]] ? 0 : 1)){
					f[ty][tx] = 1;
					q.push(P(ty, tx));
				}
				if (b[ty][tx] < b[y][x] + (s[d[ty][tx]] ? 0 : 1)){
					b[ty][tx] = b[y][x] + (s[d[ty][tx]] ? 0 : 1);
					if (!s[d[ty][tx]] && (ans.first < b[ty][tx] || (ans.first == b[ty][tx] && ans.second < d[ty][tx]))){
						ans.first = b[ty][tx];
						ans.second = d[ty][tx];
					}
				}
			}
		}
		cout << ans.first << " " << ans.second << endl;

	}
	
	return 0;
}

Measured memory_bytes: 84244
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        double sum = 0.0;
        for (int i= 0; i < n; i++) {
            double a = sc.nextDouble();
            String b = sc.next();
            if (b.equals("BTC")) {
                a *= 380000.0;
            }
            sum += a;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23124
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	var s1 int
	var s2 int
	var s3 int

	s1, _ = strconv.Atoi(string(s[0]))
	s2, _ = strconv.Atoi(string(s[1]))
	s3, _ = strconv.Atoi(string(s[2]))
	fmt.Println(s1 + s2 + s3)

}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a < b && b < c && a < c) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26324
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        Map<String, Integer> votes = new HashMap<>();
        int mx = 0;

        for (int i = 0; i < n; i++) {
            String current = sc.nextLine().trim();
            votes.putIfAbsent(current, 0);
            votes.put(current, votes.get(current) + 1);
            mx = Math.max(mx, votes.get(current));
        }

        final int _mx = mx;
        votes.entrySet().stream()
                .filter(e -> e.getValue().equals(_mx))
                .map(Map.Entry::getKey)
                .sorted(String::compareTo)
                .forEach(System.out::println);
    }
}

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

using namespace std;

int main(){
    int A ,B ;
    cin>> A>>B;
    if (A+B>=A*B && A+B>= A-B){
            cout<< A+B ;
    }
    else if (A*B>=A+B && A*B >=A-B){
            cout<<A*B;

    }

    else{ cout<<A-B;}
    return 0 ;
}



Measured memory_bytes: 3604
len[3],used[3],s[3][100],d,i;rec(t){if(used[t]++>=len[t])putchar('A'+t);else rec(s[t][used[t]-1]);}main(){for(i=0;i<3;i++)while((d=getchar())!='\n')s[i][len[i]++]=d-'a';rec(0);}

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

int main(){
    int N;
    cin>>N;
    vector<int> X(N);
    vector<int> Y(N);
    vector<int> H(N);
    tuple<int,int,int> check;

    for(int i=0; i<N; i++){
        cin>>X[i]>>Y[i]>>H[i];
        if(H[i] > 0){
            check = make_tuple(X[i],Y[i],H[i]);//これは高さの答がゼロになるのを防ぐ
        }
    }

    int cnt,cmp;
    cnt = 0;

    for(int cx=0; cx<=100; cx++){
        for(int cy=0; cy<=100; cy++){
            cmp = get<2>(check)+abs(get<0>(check)-cx)+abs(get<1>(check)-cy);
            cmp = max(0,cmp);
            bool flag = true;
            int sec_cmp;
            for(int i=0; i<N; i++){
                sec_cmp = cmp-abs(X[i]-cx)-abs(Y[i]-cy);
                sec_cmp = max(sec_cmp,0);
                if(sec_cmp != H[i]){
                    flag = false;
                }
            }
            if(flag){
                cout<<cx<<" "<<cy<<" "<<cmp<<endl;
                return 0;
            }
        }
    }

    return 0;
}

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

int main() {
	vector<int> X(3); cin >>X[0]>>X[1]>>X[2];
	sort(X.begin(),X.end());
	int K;cin>>K;
	cout << X[0] + X[1] + X[2]*pow(2,K) << endl;
}

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

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

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

	cin >> K;
	while (K--) {
		cin >> N;
		vector<long long int>v(N);
		for (auto &i : v)cin >> i;
		string s;
		cin >> s;
		vector<long long int>w;
		bool flag = false;
		for (int i = N - 1; i >= 0; i--) {
			if (s[i] == '1') {
				long long int p = v[i];
				int b = 60;
				for (auto j : w) {
					while (((j >> b) & 1) == 0)b--;
					if ((p >> b) & 1)p ^= j;
				}
				if (p)flag = true;
			}
			else {
				w.push_back(v[i]);
				vector<int>used(w.size());
				for (int b = 60; b >= 0; b--) {
					int index = -1;
					for (int j = 0; j < w.size(); j++) {
						if (used[j])continue;
						if ((w[j] >> b) & 1)index = j;
					}
					if (index != -1) {
						used[index] = 1;
						for (int j = 0; j < w.size(); j++) {
							if (j != index && ((w[j] >> b) & 1)) {
								w[j] ^= w[index];
							}
						}
					}
				}
				sort(w.rbegin(), w.rend());
				while (!w.empty() && w.back() == 0)w.pop_back(); 
			}
		}
		cout << flag << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
# include <bits/stdc++.h>
# define ll long long
# define pb push_back
# define fi first
# define se second
# define mp make_pair
# define gcd(m,n)  __gcd(m, n)
# define pr_double(x) cout << fixed << setprecision(10) << x
using namespace std;
const ll N = 1e5+5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll x; cin>>x;
  if (x==0) cout<<"1"<<endl;
  else cout<<"0"<<endl;
}


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

int main() {
  int K;
  cin >> K;
  
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 
                   1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2
                    , 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a.at(K-1) << endl;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
		lint N, M;
		cin >> N >> M;
		vector<lint>p(M);
		vector<string>S(M);
		rep(i, M) {
			cin >> p[i] >> S[i];
		}
		vector<int>check(N, 0);
		lint cntwa = 0, cntac = 0;
		vector<lint>cwa(N);
		rep(i, M) {
			if (check[p[i] - 1] == 0) {
				if (S[i] == "WA") {
					cwa[p[i]-1]++;
				}
				else if (S[i] == "AC") {
					cntac++;
					check[p[i] - 1] = 1;
					cntwa += cwa[p[i] - 1];
				}
				/*	rep(i, N) {
						cout << check[i] << ' ';
					}
					cout << endl;*/
			}
		}

		cout << cntac << ' ' << cntwa << endl;
}


Measured memory_bytes: 7680
import math
import fractions
#import sys
#input = sys.stdin.readline

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

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



n = int(input())

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

nums = Zeros(10**5,-1)

for i in a:
    nums[i]+=1
ans=0
num2 = 0
for i in nums:
    if(i%2==1):
        ans+=1
    elif(i!=0):
        num2+=1
        
print(ans + num2 - num2%2)






































Measured memory_bytes: 81856
n = int(input())
s = input()

c = [0]
cc = [0]
for i in range(n):
  if s[i] == ".":
    c.append(c[-1]+1)
    cc.append(cc[-1])
  else:
    c.append(c[-1])
    cc.append(cc[-1]+1)
c = c[1:]
cc = cc[1:]

ans = min(c[-1], cc[-1])
for i in range(n):
  ans = min(ans, cc[i]+c[-1]-c[i])
print(ans)


Measured memory_bytes: 14392
//動かさない要素の和を最大化する。動かさない要素は増加列。
//dp([i])[cost] = minVal, a[0]～a[i-1]の中で残す要素の和をcost以上にするときの、最後の要素の最小値
//を考えると単調性より更新箇所が1つとなり、1回の更新もO(logN)でできるが、costが大きいので配列では持てない。
//そこで、(minVal, [start_pos, end_pos))をmapで持つ。(強実装…)
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define int long long
using namespace std;
typedef pair<int, int> P;

int n;
int x[100000];
map<int, P> dp;

signed main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> x[i];
	
	dp[0] = P(0, 1);
	dp[n + 1] = P(1, 2);
	for (i = 0; i < n; i++) {
		map<int, P>::iterator it = dp.upper_bound(x[i]);
		int l = it->second.first;
		dp[x[i]] = P(l, l + x[i]);
		
		vector<map<int, P>::iterator> erase_its;
		for (map<int, P>::iterator it2 = it; it2 != dp.end(); it2++) {
			if ((it2->second).second <= l + x[i]) {
				erase_its.push_back(it2);
			}
			else if ((it2->second).first < l + x[i]) {
				it2->second = P(l + x[i], (it2->second).second);
			}
			else {
				break;
			}
		}
		
		for (j = 0; j < erase_its.size(); j++) {
			dp.erase(erase_its[j]);
		}
		dp[n + 1].first = max(dp[n + 1].first, l + x[i]);
		dp[n + 1].second = dp[n + 1].first + 1;
	}
	
	int maxCost = 0;
	for (map<int, P>::iterator it = dp.begin(); it != dp.end(); it++) {
		if (it->first == n + 1) {
			maxCost = (it->second.first) - 1;
			break;
		}
	}
	
	int sumX = 0;
	for (i = 0; i < n; i++) sumX += x[i];
	cout << sumX - maxCost << endl;
	return 0;
}


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

namespace 練習問題
{
    class Program {
        static void Main(string[] args) {
            debug Debug = new debug();
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
          	n = n % k;
          	long minval = n;
          	//for(int i=0;i<k;i++){
     
             while(Math.Abs(n - k)< n){            
               n = Math.Abs(n - k);
               
            	if (n < minval){
            		minval = n;
            	}
            }
     
            Console.WriteLine(minval);
        }

        static void bubble_sort(List<List<int>> a) {
            int count=0;
            for (int i = 0; i < a.Count; i++) {
                for (int j = 0; j < a.Count-i-1; j++) {
                    // if (a[j] == a[a.Count - 1]){
                    //     continue;
                    // }
                    count++;
                    if (a[j][1] > a[j+1][1]){
                        int localsave = 0;
                        localsave = a[j+1][1];
                        a[j+1][1] = a[j][1];
                        a[j][1] = localsave;
                        localsave = a[j][0];
                        a[j][0] = a[j+1][0];
                        a[j+1][0] = localsave;
                    }
                }
                //debug(a,"途中" + i);
            }
            // debug(a,"result");
            //Console.WriteLine("回数"+count);
            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a[i][0]+" "+a[i][1]);
            }
        }
        /* 標準入力と標準出力が使えるかのチェック
        static void echo() {
            string echotest = Console.ReadLine();
            Console.WriteLine(echotest);
        }

        static void HelloWorld(){
            Console.WriteLine("Hello World!");
        }
        */
    }

    public class debug{
        public void Log(string str){
            Console.WriteLine(str);
        }
        public void Log(int str){
            Console.WriteLine(str);
        }
        public void Log(object obj){
            Console.WriteLine(obj);
        }

        public void Log(int[] arr){
            Console.WriteLine(string.Join(",", arr));
        }
        public void Log(string[] arr){
            Console.WriteLine(string.Join(",", arr));
        }
        public void Log(List<int> arr){
            string shuturyoku = "";
            for (int i = 0; i < arr.Count; i++) {
                shuturyoku += arr[i] + " ";
            }
            Console.WriteLine(shuturyoku.TrimEnd(' '));
        }
    }
}

Measured memory_bytes: 11092
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define all(a)           a.begin(), a.end()
#define mem(a, n)        memset(a, n, sizeof(a))
#define Unique(n)        (n).erase(unique(all(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
#define repeat(i, a, n)  for(int i=a; i<n; i++)
#define isPowerOfTwo(n)  (n && !(n & (n - 1)))

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void file(){
#ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif /*ONLINE_JUDGE*/
}
int gin, bin, low, high, mid, n;

ll RGB(vector<int> R, vector<int> G, vector<int> B, int b[]){

    n = R.size();
    long long sum = 0;
    repeat(i, 0, n){
        low = 0, high = (int)G.size()-1, gin = -1;
        while(low<=high){
            mid = (low+high)/2;
            if(G[mid]>R[i])
                gin = mid, high = mid-1;
            else low = mid+1;
        }
        if(gin == -1) break;

        repeat(j, gin, G.size()){
            low = 0, high = (int)B.size()-1, bin = -1;
            while(low<=high){
                mid = (low+high)/2;
                if(B[mid]>G[j])
                    bin = mid, high = mid-1;
                else low = mid+1;
            }
            if(bin == -1) break;

            if(b[2*G[j] - R[i]]) sum--;
            sum += B.size() - bin;
        }
    }
    return sum;
}


int main(){
    quicken();

    cin >> n;
    string a; cin >> a;

    int r[8004] = {}, g[8004] = {}, b[8004] = {};
    vector<int> R, G, B;
    repeat(i, 0, n)
        if(a[i]=='R') R.push_back(i), r[i]++;
        else if(a[i]=='G') G.push_back(i), g[i]++;
        else B.push_back(i), b[i]++;


    cout << RGB(R, G, B, b) + RGB(R, B, G, g) +
            RGB(B, G, R, r) + RGB(B, R, G, g) +
            RGB(G, B, R, r) + RGB(G, R, B, b);

    return 0;
}

unsigned long long pow(long long base, long long power){  /// mod?
    if(power==0)
        return 1;
    if(power==1)
        return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1)
        return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n){
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, 0, n+1)
    if(isPrime[i])
        c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
   int n;
   cin>>n;
   int j=0;
   int sum=0;
   int SUM=0;

   int a[100000];
   for(int i=0;i<n;i++){
       cin>>a[i];
   }

   sort(a,a+n);

    j=a[0];
    for(int i=0;i<n;i++){
       
        if(a[i]==j){
            sum++;
           // if(sum>j)SUM++;
        }else{
            if(sum<j)SUM+=sum;
            else  if(sum>j)SUM+=sum-j;
            else sum=0;
            j=a[i];
            sum=1;
        }
        //cout<<j<<" "<<sum<<" "<<SUM<<endl;
    }
    if(sum<j)SUM+=sum;
     else  if(sum>j)SUM+=sum-j;
    cout<<SUM<<endl;
  
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define ll long long
#define ull unsigned long long
#define FOR(m,s,n,u) for(int m=s; m<n; m+=u)
#define ROF(m,s,n,u) for(int m=n; m>=s; m-=u)
#define FORb(m,s,n,u,k) for(int m=s; m<n&&k; m+=u)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define PI 3.1415926535897932384626433832795028841971
#define INF 0x3f3f3f3f
#define EPS 1e-9
#define MOD(x) ((x%mod)+mod)%mod
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define vi vector<int>
#define pii pair<int,int>

using namespace std;

int main(){
sync;
int n; cin>>n; 
int arr[n+1];
FOR(i,1,n+1,1)cin>>arr[i];

int DP[n+1];
DP[2] = max(arr[1],arr[2]) - min(arr[1],arr[2]);

FOR(i,3,n+1,1){
    int dif1 = abs(arr[i]-arr[i-1]);
    int dif2 = abs(arr[i]-arr[i-2]);
    DP[i] = min(DP[i-1] + dif1 , DP[i-2] + dif2);
}
cout<<DP[n];


return 0;
}

Measured memory_bytes: 4244
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7


int main(){
    string s;
    int n;
    cin >> s;
    cin >> n;
    int cnt = 0;
    while(true){
        if(cnt >= s.size()){
            break;
        }
        cout << s[cnt];
        cnt += n;
    }
    print("");
    return 0;
}

Measured memory_bytes: 256
while 1:
    try:
        xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float, raw_input().split())
        print "YES" if (xa1<=xb1<=xa2 or xa1<=xb2<=xa2 or xb1<=xa1<=xb2 or xb1<=xa2<=xb2) and (ya1<=yb1<=ya2 or ya1<=yb2<=ya2 or yb1<=ya1<=yb2 or yb1<=ya2<=yb2) else "NO"
    except EOFError:
        break

Measured memory_bytes: 4220
N, M = map(int, input().split())

matrix = [None] * N
vector = [0] * M

for i in range(N):
    matrix[i] = [int(c) for c in input().split()]
for i in range(M):
    vector[i] = int(input())

ans = [sum([a * b for a, b in zip(matrix[i], vector)]) for i in range(N)]

for i in ans:
    print(i)



Measured memory_bytes: 6024
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    s = gete()

    ans = 1

    for i in range(n - 1):
        if s[i] != s[i + 1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 39408
import sys
import unittest
import random

T = 26


def solve(d, c, s):
    best = [0] * d
    last = [-1]*T

    for i in range(d):
        max_v = -float('inf')
        for j in range(T):
            v = s[i][j] + c[j] * (i - last[j])
            if max_v < v:
                max_v = v
                best[i] = j
        last[best[i]] = i

    score = get_score(d, c, s, best)
    for i in range(700):
        a = random.randint(0, d-1)
        b = random.randint(0, T-1)
        old = best[a]
        best[a] = b
        t_score = get_score(d, c, s, best)
        if t_score > score:
            score = t_score
        else:
            best[a] = old
    return best


def get_score(d, c, s, t):
    last = [-1]*T
    total = 0
    for i in range(d):
        total += s[i][t[i]]
        last[t[i]] = i
        for j in range(T):
            total -= c[j] * (i - last[j])
    return max(10**6+total, 0)


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    t = solve(d, c, s)
    print(get_score(d, c, s, t), file=sys.stderr)
    for i in range(d):
        print(t[i]+1)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_score(self):
        pass


Measured memory_bytes: 16824
from queue import Queue
from sys import stdin, stdout
input = stdin.readline
print = stdout.write

n, q = map(int, input().split())
adj = [[] for _ in range(n + 1)]
lazy = [0] * (n + 1)

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

for _ in range(q):
    p, x = map(int, input().split())
    lazy[p] += x

qu = Queue()
qu.put((1, 0))
while not qu.empty():
    pair = qu.get()
    u = pair[0]
    for v in adj[u]:
        if v == pair[1]: continue
        lazy[v] += lazy[u]
        qu.put((v, u))

for i in range(1, n + 1):
    print(str(lazy[i]) + ' ')
 

Measured memory_bytes: 91720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
 
int main() {
	int N, A[100005];
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    int next = 1;
    int count = 0;
    for (int i = 1; i <= N; ++i) {
        if (next == 2) break;
        next = A[next];
        count += 1;
    }

    if (count == N) cout << -1 << endl;
    else cout << count << endl;

    return 0;
}

Measured memory_bytes: 640
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;

int i = 0;

string s;

int check(int num) {
	char sn = s[num];
	

	if (num == s.size() - 1) {
		if (sn == 'A') {
			return 1;
		}
		else {
			return 0;
		}
	}
	char sni = s[num + 1];
	if (  (sn == 'B' &&  sni == 'A') || (sn == 'B' &&  sni == 'B')) {
		
		return 0;
	}
	else if ((sn == 'C')) {
		return 0;
	}
	else if (sn == 'A') {
		return 1;

	}
	else if ((sn == 'B' &&  sni == 'C')) {
		i++;
		return 2;		
	}
}

int main()
{

	cin >> s;

	int count = 0;

	long long ans = 0;

	int siz = s.size();
	for (i; i < siz; i++) {

		int ch = check(i);
		if (ch == 0) {
			count = 0;
		}
		else if (ch == 1) {
			count++;
		}
		else {
			ans = ans + count;
		}
	}
	



	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
	char a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a == b && c == d && a != c) {
		printf("Yes");
	}else if (a == d && b == c && a != c) {
		printf("Yes");
	}else if (a == c && b == d && a != b) {
		printf("Yes");
	}else {
		printf("No");
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main() { 

    ll n,k;
    cin >> n >> k;

    vector <pint> pairs(n);

    REP(i,n)
    {
        cin >> pairs[i].first >> pairs[i].second;
    }

    sort(pairs.begin(), pairs.end());

    ll cnt = 0;
    ll res;
    REP(i,n)
    {
        cnt += pairs[i].second;
        if(cnt >= k)
        {
            res = pairs[i].first;
            break;
        }
    }



    cout << res << endl;

    return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    int n;
    while(cin>>n){
        vector<int> a(n);
        REP(i,n)cin>>a[i];
        sort(a.begin(),a.end());
        ll sum=0;
        ll ans=0;
        REP(i,n){
            sum+=a[i];
            ans+=sum;
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(void) {
  int a[12], i, j, s = 0;
  for(i = 0; i < 12; ++i)scanf("%d", &a[i]);
  sort(a, a + 12);
  for(i = 0; i < 3; ++i) for(j = 1; j < 4; ++j) if(a[i * 4] != a[i * 4 + j]) s = 1;
  if(!s) printf("yes\n");
  else printf("no\n");
  return 0;
}


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

int main() {
    int N, M, i, cnt = 0;
    cin >> N >> M;
    vector<int> high(N);
    vector<int> A(M);
    vector<int> B(M);
    vector<int> flag(N, 1);
    for (i = 0; i < N; i++) cin >> high.at(i);
    for (i = 0; i < M; i++) {
        cin >> A.at(i) >> B.at(i);
        if (high.at(A.at(i) - 1) > high.at(B.at(i) - 1)) flag.at(B.at(i) - 1) = 0;
        else if (high.at(A.at(i) - 1) < high.at(B.at(i) - 1)) flag.at(A.at(i) - 1) = 0;
        else {
            flag.at(B.at(i) - 1) = 0;
            flag.at(A.at(i) - 1) = 0;
        }
    }
    for (i = 0; i < N; i++) {
        if (flag.at(i) == 1) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4840
s=gets.chomp


if s !~ /^1.*0$/ || s[0..-2] != s[0..-2].reverse
  p -1
  exit
end

puts "1 2"

ptr = 2

(1...s.size-1).each{|i|
  puts "#{ptr} #{i+2}"
  if s[i]==?1
    ptr = i+2
  end
}


Measured memory_bytes: 7676
use std::cmp::max;

fn main() {
    let (k, n) = read_tuple::<i64>();
    let an: Vec<i64> = read_vec();

    let min_an = an[0];
    let mut an: Vec<i64> = an.iter().map(|v| v - min_an).collect();
    an.push(k);

    let mut longest_distance = 0;
    for i in 0..(n as usize) {
        longest_distance = max(longest_distance, an[i + 1] - an[i]);
    }

    println!("{:?}", k - longest_distance);
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



Measured memory_bytes: 10992
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <math.h>
#include <algorithm>
#include <functional>
#include <set> 

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

signed main()
{
	int n;
	cin >> n;
	vector<int> vec(n, 0);
	REP(i, n) { cin >> vec[i]; }

	int take = 0;
	int now = 0;
	while (take < n * 2) {
		take++;
		now = vec[now]-1;
		if (now == 1) break;
	}
	if (take >= n * 2) cout << -1 << endl;
	else cout << take << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll N;
vector<ll> E[100010];
ll memo[100010][2];
ll dp(ll now, ll from, char col){
  if(memo[now][col == 'W'] != -1) return memo[now][col == 'W'];
  ll res = 1;
  for(ll to : E[now]){
    if(to == from) continue;
    if(col == 'W'){
      res *= dp(to, now, 'W') + dp(to, now, 'B');
    }else{
      res *= dp(to, now, 'W');
    }
    res %= MOD;
  }
  return memo[now][col == 'W'] = res;
}


int main(){
  cin >> N;
  rep(i, N-1){
    ll x, y;
    cin >> x >> y;
    x--, y--;
    E[x].pb(y);
    E[y].pb(x);
  }
  rep(i, N)rep(j, 2) memo[i][j] = -1;
  cout << (dp(0, -1, 'W') + dp(0, -1, 'B')) % MOD << endl;
}


Measured memory_bytes: 15872
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}
func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		h[i], _ = strconv.Atoi(sc.Text())
	}
	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = math.MaxInt32
	}
	dp[0] = 0
	for i := 1; i < n; i++ {
		for j := 1; j <= min(k, i); j++ {
			dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
		}
	}
	fmt.Println(dp[n-1])
}


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

N, K = map(int,input().split())
s = input().split() 
s = list(s[0])
renketu=[]
cnt=1
for i in range(1,N):
    if s[i] != s[i-1]:
        renketu.append(cnt)
        cnt=1
    else:
        cnt+=1
renketu.append(cnt)
cnt=0
ans=0
for i in range(len(renketu)):
    if i%2==1:
        cnt+=1
    if cnt <= K:
        ans+=renketu[i]
    else:
        ans+=renketu[i]-1
print(ans-1)
    

Measured memory_bytes: 49520
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,x,y,d[N];
int main(){
	scanf("%d%d",&n,&m);
	while (m--)scanf("%d%d",&x,&y),d[x]^=1,d[y]^=1;
	int cnt=0;
	for (int i=1;i<=n;i++)cnt+=d[i];
	if (cnt>1)puts("NO");
	else puts("YES");
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a1[105]={};
    long long a2[105],ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a1[i];
        if(i!=0)
            a1[i]+=a1[i-1];
    }
    for(int i=0;i<n;i++){
        cin>>a2[i];
    }
    for(int i=n-2;i>=0;i--){
        a2[i]+=a2[i+1];
    }
    for(int i=0;i<n;i++){
        if(ans<a1[i]+a2[i])
            ans=a1[i]+a2[i];
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

int map[4];
int now, out;

void changeMap(string direction) {
	int tmp;
	if(direction == "North") {
		tmp = out;
		out = map[3];
		map[3] = now;
		now = map[0];
		map[0] = tmp;
	} else if(direction == "East") {
		tmp = out;
		out = map[2];
		map[2] = now;
		now = map[1];
		map[1] = tmp;
	} else if(direction == "West") {
		tmp = out;
		out = map[1];
		map[1] = now;
		now = map[2];
		map[2] = tmp;
	} else if(direction == "South") {
		tmp = out;
		out = map[0];
		map[0] = now;
		now = map[3];
		map[3] = tmp;
	} else if(direction == "Right") {
		tmp = map[0];
		map[0] = map[2];
		map[2] = map[3];
		map[3] = map[1];
		map[1] = tmp;
	} else if(direction == "Left") {
		tmp = map[0];
		map[0] = map[1];
		map[1] = map[3];
		map[3] = map[2];
		map[2] = tmp;
	}
}

int main(void) {
	int num, count;
	string in;
	int i;

	while(true) {
		cin >> num;
		if(num == 0) { break; }
		map[0] = 2; map[1] = 4; map[2] = 3; map[3] = 5;
		now = 1; out = 6;
		count = now;
		for(i = 0; i < num; i++) {
			cin >> in;
			changeMap(in);
			count += now;
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
template<ll MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;
mint nCk(ll n, ll k) {
mint res=1;
for(ll i=0; i<k; i++){
res*=(ll)(n-i);
res/=(ll)(k-i);
}
return res;}
 
int main() {
ll x = 1;
ll n , a , b;
cin>>n>>a>>b;
ll z =n;
ll y = 2;
while(n){
if(n&1){
x = (x * y) % (ll)1000000007;}
y = y * y %  (ll)1000000007;
n /= 2;}
x--;
mint q = x;
//cout << q <<" " << nCk(z,a) << " " << nCk(z,b) << endl;
q-=(nCk(z,a)+nCk(z,b));
cout << q << endl;}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void printv(vector<vector<int> > g){
    int si = g.size();
    for (int i = 0; i < si; ++i) {
        for (int j = 0; j < si; ++j) {
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
}

void printq(queue<int> que){
    int si = que.size();
    int tmp;
    queue<int> k = que;
    for (int i = 0; i < si; ++i) {
        tmp = k.front();
        cout << tmp << " ";
        k.pop();
    }
    cout << endl;
}

int main() {
    int v, e, s_tmp, t_tmp, tmp;
    cin >> v >> e;
    vector<vector<bool> > g(v, vector<bool> (v,0));
    vector<int> ans;
    vector<int> v_n(v, 0);
    for (int i = 0; i < e; ++i) {
        cin >> s_tmp >> t_tmp;
        g[s_tmp][t_tmp] = 1;
        ++v_n[t_tmp];
    }
    //printv(g);
    queue<int> que;
    for (int i = 0; i < v; ++i) {
        if(v_n[i] == 0) {
            que.push(i);
        }
    }
    while(!que.empty()){
        //printq(que);
        tmp = que.front();
        que.pop();
        ans.push_back(tmp);
        for (int i = 0; i < v; ++i) {
            if(g[tmp][i] == 1){
                g[tmp][i] = 0;
                --v_n[i];
                if(!v_n[i]) {
                    que.push(i);
                }
            }
        }
    }
    for (int i = 0; i < v-1; ++i) {
        cout << ans[i] << " " << endl;
    }
    cout << ans[v-1] << endl;
    return 0;
}




Measured memory_bytes: 15868
#include<cmath>
#include<string>
#include<fstream>
#include<iostream>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){
	int cnt=0;
	string s;
	cin >> s;
	if(s[0]=='1') cnt++;
	if(s[1]=='1') cnt++;
	if(s[2]=='1') cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256