akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 303;
typedef long long LL;
int n;
LL e[MaxN][MaxN];bool deleted[MaxN][MaxN];
typedef pair<int,pair<int,int> > PII;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n;
    for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) cin >> e[i][j];
    for (int k=1;k<=n;++k) for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) if (i!=j && i!=k && j!=k) {
        if (e[i][j]>e[i][k]+e[k][j]) {
            puts("-1");
            return 0;
        } else if (e[i][j]==e[i][k]+e[k][j]) {
            deleted[i][j]=true;
        }
    }
    LL sum=0;
    for (int i=1;i<=n;++i) for (int j=i+1;j<=n;++j) if (!deleted[i][j]) sum+=e[i][j];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Bits

main = do
    n <- readLn :: IO Int
    x <- C.getLine
    let bitsSet = C.count '1' x
        xLow = bsToModInt (bitsSet - 1) x
        xHi  = bsToModInt (bitsSet + 1) x

    forM_ [0..n-1] (\i -> if bitsSet == 1 && C.index x i == '1'
                then print 0
                else let memo = if C.index x i == '1'
                            then minusMod
                                (bitsSet - 1)
                                xLow
                                (powMod (bitsSet - 1) 2 (n-i-1))
                            else plusMod
                                (bitsSet + 1)
                                xHi
                                (powMod (bitsSet + 1) 2 (n-i-1))
                    in print (fNaive memo+1)
        )


step n = n `rem` (popCount n)

fNaive = fNaiveAux 0
    where
        fNaiveAux ac 0 = ac
        fNaiveAux ac n = fNaiveAux (ac+1) (step n)

bsToModInt :: Int -> C.ByteString -> Int
bsToModInt md bs = let l = C.length bs
    in foldr1 (plusMod md) $
        map (\flipPos -> if C.index bs (l-flipPos-1) == '1'
                then powMod md 2 flipPos else 0) [l-1,l-2..0]

powMod :: Int -> Int -> Int -> Int
powMod mdl b e = powAux (b `rem` mdl) e 1 `mod` mdl
    where 
        powAux _ 0 !ac = ac
        powAux b e !ac = powAux (b*b `rem` mdl) (e `quot` 2)
            (if odd e then b*ac `rem` mdl else ac)

plusMod  mdl a b = (a + b) `rem` mdl
minusMod mdl a b = (a - b) `mod` mdl

Measured memory_bytes: 14092
class Dice:
    index_list_map = [[[-1],[2,3,4,5],[4,1,3,5],[1,4,2,5],[3,2,1,5],[-1]],
                      [[3,2,5,4],[-1],[0,5,3,4],[5,0,2,4],[-1],[2,3,0,4]],
                      [[1,4,5,3],[5,0,4,3],[-1],[-1],[0,5,1,3],[4,1,0,3]],
                      [[4,1,5,2],[0,5,4,2],[-1],[-1],[5,0,1,2],[1,4,0,2]],
                      [[2,3,5,1],[-1],[5,0,3,1],[0,5,2,1],[-1],[3,2,0,1]],
                      [[-1],[3,2,4,0],[1,4,3,0],[4,1,2,0],[2,3,1,0],[-1]]]

    def __init__(self,list):
        self.num = list

    def lookup_east_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][0]]


    def lookup_west_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][1]]

    def lookup_north_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][2]]

    def lookup_down_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][3]]

spots1 = map(int,raw_input().split())
spots2 = map(int,raw_input().split())

s2_index_u = [ i for i,x in enumerate(spots2) if x == spots1[0]]
s2_index_s = [ i for i,x in enumerate(spots2) if x == spots1[1]]

combinations_u_s = [ [x,y] for x in s2_index_u for y in s2_index_s if x != y and (abs(x-2.5) != abs(y-2.5))]

dice2 = Dice(spots2)

for comb in  combinations_u_s :
    e = dice2.lookup_east_side(comb[0],comb[1])
    w = dice2.lookup_west_side(comb[0],comb[1])
    n = dice2.lookup_north_side(comb[0],comb[1])
    d = dice2.lookup_down_side(comb[0],comb[1])

    if e == spots1[2] and w == spots1[3] and n == spots1[4] and d == spots1[5]:
        print "Yes"
        quit()
print "No"

Measured memory_bytes: 6464
import sys
from time import time
from random import randint
from numpy import int64

def func(s, x):
    last = [0] * 26
    score = 0
    for i, v in enumerate(x, 1):
        last[v] = i
        c = 0
        for j in range(26):
            c += s[j] * (i - last[j])
        score += s[i * 26 + v] - c
    return score

def main():
    start = time()
    d, *s = map(int, sys.stdin.buffer.read().split())
    s = int64(s)
    x = int64(([*range(26)] * 15)[:d])
    M = func(s, x)
    while time() - start < 1.85:
        y = x.copy()
        if randint(0, 1):
            y[randint(0, d - 1)] = randint(0, 25)
        elif randint(0, 1):
            i=randint(0, d - 16)
            j=randint(i + 1, i + 15)
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y)
        if t > M:
            M = t
            x = y
    print(*x + 1, sep='\n')

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('func', 'i8(i8[:], i8[:])')(func)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import func
    main()

Measured memory_bytes: 27944
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;
ll mod2 = (ll) 1e9 + 9;

signed main() {
    ll n;
    cin >> n;
    ld now = 0;
    for(int i = 0; i < n;++i) {
        ld x;
        cin >> x;
        now += 1 / x;
    }
    cout << fixed << setprecision(6) << 1/ now;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
string s[N];
char ans[N];
ll n,aa,bb,cc;
void dfs(int x,ll a,ll b,ll c)
{
	if(x==n+1)
	{
		cout<<"Yes"<<endl;
		for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;
		exit(0);
	}
	if(s[x]=="AB")
	{
		if(b)ans[x]='A',
		dfs(x+1,a+1,b-1,c);
		if(a)ans[x]='B',
		dfs(x+1,a-1,b+1,c);
	}
	else if(s[x]=="AC")
	{
		if(c)ans[x]='A',
		dfs(x+1,a+1,b,c-1);
		if(a)ans[x]='C',
		dfs(x+1,a-1,b,c+1);
	}
	else
	{
		if(c)ans[x]='B',
		dfs(x+1,a,b+1,c-1);
		if(b)ans[x]='C',
		dfs(x+1,a,b-1,c+1);
	}
}
int main()
{
	cin>>n>>aa>>bb>>cc;
	for(int i=1;i<=n;i++)cin>>s[i];
	dfs(1,aa,bb,cc);
	cout<<"No";
	return 0;
}


Measured memory_bytes: 14596
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	long c[]=new long[a];
	long count=0;
	for(int i=0;i!=a;i++) {
		int b=scan.nextInt();
		c[i]=b;
	}
	for(int i=0;i<a-1;i++) {
		if(c[i]==c[i+1]) {
			count++;
			i++;
		}
	}
	System.out.println(count);
	}
}


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

int main(){
	int n;
	cin >> n;
	int a[n];
	int min, max;
	long sum;
	cin >> a[0];
	min = a[0];
	max = a[0];
	sum += a[0];
	for(int i = 1; i < n; i++){
		cin >> a[i];
		if(min > a[i]){
			min = a[i];
		}else if(max < a[i]){
			max = a[i];
		}
		sum += a[i];
	}
	cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 1204
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   bool flg = 1;
   rep(i,s.size()){
      if(i==a){
         if( s[i] != '-') flg = 0;
      }else{
         if(s[i]<48 || s[i]>59) flg = 0;
      }
   }

   if(flg) cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;



int32_t main(){
    FAST;

    int k ,x;   cin >> k >> x;

    int left = max(x-k+1 , -1000000LL);
    int right = min(1000000LL , x+k-1);
    
    for(int x=left ; x <= right ; x++)
            cout << x << ' ';
    
    return 0;
}


Measured memory_bytes: 256
//Created by Aminul on 8/14/2019.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    static double N;
    static int n;
    static double dp[][][];

    public static void main(String[] args) throws Exception {
        new Thread(null ,new Runnable(){
            public void run(){
                try{solveIt();} catch(Exception e){e.printStackTrace(); System.exit(1);}
            }
        },"Main",1<<28).start();
    }

    public static void solveIt() throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        n = in.nextInt();
        int a[] = new int[4];
        for (int i = 0; i < n; i++) {
            a[in.nextInt()]++;
        }
        dp = new double[n + 1][n + 1][n + 1];
        N = n;
        for (double x[][] : dp) for (double y[] : x) Arrays.fill(y, -1);
        pw.println(solve(a[1], a[2], a[3]));

        pw.close();
    }

    static double solve(int ones, int twos, int threes) {
        if (ones == 0 && twos == 0 && threes == 0) return 0;
        if (dp[ones][twos][threes] != -1) return dp[ones][twos][threes];
        int zeros = n - ones - twos - threes;
        double e = 1;
        if (ones > 0) e += (ones / N) * solve(ones - 1, twos, threes);
        if (twos > 0) e += (twos / N) * solve(ones + 1, twos - 1, threes);
        if (threes > 0) e += (threes / N) * solve(ones, twos + 1, threes - 1);
        if (zeros > 0) e /= (1 - (zeros / N));
        return dp[ones][twos][threes] = e;
    }

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

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

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    for(auto& e : a) cin >> e;
    string mes = "Yes";
    if(h > accumulate(begin(a), end(a), 0)){
        mes = "No";
    }
    cout << mes << endl;
    return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==m)
    {
        cout<<"Yes"<<endl;
    }
    else if(n>m)
    {
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

const double PI = 3.14159265358979;

int CNT = 0;

void printArr(int a[], int len) {

	for (int i = 0; i < len; i++) {
		if (i == 0) cout << a[0];
		else cout << " " << a[i];
	}
	cout << endl;
}

void merge(int a[], int left, int mid, int right) {

	//if (right - left == 1) return;

	int Llen = mid - left;
	int Rlen = right - mid;
	int* L = new int[Llen + 1];
	int* R = new int[Rlen + 1];

	for (int i = 0; i < Llen; i++) {
		L[i] = a[left + i];
	}
	L[Llen] = INT_MAX;
	for (int i = 0; i < Rlen; i++) {
		R[i] = a[mid + i];
	}
	R[Rlen] = INT_MAX;

	int ll = 0, rr = 0;
	for (int i = left; i < right; i++) {
		CNT++;
		if (L[ll] <= R[rr]) {
			a[i] = L[ll++];
		}
		else {
			a[i] = R[rr++];
		}
	}

	delete[] L;
	delete[] R;
}

void mergeSort(int a[], int left, int right) {

	if (left + 1< right) {
		int mid = (left + right) / 2;
		mergeSort(a, left, mid);
		mergeSort(a, mid, right);
		merge(a, left, mid, right);
	}
}



int main() {

	int n; cin >> n;
	int* a = new int[n];
	for (int i = 0; i < n; i++)	{
		scanf("%d", &a[i]);
	}

	mergeSort(a, 0, n);
	printArr(a, n);
	cout << CNT << endl;

	return 0;
}



Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

struct Point { double x, y;};

void koch(int n, Point a, Point b){
    if(n == 0) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

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

    int n; cin >> n;
    Point a, b;
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;
}


Measured memory_bytes: 3176
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    tot = sum(A)

    ans = (10 ** 9) * (2 * 10 ** 5) + 1
    s = 0
    for x in A[:-1]:
        s += x + x
        diff = abs(tot - s)
        if ans > diff:
            ans = diff

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25068
H, W, K = map(int, input().split())
T = []
for i in range(H):
    a = list(input())
    T.append(a)

ans = 0
for i in range(2**H):
    for j in range(2**W):
        c = 0
        for p in range(H):
            for q in range(W):
                if T[p][q] == "#":
                    if (i>>p) & 1:
                        if (j>>q) & 1:
                            c += 1
        if c == K:
            ans += 1
print(ans)


Measured memory_bytes: 68432
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int N; cin>>N;
    vi A(N+1, 0); FOR(i,2,N+1) cin>>A[i];

    vi ans(N+1);
    FOR(i,2,N+1) {
        int boss = A[i];
        ans[boss] += 1;
    }

    FOR(i,1,N+1)
        cout << ans[i] << endl;


    return 0;
}


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

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        List<int> s = Console.ReadLine().Split().Select(int.Parse).Distinct().ToList();
        int q = int.Parse(Console.ReadLine());
        int[] t = Console.ReadLine().Split().Select(int.Parse).ToArray();
        n = s.Count();
        int count = 0;
        for(int i = 0; i < q; i ++) {
            s.Add(t[i]);
            count += linearSearch(s,n);
            s.RemoveAt(n);
        }
        Console.WriteLine(count);
    }
    static int linearSearch(List<int> s,int n) {
        int i = 0;
        int key = s[n];
        while(s[i] != key) {
            i ++;
            if (i == n) {
                return 0;
            }
        }
        return 1;
    }
}


Measured memory_bytes: 18296
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12


int search(int a,int b,int kaisu){
	if(a==b){
		return kaisu;
	}else if(a==-b){
		return kaisu+1;
	}else if(a<-abs(b)){
		return search(-abs(b),b,kaisu-abs(b)-a);
	}else if(a>abs(b)){
		return search(-a,b,kaisu+1);
	}else if(a>=0){
		return search(abs(b),b,kaisu+abs(b)-a);
	}else{
		return search(-a,b,kaisu+1);
	}
}


int main(void)
{
	//変数の宣言
	int x,y;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	
	
	//データの読み込み
	scanf("%d %d",&x,&y);
//	scanf_s("%d %d",&x,&y);

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理
	
	ans=search(x,y,0);

	//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);

	//	printf("結果の出力終了\n");

	
	return 0;
}



Measured memory_bytes: 128
#!/usr/bin/ruby
def dfs(s)
	r=''
	i=0
	n=nil
	while i<s.size
		if ('0'..'9').include?(s[i])
			if !n
				n=s[i].to_i
			else
				n=n*10+s[i].to_i
			end
			i+=1
		elsif s[i]=='('
			n=1 if !n
			cnt=1
			j=i+1
			while cnt>0
				if s[j]=='('
					cnt+=1
				elsif s[j]==')'
					cnt-=1
				end
				j+=1
			end
			_r=dfs(s[i+1..j-2])
			n.times{
				r+=_r
				return r if r.size>$n
			}
			n=nil
			i=j
		else
			n=1 if !n
			r+=s[i]*n
			n=nil
			i+=1
		end
	end
	r
end
i=0
loop{
	s,_=gets.split
	break if s=='0'
	$n=_.to_i
	r=dfs(s)
	puts r.size>$n ? r[$n] : '0'
}

Measured memory_bytes: 18068
#include <bits/stdc++.h>
#define r(x,i,n) for(int i = x; i<n; i++)
using namespace std;

int main(){
  int n,m,i=0,j=0;
  bool flag=false;
  cin >> n;
  vector<int> v1(n+1,0);
  r(0,i,n)cin >> v1.at(i);
  cin >> m;
  vector<int> v2(m+1,0);
  r(0,i,m)cin >> v2.at(i);
  sort(v1.begin(),v1.end()-1);
  sort(v2.begin(),v2.end()-1);
  while(1){
    if(v2.at(j)==0){
      flag=true;
      break;
    }
    else if(v1.at(i)==0)break;
    if(v1.at(i)==v2.at(j)){
      i++;j++;
    }
    else i++;
  }
  if(flag)cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = -1; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;


int main() {

	int n;

	cin >> n;
	vector<int> p(n);
	rep(i, n)cin >> p[i];
	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
	
		if(p[i-1]<p[i]&&p[i]<p[i+1]){
			ans++;
		}
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
			ans++;
		}
	
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define INF (1<<31-1)
#define ll long long


// 頻度をmapに変換		{1,2,1,1,3,2,2}=>{1:3, 2:3, 3:1}
map<int, int> count(int*a, int*b){
	map<int, int> m;
	for (; a != b; a++){
		m[*a]++;
	}
	return m;
}

// 頻度順にsortしたpairをvector		{1,2,1,1,3,2,2}=>{(1,3),(2,3),(3,1)}
vector<P> most_common(int*a, int*b){
	map<int, int> m = count(a, b);
	vector<P> v;
	for (auto i = m.begin(); i != m.end(); i++){
		v.push_back(P(i->first, i->second));
	}
	sort(v.begin(), v.end(), [](const P& x, const P& y){return x.second > y.second; });
	return v;
}

// 連続する長さを数えてpairをvector		{1,2,1,1,3,2,2}=>{(1,1),(2,1),(1,2),(3,1),(2,2)}
vector<P> count_runlength(int*a, int*b){
	vector<P> v;
	int p = *a;
	int l = 0;
	while (1){
		a++;
		l++;
		if (a == b) break;
		if (p != *a){
			v.push_back(P(p, l));
			l = 0;
			p = *a;
		}
	}
	v.push_back(P(p, l));
	return v;
}


int main(){

//	map<int, int> m = count(a, a + 7);
//	vector<P> v = most_common(a, a + 7);
//	vector<P> v1 = count_runlength(a, a + 7);

	int n;
	int v[100001], even[50001], odd[50001];

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	for (int i = 0; i < n/2; i++){
		even[i] = v[i * 2];
		odd[i] = v[i * 2 + 1];
	}

	auto v1 = most_common(even, even + n / 2);
	auto v2 = most_common(odd, odd + n / 2);

	v1.push_back(P(0, 0));
	v2.push_back(P(0, 0));

	if (v1[0].first == v2[0].first)
		cout << min(n - v1[0].second - v2[1].second, n - v1[1].second - v2[0].second) << endl;
	else
		cout << n - v1[0].second - v2[0].second << endl;

	return 0;
}


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

void Watch(int S)
{
	int h,m,s;

	h = S/3600;
	m = S%3600/60;
	s = S%60;

	cout<<h<<':'<<m<<':'<<s<<endl;
}

int main()
{
	int x;

	cin >>x;

	Watch(x);

	//while(1);

	return 0;
}

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

int main(){
  int n,ans=1;
  string s;
  cin>>n>>s;
  
  rep(i,0,n-1){
    if(s.substr(i,1)!=s.substr(i+1,1)){ans++;}
  }
  
  cout<<ans<<endl;
  
  return 0;
}

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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a


using ll = long long;

int main() {
    IN(string, s);
    int c = 0;
    int n = s.length();
    REP(i, n/2){
        if(s[i] != s[n-1-i]) c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Os")
#pragma GCC optimize("Og")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,sse,sse2,sse3,ssse3,sse4")
#include <stdio.h>
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline long long read(){
	long long now=0;int f=0;register char c=gc();
	for(;c<48||c>57;c=='-'&&(f=1),c=gc());for(;c>47&&c<58;now=(now<<3)+(now<<1)+c-'0',c=gc());
	return f?-now:now;
}
#define Maxn 200005
long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
long long Min(long long x, long long y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; }
signed main()
{
	n=read(),d=read();
	for (int i=0;i<n;++i) a[i]=read(),ans+=a[i];
	ans+=(n-1)*d;dpl[0]=a[0];dpr[n-1]=a[n-1];
	for (int i=1;i<n;++i) dpl[i]=Min(a[i],dpl[i-1]+d);
	for (int i=n-2;~i;--i) dpr[i]=Min(a[i],dpr[i+1]+d);
	for (int i=1;i<n-1;++i) ans+=Min(dpl[i],dpr[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
struct Mino{
  Int h,w;
  vector<string> vs;
};
vector<Mino> ms(4);

const Int H=4,W=10;
set< vector<string> > cs;
vector<string> bs(H,string(W,'#')),st;

void fill(Mino m,Int k){
  Int y=k/W,x=k%W;
  if(y+m.h>H||x+m.w>W) return;
  for(Int i=0;i<m.h;i++)
    for(Int j=0;j<m.w;j++)
      if(m.vs[i][j]=='#') st[y+i][x+j]='.';
}

void solve(){
  for(Int i=0;i<4;i++){
    for(Int j=0;j<i;j++){
      for(Int k=0;k<j;k++){
        for(Int a=0;a<40;a++){
          for(Int b=0;b<40;b++){
            for(Int c=0;c<40;c++){
              st=bs;
              fill(ms[i],a);
              fill(ms[j],b);
              fill(ms[k],c);

              //for(int p=0;p<H;p++) cout<<st[p]<<endl;
              //cout<<endl;

              cs.emplace(st);
            }
          }
        }
      }
    }
  }
}

signed main(){
  for(Int i=0;i<4;i++){
    cin>>ms[i].h>>ms[i].w;
    ms[i].vs.resize(ms[i].h);
    for(Int j=0;j<ms[i].h;j++)
      cin>>ms[i].vs[j];

    if(0){
      for(Int j=0;j<ms[i].h;j++)
        cout<<ms[i].vs[j]<<endl;
      cout<<endl;
    }
  }
  solve();

  Int n;
  cin>>n;
  for(Int i=0;i<n;i++){
    vector<string> st(4);
    for(Int j=0;j<4;j++) cin>>st[j];
    if(cs.count(st)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 18220
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

int e[101] = {};

int num(int x) {
    int res = 0;
    REP(i, 101) {
        if (e[i] >= x - 1) {
            res++;
        }
    }
    return res;
}

// main
int main() {
    int N;
    cin >> N;
    FOR(i, 2, N + 1, 1) {
        int n = i;
        FOR(j, 2, i + 1, 1) {
            while (n % j == 0) {
                e[j]++;
                n /= j;
            }
        }
    }
    cout << num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) +
                num(5) * (num(5) - 1) * (num(3) - 2) / 2
         << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int N; cin >> N;
    vector<int> A(N), B(N);
    for(auto& t : A) cin >> t;
    for(auto& t : B) cin >> t;
    priority_queue<pair<int, int>> qu;
    for(int i=0;i<N;i++) qu.emplace(B[i], i);
    long long res = 0;
    while(!qu.empty()){
        int idx = qu.top().second; qu.pop();
        if(A[idx] == B[idx]) continue;
        int a = B[(idx+N-1)%N], b = B[(idx+1)%N];
        if(max(a, b) <= A[idx]){
            if((B[idx]-A[idx])%(a+b) != 0) break;
            res += (B[idx]-A[idx])/(a+b);
            B[idx] = A[idx];
        } else {
            long long m = max(1, (B[idx] - max(a, b))/(a+b));
            res += m;
            B[idx] -= m * (a + b);
            if(B[idx] >= max(a, b)){
                res++;
                B[idx] -= a + b;
            }
            if(B[idx] < A[idx]) break;
            if(B[idx] > A[idx]) qu.emplace(B[idx], idx);
        }
    }
    cout << (A == B ? res : -1) << endl;
}

Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        string inpt = Reader.ReadLine();
        inpt = inpt.Replace(inpt[0]=='W'?'B':'W', '1');
        inpt = inpt.Replace(inpt[0], '0');
        inpt = Conv(inpt);

        int ans = inpt.Length - 1;
        Console.WriteLine(ans);
    }


    private string Conv(string str)
    {
        System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex("00+");
        string tmp = rg.Replace(str, "0");
        System.Text.RegularExpressions.Regex rg2 = new System.Text.RegularExpressions.Regex("11+");
        return rg2.Replace(tmp, "1");
    }



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

WBWBWBWBWB


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ll A,B,x;
    cin >> A >> B >> x;
    ll mx=0;
    if(x>=B){
        cout << A*(B-1)/B-A*((B-1)/B) << endl;
    }
    else{
        cout << A*x/B << endl;
    }
}

Measured memory_bytes: 3640
def f(n, l):
  ss = [input() for i in range(n)]
  ss.sort()
  return ''.join(ss)
  
if __name__ == '__main__':
  nl = [int(n) for n in input().split(' ')]
  n = nl[0]
  l = nl[1]
  print(f(n, l))

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;

const int INF = 1e7;

namespace NetFlow
{
	const int N = 2e5+2;
	const int M = 4e5;
	struct Edge
	{
		int v,w,nxt,rev;
	} e[(M<<1)+3];
	int fe[N+3];
	int te[N+3];
	int dep[N+3];
	int que[N+3];
	int n,en,s,t;
	void addedge(int u,int v,int w)
	{
//		printf("addedge %d %d %d\n",u,v,w);
		en++; e[en].v = v; e[en].w = w;
		e[en].nxt = fe[u]; fe[u] = en; e[en].rev = en+1;
		en++; e[en].v = u; e[en].w = 0;
		e[en].nxt = fe[v]; fe[v] = en; e[en].rev = en-1;
	}
	bool bfs()
	{
		for(int i=1; i<=n; i++) dep[i] = 0;
		int head = 1,tail = 1; que[1] = s; dep[s] = 1;
		while(head<=tail)
		{
			int u = que[head]; head++;
			for(int i=fe[u]; i; i=e[i].nxt)
			{
				int v = e[i].v;
				if(e[i].w>0 && dep[v]==0)
				{
					dep[v] = dep[u]+1;
					if(v==t)return true;
					tail++; que[tail] = v;
				}
			}
		}
		return false;
	}
	int dfs(int u,int cur)
	{
		if(u==t||cur==0) {return cur;}
		int rst = cur;
		for(int &i=te[u]; i; i=e[i].nxt)
		{
			int v = e[i].v;
			if(e[i].w>0 && rst>0 && dep[v]==dep[u]+1)
			{
				int flow = dfs(v,min(rst,e[i].w));
				if(flow>0)
				{
					e[i].w -= flow;	
					rst -= flow;
					e[e[i].rev].w += flow;
					if(rst==0) {return cur;}
				}
			}
		}
		if(rst==cur) {dep[u] = -2;}
		return cur-rst;
	}
	int dinic(int _n,int _s,int _t)
	{
		n = _n,s = _s,t = _t;
		int ret = 0;
		while(bfs())
		{
			for(int i=1; i<=n; i++) te[i] = fe[i];
			memcpy(te,fe,sizeof(int)*(n+1));
			ret += dfs(s,INF);
		}
		return ret;
	}
}
using NetFlow::addedge;
using NetFlow::dinic;

const int N = 1e5;
int a[N+3],b[N+3];
int ca[N+3],cb[N+3];
int n,cnta,cntb;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]),a[i]++;
	for(int i=1; i<=n; i++) scanf("%d",&b[i]),b[i]++;
	for(int i=1; i<=n; i++)
	{
		if(!ca[i])
		{
			cnta++;
			int x = i;
			do
			{
				ca[x] = cnta;
				x = a[x];
			} while(x!=i);
		}
	}
	for(int i=1; i<=n; i++)
	{
		if(!cb[i])
		{
			cntb++;
			int x = i;
			do
			{
				cb[x] = cntb;
				x = b[x];
			} while(x!=i);
		}
	}
//	printf("ca: "); for(int i=1; i<=n; i++) printf("%d ",ca[i]); puts("");
//	printf("cb: "); for(int i=1; i<=n; i++) printf("%d ",cb[i]); puts("");
	int ans = n;
	for(int i=1; i<=n; i++)
	{
		if(a[i]==i && b[i]==i) {ans--;}
		else if(a[i]==i) {addedge(1,cb[i]+cnta+2,1);}
		else if(b[i]==i) {addedge(ca[i]+2,2,1);}
		else
		{
			addedge(ca[i]+2,cb[i]+cnta+2,1);
			if(a[i]==b[i]) {addedge(cb[i]+cnta+2,ca[i]+2,1);}
		}
	}
	ans -= dinic(2+cnta+cntb,1,2);
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int k, n, x=0;
  cin >> k >> n;
  vector<int> vec(n);
  for (int i=0; i<n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i=1; i<n; i++) {
    x=max(x,vec.at(i)-vec.at(i-1));
  }
  x=max(x,vec.at(0)+k-vec.at(n-1));
  cout << k-x << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

void fill_square(int num,int square[15][15],int is_filled[15][15],int x,int y,int n) {

  int flag=1;
  int i,j;

  if(y>=n) fill_square(num,square,is_filled,x,0,n);

  else if(y<0) fill_square(num,square,is_filled,x,n-1,n);

  else if(x>=n) fill_square(num,square,is_filled,0,y,n);

  else if(is_filled[x][y]==1) fill_square(num,square,is_filled,x+1,y-1,n);

  else {
    
    square[x][y]=num;

    is_filled[x][y]=1;

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

      for(j=0;j<n;j++) {

	if(is_filled[i][j]==0) flag=0;

      }

    }

    if(flag==0) fill_square(num+1,square,is_filled,x+1,y+1,n);

  }

}

int main(void) {

  int n;

  int square[15][15];
  int is_filled[15][15];
  
  int i,j;


  while(1) {

    scanf("%d",&n);

    if(n==0) break;

    for(i=0;i<15;i++) for(j=0;j<15;j++) is_filled[i][j]=0;

    square[(n+1)/2][(n-1)/2]=1;

    is_filled[(n+1)/2][(n-1)/2]=1;

    fill_square(2,square,is_filled,(n+3)/2,(n+1)/2,n);

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

      for(j=0;j<n;j++) {

	printf("%4d",square[i][j]);

      }

      puts("");

    }

  }

  return 0;

}

    

Measured memory_bytes: 0
#include <iostream>
using namespace std;
#define Min -1000000000
int main(){
    int n;
    cin>>n;
    int maxn = Min;
   // for(int i =0;i<n;++i) cin>>a[i];
    /*for(int i = 0;i<n;++i){
        for(int j =i+1;j<n;++j)
            if(a[j]-a[i]>maxn) maxn=a[j]-a[i];
    }*/
    int minn;
    cin>>minn;
  for(int j = 1;j<n;++j){
     int x;
     cin>>x;
      if(x-minn>maxn) maxn = x-minn;
       if(x<minn) minn = x;
  }
      
      
 
    cout<<maxn<<endl;
    return 0;
}


Measured memory_bytes: 3104
n=int(input())
s=str(n)+":"
b=True
d=n
i=2
while b:
 if d%i==0:
  d/=i
  s+=' '+str(i)
  i-=1
 b=i<d**0.5
 i+=1
if d!=1:s+=' '+str(int(d))
print(s)

Measured memory_bytes: 7752
#include <stdio.h>

//prototype
int main(void);

//main
int main(void){

  int n, i, j;
  int str[100];

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &str[i]);
  }

  for (j = i - 1; j >= 0; j--) {

    if (j != 0) {
      printf("%d ", str[j]);
    }else{
      printf("%d\n", str[j]);
    }
  }

  return 0;

}



Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;
int graph[110][110];
int c,n,m,s,d;
int D[110][15];
const int INF = 1<<28;

void Init(){
  for(int i=0;i<110;i++){
    for(int k=0;k<110;k++){
      graph[i][k] = INF;
    }
    for(int j=0;j<15;j++){
      D[i][j] = INF;
    }
  }

}


void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  D[s][c] = 0;
  // PP( P(pos,cost), c )
  // .F.F -> pos
  // .F.S -> cost
  // .S   -> c
  que.push(PP(P(s,0),c));
  while(!que.empty() ){
    PP p = que.top();que.pop();
    int v = p.F.F;
    for(int i=1;i<=n;i++){
     
      if(D[i][p.S] > graph[v][i] + p.F.S){
	D[i][p.S] = graph[v][i] + p.F.S;
	que.push(PP(P(i,D[i][p.S]),p.S));
      }

      if(D[i][p.S-1] > graph[v][i]/2 + p.F.S && p.S != 0){
	D[i][p.S-1] = graph[v][i]/2 + p.F.S;
	que.push(PP(P(i,D[i][p.S-1]),p.S-1));
      }


    }


  }

}

int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    Init();

    for(int i=0;i<m;i++){
      cin >> x >> y >> co;
      graph[x][y] = graph[y][x] = co;
    }


    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++)ans = min(ans,D[d][i]);
    cout<< ans << endl;
  }
  return 0;
}


//Version.2

Measured memory_bytes: 1380
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

bool prime(int n){
	if(n==1)
		return false;
	if(n==2)
		return true;
	for(int i=2;i*i<=n;i++){
		if(n%i==0)
			return false;
	}
	return true;
}

void solve(){
	int n;cin>>n;
	for(int i=n;i<=N;i++){
		if(prime(i)){
			cout<<i;
			return;
		}
	}
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    int N;
    cin >> N;
    vector<int> data;
    int sum = 0;
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        data.push_back(tmp);
        sum += tmp;
    }
    int ans = 0;
    int min_diff = INF;
    rep(i, N)
    {
        if (min_diff > (N * data[i] - sum > 0 ? N * data[i] - sum : sum - N * data[i]))
        {
            ans = i;
            min_diff = (N * data[i] - sum > 0 ? N * data[i] - sum : sum - N * data[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def bubble_sort(A):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
    return count


def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1])


n = int(input())
line = input()
A = list(map(int, line.split()))
count = bubble_sort(A)
show(A)
print(count)

Measured memory_bytes: 7764
#include <stdio.h>
#include <iostream>
using namespace std;

struct music_t{
  string title;
  int time;
};

int main(void)
{
  int n = 0;
  int sleepflg = 0;
  string endtitle;
  int sleeptime = 0;

  scanf("%d",&n);
  
  music_t music[n];

  for(int i = 0; i < n; i++){
    cin >> music[i].title >> music[i].time;
//    cout << music[i].title << " " << music[i].time << "\n";
  }
  cin >> endtitle;
//  cout << endtitle << "\n";

  for(int i = 0; i < n; i++){
    if(sleepflg == 0){
     if(music[i].title == endtitle){
       sleepflg = 1;
     }
    }else{
      sleeptime = sleeptime + music[i].time;
    }
  }
  
  printf("%d",sleeptime);
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
    long[,] area = new long[1002,1002];//シールを貼った部分
    long answer = 0;

    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る

      area[nums[0],nums[1]]++;
      area[nums[0],nums[3]]--;
      area[nums[2],nums[1]]--;
      area[nums[2],nums[3]]++;
    }

    for(long x = 1; x <= 1000; x++)
    {
      for(long y = 0; y <= 1000; y++)
      {
        area[x,y] += area[x-1,y];
      }
    }

    for(long y = 1; y <= 1000; y++)
    {
      for(long x = 0; x <= 1000; x++)
      {
        area[x,y] += area[x,y-1];
      }
    }
    
    for(long x = 0; x <= 1000; x++)
    {
      for(long y = 0; y <= 1000; y++)
      {
        answer = Math.Max(answer, area[x,y]);
      }
    }

		Console.WriteLine(answer);
	}
}


Measured memory_bytes: 27372
import math
a,b,x = map(int,input().split())

y = math.atan((a*(b**2))/(2*x))

if b/math.tan(y) <= a:
    print(math.degrees(y))
    
else:
     print(math.degrees(math.atan(2*(a**2*b-x)/(a**3))))

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

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

    string ans = "Yes";
    for (size_t i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            ans = "No";
            break;
        }
    }

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


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

int main(){
    string x;
    cin >> x;
    int y[3];
    for(int i=0; i<3; i++){
        y[i] = 0;
    }
    int flag = 1;
    for(int i=0; i < 3; i++){
        if(y[x[i] - 'a'] == 0){
            y[x[i] - 'a'] = 1;
        }else{
            flag = 0;
            break;
        }
    }
    if(flag == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main(){
    int N, X;
    cin >> N >> X;
    vector<int> vec(N);
    for(int i = 0;i < N;i++)
        cin >> vec.at(i);
    sort(vec.begin(),vec.end());
 
    for(int i = 0;i < N;i++)
        X -= vec.at(i);
 
    int a = X/vec.at(0);
 
    cout << N + a << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ========================================================================

ll N = 100000;

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計を出す
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定



ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります（ただの前座）
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の%INF対策で逆元を出します

//暇ですね(*'▽')

// ========================================================================

int main() {
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = n;
	ll cnt = 1;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) {
			ans -= 2;
			i += 1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3924