akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int l, k;
    cin >> l >> k;

    lint dp[101][2];
    fill(dp[0], dp[l + 1], 0LL);
    dp[0][0] = 1;

    rep(i, l){
        rep(j, 2){
            dp[i + 1][j ^ 1] += dp[i][j];
            if(j == 0 && i + k <= l){
                dp[i + k][j ^ 1] += dp[i][j];
            }
        }
    }

    lint ans = 0;
    reps(i, l){
        ans += dp[i][1];
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>

char s[1024];

int main(){
	while(scanf("%s",s), s[0] != '0'){
		int n = 0;
		int i = 0;
		while(s[i] != 0){
			n += s[i] - '0';
			i++;
		}
		printf("%d\n",n);
	}
	return 0;
}



Measured memory_bytes: 2696
#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;

string s;
int main(){
  cin >> s;
  for(int i = 0; i < s.size(); i+=2){
    printf("%c%s", s.at(i), i == s.size()-1|| i == s.size() -2 ? "\n" : "");
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define s(x)	cin>>x
#define p(x)	cout<<x<<"\n"
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve() {
  int x;s(x);
  if(x>=30)
  cout<<"Yes\n";
  else
  cout<<"No\n";
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    //u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

set<string> st;

int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	int k;
	cin>>s>>k;
	int n = s.size();
	for(int i=0;i<n;i++)
	{
		string curr;
		for(int j=i;j<min(i+5,n);j++)
		{
			curr+=s[j];
			st.insert(curr);	
		}	
	}	
	int ct=0;
	for(auto i:st)
	{
		ct+=1;
		if(ct==k)
		{
			cout<<i;
			break;
		}
	}
}

Measured memory_bytes: 1664
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		while(true){
			if(x > y)System.out.println(y + " " + x);
			else System.out.println(x + " " + y);
			x = scan.nextInt();
			y = scan.nextInt();
			if(x == 0 && y == 0)break;
		}
	}
}

Measured memory_bytes: 35760
/* 
* ID: juryc
* PROG: Change a little bit
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 2*1e5+5;
typedef long long ll;
ll n; 
ll mod=1e9+7;
ll v[N]; 
ll modpow(ll a,ll b){
ll res=1;a%=mod;
while(b){
if(b&1){res=(res*a)%mod; }
a=(a*a)%mod;
b>>=1;
}
return res;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>v[i];
sort(v+1,v+1+n); 
ll ans=modpow(2,2*n-2),sum=0; 
for(ll i=1;i<=n;i++){
sum=(sum+((n-i+2)*v[i])%mod)%mod;
}
cout<<(ans*sum)%mod<<"\n"; 
return 0;
} 



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

int main() {
  int n,l;
  cin >> n >> l;
  
  int sum = 0;
  
  vector<int> azi(n);
  for (int i=0; i<n; i++){
    azi.at(i) = l+i;
    sum += azi.at(i);
  }
  
  int ans = azi.at(0);
  
  for (int i=1; i<n; i++){
    if (abs(azi.at(i-1)) > abs(azi.at(i))){
      ans = azi.at(i);
    }
    
  }
  
  
  cout << sum - ans << endl;
}


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

using namespace std;
using ll = long long;

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

	string t = "CODEFESTIVAL2016";
	int res = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != t[i]) { ++res; }
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;

        public static void Input()
        {
            var cin = new Solve();
            N = int.Parse(Console.ReadLine());
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int ans = 0;
            for(var i = 1; i <= Math.Sqrt(N); i++)
            {
                if (i * i <= N) { ans = i * i; }
                else { break; }
            }
            Console.WriteLine(ans);

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
}

    



Measured memory_bytes: 13140
#!/usr/bin/env pyton3

S = input()
lst = [c for c in S]

le = len(lst)

for i in range(0,le):
    if lst[i] == "A" or lst[i] == "C" or lst[i] == "G" or lst[i] == "T":
        lst[i] = 1
    else:
        lst[i] = 0

ans = 0
ans_sub = 0
for i in range(0,le):
    if lst[i] == 1:
        ans_sub += 1
        if ans_sub >= ans:
            ans = ans_sub
    else:
        if ans_sub >= ans:
            ans = ans_sub
        ans_sub = 0

        

print(ans)


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e3+23;

int h, w;
int ch, cw, dh, dw;
int s, e;
char m[N][N];
int bio[N][N];
int bio2[N*N];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int dx2[] = {-2, -2, -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2, -1, -1, 1, 1};
int dy2[] = {-2, -1, 0, 1, 2, -2, 2, -2, 2, -2, 2, -2, -1, 0, 1, 2, -1, 1, -1, 1};
set<int> g[N*N];

bool check(int x, int y) {
  return x >= 0 && x < h && y >= 0 && y < w;
}

void dfs(int x, int y, int c) {
  bio[x][y] = c;
  if (x == ch && y == cw) s = c;
  if (x == dh && y == dw) e = c;
  for (int i = 0; i < 4; ++i) {
    if (!check(x+dx[i], y+dy[i]) || bio[x+dx[i]][y+dy[i]]) continue;
    if (m[x+dx[i]][y+dy[i]] == '#') continue;
    dfs(x+dx[i], y+dy[i], c);
  }
}

void solve() {
  scanf("%d%d%d%d%d%d", &h, &w, &ch, &cw, &dh, &dw);
  --ch, --cw, --dh, --dw;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf(" %c", m[i]+j);
    }
  }
  int color = 1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (m[i][j] == '#') continue;
      if (bio[i][j]) continue;
      dfs(i, j, color++);
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (m[i][j] == '#') continue;
      for (int k = 0; k < sizeof(dx2)/sizeof(int); ++k) {
	if (!check(i+dx2[k], j+dy2[k])) continue;
	if (m[i+dx2[k]][j+dy2[k]] == '#') continue;
	if (bio[i][j] == bio[i+dx2[k]][j+dy2[k]]) continue;
	g[bio[i][j]].insert(bio[i+dx2[k]][j+dy2[k]]);
	g[bio[i+dx2[k]][j+dy2[k]]].insert(bio[i][j]);
      }
    }
  }
  queue<pair<int, int>> q;
  bio2[s] = 1;
  q.emplace(s, 0);
  while (!q.empty()) {
    int u = q.front().first, d = q.front().second; q.pop();
    if (e == u) {
      printf("%d", d);
      return;
    }
    for (int v: g[u]) {
      if (bio2[v]) continue;
      q.emplace(v, d+1);
      bio2[v] = 1;
    }
  }
  printf("-1");
}

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


Measured memory_bytes: 76732
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    string s;
    cin>>s;
    int n=s.len;
    rep0(i,n-1){
        if(s[i]==s[i+1]){
            cout<<i+1<<" "<<i+2;
            return;
        }
    }
    rep0(i,n-2){
        if(s[i]==s[i+2]){
            cout<<i+1<<" "<<i+3;
            return;
        }
    }
    cout<<"-1 -1";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <stdio.h>
#include <math.h>
#define MAX 100

int H[MAX];
int n;

int parent(int i) {
    int index = floor(i/2.0);
    return H[index];
}

int left(int i) {
    return H[2 * i];
}

int right(int i) {
    return H[(2 * i) + 1];
}

int main() {
    int val;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &val);
        H[i] = val;
    }
    
    for (int i = 1; i <= n; i++) {
        printf("node %d: ", i);
        printf("key = %d, ", H[i]);
        if (i>1) printf("parent key = %d, ", parent(i));
        if (2*i <= n) printf("left key = %d, ", left(i));
        if (2*i+1<= n) printf("right key = %d, ", right(i));
        printf("\n");
    }
    
    return 0;
}



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

int main()
{
  int A[5], k;
  // int a, b, c, d, e, k;

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

  for (int i = 0; i < 5; i++)
  {
    for (int j = 0; j < 5; j++)
    {
      if (i == j)
        continue;
      if (A[i] > A[j])
        continue;
      if ((A[j] - A[i]) > k)
      {
        cout << ":(";
        return 0;
      }
    }
  }

  cout << "Yay!";
}


Measured memory_bytes: 256
N,M=map(x->parse(Int,x),split(readline()))
i=2
ans=1
mod=10^9+7
p(a,b)=b>0 ? p(a*a%mod,b>>1)*(b%2>0 ? a : 1)%mod : 1
function comb(a,b)
	x=y=1
	for i=1:b
		y=y*i%mod
		x=x*(a-i+1)%mod
	end
	x*p(y,mod-2)%mod
end
while i*i<=M
	c=0
	while M%i==0
		c+=1
		M=div(M,i)
	end
	ans=ans*comb(c+N-1,c)%mod
	i+=1
end
if M>1
	ans=ans*N%mod
end
println(ans)


Measured memory_bytes: 111820
import sys
from heapq import *
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    
    tree = [[] for _ in range(n)]
    for i in range(m):
        s, t, c = map(int, input().split())
        tree[t-1].append((s-1, c))
        tree[s-1].append((t-1, c))
    
    for i in range(n-1):
        tree[i+1].append((i, 0))
    
    ans = [-1]*n
    already = [False]*n
    not_yet = [(0, 0)]
    
    while not_yet:
        value, key = heappop(not_yet)
        if already[key]:
            continue
        already[key] = True
        ans[key] = value
        
        for k, v in tree[key]:
            if already[k]:
                continue
            heappush(not_yet, (v+value, k))
        
    print(ans[n-1])
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 61760
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

ll solve(const VL &ss, const VL &ts, ll q) {
  int sei = lower_bound(ss.begin(), ss.end(), q) - ss.begin();
  int tei = lower_bound(ts.begin(), ts.end(), q) - ts.begin();
  ll se = ss[sei];
  ll sw = ss[sei-1];
  ll te = ts[tei];
  ll tw = ts[tei-1];
  ll ans = 1ll << 60;
  ans = min(ans, q - min(sw, tw));
  ans = min(ans, max(se, te) - q);
  ans = min(ans, se - tw + min(se - q, q - tw));
  ans = min(ans, te - sw + min(te - q, q - sw));
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  int a, b, qc;
  cin >> a >> b >> qc;
  VL ss = {-(1ll << 60)};
  REP(i,0,a) {
    ll s;
    cin >> s;
    ss.push_back(s);
  }
  ss.push_back(1ll << 60);
  VL ts = {-(1ll << 60)};
  REP(i,0,b) {
    ll t;
    cin >> t;
    ts.push_back(t);
  }
  ts.push_back(1ll << 60);
  VL qs(qc);
  FOR(q,qs) {
    cin >> q;
  }
  FOR(q,qs) {
    cout << solve(ss, ts, q) << endl;
  }

  return 0;
}


Measured memory_bytes: 3828
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG: {} -> {}'.format(name, val), file=sys.stderr)
            return None

N = int(input())
A = set(map(int, input().split()))

# debug(A, locals())
m = len(A)

if m % 2 == 0:
    ans = m - 1
else:
    ans = m

print(ans)

Measured memory_bytes: 19316
/* kadai3_3
   Saikyo_Kazune
*/
#include <stdio.h>
//累乗関数を自前定義
int pow(int K,int L){
    if(L==0){
        return 1;
    }
    else if(L%2==1){
        return K*pow(K,L-1);
    }
    else{
        return pow(K,L/2)*pow(K,L/2);
    }
}
 
int main(void){
   //int型　num_N,num_K,桁数ようにLを宣言
   int num_N,num_K,L=1;
   scanf("%d %d",&num_N,&num_K);
   while(num_N/pow(num_K,L)!=0){
       L++;
   }
   printf("%d\n",L);
 
    return 0;
}

Measured memory_bytes: 128
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {}
    int root(int x) {
        if (par[x] < 0)
            return x;
        else
            return (par[x] = root(par[x]));
    }
    bool issame(int x, int y) {
        if (root(x) == root(y)) return true;
    }
    bool merge(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx == ry) return false;
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
};

const int MAXN = 100100;

int main() {
    int N;
    cin >> N;
    UnionFind uf(2 * MAXN + 10);
    int x, y;
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        uf.merge(x, MAXN + y);
    }
    map<ll, ll> nodes_x, nodes_y;
    for (ll i = 0; i < MAXN; i++) {
        nodes_x[uf.root(i)]++;
    }
    for (ll i = MAXN; i < 2 * MAXN; i++) {
        nodes_y[uf.root(i)]++;
    }
    ll ret = 0;
    for (ll i = 0; i < 2 * MAXN; i++) {
        ret += nodes_x[i] * nodes_y[i];
    }
    cout << ret - N << endl;
    return 0;
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,a[210000];
signed main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];a[i] -= (i+1);
  }
  sort(a, a+n);
  int m = a[n/2];
  int ans = 0;
  rep(i,n)ans += abs(a[i] - m);
  m = a[n/2+(n/2 >= n ? 1 : 0)];
  int ans2 = 0;
  rep(i,n)ans2 += abs(a[i] - m);
  cout << max(ans, ans2) << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<algorithm>
#define ll long long
using namespace std;
int n;
ll a[120000];
ll b[120000];
ll dif[120000];

int main()
{
    int ans=0;
    ll ansSum=0;
    cin>>n;
    for (int i=0; i<n; ++i)
        scanf("%lld",&a[i]);
    for (int i=0; i<n; ++i)
        scanf("%lld",&b[i]);
    for (int i=0; i<n; ++i)
        dif[i]=a[i]-b[i];
    sort(dif,dif+n);
    for (int i=0; i<n; ++i)
        if (dif[i]<0)
        {
            ans++;
            ansSum+=dif[i];
        }
    for (int i=n-1; i>0; --i)
        if (ansSum<0 && dif[i]>0)
        {
            ans++;
            ansSum+=dif[i];
            if (ansSum>=0)
                break;
        }
    if (ansSum<0)
        cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>

using namespace std;

int main() {	
	string input;
	char in[1201] = { 0 },moji[26];
	int inputlen = 0, count[26] = { 0 }, i , n, j = 0;
	while (getline(cin, input)) {
		i = 0;
		while (input[i] != '\0') {
			n = 65;
			while (n != 91) {
				if (input[i] == n) count[n - 65]++;
				n++;
			}
			n = 97;
			while (n != 123) {
				if (input[i] == n) count[n - 97]++;
				n++;
			}
			i++;
		}
	}
	for (int k = 97; k < 123; k++) {
		printf("%c : %d\n", k, count[j]);
		j++;
	}
	return 0;
}

Measured memory_bytes: 1188
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n, X = MAP()
x = LIST()
d = [-1 for _ in range(n)]
for i in range(n):
    d[i] = abs(x[i] - X)
ans = d[0]
for i in range(1, n):
    ans = gcd(ans, d[i])
print(ans)

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

#define MAX_N (100000L)
#define MAX_FACT (MAX_N)
#define NUM_MOD (1000000007L)

long fs[MAX_FACT + 1], finvs[MAX_FACT + 1], invs[MAX_FACT + 1];

void combination_init() {
  fs[0] = fs[1] = 1;
  finvs[0] = finvs[1] = 1;
  invs[1] = 1;
  for (long i = 2; i <= MAX_FACT; i++) {
    fs[i] = fs[i - 1] * i % NUM_MOD;
    invs[i] = NUM_MOD - invs[NUM_MOD % i] * (NUM_MOD / i) % NUM_MOD;
    finvs[i] = finvs[i - 1] * invs[i] % NUM_MOD;
  }
}

long combination(long n, long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fs[n] * (finvs[k] * finvs[n - k] % NUM_MOD) % NUM_MOD;
}

long mod(long n, long k) { return n % k >= 0 ? n % k : n % k + k; }

int main(int argc, char *argv[]) {
  // read inputs
  long N, as[MAX_N + 1];
  scanf("%ld", &N);
  for (long i = 0; i < N + 1; i++) {
    scanf("%ld", &as[i]);
  }

  // determine the number X that appears twice and the number of elements
  // between them
  long indices[MAX_N + 1], c;
  for (long i = 0; i <= N; i++) {
    indices[i] = -1;
  }
  for (long i = 0; i < N + 1; i++) {
    const long a = as[i];
    if (indices[a] < 0) {
      indices[a] = i;
    } else {
      c = i - indices[a] - 1;
    }
  }

  // solve
  combination_init();
  for (long k = 1; k <= N + 1; k++) {
    long ans = 0;
    // include X twice
    if (k < 2) {
      ans = mod(ans + 0, NUM_MOD);
    } else {
      ans = mod(ans + combination(N - 1, k - 2), NUM_MOD);
    }
    // include X once
    if (k < N + 1) {
      ans = mod(
          ans + 2 * combination(N - 1, k - 1) - combination(N - 1 - c, k - 1),
          NUM_MOD);
    } else {
      ans = (ans + 0) % NUM_MOD;
    }
    // don't include X
    if (k < N) {
      ans = mod(ans + combination(N - 1, k), NUM_MOD);
    } else {
      ans = mod(ans + 0, NUM_MOD);
    }
    printf("%ld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 500005
//<<fixed << setprecision(9)

int arr[space];
int cnt[space];
int distinct;

const int block_size=700;

struct Query
{
    int l, r, idx;
    bool operator<(Query other) const
    {
        return make_pair(l / block_size, r) <
               make_pair(other.l / block_size, other.r);
    }
};

void add(int x)
{
    cnt[arr[x]]++;
    if(cnt[arr[x]]==1) distinct++;
}
void remove(int x)
{
    cnt[arr[x]]--;
    if(cnt[arr[x]]==0) distinct--;
}

int main()
{
    int n,i,j,t;
    boost;

    cin>>n>>t;

    rep(i,1,n+1) cin>>arr[i];

    Query Q[t];
    int ans[t];
    rep(i,0,t)
    {
        int l,r;
        cin>>l>>r;
        Q[i]={l,r,i};
    }
    sort(Q,Q+t);

    int cur_l = 1;
    int cur_r = 0;
    
    for (Query q : Q)
    {
        while (cur_l > q.l) {
            cur_l--;
            add(cur_l);
        }
        while (cur_r < q.r) {
            cur_r++;
            add(cur_r);
        }
        while (cur_l < q.l) {
            remove(cur_l);
            cur_l++;
        }
        while (cur_r > q.r) {
            remove(cur_r);
            cur_r--;
        }
        ans[q.idx] = distinct;
    }

    rep(i,0,t)cout<<ans[i]<<'\n';

    return 0;
}

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

int main() {
  int n,d;cin>>n>>d;
  vector<vector<int>> x(n,vector<int>(d));
  rep(i,n)rep(j,d)cin>>x[i][j];
  int ans=0;
  rep(i,n)for(int j=i+1;j<n;j++){
    int cnt=0;
    rep(k,d){
      int a=x[i][k]-x[j][k];
      cnt+=a*a;
    }
    for(int k=1;k<=cnt;k++){
      if(k*k==cnt)ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3544
#include<stdio.h>

int main()
{
    int i,n,t,cost,time,ans=10000;
	scanf("%d %d",&n,&t);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&cost,&time);//ci,ti
		if(time<=t)
		{
			if(cost<ans)ans=cost;
		}
	}
	if(ans==10000)printf("TLE");
	else printf("%d",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	char s[10];
	scanf("%s",s);
	if(s[2]==s[3] && s[4]==s[5])
		printf("Yes\n");
	else
		printf("No\n");
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int X, i, j, output;
  
  scanf("%d", &X);
  
  i = X / 500;
  X = X % 500;
  j = X / 5;
  X = X % 5;
  
  output = i * 1000 + j * 5;
  
  printf("%d", output);
  
  return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    ll H, W, N;
    std::cin >> H >> W >> N;

    map<ll, ll> cnt;
    REP(i, N) {
        ll a, b;
        std::cin >> a >> b;
        a--; b--;
        REP(hi, 3) {
            auto y = a - hi;
            if(y < 0 || H - 3 < y) continue;
            REP(wi, 3) {
                auto x = b - wi;
                if(x < 0 || W - 3 < x) continue;
                cnt[x + y * W]++;
            }
        }
    }

    ll not_zero = 0;
    vector<ll> ans(10, 0);
    for(const auto& v : cnt) {
        ans[v.second]++;
        not_zero++;
    }
    ans[0] = (H - 2) * (W - 2) - not_zero;

    for(const auto& v : ans) {
        std::cout << v << std::endl;
    }

    return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}


// ------------------------------------------------------------------------------------------

void print3() {}

template <class Head, class... Tail>
void print3(Head&& head, Tail&&... tail)
{
  std::cout << head << std::endl;

  // パラメータパックtailをさらにheadとtailに分割する
  print3(std::forward<Tail>(tail)...);
}

signed main() {
  int n;
  cin >> n;
  if (n < 1200) {
    puts("ABC");
  } else if (n < 2800) {
    puts("ARC");
  } else {
    puts("AGC");
  }
}

Measured memory_bytes: 764
package main

import "fmt"

func main() {
	var a, b, c, x, count int
	fmt.Scan(&a, &b, &c, &x)

	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if x == i*500+j*100+k*50 {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


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

using namespace std;

int main() {
    int waseda[10];
    int kyoto[10];
    for (int i = 0; i < 10; ++i) {
        cin >> waseda[i];
    }
    sort(waseda, waseda + 10);
    for (int i = 0; i < 10; ++i) {
        cin >> kyoto[i];
    }
    sort(kyoto, kyoto + 10);
    cout << waseda[9] + waseda[8] + waseda[7] << " " << kyoto[9] + kyoto[8] + kyoto[7] << '\n';
}


Measured memory_bytes: 3156
#include <iostream> 
using namespace std; 
int main(){ 
  int N,K; 
  cin>>N>>K;
 int cnt=0; 
  for(int i=0;i<N;i++){ 
    int h; 
    cin>>h; 
    if(h>=K) cnt++; 
  }
 cout<<cnt<<endl; 
  return 0; 
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

        long ans = 0;
        if (N >= M / 2) {
            ans = M / 2;
        } else {
            ans = N + (M - 2 * N) / 4;
        }

        out.println(ans);
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int n,m;
  cin>>n>>m;
  vi a(m);
  REP(i,m)cin>>a[i];
  REP(i,m)--a[i];
  vi d(n,1145141919);
  queue<int> Q;
  REP(i,m){
    d[a[i]]=0;
    Q.push(a[i]);
  }
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    if(p>0){
      if(d[p-1]>d[p]+1){
        d[p-1] = d[p]+1;
        Q.push(p-1);
      }
    }
    if(p<n-1){
      if(d[p+1]>d[p]+1){
        d[p+1] = d[p]+1;
        Q.push(p+1);
      }
    }
  }
  int res = 0;
  REP(i,n)res=max(res,d[i]);
  cout<<res<<endl;
  return 0;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

vector<ll> ans;

void dfs(ll n) {
  ans.emplace_back(n);
  if (n >= 3234566669) {
    return;
  }
  string num = to_string(n);
  reverse(num.begin(), num.end());
  ll dig = num[0] - '0';
  dfs(n * 10 + dig);
  if (dig + 1 <= 9) {
    dfs(n * 10 + dig + 1);
  }
  if (dig - 1 >= 0) {
    dfs(n * 10 + dig - 1);
  }
}

int main() {
  ll k;
  cin >> k;
  rep(i, 1, 10) dfs(i);
  sort(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
}

Measured memory_bytes: 6548
#include <stdio.h>
 
int main(void){
  int a, b, c;
  scanf("%d%d%d\n", &a, &b, &c);
 
  if(a <= b && b <= c) printf("%d %d %d\n", a, b, c);
  else if(a <= c && c <= b) printf("%d %d %d\n", a, c, b);
  else if(b <= a && a <= c) printf("%d %d %d\n", b, a, c);
  else if(b <= c && c <= a) printf("%d %d %d\n", b, c, a);
  else if(c <= a && a <= b) printf("%d %d %d\n", c, a, b);
  else if(c <= b && b <= a) printf("%d %d %d\n", c, b, a);
  else return 1; /* what's happen!? */
 
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
    vec.at(i) -= 1;
  }
  
  int l=0; //光っているボタン
  for(int i=0; i<n; i++){
    if(l==1){
      cout << i << endl;
      return 0;
    }
    else{
      l = vec.at(l);
    }
  }
  
  cout << "-1" << endl;
  return 0;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,a[100009]={},sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=abs(a[i]-a[i-1]);
    }
    sum+=abs(a[n]);
    for(int i=1;i<=n;i++){
        if((a[i-1]-a[i])*(a[i]-a[i+1])>=0){
            cout<<sum<<endl;
        } else {
            cout<<sum-2*min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long int N,H,W,i,j,k,ans,count,cost,tmp;
    long long int S[200010];
    long long int Ssum[200010];
    string T;
    bool flag;
    count=0;
    ans=0;
    flag=false;
    cin >>N>>H>>ans;
    
    
        for (i=0;i<10;i++){
            ans=N*ans-H;
            cout <<ans<<endl;
        }

    
    

    return 0;
    
}


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

int main() {
    int A,B,C,D,E,F;
    cin >>A >>B >>C >>D >>E >>F;
    
    set<int> water;
    for(int a = 0; a * 100 <= F; ++a) {
        for(int b = 0; b * 100 <= F; ++b) {
            int w = (a * A + b * B) * 100;
            if(w <= F) {
                water.insert(w);
            }
        }
    }
    set<int> sugar;
    for(int c = 0; c <= F; ++c) {
        for(int d = 0; d <= F; ++d) {
            int s = c * C + d * D;
            if(s <= F) {
                sugar.insert(s);
            }
        }
    }
    double Max = -1;
    int W = 1; int S = 0;
    for(auto wa: water) {
        for(auto su: sugar) {
            if(wa + su > F) continue;
            if(su * 100 > wa * E) continue;
            double tmp = (double) su / (su + wa);
            if(tmp > Max) {
                Max = tmp;
                W = wa; S = su;
            }
        }
    }
    cout << W + S << " " << S << endl;
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9+7;
int main() {
  int n, t;
  cin >> n >> t;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];
  vector<vector<int>> dp(t + 1, vector<int>(2, 0));

  for (int i = 0; i < n; i++) {
    for (int j = t - 1; j >= 0; j--) {
      if (j + a[i] <= t) {
        dp[j + a[i]][0] = max(dp[j + a[i]][0], dp[j][0] + b[i]);
        dp[j + a[i]][1] = max(dp[j + a[i]][1], dp[j][1] + b[i]);
      }
      dp[j][1] = max(dp[j][1], dp[j][0] + b[i]);
    }
  }

  cout << dp[t - 1][1] << endl;
  return 0;
} 


Measured memory_bytes: 3772
# -*- Coding: utf-8 -*-
# ???????????????
info = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

# ?????????????????°
n = int(input())

# ?????????????????????????????????
for i in range(n):
    b,f,r,v = map(int,list(input().split()))
    info[b-1][f-1][r-1] += v

# ???????????????
for i in range(4):
    if i != 0:
        print('####################')
    for j in range(3):
        print(' '+' '.join(map(str,info[i][j])))

Measured memory_bytes: 7684
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define N 100000
    int n,k;
    int w[105],v[105];
    ll dp[N+5];
    int main() {
        cin>>n>>k;
        for(int i=1;i<=n;i++) {cin>>w[i]>>v[i];}
        for(int i=1;i<=N;i++) {dp[i]=int(2e9);}
        for(int i=1;i<=n;i++) {
           for(int j=N;j>=v[i];j--)
           	{dp[j]=min(dp[j],dp[j-v[i]]+w[i]);}
        }
        int ans=0;
        for(int i=0;i<=N;i++) {
           if(dp[i]<=k) {ans=max(ans,i);}
        }
        cout<<ans<<endl;
    }

Measured memory_bytes: 4368
class Cake:
  def __init__(self, w, d):
    self.w = w
    self.d = d
    self.next = None

  def getArea(self):
    return self.w*self.d

  def getCake(self, i):
    if i==1: return self
    else: return self.next.getCake(i-1)

  def devideCake(self, n):
    n = n % (self.w+self.d)
    if n < self.w:
      c1 = Cake(min(n, self.w-n), self.d)
      c2 = Cake(max(n, self.w-n), self.d)
    else:
      c1 = Cake(self.w, min(n-self.w, self.d-n+self.w))
      c2 = Cake(self.w, max(n-self.w, self.d-n+self.w))
    c1.next = c2
    return c1

while True:
  n,w,d = map(int, raw_input().split())
  if n==w==d==0: break
  cakes = Cake(w, d)
  for i in xrange(n):
    p,s = map(int, raw_input().split())
    cake = cakes.getCake(p)
    if p == 1:
      cakes = cakes.next
    else:
      cakes.getCake(p-1).next = cake.next
    if i == 0:
      cakes = cake.devideCake(s)
    else:
      cakes.getCake(i).next = cake.devideCake(s)
  areas = []
  c = cakes
  while True:
    areas.append(c.getArea())
    if c.next == None: break
    c = c.next
  print " ".join(map(str, sorted(areas)))

Measured memory_bytes: 6316
#!/usr/bin/env python3
import sys


def solve(x: int, a: int, b: int):
    if abs(a-x) > abs(b-x):
        return "B"
    else:
        return "A"


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    print(solve(x, a, b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n=input()
a = lambda x,y:3**x - y*2**x + y -1+(y%3==0)
ans = 0
ln = len(n)
s = set()
b = True
for p, i in enumerate(n):
    m = int(i) 
    if b:
        if m > 7:
            ans += a(ln-p-1,3-len(s|{7}))
        if m > 5:
            ans += a(ln-p-1,3-len(s|{5}))
        if m > 3:
            ans += a(ln-p-1,3-len(s|{3}))
        if m in (7,5,3):
            s.add(m)
            if ln == p+1:
                ans += len(s)==3
        else:
            b = False
    if ln > p +1:
        ans += a(ln - p -1,3)
print(ans)


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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

class UnionFind {
public:
    int n;
    vector<int> p;
    vector<vector<int>> cmps;

    UnionFind(): n(), p(), cmps() {}
    UnionFind(int n): n(n), p(n + 1), cmps(n + 1) {
        iota(p.begin(), p.end(), 0);
        for (int i = 1; i <= n; i++) cmps[i] = {i};
    }
    int size() const {
        return n;
    }
    int find(int x) {
        return p[x];
    }
    bool merge(int x, int y) {
        int s1 = find(x);
        int s2 = find(y);

        if (s1 == s2)
            return false;
        if (cmps[s2].size() > cmps[s1].size())
            swap(s1, s2);
        for (int i : cmps[s2]) {
            cmps[s1].push_back(i);
            p[i] = s1;
        }
        cmps[s2].clear();

        n--;
        return true;
    }
};

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

    int n, m;
    cin >> n >> m;

    UnionFind uf(n);
    while (m--) {
        int a, b;
        cin >> a >> b;
        uf.merge(a, b);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, (int)uf.cmps[i].size());
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 18316
inputs = gets.strip().split(" ").map{|i| i.to_i}
n, m, l = inputs[0], inputs[1], inputs[2]
a = Array.new(n){Array.new(m){0}}
b = Array.new(m){Array.new(l){0}}
c = Array.new(n){Array.new(l){0}}
for row_i in 0..n-1
	rows = gets.strip().split(" ").map{|i| i.to_i}
	a[row_i][0..m-1] = rows
end
for row_i in 0..m-1
	rows = gets.strip().split(" ").map{|i| i.to_i}
	b[row_i][0..l-1] = rows
end
for row_i in 0..n-1
	for col_i in 0..l-1
		for k in 0..m-1
			c[row_i][col_i] += a[row_i][k] * b[k][col_i]
		end
		print (col_i == 0)? c[row_i][col_i] : " #{c[row_i][col_i]}"
	end  
	puts ""
end


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
ll MOD = ll(1e8) + 9;

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int n;
    cin >> n;
    int ans = n / 2;
    if (n & 1) {
        ans++;
    }
    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
 using namespace std ;
 int main()
 {
   int A, B, c, d, e;
   cin>>A;
   cin>>B;
   c =(A + B);
   d =(A - B);
   e =(A * B);
   if (c >= e&&c >= d)
   {
   cout<<c<<endl;
   }
else   if (e >= d&&e >= c)
   {
     cout<<e<<endl;
   }
  else  if (d >= e&&d >= c) 
   {
     cout<<d<<endl;
   }
   }

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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	map<char, int> ct;
	for( auto ch: S ) { ct[ch] += 1; }

	int m = max( { ct['a'], ct['b'], ct['c'] } );
	int n = min( { ct['a'], ct['b'], ct['c'] } );
	cout << (m-n <= 1 ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                print("#",end="")
            else:
                c = 0
                for p in range(max(i-1,0),min(i+2,H)):
                    for q in range(max(j-1,0),min(j+2,W)):
                        if (p != i or q != j) and S[p][q] == "#":
                            c += 1
                print(c,end="")
        print("")
                        
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444