akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[][] g = new boolean[n][n];
        int[] a = new int[m];
        int[] b = new int[m];
        for(int i = 0;i < m;i++){
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
            g[a[i]][b[i]] = true;
            g[b[i]][a[i]] = true;
        }

        int answer = 0;
        for(int i = 0;i < m;i++){
            g[a[i]][b[i]] = false;
            g[b[i]][a[i]] = false;
            boolean[] v = new boolean[n];
            dfs(0,n,g,v);
            boolean bridge = false;
            //System.out.println(Arrays.toString(v));
            for(int j = 0;j < n;j++){
                if(!v[j]){
                    bridge = true;
                    break;
                }
            }
            if(bridge){
                answer++;
            }
            g[a[i]][b[i]] = true;
            g[b[i]][a[i]] = true;
        }
        System.out.println(answer);
    }
    public static void dfs(int i,int n,boolean[][] g,boolean[] v){
        v[i] = true;
        for(int j = 0;j < n;j++){
            if(!g[i][j]){
                continue;
            }
            if(v[j]){
                continue;
            }
            dfs(j,n,g,v);
        }
        return;
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<set>
#include<cmath>
using namespace std;
int main()
{
  int a,b,c,x,ans=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++)
    for(int j=0;j<=b;j++){
      int k=(x-500*i-100*j)/50;
      if(k>=0&&k<=c)
        ans++;
    }
  cout<<ans;
  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll W, a, b;
    cin >> W >> a >> b;
    ll ans = INF;
    if (a + W < b)
        ans = b - (a + W);
    else
        ans = a - (b + W);

    cout << std::max(0LL, ans) << endl;
    return 0;
}

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

int main(){
	int n; cin>>n;
	vector<vector<int>> vv(2,vector<int>(n));
	rep(i,2){
		rep(j,n){
			cin>>vv[i][j];
		}
	}
	int mx=0;
	int cnt1=0;
	rep(i,n){
		cnt1+=vv[0][i];
		int cnt2=0;
		for(int j=i; j<n; j++){
			cnt2+=vv[1][j];
		}
		mx=max(mx,cnt1+cnt2);
	}
	cout<<mx<<endl;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(A * B == 15){
			Console.WriteLine("*");
		} else if(A + B == 15){
			Console.WriteLine("+");
		} else {
			Console.WriteLine("x");
		}
	}
	long A,B;
	public Sol(){
		var d = ria();
		A = d[0]; B = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

vector<int> g[MAX];
int C[MAX];
int numb;
bool is;
LL o, e, iz;

void dfs(int v, int c)
{
	if (C[v] != -1)
	{
		if (C[v] != c) is = false;
		return;
	}

	numb++;
	C[v] = c;
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to, c ^ 1);
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	FILL(C, -1);
	FOR(i, 0, n)
	{
		if (C[i] == -1)
		{
			numb = 0;
			is = true;
			dfs(i, 0);

			if (numb == 1)
			{
				iz++;
				continue;
			}

			if (is) e++; else o++;
		}
	}

	//cout << res << endl;
	LL res = 2 * e * e + o * o + 2 * o * e + n * iz + iz * (n - iz);
	cout << res << endl;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	ll Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	ll ans = N * S;
	ans = min(ans, N * H * 2);
	ans = min(ans, N * Q * 4);
	if (N % 2 == 0)
		ans = min(ans, N * D / 2);
	else
		ans = min(ans, ans / N + N / 2 * D);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []

for i in range(n):
  a.append(input())

print("AC x " + str(a.count("AC")))
print("WA x " + str(a.count("WA")))
print("TLE x " + str(a.count("TLE")))
print("RE x " + str(a.count("RE")))

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

int main(){
  int N, M;
  cin >> N >> M;
  int sho = -1000000, dai = 1000000, tmpsho, tmpdai;
  for (int i = 0; i < M; i++){
    cin >> tmpsho >> tmpdai;
    sho = max(sho, tmpsho);
    dai = min(dai, tmpdai);
  }
  int c = 0;
  for (int i = 1; i <= N; i++){
    if(sho <= i && i <= dai) c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

const int maxn = 2e5 + 5;

long long bit[maxn];

void update(int pos, long long val) {
	while (pos < maxn) {
		bit[pos] += val;
		pos += (pos & -pos);
	}
}

void update(int l, int r, long long val) {
	update(l, val);
	update(r + 1, -val);
}

long long query(int pos) {
	long long sum = 0;
	while (pos > 0) {
		sum += bit[pos];
		pos -= (pos & -pos);
	}
	return sum;
}

int n;
long long d;
long long A;
long long arr[maxn];
long long coor[maxn];

signed main() {
	cin >> n >> d >> A;
	vector < pair <int, int> > vec;
	for (int i = 1; i <= n; i++) {
		int cor, val;
		cin >> cor >> val;
		vec.push_back(make_pair(cor, val));
	}
	sort(vec.begin(), vec.end());
	vector <int> coordinates;
	for (int i = 1; i <= n; i++) {
		arr[i] = vec[i - 1].second;
		coor[i] = vec[i - 1].first;
		coordinates.push_back(vec[i - 1].first);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		long long sum = query(i);
		if (sum >= arr[i]) {
			continue;
		}
		long long dif = arr[i] - sum;
		long long need = dif / A + (dif % A > 0); 
		ans += need;
		int l = i;
		int r = upper_bound(coordinates.begin(), coordinates.end(), coor[i] + 2 * d) - coordinates.begin();
		update(l, r, A * need);
	}
	cout << ans << endl;
}

Measured memory_bytes: 11404
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vint vector<int> 
#define rep(i,a,n) for(i=a;i<n;i++)
#define INF (int)1000000007

//etprecision()<<

using namespace std;

void fin(int i,int n,vint &a){
    rep(i,0,n){
        cin>>a.at(i);
    } 
}

int summ(int n){
    int i,sum=0;
    rep(i,0,n+1){
        sum+=i;
    }
    return sum;
}

signed main() {
    int i;
    string S;
    cin>>S;
    int N=S.size()+1;
    int count=1;
    vint num(0); //連続する個数
    rep(i,0,N-2){
        if(S.at(i)==S.at(i+1)){
            count++;
        }
        else{
            num.push_back(count);
            count=1;
        }
        if(i==N-3){
            num.push_back(count);
        }
    }
    if(S.size()==1){
        num.push_back(count);
    }
    int len=num.size();
    int sum=0;

    /*rep(i,0,len){
        cout<<num.at(i)<<endl;
    }*/

//cout<<len<<endl;
    if(S.at(0)=='<'){
        for(i=0;i<=len-2;i+=2){
            sum+=summ(max(num.at(i),num.at(i+1)))+summ(min(num.at(i),num.at(i+1))-1);
                    //cout<<sum<<endl;
        }
        if(i==len-1 && len%2==1){
            sum+=summ(num.at(len-1));
                   // cout<<sum<<endl;
        }
    }
    else{
        sum+=summ(num.at(0));
        for(i=1;i<=len-2;i+=2){
            sum+=summ(max(num.at(i),num.at(i+1)))+summ(min(num.at(i),num.at(i+1))-1);
        }
        if(i==len-1 && len%2==0){
            sum+=summ(num.at(len-1));
        }
    }

    cout<<sum<<endl;
    
return 0;
}

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

int main(){
    long long N;
    cin>>N;
    long long check=26;
    long long keta=1;
    while(1){
        if(N>check){
            N-=check;
            keta++;
        }else{
            break;
        }
        check*=26;
    }
    check/=26;
    while(check>1){
        long long syou=N/check;
        long long amari=N%check;
        char s='a'+syou;
        if(amari==0){
           if(syou==0){
               s='z';
           }else{
               s='a'+syou-1;
           }
        }
        cout<<s;
        check/=26;
        N=amari;
    }
    char ss='a'+N-1;
    if(N==0){
        ss='z';
    }
    cout<<ss<<endl;
    return 0;
}

Measured memory_bytes: 3632
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort(reverse=True)
plus = []
minus = []
lin = []
for i in li:
    if i < 0:
        minus.append(i)
    else:
        plus.append(i)
if not plus:
    x = minus[0]
    for i in range(1,n):
        y = minus[i]
        lin.append([x,y])
        x -= y
    print(x)
    for i in lin:
        print(*i)
elif not minus:
    x = plus[-1]
    for i in range(1,n-1):
        y = plus[i]
        lin.append([x,y])
        x -= y
    lin.append([plus[0],x])
    print(plus[0]-x)
    for i in lin:
        print(*i)
else:
    x = minus[-1]
    y = plus[0]
    for i in range(len(minus)-1):
        lin.append([y,minus[i]])
        y -= minus[i]
    for i in range(1,len(plus)):
        lin.append([x,plus[i]])
        x -= plus[i]
    lin.append([y,x])
    print(y-x)
    for i in lin:
        print(*i)

Measured memory_bytes: 23224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  string a;
  cin>>a;
  if(a.at(2)==a.at(3)&&a.at(4)==a.at(5)){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  
  
  
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

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

    vector<lint> f(N + 1, 0);

    for (int x = 1; x * x <= N; x++) {
        for (int y = 1; y * y < N; y++) {
            for (int z = 1; z * z <= N; z++) {
                int v = x * x + y * y + z * z + x * y + y * z + z * x;
                if (v <= N) { f[v]++; }
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        cout << f[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using ll = long long;


int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

    ll ans = 0;
    for(int a=1; a<=k; a++){
        for(int b=1; b<=k; b++){
            for(int c=1; c<=k; c++){
                ans+= gcd( gcd(a,b), gcd(b,c));
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3552
#define loop(i, s, e) for(ll i = s;i < e;i++)

#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long signed ll;

ll v, e, s, t;
vector<pair<ll, ll>> w;
bool color[10000];
ll indeg[10000];
queue<ll> q;
vector<ll> out;

void bfs(ll ss){
    q.push(ss);
    color[ss] = true;
    while(!q.empty()){
        int u = q.front();q.pop();
        out.push_back(u);
        auto l = lower_bound(w.begin(),w.end(),make_pair((ll)u,(ll)0));
        auto r = lower_bound(w.begin(),w.end(),make_pair((ll)u+1,(ll)0));
        for(auto itr = l;itr != r;itr++){
            indeg[itr->second]--;
            if(!indeg[itr->second] && !color[itr->second]){
                color[itr->second] = true;
                q.push(itr->second);
            }
        }

    }
}

int main() {
    cin >> v >> e;
    loop(i, 0, e) {
        cin >> s >> t;
        indeg[t]++;
        w.push_back(make_pair(s, t));
    }
    sort(w.begin(), w.end());
    loop(u,0,v) if(!indeg[u] && !color[u]) bfs(u);
    for(auto x:out) cout << x << endl;
}




Measured memory_bytes: 3884
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
int a,b,c,K;
int ans;
int main(){
    std::cin>>a>>b>>c>>K;
    int m=std::max({a,b,c});
    ans=a+b+c-m;
    for(int i=0;i<K;i++){
        m*=2;
    }
    std::cout<<ans+m<<std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main()
{
  int n, k;
  cin>>n>>k;
  int a[n+1];
  for(int i=1;i<=n;i++) cin>>a[i];
  long long int dp[n+1][k+1];
  for(int i=0;i<=n;i++) dp[i][0]=1;
  for(int j=1;j<=k;j++) dp[0][j]=1;
  for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) dp[i][j]=(dp[i][j-1]+dp[i-1][j]-((j>a[i])?dp[i-1][j-a[i]-1]:0))%mod;
  /*for(int i=0;i<=n;i++)
  {
      for(int j=0;j<=k;j++) cout<<dp[i][j]<<" ";
      cout<<"\n";
  }*/
  cout<<(dp[n][k]-((k>0)?dp[n][k-1]:0)+mod)%mod;
}

Measured memory_bytes: 82408
package main

import "fmt"

func main() {
	var n, d, x int
	fmt.Scan(&n, &d, &x)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	count := 0
	for i := 0; i < n; i++ {
		for j := 0; ; j++ {
			if d < j*a[i]+1 {
				break
			}
			count++
		}
	}

	fmt.Println(count + x)
}


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

int main() {
    int N, M;  cin >> N >> M;
    vector<int> k(M);
    vector<vector<int>> s(M, vector<int>(N));
    for (int i = 0; i < M; ++i) {
        cin >> k[i];
        s[i].resize(k[i]);
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
            --s[i][j];
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; ++i) cin >> p[i];

    int ans = 0;
    for (int i = 0; i < (1 << N); ++i) {
        bool ok = true;
        for (int j = 0; j < M; ++j) {
            int c = 0;
            for (int id : s[j]) {
                if ((i >> id) & 1) ++c;
            }
            if (c % 2 != p[j]) ok = false;
        }
        if (ok) ++ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,
        a:[usize;n],
    }
    let mut nx = 0;

    let mut ans = 0;
    for &x in a.iter() {
        if x == nx + 1 {
            nx = x;
        }
    }
    if nx == 0 {
        println!("{}", -1);
    } else {
        println!("{}", n - nx);
    }
}


Measured memory_bytes: 4820
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()
if (A + B < C + D):
    print("Right")
elif A + B == C + D:
    print("Balanced")
else:
    print("Left")


Measured memory_bytes: 27212
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 2:
        print(max(A))
        exit()
    l_gcd = [A[0]]
    for a in A[1:N-1]:
        l_gcd.append(math.gcd(l_gcd[-1], a))
    r_gcd = [A[-1]]
    for a in list(reversed(A))[1:N-1]:
        r_gcd.append(math.gcd(r_gcd[-1], a))

    ans = 1
    for i in range(N):
        if i == 0:
            v = r_gcd[-1]
        elif i == N-1:
            v = l_gcd[-1]
        else:
            v = math.gcd(l_gcd[i-1], r_gcd[N-i-2])
        if v > ans:
            ans = v
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 99228
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
const int MAXN = 100001;

/*struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];*/


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

//-----Template---------
int n;
int minimum=INF;
string s,t;
int main(){
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin>>n>>s>>t;
    for (int i = 0; i <= n; ++i) {//食い込む量
        bool flag=true;
        for (int j = 1; j <= i; ++j) {
            if(s[s.length()-j]!=t[i-j]){
                flag=false;
                break;
            }
        }
        if(flag)
            chmin(minimum,(s.length()-i)*2+i);
    }
    cout<<minimum<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x;
    cin >> x;
    vector<ll> a(N,0);
    for(ll i=0;i<N;++i)cin>>a[i];
    ll ans=INF;
    vector<ll> cost=a;
    for(ll i=0;i<N;++i){
        ll sum=x*i;
        for(ll j=0;j<N;++j)sum+=cost[j];
        chmin(ans,sum);
        for(ll j=0;j<N;++j)chmin(cost[j],a[(j-i-1+N)%N]);
    }
    prt(ans);


    return 0;
}



Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL dp[101][100001];
int main(void){
	int n,w;
	int i,j;
	int we,va;
	cin>>n>>w;
	for(i=0;i<=n;i++){
		for(j=0;j<=w;j++){
			dp[i][j]=-1;
		}
	}
	dp[0][0]=0;
	for(i=0;i<n;i++){
		cin>>we>>va;
		for(j=0;j<=w;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+we<=w&&dp[i][j]!=-1){
				dp[i+1][j+we]=max(dp[i+1][j+we],dp[i][j]+va);
			}
		}
	}
	/* for(i=0;i<=n;i++){
		for(j=0;j<=w;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	} */
	LL MAX=-1;
	for(i=0;i<=w;i++){
		MAX=max(dp[n][i],MAX);
	}
	cout<<MAX<<endl;
	return 0;
}
	

Measured memory_bytes: 79104
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
const int N = 2e5 + 10;
const ll inf = 1e18 + 10, mod = 1e9 + 7;

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca_rmq.in", "r", stdin);
    //freopen("lca_rmq.out", "w", stdout);
    int n, ans;
    cin >> n;
    ans += n / 500 * 1000;
    n %= 500;
    cout << ans + n / 5 * 5;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  double prob;
  double sum=0.0;
  double NUM=1.0;
  double DEN;
  if(N>=K){
    for(int i=1;i<K;i++){
      DEN = pow(2, ceil(log2(double(K)/double(i))) ) * N;
      prob = NUM/DEN;
      sum += prob;
    }
    for(int i=K;i<=N;i++){
      DEN = N;
      prob = NUM/DEN;
      sum += prob;
    }

  }else{
    for(int i=1;i<=N;i++){
      DEN = pow(2, ceil(log2(double(K)/double(i))) ) * N;
      prob = NUM/DEN;
      sum += prob;
    }

  }

  cout << fixed << setprecision(10) << sum << endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
from operator import mul
from functools import reduce
 
def nCr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
 
for j in range(K):
  if (K+j)>N:
    print(0)
  else:
    x = (nCr((K-1), j) * nCr(N-K+1, j+1))
    if (x > (10**9+7)):
         print(x%(10**9+7))
    else:
         print(x)

Measured memory_bytes: 3944
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <tuple>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

int main(int argc, char **argv) {
    int n;
    cin >> n;
    std::vector<i64> a(n+1);
    std::vector<i64> b(n);

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

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

    i64 ans{0};
    for (int i=n-1; i>=0; --i) {
        if (b[i] >= a[i+1]) {
            ans += a[i+1];
            b[i] -= a[i+1];
            //cout << "1: " << ans << a[i+1] << endl;
            a[i+1] = 0;
            if (a[i] >= b[i]) {
                ans += b[i];
                a[i] -= b[i];
                //cout << "2: " << ans << " "<<  a[i] << endl;
            } else {
                ans += a[i];
                a[i] = 0;
                //cout << "3: " << ans << endl;
            }
        } else {
            ans += b[i];
            a[i+1] -= b[i];
            //cout << "4: " << ans << endl;
        }
        //cout << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
 
int main() {
    int a,b,c;
    bool bs;
    cin >> a >> b >> c;
 
    bs = b / a - c <= 0;
  
    if (bs) { 
        cout << b / a << endl;
      }
      else{
       cout << c << endl;
      }

}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    for (int i = 0;i < N - 1;i++){
        if (S[i] != S[i + 1]) ans++;
    }
    cout << ans << endl;
}

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

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] A = new int[n][m];
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j){
				A[i][j] = sc.nextInt();
			}
		}
		int[] b = new int[m];
		for(int i = 0; i < m; ++i){
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < n; ++i){
			int ans = 0;
			for(int j = 0; j < m; ++j){
				ans += A[i][j] * b[j];
			}
			System.out.println(ans);
		}
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	private boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


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

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int[] input;
            HashSet<int> point = new HashSet<int>();
            Dictionary<int, int> team = new Dictionary<int, int>();
            while((input = Console.ReadLine().Split(',').Select(q => int.Parse(q)).ToArray())[0] != 0 || input[1] != 0) {
                point.Add(input[1]);
                team.Add(input[0], input[1]);
            }
            List<int> pointList = point.ToList().OrderByDescending(q => q).ToList();
            Dictionary<int,int> rank = new Dictionary<int, int>();
            for(int i=1; i <= pointList.Count; ++i) {
                rank.Add(pointList[i - 1], i);
            }
            string check;
            while((check = Console.ReadLine()) != null){
                Console.WriteLine(rank[team[int.Parse(check)]]);
            }
        }
    }
}

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

int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<vector<int>> vec(Q,vector<int>(2));
  for(int i=0; i<Q; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<int> ac(N);
  int cnt = 0;
  for(int i=0; i<S.size()-1; i++){
    if(S.at(i) == 'A' && S.at(i+1) == 'C'){
      cnt++;
    }
    ac.at(i+1) = cnt;
  }
  
  int ans = 0;
  for(int i=0; i<Q; i++){
    int s = vec.at(i).at(0)-1;
    int t = vec.at(i).at(1)-1;
    ans = ac.at(t) - ac.at(s);
    cout << ans << endl;
    ans = 0;
  }
    
}

Measured memory_bytes: 6784
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


ll n;
ll dp[22][1<<22];
ll a[30][30];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin>>n;
    rep(i,n)rep(j,n){
        cin>>a[i][j];

    }
    dp[0][0]=1;
    rep(bit,(1<<n)){
        ll cnt=0;
        rep(i,n){
            if(bit&(1<<i)) cnt++;
        }
        rep(i,n){
            if(bit&(1<<i)) continue;
            if(a[cnt][i]){
                dp[cnt+1][bit|(1<<i)]+=dp[cnt][bit];
                dp[cnt+1][bit|(1<<i)]%=MOD;
            }
        }
    }
    cout<<dp[n][(1<<n)-1]<<endl;
    return 0;
}

Measured memory_bytes: 323840
print(110943)
X=[10**9,10**9]
for i in range(10000):
  X.append(0)
C=0
def f(f,i,j,k):
  global C
  C+=1
  if f=='<':
    if X[i]<X[j]:
      X[k]=1
    else:
      X[k]=0
    print('<',i,j,k)
  else:
    X[k]=X[i]+X[j]
    print('+',i,j,k)

def g(a,b,r):
  f('+',900,b,300)
  f('<',r,r,r)
  for j in range(58,-1,-1):
    f('+',r,j+2,435)
    f('<',a,435,436)
    f('<',436,300,436)
    for k in range(58):
      f('+',436+k,436+k,437+k)
    f('+',r,436+j,r)

f('<',2,1,2)
f('<',3,0,3)
f('+',2,3,2)
f('<',4,2,2)
for i in range(58):
  f('+',i+2,i+2,i+3)
f('+',63,0,63)
for i in range(29):
  f('+',i+63,i+63,i+64)
for i in range(29,-1,-1):
  f('+',154,i+2,155)
  f('<',1,155,155)
  f('<',155,2,155)
  f('+',900,155,500)
  for j in range(29):
    f('+',500+j,500+j,501+j)
  g(63+i,155,156)
  f('+',500+i,154,154)
  f('+',156,158,158)
f('+',900,158,2)


Measured memory_bytes: 76192
n = int(input())
a = list(map(int,input().split()))
mon = 1000
kab = 0

for i in range(1,n+1):
    if i == 1:
        if a[i-1] < a[i]:
            kab = int(mon/a[i-1])
            mon = mon%a[i-1]

    elif i == n:
        if kab != 0:
            mon += kab * a[n-1]
            kab = 0
    else:
        if a[i-2] < a[i-1]:
            mon += kab * a[i-1]
            kab = 0
        if a[i-1] < a[i]:
            kab = int(mon/a[i-1])
            mon = mon%a[i-1]


print(mon)


Measured memory_bytes: 9092
from math import factorial as f

def comb(n, r):
  return f(n) // (f(r) * f(n-r))

n, a, b = map(int, input().split())
v = list(map(int, input().split()))

v.sort(reverse=True)

print(sum(v[:a])/a)

ans = 0
cnt0 = v.count(v[0])

if cnt0 >= a:
  for i in range(a, min(cnt0, b)+1):
    ans += comb(cnt0, i)
else:
  c = v[a-1]
  cnt1 = 0
  cnt2 = 0
  for i, vi in enumerate(v):
    if vi != c:
      continue
    if i < a:
      cnt1 += 1
    cnt2 += 1
  ans = comb(cnt2, cnt1)

print(ans)


Measured memory_bytes: 3064
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int i = sc.nextInt();

        System.out.println(N-i+1);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

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

template<class T>
using vp = vector<pair<T, T>>;

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

const auto INF = 1e9;
const auto EPS = 1e-9;


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

	int shift = 0;
	while(1 < N)
	{
		N >>= 1;
		shift++;
	}
	int result = 1 << shift;

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
const int inf=1000000000;

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n) cin>>a[i];
  int ans=inf;
  for(int i=1;i<=100;i++){
    int cost=0;
    rep(j,n) cost+=(a[j]-i)*(a[j]-i);
    ans=min(ans,cost);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

signed main(void) {
	int n;
	cin >> n;
	vector<int> d(n);
	REP(i, n)
		cin >> d[i];
	int sum = 0;
	REP(i, n) {
		rep(j, i + 1, n) {
			sum += d[i] * d[j];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n,int r) {
//	n = n + r - 1;
//	return nCr(n,r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI N, A, B;
	cin >> N >> A >> B;
	cout << min(N*A,B) << endl;
}


Measured memory_bytes: 256
import sys
n, m, l = map(int, sys.stdin.readline().split())
d = [[10**15] * (n+1) for _ in range(n+1)]
for i in range(n+1):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, sys.stdin.readline().split())
    if c > l:
        continue
    d[a][b] = c
    d[b][a] = c

q = int(input())
qs = []
for i in range(q):
    s,t = map(int, sys.stdin.readline().split())
    qs.append([s, t])

for k in range(n+1):
    for i in range(n+1):
        for j in range(n+1):
            if d[i][k] + d[k][j] < d[i][j]:
                d[i][j] = d[i][k] + d[k][j]

for i in range(n+1):
    for j in range(n+1):
        if d[i][j] == 0:
            d[i][j] = 0
        elif d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**15
for k in range(n+1):
    for i in range(n+1):
        for j in range(n+1):
            if d[i][k] + d[k][j] < d[i][j]:
                d[i][j] = d[i][k] + d[k][j]
for i in range(q):
    st = qs[i][0]
    gl = qs[i][1]
    if d[st][gl] == 10**15:
        print(-1)
    else:
        print(d[st][gl]-1)



Measured memory_bytes: 63452
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class SegTree {
public:
  int n;
  vector<T> data;
  SegTree(int n_){
    n=1;
    while(n<n_) n*=2;
    data.resize(2*n, INF);
  }
  inline T query(int l, int r){
    T ret = INF;
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1) ret = min(ret, data[l++]);
      if(r&1) ret = min(ret, data[--r]);
    }
    return ret;
  }
  inline void update(int k, T a){
    k+=n;
    data[k]=a;
    while(k>0){
      k = k/2;
      data[k] = min(data[k*2], data[k*2+1]);
    }
  }
};


int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i], vec[i]--;
  vector<int> pos(n);
  rep(i,n) pos[vec[i]] = i;
  SegTree<int> st[2] = SegTree<int>(n);
  rep(i,n){
    st[i%2].update(i, vec[i]);
  }

  vector<int> ans;

  using P = pair<int,int>;
  priority_queue<pair<int,P>, vector<pair<int,P>>, greater<pair<int,P>>> pq;
  pq.push(mp(st[0].query(0,n),mp(0,n)));

  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    int l = p.se.fi, r = p.se.se;
    int p1 = pos[p.fi];
    int p2;
    bool sw = false;
    if((p1-l)%2==0) p2 = st[!(p1%2)].query(p1, r);
    else sw=true,p2 = st[!(p1%2)].query(l, p1);
    p2 = pos[p2];
    st[!(p1%2)].update(p2, INF);
    st[(p1%2)].update(p1, INF);

    if(sw) swap(p1,p2);
    ans.pb(vec[p1]);ans.pb(vec[p2]);

    auto ins = [&](int a, int b){
      if(a==b) return;
      pq.push(mp(st[a%2].query(a,b), mp(a,b)));
    };

    ins(l,p1);
    ins(p1+1,p2);
    ins(p2+1,r);
  }

  rep(i,n) cout << ans[i]+1 << " \n"[i==n-1];

  return 0;
}


Measured memory_bytes: 8616
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key,i,h;
  key=getKey(str);//moji -> suuchi
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}


Measured memory_bytes: 16100
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
    int R[MAX],n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>R[i];

    int maxv=-2000000000;
    int minv=R[0];

    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout<<maxv<<endl;
    return 0;
    }


Measured memory_bytes: 3892
'use strict'
function main(input) {
  input = input.trim().split('')
  let countA = 0
  let countB = 0
  input.forEach((c, i) => {
    if (i % 2 !== Number(c)) countA++;
    if (i % 2 === Number(c)) countB++;
  })
  console.log(Math.min(countA, countB))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9292
($n, $m) = split(' ', <>);

while (<>) {
    ($ai, $bi) = split(' ');

    push(@{$link{$ai}}, $bi);
    push(@{$link{$bi}}, $ai);

}

sub ex {
    my ($p) = @_;
    for (@{$link{$p}}) {
        ($v{$_}) and next;
        return $_;
    }
    return undef;
}

$a = 1;
$v{1}++;
@out = (1);
while ($x = ex($a)) {
    $v{$x}++;
    $a = $x;
    push(@out, $x);
}
$a = 1;
while ($x = ex($a)) {
    $v{$x}++;
    $a = $x;
    unshift(@out, $x);
}
print @out+0, "\n@out\n";

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll d = 100;
    ll X;
    int ans = 0;
    Scll(X);
    while( d < X ){
        d += d/100;
        ans++;
    }

    printf ("%d\n", ans );

    return 0;
}



Measured memory_bytes: 3828
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));

    bool ok = false;
    if (n % 3 != 0){
        if (a[n - 1] == 0) ok = true;
    }else{
        ok = true;
        int m = n / 3;
        int x = a[0], y = a[m], z = a[2*m];
        REP(i,m){
            if (a[i] != x) ok = false;
            if (a[m+i] != y) ok = false;
            if (a[2*m+i] != z) ok = false;
        }
        if (x != (y ^ z) || y != (x ^ z) || z != (x ^ y)) ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 640