akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define vector3D(K, N, M, DP) vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M)));
#define vector4D(K, N, M, O, DP) vector<vector<vector<vector<ll>>>> DP(K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O))));
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}
template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};
template<typename T> ll comb(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}

/* ここからコード開始 */

int main(){
  kyopro;
  string S;
  cin >> S;
  ll y = stoll(S.substr(0, 4));
  ll m = stoll(S.substr(5, 2));
  ll o{};
  if(y == 2019){
    if(m > 4){
      o = 1;
    }
  }
  else if(y > 2019) o = 1;
  if(o) cout << "TBD" << rt;
  else cout << "Heisei" << rt;
}

Measured memory_bytes: 256
import static java.lang.System.out;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int a = scan.nextInt();
            String op = scan.next();
            int b = scan.nextInt();

            if (op.equals("?")) {
                break;
            } else if (op.equals("+")) {                               
                out.println(a + b); 
            } else if (op.equals("-")) {
                out.println(a - b); 
            } else if (op.equals("*")) {
                out.println(a * b); 
            } else if (op.equals("/")) {
                out.println(a / b); 
            }
        }
    }   
}

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

count = 0

for i in range(2 ** n):
    swith = str(bin(i))[2:]
    swith_num = swith.zfill(n)
    for j in ks:
        flag = 0
        swith_sum = 0
        for k in j[1:]:
            swith_sum += int(swith_num[int(k) - 1])
        if swith_sum % 2 == p[ks.index(j)]:
            pass
        else:
            flag = 1
            break
    if flag == 0:
        count += 1

print(count)

Measured memory_bytes: 3064
S = input()
a = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == "<":
        a[i + 1] = a[i] + 1

for i in list(range(len(S)))[::-1]:
    if S[i] == ">" and a[i + 1] >= a[i]:
        a[i] = a[i + 1] + 1

print(sum(a))


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

const int MAX_N = 2e5+5;

int n, k;
int a[MAX_N], pos[MAX_N];

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

    cin >> k >> n;
    for (int i = 1; i <= n; i++) {
        cin >> pos[i];
        a[i] = pos[i] - pos[i-1];
    }

    a[n+1] = k - pos[n] + a[1];
    a[1] = a[n+1];

    /*for (int i = 1; i <= n+1; i++) {
        cout << a[i] << " ";
    }*/

    int ans = 1e9;
    for (int i = 1; i <= n; i++) {
        ans = min(ans, k - a[i]);
        ans = min(ans, k - a[i+1]);
    }

    cout << ans;



    return 0;
}


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

int main(int argc, char const *argv[]) {
  int w,a,b;
  cin>>w>>a>>b;
  if(b>(a+w)){
    cout<<b-(a+w)<<endl;
  }else if((b+w)<a){
    cout<<a-(b+w)<<endl;
  }else{
    cout<<"0"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
  /*
    int N,K;
    int T_len;
    int i;
    char *ret;
    char S[51]="UNRESTORABLE";
    char SR[51]="";
    char T[51]="";
*/
    int input=0;
    double sq1=0;
    int sq_ans=0;
    int po1=0;
    
  // 整数の入力
    scanf("%d", &input);
//    printf("%d\n",input);
    sq_ans = (int)sqrt((double)input);
//    printf("%d\n",sq_ans);
//    po1 = pow(sq_ans,sq_ans);
//      printf("%lf\n",(double)sq_ans);
    printf("%d\n",(int)(pow((double)sq_ans,(double)2)));
//    printf("%c\n",Cj);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int i = 1;
  while (N != 0) {
      cout << "Case" << ' ' << i << ':' << ' ' <<  N << endl;
      cin >> N;
      i++;
  }
}
 



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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	string s;
	cin >> n >> k >> s;
	if (s[k - 1] >= 'A' && s[k - 1] <= 'Z')
		s[k - 1] += 'a' - 'A';
	cout << s;
}

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

int main(){
int a, b;

while(1){
cin >> a >> b;
if( a == 0 && b == 0 ) break;

if( a < b ){
cout << a << " " << b << endl;
} else {
cout << b << " " << a << endl;
}
}

return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  
  int tsize = t.size();
  int ssize = s.size();
  bool ok,flag = false;
  string ans;
  rep(i,ssize){
    ans += 'z';
  }
  rep(i,ssize -tsize+1){
    ok = true;
    rep(j,tsize){
      if(s[i+j] != t[j] && s[i+j] != '?') ok = false;
    }
    if(ok){
      string temp;
      rep(asize,i){
        if(s[asize] == '?') temp += 'a';
        else temp += s[asize];
      }
      temp += t;
      while(temp.size()<s.size()){
        if(s[temp.size()] == '?')temp += 'a';
        else temp += s[temp.size()];
      }
      ans = min(temp,ans);
      flag = true;
    }
  }
  if(!flag) ans = "UNRESTORABLE";
  cout << ans << endl;
  return 0;
}
    
    

Measured memory_bytes: 256
# 写経
S = input()
T = input()


found = []
for i in range(len(S) - len(T) + 1):
    for cs, ct in zip(S[i:], T):
        if cs != "?" and cs != ct:
            break
    else:
        found.append(i)


if not found:
    ans = "UNRESTORABLE"
else:
    ans = "z" * 51
    for i in found:
        tmp = S[:i] + T + S[i+len(T):]
        ans = min(ans, tmp.replace("?", "a"))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll unsigned long long
#define pi 3.1415926535897932384626433832795
#define fin(a,n)  for(ll i=0;i<n;i++) cin>>a[i];
#define fout(a,n)  for(ll i=0;i<n;i++) cout<<a[i]<<" ";
int N = 1000000007;
using namespace std;

int main() 
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); cout.tie(NULL);
	int n,m,c=0,ans=0;
	cin>>n>>m;
	int a[n];
	fin(a,n);
	if(m > n)
	{
		cout<<"No\n";
		return 0;
	}
	c = accumulate(a,a+n,0);
	for(int i=0;i<n;i++)
		if(a[i]*4*m >= c)
			ans++;
	if(ans >= m)
	{
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int n, m, q;
int a[50], b[50], c[50], d[50];
int A[10];

int maxScore = -1;
void dfs(int dep, int x) {
	if (dep == n) {
		int i, score = 0;
		rep(i, q) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				score += d[i];
			}
		}
		maxScore = max(maxScore, score);
		return;
	}
	
	for (int i = x; i <= m; i++) {
		A[dep] = i;
		dfs(dep + 1, i);
	}
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> q;
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	
	dfs(0, 1);
	
	cout << maxScore << endl;
	
	return 0;
}


Measured memory_bytes: 3572
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		M += v[i] != i;
	}
	if (M <= 2) cout << "YES\n";
	else cout << "NO\n";
}


Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
string s;
int mod=1e9+7;
int cache[100005][15];
int dp(int pos,int rem)
{
    if(pos==n)
        return rem==5;
    int &ans=cache[pos][rem];
    if(ans!=-1)
        return ans;
    ans=0;
    if(s[pos]!='?')
        return ans=dp(pos+1,(rem*10+s[pos]-'0')%13);
    else
    {
        for(int i=0;i<10;i++)
            ans+=dp(pos+1,(rem*10+i)%13);
        ans%=mod;
        return ans;
    }

}
int32_t main()
{
    IOS;
    cin>>s;
    n=s.length();
    memset(cache,-1,sizeof(cache));
    print(dp(0,0));
}

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

using namespace std;

int main()
{
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >>e;
    if(a == 0) cout << 1;
    else if(b == 0) cout << 2;
    else if(c == 0) cout << 3;
    else if(d == 0) cout << 4;
    else if(e == 0) cout << 5;


    return 0;

}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;int n,x,y,h,w,d,e,s,v;double j(int a,int b){return sqrt(a*a+b*b+0.0);}int main(){while(1){bool ok=1;cin>>n>>h>>w>>d>>e;if(!n)break;cin>>s>>v;if(j(h-s,w-v)>=j(d-s,e-v))ok=0;for(int i=1;i<n;i++){cin>>x>>y;if(j(h-s,w-v)+j(s-x,v-y)>=j(d-x,e-y))ok=0;}if(ok) cout << "YES" << endl;else cout << "NO" << endl;}return 0;}

Measured memory_bytes: 2988
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
#input = sys.stdin.readline

start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
d = defaultdict(int)
for i in range(N):
    ans += d[Adif[i]]
    d[Asum[i]] += 1

print(ans)


Measured memory_bytes: 157048
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
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;}
 
const ll INF=1e9+7;

int main(){
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans=0;
    if(c<=a+b){
        ll ans=INF;
        rep(i,100001){
            ll p=max(0LL,x-i);
            ll q=max(0LL,y-i);
            ans=min(ans,p*a+q*b+2*i*c);
        }
        cout << ans << endl;
    }
    else{
        cout << a*x+b*y << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  string S;
  cin >> S;
  string answer;
  answer = S[0] + to_string(S.size() - 2) + S.back();
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<' ';pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) a[i]=i;
  vector<P> v;
  rep(i,m) {
    int x=1;
    if(n%2==0&&i>=n/4) x++;
    v.pb(P((0-i+n)%n,(x+i+n)%n));
  }
  rep(i,m) pr(v[i].F+1,v[i].S+1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main(){
    int n,T;
    cin>>n>>T;
    long long t[n];
    long long ans=0;
    cin>>t[0];
    for(int i=1;i<n;i++){
        cin>>t[i];
        if(t[i]-t[i-1]<=T) ans+=t[i]-t[i-1];
        else ans+=T;
    }
    cout<<ans+T<<endl;
}


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

const int MOD = 1000000007;

int power(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1LL * ret * x % MOD;
    x = 1LL * x * x % MOD;
  }
  return ret;
}

int n;

// [x^n] x^5 / ((1 - x)^11 (1 - x^2)^5)
// sum(C(N - 2*i + 10, 10) * C(i + 4, 4))
// 15-deg polynom

int solve() {
  scanf("%d", &n);
  n -= 5;

  vector<int> y;
  int sum = 0;
  for (int i = 0; i < 16; ++i) {
    int t = 1;
    for (int j = 0; j < 10; ++j) {
      t = 1LL * t * (n - i*2 + 10 - j) % MOD;
      t = 1LL * t * power(j+1, MOD-2) % MOD;
    }
    for (int j = 0; j < 4; ++ j) {
      t = 1LL * t * (i + 4 - j) % MOD;
      t = 1LL * t * power(j+1, MOD-2) % MOD;
    }

    sum = (sum + t) % MOD;
    y.push_back(sum);
  }

  int ans = 0;
  for (int k = 0; k < 16; ++k) {
    int t = 1;
    for (int i = 0; i < 16; ++i) {
      if (i == k) continue;
      t = 1LL * t * (n/2 - i) % MOD;
      t = 1LL * t * power(k - i, MOD-2) % MOD;
    }

    ans = (ans + 1LL * t * y[k]) % MOD;
  }

  if (ans < 0) ans += MOD;
  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 3760
N = int(input())
A = list(map(int, input().split()))

n_kabu = 0
money = 1000
for d in range(N-1):
    kabuka_today = A[d]
    kabuka_tomorrow = A[d+1]
    if kabuka_today < kabuka_tomorrow:
        can_buy = money//kabuka_today
        n_kabu += can_buy
        money -= can_buy*kabuka_today
    elif kabuka_today > kabuka_tomorrow:
        money += n_kabu*kabuka_today
        n_kabu = 0

money += n_kabu*A[N-1]

print(money)

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

int main(){
 int a[3][3];
  int b[3]={};
  int q=0,p=0;
  for(int i=0;i<3;i++){
    for(int r=0;r<3;r++){
     cin >> a[i][r];
      b[i]+=a[i][r];
    }
    if(b[i]>=q){q=b[i];
               p=i;}
  }
  
  for(int i=0;i<3;i++){
    if(p==i){continue;}
    if(a[p][0]-a[i][0] !=a[p][1]-a[i][1] || a[p][1]-a[i][1] != a[p][2]-a[i][2])
    {cout << "No" << endl;
    return 0;}
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	S := nextLine()
	var prev rune
	for _, Si := range S {
		if Si == prev {
			fmt.Println("Bad")
			return
		}
		prev = Si
	}
	fmt.Println("Good")
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}


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

typedef unsigned short int us;
typedef short int s;
typedef unsigned long int ul;
typedef long int l;
typedef unsigned long long int ull;
typedef long long int ll;
typedef char c;
typedef bool b;
typedef double d;
typedef long double ld;
typedef float f;

#define FOR(x, y, z) for(ll z = x; z < y; z++)
#define FORE(x, y, z) for(ll z = x; z <= y; ++z)
#define FORD(x, y, z) for(ll z = x; z > y; --z)
#define FORDE(x, y, z) for(ll z = x; z >= y; --z)
#define REP(x, y) for(ll y = 0; y < x; ++y)

#define PF push_front
#define POF pop_front
#define PB push_back
#define POB pop_back
#define MP make_pair

const l INF = 1e9+1;
const ll L_INF = 1e18+1;
const double EPS = 1e-7;

using namespace std;

string A, B;
vector<l> positions[256];
l last = -1;
ll answer = 0;

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

    cin >> A >> B;

    REP(A.size(), i)
        positions[static_cast<int>(A[i])].PB(i);

    REP(B.size(), i)
    {
        if(positions[static_cast<int>(B[i])].empty())
        {
            cout << -1 << "\n";
            return 0;
        }

        else
        {
            auto it = lower_bound(positions[static_cast<int>(B[i])].begin(), positions[static_cast<int>(B[i])].end(), last+1);

            if(it == positions[static_cast<int>(B[i])].end())
            {
                answer += A.size();
                last = positions[static_cast<int>(B[i])][0];
            }

            else
                last = *it;
        }
    }

    cout << answer + last + 1;
}

Measured memory_bytes: 1736
using namespace std;
#include<iostream>
#include<vector>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<string>
#include<cctype>
#include <algorithm>
#include<cassert>
int main(void){
	string s;
	cin >> s;
	if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi"){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)

int main() {
  int n;
  long long k, high=0, low=-1, X, sum;
  cin >> n >> k;
  vector<int> A(n);
  vector<int> F(n);
  rep(i,n) cin >> A.at(i);
  rep(i,n) cin >> F.at(i);
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), [](int &a, int &b){return a > b;});
  for(int i=0;i<n;i++)high=max(high, (long long)A.at(i) * (long long)F.at(i));
  while(low+1!=high){
    X=(high+low)/2;
    sum = 0;
    rep(i,n) {
      sum += max(A.at(i)-X/F.at(i),(long long)0);
    }
    if(sum > k)low=X;
    else high=X;
  }
  cout << high << endl;
}

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

using namespace std;

int median(int a, int b, int c)
{
    vector<int> v = { a, b, c };
    sort(v.begin(), v.end());
    return v[1];
}

vector<int> iter(vector<int> a)
{
    if (a.size() == 1) return a;
    
    vector<int> b;
    for (int i = 0; i < a.size() - 2; i++)
        b.push_back(median(a[i], a[i + 1], a[i + 2]));
    
    for (int x: b) printf("%d ", x); printf("\n");
    
    return iter(b);
}

int extractG(set<int>& s, int x)
{
    auto it = s.lower_bound(x);
    int g = *it;
    s.erase(g);
    return g;
}

vector<int> build(int n, int x)
{
    if (x == 1 || x == 2 * n - 1) return vector<int>();
 
    if (n == 2)
    {
        return vector<int> { 1, 2, 3 };
    }
    
    if (x == 2 * n - 2)
    {
        vector<int> y = build(n, 2 * n - x);
        for (int& a: y)
            a = 2 * n - a;
        return y;
    }
    
    set<int> unused;
    for (int i = 1; i <= 2 * n - 1; i++) unused.insert(i);
    
    unused.erase(x);
    unused.erase(1);
    
    int g1 = extractG(unused, x);
    int g2 = extractG(unused, x);
    
    vector<int> ans(2 * n - 1);
    ans[n - 2] = g1;
    ans[n - 1] = 1;
    ans[n] = x;
    ans[n + 1] = g2;
    
    for (int i = 0; i < 2 * n - 1; i++)
    {
        if (ans[i]) continue;
        ans[i] = *unused.begin();
        unused.erase(ans[i]);
    }
    
    return ans;
}

int main()
{
    int n = rand() % 10 + 2;
    int x = rand() % (2 * n - 3) + 2;
    cin >> n >> x;
    
    //printf("n=%d, x=%d\n", n, x);
    vector<int> b = build(n, x);
    
    if (!b.empty())
    {
        printf("Yes\n");
        for (int y: b) printf("%d ", y); printf("\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
    
    while (true)
    {
    int n = rand() % 10 + 2;
    int x = rand() % (2 * n - 3) + 2;
    
    printf("n=%d, x=%d\n", n, x);
    vector<int> b = build(n, x);
    
    for (int y: b) printf("%d ", y); printf("\n");
    
    assert(iter(b)[0] == x);
    }
    
    return 0;
    
    vector<int> a;
    for (int i = 0; i < 2 * 3 + 1; i++)
        a.push_back(i + 1);
    
    set<int> can;
    
    do
    {
        int x = iter(a)[0];
        //printf("%d ", x);
        can.insert(x);
        if (x == 2) { for (int y: a) printf("%d ", y); printf("\n"); break; }
        //break;
    }
    while (next_permutation(a.begin(), a.end()));
    //printf("\n");
    
    for (int x: can) printf("%d ", x); printf("\n");

    return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const int INF=1e9;

int n;

int main(){
  string s,t,u;
  int a,b;
  cin>>s>>t;
  cin>>a>>b;
  cin>>u;
  
  
  if(s==u) a--;
  if(t==u) b--;
  cout<<a<<" "<<b<<endl;
  return 0;
  
 
  

}

Measured memory_bytes: 256
#include <iostream>
int main(){
	int n,i,j;
	double x[4],y[4];
	std::cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<4;j++)std::cin>>x[j]>>y[j];
		if(((y[0]-y[1])/(x[0]-x[1]))==((y[2]-y[3])/(x[2]-x[3])))std::cout<<"YES\n";
		else std::cout<<"NO\n";
	}
}

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

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

    if (a == 'H' && b == 'H' || a == 'D' && b == 'D')
        cout << 'H' << endl;
    else
        cout << 'D' << endl;
    return 0;
}


Measured memory_bytes: 3540
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
map<string,int>cnt;
int main()
{
	int n;
	cin >>n;
	while(n--)
	{
		string a;
		cin>>a;
		cnt[a]++;
	}
	int k=0;
	for(map<string,int>::iterator it=cnt.begin();it!=cnt.end();it++)
	k=max(k,it->second);
	for(map<string,int>::iterator it=cnt.begin();it!=cnt.end();it++)
	if(k==it->second)
	cout<<it->first<<endl;
	

	return 0;
 } 

Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,n,sum=0;
  cin>>n;
  int d[n];
  for(i=0;i<n;i++)
    cin>>d[i];
  
  for(i=0;i<n-1;i++)
  {
    for(int j=i+1;j<n;j++)
      sum+=(d[i]*d[j]);
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

    int n, k;
    cin >> n >> k;

    int t = 0, m = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        t = gcd(a, t);
        if (a > m) m = a;
    }
    cout << (k <= m && k % t == 0 ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] st = Console.ReadLine().Split(' ');
        int n = int.Parse(st[0]);
        int k = int.Parse(st[1]);
        string s = Console.ReadLine();

        char[] c = s.ToCharArray();
        c[k - 1] = (char)((int)c[k - 1] + 32);
      
        s = new String(c);
        Console.WriteLine(s);
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s;
	scanf("%c",&s);
	if(s=='S')	printf("Cloudy\n");
	else if(s=='C')	printf("Rainy\n");
	else if(s=='R')	printf("Sunny\n");
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var H, W int
	fmt.Scanf("%d %d", &H, &W)
	S := make([][]string, H)
	for i := 0; i < H; i++ {
		var s string
		fmt.Scanf("%s", &s)
		S[i] = strings.Split(s, "")

	}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if S[i][j] != "#" {
				S[i][j] = calc(S, i, j)
			}
		}
	}
	for i := 0; i < H; i++ {
		fmt.Println(strings.Join(S[i], ""))
	}
}

func isSharp(s [][]string, h, w int) bool {
	if h < 0 || len(s) <= h || w < 0 || len(s[0]) <= w {
		return false
	}
	if s[h][w] == "#" {
		return true
	}
	return false
}

func calc(s [][]string, h, w int) string {
	ret := 0
	for i := h - 1; i <= h+1; i++ {
		for j := w - 1; j <= w+1; j++ {
			if i == h && j == w {
				continue
			}
			if isSharp(s, i, j) {
				ret += 1
			}
		}
	}
	r := strconv.Itoa(ret)
	return r
}


Measured memory_bytes: 640
import java.util.Scanner;

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

		// 文字列の入力
		String str = sc.next();
		char c[] = str.toCharArray();
		int len = c.length;
		int[] a = new int[len];
		int[] n = new int[len];
		int[] n2 = new int[len];

		int j, cnt;

		for(int i = 0; i < len; i++) {
			n[i] = 0;
		}

		for(int i = 0; i < len-1; i++) {
			if(c[i]=='R' && c[i+1]=='L') {
				n[i] = 1;
				n[i+1] = 1;

				j = i-1;
				while(j >= 0 && c[j] == 'R') {
					j--;
				}

				if((i-j-1) % 2 == 0) {
					n[i] += (i-j-1)/2;
					n[i+1] += (i-j-1)/2;
				} else {
					n[i] += (i-j-1)/2;
					n[i+1] += (i-j-1)/2+1;
				}

				j = i+1;
				while(j < len && c[j] == 'L') {
					j++;
				}

				if((j-i-2) % 2 == 0) {
					n[i] += (j-i-2)/2;
					n[i+1] += (j-i-2)/2;
				} else {
					n[i] += (j-i-2)/2+1;
					n[i+1] += (j-i-2)/2;
				}
			}
		}

		/* 配列に読み込み */
		/*
		for(int i = 0; i < len; i++) {
			a[i] = c[i] == 'L' ? -1 : 1;
			n[i] = 1;
		}

		for(int i = 0; i < ((len % 2 == 0) ? len : len+1); i++) {

			if(i % 2 == 0) {
				for(int j = 0; j < len; j++) {
					n2[j] = 0;
				}

				for(int j = 0; j < len; j++) {
					n2[j+a[j]] += n[j];
				}
			} else {
				for(int j = 0; j < len; j++) {
					n[j] = 0;
				}

				for(int j = 0; j < len; j++) {
					n[j+a[j]] += n2[j];
				}
			}
		}*/

		for(int i = 0; i < len; i++) {
			System.out.print(n[i]+ " ");
		}

        sc.close();
	}
}

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

using namespace std;

template<typename T> class SegmentTree {
private:
  const T INF;
  int n;
  vector<T> d;
  
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return d[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return function(vl, vr);
  }

protected:
  virtual T function(T l, T r) = 0;
  
public:
  SegmentTree(int m) : INF(numeric_limits<T>::max()) {
    n = 1 << (32 - __builtin_clz(m - 1));
    d.resize(2 * n - 1, INF);
  }

  void update(int k, T a) {
    k += n - 1;
    d[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      d[k] = function(d[k * 2 + 1], d[k * 2 + 2]);
    }
  }

  // [a,b)
  T query(int a, int b) {
    return query(a, b, 0, 0, n);
  }
};

template<typename T> class RMQ : public SegmentTree<T> {
protected:
  T function(T l, T r) {
    return min(l, r);
  }
  
public:
  RMQ(int n) : SegmentTree<T>(n) {}
};

int main() {
  int n, q;
  cin >> n >> q;
  RMQ<int> rmq(n);
  for (int i = 0; i < q; ++i) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) rmq.update(x, y);
    else cout << rmq.query(x, y + 1) << endl;
  }
}

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

int main(){
    string s; cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int a = obj.nextInt(),b = obj.nextInt();
        int c = obj.nextInt(),k = obj.nextInt();
        int sum = 0;
        if(k>0)
        {
            sum += Math.min(a,k);
            k -= Math.min(a,k);
        }
        if(k==0)
        {
            System.out.println(sum);
            return;
        }
        if(k>0)
            k-= Math.min(k,b);
        if(k==0)
        {
            System.out.println(sum);
            return;
        }
        if(k>0)
        {
            sum -= Math.min(k,c);
            k-=Math.min(k,c);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 32564
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <climits>
#include <string>

typedef long long ll;

using namespace std;

string shuffle(string s, int x){
    string s1, s2;
    for(auto itr = s.begin(); itr < s.begin()+x; itr++){
        s1 += *itr;
    }
    for(auto itr = s.begin()+x; itr < s.end(); itr++){
        s2 += *itr;
    }
    return s2+s1;
}

void solve(){
    string s;
    int m;
    while(cin >> s){
        if(s == "-"){
            break;
        }
        cin >> m;
        for(int i = 0; i < m; i++){
            int x;
            cin >> x;
            s = shuffle(s, x);
        }
        cout << s << endl;
    }
}

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

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

// index が条件を満たすかどうか
bool isOK(vector<ll> &A, ll index, ll key) {
    if (A[index] > key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll bin_search(vector<ll> &A, ll key) {
    ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = (ll)A.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

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

        if (isOK(A, mid, key)) right = mid;
        else left = mid;
    }

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

int main(){

    int N,M,K;
    cin >> N >> M >> K;
    vector<ll> A,B;
 
    A.push_back(0);
    B.push_back(0);
 
    rep(i,N) {
        int a;
        cin >> a;
        A.push_back(A[i]+a);
    }
    rep(i,M){
        int b;
        cin >> b;
        B.push_back(B[i]+b);
    }
    int amax = bin_search(A,K);
    amax--;
    int ans = 0;
    for (int i = amax; i>=0; i--) {
        int res = K - A[i];
        int bmax = bin_search(B,res);
        bmax--;
        //cout << res << " " << bmax << " " << i << endl;
        ans = max(ans,bmax+i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7980
from itertools import product

N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [input() for _ in range(M)]

b = "".join(B)

ans = "No"
for i, j in product(range(N - M + 1), repeat=2):
    a = "".join(["".join(x[j:j + M]) for x in A[i:i + M]])
    if a == b:
        ans = "Yes"
        break
print(ans)


Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    int r = 1;
    int l = n-2;
    int mi = a[0];
    int ma = a[n-1];
    vector<pair<ll,ll> > ret;
    while(r<=l){
        if(a[r]<=0){
            ret.pb(make_pair(ma,a[r]));
            ma = ma-a[r];
            r++;
        }
        if(a[l]>=0&&r<=l){
            ret.pb(make_pair(mi,a[l]));
            mi = mi-a[l];
            l--;
        }
    }
    cout << ma - mi << endl;
    for(auto r : ret){
        cout << r.fi << " " << r.se << endl;
    }
    cout << ma << " " << mi << endl;
    return 0;
}

Measured memory_bytes: 4336
import math

def sizeN(n):
    count = 1
    for i in range(n):
        count = count*2 + 3
    return count


def countP(n):
    if n < 0:
        return 0
    count = 1
    for i in range(n):
        count = count*2 + 1
    return count


def sharpen(x):
    return x - 1


def answer(N, X):
    count_p = 0
    x = X
    for n in range(N,-1,-1):
        if x < math.ceil(sizeN(n)/2):
            x = sharpen(x)
        else:
            x = sharpen(x - math.floor(sizeN(n)/2))
            count_p += countP(n-1)+1
    return count_p


if __name__ == '__main__':

    N, X = map(int, input().split())
    print(answer(N, X))


Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	// your code goes here
	
	int i,j,H,W;
	
	while(-1){
	    scanf("%d %d",&H,&W);
	    if(H == 0 && W==0) break;
	    
	    for(i=1;i<=H;i++){
	        for(j=1;j<=W;j++){
	           if((j+i)%2 == 0) printf("#");
	           else printf(".");
	        }
	        printf("\n");
	    }
	    printf("\n");
	        
	}
	return 0;
}




Measured memory_bytes: 2040
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ans = IntArray(n) {0}
    (1..100).forEach { x->
        (1..100).forEach { y->
            (1..100).forEach { z->
                val v = x * x + y * y + z * z + x * y + y * z + z * x
                if (v <= n) {
                    ans[v - 1]++
                }
            }
        }
    }
    println(ans.joinToString("\n"))
}

Measured memory_bytes: 39976
#include <iostream>
#include <set>

using namespace std;

int main()
{
    set<string> words;
    int n;
    string word;
    cin >> n >> word;
    words.insert(word);
    char lastchar = word[word.length()-1];
    for (int i=1; i<n; i++)
    {
        string nxtword;
        cin >> nxtword;
        if (nxtword[0] != lastchar)
        {
            printf("No");
            return 0;
        }
        words.insert(nxtword);
        lastchar = nxtword[nxtword.length()-1];
    }
    if (words.size() != n)
    {
        printf("No");
        return 0;
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner src = new Scanner(System.in);
		int answer = 0;
		int[] value = {500, 100, 50, 10, 5, 1};
		int[] coin = new int[1000];
		int count = 0;
		for(int i = 0;; i++) {
			int temp = src.nextInt();
			if(temp == 0)	break;
			coin[i] = 1000 - temp;
			count++;
		}


		//	コインの枚数
		for(int j = 0; j < count; j++) {
			int t = coin[j];
			for(int i = 0; i < value.length; i++) {
				int n;
				if(coin[j] / value[i] > 0) {
					//	coin[i]で支払いができるとき
					n = t / value[i];
					t -= n * value[i];
				}else {
					// coin[i]で支払いが無理なとき
					continue;
				}
				answer += n;
			}
			System.out.println(answer);
			answer = 0;
		}
	}
}


Measured memory_bytes: 26108
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	while(cin >> s){
		bool m = true;
		string ans = "No";
		REP(i,SZ(s)){
			if(m){
				if(s[i] == 'C'){
					m = false;
				}
			}else{
				if(s[i] == 'F'){
					ans = "Yes" ;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
const int N=1e5+5;
typedef long long ll;
int n,a[N],b[N],c[N],d[N];
int bit[N<<1];ll tot=0;
void init() {
    for(int i=1;i<N<<1;i++) bit[i]=0;
}
void add(int x,int v) {
    for(;x<N<<1;x+=x&-x) bit[x]+=v;
}
int sum(int x) {
    int res=0;
    for(;x;x-=x&-x) res+=bit[x];
    return res;
}
bool check(int x) {
    init();
    for(int i=1;i<=n;i++) {
        if(a[i]<x) b[i]=-1;
        else b[i]=1;
        c[i]=c[i-1]+b[i];
        add(c[i]+N,1);
    }
    ll ans=0;int now=N;
    for(int i=1;i<=n;i++) {
        ans+=sum(now-1);
        now+=b[i];add(c[i]+N,-1);
    }
    return tot-ans>=ans;
}
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",a+i),d[i]=a[i];
    int l=1,r=1e9+7,mid;tot=1LL*(n+1)*n>>1;tot=tot;
    std::sort(d+1,d+n+1);int tail=std::unique(d+1,d+n+1)-d;
    r=tail;
    while(r-l>1) {
        mid=(l+r)>>1;
        if(check(d[mid])) l=mid;
        else r=mid;
    }
    printf("%d\n",d[l]);
    return 0;
}


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

int n, q;
Graph G; //LCAの外で持っておく

struct LCA
{
  vector<vector<int>> parent;
  vector<long long> dist;
  LCA(const Graph &G, int root)
  {
    init(G, root);
  }
  
  void init(const Graph &G, int root)
  {
    int n = G.size();
    int m = 1;
    while((1 << m) < n) m++;
    parent.assign(m, vector<int>(n, -1));
    dist.assign(n, -1);
    dfs(G, root, 0, -1);
    //ダブリング
    for(int i = 0; i < m-1; i++)
    {
      for(int j = 0; j < n; j++)
      {
        if(parent[i][j] < 0) parent[i][j] = -1;
        else parent[i+1][j] = parent[i][parent[i][j]];
      }
    }
  }
  
  void dfs(const Graph &G, int a, int pa, int dep)
  {
    parent[0][a] = pa;
    dist[a] = dep;
    for(auto e : G[a])
    {
      if(e.to != pa)
        dfs(G, e.to, a, dep+1);
    }
  }
  
  long long query(int u, int v)
  {
    int m = parent.size();
    
    //深さをu >= vとする
    if(dist[u] < dist[v]) swap(u, v);
    //深さを揃える
    for(int i = 0; i < m; i++)
    {
      if((dist[u] - dist[v]) & (1 << i))
      {
        u = parent[i][u];
      }
    }
    
    //ダブリング（二分探索）でLCAを求める
    if(u == v) return u;
    for(int i = m - 1; i >= 0; i--) //大きい桁から見ていく
    {
      if(parent[i][u] != parent[i][v])
      {
        u = parent[i][u];
        v = parent[i][v];
      }
    }
    return parent[0][u];
  }
};

void init()
{
  cin >> n;
  G.assign(n, vector<Edge>(0));
  rep(i, n)
  {
    int k;
    cin >> k;
    rep(j,k)
    {
      ll c;
      cin >> c;
      Edge e;
      e.to = c;
      G[i].emplace_back(e);
    }
  }
}

void solve()
{
  LCA lca(G, 0);
  cin >> q;
  rep(i, q)
  {
    int a, b;
    cin >> a >> b;
    cout << lca.query(a, b) << "\n";
  }
  //rep(i,n){ for(auto e : G[i]) cout << e.to << " "; cout << endl;}
  return;
}

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


Measured memory_bytes: 19700
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

typedef long long LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = N; i >= 0; i--)

template<typename Container>
bool include(const Container& c, const typename Container::value_type& v) {
  return ( c.end() != std::find(c.begin(),c.end(),v) );
}

template<class T>
vector<T> unique_vec(const vector<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}

int main() {
  int N;
  cin >> N;
  if (N % 1000 == 0) {
    cout << 0 << endl;
    return 0;
  }

  while(N > 1000) {
    N = N % 1000;
  }
  cout << 1000 - N << endl;

  return 0;
}


Measured memory_bytes: 3632
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,x=INTM()
    if a>=1:
        cta=(a-1)//x+1
    else:
        cta=0
    ctb=b//x+1
    print(ctb-cta)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define li long long
li a,b,c,d,ans;
int main(){
	int i,j,t;
	cin>>t;
	while(t--){
		cin>>a>>b;
		c = a * b;
		d = sqrtl(c);
		while((d + 1) * (d + 1) <= c) ++d;
		while(d * d > c) --d;
		//cout<<c<<" "<<d<<endl;
		ans = d * 2 - 1;
		if(d * (d + 1) >= c) --ans;
		if(d * d == c && a != b) --ans;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<string> // for string class
#include <math.h> 
#include<bits/stdc++.h> 
using namespace std; 
int main() 
{
	int n,k;
 cin>>n>>k;
   int a[n];
   double e[n];
   double aa[n-k+1];
   int l=1;
   for(int i=0;i<n;i++)
   	{
   		cin>>a[i];
      e[i]=(a[i]+1)/2.0;
      
      if(i>=k)
      {
         aa[l]=aa[l-1]-e[l-1]+e[l+k-1];
         l++;
      }
      else 
      {
          aa[0]+=e[i];
      }
  }
 // sort(e,e+n);
  
  /* for(int i=0;i<k;i++)
   {
       aa[0]+=e[i];
   }
   for(int i=1;i<n-k+1;i++)
   {
       aa[i]=a[i-1]-e[i-1]+e[i+k-1];
   }*/
   /*for(int i=0;i<n-k+1;i++)
   { 
   	aa[i]=0.0;
   	for(int j=0;j<k;j++)
   		aa[i]=e[i+j]+aa[i];

   }*/

   sort(aa,aa+n-k+1);
  // double sum =0;
   //for(int i=0;i<k;i++)
   //{
     //  sum+=e[n-i-1];
   //}
 printf("%.8lf",aa[n-k]);


 return 0;

}


Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int a[1000];
int cnt[1000];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
	int mx = 0, mn = 100000;
	for (int i = 0; i < n; i++) mn = min(mn, a[i]), mx = max(mx, a[i]);
	if (mx % 2 == 0)
	{
		if (cnt[mn] != 1) {
			cout << "Impossible";
			return 0;
		}
		for (int i = mx; i > mn; i--) if (cnt[i] < 2) {
			cout << "Impossible";
			return 0;
		}
		cout << "Possible";
		return 0;
	}
	else
	{
		if (cnt[mn] != 2) {
			cout << "Impossible";
			return 0;
		}
		for (int i = mx; i > mn; i--) if (cnt[i] < 2) {
			cout << "Impossible";
			return 0;
		}
		cout << "Possible";
		return 0;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

void ini(long *x, int n);
void scan(long *x, int n);
void print(long *x, int a, int b);

int main(void){

  int n, m, l, i, j, k;
  long *a, *b, *c;

  scanf("%d %d %d", &n, &m, &l);

  a = (long *)malloc(sizeof(long)*n*m);
  b = (long *)malloc(sizeof(long)*m*l);
  c = (long *)malloc(sizeof(long)*n*l);

  //ini
  ini(a, n*m);
  ini(b, m*l);
  ini(c, n*l);

  scan(a, n*m);
  scan(b, m*l);

  //cal
  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      for(k=0;k<m;k++){
        c[i*l+j] += a[i*m+k] * b[k*l+j];
      }
    }
  }

  print(c, n, l);

  free(a);
  free(b);
  free(c);
  return 0;
}

void ini(long *x, int n){
  long i;
  for(i=0;i<n;i++){
    x[i] = 0;
  }
}

void scan(long *x, int n){
  long i;
  for(i=0;i<n;i++){
    scanf("%ld", &x[i]);
  }
}

void print(long *x, int a, int b){
  long i, j;
  for(i=0;i<a;i++){
    for(j=0;j<b;j++){
      printf("%ld", x[i*b+j]);
      if(j != b-1){
        printf(" ");
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2048
//shan61916
#include <bits/stdc++.h>
    using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull ;
typedef double dll ;
ll n; 
ll a[100020][3] ;
ll dp[100020][4] ;
ll recurse(ll idx, ll type) {
  if(idx == n) return  0;
  ll &ans = dp[idx][type];
  if(ans != -1) return ans;
   ans = 0;
  if(type == 0) {
    return ans = max({a[idx][0] + recurse(idx+1, 1), a[idx][1] + recurse(idx+1, 2), a[idx][2] + recurse(idx+1, 3)});
  }
  if(type == 1) {
    return ans = max({a[idx][1] + recurse(idx+1, 2), a[idx][2] + recurse(idx+1, 3)});
  }
  if(type == 2) {
    return ans = max({a[idx][0] + recurse(idx+1, 1), a[idx][2] + recurse(idx+1, 3)}) ;
  }
  else {
    return ans = max({a[idx][0] + recurse(idx+1, 1), a[idx][1] + recurse(idx+1, 2)}) ;
  }
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for(ll i = 0; i < n; i++) {
    for(ll j = 0; j < 3; j++) cin >> a[i][j];
  }
  ll ans = recurse(0, 0) ;
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 10368