akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    Scanner sc = new Scanner(System.in);

    void show(final int[] xs) {
        if(xs != null) {
            String out = 
                Arrays.stream(xs)
                    .mapToObj(Integer::toString)
                    .collect(Collectors.joining(" "));
            System.out.println(out);
        }        
    }

    void solve() {
        // Input
        final int N = sc.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        show(A);

        // Solve
        for(int i = 1; i < N; i++) {
            int v = A[i];
            int j = i - 1;
            while(j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            show(A);
        }

    }

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



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

int main(){

  int n;
  string str;

  while(cin >> n, n){
    int cnt = 0;
    bool next = true;
    bool l = false, r = false;
    for(int i = 0; i < n; i++){
      cin >> str;
      if(str == "lu") l = true;
      if(str == "ru") r = true;
      if(str == "ld") l = false;
      if(str == "rd") r = false;
      if(l == next && r == next){
        cnt++;
        next = !next;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 3132
#!/usr/bin/env python3
import sys

def solve(N: int, A: int, x: "List[int]"):
    ## dp[i][j][k] = i番目までのカードからjマイ選んで合計kにする選び方の総数
    dp = [[[0]*2501 for _ in range(N+1)] for _ in range(N+1)]

    for i in range(N):
        dp[i][0][0] = 1

    for i in range(N):
        for j in range(N):
            for k in range(2501):
                if k-x[i] >= 0:
                    dp[i+1][j+1][k] = dp[i][j][k-x[i]]+dp[i][j+1][k]
                else:
                    dp[i+1][j+1][k] = dp[i][j+1][k]

    answer = 0
    for j in range(1,N+1):
        answer += dp[N][j][A*j]
    print(answer)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 91740
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void){ 
	char c;
	int data[256]={0},i;
	while(1){
		c = getchar();
		//printf("%d",c);
		if(isupper(c)){
			c = tolower(c);
		}
		data[c]++;
		if(c == EOF){
			break;
		}
	}
	for(i = 'a' ; i<='z';i++){
		printf("%c : %d\n",i,data[i]);
	}
	return 0;
}

Measured memory_bytes: 524
n,k=map(int,input().split())
x=[int(i) for i in input().split()]
l,r=[],[]
for i in range(n):
    if x[i]<0 and i+1<n: l.append(abs(x[i]-min(x[i+1],0)))
    elif x[i]<0: l.append(-x[i])
    if x[i]>=0 and i>0: r.append(x[i]-max(0,x[i-1]))
    elif x[i]>=0: r.append(x[i])

l=l[::-1]
l=l[:k]
r=r[:k]

ll=len(l)
rr=len(r)
lx=sum(l)
rx=sum(r)

if ll<k: lx=lx*2+sum(r[:(k-ll)])
if rr<k: rx=rx*2+sum(l[:(k-rr)])
ans=min(lx,rx)
o=[ll,[0,k-ll][ll<k]]
p=[rr,[0,k-rr][rr<k]]


for i in range(1,k):
    if o[1]==0: lx*=2
    if p[1]==0: rx*=2
    if o[1]+1<=rr and o[0]>0:
        lx-=l[o[0]-1]*2
        lx+=r[o[1]]
        o[0]-=1
        o[1]+=1
        ans=min(ans,lx)
    if p[1]+1<=ll and p[0]>0:
        rx-=r[p[0]-1]*2
        rx+=l[p[1]]
        p[0]-=1
        p[1]+=1
        ans=min(ans,rx)
print(ans)


Measured memory_bytes: 14148
#include <bits/stdc++.h>
#define filename "frog"
#define int long long
#define oo 1e9
#define N 200005

using namespace std ;

int n, k ;
int f[N] , a[N] ;
void open()
{
    //freopen(filename".inp","r",stdin) ;
    //freopen(filename".out","w",stdout) ;
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    cout.tie(0) ;
}
void readin()
{
    cin >> n >>k ;
    for (int i = 1 ; i <= n ; i++) cin >> a[i] ;
}
void process()
{
    for (int i = 1 ; i <= n ; i++) f[i] = oo ;
    f[1] = 0 ;
    for (int i = 1 ; i < n ; i++ )
        for (int j = 1 ;j <= k ; j++)
        {
            if (i+j > n) break ;
            int pre = f[i] + abs(a[i] - a[j+i]) ;
            f[i+j] = min(f[i+j] , pre) ;
        }
}
signed main()
{
    open() ;
    readin() ;
    process() ;
    cout << f[n] ;
}

Measured memory_bytes: 5224
# 整数の入力
a = input()
result = -500000

privious_list = ["0", "1"]
#print(len(a))

if len(a) == 1 or 0:
    print(0)
else:
    for x in privious_list:
        new_result = 0
        privious = x
        for i in a:
            if i == "0":
                if privious == "0":
                    new_result += 1
                    privious = "1"
                else:
                    privious = "0"
            else:
                if privious == "0":
                    privious = "1"
                else:
                    new_result += 1
                    privious = "0"
        #print(result, new_result)
        if result == -500000:
            result = new_result
        elif new_result < result:
            result = new_result
    
    if result == -500000:
        result = 0
    print(result)









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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;


int main() {
    ll n, m;
    cin >> n >> m;
    ll x = 0;
    ll y = 0;
    ll a;
    REP(i, n) {
        cin >> a;
        x += (i * a) % MOD - ((n - (i + 1)) * a) % MOD;
        x += MOD;
        x %= MOD;
    }
    REP(i, m) {
        cin >> a;
        y += (i * a) % MOD - ((m - (i + 1)) * a) % MOD;
        y += MOD;
        y %= MOD;
    }
    cout << x * y % MOD << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var x1 = cin.ReadInt;
            var y1 = cin.ReadInt;
            var x2 = cin.ReadInt;
            var y2 = cin.ReadInt;
            var dx = x2 - x1;
            var dy = y2 - y1;
            var x4 = x1 - dy;
            var y4 = y1 + dx;
            var x3 = x2 - dy;
            var y3 = y2 + dx;
            Console.WriteLine(string.Join(" ", x3, y3, x4, y4));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#define SIZ 1400
#define min(a,b) ((a)<(b)?(a):(b))
int A[SIZ][SIZ];
int m[SIZ][SIZ];
int main(){
	int i,j,k,x,y,r,M=0,t=0,z;
	scanf("%d%d",&y,&x);
	for(j=0;j<y;j++)for(i=0;i<x;i++)scanf("%d",A[j]+i);
	for(j=0;j<y;j++)for(r=i=0;i<x;m[j][i]=r,i++)r=A[j][i]==0?r+1:0;
	for(r=i=0;i<x;i++)for(j=0;j<y;j++)for(M=x,k=j;k<y;k++){
		if(M>m[k][i])M=m[k][i];
		int z=k-j+1;
		if(M<z)break;
		if(r<z)r=z;
	}
	printf("%d\n",r*r);
	return 0;
}

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

int main()
{
    int n,i,j;
    double sum=0;
    cin>>n;
    vector<pair<int,int>> v(n);
    for(i=0;i<n;++i)
    {
        cin>>v[i].first>>v[i].second;
    }
    for(i=0;i<n-1;++i)
    {
        for(j=i+1;j<n;++j)
        {
            sum+=sqrt(pow((v[i].first-v[j].first),2)+pow((v[i].second-v[j].second),2));
        }
    }
    sum=(sum/n)*2;
    cout<<fixed<<setprecision(10)<<sum;
    return 0;
}


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

int main() {
  int N, a, b;
  cin >> N;
  
  bool exist = false;
  
  for (int a = 0; a <= N/4+1; ++a) {
    for (int b = 0; b <= N/7+1; ++b) {
      int total = 4*a + 7*b; // 合計金額
      if (total == N) exist = true; // 合計金額が N に一致したら true
    }
  }
  
  if (exist) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,M=map(int,input().split())

# UnionFind

Group = [i for i in range(N)] # グループ分け
Nodes = [1]*(N) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(M):
    A,B=map(int,input().split())
    Union(A-1,B-1)

X=len(set([find(i) for i in range(N)]))

print(X-1)


Measured memory_bytes: 86736
N = int(input())
count = 0

for i in range(N):
    D1, D2 = map(int, input().split())
    if count >= 3:
        break
    if D1 == D2:
        count += 1
    elif D1 != D2:
        count = 0

if count >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9196
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	String s = scan.next();
      	int some = roundup(s.length());
      	char[] ans = new char[some];
      	for (int i = 0; i < some; i++){
       		ans[i] = s.charAt(i * 2);
        }
      	System.out.print(ans);
    }
  	public static int roundup(int x){
      	int ans = 0;
      	if(x % 2 == 0){
        	ans = x / 2;
        }
      	else{
        	ans = x / 2 + 1; 
        }
      	return ans;
    }
}

Measured memory_bytes: 23764
#include<stdio.h>

int main(){
char C[10];
char ch[9][9]={};
int x=0,y=0;
bool f=true;
while(scanf("%s",C)!=EOF){
	bool F=true;
	for(int i=0;i<8;i++)
		{ch[0][i]=C[i];if(ch[0][i]=='1'&&F==true){x=i;y=0;F=false;}
	}
for(int i=1;i<8;i++){
	scanf("%s",C);
for(int j=0;j<9;j++)
{char cc;
	//if(j==8)scanf("%c",&cc);
ch[i][j]=C[j];
if(ch[i][j]=='1'&&F==true){x=j;y=i;F=false;}
if(ch[i][j]==EOF)f=false;}
}

	

if(ch[y][x+1]=='1'&&ch[y+1][x]=='1'&&ch[y+1][x+1]=='1')printf("A\n");

if(ch[y+1][x]=='1'&&ch[y+2][x]=='1'&&ch[y+3][x]=='1')printf("B\n");

if(ch[y][x+1]=='1'&&ch[y][x+2]=='1'&&ch[y][x+3]=='1')printf("C\n");

if(ch[y+2][x-1]=='1'&&ch[y+1][x]=='1')printf("D\n");

if(ch[y][x+1]=='1'&&ch[y+1][x+2]=='1')printf("E\n");

if(ch[y+1][x]=='1'&&ch[y+2][x+1]=='1')printf("F\n");

if(ch[y][x+1]=='1'&&ch[y+1][x-1]=='1')printf("G\n");
/*
if(f==false)break;
}*/
}
return 0;
}

Measured memory_bytes: 948
// [AT2018 バイナリハックイージー / Unhappy Hacking (ABC Edit)] https://www.luogu.org/problem/AT2018
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    cin >> s;

    int a[15];
    int x = 0;

    int slen = s.length();
    for (int i = 0; i < slen; i++)
    {
        if (s[i] == '0') 
        {
            a[x++] = 0;
        } else if (s[i] == '1') {
            a[x++] = 1;
        } else {
            if (x > 0) x--;
        }
    }

    for (int i = 0; i < x; i++)
        cout << a[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;


int main(void)
{

	char a[200][200];
	int i, j;


	int h, w;
	int width, high;



	cin >> h >> w;

	width = w + 2;
	high = h + 2;

	for (i = 1; i <= h; i++) {
	
		for (j = 1; j <= w; j++) {
		
			cin >> a[i][j];
		
		}

	
	}

	
	for (i = 0; i < high; i++) {
		
		a[i][0] = '#';
		
		a[i][width] = '#';

	
	}

	for (i = 1; i < width; i++) {
		
		a[0][i] = '#';
		
		a[high][i] = '#';

	}


	for (i = 0; i < high-1; i++) {
			
		for (j = 0; j < width-1; j++) {
				
			printf("%c", a[i][j]);
			if (j == width - 2) {
				printf("#");
			}

	
		}
		printf("\n");



	}

	for (i = 0; i < width; i++) {
		printf("#");
	}

	printf("\n");

	
	return (0);
}


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

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

	int ans = 1;
	rep(i, n)
	{
		if (ans * 2 - ans <= k)
			ans *= 2;
		else
			ans += k;
	}
	cout << ans << endl;
	return (0);
}


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

using namespace std;

string s, t;
vector<vector<int>> dp(3001, vector<int>(3001));
vector<vector<int>> vist(3001, vector<int>(3001));

int bs(int i, int j)
{
    if(i >= s.length() || j >= t.length())
        return 0;


    if(vist[i][j])
        return dp[i][j];

    vist[i][j] = 1;

    if(s[i] == t[j])
        return dp[i][j] = 1 + bs(i + 1, j + 1);
    else {
        int ans = max(bs(i+1, j), bs(i, j+ 1));
        return dp[i][j] = ans;
    }
}

void a()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}

int main()
{
    a();

    string ans = "";
    cin >> s >> t;
    bs(0, 0);
    int i = 0, j = 0;

    while(i < s.length() && j < t.length()){
        if(s[i] == t[j]){
            ans += s[i];
            i++;
            j++;
        }
        else{
            if(dp[i+1][j] > dp[i][j+1]){
                i++;
            } else {
                j++;
            }
        }
    }

    cout << ans;
}


Measured memory_bytes: 74512
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n;
cin>>n;
bool flag=false;
for(ll i=1;i<=9;i++)
{
    for(ll j=1;j<=9;j++)
    {
        if(i*j==n)
        {
            flag=true;
        }
    }
}
if(flag)
{
    cout<<"Yes"<<endl;
}else
{
    cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int D;
  cin >> D;
  cout << "Christmas";
  if(D<25){
    cout << " Eve";
  }
   if(D<24){
    cout << " Eve";
  }
   if(D<23){
    cout << " Eve";
  }
   cout <<endl;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split(' ').map(&:to_i)

allrain = A.inject(:+)

x = Array.new
otherrain = 0
(N/2).times do |i|
	otherrain += A[(1+i*2)%N]*2
end
x[0] = allrain - otherrain

(1..N-1).each do |i|
	x[i] = 2*A[i-1] - x[i-1]
end

N.times do |i|
	print x[i].to_s + " "
end

Measured memory_bytes: 13004
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
using namespace std;
int main()
{
	char s[20];
	for(int i=0;i<19;i++)
	  cin>>s[i];
	for(int i=0;i<19;i++)
	  {
	  	if(s[i]==',')
	  	 s[i]=' ';
	  	
	  }
	  for(int i=0;i<19;i++)
	  cout<<s[i];
	 
	  cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{ 
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int num = Integer.valueOf(br.readLine());
        String[] preData = br.readLine().split(" " , num);
        int[] data = new int[num];

        for(int i = 0; i < num; i++) data[i] = Integer.parseInt(preData[i]);

        int max = data[0];

        for(int i = 1; i < num; i++){
            if(data[i] > max)   max = data[i];
        }

        int times = 0;
        int lcd = 0;

        while(true){
            times++;
            lcd = max * times;
            boolean isLCD = true;
            
            for(int i = 0; i < num; i++){
                if(lcd % data[i] != 0) isLCD = false;
            }

            if(isLCD){
                break;
            }
        }

        System.out.println(lcd);
    }
}

Measured memory_bytes: 25260
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> p;
    vector<bool> p_check(55556,true);
    for(int i = 2; i <= 55555; i++) {
        if(p_check.at(i)) {
            for(int j = i*2; j <= 55555; j += i) p_check.at(j) = false;
        }
    }
    for(int i = 2; i <= 55555; i++) {
        if(p_check.at(i)) p.push_back(i);
    }
    
    int N;
    cin >> N;
    int i = 1, j = 0;
    while(i<=N) {
        if(p.at(j)%5==1) {
            cout << p.at(j);
            if(i==N) cout << endl;
            else cout << " ";
            i++;
        }
        j++;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int sweets;
	int info[1000][4] = {0};
	int limit[4];
	int cal, ok;
	int i;
	
	while(1){
		ok = 0;
		
		scanf("%d", &sweets);
		if(sweets == 0)    break;
		for(i = 0; i < sweets; i++){
			scanf("%d %d %d %d", &info[i][0], &info[i][1], &info[i][2], &info[i][3]);
		}
		scanf("%d %d %d %d", &limit[0], &limit[1], &limit[2], &limit[3]);
		
		for(i = 0; i < sweets; i++){
			cal = (info[i][1] * 4) + (info[i][2] * 9) + (info[i][3] * 4);
			
			if (info[i][1] <= limit[0] && info[i][2] <= limit[1] &&
				info[i][3] <= limit[2] && cal <= limit[3]){
				printf("%d\n", info[i][0]);
				ok++;
				}
		}
		if(ok == 0)    printf("NA\n");
	}
	
	return 0;
}

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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  int as[3] = {a1, a2, a3};
  sort(as, as + 3);

  cout << as[2] - as[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    ll ans = 0;
    if (a[0] >= 2) {
        ans += a[0] - 1;
        a[0] = 1;
    }
    int M = 0;
    REP(i, 0, n) {
        ans += (a[i] - 1) / (M + 1);
        if (M + 1 == a[i]) {
            M++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    string s;
    cin >> s;
    int Q;
    cin >> Q;
    deque<char> que;
    int front = 1;
    for (auto c : s) {
        que.push_back(c);
    }
    rep(i, 0, Q) {
        int q;
        cin >> q;
        if (q == 1) {
            front ^= 1;
        } else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (f == 1) {
                if (front)
                    que.push_front(c);
                else
                    que.push_back(c);
            } else {
                if (front)
                    que.push_back(c);
                else
                    que.push_front(c);
            }
        }
    }
    string ans = "";
    for_each(all(que), [&](char c) {
        ans += c;
    });
    if (!front) reverse(all(ans));
    cout << ans << "\n";
}


Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define al(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define IOS ios::sync_with_stdio(0);

int main() {
	int n;
	cin >> n;
	int x, ans = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &x);
		if (i & 1 && x & 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int X, Y;
int p = 1000000007;
ll fact[1000005];

ll inverse(ll base){
    int e = p-2;
    ll res = 1;
    while (e > 0){
        if (e & 1) res = (res*base)%p;
        base = (base*base) % p;
        e /= 2;
    }
    return res;
}

ll comb(int n, int r){
    // returns nCr mod p
    fact[0] = 1;
    for (int i=1; i<=n; i++) fact[i] = (i*fact[i-1])%p;
    return fact[n] * inverse(fact[r]) % p * inverse(fact[n-r]) % p;
}

int main() {
    cin >> X >> Y;
    int a, b;
    a = (2*Y-X)/3;
    b = (2*X-Y)/3;
    if (a >= 0 && b >= 0 && 3*a == 2*Y-X && 3*b == 2*X-Y){
        cout << comb(a+b, a) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() 
{
    int N; cin >> N;
    vector<int> L(2*N); for (auto &l : L) cin >> l;
    sort(begin(L), end(L));
    int sum = 0;
    for (int i = 0; i < 2*N; i+=2) {
        sum += L[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 20:13:03 2019

@author: avina
"""

n,k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))
l.sort()
i = 0
mins = 1e10
while i < n - k +1:
  mins = min(mins, l[i+k-1] - l[i])
  i+=1
print(mins)

Measured memory_bytes: 7508
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int n;
    cin>>n;
    int k;
    cin>>k;
    vec a(k);
    rep(i,k) cin>>a[i];
    for(int i=0;i<(1<<k);i++){
        int cnt=0;
        for(int j=0;j<n;j++){
            for(int m=0;m<k;m++){
                if((i>>m&1)&&a[m]==j) cnt+=(int)pow(2,a[m]);
            }
        }
        cout<<cnt<<':';
        for(int j=0;j<k;j++){
            if(i>>j&1) cout<<' '<<a[j];
        }
        cout<<endl;
    }
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

ll N, A, B;
vl h;

bool C(ll t)
{
    ll count = 0;
    vi x(N); REP(i, N) x[i] = max(h[i] - B*t, 0LL);
    REP(i, N)
    {
        count += (x[i]+A-B-1)/(A-B);
    }
    return count <= t;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> N >> A >> B;
    h.resize(N); REP(i, N) cin >> h[i];
    ll l = 0, r = 1e9;
    while(r - l > 1)
    {
        ll mid = (l+r) / 2;
        if(C(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

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

int main(){
    int k;
    cin >> k;
    int 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), c);
            }
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<long long> A(N), B(N+1, 0);
    for(int i=0; i<N; i++)
        cin >> A[i];
    for(int i=1; i<=N; i++)
        B[i] = A[i-1] + B[i-1];
    map<long long, int> mp;
    for(int i=0; i<=N; i++)
        mp[B[i]]++;

    long long ans = 0;
    for(auto x : mp){
        long long tmp = x.second;
        ans += tmp*(tmp-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i,j;
  string s;
  string t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();

  
  int diff = 0;
  int ans = m;
  
  for(i = 0; i <= n-m;i++){
    int diff = 0;
    for(j = 0; j < m;j++){
      
        if(s.at(i+j) != t.at(j)){
            diff++;
            
          }

        
    }
    ans = min(ans,diff);
    
  }
  
  
  cout << ans;
      

  
  
    
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int a=(n-1)/2-1;
    for(int i=0;i<a;i++){
        if(s[i]!=s[a]){
            cout<<"No"<<endl;
            return 0;
        }
        a--;
    }
    int b=(n+3)/2-1,c=n-1;
    for(int i=b;i<c;i++){
        if(s[i]!=s[c]){
            cout<<"No"<<endl;
            return 0;
        }
        c--;
    }
    c=n-1;
    for(int i=0;i<c;i++){
        if(s[i]!=s[c]){
            cout<<"No"<<endl;
            return 0;
        }
        c--;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
X = [int(i) for i in input().split()]
sX = sorted(X)
r,l = sX[n//2],sX[n//2-1]
if r != l:
    for x in X:
        if x<=l: print(r)
        else: print(l)
else:
    for _ in range(n): print(l)


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

int main(){
  int N;
  cin >> N;
  int t[N+1], x[N+1], y[N+1];
  t[0] = 0, x[0] = 0, y[0] = 0;
  for(int i = 1; i <= N; i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  bool can = true;
  for(int i = 0; i < N; i++){
    int dt = t[i+1] - t[i];
    int dx = abs(x[i+1] - x[i]);
    int dy = abs(y[i+1] - y[i]);
    if((dx + dy > dt) || ((dt - dx - dy) %2 != 0)) {
      can = false;
      break;
    }
  }
  if(can){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int l[q];
  int r[q];
  int t[n] = {};
  int tmp = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      s[i] = 'a';
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a') {
      tmp++;
      t[i] = tmp;
    } else {
      t[i] = tmp;
    }
    //cout << t[i] << endl;
  }
  for (int i = 0; i < q; i++) {
    cout << t[r[i] - 2] - t[l[i] - 2] << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
 
  int N,K; cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }

  vector<double> ex(200010);
  //期待値をexに格納
  double s = 0.0;
  // s = 初めのK個の和
  for(int l = 0; l < K; l++){
    s += p.at(l);
  }
  //i番目からK個で期待値を計算
  for(int i = 0; i < N-K+1; i++){
    if(i != 0){
      s -= p.at(i-1);
      s += p.at(i+K-1);
    }
    ex.at(i) = (s+K)/2.0;
  }
  
  sort(ex.begin(), ex.end());
  reverse(ex.begin(), ex.end());
  cout << fixed << setprecision(10);
  cout << ex.at(0) << endl;
}

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = 1LL<<60;
    ans *= -1;
    // cout << ans << endl;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);

    cout << ans << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 3652
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse = True)

def solve(n):
    cnt = 0
    for i in range(N):
        cnt += max(0, A[i] - n // F[i])
    return cnt <= K

left = -1
right = 10 ** 12 + 1

while left + 1 < right:
    mid = (left + right) // 2
    if solve(mid):
        right = mid
    else:
        left = mid

print(right)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<pair<int,int>> E[101010];
int vis[101010];
ll D[101010];

void dfs(int cur, ll S) {
	
	if(vis[cur]==1) {
		if(D[cur]!=S) {
			_P("No\n");
			exit(0);
		}
		return;
	}
	vis[cur]=1;
	D[cur]=S;
	FORR(e,E[cur]) dfs(e.first,S+e.second);
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>j;
		x--,y--;
		E[x].push_back({y,j});
		E[y].push_back({x,-j});
	}
	
	FOR(i,N) if(vis[i]==0) dfs(i,0);
	_P("Yes\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007


int main() {
	int n,sum=0,MIN=1<<30;
	cin>>n;
	for(int i=0;i<n;i++){
		int z;
		cin>>z;
		sum+=z;
		if(z%10!=0){
			MIN=min(z,MIN);
		}
	}
	if(sum%10!=0){
		cout<<sum;
		return 0;
	}
	if(MIN>1000000){
		cout << 0;
		return 0;
	}
	sum=sum-MIN;
	cout <<sum;
}

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll cnt[10][10];
int main() {
	cin >> N;
	rep(i, 9) {
		rep(j, 9) {
			cnt[i][j] = 0;
		}
	}
	for (int i = 1; i <= N; i++) {
		cnt[i % 10][to_string(i)[0] - '0']++;
	}
	ll sum = 0;
	rep(i, 10) {
		rep(j, 10) {
			sum += cnt[i][j] * cnt[j][i];
		}
	}
	cout << sum;
}


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

int main() {
  int r, c;
  cin >> r >> c;
  int i, j;
  vector<vector<int>> vec(r, vector<int>(c));
  for (i = 0; i < vec.size(); i++) {
    for (j = 0; j < vec.at(0).size(); j++) {
      cin >> vec.at(i).at(j);
      // cout << vec.at(i).at(j) << " ";
    }
    // cout << endl;
  }
  int sum = 0;
  for (i = 0; i < vec.size(); i++) {
    int sumW = 0;
    for (j = 0; j < vec.at(0).size(); j++) {
      cout << vec.at(i).at(j) << " ";
      sumW += vec.at(i).at(j);
    }
    cout << sumW << endl;
  }
  for (i = 0; i < vec.at(0).size(); i++) {
    int sumH = 0;
    for (j = 0; j < vec.size(); j++) {
      sumH += vec.at(j).at(i);
    }
    sum += sumH;
    cout << sumH << " ";
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3172
using System;

namespace _20190629_ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split(' ');
            int x = 0;

            for (int i = 0; i < n - 2; i++)
            {
                var pi = int.Parse(p[i]);
                var pi1 = int.Parse(p[i + 1]);
                var pi2 = int.Parse(p[i + 2]);

                if (pi < pi1 && pi1 < pi2 || pi2 < pi1 && pi1 < pi)
                {
                    x++;
                }
            }
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 13140
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;

int main()
{
	list<int> v;

	int n;
	for (cin >> n; n--;)
	{
		char c[20];
		int x;
		scanf("%s", c);

		string s = c;

		if (s == "insert")
		{
			scanf("%d", &x);
			v.push_front(x);
		}
		else if (s == "delete")
		{
			scanf("%d", &x);
			for (list<int>::iterator it = v.begin(); it != v.end(); it++)
			{
				if (*it == x)
				{
					v.erase(it);
					break;
				}
			}
		}
		else if (s == "deleteFirst")
		{
			v.pop_front();
		}
		else if (s == "deleteLast")
		{
			v.pop_back();
		}
	}

	bool space = false;
	for (list<int>::iterator it = v.begin(); it != v.end(); it++)
	{
		cout << (space ? " " : "");
		space = true;

		cout << *it;
	}

	cout << endl;
}


Measured memory_bytes: 34420
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[]T = new long[N];
		for(int i = 0; i < N; i++) {
			T[i] = sc.nextLong();
		}
		sc.close();
		if(N == 1) {
			System.out.println(T[0]);
			System.exit(0);
		}
		long l = lcm(T[0], T[1]);
		for(int i = 1; i < N; i++) {
			l = lcm(l, T[i]);
		}
		System.out.println(l);
	}
	static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
		if(n == 0) return m;
		return gcd(n, m % n);
	}
	static long lcm(long n, long m) {
		return n / gcd(n, m) * m;
	}
}

Measured memory_bytes: 25172
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
	int dp[2][201][10001];
int main() {

	
	int N, W; cin >> N >> W;
	vector<int>ws(N);
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		ws[i] = a;
	}
	if (*min_element(ws.begin(), ws.end())>W) {
		cout << 1 << endl;
		return 0;
	}
	if (accumulate(ws.begin(), ws.end(), 0) <= W) {
		cout << 1 << endl;
		return 0;
	}
	sort(ws.begin(), ws.end(),greater<int>());
	for (int f = 0; f < 201; ++f) {
		for (int j = 0; j < 10001; ++j) {
			dp[0][f][j] = 0;
		}
	}
	dp[0][200][0] = 1;

	int tar, cur;
	for (int i = 0; i < N; ++i) {
		tar = i & 1; cur = tar ^ 1;
		if (i == 0)assert(tar == 0 && cur == 1);
		for (int f = 0; f < 201; ++f) {
			for (int j = 0; j < 10001; ++j) {
				dp[cur][f][j] = 0;
				dp[tar][f][j] %= 1000000007;
			}
		}
		for (int f= 0; f< i; ++f) {
			for (int w = 0; w < 10001; ++w) {
				int nextw = w + ws[i];
				if (nextw <= W) {
					dp[cur][f][nextw] += dp[tar][f][w];
				}
				{
					dp[cur][i][w] += dp[tar][f][w];
				}
			}
		}
		{
			int f = 200;
			{
				for (int w = 0; w < 10001; ++w) {
					int nextw = w + ws[i];
					if (nextw <= W) {
						dp[cur][f][nextw] += dp[tar][f][w];
					}
					{
						dp[cur][i][w] += dp[tar][f][w];
					}
				}
			}
		}
	}
	long long int ans = 0;
	for (int f = 0; f < N; ++f) {
		for (int j = max(0,W-ws[f]+1); j <=W; ++j) {
			ans += dp[cur][f][j];
		}
	}
	cout << ans% 1000000007 << endl;
	return 0;
}
//
//int N, W; cin >> N >> W;
//vector<int>ws(N);
//for (int i = 0; i < N; ++i) {
//	int a; cin >> a;
//	ws[i] = a;
//}
//int dp[2][10001];

Measured memory_bytes: 18856
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int max = 0;
    int min = 123;
    int input;
    for(int i = 0; i < 5; i++){
      input = sc.nextByte();
      max = Math.max(max,input);
      min = Math.min(min,input);
    }
    int k = sc.nextByte();
    if(k >= max - min){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 22612
/* ITP1_10_C: Distance 2 */

#include <iostream>
#include <iomanip>
#include <cmath>

double minkowski_distance(int p, int n, int vx[], int vy[]) {
    double d = 0;
    for (int i = 0; i < n; i++) {
        int abs = std::abs( vx[i] - vy[i] );
        d += std::pow((double)abs, p);
    }
    // calculate the `p`th root of the `d`.
    return std::pow(d, 1.0 / p);
}

double chebyshev_distance(int n, int vx[], int vy[]) {
    double d = 0;
    for (int i = 0; i < n; i++) {
        int abs = std::abs( vx[i] - vy[i] );
        if (d < abs) d = abs;
    }
    return d;
}

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    int vx[n];
    for (int i = 0; i < n; i++)
        std::cin >> vx[i];

    int vy[n];
    for (int i = 0; i < n; i++)
        std::cin >> vy[i];

    std::cout
        << std::fixed << std::setprecision(6)
        << minkowski_distance(1, n, vx, vy) << "\n"
        << minkowski_distance(2, n, vx, vy) << "\n"
        << minkowski_distance(3, n, vx, vy) << "\n"
        << chebyshev_distance(n, vx, vy) << "\n";

    return 0;
}

Measured memory_bytes: 1324
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

var sc = newScanner()

func main() {
	n := scanInt()

	var min, res int
	res = math.MinInt32
	for i := 0; i < n; i++ {
		r := scanInt()
		if i == 0 {
			min = r
		} else {
			if r-min > res {
				res = r - min
			}
			if min > r {
				min = r
			}
		}
	}
	fmt.Println(res)
}



Measured memory_bytes: 4132
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
     
        if(N<=9){
            System.out.println("Yes");
        }else if(N<=18 && N%2==0){
            System.out.println("Yes");
        }else if(N<=27 && N%3==0){
            System.out.println("Yes");
        }else if(N<=36 && N%4==0){
            System.out.println("Yes");
        }else if(N<=45 && N%5==0){
            System.out.println("Yes");
        }else if(N<=54 && N%6==0){
            System.out.println("Yes");
        }else if(N<=63 && N%7==0){
            System.out.println("Yes");
        }else if(N<=72 && N%8==0){
            System.out.println("Yes");
        }else if(N<=81 && N%9==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");        
        }
	}
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  int cnt_4 = 0;
  int cnt_1 = 0;
  int cnt_2 = 0;
  rep(i, n){
    if(a[i] % 4 == 0){
      cnt_4++;
    }else if(a[i] % 2 == 0){
      cnt_2++;
    }
    if(a[i] % 2 != 0){
      cnt_1++;
    }
  }

  if(cnt_2 == 0){
    if(cnt_4 > 0 && cnt_1 - cnt_4 < 2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(cnt_4 >= cnt_1){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

  return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

map<ll, ll> d;
int flag[2500];
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        rep(edges[v.second].size()){
            Pll e = edges[v.second][i];
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                flag[e.first] = 1;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}


int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int h,w;
    cin >> h >> w;
    
    string field[h];
    int sharp = 0;
    rep(h){
        cin >> field[i];
        repp(j, w){
            if(field[i][j] == '#'){
                sharp++;
                continue;
            }
        }
    }

    rep(h)repp(j, w){
        if(j != 0 && field[i][j-1] == '.'){
            edges[w*i+j-1].emplace_back(w*i+j, 1);
            edges[w*i+j].emplace_back(w*i+j-1, 1);
        }
        if(i != 0 && field[i-1][j] == '.'){
            edges[w*(i-1)+j].emplace_back(w*i+j, 1);
            edges[w*i+j].emplace_back(w*(i-1)+j, 1);
        }
    }
    dijkstra(0);
    if(flag[w*h-1]) cout << h*w - d[w*h-1] - 1 - sharp << endl;
    else cout << -1 << endl;

}


Measured memory_bytes: 768
import java.util.*;

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

      int n = sc.nextInt();
      int half=n/2;
      int cnt=0;

      int[] d = new int[n];

      for(int i=0;i<n;i++){
        d[i] = sc.nextInt();
      }

      Arrays.sort(d);

      for(int i=d[half-1]+1;i<=d[half];i++){
        cnt++;
      }


      System.out.println(cnt);

    }
}


Measured memory_bytes: 49856
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  if(s[0]==s[s.size()-1] && (int)s.size()%2){
    cout<<"Second"<<endl;
    return 0;
  }
  if(s[0]!=s[s.size()-1] && (int)s.size()%2==0){
    cout<<"Second"<<endl;
    return 0;
  }
  cout<<"First"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> h(n);
    REP(i,n) cin >> h[i];
    ll ans = 0;
    while(true){
        if (*max_element(h.begin(), h.end()) == 0) break;
        REP(i,n) {
            if (h[i] == 0) continue;
            for (int j = i; j < n; ++j) {
                if (h[j] == 0) break;
                h[j]--;
            }
            break;
        }
        ans++;
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        for (int i = 1; ; i++) {
            int x = sc.nextInt();

            if (x == 0) {
                break;
            }

            System.out.printf("Case %d: %d\n", i, x);
        }
    }
}



Measured memory_bytes: 66964