akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
struct Segtree{
    int siz=1;
    vector<int>dat;
    Segtree(int n){
	    while(siz<n)siz*=2;
	    dat.resize(siz*2-1,2147483647);
    }
    void update(int k,int x){
        //Point Set
	    k+=(siz-1);
	    dat[k]=x;
	    while(k>0){
		    k=(k-1)/2;
		    dat[k]=min(dat[2*k+1],dat[2*k+2]);
	    }
    }
    int query(int a,int b,int k=0,int l=0,int r=-1){
	    if(r==-1)r=siz;
	    if(r<=a||b<=l)return 2147483647;
	    if(a<=l&&r<=b)return dat[k];
	    int vl=query(a,b,2*k+1,l,(l+r)/2);
	    int vr=query(a,b,2*k+2,(l+r)/2,r);
	    return min(vl,vr);
    }
};
signed main(){
    int n,q;
    cin>>n>>q;
    Segtree seg(n);
    while(q--){
        int type;
        cin>>type;
        if(type==0){
            int x,y;
            cin>>x>>y;
            seg.update(x,y);
        }
        if(type==1){
            int x,y;
            cin>>x>>y;
            cout<<seg.query(x,y+1)<<endl;
        }
    }
    return 0;
}



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

int main(){
  long long n, a, b;
  cin >> n >> a >> b;
  
  if(!a){
    cout << 0 << endl;
    return 0;
  }
  
  long long ans = 0;
  
  ans += a*(n/(a+b));
  if(n%(a+b) > a){
    ans += a;
  } else {
    ans += n%(a+b);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s, a = 1e9;
int main() {
    cin >> s;
    ll b = (s + a - 1) / a;
    cout << "0 0 " << a << " " << a * b - s << " 1 " << b;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

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

N = int(input())

ans = 1
for _ in range(N):
    T = int(input())
    ans = lcm(ans, T)

print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;

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

		int[][] a =	new int[1000][1000];
		int[] b = new int[1000];
		int[] c = new int[1000];

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

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

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				c[i] += a[i][j] * b[j];
			}
			System.out.println(c[i]);
		}
		sc.close();
	}
}



Measured memory_bytes: 44676
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int N = rei();
	int L = rei();
	int ans = 1000;
	int sum = 0;
	for(int i=1;i<=N;i++){
		ans = min(ans,abs(L+i-1));
		sum += L+i-1;
	}
	for(int i=1;i<=N;i++){
		if(abs(L+i-1) == ans){
			ans = sum - (L+i-1);
			break;
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

template <typename T>
struct BIT
{
    int N, K;
    vector<T> bit;

    BIT(int X)
    {
        bit = vector<T>(X + 10, 0);
        N = X + 1;
        K = pow(2, (int)(log(X) / log(2)));
    }

    void add(int idx, T w)
    {
        for (int x = idx; x <= N; x += x & -x)
        {
            bit[x] += w;
        }
    }

    T sum(int idx)
    {
        T res = 0;
        for (int x = idx; x > 0; x -= x & -x)
            res += bit[x];
        return res;
    }
};

// verified @ https://atcoder.jp/contests/arc033/submissions/3515244

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> bs(n), ws(n);
    akari<int> accb(n + 1), accw(n + 1);
    yukari<int> accb2(n, akari<int>(n + 1)), accw2(accb2);
    akari<BIT<int>> bit(2, BIT<int>(2020));
    for (int i = 0; i < 2 * n; i++)
    {
        char c;
        int a;
        cin >> c >> a;
        a--;
        if (c == 'B')
        {
            bs[a] = i;
            accb[a + 1] = a - bit[0].sum(a + 1);
            bit[0].add(a + 1, 1);
            for (int j = 0; j < n; j++)
            {
                accb2[a][j + 1] = j + 1 - bit[1].sum(j + 1);
            }
        }
        else
        {
            ws[a] = i;
            accw[a + 1] = a - bit[1].sum(a + 1);
            bit[1].add(a + 1, 1);
            for (int j = 0; j < n; j++)
            {
                accw2[a][j + 1] = j + 1 - bit[0].sum(j + 1);
            }
        }
    }
    yukari<int> dp(n + 1, akari<int>(n + 1, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
        {
            if (i < n)
            {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + max(0, bs[i] - (i + j) + accb[i + 1] + accb2[i][j]));
            }
            if (j < n)
            {
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + max(0, ws[j] - (i + j) + accw[j + 1] + accw2[j][i]));
            }
        }
    cout << dp[n][n] << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 47360
fun main(args: Array<String>) {
    val N = readInputLine().toCharArray()
    
    if ((N[0] == N[1] && N[1] == N[2]) ||
        (N[1] == N[2] && N[2] == N[3])) {
        println("Yes")    
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 29936
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	
    public static void main(String[] args) throws IOException {
    	Scanner s = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] input;
		int n = Integer.parseInt(reader.readLine());
		String c = reader.readLine();
		int ans = Integer.MAX_VALUE, r = 0, w = 0;
		for (int i = 0; i < n; i++) {
			if (c.charAt(i) == 'R') {
				r++;
			}
		}
		ans = r;
		for (int i = 0; i < n; i++) {
			if (c.charAt(i) == 'R') {
				r--;
			}
			if (c.charAt(i) == 'W') {
				w++;
			}
			ans = Math.min(ans, Math.min(r, w) + Math.abs(r - w));
		}
		out.print(ans);
		out.flush();
		out.close();
    }

}


Measured memory_bytes: 39440
#include <iostream>
#include <string>
#include<algorithm>

using namespace std;

int main()
{
	int n,k,nn;
	int x[1000];
	int y[1000];
    int z[1000];
	cin>>n>>k;

	for(int i=0;i<k;i++){
		cin>>x[i];
		cin>>y[i];
	}
	for(int i=0;i<k;i++){
	if(n-x[i]<x[i])
		x[i]=n-x[i]+1;
	if(n-y[i]<y[i])
		y[i]=n-y[i]+1;

	if(x[i]>y[i])
	    z[i]=y[i]%3;
	if(y[i]>x[i])
	    z[i]=x[i]%3;
	if(x[i]==y[i])
		z[i]=x[i]%3;
	if(z[i]==0)
		z[i]=3;
	cout<<z[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <stdio.h>
using namespace std;

struct Card
{
    char value, suit;
};

// bubble
void BubbleSort(struct Card A[], int N)
{
    for (int j = 0; j < N; j++)
    {
        for (int i = N - 1; i >= j + 1; i--)
        {
            if (A[i - 1].value > A[i].value)
            {
                swap(A[i], A[i - 1]);
            }
        }
    }
}

// selection
void SelectionSort(struct Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        int minj = i;
        for (int j = i; j < N; j++)
        {
            if (A[minj].value > A[j].value)
                minj = j;
        }
        swap(A[minj], A[i]);
    }
}

void print(struct Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i != 0)
            cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

int main()
{
    int N;
    Card C1[100], C2[100];
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        cin >> C1[i].suit >> C1[i].value;
    }
    for (int i = 0; i < N; i++)
        C2[i] = C1[i];
    BubbleSort(C1, N);
    SelectionSort(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);

    bool chk = true;
    for (int i = 0; i < N; i++)
    {
        if (C1[i].suit != C2[i].suit)
            chk = false;
    }
    if (chk)
    {
        cout << "Stable" << endl;
    }
    else
    {
        cout << "Not stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3156
n = int(input())

def search(n,num):
    i = 1
    while True:
        if n < num**i:
            return i-1
        i += 1
        
ans = n
for i1 in range(0,6):
    for i2 in range(0,6):
        for i3 in range(0,6):
            for i4 in range(0,6):
                for i5 in range(0,6):
                    for i6 in range(0,6):
                        res = n
                        res -= (6**1)*i1+(6**2)*i2+(6**3)*i3+(6**4)*i4+(6**5)*i5+(6**6)*i6
                        if res >= 0:
                            count = i1+i2+i3+i4+i5+i6
                            while res > 6:
                                i = search(res,9)
                                cnt = int(res / (9**i))
                                res -= (9**i) * cnt
                                count += cnt
                            count += res
                            if ans > count:
                                ans = count
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
int main(){
  string s;
  cin>>s;
  long int tem,m=999;
  int a,b,c,d;
  for(int i=0;i<s.length()-2;++i){
    a = s[i]-'0';
    b = s[i+1]-'0';
    c = s[i+2]-'0';
    tem = a*100 + b*10 + c;
    tem = abs(753-tem);
    m = min(m,tem);
  }

  cout<<m;
}


Measured memory_bytes: 256
using System;

class B{
  static int n;
  static int[] A;

  public static void Main(){
    n = int.Parse(Console.ReadLine());
    string[] str = Console.ReadLine().Split(' ');
    A = new int[n];
    for(int i = 0;i < n;i++){
      A[i] = int.Parse(str[i]);
    }
    int x = calc.partition(A,0,n-1);
    int l = 0;
    foreach(int y in A){
      Console.Write(y);
      l++;
      if(l == x) Console.Write(" [");
      else if(l == x + 1) Console.Write("] ");
      else if(l == n) Console.WriteLine("");
      else Console.Write(" ");
    }
  }
}

class calc{
  public static int partition(int[] A,int p,int r){
    int x = A[r];
    int i = p - 1;
    for(int j = p;j < r;j++){
      if(A[j] <= x){
        i++;
        Swap(ref A[i],ref A[j]);
      }
    }
    Swap(ref A[i+1],ref A[r]);
    return i+1;
  }
  public static void Swap(ref int x,ref int y){
    int temp;
    temp = x;
    x = y;
    y = temp;
  }
}



Measured memory_bytes: 17340
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

long long int dp[51][51][2501] = {};

int main(void) {
	int n, a;
	int x[51];
	long long int total = 0;

	cin >> n >> a;

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

	dp[0][0][0] = 1;
	

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= 2500; k++) {
				if (j == 0 || k - x[i] < 0) {
					dp[i][j][k] = dp[i - 1][j][k];
				}
				else {
					dp[i][j][k] = dp[i - 1][j - 1][k - x[i]] + dp[i - 1][j][k];
				}
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		total += dp[n][i][i*a];
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 49152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
typedef vector<int> vint;
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
char aaa[3]={'+','-','*'};
string temp[]={"(0 0) (0 0)","((0 0) 0) 0","0 (0 (0 0))","(0 (0 0)) 0"};
vint bbb[4];
vint ccc[4];

string calc(string in,int c){
	stringstream ss1;
	ss1<<in;
	int a,b;
	char t;
	ss1>>a>>t>>b;
	if(c==1) a=a+b;
	if(c==2) a=a-b;
	if(c==3) a=a*b;
	stringstream ss2;
	ss2<<a;
	string ans;
	ss2>>ans;
	if(ans[0]=='-') ans="43"; 
	return ans;
}
string foo(string s){
	int pos1=-1,pos2=-1;
	rep(i,s.size()){
		if(s[i]=='('){
			pos1=i;
		}
		else if(s[i]==')'){
			pos2=i;
			break;
		}
	}
	if(pos1!=-1) s=foo(s.substr(0,pos1)+foo(s.substr(pos1+1,pos2-pos1-1))+s.substr(pos2+1));
	int update=1;
	while(update){
		update=0;
		rep(i,s.size()){
			if(s[i]=='*'){
				update=1;
				int x=i-1,y=i+1;
				while(s[x]>='0'&&s[x]<='9'){
					x--;
					if(x==-1) break;
				}
				while(s[y]>='0'&&s[y]<='0'){
					y++;
					if(y==s.size()) break;
				}
				s=s.substr(0,x+1)+calc(s.substr(x+1,y-1)+s.substr(y-1),3);
				break;
			}
		}
	}
	update=1;
	while(update){
		update=0;
		rep(i,s.size()){
			if(s[i]=='+'||s[i]=='-'){
				update=1;
				int x=i-1,y=i+1;
				while(s[x]>='0'&&s[x]<='9'){
					x--;
					if(x==-1) break;
				}
				while(s[y]>='0'&&s[y]<='0'){
					y++;
					if(y==s.size()) break;
				}
				int ddd=2;
				if(s[i]=='+') ddd=1;
				s=s.substr(0,x+1)+calc(s.substr(x+1),ddd);
				break;
			}
		}
	}
	return s;
}
void mainmain(){
	int a,b,c,d;
	rep(i,3){
		rep(j,temp[i].size()){
			if(temp[i][j]=='0'){
				bbb[i].PB(j);
			}
			if(temp[i][j]==' '){
				ccc[i].PB(j);
			}
		}
	}
	int aa[4];
	vint v(4);
	vint tt(4);
	while(cin>>v[0]>>v[1]>>v[2]>>v[3],v[0]){
		sort(ALL(v));
		bool f=false;
		do{
			rep(i,3){
				string tmp=temp[i];
				rep(j,4){
					tmp[bbb[i][j]]+=v[j];
				}
				rep(j,3){
					tmp[ccc[i][0]]=aaa[j];
					rep(k,3){
						tmp[ccc[i][1]]=aaa[k];
						rep(l,3){
							tmp[ccc[i][2]]=aaa[l];
							if("10"==foo(tmp)){
								cout<<tmp<<endl;
								f=true;
								break;
							}
						}
						if(f) break;
					}
					if(f) break;
				}
				if(f) break;
			}
			if(f) break;
		}while(next_permutation(ALL(v)));
		if(!f) cout<<0<<endl;
	}
}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1264
#include<iostream>
#include<complex>
using namespace std;
typedef complex<double> Point;

int main() {
    int n;
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> n;
    Point z2(x2 - x1, y2 - y1);
    while (n--)
    {
        cin >> x3 >> y3;
        Point z3(x3 - x1, y3 - y1);
        Point p = z3 * conj(z2);
        if (p.imag() > 0) cout << "COUNTER_CLOCKWISE\n";
        else if (p.imag() < 0) cout << "CLOCKWISE\n";
        else if (p.real() < 0) cout << "ONLINE_BACK\n";
        else if (abs(z3) > abs(z2)) cout << "ONLINE_FRONT\n";
        else cout << "ON_SEGMENT\n";
    }
    return 0;
}


Measured memory_bytes: 3264
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

void solve() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll x = min(q*2, h);
    ll y = min(x*2, s);
    if(y*2 <= d){
        cout << y*n << endl;
    }else{
        unsigned long long res = ((n/2)*d)+(n%2)*y;
        cout << res << endl;
    }
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
S=0
B=[0]*(10**5+1)
for i in A:
    S+=i
    B[i]+=1  #Bは要素数管理
Q=int(input())
C=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    S=S+(C[i][1]-C[i][0])*B[C[i][0]]
    B[C[i][1]]=B[C[i][0]]+B[C[i][1]]
    B[C[i][0]]=0
    print(S)

Measured memory_bytes: 32688
#!/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 = I()
x = [I() for _ in range(5)]
m = min(x)
print((n-1)//m+1+4)

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

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vl a(n), f(n);
  REP(i, n)cin >> a[i];
  REP(i, n)cin >> f[i];
  sort(ALL(a));
  sort(ALL(f), greater<>());
  ll l = -1, r = INF * INF;
  while (r - l > 1) {
    ll mid = (r + l) / 2;
    ll cnt = 0;
    REP(i, n) {
      ll tar = mid / f[i];
      cnt += max(0ll, a[i] - tar);
    }
    if (cnt <= k)r = mid;
    else l = mid;
  }
  cout << r << endl;
}


Measured memory_bytes: 3456
x, k, d = map(int, input().split())

if abs(x) > d*k:
    print(abs(x) - d*k)

elif (k - abs(x)//d)%2 == 0:
    print(abs(x)%d)
    
elif (k - abs(x)//d)%2 == 1:
    print(abs(abs(x)%d - d))

Measured memory_bytes: 9168
#include<stdio.h>
#include<string.h>
int main(){
   int i,j,n,p;
   while(scanf("%d",&n)!=EOF)
   {i=n;p=0;
   while(n>0){
    p=p*10+n%10;
    n=n/10;
   }
   if(i==p)
    printf("Yes\n");
   else
    printf("No\n");}
   return 0;


}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
	int a;
	int b;
	int c;
	int d;
	cin>>a >> b >> c >> d;
	int ans = 0;
	if(a>b){
		ans += b;
	} else {
		ans += a;
	}
	if(c>d){
		ans += d;
	} else {
		ans += c;
	}


	cout<<ans<<endl;
	return 0;
}

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

Measured memory_bytes: 26020
import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        for(int i = 1; i <= 10000; i++){
            if((int)(i * 0.08) == a && (int)(i * 0.1) == b){
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
        scan.close();
    }
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 27076
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    if (s[5] == '1'){
        cout << "TBD" << endl;
    }
    else{
        if(s[6] - '0'>= 5){
            cout << "TBD" << endl;
        } 
        else{
            cout << "Heisei";
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, k; cin >> n >> k;
  vvll checker(k+1, vll(k+1, 0));
  ll x, y; char c; bool is_b;
  for (ll i=0; i<n; i++) {
    cin >> x >> y >> c;
    x %= 2*k; y %= 2*k;
    is_b = c == 'B';
    if (x >= k) {x -= k; is_b=!is_b;}
    if (y >= k) {y -= k; is_b=!is_b;}
    if (is_b) {
      checker.at(0).at(0)++;
      checker.at(y+1).at(0)--;
      checker.at(0).at(x+1)--;
      checker.at(y+1).at(x+1)+=2;
    } else {
      checker.at(y+1).at(0)++;
      checker.at(0).at(x+1)++;
      checker.at(y+1).at(x+1)-=2;
    }
  }
  for (ll i=1; i<k; i++) {
    for (ll j=0; j<k+1; j++) {
      checker.at(j).at(i) += checker.at(j).at(i-1);
    }
  }
  for (ll i=1; i<k; i++) {
    for (ll j=0; j<k+1; j++) {
      checker.at(i).at(j) += checker.at(i-1).at(j);
    }
  }
  ll ans = 0;
  for (ll i=0; i<k; i++) for (ll j=0; j<k; j++) {
    ans = max(ans, max(checker.at(i).at(j), n-checker.at(i).at(j)));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  char S;
  cin >> S;
  if (S=='a'||S=='e'||S=='u'||S=='i'||S=='o') {
    cout << "vowel"  << endl;
  }else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, i, j, k, x, count = 0;
    
    while(1) {
        scanf("%d%d", &n, &x);
        if (n == 0 && x == 0) break;
        
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++) {
                for (k = 1; k <= n; k++) {
                    if (i + j + k == x && i < j && j < k) count++;
                }
            }
        }
        printf("%d\n", count);
        count = 0;
    }
    return 0;
}


Measured memory_bytes: 2064
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	string s; cin >> s;
	cout << s.substr(0, 3) << endl;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int h, w;
  cin >> h >> w;
  vs s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(i,h) {
    rep(j,w) {
      if(s[i][j] == '#') continue;
      vii d(h,vi(w, -1));
      d[i][j] = 0;
      queue<P> q;
      q.emplace(i,j);
      while(sz(q)) {
        int y = q.front().fi;
        int x = q.front().se;
        q.pop();
        rep(dis,4) {
          int ny = y + dy[dis];
          int nx = x + dx[dis];
          if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
          if(d[ny][nx] != -1 || s[ny][nx] == '#') continue;
          d[ny][nx] = d[y][x] + 1;
          q.emplace(ny,nx);
          chmax(ans, d[ny][nx]);
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() 
{
    long long ar[26]={0},i,j,n;
    string s;
    cin>>s;
    n=s.length();
    long long ans=1+n*(n-1)/2;
    for(i=0;i<n;++i)
    ++ar[s[i]-97];
    for(i=0;i<26;++i)
    ans=ans-ar[i]*(ar[i]-1)/2;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 644
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
const int MAXN=520233;
int n,ans;
map<int,int> mp;
int main()
{
	scanf("%d",&n);
	for(int i=1,a;i<=n;++i)scanf("%d",&a),++mp[a];
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it)
	{
		pair<int,int> rec=(*it);
		if(rec.first<=rec.second)ans+=rec.second-rec.first;
		else ans+=rec.second;
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N, K);
  vector< int > A(N);
  int n;
  REP(i, N) {
    cin >> A[i];
    if (A[i] == 1) n = i;
  }

  int ans;
  N -= K;
  ans = 1;
  ans += (N + K - 2) / (K - 1);
  //int ans = (N + K - 1)/ K;
  // if (n % K == 0 || (N - n + 1) % K == 0) ans--;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long d = sc.nextLong();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            long x =sc.nextLong();
            long y =sc.nextLong();
            if (x*x + y*y <= d*d) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 60340
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    int N,buf;
    vector<int> L;
    int res=0;

    scanf("%d",&N);

    REPI(2*N){
        scanf("%d",&buf);
        L.push_back(buf);
    }

    sort(L.begin(),L.end());

    while(!L.empty()){
        L.pop_back();
        res += L.back();
        L.pop_back();
    }

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


    return 0;
}

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

map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<string> s(n);
	vector<vector<int>> a(n, vector<int>(26, 0));
	rep(i, n) {
		cin >> s.at(i);
		rep(j, s.at(i).size()) {
			a.at(i).at(s.at(i).at(j) - 'a')++;
		}
	}
	string ans = "";
	rep(i, 26) {
		int m = INT_MAX;
		rep(j, n) {
			m = min(m, a.at(j).at(i));
		}
		rep(j, m) {
			char c = 'a' + i;
			ans += c;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 != 0){
		cout << (a + b) / 2 + 1 << endl;
	}
	else{
		cout << (a + b) / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
require 'set'

class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

n, k, l  = gets.strip.split.map(&:to_i)
pq = k.times.map { gets.strip.split.map(&:to_i) }
rl = l.times.map { gets.strip.split.map(&:to_i) }

roads = UnionFind.new(n+1)
rails = UnionFind.new(n+1)

pq.each do|p, q|
  roads.unite(p, q)
end

rl.each do |r, l|
  rails.unite(r, l)
end

counter = {}
(1..n).each do|i|
  k = [rails.get_parent(i), roads.get_parent(i)].to_s
  counter[k] ||= []
  counter[k] << i
end

puts (1..n).map {|i|
  k = [rails.get_parent(i), roads.get_parent(i)].to_s
  counter[k].size
}.join(' ')




Measured memory_bytes: 81788
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	string s;
	
	while(1){
		getline(cin,s);
		long long n=0;
		int	count=0;
		if(s=="0")
			break;
		else{
			string a="";
			for(int i=0;i<s.size();i++){
				if(s[i]!=' '){
					a=a+s[i];
				}
				else{
					int b=stoi(a);
					if(b==1)
						count+=11;
					else if(b>=2&&b<=9)
						n+=b;
					else
						n+=10;
					a="";
				}
			}
			int b=stoi(a);
					if(b==1)
						count+=11;
					else if(b>=2&&b<=9)
						n+=b;
					else
						n+=10;
					a="";
			while(count>0){
				if(n+count>21)
					n++;
				else
					n=n+11;
				count-=11;
			}
			
			if(n>21)
				cout<<0<<endl;
			else
				cout<<n<<endl;
		}
	}
	
	
	
	

}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    bool hantei=false;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j == n) hantei = true;
        }
    }
    if(hantei) cout << "Yes" << endl;
    else        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>

using namespace std;
const long long int mod=1000000007;

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

	vector<long long int> a(61,0);
	long long int r=0;
	for(int i=0; i<n; i++){
		cin >> r;
		for(int j=0; j<61; j++){
			a[j]+=((r>>j)&1);
		}
	}

	long long int sum=0, t=0;
	long long int s=0;
	for(int i=0; i<61; i++){
		t=((long long int)1<<i)%mod;
		s=(a[i]*(n-a[i]))%mod;
		sum+=(t*s)%mod;
		sum%=mod;
	}

	cout << sum << endl;

	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
typedef long long int llint;

int main(void){


  llint a, b;
  std::cin >> a >> b;

  for(int i=0; i<b*100; i++){
    if(llint(i*0.08) == a && llint(i*0.10) == b){
      std::cout << i << std::endl;
      return 0;
    }
  }

  std::cout << -1 << std::endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf0 := strings.Split(scanner.Text(), " ")
		input0 := make([]int, 2)
		for i := range input0 {
			input0[i], _ = strconv.Atoi(buf0[i])
		}
		if input0[0] == 0 && input0[1] == 0 {
			break
		}
		a, b := input0[0], input0[1]
		scanner.Scan()
		buf1 := strings.Split(scanner.Text(), " ")
		input1 := make([]int, 2)
		for i := range input1 {
			input1[i], _ = strconv.Atoi(buf1[i])
		}
		c, d := input1[0], input1[1]
		scanner.Scan()
		buf2 := strings.Split(scanner.Text(), " ")
		input2 := make([]int, 2)
		for i := range input2 {
			input2[i], _ = strconv.Atoi(buf2[i])
		}
		e, f := input2[0], input2[1]
		scanner.Scan()
		buf3 := strings.Split(scanner.Text(), " ")
		input3 := make([]int, 2)
		for i := range input3 {
			input3[i], _ = strconv.Atoi(buf3[i])
		}
		g, h := input3[0], input3[1]
		scanner.Scan()
		r, _ := strconv.Atoi(scanner.Text())
		if (a-g)*(a-g)+(b-h)*(b-h) <= r*r && (c-g)*(c-g)+(d-h)*(d-h) <= r*r && (e-g)*(e-g)+(f-h)*(f-h) <= r*r {
			fmt.Println("b")
		} else if dist(a, b, c, d, g, h) > float64(r)-0.000001 && dist(a, b, e, f, g, h) > float64(r)-0.000001 && dist(e, f, c, d, g, h) > float64(r)-0.000001 && inclusive(a, b, c, d, e, f, g, h) {
			fmt.Println("a")
		} else if CL_intersect(a, b, c, d, g, h, r) || CL_intersect(a, b, e, f, g, h, r) || CL_intersect(e, f, c, d, g, h, r) {
			fmt.Println("c")
		} else {
			fmt.Println("d")
		}
	}
}

func CL_intersect(ax, ay, bx, by, cx, cy, r int) bool {
	acx := cx - ax
	acy := cy - ay
	bcx := cx - bx
	bcy := cy - by
	abx := bx - ax
	aby := by - ay
	if acx*acx+acy*acy >= r*r || bcx*bcx+bcy*bcy >= r*r {
		if abx*acx+aby*acy < 0 {
			if acx*acx+acy*acy <= r*r {
				return true
			}
		} else {
			if abx*acx+aby*acy > abx*abx+aby*aby {
				if bcx*bcx+bcy*bcy <= r*r {
					return true
				}
			} else if acx*acx+acy*acy-(abx*acx+aby*acy)*(abx*acx+aby*acy)/(abx*abx+aby*aby) <= r*r {
				return true
			}
		}
	}
	return false
}

func inclusive(ax, ay, bx, by, cx, cy, px, py int) bool {
	ok1 := true
	ok2 := true
	if (bx-ax)*(py-ay)-(px-ax)*(by-ay) < 0 {
		ok1 = false
	}
	if (bx-ax)*(py-ay)-(px-ax)*(by-ay) > 0 {
		ok2 = false
	}
	if (cx-bx)*(py-by)-(px-bx)*(cy-by) < 0 {
		ok1 = false
	}
	if (cx-bx)*(py-by)-(px-bx)*(cy-by) > 0 {
		ok2 = false
	}
	if (ax-cx)*(py-cy)-(px-cx)*(ay-cy) < 0 {
		ok1 = false
	}
	if (ax-cx)*(py-cy)-(px-cx)*(ay-cy) > 0 {
		ok2 = false
	}
	return ok1 || ok2
}

func dist(ax, ay, bx, by, px, py int) float64 {
	dx := float64(bx - ax)
	dy := float64(by - ay)
	A := float64(dx*dx + dy*dy)
	B := dx*float64(ax-px) + dy*float64(ay-py)
	t := -B / A
	if t < 0 {
		t = 0
	}
	if t > 1 {
		t = 1
	}
	tx := float64(ax) + dx*t
	ty := float64(ay) + dy*t
	return math.Sqrt((float64(px)-tx)*(float64(px)-tx) + (float64(py)-ty)*(float64(py)-ty))
}



Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll solve(vector<int> A){
  int N = A.size();

  if(A[0] != 0) return -1;

  vector<vector<int>> v;
  vector<int> tmp;
  tmp.push_back(A[0]);
  REP(i,1,N){
    if(i < A[i]) return -1;
    if(A[i] < A[i-1]){
      v.push_back(tmp);
      tmp.clear();
    }
    tmp.push_back(A[i]);
  }
  v.push_back(tmp);

  ll ret = 0;
  rep(i,v.size()){
    tmp = v[i];
    if(tmp.size() == 0) continue;
    int base = tmp[0];
    map<int,int> cnt;
    rep(j,tmp.size()){
      if(tmp[j]-base == 0 || tmp[j]-base == 1){
        cnt[tmp[j]]++;
        base = tmp[j];
      }else{
        return -1;
      }
    }
    int mx = 0;
    FOR(it,cnt){
      mx = max(mx, it->first);
    }
    FOR(it,cnt){
      if(it->first == mx){
        ll a = it->first;
        a *= it->second;
        ret += a;
      }else{
        ll a = it->first;
        a *= it->second-1;
        ret += a;
      }
    }
  }

  return ret;
}



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

  vector<int> A;
  rep(i,N){
    int a;
    cin >> a;
    A.push_back(a);
  }

  cout << solve(A) << endl;
  
  return 0;
}



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

int	main(void)
{
	int x, y;
	cin >> x >> y;
	for (int i = 0; i <= x; i++)
	{
		if (2 * i + 4 * (x - i) == y)
		{
			cout << "Yes" << endl;
			return (0);
		}
	}
	cout << "No" << endl;
	return (0);
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
vector<int> adj[100001];
vector<ll> w(100001);
vector<ll> b(100001);
void dfs(int i,int par){
	ll z1=1,z2=1;
	for(int j=0;j<adj[i].size();j++){
		if(adj[i][j]==par)
		continue;
		dfs(adj[i][j],i);
		z1=(z1*w[adj[i][j]])%mod;
		z2=(z2*(w[adj[i][j]]+b[adj[i][j]]))%mod;
	}
	w[i]=z2;
	b[i]=z1;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1,0);
	cout<<(w[1]+b[1])%mod;
	return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> t(N+1);
  std::vector<int> x(N+1);
  std::vector<int> y(N+1);

  t[0] = 0;
  x[0] = 0;
  y[0] = 0;

  for(int i=0; i<N; i++) {
    int ti, xi, yi;
    std::cin >> ti >> xi >> yi;
    t[i+1] = ti;
    x[i+1] = xi;
    y[i+1] = yi;
  }

  for(int i=0; i<N; i++) {
    int dt = t[i+1] - t[i];
    int dx = std::abs(x[i+1] - x[i]);
    int dy = std::abs(y[i+1] - y[i]);
    if(dt < (dx + dy) || dt%2 != (dx+dy)%2) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 1408
package main

import "fmt"

func main() {
	var a, b, c, v int
	fmt.Scan(&a, &b, &c)

	for a&1 == 0 && b&1 == 0 && c&1 == 0 {
		v++
		a, b, c = (b+c)/2, (a+c)/2, (a+b)/2
		if a == b && b == c {
			v = -1
			break
		}
	}
	fmt.Println(v)
}


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

using namespace std;

int main()
{
  vector<int> A(5);
  for (int i = 0; i < 5; i++) {
    cin >> A[i];
  }
  int K;
  cin >> K;

  sort(A.begin(), A.end());

  if (A[4] - A[0] > K) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    vector <ll> bs;
    REP(i, n){
        bs.push_back(as[i]-i);
    }
    map<ll, ll> bm;
    REP(i, n){;
        bm[as[i]+i]++;
    }
    ll ans = 0;
    REP(i, n){
        ans += bm[bs[i]*-1];
    }
    vector <ll> cs;
    REP(i, n){
        cs.push_back(as[i]+i);
    }
    map<ll, ll> cm;
    REP(i, n){;
        cm[as[i]-1]++;
    }
    REP(i, n){
        ans += cm[cs[i]*-1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 53136
import java.util.*;

public class Main {

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

		int[] pri = new int[55000];
		for(int i=2;i<=51000;i++){
			pri[i] = i;
		}

		for(int i=2;i<=51000;i++){
			for(int j=i+i;j<=51000;j+=i){
					pri[j]=0;
			}
		}
		
		while(sc.hasNext()){
			int n = sc.nextInt();

			for(int i=n-1;;i--){
				if(pri[i]>0){
					System.out.print(pri[i]);
					break;
				}
			}
			for(int i=n+1;;i++){
				if(pri[i]>0){
					System.out.println(" " + pri[i]);
					break;
				}
			}
			
		}
	}
}

Measured memory_bytes: 19868
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll A,B,C,K; cin >> A >> B >> C >> K;
    ll ans = 0;
    ll a = min(A,K);
    ans += a;
    K -= a;
    ll b = min(B,K);
    K -= b;
    ans -= K;
    cout << ans << ln;
}

Measured memory_bytes: 3664
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;
int main(){
    fastio
    int n ;
    cin >> n ; 
    vector<pair<int,int> > v(n) ; 
    for(int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second ; 
    }
    sort(v.begin() ,v.end()) ; 
    int cnt = 0 ;
    long double dist = 0;
    do{
        cnt++ ; 
        for(int i = 1; i < n; i++){
            dist += sqrt((v[i].first - v[i - 1].first)*(v[i].first - v[i - 1].first) + (v[i].second - v[i - 1].second)*(v[i].second - v[i - 1].second)) ; 
        }
    }while(next_permutation(v.begin(), v.end())) ;
    long double ans = dist / (double) cnt ; 
    cout << fixed << setprecision(12) << ans << endl;
    return 0 ; 
}

Measured memory_bytes: 256