akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
ac
*/

ll x,y,a,b,c;
ll p[100010],q[100010],r[300010];
ll ans=0;

int main(void){
	cin>>x>>y>>a>>b>>c;
	rep(i,a)cin>>p[i];
	rep(i,b)cin>>q[i];
	rep(i,c)cin>>r[i];
	sort(p,p+a);
	sort(q,q+b);
	rep(i,x)r[c+i]=p[a-1-i];
	rep(i,y)r[c+x+i]=q[b-1-i];
	sort(r,r+c+x+y);
	rep(i,x+y)ans+=r[c+x+y-1-i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3968
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    // first is plus
    let mut cost = 0;
    let mut sum = 0;
    for i in 0..a.len() {
        sum += a[i];
        if i % 2 == 0 {
            if sum <= 0 {
                cost += (sum - 1).abs();
                sum = 1;
            }
        } else {
            if sum >= 0 {
                cost += (sum + 1).abs();
                sum = -1;
            }
        }
    }
    let mut r1 = cost;

    // first is minus
    let mut cost = 0;
    let mut sum = 0;
    for i in 0..a.len() {
        sum += a[i];
        if i % 2 == 0 {
            if sum >= 0 {
                cost += (sum + 1).abs();
                sum = -1;
            }
        } else {
            if sum <= 0 {
                cost += (sum - 1).abs();
                sum = 1;
            }
        }
    }
    let mut r2 = cost;
    println!("{}", min(r1, r2));
}


Measured memory_bytes: 3720
import fractions
import collections

def p(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a

a,b=map(int,input().split())
f=fractions.gcd(a,b)
c=collections.Counter(p(f))
print(len(list(c.keys()))+1)

Measured memory_bytes: 5052
count = 0

def mizu(h):
    global count
    # 終端処理
    if len(h) is 0:
        return
    if len(h) is 1:
        count += h[0]
        return
    # その範囲の最小値
    m = min(h)
    count += m
    # 残りの高さ
    h = [i - m for i in h]
    while 0 in h:
        # （最小値だった）0の箇所で分割
        mizu(h[:h.index(0)])
        h = h[h.index(0)+1:]
    mizu(h)

if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    mizu(h)
    print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n, is = 1, num[200007];
map<int, int>mp;
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int check(int mid)
{
	mp.clear();
	for (int i = 2; i <= n; i++)
		if (num[i] <= num[i - 1])
		{
			while (!mp.empty() && mp.rbegin()->first > num[i])
				mp.erase(mp.rbegin()->first);
			int pos = num[i];
			while (mp[pos] + 1 == mid)mp.erase(pos), pos--;
			if (!pos)return 0;
			mp[pos]++;
		}
	return 1;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
		num[i] = read(), is &= (num[i] > num[i - 1]);
	if (is) { cout << 1 << endl; return 0; }
	int l = 2, r = n;
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (check(mid))r = mid;
		else l = mid + 1;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 1152
try:
    from math import inf
except:
    inf = float("inf")
from collections import deque

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)


Measured memory_bytes: 3316
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);
		Collections.reverse(list);
		int result = 0;
		for(int i = 0; i < n; i++) {
			if(i == 0 || i % 2 == 0) {
				result += list.get(i);
			} else {
				result -= list.get(i);
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  string odd,even;
  cin >> odd >> even;
  int len_odd  = odd.size();
  int len_even = even.size();
  if(len_odd > len_even){
    for(int i = 0; i < len_even; i++){
      cout << odd[i] << even[i];
    }
    cout << odd[len_odd-1] << endl;
  } else {
    for(int i = 0; i < len_even; i++){
      cout << odd[i] << even[i];
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define unordered_map umap
typedef long long ll;
typedef long double ld;
ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}
bool isPrime(int n){if(n<2){return false;}for(int i=2;i<sqrt(n)+1;i++){if(n%i==0) return false;}return true;}


int main(){
  int a[3]; CINA(a,3);
  int d[3];
  REP(i,3){d[i] = abs(a[i]-a[(i+1)%3]) ;}
  sort(d,d+3);
  cout << d[0]+d[1]<<"\n";
}


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

  mod=10**9+7
  ans=0

  for i in range(60):
      a=0
      for x in A:
          if x>>i&1:
              a+=1
      ans+=a*(N-a)*pow(2,i,mod)
      ans%=mod
  print(ans)
if __name__ == '__main__':
    main()

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

int main() {
  int n, m;
  int x, y;
  int i, j, k;
  int count;
  char sw[100001];

/*read header*/
  scanf("%d %d", &n, &m);

/*hairetsu initialize*/
  memset(sw,0x31,n);/*00110001*/
  sw[n+1] = 0x00;

/*read data*/
  for (i=0; i < m; i = i+1){
    scanf("%d %d", &x, &y);
    sw[x] = sw[x]^0x01;
    sw[y] = sw[y]^0x01;
  }

/*hantei*/
  if (strchr(sw, 0x30) == 0x00){
      printf("YES\n");
  }
  else {
      printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;



int main(int argc, char *args[]) {
	int a, b, c;
	int d;
	bool ab=false, bc=false, ca=false;
	cin >> a >> b >> c >> d;
	if (abs(a - b) <= d)ab = true;
	if (abs(b - c) <= d)bc = true;
	if (abs(c - a) <= d)ca = true;
	if (ab && bc)ca = true;
	if (ca)cout << "Yes" << endl;
	else cout << "No" << endl;


}


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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

//-------------------------------------------------------------------\\


int main()
{
    IOS;
    //fileRead
    int tc = 1;
    //cin>>tc;
    while(tc--)
    {
        int n; cin>>n;
        int x = (n+1000-1)/1000;
        cout<< x*1000 - n;
    }
}

Measured memory_bytes: 3576
a,b,c = input().split()
A = int(a)
B = int(b)
C = int(c)

i = 1
while(i<B+1):
	if((A*i)%B == C):
		print("YES")
		break
	else:
		i += 1

if(i==B+1):
	print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	
	string s;

	cin >> s;

	int ans = 0;

	for (int i = 0;i < 4;i++) {
		if (s[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>
 
using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"
 
int main() {
	int N;
	cin >> N;
	map<string, int> mp;
	int count = 0;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		if (mp[s]++ == 0) {
			++count;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 19120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] S = sc.next().toCharArray();
		sc.close();
		String rs = String.valueOf(S);
		int num = rs.length();

		int A = 0;

		for (int i = 0; i < num-2; i++) {
			if (S[i] == 'A') {
				if (S[i + 1] == 'B') {
					if (S[i + 2] == 'C') {
						A++;
					}
				}
			}
		}
		System.out.println(A);
	}
}

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

using namespace std;

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

	int n,k;
	cin >> n >> k;
	double res = 0.0;
	for(int i=1; i<=n; i++){
		double prob = 1.0/n;
		int temp = i;
		while(temp<k){
			temp*=2;
			prob/=2;
		}
		res += prob;
	}
	cout << fixed << setprecision(10) << res;
	return 0;
}

Measured memory_bytes: 3776
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
ssi =lambda: stdin.readline()
sii =lambda: int(stdin.readline())
sp  =lambda x: stdout.write(str(x))

mod=1000000007


#main code
n,x,t=mi()
a=ceil(n/x)
print(t*a)



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

struct Rational{
    // p : 分子 q : 分母
    LL p, q;
    void normalize(){
        if(q < 0) {
            p *= -1;
            q *= -1;
        }
        LL d = __gcd(abs(p), q);
        if(d == 0){
            p = 0;
            q = 1;
        }else{
            p /= d;
            q /= d;
        }
    }
    Rational(LL p, LL q) : p(p), q(q) {
        normalize();
    }

};

Rational operator + (const Rational& a, const Rational& b){
    return Rational(a.p * b.q + b.p * a.q, a.q * b.q);
}

Rational operator - (const Rational& a, const Rational& b){
    return Rational(a.p * b.q - b.p * a.q, a.q * b.q);
}

Rational operator * (const Rational& a, const Rational& b){
    return Rational(a.p * b.p, a.q * b.q);
}

Rational operator / (const Rational& a, const Rational& b){
    return Rational(a.p * b.q, a.q * b.p);
}

bool operator == (const Rational& a, const Rational& b){
    return (a.p == b.p) && (a.q == b.q);
}

bool operator < (const Rational& a, const Rational& b){
    // overflowを避けるためにlong doubleを用いる
    return (long double) a.p * b.q < (long double) b.p * a.q;
}
bool operator >= (const Rational& a, const Rational& b){
    return a == b || (b < a);
}

int main(){
    int H, fh, fm, fs;
    while(cin >> H >> fh >> fm >> fs && H > 0) {
        Rational begin(fh * 3600 + fm * 60 + fs, 1);
        // cout << "begin: " << begin.p << " " << begin.q << endl;
        bool exist = false;
        Rational answer(1, 1);
        int ah, am;
        Rational as(1, 0);
        for(int h = 0; h < H; h++) {
            for(int m = 0; m < 60; m++) {
                for(int i = -1; i <= 1; i++) {
                    Rational s(3600 * h + 60 * (1 + H) * m + i * 3600 * H, 119 * H - 1);

                    if(s >= Rational(60, 1)) continue;
                    if(s < Rational(0, 1)) continue;
                    if(Rational(59, 1) * s == Rational(60 * m, 1)) continue;

                    // if(h == 0 && m == 0) {
                    //     cout << s.p << " " << s.q << endl;
                    // }

                    Rational now(h * 3600 + m * 60, 1);
                    now = now + s;
                    // cout << "hm: " << h << " " << m << endl;
                    // cout << "now: " << now.p << " " << now.q << endl;
                    if(now < begin) {
                        now = now + Rational(H * 3600, 1);
                    }
                    // cout << "now2: " << now.p << " " << now.q << endl;
                    if(!exist || now < answer) {
                        exist = true;
                        answer = now;
                        ah = h, am = m, as = s;
                    }
                    // cout << "answer: " << answer.p << " " << answer.q << endl;
                    // cout << "ah: " << ah << " " << am << " " << as.p << " " << as.q << endl;
                }
            }
        }
        cout << ah << " " << am << " " << as.p << " " << as.q << endl;
        // cout << "---" << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int getgcd(int n, int m)
{
    int r;
    if (n > m) {
    int t = m;
    m = n;
    n = t;
    }
    while ((r = m % n) != 0) {
    m = n;
    n = r;
    }
    return n;
}

int main() {
    int n,ans=0,x;
    cin>>n;
    for(int a=1;a<=n;a++)
    {
        for(int b=1;b<=n;b++)
        {
            for(int c=1;c<=n;c++)
            {
                x = getgcd(getgcd(a, b), c);
                ans+=x;
                // cout<<a<<" "<<b<<" "<<c<<" "<<" "<<ans<<endl;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#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 pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    int k; cin>> k;
    string s; cin>> s;
    int c = 0;
    int l = s.length();
    string res = "";
    
    if(l <= k) {
        cout << s << '\n';
    }else {
        rep(i, 0, k) {
            res += s[i];
        }res += "...";
        cout << res << '\n';
    }

    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var dataset = nextStrings(10000)
	for i, x := range dataset {
		if x == "0" {
			break
		}
		fmt.Printf("Case %v: %v\n", i+1, x)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}



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

int main(){
  
  int K,S; cin >> K >> S;
  
  int ans = 0;
  
  for(int x = 0; x <= K; ++x){
    for(int y = 0; y <= K; ++y){
      int z = S - x -y;
      if(0 <= z && z <= K){
        ans++;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,name1;
  cin>>a>>b;
  name1=a*b;
  if (name1%2==0){
    cout<<"Even"<<endl;
  }
  else{
    cout<<"Odd"<<endl;
  } 
}

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

using namespace std;

long long int a[100010], b[100010];

int main(void) {


	int n;
	cin>>n;
	long long int ans = 0;

	for(int i = 0; i < n; ++i) {
		cin>>a[i];
	}
	for(int i = 0; i < n; ++i) {
		if(a[i] == 0)	continue;
		//b[i] = a[i];
		//cout<<i<<" "<<a[i]<<endl;
		ans += a[i]/2ll;
		a[i] = (a[i]%2);
		if((i != n-1) && (a[i])) {
			//cout<<"oye ohoey\n";
			if(a[i+1] != 0)
				a[i+1]++;
			//cout<<"changed "<<a[i+1]<<endl;
		}
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7,inv2=5e8+4;
int n,nxt[200005],a[200005],b[200005];
ll cnt[200005],pre[200005],suf[200005],s2[200005],c[200005];
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
void add(int p,ll v)
{
	while(p<=n)
	{
		c[p]+=v;
		if(c[p]>=MOD)c[p]-=MOD;
		p+=p^(p&(p-1));
	}
}
ll sum(int p)
{
	ll ans=0;
	while(p)
	{
		ans+=c[p];
		p&=p-1;
	}
	return ans%MOD;
}
ll sum(int l,int r)
{
	return sum(r)-sum(l-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
		cnt[a[i]]++;
	}
	for(int i=n;i>=1;i--)cnt[i]+=cnt[i+1];
	for(int i=1;i<=n;i++)
	{
		cnt[i]-=n-i;
		if(cnt[i]<=0)
		{
			printf("0\n");
			return 0;
		}
	}
	pre[0]=1;
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]*cnt[i]%MOD;
	suf[n+1]=1;
	for(int i=n;i>=1;i--)suf[i]=suf[i+1]*cnt[i]%MOD;
	for(int i=1;i<=n;i++)
	{
		if(cnt[i]==1)s2[i]=1;
		else s2[i]=s2[i-1]*(cnt[i]-1)%MOD;
	}
	ll ans=0;
	sort(b+1,b+n+1);
	for(int i=1;i<=n;)
	{
		int j=i;
		while(b[j]==b[i])j++;
		ans=(ans+1ll*(j-i)*(j-i-1)/2%MOD*pre[n]%MOD*inv2)%MOD;
		i=j;
	}
	nxt[n+1]=n+1;
	for(int i=n;i>=1;i--)
	{
		nxt[i]=nxt[i+1];
		if(cnt[i+1]==1)nxt[i]=i+1;
	}
	for(int i=n;i>=1;i--)
	{
		ll k=pre[a[i]]*quick_pow(s2[a[i]],MOD-2)%MOD;
		ans=(ans+k*sum(a[i]+1,nxt[a[i]]-1)%MOD*inv2)%MOD;
		add(a[i],suf[a[i]+1]*s2[a[i]]%MOD);
	}
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++)
	{
		add(a[i],1);
		ans=(ans+sum(a[i]+1,n)*pre[n])%MOD;
	}
	nxt[0]=0;
	for(int i=1;i<=n;i++)
	{
		nxt[i]=nxt[i-1];
		if(cnt[i]==1)nxt[i]=i;
	}
	memset(c,0,sizeof(c));
	for(int i=n;i>=1;i--)
	{
		ll k=suf[a[i]+1]*s2[a[i]]%MOD;
		if(nxt[a[i]]+1>a[i]-1)
		{
			add(a[i],pre[a[i]]*quick_pow(s2[a[i]],MOD-2)%MOD);
			continue;
		}
		ans=(ans-k*sum(nxt[a[i]]+1,a[i]-1)%MOD*inv2)%MOD;
		add(a[i],pre[a[i]]*quick_pow(s2[a[i]],MOD-2)%MOD);
	}
	if(ans<0)ans+=MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		//????????£?????????????????????
		Scanner sc = new Scanner (System.in);
		//???????????? ??????r
		double r = sc.nextDouble();

		//???????°???
		double PI = 3.14;

		//??¢???????±??????? ?????? ?? ?????? ?? 3.14
		double Area = (r * r) * Math.PI;
		//?????¨????????? ?????? * 2 ??3.14
		double Circle = ( r * 2 ) * Math.PI;

		//??¨???
		System.out.printf("%.6f %.6f", Area,Circle);
	}
}

Measured memory_bytes: 28208
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
typedef  long long ll;
priority_queue <ll>q;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    while(n--)
    {
        ll a;
        scanf("%lld",&a);
        q.push(a);
    }
    while(m)
    {
        ll t=q.top();
        q.pop();
        t=t/2;
        q.push(t);
        m--;
    }
    ll ans=0;
    while(!q.empty())
    {
        ll t=q.top();
        ans=ans+t;
        q.pop();
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define N 100010
int b[N],ans;
int main()
{
	int n,h,k,a=-1000000010;
	scanf("%d%d",&n,&h);
	for(int i=1;i<=n;++i) 
	{
		scanf("%d%d",&k,&b[i]);
		a=max(a,k);
	}
	sort(b+1,b+1+n);
	for(int i=n;i>=1;--i) 
	{
		if(a>=b[i]) 
		{
			int tmp=h/a;
			int yu=h%a;
			if(yu>0)ans++;
			ans+=tmp;
			h=0;
			break;
		}
		else 
		{
			h-=b[i];
			ans++;
		}
		if(h<=0) break;
	}
	if(h>0) {int tmp=h/a;int yu=h%a;if(yu>0) ans++; ans+=tmp;}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  ll N; cin >> N;
  ll ans = 0;
  rep(i, 1, sqrt(N)) {
    ll v = (N - i) % i;
    if(v == 0) {
      ll s = (N - i) / i;
      if(N/s == N%s) ans += s;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int dx = c - a, dy = d - b;
  cout << c - dy << " " << d + dx << " " << a - dy << " " << b + dx << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int H[300], W[300], n=0, i, j, k;
    
    while(1){
        scanf("%d %d", &H[n], &W[n]);
        if(H[n]==0 && W[n]==0){
            break;
        }
        n++;
    }
    
    for(k=0; k<n; k++){
        for(i=0; i<H[k]; i++){
            for(j=0; j<W[k]; j++){
                if((i+j)%2==0)  putchar('#');
                else        putchar('.');
            }
            printf("\n");
        }
        putchar('\n');
    }
    
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

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

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


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


int main(){
  int n; cin >> n;
  vector<long long> v;
  long long m = 0;
  long long count = 0;
  v.push_back(0);
  for (int i = 0; i < n; i++) {
    long long k; cin >> k;
    m += k;
    v.push_back(m);
    //cout << " " << m;
  }

  sort(v.begin(), v.end());
  long long prev;
  long long cnt = 0;
  for (int i = 0; i < n+1; i++) {
    //cout << count << "\n";
    if (i == 0) {
      prev = v[i];
      cnt = 1;
    }
    else {
      if (prev == v[i]) cnt++;
      else {
        long long u = cnt * (cnt-1);
        u /= 2;
        count += u;
        prev = v[i];
        cnt = 1;
      }
    }
  }
  long long u = cnt * (cnt-1);
  u /= 2;
  count += u;

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 2420
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 12 20:07:27 2018

@author: Fujiichang
"""

if __name__ == "__main__":

    x = map(int, raw_input().split())
    a = x[0]
    b = x[1]
    c = x[2]

    if a < b:
        if b < c:
            print 'Yes'
        else:
            print 'No'

    else:
        print 'No'



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

int main() {
  vector<int> e(12);
  int i;
  for (i = 0; i < e.size(); i++) {
    cin >> e[i];
  }
  sort(e.begin(), e.end());
  for (i = 0; i < 3; i++) {
    if (!(e[4 * i + 0] == e[4 * i + 1] && e[4 * i + 2] == e[4 * i + 3] && e[4 * i + 0] == e[4 * i + 3])) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}



Measured memory_bytes: 3128
import math
N,D=map(int,input().split())
X=[list(map(int, input().split())) for i in range(N)]
ans=0
for i in range(N-1):
  for j in range(i+1,N):
    key=0
    for x in range(D):
      key+=(X[i][x]-X[j][x])**2
    if math.sqrt(key)==int(math.sqrt(key)):
      ans+=1
print(ans)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    ll n;
    cin >> n;
    ppp(n*(n-1)/2);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	char op;
	while (true)
	{
		cin >> a >> op >> b;
		if(op == '?')
			break;
		switch (op)
		{
		case '+':
			cout << a + b << endl;
			break;
		case '-':
			cout << a - b << endl;
			break;
		case '*':
			cout << a * b << endl;
			break;
		case '/':
			cout << a / b << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
long int power(int a,int b){
  long int count=1;
  for(int i=0;i<b;i++){
    count *= 2;
  }
  return count;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int flag=2;
  char s[100],t[100];
  scanf("%s",s);
  scanf("%s",t);
  for(int i=0;i<strlen(s);i++){
    for(int j=i+1;j<strlen(s);j++){
      if(s[i] > s[j]){
        char tmp=s[i];s[i]=s[j];s[j]=tmp;
      }
    }
  }
  for(int i=0;i<strlen(t);i++){
    for(int j=i+1;j<strlen(t);j++){
      if(t[i] < t[j]){
        char tmp=t[i];t[i]=t[j];t[j]=tmp;
      }
    }
  }
  for(int i=0;i<min(strlen(s),strlen(t));i++){
    if(s[i] < t[i]){
      flag=1;break;
    }
    if(s[i] > t[i]){
      flag=0;break;
    }
  }
  if(flag==1)printf("Yes");
  else if(flag==0)  printf("No");
  else if(flag==2){
    if(strlen(s) < strlen(t))printf("Yes");
    else printf("No");
  }
  //printf("%s\n",s);
  //printf("%s\n",t);

  return 0;
}


Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
ans=0

a.sort(reverse=True)
ans+=int(a[0])
n-=2
where=1
kaisu=0
while n>0:
  ans+=int(a[where])
  kaisu+=1
  n-=1
  if kaisu==2:
    kaisu=0
    where+=1

print(str(ans))

Measured memory_bytes: 31704
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut c = Vec::new();
    let mut d = Vec::new();
    for _ in 0..n {
        let a: i64 = itr.next().unwrap().parse().unwrap();
        let b: i64 = itr.next().unwrap().parse().unwrap();
        c.push(a);
        d.push(b);
    }
    c.sort();
    d.sort();

    if n % 2 == 0 {
        println!(
            "{}",
            (d[n / 2] * 2 + d[n / 2 - 1] * 2) / 2 - (c[n / 2] * 2 + c[n / 2 - 1] * 2) / 2 + 1
        );
    } else {
        println!("{}", d[n / 2] - c[n / 2] + 1);
    }
}


Measured memory_bytes: 9692
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int n,k;
	cin>>n>>k;
	vi h(n);
	for(auto&i:h)cin>>i;
	ll res=1000000000000ll;
	rep(i,1<<n){
		if(__builtin_popcount(i)!=k) continue;
		vi s;
		rep(j,n) if((1<<j)&i)s.push_back(j);
		ll ans=0, t=(s[0]==0?0:*max_element(h.begin(),h.begin()+s[0]));
		rep(j,k){
			if(t>=h[s[j]]){
				t++;
				ans+=t-h[s[j]];
			}else t=h[s[j]];
			if(j+1!=k and s[j]+1!=s[j+1]){
				int m=*max_element(h.begin()+s[j]+1, h.begin()+s[j+1]);
				if(t<m){
					ans+=m-t;
					t=m;
				}
			}
		}
		res=min(res,ans);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPll(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int gcd(int a, int b){
  if(b == 0){
    return a;
  }
  if(a < b)return gcd(b, a);
  return gcd(b, a%b);
}

int main()
{
  int n; cin >> n;
  vecll a(n,0);REP(i,n) cin >> a[i];
  ll sum = 0;
  map<ll, ll> mp;
  mp[0] ++;
  REP(i,n){
    sum += a[i];
    mp[sum] ++;
    // cout << sum << endl;
  }
  ll ans = 0;
  REPvec(itr, mp){
    ans += (itr->second)*(itr->second - 1)/2;
  }
  cout << ans << endl;
}


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

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

char input[70][70];
string dp[70][70];

int comp(string s,string t) { // comp s and t if s < t return negative
  if(s.length() != t.length()) return (s.length() - t.length());
  rep(i,s.length()) if(s[i] != t[i]) return (s[i] - t[i]);
  return 0;
}

int main() {
  int w,h,n;
  while(cin>>w>>h, w|h) {
    string s;
    rep(i,h) {
      cin>>s;
      rep(j,w) {
	dp[i][j] = "";
	input[i][j] = s[j];
      }
    }

    rep(i,h) {
      rep(j,w) {
	char c = input[i][j];
	if(i == 0 && j == 0) {
	  if(c <= '9' && c >= '0') dp[i][j] = string(1,c);
	}else{
	  if(!(c <= '9' && c >= '0')) continue;
	  string ab = "",left = "";
	  if(i > 0) ab = dp[i-1][j] + string(1,c);
	  if(j > 0) left = dp[i][j-1] + string(1,c);
	  if(comp(ab,left) <= 0) {
	    dp[i][j] = left;
	  }else{
	    dp[i][j] = ab;
	  }
	  if(dp[i][j][0] == '0') dp[i][j] = dp[i][j].substr(1);
	  //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
	}
      }
    }

    string ans = "";
    rep(i,h) rep(j,w) { if(comp(ans,dp[i][j]) < 0) ans = dp[i][j]; }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1032
using static System.Console;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] tmp = ReadLine().Split(' ');
        var a = int.Parse(tmp[0]);
        var b = int.Parse(tmp[1]);

        if ((a * b) % 2 == 0)
        {
            WriteLine("Even");
        }
        else
        {
            WriteLine("Odd");
        }
    }
}


Measured memory_bytes: 13140
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [usize;n]
    }

    let mut a = a;
    a.sort();
    a.reverse();

    let first = a[0];
    let second = a[1];

    let mut ans = first;

    let mut que1 = BinaryHeap::new();
    que1.push((second, first, second));
    que1.push((second, first, second));

    for i in 2..n {
        let between = que1.pop().unwrap();
        ans += cmp::min(between.1, between.2);
        que1.push((a[i], between.1, a[i]));
        que1.push((a[i], between.2, a[i]));

        //println!("{:?}", que1);
    }

    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

int main(void){
    int i, j;
    unsigned int n;
    int cnt = 0;
    scanf("%1000d", &n);
    unsigned int *a = (int *)calloc(n, sizeof(unsigned int));

    for(i=0; i<n; i++){
        scanf("%1000d", &a[i]);
    }
    
    for(i=0; i<n; i++){
        if(a[a[i] - 1] == i+1){
            cnt++;
        }
    }
    cnt /= 2;
    
    printf("%d", cnt);
	
    putchar('\n');
	return 0;
}

Measured memory_bytes: 640
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	llint n,K,bmax=big,bmin=-1,i;
	cin>>n>>K;
	vector<llint>A(n);
	for(i=0;i<n;i++){cin>>A[i];}
	vector<llint>F(n);
	for(i=0;i<n;i++){cin>>F[i];}
	SO(A);SO(F);REV(F);
	while(bmax-bmin>1){
		llint bgen=(bmax+bmin)/2;
		llint pla=0;
		for(i=0;i<n;i++){pla+=max(A[i]-bgen/F[i],0LL);}
		if(pla<=K){bmax=bgen;}
		else{bmin=bgen;}
	}
	cout<<bmax<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846264338327950L

int main(void){
    int A,B,H,M;
    double ans;
    
    scanf("%d%d%d%d",&A,&B,&H,&M);
    
    ans = cos(2*PI*(H/12.0 + (M/(60.0*12.0)) - M/60.0));
    printf("%.20lf\n",sqrt(A*A+B*B-2*A*B*ans));
    
}

Measured memory_bytes: 2564
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

const double N_MAX=100;
const int dt_MAX=40010;
vector<double> t(N_MAX+2);
vector<double> v(N_MAX+2);

int main(){
    double N;
    cin>>N;
    REP(i,N) cin>>t[i+1];
    REP(i,N) cin>>v[i+1];
    v[0]=0;
    v[N+1]=0;
    t[0]=0;
    REP(i,N){
        t[i+1]+=t[i];
    }
    t[N+1]=20020;
    double dt=0.50;
    double ans=0;
    REP(i,dt_MAX){
        double timea=dt*i;
        double timeb=timea+dt;
        if(timea>=t[N]) break; 
        double va=200;
        double vb=200;
        
        REP(j,N+2){
            double l;
            if(j==0) l=t[0];
            else l=t[j-1];
            double r=t[j];
            if(timea<=l){
                va=min(va,v[j]+(l-timea));
            }else if(timea>=l&&timea<=r){
                va=min(va,v[j]);
            }else{
                va=min(va,v[j]+(timea-r));
            }

            if(timeb<=l){
                vb=min(vb,v[j]+(l-timeb));
            }else if(timeb>=l&&timeb<=r){
                vb=min(vb,v[j]);
            }else{
                vb=min(vb,v[j]+(timeb-r));
            }
        }
        ans+=0.25*(va+vb);
    }
    printf("%.4f\n",ans);

}

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

int main()
{
    ll x;
    cin >> x;
    for (ll i = -200; i < 200; i++) {
        for (ll j = -200; j < 200; j++) {
            if (i * i * i * i * i - j * j * j * j * j == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3604
using System;

public class Hello
{
    public static void Main()
    {
        var a = new int[3, 3];
        for (int i = 0; i < 3; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < 3; j++) a[i, j] = int.Parse(line[j]);
        }
        var b = new bool[3, 3];
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var t = int.Parse(Console.ReadLine().Trim());
            for (int j = 0; j < 3; j++)
                for (int k = 0; k < 3; k++)
                    if (a[j, k] == t) b[j, k] = true;
        }
        getAns(b);
    }
    static void getAns(bool[,] b)
    {
        for (int i = 0; i < 3; i++)
        {
            var ok = true;
            var ok2 = true;
            for (int j = 0; j < 3; j++)
            {
                if (!b[i, j])  ok = false; 
                if (!b[j, i])  ok2 = false;  
            }
            if (ok | ok2) { Console.WriteLine("Yes"); return; }
        }
        if (b[0, 0] && b[1, 1] && b[2, 2]) { Console.WriteLine("Yes"); return; }
        if (b[0, 2] && b[1, 1] && b[2, 0]) { Console.WriteLine("Yes"); return; }
        Console.WriteLine("No");
    }
}



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

int n, a[2000010], b[2000010];

void csort(int k)
{
    int c[10010];
    for(int i = 0; i < k; i++) c[i] = 0;

    for(int j = 0; j < n; j++) {
        c[a[j]]++;
    }

    for(int i = 1; i < k; i++) {
        c[i] += c[i - 1];
    }

    for(int j = n - 1; j >= 0; j--) {
        b[c[a[j]]] = a[j];
        c[a[j]]--;
    }
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);

    csort(10010);

    for(int i = 0; i < n; i++) printf("%s%d", (i ? " " : ""), b[i + 1]);
    cout << endl;

    return 0;
}



Measured memory_bytes: 18848
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

void main()
{
    auto cord = readln.split.to!(long[]);
    auto x1 = cord[0];
    auto y1 = cord[1];
    auto x2 = cord[2];
    auto y2 = cord[3];
    long vx = x2 - x1;
    long vy = y2 - y1;
    long ix = -vy;
    long iy = vx;

    writeln(x2 + ix, " ", y2 + iy, " ", x1 + ix, " ", y1 + iy);
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int N, M;

    cin >> N >> M;
    int l, r;
    int c = 0;
    int lma = 0, rmi = INF;
    REP(i, M) {
        cin >> l >> r;
        chmax(lma, l);
        chmin(rmi, r);
    }
    cout << max(rmi - lma+1,0);

    return 0;
}

Measured memory_bytes: 384
from collections import deque

A = input()
s1 = deque()
c = 0
i = 1

left = None
s2 = deque()
for a in A:
    if a == '\\':
        s1.append(i)
    elif a == '/':
        if len(s1) > 0:
            j = s1.pop()
            # 当前积水处的面积
            area = i - j
            # 加到总面积
            c += area
            while len(s2) > 0:
                t = s2.pop()
                if t[0] > j:
                    area += t[1]
                else:
                    s2.append(t)
                    break
            s2.append([j, area])
            # print(s2)
    else:
        pass
    i += 1
print(c)
print(len(s2), end='')
for t in s2:
    print(' ', end='')
    print(t[1], end='')
print()


Measured memory_bytes: 7324