akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final int MAX = 2500;
	
	public static final int INF = Integer.MAX_VALUE / 2 - 1;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[][] DP = new int[MAX][MAX];
		byte[][] pos_x = new byte[MAX][MAX];
		byte[][] pos_y = new byte[MAX][MAX];
		short[] nodes = new short[MAX];
		
		while(true){
			final byte w = sc.nextByte();
			final byte h = sc.nextByte();
			
			if(w == 0 && h == 0){
				break;
			}
			
			short max_node = 0;
			Arrays.fill(nodes, (short)(0));
			
			byte s_x = -1, s_y = -1, g_x = -1, g_y = -1;
			
			for(byte i = 0; i < h; i++){
				for(byte j = 0; j < w; j++){
					String input = sc.next();
					
					if("S".equals(input)){
						s_x = j;
						s_y = i;
					}else if("G".equals(input)){
						g_x = j;
						g_y = i;
					}else if(!".".equals(input)){
						final short number = Short.parseShort(input);
						
						pos_x[number][nodes[number]] = j;
						pos_y[number][nodes[number]] = i;
						nodes[number]++;
						
						max_node = (short) Math.max(max_node, number);
					}
				}
			}
			
			final int goal_node = max_node + 1;
			
			nodes[0] = 1;
			pos_x[0][0] = s_x;
			pos_y[0][0] = s_y;
			
			nodes[goal_node] = 1;
			pos_x[goal_node][0] = g_x;
			pos_y[goal_node][0] = g_y;
			
			
			for(int i = 1; i <= goal_node; i++){
				for(int j = 0; j < nodes[i]; j++){
					DP[i][j] = Integer.MAX_VALUE;
				}
			}
			DP[0][0] = 0;
			
			for(int cur_node = 0; cur_node < goal_node; cur_node++){
				final int next_node = cur_node + 1;
				
				for(int from = 0; from < nodes[cur_node]; from++){
					final int from_x = pos_x[cur_node][from];
					final int from_y = pos_y[cur_node][from];
					
					for(int to = 0; to < nodes[next_node]; to++){
						final int to_x = pos_x[next_node][to];
						final int to_y = pos_y[next_node][to];
						
						int cost = Math.abs(from_x - to_x) + Math.abs(from_y - to_y);
						
						DP[next_node][to] = Math.min(DP[next_node][to], DP[cur_node][from] + cost);
					}
				}
			}
			
			System.out.println(DP[goal_node][0]);
			
		}
	}

}

Measured memory_bytes: 95380
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main(){
    ll A , B , C;
    cin >> A >> B >> C;
    if(A % 2 == 1 && B % 2 == 1 && C % 2 == 1){
        cout << min({A * B , A * C , B * C}) << endl;
    }
    else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

struct edge{int from,to,cost;};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,p;
	cin>>n>>m>>p;
	vector<edge> g(m);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		g[i]={a,b,p-c};
	}
	vector<int> dist(n,INF);
	dist[0]=0;
	rep(i,n){
		rep(j,m){
			edge now=g[j];
			if(dist[now.from]!=INF && dist[now.to]>dist[now.from]+now.cost){
				dist[now.to]=dist[now.from]+now.cost;
			}
		}
	}
	vector<bool> negative(n,false);
	rep(i,n){
		rep(j,m){
			edge now=g[j];
			if(dist[now.to]!=INF && dist[now.to]>dist[now.from]+now.cost){
				dist[now.to]=dist[now.from]+now.cost;
				negative[now.to]=true;
			}
			if(negative[now.from]) negative[now.to]=true;
		}
	}
	if(negative[n-1]) cout<<-1<<endl;
	else cout<<max(0,-dist[n-1])<<endl;
}

Measured memory_bytes: 384
N = gets.to_i
W = gets.split.map(&:to_i)
sum = []
(1..N).each do|i|
  w1 = W.slice(0, i)
  w2 = W.slice(i, W.length-i)
  sum << (w1.inject(:+).to_i - w2.inject(:+).to_i).abs
end
p sum.min

Measured memory_bytes: 1788
#include <stdio.h>
int main(void){
  int a,b;
  char op;
  scanf("%d %c %d", &a, &op, &b);
  if(op=='+') printf("%d\n",a+b);
  else printf("%d\n",a-b);
  return 0;
}
//scanfを小分けにするとできなくなる//

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int a,b,c;
    cin >> a >> b >> c;

    if (a+b >= c) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a,b;
   int x,y;
   cin >> a >> b;
   int ans = -1;


   for (int i=1; i<100000; i++){
       x = i*0.08;
       y = i*0.1;
       if (x == a && y == b){
           ans = i;
           break;
       }
       
   }
   cout << ans << endl;
   
   
}

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

int main() {
  ll a,b,n,ans,x;
  cin>>a>>b>>n;
  x=min(b-1,n);
  ans=a*x/b-a*(x/b);
  cout<<ans<<endl;
}


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

int main(){
    int n;
    while(cin >> n && n > 0){
        int left = 1, right = 2, ans = 0, sum = 1;
        while(n > left){
            if(n > sum){
                sum += right;
                right++;
            }
            else if(n < sum){
                sum -= left;
                left++;
            }
            else{
                ans++;
                sum -= left;
                left++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 2984
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	int pos = 0, neg = 0;
	vi ps, ng;
	rep(i, n){
		if(a[i] >= 0) pos++, ps.pb(i);
		else neg++, ng.pb(i);
	}
	int only = 1;
	if(pos && neg) only = 0;
	vector<pi> ans;
	if(only){
		if(pos){
			//keep subtracting from the lowest?
			sort(all(a));
			repn(i, 1, n - 1){
				ans.pb(mp(a[0], a[i]));
				a[0] -= a[i];
			}
			ans.pb(mp(a[n - 1], a[0]));
			a[n - 1] -= a[0];
			cout << a[n - 1] << endl;
			rep(i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
		}
		else{
			//keep adding to the lowest ig
			sort(all(a));
			reverse(all(a));
			repn(i, 1, n){
				ans.pb(mp(a[0], a[i]));
				a[0] -= a[i];
			}
			cout << a[0] << endl;
			rep(i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
		}
	}
	else{
		int pos1 = ps[0];
		int neg1 = ng[0];
		rep(i, n) if(i != pos1 && i != neg1){
			if(a[i] >= 0){
				ans.pb(mp(a[neg1], a[i]));
				a[neg1] -= a[i];
			}
			else{
				ans.pb(mp(a[pos1], a[i]));
				a[pos1] -= a[i];
			}
		}
		ans.pb(mp(a[pos1], a[neg1]));
		cout << a[pos1] - a[neg1] << endl;
		rep(i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3828
N, M, X = list(map(int, input().split()))
A = []
for i in range(N):
    s = list(map(int, input().split()))
    t = [s[j] for j in range(1, M+1)]
    A.append([s[0], t])
# print(A)

# 下からj番目のbitが1->本jを買う
# B[i]がすべてX以上になればOK
ans = []
for i in range(2**N):
    price = 0
    B = [0]*M
    for j in range(N):
        if (i >> j) & 1:
            price += A[j][0]
            for k in range(M):
                B[k] += A[j][1][k]
    # print(i,[B[k]for k in range(M)])
    for k in range(M):
        if B[k] < X:
            break
    else:
        ans.append(price)

if ans == []:
    print(-1)
else:
    # print(ans)
    print(min(ans))


Measured memory_bytes: 74200
#include<iostream>

using namespace std;

//  A_n - A_(n-1) = n 
main(){
  int n;
  
  while(cin >> n){
    int out =2;
    
    for(int j=2;j<=n;j++){
      
      out += j;
      
    }
    cout << out << endl;
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){

   int i,a;
   int x,y,z,w;
  
  /*  scanf("%d",&a);
   x=a/1000;y=(a-x*1000)/100;z=(a-x*1000-y*100)/10;
   w=(a-x*1000-y*100-z*10);
  if(x==y||y==z||z==w)*/    //改良型
  int b[4];
  for(i=0;i<4;i++)
    b[i]=getchar();

  if(b[0]==b[1]||b[1]==b[2]||b[2]==b[3])
    printf("Bad");
  else
    printf("Good");

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,d[200004],K,cnt[200004];
int main(){
	cin>>n>>K;
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=1;i<=K;i++){
		bool isfull=1;
		for(int i=1;i<=n;cnt[i]=0,i++)if(d[i]!=n)isfull=0;
		if(isfull)break;
		for(int i=1;i<=n;i++)cnt[max(1,i-d[i])]++,cnt[min(n+1,i+d[i]+1)]--;
		int now=0;
		for(int i=1;i<=n;i++)now+=cnt[i],d[i]=now;
	}
	for(int i=1;i<=n;i++)cout<<d[i]<<" ";
}

Measured memory_bytes: 5180
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, x, t = LI()
print(math.ceil(n/x)*t)

Measured memory_bytes: 65304
# https://atcoder.jp/contests/abc157/tasks/abc157_b


Ass = Array.new(3) { gets.split.map(&:to_i) }
N = gets.to_i
bs = Array.new(N) { gets.to_i }

cond = Array.new(3) {Array.new(3) {false}}


N.times do |k|
  3.times do |i|
    3.times do |j|
      cond[i][j] = true if bs[k] == Ass[i][j]
    end
  end
end

def checkBingo(cond)
  3.times do |i|
    ans ||= (cond[i][0] && cond[i][1] && cond[i][2])
    return ans if ans
    ans ||= (cond[0][i] && cond[1][i] && cond[2][i])
    return ans if ans
  end

  ans ||= (cond[0][0] && cond[1][1] && cond[2][2])
  return ans if ans
  ans ||= (cond[0][2] && cond[1][1] && cond[2][0])
  return ans if ans
end

ans = checkBingo(cond)

puts ans ? 'Yes' : 'No'


Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int a, p;
  cin >> a >> p;
  cout << (a * 3 + p) / 2 << 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);
		int x1 = Integer.parseInt(sc.next());
		int y1 = Integer.parseInt(sc.next());
		int x2 = Integer.parseInt(sc.next());
		int y2 = Integer.parseInt(sc.next());
		sc.close();
 
		int x = x2 - x1;
		int y = y2 - y1;
 
		System.out.print(x2 - y + " ");
		System.out.print(y2 + x + " ");
		System.out.print(x2 - y - x + " ");
		System.out.println(y2 + x - y);
	}
 
}

Measured memory_bytes: 22996
#include<stdio.h>

 int a[200010];
 int ans[200010];

int main(){
  int N;
  scanf("%d",&N);
  
  for(int i=2;i<=N;i++)scanf("%d",&a[i]);
  for(int i=2;i<=N;i++)ans[a[i]]++;
  for(int i=1;i<=N;i++)printf("%d\n",ans[i]);

  
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
#define pi 3.1415926535
#define doubl long double
int main(){
    
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    doubl x=(doubl)h*(doubl)30.0;
    doubl y=(doubl)m*(doubl)6.0;
    x+=((doubl)m*(doubl)0.5);
    doubl ang=abs(y-x);
	doubl rd=(ang*(doubl)pi);
	rd=(doubl)(rd)/(doubl)(180);
    doubl ans1=(doubl)(a*a+b*b);
	doubl w=(doubl)((doubl)(2*a*b)*(doubl)cos(rd));
	doubl ans=(doubl)sqrt(ans1-w);
    cout<<fixed<<setprecision(10)<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4176
from collections import defaultdict
N = int(input())
d = defaultdict(list)
city = set()
for i in range(N):
    S, P = input().split()
    P = int(P)
    d[S].append((P, i+1))
    city.add(S)

for s in d.keys():
    d[s].sort(reverse=True)

city = list(city)
city.sort()

for s in city:
    for p, i in d[s]:
        print(i)


Measured memory_bytes: 3444
fun main(args : Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    println(comb(n, 2) + comb(m, 2))
}

fun perm(n: Int, k: Int): Long {
    return (n - k + 1 .. n).fold(1L) { acc, i -> acc * i }
}

fun comb(n: Int, k: Int): Long {
    if (n == 0) return 0
    val fact = (2..k).fold(1L) { acc, i -> acc * i }
    return perm(n, k) / fact
}


Measured memory_bytes: 36280
void main() {
    string s = readln.chomp;
    foreach (x; lowercase) {
        if (!s.canFind(x)) {
            x.writeln;
            break;
        }
        if (x == 'z') "None".writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 508
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b=MI()
    print(a*b)

main()

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,a[N],b[N];
void read(int &x){
	int f=1;x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
bool chk(int x){
	int i,p=1;
	for(int i=n;i<2*n-1;i++)
		if((a[i]>=x)==(a[i+1]>=x)){p=i;break;}
	for(int i=n;i>1;i--)
		if((a[i]>=x)==(a[i-1]>=x)){
			if(p==1||n-i<p-n)return a[i]>=x;
			break;
		}
	return a[p]>=x;
}
int main(){
	read(n);
	for(int i=1;i<=2*n-1;i++)
		read(a[i]),b[i]=a[i];
	sort(b+1,b+2*n);
	int l=1,r=2*n-1;
	while(l<r){
		int mid=l+r+1>>1;
		if(chk(mid))l=mid;
		else r=mid-1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int mnx = 3e5 + 9;
const int mod = 1e9 + 7;

ll a[mnx], n;
ll s, cnt;

int main() {

cin >> n;

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

for(int i = 1; i <= n; i++) {
    if(a[i] != 0){
        s += a[i];
    }
    if(a[i] == 0 || i == n) {
        cnt += s / 2;
        s = 0;
    }
}

cout << cnt << '\n';


    return 0;

}


Measured memory_bytes: 1024
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    #n = int(input())
    #n, k = map(int, input().split())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    #a = list(map(int, input().split()))
    #b = list(map(int, input().split()))
    s = input()
    if s[-1] == "s":
        print(s+"es")
    else:
        print(s+"s")

Measured memory_bytes: 62972
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        bool isOdd = false;
        if (n % 2 == 1)
        {
            isOdd = true;
            n -= 1;
        }
        List<Tuple<int, int>> edges = new List<Tuple<int, int>>();
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                if (i + j == n + 1) continue;
                edges.Add(new Tuple<int, int>(i, j));
            }
        }
        if (isOdd)
        {
            for (int i = 1; i <= n; i++)
            {
                edges.Add(new Tuple<int, int>(i, n + 1));
            }
        }
        Console.WriteLine(edges.Count);
        Console.WriteLine(string.Join("\n", edges.Select(x => $"{x.Item1} {x.Item2}")));
    }
}

Measured memory_bytes: 11488
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] b = new int[n - 1];

        for (int i = 0; i < n - 1; i++) {
            b[i] = scanner.nextInt();
        }

        int answer = b[0];

        for (int i = 1; i < n - 1; i++) {
            answer += Math.min(b[i], b[i - 1]);
        }
        answer += b[n-2];
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,cnt=0;
    cin>>n;
    unordered_map<string,long long> mp;
    string s;
    for(int i=0; i<n; i++){
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
     for(auto itr = mp.begin(); itr!=mp.end(); itr++){
        cnt+=itr->second*(itr->second - 1)/2;
    }
    cout<<cnt<<endl;
    return 0;
}

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

public class Main{
	void solve(){

		Scanner cin = new Scanner(System.in);
		while(true)
		{
			int e = cin.nextInt();
			if(e==0) return;
			int ret = e;
			for(int i=0;i*i*i<=e;i++){
				for(int j=0;j*j<=e-i*i*i;j++){
					ret = Math.min(ret, i + j + (e - i * i * i - j * j));
				}
			}
			System.out.println(ret);
		}
	}


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

Measured memory_bytes: 12000
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	s := make([]string, n)
	for i := 0; i < len(s); i++ {
		fmt.Scanf("%s", &s[i])
	}

	var s1, s2, s3, s4 int
	for i := 0; i < len(s); i++ {
		if "AC" == s[i] {
			s1 = s1 + 1
		} else if "WA" == s[i] {
			s2 = s2 + 1
		} else if "TLE" == s[i] {
			s3 = s3 + 1
		} else {
			s4 = s4 + 1
		}
	}

	fmt.Println("AC x", s1)
	fmt.Println("WA x", s2)
	fmt.Println("TLE x", s3)
	fmt.Println("RE x", s4)
}


Measured memory_bytes: 6852
e=input
a=[]
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[z]
print(*map(len,a),sep='\n')


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

vector<ll> a, p;

ll f(ll n, ll x){
    if(n==0) return 1;

    if(x==1) return 0;
    else if(x<=1+a[n-1]) return f(n-1,x-1);
    else if(x==2+a[n-1]) return p[n-1]+1;
    else if(x<=2+2*a[n-1]) return p[n-1]+1+f(n-1, x-2-a[n-1]);
    else return 2*p[n-1]+1;
}

int main(void){
    ll n, x; cin >> n >> x;
    a.push_back(1); p.push_back(1);
    for(int i=0; i<n; i++){
        a.push_back(2*a[i]+3);
        p.push_back(2*p[i]+1);
    }

    cout << f(n,x) << endl;
}

Measured memory_bytes: 256
module Main where

import Data.List
import Control.Monad
import Debug.Trace

readLs :: Read a => IO [a]
readLs = fmap read . words <$> getLine

readTuple :: Read a  => IO (a, a)
readTuple = do
    [f, s] <- readLs
    pure (f, s)

solve :: Int -> Int -> Int -> [Int] -> Int
solve a b c lss = inner [] [] [] lss where
    inner :: [Int] -> [Int] -> [Int] -> [Int] -> Int
    inner [] b' c' [] = 100000000
    inner a' [] c' [] = 100000000
    inner a' b' [] [] = 100000000
    inner a' b' c' [] = abs (a - sum a') + abs (b - sum b') + abs (c - sum c')
        + (max 0 $ length a' - 1) * 10
        + (max 0 $ length b' - 1) * 10
        + (max 0 $ length c' - 1) * 10
    inner a' b' c' (l:ls) = minimum [ inner (l:a') b' c' ls 
                                       , inner a' (l: b') c' ls 
                                       , inner a'  b' (l: c') ls 
                                       , inner a'  b' c' ls 
                                        ]  


main = do
    [n,a,b,c] <- readLs
    ls <- replicateM n readLn
    print $ solve a b c ls 


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 200010;

#define ld long double

ld n,k;
ld A[maxn];

int32_t main() {
	//cout << fixed << setprecision(10) << 1e-6 << "\n";
	
	cin >> n >> k;
	for (int i =0;i<n;i++) cin >> A[i];

	
	ld high = 1000000001;
 	ld low = 0;
 	
	while (high - low > 1e-9) {
		ld mid = (high + low) / 2;
		
		int cutsr = 0;
		for (int i =0;i<n;i++) {
			if (A[i] <= mid) continue;
			cutsr += (ceil(A[i]/mid) - 1);
		}
		
		if (cutsr <= k) high = mid;
		else low = mid; 
	}
	
	if (abs(round(high) - high) < 1e-8) cout << (int) round(high); 
	else cout << (int) ceil(high);
}




Measured memory_bytes: 6820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=1001 ;
ll dp[N][10001] ;
ll n,h ;
ll a[N],b[N] ;
ll fun(ll i,ll j)
{
    if(i==n)
    {
        if(j<=0)
            return 0 ;
        else
            return INT_MAX ;
    }
    else if(dp[i][j]!=-1)
        return dp[i][j] ;
    else
    {
        ll ans=fun(i+1,j) ;

        ll nj=j-a[i] ;
        ll x=b[i] ;
        if(nj>0)
            x+=fun(i,nj) ;

        ans=min(ans,x) ;
        return dp[i][j]=ans ;
    }
}
int main()
{
   fast ;
   cin>>h>>n ;
   for(ll i=0;i<n;i++)
    cin>>a[i]>>b[i] ;

   for(ll i=0;i<N;i++)
   {
       for(ll j=0;j<10001;j++)
        dp[i][j]=-1 ;
   }

   ll ans=fun(0,h) ;

   cout<<ans ;



}


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

void fnInput(int& rnNum)
{
  cin >> rnNum;
}
  
int fnNextPrimeGet(int nNum)
{
  int nNextNum = nNum - 1;
  bool bPrime = false;

  while (!bPrime)
  {
    nNextNum++;
    int nSqrtNum = sqrt(nNextNum);
    bPrime = true;

    for (int n = 2; n <= nSqrtNum; n++)
      if (nNextNum % n == 0)
      {
        bPrime = false;
        break;
      }
  }
  return nNextNum;
}
  
int main()
{
  int nNum;

  fnInput(nNum);
  cout << fnNextPrimeGet(nNum) << endl;

  return 0;
}

Measured memory_bytes: 256
package main

// ARC062D - AtCoDeerくんと変なじゃんけん
// https://atcoder.jp/contests/arc062/tasks/arc062_b

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	ans := 0
	for i := 0; i < len(s); i++ {
		if i%2 == 0 { // 自分がグーを出すターン
			if s[i] == 'p' {
				ans--
			}
		} else { // 自分がパーを出すターン
			if s[i] == 'g' {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll k; cin>>k;
  if(k<=9){
    cout<<k<<endl;
    return 0;
  }
  queue<ll> q;
  reps(i,9){
    q.emplace(i);
  }
  ll nxt[]={-1,0,1};
  ll cnt=9;
  while(true){
    ll v=q.front(); q.pop();
    rep(i,3){
      ll t=v%10+nxt[i];
      if(t<0||9<t) continue;
      cnt++;
      ll nv=v*10+t;
      if(cnt==k){
        cout<<nv<<endl;
        return 0;
      }
      q.emplace(nv);
    }
  }
}

Measured memory_bytes: 768
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i]==a[i+1]:
        ans+=1
        if i==n-2:
            a[i+1]=(a[i])%10000+1
        else:
            a[i+1]=10001
print(ans)

Measured memory_bytes: 3060
import java.util.HashMap;
import java.util.Scanner;
 
class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main();
		m.solve(sc);
		sc.close();
	}
	void solve(Scanner sc){
		HashMap<String,Integer> h = new HashMap<String,Integer>();
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			String s = sc.next();
			if(h.containsKey(s)){
				h.replace(s, h.get(s)+1);
			} else {
				h.put(s,1);
			}
		}
		n = sc.nextInt();
		for(int i=0;i<n;i++){
			String t = sc.next();
			if(h.containsKey(t)){
				h.replace(t, h.get(t)-1);
			} else {
				h.put(t,-1);
			}
		}
		int max = 0;
		for(String s:h.keySet()){
			max = Math.max(max, h.get(s));
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 22740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>

using namespace std;


int main() {
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<long long>p(A), q(B), r(C);
	for (int i = 0; i < A; i++)cin >> p[i];
	for (int j = 0; j < B; j++)cin >> q[j];
	for (int k = 0; k < C; k++)cin >> r[k];
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end());
	long long ans = 0;
	int sum = X + Y;
	int Z = 0;
	vector<long long> apple;
	for (int i = A - X; i < A; i++) {
		apple.push_back(p[i]);
	}
	for (int i = B - Y; i < B; i++) {
		apple.push_back(q[i]);
	}
	for (int i = 0; i < r.size(); i++) {
		apple.push_back(r[i]);
	}
	sort(apple.begin(), apple.end());
	for (int i = apple.size() - 1; i >= apple.size() - sum; i--) {
		ans += apple[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8816
#include <stdio.h>
 
int main(void){
    int n,x,i,j,k;
    while(1){
    int c=0;
    scanf("%d %d",&n,&x);
    if(n==0 && x==0){
        break;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            for(k=j+1;k<=n;k++){
                if(i+j+k==x){
                    c++;
                }
            }
        }
    }
    printf("%d\n",c);
    }
    return 0;
}
 

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

int main() {
    int n;cin >> n;
    double a[n];
    double sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] = 1/a[i];
        sum += a[i];
    }
    sum = 1/sum;
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    str a,b;
    cin >> a>>b;
    if (a<b){cout << '<' << endl;}
    else if(a>b){cout << '>' << endl;}
    else{cout << '=' << endl;}
    
}

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

int main(){
  int N;
  cin>>N;
  double p;
  if(N%2==0){
  p=0.5;
  printf("%lf\n",p);
  }
  else{
  double M=(N-1)/2;
    p=(M+1)/N;
    printf("%lf\n",p);
  }
}

Measured memory_bytes: 256
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

typedef long long LL;

LL solve(LL n) {
	LL ans = 0;
	if ((n % 2) == 0) {
		LL x = 10;
		while (n > 0) {
			ans += n / x;
			n /= x;
			x = 5;
		}
	}
	return ans;
}

int main(int argc, char* argv[]) {

#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1, ans = 0;
		cin >> n;
		if (n < 0) return 0;
		ans = solve(n);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	int ans = 0;

	for (int i = a;i <= b;i++)
	{
		if (c%i == 0) ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int a[20];
  for(int i=0;i<3;i++){
    cin >>  a[i];
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<2-i;j++){
      if(a[j]>a[j+1]){
	int temp=a[j];
	a[j]=a[j+1];
	a[j+1]=temp;
      }
    }
  }
  cout << a[0] << " " << a[1] << " " << a[2] << endl;
  return(0);
}



Measured memory_bytes: 3112
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    a[] -= 1;
    long[] list = new long[n];
    foreach (x; a)
    {
        ++list[x];
    }

    foreach (l; list)
    {
        l.writeln;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 11692
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define endl '\n'
#define pb push_back

// debug 도구

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

// debug 도구 end

using llong = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VPII = vector<pair<int, int>>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int mind = 0;
    rep(i,0,s.length()) {
        if (s[i] == '+') mind++;
        else mind--;
    }
    cout << mind;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using P = pair<ll, ll>;
const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll mn = INF, mx = -INF, mnidx, mxidx;
  REP(i, n){
    cin >> a[i];
    if(a[i] < mn){
      mn = a[i];
      mnidx = i;
    }
    if(mx < a[i]){
      mx = a[i];
      mxidx = i;
    }
  }
  vector<P> ans;
  if(mn*mx < 0){
    if(mx >= labs(mn)){
      REP(i, n){
        a[i] += mx;
        ans.emplace_back(P(mxidx+1, i+1));
      }
      REP(i, n-1){
        a[i+1] += a[i];
        ans.emplace_back(P(i+1, i+2));
      }
    }else{
      REP(i, n){
        a[i] += mn;
        ans.emplace_back(P(mnidx+1, i+1));
      }
      REPr(i, n-1){
        a[i] += a[i+1];
        ans.emplace_back(P(i+2, i+1));
      }
    }
  }else{
    if(mn >= 0){
      REP(i, n-1){
        a[i+1] += a[i];
        ans.emplace_back(P(i+1, i+2));
      }
    }else{
      REPr(i, n-1){
        a[i] += a[i+1];
        ans.emplace_back(P(i+2, i+1));
      }
    }
  }
  ll m = ans.size();
  cout << m << endl;
  REP(i, m) cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}

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

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    vector <int> a(q), b(q), c(q), d(q);
    for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    auto dfs = [&](auto dfs, vector<int> vec, int k) -> int {
        int ret = 0;
        if (k < n) {
            for (int i = vec[k]; i <= m; i++) {
                vec[k + 1] = i;
                ret = max(ret, dfs(dfs, vec, k + 1));
            }
        } else {
            for (int i = 0; i < q; i++) {
                if (vec[b[i]] - vec[a[i]] == c[i]) ret += d[i];
            }
        }
        return ret;
    };

    vector<int> vec(n + 1, 1);
    cout << dfs(dfs, vec, 0) << "\n";
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	long long K, A, B;

	cin >> K >> A >> B;

	long long ans = 1;
	if (A < B - 2 && A + 1 <= K)
	{
		long long count = K;

		ans = A;
		count -= A - 1;

		long long trade_p = count / 2;
		ans += trade_p * (B - A);
		
		if (count % 2 == 1)
		{
			ans++;
		}
	}
	else
	{
		ans += K;
	}

	cout << ans << endl;

	return 0;
}

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

#define x first
#define y second

typedef long double LD;
typedef std::pair<int, LD> pair;
const int N = 500005;

int n, L, h, t;
pair q[N]; LD sum;

void operator += (pair &a, pair b) { a.y = (a.x * a.y + b.x * b.y) / (a.x + b.x), a.x += b.x; }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> L, h = 1;
	for (int i = 0; i < n; ++i) {
		int x, y, v = i ? L : 0; std::cin >> y >> x;
		while (v + x > L) {
			int d = std::min(q[h].x, v + x - L);
			q[h].x -= d, sum -= d * q[h].y, v -= d;
			if (!q[h].x) ++h;
		}
		sum += (LD) x * y, q[++t] = pair(x, y);
		std::cout << std::fixed << std::setprecision(8) << sum / L << '\n';
		while (h < t && q[t].y <= q[t - 1].y) q[t - 1] += q[t], --t;
	}
	return 0;
}

Measured memory_bytes: 25216
#include<iostream>
using namespace std;
int main()
{
    int n;cin >> n;
    int cnt = 0,ans = 0;
    int m;
    for(int i = 1;i <= n;i++)
    {
        m = i;
        while(m != 0)
        {
        cnt++;
        m = m/10;
        }
        if(cnt % 2 == 1)ans++;
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def query(self,top_num,front_num):

        self.save_data = [i for i in range(6)]
        #元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        #元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

        return ret;




dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

num_query = int(input())
for loop in range(num_query):
    top_num,front_num = map(int,input().split())
    print("%d"%(dice.query(top_num, front_num)))





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

int main(){
	int n; cin >> n;
    double a = 0;
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        a += (1.0/x);
    }
    printf("%.6f\n", 1/a);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = list(map(int,input().split()))

total = 0 
for i in range(n):
    total += arr[i]

ave = total / n

tmp = float('inf')

for j in range(n):
    if abs(arr[j] - ave) < tmp:
        tmp = abs(arr[j] - ave)
        ans = j
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>

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

const ll MAX_N = 100005;
const ll INF = 1e10;
ll N, M;
vector<ll> G[MAX_N];
ll d[MAX_N];
ll pre[MAX_N];

void dijkstra(ll s)
{
    fill(d, d+N, INF);
    fill(pre, pre+N, -1);
    priority_queue<P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty())
    {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if(d[v] < p.first)
        {
            continue;
        }
        for(ll i = 0; i < G[v].size(); i++)
        {
            ll u = G[v][i];
            if(d[u] > d[v] + 1)
            {
                d[u] = d[v] + 1;
                que.push(P(d[u], u));
                pre[u] = v;
            }
        }
    }
}

int main()
{
    cin >> N >> M;
    for(ll i = 0;i < M;i++)
    {
        ll A, B;
        cin >> A >> B;
        A--;B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    dijkstra(0);

    cout << "Yes" << endl;
    for(ll i = 1; i < N;i++)
    {
        cout << (pre[i] + 1) << endl;
    }
   return 0;
}

Measured memory_bytes: 14516
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility> //pairを使う
using namespace std;

typedef unsigned long long ll;

const ll inf = 1000000000000;
const ll mod = 100000;

int main(){
	ll dp[100], n;
	cin >> n;
	dp[0] = 2; dp[1] = 1;
	for(int i = 2; i <= n; i++){
		dp[i] = dp[i - 1] + dp[i - 2];
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, t;
    cin >> n >> t;
    ll last = 0, ans = 0;
    for(int i = 0; i < n; i++) {
        int ti;
        cin >> ti;
        ans += t + min(ti - last, 0ll);
        last = ti + t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256