akhauriyash/Code-Regression huggingface dataset:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
# Breadth First Search
# Result:
import sys

class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def breadth_first_search(self):
        ds = [-1] * self.__size
        vs = [None] * self.__size
        vs[0] = [self.get_vertex(1)]
        ds[0] = 0
        vs_idx = 0
        while vs_idx < self.__size and vs[vs_idx] != None:
            vlst = vs[vs_idx]
            vs_idx += 1
            for vtx in vlst:
                for advid in vtx.adjacents:
                    adv = self.get_vertex(advid)
                    if ds[advid - 1] == -1:
                        ds[advid - 1] = vs_idx
                        if vs[vs_idx] == None:
                            vs[vs_idx] = []
                        vs[vs_idx].append(adv)
        for idx, d in enumerate(ds):
            print '%d %d' % ((idx + 1), d)

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_

class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_



s = int(sys.stdin.readline().strip())
graph = Graph(s)
for _ in range(0, s):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    v = Vertex(vals[0])
    graph.add_vertex(v)
    if vals[1] == 0: continue
    for i in range(0, vals[1]):
        v.add_adjacent(vals[2 + i])

graph.breadth_first_search()

Measured memory_bytes: 4360
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

bool allSunny(string str){
	bool ans = true;
	if( str[0] == 'S' && str[1] == 'S' && str[2] == 'S') return true;
	return false;
}

int main(){
	string str;
	cin>>str;
	if( str[0] == 'R' && str[1] == 'R' && str[2] == 'R'){
		cout<<3<<endl;
	}else if(str[0] == 'R' && str[1] =='R' ){
		cout<<2<<endl;
	}else if(str[1] == 'R' && str[2] == 'R'){
		cout<<2<<endl;
	}else if( allSunny(str) == true){
		cout<<0<<endl;
	}else{
		cout<<1<<endl;
	}
		
	return 0;
}


Measured memory_bytes: 3164
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string t;
    cin >> t;
    string s = "AKIHABARA";
    string r = "KIHBR";
    if (t.size() > 10)
    {
        cout << "NO\n";
        return 0;
    }
    for (int i = 0; i < (1 << s.size()); i++)
    {
        string g = "";
        for (int j = 0; j < s.size(); j++)
        {
            if ((1 << j) & i) g += s[j];
        }
        if (g == t)
        {
            int tr = 0;
            for (int i2 = 0; i2 < (1 << t.size()); i2++)
            {
                string q = "";
                for (int j2 = 0; j2 < t.size(); j2++)
                {
                    if ((1 << j2) & i2) q += t[j2];
                }
                if (q == r) tr = 1;
            }
            if (tr)
            {
                cout << "YES";
                return 0;
            }
        }
    }
    cout << "NO\n";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define max2(a,b) ((a)>(b)?(a):(b))   
#define min2(a,b) ((a)<(b)?(a):(b)) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();       

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
// #define cerr if(0)cerr

void solve()
{
  string s,t; cin>>s>>t;

  bool present[26]={0};
  
  ll ct=0; 

  vll idx[26];

  rep(i,0,sz(s)-1)
  {
     present[s[i]-'a']=1;
     idx[s[i]-'a'].pb(i);
  }

 int prev=-1;

  rep(i,0,sz(t)-1)
    if(!present[t[i]-'a'])
    {
      cout<<"-1\n";
      return;
    }
    else
    {
      int c=t[i]-'a';

       auto it=lower_bound(all(idx[c]),prev+1)-idx[c].begin();

       if(it==idx[c].size())
       {
        --i;
         ++ct;
         prev=-1;
       }
       else
         prev=idx[c][it];
    }

    cout<<ct*sz(s)+prev+1<<'\n';

}

Measured memory_bytes: 1736
import java.util.Scanner;

//Finding the Largest Carbon Compound Given Its Longest Chain
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int[] dp = new int[31];
		dp[1] = 1;
		dp[2] = 2;
		int sum = 0;
		for(int i=3;i<=30;i+=2){
			sum+=Math.pow(3, (i-3)/2);
			dp[i] = 1+4*sum;
		}
		sum = 0;
		for(int i=4;i<=30;i+=2){
			sum+=Math.pow(3, (i-4)/2);
			dp[i] = 2+6*sum;
		}
		while(sc.hasNext())System.out.println(dp[sc.nextInt()]);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]s = new int[100001];
		for(int i = 0; i < N; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			for(int j = l; j <= r; j++) {
				s[j] = 1;
			}
		}
		sc.close();
		int cnt = 0;
		for(int i = 1; i <= 100000; i++) {
			if(s[i] == 1) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

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


static const int MAX_NUM = 100 + 1;

int main(void)
{
    int i, j;
    int num;
    int elem;
    int elemnum;
    int tmp;
    int matrix[MAX_NUM][MAX_NUM] = {0};


    scanf("%d", &num);
    for (i = 1; i <= num; i++) {
        scanf("%d %d", &elem, &elemnum);
        for (j = 1; j <= elemnum; j++) {
            scanf("%d", &tmp);
            matrix[elem][tmp] = 1;
        }
    }

    for (i = 1; i <= num; i++) {
        printf("%d", matrix[i][1]);
        for (j = 2; j <= num; j++) {
            printf(" %d", matrix[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1240
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
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;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

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

	sort(ALL(a));

	cout << a[N - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,t,ans;
    cin>>n>>t;
    ans=t;
    for(int i=0;i<n-1;i++){
        cin>>t;
        ans=lcm(ans,t);
    }
    cout<<ans<<endl;
    return(0); 
}


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

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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int N, M;
Graph G(100005);
vector<vector<int>> dist(100005, vector<int>(3, -1));

int main()
{
    cin >> N >> M;
    rep(i, M)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
    }
    int S, T;
    cin >> S >> T;
    S--, T--;

    queue<int> q;
    q.push(S);
    dist[S][0] = 0;
    int move = 0;

    while (!q.empty()) {
        int size = q.size();
        move++;
        for (int i = 0; i < size; i++) {
            int v = q.front();
            q.pop();
            for (int nv : G[v]) {
                if (dist[nv][move % 3] != -1)
                    continue;
                q.push(nv);
                dist[nv][move % 3] = move;
            }
        }
    }

    if (dist[T][0] == -1) {
        cout << -1 << endl;
    } else {
        cout << dist[T][0] / 3 << endl;
    }

    return 0;
}

Measured memory_bytes: 14320
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n = sc.nextInt();
        long N=sc.nextLong(),ans=0;
        for (long i = 1; i*i <= N; i++) {
        	if(N%i==0) {
//        		long m=N/i-1;
//        		if(N<m*(m+1))
        		if(N/i-1>i)ans+=N/i-1;
        	}
        }
        out.println(ans);
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id,T;
//    P(int id, int T) {
//        this.id=id;
//        this.T=T;
//    }
//    public int compareTo(P p){
//        return id-p.id; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 23252
judgeEq :: (Ord a) => a -> a -> String
judgeEq a b
    | a < b = "a < b"
    | a > b = "a > b"
    | otherwise = "a == b"

stringToInt :: String -> Int
stringToInt = read

main = do
    line <- getLine
    let [a, b] = map stringToInt $ words line
    putStrLn $ judgeEq a b 



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

using namespace std;

int a, b, tot;

int main() {
	scanf("%d%d", &a, &b);
	for(int i = 10; i <= 1000; i *= 10)
		if(i > b) {
			a = a * i + b;
			break;
		}
	for(int i = 1; i * i <= a; i++)
		if(i * i == a) {
			printf("Yes\n");
			return 0;
		}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0588?year=2006>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    cin >> res;
    char c; cin >> c;
    while(true){
        if(c == '=') break;
        ll n; cin >> n;
        switch (c) {
            case '+':
                res += n;
                break;
            case '-':
                res -= n;
                break;
            case '*':
                res *= n;
                break;
            case '/':
                res /= n;
                break;
                
            default:
                break;
        }
        cin >> c;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 36
typedef struct{
  char gara;
  int number;
}card;
void Swap(card*x,card*y){
  card temp;
  temp=*x;
  *x=*y;
  *y=temp;
}
void bubble(card *after,int n){
  int i,j;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(after[j].number<after[j-1].number){
	Swap(&after[j],&after[j-1]);
      }
    }
  }
}
void Select(card *after,int n){
  int i,j,minj;
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(after[j].number<after[minj].number){
	minj=j;
      }
    }
    if(minj!=i){
      Swap(&after[i],&after[minj]);
    }
  }
}
		       
int isstable(card*x,card*y,int n){
  int i,j,a,b;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(a=0;a<n;a++){
	for(b=a+1;b<n;b++){
	  if(x[i].number==x[j].number&&memcmp(&x[i],&y[b],sizeof(card))==0&&memcmp(&x[j],&y[a],sizeof(card))==0)
	    return -1;
	}
      }
    }
  }
  return 0;
}
int main(){
  card A[N],*after1,*after2;
  int i,j,n,judge1,judge2;
  scanf("%d",&n);
  after1=(card *)malloc(n*(sizeof(card)));
  after2=(card *)malloc(n*(sizeof(card)));
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].gara,&A[i].number);
  }
  for(i=0;i<n;i++){
    after1[i]=A[i];
  }
  for(i=0;i<n;i++){
    after2[i]=A[i];
  }
  bubble(after1,n);
  Select(after2,n);
  judge1=isstable(A,after1,n);
  judge2=isstable(A,after2,n);
  for(i=0;i<n;i++){
    printf("%c%d",after1[i].gara,after1[i].number);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  if(judge1==0){
    printf("Stable\n");
  }
  if(judge1==-1){
    printf("Not stable\n");
  }
  for(i=0;i<n;i++){
    printf("%c%d",after2[i].gara,after2[i].number);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  if(judge2==0){
    printf("Stable\n");
  }
  if(judge2==-1){
    printf("Not stable\n");
  }
  free(after1);
  free(after2);
  return 0;
}

Measured memory_bytes: 628
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

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


int main(){
    int a, b;
    cin >> a >> b;
    if (a >= 13){
        cout << b << endl;
    }else if (a <= 5){
        cout << 0 << endl;
    }else{
        cout << b / 2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    ll n;cin >> n;
    ll cnt=0;
    ll now=0;
    rep(i,n){
        ll k;
        cin >> k;
        now+=k;
        if(k==0){cnt+=now/2;now=0;}
    }
    cnt+=now/2;
    cout << cnt << '\n';
}

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

int main()
{
 long long l, r;
 cin >> l >> r;
 long ans=2018;
 if((l/2019<r/2019)||(l%2019==0)){
   ans=0;
 }else{
   int la, ra;
   la=l%2019;
   ra=r%2019;
   for(int i=la;i<ra;i++){
     for(int j=i+1;j<ra+1;j++){
       int tmp;
       tmp=(i*j)%2019;
       if(tmp<ans) ans=tmp;
     }
   }
 }
 cout<< ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

vector<ll>a,b;
int main() {
	ll n,h;
	cin>>n>>h;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		a.push_back(x);
		b.push_back(y);
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	ll AMA=a[0];
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	ll tsum=0,ans=0;
	for(int i=0;i<n;i++){
		if(b[i]<=AMA||tsum>=h){
			break;
		}
		ans++;
		tsum+=b[i];
	}
	if(h-tsum>0){
		ans+=((h-tsum)+AMA-1)/AMA;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2036
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());

        if (n == 1) {
            stdout.println("Yes");
            stdout.println("2");
            stdout.println("1 1");
            stdout.println("1 1");
            return ;
        }

        int h = 1;
        int sum = 1;
        while (true) {
            if (sum == n) {
                break;
            }

            if (n < sum) {
                stdout.println("No");
                return ;
            }

            h++;
            sum += h;
        }

        int v = 1;
        int[][] mat = new int[h][h];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < i + 1; j++) {
                mat[i][j] = v++;
            }
        }

        List<List<Integer>> ans = new ArrayList<>();
        ans.add(IntStream.range(0, h).map(i -> mat[i][0]).boxed().collect(Collectors.toList()));
        ans.add(Arrays.stream(mat[h - 1]).boxed().collect(Collectors.toList()));
        ans.add(IntStream.range(0, h).map(i -> mat[i][i]).boxed().collect(Collectors.toList()));
        for (int i = 1; i < h - 1; i++) {
            List<Integer> row = new ArrayList<>();
            for (int j = 0; j < i; j++) row.add(mat[i][j]);
            for (int j = i; j < h; j++) row.add(mat[j][i]);
            ans.add(row);
        }

        stdout.println("Yes");
        stdout.println(ans.size());
        for (List<Integer> row : ans) {
            String line = row.stream().map(Objects::toString).collect(Collectors.joining(" "));
            stdout.printf("%d %s%n", row.size(), line);
        }
    }

    private boolean isOK(int n) {
        int sum = 0;
        for (int i = 0; sum <= n; i++) {
            if (sum == n) {
                return true;
            }
            sum += i;
        }
        return false;
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 49940
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	var r = parseInt( input[0], 10 );

        if( r%2!=0){ console.log("No"); return;}

	var half = r/2;

        var half_text = input[1].substr(0, half);
        var half_text2 = input[1].substr(half);

        if(half_text == half_text2){
          console.log("Yes" );
        }else{
          console.log( "No");
        }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<string> 
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int n,m,x,i,y,z,a;
	cin>>n>>m>>x;
	z=0,y=0;
	for(i=0;i<m;i++)
	{
		scanf("%d",&a);
		if(a<x)z++;
		else y++;
	}
	printf("%d\n",min(z,y));
	return 0;
} 

Measured memory_bytes: 256
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
# from collections import Counter
# from fractions import Fraction
# s=iter(input())
# for _ in range(int(input())):
# from collections import deque
from itertools import permutations as pmt

# n=int(input())
# arr=list(map(int,input().split()))
# ls=list(map(int,input().split()))
# for i in range(m):
# for i in range(int(input())):
# arr = list(map(int, input().split()))
# for  i in range(int(input())):
# for  _ in range(int(input())):
# n, k = map(int, input().split())
#for _ in range(int(input())):
#from decimal import Decimal
import math
def factors(n):
    cn=n
    cnt=0
    ans=[]
    while n%2==0:
        n=n//2
        cnt+=1
    ans.append(cnt)
    #print(ans)
    #print('n', n)
    for i in range(3, int(math.sqrt(cn)) + 1, 2):
        cnt=0
        while n%i==0:
            n = n / i
            cnt+=1
        if cnt>0:
            ans.append(cnt)
            #print(ans)
    if n>2:
        ans.append(1)
    #print(ans)
    return ans






n=int(input())
p=factors(n)
if n==1:
    print(0)
elif len(p)==0:
    print(1)
else:
    f=0
    #print(p)
    for ex in p:
        i=1
        while ex>0:
            ex-=i
            if ex<0:
                break
            i+=1
            f+=1
    print(f)

Measured memory_bytes: 9468
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;
				

				
int main(){
	double a,b,h,m;
	cout << setiosflags(ios::fixed) << setprecision(14);
	cin>>a>>b>>h>>m;
	double ag=fabs(m/60-(m/60+h)/12)*2*pi;
	cout<<sqrt(a*a+b*b-2*a*b*cos(ag))<<endl;
  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long


int main()
{
	IOS;
	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "..." << endl;
	}


	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a > b){
    if(b > c){
      cout << c << " " << b << " " << a;
    } else {
      if(a > c){
        cout << b << " " << c << " " << a;
      } else {
        cout << b << " " << a << " " << c;
      }
    }
  } else { // a < b
    if(b > c){ // a?c < b
      if(a > c){
        cout << c << " " << a << " " << b;
      } else {
        cout << a << " " << c << " " << b;
      }
    } else { // b < c
      cout << a << " " << b << " " << c;
    }
  }
  cout << endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
#define ttttyyyy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fo(i,n,m) for(int i=n;i<m;i++)
#define pb(x) push_back(x)
#define mk(a,b) make_pair(a,b)
#define all(x) x.begin(),x.end()
#define ft first
#define se second
#define ci(x) int x; cin>>x
int main(){
    ttttyyyy
    ll n;cin>>n;
    cout<<n*6.283185307<<endl;
    return 0;
}



Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] arr = line.split(" ");
        int t_h = Integer.parseInt(arr[0]);
        int t_s = Integer.parseInt(arr[1]);
        int a_h = Integer.parseInt(arr[2]);
        int a_s = Integer.parseInt(arr[3]);

        boolean t_turn = true;

        while (t_h > 0 && a_h > 0) {
            if (t_turn) {
                a_h -= t_s;
            } else {
                t_h -= a_s;
            }
            t_turn = !t_turn;
        }

        if (t_h > 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 27008
#include<iostream>
using namespace std;
int main()
{
   // 整数の入力
  string input_s;
  cin >> input_s;

  const string keyence = "keyence";

  
  	for( int i = 0; i < input_s.length(); i++ )
  	{
      for( int j =0; j < input_s.length() ; j++ )
      {
         string tempStr = input_s;
         tempStr = tempStr.erase(i,j);
         if( tempStr == keyence )
         {
           cout << "YES" << endl;
           return 0;
         }
      }
    }


  cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    s = []
    for _ in range(M):
        s.append(list(map(int, input().split()))[1:])
    p = list(map(int, input().split()))
    
    ans = 0
    for i in range(2**N, 2**(N+1)):
        bi = bin(i)[3:]
        t = [0] * (M*1)
        for i, si in enumerate(s):
            for j, b in enumerate(list(bi)):
                if b == '1' and j+1 in si:
                    t[i] += 1
            if t[i] % 2 != p[i]:
                ans -= 1
                break
        ans += 1
    
    return ans
  
print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 998244353
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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

const int dx8[] = {-1, 0, 1, 0,1,1,-1,-1};
const int dy8[] = {0, -1, 0, 1,1,-1,1,-1};


unordered_map<ll,ll> m1 ;
void solve()
{
    m1.clear();
 ll n,x,m ;
 cin >> n >> x >> m;
 vector<ll>arr1;
 vector<ll>arr2 ;
 arr1.pb(x);
 arr2.pb(x);
 m1[x]=0;
  for(ll i =1 ;i<n;i++)
 {
     arr1.pb(0);
     arr2.pb(0);
  arr1[i]=(arr1[i-1]*arr1[i-1])%m;
  arr2[i]=arr2[i-1]+arr1[i];
     if(m1.count(arr1[i])!=0)
     {
        // cout <<"hello" << endl;
         ll len= i-m1[arr1[i]];
         ll sum = arr2[i]-arr2[m1[arr1[i]]];
         ll rem= n-i;
         ll ans=0 ;
         ans= arr2[i-1]+ (rem/len)*sum;
         ll a = m1[arr1[i]] ;
         ll b = a+ (rem%len) -1 ;
        for (ll j=a ;j<=b;j++)
            ans+= arr1[j];
         cout << ans<< endl;

         return ;
     }
     m1[arr1[i]]=i;
 }


 cout << arr2[n-1]<< endl;

}



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


Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  int p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 2; i < n; i++) {
    if (p[i - 2] < p[i - 1] && p[i - 1] < p[i]) ans++;
    if (p[i - 2] > p[i - 1] && p[i - 1] > p[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,ans=10*5;
    cin>>n;
    for (int i=0;i<n;i++){
        int c;
        cin>>c;
        int p=0;
        while(c%2==0){
            c/=2;
            p+=1;
        }
        ans=min(ans,p);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
            System.out.println("0");
            return;
        }
        if ((A == B && B == C)) {
            System.out.println("-1");
            return;
        }
        long count = 1;
        while (true) {
            long a = A / 2;
            long b = B / 2;
            long c = C / 2;
            A = b + c;
            B = a + c;
            C = a + b;
            if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
                break;
            }
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        for(int i=0; i<N; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[N-1]);
    }
}

Measured memory_bytes: 51220
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = int(1e6) + 5;

uint64_t flag[MAX_N];


void set_f(uint64_t i){
    flag[i>>6] &= ~(1ULL<<(i&((1ULL<<6)-1)));
}

bool get_f(uint64_t i){
    return ((flag[i>>6]>>(i&((1ULL<<6)-1)))&1);
}

void sieve(const int64_t n){
    const uint64_t siz = n/2, sqrtN = ceil(sqrt(n)+0.1)/2;
    fill(flag, flag+(siz>>6)+1, -1);
    for(uint64_t i=1ULL; i<=sqrtN; ++i){
        if(get_f(i)){
            const uint64_t p = 2*i+1;
            for(uint64_t j = 2*i*(i+1); j<=siz; j+=p){
                set_f(j);
            }
        }
    }
}

bool isPrime(int n){
    if(n == 2) return true;
    else return n&1 && get_f(n/2);
}

int cum[MAX_N]{};

int main() {
    sieve(MAX_N);
    for(int i=2;i<MAX_N;i++){
        if(isPrime(i))cum[i]++;
        cum[i] += cum[i-1];
    }
    int n;
    while(cin >> n){
        cout << cum[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 6952
import Data.List
import Data.Ratio

main = do
  n <- readLn
  print $ totient n

phi :: Int -> [Int]
phi n = 1 : [ x | x <- [2..sqr], gcd n x == 1] ++ [ y | x <- [2..sqr], let y = n `div` x, gcd n x == 1]
  where sqr = floor $ sqrt $ fromIntegral n
--phi n = [x | x <- [2..n], gcd n x == 1 || gcd n x == x]

totient :: Int -> Int
totient 1 = 1
totient n = numerator ratio `div` denominator ratio
  where ratio = foldl (\acc x -> acc * (1 - (1 % x)))
                      (n % 1) $ nub (primeFactor n)

factors :: Int -> [Int]
factors n = [d | d <- [1..n], n `mod` d == 0]

isPrime :: Int -> Bool
isPrime x =
  null [y | y <- [2..floor $ sqrt $ fromIntegral x], x `mod` y == 0]

primeFactor :: Int -> [Int]
primeFactor n
  | isPrime n = [n]
  | otherwise = reverse $ go [] n
  where
    go res 1 = res
    go res n = go (d : res) (n `div` d)
      where d = factors n !! 1

Measured memory_bytes: 4268
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
n,a = IR(2)
print(n**2-a)
#B

#C
"""
a,b,c,d,e,f = LI()
a *= 100
b *= 100
ans = [a,0]
for i in range(f//a+1):
    for j in range((f-a*i)//b+1):
        for k in range((f-a*i-b*j)//c+1):
            for l in range((f-a*i-b*j-c*k)//d+1):
                if i or j or k or l:
                    s = c*k+d*l
                    w = a*i+b*j
                    q = w*e//100
                    if s <= q:
                        if w+s <= f:
                            if ans[1]/ans[0] < s/(s+w):
                                ans = [w+s,s]
print(*ans)
"""

#D
"""
n = I()
d = LIR(n)
l = [[1 for j in range(n)] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            if d[i][j] > d[i][k]+d[k][j]:
                print(-1)
                quit()
            if d[i][j] == d[i][k]+d[k][j]:
                l[i][j] = l[i][k]+l[k][j]

ans = 0
for i in range(n):
    for j in range(n):
        if l[i][j] == 4:
            ans += d[i][j]
ans //= 2
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

typedef long long ll;
const int maxn=1005;
ll a[maxn], b[maxn], c[maxn];

bool cmp(const ll &x, const ll &y){
    return x>y;
}

ll temp1[maxn][maxn], temp2[maxn][maxn];
ll temp3[maxn][maxn];

int main()
{
    int x, y, z, k;
    while(cin>>x>>y>>z>>k){
        for(int i=0;i<x;i++){
            cin>>a[i];
        }
        for(int i=0;i<y;i++){
            cin>>b[i];
        }
        for(int i=0;i<z;i++){
            cin>>c[i];
        }
        vector<ll>ab;
        vector<ll>abc;
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                ab.push_back(a[i]+b[j]);
            }
        }
        sort(ab.begin(), ab.end(), cmp);
        for(int i=0;i<min(k,x*y);i++){
            for(int j=0;j<z;j++){
                abc.push_back(ab[i]+c[j]);
            }
        }
        sort(abc.begin(), abc.end(), cmp);
        for(int i=0;i<k;i++){
            cout<<abc[i]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 42596
def prod(ls):
    def resolve(ls, a):
        if len(ls) == 1:
            return a*ls[0]
        else:
            car = ls[0]
            ls = ls[1:]
            return resolve(ls, a*car)
    return resolve(ls, 1)

ls = list(map(int, input().split()))
if sum(ls) == 17 and prod(ls) == 175:
    print("YES")
else :
    print("NO")

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

string ALPHA = "abcdefghijklmn";
int cnt_alpha(string s) {
    int cnt = 0;
    rep(i, ALPHA.size()) {
        rep(j, s.size()) {
            if (ALPHA[i] == s[j]) {
                cnt++;
                break;
            }
        }
    }
    return cnt;
}

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

    vector<string> st;
    st.push_back("a");

    for (int n=2; n<=N; n++) {
        vector<string> tmp = st;
        st.clear();
        rep(i, tmp.size()) {
            string str_i = tmp[i];
            int add_num = cnt_alpha(str_i) + 1;
            rep(j, add_num) {
                st.push_back(str_i + ALPHA[j]);
            }
        }
    }

    for (auto str_i: st) cout << str_i << endl;

    return 0;
}

 

Measured memory_bytes: 9164
<?php

while (true) {
  $n = trim(fgets(STDIN));
  if ($n == 0) {
    break;
  }

  $input = trim(fgets(STDIN));
  $data = explode(" ", $input);

  $m = array_sum($data) / count($data);
  $z = 0;
  foreach ($data as $s) {
    $z += pow($s - $m, 2);
  }
  $a = sqrt($z / $n);

  printf("%f" . PHP_EOL, $a);
}

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

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);

    cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
}



Measured memory_bytes: 3136
n,m = map(int,input().split())
price = []
honsu = []
c = []
for i in range(n):
  a,b = map(int,input().split())
  c.append([a,b])
c = sorted(c)
price,honsu=zip(*c)
money = 0
l = 0
while m > 0:
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  l += 1
print(money)

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

string a;

int iseven(int n) {
  if (n % 2 != 0) return 0;
  for (int i = 0; i < n/2; i++) {
    if (a[i] != a[n/2 + i]) return 0;
  }
  return 1;
}

int main() {
  cin >> a;
  int n = a.size();
  for (int i = 1; i < n; i++) {
    if (iseven(n-i-1)) {
      cout << a.substr(0, n-i-1).size() << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int x,a,b;
cin >> x >> a >> b;
(abs(x-a) <= abs(x-b)) ? cout << "A\n" : cout << "B\n";
return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextInt();
		long[] arr = new long[n];
		long tot = 0;
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
			tot += arr[i];
		}
		long max = 0;
		for(long d = 1; d*d <= tot; d++){
			if(tot % d == 0){
				if(check(arr, n, d, k)){
					max = Long.max(max, d);
				}
				if(check(arr, n, tot/d, k)){
					max = Long.max(max, tot/d);
				}
			}
		}
		System.out.println(max);
	}
	static boolean check(long[] arr, int n, long d, long k){
		long[] newarr = new long[n];
		for(int i = 0; i < n; i++){
			newarr[i] = arr[i] % d;
		}
		Arrays.sort(newarr);
		int a = 0, b = n-1;
		while(a < n && newarr[a] == 0) a++;
		long c = 0;
		while(b > a){
			c += newarr[a];
			k -= newarr[a];
			while(newarr[b] + c >= d && b > a){
				c -= (d - newarr[b]);
				b--;
			}
			a++;
		}
		return k >= 0;
	}

}


Measured memory_bytes: 28972
import itertools
import numpy as np

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
N_list = list(range(1, N+1, 1))
N_dictionary = list(itertools.permutations(N_list))
N_dic = [list(n) for n in N_dictionary]
a = N_dic.index(P)
b = N_dic.index(Q)
ans = np.abs(a - b)
print(ans)

Measured memory_bytes: 24048
# coding: utf-8


def main():
    S = input()

    y = "Yes"
    n = "No"

    rud = ["R", "U", "D"]
    lud = ["L", "U", "D"]
    for i, s in enumerate(S):
        j = i + 1
        if j % 2 == 1:
            if s not in rud:
                return n
        else:
            if s not in lud:
                return n

    return y


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 3060