akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "code_festival_2017_qualb_e"
int a, b;
const int base=1000000007;
int c[2001][2001];
int sum[2001][2001];
int f[2001][2001];
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(a);
    read(b);
    FOR(i, 0, 2000){
        c[i][i]=c[i][0]=1;
        FFOR(j, 1, i){
            c[i][j]=c[i-1][j]+c[i-1][j-1];
            while(c[i][j]>=base) c[i][j]-=base;
        }
        sum[i][0]=1;
        if(i) FOR(j, 1, i){
            sum[i][j]=c[i][j]+sum[i][j-1];
            while(sum[i][j]>=base) sum[i][j]-=base;
        }
    }
//    FOR(i, 0, 5) FOR(j, 0, 5) cerr<<c[i][j]<<" \n"[j==5];
    FOR(x, 0, a){
        FOR(y, 0, b){
            if(y==0) f[x][y]=1;
            else{
                f[x][y]=(x?f[x-1][y]:0)+sum[y-1][min(x, y-1)];
                while(f[x][y]>=base) f[x][y]-=base;
            }
        }
    }

    ll ans=0;
    FOR(x, 0, a){///
        ///delete b character, the first is B
        FOR(y, 0, min(x, b-1)){/// y of them is R
            ans=(1LL*f[x-y][y]*c[b-1][y]+ans)%base;
        }
        /**
        f[0][3]*c[3][0]
        f[1][2]*c[3][1]
        f[2][1]*c[3][2]
        f[3][0]*c[3][3]
        */
    }
    writeln(ans);
}

Measured memory_bytes: 47232
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,m = readInts()
def yaku(m):
        ans = []
        i = 1
        while i*i <= m:
            if m % i == 0:
                j = m // i
                ans.append(i)
                if j != i:
                    ans.append(j)
            i += 1
        ans = sorted(ans)
        return ans
dic = yaku(m)
ans = 1
for k in dic:
    if k*n <= m:
        ans = max(ans,k)
print(ans)


Measured memory_bytes: 10460
n,k=map(int,input().split())
s=input()
s_list=[]
first=s[0]
last=s[n-1]
state=first
length=1
for i in range(1,n):
    if (state=='0' and s[i]=='0') or (state=='1' and s[i]=='1'):
        state=s[i]
        length=length+1
    else:
        state=s[i]
        s_list.append(length)
        length=1
s_list.append(length)
m=len(s_list)
if first=='0' and last=='0':
    if (len(s_list)+1)/2<=k:
        Max=n
    else:
        p_list=s_list[0:2*k]
        Sum=sum(p_list)
        Max=Sum
        i=1
        p_list=s_list[i:i+2*k+1]
        Sum=sum(p_list)
        if Sum>Max:
            Max=Sum
        i=i+2
        while i+2*k<m-1:
            Sum=Sum-s_list[i-2]-s_list[i-1]+s_list[i+2*k-1]+s_list[i+2*k]
            if Sum>Max:
                Max=Sum
            i=i+2
        p_list=s_list[m-2*k:]
        if sum(p_list)>Max:
            Max=sum(p_list)
elif first=='0' and last=='1':
    if len(s_list)/2<=k:
        Max=n
    else:
        p_list=s_list[0:2*k]
        Sum=sum(p_list)
        Max=Sum
        i=1
        p_list=s_list[i:i+2*k+1]
        Sum=sum(p_list)
        if Sum>Max:
            Max=Sum
        i=i+2
        while i+2*k<=m-1:
            Sum=Sum-s_list[i-2]-s_list[i-1]+s_list[i+2*k-1]+s_list[i+2*k]
            if Sum>Max:
                Max=Sum
            i=i+2
elif first=='1' and last=='0':
    if len(s_list)/2<=k:
        Max=n
    else:
        p_list=s_list[0:2*k+1]
        Sum=sum(p_list)
        Max=Sum
        i=2
        while i+2*k<m-1:
            Sum=Sum-s_list[i-2]-s_list[i-1]+s_list[i+2*k-1]+s_list[i+2*k]
            if Sum>Max:
                Max=Sum
            i=i+2
        p_list=s_list[m-2*k:]
        if sum(p_list)>Max:
            Max=sum(p_list)
elif first=='1' and last=='1':
    if (len(s_list)-1)/2<=k:
        Max=n
    else:
        p_list=s_list[0:2*k+1]
        Sum=sum(p_list)
        Max=Sum
        i=2
        while i+2*k<=m-1:
            Sum=Sum-s_list[i-2]-s_list[i-1]+s_list[i+2*k-1]+s_list[i+2*k]
            if Sum>Max:
                Max=Sum
            i=i+2
print(Max)


Measured memory_bytes: 5260
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int b[110000];
vector<pair<int,int> > g[110000];
int cnt[20];
int dp[1<<16];
int calc(int a){
	if(dp[a]>=0)return dp[a];
	if(a==0)return dp[a]=0;
	int ret=mod;
	for(int i=0;i<16;i++){
		if(a&(1<<i)){
			ret=min(ret,calc(a-(1<<i))+1);
			for(int j=0;j<16;j++){
				if(i==j)continue;
				if(a&(1<<j)){
					int to=i^j;
					if(a&(1<<to)){
						ret=min(ret,calc(a-(1<<i)-(1<<j)-(1<<to))+2);
					}else{
						ret=min(ret,calc(a-(1<<i)-(1<<j)+(1<<to))+1);
					}
				}
			}
		}
	}
	return dp[a]=ret;
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);
		g[p].push_back(make_pair(q,r));
		g[q].push_back(make_pair(p,r));
	}
	for(int i=1;i<a;i++){
		for(int j=0;j<g[i].size();j++)b[i]^=g[i][j].second;
	}
	for(int i=0;i<a;i++)cnt[b[i]]++;
	for(int i=0;i<(1<<16);i++)dp[i]=-1;
	int ret=0;
	int st=0;
	for(int i=1;i<16;i++){
		ret+=cnt[i]/2;
		if(cnt[i]%2)st+=(1<<i);
	}
	printf("%d\n",ret+calc(st));
}

Measured memory_bytes: 7412
use std::collections::HashMap;

pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    match std::io::stdin().read_line(&mut line) {
        Ok(0) => return Err("eof".to_string()),
        Ok(_) => (),
        Err(err) => return Err(format!("{:?}", err)),
    }

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn main() {
    let mut map = HashMap::new();
    loop {
        let ret = read_parameters::<String>();
        let s = match ret {
            Ok(sv) => sv.join(" "),
            Err(ref err) if err == "eof" => break,
            Err(_) => return,
        };

        for c in s.chars() {
            let key = c.to_string().to_lowercase();
            let count = map.entry(key).or_insert(0);
            *count += 1;
        }
    }
    for c in 'a' as u8..'z' as u8 + 1 {
        let key = (c as char).to_string();
        if let Some(n) = map.get(&key) {
            println!("{} : {}", key, n);
        } else {
            println!("{} : {}", key, 0);
        }
    }
}



Measured memory_bytes: 5060
#include<iostream>
using namespace std;
int main(){
  int N,L,eat=200,sum=0;
  cin >> N >> L;
  for(int i=0;i<N;i++){
    if(abs(L+i)<abs(eat)){
      eat=L+i;
    }
    sum+=L+i;
  }
  cout << sum-eat << endl;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/
vi d;

bool f(int x)
{
	while(x){
		int t = x%10;
		for(int i : d){
			if(t == i) return true;
		}
		x /= 10;
	}
	return false;
}

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

	d.resize(k);
	rep(i, 0, k) cin >> d[i];

	int ans = n;
	while(f(ans)){
		ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import heapq as h
I=lambda:list(map(int,input().split()))
n,k=I()
q=[]
v=i=T=A=0
l=[0]*-~n
for a,b in sorted([I()for _ in[0]*n],key=lambda x:-x[1]):
 if i<k:
  if l[a]:h.heappush(q,b)
  else:T+=v*2+1;v+=1
  l[a]=1;T+=b
 elif l[a]^1and q:l[a]=1;T+=b+v*2+1-h.heappop(q);v+=1
 A=max(A,T);i+=1
print(A)

Measured memory_bytes: 33784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int a, b, c;

int main(void){
	
	scanf("%d %d %d", &a, &b, &c);
	int x = a + b, y = a + c, z = b + c;
	if(x == c) printf("Yes\n");
	else if(y == b) printf("Yes\n");
	else if(z == a) printf("Yes\n");
	else printf("No\n");
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n;
	int a[200010];
	cin >> n;
	int m;
	FOR(i,n){
		cin >> a[i];
		if(i==0)m=a[i];
		else m^=a[i];
	}

	FOR(i,n){
		int u=m^a[i];
		cout << u;
		if(i!=n-1)cout << " ";
		else cout << endl;
	}


}

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

int main(){
  int n,d;
  cin >> n >> d;
  int x[n],y[n];
  rep(i,0,n){
    cin >> x[i];
    cin >> y[i];
  }
  int c = 0;
  rep(i,0,n){
    double dis = sqrt(pow(x[i],2)+pow(y[i],2));
    if(dis <= d) c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 5140
import java.util.Scanner;

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

		int N = sc.nextInt();

		int[] H = new int[N];

		for(int i=0; i<H.length; i++) H[i] = sc.nextInt();

		boolean isOK = true;
		for(int i=N-1; i>0; i--) {
			int now = H[i];
			int next = H[i-1];

			H[i-1] = next-now == 1 ? next-1 : next;

			if(H[i-1]-now > 0) {
				isOK = false;
			}
		}

		System.out.println((isOK ? "Yes" : "No"));
		sc.close();
	}
}


Measured memory_bytes: 50108
n, a, b = [int(i) for i in input().split()]
mod = 10**9+7

def func_156d(n, r):
    numerator = 1
    denominator = 1
    for i in range(r):
        numerator = numerator * (n-i) % mod
        denominator = denominator * (i+1) % mod
    return numerator * pow(denominator, mod-2, mod) %mod

print((pow(2, n, mod) -1 - func_156d(n,a) - func_156d(n,b))  %mod )

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include <algorithm>
#include <numeric>
using namespace std;
# define maxi 100000
# define maxw 100000
# define maxn 100
using ll = long long;
int main() {
  ll N,Y;
  cin>>Y>>N;
  for (ll y(0);y<=Y;y++){
    for (ll z(0);z<=Y;z++){
      if (5000*y+9000*z==10000*Y-N && Y-y-z>=0){
        cout << Y-y-z <<" "<< y <<" "<< z;
        return 0;
      }
    }
  }
  cout << -1<<" " << -1 << " "<< -1;
  return 0;
}


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


int main(){
  string s; cin >> s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

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

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    string S, T;
    cin >> S >> T;
    int cnt = 0, N = S.size();
    for (int i=0;i<N;i++) {
        if (S[i] == T[i]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


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

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }


  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int[] p = sc.nextIntArray(a);
    int[] q = sc.nextIntArray(b);
    int[] r = sc.nextIntArray(c);
    Arrays.sort(p);
    Arrays.sort(q);
    Arrays.sort(r);
    int xy = x + y;
    PriorityQueue<Integer> pq = new PriorityQueue<>((Integer ap1, Integer ap2) -> ap2 - ap1);
    for (int i = a - 1; x > 0; i--) {
      pq.add(p[i]);
      x--;
    }
    for (int i = b - 1; y > 0; i--) {
      pq.add(q[i]);
      y--;
    }
    for (int ri : r) pq.add(ri);
    long sum = 0L;
    for (int i = 0; i < xy; i++) {
      sum += (long) pq.poll();
    }
    System.out.println(sum);
  }
}

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

int main(){
int ABCD;
  cin>>ABCD;
  
  int A, B=ABCD/100%10, C=ABCD/10%10, D=ABCD%10;
  if(0<=ABCD && ABCD<=999){A=0;}
  else{A=ABCD/1000;}
  
  char b, c, d;
  for(int op1=-1; op1<=1; op1+=2){
   for(int op2=-1; op2<=1; op2+=2){
    for(int op3=-1; op3<=1; op3+=2){
     if(A+op1*B+op2*C+op3*D==7){
       if(op1==-1){b='-';}
       if(op1==1){b='+';}
       if(op2==-1){c='-';}
       if(op2==1){c='+';}
       if(op3==-1){d='-';}
       if(op3==1){d='+';}
       cout<<A<<b<<B<<c<<C<<d<<D<<"=7"; return 0;}
    }
   }
  }
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define ll long long

ll a,b,c,d;
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
ll solve(ll n)
{
	ll ans=n;
	ans-=n/c;
	ans-=n/d;
	ans+=n/(c*d/gcd(c,d));
	return ans;
}

int main()
{
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	printf("%lld",solve(b)-solve(a-1));
}

Measured memory_bytes: 128
import java.util.*;
    import java.util.Scanner;
    import java.io.*;
    import java.io.BufferedReader; 
    import java.io.IOException; 
    import java.io.InputStreamReader; 
    import java.util.Scanner; 
    import java.util.StringTokenizer; 
    
    public class Main
    {
        static class FastReader 
        { 
            BufferedReader br; 
            StringTokenizer st; 
    
            public FastReader() 
            { 
                br = new BufferedReader(new
                        InputStreamReader(System.in)); 
            } 
    
            String next() 
            { 
                while (st == null || !st.hasMoreElements()) 
                { 
                    try
                    { 
                        st = new StringTokenizer(br.readLine()); 
                    } 
                    catch (IOException  e) 
                    { 
                        e.printStackTrace(); 
                    } 
                } 
                return st.nextToken(); 
            } 
    
            int nextInt() 
            { 
                return Integer.parseInt(next()); 
            } 
    
            long nextLong() 
            { 
                return Long.parseLong(next()); 
            } 
    
            double nextDouble() 
            { 
                return Double.parseDouble(next()); 
            } 
    
            String nextLine() 
            { 
                String str = ""; 
                try
                { 
                    str = br.readLine(); 
                } 
                catch (IOException e) 
                { 
                    e.printStackTrace(); 
                } 
                return str; 
            } 
        } 
        
        

        public static void main(String args[]) 
        {  
            FastReader in=new FastReader();
            int n=in.nextInt();
            String AC="AC";
            String WA="WA";
            String TLE="TLE";
            String RE="RE";
            int counta=0;
            int countw=0;
            int countl=0;
            int countr=0;
            while(n-->0)
            {
                String S=in.nextLine();
                if(S.equals(AC))
                    counta++;
                else if(S.equals(WA))
                    countw++;
                else if(S.equals(TLE))
                    countl++;
                else if(S.equals(RE))
                    countr++;
                
            }
            System.out.println("AC x "+counta);
            System.out.println("WA x "+countw);
            System.out.println("TLE x "+countl);
            System.out.println("RE x "+countr);
    
            
                
            
        }
    }

Measured memory_bytes: 33996
#include <bits/stdc++.h>
#define N 1000
using namespace std;
int n, f[N], g[N], d[N][N];
char s[N];
int find(int x) {
    if(f[x] == x) return x;
    int y = find(f[x]);
    g[x] ^= g[f[x]];
    return f[x] = y;
}
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++ i) f[i] = i;
    for(int i = 1; i <= n; ++ i)
        for(int j = 1; j <= n; ++ j) d[i][j] = N;
    bool flag = 1;
    for(int i = 1; i <= n; ++ i) {
        scanf("%s", s + 1);
        for(int j = i + 1; j <= n; ++ j)
            if(s[j] == '1') {
                int x = find(i), y = find(j);
                if(x != y) f[x] = y, g[x] = g[i] ^ 1 ^ g[j];
                else if(g[i] ^ 1 ^ g[j]) flag = 0;
            }
        for(int j = 1; j <= n; ++ j)
            if(s[j] == '1') d[i][j] = 1;
    }
    if(!flag) { puts("-1"); return 0; }
    for(int k = 1; k <= n; ++ k)
        for(int i = 1; i <= n; ++ i) if(i != k)
            for(int j = 1; j <= n; ++ j) if(j != k && j != i)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    int ans = 1;
    for(int i = 1; i < n; ++ i)
        for(int j = i + 1; j <= n; ++ j) ans = max(ans, d[i][j] + 1);
    printf("%d\n", ans);
}

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

int main()
{
    int n1, n2, value[3];
    cin>>n1>>n2;
    value[0] = n1+n2;
    value[1] = n1-n2;
    value[2] = n1*n2;
    int i, maxemum = value[0];
    for(i = 0; i < 3; i++)
    {
        if(value[i] > maxemum)
            maxemum = value[i];
    }
    cout<<maxemum;

    return 0;
}


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

int main(){

	int w, ww[30], n;
	char ab;
	int a, b;
	int temp;
	
	cin >> w >> n;
	for(int i = 0; i < w; i++) {
		ww[i] = i+1;
	}
	
	for(int i = 0; i < n; i++) {
		cin >> a >> ab >> b;
		temp = ww[b-1];
		ww[b-1] = ww[a-1];
		ww[a-1] = temp;
	}
	
	for(int i = 0; i < w; i++) {
		cout << ww[i] << endl;
	}

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int a,b,c,d;

    cin >> a >> b >> c >> d;

    if(abs(a-c)<=d){
        cout << "Yes" << endl;
        return 0;
    }

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



    return 0;
}

Measured memory_bytes: 764
#
#    ------------------------------------------------
#           ____          _     Generatered using
#          / ___|        | |
#         | |    __ _  __| | ___ _ __  ______ _
#         | |   / _` |/ _` |/ _ \ '_ \|_  / _` |
#         | |__| (_| | (_| |  __/ | | |/ / (_| |
#          \____\____|\____|\___|_| |_/___\____|
#
#      GNU Affero General Public License v3.0
#    ------------------------------------------------
#    Author   : prophet
#    Created  : 2020-07-25 08:23:15.745703
#    UUID     : K8TO3VDPFHYsy1xb
#    ------------------------------------------------
#
production = True

import sys, math, collections

def input(f = 0, m = 0):

    if m > 0: return [input(f) for i in range(m)]
    else:
        l = sys.stdin.readline()[:-1]

        if f >= 10:
            u = False
            f = int(str(f)[-1])
        else: u = True

        if f == 0: p = [l]
        elif f == 1: p = list(map(int, l.split()))
        elif f == 2: p = list(map(float, l.split()))
        elif f == 3: p = list(l)
        elif f == 4: p = list(map(int, list(l)))
        elif f == 5: p = l.split()

        return p if u else p[0]

def out(l, f = 0, n = True):

    if f == 0: p = str(l)
    elif f == 1: p = " ".join(map(str, l))
    elif f == 2: p = "\n".join(map(str, l))
    elif f == 3: p = "".join(map(str, l))

    print(p, end = "\n" if n else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)
flip = lambda a: (a + 1) & 1

def mapl(i, f = 0):

    if f == 0: return list(map(int, i))
    elif f == 1: return list(map(str, i))
    elif f == 2: return list(map(list, i))

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#


def solve():

    n = input(11)
    a = input(1)


    y = 1000

    p = 10 ** 10

    for i in a: 
        if i > p:
            m = y // p
            y -= m * p
            y += m * i
        p = i

    out(y)

    return


solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


Measured memory_bytes: 65520
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <math.h>
using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
 	
   	int n,k;
   	cin>>n>>k;
   	if(n*500>=k)puts("Yes");
   	else printf("No\n");
   	
   

    return 0;
}
 

Measured memory_bytes: 256
package main

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

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e9

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	x := next.Int()
	t := next.Int()

	fmt.Println(max(0, x-t))
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
	int n, count=0;
	cin >> n;
	while(n--){
		bool prime = true;
		int k, endk;
		cin >> k;
		endk = (int)sqrt(k);
		for( int i=2; i<=endk; i++ ){
			if( k%i == 0 ){
				prime = false;
				break;
			}
		}
		if( prime )	count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1160
x=int(input())

b=~x&0b11111111111111111111111111111111
c=(x<<1)&0b11111111111111111111111111111111
d=(x>>1)&0b11111111111111111111111111111111
print(format(x,'032b'))
print(format(b,'032b'))
print(format(c,'032b'))
print(format(d,'032b'))



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

int
main(void)
{
  int n;
  int arr[100];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];

  int sum = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++){
      sum += arr[i] * arr[j];
    }
  }

  cout << sum << endl;


  return 0;
}

Measured memory_bytes: 256
li = []
li.append(int(input()))
li.append(int(input()))
li.append(int(input()))
li.append(int(input()))
li.append(int(input()))

for i in range(len(li)-1):
    if li[i] % 10 < li[i+1] % 10 or li[i+1] % 10 == 0:
        x = li[i]
        li[i] = li[i+1]
        li[i+1] = x
for i in range(len(li)):
    if i == len(li)-1:
        break
    d10 = li.pop(i)
    if d10 % 10 != 0:
        li.insert(i, (d10//10+1) * 10)
    else:
        li.insert(i, (d10//10+0) * 10)
print(sum(li))


Measured memory_bytes: 3064
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (true) {
            final int q = scanner.nextInt();
            final int lim = scanner.nextInt();
            if (q == 0 && lim == 0) {
                break;
            }
            int counter = 0;
            final List<Integer> array = new LinkedList<Integer>();
            for (int i = 0; i < q; i++) {
                final int query = scanner.nextInt();
                final int xi = scanner.nextInt();
                switch (query) {
                    case 0:
                        array.add(xi);
                        counter++;
                        break;
                    case 1:
                        array.remove(xi - 1);
                        counter--;
                        break;
                    case 2:
                        System.out.println(array.get(xi - 1));
                        break;
                    case 3:
                        array.remove(Integer.valueOf(xi));
                        counter--;
                        break;
                }
                if (counter > lim) {
                    array.remove(0);
                    counter--;
                }
            }
            System.out.println("end");
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 17000
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 10;

int main() {
	fast_cin();
	string t; cin >> t;
	int n = t.length();
	ll ans = 0;
	int k = 0, mx = 0, p = 0;
	vector<ll> c(2, 0);
	while (p < n and t[p] == '1') {
		++c[p & 1];
		++p;
	}
	mx = max(c[0], c[1]);
	while (p < n) {
		c[0] = c[1] = 0;
		++p;
		while (p < n and t[p] == '1') {
			++c[p & 1];
			++p;
		}
		ans += ((k + 2) / 2) * c[0] + ((k + 1) / 2) * c[1] + mx;
		mx += max(c[0], c[1]);
		++k;
	}
	int left = n - k;
	while (left) {
		ans += (left + 1) / 2;
		--left;
	}
	cout << ans << endl;
}

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

typedef pair <int, int> ii;
typedef long long ll;

const int Maxn = 100005;

int n;
int A[Maxn], B[Maxn];
vector <ii> seq;
set <ii> S[2];
ll my[2];
ll suma, sumb;
int wh[2 * Maxn];

void Fix()
{
    while (S[0].size() > n - 2) {
        set <ii>::iterator it = S[0].end(); it--;
        S[1].insert(*it); my[1] += it->first;
        wh[it->second] = 1;
        my[0] -= it->first; S[0].erase(it);
    }
    while (S[0].size() < n - 2) {
        set <ii>::iterator it = S[1].begin();
        S[0].insert(*it); my[0] += it->first;
        wh[it->second] = 0;
        my[1] -= it->first; S[1].erase(it);
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &A[i], &B[i]);
        seq.push_back(ii(A[i], 2 * i));
        seq.push_back(ii(B[i], 2 * i + 1));
        suma += A[i]; sumb += B[i];
    }
    ll res = min(suma, sumb);
    sort(seq.begin(), seq.end());
    for (int i = 0; i < seq.size(); i++) {
        wh[seq[i].second] = i < n - 2? 0: 1;
        my[wh[seq[i].second]] += seq[i].first;
        S[wh[seq[i].second]].insert(seq[i]);
    }
    for (int i = 0; i < n; i++) {
        int inda = wh[2 * i], indb = wh[2 * i + 1];
        my[inda] -= A[i]; S[inda].erase(ii(A[i], 2 * i));
        my[indb] -= B[i]; S[indb].erase(ii(B[i], 2 * i + 1));
        Fix();
        res = min(res, ll(A[i]) + ll(B[i]) + my[0]);
        my[inda] += A[i]; S[inda].insert(ii(A[i], 2 * i));
        my[indb] += B[i]; S[indb].insert(ii(B[i], 2 * i + 1));
        Fix();
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 12784
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)


////////////////////////////////////////////////////////////

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

	int a=0;
	rep(i,0,3)
		if(s[i] == 'o')
			a += 100;

	cout << 700 + a << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N, K, S, T; cin >> N >> K >> S >> T; 
	long long com[55][55] = {}; 
	long long Com[55][55] = {}; 
	com[0][0] = 1; 
	for(int i = 0; i < 52; i++){
		for(int j = 0; j <= i; j++){
			com[i+1][j] += com[i][j]; 
			com[i+1][j+1] += com[i][j]; 
		}
	}
	for(int i = 0; i < 52; i++){
		Com[i][0] = 1; 
		for(int j = 1; j <= i; j++){
			Com[i][j] = Com[i][j-1] + com[i][j]; 
		}
	}
	vector<int> A, B; 
	for(int i = 0; i < N; i++){
		int a; cin >> a; 
		if((a & S) != S || (a | T) != T) continue; 
		A.push_back(a); 
	}
	vector<int> d; 
	for(int i = 0; i < 18; i++){
		if(((S >> i) & 1) && !((T >> i) & 1)){
			cout << 0 << "\n"; return 0; 
		}
	}
	for(int i = 0; i < 18; i++){
		if(((S >> i) & 1) || !((T >> i) & 1)) continue;
		d.push_back(i); 
	}
	for(auto a : A){
		int b = 0; 
		for(int i = 0; i < d.size(); i++){
			b += (((a >> d.at(i)) & 1) << i); 
		}
		B.push_back(b); 
	}
	int D = d.size(); 
	long long ans = 0; 
	for(int bit = 0; bit < (1 << D); bit ++){
		vector<int> C; 
		long long num = 0; 
		for(auto b : B){
			C.push_back(b & bit); 
		}
		sort(C.begin(), C.end()); 
		C.push_back(1145141919); 
		if(!C.size()) continue; 
		int now = C.at(0); int cons = 1; 
		for(int c = 1; c < (int) C.size(); c++){
			if(C.at(c) == now) cons ++; 
			else{
				if(cons > K) num += Com[cons][K] - 1; 
				else num += (1LL << cons) - 1; 
				now = C.at(c); cons = 1; 
			}
		}
		int m = __builtin_popcount(bit);
		if(m % 2) ans -= num; 
		else ans += num; 
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    int arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr, arr+3);
    cout<<arr[2]*10+arr[1]+arr[0]<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	cout << ((s[2] == s[3]) && (s[4] == s[5]) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp make_pair
#define ll long long
#define reg register
#define inf 0x7fffffff
#define MOD 1000000007
#define clr(a) memset(a,sizeof(a),0);
#define rep(i,l,r) for(reg int i=l;i<=r;i++)
#define dow(i,l,r) for(reg int i=l;i>=r;i--)
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;}
inline ll readl(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
template<class T>inline T power(T a,T b){T ans=1;while(b){if(b&1){ans=ans*a%MOD;}b>>=1;a=a*a%MOD;}return ans%MOD;}
/*================Header Template==============*/
int main(){
	int n=read(),mn=inf,mx=0;
	rep(i,1,n) {
		int x=read();
		mx=max(x,mx); mn=min(mn,x);
	}
	writeln(mx-mn);
}



Measured memory_bytes: 256
#include <stdio.h>
#define NUM 7

int main(void)
{
  int n[NUM][2];
  int t[NUM];
  int i;
  for(i=0;i<NUM;i++){
    scanf("%d %d",&n[i][0],&n[i][1]);
    t[i] = n[i][0] - n[i][1];
  }
  for(i=0;i<NUM;i++)
    printf("%d\n",t[i]);
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,a[10050],ans;
int main(){
	scanf("%d",&n);n<<=1;
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i+=2) ans+=a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import fractions
def smallestCommon(a,b):
    return a*b/fractions.gcd(a,b)

def caluclate(a, b, c, d):

    s1 = (a - 1) // c
    s2 = (a - 1) // d

    m1 = s2 + s1

    s3 = b // c
    s4 = b // d

    m2 = s4 + s3

    common = int(smallestCommon(c,d))

    m3 = (b // common) - (a-1)//common

    total = int(b - a + 1)

    return total - (m2 - m1 - m3)


S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

result = caluclate(A,B,C,D)

print(result)

Measured memory_bytes: 5076
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
s = []
negative = 0
for i, j in zip(a, b):
    s.append(i - j)
    if i - j < 0:
        negative += i - j
        ans += 1

s.sort(reverse=True)

if ans != 0:
    if sum(s) < 0:
        ans = -1
    else:
        for i , p in enumerate(s):
            negative += p
            if negative >= 0:
                ans += i + 1
                break
    

print(ans)

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template <typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int main() {
    int N;
    VI A;

    cin >> N;
    times(N) { int val; cin >> val; A.pb(val); }

    VI plus, minus;
    for(int n: A) if(n >= 0) { plus.pb(n); } else { minus.pb(n); }
    sort(all(plus), greater<int>());
    sort(all(minus));
    if(minus.empty()) minus.pb(plus.back()), plus.pop_back();
    if(plus.empty()) plus.pb(minus.back()), minus.pop_back();

    VP res;
    int sum = minus[0];
    rep(i, plus.size() - 1) res.pb({ sum, plus[i] }), sum -= plus[i];
    res.pb({ plus.back(), sum });
    sum = plus.back() - sum;
    REP(i, 1, minus.size()) res.pb({ sum, minus[i] }), sum -= minus[i];

    out(sum);
    for(Pair p: res) cout << p.first << " " << p.second << endl;
    return 0;
}

Measured memory_bytes: 4720
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:usize,
    m:usize,
    aa:[usize;a],
    bb:[usize;b],
    c:[(usize,usize,usize);m],
    }
    let aaa=*aa.iter().min().unwrap();
    let bbb=*bb.iter().min().unwrap();
    let mut z=aaa+bbb;
    for i in 0..m {
        if z>aa[c[i].0-1]+bb[c[i].1-1]-c[i].2{
            z=aa[c[i].0-1]+bb[c[i].1-1]-c[i].2
        }
    }
    println!("{}",z)
}

Measured memory_bytes: 8740
#include<stdio.h>

int main(void)
{
    int r,g;
    scanf("%d%d",&r,&g);
    while((0>r||r>4500)||(0>g||g>4500))
    {
        scanf("%d%d",&r,&g);
    }
    printf("%d\n",2*g-r);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int main ()
{

    int n; cin >> n;

    if (n == 1) {
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << 1 << " " << 1 << endl;
        cout << 1 << " " << 1 << endl;
        return 0;
    }

    if (n == 2) {
        cout << "No" << endl;
        return 0;
    }

    int v = -1;
    for (int i = 3; i <= 1000; i++) {
        if (i * (i - 1) / 2 == n) {
            v = i;
            goto nxt;
        }
    }

    cout << "No" << endl;
    return 0;

    nxt:;

    vector < vector < int > > ans;
    ans.push_back({1, 2});
    ans.push_back({1, 3});
    ans.push_back({2, 3});

    int cnt = 4;
    for (int i = 0; i < v - 3; i++) {
        vector < int > add;
        REP(j,ans.size()) {
            ans[j].push_back(cnt);
            add.push_back(cnt);
            cnt++;
        }
        ans.push_back(add);
    }

    cout << "Yes" << endl;
    cout << ans.size() << endl;
    REP(i,ans.size()) {
        cout << ans[i].size();
        REP(j,ans[i].size()) {
            cout << " " << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
static const int MAX_N = 1e5;
priority_queue<int64_t> pq;
priority_queue<pair<int, int>> pq_p;
int64_t n, m;
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		pq.push(a);
	}
	for (int i = 0; i < m; i++)
	{
		int first, second;
		cin >> second >> first;
		pq_p.push(make_pair(first, second));
	}
	int countn = n, countm = m;
	while (countn > 0 && countm > 0)
	{
		int first = pq_p.top().first, second = pq_p.top().second;
		pq_p.pop();
		while (countn > 0 && countm > 0 && second > 0)
		{
			pq.push(first);
			--countn;
			--second;
		}
		--countm;
	}
	int64_t result = 0;
	for (int i = 0; i < n; i++)
	{
		result += pq.top();
		pq.pop();
	}
	cout << result << endl;
}

Measured memory_bytes: 3316
#include <stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	int i,j,min=0,tmp=0,k=0;
	int A[N];
	
	for(i=0;i<N;i++)  //配列読み込み
	{
		scanf("%d",&A[i]);
	}
	
	for(i=0;i<N;i++){		//選択ソート
		min=i;
		for(j=i;j<N;j++){		
			if(A[j]<A[min]){
				min=j;
			}
		}
		
		if(i!=min){
			tmp=A[i];
			A[i]=A[min];
			A[min]=tmp;
			k++;
			}
		
		}
	   
	
	
	
	for(i=0;i<N;i++)
	{
		printf("%d",A[i]);
		if(i<N-1)
		{
			printf(" ");
		}
	}
	printf("\n");
	printf("%d\n",k);
	return 0;

}

	


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    long double L;
    cin >> L;
    L /= 3;
    cout << fixed << setprecision(10);
    cout << L * L * L << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vl C(MAX_N);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        C[a]++;  C[b]++;
    }

    rep(i, MAX_N) {
        if(C[i]%2 == 1) {
            out("NO");
            re0;
        }
    }
    
    out("YES");
    re0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int h, w;
	cin >> h >> w;
	char a[110][110];
	char b[110][110];

	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	rep(i, h + 2LL) {
		rep(j, w + 2LL) {
			b[i][j] = '#';
		}
	}

	rep(i, h) {
		rep(j, w) {
			b[i + 1][j + 1] = a[i][j];
		}
	}

	rep(i, h + 2LL) {
		rep(j, w + 2LL) {
			cout << b[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256