akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#include <algorithm> // std::min
#include <utility> // std::pair
#include <vector> // std::vector

using ull = long long;

using Item = std::pair<ull, int>;

// Time complexity is O(items.size() * sum(value)),
// auxiliary space is O(sum(value)).
int knapsack_01_small_value(const std::vector<Item> &items, ull capacity) {
    int n = items.size();
    int value_sum = 0;
    for (const Item &item: items) {
        value_sum += item.second;
    }
    std::vector<ull> dp(value_sum + 1, capacity + 1);
    dp[0] = 0;
    for (const Item &item: items) {
        for (int v = value_sum; v >= item.second; --v) {
            dp[v] = std::min(dp[v], dp[v - item.second] + item.first);
        }
    }
    for (int v = value_sum; ; --v) {
        if (dp[v] <= capacity) {
            return v;
        }
    }
}

int main() {
    using namespace std;

    int N, W;
    cin >> N >> W;
    vector<Item> items(N);
    for (int i = 0; i < N; ++i) {
        int v, w;
        cin >> v >> w;
        items[i] = make_pair(w, v);
    }
    cout << knapsack_01_small_value(items, W) << endl;
    return 0;
}


Measured memory_bytes: 3152
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  string s;cin>>s;
  int n=(int)s.size();
  if(n&1){cout<<"No"<<endl;return 0;}
  bool ans=true;
  rep(i, n){
    if(i%2==0&&s[i]!='h'){ans=false;break;}
    if(i%2==1&&s[i]!='i'){ans=false;break;}
  }
  cout<<(ans?"Yes":"No")<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c float64
	_, _ = fmt.Scan(&a, &b, &c)

	s := a * b * math.Sin(math.Pi*c/180) / 2
	l := a + b + math.Sqrt(math.Pow(a, 2)+math.Pow(b, 2)-2*a*b*math.Cos(math.Pi*c/180))
	h := s / a * 2
	fmt.Println(s)
	fmt.Println(l)
	fmt.Println(h)
}



Measured memory_bytes: 1164
#include<iostream>

using namespace std;

int n, a[100009];

bool binary_search(int x){
  int lb=-1, ub=n;
  while(lb+1<ub){
    int md = (lb+ub)/2;
    if(a[md]<=x)lb=md;
    else ub=md;
  }
  return a[lb]==x;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  int q;cin >> q;
  int cnt=0;
  for(int i=0;i<q;i++){
    int x;cin >> x;
    if(binary_search(x))cnt++;
  }
  cout <<cnt << endl;
}


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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

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

	int ans, cnt = 0;
	for (int i = min(a,b); i >= 1; i--) {
		if ((a % i == 0) && (b % i == 0)) cnt++;
		if (cnt == k) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
int asc(const void *a,const void *b){
    long long *A=(long long*)a,*B=(long long*)b;
    if(*A<*B) return 1;
    if(*A>*B) return -1;
    return 0;
}
int main(){
    ll x,y,a,b,c,i;
    scanf("%lld%lld%lld%lld%lld",&x,&y,&a,&b,&c);
    ll p[a],q[b],r[c];
    for(i=0;i<a;i++) scanf("%lld",&p[i]);
    for(i=0;i<b;i++) scanf("%lld",&q[i]);
    for(i=0;i<c;i++) scanf("%lld",&r[i]);
    qsort(p,a,sizeof(long long),asc);
    qsort(q,b,sizeof(long long),asc);
    qsort(r,c,sizeof(long long),asc);
    ll max=r[0],ans=0,countp=0,countq=0,countr=0;
    ll count=0,all=x+y;
    ll to[a+b+c];
    for(i=0;i<x;i++) to[i]=p[i];
    for(;i<x+y;i++) to[i]=q[i-x];
    for(;i<x+y+c;i++) to[i]=r[i-x-y];
    qsort(to,i,sizeof(long long),asc);
    for(ll j=0;j<x+y;j++)
        ans+=to[j];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7660
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;


ll N, C;

int main(void) {
  cin >> N >> C;
  ll i, j, k;
  ll d[33][33]={};
  ll c[555][555]={};
  
  for(i=0; i<C; i++) {
    for(j=0; j<C; j++) {
      cin >> d[i][j];
    }
  }
  
  for(i=0; i<N; i++) {
    for(j=0; j<N; j++) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  
  ll score[3][33]={};
  for(k=0; k<C; k++) {
    for(i=0; i<N; i++) {
      for(j=0; j<N; j++) {
        ll pclr=c[i][j];
        score[(i+j)%3][k]+=d[pclr][k];
      }
    }
  }
  
  ll ans=INF;
  for(i=0; i<C; i++) {
    for(j=0; j<C; j++) {
      for(k=0; k<C; k++) {
        if(i==j || j==k || k==i) continue;
        
        chmin(ans, score[0][i]+score[1][j]+score[2][k]);
      }
    }
  }
  
  pt(ans);
}






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

public class Main { // "Main" should be used for most online judges
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		if ((r * 100 + g * 10 + b) % 4 == 0)
			System.out.println("YES");
		else
			System.out.printf("NO");
	}
}

Measured memory_bytes: 20820
n = int(input())
a = list(map(int,input().split()))
c = []
a.reverse()
if(len(a)%2==0):
    for i in range(len(a)):
        if(i%2==0):
            c.append(a[i])
    a.reverse()
    for i in range(len(a)):
        if(i%2==0):
            c.append(a[i])
    print(*c)
else:
    for i in range(len(a)):
        if(i%2==0):
            c.append(a[i])
    a.reverse()
    for i in range(len(a)):
        if(i%2==1):
            c.append(a[i])
    print(*c)


Measured memory_bytes: 101588
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int s = 0;
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			s += a[i];
		}
		BigInteger can = BigInteger.ONE;
		for (int i = 0; i < n; ++i) {
			can = can.shiftLeft(a[i]).or(can);
		}
		for (int i = (s + 1) / 2; i <= s; ++i) {
			if (can.testBit(i)) {
				System.out.println(i);
				return;
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

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


Measured memory_bytes: 227368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    sort(ALL(t));
    int count = 1;
    int time = t[0] + k;
    int ans = 1;
    rep(i, n - 1)
    {
        if (count == c || t[i + 1] > time)
        {
            ans++;
            time = t[i + 1] + k;
            count = 1;
        }
        else
        {
            count++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
S = input()
if (int(S[:2]) == 0 and (int(S[2:]) >= 13 or int(S[2:]) == 0)) or \
   (int(S[2:]) == 0 and (int(S[:2]) >= 13 or int(S[:2]) == 0)) or \
   (int(S[2:]) >= 13 and int(S[:2]) >= 13):
    print('NA')
elif (int(S[:2]) >= 13 and int(S[2:]) < 13) or \
     (int(S[:2]) == 0 and int(S[2:]) < 13):
    print('YYMM')
elif (int(S[2:]) >= 13 and int(S[:2]) < 13) or \
     (int(S[2:]) == 0 and int(S[:2]) < 13):
    print('MMYY')
else:
    print('AMBIGUOUS')


Measured memory_bytes: 9180
n=int(input())
lst=[]
for i in range(n):
    a=int(input())
    b=[]
    for j in range(a):
        x,y=map(int,input().split())
        x-=1
        b.append([x,y])
    lst.append(b)
ans=0
for i in range(2**n):
    on=[]
    switch=0
    for j in range(n):
        if ((i>>j)&1):
            on.append(j)
    for j in on:
        judge=lst[j]
        for k in judge:
            if k[1]==1:
                if not k[0] in on:
                    switch=1
            else:
                if k[0] in on:
                    switch=1
    if switch==0:
        ans=max(ans,len(on))

print(ans)

Measured memory_bytes: 9244
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N, A;
    cin >> N >> A;
    cout << N * N - A << endl;
    return 0;
}

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

    f(N, A)


def f(N, A):
    """
    2 ≤ N ≤ 10^5
    −5000 ≤ Ai ≤ 5000 (1≤ i≤ N)

    第一印象: 累積和?
    """
    costs = [abs(A[0])]
    costs_cumsum = [abs(A[0])]
    for i in range(1, N):
        cost = abs(A[i] - A[i-1])
        cumsum = cost + costs_cumsum[-1]

        costs.append(cost)
        costs_cumsum.append(cumsum)

    # 0へ戻る
    cost_N_to_start = abs(A[-1])
    costs.append(cost_N_to_start)
    costs_cumsum.append(cost_N_to_start + costs_cumsum[-1])

    for i in range(N):
        total = costs_cumsum[-1]
        # skip: i-1 to i and i to i+1
        total -= (costs[i] + costs[i+1])

        # add: i-1 to i+1
        bef, aft = 0, 0
        if i - 1 >= 0:
            bef = A[i-1]
        if i + 1 < N:
            aft = A[i+1]
        total += abs(bef - aft)

        print(total)


if __name__ == '__main__':
    main()


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


main(){
   int n;
   cin >> n;
   string s;
   cin >> s;
   for(int i=0;i<s.length();i++){
      s[i]= s[i]+n%26;
      if(s[i]>=65+26) s[i]=s[i]-26;
   }
   for(int i=0;i<s.length();i++) cout << s[i];
}

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int) 1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

int main()
{
    u64 n, x, m;
    u64 sum[200000];
    int fl[200000];
    scanf("%llu%llu%llu", &n, &x, &m);
    memset(sum, 0, sizeof sum);
    memset(fl, 0, sizeof fl);
    sum[1] = x;
    fl[x] = 1;
    u64 ans = x;
    for(i64 i = 2; i <= n; i++) {
        x *= x;
        x %= m;
        // if(x == 0) break;
        if(fl[x]) {
            ans = sum[fl[x]-1];
            i64 f = i - fl[x];
            i64 k = ((n-fl[x]+1)/f);
            i64 l = ((n-fl[x]+1)%f);
            ans += (sum[i-1]-sum[fl[x]-1])*k;
            ans += sum[fl[x]+l-1] - sum[fl[x]-1];
            break;
        } else {
            fl[x] = i;
            sum[i] = x + sum[i-1];
            ans = sum[i];
        }
    }
    printf("%llu\n", ans);
}


Measured memory_bytes: 6172
#include<iostream>
#define ll long long
using namespace std;

int n,a=0,b=0,c=0;
ll tmp;

int main(){
  cin >> n;
  for(int i = 0; i<n; i++){
    cin >> tmp;
    if(tmp % 4 == 0) b++;
    else if(tmp % 2 == 0) c++;
    else a++;
  }

  if(c == 0 and b+1 >= a){
    cout << "Yes" << endl;
    return 0;
  }
  if( c != 0 and b >= a){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  /*/
  if(c != 0) a++;
  if( b+1 >= a) cout << "Yes" << endl;
  else cout << "No" << endl;
  /*/

  return 0;
}

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

char data[101];

int main(void) {
    int i, j, n;
    while(scanf("%s",data) != EOF) {
        n = strlen(data);
        for(i = 0; i < n; i++) {
            if(data[i] == '@') {
                for(j = 0; j < data[i+1] - '0'; j++) {
                    printf("%c",data[i+2]);
                }
                i += 2;
            } else {
                printf("%c",data[i]);
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 524
def merge(s, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = s[left:mid] + [1000000001]
    R = s[mid:right] + [1000000001]

    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            s[k] = L[i]
            i += 1
        else:
            s[k] = R[j]
            j += 1

def mergesort(s, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(s, left, mid)
        mergesort(s, mid, right)
        merge(s, left, mid, right)

n = int(input())
count = 0
s = list(map(int, input().split()))
mergesort(s, 0, n)

for i in range(len(s)-1):
      print(s[i], end = " ")
print(s[n-1])
print(count)



Measured memory_bytes: 61652
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    double h, w, x, y;
    cin >> h >> w >> x >> y;
    printf("%.10lf %d\n", h * w / (double)2, ((x == h / (double)2 && y == w / (double)2) ? 1 : 0));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
long long k,A,p,q;
int main()
{
	cin>>s>>k;
	if(s[0]!=s[s.size()-1])
	{
		for(int i=0;i<s.size()-1;i++)
			if(s[i]==s[i+1])
				A++,i++;
		cout<<A*k;
		return 0;
	}
	for(int i=0;i<s.size();i++)
		if(s[i]==s[0])
			p=i;
		else
			break;
	if(p==s.size()-1)
	{
		cout<<s.size()*k/2;
		return 0;
	}
	for(int i=s.size()-1;i>=0;i--)
		if(s[i]==s[0])
			q=i;
		else
			break;
	for(int i=p;i<q-1;i++)
		if(s[i]==s[i+1])
			A++,i++;
	cout<<((p+1+s.size()-q)/2)*(k-1)+A*k+(s.size()-q)/2+(p+1)/2;
	return 0;
}

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

int main(void){
    //int r,g,b;
    char r,g,b;
    char str[4];
    
    scanf("%c %c %c", &r,&g,&b);
    
    //printf("%c", (char)r);
    
    str[0]=r;
    str[1]=g;
    str[2]=b;
    
    //printf("%s\n", str);

    if((atoi(str))%4==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    
    return 0;
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 100'000 + 5;

i64 T;

i64 n, k;

i64 a[MAXN];
vector<i64> e[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

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

    for (i64 i = 0; i < k; i++) {
        i64 u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    i64 R = 0;
    for (i64 i = 1; i <= n; i++) {
        bool f = true;
        for (auto z : e[i]) {
            if (a[z] >= a[i]) {
                f = false;
                break;
            }
        }

        if (f) {
            R += 1;
        }
    }


    cout << R << endl;
    return 0;
}

Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAXC 100000
#define MOD 1000000007 
int main()
{
	int n,m;
	cin>>n>>m;
	char a[n][m];
	ll dp[n+1][m+1];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0 || j==0) dp[i][j]=0;
			else if(a[i-1][j-1]=='#') dp[i][j]=0;
			else if(i==1 && j==1) dp[i][j]=1; 
			else dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
		}
	}
	cout<<dp[n][m]%MOD;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 1005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        ll cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
        int n, m;
        cin >> n >> m;
        vector<ll> v(m);
        for (ll i = 0; i < m; i++) cin >> v[i];
        sort(v.begin(), v.end());
        vector<string> dp(n + 10, "");
        auto cmp = [](string a, string b) {
            if (a.size() != b.size()) return a.size() < b.size();
            for (ll i = 0; i < (ll)a.size(); i++) {
                if (a[i] != b[i]) return a[i] < b[i];
            }
            return false;
        };

        for (ll i = 0; i < n; i++) {
            if (i && dp[i] == ""s) continue;
            for (ll x : v) {
                if (cmp(dp[i + cost[x]], dp[i] + char('0' + x)))
                    dp[i + cost[x]] = dp[i] + char('0' + x);
            }
        }
        cout << dp[n] << endl;

    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 43904
#include<iostream>


int main()
{
    int a, b, k; std::cin >> a >> b >> k;

    while(k != 0){
        if (a%2 != 0){
            a--;
        }
        b += a/2;
        a /= 2;
        k--;
        if ( k == 0 ){break;}
        if (b%2 != 0){
            b--;
        }
        a += b/2;
        b /= 2;
        k--;
    }
    std::cout << a << " " << b << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
//なんかよくわからないやつ
class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      //入力のやつ
        int X = sc.nextInt();
        //鉄道運賃
        int Y = sc.nextInt();
        //バス運賃
        System.out.println(X + Y / 2);
        //合計運賃を計算して出力
    }
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

void solve(long long N, std::vector<long long> a) {
    long long sum = 0;
    int idx = -1;
    int dist = 1e9;
    for(int i = 0 ; i < N ; i++){
      sum += a[i];
    }

    for(int i = 0 ; i < N ; i++){
      if( dist > abs(a[i] * N - sum) ){
        dist = abs(a[i] * N - sum);
        idx = i;
      }
    }
    cout << idx << endl;

}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N - 1 - 0 + 1);
  for (int i = 0; i < N - 1 - 0 + 1; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int a[maxn][4],dp[maxn][4];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    rep(i,1,n)cin>>a[i][1]>>a[i][2]>>a[i][3];
    rep(i,1,n){
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+a[i][2];
        dp[i][3]=max(dp[i-1][1],dp[i-1][2])+a[i][3];
        /* rep(j,1,3)rep(k,1,3)if(j!=k){
            dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i][k]);
        } */

    }
    int ans=0;
    rep(i,1,3){ans=max(dp[n][i],ans);}
    cout<<ans<<endl;
}
/* 
不能两天选同样的。
dp[i][123]:结尾是几的最大值。
 */

Measured memory_bytes: 5888
//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>	
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define ld long double
#define put(x) printf("%d\n",x)
#define min(x,y) ((x)>(y)?(y):(x))
#define max(x,y) ((x)>(y)?(x):(y))
#define EPS 1e-8
#define mod 1000000007
#define INF 1000000000
using namespace std;
char *fs,*ft,buf[1<<15];
inline char getc()
{
	return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=20;
int n,ans=INF;
int a[MAXN],b[MAXN],c[MAXN],v[MAXN][2];
int w[MAXN],pos[MAXN],vis[MAXN];
struct wy
{
	int x;
	int op;
}t[MAXN];
inline void calc()
{
	int cnt=0;
	for(int i=1;i<=n;++i)
	{
		if(c[i]) w[i]=b[i];
		else w[i]=a[i];
		t[i]=(wy){i,0};
	}
	sort(w+1,w+1+n);
	for(int i=1;i<=n;++i)//谁到第一个位置
	{
		for(int j=i;j<=n;++j)
		{
			int d=j-i;
			int ww=t[j].op^(d&1);
			if(v[t[j].x][ww]==w[i]&&c[t[j].x]==ww)
			{
				for(int k=j;k>i;--k)
				{
					swap(t[k],t[k-1]);
					t[k].op=t[k].op^1;++cnt;
					t[k-1].op=t[k-1].op^1;
					if(cnt>=ans)return;
				}
				break;
			}
		}
		if(v[t[i].x][t[i].op]!=w[i])return;
	}
	ans=min(ans,cnt);
}
inline void dfs(int x)
{
	if(x==n+1)
	{
		calc();
		return;
	}
	c[x]=0;
	dfs(x+1);
	c[x]=1;
	dfs(x+1);
}
int main()
{
	//freopen("1.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i)a[i]=read(),v[i][0]=a[i];
	for(int i=1;i<=n;++i)b[i]=read(),v[i][1]=b[i];
	dfs(1);
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main()
{

    int n;
    cin>>s;
    n=s.size();
    int a,b;
    a=0,b=0;
    for(int i=0;i<n;i++)
        if(s[i]=='0')a++;
    else b++;
    a=min(a,b);
    printf("%d",a*2);


    return 0;
}


Measured memory_bytes: 512
// atcoder/agc018/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  while (cin >> n >> k) {
    vector<int> a(n);
    cin >> a;
    int g = a.front();
    each (i, a) g = __gcd(i, g);
    bool f = count(a.begin(), a.end(), k);
    each (i, a) {
      if (k <= i) {
        f = f || ((k - i) % g == 0);
      }
    }
    cout << (f ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI n;
	cin >> n;
	LLI ans = 0;
	FOR(a, 1, n)
	{
		ans += (n - 1) / a;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 200010
#define M 26
int n, dp[N][M];
char dp2[N][M];
int a[M], l[N][M], r[N][M];
string s;

int main(){
	cin>>s;
	n = s.size();
	mset(a, -1);
	rep(i, n){
		rep(j, M) l[i][j] = a[j];
		a[s[i]-'a'] = i;
	}
	fill(a, a+M, n);
	for(int i = n-1; i >= 0; i--){
		a[s[i]-'a'] = i;
		rep(j, M) r[i][j] = a[j];
	}
	mset(a, 0);
	int cnt = 0;
	vector<int> v;
	v.push_back(n);
	for(int i = n-1; i >= 0; i--){
		cnt += !a[s[i]-'a'];
		a[s[i]-'a'] |= 1;
		if(cnt==M){
			v.push_back(i);
			cnt = 0;
			mset(a, 0);
		}
	}
	reverse(all(v));
	string res = "";
	/*rep(i, M){
		if(!a[i]){
			res += 'a'+a[i];
			break;
		}
	}
	int p = r[0][res[0]-'a'];*/
	int p = 0;
	rep(i, v.size()){
		char t;
		rep(j, M) if(r[p][j]>=v[i]){
			t = j;
			break;
		}
		res += 'a'+t;
		p = r[p][t]+1;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 41604
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  long N;
  cin >> N;
  vector<long> a(3*N);
  rep(i, 3*N) cin >> a[i];

  priority_queue<long, vector<long>, greater<long>> before_queue;
  priority_queue<long> after_queue;

  long before_sum = 0;
  long after_sum = 0;

  vector<long> before_result(3*N, 0);
  vector<long> after_result(3*N, 0);

  for(long i = 0; i < N; i++) {
    before_sum += a[i];
    before_queue.push(a[i]);
  }
  before_result[N-1] = before_sum;
  for (long i = N; i < 2*N; i++) {
    before_sum += a[i];
    before_queue.push(a[i]);
    before_sum -= before_queue.top();
    before_queue.pop();
    before_result[i] = before_sum;
  }

  for (long i = 3*N-1; i >= 2*N; i--) {
    after_sum += a[i];
    after_queue.push(a[i]);
  }
  after_result[2*N] = after_sum;
  for (long i = 2*N-1; i >= N; i--) {
    after_sum += a[i];
    after_queue.push(a[i]);
    after_sum -= after_queue.top();
    after_queue.pop();
    after_result[i] = after_sum;
  }

/*
  rep (i, 3*N) cout << before_result[i] << " ";
  cout << endl;
  rep (i, 3*N) cout << after_result[i] << " ";
  cout << endl;
*/

  for (long i = N-1 + 1; i < 2*N; i++) before_result[i] = max(before_result[i-1], before_result[i]);
  for (long i = 2*N - 1; i >= N; i--) after_result[i] = min(after_result[i+1], after_result[i]);

  bool not_calculated = true;
  long result;

  for (long i = N-1; i < 2*N; i++) {
    long tmp_result = before_result[i] - after_result[i+1];
    if (not_calculated or result < tmp_result) result = tmp_result;
    not_calculated = false;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 9588
#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;

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


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

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

	int ans = 0;
	rep(i,n){
		int a;
		cin >> a;
		if(a % 2 == 1) ans = 1;
	}

	if(ans != 0)
		puts("first");
	else
		puts("second");

	return 0;
}

Measured memory_bytes: 256
S = input()
flg = True
cnt = 0

for i, c in enumerate(S):
    if i == 0 and c != 'A':
        flg = False
    if i == 1:
        if c == 'C' or c.islower == False:
            flg = False
    if i > 0 and i != len(S) - 1:
        if c == 'C':
            cnt += 1
        elif c.islower() == False:
            flg = False
    if i == len(S) - 1:
        if c.islower() == False or c == 'C':
            flg = False

if cnt == 1 and flg == True:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 38488
#include <bits/stdc++.h>
#define hash Tomori_chan
#define check Isla_never_dies
#define int long long
#define checkxuoi Isla_best_waifu
#define checknguoc Tomori_second_best_waifu

using namespace std;

const int base=69;
const int mod=696969691;

int n;
int Tomori_chan[500005];
bool Isla_never_dies[500005];
int mu[500005];
string s;
bool Isla_best_waifu[500005];
bool Tomori_second_best_waifu[500005];

bool match(int i, int j, int len)
{
	if(i>j) swap(i,j);
	if(((hash[i+len-1]-hash[i-1]+mod)%mod*mu[j-i])%mod==(hash[j+len-1]-hash[j-1]+mod)%mod) return true;
	return false;
}

signed main()
{
	mu[0]=1;
	for(int i=1; i<=500000; i++)
	{
		mu[i]=(mu[i-1]*base)%mod;
	}
	cin>>s;
	n=s.length();
	s='!'+s;
	for(int i=1; i<=n; i++)
	{
		hash[i]=hash[i-1]+s[i]*mu[i];
		hash[i]%=mod;
	}
	bool dif=true;
	for(int i=2; i<=n; i++)
	{
		if(s[i]!=s[i-1])
		{
			dif=false;
			break;
		}
	}
	if(dif)
	{
		cout<<n<<"\n"<<1;
		return 0;
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=2*i; j<=n; j+=i)
		{
			if(match(j-i+1, j-2*i+1,i))
			{
				checkxuoi[j]=true;
			}
			else
			{
				break;
			}
		}
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=n+1-2*i; j>=1; j-=i)
		{
			if(match(j, j+i,i))
			{
				checknguoc[j]=true;
			}
			else
			{
				break;
			}
		}
	}
	if(!checkxuoi[n]) 
	{
		cout<<"1\n1";
		return 0;
	}
	int ans=0;
//	for(int i=1; i<=n; i++)
//	{
//		cout<<checkxuoi[i]<<" "<<checknguoc[i]<<endl;
//	}
	for(int i=1; i<n; i++)
	{
		if(checkxuoi[i]||checknguoc[i+1]) continue;
		ans++;
	}
	cout<<2<<endl<<ans;
}

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

using namespace std;
#define int long long
const int N = 666666 , inf = 99999999999;
signed main(){
	string s,t;
	cin>>s>>t;
	int ans=s.size();
	for(int i=0;i<=s.size()-t.size();i++){
		
		
			int sum=0;
			for(int j=0;j<t.size();j++){
				if(s[i+j]!=t[j]) sum++;
			}
			ans=min(ans,sum); 			
	
	}
	cout<<ans;
	return 0;
}
/*
cabacc
012345
*/

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

long long int t;
const long long int MAX_T=1e8;
long long int read(int& i,string& s);
long long int counta(int &i,string &s);
char solve(int &i,string &s){
  int prei=i;
  long long int ret;
  while(ret=read(i,s)){
    prei=i;
    if(ret==-1){
      t--;
      if(t==0) return s[i-1];
    }
    else{
      long long int val=counta(i,s);
      if(val*ret>=t){
	t%=val;
	if(t==0) t=val;
	i=prei;
	return solve(i,s);
      }
      else{
	t-=val*ret;
      }
    }
  }
  return '0';
  
}

long long int counta(int &i,string &s){
  long long int ret;
  long long int res=0;
  while(ret=read(i,s)){
    if(ret==-1){
      res++;
    }
    else{
      res+=counta(i,s)*ret;
      res=min(res,MAX_T);
    }
  }
  return min(MAX_T,res);
}

long long int read(int& i,string& s){
  if(i>=s.size() || s[i]==')'){
    i++;
    return 0;
  }
  if(isalpha(s[i])){
    i++;
    return -1;
  }

  long long int prei=i;
  for(;i<s.size() && isdigit(s[i]);i++);
  long long int res=(i-prei>8 ? MAX_T :stoi(s.substr(prei,i-prei)));
  i++;
  return res;
}


int main(){
  string s;
  while(cin>>s>>t,s!="0"){
    int i=0;
    t++;
    string s2="";
    s2+=s[0];
    for(int i=1;i<s.size();i++){
      if(isdigit(s[i-1]) && !isdigit(s[i]) && s[i]!='('){
	s2+='(';
	s2+=s[i];
	s2+=')';
      }
      else{
	s2+=s[i];
      }

    }
    s=s2;

    cout<<solve(i,s)<<endl;
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    cout << (a+b >= c ? "Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool check(int x){
    int value = x%10;
    while(x){
        if(x%10 != value){
            return false;
        }
        x /= 10;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    for(int i = N;;++i){
        if(check(i)){
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,m;cin >> n >> m;
    vector<tuple<ll,ll,vector<ll>,ll>> v(m);
    vl s(12,0);
    rep(i,m){
        cin >> get<0>(v[i]) >> get<1>(v[i]);
        get<2>(v[i])=s;
        get<3>(v[i])=i+1;
    }
    sort(all(v));
    ll count=1;
    rep(i,m){
        ll p=count;
        ll place=11;
        while(p){
            get<2>(v[i])[place]=p%10;
            p/=10;
            place--;
        }
        if((get<0>(v[i])!=get<0>(v[i+1]))&&i<m-1)count=1;
        else count++;
        ll pref=get<0>(v[i]);
        ll end=5;
        while(pref){
            get<2>(v[i])[end]=pref%10;
            pref/=10;
            end--;
        }
    }
    rep(i,m){
        swap(get<0>(v[i]),get<3>(v[i]));
    }
    sort(all(v));
    rep(i,m){
        rep(j,12){
            cout << get<2>(v[i])[j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int limit = 100010;
    using edge = struct {int to; ll cost;};
    vector<edge> tree[limit];
    ll depth[limit];
     
    void dfs(int v, int p, ll d) {
    	depth[v] = d;
    	for (auto &e : tree[v]) {
    		if (e.to == p) continue;
    		dfs(e.to, v, d + e.cost);
    	}
    }
     
    int main(void) {
    	int n;
    	cin >> n;
     
    	for (int i = 0; i < n - 1; ++i) {
    		int a, b, c;
    		cin >> a >> b >> c;
    		a--, b--;
    		tree[a].push_back({b, c});
    		tree[b].push_back({a, c});
    	}
     
    	int q, k;
    	cin >> q >> k;
    	k--;
     
    	dfs(k, -1, 0);
    	for (int i = 0; i < q; ++i) {
    		int x, y;
    		cin >> x >> y;
    		x--, y--;
    		cout << depth[x] + depth[y] << endl;
    	}
     
    	return 0;
    }

Measured memory_bytes: 14336
class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def toN(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def toE(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def toS(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def toW(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def printTop(self):
        print(self.top)


n = input().split()

dice = Dice(int(n[0]), int(n[1]), int(n[2]), int(n[3]), int(n[4]), int(n[5]))

order = input()
for o in order:
    if o == "N":
        dice.toN()
    elif o == "E":
        dice.toE()
    elif o == "S":
        dice.toS()
    elif o == "W":
        dice.toW()

dice.printTop()



Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * a -b << endl;
}

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

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = (int)vs[0];
			long c = vs[1];
			long[,] sushi = new long[n + 1, 10];
			// sushi[i,0] 距離
			// sushi[i,1] 熱量

			// sushi[i,2] cw 熱量 累積和
			// sushi[i,3] cw 片道収支
			// sushi[i,4] cw 往復収支
			// sushi[i,5] cw 往復収支 最大

			// sushi[i,6] ccw 熱量 
			// sushi[i,7] ccw 片道収支
			// sushi[i,8] ccw 往復収支
			// sushi[i,9] ccw 往復収支 最大

			for (int i = 1; i <= n; i++) {
				vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
				sushi[i, 0] = vs[0];
				sushi[i, 1] = vs[1];
				sushi[i, 2] = sushi[i, 1] + sushi[i - 1, 2];
				sushi[i, 3] = sushi[i, 2] - sushi[i, 0];
				sushi[i, 4] = sushi[i, 2] - sushi[i, 0] * 2;
				sushi[i, 5] = Math.Max(sushi[i - 1, 5], sushi[i, 4]);
			}
			for (int i = n; i > 0; i--) {
				sushi[i, 6] = sushi[i, 1] + (i < n ? sushi[i + 1, 6] : 0);
				sushi[i, 7] = sushi[i, 6] - (c - sushi[i, 0]);
				sushi[i, 8] = sushi[i, 6] - (c - sushi[i, 0]) * 2;
				sushi[i, 9] = Math.Max((i < n ? sushi[i + 1, 9] : 0), sushi[i, 8]);
			}
			//for (int i = 0; i < sushi.GetLength(0); i++) {
			//	System.Diagnostics.Debug.Write($"{i}:");
			//	for (int j = 0; j < sushi.GetLength(1); j++) {
			//		System.Diagnostics.Debug.Write($"{sushi[i, j],3} ");
			//	}
			//	System.Diagnostics.Debug.WriteLine("");
			//}
			long ans = 0;
			for (int i = 1; i <= n; i++) {
				//System.Diagnostics.Debug.WriteLine($"          0 --> {i}:{sushi[i, 3],3}");
				ans = Math.Max(ans, sushi[i, 3]);
				int j = i + 1;
				if (j <= n) {
					//System.Diagnostics.Debug.WriteLine($"{j}:{sushi[j, 9],3} <-> 0 --> {i}:{sushi[i, 3],3} {sushi[j, 9] + sushi[i, 3]}");
					ans = Math.Max(ans, sushi[j, 9] + sushi[i, 3]);
				}
			}
			for (int i = n; i >= 1; i--) {
				//System.Diagnostics.Debug.WriteLine($"{i}:{sushi[i, 7],3} <-- 0");
				ans = Math.Max(ans, sushi[i, 7]);
				int j = i - 1;
				if (j >= 0) {
					//System.Diagnostics.Debug.WriteLine($"{i}:{sushi[i, 7],3} <-- 0 <-> {j}:{sushi[j, 5],3} {sushi[i, 7] + sushi[j, 5]}");
					ans = Math.Max(ans, sushi[i, 7] + sushi[j, 5]);
				}
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 54696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define ll long long
#define mod 1000000007

using namespace std;


void check(int **dp,int N){
    int num=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<64;j++){
            if(dp[i][j]<0) num++;
        }
    }
    cout<<num<<endl;
}

int main(){
    int N;
    cin >> N;
    ll **dp=new ll*[N-2];
    for(int i=0;i<N-2;i++) dp[i]=new ll[64];
    int rem;
    for(int i=0;i<N-2;i++){
        for(int j=0;j<64;j++){
            if(i==0){
                dp[i][j]=1;
            }else{
                rem=j%16;
                if(rem==1||rem==4||j==5||j==7||j==9||j==13) dp[i][j]=(dp[i-1][rem*4]+dp[i-1][rem*4+1]+dp[i-1][rem*4+3])%mod;
                else if(rem==2) dp[i][j]=(dp[i-1][rem*4]+dp[i-1][rem*4+2]+dp[i-1][rem*4+3])%mod;
                else dp[i][j]=(dp[i-1][rem*4]+dp[i-1][rem*4+1]+dp[i-1][rem*4+2]+dp[i-1][rem*4+3])%mod;
            }
        }
    }
    ll ans=0;
    for(int i=0;i<64;i++){
        if(i==6||i==9||i==18) continue;
        ans+=dp[N-3][i];
    }
    cout<<ans%mod<<endl;
    return 0;

}

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

template <class T>
using V = vector<T>;

template <class T>
using VV = V<V<T>>;

template <class T>
using P = pair<T, T>;

const int MOD = 1000000007;

int main() {
    int H, W;
    cin >> H >> W;
    V<string> A(H);
    for (int i = 0; i < H; ++i) {
        cin >> A[i];
    }
    VV<int> dp(H, V<int>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') continue;
            if (i - 1 >= 0 && A[i - 1][j] == '.') {
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            }
            if (j - 1 >= 0 && A[i][j - 1] == '.') {
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 9468
# include <bits/stdc++.h>
# define rr register
const int N=100010,INF=0x3f3f3f3f;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
int main(void){
	double R=read()*2;
	printf("%.12lf",R*acos(-1));

	return 0;
}


Measured memory_bytes: 3764