akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    size_t n=G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s]=0;
    Q.emplace(0,s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        int s, g;
        cin >> s >> g;
        s--; g--;
        int sz = n*n*31;
        vector<vector<edge<double>>> G(sz);
        auto f = [&n](int a, int b, int c){
            return a*n*31+b*31+c;
        };
        for (int i = 0; i < m; ++i) {
            int x, y, c; double d;
            cin >> x >> y >> d >> c;
            x--; y--;
            for (int xxx = 0; xxx < 2; ++xxx) {
                for (int j = 0; j < n; ++j) {
                    if(y == j) continue;
                    for (int k = 0; k <= 30; ++k) {
                        if(k > 1 && k-1 <= c) G[f(x, j, k)].emplace_back(f(y, x, k-1), d/(k-1));
                        if(k > 0 && k <= c) G[f(x, j, k)].emplace_back(f(y, x, k), d/k);
                        if(k+1 <= c) G[f(x, j, k)].emplace_back(f(y, x, k+1), d/(k+1));
                    }
                }
                swap(x, y);
            }
        }
        auto dist = dijkstra(f(s, s, 0), G);
        double ans = INF<double>;
        for (int i = 0; i < n; ++i) {
            ans = min(ans, dist[f(g, i, 1)]);
        }
        if(ans >= INF<int>) puts("unreachable");
        else printf("%.10lf\n", ans);
    }
    return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n, k;
	vector<ll> v;
	ll ans = 0;

	cin >> n >> k;

	REP(i, n) {
		ll l;
		cin >> l;
		v.push_back(l);
	}

	sort(v.begin(), v.end(), greater<ll>());

	REP(i, k) {
		ans += v[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

char maze[1010][1010];
int H,W,n;
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(int sx,int sy, int gx,int gy){
    queue<pair<int,int>> que;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j]=INF;
        }
    }
    que.push(make_pair(sx,sy));
    d[sx][sy]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        if(p.first==gx && p.second==gy) break;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];
}

int main(){
    cin>>H>>W;
    int ans=0;
    rep(i,H){
        rep(j,W){
            cin>>maze[i][j];
            if(maze[i][j]=='.') ans++;
        }
    }
    int tmp=bfs(0,0,H-1,W-1);
    if(tmp==INF){
        cout<<-1<<endl;
        return 0;
    }
    //cout<<ans<<" "<<tmp<<endl;
    cout<<ans-tmp-1<<endl;
}

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

if N <= 111:
    print(111)
elif 111 < N <= 222:
    print(222)
elif 222 < N <= 333:
    print(333)
elif 333 < N <= 444:
    print(444)
elif 444 < N <= 555:
    print(555)
elif 555 < N <= 666:
    print(666)
elif 666 < N <= 777:
    print(777)
elif 777 < N <= 888:
    print(888)
else:
    print(999)

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll N;
ll M;
ll D[100005];
ll pos[100005];
ll d_max = -1;
ll d_min = LLONG_MAX;

bool is_higher(ll val){
	queue<ll> que;

	ll cnt = 0;
	for (int i = M;i < N;i++){
		if(D[i] >= val) cnt++;
	}

	for (int i = (N/3)*3;i < N;i++){
		if(pos[i] == -1) que.push(1);
		else if(D[pos[i]] < val) que.push(INT_MAX/10);
		else que.push(0);
	}

	int itr;
	for (itr = 0;itr < N;itr += 3 ){
		if(itr+2 >= N) break;
		ll cnth = 0;
		ll cntl = 0;
		for (int j = 0;j < 3;j++){
			if(pos[itr+j] == -1) continue;
			ll tmp = D[pos[itr+j]];
			if(tmp >= val) cnth++;
			else cntl++;
		}
		if(cntl+cnth == 0) que.push(2);
		else if(cntl+cnth == 1){
			if(cntl == 1) que.push(2);
			else que.push(1);
		}
		else if(cntl+cnth == 2){
			if(cntl == 2) que.push(INT_MAX/10);
			else if(cnth == 2) que.push(0);
			else que.push(1);
		}
		else {
			if(cntl == 2 || cntl == 3) que.push(INT_MAX/10);
			else que.push(0);
		}

	}

	while(que.size() != 1){
		ll tr[3];
		for (int i = 0;i < 3;i++){
			tr[i] = que.front(); que.pop();
		}
		que.push(min(tr[0]+tr[1],min(tr[1]+tr[2],tr[2]+tr[0])));
	}
	
	return (que.front() <= cnt);

}

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

	cin >> N >> M;

	memset(pos, -1, sizeof(pos));

	for (int i = 0;i < M;i++){
		int tmp;
		cin >> D[i] >> tmp;
		tmp--;
		pos[tmp] = i;
		d_max = max(d_max, D[i]);
		d_min = min(d_min, D[i]);
	}

	for (int i = M;i < N;i++){
		cin >> D[i];	
		d_max = max(d_max, D[i]);
		d_min = min(d_min, D[i]);
	}

	// [low, high)
	ll low = d_min;
	ll high = d_max+1;

	while(high-low > 1){
		ll mid = (low+high)/2;
		if(is_higher(mid)) low = mid;
		else high = mid;
	}

	cout << low << endl;

	return 0;

}



Measured memory_bytes: 4904
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int U[2003][2003];

int main() {
  double T,X;
  cin >> T>>X;
  printf("%lf",T/X);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    cii(m);
    VI vi(n, -1);
    auto ans = -1;
    rep(i, m){
        cii(s);
        cii(c);
        if (vi[s-1]==-1){
            vi[s-1] = c;
        }else{
            if (vi[s-1]!=c)
                ans = -2;
        }
    }
    if (ans!=-2){
        rep(i, pow(10, n)){
            if(to_string(i).length()!=n){
                continue;
            }
            bool bo = true;
            rep(j, n){
                if (vi[j] == -1){
                    continue;
                }
                if (to_string(vi[j])[0] != to_string(i)[j]){
                    bo = false;
                }
            }
            if (bo){
                ans = i;
                break;
            }
        }
    }else{
        ans = -1;
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int a, p;
    cin >> a >> p;
    p += a*3;
    cout << p/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[100010],B[100010];
vector<int> G[100010];
int dp[100010][2];
bool F[100010];

void DP(int s){
	F[s]=1;
	dp[s][0]=1;
	dp[s][1]=1;
	REP(i,G[s].size()){
		int e=G[s][i];
		if(F[e]==1)continue;
		DP(e);
		dp[s][0]*=(dp[e][0]+dp[e][1])%MOD;
		dp[s][0]%=MOD;
		dp[s][1]*=dp[e][0];
		dp[s][1]%=MOD;
	}
}

signed main(){
	cin>>N;
	REP(i,N-1){
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	DP(0);
	int ans=(dp[0][0]+dp[0][1])%MOD;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 19212
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int H,N,s,d,f;
  cin >>H>>N;
  int x,y;
  int c;
  c=0;
  vector<pair<long long,long long>>a(N);
    for(int i=0;i<N;i++){
      cin>>x>>y;
      c=max(c,x);
      a[i]=make_pair(x,y);
    }
  long long dp[H+c+1];
  dp[0]=0;
  for(int i=1;i<=H+c;i++){
    if(i<a[0].first){
      dp[i]=a[0].second;
    }
    else{
    dp[i]=dp[i-a[0].first]+a[0].second;
    }
    for(int j=1;j<N;j++){
         if(i<a[j].first){
      dp[i]=min(dp[i],a[j].second);
    }
    else{
    dp[i]=min(dp[i],dp[i-a[j].first]+a[j].second);
    } 
    }
  }
  long long ans;
  ans=10000000000;
   for(int i=H;i<=H+c;i++){
     ans=min(ans,dp[i]);
   }
  cout<<ans<<endl;
}

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

import heapq as hp


def main():
    N, K, Q = map(int, input().split())
    A = list(map(int, input().split()))

    NUM = sorted(list(set(A)))

    ans = 10**10
    for n in NUM:
        Qs = []
        q = []
        for i in range(N):
            if A[i] < n:
                if q:
                    Qs.append(q)
                    q = []
                continue
            if not q:
                q = [A[i]]
            else:
                hp.heappush(q, A[i])
        if q:
            Qs.append(q)
        P = []
        for q in Qs:
            l = len(q)
            if l < K: continue
            for _ in range(min(Q, l-K+1)):
                v = hp.heappop(q)
                P.append(v)
        if len(P) < Q:
            break
        P.sort()
        ans = min(ans, P[Q-1]-P[0])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;
class abc166_d{
  public static void Main(){
    int x = int.Parse(Console.ReadLine());
    bool flag = true;
    for(int a = -118; a <= 119 && flag; a++){
      for(int b = -119; b <= 118 && flag; b++){
        if((a*a*a*a*a-b*b*b*b*b) == x){
          Console.WriteLine("{0} {1}",a,b);
          flag = false;
        }
      }
    }
  }
}


Measured memory_bytes: 17544
#include<stdio.h>

int takasa(int n){
  int sum = 0;
  for(int i=1; i<=n; i++){
    sum += i;
  }
  return sum;
}


int main(){
  int a,b;
  scanf("%d", &a);
  scanf("%d", &b);

  int sa = b-a;
  int tou = takasa(sa);

  int yuki = tou - b;

  printf("%d\n", yuki);
  

  return 0;
}


Measured memory_bytes: 128
from operator import itemgetter
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]
D = [(1, a) for a in A] + BC
D.sort(key=itemgetter(1))
ans = 0
n = N
while n > 0:
    b, c = D.pop()
    ans += min(n, b) * c
    n -= b
print(ans)

Measured memory_bytes: 32364
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    int x = 7;
    for(int i = 1; i <= 1e7; i++){
        if(x%n==0){
            cout<<i;
            return;
        }
        x=(x*10+7)%n;
    }
    cout<<"-1\n";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){
	while(1){
		int n,r;
		cin>> n>> r;
		if(n==0 && r==0) break;
		
		vector<vector<int> > a(2, vector<int>(n));
		for(int i=0;i<n;i++){
			a[0][i] = a[1][i]  = n-i;
		}
		
		for(int i=0;i<r;i++){
			int p, c;
			cin>> p>> c;
			for(int j=0;j<c;j++){
				a[1][j] = a[0][p+j-1];
			}
			for(int j=c;j<c+p-1;j++){
				a[1][j] = a[0][j-c];
			}
			for(int i=0;i<n;i++){
				a[0][i] = a[1][i];
			}
		}
		cout<< a[0][0]<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1220
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
if A == B and C == D and A != C:
  print('Yes')
elif A == C and B == D and A != B:
  print('Yes')
elif A == D and B == C and A != B:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38256
import collections
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().split()]
ac = collections.Counter(A)
assert set(ac.keys()).issubset({1, 2, 3})


def solve(c1, c2, c3):
    K = c1 + c2 + c3
    L = K + 1
    L2 = L ** 2
    dp = [0.0] * L ** 3
    for i3 in range(c3 + 1):
        for i2 in range(c2 + c3 + 1):
            for i1 in range(N - i2 - i3 + 1):
                isum = i1 + i2 + i3
                if isum == 0:
                    continue
                i0 = N - i1 - i2 - i3
                if i0 < 0:
                    continue
                e = i0
                if i1 > 0:
                    e += i1 * (1.0 + dp[(i1 - 1) * L2 + i2 * L + i3])
                if i2 > 0 and i1 <= K:
                    e += i2 * (1.0 + dp[(i1 + 1) * L2 + (i2 - 1) * L + i3])
                if i3 > 0 and i2 + 1 <= c2 + c3:
                    e += i3 * (1.0 + dp[i1 * L2 + (i2 + 1) * L + i3 - 1])
                dp[i1 * L2 + i2 * L + i3] = e / isum
    return dp[c1 * L2 + c2 * L + c3]


if __name__ == "__main__":
    print(solve(ac[1], ac[2], ac[3]))


Measured memory_bytes: 247816
N,H = map(int, input().strip().split(' '))
P = [list(map(int, input().strip().split(' '))) for _ in range(N)]

max_a = max(P[i][0] for i in range(N))
B = sorted([P[i][1] for i in range(N) if P[i][1] > max_a], reverse=True)

ans = 0
for b in B:
  H -= b
  ans += 1
  if H <= 0:
    break

if H > 0:
  ans += (H+max_a-1)//max_a
  
print(ans)

Measured memory_bytes: 68184
import sys
input=sys.stdin.readline
from random import seed, randint

def calc(d,C,S,T):
    Last=[0]*26
    score=0
    for day,t in enumerate(T):
        t-=1
        Last[t]=day+1
        score+=S[day][t]
        for i,c in enumerate(C):
            score-=c*(day+1-Last[i])
    return score

def main():
    d=int(input())
    C=tuple(map(int,input().split()))
    S=[tuple(map(int,input().split())) for _ in range(d)]
    Ans=[0]*d
    Last=[0]*26
    for day in range(d):
        ans=0
        score=-float('inf')
        for t in range(26):
            TmpList=Last[:]
            tmp_score=S[day][t]
            TmpList[t]=day+1
            for i,c in enumerate(C):
                tmp_score-=c*(day+1-TmpList[i])
            if tmp_score>score:
                score=tmp_score
                ans=t+1
        Ans[day]=ans
        Last[ans-1]=day
    print(*Ans,sep='\n')
    
if __name__=='__main__':
    main()

Measured memory_bytes: 83852
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    string S; cin >> S;

    int gc = 0, pc = 0;
    rep(i, S.size()) {
        if (S[i] == 'g') {
            gc += 1;
        } else {
            pc += 1;
        }
    }
    int ans = (gc-pc) /2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=jp
#  Linear Search : python3
#  2018.12.08 yonezawa


#from collections import deque
import sys
input = sys.stdin.readline
#import cProfile

def main():
    n1 = int(input())
    s1 = set(map(int,input().split()))
    n2 = int(input())
    s2 = set(map(int,input().split()))
    print (len(s1 & s2))

if __name__ == '__main__':
   main()
#    pr = cProfile.Profile()
#    pr.runcall(main)
#    pr.print_stats()


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

int main(){
    int k, n, i, res = 0, j = 0;

    cin >> k >> n;

    int a[k];

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

    sort(a, a + k);

    for(i = 0; i < n; i++){
        res += a[j++];
    }

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	while(cin>>n,n){
		int mi=inf;
		rep(i,110)rep(j,1010){
			int k=n-i*i*i-j*j;
			if(k<0)continue;
			mi=min(mi,i+j+k);
		}
		cout<<mi<<endl;
	}
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, ans = INF;
    cin >> n >> k;
    vector<int> p, m;
    rep(i, 0, n){
        int x;
        cin >> x;
        if(x < 0) m.push_back(-x);
        else if(x > 0) p.push_back(x);
        else if(x == 0) k--;
    }
    sort(m.begin(), m.end());
    if(k > 0 && m.size() >= k) chmin(ans, m[k - 1]);
    if(k > 0 && p.size() >= k) chmin(ans, p[k - 1]);
    rep(i, 0, m.size()){
        int r = k - (i + 1);
        if(r - 1 < 0 || r > p.size()) continue;
        int tmp = m[i] * 2 + p[r - 1];
        int tmp2 = m[i] + p[r - 1] * 2;
        ans = min({ans, tmp, tmp2});
    }
    if(k == 0) ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 1656
#include<stdio.h>
int a[10010];
 
int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d",&a[i]);
  }
  int s=0;
  for(int i=0;i<m;i++)s+=a[i];
  if(s>n){
    printf("-1\n");
  }
  else{
    printf("%d\n",n-s);
  }
}

Measured memory_bytes: 1680
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a = 0
for i in range(0,N-1):
    if A[i+1] == A[i] + 1:
        a += C[A[i]-1]

print(sum(B)+a)

Measured memory_bytes: 3064
N, X = map(int, input().split())
L_list = list(map(int, input().split()))
D_list = [0]

for i in range(1, N + 1):
    D_list.append(D_list[i - 1] + L_list[i - 1])

for i in range(N + 1):
    if X < D_list[i]:
        print(i)
        exit()
    elif X == D_list[i]:
        print(i + 1)
        exit()

print(i + 1)

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

double dist(int i, int j, vector<double> x, vector<double> y)
{
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main()
{
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> per(N);
    rep(i, N) per[i] = i + 1;
    int s, e;
    int num = 0;
    do
    {
        num++;
        bool ok1 = true, ok2 = true;
        rep(i, N)
        {
            if(P[i]!=per[i]){
                ok1 = false;
            }
            if (Q[i] != per[i])
            {
                ok2 = false;
            }
        }
        if(ok1){
            s = num;
        }
        if(ok2){
            e = num;
        }
    } while (next_permutation(all(per)));
    
    cout << abs(s-e) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)

odds = v.each_slice(2).map(&:first)
evens = v.each_slice(2).map(&:last)

h_odd = Hash.new(0)
h_even = Hash.new(0)

odds.each do |val|
  h_odd[val] += 1
end

evens.each do |val|
  h_even[val] += 1
end

h_odd = h_odd.sort_by{ |k, v| -v}
h_even = h_even.sort_by{ |k, v| -v}

# oddとevenの数字が同じなってしまった場合はあとで変更できる？
# それぞれの出現回数をとっておく
# それぞれ一番多いやつに合わせるのが正解
# もし同じときはどっちかが二番目 両方みてminにすれば良さそう

if h_odd[0][0] != h_even[0][0]
  puts (n/2 - h_odd[0][1]) + (n/2 - h_even[0][1])
elsif h_odd.size == 1 && h_even.size == 1
  puts n/2
elsif h_odd.size == 1
  puts n/2 - h_even[0][1]
elsif h_even.size == 1
  puts n/2 - h_odd[0][1]
else
  a = (n/2 - h_odd[0][1]) + (n/2 - h_even[1][1])
  b = (n/2 - h_odd[1][1]) + (n/2 - h_even[0][1])

  puts [a, b].min
end


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	str s;
	cin >> s;
	int n = s.size();
	int L = 0, R = n + 3;
	int mid;
	int lz, rz, lf, rf;
	while(L + 1 < R){
		mid = (L + R) >> 1;
		lz = 0, rz = mid - (mid & 1);
		lf = 1, rf = mid - (1 - (mid & 1));

		bool flz = true, flf = true;
		for(auto &c : s){
			if(c == '0'){
				lz --; rz--;
				lf --; rf--;
			}
			if(c == '1'){
				lz ++;
				rz ++;
				lf ++; rf++;
			}
			if(c == '?'){
				lz --;
				rz ++;
				lf --;
				rf ++;
			}
			swap(lz, lf); swap(rz, rf); swap(flz, flf);
			lz = max(lz, 0); lf = max(lf, 1);
			rz = min(rz, mid - (mid & 1));
			rf = min(rf, mid - (1 - (mid & 1)));
			if(lz > rz) flz = false;
			if(lf > rf) flf = false;
		}
		if(flz || flf) R = mid;
		else L = mid;
	}
	cout << R << '\n';
	return 0;
}


Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class SegTree {
public:
  int n;
  vector<T> data;
  vector<int> pos;
  SegTree(int n_){
    n=1;
    while(n<n_) n*=2;
    data.resize(n+1, INF);
    pos.resize(2*n, n);
  }
  inline int query(int l, int r){ // position of min value
    int ret = n;
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1){
        if(data[ret] > data[pos[l]]) ret = pos[l];
        l++;
      }
      if(r&1){
        r--;
        if(data[ret] > data[pos[r]]) ret = pos[r];
      }
    }
    return ret;
  }
  inline void update(int k, T a){
    data[k]=a;
    pos[k+n]=k;
    k+=n;
    while(k>0){
      k = k/2;
      if(data[pos[k*2]] < data[pos[k*2+1]]){
        pos[k] = pos[k*2];
      }
      else {
        pos[k] = pos[k*2+1];
      }
    }
  }
  inline T operator[](int idx){ return data[idx+n]; }
};


int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i], vec[i]--;
  SegTree<int> st[2] = SegTree<int>(n);
  rep(i,n){
    st[i%2].update(i, vec[i]);
  }

  vector<int> ans;

  using P = pair<int,int>;
  priority_queue<pair<int,P>, vector<pair<int,P>>, greater<pair<int,P>>> pq;
  pq.push(mp(vec[st[0].query(0,n)], mp(0,n)));

  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    int l = p.se.fi, r = p.se.se;
    int p1 = st[l%2].query(l,r);
    int p2;
    bool sw = false;
    if((p1-l)%2==0) p2 = st[!(p1%2)].query(p1, r);
    else sw=true,p2 = st[!(p1%2)].query(l, p1);
    st[!(p1%2)].update(p2, INF);
    st[(p1%2)].update(p1, INF);

    if(sw) swap(p1,p2);
    ans.pb(vec[p1]);ans.pb(vec[p2]);

    auto ins = [&](int a, int b){
      if(a==b) return;
      pq.push(mp(vec[st[a%2].query(a,b)], mp(a,b)));
    };

    ins(l,p1);
    ins(p1+1,p2);
    ins(p2+1,r);
  }

  rep(i,n) cout << ans[i]+1 << " \n"[i==n-1];

  return 0;
}


Measured memory_bytes: 9896
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		long answer = 0;
		int mod = 0;
		for(int i=0;i<n;i++){
			int num = Integer.parseInt(br.readLine());
			if(mod > 0 && num > 0){
				answer += 1;
				num -= 1;
			}
			answer += num/2;
			mod = num%2;
		}
		System.out.println(answer);
	}
}


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

int main(){
  int n;
  cin>>n;
  vector<long long> l(n+1);
  l.at(0)=2;
  l.at(1)=1; 
  for(int i=2; i<=n; i++) l.at(i)=l.at(i-1)+l.at(i-2);

  cout<<l.at(n)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int k,x;
    cin>>k>>x;
    int begin,end;
    begin=x-(k-1);
    end=x+(k-1);
    if(begin<-1000000) begin=-1000000;
    if(end>1000000) end=1000000;
    for(int i=begin; i<=end; i++){
        cout<<i<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
const int mod=1e9+7;
unordered_map<char,int>byk;
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    string s;

    cin>>n;
    cin>>s;
    for(auto isi:s){
        byk[isi]++;
    }   
    ll ans=1;
    for(int i='a';i<='z';i++){
        ans=mul(ans,byk[i]+1);
    }
    cout<<(ans-1 +mod)%mod<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p;
	cin>>n;
	int ma=0, ans=0;
	REP(i, n){
		cin>>p;
		CHMAX(ma, p);
		ans+=p;
	}
	ans-=ma/2;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
int main(){
  int N;
  double res;
  rd(N);
  res = (divup_L(N,2)) / (double)N;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190928-1

// --- original code ---
// {
//   int N;
//   double res;
//   rd(N);
//   res = (N /+ 2) / (double)N;
//   wt(res);
// }


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

        Scanner sc  = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        if( 
           c1[s1.length()-1] == c2[ 0 ]
           &&
           c2[s2.length()-1] == c3[ 0 ]
            
          )System.out.print("YES");
        else System.out.print("NO");


        System.out.println();
    }

}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 100010

ll n,m;
vector<ll> adj[MAX];
ll out_degree[MAX];
bool odd_vertices[MAX];

set<pii> edges;
bool visited[MAX];

bool dfs(ll start){
	visited[start]=1;
	ll count = odd_vertices[start];

	for(ll x:adj[start]) if(!visited[x]){
		bool t = dfs(x);
		if(t) {
			edges.insert({start,x});
			count++;
		}
	}

	return (count%2==1);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	memset(out_degree,0,sizeof(out_degree));
	memset(odd_vertices,0,sizeof(odd_vertices));
	memset(visited,0,sizeof(visited));
	cin>>n>>m;
	vector<pii> answer;
	For(i,0,m){
		ll x,y;cin>>x>>y;x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
		out_degree[x]++;
		answer.pb({x,y});
	}
	ll count = 0;
	For(i,0,n) if(out_degree[i]%2==1) {
		odd_vertices[i]=1;
		count++;
	}
	if(count%2==1){
		cout<<-1<<endl;
		return 0;
	}else{
		dfs(0);

		for(pii& x:answer){
			pii e = x;
			if(edges.find(e)!=edges.end() || edges.find({e.se,e.fi})!=edges.end()){
				e = {x.se,x.fi};
			}
			x = e;
			cout<<x.fi+1<<" "<<x.se+1<<endl;
		}
	}
	































	
}

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

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

int N, A, B, C;
vector<int> L;

int main(int argc, char **argv)
{
	cin >> N >> A >> B >> C;
	L.resize(N); for (int i = 0; i < N; ++i) cin >> L[i];

	vector<int> bits(3);

	ll res{1ll << 60};
	for (bits[0] = 1; bits[0] < (1<<N); ++bits[0])
	{
		for (bits[1] = 1; bits[1] < (1<<N); ++bits[1])
		{
			if (bits[0] & bits[1]) continue;
			for (bits[2] = 1; bits[2] < (1<<N); ++bits[2])
			{
				if (bits[0] & bits[2] || bits[1] & bits[2]) continue;
				
				vector<ll> sum_l(3, 0);
				ll num_l{0};
				for (ll l = 0; l < N; ++l)
				{
					for (ll i = 0; i < 3; ++i)
					{
						if (bits[i] & (1 << l))
						{
							sum_l[i] += L[l];
							++num_l;
						}
					}
				}

				// calc score
				ll score = 10 * (num_l-3);
				score += abs(A - sum_l[0]);
				score += abs(B - sum_l[1]);
				score += abs(C - sum_l[2]);

				chmin(res, score);
			}
		}
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int l,r;
    cin>>l>>r;
    int ans=INF;
    for(int i=l;i<=min(l+2019,r);i++){
        for(int j=i+1;j<=min(l+2019,r);j++){
            ans=min(ans,((i%2019)*(j%2019))%2019);
        }
    }
    cout<<ans<<endl;
}


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


int main(void) {
	char s[999999];
	
	scanf("%s", s);
	
	int l=strlen(s),wcnt=0, i;
	

	
	for(i=1;s[i];i++){
		if(s[i-1]-s[i]){
			wcnt++;
		}
	}
	
	printf("%d\n", wcnt);
	return 0;
}


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

int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y ;
  int aaa;
  if(N<=K){
   aaa=N*X;
  }
  else{
   aaa=K*X+(N-K)*Y;
    
  }
  
  
  
  
  
 cout <<aaa << endl;
}


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

int main(){
    
    int a, b;
    scanf("%d %d", &a, &b);
    int len = a + b + 1;
    char s[a+b+10];
    int count = 0;
    scanf("%s", s);
    
    if(strlen(s) != len){
    	printf("No\n");
    	// printf("1\n");
    	return 0;
	}
	else if(s[a] != '-'){
		printf("No\n");
		// printf("2\n");
		return 0;
	}
    for(int i = 0 ; i < len+5 ; i++){
    	if(s[i] == '-'){
    		count++;
		}
	}
    
    if(count > 1){
    	printf("No\n");
    	return 0;
	}
    
    printf("Yes\n");
    
    return 0;
}


Measured memory_bytes: 1660
#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);
    char a[N],b[N],c[N];
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);

    int ans=0;

    
    for(int i = 0; i < N; i++)
    {
        ans+=2;
        if(a[i]==b[i]){
            ans--;
        }
        if(b[i]==c[i]){
            ans--;
        }
        if(a[i]==c[i]&&a[i]!=b[i]){
            ans--;
        }
    }
    

    printf("%d",ans);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define MOD = 1e9+7
#define rep(i,n) for(int i=0;i<(n);++i)
const double PI=3.14159265358979323846; 
const int INF = 1001001001;

using namespace std;

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> C(n);
  vector<int> A[n];
  rep(i,n){
    cin >> C[i];
    rep(j,m){
      int a;
      cin >> a;
      A[i].push_back(a);
    }
  }

  vector<int> cost;
  int ans=INF;
  for(int bit=0; bit<(1<<n);++bit){
    vector<int> num(m,0); 
    int sum=0;
    for(int i=0;i<n;i++){
      if((bit>>i) & 1){
        rep(j,m){
          num[j] += A[i][j];
        }
        sum += C[i];
      }
    }
    
    bool ok = true;
    rep(j,m) if (num[j] < x) ok = false;  
    if(ok) ans = min(ans,sum);
  }

  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}


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

int main() {
    char S[100];
    char T[100];
    cin >> S;
    cin >> T;

    int L = strlen(S);
    for (int i = 0; i < L; i++) {
        bool match = true;
        for (int j = 0; j < L; j++) {
            match = match * (S[(i + j) % L] == T[j % L]);
            if (!match) break;
        }
        if (match) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main
{
	public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer t = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(t.nextToken());
		int W = Integer.parseInt(t.nextToken());
		int[] w = new int[n+1], v = new int[n+1];
		int s = 0;
		for(int i = 1 ; i <= n ; i++)
		{
		      t = new StringTokenizer(br.readLine());
		      w[i] = Integer.parseInt(t.nextToken());
		      v[i] = Integer.parseInt(t.nextToken());
		      s += v[i];
		}
		long[] dp = new long[s+1];
		Arrays.fill(dp, (long)1e12);
		dp[0] = 0;
		for(int i = 1 ; i < n+1 ; i++)
		{
		      long min = (long)1e12;
		      int pos = 0;
		      for(int j = s ; j >= 1 ; j--)
		      {
		            if(j < v[i]) continue;
		            dp[j] = Math.min(dp[j] , dp[j-v[i]]+w[i]); 
		      }
		}
		for(int i = s ; i >= 0 ; i--)
		{
		      if(dp[i] <= W)
		      {
		            System.out.println(i);
		            break;
		      }
		}
	}
}

Measured memory_bytes: 23636
h,w=map(int,input().split())
INF=float('inf')

a=[]
for _ in range(10):
  c=list(map(int,input().split()))
  a.append(c)
  
for i in range(10):
  for j in range(10):
    for k in range(10):
      a[j][k]=min(a[j][k],a[j][i]+a[i][k])


ans=0
for x in range(h):
  d=list(map(int,input().split()))
  for e in d:
    if e!=-1:
      ans+=a[e][1]
      
print(ans)



Measured memory_bytes: 73568
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			int i = 0;
			String s = "";
			StringBuffer sb = new StringBuffer();
			
			while(true){		
				if(n-i>0){
					s = Integer.toString(n-i);
					sb = new StringBuffer(s);
					if(sb.reverse().toString().compareTo(s)==0){
						System.out.println(s);
						break;
					}
				}
				s = Integer.toString(n+i);
				sb = new StringBuffer(s);
				if(sb.reverse().toString().compareTo(s)==0){
					System.out.println(s);
					break;
				}
				i++;
			}
			
		}
	}	
}

Measured memory_bytes: 17384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  ll n,k;cin >> n >> k;
  vl h(n);
  rep(i,n)cin >> h[i];
  sort(h.begin(),h.end());
  vl ans(n-k+1);
  ll m=h[k-1]-h[0];
  rep(i,n-k+1){
    ans[i]=h[i+k-1]-h[i];
    m=min(m,ans[i]);
  }
  cout << m << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200001],t[200001];
	int len,i,cnt;
	scanf("%s %s",s,t);
	len=strlen(s);
	cnt=0;
	for(i=0;i<len;i++){
		if(s[i]!=t[i]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2116
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String a = s.next();
		String b = s.next();
		String c = s.next();
		
		if(a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}


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

An = []
Bn = []

results = dict()
for i in range(N):
    a, b = map(int, input().split())
    hyoka = (a, b)
    wa = a + b
    if wa in results:
        results[wa].append(hyoka)
    else:
        results[wa] = [hyoka]

sa = 0
turn = 1
for _, v in sorted(results.items(), reverse=True):
    for hyoka in v:
        if turn % 2 == 1:
            sa += hyoka[0]
        else:
            sa -= hyoka[1]
        turn += 1
print(sa)

Measured memory_bytes: 42028
data = list(map(int,input().split()))
N = data[0]
i = 1
b = 0
c = float('inf')
while (N / i >= i):
  a = N / i
  b = N % i
  if b == 0:
    r1 = int(i)
    r2 = int(a)
    if (r1 + r2) < c:
      c = int(r1 + r2)
  i = i + 1
print(c-2)
      

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

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

    int n;
    cin >> n;
    map<string, int> cnt;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    int hoge = 0;
    for (auto& p : cnt) hoge = max(hoge, p.second);
    for (auto& p : cnt) {
        if (p.second == hoge) {
            cout << p.first << '\n';
        }
    }
}


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

int main()
{
	int64_t n, k, mod = 1000000007;
	cin >> n >> k;
	vector<int64_t> as(n - 1), bs(n - 1);
	for (int64_t i = 0; i < n - 1; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}

	vector<vector<int64_t>> g(n);
	for (int64_t i = 0; i < n - 1; i++)
	{
		g[as[i]].emplace_back(bs[i]);
		g[bs[i]].emplace_back(as[i]);
	}

	vector<int64_t> cnt(n, 0);

	int64_t ans = 1;

	auto f = [&](auto &&h, int64_t now = 0, int64_t par = -1, int64_t parpar = -1) -> void {
		int64_t cur = 0;
		if (par != -1)
		{
			cur += cnt[par];
		}
		if (parpar != -1)
		{
			cur++;
		}

		(ans *= max(int64_t(0), k - cur)) %= mod;

		cnt[now]++;
		for (auto &next : g[now])
		{
			if (next == par)
			{
				continue;
			}
			h(h, next, now, par);
			cnt[now]++;
		}
	};

	f(f);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10752
#include<iostream>
#include<string>
using namespace std;
 
int main(void){
   string s;
   
   cin >> s;
   
   for(int i = 0; i < s.length(); i++){
       if(s[i] == '7'){
           cout << "Yes" << endl;
           return 0;
       }
   }
 
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
input()
a=[int(i) for i in input().split()]

cnt=0
flg=True
while flg:
  b=[]
  for i in a:
    if i%2!=0:
      flg=False
      break
    else:
      b.append(i//2)
  if flg:
    cnt+=1
    a=b
print(cnt)    

Measured memory_bytes: 3060
n = int(input())
#文字を最初から数えていって、辞書に入れていき、同じになるかどうかを確認する
#nこ分の文字列があるってことは、nこ分の辞書が生まれる可能性があるってこと
#文字列を小さい順に書き換えた時に、全くもって一致すれば良い
slist = []
countdic = {}
# ss = sorted(input())
# ss = input()
snum = ''.join(sorted(input()))
# print(snum)

# ss.sort()
# print(ss)
# slist.append(snum)
# print(slist)
countdic[snum] = 0
# print(countdic)

for i in range(n-1):
    snum = "".join(sorted(input()))
    if snum not in countdic:
        countdic[snum] = 0
        # print(countdic)
    else:
        countdic[snum] += 1
        # print(countdic)
count_values =list(countdic.values())
# print(count_values)
count_values_len = len(count_values)
# print(count_values_len)

count_sum = 0
numtemp = 0

for i in range(count_values_len):
    count_values[i] = count_values[i] * (count_values[i]+1) / 2
# print(count_values)
print(int(sum(count_values)))

Measured memory_bytes: 18584