akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static long[][][] dp;
	static int N;
	static int A;
	static int[] X;

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

	    N=gi();
	    A=gi();
	    X=new int[N+1];
	    dp=new long[N+1][N+1][N*A+1];

        for (int i=1; i<=N; i++) {
        	X[i]=gi();
        }

        Arrays.parallelSort(X);

        for (int i=0; i<=N; i++) {
        	dp[i][0][0]=1;
        }
        for (int i=1; i<=N; i++) {
			int a=X[i];
        	for (int j=1; j<=i; j++) {
        	    for (int k=1; k<=N*A; k++) {
        	    	dp[i][j][k]=dp[i-1][j][k];
        	    	if(k>=a) {
        	    		dp[i][j][k]+= dp[i-1][j-1][k-a];
        			}
                }
            }
        }

        long ans=0;
        for(int i=1; i<=N; i++) {
        	ans+=dp[N][i][i*A];
        }
        System.out.println(ans);

//        if(ans==0) {
//
//		    System.out.println("Yes");
//        } else {
//        	System.out.println("No");
//
//        }
	}

	// 約数の数を計算
		public static int yakusuC(int n) {
			StringBuilder sb = new StringBuilder();
			int c=0;
			for (int i=1; i<=n; i++) {
				if (n%i==0) {
					c++;
				}
			}

			return c;
		}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 103192
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int n,k;
ll nums[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>k;
    rep(i,n) cin>>nums[i];
    
    ll total=0;
    rep(i,n) if(nums[i]>0) total+=nums[i];
    
    if(total==0){
        cout1(0);
        return 0;
    }
    
    ll pl=0, mi=0, mx=0;
    rep(i,n){
        if(nums[i]>0) pl+=nums[i];
        else mi+=nums[i];
        if(i>=k-1){
            ll res=max(total+mi,total-pl);
            mx=max(mx,res);
            if(nums[i-(k-1)]>0) pl-=nums[i-(k-1)];
            else mi-=nums[i-(k-1)];
        }
    }
    cout1(mx);
}

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> mine(H);
  
  for (int i=0;i<H;i++){
    cin >> mine.at(i);
  }
  
  vector<int> S={-1,-1,-1,0,0,1,1,1};
  vector<int> T={-1,0,1,-1,1,-1,0,1};
  
  string V="012345678";
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int count=0;
      if(mine.at(i).at(j)=='.'){
        for(int k=0;k<8;k++){
          if(0<=i+S.at(k) && i+S.at(k)<H && 0<=j+T.at(k) &&j+T.at(k)<W){
            if(mine.at(i+S.at(k)).at(j+T.at(k))=='#'){
              count=count+1;            
            }
          }
        }
        mine.at(i).at(j)=V.at(count);
      }
    }
  }
  
  for(int i=0;i<H;i++){
    cout << mine.at(i) << endl;
  }
}

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

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int a, b;
		string code;
		cin >> code;
		if(code=="print"){
			cin >> a >> b;
			cout << s.substr(a, b-a+1) << endl;
		}else if (code == "reverse") {
			cin >> a >> b;
			string ss = s.substr(a, b-a+1);
			//cout << ss << endl;
			reverse(ss.begin(), ss.end());
			s.replace(a, b-a+1, ss);
			//cout << s << endl;
		}
		else if (code == "replace") {
			cin >> a >> b;
			string p;
			cin >> p;
			s.replace(a, b-a+1, p);
			//cout << s << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3208
#include<iostream>
using namespace std;
int main()
{
	// スペース区切りの整数の入力
    int N;
    cin >> N ;
    
  	if(N==0){
    // 出力
    cout << 1;
    }
  else{
  cout << 0;
  }
 

    return 0;
}

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

int main(){
  int a,i;
  double b;
  
  cin >> a;
  
  vector<double> vec(a);
  for(i=0;i<a;i++){
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
      
  b=vec[0];
  
  for(i=1;i<a;i++){
    b=b/2+vec[i]/2;
  }
  
  cout << b;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

int n,ans,l[2010],r[2010];
char a[2010],b[4010];

void solve()
{
    bool flag=0;
    repu(i,1,n)
        flag|=(b[i+n]=b[i])=='1';
    if (!flag)
    {
        flag=1;
        repu(i,1,n)
            flag&=a[i]==b[i];
        printf("%d\n",flag?0:-1);
        exit(0);
    }
    for (l[1]=0; b[n+1-l[1]]=='0'; ++l[1]);
    repu(i,2,n)
        l[i]=b[i]=='1'?0:l[i-1]+1;
    for (r[n]=0; b[n+r[n]]=='0'; ++r[n]);
    repd(i,n-1,1)
        r[i]=b[i]=='1'?0:r[i+1]+1;
    repu(i,0,n-1)
    {
        static int maxr[2010];
        memset(maxr,0,sizeof(maxr));
        int cnt=0;
        repu(j,1,n)
            if (a[j]!=b[i+j])
                ++cnt,maxr[l[j]]=max(maxr[l[j]],r[j]-i);
        int w=0;
        repd(j,n-1,0)
            ans=min(ans,i+j*2+w*2+cnt),w=max(w,maxr[j]);
    }
}

int main()
{
    scanf("%s%s",a+1,b+1),n=strlen(a+1),ans=1<<30;
    solve();
    repu(i,1,n/2)
        swap(a[i],a[n-i+1]),swap(b[i],b[n-i+1]);
    solve();
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
import glob
import numpy as np


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class D(Common):

    def resolve(self):

        box_num = int(self.input_data())
        remain = [int(i) for i in self.input_data().split()]

        boxes = [0 for i in range(box_num)]
        ball_num = 0

        for box in range(box_num, 0, -1):
            ball_num = 0
            for j in range(box-1, box_num, box):
                ball_num += boxes[j]
            if ball_num % 2 != remain[box-1]:
                boxes[box-1] = 1
                ball_num += 1

        print(str(ball_num))
        for i in range(box_num):
            if boxes[i] == 1:
                print(str(i+1), end=" ")


solver = D(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 18460
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;
using PP = std::pair<P, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll R, C, K;
ll r[200010], c[200010], v[200010];
ll dp[3010][3010][4];
ll used[3010][3010];
std::vector<ll> vs;

int main() {
  std::cin >> R >> C >> K;

  rep( i, R ) rep( j, C ) 
    used[i][j] = -1;

  ll cnt = 0;

  rep( i, K ) {
    std::cin >> r[i] >> c[i] >> v[i];
    --r[i]; --c[i];
    used[r[i]][c[i]] = cnt++;
    vs.emplace_back( v[i] );
  }

  dp[0][0][0] = 0;
  dp[0][0][1] = used[0][0] >= 0 ? vs[used[0][0]] : 0;

  rep( i, R ) rep( j, C ) rep( k, 4 ) {
    if( i-1 >= 0 ) {
      chmax( dp[i][j][0], dp[i-1][j][k] );

      if( used[i][j] >= 0 )
        chmax( dp[i][j][1], dp[i-1][j][k]+vs[used[i][j]] );
    }

    if( j-1 >= 0 ) {
      chmax( dp[i][j][k], dp[i][j-1][k] );

      if( k+1 <= 3 && used[i][j] >= 0 )
        chmax( dp[i][j][k+1], dp[i][j-1][k]+vs[used[i][j]] );
    }

    //printf( "dp[%lld][%lld][%lld] = %lld\n", i, j, k, dp[i][j][k] );
  }

  ll ans = 0;

  rep( k, 4 )
    chmax( ans, dp[R-1][C-1][k] );

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 362292
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n;cin>>n;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	ll ans=inf;
	rep(i,1,101)
	{
		ll temp=0;
		rep(j,0,n) temp+=abs(a[j]-i)*abs(a[j]-i);
		ans=min(ans,temp); 
	}
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

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

int main(){
  vector<int> vec(5);
  for(int i=0;i<5;i++){
    cin >> vec.at(i);
  }
  int k;
  cin >> k;
  
 sort(vec.begin(),vec.end());
  int z=vec.at(4)-vec.at(0);
  
  if(k>=z){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    ll MOD = 1000000007;
    ll N,K;
    cin >> N >> K;
    ll Cnt[2005] = {0}; //数字が出てくる回数
    ll Tentou[2005] = {0}; //A[i]の転倒数
    ll A[N];
    rep(i,N){
        cin >> A[i];
        Cnt[A[i]]++;
    }
    rep(i,2000){
        Cnt[i+1] += Cnt[i];
    }

    for (int i = 0; i < N-1; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            if(A[i] > A[j]) Tentou[i]++;
        }
        
    }
    ll ans = 0;

    rep(i,N){
        ans += (Tentou[i] * K)%MOD;
        ans += (K*(K-1)/2)%MOD * Cnt[A[i]-1];
        ans = ans % MOD;
    }
    cout << ans << endl;
}

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

typedef long long int LLI;

LLI N;

int main() {
  scanf("%lld", &N);
  for (LLI h=1; h<=3500; h++) {
    for (LLI w=1; w<=3500; w++) {
      LLI a = N*h*w;
      LLI b = 4*h*w - N*(h+w);
      if (b && a%b == 0 && a/b > 0) {
        printf("%lld %lld %lld\n", h, a/b, w);
        return 0;
      }
    }
  }
  puts("-1");
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll g,h;cin>>g>>h;
  if((g+h)%2){cout<<"IMPOSSIBLE"<<endl;return 0;}
  //caricurate
  cout<<(g+h)/2<<endl;
  //output
}

Measured memory_bytes: 256
S = list(input())
N = len(S)
c = 0
dream = list("dream")
dreamer = list("dreamer")
erase = list("erase")
eraser = list("eraser")
while True:
    if S[c:c + 5] == dream:
        c += 5
        if S[c:c + 5] != erase and S[c:c + 2] == list("er"):
            c += 2
        if c == N:
            print("YES")
            break
    elif S[c:c + 5] == erase:
        c += 5
        if S[c:c + 1] == ["r"]:
            c += 1
        if c == N:
            print("YES")
            break
    else:
        print("NO")
        break

Measured memory_bytes: 3956
#include <stdio.h>
#include <math.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  double x1, y1, x2, y2, xq, yq;

  while ( scanf ( "%lf,%lf,%lf,%lf,%lf,%lf"
                , &x1, &y1, &x2, &y2, &xq, &yq ) == 6 )
  {
    const double th = atan2 ( y2 - y1, x2 - x1 );
    const double rx = xq - x1
               , ry = yq - y1;
    const double sx = rx * cos ( -th ) - ry * sin ( -th )
               , sy = rx * sin ( -th ) + ry * cos ( -th );

    printf ( "%.4f %.4f\n"
           , x1 + ( sx * cos ( th ) - ( -sy ) * sin ( th ) )
           , y1 + ( sx * sin ( th ) + ( -sy ) * cos ( th ) ) );
  }

  return ( 0 );
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


@mt
def slv(N, K, A):
    S = sum(A)
    D = [n for n in divisor(S)]
    D.sort()

    ans = 0
    for d in D:
        r = []
        for a in A:
            r.append(a % d)
        r.sort()
        rr = [d - n for n in r]
        sr = [0]
        srr = [0]
        for i in range(N):
            sr.append(sr[-1] + r[i])
            srr.append(srr[-1] + rr[i])
        
        for i in range(N):
            e = sr[i+1] - sr[0]
            f = srr[N]-srr[i+1]
            if e == f and e <= K:
                ans = max(ans, d)
                break
    return ans



def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6216
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def solve(N: int, A: int, B: int, h: "List[int]"):
    tot = sum(h)

    def isOK(index):
        base = B*index
        sub = A-B
        counter = 0
        for hh in h:
            if hh > base:
                counter += int(math.ceil((hh-base)/sub))
            if index < counter:
                return False

        return index >= counter

    ng = -1
    ok = 2*tot//(N*B) + 1
    # print(ng, ok)

    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    print(ok)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, h)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7132
#include <iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    if(n%10==9){
        cout << "Yes" << "\n";
    }
    else if(100-n<=10){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" <<"\n";
    }
}

Measured memory_bytes: 256
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		int result = -1;
		if(x % y != 0){
			for(int i=x; ; i+=8){
				if(i % y != 0){
					result = i;
					break;
				}
			}
		}
		
		System.out.println(result);
	}
}


Measured memory_bytes: 35516
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll A,B;
  char op;
  cin >> A >> op >> B;
  if(op=='+'){
    cout << A+B << endl;
  }else{
    cout << A-B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int& a, int b) { if (a < b) { a = b; return true; } else return false; }
inline bool minch(int& a, int b) { if (a > b) { a = b; return true; } else return false; }

void dfs(string s, char c, char maxc, int h){
		s += c;
		char next = (char) c+1 > maxc ? c+1 : maxc;
		if (h == 1) cout <<	s << endl;
		else 
		for (char i = 'a'; i <= next; i = (char) (i+1)) {
		  dfs(s, i, next ,h-1);
		}
}

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

	dfs("",'a', 'a',n);
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(3e2 + 5);
const int MAX_ELEM = (int)(3e2 + 5);
const ll MOD = (ll)(998244353);

int n;
int a[MAX_N];

ll dp_single[MAX_N][MAX_N * MAX_ELEM];
ll dp_double[MAX_N][MAX_N * MAX_ELEM];

int max_size;
int acc;

ll ans;

ll calc_whole() {
  ll ret = 1LL;
  for (int i = 0; i < n; ++i) {
    ret *= 3;
    ret %= MOD;
  }
  return ret;
}

ll calc_single() {
  dp_single[0][0] = 1LL;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= max_size; ++j) {
      dp_single[i][j + a[i]] += dp_single[i - 1][j]; // paint a[i] as red;
      dp_single[i][j + a[i]] %= MOD;

      dp_single[i][j] += 2 * dp_single[i - 1][j]; // paint a[i] as green or blue, sum of red don't change
      dp_single[i][j] %= MOD;
    }
  }

  int half = (acc - 1) / 2 + 1;

  ll ret = 0LL;
  for (int i = half; i <= max_size; ++i) {
    ret += dp_single[n][i];
    ret %= MOD;
  }

  return ret;
}

ll calc_double() {
  dp_double[0][0] = 1LL;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= max_size; ++j) {
      dp_double[i][j + a[i]] += dp_double[i - 1][j]; // paint a[i] as red;
      dp_double[i][j + a[i]] %= MOD;

      dp_double[i][j] += dp_double[i - 1][j]; // paint a[i] as some-color not red, sum of red don't change
      dp_double[i][j] %= MOD;
    }
  }

  if (acc % 2 == 0) {
    return dp_double[n][acc / 2];
  }
  else {
    return 0LL;
  }
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    scanf("%d", &(a[i]));
  }

  max_size = MAX_ELEM * n;
  acc = accumulate(a + 1, a + n + 1, 0);

  ll num_whole = calc_whole();
  ll num_single = calc_single();
  ll num_double = calc_double();

  ans = 0LL;

  ans += num_whole;
  ans %= MOD;

  ans -= 3 * num_single;
  ans %= MOD;

  ans += 3 * num_double;
  ans %= MOD;

  if (ans < 0) ans += MOD;

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

  return 0;
}


Measured memory_bytes: 439808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF ((1LL<<62)-(1LL<<31))
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll dp[101][100001];

ll solve(int n, int w, vector<int> u, vector<int> v) {
	rep(i,101) rep(j,100001) dp[i][j] = INF + 1;
	dp[0][0] = 0; 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (j - v[i] >= 0) {
				dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + u[i]); 
			} else {
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	for (int j = 100000; j >= 0; j--) {
		if (dp[n][j] <= w) {
			return j;
		}
	}
	return 0;
}

int main() {
	int n, w;
	cin >> n >> w;
	vector<int> u(n), v(n);
	rep(i,n) cin >> u[i] >> v[i];
	cout << solve(n, w, u, v) << endl;
}

Measured memory_bytes: 82544
def main():
    A, B, N = (int(i) for i in input().split())
    ans = 0
    if B-1 <= N:
        i = B-1
        ans = (0--((A*i)//B)) - (A*(0--(i//B)))
    else:
        i = N
        ans = (0--((A*i)//B)) - (A*(0--(i//B)))
    print(ans)


if __name__ == '__main__':
    main()


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

//thanks to pyf ...
//thanks to qhl ...

string s;


bool judge(int l)
{
	if(l % 2)
		return false;
	for(int i = 0 ;i<l/2;i++)
	{
		if(s[i] != s[i+l/2])
			return false;
	}
	return true;
}

int main()
{
	while(cin >> s)
	{
		int i;
		for(i = s.length()-1;i>0;i--)
		{
			if(judge(i))
				break;			
		}
		cout << i  << endl;
	}	
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;

	cin >> n;
	int flag = 0;
	long long int a[100000 + 5];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		flag ^= a[i];
	}
	cout << (flag ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    list<int> ls[n];
    for(int i = 0; i < q; i++)
    {
        int v, t, x;
        cin >> v >> t;
        if(v == 0)
        {
            cin >> x;
            ls[t].push_back(x);
        }
        else if(v == 1)
        {
            bool flag = true;
            for(auto x : ls[t])
            {
                if(flag) 
                {
                    cout << x;
                    flag = false;
                }
                else cout << " " << x;
            }
            cout << endl;
        }
        else if(v == 2)
        {
            cin >> x;
            ls[x].splice(ls[x].end(), move(ls[t]));
        }
    }
    return 0;
}




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

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;


main(){
	int a,b,c;
	cin >> a >> b >> c;

	cout << c << " " << a << " " << b << " " << endl;

	return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n;
    string s,t;
    cin >> n >> s >> t;
    int kaburi = 0;
    //bool ok = false;
    rep(i,n){
        //cout << s.substr(i,n-i) << " " << t.substr(0,n-i) << endl;
        if(s.substr(i,n-i)==t.substr(0,n-i)){
            kaburi = n-i;
            //cout << kaburi << endl;
            break;
        }
    }
    string ans = s + t.substr(kaburi);
    cout << ans.length() << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n;
      while(cin>>n&&n){
            string s,t[100];
            int p,m;
            bool update=true;
            map<string,int>M;
            string o[100];vector<string> pp[100];
            REP(i,n){
                  cin>>t[i]>>p;
                  M[t[i]]=p;
            }
            cin>>m;
            REP(i,m){
                  cin>>o[i]>>p;
                  REP(j,p){
                        cin>>s;pp[i].PB(s);
                  }
            }
            while(update){
                  update=false;
                  REP(i,m){
                        int cost=0;
                        REP(j,pp[i].size()){
                              cost+=M[pp[i][j]];
                        }
                        if(M[o[i]]>cost){
                              M[o[i]]=cost;
                              update=true;
                        }
                  }
            }
            cin>>s;
            cout<<M[s]<<endl;
      }
}

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

int main(){
    ll w,a,b;
    cin>>w>>a>>b;
    ll c=max(a,b);
    ll d=min(a,b);
    ll ans=c-(d+w);
    if(ans>0){
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const int MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
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 / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }

int main() {
    int N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];
    sort(all(b), greater<int>());
    int a_max = *max_element(all(a));
    ll ans = 0;
    int i = 0;
    while(b[i] > a_max && H > 0){
        H -= b[i];
        ans++;
        i++;
    }
    if(H>0) ans += ceil((double)H/a_max);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main{
       public static void main(String[] args){
       int i = 0;
        Scanner scan = new Scanner(System.in);
        int W = scan.nextInt();
        int H = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();
        
        int left = x - r;
        int right = x + r;
        int bottom = y - r;
        int up = y + r;
        
        if(left >= 0 && right <= W && bottom >= 0 && up <= H){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        
        
        
        } 
        
        
        
        
        
       }
}

Measured memory_bytes: 26256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;



int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	sort(h.begin(), h.end());
	int ans = 1e9;
	for (int i = 0; i + k <= n; i++) ans = min(ans, h[i + k - 1] - h[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 100;
const int MAX_K = 1E+05;

int N, K;

int dp[MAX_K + 1], A[MAX_N];

int getGrundy(int k);

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

    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A, A + N);
    memset(dp, -1, sizeof(dp));

    if (getGrundy(K) > 0) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }

    return 0;
}

int getGrundy(int k)
{
    if (dp[k] != -1) {
        return dp[k];
    }
    if (k < A[0]) {
        return dp[k] = 0;
    }

    for (int i = 0; i < N; i++) {
        if (k >= A[i] && getGrundy(k - A[i]) == 0)
            return dp[k] = 1;
    }
    return dp[k] = 0;
}


Measured memory_bytes: 8708
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> N;
  cout << (N + 1) / 2 << endl;
  ;
}
void solve() {
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
mod=10**9+7
from fractions import gcd
h,w,t=map(int,input().split())
gh,gw=gcd(h,t),gcd(w,t)
h1,w1=h//gh,w//gw
print(
		pow(
			pow(2,w1,mod)+
			pow(2,h1,mod)+
			(mod-1)+
			pow(2,gcd(h1,w1),mod)+mod-2
			,gh*gw,mod)
		)


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=INF,a[ohara],b,c,d,cmpp[ohara],cmp,m,h,w,x,y,sum=0,pos,sei[ohara],fu[ohara],k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>k;
      rep(i,n){
        cin>>a[i];
        cmpp[i]=a[i];
      }
      rep(i,n){
          if(cmpp[i]<0){
          cnt++;
          if(cmpp[i+1]>0)a[i]=abs(cmpp[i]);
          else a[i]=abs(cmpp[i]*-1-cmpp[i+1]*-1);
        }
        else{
          if(i==0)continue;
          else if(cmpp[i-1]<0)continue;
          a[i]=abs(cmpp[i]-cmpp[i-1]);
        }
      }
      ll cntt=0;
      if(cnt>=1){
      rrrep(i,cnt-1,0){
        fu[cntt]=a[i];
        cntt++;
      }
      rep(i,cntt-1){
        fu[i+1]+=fu[i];
      }
      }
      ll cnttt=0;
      rrep(i,cnt,n){
        sei[cnttt]=a[i];
        cnttt++;
      }
      rep(i,cnttt-1){
        sei[i+1]+=sei[i];
      }
      if(cnttt>=k)ans=min(ans,sei[k-1]);
      if(cntt>=k)ans=min(ans,fu[k-1]);
      rep(i,cnttt){
        pos=sei[i];
        cmp=k-i-1;
        if(cmp<0)continue;
        if(cntt<cmp)continue;
        pos*=2;
        pos+=fu[cmp-1];
        ans=min(ans,pos);
      }
      rep(i,cntt){
        pos=fu[i];
        cmp=k-i-1;
        if(cmp<0)continue;
        if(cnttt<cmp)continue;
        pos*=2;
        pos+=sei[cmp-1];
        ans=min(ans,pos);
      }
      Cout(ans);

      
     

       
return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    s.push_back("!!!!!!!!!!");

    long long ret = 0;
    for (int i = 0; i < n; i++) {
        long long c = 0;
        while (s[i] == s[i + c])c++;
        ret += c * (c - 1) / 2;
        i += c - 1;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>

int main(void)
{
  long int N, D;
  scanf("%ld %ld", &N, &D);

  long int X[N], Y[N];
  for(int i=0;i<N;i++){
    scanf("%ld %ld", &X[i], &Y[i]);
  }

  int count = 0;
  for(int i=0;i<N;i++){
    if(D*D >= X[i]*X[i]+Y[i]*Y[i]) count++;
  }

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

  return 0;
}


Measured memory_bytes: 4856
using System;
using System.Collections.Generic;
using System.Linq;
 
class MainClass {
  public static void Main (string[] args) {
    //入力3
    var N = int.Parse(Console.ReadLine());
    var list = new List<string>();
    
    for(var i = 0; i < N; i++){
      list.Add(Console.ReadLine());
    }
    var intersectList = list[0].ToCharArray();

    list.ForEach(x => intersectList = intersectList.Intersect(x).ToArray() );

    //intersectList.ForEach(Console.Write);
    var result = new List<List<int>>();
     for(var i = 0; i < N; i++){
        result.Add(new List<int>());
      for(var j = 0; j < intersectList.Length; j++){
        result[i].Add(list[i].ToCharArray().Count(x => x == intersectList[j]) );
      }
    }

    var str = "";
    for(var i = 0; i < intersectList.Length; i++){
      for(var j = 0; j < result.Select(x => x[i]).Min(); j++){
        str += intersectList[i]; 
      }
    }
    str = new String(str.OrderBy(x => x).ToArray());
    Console.WriteLine(str);
    
  }
}


Measured memory_bytes: 13524
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N;

    int d[N];

    rep(ni,N) cin >> d[ni];

    sort(d,d+N);

    int b1,b2;
    b1 = d[N/2-1];
    b2 = d[N/2];
    if(b1==b2) cout << 0 << endl;
    else cout << b2-b1 << endl;

}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<map>
using namespace std;

string S,T;
int alp[30];
int beta[30];
int main (){
    cin >> S >> T;
    int l = S.length();
    for(int i=0; i<29; i++) {
        alp[i] = -1;
        beta[i] = -1;
    }
    for(int i=0; i<l; i++) {
            int a = S[i] - 'a';
            int b = T[i] - 'a';
            if( alp[a] != -1 || beta[b] != -1 ) {
                if (alp[a] != b || beta[b] != a ) {
                cout << "No" << endl;
                return 0;
                }
            }
            alp[a] = b;
            beta[b] = a;
        }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define swap(x,y) ((x)^=(y),(y)^=(x),(x)^=(y))
#define abs(x) ((x) < 0 ? -(x) : (x)) 
const int maxn=1e6+7;
typedef long long ll;
const int inf=1<<25;
ll read(){
    ll s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0' && c<='9') {s=s*10+c-48;c=getchar();}
    return s*f;
}
void write(int x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}
int tree[101010];
ll d[101010];
int siz[101010],fa[101010];
int cmp(int x,int y){
    return d[x] < d[y];
}
map<ll,int> maps;
int main()
{
    ll n=read();
    maps.clear();
    fors(i,1,n){
        d[i]=read();
        siz[i]=1;
        maps[d[i]]=i;
        tree[i]=i;
    }
    sort(tree+1,tree+n+1,cmp);
    for(int i=n;i>1;i--){
        fa[tree[i]]=maps[ d[tree[i]]+ 2*siz[tree[i]] -n ];
        if(!fa[tree[i]]){
            printf("-1");
            return 0;
        }
        siz[fa[tree[i]]]+=siz[tree[i]];
    }
    fors(i,2,n)
        d[tree[1]]-=siz[tree[i]];
    if(d[tree[1]]){
        printf("-1");
        return 0;
    }
    fors(i,2,n)
        printf("%d %d\n",fa[tree[i]],tree[i]);
    return 0;
}

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

using namespace std;

int uni_func(int start, int year, double per, int tesu)
{
	int ans = start;
	int sum = 0;

	for (int i = 0; i < year; ++i) {
		int rishi = static_cast<int>(ans * per);
		sum += rishi;
		ans = ans -  tesu;
	}

	ans += sum;

	return ans;
}

int mul_func(int start, int year, double per, int tesu)
{
	int ans = start;

	for (int i = 0; i < year; ++i) {
		ans = ans + static_cast<int>(ans * per) - tesu;
	}
	
	return ans;
}

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

	for (int data_i = 0; data_i < m; ++data_i) {
		int start, year, n;
		cin >> start;
		cin >> year;
		cin >> n;

		vector<int> last_money(n, 0);

		for (int i = 0; i < n; ++i) {
			int type, tesu;
			double per;
			cin >> type >> per >> tesu;

			if (type) {
				last_money[i] = mul_func(start, year, per, tesu);
			}
			else {
				last_money[i] = uni_func(start, year, per, tesu);
			}
		}

		int max = last_money[0];
		for (int i = 0; i < n; ++i) {
			if (max < last_money[i]) {
				max = last_money[i];
			}
		}

		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略

int main(){
  ll x;
  cin >> x;
  int flag = 0;
  for(ll i = -1000; i < 1000; i++){
    for(ll j = -1000; j < 1000; j++){
      if((i*i*i*i*i) - (j*j*j*j*j) == x){
        cout << i << " " << j << endl;
        flag = 1;
      }
    }
    if(flag == 1){
      break;
    }
  }
}

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

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

  int n = s.size();

  vector<int> a(n);

  for(int i = 0; i < n; i++){
    int count = 0;
    if((s.at(i) == 'A') || (s.at(i) == 'C') || (s.at(i) == 'G') || (s.at(i) == 'T')){
      int b = i;
      for(int j = b; j < n; j++){
        if((s.at(j) == 'A') || (s.at(j) == 'C') || (s.at(j) == 'G') || (s.at(j) == 'T')){
          count++;
        }
        else{
          break;
        }
      }
    }
    else{
      continue;
    }

    a.at(i) = count;
  }

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

  cout << a.at(n - 1) << endl;
}

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


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

    int R[n];
    for (int i=0; i<n; i++) R[i] = 0;
    for (int i=0; i<n; i++) cin >> R[i];
    int min = R[0];
    int max = -2000000000;
    for (int i=1; i<n; i++) {
        int tmp = R[i] - min;
        if (max < tmp) max = tmp;
        if (R[i] < min) min = R[i];
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int N;
  cin >> N;
  vector<pii> P(N);
  set<ll> s;
  s.insert(0);
  s.insert(N+1);
  rep(i,N) {
    cin >> P[i].first;
    P[i].second = i+1;
  }
  sort(all(P));
  s.insert(P.back().second);
  P.pop_back();
  ll ans = 0;
  while (!P.empty()) {
    ll fir = P.back().first,sec = P.back().second;
    auto itl = s.lower_bound(sec);
    auto itr = itl;
    itl--;
    if (itl != s.begin()) {
      ans += fir*(*itl-*(--itl))*(*itr-sec);
      itl++;
    }
    if (++itr != s.end()) {
      ll tmp = *itr;
      ans += fir*(sec-*itl)*(tmp-*(--itr));
    }
    s.insert(sec);
    P.pop_back();
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 8732
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int a[27];
int main() {
    string s;
    cin >> s;
    memset(a , 0 , sizeof(a));
    int flag = 0;
    for(int i = 0 ; i < s.size() ; i++) {
        a[s[i] - '0']++;
        if(a[s[i] - '0'] > 1) {flag = 1;break;}
    }
    if(!flag) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b;
  cin >> a;
  cin >> b;
  
  if(a % 500 -b > 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

int main(){
	int N;
  	cin >> N;
  	int sum = 0;
  	vector<int> vec;
  	int base4 = 0;
  	int base7 = 0;
  	int base;
  	
  	while(true){
    	
      	while(true){
        	
          	base = base4 + base7;
          	if(base>100){
              	base = 0;
              	base7 = 0;
              	break;
            }
          	//cout << base << endl;
          	vec.push_back(base);
          	base7 += 7;
        }
    	if(base4>100){
     		base4 = 0;
      		break;	
    	}  	
      	base4 += 4;
      	//cout << base4 <<endl;
    }
	
  	auto ans = find(vec.begin(),vec.end(),N);
  	if(ans != vec.end()){
    	cout << "Yes"<<endl;
    }else{
    	cout << "No"<<endl;
    }

}

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

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
int n, m;
char a[55][55], b[55][55];

bool solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j) cin >> a[i][j];
  for(int i = 0; i < m; ++i)
    for(int j = 0; j < m; ++j) cin >> b[i][j];
  prians(solve());
  return 0;
}

bool solve() {
  bool ch = 0;
  for(int i = 0; i + m - 1 < n; ++i)
    for(int j = 0; j + m - 1 < n; ++j) {
      ch = 0;
      for(int k = 0; k < m; ++k)
        if(!ch)
          for(int l = 0; l < m; ++l) {
            if(b[k][l] != a[i + k][j + l]) {
              ch = 1;
              break;
            }
            if(k == l && k == m - 1) return 1;
          }
    }
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int n,table[100002]={0};
  cin >>n;
  for(int i=0,a,b; i<n; i++){
    cin >>a>>b;
    for(a; a<=b; a++) table[a]++;
  }
  for(int i=n+1; i>0; i--){
    if(table[i] >= i-1){
      cout <<i-1<<endl;
      return 0;
    }
  }
  cout <<"0"<<endl;
  return 0;
}

Measured memory_bytes: 1560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N;
	vector<int> T(200000,100001);
	vector<int> mv={1};
	T[0]=0;
	cin>>N;
	for(int i=6;i<=N;i*=6)mv.push_back(i);
	for(int i=9;i<=N;i*=9)mv.push_back(i);
	for(int i=0;i<N;i++)
	{
		for(int m=0;m<mv.size();m++)
		{
			T[i+mv[m]]=min(T[i+mv[m]],T[i]+1);
		}
	}
	cout<<T[N]<<endl;

}

Measured memory_bytes: 1024