akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            long[] H = new long[N];
            for (int i = 0; i < N; i++) {
                H[i] = in.nextLong();
            }
            for (int i = N - 1; 0 < i; i--) {
                long diff = H[i] - H[i - 1];
                if (diff < -1) {
                    out.println("No");
                    return;
                } else if (diff == -1) {
                    H[i - 1]--;
                }
            }
            out.println("Yes");
        }

    }
}



Measured memory_bytes: 60892
#include<bits/stdc++.h>
using namespace std;
int a[100005];
long long cnt[100005];
long long ans;
int main()
{
    int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
       	scanf("%d",&a[i]),ans+=a[i],cnt[a[i]]++;
    long long q;
    scanf("%lld",&q);
    for(int i=1;i<=q;++i)
    {
    	int j,k;
    	cin>>j>>k;
    	ans+=(k-j)*cnt[j];
    	cnt[k]+=cnt[j];
    	cnt[j]=0;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 4880
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long double ld;

int main() {
    std::cout<< std::setprecision(11) << std::fixed;
    int r, n;
    while(cin >> r >> n, r != 0 || n != 0) {
        vi xl(n), xr(n), h(n);
        REP(i, n) cin >> xl[i] >> xr[i] >> h[i];

        vector<int> px;
        px.push_back(-100);
        px.push_back(-r);
        px.push_back(0);
        px.push_back(+r);
        px.push_back(+100);
        n = -1;
        REP(i, xl.size()) {
            px.push_back(xl[i]);
            px.push_back(xr[i]);
        }
        sort(ALL(px));
        px.erase(unique(ALL(px)), px.end());
        vector<int> ph(px.size(), 0);
        REP(k, px.size()) {
            REP(i, xl.size()) {
                int x = px[k];
                if (xl[i] <= x && x < xr[i]) ph[k] = max(ph[k], h[i]);
            }
        }

        // REP(i, ph.size()){  cout<< "#" << px[i] << " - " << ph[i] << endl; }

        ld al = 0;
        ld ar = 100;
        ld eps = 0.00000001;
        while(ar - al > eps) {
            ld m = (al + ar) / 2;
            bool ok = true;
            REP(i, px.size() - 1) {
                ld nl = px[i], nr = px[i + 1];
                ld nh =  ph[i] - m + r;
                nh = max(0.0L, nh);
                // cout<< "T=" << m << " Check:" << nl << "," << nr << " H:" << nh << endl;
                ld rl = r * r - nl * nl;
                ld rr = r * r - nr * nr;
                // cout<< "=" << rl << "," << rr << endl;
 
                if (rl > nh * nh || rr > nh * nh) {
                    ok = false;
                    break;
                }
            }
            if (ok) { al = m; /* cout<< "OK" << endl; */}
            else { ar = m; /* cout<< "NG" << endl; */}
        }
        cout<< al << endl;
    }

}


Measured memory_bytes: 3204
#include <cstdio>

typedef long long ll;

const ll MAX_N = 100000;
ll N;
ll A[MAX_N + 1];
ll B[MAX_N + 1];

ll f(ll i, ll add)
{
    ll nowA = A[i] + add;
    ll X = nowA % B[i];
    if(X == 0){
        return 0;
    }
    return B[i] - X;
}

int main()
{
    scanf("%lld", &N);
    for(ll i = 1; i <= N; i++){
        scanf("%lld %lld", &A[i], &B[i]);
    }

    ll answer = 0;
    for(ll i = N; i >= 1; i--){
        answer += f(i, answer); 
    }
    
    printf("%lld\n", answer);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll n;
	cin >> n;
	
	if( n % 2 ) {	
		cout << 0 << endl;
		return 0;
	}
	
	ll ans = 0;
	n /= 2;
	
	while( n >= 5 ) {
		ans += n / 5;
		n /= 5;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        /**
         *入力部
         **/
        int n = sc.nextInt();
        int[] w = new int[n];
        int t = 1;
        sc.nextLine();
        int[] s_1=new int[n];
        int[] s_2 =new int[n];
        int min = 0;
        for(int j =0; j < n;j++){
            w[j]=sc.nextInt();
        }
        //どのtでS_1-S_2が最小となるか
        for(int j =0; j < n;j++){
            
        for(int i =0;i < n;i++){
            if(i <= j){
                //s_1を求める
                s_1[j] = s_1[j] +w[i];
            } else {
                s_2[j] = s_2[j] + w[i];
            }
            
        }
        }
        min=Math.abs(s_1[0]-s_2[0]);
        for(int k =0; k < n;k++){
        if(min > Math.abs(s_1[k]-s_2[k])){
            min = Math.abs(s_1[k]-s_2[k]);
        }
        }
        
        System.out.println(min);
    }
}


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

using namespace std;

const int N = int(2e5) + 5;
const int MOD = int(1e9) + 7;
const int inf = int(2e9);

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

    string s;
    cin >> s;
    if (s[0] != s[1] || s[1] != s[2] || s[0] != s[2])
        cout << "Yes";
    else cout << "No";
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, k, c;
  cin >> n >> k >> c;

  string s;
  cin >> s;

  vector<ll> l(k, -1);
  ll x = 0;
  for (ll i = 0; i < s.size(); ++i) {
    if (x == k) break;
    if (s[i] == 'o') {
      l[x] = i;
      x++;
      i += c;
    }
  }

  vector<ll> r(k, -1);
  x = k-1;
  for (ll i = s.size()-1; i >= 0; --i) {
    if (x < 0) break;
    if (s[i] == 'o') {
      r[x] = i;
      x--;
      i -= c;
    }
  }

  for (ll i = 0; i < k; ++i) {
    if (l[i] == r[i]) {
      cout << l[i]+1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,int>mp;
int main(){
	ll x;
	cin>>x;
	for(ll i=-1000;i<=1000;i++){
	 for(ll j=-1000;j<=1000;j++){
	 	if(pow(i,5)-pow(j,5)==x) {cout<<i<<' '<<j<<'\n';return 0;}
	 }
  }
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;

int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    ll dist = x;
    if(x <= 0){
        dist = -x;
    }
    ll meyasu = dist / d;
    if(meyasu >= k){
        cout << dist - k * d;
    }
    else{
        if(x >= 0){
            /*ll pos1,pos2;
            pos1 = x - d * meyasu;
            pos2 = x - d * (meyasu+1);
            ll ans1,ans2;
            if(k - meyasu % 2 == 0){
                ans1 = pos1;
            }
            else{
                ans1 = -(pos1 - d);
            }
            if((k - meyasu - 1) % 2 == 0){
                ans2 = -pos2;
            }
            else{
                ans2 = pos2+d;
            }
            cout << min(ans1,ans2) << endl;*/
            if((k - meyasu) % 2 == 0){
                cout << x - d * meyasu << endl;
            }
            else{
                cout << -(x - d * (meyasu + 1)) << endl;
            }

        }
        else{
            /*ll pos1,pos2;
            pos1 = x + d * meyasu;
            pos2 = x + d * (meyasu+1);
            ll ans1,ans2;
            if(k - meyasu % 2 == 0){
                ans1 = -pos1;
            }
            else{
                ans1 = pos1 + d;
            }
            if((k - meyasu - 1) % 2 == 0){
                ans2 = pos2;
            }
            else{
                ans2 = -pos2+d;
            }
            cout << min(ans1,ans2) << endl;*/
            if((k - meyasu)% 2 == 0){
                cout << dist -  d * meyasu << endl;
            }
            else{
                cout << d * (meyasu+1) - dist << endl;
            }
        }
    }
}

Measured memory_bytes: 3604
# from math import factorial,sqrt,ceil,gcd,pi
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# slist = "abcdefghijklmnopqrstuvwxyz"
R = int(input())

ans = 2*R*3.14159265359

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9152
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())
a.sort()
b.sort()
if n%2:ans=b[n//2]-a[n//2]+1
else:ans=b[(n-1)//2+1]-a[(n-1)//2+1]+b[(n-1)//2]-a[(n-1)//2]+1
print(ans)

Measured memory_bytes: 82252
import math
a,b=map(int,input().split())
print(math.gcd(a,b))

'''
# 09.98 sec    13492 KB    4 lines     99 bytes
# Time Limit Exceeded
n=int(input())
r=[int(input())for _ in range(n)]
print(max([max(r[i+1:])-r[i]for i in range(n-1)]))
'''

Measured memory_bytes: 5664
//in the name of allah
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int> g[N];
bool mark[N];

int main(){               
        int n , m;
        scanf("%d%d" , &n , &m);       
        deque<int> dq;
        for(int i=0 ; i<m ; i++){
                int a , b;
                scanf("%d%d" , &a , &b);
                a--;
                b--;
                g[a].push_back(b);
                g[b].push_back(a);
                if(i == 0){
                        dq.push_front(a);
                        dq.push_front(b);
                        mark[a] = mark[b] = true;
                }
        }
        while(true){
                int v = dq.back();
                bool f = true;
                for(auto u : g[v]){
                        f &= mark[u];
                        if(!mark[u]){
                                dq.push_back(u);
                                mark[u] = true;
                                break;
                        }
                }
                if(f)
                        break;
        }
        while(true){
                int v = dq.front();
                bool f = true;
                for(auto u : g[v]){
                        f &= mark[u];
                        if(!mark[u]){
                                dq.push_front(u);
                                mark[u] = true;
                                break;
                        }
                }
                if(f)
                        break;
        }
        int len = (int)dq.size();
        printf("%d\n" , len);        
        for(int i=0 ; i<len ; i++){
                printf("%d" , dq[i]+1); 
                if(i == len-1)
                        puts("");
                else
                        printf(" ");
        }                                
        return 0;
}

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

int main(){
  int N;
  cin >> N;
  int tmp;
  set <int> set_i;
  for(int i=0;i<N;i++){
    cin >> tmp;
	set_i.insert(tmp);
  }
  cout << set_i.size() << endl; 
  return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n, m, x = map(int, input().split())
    factors = [ tmp for tmp in range(n+1) ]
    gateFlag = [ False for tmp in range(n+1) ]
    a = list(map(int, input().split()))
    for tmp in range(m):
        gateFlag[a[tmp]] = True
    ansFactor = 0
    ansFactor2 = 0
    pivot = x
    while pivot-1 > 0:
        if gateFlag[pivot-1]:
            ansFactor += 1
        else:
            pass
        pivot -= 1
    else:
        pivot = x
    while pivot+1 < n:
        if gateFlag[pivot+1]:
            ansFactor2 += 1
        else:
            pass
        pivot += 1
    print(min(ansFactor, ansFactor2))

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a, Collections.reverseOrder());
        int alice = 0;
        int bob = 0;
        for (int i =0;i<n;i++){
            if(i %2 == 0) {
                alice += a[i];
            } else{
                bob += a[i];
            }
        }
        System.out.println(alice - bob);

    }
}


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

using namespace std;

#define PI acos(-1.0)

struct Point {
    double x, y;
};

int n;

int Plot(Point p1, Point p2, int counter) {
    if (counter >= n) return 0;

    double angle = 60.0 * (PI / 180.0); // degree to rad
    Point s, t, u;
    s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
    s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
    t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
    t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
    u.x = (t.x - s.x) * cos(angle) - (t.y - s.y) * sin(angle) + s.x;
    u.y = (t.x - s.x) * sin(angle) + (t.y - s.y) * cos(angle) + s.y;
    counter++;

    Plot(p1, s, counter);
    printf("%.8lf %.8lf\n", s.x, s.y);
    Plot(s, u, counter);
    printf("%.8lf %.8lf\n", u.x, u.y);
    Plot(u, t, counter);
    printf("%.8lf %.8lf\n", t.x, t.y);
    Plot(t, p2, counter);
}

int main() {
    const Point first = {0.0, 0.0}, second = {100.0, 0.0};

    cin >> n;
    printf("%.8lf %.8lf\n", first.x, first.y);
    Plot(first, second, 0);
    printf("%.8lf %.8lf\n", second.x, second.y);

    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  vector<int> road(n);
  int counter;
  counter = 0;
  
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    road.at(i) = i+1;
  }
  

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++){
      if (a.at(j) == road.at(i)){	
        counter++;
      }
      else if (b.at(j) == road.at(i)){
        counter++;
      }
    }
    cout << counter << endl;
    counter = 0;
    
  }
  
  
  
  
}



Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    string x;
    cin>>x;
    int a = x[0] - '0';
    int b = x[1] -'0';
    int c = x[2] - '0';
    int d = x[3] - '0';
    string op[2] = {"+","-"};
    //string res=x[0];
    int sum = 0;
    for(int i=0;i<2;i++){
        sum = a;
        //cout<<"Starting with "<<a<<endl;
        if(op[i]=="+"){
            //res+=(a[i]+x[1]);
            sum+=b;
          //  cout<<i<<" "<<sum<<endl;
        }
        else{
            //res+=(a[i]+x[1]);
            sum-=b;
           // cout<<i<<" "<<sum<<endl;
        }
        for(int j=0;j<2;j++){
            int res = sum;
            if(op[j]=="+"){
                //res+=(a[i]+x[2]);
                res+=c;
            }
            else{
                //res+=(a[i]+x[2]);
                res-=c;
            }
            for(int k=0;k<2;k++){
                int les = res;
                if(op[k]=="+"){
                    //res+=(a[i]+x[3]);
                    les+=d;
                }
                else{
                    //res+=(a[i]+x[3]);
                    les-=d;
                }
                if(les==7){
             //       cout<<op[i]<<" "<<op[j]<<" "<<op[k]<<endl;
                    cout<<a<<op[i]<<b<<op[j]<<c<<op[k]<<d<<"=7"<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}



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

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());
		String[] ss = s.split(" ");
		int a = Integer.parseInt(ss[0]);
		int b = Integer.parseInt(ss[1]);
		System.out.print(a*b);
		System.out.print(" ");
		System.out.println(2*a+2*b);
		
	}

}

Measured memory_bytes: 16892
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const long double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

void solve(){     
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.length(); i++){
        int j = i;
        if (s[i] == 'R'){
            while (s[i] == s[j] && j < s.length()) j++;
            j--;
            ans = max(ans, j - i + 1);
            i = j;
        }else continue;
    }    
    cout << ans << endl;
}
int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(6);
    //freopen("input.txt", "r", stdin);   
    //freopen("sausage.in","r",stdin); freopen("sausage.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] a = sc.IntArray();

        Dictionary<int, int> dic = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            if (dic.ContainsKey(a[i]))
            {
                dic[a[i]]++;
            }
            else
            {
                dic.Add(a[i], 1);
            }
        }

        var list1 = dic.Where(d => d.Value >= 2).OrderByDescending(d => d.Key).Select(d => d.Key).Distinct().ToList();
        var list2 = dic.Where(d => d.Value >= 4).OrderByDescending(d => d.Key).Select(d => d.Key).Distinct().ToList();

        long answer = 0;
        if (list1.Count >= 2)
        {
            answer = (long)list1[0] * (long)list1[1];
        }
        if (list2.Count >= 1)
        {
            answer = Math.Max(answer, (long)list2[0] * (long)list2[0]);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 29920
open Printf
open Scanf

let solve n =
  let ar = Array.init n @@ fun _ -> scanf "%d %d " @@ fun x l -> (x+l, x-l) in
  Array.fast_sort compare ar;
  fst @@ Array.fold_left (fun (ct, p) (r, l) -> if p <= l then (ct + 1, r) else (ct, p)) (0, -1000000000) ar

let () =
  scanf "%d " solve |> printf "%d\n"


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int A = nextInt();
  int B = nextInt();
  int ans = max(0, A-2*B);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char m = '1',t = '2';
    int est = 0,mc=0,tc=0;
    string S;
    bool arc = 0;
    cin >> S;
    REP(i,4){
        if(S[i] == m){
            mc++;
        }else if(S[i] == t){
            tc++;
        }else if(est == 0){
            m = S[i];
            mc++;
            est++;
        }else if(est == 1){
            t = S[i];
            tc++;
            est++;
        }else{
            arc = 1;
            break;
        }
    }
    if(tc > 2 || mc > 2)arc = 1;
    if(arc){
        cout <<"No"<< "\n";
    }else{
        cout <<"Yes"<< "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string result = "Three";
  cin >> N;
  
  for (int i=0; i<N; i++){
    string a;
    cin >>a;
    
    if (a== "Y")
      result = "Four";
  }
  cout << result << endl;
  
}


Measured memory_bytes: 3612
#include<stdio.h>

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

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[300000];
int main()
{
    int n;
    scanf("%d", &n);
    long long sum=0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    printf("%lld\n",sum-n);

}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,l,r,a;
string s;
int ask(int x)
{
	cout<<x<<'\n';
	fflush(stdout);
	cin>>s;
	if(s[0]=='V')
		exit(0);
	return (s[0]=='M');
}
int main(){
	cin>>n;
	l=0,r=n;
	a=ask(0);
	while(l<r)
	{
		int m=(l+r)>>1,m2=ask(m);
		if((m-l)%2!=(m2^a))
			r=m;
		else
			l=m,a=m2;
	}
	return 0;
}

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

const int mod = 1000000007;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(1010, vector<char>(1010, 0));
    for (int k = 0; k < h; ++k) {
        for (int i = 0; i < w; ++i) {
            cin >> grid[k][i];
        }
    }
    vector<vector<ll>> dp(1100, vector<ll>(1100, 0));
    dp[0][0] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i + 1][j] != '#') {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= mod;
            }
            if (grid[i][j + 1] != '#') {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= mod;
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 10752
import std.stdio;
import std.conv;
import std.array;
import std.algorithm;

const bool DEBUG = false;

class Node {
    string name;
    Node[] parents;
    Node[] children;

    static Node birth, end;

    static this() {
        birth = new Node;
        end = new Node;
    }

    private this() {}

    this(string name) {
        this.name = name;
        birth.children ~= this;
        parents = [birth];
        end.parents ~= this;
        children = [end];
    }

    private int _fromBirth = -1;
    @property int fromBirth() {
        if (_fromBirth >= 0) return _fromBirth;
        int dist = 0;
        foreach (p; parents) {
            dist = max(dist, p.fromBirth + 1);
        }
        return _fromBirth = dist;
    }

    private int _toEnd = -1;
    @property int toEnd() {
        if (_toEnd >= 0) return _toEnd;
        int dist = 0;
        foreach (c; children) {
            dist = max(dist, c.toEnd + 1);
        }
        return _toEnd = dist;
    }

    static int longest() {
        return birth.toEnd;
    }
}

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    Node[] employees = new Node[n + 2];
    foreach (i; 1 .. n + 1) {
        employees[i] = new Node(i.to!string);
    }
    employees[0]     = Node.birth;
    employees[n + 1] = Node.end;

    int[] as = new int[m];
    int[] bs = new int[m];
    foreach (i; 0 .. m) {
        int a, b; readf("%d %d\n", &a, &b);
        as[i] = a; bs[i]  = b;
        employees[a].children ~= employees[b];
        employees[b].parents  ~= employees[a];
    }

    int[] list;
    int[] flag = new int[n + 1];

    foreach (i; 0 .. m) {
        auto a = employees[as[i]];
        auto b = employees[bs[i]];
        if (a.fromBirth + b.toEnd + 1 == Node.longest) {
            flag[a.fromBirth]++;
            list ~= i;
        }
    }
    static if (DEBUG) {
        writeln("longest: ", Node.longest);
    }

    int[] ans;
    foreach (i; list) {
        auto a = employees[as[i]];
        if (flag[a.fromBirth] > 1) continue;
        ans ~= i + 1;
    }

    (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
}

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

int main() {
    int n;cin>>n;
    int a[n+2]{};
    for (int i=1;i<=n;i++)
        cin>>a[i];
    int sm=0;
    for (int i=0;i<n+1;i++)
        sm+=abs(a[i]-a[i+1]);
    for (int i=1;i<n+1;i++)
        cout<<sm-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

string s;
int cnt[3];
int ta, mu;
bool bl;
int coun;

signed main() {
	cin >> s;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == 'a')cnt[0]++;
		if (s[i] == 'b')cnt[1]++;
		if (s[i] == 'c')cnt[2]++;
	}
	bl = true;
	ta = ((int)s.size() - 1) / 3 + 1;
	mu = ((int)s.size() - 1) % 3 + 1;
	for (int i = 0; i < 3; i++) {
		if (cnt[i] > ta) {
			cout << "NO" << endl;
			return 0;
		}
		else if(cnt[i] == ta)coun++;
	}
	if (mu < coun)cout << "NO" << endl;
	else cout << "YES" << endl;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG // 配列エラー
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
// typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int main() {
  int64_t num;
  cin >> num;

  string S = to_string(num);

  vector<int64_t> s;
  int len = S.size()-1; // 10 - 1 = 9
  s.push_back( num );
  for (int i = 1; i < (1 << (len)); i++) {
    bitset<9> bit(i);
    int start = 0;
    for(int j = 0; j < len; j++) { // 0 ~ 9

      if(bit.test(j)) {
        s.push_back( stoi( S.substr(start, j - start + 1) ) );
        start = j + 1;
      }
      if(j == len-1) {
        s.push_back( stoi( S.substr(start) ) );
      }

    }
  }

  auto sum = accumulate(s.begin(), s.end(), 0LL);

  cout << sum << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




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

	vector<int> sumB(n), sumW(n);

	rep(i, n) {
		if (s[i] == '.') {
			if (i == 0) {
				sumW[0] = 1;
			}
			else {
				sumW[i] = sumW[i - 1] + 1;
				sumB[i] = sumB[i - 1];
			}
		}
		else {
			if (i == 0) {
				sumB[0] = 1;
			}
			else {
				sumB[i] = sumB[i - 1] + 1;
				sumW[i] = sumW[i - 1];
			}
		}
	}

	int ans = INF;
	rep(i, n + 1) {
		if (i == 0) {
			ans = min(ans, sumW[n - 1]);
		}
		else if (i == n) {
			ans = min(ans, sumB[n - 1]);
		}
		else {
			ans = min(ans, sumB[i - 1] + sumW[n-1] - sumW[i-1]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 2180
#include<stdio.h>
#include<string.h>
#define Max(x,y)((x>y)?x:y)
int ans=0;
void func(int n,int c){
	if(n<=3)ans=c;
	else if(n%3==0)func(n/3,c+1);
	else func(n/3+1,c+1);
	return;
}
int main(){
	int i,j,n;
	scanf("%d",&n);
	func(n,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	string ans;
	
	while(n!=0)
	{
		n--;
		ll rem=n%26;
		// rem--;
		// if(rem<0)
		// 	rem+=26;
		ans+=rem+'a';
		n/=26;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;
using LL = long long;

const int MAXN = 200000 + 5;

int a[MAXN];

LL solve(int n) {
  for (int i = 1; i <= n; ++i) {
    a[i] -= i;
  }
  sort(a + 1, a + n + 1);
  int mid = a[(n + 1) / 2];
  LL res = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] < mid) 
      res += mid - a[i];
    else
      res += a[i] - mid;
  }
  return res;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  printf("%lld\n", solve(n));
  return 0;
}


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

int main(){
 int n ;
 cin >>n;
 VI h(n);
  rep(i,n){
    cin >> h.at(i);
  }
  
 VI diff(n-1);
  rep(i,n-1){
    diff.at(i)=h.at(i+1)-h.at(i);
  }
 ll sum=0;
 ll mx=0;
 bool a=true;
  rep(i,n-1){
    sum+=diff.at(i);
    mx= max(mx,sum);
    if(mx-sum>=2){
		a=false;
      break;
    }
  }
  if(a) cout <<"Yes" << endl;
  else cout << "No " << endl;
    
}

Measured memory_bytes: 1024
//package AtCoder_163;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        StringBuilder print=new StringBuilder();
        int a[]=new int[n+1];
        StringTokenizer st=new StringTokenizer(br.readLine());
        for(int i=1;i<n;i++){
            int x=Integer.parseInt(st.nextToken());
            a[x]++;
        }
        for(int i=1;i<=n;i++){
            print.append(a[i]+"\n");
        }
        System.out.print(print.toString());
    }
}


Measured memory_bytes: 58264
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
adj = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((c, b))
    adj[b].append((c, a))

Q, K = map(int, input().split())
K -= 1

def dijkstra(start):
    dist = [INF for _ in range(N)]
    visited = [False for _ in range(N)] 
    q = [(0, start)]
    dist[start] = 0
    while len(q) > 0:
        v = heapq.heappop(q)
        a = v[1]
        if visited[a]:
            continue
        visited[a] = True
        for u in adj[a]:
            w = u[0]
            b = u[1]
            if dist[a] + w < dist[b]: 
                dist[b] = dist[a] + w
                heapq.heappush(q, (dist[b], b))
    return dist

dist = dijkstra(K)

for i in range(Q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(dist[x] + dist[y])


Measured memory_bytes: 51424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

class Node{
	int id;
	Node left,right;
	
	public void display(){
		System.out.print(" "+id);
	}
}

class Tree{
	private Node root;
	public void insert(int id){
		Node newNode = new Node();
		newNode.id = id;
		if(root==null) 
			root = newNode;
		else{
			Node current = root;
			Node parent;
			while(true){
				parent = current;
				if(current.id>id){
					current = current.left;
					if(current == null){
						parent.left = newNode;
						return;
					}
				}else{
					current = current.right;
					if(current==null){
						parent.right = newNode;
					 	return;
					}
				}
			}
		}
	}
	
	public void inOrder(Node localRoot){
		if(localRoot!=null){
			inOrder(localRoot.left);
			localRoot.display();
			inOrder(localRoot.right);
		}
	}
	public void preOrder(Node localRoot){
		if(localRoot!=null){
			localRoot.display();
			preOrder(localRoot.left);
			preOrder(localRoot.right);
		}
	}
	public void print(){
		inOrder(root);
		System.out.println("");
		preOrder(root);
	}
}

public class Main{
	public static void main(String[] args) throws IOException{
		Tree tree = new Tree();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String in;
		String[] input;
		for(int i=0;i<n;i++){
			in = br.readLine();
			if(in.charAt(0)=='i'){
				input = in.split(" ");
				tree.insert(Integer.parseInt(input[1]));
			}
			else if(in.charAt(0)=='p'){
				tree.print();
				System.out.println("");
			}
		}
	}
}

Measured memory_bytes: 131312
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	cout << (n + 1) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
dist = [0]*n

for i in range(n):
    dist[d[i]] += 1

ans = 1

if d[0]!=0:
    ans = 0
elif dist[0] != 1:
    ans = 0
else:
    for i in range(2,n):
        if dist[i-1]==0 and dist[i]!=0:
            ans = 0
            break
        elif dist[i] == 0:
            continue
        else:
            for j in range(dist[i]):
                ans *= dist[i-1]
            if ans > 998244353:
                ans %= 998244353

print(ans)


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

int main()
{
	int n;
	std::vector<int> A;
	std::vector<int> B;
	std::vector<int> C;
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		std::cin >> a;
		A.push_back(a);
	}
	for (int i = 0; i < n; i++)
	{
		int a;
		std::cin >> a;
		B.push_back(a);
	}
	for (int i = 0; i < n; i++)
	{
		int a;
		std::cin >> a;
		C.push_back(a);
	}
	long ans = 0;
	std::sort(A.begin(), A.end());
	std::sort(B.begin(), B.end());
	std::sort(C.begin(), C.end());
	for (int i = 0; i < n; i++)
	{
		long ans1;
		long ans2;
		std::vector<int>::iterator itr = std::lower_bound(A.begin(), A.end(), B.at(i));
		ans1= std::distance(A.begin(), itr);
		std::vector<int>::iterator itr2 = std::upper_bound(C.begin(), C.end(), B.at(i));
		ans2 = std::distance(itr2, C.end());
		ans += ans1 * ans2;
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 1784
#!/usr/bin/python3

def main():
    answer = int( input() )
    a, b = 0, 0

    while True:
        if a ** 5 - b ** 5 == answer:
            break
        if a ** 5 > answer + ( b ** 5 ):
            a -= 1
        if a ** 5 < answer + ( b ** 5 ):
            a += 1
        if b ** 5 > ( a ** 5 ) - answer:
            b -= 1
        if b ** 5 < ( a ** 5 ) - answer:
            b += 1

    print('%d %d' % (a, b))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9136
use std::str;
use std::io::{self, BufRead, Read};

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    for _ in stdin.by_ref().bytes().take_while(|r| r.as_ref().unwrap() != &b'\n') {}

    let mut res = 0;
    for ln in stdin.lines() { // XXX: redundant buffering
        let ln = ln.unwrap();
        let (l, r) = ln.split_at(ln.find(' ').unwrap());
        let l: u32 = l.parse().unwrap();
        let r: u32 = r[1..].parse().unwrap();
        res += r + 1 - l;
    }

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

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;
typedef long long ll;

void out(vi &as, vi &bs) {
  rep(i, SZ(as)) {
    _p(i+1<SZ(as)?"%d ":"%d\n", as[i]);
  }

  _p("%d\n", SZ(bs));
  rep(i, SZ(bs)) {
    _p(i+1<SZ(bs)?"%d ":"%d\n", bs[i]);
  }
}

void Main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vi A(M);
  rep(i, M) scanf("%d", &A[i]);

  if (M == 1) {
    if (N == 1) {
      out(A, A);
    }
    else {
      vi bs {N-1, 1};
      out(A, bs);
    }
    return;
  }

  vi os, es;
  rep(i, M) {
    (A[i] % 2 ? os : es).push_back(A[i]);
  }

  if (SZ(os) >= 3) {
    puts("Impossible");
    return;
  }

  vi as;
  if (SZ(os)) as.push_back(os[0]);
  forr(e, es) as.push_back(e);
  if (SZ(os) == 2) as.push_back(os[1]);

  vi bs(as);
  bs[0]--;
  bs[SZ(bs)-1]++;
  vi cs;
  forr(b, bs) if (b != 0) cs.push_back(b);
  out(as, cs);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision


#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

namespace Problem{
using namespace std;
class Writer{
static ostringstream oss;
public:template<class T> void appendln(const vector<vector<T>> &ans,string spl=" ", string el="\n"){for(int i=0; i<(int)ans.size(); ++i){for(int j=0; j<(int)ans[i].size(); ++j){oss << ans[i][j];oss << (j==(int)ans[i].size()-1?el:spl);}}}
    template<class T> void appendln(const vector<T>& ans, string spl=" "){for(int i=0; i<(int)ans.size(); ++i){oss << ans[i] << (i==(int)ans.size()-1?"\n":spl);}}
    template<class T> void appendln(const T& answer){oss << answer << "\n";}
    template<class T> void append(const T& answer){oss << answer;}
    void appends(const string spl){oss.seekp((int)oss.tellp()-1);oss<<"\n";}
    template<class F, class... R>void appends(const string spl,const F& fi, const R&... rest){oss << fi << spl; appends(spl, rest...);}
    static void write(){cout << oss.str();}
    Writer(){static bool is_single =true;assert(is_single);is_single=false;};
};ostringstream Writer::oss;


class Solver{
public:
    LL n;
    vector<pair<int,pair<int,int>>> seq;
    Solver(LL n):n(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            int a,b;
            cin >> a >> b;
            seq.push_back({a-b,{a,b}});
        }
        sort(seq.begin(),seq.end());
        if(seq[0].first==0){
            cout << 0 <<"\n";
        }else{
            LL ans = 0,mini=LINF;
            DBG(seq)
            for(int i=0; i<n; ++i){
                ans+=seq[i].second.second;
                DBG(seq[i].first)
                if(seq[i].first>0 and seq[i].second.second<mini){
                    mini=seq[i].second.second;
                }
                DBG(mini)
            }
            cout << ans-mini <<"\n";
        }
    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n=0;
    std::cin >> n;
    Problem::Solver sol(n);
    sol.solve();
    Problem::Writer::write();
    return 0;
}



Measured memory_bytes: 832
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define pq priority_queue
#define st first
#define nd second
#define np next_permutation

using namespace std;
typedef long long ll;
int link[100005];
int Size[100005];
int findx(int x){
    while(x != link[x]) x = link[x];
    return x;
}
bool same(int a, int b){
    return findx(a) == findx(b);
}
void unite(int a, int b){
    a = findx(a);
    b = findx(b);
    if(Size[a] < Size[b]) swap(a, b);
    link[b] = a;
    Size[a] += Size[b];
}

int main()
{
    int n, m;
    cin >> n >> m;
    int p[n];
    fr(i, 0, n){
        cin >> p[i];
        p[i] --;
    }
    fr(i, 0, n) link[i] = i;
    fr(i, 0, n) Size[i] = 1;


    fr(i, 0, m){
        int a, b;
        cin >> a >> b;
        a --, b --;
        if(!same(a, b)){
            unite(a, b);
        }
    }
    int c = 0;
    fr(i, 0, n){
        if(same(i, p[i])) c ++;

    }

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;

namespace C
{
	class Program
	{
		static void Main()
		{
			var line = Console.ReadLine();
			var lineSplited = line.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

			var N = int.Parse(lineSplited[0]);
			var M = int.Parse(lineSplited[1]);

			var A = new List<long>();
			var B = new List<int>();
			var items = new List<Item>();
			for (int i = 0; i < N; i++) {
				var line2 = Console.ReadLine();
				var line2Splited = line2.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

				// A.Add(long.Parse(line2Splited[0]));
				// B.Add(int.Parse(line2Splited[1]));

				items.Add(new Item(){ A = long.Parse(line2Splited[0]), B = int.Parse(line2Splited[1])});
			}

			items.Sort((a, b) => {
				if (a.A < b.A) return -1;
				else if (a.A > b.A) return 1;
				else return 0;
			});

			var money = 0L;
			var m = M;
			foreach (var item in items) {
				if (m > 0) {
					if (item.B < m) {
						money += item.A * item.B;
						m -= item.B;
					} else {
						money += item.A * m;
						m -= m;
					}
				} else {
					break;
				}
			}

			Console.WriteLine(money);
		}

		class Item
		{
			public long A;
			public int B;
		}
	}
}

Measured memory_bytes: 24128