akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


ll gcd(ll a, ll b) {
  if (b > a) {
    swap(a, b);
  }
  ll r = a%b;
  while (r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return (a / gcd(a, b))*b;
}



signed main() {
  int n;
  cin >> n;
  string s,t ;
  cin >> s >> t;
  string ans;
  rep (i, n) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
X = int(input())

def prime_judge(N):
  K = 2
  ans = True
  while K*K <= N:
    if N%K == 0:
      ans = False
      break
    else:
      K += 1
  return ans

while True:
  if prime_judge(X):
    print(X)
    break
  else:
    X += 1

Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> graph[100002];
int indeg[100002]={0};
int stk[100002],tail=0;
int dp[100002]={0};
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		graph[x].push_back(y);
		indeg[y]++;
	}
	for(int i=1;i<=n;i++) if(!indeg[i]) stk[++tail]=i;
	while(tail){
		int x=stk[tail--];
		for(int i=0;i<graph[x].size();i++){
			dp[graph[x][i]]=max(dp[graph[x][i]],dp[x]+1);
			indeg[graph[x][i]]--;
			if(!indeg[graph[x][i]]) stk[++tail]=graph[x][i];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
//smtb2019_b.cpp
//Sun Dec  1 20:56:56 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=0;i<=60000;i++){
		int temp = i*1.08;
		if (temp == n){
			cout << i << endl;
			return 0;
		}
	}

	cout << ":(" << endl;
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, k, ans = 1;
  cin >> n >> k;
  rep(i, n) {
    if (ans * 2 > ans + k) {
      ans += k;
    } else {
      ans *= 2;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, K;
ll p[200010];
double tmpp[200010];
double sump[200010];
double ans;
int main(){
	cin >> N >> K;
	REP(i,0,N) cin >> p[i];
	REP(i,0,N){
		tmpp[i] += 0.5 * (p[i] + 1);
		sump[i+1] = sump[i] + tmpp[i];
	}
	REP(i,K,N+1){
		ans = max<double>(sump[i] - sump[i-K], ans);
	}
	printf("%.7lf\n", ans);
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int x = distance(v.begin(), lower_bound(v.begin(), v.end(), v[i] + v[j]));
			ans += x - (j+1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
vector<int> gr[100005];
int cnt[100005],vis[100005];
int dp[100005];
int main()
{
	int i,j,x,y,n,m;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		gr[x].pb(y);
		cnt[y]++;
	}
	queue<int> q;
	for(i=1;i<=n;i++)
		if(!cnt[i])
			q.push(i);
	// cout<<q.size()<<endl;
	while(!q.empty())
	{
		int t = q.front();
		q.pop();
		vector<int>::iterator it = gr[t].begin();
		for(;it!=gr[t].end();it++)
		{
			dp[*it] = max(dp[t]+1,dp[*it]);
			cnt[*it]--;
			if(cnt[*it] == 0)
				q.push(*it);
		}
		// for(i=1;i<=n;i++)
		// 	cout<<dp[i]<<" ";
		// cout<<endl;
	}
	int ma = 0;
	for(i=1;i<=n;i++)
		ma = max(ma,dp[i]);
	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 6528
import sys
input = sys.stdin.readline
mod = 10**9+7
N,M = [int(i) for i in input().split()]
a = [0] * M
for i in range(M) :
    a[i] = int(input())
dp = [0] * (N+1)
dp[0] = 1
A = set(a)
for i in range(1,N+1) :
    if i in A:
        continue
    else :
        if i == 1 :
            dp[i] += dp[i-1]
        else :
            dp[i] = dp[i-1] + dp[i-2]
print(dp[N] % mod)

Measured memory_bytes: 460020
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	n, _ := strconv.Atoi(s)

	a := n / 100
	b := n % 100

	var ret string
	if (1 <= a && a <= 12) && (1 <= b && b <= 12) {
		ret = "AMBIGUOUS"
	} else if 1 <= a && a <= 12 {
		ret = "MMYY"
	} else if 1 <= b && b <= 12 {
		ret = "YYMM"
	} else {
		ret = "NA"
	}

	fmt.Println(ret)
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        int n = sc.nextInt();
        bool flag = false;

        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                if (n == i * j) flag = true;
            }
        }
        if (flag) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    static double Distance(int x1, int y1, int x2, int y2)
    {
        return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const ll INF=2e20;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
/*struct Point{
    ll x,y;
    void read(){
        scanf("%lld%lld",&x,&y);
    }
    bool operator<(const Point&rhs) const{
        if (x==rhs.x) return y<rhs.y;
        return x<rhs.x;
    }
}p[100];
int n,k;
int main(){
    read(n),read(k);
    for (int i=1;i<=n;i++) p[i].read();
    sort(p+1,p+1+n);
    ll ans=INF;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++)if (i!=j){
            int cnt=0;
            for (int k=1;k<=n;k++){
                if (p[k].x>=min(p[i].x,p[j].x) && p[k].x<=max(p[i].x,p[j].x)
                    && p[k].y>=min(p[i].y,p[j].y) && p[k].y<=max(p[i].y,p[j].y)){
                        cnt++;
                    }
            }
            if (cnt>=k){
                ans=min(ans,(max(p[i].x,p[j].x)-min(p[i].x,p[j].x))*(max(p[i].y,p[j].y)-min(p[i].y,p[j].y)));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}*/
int a,b,c;
int main(){
    read(a),read(b),read(c);
    if (a==b) cout<<c<<endl;
    else if (a==c) cout<<b<<endl;
    else cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
/**
*   @Author : MeGaCrazy
*   @InitTime : Thu Jan 03 02:19:24 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
    long long  n,t;
    cin>>n>>t;
    vector<int>v;
    for(int i=0;i<n;i++){
    	int a;
    	cin>>a;
    	v.push_back(a);
    }
    long long sum=t,ans=0;
    ans+=t;

    for(int i=1;i<n;i++){
    	if(sum > v[i]){
    	    ans+=(v[i]+t)-sum;
    	    sum=(v[i]+t);

           // cerr<<sum<<" "<<v[i]+t<<endl;
    	}else{
    	   sum=(v[i]+t);
	   ans+=t;
    	}
    }
    cout<<ans<<endl;




}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>     // std::cout, std::fixed
#include <iomanip>
#include<queue>
#include <cmath>
#include <queue>
#include <cmath>
#include <set>



using namespace std;
typedef long long ll;


int main () {
    ios_base::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<int> arr(26,0);
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        for(auto letter :s)
            arr[letter-'a']++;
    }
    int fours=0;
    int two=0;
    int one=0;
    for(int i=0;i<26;i++)
    {
        fours+=arr[i]/4;
        arr[i]=arr[i]%4;
        if(arr[i]>=2)
        {
            two++;
            arr[i]=arr[i]%2;
        }
        
        if(arr[i]==1)
        {
            one++;
            arr[i]=0;
        }
    }
    if(n%2==0 and m%2==0)
    {
        int need=(n*m)/4;
        if(need==fours)
            cout<<"Yes";
        else
             cout<<"No";
        return 0;
    }
    
    if(n%2==0 and m%2==1)
    {
        int needF=(n*(m-1))/4;
        int needT=n/2;
        
        int rest=fours-needF;
        if(rest<0)
        {
            cout<<"No";
            return 0;
        }
        
        two+=(rest*2);
        if(needT==two)
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
    }
    
    if(n%2==1 and m%2==0)
    {
        int needF=((n-1)*m)/4;
        int needT=m/2;
        
        int rest=fours-needF;
        if(rest<0)
        {
            cout<<"No";
            return 0;
        }
        
        two+=(rest*2);
        if(needT==two)
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
    }
    if(n%2==1 and m%2==1)
    {
        int needF=(n*m-n-m+1)/4;
        int needT=n/2+m/2;
        
        
        int rest=fours-needF;
        if(rest<0)
        {
            cout<<"No";
            return 0;
        }
        
        two+=(rest*2);
        
        if(needT==two && one==1)
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
        

    }
    

    return 0;

    
}


Measured memory_bytes: 256
import sys
n = int(sys.stdin.readline())
b = 20000000
a = [None]*b
def getC(c):
    if c == "A": t = 1
    elif c == "C": t = 2
    elif c == "G": t = 3
    elif c == "T": t = 4
    return t
def getK(s):
  ret = 0
  for c in s:
    ret = ret*5 + getC(c)
  return ret
def hash1(key):
  return key % b
def hash2(key):
  return 1 + key % (b-1)
def find(key):
  #print(key,a)
  i = 0
  j = (hash1(key)+i*hash2(key))%b
  while a[j]:
    if a[j] == key:
      return True
    i += 1
    j = (hash1(key)+i*hash2(key))%b
  return False
def insert(key):
  i = 0
  j = (hash1(key)+i*hash2(key))%b
  while a[j]:
    i += 1
    j = (hash1(key)+i*hash2(key))%b
  if a[j] == None:
    a[j] = key
for i in range(n):
  q,s = sys.stdin.readline().split()
  if q[0]=="i":
    insert(getK(s))
  else:
    if find(getK(s)):
      print("yes")
    else:
      print("no")



Measured memory_bytes: 180252
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int sum = 0;
        
        for( int a = 1; a < 10; a++ ) {
            for( int b = 0; b < 10; b++ ) {
                for( int c = 0; c < 10; c++ ){
                    String strNum = String.valueOf(a) + String.valueOf(b) + String.valueOf(c) + String.valueOf(b) + String.valueOf(a);
                    int num = Integer.parseInt( strNum );
                    if( A <= num && num <= B ) {
                        sum++;
                    }
                }
            }
        }
        
        System.out.println(sum);
        
    }
}


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



int main() {
   int a, b, c;
   cin >> a >> b >> c;
   if (((a == b) && (b == c)) || ((a != b) && (b != c) && (c != a))) {
      cout << "No" << endl;
   }
   else cout << "Yes" << endl;
   return 0;
}

Measured memory_bytes: 256
import math

X = int(input())

num = [True] * (X * 2 + 1)

t = min(X * 2 + 1, int(math.sqrt(X) + 10))

for i in range(2, t):
    if num[i]:
        for j in range(2, (X * 2) // i):
            num[i * j] = False

for i in range(X, X * 2):
    if num[i]:
        print(i)
        exit()

Measured memory_bytes: 10352
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;


int main(void) {
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    int d[n][n];
    int count[n+1];
    fill(count, count+n+1, 0);
    for(int i=0;i<n-1;i++) {
    	if(i<=x) {  	  
          for(int j=i+1;j<n;j++) {
            count[min(abs(i-j), x-i + 1 + abs(y-j))]++;
          }
        }
        else if(i>=y) {
          for(int j=i+1;j<n;j++) {
            count[abs(i-j)]++;
          }
        }
        else {
          for(int j=i+1;j<n;j++) {
            count[min(abs(x-i) +1+ abs(y-j), abs(i-j))]++;
          }
        }
    }
    for(int i=1;i<n;i++) cout << count[i] << endl;
}


Measured memory_bytes: 256
n,m = map(int, input().split())

lis = []
for _ in range(n):
    lis.append(list(map(int, input().split())))
    
like =[0] * 31

for i in range(n):
    for j in lis[i][1:]:
        like[j] += 1
        
cnt = 0
for k in like:
    if k == n:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N,K;
    cin>>N>>K;
    vector<int> Vec(N);
    for (int i=0;i<N; i++){
        cin>>Vec.at(i);
    }
    int count=0;
    for (int i=0;i<N; i++){
        if (Vec.at(i)>=K){
        	count ++;
        }
      
    }
  cout<<count<<endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main (){
    int n,k,q;
    cin >> n>>k>>q;
    int i,a[n];
    for(i=0;i<n;i++){
        a[i]=k-q;
    }
    int z;
    for(i=0;i<q;i++){
        cin >>z;
        a[z-1]+=1;
    }
    for(i=0;i<n;i++){
        if(a[i]>0)
        cout << "Yes"<< endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N + 2);
    A[0] = A[N + 1] = 0;
    REP(i, N) {
        cin >> A[i + 1];
    }
    int sum = 0;
    REP(i, N + 1) {
        sum += abs(A[i + 1] - A[i]);
    }
    FOR(i, 1, N + 1, 1) {
        cout << sum - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dp[111][11111];

int main() {
    int N, W;
    cin >> N >> W;
    for (int i = 0, v, w; i < N; i++) {
        cin >> v >> w;
        for (int j = 0; j <= W; j++) {
            if (j - w >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w] + v);
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    for (int j = 0; j <= W; j++) ans = max(ans, dp[N][j]);
    cout << ans << endl;
}


Measured memory_bytes: 11308
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    int cnt = 0;
    for (int i = a; i <= b; ++i)
    {
        if (c % i == 0) ++cnt;
    }
    std::cout << cnt << std::endl;
    return 0;
}



Measured memory_bytes: 3088
(* O(k^2) (k = max n m) *)
Scanf.scanf " %d" @@ fun n ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s in
  let m = Scanf.scanf " %d" @@ (+) 0 in
  let ts = Array.init m @@ fun _ -> Scanf.scanf " %s" @@ fun t -> t in
  let f acc s =
    let c = Array.fold_left (fun c s' -> if s' = s then c + 1 else c) 0 ss in
    let c = Array.fold_left (fun c t -> if t = s then c - 1 else c) c ts in
    max acc c in
  Array.fold_left f 0 ss |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<map>
#include<set>

using namespace std;
int N,Q,D;
typedef long long ll;

priority_queue<pair<int,pair<int,int> > > q;
ll answer[500000];
set<ll> se;

int main(){
  cin >> N >> Q;
  for(int i=0;i<N;i++){
    ll s,t,x;
    cin >> s >> t >> x;
    q.push(make_pair(-s+x,make_pair(-1,-x)));
    q.push(make_pair(-t+x,make_pair(0,-x)));
  }
  for(int i=0;i<Q;i++){
    int d;
    cin >> d;
    q.push(make_pair(-d,make_pair(-2,-i)));
  }

  while(!q.empty()){
    auto top = q.top();
    q.pop();
    int a = -top.first;
    int c = -top.second.first;
    int b = -top.second.second;
    if(c == 2){
      if(se.empty()){
        answer[b] = -1;
      } else {
        set<ll>::iterator it = se.begin();
        answer[b] = (*it);
      }
    }
    if(c == 1){
      se.insert(b);
    }
    if(c == 0){
      se.erase(b);
    }
  }
  for(int i=0;i<Q;i++){
    cout << answer[i] << endl;
  }
  
  
}


Measured memory_bytes: 21096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,n) for(int i=0;i<n;i++);
#define fore(i,a,b) for(int i=a;i<b;i++);


int main(){
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }
    else{
        cout<<"safe"<<endl;
    }
}


Measured memory_bytes: 3624
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<string> out;
bool cal(int n,int m,int a,int b){
	if(n%2>0){
		rep(j,m/2){
			if(a>0){
				out[n-1][j*2]='<';
				out[n-1][j*2+1]='>';
				a--;
			}
		}
		return cal(n-1,m,a,b);
	}
	if(m%2>0){
		rep(i,n/2){
			if(b>0){
				out[i*2][m-1]='^';
				out[i*2+1][m-1]='v';
				b--;
			}
		}
		return cal(n,m-1,a,b);
	}
	//if(n*m/4<(a+1)/2+(b+1)/2) return false;
	rep(i,n/2) rep(j,m/2){
		if(a>1){
			out[i*2][j*2]=out[i*2+1][j*2]='<';
			out[i*2][j*2+1]=out[i*2+1][j*2+1]='>';
			a-=2;
		}
		else if(a>0){
			out[i*2][j*2]='<';
			out[i*2][j*2+1]='>';
			a--;
		}
		else if(b>1){
			out[i*2][j*2]=out[i*2][j*2+1]='^';
			out[i*2+1][j*2]=out[i*2+1][j*2+1]='v';
			b-=2;
		}
		else if(b>0){
			out[i*2][j*2]='^';
			out[i*2+1][j*2]='v';
			b--;
		}
	}
	return (a<=0 && b<=0);
}
bool cal2(int n,int m,int a,int b){
	//cout<<n<<m<<a<<b;
	if(a<2 || b<2 || n%2<1 || m%2<1) return false;
	out[n-3][m-2]=out[n-1][m-3]='<';
	out[n-3][m-1]=out[n-1][m-2]='>';
	out[n-3][m-3]=out[n-2][m-1]='^';
	out[n-2][m-3]=out[n-1][m-1]='v';
	a-=2;b-=2;
	rep(j,m/2-1){
		if(a>0){
			out[n-1][j*2]='<';
			out[n-1][j*2+1]='>';
			a--;
		}
	}
	rep(i,n/2-1){
		if(b>0){
			out[i*2][m-1]='^';
			out[i*2+1][m-1]='v';
			b--;
		}
	}
	//cout<<a<<b<<endl;
	rep(i,n/2) rep(j,m/2){
		if(out[i*2][j*2]!='.') continue;
		if(a>1){
			out[i*2][j*2]=out[i*2+1][j*2]='<';
			out[i*2][j*2+1]=out[i*2+1][j*2+1]='>';
			a-=2;
		}
		else if(a>0){
			out[i*2][j*2]='<';
			out[i*2][j*2+1]='>';
			a--;
		}
		else if(b>1){
			out[i*2][j*2]=out[i*2][j*2+1]='^';
			out[i*2+1][j*2]=out[i*2+1][j*2+1]='v';
			b-=2;
		}
		else if(b>0){
			out[i*2][j*2]='^';
			out[i*2+1][j*2]='v';
			b--;
		}
	}
	return (a<=0 && b<=0);
}
int main()
{
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	rep(i,n) out.pb(string(m,'.'));
	if(cal(n,m,a,b)){
		cout<<"YES"<<endl;
		rep(i,n) cout<<out[i]<<endl;
	}
	else{
		rep(i,n) out[i]=string(m,'.');
		if(cal2(n,m,a,b)){
			cout<<"YES"<<endl;
			rep(i,n) cout<<out[i]<<endl;
		}
		else cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 2304
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] ST = Console.ReadLine().Split(' ');
            string S = ST[0];
            string T = ST[1];

            string ans = null;

            for (int i = 0; i < N; i++)
            {
                ans += S[i];
                ans += T[i];
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

n, m, k = map(int, input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1]+arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

ans = 0
j=m
for i in range(n+1):
    if acum1[i] > k:
        break
    while acum2[j] > k - acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 47472
#include <iostream>
#include <string>

using namespace std;

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

    int ans = 0;
    for(int i = 0; i < N-2;){
        if(S[i] == 'A'){
            if(S[i+1] == 'B'){
                if(S[i+2] == 'C'){
                    ans++;
                    i += 3;
                }else{
                    i += 1;
                } 
            }else{
                i += 1;
            }
        }else{
            i += 1;
        }
    }
    cout << ans << endl;

    return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 const int maxm=3e3+2;
//Prints the Longest common subsequence
void printLCS( char *s1, char *s2, int m, int n )
{
   int L[m+1][n+1];
 
   //Building L[m][n] as in algorithm
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (s1[i-1] == s2[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }
 
   //To print LCS
   int index = L[m][n];
   //charcater array to store LCS
   char LCS[index+1];
   LCS[index] = '\0'; // Set the terminating character
   
   //Stroing characters in LCS
   //Start from the right bottom corner character
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      //if current character in s1 and s2 are same, then include this character in LCS[]
      if (s1[i-1] == s2[j-1])
      {
          LCS[index-1] = s1[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }
      // compare values of L[i-1][j] and L[i][j-1] and go in direction of greater value.
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }
 
   // Print the LCS
   cout << LCS<<endl;
}
 
/* Driver program to test above function */
int main()
{ 
  char s1[maxm],s2[maxm];
  cin>>s1>>s2;
  printLCS(s1, s2, strlen(s1), strlen(s2));
  return 0;
}

Measured memory_bytes: 35456
n=int(input())
t=input().split()
m=int(input())
for i in range(m) :
    p,x=input().split()    
    sum=0
    for i in range(n) :
        if i==int(p)-1 :    sum=sum+int(x)
        else :   sum=sum+int(t[i])
    print(sum)


Measured memory_bytes: 3064
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int money = sc.nextInt();
        if (money % 1000 == 0) {
            System.out.println(0);
        } else {
        int a = money / 1000;
        a = a + 1;
        System.out.println(a * 1000 - money);
        }
    }
}

Measured memory_bytes: 27060
n, m = map(int, input().split())
s = []
for i in range(m):
    ks = list(map(int, input().split()))
    s.append(ks[1:])
p = list(map(int, input().split()))

ans = 0

for i in range(2**n):
    flag = True
    for j in range(m):
        c = 0
        for v in s[j]:
            if i >> (v-1) & 1:
                c += 1
        if c%2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 9080
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	N, _ := strconv.Atoi(scanner.Text())
	if N == 2 {
		scanner.Scan()
		A, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		B, _ := strconv.Atoi(scanner.Text())
		fmt.Println(A + B)
	} else {
		fmt.Println("Hello World")
	}

}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        try {
            String input = in.readLine();

            long result = calculation(Long.valueOf(input));

            System.out.println(result);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static long calculation(Long num) {

        if (num == 1) {
            return num;
        } else {
            return num * calculation(num - 1);
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    deque<int> q;
    rep(i,n) {
        int a;
        cin >> a;
        if(i%2==0) q.push_back(a);
        else q.push_front(a);
    }
    if(n&1){
        while(!q.empty()){
            cout << q.back() << " ";
            q.pop_back();
        }
    }
    else {
         while(!q.empty()){
            cout << q.front() << " ";
            q.pop_front();
            
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A[100010];

ll solve(){
    ll ans = 0;
    if(N % 2 == 0){
        REP(i, N / 2 - 1) ans += 2 * A[i];
        ans += A[N / 2 - 1];
        ans -= A[N / 2];
        FOR(i, N / 2 + 1, N) ans -= 2 * A[i];
    }else{
        REP(i, N / 2 - 1) ans += 2 * A[i];
        ans += A[N / 2 - 1] + A[N / 2];
        FOR(i, N / 2 + 1, N) ans -= 2 * A[i];
    }
    return ans;
}

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N, greater<ll>());
    ll ans = 0;
    ans = solve();
    REP(i, N) A[i] *= -1;
    reverse(A, A + N);
    ans = max(ans, solve());
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, k;
    cin >> n >> k;
    double ans = 0;
    REP(i,1,n+1){
        if(i >= k){
            ans += n-k+1.0;
            break;
        }else{
            ll x = ceil(log2(ceil((double)k/i)));
            ans += pow(0.5,x);
        }
    }
    ans /= (double)n;
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 4168
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int main(void)
{
  int i, j, n, m;
  int *c, *t;
  scanf("%d %d", &n, &m);
  c = (int*)malloc(sizeof(int) * m);
  t = (int*)malloc(sizeof(int) * (n + 1));
  for (i = 0; i < m; i++) scanf("%d", &c[i]);
  for (i = 0; i <= n; i++) t[i] = INT_MAX;
  t[0] = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j + c[i] <= n; j++) {
      if (t[j+c[i]] > t[j] + 1) t[j+c[i]] = t[j] + 1;
    }
  }
  printf("%d\n", t[n]);
  free(c);
  free(t);
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	cin >> n;
		
	if (n==1||n==2||n==3||n==5||n==6||n==9||n==10||n==13||n==17) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, v[100050], dp[200020], mod = (int)(1e9 + 7);

int solve(int x)
{
	if(v[x]) return 0;

	if(x == n) return 1;

	if(x > n) return 0;

	if(dp[x] != -1) return dp[x];

	return dp[x] = (solve(x + 1) + solve(x + 2))%mod;
}

int32_t main()
{
	cin>>n>>m;

	for(int i = 1; i <= m; i++)
	{
		int t;

		cin>>t;

		v[t] = 1;
	}
	memset(dp, -1, sizeof dp);
	cout<<solve(0)<<"\n";
}

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

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

   if(s%100<=12 && 1<=s%100 ){
       if(1<=s/100 && s/100<=12){
           cout << "AMBIGUOUS" << endl;
       }else{
           cout << "YYMM" << endl;
       }
   }else{
        if(1<=s/100 && s/100<=12){
           cout << "MMYY" << endl;
       }else{
           cout << "NA" << endl;
       }
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#define int long long
#define P pair<int,int>
#define V vector<int>
#define rep(i,n) for(int i=0;i<n;++i)
#define vsort(vec) sort(vec.begin(),vec.end())
#define end system("PAUSE");return 0
using namespace std;
signed main() {
	int n, Y;
	cin >> n >> Y;
	rep(x, n + 1) {
		rep(y, n - x + 1) {
			int z = n - x - y;
			if (z < 0)continue;
			if (10000 * x + 5000 * y + 1000 * z == Y) {
				cout << x << " " << y << " " << z << endl;
				end;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	end;
}


Measured memory_bytes: 504
/**
 * Created By: Anonyman637
 * Created On: 4/19/2020 6:13:49 PM
 */

/* =============================================================================
   ================================== HEADERS ==================================
   ========================================================================== */

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

/* =============================================================================
   ================================= TYPEDEFS ==================================
   ========================================================================== */

typedef char i8;
typedef short i16;
typedef int i32;
typedef long long i64;

typedef unsigned char ui8;
typedef unsigned short ui16;
typedef unsigned int ui32;
typedef unsigned long long ui64;

typedef double db;
typedef long double ldb;

using namespace std;

/* =============================================================================
   ================================== MACROS ===================================
   ========================================================================== */

#ifdef DEBUG
#define debug(format, ...) printf(format, __VA_ARGS__)
#else
#define debug(format, ...) 
#endif

#define NOCSYNCIOS 1

#define FOREACH(it, cont) for (const auto& it : (cont)) 

#define ALL(cont) (cont).begin(), (cont).end()
#define RALL(cont) (cont).end(), (cont).begin()
#define SP(x) fixed << setprecision(x)

#define MP make_pair
#define PB push_back
#define fi first
#define se second

#define EPS 1e-9
#define MOD 1000000007

/* =============================================================================
   ================================== GLOBALS ==================================
   ========================================================================== */

const double pi=acos(-1.0);

/* =============================================================================
   =================================== SETUP ===================================
   ========================================================================== */

i32 setup() {

#if NOCSYNCIOS
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif

#if FILEIO
	#define FILEI
	if(freopen(OUTFILE, "w", stdout) == NULL) return 402;
#endif

#ifdef FILEI
	if(freopen(INFILE, "r", stdin) == NULL) return 401;
#endif

	return 0;
}


/* =============================================================================
   ================================= FUNCTIONS =================================
   ========================================================================== */

i32 main() {

	i32 errorInSetup = setup();
	if (errorInSetup) exit(errorInSetup);

	i32 i, t;
	i32 r;

	cin >> r;
	cout << SP(2) << 2 * 3.14159 * r;
	
	return 0;
}


Measured memory_bytes: 3804
/*
input:
2 5
0 1 0 1 0
1 0 0 0 1
3 6
1 0 0 0 1 0
1 1 1 0 1 0
1 0 1 1 0 1  
0 0
output:
9
15
*/
#include <cstdio>
#include <algorithm>
#include <bitset>

using namespace std;

const int MAX_R = 10;
const int MAX_C = 10000;

//&#36755;入
int R, C;
bitset<MAX_C> a[MAX_R];

int ans;

void dfs(int k){
	if(k == R){
		//在当前行翻&#36716;&#30830;定的情况下，由于列数量&#36739;大，并不真正翻&#36716;列
		int result = 0;
		for(int j = 0; j < C; j ++){
			int upNum = 0;
			for(int i = 0; i < R; i ++){
				if(a[i][j]) upNum ++;
			}
			result += max(upNum, R - upNum);			//虚&#25311;翻&#36716;
		}
		ans = max(ans, result);
		return;
	}
	//不翻&#36716;第k行
	dfs(k + 1);
	//翻&#36716;第k行
	a[k].flip();
	dfs(k + 1);
	//&#22797;原
	a[k].flip();
}

void solve(){
	//初始化
	ans = 0;
	//深度&#20248;先遍&#21382;
	dfs(0);
	printf("%d\n", ans);
}

int main(int argc, char const *argv[]){

	while(scanf("%d %d", &R, &C)){
		if(R == 0 && C == 0) break;

		for(int i = 0; i < R; i ++){
			for(int j = 0; j < C; j ++){
				bool tmp;
				scanf("%d", &tmp);
				a[i][j] = tmp;
			}
		}
		solve();
	}

	return 0;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <long long, int> pli;
typedef pair <int, int> pii;

long long d[100010];
map <long long, int> all;
long long dp[100010], size[100010];

int main(){
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &d[i]);
		all[d[i]] = i;
	}
	vector <pii> ans;
	int pos = all.begin()->se;
	for (auto it = all.rbegin(); it != all.rend(); it++){
		long long x = it->fi; int id = it->se;
		if (id == pos) continue;
		size[id]++;
		long long need = d[id] + 2 * size[id] - n;
		if (!all.count(need) || need >= x){
			printf("-1\n");
			return 0;
		}
		int fa = all[need];
		ans.push_back(mp(fa, id));
		size[fa] += size[id], dp[fa] += dp[id] + size[id];
	}
	if (dp[pos] != d[pos]){
		printf("-1\n");
		return 0;
	}
	for (int i = 0; i < ans.size(); i++){
		printf("%d %d\n", ans[i].fi + 1, ans[i].se + 1);
	}
	return 0;
}


Measured memory_bytes: 10872
#14:00
n = int(input())
n += 1
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append([a[i],i])
b.sort()
for j in range(n-1):
  if b[j][0] == b[j+1][0]:
    k = b[j+1][1] - b[j][1] - 1
mod = 10 ** 9 + 7
now = [ n-k-2 , 1 , 0 , n , n-k ]
#print(now)
print(sum(now)-2*now[-1])
now = [ (n-k-2)*(n-k-3)//2 , n-k-2 , 1 , n*(n-1)//2 , (n-k)*(n-k-1)//2 ]
#print(now)
print((sum(now)-2*now[-1]) % mod)

def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y

for i in range(3,n+1):
  last = now
  now = [0 for _ in range(5)]
  now[0] = last[0] * (n-k-i-1) * inv(i)
  now[1] = last[1] * (n-k-i)   * inv(i-1)
  now[2] = last[2] * (n-k-i+1) * inv(i-2)
  now[3] = last[3] * (n  -i+1) * inv(i)
  now[4] = last[4] * (n-k-i+1) * inv(i)
  for d in range(5):
    now[d] %= mod
  #print(now)
  print((sum(now)-2*now[-1]) % mod)

Measured memory_bytes: 70764
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
static const int INF = 1e8;

void solve()
{
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2)
	{
		--s; --g1; --g2;
		vector< vector<int> > d(n, vector<int>(n));
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				d[i][j] = INF;
			}
			d[i][i] = 0;
		}
		for (int i = 0; i < m; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			--from; --to;
			d[from][to] = cost;
		}
		for (int k = 0; k < n; ++k)
		{
			for (int i = 0; i < n; ++i)
			{
				for (int j = 0; j < n; ++j)
				{
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int ans = INF;
		for (int i = 0; i < n; ++i)
		{
			ans = min(ans, d[s][i] + d[i][g1] + d[i][g2]);
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1260
#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

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

struct SegmentTree {
	int init_val;
	int n;
	vector<int> dat;
	
	SegmentTree(int _n) {
		init_val = INF;
		n = 1;
		while (n < _n) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, init_val);
	}
	
	void update(int k, int a) {
		k += n - 1;
		dat[k] = min(dat[k], a);
		
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
	
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return min(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	
	int query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

typedef pair<int, int> pii;
typedef pair<int , pii> pip;
typedef SegmentTree Seg;
typedef long long ll;

int main() {
	int n, d;
	cin >> n >> d;
	vector<pip> stars(n);
	REP(i, n) {
		int x, y, b;
		scanf("%d %d %d", &x, &y, &b);
		stars[i] = pip(b, pii(x, y));
	}
	sort(stars.begin(), stars.end());
	
	Seg up(n), down(n), right(n), left(n);
	REP(i, n) {
		int x = stars[i].second.first;
		int y = stars[i].second.second;
		
		up.update(i, -y);
		down.update(i, y);
		right.update(i, -x);
		left.update(i, x);
	}
	
	/*
	puts("");
	REP(i, n) {
		cout << stars[i].first << " " << stars[i].second.first << " " << stars[i].second.second << endl;
	}
	puts("");
	*/
	
	int st = 0, en = 0;
	ll ans = 0;
	
	while (st < n) {
		if (en - st > 0 && stars[en].first - stars[st].first <= d) {
			ll  s = (ll)(-up.query(st, en + 1) - down.query(st, en + 1))
				    * (-right.query(st, en + 1) - left.query(st, en + 1));
			ans = max(ans, s);

			if (en == n - 1) st++;
			else en++;
			
		}
		else if (stars[en].first - stars[st].first > d) st++;
		else if (en < n - 1) en++;
		else st++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 11760
import java.util.*;

public class Main {
	int n, k, max;
	int[] c;
	StringBuffer a, b;
	
	
	void loop(int id, int br, int kk){
		if(kk==k+1) return;
		if(id==n){
			int ans = 0;
			int ten = 1;
			for(int i=0;i<n;i++){
				ans += c[i]*ten;
				ten *= 10;
			}
			max = Math.max(max, ans);
			return;
		}
		
		int p = a.charAt(id) - b.charAt(id) - br;
		if(p>=0){
			c[id] = p;
			loop(id+1,0,kk);
		}else{
			c[id] = p+10;
			loop(id+1,1,kk);
			loop(id+1,0,kk+1);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		a = new StringBuffer(sc.next()).reverse();
		b = new StringBuffer(sc.next()).reverse();
		k = sc.nextInt();
		n = a.length();
		int dif = n-b.length();
		for(int i=0;i<dif;i++) b.append(0);
		max = 0;
		c = new int[n];
		loop(0,0,0);
		System.out.println(max);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 17360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));

int main(){
    ll n;
    ll cnt=0;
    cin>>n;
    vec(a,n,0);
    
    vector<int> b(100001,0);
    rep(i,n){
        cin>>a[i];
        
        if(a[i]>100000){cnt++;}
        else {
            b[a[i]]++;
        }
    }
    repf(i,1,100001){
        if(b[i]>=i){
            cnt+=(b[i]-i);
        }else {
            cnt+=b[i];
        }
    }
    op(cnt);
    return 0;

}

Measured memory_bytes: 1536
from sys import stdin
n = int(stdin.readline())
h = [int(i) for i in stdin.readline().split(' ')]

minCosts = [0, abs(h[1]-h[0])]
for i in range(2, len(h)):
    minCosts.append(min(abs(h[i]-h[i-2])+minCosts[i-2], abs(h[i]-h[i-1])+minCosts[i-1]))

print(minCosts[-1])

Measured memory_bytes: 14108