akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N,M,K;
	cin>>N>>M>>K;
	
	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			if(i*M + j*N - i*j*2 == K){
				//cout<<i<<','<<j<<endl;
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
#include <random>
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { d, r, u, l , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D array to 1D array. (Zero-indexed)
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) {
	int r = n / nCol, c = n % nCol;
	return ii(r, c);
}

void inter(string s) {
	cout << s << endl;
	fflush(stdout);
}

const int NN = 2e6 + 10;
ll fact[NN];

void init() {
	fact[0] = 1;
	for (int i = 1; i < NN; ++i) fact[i] = (fact[i - 1] * 1LL * i) % MOD;
}

ll nCr(ll n, ll r) {
	auto modInverse = [](ll a) { 
		auto power = [](ll base, ll exp) {
			ll ans = 1;
			base %= MOD;
			while (exp > 0) {
				if (exp & 1) ans = (ans * base) % MOD;
				exp >>= 1;
				base = (base * base) % MOD;
			}
			return ans;
		};
		return power(a, MOD - 2); 
	};
	return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r])) % MOD;
}



int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vll cnt(n + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) cnt[j]++;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += i * 1ll * cnt[i];
	cout << ans << endl;


	return 0;
}


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

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

	const int C = 8;
	int N;
	cin >> N;

	vector<int> a( C+1 );
	for( int i = 0; i < N; ++i ) {
		int r;
		cin >> r;
		r /= 400;

		a[r < C ? r : C] += 1;
	}

	int cl = 0;
	for( int i = 0; i < C; ++i ) {
		cl += a[i] > 0;
	}

	int x = max<int>( cl, a[C] > 0 );
	int y = cl + a[C];

	cout << x << ' ' << y << endl;
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var m = parseInt(line[0]);
    var n = parseInt(line[1]);
    
    var ans = (m-1)*(n-1);
    console.log(ans);
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>

#define all(v) (v).begin(), (v).end()
#define LEFT(n) (2*n + 1)
#define RIGHT(n) (2*n + 2)

using namespace std;

typedef long long LL;
const int MAX_N = 2e5 + 5;
int sum[3*MAX_N];

struct info
{
    LL value;
    int index;

    info(LL V, int I)
    {
        value = V, index = I;
    }

    int operator<(const info &A)
    {
        return (value == A.value ? index < A.index : value < A.value);
    }
};

void update(int n, int left, int right, int position, int value)
{
    if(right < position || position < left)
        return;

    if(left == right)
    {
        sum[n] = value;
        return;
    }

    int mid = (left + right) >> 1;

    update(LEFT(n), left, mid, position, value);
    update(RIGHT(n), mid + 1, right, position, value);

    sum[n] = sum[RIGHT(n)] + sum[LEFT(n)];
}

int get_sum(int n, int left, int right, int query_left, int query_right)
{
    if(right < query_left || query_right < left)
        return 0;

    if(query_left <= left && right <= query_right)
        return sum[n];

    int mid = (left + right) >> 1;
    int left_sum = get_sum(LEFT(n), left, mid, query_left, query_right);
    int right_sum = get_sum(RIGHT(n), mid + 1, right, query_left, query_right);

    return (left_sum + right_sum);
}

int main()
{
    int no_of_elements, k;
    scanf("%d %d", &no_of_elements, &k);

    LL array_sum = 0;
    vector <info> A(no_of_elements + 1, info(0, 0));
    for(int i = 1; i <= no_of_elements; i++)
    {
        int element;
        scanf("%d", &element);

        array_sum += element;
        A[i] = info(array_sum - i*1LL*k, i);
    }

    sort(all(A)); //for(int i = 0; i <= no_of_elements; i++) printf("i = %d, A[i] = %lld index = %d\n", i, A[i].value, A[i].index);

    memset(sum, 0, sizeof(sum));

    LL answer_pairs = 0;

    for(int i = 0; i <= no_of_elements; i++)
    {
        answer_pairs += get_sum(0, 0, no_of_elements, 0, A[i].index); //printf("ans = %lld\n", answer_pairs);

        update(0, 0, no_of_elements, A[i].index, 1);
    }

    printf("%lld\n", answer_pairs);
    return 0;
}


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


int main()
{
    std::ios::sync_with_stdio(false);	
	int N;
	cin>>N;
	vector<int> a(N);
	int minn = 2000;
	int maxn = -1;
	for(int i = 0 ; i < N ; i++)
	{
		cin>>a[i];
		if(a[i]<minn)
		{
			minn = a[i];
		}
		if(a[i]>maxn)
		{
			maxn = a[i];
		}
	}
	cout<<maxn-minn;
	
    return 0;
}

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

int main() {
  int n; std::cin >> n;
  std::string s; std::cin >> s;
  if (n % 2 == 1) {
    std::cout << "No" << std::endl;
    return 0;
  }
  bool ok = true;
  for (int i = 0; i < n/2; ++i) {
    if (s[i] != s[i+n/2]) ok = false;
  }
  if (ok) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

LL dp[3340][3340][2];
int n;
vector<int> a;

LL rec(int l, int r, int turn){
    if(dp[l][r][turn] != -LLINF) return dp[l][r][turn];
    if(l+r == n) return dp[l][r][turn] = 0;
    if(turn == 0){
        LL tmp = -LLINF;
        chmax(tmp, rec(l+1, r, 1)+a[l]);
        chmax(tmp, rec(l, r+1, 1)+a[n-1-r]);
        return dp[l][r][turn] = tmp;
    }else{
        LL tmp = LLINF;
        chmin(tmp, rec(l+1, r, 0)-a[l]);
        chmin(tmp, rec(l, r+1, 0)-a[n-1-r]);
        return dp[l][r][turn] = tmp;
    }
}

int main(){
    fastcin();

    cin >> n;
    a.assign(n, 0);
    rep(i, n) cin >> a[i];
    fill(dp[0][0], dp[3340][0], -LLINF);
    cout << rec(0, 0, 0) << endl;


}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll x, y;
  cin >> x >> y;

  ll count = 1;
  ll now = y / x;
  while(now != 1){
    now /= 2;
    count++;  
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int N;
int l, r;
int i, sum;

int main(void){
  scanf("%d", &N);
  sum = 0;
  for(i = 0; i < N; i++){
    scanf("%d %d", &l, &r);
    sum += (r-l);
  }
  printf("%d", sum+N);
    
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
ans = 0
while True:
  for i in range(N):
    if A[i] % 2 == 0:
      A[i] = A[i] // 2
    else:
      print(ans)
      exit()

  else:
    ans += 1
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        for(int i = 1;;i++) {
            int x = sc.nextInt();                
            if(x == 0) {
                break;
            }
            System.out.println("Case " + i + ": " + x);
        }
        sc.close();
    }
}


Measured memory_bytes: 41508
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int power(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return ret;
}
int n,x,y,c[200111],w[200111];
vector<pii> v[200111];
map<int,int> cnt[200111];
int sz[200111],f[200111],fac[200111],invf[200111];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
void un(int x,int y)
{
	x=gf(x);y=gf(y);
	if(x==y)return;
	if(sz[x]<sz[y])swap(x,y);
	f[y]=x;
	sz[x]+=sz[y];
}
int main()
{
	fac[0]=invf[0]=1;
	for(int i=1;i<200111;i++)
	{
		fac[i]=1ll*fac[i-1]*i%mod;
		invf[i]=power(fac[i],mod-2);
	}
	
	get3(n,x,y);
	for(int i=1;i<=n;i++)
	{
		f[i]=i;sz[i]=1;
		get2(c[i],w[i]);
		v[c[i]].pb(mp(w[i],i));
	}
	int mn=0,mn2=0;
	for(int i=1;i<=n;i++)
	{
		if((int)v[i].size()==0)continue;
		sort(v[i].begin(),v[i].end());
		for(int j=1;j<(int)v[i].size();j++)
		{
			if(v[i][0].ff+v[i][j].ff<=x)
				un(v[i][0].ss,v[i][j].ss);
		}
		if(mn==0||v[mn][0].ff>v[i][0].ff)
		{
			mn2=mn;
			mn=i;
		}
		else if(mn2==0||v[mn2][0].ff>v[i][0].ff)mn2=i;
	}
	if(mn)mn=v[mn][0].ss;if(mn2)mn2=v[mn2][0].ss;
	for(int i=1;i<=n;i++)
	{
		if(c[i]!=c[mn]&&w[i]+w[mn]<=y)un(i,mn);
		else if(c[i]!=c[mn2]&&w[i]+w[mn2]<=y)un(i,mn2);
	}
	for(int i=1;i<=n;i++)cnt[gf(i)][c[i]]++;
	int ans=1,sum=0;
	for(int i=1;i<=n;i++)if(f[i]==i)
	{
		sum+=sz[i];
		ans=1ll*ans*fac[sz[i]]%mod;
		for(map<int,int>::iterator it=cnt[i].begin();it!=cnt[i].end();it++)
			ans=1ll*ans*invf[it->ss]%mod;
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 32768
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >>k;
  for(int i=a;i<=b;i++){
     if(i<=(a+k-1)) cout << i <<endl;
     else if(i>=(b-k+1)) cout << i <<endl;
  }
}


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

typedef long long int ll;
ll mod = 1000000000 + 7;

const int nmax = 1000;
const int mmax = 10;

// All possible arrays where
// 1. Length = i
// 2. last element is j
ll arr[mmax][nmax] = {0};

int gcd(int a, int b){
    if(a > b) return gcd(b, a);
    else if(a == 0) return b;
    else return gcd(b%a, a);
}

int gcd(int a, int b, int c){
    return gcd(a, gcd(b, c));
}


int main(){
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                ans += gcd(i, j, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
N=gets.to_i
a=gets.split.map(&:to_i)
a=a.sort{|a,b| b<=>a}
c=0
d=0
N.times do |i|
  c=c+a[i] if i%2 ==0
  d=d+a[i] if i%2 ==1
end
p c-d

Measured memory_bytes: 1788
// 標準入力から一行を読み取り、指定の型に変換する
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()
}

fn main() {
    let n: usize = read();
    let h: Vec<i64> = read_vec();
    let mut is_continuation: bool = false;

    // 1度減少してから1度も増加せずに再び減少した場合はNo
    // 2以上の値減少した場合はNo
    for i in 0..(n - 1)
    {
        // 次の要素が1だけ少ない場合
        if h[i] - h[i + 1] == 1
        {
            // 増加することなく連続して発生した場合 - 強制終了
            if is_continuation { println!("No"); return; }

            // フラグをたてて続行
            is_continuation = true;
            continue;
        }

        // 次の要素が2以上少ない場合 - 強制終了
        if h[i] - h[i + 1] >= 2 { println!("No"); return; }

        // 増加した場合 - フラグ消去
        if h[i] - h[i + 1] < 0
        {
            is_continuation = false;
        }
    }

    println!("Yes");
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  int n;
  vector<int> sum, diff;
  cin >> n;
  rep(i, n)
  {
    int x;
    cin >> x;
    sum.push_back(x + i + 1);
    diff.push_back(i + 1 - x);
  }
  ll ans = 0;
  sort(diff.begin(), diff.end());
  rep(i, n)
  {
    int tmp = sum[i];
    auto l = lower_bound(diff.begin(), diff.end(), tmp);
    auto u = upper_bound(diff.begin(), diff.end(), tmp);
    if (l == diff.end() && u == diff.end())
      continue;
    ans += (u - diff.begin()) - (l - diff.begin());
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5016
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n)cin >> p[i];
    sort(p.begin(),p.end());
    ll ans = 0;
    rep(i,k){
        ans+=p[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int K, N; cin >> K >> N;
  vector<int> A(N*2);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    A[N+i] = A[i] + K;
  }
  int d = 0, pos = 0;
  for(int i = 1; i < N; i++) {
    if(d < A[i] - A[i-1]) {
      d = A[i] - A[i-1];
      pos = i;
    }
  }

  long long ans = 0;
  for(int i = 1; i < N; i++) ans += A[i]-A[i-1];
  long long res = 0;
  for(int i = pos+1; i < N+pos; i++) {
    res += A[i] - A[i-1];
  }
  cout << min(ans, res) << endl;
  return 0;
}


Measured memory_bytes: 1792
def c_chocolate_bar(H, W):
    # 変数a, b, cはeditorialの図のA, B, Cに対応する
    ans = float('inf')
    for _ in range(2):
        for i in range(1, H):
            a = i * W  # 領域Aの面積

            # 横に2つ切り込みを入れる(図の左から1番目の分け方)
            b = ((H - i) // 2) * W
            c = ((H - i + 1) // 2) * W
            ans = min(ans, abs(max(a, b, c) - min(a, b, c)))

            # 横縦に1つずつ切り込みを入れる(図の左から2番目の分け方)
            b = (W // 2) * (H - i)
            c = ((W + 1) // 2) * (H - i)
            ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
        H, W = W, H  # H,Wを入れ替えて同じことをする(図の左から3, 4番目の分け方)
    return ans

H, W = [int(i) for i in input().split()]
print(c_chocolate_bar(H, W))

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



int main() {
  int n, m;
  cin >> n >> m;
  ll sum = 0;
  rep(i, m) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum > n) cout << -1 << endl;
  else cout << n - sum << endl;
  
}

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

using namespace std;

int main(){
  int num;
  vector<int> vec; 
  int count = 0;
  
  for(int i=0 ; i < 3 ; i++){
    cin >> num;
    vec.push_back(num);
  }
  
  sort(vec.begin(),vec.end());;
  
  //cout << "fi: " << vec[2] << " se: " << vec[1] << " th: " << vec[0] << endl;
  
  int dif = vec[1] - vec[0];
  
  count = dif / 2;
  
  if(dif % 2 == 1){
    count++;
    vec[2]++;
  }
  
  count += (vec[2] - vec[1]);
  
  cout << count << endl;
  
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<bool> isprime(1000000, true);
    isprime[0] = isprime[1] = false;
    for (int i = 2; i * i < isprime.size(); i += 2)
    {
        if (!isprime[i])
            continue;
        if (n <= i)
        {
            cout << i << "\n";
            return 0;
        }
        for (int j = i * i; j < isprime.size(); j += i)
        {
            isprime[j] = false;
        }
        i -= i == 2;
    }
    vector<int> primenumber;
    for (int i = 0; i < isprime.size(); i++)
    {
        if (isprime[i])
        {
            primenumber.push_back(i);
        }
    }
    cout << *lower_bound(begin(primenumber), end(primenumber), n) << "\n";
}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<int> prime(int x){
	vector<int> ret;
	for (int i = 1; i*i <= x; i++){
		if(x%i==0){
			ret.push_back(i);
			if(x/i!=i) ret.push_back(x/i);
		}
	}
	return ret;
}

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin>>a[i];
	}

	int sum = accumulate(all(a),0);
	vector<int> div = prime(sum);
	// for(auto z:div)cout<<z<<" ";
	// 	cout<<endl;

	int ans = 1;
	for(auto x : div){
		// cout<<"x = " << x << endl;
		vector<int> modulo_x = a;
		for (int i = 0; i < n; i++){
			modulo_x[i] %= x;
		}
		sort(all(modulo_x));
		// for(auto z:modulo_x)cout<<z<<" ";
		// cout<<endl;
		vector<int> sum(n+1,0);
		for (int i = 1; i <= n; i++){
			sum[i] = sum[i-1] + modulo_x[i-1];
		}
		// for(auto z:sum)cout<<z<<" ";
		// cout<<endl;
		for (int i = 1; i <= n; i++){
			if(sum[i] == (n-i)*x - (sum[n]-sum[i]) && sum[i]<=k) ans = max(ans,x);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    string s;
    cin >> s;
    int now = 0;
    int mx = 0;
    for(const auto &c: s) {
        if(c == 'R') {
            now++;
            chmax(mx,now);
        } else {
            now = 0;
        }
    }
    cout << mx << endl;
}

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<set<int>>;
 
int main() {
  int N, M;
  cin >> N >> M;
  Graph E(N);
  int a, b;
  for (int i=0; i < M; i++) {
    cin >> a >> b; a--; b--;
    E.at(a).insert(b);
  }
  vector<double> ex(N, 0); double ans;
  vector<int> mx(N-1, 0);
  ex.at(N - 1) = 0;
  for (int i=N-2; i >= 0; i--) {
    double tmp = -1;
    for (int x : E.at(i)) {
      ex.at(i) += ex.at(x);
      if (ex.at(x) > tmp) {
        mx.at(i) = x;
        tmp = ex.at(x);
      }
    }
    ex.at(i) = ex.at(i) / E.at(i).size() + 1;
  }
  ans = 0;
  vector<double> p(N, 0); p.at(0) = 1;
  for (int i=0; i < N; i++) {
    for (int x : E.at(i)) {
      p.at(x) += 1.0 * p.at(i) / E.at(i).size();
    }
  }
  for (int i=N-2; i >= 0; i--) {
    double ex2 = 0;
    if (E.at(i).size() > 1) {
      for (int x : E.at(i)) {
        ex2 += ex.at(x);
      }
      ex2 = ( ex2 - ex.at(mx.at(i)) ) / ( E.at(i).size() - 1) + 1;
      ans = max(ans, p.at(i) * (ex.at(i) - ex2));
    }
  }
  printf("%.8lf\n", ex.at(0) - ans);
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, a[N], f[N], g[N<<2], tmp[N], tag[N<<2];
void pushup(int p)
{
	g[p] = max(g[p<<1], g[p<<1|1]);
}
void pushdown(int p)
{
	int &x = tag[p];
	g[p<<1] = max(g[p<<1], x);
	g[p<<1|1] = max(g[p<<1|1], x);
	tag[p<<1] = max(tag[p<<1], x);
	tag[p<<1|1] = max(tag[p<<1|1], x);
	x = 0;
}
void upd(int p, int l, int r, int x, int y, int v)
{
	if(l>=x && r<=y)
	{
		g[p] = max(g[p], v);
		tag[p] = max(tag[p], v);
		return;
	}
	if(tag[p]) pushdown(p);
	int mid = (l+r)>>1;
	if(x<=mid) upd(p<<1, l, mid, x, y, v);
	if(y>mid) upd(p<<1|1, mid+1, r, x, y, v);
	pushup(p);
}
int ask(int p, int l, int r, int x)
{
	if(l==r) return g[p];
	if(tag[p]) pushdown(p);
	int mid = (l+r)>>1;
	if(x<=mid) return ask(p<<1, l, mid, x);
	else return ask(p<<1|1, mid+1, r, x);
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<=n; i++) 
 	{
 		cin >> a[i]; 
 		tmp[i] = a[i];
 	}
 	sort(tmp+1, tmp+n+1);
 	int m = unique(tmp+1, tmp+n+1) - tmp - 1;
 	for(int i=1; i<=n; i++)
 		a[i] = lower_bound(tmp+1, tmp+m+1, a[i]) - tmp;
 	for(int i=1; i<=n; i++)
 	{
 		f[i] = ask(1, 1, n, a[i]) + 1;
 		upd(1, 1, n, 1, a[i], f[i]);
 	}
 	int ans = *max_element(f+1, f+n+1);
 	cout << ans;
	return 0;
}


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

const ll INF = 5e15;

vector<vector<ll>> pos(26);
vector<ll> len(2e5 + 10, -1);
string S;
ll N;

ll dfs(ll now){
    if(now > N) return len[now] = -1;
    if(len[now] != -1) return len[now];
    ll nxt = now;
    for(ll i = 0; i < 26; i++){
        auto ite = lower_bound(pos[i].begin(), pos[i].end(), now);
        nxt = max(nxt, *ite);
    }
    return len[now] = dfs(nxt + 1) + 1;
}

int main(){
    cin >> S;
    N = S.size();
    for(ll i = 0; i < S.size(); i++) pos[S[i] - 'a'].push_back(i);
    for(auto &v : pos) v.push_back(N);
    for(ll i = 0; i < N; i++) dfs(i);
    ll idx = 0;
    string ans = "";
    while(idx < N){
        for(ll i = 0; i < 26; i++){
            auto ite = lower_bound(pos[i].begin(), pos[i].end(), idx);
            if(len[*ite + 1] + 1 <= len[idx]){
                ans += 'a' + i;
                idx = *ite + 1;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
typedef bitset<2002011> b100;
int a[2111];
b100 dp[2];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int S=0;
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; S+=a[i];
	}
	int half = (S+1)/2;
	//find smallest subset sum >= half
	dp[0].reset(); dp[0].set(0,1); dp[0].set(a[0],1);
	for(int i=1;i<n;i++)
	{
		int cur=(i&1); int pre=(cur^1);
		dp[cur] = dp[pre]|(dp[pre]<<a[i]);
	}
	for(int i=half;i<=S;i++)
	{
		if(dp[(n+1)&1][i])
		{
			cout<<i<<'\n';
			return 0;
		}
	}
}


Measured memory_bytes: 1536
s = input()
reverse_str = s[::-1]
word_list = ["maerd","remaerd","esare","resare"]
while(True):
    start_len = len(reverse_str)
    for word in word_list:
        if reverse_str.startswith(word):
            reverse_str = reverse_str[len(word):]
    if start_len == len(reverse_str) and start_len != 0:
        print("NO")
        exit()
    elif len(reverse_str) == 0:
        print("YES")
        exit()


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

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

const int INF = 1 << 29;
const int vy[] = {1, 0, -1, 0};
const int vx[] = {0, -1, 0, 1};
const string vt = "|-|-";

template< typename T = int >
void warshall_floyd(Matrix< T > &g) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main() {
  int H, W;
  char S, T;
  string A[50];
  cin >> H >> W >> S >> T;
  for(int i = 0; i < H; i++) {
    cin >> A[i];
  }

  Matrix< int > mat(26, vector< int >(26, INF));
  for(int i = 0; i < 26; i++) mat[i][i] = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(isupper(A[i][j])) {
        for(int k = 0; k < 4; k++) {
          int ny = i + vy[k], nx = j + vx[k];
          while(0 <= ny && ny < H && 0 <= nx && nx < W) {
            if(isupper(A[ny][nx])) {
              mat[A[i][j] - 'A'][A[ny][nx] - 'A'] = 1;
              break;
            } else if(A[ny][nx] == '.') {
              break;
            } else if(vt.find(A[ny][nx]) != string::npos && A[ny][nx] != vt[k]) {
              break;
            }
            ny += vy[k];
            nx += vx[k];
          }

        }
      }
    }
  }
  warshall_floyd(mat);
  cout << mat[S - 'A'][T - 'A'] << endl;
}


Measured memory_bytes: 3232
#include <cstdlib>
#include <iostream>

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

    int a;
    uint b = 100000;
    while (std::cin >> a) {
        for (int i=1; i <= a; i++){
            b = b*1.05;
            if (b%1000 != 0) {
                b -= b%1000;
                b += 1000;
            }
        }
        std::cout << b << std::endl;
    }
    return EXIT_SUCCESS;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,maximum;
  maximum=0;
  cin>>n;
  long long ans=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  maximum=a.at(0);
  for(int i=0;i<n;i++){
    if(maximum>a.at(i)){
      ans=ans+maximum-a.at(i);
    }
    maximum=max(maximum,a.at(i));
  }
  cout<<ans;
}

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

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> arr(n, 0);
	for(int& x: arr)
		cin>>x;
	double sum = 0.0;
	for(int x: arr)
		sum+= x;
	int avg = round(sum/(double)n);
	long long int ans = 0;
	for(int x: arr) {
		ans += (avg-x)*(avg-x);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	while(1){
	int masu[2000];
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==0 && m==0){
		break;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&masu[i]);
	}
	int iti=1;
	int sai[2000];
	for(int i=1;i<=m;i++){
		scanf("%d",&sai[i]);
	}
	for(int i=1;i<=m;i++){
		iti+=sai[i];
		if(iti>=n){
			printf("%d\n",i);
			break;
		}
		iti+=masu[iti];
		if(iti>=n){
			printf("%d\n",i);
			break;
		}
	}
	}
}

Measured memory_bytes: 0
x=int(input())
if 400<=x<=599:
  print(8)
elif 600<=x<=799:
  print(7)
elif 800<=x<=999:
  print(6)
elif 1000<=x<=1199:
  print(5)
elif 1200<=x<=1399:
  print(4)
elif 1400<=x<=1599:
  print(3)
elif 1600<=x<=1799:
  print(2)
elif 1800<=x<=1999:
  print(1)

Measured memory_bytes: 9188
#include<iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a >>b >>c;
    if (a<b && b<c) cout << a <<" " << b << " "<< c << endl;
    else if (a<b && b>c) {
        
        if (a>c) {
            cout << c <<" " << a << " "<< b<< endl;
            
        }
        else {
             cout << a <<" " << c << " "<< b<< endl;
        }
    } 
    else if (a>b && b<c) {
        if (a<c) {
             cout << b <<" " << a << " "<< c<< endl;
        }
        else  cout << b <<" " << c << " "<< a<< endl;
    }else  cout << c <<" " << b << " "<< a<< endl;
    
    
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,m; cin >> n >> m;
    vector<ll> h(n); rep(i,n) cin >> h[i];
    vector<bool> v(n); rep(i,n) v[i] = true;
    rep(i,m){
        int a,b; cin >> a >> b;
        if(h[a-1] <= h[b-1]){
            v[a-1] = false;
        }
        if(h[a-1] >= h[b-1]){
            v[b-1] = false;
        }
    }
    int c=0;
    rep(i,n) if(v[i]) c++;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3980
import sys
import math
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    n = math.ceil((-1 + math.sqrt(1+8*N))/2)
    jokyo = n*(n+1)//2 - N
    for i in range(1,n+1):
        if i == jokyo:
            continue
        else:
            print(i)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3408
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        sc.close();
        if((a + b) % 2 == 0){
            System.out.println((a + b) / 2);
        }else{
            System.out.println("IMPOSSIBLE");
        }
    }
}

Measured memory_bytes: 35680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// UnionFind
struct UnionFind {
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; i++)
            par[i] = i;
    }
    int root(int x) {
        if(par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)
            return;
        if(siz[rx] < siz[ry])
            swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    ll size(ll x) { return siz[root(x)]; }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    int res = 1;
    rep(i, N) { res = max((int)uf.size(i), res); }
    cout << res << endl;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  double ans=0;
  double x[9],y[9];
  cin>>n;
  rep(i,n){
    cin>>x[i]>>y[i];
  }
  rep(i,n){
    rep(j,n){
      ans+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
    }
  }
  printf("%.10f\n",ans/n);
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define nnm(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int N, M;
vector<int> edge[200000];
bool check[200000];

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	queue<pii> q;
	q.push(pii(0, 0));
	check[0] = true;

	while (!q.empty()) {
		int v = q.front().first; 
		int d = q.front().second;
		if (d == 2 && v == N - 1) {
			printf("POSSIBLE\n");
			return 0;
		}
		q.pop();
		if (d == 2) continue;
		for (int i = 0; i < (int)edge[v].size(); i++) {
			int n = edge[v][i];
			if (check[n]) continue;
			check[n] = true;
			q.push(pii(n, d + 1));
		}
	}

	printf("IMPOSSIBLE\n");

	return 0;
}


Measured memory_bytes: 13040
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let k: usize = util::get();

    let base = 49 + k / 50;
    println!("50");
    println!(
        "{}",
        (0..k % 50)
            .map(|_| base + 50 - k % 50 + 1)
            .chain((k % 50..50).map(|_| base - k % 50))
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MAX_N = 200000;
int cnt[2][MAX_N+2] = {};

void cnt_init(){
    for(int i=0; i<2; ++i){
        for(int j=0; j<=MAX_N; ++j){
            cnt[i][j]=-1;
        }
    }
}

int main()
{
    ll n, q;
    cin >> n >> q;
    cnt_init();
    ll ans=(n-2)*(n-2);
    // 各queryで出てきたbの最小値
    // 相手のqueryの最小値-2個だけひっくり返せる
    ll min_val[2] = {n, n};
    for(int i=0; i<q; ++i){
        int a, b;
        cin >> a >> b;
        if(cnt[a-1][b] >= 0){
            ans -= cnt[a-1][b]-2;
        }else{
            ll val = min_val[2-a];
            min_val[a-1] = b;
            for(int j=b; cnt[a-1][j]<0 && j<=n; ++j)cnt[a-1][j]=val;
            ans -= val-2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5144
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int n,m;
	while(cin>>n>>m,n!=0||m!=0){
	int a[1000]={0},ans=0;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n,greater<int>());
		if(n>=m){
			for(int i=0;i<n;i++){
				if((i+1)%m==0){
				a[i]=0;
				}
				}
			}
		for(int i=0;i<n;i++)ans+=a[i];
		cout<<ans<<endl;
	}
	return 0;
}

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


int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { 
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); 
    if (sum >= A && sum <= B) { 
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,T;
    cin >> n >> T;
    int t[n];
    int end = 0;
    int sum = 0;
    for(int i = 0; i < n ; i++){
        cin >> t[i];
        if(end <= t[i])
            sum += T;
        else{
            sum -= t[i-1];
            sum += t[i];
        }
        end = t[i] + T;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
package main

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

func main() {
	a := getString()
	b := getString()

	ans := "H"
	if a == "H" {
		if b == "D" {
			ans = "D"
		}
	} else {
		if b == "H" {
			ans = "D"
		}
	}

	fmt.Println(ans)
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n, k;
    cin >> n >> k;

    if (k % 2 == 0) {
        ll sum = 0;
        if (n - k/2 >= 0) {
            ll m = (n - k/2) / k + 1;
            sum += m * m * m;
        }
        if (n - k >= 0) {
            ll m = (n-k)/k + 1;
            sum += m * m * m;
        }
        put(sum);
    }
    else {
        ll sum = 0;
        if (n - k >= 0) {
            ll m = (n-k)/k + 1;
            sum += m * m * m;
        }
        put(sum);
    }

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

const int N = 1e6+50;


int n, a[N];

int main() {
	scanf("%d",&n);
	REP(i,1,3*n) scanf("%d",a+i);
	sort(a+1,a+1+3*n);
	ll ans = 0;
	REP(i,n+1,3*n) ans += a[i++];
	printf("%lld\n", ans);
}


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

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

    vector<pair<int, int>> arr(n); // deadline, time taken

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        arr[i] = {b, a};
    }
    sort(arr.begin(), arr.end());
    int curr_time = 0;
    for (int i = 0; i < n; i++) {
        if (curr_time + arr[i].second > arr[i].first) {
            cout << "No" << endl;
            return 0;
        }
        curr_time += arr[i].second;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792
# coding=utf-8


get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]


N = get()
A = getss(N)


A.sort(key=lambda a: a[1])
cur = 0
for i, j in A:
    cur += i
    if cur > j:
        print "No"
        exit()

print "Yes"


Measured memory_bytes: 40376
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[25][25],n;
ll dp[(1<<21)];

ll add(ll x, ll y){
	return (x+y)%mod;
}

ll go( ll mask){
	ll men = __builtin_popcount(mask);
	if(men == n) {
		return 1;
	}

	ll &ans = dp[mask]; 
	if(ans!=-1)return ans;

	ans = 0 ;
	for(int i = 1; i<=n; i++){
		if( !( mask&(1<<(i-1)) ) && a[men+1][i] ) {
			ans = add(ans, go(mask|(1<<(i-1)))) ;
		}
	}
	//cout<<men<<" "<<mask<<" "<<ans<<"\n";
	return ans;
}

void solve()
{    
    cin>>n ;
    memset(dp,-1,sizeof dp);
    for(int i=1; i<=n; i++){
    	for(int j=1; j<=n; j++){
    		cin >> a[i][j] ;
    	}
    }

    cout<<  go(0);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}


// Xorawar

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)

ll X,Y,Z;
ll K;
ll A[1005];
ll B[1005];
ll C[1005];
ll AB[1000005];
ll ans[3000005];

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>X>>Y>>Z>>K;

rep(i,X) cin>>A[i];
rep(i,Y) cin>>B[i];
rep(i,Z) cin>>C[i];

ll n=0;
rep(i,X){
	rep(j,Y){
		AB[n]=A[i]+B[j];
		n++;
	}
}

sort(AB,AB+n,greater<ll>());

ll sz=0;
ll nn=0;
rep(i,Z){
	if(n<3000) sz=n;
	else sz=3000;
	rep(j,sz){
		ans[nn]=C[i]+AB[j];
		nn++;
	}
}

sort(ans,ans+nn,greater<ll>());

rep(i,K){
	cout<<ans[i]<<endl;
}

}
	


Measured memory_bytes: 31616
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())
    X = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    X.sort()

    ans = 0
    n = 0
    for a, b in X:
        if n + b >= M:
            ans += (M - n) * a
            break
        else:
            ans += a * b
            n += b

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32504
/*
    A - Still TBD
    https://atcoder.jp/contests/abc119/tasks/abc119_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    string s;
    cin >> s;

    // month : 1X
    if (1 == (s[5] - '0')) {
        cout << "TBD" << endl;
    } else {
        // 00 - 04
        if (0 <= (s[6] - '0') && (s[6] - '0') <= 4) {
            cout << "Heisei" << endl;
        } else {
            cout << "TBD" << endl;
        }
    }
}

Measured memory_bytes: 256