akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const char *sign(int a, int b)
{
    if (a > b)
        return ">";
    else if (a < b)
        return "<";
    else
        return "==";
}

int main()
{
    int a, b;

    cin >> a >> b;

    cout << "a " << sign(a, b) << " b" << endl;

    return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
long long n, m, i, j, k, t=0, A=0, b=0, c=0;
long long a[100010];
vector<int> ok; 
int main(){
	cin>>n;
	a[0]=0;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++){
		if(a[i]==a[i-1]){
			ok.push_back(a[i]);
			t++;
		}
	}
	if(t>=1) A=ok[t-1];
	if(t>=2) b=ok[t-2];
	if(t>=3) c=ok[t-3];
	if(b==0||(A==b&&c==0)){
		cout<<0;
		return 0;
	}
	if(A==b&&A==c) cout<<A*A;
	else{
		if(A==b) cout<<A*c;
		else cout<<A*b;
	}
	return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	ll n;
	int x, m;
	cin >> n >> x >> m;
	vector<int> id(m, -1);
	vector<int> a;
	int len = 0;
	ll total = 0;
	while (id[x] == -1) {
		a.push_back(x);
		len++;
		id[x] = len;
		total += x;
		x = (ll)x * x % m;
	}
	ll ans = 0;
	if (n < len) {
		for (int i = 0; i < n; i++) ans += a[i];
	}
	else {
		ans += total;
		n -= len;
		int c_len = len - id[x] + 1;
		ll c_total = 0;
		for (int i = id[x]; i <= len; i++) c_total += a[i - 1];
		ans += (n / c_len) * c_total;
		n %= c_len;
		for (int i = 0; i < n; i++) ans += a[id[x] + i - 1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3900
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	vector<int> order(N);
	foreach(i, order)cin>>i;
	int sum = 0;
	REP(i, N){
		int d;
		cin >> d;
		sum += d;
	}
	vector<int> adder(N-1);
	foreach(i, adder)cin>>i;
	REP(i, N-1){
		if(order[i] + 1 == order[i+1]){
			sum += adder[order[i]-1];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
//gcd(x, y) -> xとyの最大公約数
int gcd(int x, int y){
    return y ? gcd(y, x % y) : x;
}
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   vector<int> a(n);
   rep(i,n)cin >> a[i];
   vector<int> v1, v2;
   v1.push_back(a[0]);
   v2.push_back(a[n-1]);
   rep(i,n-1){
      v1.push_back(gcd(v1[i], a[i+1]));
      v2.push_back(gcd(v2[i], a[n-i-2]));
   }
   int ans = max(v1[n-2], v2[n-2]);
   rep(i,n-2){
      ans = max(ans, gcd(v1[i], v2[n-i-3]));
   }
   cout << ans << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    map<int,int> mp;
    ll ans=0;
    rep(i,n) {
        ans+=mp[i-a[i]];
        ++mp[i+a[i]];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 21800
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
   //  String[] O=sc.nextLine().split(" ");
//     String[] E=sc.nextLine().split(" ");

int n=Integer.parseInt(nyuA);

//int H=Integer.parseInt(O[0]);
//int W=Integer.parseInt(O[1]);

int[] num=new int[n];

for(int i=0;i<n;i++){
num[i]=Integer.parseInt(sc.nextLine())-1;
}

int count=0;
int flag=0;
int res=-1;
int button=0;
while(true){
count=num[count];
button++;
if(count==1){
res=button;
break;
}
if(button>=n+2)break;
}

System.out.println(res);



//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 98400
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,m,k,one,two;
bool gotit[100001];
int arr[100001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for (int i=0;i<m;i++){
        string s;
        cin>>k>>s;
        if (gotit[k]) continue;
        if (s=="AC"){
            gotit[k]=true;
        }
        else {
            arr[k]++;
        }
    }
    for (int i=1;i<=n;i++){
        if (gotit[i]){
            one++;
            two+=arr[i];
        }
    }
    cout<<one<<' '<<two;
}

Measured memory_bytes: 896
#include<stdio.h>
 
static const int N = 1000;
 
void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}
 
int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);
 
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
   
  
  for(i=1; i<=n; i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    trace(A, n);
  }
  return 0;
}

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

int main() {
  int N,L;
  cin >> N >> L;
  vector<string> A(N);
  for(int i=0;i<N;i++) cin >> A.at(i);
  sort(A.begin(),A.end());
  string sum="";
  for(int i=0;i<N;i++){
    sum+=A.at(i);
  }
  cout << sum << endl;
  
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - Alchemist
https://atcoder.jp/contests/abc138/tasks/abc138_c

"""
import sys


def solve(N, values):
    while len(values) > 1:
        values.sort()
        x = values.pop(0)
        y = values.pop(0)
        values.append((x + y) / 2)
    return values[0]


def main(args):
    N = int(input())
    values = [int(v) for v in input().split()]
    ans = solve(N, values)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        int ma=0,mi=10000,sum=0,n,si,i;
        Scanner s = new Scanner(System.in);
        while(true){
           n = s.nextInt();
           if(n==0)break;
           for(i=0;i<n;i++){
            si = s.nextInt();
            sum += si;
            if(ma<si)ma = si;
            if(mi>si)mi = si;
           }
           System.out.println((sum-ma-mi)/(n-2));
           sum=0;
           ma=0;
           mi=10000;
        }
    }
}


Measured memory_bytes: 28876
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool dp1[4005][16005];
bool dp2[4005][16005];

int main() {
    string str;
    int x, y;
    cin >> str >> x >> y;

    vector<int> D;
    int tmp = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'T') {
            D.push_back(tmp);
            tmp = 0;
        } else {
            ++tmp;
        }
    }
    D.push_back(tmp);

    vector<int> odd;
    vector<int> even;
    for (int i = 0; i < D.size(); ++i) {
        if (i % 2 == 0) {
            even.push_back(D[i]);
        } else {
            odd.push_back(D[i]);
        }
    }

    // -8002したのが実際の座標
    dp1[0][8002] = true;
    for (int i = 0; i < even.size(); ++i) {
        for (int j = 0; j < 16005; ++j) {
            if (j - even[i] >= 0) dp1[i+1][j] |= dp1[i][j - even[i]];
            if (i > 0 && j + even[i] < 16005) dp1[i+1][j] |= dp1[i][j + even[i]];
        }
    }

    if (!dp1[even.size()][x + 8002]) {
        cout << "No" << endl;
        return 0;
    }

    dp2[0][8002] = true;
    for (int i = 0; i < odd.size(); ++i) {
        for (int j = 0; j < 16005; ++j) {
            if (j - odd[i] >= 0) dp2[i+1][j] |= dp2[i][j - odd[i]];
            if (j + odd[i] < 16005) dp2[i+1][j] |= dp2[i][j + odd[i]];
        }
    }

    if (!dp2[odd.size()][y + 8002]) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 125184
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=sorted(list(map(int,input().split())))
process = []
for i in range(N-2):
    tmp = A.pop()
    y=A.pop()
    A.append(tmp)
    if y>=0:
        process.append([A[0],y])
        A[0]-=y
    else:
        process.append([A[-1],y])
        A[-1]-=y
process.append([A[-1],A[0]])
print(A[-1]-A[0])
for pro in process:
    print(*pro)


Measured memory_bytes: 25076
#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    proconio::input! {
        W: usize,
        H: usize,
        M: usize,
        B: [(usize, usize); M],
    }

    let mut xmax = 0;
    let mut ymax = 0;

    let mut xmap = std::collections::HashMap::new();
    let mut ymap = std::collections::HashMap::new();

    for &(x, y) in &B {
        let xn = xmap.entry(x).or_insert(0);
        let yn = ymap.entry(y).or_insert(0);

        *xn += 1;
        *yn += 1;

        xmax = std::cmp::max(xmax, *xn);
        ymax = std::cmp::max(ymax, *yn);
    }

    let xn = xmap.iter().filter(|(&k, &v)| v == xmax).count();
    let yn = ymap.iter().filter(|(&k, &v)| v == ymax).count();
    let nn = B.iter().filter(|(x, y)| xmap[x] == xmax && ymap[y] == ymax).count();

    let ans = xmax + ymax - (if xn * yn == nn { 1 } else { 0 });

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

Measured memory_bytes: 32316
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  ll n;
  cin >> n;
  vector<int> a;
  int k = 1;
  if (n == 0) {
    cout << 0 << endl;
  } else {
    while (n != 0) {
      int k = n % 2;
      if (k < 0) k = 1;
      n = (n - k) / (-2);
      a.push_back(k);
    }

    for (int i = a.size() - 1; i >= 0; i--) {
      cout << a[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ci cin>>
#define co cout<<
#define l <<endl
#define mp make_pair
#define v vector<int> v;
#define vv vector<vector<int>> vv
#define v_print for(auto x:v){cout<<x<<"\n";}
#define floop(i,a,b) for(int i=a;i<b;i++)
#define w(n) while(n--)
#define mod 1000000007
using namespace std;

//int dp[100003];


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;	ci n;
	ll A[n],B[n],C[n],dp[3],ans,a,b,c;
	floop(i,0,n)
	{
		ci A[i]>>B[i]>>C[i];
	}
	a=dp[0]=A[0];
	b=dp[1]=B[0];
	c=dp[2]=C[0];
	floop(i,1,n)
	{
		if(dp[0]+B[i]>b) b=dp[0]+B[i];
		if(dp[0]+C[i]>c) c=dp[0]+C[i];

		if(dp[1]+A[i]>a)	a=dp[1]+A[i];
		if(dp[1]+C[i]>c)	c=dp[1]+C[i];

		if(dp[2]+A[i]>a)	a=dp[2]+A[i];
		if(dp[2]+B[i]>b)	b=dp[2]+B[i];

		dp[0]=a;
		dp[1]=b;
		dp[2]=c;
		//co a<<" "<<b<<" "<<c<<endl;
	}

	ans=max(b,c);
	ans=max(ans,a);
	co ans;

	

}

Measured memory_bytes: 2560
S = input()
X, Y = map(int, input().split())

SIZE = 10 ** 4

M = [0] if S[0] == "T" else []
for i in range(1, len(S)):
  if S[i] != S[i-1]:
    M.append(i)
M.append(len(S))
M = [0] + M
#print("M:", M)

L = []
for i in range(1, len(M)):
  L.append(M[i] - M[i - 1])
#print("L:", L)

for i in range(3, len(L), 2):
  L[i] += L[i - 2]
L = [0] + L
#print("L:", L)

x = 1 << SIZE
y = 1 << SIZE
#print("x:", bin(x)[2::])
#print("y:", bin(y)[2::])

for i in range(1, len(L), 2):
  dist = L[i]
  dirc = L[i - 1]
  #print("dist, dirc:", dist, dirc)
  if i == 1:
    x = x << dist
  else:
    if dirc % 2 == 0:
      x = (x << dist) | (x >> dist)
    else:
      y = (y << dist) | (y >> dist)
      
if (x >> SIZE + X) & 1 == 1 and (y >> SIZE + Y) & 1 == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 41036
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int N;
long long a[300010];
long long MOD = 1000000007;


int main()
{
	scanf("%d", &N);
	for (int i = 0 ; i < N ; i++)
	{
		scanf("%lld", &(a[i]));
	}
	
	long long ans = 0;
	long long base = 1;
	for (int i = 0 ; i <= 60 ; i++)
	{
		long long oneCount = 0;
		long long zeroCount = 0;
		for (int i = 0 ; i < N ; i++)
		{
			if (a[i] % 2 == 0)
				zeroCount++;
			else
				oneCount++;
			a[i] = a[i] / 2;
		}
		
		long long section = 0;
		section = (oneCount * zeroCount) % MOD;
		section = (section * base) % MOD;
		ans = (ans + section) % MOD;
		base = (base * 2) % MOD;
	}
	
	printf("%lld\n", ans);
		
	return 0;
}


//竖起来算，拆分成每位来计算 

Measured memory_bytes: 2560
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
vector<int> fri[100000];
vector<int> blo[100000];
int frindex[100000];
int frindexcounter[100000];
int blocounter, fricounter[100000];
int main() {
	
	//A
	int n;
	cin >> n;
	cout << (int)((n+1) / 2) << endl;
	return 0;

	//B
	/*int a[3][3];
	int i, j, k;
	for (i = 0; i < 3; i++) {
		for (j = 0;j< 3; j++) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	int b;
	for (i = 0; i < n; i++) {
		cin >> b;
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 3; k++) {
				if (a[j][k] == b) {
					a[j][k] = -1;
				}
			}
		}
	}
	for (i = 0; i < 3; i++) {
		if (a[i][0] * a[i][1] * a[i][2] == -1) {
			cout << "Yes" << endl;
			return 0;
		}
		if (a[0][i] * a[1][i] * a[2][i] == -1) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (a[0][0] * a[1][1] * a[2][2] == -1) {
		cout << "Yes" << endl;
		return 0;
	}
	if (a[0][2] * a[1][1] * a[2][0] == -1) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;*/
	//C
	/*int n, m;
	int s[3] = { -1,-1,-1 };
	int a, b;
	int i;
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		if (s[a - 1] == -1) {
			s[a - 1] = b;
		}
		else {
			if (s[a - 1] != b) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	if (n == 3) {
		if (s[0] == 0) {
			cout << -1 << endl;
			return 0;
		}
		else if (s[0] == -1) {
			a = 100;
		}
		else {
			a = s[0] * 100;
		}
		if (s[1] == -1) {
			
		}
		else {
			a = a + s[1] * 10;
		}
		if (s[2] == -1) {

		}
		else {
			a = a + s[2];
		}
	}
	else if (n == 2) {
		if (s[0] == 0) {
			cout << -1 << endl;
			return 0;

		}
		else if (s[0] == -1) {
			a = 10;
		}
		else {
			a = s[0] * 10;
		}
		if (s[1] == -1) {

		}
		else {
			a = a + s[1] * 1;
		}
	}
	else {
		if (s[0] == -1) {
			a = 0;
		}
		else {
			a = s[0];
		}
	}
	cout << a << endl;
	return 0;*/
	//D
	/*int n, m, k;
	cin >> n >> m >> k;

	int i, j, a, b;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		fri[a - 1].push_back(b - 1);
		fri[b - 1].push_back(a - 1);
	}
	for (i = 0; i < k; i++) {
		cin >> a >> b;
		blo[a - 1].push_back(b - 1);
		blo[b - 1].push_back(a - 1);
	}

	for (i = 0; i < n; i++) {
		frindex[i] = -1;
		frindexcounter[i] = 0;
	}
	queue<int> que;
	int index = 0;
	for (i = 0; i < n; i++) {
		if (frindex[i] == -1) {
			frindex[i] = index;
			que.push(i);
			while (que.size()) {
				j = que.front(); que.pop();
				for (a = 0; a < fri[j].size(); a++) {
					if (frindex[fri[j][a]] == -1) {
						que.push(fri[j][a]);
						frindexcounter[index]++;
						frindex[fri[j][a]] = index;
					}
				}
			}
			index++;
		}
	}

	for (i = 0; i < n; i++) {
		blocounter = 0;
		for (j = 0; j < blo[i].size(); j++) {
			if (frindex[blo[i][j]] ==frindex[i]) {
				blocounter++;
			}
		}
		fricounter[i] = frindexcounter[frindex[i]] - fri[i].size() - blocounter;
		
	}
	for (i = 0; i < n; i++) {
		cout << fricounter[i] << ' ';
	}
	return 0;*/

}

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

long long int calsum(long long int num){
long long int sum=0;
while(num!=0){

    sum=sum+num%10;
    num=num/10;
}
return(sum);}

int main(void){
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
long long int n,a,b,val,sum,i;
cin>>n>>a>>b;

for(i=1;i<=n;i++){
    val=calsum(i);
    if(val>=a && val<=b){
    sum=sum+i;}
}
    cout<<sum;
return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;
int cnt0[100010],cnt1[100010];
int main() {
  int N,K; cin >> N >> K;
  string s; cin >> s;
  s = '2' + s;
  vector<int> A;
  
  for ( int i = 1; i < s.length(); i++ ) {
    if ( s[i] == '0') {
      cnt0[i] = cnt0[i-1]+1;
    } else if ( s[i] == '1' ) {
      cnt1[i] = cnt1[i-1]+1;
    }
  }

  for ( int i = 1; i < s.length(); i++ ) {
    if ( cnt0[i] > 0 && cnt0[i+1] == 0 ) A.push_back(-1*cnt0[i]);
    else if ( cnt1[i] > 0 && cnt1[i+1] == 0 ) A.push_back(cnt1[i]);
  }

  int count = 0;
  for ( int i = 0; i < A.size(); i++ ) {
    if ( A[i] < 0 ) count++;
  }
  
  if ( count <= K ) {
    cout << N << endl;
    return 0;
  }
  int ans = 0;
  int cnt = 0;
  int l = 0,r = 0;
  int sum = 0;
    while(1) {
      if ( r == A.size() ) break;      
      while(1) {
	
	if ( A[r] > 0 && cnt <= K) {
	  sum += A[r++];
	  if ( cnt == K || r == A.size() ) break;
	} else if ( A[r] < 0 && cnt < K ) {
	  sum += abs(A[r++]);
	  cnt++;
	  if ( r == A.size() ) break;
	}
      }

      if ( cnt == K ) ans = max(sum,ans);
      
      while( cnt == K ) {
	//if ( l == A.size() ) break;
	if ( A[l] < 0 ) {
	  sum += A[l++];
	  cnt--;
	}else if ( A[l] > 0 ) sum -= A[l++];
      }
      
    }

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


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

using namespace std;

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define MAXN 100000
int table[MAXN+5];
int l[MAXN+5];
int r[MAXN+5];

int main(int argc, char const *argv[])
{
	#ifdef DBG
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
	#endif

	int num,tmp,ans;
	while( ~scanf("%d",&num) ){
		
		for(int i = 0 ; i < num ; i++ )
			scanf("%d",&table[i]);
		
		if( num == 2 ){
			printf("%d\n", max(table[0],table[1]) );
			continue;
		}

		l[0] = table[0];
		for(int i = 1 ; i < num ; i++ )
			l[i] = __gcd(l[i-1],table[i]);
		r[num-1] = table[num-1];
		for(int i = num-2 ; i >= 0 ; i-- )
			r[i] = __gcd(r[i+1],table[i]);

		ans = max(r[1],l[num-2]);
		for(int i = 1 ; i < num-1 ; i++ ){
			int tmp = __gcd(l[i-1],r[i+1]);
			if( tmp > ans )
				ans = tmp;
		}

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

	}


	return 0;
}

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

using namespace std;

using ll = long long;

const int MX = 607;

vector<pair<int, int> > e;

void load(int x) {
    for (int i = -MX; i <= MX; i++) {
        for (int j = -MX; j <= MX; j++) {
            if (i * i + j * j == x) {
                e.emplace_back(i, j);
            }
        }
    }
}

bool was[MX][MX];
int cl[2][MX][MX];

void dfs(int x, int y, int n, int id, int cc) {
    cl[id][x][y] = cc;
    was[x][y] = true;
    for (const auto& d : e) {
        int nx = x + d.first, ny = y + d.second;
        if (nx < 0 || nx >= n || ny < 0 || ny >= n) {
            continue;
        }
        if (!was[nx][ny]) {
            dfs(nx, ny, n, id, cc ^ 1);
        }
    }
}

int cnt[2][2];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, d1, d2;
    cin >> n >> d1 >> d2;
    load(d1);
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            if (!was[i][j]) {
                dfs(i, j, n + n, 0, 0);
            }
        }
    }
    e.clear();
    load(d2);
    memset(was, 0, sizeof(was));

    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            if (!was[i][j]) {
                dfs(i, j, n + n, 1, 0);
            }
        }
    }

    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            cnt[cl[0][i][j]][cl[1][i][j]]++;
        }
    }

    int a = 0, b = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            if (cnt[i][j] > cnt[a][b]) {
                a = i;
                b = j;
            }
        }
    }
    int pr = 0;
    for (int i = 0; i < n + n; i++) {
        for (int j = 0; j < n + n; j++) {
            if (cl[0][i][j] == a && cl[1][i][j] == b && pr < n * n) {
                cout << i << " " << j << "\n";
                pr++;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 32256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl
#define sz(a) (ll)(a.size())
#define endl "\n"

//dp[k][mask] - 0..(k-1) (total k) people have been assigned task,
// we have to assign task to person at kth index (k+1th person)
// mask is a binary number whose ith bits tells whether the ith task is assigned or not
ll dp[1LL<<22],a[25][25];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,0,n){
    forn(j,0,n){
      cin>>a[i][j];
    }
  }
  dp[0]=1;
  for(ll mask=0;mask < (1LL<<n);mask++){
    ll x=__builtin_popcount(mask);
    for(ll k=0;k<n;k++){
      if((mask&(1LL<<k))==0 && a[x][k]==1){
        ll m2=(mask|(1LL<<k));
        dp[m2]=(dp[m2]+dp[mask])%mod;
      }
    }
  }
  //forn(i,0,(1LL<<n)) cout<<dp[i]<<" ";
  //cout<<endl;
  ll ans=dp[(1LL<<n)-1];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 18816
#include <algorithm>
#include <cstdio>
const int MAXN = 5005;
char S[MAXN];
int dp[MAXN][MAXN];
int N;

int solve() {
  for (int j = 0; j <= N; ++j) {
    dp[0][j] = 0;
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j <= N; ++j) {
      if ((i == j) || (S[i] != S[j])) {
        dp[i][j] = 0;
      } else if (S[i] == S[j]) {
        dp[i][j] = std::min(dp[i-1][j-1] + 1, j - i);
        ret = std::max(dp[i][j], ret);
      }
    }
  }
  return ret;
}

int main() {
  scanf(" %d%s", &N, S+1);
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 96768
import java.util.Scanner;

public class Main {
	final static long MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] T = new long[N];
		long[] A = new long[N];
		for (int i=0; i<N; i++) T[i] = sc.nextLong();
		for (int i=0; i<N; i++) A[i] = sc.nextLong();
		//
		long[] B = new long[N];
		for (int i=0; i<N; i++) B[i] = min(T[i], A[i]);
		long ans = 0;
		if (max(T)==max(A) && max(T)==max(B)) {
			ans = 1;
			int top = indexOf(B, max(B));
			for (int i=1; i<=top; i++) {
				if (B[i-1]!=B[i]) continue;
				ans *= B[i];
				if (ans>MOD) ans %= MOD;
			}
			for (int i=B.length-2; i>top; i--) {
				if (B[i+1]!=B[i]) continue;
				ans *= B[i];
				if (ans>MOD) ans %= MOD;
			}
		}
		//
		System.out.println(ans);
		sc.close();
	}
	
	static long min(long a, long b) {
		return a<b ? a:b;
	}
	
	static long max(long[] array) {
		long max = Long.MIN_VALUE;
		for (int i=0; i<array.length; i++) {
			if (array[i]>max) max = array[i];
		}
		return max;
	}
	
	static int indexOf(long[] a, long m) {
		for (int i=0; i<a.length; i++) {
			if (a[i]==m) return i;
		}
		return -1;
	}
}


Measured memory_bytes: 70360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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(){
    ll n,q; cin>>n>>q;
    vector<vector<ll>> edge(n+1);
    rep(i,n-1){
        ll a,b; cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<ll> res(n+1,0);
    rep(i,q){
        ll p,x; cin>>p>>x;
        res[p]+=x;
    }
    map<ll,ll> used;
    queue<ll> que;
    que.push(1);
    while(!que.empty()){
        ll node=que.front();
        que.pop();
        used[node]=1;
        for(ll i: edge[node]){
            if(used[i]==0){
                que.push(i);
                res[i]+=res[node];
            }
        }
    }
    rep(i,n) cout<<res[i+1]<<' ';
    cout<<endl;
    return 0;
}

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

int main(){
  int n, t; cin >> n >> t;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  int ans = t;
  for(int i = 1; i < n; i++){
    ans += min(a.at(i) - a.at(i-1), t);
  }
  cout << ans << endl;
}
      

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

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int choco = 0;
    for (int i = 0; i < n; i++) {
        if (d%a[i] != 0) choco += d/a[i] + 1;
        else choco += d/a[i];
    }
    cout << choco + x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//written by thidailoc
using namespace std;				//team three wolves
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a, x) 	memset(a, x, sizeof a)
#define prec(n) 	fixed<<setprecision(n)
#define pb(i)	    push_back(i)
#define popb()    	pop_back()
#define sc(a) 	    scanf("%lld",&a)
#define sc2(a,b)    scanf("%lld%lld",&a,&b)
#define pr(a)	    printf("%lld ",a)
#define pr2(a,b)    printf("%lld %lld",a,b)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)	lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x) 		(x).begin(), (x).end()
#define sz(a) 		(ll)a.size()
#define le			length()						
#define re 			return 	
#define	mp(a,b)  	make_pair(a,b)
#define se			second
#define fi			first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)

double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17;

ll arr[100005];

ll Solves(){
	//INPUT;
	ll n,k,cnt=0,ans=0,x,y,query,l,r;
	// PROCESSING IN HERE
	string s;
	cin>>s;
	fu(i,0,s.le){
		if(arr[s[i]])re cout<<"no",0;
		arr[s[i]]=1;		
	}
	cout<<"yes";
	re 0;
}


int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	Solves();
}

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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 1e9+7;

ll n;
map<ll, int> mp;
int ans=0;

int bs(int x){
  int ans=1;
  for(int i=x; i>0; i/=2){
    while((ans+i+1)*(ans+i)/2<=x){
      ans+=i;
    }
  }
  return ans;
}

int main(){
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0); cin.tie();
  cin.exceptions(cin.failbit);

  cin >> n;
  for(ll i=2; i*i<=n; i++){
    while(n%i==0){
      n/=i;
      mp[i]++;
    }
  }
  if(n>1) mp[n]++;
  trav(p, mp){
    ans+=bs(p.second);
  }
  cout << ans;
}

Measured memory_bytes: 3656
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

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

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

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

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

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

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

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

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int H, A;
    std::cin >> H >> A;
    std::cout << (H + A - 1) / A << std::endl;
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<ll> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    ll ans = 0;
    for(int i = 0; i < n; i++){
        auto ite1 = lower_bound(ALL(a), b[i]);
        auto ite2 = upper_bound(ALL(c), b[i]);
        ans += (ite1 - a.begin()) * (c.end() - ite2);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i) >> b.at(i);

    vector<pair<int,int> > ba(n);
    for(int i = 0;i < n;i ++){
        ba.at(i).first = b.at(i);
        ba.at(i).second = a.at(i);
    }

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

    int keika = 0;
    for(int i = 0;i < n;i ++){
        keika += ba.at(i).second;
        if(keika > ba.at(i).first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 6528
#include <iostream>

using namespace std;

void reverse(int *array, int length) {
	int i;
	int j;
	for(i=0;i<length-1;i++){
		for(j=i+1;j<length;j++){
			if(array[i]<array[j]){
				int temp=array[i];
				array[i]=array[j];
				array[j]=temp;
			}
		}
	}
}

int main() {
	int mountain[10];
	for (int i = 0; i < 10; i++) {
		cin >> mountain[i];
	}
	reverse(mountain, 10);
	for (int i = 0; i < 3; i++) {
		cout << mountain[i] << endl;
	}
}

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

using namespace std;

int main() {
    
    string s;
    cin >> s;
    
    bool f = 1, f2 =1;

    for (int i = 0; i < (int)s.size(); ++i) {
        if((i + 1) & 1) f &= s[i] == 'R' or s[i] == 'U' or s[i] == 'D';
        else f2 &= (s[i] == 'L' or s[i] == 'U' or s[i] == 'D');
    }
    
    if(f and f2) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
(ns Atcoder.ABC087-B)

(require '[clojure.string :as str])

(def A (read))
(def B (read))
(def C (read))
(def X (read))
;(println A B C X)

(defn calc [x y z]
  (+ (* x 500) (* y 100) (* z 50))
  )

(def solve
  (count
    (for
      [x (range 0 (+ A 1))
       y (range 0 (+ B 1))
       z (range 0 (+ C 1))
       :when (= (calc x y z) X)                             ;計算結果がXと一致した時
       ] 1
      )
    )
  )

(println solve)

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

using namespace std;
int main()
{
    string s,k;
    cin>>s>>k;
    int i=0;
    while(s[i]!='\0'){
        i++;
    }
    int sum=0;
    for(int j=0,j1=0;j<i,j1<i;j+=1,j1+=1){
        if(s[j]==k[j1]){
           sum++;
        }
    }
    if(i==sum) cout<<"Yes\n";
    else cout<<"No\n";


    return 0;
}


Measured memory_bytes: 3624
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        long remainder = N % K;

        if (remainder == 0) {
            System.out.println(0);
        } else {
            if (remainder > (K - remainder)) {
                System.out.println(K - remainder);
            } else {
                System.out.println(remainder);
            }
        }
    }
}

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

#define ll long long

const ll MOD = 1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 0;
    for(ll i = 0; i < 61; i++){
        ll x = 0, y = 0;
        for(ll j = 0; j < n; j++){
            if( (a[j] & (1ll<<i)) ) x++;
            else y++;
        }
        ll tmp = (x*y)%MOD;
        tmp = (tmp * ((1ll<<i)%MOD))%MOD;
        ans = (ans + tmp)%MOD;
    }
    cout << ans;

}


Measured memory_bytes: 5540
#include<stdio.h>
int main()
{
	int i,a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	for(i=a;i<a+k&&i<=b;i++){
		printf("%d\n",i);	}
	if(i<b-k+1)
	i=b-k+1;
 for(;i<=b;i++)
 printf("%d\n",i);
	 return 0;


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fr first
#define se second 
signed main()
{
	CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;		
	int n;
	cin>>n;
	int dp[10][10];
	memset(dp,0,sizeof(dp));
	int sum=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		int u=i;
		vector<int> v;
		while(u>0){
			v.pb(u%10);
			u=u/10;
		}
		sum+=(dp[v[v.size()-1]][v[0]])*2;
		if(v[0]==v[v.size()-1])
			sum++;
		dp[v[0]][v[v.size()-1]]++;
		ans+=sum;
		//cout<<sum<<endl;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define endl        '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  300005
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



// class MemoryGame{
// public:
// // vs construct(int n){
void solve(){
	ll an=1e9;
	ll n,m,zz;
	cin>>n>>m>>zz;
	ll c[n],a[n][m];
	rep(i,0,n){
		cin>>c[i];
		rep(j,0,m) cin>>a[i][j];
	}
	// ll a[pow(2,n)+5][12];
	// rep(i,0,pow(2,n)+5)
	// rep(j,0,12)
	// a[i][j]=0;
	rep(i,0,pow(2,n)){
		ll b[12]={0},x=i,y=0,su=0;
		while(x){
			if(x%2){
				su+=c[y];
				// cout<<su<<" "<<c[y]<<endl;
				rep(k,0,m)
				b[k]+=a[y][k];
			}
			x/=2;
			y++;
		}
		ll xx2=1;
		rep(j,0,m){
			// cout<<b[j]<<" ";
			if(b[j]<zz)
				xx2=0;
		}
		// cout<<x<<b[0]<<endl;
		if(xx2) an=min(an,su);
	}
	if(an==1e9){
		cout<<"-1";
		return;
	}
	cout<<an;


}
// };
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll TESTS=1,an=1;
    // cin>>TESTS;
    while(TESTS--){
        // cout<<"Case #"<<an<<": ";
        an++;
        solve();

    }
    return 0;
}           

Measured memory_bytes: 4116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x)cin >> a[i];
    rep(i, y)cin >> b[i];
    rep(i, z)cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll l = 0;
    ll r = a[x-1] + b[y-1] + c[z-1] + 1;
    while(l + 1 < r){
        ll xx = (l + r) / 2;
        int cnt = 0;
        rep(i, x)rep(j, y){
            ll sum = a[i] + b[j];
            int nl = -1;
            int nr = z;
            while(nl + 1 < nr){
                int xxx = (nl + nr) / 2;
                ll zsum = sum + c[xxx];
                if(zsum >= xx)nr = xxx;
                else nl = xxx;
            }
            cnt += z - nr;
        }
        if(cnt > k)l = xx;
        else r = xx;
    }
    vector<ll> ans;
    rep(i, x)rep(j, y){
        ll sum = a[i] + b[j];
        rep(ii, z){
            ll zsum = sum + c[z-1-ii];
            if(zsum >= l)ans.push_back(zsum);
            else break;
        }
    }
    sort(ans.begin(), ans.end(), greater<ll>());
    rep(i, k)cout << ans[i] << endl;
}

Measured memory_bytes: 132960
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
int main()
{
  int n, l, s=0, m=500;
  cin >> n >> l;
  int a[n];
  for(int i=1; i<=n; i++)
  {
    a[i-1]=l+i-1;
    s+=a[i-1];
    if(abs(a[i-1]) < abs(m))
      m=a[i-1];
  }
  cout << s-m << '\n';
}

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

using namespace std;
int fac[15],av[15];
void clr(int n)
{
    for(int i = 1; i <= n; i++)
    {
        av[i] = 1;
    }
    return;
}
int  main()
{
    int n;
    scanf("%d",&n);
    fac[0] = 1;
    for(int i =1; i<=n; i++)
    {
        fac[i] = fac[i-1] *i;
    }
    int x,p[2] = {0,0};

    for(int bi = 0; bi < 2; bi++)
    {
        clr(n);
        for(int j = n - 1; j >= 0; j--)
        {
            scanf("%d",&x);
            int ct = 0;
            for(int i = 1; i <= x; i++)
            {
                ct += av[i];
            }
            av[x] = 0;
            p[bi] += (ct - 1) * (fac[j]);

        }
    }
    printf("%d",abs(p[0]-p[1]));

}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, a, b;
  cin >> n >> a >> b;

  ll M = max(a, b);
  ll m = min(a, b);

  bool ok = (a + b - 1) <= n && (a*b >= n);
  if(!ok) {
    cout << -1 << endl;
    return 0;
  }

  vll ans(n);
  ll w = n - (a + b - 1);
  ll idx = 0;
  rep(i, m){
    rep(j, M) {
      if(i > 0 && j > 0){
        if(w == 0) break;
        else w--;
      } 
      ans[idx++] = j + i*(-M);
    }
  }

  if(a < b) rep(i, n) ans[i] *= -1;

  {
    map<ll, ll> mp;
    rep(i, n) {
      mp[ans[i]] = i;
      mp[0] = 0;
    }
    ll j = 1;
    for(auto [v, i] : mp) ans[i] = j++;
  }

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

  return 0;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var abc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = abc[0];
        var b = abc[1];
        var c = abc[2];
        Console.WriteLine(Math.Min(b / a, c));
    }
}


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

vector<pair<int,int>> ans;
int N,K;
int main(){
    cin >> N >> K;
    int cnt = (N-1)*(N-2)/2;
    if(cnt<K){
        cout << -1 << endl;
        return 0;
    }
    for(int i=1;i<N;i++) ans.push_back({i,N});
    for(int i=1;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            if(cnt>K){
                ans.push_back({i,j});
                cnt--;
            } 
        }
    }
    cout << ans.size() << endl;
    for(auto x:ans) cout << x.first << " " << x.second << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1e18;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<ll>A;
vector<ll>sum;

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

	int N;
	ll K;
	cin >> N >> K;
	A.resize(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	sum.resize(N + 1);
	for (int i = 0; i < N; i++)sum[i + 1] = sum[i] + A[i];
	for (int i = 0; i <= N; i++) {
		sum[i] -= i;
		sum[i] += (ll)i*K;
		sum[i] %= K;
	}

	map<ll, ll>mp;
	ll ans = 0;
	for (int r = 0; r < N; r++) {
		if (r - K + 1 >= 0)mp[sum[r-K+1]]--;
		mp[sum[r]]++;
		ans += mp[sum[r+1]];
	}
	puts(ans);

	return 0;
} 

Measured memory_bytes: 15872
import networkx as nx
from networkx.algorithms.bipartite import hopcroft_karp_matching

n, m = map(int, input().split())

def inside(x, y):
	if 0 <= x < n and 0 <= y < m:
		return True
	else:
		return False

DI = [1, 0, -1, 0]
DJ = [0, 1, 0, -1]

a = [list(input()) for _ in range(n)]
g = nx.Graph()
g.add_nodes_from(range(n*m))
zero = True
top = set()
for i in range(n):
	for j in range(m):
		if a[i][j] == "#":
			continue
		if (i+j)%2 == 0:
			for k in range(4):
				di, dj = i+DI[k], j+DJ[k]
				if inside(di, dj) and a[di][dj] == ".":
					zero = False
					g.add_edge(i*m+j, di*m+dj)
					top.add(i*m+j)
if zero:
	print(0)
else:
	h = hopcroft_karp_matching(g, top_nodes=top)
	print(len(h)//2)
	for fr, to in h.items():
		i0, j0 = fr//m, fr%m
		i1, j1 = to//m, to%m
		if a[i0][j0] != ".":
			continue
		if i1 == i0+1:
			a[i0][j0] = "v"
			a[i1][j1] = "^"
		elif i1 == i0-1:
			a[i0][j0] = "^"
			a[i1][j1] = "v"
		elif j1 == j0+1:
			a[i0][j0] = ">"
			a[i1][j1] = "<"
		else:
			a[i0][j0] = "<"
			a[i1][j1] = ">"
print(*["".join(x) for x in a], sep="\n")

Measured memory_bytes: 67208
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
int main()
{
   ll n,a,b,x=0,y=0;
  cin>>n>>a>>b;
 
  y=n/(a+b);
  x=min(n%(a+b),a);
  cout<<y*a+x<<endl;
}

Measured memory_bytes: 256
//Rally
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, final = INT_MAX; int k = 0, hi = 0, lo = INT_MAX;	cin >> n;
	vector <int> x;
	for (int i = 0; i < n; i++) {
		int temp;	cin >> temp;	x.push_back(temp);
		hi = max(temp, hi);		lo = min(temp, lo);
	}
	for (int i = lo; i <= hi; i++) {
		long long sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (x[j] - i) * (x[j] - i);
		}
		if (sum < final) {
			k = i;	final = sum;
		}
	}
	cout << final << endl;
	return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int N;
	cin >> N;
	ll ans = 0;
	vecl(D)
	fx(N) {
		vecpl(D);
	}
	fx(N) {
		fyg(N,x+1) {
			ans += D[x] * D[y];
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 256
from sys import stdin
n,m = map(int,stdin.readline().split())
ans = 'IMPOSSIBLE'
di = set()
for i in xrange(m):
 x,y = map(int,stdin.readline().split())
 di.add((min(x,y),max(x,y)))
for i in xrange(2,n):
 fir = (1,i)
 sec = (i,n)
 if fir in di and sec in di:
  ans = 'POSSIBLE'; break
print ans

Measured memory_bytes: 35704