akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define IFOR(i,a) for(int i=(a);;i++)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INPUT \
FILE *fp; \
fp=fopen("input.text","r");



int main() {
    int N,M;
    cin >> N >> M;
    
    int amat[N][M],bmat[M];
    
    REP(row, N){
        REP(column, M) cin >> amat[row][column];
    }
    
    REP(row, M) cin >> bmat[row];
  
    
    
    REP(row, N){
        int sum=0;
        REP(column, M) {
          sum+=amat[row][column]*bmat[column];
        }
          
        cout << sum << endl;
    }
    return 0;
}





Measured memory_bytes: 3140
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn];
vector <int> ans[maxn];
int b[maxn],cnt;

int main()
{
	scanf("%s",s+1); int len=strlen(s+1),f=0;
	if(s[1]!='1'||s[len]!='0') f=1;
	for(int i=1;i<=len;i++) if(s[i]-'0'+s[len-i]-'0'==1) f=1;
	if(f==1) {puts("-1"); return 0;}
	int lst=2;
	b[++cnt]=1;
	printf("%d %d\n",2,1);
	for(int i=2;i<=len-1;i++)
	{
		if(s[i]=='1')
		{
			for(int j=lst+1;j<=i;j++) printf("%d %d\n",lst,j);
			printf("%d %d\n",lst,i+1); lst=i+1;
		}
	}
	//printf("%d %d\n",len,lst);
	return 0;
}

Measured memory_bytes: 26880
#include <stdio.h>

int main(){

  long long int x,r,tmp,count,ans;

  scanf("%lld",&x);

  if(x<=6){
    ans=1;
  }else if(x>6 && x<=11){
    ans=2;
  }else{
    tmp=x/11;
    r=x%11;
    if(r==0){
      count=0;
    }else if(r<=6){
      count=1;
    }else{
      count=2;
    }
    ans=tmp*2+count;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;
int main() {
 int64_t Q,H,S,D,N;
 cin>>Q>>H>>S>>D>>N;
 if(min({4*Q,2*H,S,D/2})==4*Q){cout<<N*4*Q<<endl;}
 if(min({4*Q,2*H,S,D/2})==2*H){cout<<N*2*H<<endl;}
 if(min({4*Q,2*H,S,D/2})==S){cout<<N*S<<endl;}
 if(min({4*Q,2*H,S,D/2})==D/2){
   if(N%2==0){cout<<D*N/2<<endl;}
     else{cout<<D*(N/2)+min({4*Q,2*H,S})<<endl;}
 }
 return 0;}

Measured memory_bytes: 256
import sys

s = input()
t = input()

# atoz = [chr(i) for i in range(97,97+26)]


for i in range(len(s)):
    if s[i] == t[i]:
        continue
    else:
        s_tmp = s
        s = s.translate(s.maketrans({s[i]:t[i], t[i]:s[i]}))
        if s_tmp[:i] != s[:i]:
            print("No")
            sys.exit()
        else:
            pass


if s == t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4400
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

char s[11] = {'\0'};

void split(char *ptr, char* ptr2, int factor, int length){ /*ptrはコピー先、ptr2は切り取りコピーの素配列、factorは開始位置、lengthは切り出し個数。*/
	int num = 0;
	for(int a = factor; a < factor+length; a++) ptr[num++] = ptr2[a];
}

long long int add(char *ptr){
	long long int ans = atoll(ptr);
	int size = strlen(ptr);
	for(int a = 1; a < size; a++){
		char tmp[11] = {'\0'};
		char tmp2[11] = {'\0'};
		split(tmp,ptr,0,a);
		ans += atoll(tmp)*powl(2,size - a - 1);
		split(tmp2,ptr,a,size-a);
		ans += add(tmp2);
	}
	return ans;
}

int main(void){
	long long int result = 0; /*factorは配列の長さとする。*/
	scanf("%s",s);
	result = add(s);
	printf("%lld\n",result);
	return 0;
}

Measured memory_bytes: 128
import sys

raw_input = sys.stdin.readline

f = lambda : raw_input().rstrip()    
f1 = lambda : f().split()
f2 = lambda t: map(t,f1())

def main1():
    a,b = f2(int)
    if (a+b)%2 == 0:
       print (a+b)/2
    elif a == b:
       print 0
    else:
       print "IMPOSSIBLE"

def main2():
    n = int(f())
    a = f2(int)
    b = sorted(a)
    m = 0
    for i in xrange(n):
        if a[i] != b[i]:
            m = m + 1
    if m<=2:
        print "YES"
    else:
        print "NO"

def main3():
    n = int(f())
    a = f2(int)
    b = f2(int)
    ans = 0
    for i in xrange(n):
        if a[i] >= b[i]:
            ans = ans + b[i]
        elif a[i] < b[i] :
            ans = ans + a[i]
            b[i] = b[i] - a[i]
            ans = ans + min(a[i+1], b[i])
            a[i+1] = max(0,a[i+1] - b[i])  
    print ans 
 
def main4():
    pass
    
    
if __name__ == "__main__":
    main3()

Measured memory_bytes: 14548
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()



ll b2(ll a)
{
    ll t = 0;
    while(!(a%2))
        t++, a/=2;
//        cout << t << endl;
    return t;

}


int main()
{
        ll n;
        cin >> n;
        ll m = LONG_MAX;

        while(n--)
        {
            ll r;
            cin >> r;
            m = min(m, b2(r));
        }
        cout << m;

    return 0;
}


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


int main() {
  // 科目の数Nを受け取る
  int N, A;
  cin >> N;
  A = 0;

  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  for (int m = 0; m < N; m++) {
    if (m == 0) {
      A++;
    }
    else if (d.at(m) < d.at(m - 1)) {
      A++;
    }
    
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define endl '\n'
#define MAX 200005
#define pb push_back
#define mk make_pair
#define ll long long

int main() {
    	
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    if(sum >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win"  << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
s = 1
for i in range(-100,101):
    if X < i <= Y and max(x) < i <= min(y):
        s = 0
print(["No War","War"][s])


Measured memory_bytes: 9172
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i<n; i++){
      a[i] = sc.nextInt();
    }
    int count = selectionSort(a,n);
    for(int i = 0; i<n; i++){
      if(i == n-1){
        System.out.println(a[i]);
      }else{
        System.out.print(a[i] + " ");
      }
    }
    System.out.println(count);
  }

  public static int selectionSort(int[] a, int n){
    int count = 0;
    for(int i = 0; i<n; i++){
      int minj = i;
      for(int j = i; j<n; j++){
        if(a[j]<a[minj]){
          minj = j;
        }
      }
      int free = a[i];
      a[i] = a[minj];
      a[minj] = free;
      if(a[i] != a[minj]){
        count++;
      }
    }
    return count;
  }
}

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

P =list(map(int, input().split()))
Q =list(map(int, input().split()))


def kai(i):
    ret = 1
    while i > 0:
        ret *= i
        i -= 1
        
    return ret


def count(l):
    n = len(l)
    i = 0

    ans = 0
    while i < n:
        kake = kai(n - i - 1)
        ans += (l[i] - 1) * kake
        now = l[i]
        for num in range(len(l)):
            if l[num] > now:
                l[num] -= 1
            
        i += 1
    
    return ans


print(abs(count(P) - count(Q)))




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a[51],b[51],c[51],d[51],n,m;
	cin>>n>>m;
	lp3(i,1,n+1){
		cin>>a[i]>>b[i];
	}
	lp3(i,1,m+1){
		cin>>c[i]>>d[i];
	}
	lp3(i,1,n+1){
		int an = INT_MAX,ans=0;
		lp3(j,1,m+1){
			if(abs(a[i]-c[j])+abs(b[i]-d[j])<an){
				ans=j;
				an = abs(a[i]-c[j])+abs(b[i]-d[j]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    map<int, int> ma;
    bool ok = true;
    for (int i = 0; i < m; i++) {
        int s, c; cin >> s >> c;
        if (ma.count(s) && ma[s] != c) ok = false;
        ma[s] = c;
    }
    if (n != 1 && ma.count(1) && ma[1] == 0) ok = false;
    if (n != 1 && !ma.count(1)) ma[1] = 1;
    string s;
    for (int i = 1; i <= n; i++) {
        s += (char) ('0' + ma[i]);
    }
    if (ok) cout << s << "\n";
    else cout << -1 << "\n";
    return 0;
}

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

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}


int main()
{
	ll n;
	cin >> n;
	cout << n*(n - 1) / 2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3000+10;

int n,t;
int a[maxn];
int b[maxn];
int f1[maxn][maxn]={0},f2[maxn][maxn]={0};
int kq;

int main(){
    cin>>n>>t;
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
    for(int i=1;i<=n;i++)
        for(int j=0;j<=t;j++){
            f1[i][j]=f1[i-1][j];
            if (j>=a[i]) f1[i][j]=max(f1[i][j],f1[i-1][j-a[i]]+b[i]);
        }
    for(int i=n;i>=1;i--)
        for(int j=0;j<=t;j++){
            f2[i][j]=f2[i+1][j];
            if (j>=a[i]) f2[i][j]=max(f2[i][j],f2[i+1][j-a[i]]+b[i]);
        }
    kq=0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=t-1;j++)
            kq=max(kq,b[i]+f1[i-1][j]+f2[i+1][t-1-j]);
    cout<<kq;
}


Measured memory_bytes: 70912
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*5001 for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1][:X[p]+1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')

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

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n){
        int c;
        cin >> c;
        mp[c]++;
    }

    int L1=0, L2=0;
    for(auto u:mp){
        if(u.second>=2 && u.first>L1){
            L1 = u.first;
        }
    }
    mp[L1] -= 2;

    for(auto u:mp){
        if(u.second>=2 && u.first>L2){
            L2 = u.first;
        }
    }
    cout << (ll)L1*L2 << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d, score;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26)), pos(26);

int get_score(vector<int> t){
    vector<int> pos(26, 0);
    int ans = 0;
    rep(i, t.size()){
        int l = i + 1 - pos[t[i]];
        ans -= (l * (l-1) / 2) * c[t[i]];
        ans += s[i][t[i]];
        pos[t[i]] = i+1;
    }
    rep(i, 26){
        int l = t.size() + 1 - pos[i];
        ans -= (l * (l-1) / 2)* c[i];
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    vector<int> t, pos(26, 0);
    rep(i, d){
        int max_score = -mod;
        int best_j = -1;
        rep(j, 26){
            t.push_back(j);
            int score = get_score(t);
            if(max_score < score){
                best_j = j;
                max_score = score;
            }
            t.pop_back();
        }
        t.push_back(best_j);
    }
    vector<int> ans = t;
    double start_temp = 100, end_temp = 10;
    int current_max_score = get_score(t);
    while(clock() < 1.95 * CLOCKS_PER_SEC){
        int D = rand() % d, q = rand() % 26;
        int old = t[D];
        int olds = get_score(t);
        t[D] = q;
        int score = get_score(t);
        double temp = start_temp + (end_temp - start_temp) * clock() / (1.95 * CLOCKS_PER_SEC);
        double prob = exp((olds - score)/temp);

        if(chmax(current_max_score, score)){
            ans = t;
        }else{
            if(prob <= (double)(rand() % 10000) / 10000){
                t[D] = old;
            }
        }

        if(prob >= ((rand()%inf)/(double)inf))t[D] = old;
    }
    rep(i, d)cout << ans[i]+1 << endl;
}


Measured memory_bytes: 3784
def f(a,n):
    for j in range(n):
        aa = ""
        s = a[0]
        c = 1
        for i in range(1,len(a)):
            if a[i] == s:
                c += 1
            else:
                aa += str(c) + s
                s = a[i]
                c = 1
        a = aa + str(c) + s
    return a
     
while 1:
    n = input()
    if n == 0: break
    a = raw_input()
    print f(a,n)

Measured memory_bytes: 7068
n=int(input())
f=[]
for i in range(n):
    fn=[int(x) for x in input().rstrip().split()]
    f.append(fn)

p=[]
for i in range(n):
    pn=[int(x) for x in input().rstrip().split()]
    p.append(pn)

ans=-float('inf')
for i in range(1,2**10):
    now=0
    for s in range(n):
        cnt=0
        for j in range(10):
            if ((i>>j) & 1) and f[s][j]==1:
                cnt+=1
        now+=p[s][cnt]
    ans=max(ans,now)
print(ans)

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

namespace _0075
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == null)
                {
                    break;
                }
                double[] x = s.Split(',').Select(double.Parse).ToArray();
                if (x[1] / x[2] / x[2] >= 25)
                {
                    Console.WriteLine(x[0]);
                }
            }
        }
    }
}

Measured memory_bytes: 9360
package main

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

type str []byte

func (s str) Len() int           { return len(s) }
func (s str) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s str) Less(i, j int) bool { return s[i] < s[j] }
func (s str) String() string     { return string(s) }

func main() {
	r := bufio.NewReader(os.Stdin)
	var s, t string
	fmt.Fscan(r, &s)
	fmt.Fscan(r, &t)

	sd := str(s[:])
	td := str(t[:])
	sort.Sort(sd)
	sort.Sort(sort.Reverse(td))

	if sd.String() < td.String() {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 640
N = int(input())
h = [int(x) for x in input().split()]

def com(x, y, h2, h1, h0):
    if x + abs(h2 - h0) > y + abs(h1 - h0):
        return y + abs(h1 - h0)
    else:
        return x + abs(h2 - h0)

DP = [0, abs(h[0] - h[1])]
for i in range(2, N):
    DP.append(com(DP[i - 2], DP[i - 1], h[i - 2], h[i - 1], h[i]))
print(DP[N - 1])

Measured memory_bytes: 13928
n, k = map(int, input().split())
l = [0]*n
for _ in range(n):
  l[_] = int(input())
l.sort()

ans = 10**9+1
for i in range(n-k+1):
  d = l[i+k-1]-l[i]
  ans = min(ans, d)
print(ans)

Measured memory_bytes: 45056
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <class T>
bool uax(T&a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool uin (T&a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();
    
    int n, k, q;
    cin >> n >> k >> q;
    
    vector <int> mp(n, k - q);
    
    for (int i = 1; i <= q; ++ i) {
   		int x;
   		cin >> x;
   		++mp[x - 1];
    }
    
    for (auto to : mp) {
    	cout << (to > 0?"Yes\n":"No\n");
    }
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    return 0;
}


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

int n; 
int sum;
int main(){
  cin >> n;
  vector<int> w(n);
  rep(i, n){
    cin >> w.at(i);
    sum += w.at(i);
  }
  int fs = 0;
  int dif = sum;
  int ans = 1e6;
  rep(i, n){
    fs += w.at(i);
    dif = abs(sum - 2*(fs));
    ans = min(ans, dif);
  }
  cout << ans << endl;
  
  
  
  
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 500000

typedef struct{
  int key, left, right;
}Node;

Node tree[N+1];
int size;

void insert(int x){
  int p = 0;
  while(1){
    if(x < tree[p].key){
      if(tree[p].left == -1){
        tree[p].left = size;
        tree[size++].key = x;
        break;
      }else p = tree[p].left;
    }else{
      if(tree[p].right == -1){
        tree[p].right = size;
        tree[size++].key = x;
        break;
      }else p = tree[p].right;
    }
  }
}

void inorder(int p){
  if(tree[p].left != -1) inorder(tree[p].left);
  printf(" %d", tree[p].key);
  if(tree[p].right != -1) inorder(tree[p].right);
}

void preorder(int p){
  printf(" %d", tree[p].key);
  if(tree[p].left != -1) preorder(tree[p].left);
  if(tree[p].right != -1) preorder(tree[p].right);
}

int find(int p, int x){
  if(tree[p].key == x) return 1;
  if(x < tree[p].key && tree[p].left != -1) if(find(tree[p].left, x)) return 1;
  if(tree[p].key < x && tree[p].right != -1) if(find(tree[p].right, x)) return 1;
  return 0;
}

main(){
  int n, i, first;
  first = 1;
  scanf("%d", &n);
  for(i=0;i<=n;i++) tree[i].key = tree[i].left = tree[i].right = -1;
  size = 0;
  while(n--){
    char str[100];
    scanf("%s", str);
    if(!strcmp(str, "insert")){
      int in;
      scanf("%d", &in);
      if(first){
        tree[size++].key = in;
        first = 0;
      }
      else insert(in);
    }else if(!strcmp(str, "find")){
      int in;
      scanf("%d", &in);
      printf("%s\n", (find(0, in) ? "yes" : "no"));
    }else{
      inorder(0);
      printf("\n");
      preorder(0);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 6284
from functools import reduce


def prime_factor(n):
  if n == 1:
    return [(1, 1)]
  results = []
  for i in range(2, n + 1):
    if n % i == 0:
      c = 0
      while n % i == 0:
        n //= i
        c += 1
      results.append((i, c))
  return results


def count_divisors(n):
  pf = prime_factor(n)
  return reduce(lambda x, y: x * y, [x[1] + 1 for x in pf])


if __name__ == "__main__":
  N = int(input())
  count = 0
  for i in range(1, N + 1, 2):
    if count_divisors(i) == 8:
      count += 1

  print(count)


Measured memory_bytes: 3572
// 本番にて
//   最小値を固定して考えるところまでは思いついたが、その後どうしていいかわからなかった

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> As(N);
    set<int> seen;

    REP(n, N) {
        cin >> As[n];
        seen.insert(As[n]);
    }

    // 最小値を固定する
    int ans = 1e9 + 10;
    vector<int> tmp;
    for (auto mn : seen) {
        vector<vector<int>> nums;
        int sum = 0;
        for (auto a : As) {
            if (a < mn) {
                if (SIZE(tmp) >= K) {
                    nums.push_back(tmp);
                }
                tmp.clear();
            }
            else {
                tmp.push_back(a);
            }
        }

        if (SIZE(tmp) >= K) nums.push_back(tmp);
        tmp.clear();

        for (auto num : nums) {
            sum += (SIZE(num) - K + 1);
        }
        if (sum < Q) continue;

        vector<int> sorted;
        for (auto num : nums) {
            sort(ALL(num));
            auto len = SIZE(num);
            REP(i, len - K + 1) {
                sorted.push_back(num[i]);
            }
        }
        sort(ALL(sorted));
        auto mx = sorted[Q - 1];
        ans = min(ans, mx - mn);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
n = gets.to_i
h_arr = gets.split.map(&:to_i)

prev_h = 0
current_step = 0
max_step = 0
h_arr.each do |h|
  if prev_h >= h
    current_step += 1
  else
    max_step = current_step if max_step < current_step
    current_step = 0
  end
  prev_h = h
end
max_step = current_step if max_step < current_step
puts max_step

Measured memory_bytes: 8580
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll A, B, C;
  cin >> A >> B >> C;
  cout << min(A + B + 1, C) + B << rt;
}

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

using namespace std;

typedef struct {
	int a, b, c;
} fuku_t;

int d, n;

int t[200];
fuku_t fuku[200];

int dp[200][200];

int main()
{
	cin >> d >> n;

	for (int i = 0; i < d; ++i) cin >> t[i];

	for (int i = 0; i < n; ++i) scanf("%d %d %d", &fuku[i].a, &fuku[i].b, &fuku[i].c);

	for (int i = 0; i < n; ++i) if (fuku[i].a <= t[1] && t[1] <= fuku[i].b) {
		for (int j = 0; j < n; ++j) if (fuku[j].a <= t[0] && t[0] <= fuku[j].b) {
			dp[1][i] = max(dp[1][i], abs(fuku[i].c - fuku[j].c));
		}
	}

	for (int i = 2; i < d; ++i) {
		for (int j = 0; j < n; ++j) if (fuku[j].a <= t[i] && t[i] <= fuku[j].b) {
			for (int k = 0; k < n; ++k) if (fuku[k].a <= t[i - 1] && t[i - 1] <= fuku[k].b) {
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(fuku[k].c - fuku[j].c));
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < n; ++i) ans = max(ans, dp[d - 1][i]);

	printf("%d\n", ans);
}

Measured memory_bytes: 1388
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0126

"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline




def solve(data):
    status = [[' '] * 9 for _ in range(9)]

    # ?¨???????????????§??????
    for y, row in enumerate(data):
        freq = defaultdict(int)
        for i, n in enumerate(row):
            if n in freq:
                freq[n].append(i)
            else:
                freq[n] = [i]
        for k, v in freq.items():
            if len(v) > 1:
                for ind in v:
                    status[y][ind] = '*'

    # ?????????????????§??????
    for x in range(9):
        freq = defaultdict(int)
        for y in range(9):
            n = data[y][x]
            if n in freq:
                freq[n].append(y)
            else:
                freq[n] = [y]
        for k, v in freq.items():
            if len(v) > 1:
                for ind in v:
                    status[ind][x] = '*'

    # 3x3????????§??????
    for y in range(0, 9, 3):
        for x in range(0, 9, 3):
            freq = defaultdict(int)
            for yy in range(3):
                for xx in range(3):
                    n = data[y+yy][x+xx]
                    if n in freq:
                        freq[n].append((x+xx, y+yy))
                    else:
                        freq[n] = [(x+xx, y+yy)]

            for k, v in freq.items():
                if len(v) > 1:
                    for xx, yy in v:
                        status[yy][xx] = '*'

    for y in range(9):
        for x in range(9):
            print('{}{}'.format(status[y][x], data[y][x]), end='')
        print()


def main(args):
    n = int(input())
    for i in range(n):
        data = [[int(x) for x in input().split()] for _ in range(9)]
        result = solve(data)
        if i != n-1:
            print()



if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8304
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	vector<pair<pair<string, int>, int> > a(n);
	vector<int> b(n);
	for (int i=0; i<n; ++i){
		cin>>a[i].first.first>>a[i].first.second;
		a[i].second = i;
		a[i].first.second = -a[i].first.second;
	}
	sort(a.begin(), a.end());
	for (int i=0; i<n; ++i) cout<<a[i].second + 1<<"\n";
	return 0;
}


Measured memory_bytes: 256
import core.stdc.stdio;
import std.algorithm;
   
char[][] mapdata;
bool[] visited;
int[3][] queue;
int w,h,n;
   
int len(int[2] p1,int[2] p2){
 visited[] = false;
 queue[0]=[p1[0],p1[1],0];
 visited[p1[0]*w+p1[1]] = true;
 int[] dx = [0,-1,0,1];
 int[] dy = [-1,0,1,0];
 int qc=1;
 for(int i=0;i<w*h;i++){
  int y=queue[i][0];
  int x=queue[i][1];
  int s=queue[i][2];
  if(y==p2[0]&&x==p2[1])
   return s;
  for(int k=0;k<4;k++){
   int ny = y+dy[k];
   int nx = x+dx[k];
   if(0<=ny&&ny<h&&0<=nx&&nx<w&&mapdata[ny][nx]!='X'&&!visited[ny*w+nx]){
    visited[ny*w+nx]=true;
    queue[qc++] = [ny,nx,s+1];
   }
  }
 }
 return 114514;
}
   
void main(){
 scanf("%d%d%d",&h,&w,&n);
 int[2][] poses = new int[2][n+1];
 mapdata = new char[][h];
 visited = new bool[w*h];
 queue = new int[3][w*h];
 for(int i=0;i<h;i++){
  mapdata[i] = new char[w+1];
  scanf("%s",mapdata[i].ptr);
  foreach(int j,c;mapdata[i]){
   if(c=='S')
    poses[0] = [i,j];
   else if('1'<=c&&c<='9')
    poses[c-'0'] = [i,j];
  }
 }
 int ans=0;
 for(int i=0;i<n;i++)
  ans += len(poses[i],poses[i+1]);
 printf("%d\n",ans);
}

Measured memory_bytes: 15980
package main

import (
	"fmt"
	"sort"
)

func main() {
	a := make([]int, 3)
	fmt.Scan(&a[0], &a[1], &a[2])
	sort.Ints(a)

	ans := 0
	d1 := a[2] - a[1]
	ans += d1

	d2 := a[2] - (a[0] + d1)
	ans += d2 / 2
	if d2%2 != 0 {
		ans += 2
	}

	fmt.Println(ans)
}


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int n;
	cin >> n;
	if (n % 1000 == 0) cout << 0 << endl;
	else cout << 1000 - (n % 1000) << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	int A,B;
	cin>>A>>B;
	cout<<(A-1)*(B-1)<<endl;
	
    return 0;
}


Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll f(ll x, ll n)
{
    ll t = (1LL << (n + 1)) - 3;
    ll y = (t + 1) / 2;
    if (n == 1)
        return 1;
    if (x == 1)
        return 0;
    if (x == t)
        return ((1LL << n) - 1);
    if (x == y)
        return (1LL << (n - 1));
    if (x > y)
        return ((1LL << (n - 1)) + f(x - y, n - 1));
    else
        return (f(x - 1, n - 1));
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, x;
    cin >> n >> x;
    cout << f(x, n + 1);
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int x,a,b;
  cin >> x >> a >> b;

  cout << (abs(x-a) < abs(x-b) ? 'A' : 'B') << endl;

}




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

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

  string n;
  cin >> n;
  string ans;
  rep(i, 3) {
    if (n[i] == '1') {
      ans += '9';
    } else {
      ans += '1';
    }
  }

  cout << ans << "               " << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
G=[[] for _ in range(1+n)]
for i in range(m):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)

from itertools import permutations
lis=[i for i in range(2,n+1)]
permu=list(permutations(lis))

ans=0
for pl in permu:
    c=1
    j=1
    for i in pl:
        if j in G[i]:
            j=i
        else:
            c=0
            break
    ans+=c
print(ans)

Measured memory_bytes: 39920
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

ll gcd_ll(ll a, ll b)
{
	if (a == 0)
		return 0;
	if (b == 0)
		return 0;
	ll x;
	while (1)
	{
		x = a % b;
		if (x == 0)
			return b;
		else
		{
			a = b;
			b = x;
		}
	}
}

int main() {
	ll K;
	cin >> K;
	ll ans = 0;
	for (ll a = 1; a <= K; a++) {
		for (ll b = 1; b <= K; b++) {
			for (ll c = 1; c <= K; c++) {
				ans += gcd_ll(gcd_ll(a, b), c);
			}
		}
	}


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

Measured memory_bytes: 3648
#include <stdio.h>
 
int main(void)
{
  int n = 0;
  int i;
  int x = 0;
   
  scanf("%d", &n);
   
  for(i = 1; i <= n; i++){
    x = i;
     
    if(x % 3 == 0)
      printf(" %d", i);
    else
      do{
    if(x % 10 == 3){
      printf(" %d", i);  
      break;
    }
      }while(x /= 10);
  }
  putchar('\n');
   
  return 0;
}

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

string toUpper(string s){
    string t=s;
    for (int i=0; i<s.size(); i++){
        t[i]=toupper(s[i]);
    }
    return t;
}

int main(){
    string target,source;
    int cnt=0;
    cin >> target;
    target=toUpper(target);
    
    while(1){
        cin >> source;
        if(source=="END_OF_TEXT") break;
        if(toUpper(source)==target) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'
 
int main()
{
    fastio;
    int ans = 0;
    string s,t;
    cin>>s>>t;

    rep(i,s.length(),0){
        ans+=(s[i] != t[i]);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3796
N = int(input())
A = list(map(int, input().split()))

flag = False
el = []
for i in range(N):
  if A[i]%2 == 0:
    el.append(A[i])

flag = True
for val in el:
  if val%3 != 0 and val%5 != 0:
    flag = False

if flag:
  print("APPROVED")
else:
  print("DENIED")

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int n,m;
int a[N],u[N],us[N],db[N],sn[N];
int ans;

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

        for (int i = 1; i <= n; i ++) {
                cin >> a[i];
                u[a[i] % m] ++;
                us[a[i]] ++;
        }
        for (int i = 1; i <= n; i ++) {
                if (us[a[i]]) {
                        db[a[i] % m] += (us[a[i]] - (us[a[i]] % 2));
                        sn[a[i] % m] += us[a[i]] % 2;
                        us[a[i]] = 0;
                }
        }
        for (int i = 1; i < (m + 1) / 2; i ++) {
                int f = u[i];
                int s = u[m - i];
                if (f < s) {
                        ans += f;
                        int p = min(0,sn[m - i] - f);
                        db[m - i] += p;
                        ans += (db[m - i] / 2);
                }
                else {
                        ans += s;
                        int p = min(0,sn[i] - s);
                        db[i] += p;
                        ans += (db[i] / 2);
                }
        }
        if (m % 2 == 0) {
                ans += (u[m / 2] / 2);
        }
        ans += (u[0] / 2);

        cout << ans << endl;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


int main() {
	string S;
	cin >> S;

	int ans = 0;
	rep(i, 0, 6) {
		ans += (S[i] == '1' ? 1 : 0);
	}
	cout << ans;
	return 0;
}

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

using namespace std;
using int64 = long long;

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

    for (int i=0; i<t.size(); i++) {
        if (t[i] == '?')
            t[i] = 'D';
    }

    cout << t << endl;
}


Measured memory_bytes: 3380
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto edges = new long[][](N);
	foreach (i; 0..N-1)
	{
		auto a = RD-1;
		auto b = RD-1;
		edges[a] ~= b;
		edges[b] ~= a;
	}
	auto c = RDR.ARR;
	auto index = MAKE_IDX!"a > b"(c);
	
	auto pos = MIN_POS!"a.length > b.length"(edges);
	long[] open = [pos];
	
	auto ans = new long[](N);
	ans[pos] = c[index[0]];
	long ans0;
	auto ci = 1;
	while (!open.empty)
	{
		auto n = open.front; open.popFront;
		long[] tmpTo;
		foreach (to; edges[n])
		{
			if (ans[to] != 0) continue;

			tmpTo ~= to;
		}
		tmpTo.sort!((long a, long b) => edges[a].length > edges[b].length)();
		foreach (e; tmpTo)
		{
			ans[e] = c[index[ci]];
			ans0 += min(ans[e], ans[n]);
			++ci;
			open ~= e;
		}
	}

	writeln(ans0);
	ans.map!(to!string).join(" ").writeln;
	stdout.flush();
	debug readln();
}

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

#include<stdlib.h>
#include<iostream>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;

int main()
{
IOS;
int t;
cin>>t;
if(t%10==2||t%10==4||t%10==5||t%10==7||t%10==9)
	cout<<"hon";
else if(t%10==0||t%10==1||t%10==6||t%10==8)
	cout<<"pon";
else
	cout<<"bon";




return 0;
}

Measured memory_bytes: 3604
n = gets.to_i
s = gets.split.map(&:to_i)
_ = gets.to_i
t = gets.split.map(&:to_i)

sum = 0

def binary_search(s, n, key)
  left = 0
  right = n

  while left < right
    mid = (left + right) / 2

    if key == s[mid]
      return true
    elsif key < s[mid]
      right = mid
    else
      left = mid + 1
    end
  end
  false
end

t.each do |key|
  sum += 1 if binary_search(s, n, key)
end
puts sum


Measured memory_bytes: 15348
//42
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int w,h;cin>>w>>h,w|h;){
    int g[7][7];
    int wx,wy,cx,cy,gx,gy;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>g[i][j];
	if(g[i][j]==2){
	  cx=j;
	  cy=i;
	}else if(g[i][j]==4){
	  wx=j;
	  wy=i;
	}else if(g[i][j]==3){
	  gx=j;
	  gy=i;
	}
      }
    }
    int d[7][7][7][7];
    fill(d[0][0][0],d[7][0][0],1<<30);
    d[cy][cx][wy][wx]=0;
    for(int i=0;i<w*w*h*h;i++){
      for(int j=0;j<h;j++){
	for(int k=0;k<w;k++){
	  for(int l=0;l<h;l++){
	    for(int m=0;m<w;m++){
	      for(int n=0;n<4;n++){
		int dd[]={0,1,0,-1,0};
		int ny=l+dd[n];
		int nx=m+dd[n+1];
		if(0<=nx&&nx<w&&0<=ny&&ny<h&&g[ny][nx]!=1){
		  if(ny!=j||nx!=k){
		    d[j][k][ny][nx]=min(d[j][k][ny][nx],d[j][k][l][m]);
		  }else{
		    int nny=ny+dd[n];
		    int nnx=nx+dd[n+1];
		    if(0<=nny&&nny<h&&0<=nnx&&nnx<w&&g[nny][nnx]!=1){
		      d[nny][nnx][ny][nx]=min(d[nny][nnx][ny][nx],d[j][k][l][m]+1);
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
    }
    int me=*min_element(d[gy][gx][0],d[gy][gx+1][0]);
    cout<<((me==1<<30)?-1:me)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUF_SIZE 1000000
int main(void) {
  char line[BUF_SIZE];
  FILE *fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;

  int num;
  sscanf(line, "%d", &num);
  int i;

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  int map[2] = {0};
  for(i = 0; i < num; i++) {
    char *buf = strtok(tmpbuf, " ");
    int n = strtol(buf, NULL, 10);
    map[n%2]++;
    tmpbuf = NULL;
  }
  int flag = !(map[1]&1);
  printf("%s\n", flag ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 1152
n = int(input())
a = list(map(int, input().split()))
MOD = 998244353

max_a = max(a)
c = [0] * (max_a + 1)
for i in range(1, max_a + 1):
    c[i] = pow(i, MOD - 2, MOD)

for i in range(1, max_a):
    j = i
    while True:
        j += i
        if j <= max_a:
            c[j] -= c[i]
            c[j] %= MOD
        else:
            break

cnt = [0] * (max_a + 1)
for i in range(n):
   cnt[a[i]] += 1

ans = 0
for i in range(1, max_a + 1):
    tmp0 = 0
    tmp1 = 0
    j = i
    while True:
        if j <= max_a:
            tmp0 += cnt[j] * j
            tmp1 += cnt[j] * (j ** 2)
        else:
            break
        j += i
    tmp0 *= tmp0
    ans += (tmp0 - tmp1) * c[i]
    ans %= MOD

print((ans * pow(2, MOD - 2, MOD)) % MOD)

Measured memory_bytes: 94668
N = gets.chop.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)
ans = 0

N.times do |i|
  ans += B[A[i]-1]
  if i>0 && A[i]-A[i-1]==1
    ans += C[A[i-1]-1]
  end
end

print ans

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using Int = long long;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> E(N); // number of E in [0,i]
    E[0] = (S[0] == 'E');
    for (int i = 1; i < N; i++) {
        E[i] = E[i-1] + (S[i] == 'E');
    }
    int result = N;
    for (int i = 0; i < N; i++) {
        int score = (i == 0 ? 0 : i - E[i-1]) + E[N-1] - E[i];
        result = min(result, score);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1796