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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  
  map<int, int> X, Y;
  for (int i = 0; i < N; i += 2) {
    if (X.count(V.at(i))) X.at(V.at(i)) += 1;
    else X[V.at(i)] = 1;
  }
  for (int i = 1; i < N; i += 2) {
    if (Y.count(V.at(i))) Y.at(V.at(i)) += 1;
    else Y[V.at(i)] = 1;
  }
  
  int X1 = 0, x1 = 0, X2 = 0, x2 = 0, Y1 = 0, y1 = 0, Y2 = 0, y2 = 0;
  if (X.size() == 1) {
    X1 = V.at(0);
    x1 = X.at(V.at(0));
    X2 = -1;
    x2 = -1;
  }
  else {
    for (auto p : X) {
      if (p.second > x1) {
        x1 = p.second;
        X1 = p.first;
      }
    }
    for (auto p : X) {
      if (p.first != X1 && p.second > x2) {
        x2 = p.second;
        X2 = p.first;
      }
    }
  }
  if (Y.size() == 1) {
    Y1 = V.at(1);
    y1 = Y.at(V.at(1));
    Y2 = -1;
    y2 = -1;
  }
  else {
    for (auto p : Y) {
      if (p.second > y1) {
        y1 = p.second;
        Y1 = p.first;
      }
    }
    for (auto p : Y) {
      if (p.first != Y1 && p.second > y2) {
        y2 = p.second;
        Y2 = p.first;
      }
    }
  }
  
  if (X2 == -1 && Y2 == -1) {
    if (X1 == Y1) cout << N / 2 << endl;
    else cout << 0 << endl;
  }
  else if (X2 == -1) {
    if (Y1 == X1) cout << N / 2 - y2 << endl;
    else cout << N / 2 - y1 << endl;
  }
  else if (Y2 == -1) {
    if (X1 == Y1) cout << N / 2 - x2 << endl;
    else cout << N / 2 - x1 << endl;
  }
  else {
    if (X1 != Y1) cout << N - x1 - y1 << endl;
    else if (x1 > y1) cout << N - x1 - y2 << endl;
    else if (y1 > x1) cout << N - y1 - x2 << endl;
    else {
      if (x2 > y2) cout << N - x2 - y1 << endl;
      else cout << N - y2 - x1 << endl;
    }
  }   
}

Measured memory_bytes: 5376
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

const int MAX = 510000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}


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

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

  COMinit();

  //cout << COM(n-k+1,1) << endl;
  FOR(i,0,k){
    //Red: n-k, Blue:k
    ll val = COM(n-k+1,i+1) * COM(k-1,i);

    //ll val = COM(restRed+restBlue+1, 1) * (ll)pow(restRed, i*2+1) %MOD;
    //val *= pow(restBlue, i);
    //val %= MOD;
    cout << val%MOD << endl;
  }

  return 0;
}

Measured memory_bytes: 12160
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<map>
#include<ctime>
#define debuglog(x) cerr<<"\tdebug:"<<#x<<endl
#define debug(x) cerr<<"\tdebug:"<<#x<<"="<<(x)<<endl
#define debugg(x,y) cerr<<"\tdebug;"<<(x)<<":"<<#y<<"="<<(y)<<endl
#define debugzu(x,a,b) 	cerr<<"\tdebug:"<<#x<<"=\n\t";for(int i=a;i<b;i++)cerr<<x[i]<<" ";fprintf(stderr,"\n");
#define debugerzu(x,a,b,c,d) 	cerr<<"\tdebug:"<<#x<<"=\n\t";for(int i=a;i<b;i++,fprintf(stderr,"\n\t"))for(int j=c;j<d;j++)cerr<<x[i][j]<<" ";fprintf(stderr,"\n");
#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned
#define START clock_t __start=clock();
#define STOP fprintf(stderr,"\n\nUse Time:%fs\n",((double)(clock()-__start)/CLOCKS_PER_SEC));
using namespace std;
I LL read()
{
	R LL x;R bool f;R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c-'0'; (c=getchar())>='0'&&c<='9'; x=(x<<3)+(x<<1)+c-'0');
	return f?-x:x;
}
#define MAXN 200011
int a[200000+3], n;
bool small(int i, int j, int k) {return a[i]<=k && a[j]<=k;}
bool big(int i, int j, int k) {return a[i]>k && a[j]>k;}
bool judge(int k)
{
	for(int i=0;i<n-1;i++)
	{
		if((a[n+i]>k&&a[n+i+1]>k)||(a[n-i]>k&&a[n-i-1]>k))
			return false;
		if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))
			return true;
	}
	return a[1]<=k&&a[1]<=k;;
}



int main()
{
// 	freopen("agc006_d.in","r",stdin);
// 	freopen("agc006_d.out","w",stdout);
	n=read();
	for(int i=1;i<n<<1;a[i++]=read());
	int l=1,r=(n<<1)-1,mid;
	while(l<r)
	{
		mid=l+r>>1;
		if(judge(mid))
			r=mid;
		else
			l=mid+1;
	}
	printf("%d\n",r);
	fclose(stdin);
	fclose(stdout);
 	return 0;
}

Measured memory_bytes: 1024
dtotal = [31,29,31,30,31,30,31,31,30,31,30,31]

x = gets
y = x.split()
month = y[0].to_i
day = y[1].to_i
until month == 0
indexmonth = month - 1
s = 0
t = 0
if indexmonth == 0
 t = day % 7
else
 i = 0
 while i < indexmonth
  s += dtotal[i]
  i += 1
 end
 tt = s + day
 t = tt % 7
end

whatday = ["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"]


puts whatday[t]

x = gets
y = x.split()
month = y[0].to_i
day = y[1].to_i
end


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

int main() {
    int N, C; cin >> N >> C;
    int D[C][C];
    int c[N][N];
    rep(i, C){
        rep(j, C){
            cin >> D[i][j];
        }
    }
    rep(i, N){
        rep(j, N){
            cin >> c[i][j];
        }
    }

    vector<int> iwa0(C);
    vector<int> iwa1(C);
    vector<int> iwa2(C);
    rep(k, C){
        rep(i, N){
            rep(j, N){
                int x = (i+j) % 3;
                if(x == 0){
                    iwa0[k] += D[c[i][j]-1][k];
                } else if(x == 1){
                    iwa1[k] += D[c[i][j]-1][k];
                } else {
                    iwa2[k] += D[c[i][j]-1][k];
                }
            }
        }
    }

    ll ans = 1001001001;
    rep(i, C){
        rep(j, C){
            if(j == i)continue;
            rep(k, C){
                if(k == i || k == j)continue;
                ll now = iwa0[i] + iwa1[j] + iwa2[k];
                ans = min(ans, now);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4600
use std::collections::BinaryHeap;

fn main() {
  let nm = read_vec::<u32>();
  let n = nm[0];
  let m = nm[1];
  let mut inputs: Vec<Vec<u32>> = Vec::new();
  for _ in 0..n {
    let ab = read_vec::<u32>();
    if ab[0] <= m {
      inputs.push(ab);
    }
  }
  inputs.sort_by(|a, b| a[0].cmp(&b[0]));

  let mut sum = 0;
  let mut i: usize = 0;
  let mut availables = BinaryHeap::new();
  for j in 0..(m + 1) {
    while i < inputs.len() && inputs[i][0] <= j {
      availables.push(inputs[i][1]);
      i += 1;
    }

    if let Some(a) = availables.pop() {
      sum += a;
    }
  }

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

fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>()
    .split_whitespace()
    .map(|e| e.parse().ok().unwrap())
    .collect()
}

Measured memory_bytes: 10104
//写一个将二维数组传入函数的函数
#include<stdio.h>
long long h,time;
int main(void)
{
    scanf("%lld",&h);
    long long time=0;
    while(h/2!=0){
        time++;
        h/=2;
    }
    long long sum=1;
    for(int i=1;i<=time;i++)
        sum*=2;
    sum=sum+sum-1;
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[100];
int M;
int P[100];
int X[100];
int main(){
  int i, res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  rd(M);
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<(M);KL2GvlyY++){
      rd(P[KL2GvlyY]);P[KL2GvlyY] += (-1);
      rd(X[KL2GvlyY]);
    }
  }
  {
    int Q5VJL1cS, e98WHCEY;
    if(N==0){
      e98WHCEY = 0;
    }
    else{
      e98WHCEY = A[0];
      for(Q5VJL1cS=(1);Q5VJL1cS<(N);Q5VJL1cS++){
        e98WHCEY += A[Q5VJL1cS];
      }
    }
    res =e98WHCEY;
  }
  for(i=0;i<(M);i++){
    wt_L(res + X[i] - A[P[i]]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N, A[100], M, P[100], X[100];
// {
//   int res;
//   rd(N,A(N),M,(P--,X)(M));
//   res = sum(A(N));
//   rep(i,M) wt(res + X[i] - A[P[i]]);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main(){
    IOS;
    in n,a,b;
    cin >> n >> a >> b;
    cout << (n/(a+b))*a+min(a,n%(a+b));
}

Measured memory_bytes: 256
# 20200612_yorukatsu_a.py
N, A, B = map(int,input().split())
ans = 0
for i in range(N+1):
    tmp = str(i)
    _sum = 0
    for j in tmp:
        c=int(j)
        _sum+=c
    if _sum >=A and _sum <=B:
        ans += i
print(ans)

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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> T>>p;
	if (T[0] == 'H') {
		a = 1;
	}
	else {
		a = -1;
	}
	if (p[0] == 'H') {
		b = 1;
	}
	else {
		b = -1;
	}
	ans = a * b;
	if (ans > 0) {
		cout << "H";
	}
	else {
		cout << "D";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int N;
  cin >> N;
  cout << "ABC" << N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a > b) {
    cout << 0 << endl;
  }
  else if(b / a < c) {
    cout << b / a << endl;
  }
  else cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

main()
{
	char s[3];
	
	for(int i=0;i<3;i++)
	{
		scanf("%c",&s[i]);
	}
	
	if(s[1]=='B')
	{
		printf("ARC");
	}
	else
	{
		printf("ABC");
	}

}




Measured memory_bytes: 1592
n = gets.to_i
a = gets.split.map(&:to_i)

xx2 = 0
for i in 0...n
    if i%2 == 0
        xx2 += a[i]
    else
        xx2 -= a[i]
    end
end

x2 = Array.new(n)
x2[0] = xx2
for i in 1...n
    x = a[i-1] - (x2[i-1] / 2)
    x2[i] = x * 2
end

puts x2.join(" ")



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

int main() {
  int N;
  cin >> N;
  vector<unsigned long long > data(N+1);

    data[0]=2;
    data[1]=1;
  for( int i = 2; i <= N; i++){
      data[i]=data[i-2]+data[i-1];
  }
  cout << data[N]<<endl;


}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

class Main
{

    public static void main(String args[])throws IOException
    {
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	String s = in.readLine();
	int[] alpha = new int[30];
	for(int i=0;i<30;i++)
	    alpha[i] = 0;
	for(int i=0;i<s.length();i++)
	    alpha[s.charAt(i)-'a']++;
	int cnt = 0;
	for(int i=0;i<27;i++)
	    {
		if(alpha[i]%2 == 1)
		    cnt++;
		if(cnt >= 2)
		    break;
	    }

	if(cnt >= 2)
	    {
		System.out.println("0");
	    }
	else
	    {
		int n = 0;
		int[] counter = new int[28];
		int index = 0;
		for(int i=0;i<28;i++)
		    {
			if(alpha[i] == 0)
			    continue;
			if(alpha[i]%2==1)
			    alpha[i]--;
			counter[index++] = alpha[i]/2;
			n += alpha[i]/2;
			counter[index] = -1;
		    }

		BigInteger N = new BigInteger("1");
		BigInteger abc = new BigInteger("1"); 

		for(int i=2;i<=n;i++)
		    N = N.multiply(new BigInteger(Integer.toString(i)));

		//System.out.println("N = " + N);
		for(int i=0;i<28;i++)
		    {
			if(counter[i] == -1)
			    break;
			for(int j=2;j<=counter[i];j++)
			    {
				abc = abc.multiply(new BigInteger(Integer.toString(j)));
			    }
		    }
		//System.out.println("abc = " + abc);
		System.out.println(N.divide(abc));


	    }

    }

}

Measured memory_bytes: 17108
z=['SAT','SUN','MON','TUE','WED','THU','FRI']
x=['Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday']
b=['tomorrow','two','three','four','five','six','seven']
c=input()
v=z.index('SUN')-z.index(c)
if v <0:
    v=7+v
elif v==0:
     v=7 
print(v)  

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
// 木の根を求める
int u[51];
int o[51];
int root(int s){
  while(o[s]>=0)
    s=o[s];
  return u[s];
}

// xとyの属する集合を併合
void merge(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y) return;
  o[x]+=o[y];
  o[y]=x;
}
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int> >pii;
  int ans=0;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    pii.pb(mp(a,b));
  }
  for(int i=0;i<m;i++){
    for(int j=1;j<=n;j++){
      u[j]=j;
      o[j]=-1;
    }
    for(int j=0;j<m;j++){
      if(i!=j){
	merge(pii[j].first,pii[j].second);
	//cout<<pii[j].first<<" "<<pii[j].second<<endl;
      }
    }
    int cn=0;
    for(int j=1;j<=n;j++){
      if(o[j]<0){
	cn++;
	if(cn==2){
	  ans++;
	  break;
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
#define pb push_back
#define int long long
int n,m,check=0,c[100005],num[2];
vector<int> graph[100005];
bool vis[100005];
void dfs(int u,int color){
    num[color]++;
    vis[u]=1;
    for(int i=0;i<graph[u].size();i++){
        int v=graph[u][i];
        if(vis[v]==0){
            c[v]=1-color;
            dfs(v,1-color);
        }
    }
}
signed main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin>>n>>m;
    int u,v;
    for(int i=1;i<=m;i++){
        cin>>u>>v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    c[1]=0;
    dfs(1,0);
    for(int i=1;i<=n;i++){
        for(int j=0;j<graph[i].size();j++){
            int v=graph[i][j];
            if(c[v]==c[i])
                check=1;
        }
    }
    if(check==1)
        cout<<n*(n-1)/2-m;
    else
        cout<<num[0]*num[1]-m;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  1000000007;
int sz[200001],zen[200001],c[200001],ans[200001];bool used[200001];
vector<int> hen[200001];
int dfssz(int a){
     
     sz[a]=1;
     for(auto&& i : hen[a])if(!sz[i])sz[a]+=dfssz(i);
     
     return sz[a];
}
void dfs(int a){
     used[a]=true;
     ans[c[a]]+=1+zen[c[a]]*(zen[c[a]]-1)/2;
     zen[c[a]]-=sz[a];
     ans[c[a]]-=(zen[c[a]]-1)*zen[c[a]]/2;
     int tmp=zen[c[a]];
     for(auto&& i : hen[a])if(!used[i]){
          
          ans[c[a]]-=sz[i]*(sz[i]-1)/2;
          zen[c[a]]=sz[i];
          dfs(i);
     }
     zen[c[a]]=tmp;
     return;
}

     signed main(){
       int n;
       cin>>n;
      for(int i=1;i<=n;i++){
           cin>>c[i];
      }
      int a,b;
      for(int i=0;i<n-1;i++){
           cin>>a>>b;
           hen[a].push_back(b);
           hen[b].push_back(a);
      }
      fill(ans,ans+n+1,0);
      fill(sz,sz+n+1,0);
      fill(zen,zen+n+1,n);
      dfssz(1);
       fill(used,used+n+1,false);
      dfs(1);
      for(int i=1;i<=n;i++)cout<<ans[i]<<endl;

      }

        


Measured memory_bytes: 36584
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

K = int(input())
X,Y = map(int,input().split())

if (X+Y) % 2 != 0 and K % 2 == 0:
    print(-1)
    exit()

def strategy(x,y,K):
    if x < 0:
        dx, dy = strategy(-x,y,K)
        return -dx, dy
    if y < 0:
        dx, dy = strategy(x,-y,K)
        return dx,-dy
    if x > y:
        dx, dy = strategy(y,x,K)
        return dy, dx
    # 0 <= x <= y としてよい
    L = x + y
    if L > 2 * K:
        dx = min(x,K)
        dy = K - dx
        return dx,dy
    # 距離2K以下。3回以内に仕留める
    if L == K:
        return x,y
    if (x+y) % 2 == 0:
        # 2回で仕留める
        # 0 <= x < y が分かっている
        t = (y - x) // 2
        dx,dy = K-t, t
        return dx,dy
    # 3回で仕留める
    # とりあえず離れないようにすればよい
    dx = min(K,x)
    dy = K - dx
    return dx,dy


x,y = 0,0
answer = []
while x != X or y != Y:
    dx,dy = strategy(X-x, Y-y, K)
    x += dx
    y += dy
    answer.append((x,y))

print(len(answer))
for x,y in answer:
    print(x,y)

Measured memory_bytes: 29248
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;

int mx = 0;

int abs(int a){
    if(a < 0) a *= -1;
    return a;
}

void solve(int A[], int k){
    if(k==0) return;
    for(int i=0; i<k; i++){
        if(abs(A[k]-A[i]) > mx) mx = abs(A[k]-A[i]);
    }
    return;
}

int main(){
    int N;
    cin >> N;
    int *A = new int[N];
    //dp = new int[N];
    //for(int i=0; i<N; i++) dp[i] = 0;
    for(int i=0; i<N; i++){
        //dp[i] = 0;
        cin >> A[i];
        solve(A, i);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL val[100005];
int s1[100005],s2[100005];
int is[100005];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&s1[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&s2[i]);
    }
    int flag=1;
    for(int i=1;i<=n;i++){
        if(s1[i]>s1[i-1]){
            if(s1[i]>s2[i]) flag=0;
            is[i]++;
        }
    }
    for(int i=n;i>0;i--){
        if(s2[i]>s2[i+1]){
            if(s1[i]<s2[i]) flag=0;
            is[i]++;
        }
    }
    LL ans=1;
    for(int i=1;i<=n;i++){
        if(is[i]) continue;
        ans=ans*min(s1[i],s2[i])%1000000007;
    }
    printf("%lld\n",ans*flag);
}


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

int h, r;

int sgn(int n) {
  return (n > 0) - (n < 0);
}

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

  cin >> h >> r; cout << sgn(h + r) << "\n";
}


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

int selectionSort(int array[],int arraySize);

int main() {
    int arraySize=0;
    scanf("%d",&arraySize);
    int*array = (int*)malloc(sizeof(int)*arraySize);

    for(int i=0;i<arraySize;i++)
    {
        scanf("%d",&array[i]);
    }
    //ソート
    int counter = selectionSort(array,arraySize);

    for(int i=0;i<arraySize;i++)
    {
        printf("%d",array[i]);
        if(i!=arraySize-1)printf(" ");
    }
    printf("\n%d\n",counter);
    return 0;
}

int selectionSort(int array[],int arraySize)
{
    int minPlace=0;
    int flag=0;
    int counter=0;
    //配列の初めから終わりまで精査する
    for(int i=0;i<arraySize;i++)
    {
        flag=0;
        minPlace=i;
        //i番目の精査では、後ろの(arraySize-i)個の配列の要素をチェックする
        for (int j=i+1;j<arraySize;j++)
        {
            //ifの方が高速(らしい)
            //min=array[j]<min?array[j]:min;
            if(array[minPlace]>array[j]) {
                flag++;
                minPlace = j;
            }
        }
        if(flag>0)
        {
            flag=array[i];
            array[i] = array[minPlace];
            array[minPlace]=flag;
            counter++;
        }
    }
    return counter;
}



Measured memory_bytes: 2044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int[][] a = new int[3][3];
        for (int i = 0 ; i < 3 ; i++) {
            for (int j = 0 ; j < 3 ; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int n = sc.nextInt();
        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = sc.nextInt();
        }
        int[][] c = new int[3][3];
        for (int k = 0 ; k < n ; k++) {
            for (int i = 0 ; i < 3 ; i++) {
                for (int j = 0 ; j < 3 ; j++) {
                    if (a[i][j] == b[k]) {
                        c[i][j] = 1;
                    }
                }
            }
        }
        boolean flg = false;
        for (int i = 0 ; i < 3 ; i++) {
            if (c[i][0] + c[i][1] + c[i][2] == 3) flg = true;
        }
        for (int i = 0 ; i < 3 ; i++) {
            if (c[0][i] + c[1][i] + c[2][i] == 3) flg = true;
        }
        if (c[0][0] + c[1][1] + c[2][2] == 3) {
            flg = true;
        }
        if (c[2][0] + c[1][1] + c[0][2] == 3) {
            flg = true;
        }

        System.out.println(flg ? "Yes" : "No");
    }

}

Measured memory_bytes: 21716
#include <stdio.h>
 int main(void)
{
int a, b, c;
 scanf("%d%d%d", &a, &b, &c);
 int ispoor = 0;
 if (a == b && b != c) ispoor = 1;
 if (b == c && c != a) ispoor = 1;
 if (c == a && a != b) ispoor = 1;
 if (ispoor) {
 puts("Yes");
 } else {
 puts("No");
 }
 return 0;
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n;
	cin >> n;
	int f[n][5][2];
	int p[n][11];
	rep(i,n)rep(j,5)rep(k,2) cin >> f[i][j][k];
	rep(i,n)rep(j,11) cin >> p[i][j];
	int ans = -INF-1;
	for(int bit = 1; bit < (1 << 10); bit++){
		int tmp = 0;
		vector<int> work(10, 0);
		for(int i = 0; i < 10; i++){
			if(1&bit>>i) work[i] = 1;
		}
		for(int i = 0; i < n; i++){
			int co = 0;
			for(int j = 0; j < 10; j++){
				if(work[j]&&f[i][j/2][j%2])  co++;
			}
			tmp += p[i][co];
		}
		chmax(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double eps=1e-9;
double x[110];
double y[110];
double r[110];
double th[110];
double v[110];
double d[110];
int in[110];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		int ret=0;
		for(int i=0;i<b;i++)in[i]=0;
		int rem=b;
		for(int i=0;i<b;i++){
			scanf("%lf%lf%lf%lf",x+i,y+i,r+i,v+i);
			th[i]=atan2(y[i],x[i]);
			d[i]=sqrt(x[i]*x[i]+y[i]*y[i]);
			if(x[i]*x[i]+y[i]*y[i]<eps+a*a){
				in[i]=1;
				ret++;
				rem--;
			}
		}
		while(rem){
			double val=999999999;
			int at=-1;
			for(int i=0;i<b;i++){
				if(in[i])continue;
				d[i]-=v[i];
				if(d[i]<eps+a){
					in[i]=1;
					ret++;
					rem--;
				}else if(val>d[i]){
					val=d[i];at=i;
				}
			}
			if(!~at)break;
			for(int i=0;i<b;i++){
				if(in[i])continue;
				double X=d[i]*cos(th[i]);
				double Y=d[i]*sin(th[i]);
				if(x[i]*x[at]+y[i]*y[at]<0){
					double xv=cos(th[at])*a;
					double yv=sin(th[at])*a;
					if(sqrt((X-xv)*(X-xv)+(Y-yv)*(Y-yv))<r[i]+eps){
						in[i]=1;rem--;
					}
					continue;
				}
				double d2=(y[at]*X-x[at]*Y)*(y[at]*X-x[at]*Y)/(x[at]*x[at]+y[at]*y[at]);
				if(d2<r[i]*r[i]+eps){
					in[i]=1;
					rem--;
				}
			}
		}
		printf("%d\n",ret);
	}
	
}

Measured memory_bytes: 1144
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,Q;
int A[3010],X[3010],Y[3010];
ll dp[3010][3010][2];
ll modpow(int m){
  ll res=1;
  rep(i,m){
    res=(res*2)%MOD;
  }  
  return res;
}
int Extgcd(int a,int b,int &x,int &y){
  int d=a;
  if(b!=0){
    Extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }
  else{
    x=1;y=0;
  }
  return d;
}

int Invmod(int a,int p){//mod pでのaの逆元を求める
  int x,y;
  Extgcd(a,p,x,y);
  return (x%p+p)%p;
}
void solve(){
  rep(i,N){
    rep(j,N){
      if(A[i]<=A[j]){
	dp[i][j][0]=0;
      }
      else dp[i][j][0]=1;
    }
  }
  rep(i,Q){
    int x=X[i],y=Y[i];
    rep(j,N){
      if(j!=y&&x!=j) dp[x][j][1]=(Invmod(2,MOD)*((dp[x][j][0]+dp[y][j][0])%MOD))%MOD;
    }
    rep(j,N){
      if(j!=y&&x!=j) dp[j][x][1]=(Invmod(2,MOD)*((dp[j][x][0]+dp[j][y][0])%MOD))%MOD;
    }
    rep(j,N){
      if(j!=x&&y!=j) dp[y][j][1]=(Invmod(2,MOD)*((dp[x][j][0]+dp[y][j][0])%MOD))%MOD;
    }
    rep(j,N){
      if(j!=x&&y!=j) dp[j][y][1]=(Invmod(2,MOD)*((dp[j][x][0]+dp[j][y][0])%MOD))%MOD;
    }
    dp[x][y][1]=(Invmod(2,MOD)*((dp[x][y][0]+dp[y][x][0])%MOD))%MOD;
    dp[y][x][1]=(Invmod(2,MOD)*((dp[x][y][0]+dp[y][x][0])%MOD))%MOD;
    rep(j,N){
      if(j!=y&&x!=j) dp[x][j][0]=dp[x][j][1];
    }
    rep(j,N){
      if(j!=y&&x!=j) dp[j][x][0]=dp[j][x][1];
    }
    rep(j,N){
      if(j!=x&&y!=j) dp[y][j][0]=dp[y][j][1];
    }
    rep(j,N){
      if(j!=x&&y!=j) dp[j][y][0]=dp[j][y][1];
    }
    dp[x][y][0]=dp[x][y][1];
    dp[y][x][0]=dp[y][x][1];


    /*  rep(a,N){
      rep(b,N){
	std::cout<<dp[a][b][0]<<" ";
      }
      std::cout<<"\n";
      }*/
  }
  ll res=0;
  ll q=modpow(Q);
  rep(i,N){
    for(int j=i+1;j<N;j++){
      res=(res+(q*dp[i][j][0])%MOD)%MOD;
    }
  }

  prin(res);
}


int main(){
  cin>>N>>Q;
  rep(i,N) cin>>A[i];
  rep(i,Q){
    cin>>X[i]>>Y[i];
    X[i]--;Y[i]--;
  }
  solve();
  
  return 0;
}


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

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(v,a,b) for(int v=(a); v<=(b); v++)
#define fr(v,a,b) for(int v=(a); v>=(b); v--)
#define rng(v,a,b) for(int v=(a); v<(b); v++)

using namespace std;
typedef long long ll;
template<typename T> T& chmax(T& a, T b) { a = a > b ? a : b; return a;}
template<typename T> T& chmin(T& a, T b) { a = a < b ? a : b; return a;}
const int maxn=2e5+5;
int a[maxn],l[maxn],r[maxn];
int main()
{
	boost;
	int n; cin >> n;
	fo(i,1,n) cin >> a[i];
	fo(i,1,n) {
		chmax(l[i], max(l[i-1],a[i]));
	}
	fr(i,n,1) {
		chmax(r[i], max(r[i+1],a[i]));
	}
	fo(i,1,n) {
		cout << max(l[i-1],r[i+1]) << '\n';
	}
	return 0;
}


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

int main() {
	ll n;
	cin >> n;
	map<string, ll> m;
	for (ll i = 0; i < n; ++i) {
		string s;
		cin >> s;
		++m[s];
	}
	ll Max = 0;
	for (auto p : m) {
		Max = max(Max, p.second);
	}
	vector<string> ans;
	for (auto p : m) {
		if (p.second == Max) {
			ans.push_back(p.first);
		}
	}
	sort(ans.begin(), ans.end());
	for (string x : ans) {
		cout << x << endl;
	}
}

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

int main() {
  while(true){
    int h,w;cin>>h>>w;
    if(h==0&&w==0)break;
    rep(i,h){
      rep(j,w){
        cout<<"#";
        if(w-j==1){
          cout<<endl;
        }
      }
    }
    cout<<endl;
  }
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug cout<<"Reached\n";

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s,t;

    cin>>s>>t;
    
    li n=s.length(),n2=t.length();

    if(n2==n+1 && t.substr(0,n)==s)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    
    map<int, int> cnt;
    while(n--){
        int key;
        scanf("%d", &key);
        cnt[key]++;
    }
    
    queue<int> sorted;
    map<int, int>::iterator it = cnt.begin();
    do{
        while((*it).second--){
            sorted.push((*it).first);
        }
    }while(++it != cnt.end());
    
    while(sorted.size()){
        printf("%d%c", sorted.front(), sorted.size() == 1 ? '\n' : ' ');
        sorted.pop();
    }
    return 0;
}

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

using namespace std;

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

int main() {
	int n;
	db a;
	cin >> n;
	vector<db> v(n);
	REP(i, n) {
		cin >> v[i];
	}
	REP(i,n-1){
	sort(v.begin(),v.end());
	
		a=(v[0]+v[1])/2;
      	v[1]=1001;
		v[0]=a;
	}
	cout << v[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

ll n;
ll a[220000];
ll k;
map<ll, ll> mp;//何回目に訪れたか
ll cnt = 0;
ll pre = 1;
ll p[220000];//n回目に訪れた場所

int main(){
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  ll t;
  while(true){
    if(mp[pre] > 0 || (pre == 1 && cnt > 0)){
      t = cnt - mp[pre];
      break;
    }
    p[cnt] = pre;
    mp[pre] = cnt;
    cnt++;
    pre = a[pre-1];
  }
  if(k > mp[pre]){
    ll u = k - mp[pre];
    cout << p[(k-mp[pre])%t+mp[pre]] <<endl;
  }else{
    cout << p[k] <<endl;
  }
  
  
}



Measured memory_bytes: 19088
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Node {
  int parent = -1;
  int left_child = -1;
  int right_child = -1;
};
map<int, Node> nodes;
int n;

void set_parent() {
  for (map<int, Node>::iterator it = nodes.begin(), end = nodes.end();
       it != end; ++it) {
    int parent_number = it->first;
    Node parent_node = it->second;
    if (parent_node.left_child != -1) {
      nodes[parent_node.left_child].parent = parent_number;
    }
    if (parent_node.right_child != -1) {
      nodes[parent_node.right_child].parent = parent_number;
    }
  }
}

int get_root_number() {
  for (map<int, Node>::iterator it = nodes.begin(), end = nodes.end();
       it != end; ++it) {
    if (it->second.parent == -1) {
      return it->first;
    }
  }
  std::cout << "no root!!!" << '\n';
  return -1;
}

void preorder(int i) {
  if (nodes.at(i).left_child == -1 && nodes.at(i).right_child == -1) {
    std::cout << " " << i;
    return;
  }
  std::cout << " " << i;
  if (nodes.at(i).left_child != -1)
    preorder(nodes.at(i).left_child);
  if (nodes.at(i).right_child != -1)
    preorder(nodes.at(i).right_child);
}

void inorder(int i) {
  if (nodes.at(i).left_child == -1 && nodes.at(i).right_child == -1) {
    std::cout << " " << i;
    return;
  }
  if (nodes.at(i).left_child != -1)
    inorder(nodes.at(i).left_child);
  std::cout << " " << i;
  if (nodes.at(i).right_child != -1)
    inorder(nodes.at(i).right_child);
}

void postorder(int i) {
  if (nodes.at(i).left_child == -1 && nodes.at(i).right_child == -1) {
    std::cout << " " << i;
    return;
  }
  if (nodes.at(i).left_child != -1)
    postorder(nodes.at(i).left_child);
  if (nodes.at(i).right_child != -1)
    postorder(nodes.at(i).right_child);
  std::cout << " " << i;
}

int main() {
  cin >> n;
  rep(i, n) {
    int number;
    cin >> number;
    Node node;
    cin >> node.left_child;
    cin >> node.right_child;
    nodes[number] = node;
  }

  set_parent();
  int root = get_root_number();

  std::cout << "Preorder" << '\n';
  preorder(root);
  std::cout << '\n';
  std::cout << "Inorder" << '\n';
  inorder(root);
  std::cout << '\n';
  std::cout << "Postorder" << '\n';
  postorder(root);
  std::cout << '\n';
  //
  // for (map<int, Node>::iterator it = nodes.begin(), end = nodes.end();
  //      it != end; ++it) {
  //   std::cout << it->first << " ";
  // }
  // std::cout << '\n';

  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7

template <typename T>
string printVector(const vector<T> &data)
{
    stringstream ss;
    ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n;
    vector<int> a, b, c;

    for (int i = 0; i < n; ++i) {
        cin >> t;
        a.push_back(t);
    }

    for (int j = 0; j < n; ++j) {
        cin >> t;
        b.push_back(t);
    }

    for (int k = 0; k < n; ++k) {
        cin >> t;
        c.push_back(t);
    }
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    ll ans = 0;

    for (auto x : b) {
        ll left = lower_bound(ALL(a), x) - a.begin();
        ll right = n - (upper_bound(ALL(c), x) - c.begin());
        ans += left * right;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1784
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll N;
    cin >> N;
    while(N){
        ll ng = 0, ok = N;
        while(ng + 1 < ok){
            ll p = (ng + ok) / 2;
            if(p * (p + 1) / 2 < N)ng = p;
            else ok = p;
        }
        cout << ok << endl;
        N -= ok;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=505;
int n,a[N][N],i,j;
void solve(int l,int r,int d){
	if(l==r)return;
	int m=l+r>>1;
	for(i=l;i<=m;++i)for(j=m+1;j<=r;++j)a[i][j]=d;
	solve(l,m,d+1);solve(m+1,r,d+1);
}
int main(){
	scanf("%d",&n);
	solve(1,n,1);
	for(i=1;i<=n;++i,puts(""))for(j=i+1;j<=n;++j)printf("%d ",a[i][j]);
}

Measured memory_bytes: 1536
program kadai
integer  ::  N
integer,allocatable  ::  X(:)
integer  ::  i
integer  ::  a
integer  ::  ans1,ans2

read(*,*) N
allocate(X(N))
read(*,*) X

a=0
ans1=0
ans2=0
do i=1,N
    a=a+x(i)
end do


a=a/N
do i=1,N
    ans1=ans1+(x(i)-a)**2
    ans2=ans2+(x(i)-(a+1))**2
end do

write(*,*) min(ans1,ans2)
stop



end program kadai


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

using namespace std;

int main()
{
    ///{}
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int n,z,w;
    cin>>n>>z>>w;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    if(n==1){
        cout<<abs(v[0]-w);
        return 0;
    }
    vector<int>bdis(n);
    for(int i=0;i<n-2;i++){
        int mn=INT_MAX;
        mn=min(mn,abs(v[i+1]-v[n-1]));
        bdis[i]=mn;
    }
    bdis[n-2]=INT_MAX;
    int bst=INT_MAX;
    for(int i=n-3;i>=0;i--){
        bst=min(bst,bdis[i]);
        bdis[i]=bst;
    }
    for(int i=n-2;i>=0;i--){
        bdis[i]=min(bdis[i],abs(v[i]-v[n-1]));
    }
    int ans=abs(v[n-1]-w);
    for(int i=0;i<n-1;i++)
        ans=max(ans,bdis[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		
		long ans=0;
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		String s1 = sc.next();
		String s2 = sc.next();
		
		char c1Next = s1.charAt(0);
		char c2Next = s2.charAt(0);
		
		boolean yokoFlg = false;
		
		if(c1Next == c2Next){
			ans = 3;
		}
		else{
			ans = 6;
			yokoFlg = true;
		}
		
		for(int i=1; i<s1.length(); i++){
			
			if(yokoFlg == true){
				yokoFlg = false;
				continue;
			}
			
			char c1Pre = c1Next;
			char c2Pre = c2Next;
			
			c1Next = s1.charAt(i);
			c2Next = s2.charAt(i);
			
			//縦
			if(c1Pre == c2Pre){
				if(c1Next == c2Next){
					ans *= 2;
				}
				else{
					ans *= 2;
					i++;
				}
				
			}
			//横
			else{
				if(c1Next == c2Next){
					ans *= 1;
				}
				else{
					ans *= 3;
					i++;
				}
			}
			/*
			System.out.println("c1Pre:" + c1Pre);
			System.out.println("c2Pre:" + c2Pre);
			System.out.println("c1Next:" + c1Next);
			System.out.println("c2Next:" + c2Next);
			System.out.println("ans:"+ ans);
			*/
		}
		System.out.println(ans%1000000007);
	}

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    ll n;
    cin>>n;

    cout<<n+(n*n)+(n*n*n)<<endl;




    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>

int main(void){
  long int i,n,a,min,max,sum;
  scanf("%ld",&n);
  scanf("%ld",&a);
  sum=a;
  min=a;
  max=a;
  for(i=2;i<=n;i++){
      scanf("%ld",&a);
      sum=sum+a;
      if(a<min){
          min=a;
      }
      if(max<a){
          max=a;
      }
  }
  printf("%ld %ld %ld\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int N=307,mod=998244353,inv2=499122177,inv3=332748118;
int n,ans,sum,lim,pw2[N],pw3[N],a[N],f[N*N],g[N*N];
int main()
{
	scanf("%d",&n);
	ans=f[0]=g[0]=1;
	for(int i=1;i<=n;i++)f[0]=2ll*f[0]%mod;
	for(int i=1;i<=n;i++)
	{
		ans=3ll*ans%mod;
		scanf("%d",&a[i]);
		sum+=a[i];
		for(int j=sum;j>=a[i];j--)
		f[j]=(f[j]+1ll*f[j-a[i]]*inv2)%mod,g[j]=(g[j]+g[j-a[i]])%mod;
	}
	lim=(sum+1)/2;
	for(int i=lim;i<=sum;i++)ans=(ans-3ll*f[i]%mod+mod)%mod;
	if(sum%2==0)ans=(ans+3ll*g[lim])%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
int n,m;
map<int,int> mp[N];
int main()
{
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++)
			mp[i].clear();
		int u,v;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			mp[u][v]=mp[v][u]=1;
		}
		bool flag=false;
		for(int i=1;i<=n;i++)
		{
			if(mp[1][i]&&mp[i][n])
				flag=true;
		}
		if(flag)
			puts("POSSIBLE");
		else
			puts("IMPOSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 37760
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def SL(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    S = SL()
    cnt = 0
    for i in range(math.ceil(len(S)/2)):
        if S[i] != S[-i-1]:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 77316
n = int(input())
a = list(map(int, input().split()))
s = {}
for aa in a:
    if aa not in s.keys():
        s[aa] = 1
    else:
        s[aa] += 1
    
    if aa + 1 not in s.keys():
        s[aa+1] = 1
    else:
        s[aa+1] += 1
    
    if aa - 1 not in s.keys():
        s[aa-1] = 1
    else:
        s[aa-1] += 1

print(max(s.values()))

Measured memory_bytes: 18744
n=int(input())
H=[int(i) for i in input().split()]


cnt=0
ans=[]
for i in range(n-1):
    if H[i]>=H[i+1]:
        cnt+=1
        ans.append(cnt)
    else:
        cnt=0
        ans.append(cnt)

if ans:
  print(max(ans))

else:
  print(0)

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

int main() 
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int r,l;
    r = c + d;
    l = a + b;
    if(l > r)
    {
        cout << "Left" << endl;
    }
    else if(l == r)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
    
}


Measured memory_bytes: 3564
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N;
	cin >> N;
	cout << (N * (N - 1)) / 2 << endl;
	}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
typedef unsigned long long ULL;
const int nMax=2e5+1, MOD=998244353;
ULL inv[nMax], fct[nMax], ivf[nMax];
ULL Comb(int n, int r){ return (((fct[n]*ivf[r])%MOD)*ivf[n-r])%MOD; }
ULL pw(ULL a, ULL n){ ULL b=1; while(n){ if(n&1){ b=(b*a)%MOD; } a=(a*a)%MOD; n>>=1; } return b; }

int main(){
inv[1]=fct[0]=fct[1]=ivf[0]=ivf[1]=1;
for(int i=2; i<nMax; i++){ 
  inv[i]=((MOD-MOD/i)*inv[MOD%i])%MOD;
  fct[i]=(fct[i-1]*i)%MOD; ivf[i]=(ivf[i-1]*inv[i])%MOD;
}
int N, M, K; cin >> N >> M >> K; ULL ans=0;
REP(i, K+1){ 
 long x=(M*pw(M-1, N-i-1))%MOD;
 x=(x*Comb(N-1, i))%MOD; ans=(ans+x)%MOD;
}
cout << ans << "\n";
}

Measured memory_bytes: 8272
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <algorithm>

int main(int argc, char *argv[]){
    int N, K, Q;
    std::cin >> N >> K >> Q;
    std::vector<int> A(Q);
    for(auto &a : A){
        std::cin >> a;
        --a;
    }
    std::vector<int> score(N,K-Q);
    for(const auto &a : A){
        score[a] += 1;
    }
    for(const auto &s : score){
        if(s>0){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include<vector>
#include <utility>
#include <string>

using namespace std;

int main(){
  int n,a,b,c,i,j,k,x,ans=0,mi=10000;
  string s;
  cin >> n >> x;
  int m[n];
  for(i=0;i<n;i++){
    cin >> m[i];
    mi = min(mi,m[i]);
    x-=m[i];
    ans++;
  }
  ans+=x/mi;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    HashMap<String, Integer> hashMap = new HashMap<>();

    for (int i = 0; i < N; i++) {
      String s_ = sc.next();
      String[] s_array = s_.split("");
      Arrays.sort(s_array);
      String key = "";
      for (int j = 0; j < s_array.length; j++) {
        key += s_array[j];
      }
      if (hashMap.containsKey(key)) {
        int v_ = hashMap.get(key);
        hashMap.put(key, v_ + 1);
      } else {
        hashMap.put(key, 1);
      }
      
    }

    sc.close();

    long count = 0;

    for (Map.Entry<String, Integer> map : hashMap.entrySet()) {

      for (int i = 1; i <= map.getValue(); i++) {
        count += i - 1;
      }
    
    }

    System.out.println(count);

  }

}

Measured memory_bytes: 106712