akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

template <class T>
struct Unionfindw {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // edge weight
  vector<T> weight;
  // constructor
  Unionfindw(int n = 1, T initialnum = 0) {
    stree(n + 1, initialnum);
  }
  // make and initialization
  void stree(int n = 1, T initialnum = 0) {
    par.resize(n);
    treerank.resize(n);
    weight.resize(n);
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      treerank[i] = 0;
      weight[i] = initialnum;
    }
  }
  // search root
  int root(int x) {
    if(par[x] == x) return x;
    int rx = root(par[x]);
    weight[x] += weight[par[x]];
    return par[x] = rx;
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }
  // calculate weight
  T calcw(int x) {
    root(x);
    return weight[x];
  }
  // add
  // x+w = y
  // already added, return 0
  bool uni(int x, int y, T w = 0) {
    w += calcw(x);
    w -= calcw(y);
    x = root(x);
    y = root(y);
    if(x == y) {
      if(calcdiff(x, y) != w) return 0;
      return 1;
    }
    if(treerank[x] < treerank[y]) {
      par[x] = y;
      weight[x] = -w;
    }
    else if(treerank[y] < treerank[x]) {
      par[y] = x;
      weight[y] = w;
    }
    else {
      par[y] = x;
      ++treerank[x];
      weight[y] = w;
    }
    return 1;
  }
  // calculate difference between x and y (y-x)
  // if not same tree, return 1
  T calcdiff(int x, int y) {
    if(!issame(x, y)) return -1;
    return calcw(y) - calcw(x);
  }
};
long long n, m;
Unionfindw<long long> uf;
bool ans = 1;

int main() {
  long long i, l, r, d;
  cin >> n >> m;
  uf = Unionfindw<long long>(n + 1);
  for(i = 0; i < m; ++i) {
    cin >> l >> r >> d;
    --l;
    --r;
    ans = uf.uni(l, r, d);
    if(!ans) break;
  }
  prians(ans);
  return 0;
}

Measured memory_bytes: 1792
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	std::map<int,int> mp;
	REP(i, 0, n){
		int a;
		scanf("%d", &a);
		mp[a]++;
	}
	int ans = 0;
	for(P p: mp){
		if(p.fi<=p.se) ans += p.se-p.fi;
		else ans += p.se;
	}
	printf("%d\n", ans);
	return 0;
}




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


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

	long long int a,b,c,k; cin >> a >> b >> c >> k;
	long long int ans ;
	if(k>0){
		ans = min(a,k);
		k-=a;
	}
	if(k>0){
		k -=b;
	}
	if(k>0){
		ans -= k;
	}
	cout << ans;
	
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;
int main() {
    int n;
    while(1){
        cin >>n;
        double a[n];
        if(n==0) break;
        double b=0;
    for (int i=0; i<n; i++) {
        cin>>a[i];
        b+=a[i];
    }
    double m=b/n;
    double c=0;
        for (int j=0; j<n; j++) {
            c += pow(m-a[j],2)/n;
        }
    printf("%.8f\n",sqrt(c) );
    }
}


Measured memory_bytes: 3196
// package agc.agc020;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int d = Math.abs(a-b);

        out.println(d % 2 == 0 ? "Alice" : "Borys");
        out.flush();
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

Measured memory_bytes: 23252
import math
from queue import Queue
import bisect

n = int(input())

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort()
c.sort()

sum = 0
for i in range(n):

    atemp = bisect.bisect_left(a,b[i])
    ctemp = n - bisect.bisect_right(c,b[i])
    sum += atemp * ctemp

print(sum)

Measured memory_bytes: 24664
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200000005
#define mod         1000000007
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,l,u,v,i,j,c,k,q,s,t;
    cin>>n>>m>>l;
    ll dis[n+1][n+1];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            dis[i][j]=mod;
        }
    }
    for(i=1;i<=m;i++){
        cin>>u>>v>>c;
        dis[u][v]=c;
        dis[v][u]=c;
    }
    for(k=1;k<=n;k++){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(dis[i][j]<=l){
                dis[i][j]=1;
            }
            else{
                dis[i][j]=mod;
            }
        }
    }
    for(k=1;k<=n;k++){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    cin>>q;
    while(q--){
        cin>>s>>t;
        if(dis[s][t]<mod){
            cout<<dis[s][t]-1;
        }
        else{
            cout<<-1;
        }
        cout<<endl;
    }
    
}

Measured memory_bytes: 1280
#include<cstdio>


int main(void)
{
	int a, b;

	while(scanf("%d%d", &a, &b)==2)
	{
		int ans='x';
		if(a+b==15) ans='+';
		if(a*b==15) ans='*';

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

	return 0;
}


Measured memory_bytes: 128
from fractions import gcd


def gcd_array(a):
    gg = gcd(a[0],a[1])

    for i in range(2, len(a)):
        gg = gcd(gg, a[i])
    return gg


n, x = (int(i) for i in input().split())

b = [abs(int(k) - x) for k in input().split()]

if len(b) == 1:
    print(b[0])
else:
    print(gcd_array(b))


Measured memory_bytes: 16280
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <unordered_map>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
#define Range(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;

int main() {
	REP(i, 12) {
		char c;
		scanf("%c", &c);
		printf("%c",c);
		if (i == 3) printf(" ");
	}
	printf("\n");
	return 0;
}

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

using namespace std;

string s;

int main()
{
  cin >> s;

  for (int i = 0; i < 26; i++) {
    int c = 0;
    deque<int> idx;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] - 'a' == i) {
        idx.push_back(j);
        c++;
      }
      if (c > 0 && 2 * c < j - idx.front() + 1) {
        idx.pop_front();
        c--;
      }
      if (c >= 2 && 2 * c > j - idx.front() + 1) {
        cout << idx.front()+1 << " " << j+1 << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1" << endl;
  
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = Integer.parseInt(sc.next())
    val y = Integer.parseInt(sc.next())
    val a = Integer.parseInt(sc.next())
    val b = Integer.parseInt(sc.next())
    val c = Integer.parseInt(sc.next())
    val p = LongArray(a)
    val q = LongArray(b)
    val r = LongArray(c)
    repeat(a){p[it] = sc.nextLong()}
    repeat(b){q[it] = sc.nextLong()}
    repeat(c){r[it] = sc.nextLong()}
    val aa = p.sortedDescending().take(x).toLongArray()
    val bb = q.sortedDescending().take(y).toLongArray()
    val apple = ( aa + bb + r).sortedDescending().take(x+y)
    var ans = 0L
    repeat(x+y){ans += apple[it]}
    println(ans)
}


Measured memory_bytes: 115168
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <vector>

#define rep(i, s, N) for(int i = s; i < N; i++)
#define YesNo(result) do {if (result) std::cout << "Yes" << '\n'; else std::cout << "No" << '\n';} while(0)
#define resetarr(arr, val) for(int i = 0; i < sizeof(arr) / 4; i++){ arr[i] = val; }

int main(int argc, char const *argv[]) {
  int list[3];
  std::cin >> list[0] >> list[1] >> list[2];
  std::sort(list, list+3);
  int first = list[2];
  int third = list[0];
  int second = list[1];

  int score = 0;

  if((first - second) % 2 != 0) {
    score += (first - second) / 2 + 1;
    second++;
    third++;
  } else {
    score += (first - second) / 2;
  }
  if((first - third) % 2 != 0) {
    score += (first - third) / 2 + 1 + 1;
  } else {
    score += (first - third) / 2;
  }


  std::cout << score << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib> 

using namespace std;

int main(void){

  int N,A,B;

  cin>>N;
  cin>>A;
  cin>>B;

  //cout << abs(B-A) << endl;

  if( abs((B-A))%2 == 1  ) cout << "Borys" << endl;
  else if( abs((B-A))%2 == 0  ) cout << "Alice" << endl;  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ab = a * b, cd = c * d;
  if (ab > cd)
    cout << ab << endl;
  else if (ab < cd)
    cout << cd << endl;
  else
    cout << ab << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
	cout << ((a[x] == a[y]) ? "Yes" : "No") << endl;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = (n-2)/(k-1) + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(n) for n in input().split()]

from fractions import gcd
L = [0]*(N+1)
R = [0]*(N+1)
ans = 0
for i in range(N):
    L[i] = gcd(L[i-1],A[i])
for i in reversed(range(N)):
    R[i] = gcd(R[i+1],A[i])
for i in range(N):
    if gcd(L[i-1],R[i+1]) > ans:
        ans = gcd(L[i-1],R[i+1])
print(ans)

Measured memory_bytes: 14060
#include <stdio.h>
#include <stdlib.h>

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main() {
  int number_of_sticks, number_k, i, sum = 0;
  scanf("%d %d", &number_of_sticks, &number_k);
  int stick_length[number_of_sticks];
  for(i = 0; i < number_of_sticks; i++) {
    scanf("%d", &stick_length[i]);
  }
  qsort(stick_length, number_of_sticks, sizeof(int), desc);
  for(i = 0; i < number_k; i++) {
    sum += stick_length[i];
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 128
n=int(input())
S=[0]*4
for i in range(n):
  s=input()
  if s=="AC":
    S[0]+=1
  elif s=="WA":
    S[1]+=1
  elif s=="TLE":
    S[2]+=1
  else:
    S[3]+=1

print("AC x "+str(S[0]))
print("WA x "+str(S[1]))
print("TLE x "+str(S[2]))
print("RE x "+str(S[3]))

Measured memory_bytes: 9212
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==1){
    cout<<"Hello World"<<endl;
  }
  else{
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main = do
  [_,x] <- map read . words <$> getLine
  as <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
  print (candies x as)

candies x = fst . foldl' (eat x) (0,0)

eat x (acc,rest) a = let n = max 0 (rest+a-x) in (acc+n, a-n)

Measured memory_bytes: 34428
N = int(raw_input())
for i in range(N):
    lis = raw_input().split(' ')
    ans = []
    for st in lis:
        if 'Hoshino' in st:
            while 'Hoshino' in st:
                s = st.find('Hoshino')
                st = st[:s]+'Hoshina'+st[s+7:]
            else:
                ans.append(st)
        else:
            ans.append(st)
    else:
        print ' '.join(ans)

Measured memory_bytes: 4208
#!/usr/bin/env python3
_, *a = map(int, open(0).read().split())
a.sort()
p = [0] * a[-1]
for i in a:
    for j in range(1, a[-1] // i + 1):
        p[j * i - 1] += j
print(sum(i == 1 for i in p))


Measured memory_bytes: 121656
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.ArrayDeque

fun resolveOp(lhs: Int, op: String, rhs: Int): Int =
        when (op) {
            "+" -> lhs + rhs
            "*" -> lhs * rhs
            "-" -> lhs - rhs
            else -> throw UnsupportedOperationException()
        }

fun main(args: Array<String>) {
    val expr = BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())

    val nuStack = ArrayDeque<Int>()

    for (item in expr) {
        if (item.matches("""\d+""".toRegex())) {
            nuStack.addLast(item.toInt())
        } else {
            val rhs = nuStack.removeLast()
            val lhs = nuStack.removeLast()
            nuStack.addLast(resolveOp(lhs, item, rhs))
        }
    }
    
    println(nuStack.first)

}


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

int main() {
	while (1) {
		int n, m; cin >> n >> m;
		if (n==0 && m==0) return 0;
		vector<ll> c(m); for (int i=0; i<m; i++) cin >> c[i];
		vector<ll> x(n); for (int i=0; i<n; i++) cin >> x[i];
		vector<vector<ll> > dp(n+1, vector<ll>(256, 1000000000000));
		dp[0][128] = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < 256; ++j)
			{
				for (int k = 0; k < m; ++k)
				{
					if (j+c[k] < 0) dp[i+1][0] = min(dp[i+1][0], dp[i][j]+x[i]*x[i]);
					else if (j+c[k] > 255) dp[i+1][255] = min(dp[i+1][255], dp[i][j]+(255-x[i])*(255-x[i]));
					else dp[i+1][j+c[k]] = min(dp[i+1][j+c[k]], dp[i][j]+(x[i]-(j+c[k]))*(x[i]-(j+c[k])));
				}
			}
		}
		ll ans = 1000000000000;
		for (int j = 0; j < 256; ++j)
		{
			ans = min(ans, dp[n][j]);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 43784
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

d,t,s = i2()
a = d/s
if a <= t:
	print("Yes")
else:
	print("No")



Measured memory_bytes: 9168
# coding: utf-8
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
cnt=0
flg=False
light=0

for i in range(N):
    light=A[light]-1
    cnt+=1
    if light==1:
        flg=True
        print(cnt)
        break

if not(flg):
    print(-1)


Measured memory_bytes: 7084
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;

// mint
const int mod = 1e9 + 7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
//istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(int argc, const char * argv[]) {
    string A;
    cin >> A;
    ll n = A.length();
    int d;
    cin >> d;
    mint dp[n+1][2][d+1]; // dp[桁][Aより小さいことが1:確定 0:未定][mod d]
    dp[0][0][0]=1;
    for(ll i=0;i<n;i++){
        rep (j, 2)rep(l,d) {
            int lim=9;
            if (j==0) lim=A[i]-'0';
            rep (now, lim + 1) {
                dp[i + 1][j || now < lim][(l+now)%d] += dp[i][j][l];
            }
        }
    }
    mint ans= -1;
    rep (j, 2)rep(l,d) if(l==0) ans+=dp[n][j][l];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18884
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    int N , K;
    cin >> N >> K;
    string s;
    cin >> s;
    for(int i = 0; i < N; i++){
        if(i+1 == K) cout << (char)(s[i] + 'a' - 'A') ;
        else cout << s[i];
    }
    cout << endl;

}


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

int main(){
    
    int N;
    int ans = 0;
    cin >> N;
    int A[20];
    int B[20];
    int C[20];
    
    for(int i = 1; i <= N; i++) cin >> A[i];
    for(int i = 1; i <= N; i++) cin >> B[i];
    for(int i = 1; i <= N-1; i++) cin >> C[i];
    
    
    for(int i = 1; i <= N; i++){
        int type = A[i];
        ans += B[type];
        if(i > 1 && A[i-1] == A[i]-1 ) ans += C[A[i-1]];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
#define INF 1e18L+1
using namespace std;
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll parent[100005];
ll find(ll a)
{
    std::vector<ll> v;
    while(parent[a]>0)
    {
        v.push_back(a);
        a = parent[a];
    }
    for(ll i=0;i<v.size();i++)
        parent[v[i]] = a;
    return a;
}
bool prime[100005];
void SieveOfEratosthenes(int n) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
void union1(ll a, ll b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
    {
        parent[a] = min(parent[a],parent[b]);
        parent[b] = a;
    }
}  
int main()
{
    //fastio();
    ll n,w;
    cin >> n >> w;
    std::vector<ll> weight(n),value(n);
    ll sum = 0 ;
    for(ll i=0;i<n;i++)
    {
        cin >> weight[i] >> value[i];
        sum+=value[i];
    }
    std::vector<ll> dp(sum+1,INF);
    dp[0] = 0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=sum-value[i];j>=0;j--)
        {
            dp[j+value[i]] = min(dp[j+value[i]],dp[j]+weight[i]);
        }
    }
    ll ans = 0;
    for(ll i=0;i<=sum;i++)
    {
        if(dp[i]<=w)
            ans = max(ans,i);
    }
    cout << ans << endl;
}

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

int main(){
  int n; cin >> n;
  str S; cin >> S;
  if(n >= 3200){
    cout << S << endl;
  }else{
    str red; red = "red";
    cout << red << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e3+7;
ll dp[N][N];
struct stu{
	ll value,id;
	bool friend operator<(const stu &x,const stu &y){
		return x.value>y.value;
	}
}arr[N];
int main(){	
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++) {
		cin>>arr[i].value;
		arr[i].id=i;
	}
	sort(arr+1,arr+1+n); 
	for(ll i=1;i<=n;i++){
		for(ll l=0;l<i;l++){
			ll r=i-1-l; 
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+arr[i].value*abs(arr[i].id-l-1));
			dp[l][r+1]=max(dp[l][r+1],dp[l][r]+arr[i].value*abs(n-r-arr[i].id));
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++) ans=max(ans,dp[i][n-i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 26308
#include<stdio.h>
  
int main(void)
{
    char num[1000],zero='0';
    int count,sum;
    while(1){
        scanf("%s", num);
        if(num[0]=='0') break;
        count=0;
        sum=0;
        while(1){
            if(num[count]=='\0') break;
            sum+=(int)num[count++]-(int)zero;
        }
        printf("%d\n",sum);
    }
    return 0;   
}   

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

#define int				long long
#define FOR( i, m, n )	for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )		FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )		(a).begin(), (a).end()
#define MP				make_pair

typedef pair<int, int> P;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[20][20];
bool u[20][20];

signed main(){
	int a, b;
	while( cin >> a >> b, a, b ) {
		int n; cin >> n;
		
		fill( dp[0], dp[20], 0 );
		fill( u[0], u[20], false );
		REP( i, n ) {
			int x, y; cin >> x >> y;
			u[x][y] = true;
		}

		REPONE( i, a ) {
			if( u[i][1] ) break;
			dp[i][1] = 1;
		}
		REPONE( i, b ) {
			if( u[1][i] ) break;
			dp[1][i] = 1;
		}


		FOR( i, 2, a + 1 ) {
			FOR( j, 2, b + 1 ) {
				if( u[i][j] ) continue;
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}
		}

		cout << dp[a][b] << endl;
	}
}



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

const int INF = INT_MAX/2;

struct Edge{
  int to;
  int cost;
  Edge():to(0),cost(0){}
  Edge(int to, int cost):to(to),cost(cost){}
  bool operator<(const Edge& e)const{
    return cost < e.cost;
  }
};

void dijkstra(const int start, const vector< vector<Edge> >& G1, vector< vector<int> >& G2){
  for(int i = 0;  i < G2[start].size(); i++){
    G2[start][i] = INF;
  }

  G2[start][0] = 0;

  priority_queue< P > que; //cost, pos
  que.push(P(0, start));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int pos = p.second;
    int cost = p.first;
    if(G2[start][pos] < cost) continue;
    for(int i = 0; i < G1[pos].size(); i++){
      int to = G1[pos][i].to;
      if(G2[start][to] > G2[start][pos] + G1[pos][i].cost){
        G2[start][to] = G2[start][pos] + G1[pos][i].cost;
        que.push(P(G2[start][to], to));
      }
    }
  }
}

int main(void){
  int n;
  cin >> n;
  vector< vector< Edge > >G(n);
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    for(int j = 0; j < k; j++){
      int v, c; cin >> v >> c;
      G[u].push_back(Edge(v, c));
    }
  }
  vector< vector<int> > ans(1, vector<int>(n));
  dijkstra(0, G, ans);
  for(int i = 0; i < n; i++) cout << i << " " << ans[0][i] << endl;

  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int q;
    cin >> q;
    vector<int> l(q);
    vector<int> r(q);
    vector<int> state(100001, 0);
    int mx = 0;
    rep(i, 0, q) {
        cin >> l[i] >> r[i];
        mx = max(r[i], mx);
    }
    map<int, bool> mp;
    mp[2] = true;
    for(int i = 3; i < mx+1; i++) {
        mp[i] = true;
        for(int j = 2; j <= sqrt(i); j++) {
            if(i%j == 0) {
                mp[i] = false;
                break;
            }
        }
    }

    int sum = 0;
    for(int i = 1; i < mx+1; i++) {
        //cout << mp[i] << " " << mp[(i+1)/2] << endl;
        if(mp[i] == true && mp[(i+1)/2] == true) {
            sum++;
        }
        state[i] = sum;
    }
    for(int i = 0; i < q; i++) {
        /*
        if(state[r[i]] == state[l[i]] && state[r[i]] != 0) {
            cout << state[r[i]]-state[l[i]]+1 << endl;
        }
        else cout << state[r[i]]-state[l[i]] << endl;
        */
        cout << state[r[i]]-state[l[i]-1] << endl;
    }
    return 0;
}   

Measured memory_bytes: 6528
N, K = [int(x) for x in input().split()]

count = 0

if K == 0:
    print(N**2)
    exit()

for i in range(K+1, N+1):
    count += (i - K) * (N // i)
    count += max(0, N - ((N // i) * i) - K + 1)
print(count)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define ll long long
#define read(x) scanf("%d",&x)
using namespace std;
const int maxn = 5e3 + 10;

int n;
char s[maxn];
int nex[maxn];

int main()
{   
	cin>>n;
	cin>>s;
	int res = 0;
	for(int len=1;len<n;len++){
		int tmplen = 0;
		int st = n - len;
		for(int i=0;i<n-len && i < st;i++){
			if(s[i]==s[i+len]){
				if (!tmplen)
					st = i + len;
				tmplen++;
			}
			else{
				res = max(res, tmplen);
				tmplen=0;
			}
		}
		res = max(res,tmplen);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Maxn 200007
#define modp 998244353
int n;
int a[Maxn],now[Maxn];
pair<int,int> que[Maxn];
int cnt=0;
int val[Maxn];
void solve(int len)
{
    ++cnt;
    que[cnt].first=len;
    que[cnt].second=0;
    for (int i=1;i<=len;i++)
        que[cnt].second=(2LL*que[cnt].second+a[i])%modp;
    bool check=true;
    for (int i=1;i<=len;i++)
        now[i]=a[i];
    for (int i=len+1;i<=n;i++)
        now[i]=now[i-len]^1;
    for (int i=1;i<=n;i++)
        if (a[i]!=now[i])
        {
            if (now[i]>a[i]) check=false;
            break;
        }
    if (check) que[cnt].second=(que[cnt].second+1)%modp;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        char ch=getchar();
        while (ch!='0'&&ch!='1') ch=getchar();
        a[i]=ch-'0';
    }
    for (int i=1;i<=n;i++)
        if ((n%i==0)&&((n/i)%2==1)) solve(i);
    sort(que+1,que+cnt+1);
    int ans=0;
    for (int i=cnt;i;i--)
    {
        int tmp=(que[i].first-val[i]+modp)%modp;
        ans=(ans+1LL*tmp*que[i].second)%modp;
        for (int j=1;j<=cnt;j++)
            if (que[i].first%que[j].first==0) val[j]=(val[j]+tmp)%modp;
    }
    ans=(2LL*ans)%modp;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5336
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
int n;
int ans[200005];
int a[200005];
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int x=a[n-1],y=x/2,ans=0;
    if(x%2==0){
        for(int i=0;i<n-1;i++){
            if(abs(a[i]-y)<=abs(ans-y))ans=a[i];
        }
    }else{
        for(int i=0;i<n-1;i++){
            if(min(abs(a[i]-y),abs(a[i]-y-1))<=min(abs(ans-y),abs(ans-y-1)))ans=a[i];
        }
    }
    printf("%d %d\n",x,ans);
}

Measured memory_bytes: 640
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


int main(void) {
   ll N,A,B;
   cin>>N>>A>>B;
   A-= 1;
   B-= 1;
   ll ans = 0;
   if ((B-A)%2==0) ans= (B-A)/2;
   else {
      {
         ll ans_now = A+1;
         ll now = B-A-1;
         ans_now += now/2;
         // chmin(now,ans_now);
         ans = ans_now;
      }
      {
         ll ans_now = N-1-B+1;
         ll now = B -A - 1;
         ans_now += now/2;
         chmin(ans,ans_now);
      }
   }
   cout<<ans<<endl;




   return 0;
}

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

ans = 0
for i in range(0, 1000):
    num = str(i).zfill(3)
    flag = True
    _idx = 0
    for s in num:
        idx = S[_idx:].find(s)
        if idx == -1:
            flag = False
            break
        else:
            _idx += idx + 1
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  s = s.front() + to_string(s.length()-2) + s.back();
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    b.at(i)=a.at(i);
  }
  sort(a.begin(),a.end());
  ll small=a.at(n/2-1);
  ll big=a.at(n/2);
  for(int i=0;i<n;i++){
    if(b.at(i)<=small)
    cout << big << endl;
    else
    cout << small << endl;
  }
}



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

bool solve(string s){
  if(s=="mew") return true;
  if(s.length()<=3) return false;
  s = s.substr(1,s.length()-2);
  while(true){
    int loc = s.find("mew");
    if(loc==-1) break;
    s.erase(loc,3);
  }
  return s=="e";
}
int main(){
  string s;cin >> s;
  if(solve(s)) cout << "Cat" << endl;
  else cout << "Rabbit" << endl;
  return 0;
}

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

using namespace std;

const int N = 1e5 + 100;

int par[N];
int n, m, ans;

int getPar(int v) {
    return (par[v] == v ? v : par[v] = getPar(par[v]));
}

int merge(int v, int u) {
    v = getPar(v);
    u = getPar(u);
    par[u] = v;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    ans = n;
    iota(par, par + n, 0);
    while (m--) {
	int v, u, w;
	cin >> v >> u >> w;
	v--; u--;
	if (getPar(v) != getPar(u))
	    ans--;
	merge(v, u);
    }
    return cout << ans, 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <map>
#include <stdio.h>

using namespace std;
typedef long long int lint;

int main()
{
	map<string, vector<int> > page;
	set<string> word;

	string str;
	int p;
	while(cin >> str >> p){
		word.insert(str);
		page[str].push_back(p);
	}
	
	set<string>::iterator it = word.begin();
	while(it != word.end()){
		cout << *it;
		sort(page[*it].begin(), page[*it].end());
		for(int i = 0; i < page[*it].size(); i++){
			if(i == 0) cout << endl;
			else cout << " ";
			cout << page[*it][i];
		}
		cout << endl;
		it++;
	}

	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    if(n == 25){
        cout << "Christmas";
    }
    else if(n == 24) cout << "Christmas Eve";
    else if(n == 23) cout << "Christmas Eve Eve";
    else cout << "Christmas Eve Eve Eve";
}

Measured memory_bytes: 256
import java.util.*;

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();
        int D = sc.nextInt();


        if(A+B > C+D){
            System.out.println("Left");
        }else if(A+B < C+D){
            System.out.println("Right");
        }else{
            System.out.println("Balanced");
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

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

#define PI 3.14159265358479

double l(long double a, long double b, long double C){
	return a + b + powl(powl(a - b*cos(C / 180.0*PI), 2.0) + powl(b*sin(C / 180.0*PI), 2.0), 0.5);
}

int main(){
	long double a, b, C;
	cin >> a >> b >> C;
	cout << fixed << 0.5*a*b*sin(C / 180.0*PI) << "\n" << l(a, b, C) << "\n" << b*sin(C / 180.0*PI) << "\n";
	return 0;
}

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

const ll INF = 1LL << 60;
int N;
int A[310][310];
ll dis[310][310], sum;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  fill_n((ll*)dis, 310*310, INF);
  for (int i = 0; i < N; i++) dis[i][i] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      bool flag = true;
      for (int k = 0; k < N; k++) {
        if (k == i || k == j) continue;
        flag &= (A[i][j] != A[i][k] + A[k][j]);
      }
      if (flag) {
        dis[i][j] = dis[j][i] = A[i][j];
        sum += A[i][j];
      }
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (dis[i][j] == A[i][j]) continue;
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

ll l, A, B;

using vec = vector<ll>;
using mat = vector<vector<ll> >; 
int m;
vec matmul(vec &dp, mat &mt) {
  vec ret(m, 0);
  rep(i, m) rep(j, m) {
    add(ret[i], mt[i][j] % mod * (dp[j] % mod) % mod); 
  }
  return ret;
}
mat update(mat &mt) {
  mat ret(m, vec(m, 0));
  rep(i, m) rep(j, m) rep(k, m) {
    add(ret[i][j], mt[i][k] % mod * (mt[k][j] % mod) % mod);
  }
  return ret;
}
// mt[0] : 1 "列"目
void matpow(vec &dp, mat &mt, ll k) {
  m = sz(dp);
  while (k) {
    if (k & 1) dp = matmul(dp, mt);
    mt = update(mt);
    k >>= 1;
  }
}

// pdf editorial
void solve() {
  int M;
  cin >> l >> A >> B >> M;
  mod = M;
  vec v{0, A, 1};
  // cout << v << endl;

  // 要素数が二分探索でうまくいかない
  // とりあえず過去のコードで行列累乗以外は
  ll last = A + B * (l - 1);
  ll ten = 1;
  rep(i, 19) {
    ten *= 10;
    ll l = ten / 10, r = ten - 1;
    ll na, nlast;
    ll nl; // debuged, int to ll
    if (last < l) continue;
    if (r < A) continue;
    if (l <= A) na = A;
    // a + b * i = l
    else na = (l - A + (B - 1)) / B * B + A;
    if (last <= r) nlast = last;
    else nlast = (r - A) / B * B + A;
    nl = (nlast - na) / B + 1;
    mat mt{{pow(10LL, i + 1), 1, 0}, {0, 1, B}, {0, 0, 1}};
    matpow(v, mt, nl);
  }
  cout << v[0] << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main()
{
    int N;
    std::string A, B, C;
    std::cin >> N >> A >> B >> C;

    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] == B[i] && B[i] != C[i]) {
            ++cnt;
        } else if (A[i] != B[i] && A[i] == C[i]) {
            ++cnt;
        } else if (A[i] != B[i] && B[i] == C[i]) {
            ++cnt;
        } else if (A[i] != B[i] && B[i] != C[i] && A[i] != C[i]) {
            cnt += 2;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())

c = []
a = []
for _ in range(n):
   tmp = list(map(int, input().split()))
   c.append(tmp.pop(0))
   a.append(tmp)

ans = float('inf')
for i in range(2**n):
   cost = 0
   und = [0] * m
   for j in range(n):
      if ((i >> j) & 1):
         for k in range(m):
            und[k] += a[j][k]
         cost += c[j]

   if min(und) >= x:
      ans = min(ans, cost)

if ans == float('inf'):
   print(-1)
else:
   print(ans)


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, m, a[N], b[N];

void insert(int x){
	m++;
	for(int i = m; i >= x + 1; i--)
		b[i] = b[i - 1];
	b[x] = x;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d",&x);
		if(x > m + 1){
			puts("-1");
			return 0;
		}
		insert(x);
	}
	for(int i = 1; i <= n; i++)
		printf("%d\n", b[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<(b);++i)
using namespace std;

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main(){
 
	ll n, m;
	cin >> n >> m;
	if(n < m) {
		swap(n, m);
	}
	if(n == 1) {
		cout << 1 << endl;
	}
	else if(m == 1) {
		cout << n-2 << endl;
	}
	else {
		cout << (n-2)*(m-2) << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

//ll n;
ll ans;
string s;
signed main(){
	acc_io;
	cin>>s;
	int n=s.size();
	string num;
	ans=0;
	if(n==1){
		cout<<stoll(s)<<endl;
		return 0;
	}
	
	rep(i,0,2<<(n-2)){
		num=s[0];
		rep(j,0,n-1){
			if((i>>j)&1){
//				cout<<":"<<i<<" "<<" "<<num<<" "<<endl;
				ans+=stoll(num);
				if(j+1<n){
					num=s.at(j+1);
				}
			}
			else{
				num+=s.at(j+1);
			}
		}
//		cout<<i<<" "<<" "<<num<<" "<<endl;
		ans+=stoll(num);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x1, y1, x2, y2, vx, vy, x3, y3, x4, y4;
  	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  	vx = x2 - x1; vy = y2 - y1;
  	x3 = x2 - vy; y3 = y2 + vx;
  	x4 = x3 - vx; y4 = y3 - vy;
  	printf("%d %d %d %d", x3, y3, x4, y4);
}

Measured memory_bytes: 128
//
//  main.cpp
//  Kenken Race
//
//  Created by Hashizo on 2019/06/02.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

int main(int argc, const char * argv[]) {
	int n,a,b,c,d;
	string s,s1,key,ans;
	cin >> n >> a >> b >> c >> d >> s;

	// a地点より前方の文字列は削除し、一番後方の到着地点より後方は削除
	if (c < d)
		s1 = s.substr((a-1),d-a+1);
	else
		s1 = s.substr((a-1),c-a+1);
	
	// 岩が連続した場合はNoを返す
	key = "##";
	if ( s1.find(key) != string::npos ) {
		ans = "No";
		cout << ans << endl;
		return 0;
	}

	if (c > d) {
		s1 = s.substr((b-2),d-b+3);
		key = "...";
		if (s1.find(key) == string::npos ) {
			ans = "No";
		}
		else {
			ans = "Yes";
		}
	}
	else {
		ans = "Yes";
	}
	
	cout << ans << endl;
    return 0;
}


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

typedef pair<int, int> P;

int main(void){
    int h, w, d[1001][1001], sx, sy, sum = 0, cnt=0, n;
    char maze[1001][1001], num[9] = {'1','2','3','4','5','6','7','8','9'};
    cin >> h >> w >> n;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            d[i][j] = 0;
            cin >> maze[i][j];
            if(maze[i][j] == 'S'){
                sy = i;
                sx = j;
            }
        }
    }
    queue<P> que;
    que.push(P(sx, sy));

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

    while(que.size()){
        P p = que.front();
        que.pop();
        if(cnt == n){
            cout << sum << endl;
            return 0;
        }

        for(int i=0;i<4;i++){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if(0<=nx && nx<w && 0<=ny && ny<h && maze[ny][nx] != 'X' && d[ny][nx] == 0){
                d[ny][nx] = d[p.second][p.first] + 1;
                que.push(P(nx, ny));
                // cout << nx << " " << ny << " "<< maze[ny][nx] << endl;
                if(maze[ny][nx] == num[cnt]){
                    // cout << nx << " " << ny << " "<< maze[ny][nx] << endl;
                    sum += d[ny][nx];
                    //que?????????????????????
                    while(que.size()){
                        que.pop();
                    }
                    //???????????¢????????????
                    for(int i=0;i<h;i++){
                        for(int j=0;j<w;j++){
                            d[i][j] = 0;
                        }
                    }
                    que.push(P(nx, ny));
                    cnt++;
                    break; //for????????????
                }
            }
        }
    }
    return 0;
}   

Measured memory_bytes: 8032
N=int(input())
S=input()
S = list(S)

def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

for i in range(len(S)):
    a = alpha2num(S[i])
    a=a+N
    while a>26:
        a=a-26
    S[i]=num2alpha(a)

print(''.join(S)) 

Measured memory_bytes: 3188