akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 

     String[] nyu=sc.nextLine().split(" ");

     String[] nyuA=nyu[0].split("");
     String[] nyuB=nyu[1].split("");
     String[] nyuC=nyu[2].split("");



//     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]+nyu[2]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu[3]);


String[] bo={"a","i","u","e","o"};

//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(nyu){
case "H H":
System.out.println("H") ;
break;

case "D D":
System.out.println("H") ;
break;

case "H D":
System.out.println("D") ;
break;

case "D H":
System.out.println("D") ;
break;


default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

String res="consonant";
for(String tem:bo){
if(tem.equals(nyu))res="vowel";
}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);



//if(D<1200){
//double res=Math.ceil((AB)/2);

//System.out.println("ABC");
//}else if(B<A){
//System.out.println("Alice");

//}else{
System.out.println(nyuA[0]+nyuB[0]+nyuC[0]);

//}




	}
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	long sum = 0;
	for (int i = 0; i < n; i++)sum += a[i];
	cout << a[0] << " " << a[n - 1] << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3180
#include<stdio.h>
#define MAX 1000
void enqueue(int);
int dequeue();
int size();
void bfs(int);
 
int A[MAX][MAX];
int b[MAX];
int n;
int Q[MAX];
int head=0,tail=0;

int main(){
  int i,j,x,y,z;
  scanf("%d",&n);
  for(i=0;i<MAX;i++) b[i]=-1;
  for(i=0;i<n;i++){
    scanf("%d",&z);
    scanf("%d",&y);
    for(j=0;j<y;j++){
      scanf("%d",&x);
      A[z-1][x-1]=1;
    } 
  }
  b[0]=0;
  bfs(0);
  while(size()!=0) bfs(dequeue());
  for(i=0;i<n;i++) printf("%d %d\n",i+1,b[i]);  
return 0;
}
void enqueue(int x){
  Q[head]=x;
  head++;
}
int dequeue(){
  tail++;
  return Q[tail-1];
} 
int size(){
  return head-tail;
} 
void bfs(int i){
  int j;
  for(j=0;j<n;j++){
    if(A[i][j]==1 && b[j]==-1){
      b[j]=b[i]+1;
      enqueue(j);
    }
  }
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin  >> n;
  ll x= 0,y=0;
  vl a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }

  
  x = 1; y = 1;
  rep(i,n){
    ll c = max(1LL,max((x+a[i]-1)/a[i],(y+b[i]-1)/b[i]));

    a[i]*=c;
    b[i]*=c;
    //cout <<a[i]<<":"<<b[i]<<endl;
    x = a[i];
    y = b[i];
    
  }
  print(x+y);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    if(a >= 10 or b >= 10) cout << -1 << endl;
    else cout << a * b << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; string S; cin>>N>>S;
	map<int,int> b,w;
	for (int i=0; i<N; i++)
		if(S[i]=='#') b[i]++;
		else w[i]++;
	for (int i=1; i<N; i++)
		b[i]+=b[i-1];
	for (int i=N-2; i>=0; i--)
		w[i]+=w[i+1];
	int ret=min(b[N-1],w[0]);
	for (int i=0; i<N; i++)
		ret=min(ret,b[i]+w[i+1]);
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 19220
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, L):
    return 'Yes' if sum(L) - max(L) > max(L) else 'No'


def main():
    N = read_int()
    # N, M = read_int_n()
    # A = [read_int_n() for _ in range(N)]
    L = read_int_n()
    print(slv(N, L))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6456
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,c,d,i,s=0;
	cin>>a>>b>>c>>d; 
	int m[105],n[105];
	for (i=0;i<105;i++)
	{
		m[i]=0;
		n[i]=0;
	}
	for (i=a;i<=b;i++)
	{
		m[i]=1;
	}
	for (i=c;i<=d;i++)
	{
		n[i]=1;
	}
	for (i=0;i<=100;i++)
	{
		if (m[i]==1&&n[i]==1)
		{
			s++;
		}
	 } 
	 if (s>0)
	 cout<<s-1<<endl;
	 else
	 cout<<s<<endl;
	return 0;
 } 

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



namespace CSharpSample01
{

    struct BC
    {
        public int num;
        public int val;
    }
    

    class Program
    {
        static int[] card;
        static List<BC> bc;
        static long ans;

        static void Solve()
        {
            //ans初期値
            ans = card.Select(x => (long)x).Sum();
           
            int bc_ind = 0;           
            int cnt = bc[0].num;
            //i番目のカードを書き換えるかどうか(ans更新)
            for(int i = 0; i < card.Length; i++)
            {
                //card[i]より大きいCに書き換える
                if (card[i] < bc[bc_ind].val)
                {
                    ans = ans - (long)card[i] + (long)bc[bc_ind].val;
                    //Cを1回使った
                    cnt--;
                }
                else break;

                             
                //次のbc_indへ
                if(cnt == 0)
                {
                    bc_ind++;
                    //書き換え操作の限界
                    if (bc_ind >= bc.Count) break;                    
                    cnt = bc[bc_ind].num;
                }

            }

            Console.WriteLine(ans);

        }


        static void Main(string[] args)
        {
            //入力1(N, M)
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);

            //入力2(number)
            card = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            bc = new List<BC>();
            
            //入力3(bc)
            for(int i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split(' ');
                int b = int.Parse(input[0]);
                int c = int.Parse(input[1]);
                bc.Add(new BC() { num = b, val = c });
            }

            //bcをCに対して降順ソート
            bc = bc.OrderByDescending(x => x.val).ToList();
            //cardを昇順にソート
            card = card.OrderBy(x => x).ToArray();

            Solve();
            
        }
    }

}

Measured memory_bytes: 32068
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

int main() {
    ll n, q, a[100000], x;
    cin >> n >> q;
    rep(i, n)cin >> a[i];
    rep(i, q) {
        cin >> x;
        ll c = 0, l = 0, r = 0, s = 0;
        for (l = 0; l < n; l++) {
            while (r < n && s + a[r] <= x) {
                s += a[r];
                r++;
            }
            c += r - l;
            s -= a[l];
        }
        cout << c << endl;
    }
}




Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int a[26]={};
    for(int i=0;i<s.size();i++) a[s[i]-'a']++;
    for(int i=0;i<26;i++){
        if(a[i]==0){
            cout << s+char(i+'a') << endl;
            return 0;
        }
    }
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    } 
    vector<int> elst(26);
    int i=25,flag = 1;
    while(0<i&&flag){
        elst[s[i]-'a']=1;
        s.erase(i);
        for(int j=s[i-1]-'a';j<26;j++){
            if(elst[j]){
                s[i-1]=j+'a';
                flag = 0;
                break;
            }    
        }
        i--;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  char s[2048];
  int i;
  fgets(s, sizeof(s), stdin);
  for(i = 0;s[i] != '\0';i++){
    if('a' <= s[i] && s[i] <= 'z') s[i] += 'A' - 'a';
    else if('A' <= s[i] && s[i] <= 'Z') s[i] += 'a' - 'A';
  }
 
  printf("%s",s);
  return 0;
}


Measured memory_bytes: 2012
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;



int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int maxi = 0;
	


	int mini = 1000000000, m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mini = min(mini, a[i]);
		if (mini == a[i])m = i;
	}
	while (1) {
		for (int i = 0; i < n; i++) {
			if (i == m)continue;
			a[i] %= a[m];
			if (a[i] != 0) {
				mini = min(mini, a[i]);
				if (mini == a[i])m = i;
			}
			
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 0)count++;
		}
		if (count == n - 1)break;
	}
	cout << a[m] << endl;



	return 0;
}


Measured memory_bytes: 640
n = int(input())
ab = [[int(_) for _ in input().split()] for __ in range(n)]
s = [[sum(e), i] for i, e in enumerate(ab)]
s.sort(reverse=True)
t = 0

for j, x in enumerate(s):
    t += ab[x[1]][0] if j % 2 == 0 else -ab[x[1]][1]
print(t)


Measured memory_bytes: 38192
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-16 07:22:20
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int64 cnt[10][10];

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

  int n; cin >> n;

  for (int i = 0; i <= n; ++i) {
    ++cnt[to_string(i)[0] - '0'][to_string(i).back() - '0'];
  }

  int64 ans = 0;

  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      //if (i == j) continue;
      ans += cnt[i][j] * cnt[j][i];
    }
  }

  cout << ans - 1 << endl;

  return 0;
}

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

const int INF = 1001001001;
int dp[1000005][2];

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';
  int n = s.size();

  rep(i, n + 1) rep(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i, n) rep(j, 2) {
    int x = s[i] - '0';
    x += j;
    rep(a, 10) {
      int nj = 0;
      int b = a - x;
      if (b < 0) {
        nj = 1;
        b += 10;
      }
      dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + a + b);
    }
  }
  int ans = dp[n][0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9220
n, d = map(int, input().split())
ans = [-1]*3
for x in range(n+1):
    for y in range(n-x+1):
        zd = d - 10000*x - 5000*y
        if zd//1000 == n-x-y:
            ans[0] = x
            ans[1] = y
            ans[2] = zd//1000
            break
print(*ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using namespace std;

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

  Real a, b;
  cin >> a >> b;
  cout << (Bint)(a*b) << endl;
  return 0;
}

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

int dh[]={0,1,0,-1};
int dw[]={1,0,-1,0};
int solve(int h,int w){
    vector<vector<vector<int>>> wall(h,vector<vector<int>>(w,vector<int>(4,0)));
    for(int i=0;i<h;i++){
        wall[i][w-1][0]=true;
        wall[i][0][2]=true;
    }
    for(int i=0;i<w;i++){
        wall[h-1][i][1]=true;
        wall[0][i][3]=true;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j+1<w;j++){
            int w;
            cin>>w;
            wall[i][j][0]=w;
            wall[i][j+1][2]=w;
        }
        if(i+1<h){
            for(int j=0;j<w;j++){
                int w;
                cin>>w;
                wall[i][j][1]=w;
                wall[i+1][j][3]=w;
            }
        }
    }
    // for(int i=0;i<h;i++){
    //     for(int j=0;j<w;j++){
    //         cerr<<i<<' '<<j;
    //         for(int k=0;k<4;k++) cerr<<wall[i][j][k];
    //         cerr<<endl;
    //     }
    // }
    //cerr<<"Input finished"<<endl;
    const int INF=1e9;
    function<int(int,int)> fromHere=[&](int p,int q){
        queue<pair<int,int>> que;
        if(accumulate(wall[p][q].begin(),wall[p][q].end(),0)==4) return INF;
        int res=0;
        for(int d=0;d<4;d++){
            if(!wall[p][q][d]){
                wall[p][q][d]=true;
                vector<vector<int>> dist(h,vector<int>(w,INF));
                dist[p][q]=0;
                que.push({p,q});
                while(!que.empty()){
                    auto tmp=que.front(); que.pop();
                    int i=tmp.first,j=tmp.second;
                    for(int k=0;k<4;k++){
                        if(!wall[i][j][k] && dist[i][j]+1<dist[i+dh[k]][j+dw[k]]){
                            dist[i+dh[k]][j+dw[k]]=dist[i][j]+1;
                            que.push({i+dh[k],j+dw[k]});
                        }
                    }
                }
                res=max(res,dist[h-1][w-1]);
                wall[p][q][d]=false;
            }
        }
        return res;
    };
    
    vector<vector<int>> f(h,vector<int>(w,INF));
    for(int i=0;i<h;i++)for(int j=0;j<w;j++) f[i][j]=fromHere(i,j);
    //cerr<<"FROM HERE CALCED"<<endl;
    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<>> que;
    vector<vector<int>> dist(h,vector<int>(w,INF));
    dist[h-1][w-1]=0;
    que.push({0,{h-1,w-1}});
    while(!que.empty()){
        auto tmp=que.top(); que.pop();
        int p=tmp.second.first,q=tmp.second.second;
        if(tmp.first>dist[p][q]) continue;
        for(int i=0;i<4;i++){
            if(!wall[p][q][i] && dist[p+dh[i]][q+dw[i]]==INF){
                dist[p+dh[i]][q+dw[i]]=max(dist[p][q]+1,f[p+dh[i]][q+dw[i]]);
                que.push({dist[p+dh[i]][q+dw[i]],{p+dh[i],q+dw[i]}});
            }
        }
    }
    return dist[0][0]>=INF ? -1 : dist[0][0];
}
int main(){
    int h,w;
    while(cin>>h>>w,h){
        cout<<solve(h,w)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
int main (void)
{
	char s[3], t[3];
	int i, n = 0;
	
	scanf("%s", s);
	scanf("%s", t);
	
	for(i = 0; i < 3; i++){
		if(s[i] == t[i]){
			n++;
		}
	}
	
	printf("%d", n);
	
	return 0;
}

Measured memory_bytes: 128
def solve():
    N, X, Y = map(int, input().split())
    ans = [0]*(N)
    for i in range(1,N):
        for j in range(i+1,N+1):
            ans[min(abs(X-i)+abs(Y-j)+1,abs(j-i))] += 1
    return ans[1:]
print(*solve(),sep='\n')

Measured memory_bytes: 43120
from collections import Counter

N, M = map(int, input().split())
X = [int(i) for i in input().split()]

c = Counter(X)
cm = [[0, 0] for _ in range(M)]
for k, v in c.items() :
    cm[k % M][0] += v
    cm[k % M][1] += v // 2

ret = cm[0][0] // 2
for i in range(1, (M + 1) // 2) :
    ret += min(cm[i][0], cm[M-i][0])
    if cm[i] >= cm[M-i] :
        ret += min((cm[i][0] - cm[M-i][0]) // 2, cm[i][1])
    else :
        ret += min((cm[M-i][0] - cm[i][0]) // 2, cm[M-i][1])
        
if M % 2 == 0 :
    ret += cm[M//2][0] // 2
    
print(ret)

Measured memory_bytes: 72424
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N; cin >> N;
	VV<int> v(N,V<int>(N-1));
	rep(i,N) rep(j,N-1) cin >> v[i][j],v[i][j]--;
	V<int> it(N);
	queue<int> qx,qy,nqx,nqy;
	VV<int> ok(N,V<int>(N));
	auto ADD = [&](int x,int y){
		if(x>y) swap(x,y);
		ok[x][y]++;
		if(ok[x][y] == 2){
			nqx.push(x);nqy.push(y);
		}
	};
	rep(i,N) ADD(i,v[i][0]);
	qx = nqx,qy = nqy;
	int D = 0;
	while(!qx.empty()){
		D++;
		while(!nqx.empty()) nqx.pop();
		while(!nqy.empty()) nqy.pop();
		while(!qx.empty()){
			int x = qx.front(), y = qy.front(); qx.pop();qy.pop();
			it[x]++,it[y]++;
			if(it[x] != N-1) ADD(x,v[x][it[x]]);
			if(it[y] != N-1) ADD(y,v[y][it[y]]);
		}
		swap(qx,nqx);swap(qy,nqy);
	}
	rep(i,N) if(it[i] != N-1){
		cout << -1 << endl;
		return 0;
	}
	cout << D << endl;
}


Measured memory_bytes: 8192
import sys,collections
input = sys.stdin.readline

N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
    B,C = list(map(int,input().split()))
    nb = Ac[B]
    Ac[C] += Ac[B]
    Ac[B] = 0

    if i==0:
        ans = 0
        for key,val in Ac.items():
            ans += key*val
    else:
        ans +=nb*C - nb*B
    
    print(ans)


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	vector<int> cnt;
	cnt.push_back(1);
	for (int i = 1; i < n; i++) {
		if (v[i] != v[i - 1]) { 
			cnt.push_back(1);
			if (v[i] != v[i - 1] + 1) {
				cout << "No";
				return 0;
			}
		}
		else
			cnt.back()++;
	}
	if (cnt.size() > 2 || v.back() > n - 1) {
		cout << "No";
		return 0;
	}
	if (cnt.size() == 1 && (v.back() == n - 1 || v.back() <= n / 2)) {
		cout << "Yes";
		return 0;
	}
	if (cnt.size() == 2 && (v.back() > cnt[0] && v.back() <= cnt[0] + cnt[1] / 2)) {
		cout << "Yes";
		return 0;
	}
	cout << "No";		
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10000);
    double p[n + 1];
    mem0(p);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        double e = a[i] + 1;
        p[i + 1] = (e) / (2);
        //cout << p[i + 1] << " ";
        p[i + 1] += p[i];
    }
    double ans = 0;
    for (int i = 1; i <= n - k + 1; i++)
    {
        ans = max(ans, p[i + k - 1] - p[i - 1]);
    }
    cout << ans << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
int main(){
    ll n,ans=0;cin>>n;
    for(int i=0;i<1000000000;i++) ans+=i;
    cout<<n*n*n<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int, int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<ll> > vvl;
typedef vector<ll> vl;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod (1e9+7)
#define inf (1e9+7)
#define nil -1
int main() {
	int h, w;
	cin >> h >> w;
	vvi A(h, vi(w));
	vvi dp(h, vi(w));
	int ans;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin>>A[i][j];
			dp[i][j] = (1 - A[i][j]);
			ans |= dp[i][j];
		}
	}
	for (int i = 1; i < h; i++)
	{
		for (int j = 1; j < w; j++)
		{
			if (A[i][j]) {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]))+1;
			}
			ans = max(ans,dp[i][j]);
		}
	}
	cout << ans*ans << endl;
}


Measured memory_bytes: 18028
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] x = line.split(" ");
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		
		int d = a/b;
		int r = a%b;
		double f = (double)a/b;
		System.out.print(d + " " + r + " " );
		System.out.printf("%5f",f);
		

	}

}



Measured memory_bytes: 26312
n = int(input())
h = [int(i) for i in input().split()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
    
# 無限大の値
f_inf = float('inf')
# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)
# 初期条件
dp[0] = 0
# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i-1]))
    # 一番目の足場では一つ前しか存在しない
    if i > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i -2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include<cmath>
#include<queue>
#include<cstdio>

using namespace std;

double hypot3(double x,double y,double z){
	return sqrt(x*x+y*y+z*z);
}

struct Cell{
	double x,y,z,r;
};

struct Edge{
	int u,v;
	double cost;
	Edge(int _u,int _v,double c):u(_u),v(_v),cost(c){}
	bool operator<(const Edge &e)const{ return cost<e.cost; }
};

int uf[100];
int UF_Root(int i){ return ~uf[i]?uf[i]=UF_Root(uf[i]):i; }
bool UF_Find(int i,int j){ return UF_Root(i)==UF_Root(j); }
void UF_Union(int i,int j){ uf[UF_Root(j)]=UF_Root(i); }

int main(){
	for(int n;scanf("%d",&n),n;){
		Cell c[100];
		for(int i=0;i<n;i++){
			scanf("%lf%lf%lf%lf",&c[i].x,&c[i].y,&c[i].z,&c[i].r);
			uf[i]=-1;
		}

		priority_queue<Edge> pq;
		for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
			double d=hypot3(c[i].x-c[j].x,c[i].y-c[j].y,c[i].z-c[j].z)-(c[i].r+c[j].r);
			if(d<0)	d=0;
			pq.push(Edge(i,j,-d));
		}

		int cnt=0;
		double total=0;
		while(!pq.empty() && cnt<n-1){
			Edge e=pq.top();	pq.pop();
			if(!UF_Find(e.u,e.v)){
				UF_Union(e.u,e.v);
				total+=-e.cost;
				cnt++;
			}
		}

		printf("%.3f\n",total);
	}

	return 0;
}

Measured memory_bytes: 0
n,m=map(int,input().split())
XYZ=[list(map(int,input().split())) for _ in range(n)]

ans=0
for i in (-1,1):
    for j in (-1,1):
        for k in (-1,1):
            cost=list(i*x+j*y+z*k for x,y,z in XYZ)
            cost.sort(reverse=True)
            ans=max(ans,sum(cost[:m]))
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <iomanip>


using namespace std;
using ll = long long;

template <int N>
struct Dominator {
    vector<int> g[N], rg[N];
    void init() {
        for (int i = 0; i < N; i++) {
            g[i].clear(); rg[i].clear();
        }
    }
    void add(int a, int b) {
        g[a].push_back(b);
        rg[b].push_back(a);
    }

    int idc, id[N], rid[N], par[N];
    void dfs(int p, int b) {
        if (id[p] != -1) return;
        par[p] = b;
        id[p] = idc; rid[idc] = p; idc++;
        for (int d: g[p]) {
            dfs(d, p);
        }
    }

    int idom[N], sdom[N];

    // unionfind
    int p[N];
    int mv[N];
    void merge(int a, int b) {
        p[a] = b;
    }
    int group(int a) {
        if (p[a] == -1) return a;
        int pa = group(p[a]);
        if (id[sdom[mv[a]]] > id[sdom[mv[p[a]]]]) {
            mv[a] = mv[p[a]];
        }
        return p[a] = pa;
    }

    vector<int> bucket[N];
    int V[N];
    void exec(int s, int n = N) {
        // uf init
        fill_n(p, n, -1);
        for (int i = 0; i < n; i++) {
            mv[i] = i;
        }

        fill_n(id, n, -1);
        idc = 0;
        dfs(s, -1);
        for (int i = 0; i < n; i++) {
            sdom[i] = i;
        }
        for (int i = n-1; i > 0; i--) {
            int u = rid[i];
            for (int v: rg[u]) {
                group(v);
                sdom[u] = rid[min(id[sdom[u]], id[sdom[mv[v]]])];
            }
            bucket[sdom[u]].push_back(u);
            for (int v: bucket[par[u]]) {
                group(v);
                V[v] = mv[v];
            }
            bucket[par[u]].clear();
            merge(u, par[u]);
        }

        for (int i = 1; i < n; i++) {
            int u = rid[i];
            int v = V[u];
            if (sdom[u] == sdom[v]) idom[u] = sdom[u];
            else idom[u] = idom[v];
        }
        idom[s] = -1;
    }
};

const int MN = 100100;
Dominator<MN> dn;

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t; s--; t--;
        dn.add(s, t);
    }
    dn.exec(0, n);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int r;
        cin >> r; r--;
        if (dn.idom[r] != 0) {
            cout << dn.idom[r]+1 << endl;
        } else {
            cout << r+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 22880
#include <iostream>

int main(void) {
	using namespace std;
	int A, B, C;
	cin >> A >> B >> C;
	int prevA, prevB, prevC;
	int res = 0;
	while((A % 2 == 0) && (B % 2 == 0) && (C % 2 == 0)) {
		prevA = A;
		prevB = B;
		prevC = C;
		int tA, tB, tC;
		tA = (B + C) / 2;
		tB = (C + A) / 2;
		tC = (A + B) / 2;
		A = tA;
		B = tB;
		C = tC;
		if(A == prevA && B == prevB && C == prevC) {
			cout << "-1\n";
			return 0;
		}
		++res;
	}
	cout << res << '\n';
	return 0;
}



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

int main()
{
  int64_t A, B, C, D, c, d, cd;
  cin >> A >> B >> C >> D;
  c = (B / C) - (A - 1) / C;
  d = (B / D) - (A - 1) / D;
  cd = (B / lcm(C, D)) - (A - 1) / lcm(C, D);
  cout << (B - (A - 1)) - c - d + cd << endl;
}

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

int main(){
    int e, y;
    cin >> e >> y;

    if(e == 0){
        if(y >= 1989)       cout << "H" << y-1989+1 << endl;
        else if(y >= 1926)  cout << "S" << y-1926+1 << endl;
        else if(y >= 1912)  cout << "T" << y-1912+1 << endl;
        else if(y >= 1868)  cout << "M" << y-1868+1 << endl;
    }else if(e == 1){
        cout << 1868+y-1 << endl;
    }else if(e == 2){
        cout << 1912+y-1 << endl;
    }else if(e == 3){
        cout << 1926+y-1 << endl;
    }else if(e == 4){
        cout << 1989+y-1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int halfN = n/2;
		ArrayList<Integer> xs = new ArrayList<>();

		for (int i=0; i<n;i++) {
			xs.add(i, scanner.nextInt());
		}
		ArrayList<Integer> sorted = new ArrayList<>(xs);
		Collections.sort(sorted);
		int x1 = sorted.get(halfN-1);
		int x2 = sorted.get(halfN);

		for (int i=0; i<n; i++) {
			if (xs.get(i)<=x1) {
				System.out.println(x2);
			}else {
				System.out.println(x1);
			}
		}
	}

}

Measured memory_bytes: 96152
import Data.List
import Control.Monad
import Debug.Trace

main  = do
    n  <- read <$> getLine :: IO Int
    as <- zip [1..] . map read <$> replicateM n getLine :: IO [(Int, Int)]
    print $ makePair as

makePair :: [(Int, Int)] -> Int
makePair []       = 0
makePair [(_, 1)] = 0
makePair ((a, 1):(b, m):l)
    | abs (b-a) <= 1 && m /= 0 = div (m+1) 2 + makePair ([(b, mod (m+1) 2)| mod (m+1) 2 /= 0]++l)
    | otherwise                = makePair ((b, m):l)
makePair ((a, n):l) = (div n 2) + makePair ([(a, mod n 2)| mod n 2 /= 0] ++ l)

Measured memory_bytes: 60796
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int b[100000], c[100000];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);	
	vector<vector<int>> a(n, vector<int>(0));
	for(int i = 0, j, k; i < m; ++i)
	{
		scanf("%d%d", &j, &k);
		a[--j].push_back(--k);
		++b[k];
	}
	queue<pair<int, int>> q;
	for(int i = 0; i < n; ++i)
	{
		if(!b[i])
		{
			q.push(make_pair(0, i));
		}
	}
	for(int t, u; !q.empty(); )
	{
		t = q.front().fst;
		u = q.front().scd;
		q.pop();
		for(int i = 0; i < a[u].size(); ++i)
		{
			c[a[u][i]] = t + 1;
			if(!--b[a[u][i]])
			{
				q.push(make_pair(t + 1, a[u][i]));
			}
		}
	}
	printf("%d\n", *max_element(c, c + n));
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int N, C[60];

int main()
{
	scanf ("%d", &N);
	for (int i = 0; i < N; i++){
		long long x; scanf ("%lld", &x);
		for (int k = 0; k < 60; k++) if (x & (1ll << k)) C[k]++;
	}

	const long long mod = 1000000007;
	long long ans = 0;
	for (int k = 59; k >= 0; k--){
		ans = ans * 2 % mod;
		long long c = 1ll * C[k] * (N - C[k]) % mod;
		ans = (ans + c) % mod;
	}
	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>

using namespace std;

char m[51][51];
int h,w;

int bfs() {
    bool vis[h][w];
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            vis[i][j] = false;
        }
    }
    queue <pair<int , pair<int, int > > > q;
    q.push(make_pair(0,make_pair(0, 0)));
    int vx[] = {1,0,-1,0};
    int vy[] = {0,1,0,-1};
    while(!q.empty() ) {
        auto p = q.front();
        int yy = p.first;
        int yx = p.second.first;
        q.pop();
        if(vis[yy][yx]) continue;
        vis[yy][yx] = true;
        for(int i = 0; i < 4; i++) {
            int tx = yx + vx[i];
            int ty = yy + vy[i];
            if(tx == w-1 && ty == h-1) return p.second.second + 1;
            if(tx < 0 || ty < 0 || tx >= w || ty >= h || vis[ty][tx] || m[ty][tx] == '#') continue;
            q.push(make_pair(ty,make_pair(tx,p.second.second+1)));
        }
    }
    return -1;
}

int main() {
    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> m[i][j];
        }
    }

    int ans = 0;
    int tmp = bfs();
    if(tmp == -1) {
        cout << "-1" << endl;
        return 0;
    }

    for(int i = 0 ;i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(m[i][j] == '#') continue;
            if(i == 0 && j == 0 || i == h-1 && j == w-1) continue;
            m[i][j] = '#';
            int ret = bfs();
            if(ret != tmp) {
                m[i][j] = '.';
                continue;
            }
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
vector<bool> ans(105, false);
int main() {
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	rep (i, n) cin >> p[i];

	
	rep (i, n) ans[p[i]] = true;

	int aa = 10000;
	int sa = 10000;

	for (int i = 0; i <= 200; i++) {
		if (ans[i]) continue;
		if (chmin(sa, abs(x-i))) aa = i;
	}
	cout << aa << endl;
	return 0;
}


Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static long[][] _c;
    public static long _mod = 1000000007;

    public static long comb(int a, int b) {
        if (_c[a][b] > 0) {
            return _c[a][b];
        } else {
            if (a == 0 && b == 0) {
                _c[0][0] = 1;
            } else {
                if (a == b) {
                    _c[a][b] = comb(a - 1, b - 1);
                } else if (b == 0) {
                    _c[a][b] = comb(a - 1, b);
                } else {
                    // if (a > 0 && b > 0) {
                    _c[a][b] = (comb(a - 1, b - 1) + comb(a - 1, b)) % _mod;
                }
            }
            return _c[a][b];
        }
    }
    public static void main(String[] args) {
        _c = new long[2001][2001];

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        for (int i = 1; i <= k; ++i) {
            if (n - k + 1 < i) {
                System.out.println(0);
            } else {
                System.out.println(comb(n - k + 1, i) * comb(k - 1, i - 1) % _mod);
            }
        }
    }
}


Measured memory_bytes: 79700
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    lint W, H;
    cin >> W >> H;
    cout << W * H / 2 << ((W * H) & 1 ? ".5" : "") << " ";

    lint x, y;
    cin >> x >> y;
    cout << (W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2 ? 1 : 0) << endl;
    return 0;
}


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



int main()
{
	int n, a[1000], sum=0, min=0;
	cin >> n;

	for(int i =0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	int avg = round((double)sum/n);
	for(int i=0;i<n;i++)
		min += (avg-a[i])*(avg-a[i]);

	cout << min << endl;
}

Measured memory_bytes: 256
import itertools

n, m, q = map(int, input().split())

l = [1, 2, 3, 4]
l = [m for m in range(1, m + 1)]

ql = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a += -1
    b += -1
    ql.append([a, b, c, d])

# print(ql)

max_s = 0
for v in itertools.combinations_with_replacement(l, n):
    # print(v)
    score = 0
    for qq in ql:
        a, b, c, d = qq
        # print("{} - {} = {}".format(v[b], v[a], c))
        if v[b] - v[a] == c:
            score += qq[3]
            
    # print(score)
    if score > max_s:
        max_s = score
        
print(max_s)

Measured memory_bytes: 9164
n = int(input())
if n%2 == 1:
    print(0)
    
else:
    if n < 10:
        print(0)
    else:
        list5 = []
        flag = True
        num = 5
        while flag:
            tmp = n//(num*2)
            if tmp > 0:
                list5.append(tmp)
                num *= 5
            else:
                flag = False
        ans_list = []
        for i in range(len(list5)-1):
            ans_list.append(list5[i] - list5[i+1])
        ans_list.append(list5[-1])
        ans = 0
        for i in range(len(ans_list)):
            ans += ans_list[i]*(i+1)
        print(ans)

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

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

    long double ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i!=j) ans+=sqrtl(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
        }
    }
    cout << setprecision(12) << ans/N << endl;

    
}

Measured memory_bytes: 256
let k = stdin.ReadLine() |> int
            
let gcd2 x y=
    let x1, x2=
        if y <= x then y,x
        else x, y
    let rec gcdrec2 x1 x2 =
        if x1%x2 = 0 then x2
        else gcdrec2 x2 (x1%x2)
    gcdrec2 x1 x2

let gcd3 x y z =
    let x2 =gcd2 x y
    if x2 >= z then gcd2 x2 z
    else gcd2 z x2

let ans =
    let mutable ans = 0L
    for i1 in {1..k} do
        for i2 in {1..k} do
            for i3 in {1..k} do
                ans <- ans + int64 (gcd3 i1 i2 i3)
    ans

string ans |> stdout.WriteLine


Measured memory_bytes: 46384
#include <iostream>
using namespace std;
int main() {
	int n; cin >> n;
	if (n >= 10000) cout << 9 + 900 + (min(n, 99999) - 10000 + 1);
	else if (n >= 100) cout << 9 + (min(n, 999) - 100 + 1);
	else cout << (min(n, 9));
}

Measured memory_bytes: 256
n, k, q = list(map(int,input().split(' ')))
import numpy as np
point =np.full(n,k-q)
for i in range(q):
  win = int(input())
  point[win-1]+=1
  
  
#print(np.where(point>0,'Yes','No'))
for i in point:
  if i>0:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 13984
#include <iostream>
using namespace std;using ll=long long;const ll M=1e9+7;void add(ll& x,ll y){x+=y; x%=M;}
int main() {int n,m;cin>>n>>m;m++;int s[n],t[m];t[0]=-1;for(int i=0;i<n;i++)cin>>s[i];for(int i=1;i<m;i++)cin>>t[i];ll sm[m]={1};for(int i=0;i<n;i++){ll su=0;for(int j=0;j<m;j++){ll tm=sm[j];if(s[i]==t[j])sm[j]+=su,sm[j]%=M;su+=tm;}}ll an=0;for(int i=0;i<m;i++){an+=sm[i];an%=M;}cout<<an<<endl;}

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

struct num
{
    long a;
    long b;
};

int compare_long(const void *a, const void *b)
{
    return ((struct num *)a)->b - ((struct num *)b)->b;
}

int main()
{
    int n, k = 0;
    scanf("%d", &n);
    struct num job[n];
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%ld %ld", &(job[i].a), &(job[i].b));
    }
    qsort(job, n, sizeof(struct num), compare_long);
    for (i = 1; i < n; i++)
    {
        job[i].a += job[i - 1].a;
    }
    for (i = 0; i < n; i++)
    {
        if (job[i].a > job[i].b)
        {
            k++;
            break;
        }
    }
    if (k == 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

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

class Program
{
	static void Main(string[] args)
	{
		LinkedList<string> answer = new LinkedList<string>();
		foreach(var c in Console.ReadLine()){
		    answer.AddLast(c.ToString());
		}
		bool reverse = false;
		
		long Q = long.Parse(Console.ReadLine());
		for(var i = 0; i < Q; i++){
		    var input = Console.ReadLine().Split(' ');
		    switch(input[0]){
		        case "1":
		            reverse = !reverse;
		            continue;
		        case "2":
		            switch(input[1]){
		                case "1":
		                    if(reverse)
		                        answer.AddLast(input[2]);
		                    else
		                        answer.AddFirst(input[2]);
		                    break;
		                case "2":
		                    if(reverse)
		                        answer.AddFirst(input[2]);
		                    else
		                        answer.AddLast(input[2]);
		                    break;
		                default :
		                    break;
		            }
		            break;
		        default :
		            break;
		    }
		}
		
		var ans = answer.ToArray();
		var sb = new StringBuilder();
		if(reverse) {
		    for(var i = ans.Length - 1; i >= 0; i--){
		        sb.Append(ans[i]);
		    }
		}else{
		    for(var i = 0; i < ans.Length; i++){
		        sb.Append(ans[i]);
		    }
		}
		Console.WriteLine(sb.ToString());
	}
}

Measured memory_bytes: 43292
count = int(input().rstrip())
shops = []
gain = []
for i in range(count):
    shops.append(input().rstrip().split())
for j in range(count):
    gain.append(input().rstrip().split())

max = -1000000000
for k in range(1,1024):
    tmp = format(k,'b').zfill(10)
    tmp_sum = 0
    for N in range(count):
        shop_count = 0
        for l in range(10):
            if tmp[l] == shops[N][l] and tmp[l] =='1':
                shop_count +=1
        tmp_sum += int(gain[N][shop_count]) 
    if max < tmp_sum:
        max = tmp_sum

print(max)

Measured memory_bytes: 3064