akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vl A(N);
    in(N,A);
    ll sum = 0;
    map<ll,ll> A_map;
    rep(i,N) sum += A[i];
    rep(i,N) A_map[A[i]]++;
    
    int Q;
    cin >> Q;
    vl ans;
    rep(qqq,Q){
        ll B,C;
        cin >> B >> C;
        ll a = A_map[B];
        A_map[B] = 0;
        sum -= B*a;
        
        A_map[C] += a;
        sum += C*a;
        
        ans.pb(sum);
        
        
    }
    
    rep(i,Q) cout << ans[i] << endl;
    
    

    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    cout << ((a * b) & 1 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/*
* @Author: Kabid
* @Date:   2020-04-29 14:50:32
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-13 14:27:58
*/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');

int t;       //test cases
int i,j;	 //iterators
double  n,k,p,f,c,s;   //variables
string q;
char h;
int main(){
	cin>>n;
	k=pow((n/3.0),3);
	printf("%lf\n",k);
	
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    for (int n = 0; n < N; ++n) {
        cin >> A[n];
    }
    for (int m = 0; m < M; ++m) {
        cin >> B[m];
    }
    
    vector<ll> SumA(N+1, 0);
    vector<ll> SumB(M+1, 0);
    for (int n = 0; n < N; ++n) {
        SumA[n+1] = SumA[n] + A[n];
    }
    for (int m = 0; m < M; ++m) {
        SumB[m+1] = SumB[m] + B[m];
    }
    
    int Ans = 0;
    int m = M;
    for (int n = 0; n <= N; ++n) {
        while (SumA[n] + SumB[m] > K) {
            --m;
            if (m < 0) break;
        }
        if (m < 0) break;
        if (n + m > Ans) Ans = n + m;
    }

    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 9592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

ll	n , k;
vector<int> a(1000001),f(1000001);

// 二分探索法
// index が条件を満たすかどうか
bool isOK(ll index) {
	ll  c = 0;
	for(int i=0;i<n;i++) {
		if ((ll)a[i]*f[i] > index) c += a[i] - index / f[i];
	}
	if (c > k) return false;
    else return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search() {
    ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = 1000000000001; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        ll mid = right + (left - right) / 2;

        if (isOK(mid)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

int main() {
	ll		b,c,d,w,h,i,j,l,m,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> n >> k;
	vector<int>	aa(n),ff(n);
	for(i=0;i<n;i++) cin >> aa[i];
	for(i=0;i<n;i++) cin >> ff[i];

	sort(aa.begin(),aa.end());
	sort(ff.begin(),ff.end());
	reverse(aa.begin(),aa.end());
	a = aa;
	f = ff;

	ans = binary_search();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12744
#include<bits/stdc++.h>
using namespace std;
#define RI register int
typedef long long LL;
LL ans,a,b,c,d,e,f,g;
int main()
{
	scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f,&g);
	ans+=b;
	if(a&&d&&e&&((a&1)+(d&1)+(e&1)>=2)) --a,--d,--e,ans+=3;
	ans+=2*(a/2+d/2+e/2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;



public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		ArrayList<BookIndex> indexes = new ArrayList<BookIndex>();
		while(true){
			String str = br.readLine();

			if(str == null){
				break;
			}
			String[] array = str.split(" ");
			String word = array[0];
			int page = Integer.parseInt(array[1]);

			boolean hit = false;
			Iterator<BookIndex> it = indexes.iterator();
			while(it.hasNext()){
				BookIndex tmpIndex = it.next();
				if(tmpIndex.word.equals(word)){
					tmpIndex.addPage(page);
					hit = true;
					break;
				}
			}

			if(!hit){
				indexes.add(new BookIndex(word, page));
			}
			//System.out.println(indexes.size());
		}

		BookIndex[] indexarray = new BookIndex[indexes.size()];
		indexes.toArray(indexarray);
		Arrays.sort(indexarray);
		for(int i = 0; i < indexarray.length ; i++){
			indexarray[i].print();
		}
	}

}

class BookIndex implements Comparable<BookIndex> {
	String word;
	ArrayList<Integer> page;

	public BookIndex (String word, int page){
		this.word = word;
		this.page = new ArrayList<Integer>();
		this.page.add(page);
	}

	@Override
	public int compareTo(BookIndex bookIndex) {
		// TODO ?????????????????????????????????????????????
		return word.compareTo(bookIndex.word);
	}

	public void addPage (int page){
		this.page.add(page);
	}

	public void print(){
		System.out.println(word);
		page.sort(new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				// TODO ?????????????????????????????????????????????
				if( o1 > o2 ){
					return 1;
				}
				else {
					return -1;
				}
			}

		});
		for(int i = 0; i< page.size() ; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(page.get(i));
		}
		System.out.println();
	}
}

Measured memory_bytes: 24364
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
string grid[100], s;
int x, y;
int w, h;

typedef pair<int, int> pii;

void move(int dx, int dy, char c){
  int nx = x + dx, ny = y + dy;
  if(c == 'R'){
    grid[y][x] = '>';
  }else if(c == 'L'){
    grid[y][x] = '<';
  }else if(c == 'U'){
    grid[y][x] = '^';
  }else if(c == 'D'){
    grid[y][x] = 'v';
  }
  if(0 <= nx && nx < w &&
     0 <= ny && ny < h &&
     grid[ny][nx] == '.'){
    grid[y][x] = '.';
    if(c == 'R'){
      grid[ny][nx] = '>';
    }else if(c == 'L'){
      grid[ny][nx] = '<';
    }else if(c == 'U'){
      grid[ny][nx] = '^';
    }else if(c == 'D'){
      grid[ny][nx] = 'v';
    }
    x = nx , y = ny;
  }
}

void shoot(char dist){
  //cout << "shoot" << endl;

  if(dist == 'v'){
    for(int i = 0;i + y < h; i++){
      if(grid[i + y][x] == '#' || grid[i + y][x] == '*'){
	if(grid[i + y][x] == '*')grid[i + y][x] = '.';
	break;
      }
    }
  }else if(dist == '<'){
    for(int i = 0;i + x >= 0; i--){
      if(grid[y][x + i] == '#' || grid[y][x+i] =='*'){
	if(grid[y][x+i] == '*')grid[y][x+i] = '.';
	break;
      }
    } 
  }else if(dist == '>'){
    for(int i = 0;i + x < w; i++){
      if(grid[y][x + i] == '#' || grid[y][x+i] =='*'){
	if(grid[y][x+i] == '*')grid[y][x+i] = '.';
	break;
      }
    } 
  }else{
    for(int i = 0;i + y >= 0; i--){
      if(grid[i + y][x] == '#' || grid[i + y][x] == '*'){
	if(grid[i + y][x] == '*')grid[i + y][x] = '.';
	break;
      }
    }
  }
	
}

int main(){
  int n;
  cin >> n;
  for(int ite = 0; ite < n; ite++){

    cin >> h >> w;
    for(int i = 0;i < h; i++){
      cin >> grid[i];
    }

    for(int i = 0;i < h; i++){
      for(int j = 0;j < w; j++){
	if(grid[i][j] == 'v' || grid[i][j] == '<' ||
	   grid[i][j] == '>' || grid[i][j] == '^'){
	  x = j; y = i;
	}
      }
    }
    map<char, pii> next_trun;
    next_trun['R'] = mp(1, 0);
    next_trun['U'] = mp(0, -1);
    next_trun['L'] = mp(-1, 0);
    next_trun['D'] = mp(0, 1);
    next_trun['S'] = mp(0, 0);
    int tmp;
    cin >> tmp >> s;
    for(int i = 0; i < s.length(); i++){
      if(next_trun[s[i]].first == 0 && next_trun[s[i]].second == 0){
	shoot(grid[y][x]);
      }else{
	move(next_trun[s[i]].first, next_trun[s[i]].second, s[i]);
      }
      //cout << next_trun[s[i]].first << " " << next_trun[s[i]].second << endl;

      //cout << s[i] << " " << x << " " << y << endl;
    }
    for(int i = 0; i < h; i++){
      cout << grid[i] << endl;
    }
    if(ite < n - 1) cout << endl;
  }
}

Measured memory_bytes: 1204
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        for(int i = a; i <= b; i++){
            if(i % k == 0){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
        scan.close();
    }
}

Measured memory_bytes: 27088
#include<stdio.h>

int main(){
	long long int x[6], max;
	
	scanf("%lld%lld%lld%lld", &x[1],&x[2],&x[3],&x[4]);
	max=x[1]*x[3];
	
	for(int i=1; i<=2; i++){
		for(int j=3; j<=4; j++){
			if(x[i]*x[j]>max) max=x[i]*x[j];
		}
	}
	
	printf("%lld\n", max);
	
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int64_t>L;
  L.push_back(A[0]);
  for(int i=1;i<N;i++){
  auto itr=lower_bound(L.begin(),L.end(),A[i]);
    int k=distance(L.begin(),itr);
    if(k==0)
      L.insert(L.begin(),A[i]);
    else
      L.at(k-1)=A[i];
    
  
  }int ans=L.size();
  cout<<ans<<endl;
  
  
     return 0;
}

Measured memory_bytes: 2168
#include<stdio.h>
int main(void)
{
char number[1001];
int num[1001],i=0;
int num2=0;
while(1){
	scanf("%s",number);
	for(i=0;i<1001;i++){
	num[i]=number[i]-'0';
	if(num[i]==-48)break;
	num2+=num[i];
	}
	if((number[0]=='0')&&(num[1]==-48))break;
	printf("%d\n",num2);
	num2=0;
	for(i=0;i<1001;i++)number[i]='/';
}
return 0;
}

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

const int N = 250000;

constexpr int inv(int a, int m) {
  return a == 1 ? 1 : 1LL * (m - m / a) * inv(m % a, m) % m;
}

const int BASE = 1000003;
const int M = 2;
const int MODS[] = {1000000007, 1000000009};

// template <int BASE, int... INTS> struct HashT {
struct HashT {
  // static constexpr int M = sizeof...(INTS);
  // static constexpr std::array<int, M> MODS = {INTS...};

  explicit HashT(int a) {
    for (int i = 0; i < M; ++i) {
      h[i] = a;
    }
  }

  explicit HashT(const HashT &a, const HashT &b) {
    for (int i = 0; i < M; ++i) {
      h[i] = 1LL * a.h[i] * b.h[i] % MODS[i];
    }
  }

  explicit HashT(const HashT &k, const HashT &b, const HashT &bf) {
    for (int i = 0; i < M; ++i) {
      h[i] = 1LL * k.h[i] * (b.h[i] + MODS[i] - bf.h[i]) % MODS[i];
    }
  }

  template <int a> void add() {
    for (int i = 0; i < M; ++i) {
      h[i] += a >= 0 ? a : MODS[i] + a;
      if (h[i] >= MODS[i]) {
        h[i] -= MODS[i];
      }
    }
  }

  void multiplyB() {
    for (int i = 0; i < M; ++i) {
      h[i] = 1LL * h[i] * BASE % MODS[i];
    }
  }

  void divideB() {
    for (int i = 0; i < M; ++i) {
      h[i] = 1LL * h[i] * inv(BASE, MODS[i]) % MODS[i];
    }
  }

  int h[M];
};

// template <int BASE, int... INTS>
// bool operator<(const HashT<BASE, INTS...> &a, const HashT<BASE, INTS...> &b) {
// bool operator<(const HashT<BASE, INTS...> &a, const HashT<BASE, INTS...> &b) {
//   for (int i = 0; i < HashT<BASE, INTS...>::M; ++i) {
bool operator<(const HashT &a, const HashT &b) {
  for (int i = 0; i < M; ++i) {
    if (a.h[i] != b.h[i]) {
      return a.h[i] < b.h[i];
    }
  }
  return false;
}

int n;
char s[N + 1];

// using Hash = HashT<3, 1000000007, 1000000009>;
using Hash = HashT;

struct Set {
  Set() : k{1}, b{0} {}

  void add(int c) {
    if (c == '+') {
      b.add<-1>();
    } else if (c == '-') {
      b.add<1>();
    } else if (c == '>') {
      b.multiplyB();
      k.divideB();
    } else {
      k.multiplyB();
      b.divideB();
    }
  }

  Hash zero() const { return Hash{k, b}; }
  Hash inverse(const Hash &kb) const { return Hash{k, b, kb}; }

  Hash k, b;
};

int main() {
  while (scanf("%d%s", &n, s) == 2) {
    Set setf;
    for (int i = n - 1; i >= 0; --i) {
      setf.add(s[i]);
    }
    Set set;
    long long result = 0;
    std::map<Hash, int> cnt;
    for (int i = n - 1; i >= 0; --i) {
      cnt[set.zero()]++;
      set.add(s[i]);
      result += cnt[set.inverse(setf.b)];
    }
    printf("%lld\n", result);
  }
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
 
string dec2bin(long long decimal, int size){
  long long binary = 0;
  for(int i=0; decimal>0; i++){
    binary += decimal % 2 * pow(10, i);
    decimal = decimal / 2;
  }
  string str_binary;
  str_binary = to_string(binary);
  while(str_binary.size() != size){
    str_binary = "0" + str_binary; 
  }
  return str_binary;
}
 
int main() {
  string S;
  cin >> S;
  long long sum = 0;
  int num_cases = pow(2, S.size()-1);
  string e = "";
  
  if(S.size() == 1){
    cout << S << endl;
    return 0;
  }
  for(int i=0; i<num_cases; i++){
    e = S.at(0);
    string str_bin = dec2bin(i, S.size()-1);
    for(int j=0; j<S.size()-1; j++){
      if (!(i>>j&1)){
      //if(str_bin.at(j) == '0'){
        e += S.at(j+1);
      }else{
        sum += (long long) stoll(e);
        e = S.at(j+1);
      }
    }
    sum += (long long) stoll(e);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int A,B,C;
	int count=0;

	scanf("%d %d %d",&A,&B,&C);

	while(1){
		if(A<=B){
			count++;
			B=B-A;
		}else{
			break;
		}
		if(count==C){
			break;
		}
	}
	printf("%d\n",count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int a;cin>>a;
  cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3632
package main

import "fmt"

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

	if a < 6 {
		fmt.Println(0)
	} else if a < 13 {
		fmt.Println(b / 2)
	} else {
		fmt.Println(b)
	}

}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

struct BIT{
    int M;
    vector<ll> bit;
    BIT(int n): M(n), bit(M+1,0) {}

    void add(int a, ll w=1) { // aを +w  aは 1-indexed
        for(int x=a; x<=M; x+= x& -x){
            bit[x] += w;
        }
    }

    ll sum(int a) { // [1,a] 1-indexed
        ll ret=0;
        for(int x=a; x>0; x-= x& -x){
            ret+= bit[x];
        }
        return ret;
    } // 左上のものをすべて足す
};

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;

    ll N=S.size();
    vector<deque<ll>> A(26);
    rep(i,N){
        A[S[i]-'a'].emplace_back(i);
    }
    ll ct=0;
    ll mid=-1;
    rep(i,26){
        if(A[i].size()%2==1) {++ct; mid=i;} 
    }
    if(ct>1) dame;

    BIT bi(N+2);
    ll hai=0;
    ll cost=0;
    rep(i,N){
        ll c=S[i]-'a';
        ll dore;
        ll togo;
        if(A[c].size()==0) continue;
        if(A[c].size()==1) {
            cost+=abs(N/2-hai);
            A[c].pop_back();
            continue;
        }
        
        togo=N-1-hai;
        dore=A[c].back();
        A[c].pop_front();
        A[c].pop_back();
        
        cost+=togo-(dore-bi.sum(dore+1));
        bi.add(dore+1,1);
        ++hai;
    }
    cout<< cost <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  vector<int> a(n); REP (i, n) cin >> a[i];
  sort(ALL(a));
  int ans = 0;
  REP (i, n) {
    if (i == 0) ans -= a[i];
    else if (i == n - 1) ans += a[i];
    else ans += abs(a[i]);
  }
  cout << ans << endl;

  vector<int> plus, minus;
  REPI (i, 1, n - 1) {
    if (a[i] >= 0) plus.push_back(a[i]);
    else minus.push_back(a[i]);
  }
  int acc0 = a[0];
  for (int x : plus) {
    cout << acc0 << " " << x << endl;
    acc0 -= x;
  }
  int acc1 = a[n - 1];
  cout << acc1 << " " << acc0 << endl;
  acc1 -= acc0;
  for (int x : minus) {
    cout << acc1 << " " << x << endl;
    acc1 -= x;
  }
  assert(acc1 == ans);
}


Measured memory_bytes: 3572
from collections import deque
A = deque()
ans = []


def push(d, x):
    global A
    if d == 0:
        A.appendleft(x)
    elif d == 1:
        A.append(x)


def randomAccess(p):
    global A, ans
    if A != []:
        ans.append(A[p])
    else:
        print('RandomAccessError')


def pop(d):
    global A
    if d == 0:
        A.popleft()
    elif d == 1:
        A.pop()


def main():
    q = input()

    for i in range(int(q)):
        command = input().split()
        if len(command) == 3:
            query, operation, number = (int(x) for x in command)
            push(operation, number)
        else:
            query, number = (int(x) for x in command)
            if query == 1:
                randomAccess(number)
            else:
                pop(number)

    for i in range(len(ans)):
        print(ans[i])


if __name__ == "__main__":
    main()



Measured memory_bytes: 22024
#include<iostream>
using namespace std;
string n;int A,k;
int g(int a,int b){A=6;while(b--)A*=(a-b)*9,A/=b+1;return A/6;}
int f(int i,int a){int A=n.size()-i;return A--<a?0:a?n[i]=='0'?f(i+1,a):g(A,a--)+g(A,a)*(n[i]-'1')+f(i+1,a):1;}
main(){cin>>n>>k;cout<<f(0,k);}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>

using namespace std;

int main()
{
  vector<vector<pair<char, int>>> maze;
  int H;
  int W;
  cin >> H >> W;
  maze.resize(H + 2, vector<pair<char, int>>(W + 2, {'#', 400}));

  for (int h = 0; h < H; h++) {
    string str;
    cin >> str;
    for (int w = 0; w < W; w++) {
      maze[h + 1][w + 1].first = str[w];
    }
  }

  int distance_max = 0;

  for (int h = 1; h <= H; h++) {
    for (int w = 1; w <= W; w++) {
      if (maze[h][w].first == '#') continue;

      vector<vector<pair<char, int>>> copy_maze = maze;
      copy_maze[h][w].second = 0;

      vector<pair<int, int>> present_boxes_position(1, {h, w});
      vector<pair<int, int>> next_boxes_position(0);

      while (true) {

        for (auto &&box_position : present_boxes_position) {
          for (int i = 0; i < 4; i++) {
            pair<char, int> &box = copy_maze[box_position.first][box_position.second];
            pair<char, int> &neighboring_box =
                copy_maze[box_position.first + i % 2 * (1 - 2 * signbit((double)i - 2))][box_position.second + !(i % 2) * (1 - 2 * signbit((double)i - 2))];

            if (neighboring_box.first != '#' && neighboring_box.second > box.second + 1) {
              neighboring_box.second = box.second + 1;
              next_boxes_position.push_back(
                  {box_position.first + i % 2 * (1 - 2 * signbit((double)i - 2)),
                   box_position.second + !(i % 2) * (1 - 2 * signbit((double)i - 2))});
              if (distance_max <= box.second + 1) {
                distance_max = box.second + 1;
              }
            }
          }
        }
        if (next_boxes_position.size() == 0) {
          break;
        }
        else {
          present_boxes_position = next_boxes_position;
          next_boxes_position.resize(0);
        }
      }
    }
  }

  cout << distance_max << flush;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdarg.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)<(y)?(x):(y)
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define reps(i,n,k) for((i)=0;(i)<(n);(i)+=(k))
#define MOD ((int)1e9+7)
#define INF INFINITY
typedef long long ll;
typedef unsigned long long ull;
typedef struct pair_{int x,y;}pair_t;
void swap(int *x, int *y){int t=*x;*x=*y;*y=t;}
void debug(char *f, ...){va_list a;va_start(a,f);vfprintf(stderr,f,a);va_end(a);}
int asc_cmp(const void *x, const void *y){int X=*((int*)x),Y=*((int*)y);if(X<Y)return -1;else if(X>Y)return 1;else return 0;}
int desc_cmp(const void *x, const void *y){int X=*((int*)x),Y=*((int*)y);if(X<Y)return 1;else if(X>Y)return -1;else return 0;}

int main(){
    int n,m;scanf("%d %d",&n,&m);
    int a[200000];for(int i=0;i<m;i++)scanf("%d",&a[i]);
    qsort(a,m,sizeof(int),asc_cmp);
    int sum=0;
    for(int i=0;i<m;i++){
        sum+=a[i];
        if(sum>n){
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n",n-sum);

}

Measured memory_bytes: 1788
using System;
 
class Program
{
        public static void Main()
        {
            string line = Console.ReadLine();
            double r = double.Parse(line);
 
            double a = r * r * Math.PI;
            double b = 2 * Math.PI * r;
 
            Console.WriteLine(a.ToString("F5") + " " + b.ToString("F5"));
        }
}

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




int main(){


	int Nmax = 1000000;
	bool isp[Nmax]={};
	int count[Nmax]={};

	isp[2] = true;
	for(int i=3;i<Nmax;i+=2){
		isp[i] = true;
	}

	for(int i=3;i<Nmax;i+=2){
		if(isp[i]){
			int j = i*2;
			while(j<Nmax){
				isp[j] = false;
				j += i;
			}
		}
	}

	for(int i=1;i<Nmax;i++){
		count[i] = count[i-1] + isp[i];
	}

	int n;
	while(cin >> n){
		cout << count[n] << endl;
	}

}


Measured memory_bytes: 7928
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n;
int a[510][510];
int color[510];

void dfs(int v, int c){
    color[v] = c;
    for(int i = v + 1; i < n; i++){
        if(a[v][i] == 0 && color[i] == 0){
            dfs(i, -c);
        }
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int k = 1;; k++){
        rep(i, 0, n) color[i] = 0;
        rep(i, 0, n){
            if(color[i] == 0) dfs(i, 1);
        }
        rep(i, 0, n){
            rep(j, i + 1, n){
                if(a[i][j] == 0){
                    if(color[i] != color[j]){
                        a[i][j] = k;
                    }
                }
            }
        }
        int cnt = 0;
        rep(i, 0, n){
            rep(j, i + 1, n){
                if(a[i][j] == 0) cnt++;
            }
        }
        if(cnt == 0) break;
    }
    rep(i, 0, n - 1){
        rep(j, i + 1, n){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int N,A,B;
    cin>>N>>A>>B;
    
    string S;
    cin>>S;
    
    int cntA=0,cntB=0;
    REP(i,S.size()){
        if(S[i]=='a'){
            if(cntA+cntB<A+B){
                cout<<"Yes"<<endl;
                cntA++;
            }else{
                cout<<"No"<<endl;
            }
        }else if(S[i]=='b'){
            if(cntA+cntB<A+B){
                if(cntB<B){
                    cout<<"Yes"<<endl;
                    cntB++;
                }else{
                    cout<<"No"<<endl;
                }
            }else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 896
from itertools import combinations

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

if k > (n - 1) * (n - 2) // 2:
  print(-1)
else:
  print(n * (n - 1) // 2 - k)
  for i in range(1, n):
    print(i, n)
  edge = combinations(range(1, n), 2)
  for _ in range((n - 1) * (n - 2) // 2 - k):
    u, v = next(edge)
    print(u, v)

Measured memory_bytes: 3616
N, K = map(int, input().split())
MOD = 10**9 + 7

ans = 0
for k in range(K, N + 2):
    S = k * (k - 1) // 2
    mx = N * k - S
    mi = S
    ans += mx - mi + 1
    ans %= MOD
print(ans)


Measured memory_bytes: 9108
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		vi in(n);
		rep(i,n)rep(j,5){
			int a;
			cin>>a;
			in[i]+=a;
		}
		sort(all(in));
		cout<<in[n-1]<<" "<<in[0]<<endl;
	}
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n;
    ll t;
    cin>>n>>t;
    vector<ll> time(n);
    REP(i,n) cin>>time[i];

    ll v=0,p=0;
    REP(i,n){
        if(i==0) v=t;
        else v+=(time[i]-time[i-1]<t)? time[i]-time[i-1]:t;
    }
    cout<<v<<endl;

	return 0; 
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc =new Scanner(System.in);
        int A,B,K;
        A=sc.nextInt();
        B=sc.nextInt();
        K=sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int a=A;a<A+K;a++){
            if(a<=B) list.add(a);
            else break;
        }
        for(int a=B-K+1;a<=B;a++){
            if(list.contains(a)!=true&&A<=a) list.add(a);
        }
        for (int a=0;a<list.size();a++){
            System.out.println(list.get(a));
        }
    }
}

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

typedef long long ll;
const int MAX = 10005;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    ll a[MAX],b[MAX],p,q,d;
    while(cin >> n)
    {
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++)
            cin >> b[i];

        p = q = 0;
        for(int i = 0; i < n; i++)
            if(b[i] <= a[i])
                q += a[i] - b[i];
            else 
            {
                d = b[i]-a[i];
                p += (d+1)/2;
                if(d % 2 != 0)
                    q++;
            }
        cout << (p >= q? "Yes" : "No") << '\n';
    }
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct edge_t {
  int to, ind;
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vec<edge_t, 2> G(N);
    for (int i = 0; i < N - 1; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].push_back({b, i});
      G[b].push_back({a, i});
    }
    int K = 0;
    for (int i = 0; i < N; i++) chmax(K, (int)G[i].size());
    vector<int> res(N - 1);
    auto dfs = [&](auto& dfs, int v, int p, int ng) -> void {
      int c = 0;
      for (auto& e : G[v]) {
        if (e.to == p) continue;
        if (c == ng) ++c;
        c = c % K;
        res[e.ind] = c;
        dfs(dfs, e.to, v, c);
        ++c;
      } 
    };
    dfs(dfs, 0, -1, -1);
    cout << K << endl;
    for (int x : res) cout << x + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll X; cin >> X;
    ll out = 0;
    cerr << X/500 << " " << X-(X/500)*500 << endl;
    out += (X/500)*1000 + ((X-(X/500)*500)/5)*5;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int main () {
	SpeedForce;
	int n;
	cin >> n;
	ll ans = 0;
	
	int mx = 0;
	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		
		ans += max(0, mx-x);
		mx = max(mx, x);
	}
	cout << ans << '\n';
	
	return Accepted;
}

// B...a


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

typedef struct {
	int id;
	long long sales;
} Data;

Data data[ 4000 ];

int main( void ) {
	int i, j;
	int n;

	while( scanf( "%d", &n ), n ) {
		int cnt, flag;

		memset( data, 0, sizeof data );

		cnt = 0;
		for ( i = 0; i < n; i++ ) {
			int id, price, num;

			scanf( "%d %d %d", &id, &price, &num );

			for ( j = 0; j < cnt && data[ j ].id != id; j++ ) ;
			if ( j == cnt )
				data[ cnt++ ].id = id;
			data[ j ].sales += (long long)price * num;
		}

		flag = 0;
		for ( i = 0; i < cnt; i++ )
			if ( data[ i ].sales >= 1000000LL ) {
				printf( "%d\n", data[ i ].id );
				flag = 1;
			}
		if ( !flag )
			puts( "NA" );
	}

	return 0;
}

Measured memory_bytes: 680
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

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

using namespace std;
using ll = long long;

vector<int> tree[100000];

int grundy(int x, int prev) {
    int g = 0;
    for (int v : tree[x]) {
        if (v != prev)
            g ^= grundy(v, x);
    }
    return g + 1;
}

int main(){
    int N;
    scanf("%d", &N);

    for (int i = 0; i < N - 1; ++i) {
        int v1, v2;
        scanf("%d%d", &v1, &v2);
        --v1;
        --v2;
        tree[v1].push_back(v2);
        tree[v2].push_back(v1);
    }

    printf(grundy(0, -1) == 1 ? "Bob\n" : "Alice\n");
}

Measured memory_bytes: 10368
#include <stdio.h>

int main() {
	int d;
	scanf(" %d", &d);
	if (d==25) {
		printf("Christmas\n");
	}
		if (d==24) {
		printf("Christmas Eve\n");
	}
		if (d==23) {
		printf("Christmas Eve Eve\n");
	}
		if (d==22) {
		printf("Christmas Eve Eve Eve\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  //in
  int n, s;
  cin >> n >> s;
  vector<int> x;
  x.push_back(s);
  REP(i,n) {
    int xx;
    cin >> xx;
    if(xx == s) continue;
    x.push_back(xx);
  }

  debug(x);
  sort(ALL(x));

  vector<int> len(x.size() - 1);
  
  REP(i,len.size()){
    len[i] = abs(x[i+1]- x[i]);
  }

  debug(len);
  //x座標と同じ値がなければ配列に追加
  int g = len[0];
  REP(i,len.size()){
    g = __gcd(g,len[i]);
  }

  cout << g << endl;

  return 0;
}


Measured memory_bytes: 4060
#ifdef __APPLE__
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>
#else
# include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

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

const int max_n = -1, inf = 1000111222;

int cnt[100][100];

ll my_to_ll(string s)
{
    ll res=0;
    for (auto i:s){
        res=res*10+(i-'0');
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin>>n;
    for (int i=0;i<n;i++){
        string s;
        cin>>s;
        bool have_dot=0;
        for (auto j:s){
            have_dot|=(j=='.');
        }

        if (!have_dot){
            s.push_back('.');
        }
        for (int it=0;it<9;it++){
            if (s.back()=='.'){
                s.pop_back();

                s.push_back('0');
                s.push_back('.');
            }
            else{
                for (int i=0;i+1<len(s);i++){
                    if (s[i]=='.'){
                        swap(s[i],s[i+1]);
                        break;
                    }
                }
            }
        }
        assert(s.back()=='.');
        s.pop_back();
        ll lol=my_to_ll(s);

        int cnt_2=0;
        int cnt_5=0;
        while (lol%2==0){
            cnt_2++;
            lol/=2;
        }
        while (lol%5==0){
            cnt_5++;
            lol/=5;
        }

//        cout<<cnt_2<<" "<<cnt_5<<"\n";
        cnt[cnt_2][cnt_5]++;
    }

    ll ans=0;
    for (int c2=0;c2<100;c2++){
        for (int c5=0;c5<100;c5++){
            if (cnt[c2][c5]){
                int cur_ways=cnt[c2][c5];
                cnt[c2][c5]--;
                for (int cc2=0;cc2<100;cc2++){
                    for (int cc5=0;cc5<100;cc5++) {
                        if (cnt[cc2][cc5] && c2+cc2>=18 && c5+cc5>=18){
                            ans+=1ll*cur_ways*cnt[cc2][cc5];
                        }
                    }
                }
                cnt[c2][c5]++;
            }
        }
    }

//    cerr<<"ans :: "<<ans<<"\n";
    assert(ans%2==0);
    cout<<ans/2<<"\n";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];

    sort(all(p));
    p[n-1] /= 2;
    int ans = 0;
    REP(i, n) ans += p[i];
    cout << ans << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int wsum[500000], esum[500000];

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (int i=1; i<=N; ++i) {
        wsum[i] = wsum[i-1]+(S[i-1]=='W');
        esum[i] = esum[i-1]+(S[i-1]=='E');
    }
    int ans = 1e8;
    for (int i=1; i<=N; ++i) {
        ans = min(ans, (wsum[i-1]-wsum[0])+(esum[N]-esum[i]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++)
        {
            p[i] = sc.NextInt();
        }
        int res = 0;
        for (int i = 1; i < n - 1; i++)
        {
            if ((p[i - 1] > p[i] && p[i] > p[i + 1]) || (p[i - 1] < p[i] && p[i] < p[i + 1])) res++;
        }
        Console.WriteLine(res);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }

    static long Lcm(long a, long b)
    {
        long d = Gcd(a, b);
        return a / d * b;
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092