akhauriyash/Code-Regression huggingface dataset:
N, P = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

Pw = [1]
for i in range(1, 51):
    Pw.append(Pw[-1] * i)

def C(n, m):
    return Pw[n] // Pw[n - m] // Pw[m]

odd = sum(x % 2 for x in A)
even = N - odd

r = 0
for i in range(0, odd + 1, 2):
    r += C(odd, i) * (2**even)

if P == 1:
    r = 2**N - r

print(r)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int w,a,b,aw,bw;//a,a+w,b,b+w
int main()
{
	cin>>w>>a>>b;
	if(a>b)
	{
		swap(a,b);
	}
	aw=a+w;
	bw=b+w;
    if(aw>=b) 
	{
		cout<<0;
	}
	else 
	{
		cout<<b-aw;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long ul;
// #define int long long

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// func declaration
template <class T> void print2DVec(vector< vector<T> >&);
template <class T> void calcVec(vector<T>&, int, char);
int char_to_int(const char);

// const
const int INF = 10000000;

/*MEMO
・辞書順
abc < abcd, atcoder < atlas
・イテレータ
std::vector<int>::iterator とタイプするのは面倒なので、
 通常は型推論の auto を使用する。
 auto iter = max_element(ALL(vec));
・2次元配列
vector<vector<int>> vec = {{1, 2, 3}, {4, 5, 6}}
・20×10の配列
vector<vector<int>> vec(20, vector<int>(10, 0));
・(n, m)の多次元配列
vector< vector<int> > vec(n, vector<int>(m, 0))  // 0で初期化
*/

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

    // input
    int A, B, C;
    cin >> A >> B >> C;
    
    // calculation
    if (A + B >= C) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    
    return 0;
}


// function
template <class T> void print2DVec(vector< vector<T> >& vec) {
    REP(i, vec.size()) {
        REP(j, vec.front().size()) {
            cout << vec.at(i).at(j);
        }
        cout << endl;
    }
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    switch (ch) {
        case '+':
            REP(i, vec.size()) vec.at(i) += num; break;
        case '-':
            REP(i, vec.size()) vec.at(i) -= num; break;
        case '*':
            REP(i, vec.size()) vec.at(i) *= num; break;
        case '/':
            REP(i, vec.size()) vec.at(i) /= num; break;
        case '%':
            REP(i, vec.size()) vec.at(i) %= num; break;
        default:
            cout << "Incorrect Operator" << endl;
    }
}

int char_to_int(const char c) {
    if('0' <= c && c <= '9') return (c - '0');
    return -1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
string s; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>s;
    cout<<(s=="ARC"?"ABC":"ARC");
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
  int n;
  int a, b, c;
  
  scanf("%d", &n);
  
  a = n / 100; // aは百の位
  n = n % 100;
  b = n / 10; // bは十の位
  c = n % 10; // cは一の位
  
  if(a == 7 || b == 7 || c == 7) {
    printf("Yes");
  } else {
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 1732
use proconio::input;

fn helper(a: usize) -> usize {
  let cnt = (a + 1) / 2;
  let mut result = cnt % 2;
  if a % 2 == 0 {
    result ^ a
  } else {
    result
  }
}

fn main() {
  input! {
    a: usize,
    b: usize,
  }
  
  println!("{}", helper(b) ^ helper(a-1));
}

Measured memory_bytes: 2124
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, C = lr()
XV = np.array([lr() for _ in range(N)])
Sushi = XV[:, 1]
Sushi_rev = Sushi[::-1]
dis = XV[:, 0]
dis_rev = C - dis[::-1]
Sushi_cum = Sushi.cumsum()
Sushi_rev_cum = Sushi_rev.cumsum()
Sushi_cum -= dis
Sushi_rev_cum -= dis_rev
Sushi_max = np.maximum.accumulate(Sushi_cum)
Sushi_max_rev = np.maximum.accumulate(Sushi_rev_cum)
answer = max(0, Sushi_max[-1], Sushi_max_rev[-1])

for i in range(N-1):
    cal = Sushi_cum[i] - dis[i] + Sushi_max_rev[N-2-i]
    cal2 = Sushi_rev_cum[i] - dis_rev[i] + Sushi_max[N-2-i]
    cal = max(cal, cal2)
    if cal > answer:
        answer = cal

print(answer)


Measured memory_bytes: 37912
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N//2+N%2)
IndexCount=0
IndexRe=0
Divider=pow(10,9)+7
ans=1
if N%2==0:
    for i in range(N):
        if A[i]%2==1 and (A[i]+1)/2<=N/2:
            B[(A[i]-1)//2]+=1
        else:
            print(0)
            exit()
    for i in range((N//2+N%2)):
        if B[i]!=2:
            print(0)
            exit()
    IndexCount=int((N/2)//1000)
    IndexRe=int((N/2)%1000)
    for i in range(IndexCount):
        ans=(ans*(pow(2,1000)%Divider))%Divider
    ans=(ans*(pow(2,IndexRe)%Divider))%Divider
    print(ans)
elif N%2==1:
    for i in range(N):
        if A[i]%2==0 and A[i]/2<=(N-1)/2:
            B[A[i]//2]+=1
        else:
            print(0)
            exit()
    if B[0]!=1:
        print(0)
        exit()
    for i in range((N//2+N%2)-1):
        if B[i+1]!=2:
            print(0)
            exit()
    IndexCount=int(((N-1)/2)//1000)
    IndexRe=int(((N-1)/2)%1000)
    for i in range(IndexCount):
        ans=(ans*(pow(2,1000)%Divider))%Divider
    ans=(ans*(pow(2,IndexRe)%Divider))%Divider
    print(ans)
else:
    print(0)

Measured memory_bytes: 14008
import java.util.Scanner;
import java.util.LinkedList;
import java.lang.Math;
import java.util.Arrays;
import java.util.Collections;

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

        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] A = new int[n];

        for(int i=0;i <n;i++){
            A[i]=sc.nextInt();
        }
        sc.close();

        Arrays.sort(A);

        int[] B = new int[n];
        
        for(int i=0;i<n-1;i++){
            B[i]=A[i+1]-A[i];
        }
        B[n-1] = A[0]+k-A[n-1];

        int max = B[0];

        for(int i=0;i<B.length;i++){
            if(max<B[i]){
                max = B[i];
            }
        }
        k=k-max;
        System.out.print(k);
        
    //     for(int i=0;i<A.length;i++){
    //         System.out.println(A[i]);
    //     }
    //     for(int i=0;i<B.length;i++){
    //         System.out.println(B[i]);
    //     }
    }
}

Measured memory_bytes: 78452
s=input()
if s=="SAT":
    print(1)
elif s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print("4")
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void dfs(int v, vi &res, const vii &g) {
  for(int nv : g[v]) {
    if(res[nv] != inf) continue;
    res[nv] = res[v] + 1;
    dfs(nv, res, g);
  }
}

int main(){
  int n;
  cin >> n;
  vii g(n);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vi b(n, inf), w(n, inf);
  b[0] = 0, w[n-1] = 0;
  dfs(0, b, g);
  dfs(n-1, w, g);
  int f = 0, s = 0;
  rep(i,n) {
    if(b[i] <= w[i]) f++;
    else s++;
  }
  if(f <= s) cout << "Snuke" << endl;
  else cout << "Fennec" << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
//#define MOD 1000000007
const int INF = 1LL<<30;

int px[90001],py[90001];
int d[90001];

int main() {
    int h,w,D;
    cin>>h>>w>>D;

    rep(i,h){
        rep(j,w){
            int a;
            cin>>a;
            px[a]=i;
            py[a]=j;
        }
    }

    for(int i=D+1;i<=h*w;i++){
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    }

    int q;
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<d[r]-d[l]<<endl;
    }
}

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

struct entry {
    string city; 
    int score;
    int orindex;
};

bool compare_entries(entry left, entry right){
    // Returns true if left entry is better than right entry
    if (left.city !=right.city){
        return left.city < right.city; 
    }

    return left.score > right.score;
}

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

    vector<entry>entries;

    for (int i=0; i<n; i++){
        string city;
        int score;
        cin >> city >> score;

        entries.push_back(entry{city,score, i+1});
    }

    sort(entries.begin(), entries.end(), &compare_entries );
    
    for (entry e :entries){
        cout << e.orindex << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  ll x[N],y[N],z[N];
  for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> z[i];

  //bit探索
  ll ans = 0LL;
  for(int i=0 ; i<(1 << 3) ; i++){
    int key[3];
    for(int j=0;j<3;j++){
      if(i & (1<<j)) key[j] = 1;
      else key[j] = -1;
    }

    ll W[N] = {};
    for(int j=0;j<N;j++){
      W[j] += x[j] * key[2];
      W[j] += y[j] * key[1];
      W[j] += z[j] * key[0];
    }

    sort(W,W+N);
    reverse(W,W+N);

    ll sum = 0LL;
    for(int j=0;j<M;j++){
      sum += W[j];
    }

    ans = max(ans , sum);
  }

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

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

long solve(long n) {
    long temp = 1;
    int cl = ceil(sqrt(n));
    for (int i = 1; i <= cl; ++i) {
        if (n % i == 0 && temp + n/temp > i + n/i) {
            temp = i;
        }
    }
    return temp;
}


int main () {
    long n, m;

    scanf("%ld", &n);
    m = solve(n);
    printf("%ld\n", m + n/m - 2);
}

Measured memory_bytes: 128
def main():
    def is_prime(n):
        """
        input: n > 0
        output: True if n is prime,otherwise False
        """
        import math
        if n == 1: return False
        for i in range(2, int(math.sqrt(n)) + 1):
            if n%i == 0:
                return False
        else:
            return True


    N = int(input())
    A = [int(input()) for _ in range(N)]
    
    ans = 0
    for val in A:
        if is_prime(val):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 6024
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
     	int n = sc.nextInt();
     	int t = sc.nextInt();
     	int[] c = new int[n];
     	int[] time = new int[n];
     	for(int i=0;i<n;i++){
     		c[i] = sc.nextInt();
     		time[i] = sc.nextInt();
     	}
     	int min = 1001;
     	for(int i=0;i<n;i++){
     		if(time[i]<=t){
     			min = Math.min(min, c[i]);
     		}
     	}

     	if(min==1001){
     		System.out.println("TLE");
     	}
     	else{
     		System.out.println(min);
     	}
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0) return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int a; cin >> a;
	a %= 10;
	if(a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
	else if(a == 3) cout << "bon" << endl;
	else cout << "hon" << endl;
}


Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");
        int n = Integer.valueOf(arr01[0]);

        int cnt = 0;

        for (int i = 0; i < n; i++) {

            int a = Integer.valueOf(arr02[i]);

            if (a % 2 == 1) {
                cnt += 1;
            }

        }

        System.out.println(cnt % 2 == 0 ? "YES" : "NO");

    }

}

Measured memory_bytes: 50140
fun main(args: Array<String>) {
    var s = readLine()!!.dropLast(2)
    while (1 < s.length) {
        val length = s.length shr 1
        val t = s.substring(0, length)
        val u = s.substring(length, s.length)
        if (t == u) {
            println(s.length)
            break
        }
        s = s.dropLast(2)
    }
}


Measured memory_bytes: 33596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
string s,t;
cin>>s>>t;
ll ca=0;
for(ll i=0; i<s.size(); i++){
if(s.at(i)!=t.at(i))
ca++;}
cout<<ca <<endl;}


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

int gcd(int,int);

int main(){
	int x,y;
	cin>>x>>y;
	cout<<gcd(x,y)<<endl;

	
return 0;
}

int gcd(int x,int y){
	if(x<y) swap(x,y);
	int r;
	while (y>0){
		r=x%y;
		x=y;
		y=r;
	}

	return x;
}

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

using namespace std;

int minY, mini, maxi, curr, N, xx[200009], yy[200009], x[200009], y[200009], maX[200009], maY[200009], miY[200009], ind[200009];
long long ans;
vector < int > nrm;

bool cmp (int i, int j) {return xx[i] < xx[j];}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N), ans = 1000000000000000009LL;
for (int i=1; i<=N; i++)
{
    scanf ("%d %d", &xx[i], &yy[i]);
    if (xx[i] > yy[i]) swap (xx[i], yy[i]);
    ind[i] = i;
    nrm.push_back (xx[i]), nrm.push_back (yy[i]);
}
sort(nrm.begin(), nrm.end());
nrm.erase (unique (nrm.begin (), nrm.end ()), nrm.end ());
sort (ind + 1, ind + N + 1, cmp);
for (int i=1; i<=N; i++)
    x[i] = xx[ind[i]], y[i] = yy[ind[i]];
mini = nrm[0], maxi = nrm[nrm.size () - 1], minY = maxi + 2;
int i = 1;
for (auto& val : nrm)
{
    while (x[i] < val && i <= N)
    {
        if (y[i] > curr) curr = y[i];
        if (y[i] < minY) minY = y[i];
        i ++;
    }
    if (minY >= val)
    {
        int dr = max (x[N], curr);
        if (i > N) dr = curr;
        if (1LL * (dr - val) * (maxi - mini) < ans)
            ans = 1LL * (dr - val) * (maxi - mini);
    }
}
int st = mini, dr = x[N], dr2 = maxi, st2 = maxi;
for (int i=1; i<=N; i++)
    if (y[i] < st2)
        st2 = y[i];
if (1LL * (dr - st) * (dr2 - st2) < ans)
    ans = 1LL * (dr - st) * (dr2 - st2);
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 6896
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
string S;

int main(int argc, const char * argv[]) {
    cin >> S;

    string ans = "Good";

    char last = S[0];
    repd(i, 1, 4) {
        if (last == S[i]) {
            ans = "Bad";
            break;
        }
        last = S[i];
    }

    output(ans);

    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int res = 0;
    for (int i=1; i<=5; ++i) {
        int x;
        cin >> x;
        if (x == 0) res = i;
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<long long> vec(3 * N);
  for(int i = 0; i < 3 * N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
 long long sum = 0;
  for(int i = 0; i < N; i++) {
    sum += vec.at(i * 2 + N);
  }
  cout << sum << endl;
  
    
}
    

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var sheet = new int[3,3];
            for(var i = 0; i < 3; i++){
                var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                for(var j = 0; j < 3; j++){
                    sheet[i,j] = a[j];
                }
            }

            var n = int.Parse(Console.ReadLine());
            for(var k = 0; k < n; k++){
                var b = int.Parse(Console.ReadLine());

                for(var i = 0; i < 3; i++){
                    for(var j = 0; j < 3; j++){
                        if(sheet[i,j] == b){
                            sheet[i,j] = 0;
                        }
                    }
                }
            }

            var flag = false;
            for(var i = 0; i < 3; i++){
                if(sheet[i,0] == 0 && sheet[i,1] == 0 && sheet[i,2] == 0){
                    flag = true;
                    break;
                }
                if(sheet[0,i] == 0 && sheet[1,i] == 0 && sheet[2,i] == 0){
                    flag = true;
                    break;
                }
            }

            if(sheet[0,0] == 0 && sheet[1,1] == 0 && sheet[2,2] == 0){
                flag = true;
            }
            if(sheet[0,2] == 0 && sheet[1,1] == 0 && sheet[2,0] == 0){
                flag = true;
            }

            Console.WriteLine(flag ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		var a = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => long.Parse(number));

		long sunukeSum = a[0];
		long kumaSum = a.Skip(1).Sum();
		long differnece = Math.Abs(sunukeSum - kumaSum);
		for (long i = 1; i < n - 1; ++i) {
			sunukeSum += a[i];
			kumaSum -= a[i];
			long tempDifference = Math.Abs(sunukeSum - kumaSum);
			if (tempDifference < differnece) {
				differnece = tempDifference;
			}
		}

		Console.WriteLine(differnece);

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 32092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<62)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    int ac=0,wa=0,tle=0,re=0;

    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(s=="AC")
            ac++;
        else if(s=="WA")
            wa++;
        else if(s=="TLE")
            tle++;
        else if(s=="RE")
            re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define test cout<<"#"

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	ll v[n][3];
	for(ll x = 0; x < n; x++)
	{
		cin>>v[x][0]>>v[x][1]>>v[x][2];
	}
	ll ans[n][3] = {0};
	ans[0][0] = v[0][0];
	ans[0][1] = v[0][1];
	ans[0][2] = v[0][2];
	for(ll x = 1; x < n; x++)
	{
		ans[x][0] = max(ans[x-1][1], ans[x-1][2]) + v[x][0];
		ans[x][1] = max(ans[x-1][0], ans[x-1][2]) + v[x][1];
		ans[x][2] = max(ans[x-1][1], ans[x-1][0]) + v[x][2];
	}
	cout<<max(ans[n-1][0], max(ans[n-1][1], ans[n-1][2]));
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#define INT_MAX 2147483647

int main(void){
  int n;
  int val;

  int max_profit = -INT_MAX;
  int minv;

  std::cin >> n;
  std::cin >> minv;

  for(int i=0; i<n-1; i++){
      std::cin >> val;
      max_profit = std::max(max_profit, val - minv);
      minv = std::min(minv, val);
  }

  std::cout << max_profit << '\n';

  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


#define max 7368792

int main()
{
	while (true) {
		int m, n;
		cin >> m >> n;
		if (m == 0 && n == 0) break;
		vector<bool> used(max);
		int j = m;
		REP(i, n)
		{
			while (used[j]) ++j;
			for (int k = j; k < used.size(); k += j) {
				used[k] = true;
			}
		}
		while (used[j]) ++j;
		cout << j << endl;
	}
	return 0;
}

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

const int MAXN = 1e5+5;
const int MAXNN = 1e2+5;
int val[MAXNN],wei[MAXNN];
#define ll long long
ll dp[MAXN];

int main()
{
    int n,cap;cin >> n >> cap;
    for(int i=0;i<n;++i){
        cin >> val[i] >> wei[i];
    }
    for(int i=0;i<n;++i){
        for(int j=cap;j>=0;--j){
            // Choose this one
            if(j>=val[i]){
                dp[j] = max(dp[j],dp[j-val[i]]+wei[i]);
            }
        }
    }
    cout << dp[cap];
}


Measured memory_bytes: 1024
fun main(arr:Array<String>) {
    println(if(canBackHome(readLine()!!)) "Yes" else "No")
}

fun canBackHome(log:String):Boolean {
    val list1 = "SENW"
    val list2 = "NWSE"
    for(i in list1.indices) {
        if(log.contains(list1[i])) {
            if(!log.contains(list2[i])) {
                return false
            }
        }
    }
    return true
}

Measured memory_bytes: 37104
#include <bits/stdc++.h>
 using namespace std;
 int main(void){
     int N,M;
     int count=0;
     cin >> N >> M;
     
     vector<int> high(N);
     vector<int> yama(N);
     for(int i=0;i<N;i++){
     	cin >> high.at(i);
     }
     
     int A,B;
     for(int i=0;i<M;i++){
     	cin >> A >> B;
     	if(high.at(A-1)>high.at(B-1))
     		yama.at(B-1)=1;
     	else if(high.at(A-1)<high.at(B-1))
     		yama.at(A-1)=1;
     	else if(high.at(A-1)==high.at(B-1)){
     		yama.at(A-1)=1;
     		yama.at(B-1)=1;
     	}
     }
     
     for(int i=0;i<N;i++){
     	if(yama.at(i)==0)
     		count++;
     }
     cout << count;
 }

Measured memory_bytes: 3984
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct edge{ll from, to, weight;};

int main(){
  ll a,b;
  cin >> a >> b;
  if(a*b%2==0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# x,k,d = gets.chomp.split(' ').map(&:to_i)
# all = [[x]]
# # p all[0]
# # p all[0][0]
# min = x
# i = 0
# while i < k
#   a = []
#   j = 0
#   while j < all[i].size
#     a << (all[i][j]+d) if (all[i][j]+d).abs < min
#     a << (all[i][j]-d) if (all[i][j]-d).abs < min
#     min = all[i][j]+d if (all[i][j]+d).abs < min
#     min = all[i][j]-d if (all[i][j]-d).abs < min
#     # a << (all[i][j]+d)
#     # a << (all[i][j]-d)
#     j += 1
#   end
#   all << a
#   i += 1
# end
# p all
# p min

x,k,d = gets.chomp.split(' ').map(&:to_i)
x = x.abs
ans = 0
if x/d > k
  ans = x-d*k
else
  e = x/d
  k -= e
  x -= e*d
  x = (x-d).abs if k%2 == 1
  ans = x
end
p ans.abs


Measured memory_bytes: 14416
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <numeric>
#include <string>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int sum = a;
	int count = 1;
	while (true)
	{
		if (b == 1) {
			cout << 0;
			return 0;
		}
		if (sum >= b)break;
		sum += a - 1;
		count++;
	}

	cout << count;
	return 0;
}


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

using namespace std;

int main()
{
    string w;
    int flag = 0, a;
    cin >> w;

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

    for (int i = 0; i < w.length(); i++)
    {

        if (w[i] != w[i + 1])
        {
            a = i + 1;
        }

        if (a % 2 != 0)
        {
            flag = 2;
        }
    }

    if (flag == 2)
    {
        cout << "No";
    }

    else
    {
        cout << "Yes";
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n, a, b = [int(x) for x in input().split()]
count = 0
for i in range(n):
    i_str = str(i+1)
    i_sum = 0
    for j in range(len(i_str)):
        i_sum += int(i_str[j])
    if i_sum >= a:
        if i_sum <= b:
            count += (i+1)
print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	char b;
	scanf("%c",&b);
	if(b=='A') 
	printf ("T");
	if(b=='C')
	printf ("G");
	if(b=='G')
	printf ("C");
	if (b=='T')
	printf ("A");
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>  
#include <vector>  
#include <queue>  
#include <cstring>  
#include <algorithm>  
using namespace std;  
  
#define INF 1<<29  
#define F first  
#define S second  
  
struct edge {  
  int to, cost;  
  edge(int _to, int _cost) {to = _to; cost=_cost;}  
};  
typedef pair<int,int> P;  
  
int V;  
P taxi[5010];  
vector<int> R[5010];  
vector<edge> G[5010];  
int d[5010];  
  
void bfs(int s){  
  bool f[5010];  
  bool used[5010];  
  queue<P> q;  
  q.push(P(s, 0));  
  memset(f, true, sizeof(f));  
  memset(used, true, sizeof(used));  
  used[s] = false;  
  
  while(q.size()){  
    P que = q.front(); q.pop();  
    f[que.F] = false;  
    if(que.S > taxi[s].S){  
      continue;  
    }  
    if(used[que.F]){  
      G[s].push_back(edge(que.F, taxi[s].F));  
      used[que.F] = false;  
    }  
    for(int i = 0;i < R[que.F].size(); i++){  
      if(f[R[que.F][i]])  
        q.push(P(R[que.F][i], que.S + 1));  
    }  
  }  
}  
  
void dijkstra(int s){  
  priority_queue<P, vector<P>, greater<P> > que;  
  fill(d, d + V + 1, INF);  
  d[s] = 0;  
  que.push(P(0, s));  
  
  while(!que.empty()){  
    P p = que.top(); que.pop();  
    int v = p.second;  
    if(d[v] < p.first) continue;  
    for(int i = 0;i < G[v].size(); i++){  
      edge e = G[v][i];  
      if(d[e.to] > d[v] + e.cost){  
        d[e.to] = d[v] + e.cost;  
        que.push(P(d[e.to],e.to));  
      }  
    }  
  }  
}  
  
int main(void){  
  int m;  
  int a, b;  
  scanf("%d %d", &V, &m);  
  for(int i = 1;i <= V; i++){  
    scanf("%d %d", &a, &b);  
    taxi[i] = P(a, b);  
  }  
  for(int i = 0;i < m; i++){  
    scanf("%d %d", &a, &b);  
    R[a].push_back(b);  
    R[b].push_back(a);  
  }  
  
  for(int i = 1;i <= V; i++)  
    bfs(i);  
  
  dijkstra(1);  
  printf("%d\n", d[V]);  
} 


Measured memory_bytes: 125948
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
};
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}


ll n, k;
ll ruiseki[444];
ll a[444];
ll dp[444][444],visited[444][444];
ll rec(ll l,ll r){
   if(visited[l][r])return dp[l][r];
   visited[l][r] = 1;
   if (l == r)return 0;

   ll t = (1LL << 61);
   for(int i=l; i < r; i++){
      t = min(t, rec(l, i) + rec(i + 1, r));
   }
   return dp[l][r] = t+ ruiseki[r] - ruiseki[l-1];

}

int solve()
{

   cin >> n;
   for(int i=0; i < n; i++){
      cin >> a[i];
   }
   ruiseki[0] = a[0];
   for(int i=0; i < n-1; i++){
      ruiseki[i + 1] = ruiseki[i] + a[i+1];
   }
   cout << rec(0, n-1) << endl;



   return 0;
}
int main()
{
   //cout.precision(10)
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll N, K;
  cin >> N >> K;

  vpii v(N);
  for (ll i = 0; i < N; i++) {
    cin >> v[i].first >> v[i].second;
  }

  sort(v.begin(), v.end(), [](pii a, pii b) {
    return a.second > b.second;
  });

  unordered_set<ll> s;
  for (ll i = 0; i < K; i++) {
    s.insert(i);
  }

  unordered_map<ll, ll> cnt;
  for (auto i: s) {
    cnt[v[i].first]++;
  }

  priority_queue<pii, vpii, greater<pii>> to_be_removed;
  priority_queue<pii> to_be_added;

  for (ll i = 0; i < K; i++) {
    to_be_removed.push(make_pair(v[i].second, i));
  }

  for (ll i = K; i < N; i++) {
    to_be_added.push(make_pair(v[i].second, i));
  }

  ll sum = 0;
  for (auto i: s) {
    sum += v[i].second;
  }

  ll kinds = 0;
  for (auto i: cnt) {
    kinds += 1;
  }

  ll ma = sum + kinds * kinds;

  while (true) {
    while (to_be_added.size()) {
      ll i = to_be_added.top().second;

      if (cnt[v[i].first] > 0) {
        to_be_added.pop();
      } else {
        break;
      }
    }

    while (to_be_removed.size()) {
      ll i = to_be_removed.top().second;

      if (cnt[v[i].first] == 1) {
        to_be_removed.pop();
      } else {
        break;
      }
    }

    if (to_be_added.size() * to_be_removed.size() == 0) {
      break;
    }

    ll i = to_be_added.top().second;
    ll j = to_be_removed.top().second;
    to_be_added.pop();
    to_be_removed.pop();

    s.insert(i);
    s.erase(j);
    cnt[v[i].first] += 1;
    cnt[v[j].first] -= 1;
    kinds += 1;
    sum += v[i].second - v[j].second;
    ma = max(ma, sum + kinds * kinds);
  }

  cout << ma << endl;
}

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

int main(){
  string O, E;
  cin >> O >> E;

  for (int i = 0; i < O.size(); i++)
  {
    cout << O.at(i);

    if (O.size() - E.size() == 1 && i == O.size() - 1) break;

    cout << E.at(i);
  }
  cout << "" << endl;
}

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

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

int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  ll gcd=c,buf=d;
  while((buf=buf%gcd)!=0) swap(gcd,buf);
  ll lcm=c*d/gcd;

  ll cnt[3];

  cnt[0] = b/lcm - a/lcm;
  if(a%lcm==0) cnt[0]++;
  cnt[1] = b/c - a/c;
  if(a%c==0) cnt[1]++;
  cnt[2] = b/d - a/d;
  if(a%d==0) cnt[2]++;

  cout << b-a+1+cnt[0]-cnt[1]-cnt[2] << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
typedef long double ld;
typedef complex<ld> Point;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const ld eps = 1e-9, pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;


int main() {
	while (1) {

		int n, k, m; cin >> n >> k >> m;
		if (!n)break;
		vector<int>ans(n+1);
		ans[1] = 1;
		for (int i = 1; i < n; ++i) {
			ans[i + 1] =( k + ans[i]-1)%i+1;
		}
		int a = (ans[n] - 1) % n + 1;
		cout <<(( a+n-(n-m))%n? (a + n - (n - m)) % n:n) << endl;
	}
	return 0;

}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n;
int c[MAXN];
pair<int, int> ed[MAXN];
set<int> adj[MAXN];

void read()
{
	cin >> n;
	for(int i = 0; i + 1 < n; i++)
	{
		cin >> ed[i].first >> ed[i].second;
		adj[ed[i].first].insert(i);
		adj[ed[i].second].insert(i);
	}

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

int val[MAXN];
set<pair<int, int> > st;

void rem_edge(int u, int i)
{
	adj[u].erase(i);
	st.erase({SZ(adj[u]) + 1, u});
	st.insert({SZ(adj[u]), u});
}

void rem_edge(int i)
{
	int u = ed[i].first, v = ed[i].second;

	if(val[u] == 0) rem_edge(u, i);
	if(val[v] == 0) rem_edge(v, i);
}

void solve()
{
	sort(c, c + n);	
	reverse(c, c + n);

	for(int i = 1; i <= n; i++)
		st.insert({SZ(adj[i]), i});
	
	for(int ii = n - 1; ii >= 0; ii--)
	{
		auto best = st.begin();
		val[best->second] = c[ii];

		for(int e: adj[best->second])
			rem_edge(e);
	
		st.erase(best);
	}

	int answer = 0;
	for(int i = 0; i < n - 1; i++)
		answer += min(val[ed[i].first], val[ed[i].second]);

	cout << answer << endl;
	for(int i = 1; i <= n; i++)
		cout << val[i] << " ";
	cout << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 55040
import math

while True:
  n = int(raw_input())
  if n == 0:
    break
  s = map(float, raw_input().split(" "))

  sum = 0
  for i in xrange(n):
    sum += s[i]
  a = sum / n

  temp = 0
  for i in xrange(n):
    temp += (s[i] - a) ** 2
  temp = math.pow(temp / n, 0.5)

  print "{0:.6f}".format(temp)

Measured memory_bytes: 6712
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


int main() {
    long long N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i], --A[i], --B[i];
    }
        
    UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
            
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
        
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}

Measured memory_bytes: 3444
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

void main()
{
    auto S = readln.chomp;
    auto T = readln.chomp;
    int r;
    foreach (i, s; S) {
        if (s != T[i]) ++r;
    }
    writeln(r);
}

Measured memory_bytes: 3088
# ABC158 C
a,b=map(int,input().split())
# x=a*(100/8)
# y=b*(100/10)

# print(x,y)
# print(int(x),int(y))

# sx=x*((108-8)/100)
# sy=y*((110-10)/100)

# print(int(sx),int(sy))

for i in range(200000):
    x,y=0.0,0.0
    x=i*0.08
    y=i*0.10
    if a==int(x) and b==int(y):
        print(i)
        exit()
print(-1)

Measured memory_bytes: 3064
#include "stdio.h"

int main(int argc, char const *argv[]) {
  int A[4];
  for (size_t i = 0; i < 4; i++) {
    scanf("%d", &A[i]);
  }
  for (size_t i = 0; i < 4; i++) {
    if (A[i]!=1 && A[i]!=9 && A[i]!=7 && A[i]!= 4) {
      printf("NO");
      return 0;
    }
  }
  for (size_t i = 1; i < 4; i++) {
    if (A[i-1]==A[i]) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 128
def solve():
  ans = 0
  N, W = map(int, input().split())
  dp = [[0]*(W+1) for _ in range(N+1)]
  for i in range(1,N+1):
    w,v = map(int, input().split())
    for j in range(W+1):
      dp[i][j] = max(dp[i-1][j],dp[i][j])
      if j+w<=W:
        dp[i][j+w] = max(dp[i-1][j+w],dp[i-1][j]+v)
  return dp[-1][-1]
print(solve())

Measured memory_bytes: 151904
#include <iostream>
using namespace std;
int n,s,ans=0;

void search(int num,int sum,int pos) {
  if(num == 0) {
    if(sum == s) {
      ans++;
      return;
    }
  }
  for(int i=pos;i<10;i++) {
    search(num-1,sum+i,i+1);
  }
}

int main() {
  while(cin >> n >> s) {
    if(n==0&&s==0)break;
    search(n,0,0);
    cout << ans << endl;
    ans = 0;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    ll h,w,tmp1,tmp2,ans;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    if(h%2 == 1 && w%2 == 1){
        tmp1 = w/2;
        tmp2 = w-tmp1;
        ans = (h/2+1)*tmp2+(h/2)*tmp1;
        cout << ans << endl;
    }else if(h%2 == 1 && w%2 == 0){
        tmp1 = w/2;
        tmp2 = w-tmp1;
        ans = (h/2+1)*tmp2+(h/2)*tmp1;
        cout << ans << endl;
    }else if(h%2 == 0 && w%2 == 1){
        tmp1 = h/2;
        tmp2 = h-tmp1;
        ans = (w/2+1)*tmp2+(w/2)*tmp1;
        cout << ans << endl;
    }else if(h%2 == 0 && w%2 == 0){
        tmp1 = w/2;
        ans = (h/2)*tmp1*2;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import sys

N = int(input())
W = [input() for i in range(N)]

dic = [W[0]]
for word in W[1:]:
    if word in dic or word[0] != dic[-1][-1]:
        print('No')
        sys.exit()
    dic.append(word)

print('Yes')

Measured memory_bytes: 3060
// 2011/02/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		// üÍij
		int n;
		cin >> n;
		if(n==0)
			break;

		int cnt[10];
		for(int i=0; i<10; i++)		// ú»
			cnt[i] = 0;

		// üÍiíÞjÆJEg
		for(int i=0; i<n; i++){
			int ice;
			cin >> ice;
			cnt[ice]++;
		}

		// oÍ
		for(int i=0; i<10; i++){
			if(cnt[i]!=0){
				for(int j=0; j<cnt[i]; j++)
					cout << '*';
				cout << endl;
			}
			else{			// ÌÂª[
				cout << '-' << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long
typedef pair<int, int> P;

int H, W;
string A[1010];
int d[1010][1010];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
queue<P> que;

void bfs() {
	while (que.size()) {
		P p = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (nx >= 0 && nx < W && ny >= 0 && ny < H && d[ny][nx] == mod && A[ny][nx] != '#') {
				que.push({ nx,ny });
				d[ny][nx] = d[p.second][p.first] + 1;
			}
		}
	}
}

int main()
{
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				que.push({ j,i });
				d[i][j] = 0;
			}
			else {
				d[i][j] = mod;
			}
		}
	}
	bfs();
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, d[i][j]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 13456
#include <stdio.h>

int main() {
	int x, _, y, nl;
	int counter = 0;

	while ((nl = getchar()) != '\n') {}

	while (1) {
		x = getchar();
		if (x == EOF) {
			printf("No");
			return 0;
		}
		_ = getchar();
		y = getchar();
		nl = getchar();

		if (x == y) {
			counter += 1;
		} else {
			counter = 0;
		}

		if (counter == 3) {
			printf("Yes");
			return 0;
		}
	}
}


Measured memory_bytes: 1600
#!/usr/bin/env python
"""AtCoder Beginner Contest 167: A - Registration
https://atcoder.jp/contests/abc167/tasks/abc167_a
"""


def main():
    S = input()
    T = input()

    if S == T[0:-1]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(){
  int N,L;
  cin >> N >> L;
  
  int minApple = 0;
  for(int i = 0; i < N; i++){
    if(abs(L+minApple) > abs(L+i)) minApple = i;
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(i != minApple) ans += L + i;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256