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

const long INF = 10e9+1;

int main() {
    int n; cin >> n;
    vector<long> a(n);
    for(int i = 0; i < n; i ++) cin >> a[i];
    vector<p> b;
    sort(a.begin(), a.end());
    b.push_back(make_pair(a[0],1));
    int bi = 0;
    for(int i = 1; i < n; i++) {
        if(a[i]==a[i-1]) b[bi].second ++;
        else {
            b.push_back(make_pair(a[i],1));
            bi ++;
        }
    }
    long count = 0L;
    for(int i = 0; i < b.size(); i ++) {
        if(b[i].first > b[i].second) count += b[i].second;
        else if(b[i].first < b[i].second) count += b[i].second - b[i].first;
        else continue;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = LLONG_MIN;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    for(int i=0; i<N; i++) {
        int A;
        cin >> A;
        v[--A]++;
    }

    sort(v.rbegin(), v.rend());
    cout << N - accumulate(v.begin(), v.begin()+K, 0) << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<string> { "Sunny", "Cloudy", "Rainy" };
            var input = Console.ReadLine();
            var ans = (list.IndexOf(input) + 1) % list.Count;
            Console.WriteLine(list[ans]);
        }
    }
}


Measured memory_bytes: 13024
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

struct node {
    ll k;
    ll p = -1;
    ll l = -1;
    ll r = -1;
};

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

    int H;
    cin >> H;
    vector<ll> T(3 * H, -INF);
    vector<node> G(H + 5);
    for (int i = 1; i <= H; i++) {
        cin >> T[i];
    }

    for (int i = 1; i <= H; i++) {
        G[i].k = T[i];
        G[i].p = T[i / 2];
        G[i].l = T[2 * i];
        G[i].r = T[2 * i + 1];
    }

    for (int i = 1; i <= H; i++) {
        cout << "node " << i << ": ";
        cout << "key = " << G[i].k << ", ";
        if (G[i].p != -INF)
            cout << "parent key = " << G[i].p << ", ";
        if (G[i].l != -INF)
            cout << "left key = " << G[i].l << ", ";
        if (G[i].r != -INF)
            cout << "right key = " << G[i].r << ", ";
        cout << endl;
    }
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  double i,ans=0,x;
  string u;
  for(i=0;i<n;i++){
    cin >> x;
    cin >> u;
    if(u == "JPY"){
      ans += x;
    }else{
      ans += x * 380000.0;
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
inp = [int(v) for v in input().split(' ')]
L = inp[0]
R = inp[1]

minv = 2020
for i in range(L, min(R + 1, L + 2019)):
    for j in range(i + 1, min(R + 1, i + 1 + 2019)):
        v = (i * j) % 2019
        if v < minv:
            minv = v
print(minv)

Measured memory_bytes: 3060
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}

class unionFind{
  constructor(n){this.a=Array(n+1).fill(-1);}
  root(i){
    return this.a[i]<0?i:this.a[i]=this.root(this.a[i]);
  }
  same(x,y){return this.root(x)===this.root(y);}
  unite(x,y){
    const a=this.a;
    x=this.root(x),y=this.root(y);
    if(x===y)return false;
    if(a[y]<a[x])a[y]+=a[x],a[x]=y;
    else a[x]+=a[y],a[y]=x;
    return true;
  }
  size(i){return -this.a[this.root(i)];}
}

class priorityQueue{
  constructor(){
    this.a=[];
  }
  push(num,inc){
    const a = this.a;
    for(var i = a.length, j; i; i = j){
      j = i - 1 >> 1;
      if(a[j][0] <= num)break;
      a[i] = a[j];
    }
    a[i] = [num,inc];
  }
  pop(){
    const a = this.a, r = a[0], x = a.pop(), k = a.length >> 1;
    for(var i = 0, j; i < k; i = j){
      j = (i << 1) + 1;
      if(a[j+1] && a[j+1][0] < a[j][0])j++;
      if(x[0] <= a[j][0])break;
      a[i] = a[j];
    }
    if(a.length)a[i] = x;
    return r;
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  var n = next();
  var z = [];
  for(var i = 0; i < n; i++){
    z.push([next(),next(),i]);
  }
  z.sort((a,b)=>a[0]-b[0]);
  var uf = new unionFind(n+1);
  var pq = new priorityQueue();
  for(var i = 0; i < n; i++){
    var [x,y,id] = z[i];
    var y2 = y, id2 = id;
    while(pq.size && pq.top[0] < y){
      var [y3,id3] = pq.pop();
      uf.unite(id,id3);
      if(y3 < y2)y2 = y3, id2 = id3;
    }
    pq.push(y2,id2);
  }
  for(var i = 0; i < n; i++){
    print(uf.size(i));
  }
}

Measured memory_bytes: 120008
import sys
n,k=map(int,input().split())
s=str(input())

ans=0
for i in range(n-1):
    if s[i]==s[i+1]:
        ans+=1
count=0        
c='Q'
for i in range(n):
    if s[i]!=c:
        count+=1
        c=s[i]
    else:
        continue
if count==2:
    print(n-1)
elif count%2==0:
    count=count//2
    print(int(ans+min(2*count-1,2*k)))

elif count%2!=0:
    count=count//2
    print(int(ans+min(2*count,2*k)))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	ll sum = 0;
	vector<ll> A(N),B(N);
	vector<pair<ll,int>> v;
	for(int i=0;i<N;i++){
		cin >> A[i] >> B[i];
		sum += A[i] + B[i];
		v.push_back(pair<ll,int>(A[i]+B[i],i));
	}
	sort(ALL(v),greater<>());
	ll Asum = 0;
	for(int i=0;i<N;i++){
		if(i%2==0){
			Asum += A[v[i].second];
		}else{
			Asum -= B[v[i].second];
		}
	}
	cout << Asum << endl;
}

Measured memory_bytes: 3956
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def na4(n,m,l,j,d=0) Array.new(n){Array.new(m){Array.new(l){Array.new(j,d)}}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

l,r = inp
dp = na4(62,2,2,2)
dp[-1][0][0][0] = 1
(1..61).reverse_each do |i|
  (0..1).each do |j|
    (0..1).each do |k|
      (0..1).each do |s|
        t = [[0,0],[0,1],[1,1]]
        t.each do |nx,ny|
          nj,nk,ns = j,k,s
          next if(s == 0 and nx != ny)
          ns = 1 if(nx == 1)
          next if(r[i-1]< ny and k == 0)
          nk = 1 if(r[i-1]> ny)
          next if(nx<l[i-1] and j == 0)
          nj = 1 if(l[i-1]< nx)
          dp[i-1][nj][nk][ns] += dp[i][j][k][s]
        end
      end
    end
  end
end
p dp[0].flatten.inject(:+)%(10**9+7)

Measured memory_bytes: 1788
K = [int(i) for i in input().split()][0]
A, B = [int(i) for i in input().split()]
is_ok = False
for i in range(A, B+1):
  if i % K == 0:
    is_ok = True
if is_ok:
  print("OK")
else:
  print("NG")

Measured memory_bytes: 9200
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int WIDTH = 4;
const int MAX_N = WIDTH * WIDTH;

typedef pair<int,int> mask; // (ツづ環づつスツ閉板閉ェツ、ツづつアツづーツ塗ツづゥツつゥ)

int N;
int hs[MAX_N], ws[MAX_N];
char goal[WIDTH][WIDTH + 1];
int dist[1<<(WIDTH * WIDTH)];
bool visited[1<<(WIDTH * WIDTH)];

int solve(){
	vector<mask> masks;

	const char colors[] = "RGB";
	//ツ前ツ渉按猟敖づ全ツづづ個マツスツクツづーツ仰づ淞づつィツつュ
	for(int k=0; k<N; k++){
		for(int col=0; col<3; col++){
			for(int y=-4; y<4; y++){
				for(int x=-4; x<4; x++){
					int correct = 0, remain = (1<<(WIDTH * WIDTH)) - 1;
					for(int i=0; i<4; i++){
						for(int j=0; j<4; j++){
							if(y <= i && i < y + hs[k] && x <= j && j < x + ws[k]){
								remain ^= 1 << (i * 4 + j);
								if(goal[i][j] == colors[col]){
									correct |= 1 << (i * 4 + j);
								}
							}
						}
					}
					masks.push_back( make_pair(correct, remain) );
				}
			}
		}
	}

	sort(masks.begin(), masks.end());
	masks.erase(unique(masks.begin(), masks.end()), masks.end());

	visited[0] = true;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int tp = que.front(); que.pop();

		for(int i=0; i<(int)masks.size(); i++){
			int next = masks[i].first | (masks[i].second & tp);
			if(!visited[next]){
				dist[next] = dist[tp] + 1;
				visited[next] = true;
				que.push(next);
			}
		}
	}

	return dist[(1<<(WIDTH*WIDTH) ) - 1];
}

int main(){
	scanf("%d",&N);
	for(int i=0; i<N; i++){
		scanf("%d%d ",hs+i, ws+i);
	}
	for(int i=0; i<4; i++){
		scanf("%[^\n]%*c", goal[i]);
	}

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

	return 0;
}

Measured memory_bytes: 0
#include <algorithm> 
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;
int n,k;

int check(int x)
{
	int qwq=1;
	while (x<k)
	{
		x*=2;
		qwq*=2;
	}
	return qwq;
}
int main()
{
	
	scanf("%d%d",&n,&k);
	double ans;
	for (int i=1;i<=n;i++)
	{
		ans+=(1.000000000000000/check(i)*1.0000000000000000000/n*1.00000000000000000);
	}
	printf("%.12lf",ans*1.00000000000000000);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  string a; cin>>a;
  if(a[0]!=a[1] && a[1]!=a[2]){
    if(a[2]!=a[3]) cout<<"Good"<<endl;
    else cout<<"Bad"<<endl;
  }
  else cout<<"Bad"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  long int n,a,b,i,cnt=0;
  scanf("%ld %ld %ld",&n,&a,&b);
  if(a>b) cnt=0;
  else if(n==1){
    if(a!=b) cnt=0;
    else cnt=1;
  }
  else cnt=(b-a)*(n-2)+1;
  printf("%ld",cnt);
  return 0;
}

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

int main()
{
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> c[i][j];
    }
  }

  int d1 = c[0][0] - c[0][1];
  int d2 = c[0][1] - c[0][2];
  
  for (int i = 1; i < 3; i++)
  {
    if (d1 != c[i][0] - c[i][1] || d2 != c[i][1] - c[i][2])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  d1 = c[0][0] - c[1][0];
  d2 = c[1][0] - c[2][0];

  for (int i = 1; i < 3; i++)
  {
    if (d1 != c[0][i] - c[1][i] || d2 != c[1][i] - c[2][i])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import math

S = input()
N = len(S)

cntl = []
tmp = S[0]
cnt = 1
for i in range(1,N):
  if tmp == S[i]:
    cnt += 1
  else:
    cntl.append(cnt)
    cnt = 1
    tmp = S[i]
else:
  cntl.append(cnt)

SUM = cntl[0]
ans = max(N-cntl[0],N-cntl[-1])
for i in range(1,len(cntl)-1):
  ans = min(ans,min(N-SUM,SUM+cntl[i]))
  SUM += cntl[i]
"""
if ans == 0:
  print(N)
else:
  print(ans)
"""
SSUM = 0
for i in cntl:
  SSUM += i
  if SSUM >= math.ceil(N/2):
    print(min(SSUM,N-(SSUM-i)))
    break

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

int main(){
  int n,x;
  cin>>n;
  vector<int> V;
  for(int i=0; i<n; i++){
    cin>>x;
    V.push_back(x);
  }
  int count=0;
  for(int i=1; i<n-1; i++){
    if((V[i]>V[i-1] && V[i]<V[i+1]) || (V[i]<V[i-1] && V[i]>V[i+1]) ){
      count++;
    }
  }
  cout<<count<<endl;
}

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

using namespace std;

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

int main(){
	int n;cin >> n;
	REP(i, n){
		REP(j, n){
			if(i >= j)continue;
			for(int k = 30;k >= 0;k--){
				if((i & (1 << k)) != (j & (1 << k))){
					cout << (k + 1) << " ";
					break;
				}
			}
		}
		cout << endl;
	}

	return 0;
}


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

int main(){
	int n,m; cin>>n>>m;
	bool ok = false;
	for(int i=1; i<=1250 && !ok; i++){
		int p1 = (i*8)/100;
		int p2 = i/10;
		if(p1 == n && p2 == m ){
			ok=1;
			cout<<i<<'\n';
		}
	}
	if(ok==0)cout<<-1<<endl;
}


Measured memory_bytes: 3604
n, k = map(int, input().split())
lst = []
for i in range(n):
  lst.append(int(input()))
lst.sort()
res = 10 ** 9
for i in range(n - k + 1):
  temp = lst[i + k - 1] - lst[i]
  if temp < res:
    res = temp
print(res)

Measured memory_bytes: 80884
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9+7;
int mod_pow(int x,int y,int INF) {
    int res = 1;
    while(y > 0) {
        if(y%2) {
            res = res*x%INF;
        }
        x = x*x%INF;
        y/=2;
    }
    return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)
		return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod ;
}
signed main() {
	int n,a,b;cin>>n>>a>>b;
	int ans=mod_pow(2,n,mod)-1;
	ans-=comb(n,a);ans=(ans+mod)%mod;
	ans-=comb(n,b);ans=(ans+mod)%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cassert>
#include <numeric>
using namespace std;

int main () {
  long long N, K;
  cin >> N >> K;
  long long max_ = 0;
  long long gcd_ = 0;
  for (long long i = 0; i < N; i++){
    long long a;
    cin >> a;
    if (i == 0) gcd_ = a;
    else gcd_ = gcd(a, gcd_);
    max_ = max(a, max_);
  }
  if (K <= max_ && K % gcd_ == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <vector>
#define MAX 11
#define rep(i, n) for (int i = 1; i < (n); i++)
using namespace std;

int main() {
    int r, D, algae = 0;
    vector<int> x(MAX);
    scanf("%d %d %d", &r, &D, &algae);
    
    x[0] = algae;
    rep(i, MAX) {
      x[i] = r*(x[i-1]) - D;
      printf("%d\n", x.at(i));
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll k,A[200000],a=2,b=2;
    cin>>k;
    rep(i,k) cin>>A[i];
    reverse(A,A+k);
    rep(i,k){
        if(a%A[i]) a=((a+A[i])/A[i])*A[i];
        b=(b/A[i]+1)*A[i]-1;
    }
    if(a<=b) cout<<a<<" "<<b;
    else cout<<-1;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1')cout<<9;
        else if(s[i]=='9')cout<<1;
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int n, a, b;
  int ans;
  
  cin >> n >> a >> b;
  
  ans = min(n*a, b);
  
  cout << ans << endl;
  return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  LL tot;
  cin >> tot;
  LL cur = 100, ans = 0;
  while (cur < tot) {
    cur += cur/100;
    ans++;
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

int x,y;

int main () {
	cin >> x >>y;
if (x==1 || x==3 || x==5||x==7||x==8||x==10||x==12) {
	if (y==1 || y==3 || y==5||y==7||y==8||y==10||y==12) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
} else if(x==2) {
	if (y==2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
} else {
	if (y==4||y==6||y==9||y==11) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
//semoga bisa wkwkwkwk
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

const int MOD = 1e9 + 7;
int H, W;
char board[1001][1001];
int dp[1000][1000];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> board[i];
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++) {
			if (i == 0 && j == 0) dp[i][j] = 1;
			else if (board[i][j] == '.') {
				if (i - 1 >= 0)dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
				if (j - 1 >= 0)dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
			}
		}
	cout << dp[H - 1][W - 1] << '\n';
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	string s;cin>>s;
	sort(s.begin(),s.end());
	REP(i,0,s.length()-1){
		if(s[i]==s[i+1]){
			cout<<"no";
			return 0;
		}
	}
	cout<<"yes";
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 256
require 'prime'

prime = Prime.each(2*10**5)
c = Array.new(2*10**5, 0)
l=[], r=[]
Q = gets.to_i
Q.times do |i|
	l[i], r[i] = gets.split.map(&:to_i)
end

isPrime = Array.new(2*10**5, false)
prime.each do |i|
	isPrime[i] = true
end

j = 1
while j < 100000
	c[j] += 1 if isPrime[j] && isPrime[(j+1)/2]
	j +=2
end

1.upto(100000) do |i|
	c[i] += c[i-1]
end

Q.times do |i|
	puts c[r[i]]-c[l[i]-1]
end

Measured memory_bytes: 7900
#include <stdio.h>

int main (int argc, char* argv[]) {
  int m[3];
  for (int i = 0; i < 3; i++) {
    scanf("%d",&m[i]);
  }

  int min = m[0]+m[1];
  for (int i = 0; i < 3; i++) {
    for (int j = i+1; j < 3; j++) {
      if (m[i] + m[j] <= min) {
	min = m[i] + m[j];
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long const MAX= 1e9 + 7;
int main()
{long long t,i,n,k,j;
cin>>n>>k;
long long a[n+1];
long long dp[n+1];
for(i=1;i<=n;i++)
{dp[i]=MAX;}
for(i=1;i<n+1;i++)
{cin>>a[i];}
dp[1]=0;
a[0]=0;
for(j=1;j<=n;j++)
{   for(i=1;i<=k;i++){
    if(j+i<=n)
 dp[j+i]=min(dp[j+i],dp[j]+abs(a[j+i]-a[j]));}
}   
cout<<dp[n];
return 0;}


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

long long K, N;
long long A[200005];
// i -> i + 1
long long diff[200005];

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

	for(long long i = 0; i < N - 1; i++) {
		diff[i] = A[i+1] - A[i];
	}
	//i = N-1
	diff[N-1] = A[0] + K - A[N-1];


	long long sumi = 0;
	long long maxi = 0;
	for(long long i = 0; i < N; i++) {
		sumi += diff[i];
		maxi = max(maxi, diff[i]);
	}
	cout << sumi - maxi << endl;





}

Measured memory_bytes: 6736
x = list(input())
if 'N' in x and 'S' in x:
  if 'E' in x and 'W' in x:
    print('Yes')
  elif 'E' not in x and 'W' not in x:
    print('Yes')
  else:
    print('No')
elif 'N' not in x and 'S' not in x:
  if 'E' in x and 'W' in x:
    print('Yes')
  elif 'E' not in x and 'W' not in x:
    print('Yes')
  else:
    print('No')
else:
  print('No')

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,m;cin>>n>>m&&n|m;){
		vi a(n);
		rep(i,n) cin>>a[i],a[i]--;

		ll res=0;
		vl b(2*m+2);
		rep(i,n-1){
			int l=a[i],r=a[i+1];
			if(l>r) r+=m;
			res+=r-l;
			if(r-l<2) continue;
			b[l+2]++;
			b[r+1]-=(r-l);
			b[r+2]+=(r-l-1);
		}
		rep(i,2*m) b[i+1]+=b[i];
		rep(i,2*m) b[i+1]+=b[i];
		rep(i,m) b[i]+=b[i+m];
		b.erase(m+all(b));

		cout<<res-*max_element(all(b))<<endl;
	}
}


Measured memory_bytes: 2176
using System;

namespace AtCoder {
    class Program {
        static void Main() {
            int x = int.Parse(Console.ReadLine());
            int a = (int) Math.Ceiling(Math.Pow(x, 0.2));
            int b = 0;
            while(a*a*a*a*a + b*b*b*b*b != x) {
                if(a*a*a*a*a + b*b*b*b*b > x) {
                    a--;
                } else {
                    b++;
                }
            }
            Console.WriteLine($"{a} {-b}");
        }
    }
}

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

int main()
{
    int r, D, x2000;
    cin >> r >> D >> x2000;
    vector<int> x(11);
    x[0] = x2000;
    for (int i = 1; i <= 10; i++)
    {
        x[i] = r * x[i - 1] - D;
    }
    for (int i = 1; i <= 10; i++)
        cout << x[i] << endl;
    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long i64;
typedef pair<i64, i64> pii;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

#define mod 1000000007

i64 power(i64 x, i64 n, i64 M) {
  if (!n) return 1;
  if (n % 2 == 0) {
    i64 t = power(x, n / 2, M);
    return t * t % M;
  }
  return x * power(x, n - 1, M) % M;
}

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  cout << k * power(k - 1, n - 1, mod) << "\n";

  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;
	
	ll a,b,c,d;
	cin>>a;
	(a%2)?cout<<a*2:cout<<a;
}

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

int main()
{
	int n;
	string s;
	int a[26];
	long long m = 1;

	cin >> n >> s;
	memset(a, 0, sizeof(a));

	for (int i = 0; i < n; i++)
		a[s[i] - 'a']++;

	for (int i = 0; i < 26; i++)
		m = (m * (a[i] + 1)) % 1000000007;

	cout << m - 1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

string beautify(string str) {
	string ret = "";
	for (int i = 0; i < str.size(); ++i) {
		char c = str[i];
		if ('a' <= c && c <= 'z') ret += c;
		else if ('A' <= c && c <= 'Z') ret += (char)(c-'A'+'a');
	}
	return ret;
}

int main() {
	int n; cin >> n;
	int x[100], y[100];
	for (int i = 0; i < n; ++i) cin >> x[i];
	for (int i = 0; i < n; ++i) cin >> y[i];

	for (int p = 1; p <= 3; ++p) {
		double d = 0;
		for (int i = 0; i < n; ++i) {
			d += pow( abs(x[i] - y[i]), p );
		}
		d = pow(d, 1.0/p);
		printf("%.10f\n", d);
	}
	{
		double d = 0;
		for (int i = 0; i < n; ++i) {
			d = max(d, (double)abs(x[i] - y[i]));
		}
		printf("%.10f\n", d);
	}
}

Measured memory_bytes: 1256
#include <stdio.h>
#include <iostream>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
#include <string.h>
#define mem(x,b) memset(x,b,sizeof(x))
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<a<<endl
#define maxn 200005
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
int a[maxn];
int main()
{
    int a;
    scanf("%d",&a);
    printf("%d\n",a+a*a+a*a*a);
    return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    ll sum = 0;
    for (ll i = 1; i <= n-1; ++i) {
        sum += i;
    }
    cout << sum << endl;
    return 0;
}


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

int main(){
  long int ab;
  long int a,b;
  cin >> a >> b;
  
  ab = a * b;
  
  if(a < b){
    long int tmp = a;
    a = b;
    b = tmp;
  }
 
  long int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  cout << ab/b;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a_list = list(map(int,input().split()))

dic = dict(Counter(a_list))

ret = 0
for k,v in dic.items():
    ret += v * (v-1) // 2

for j in a_list:
    n = dic[j]
    if n == 1:
        print(ret)
    else:
        print(ret - (n * (n - 1) // 2) + ((n - 1) * (n - 2) // 2))

Measured memory_bytes: 26772
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int f(int n) {
		if (n % 2 == 0) {
			return n / 2;
		} else {
			return 3 * n + 1;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);
		int s = sc.nextInt();

		int[] a = new int[1000000];

		a[s] = 1;
		int i, i_1 = s;
		int n = 1;
		for (;;) {
			i = f(i_1);
			n++;
			if (a[i] == 1) {
				out.println(n);
				break;
			}
			a[i] = 1;
			i_1 = i;
		}

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

int dp[1005][10005];
const int INF = 1001001001;

int main() {
    int h, n;
    cin >> h >> n;
    rep(i,1005)rep(j,10005) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n) dp[i][0] = 0;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        rep(j,h+1) {    
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+a, h)], dp[i+1][j] + b);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 42912
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.wdt", "r", stdin);
	// 2004/01/01 is Thursday
	const string week[] = {
	"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
	const int days[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 
	string str = "";
	
	while (1){
		int month = 0;
		int day = 0;		
		cin >> month >> day;
		if (month == 0 && day == 0){
			break;
		} // end if
		int num = 0;
		for (int i = 0; i < month; ++i){
			num += days[i];
		} // end for
		num += day;
		cout << week [( num - 1 + 3 ) % 7 ] << endl;
	} // end while
		
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

char outFile[128][128];
int patSize; 
int logx, logy;

void makeSpin(int dir, int ty, int tx)
{
	int i, j;
	int dy[] = {-1, 0, 1, 0};
	int dx[] = {0, 1, 0, -1};
	logy = ty;
	logx = tx;
	outFile[ty][tx] = '#';

	for (i = dir; i < dir + 4; i++){
		j = i % 4;
		if (ty + dy[j] > 0 && ty + dy[j] < patSize + 1 && tx + dx[j] > 0 && tx + dx[j] < patSize + 1 && 
				outFile[ty + dy[j]][tx + dx[j]] != '#' && outFile[ty + 2 * dy[j]][tx + 2 * dx[j]] != '#'){
			makeSpin(j, ty + dy[j], tx + dx[j]);
			return;
		}
	}
}	

int main(void)
{
	int testNum;
	int i, j;
	int flag;
	
	scanf("%d", &testNum);
	
	flag = 0;
	while (testNum--){
		scanf("%d", &patSize);
		
		memset(outFile, ' ', sizeof(outFile));
		
		makeSpin(0, patSize, 1);

		if (patSize % 2 == 0){
			outFile[logy][logx] = ' ';
		}

		if (flag++){
			puts("");
		}

		for (i = 1; i <= patSize; i++){
			for (j = 1; j <= patSize; j++){
				printf("%c", outFile[i][j]);
			}
			puts("");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int main(){
	int N;
	cin>>N;
	vector<ll> A(N),B(N);
	rep(i,N) cin>>A[i]>>B[i];
	ll ans = 1e18;
	{
		ll Asum = 0;
		rep(i,N) Asum += A[i];
		chmin(ans,Asum);
		ll Bsum = 0;
		rep(i,N) Bsum += B[i];
		chmin(ans,Bsum);
	}
	vector<bool> used(2*N);
	using P = pair<ll,int>;
	vector<P> vi;
	rep(i,N){
		vi.pb(P(A[i],i));
		vi.pb(P(B[i],i+N));
	}
	sort(all(vi));
	ll sum = 0;
	rep(i,N){
		int x = vi[i].sc;
		sum += vi[i].fs;
		used[x] = 1;
	}
	bool allone = 1;
	rep(i,N){
		if(!(used[i]^used[i+N])) allone = 0;
	}
	if(allone){
		ll inf = 1e17;
		ll Ausedmx = -inf,Aunusedmn=inf,Busedmx=-inf,Bunusedmn=inf;
		rep(i,N){
			if(used[i]){
				chmax(Ausedmx,A[i]);
			}else{
				chmin(Aunusedmn,A[i]);
			}
			if(used[i+N]){
				chmax(Busedmx,B[i]);
			}else{
				chmin(Bunusedmn,B[i]);
			}
		}
		if(Ausedmx == -inf || Busedmx == -inf){

		}else{
			ll dif = 1e18;
			rep(i,N){
				ll tmp = 0;
				if(used[i]){	//add B
					tmp += B[i];
					int x = vi[N-1].sc;
					if(x == i){
						x = vi[N-2].sc;
					}
					ll dec = x<N ? A[x] : B[x-N];
					tmp -= dec;
					chmin(dif,tmp);
				}else{
					tmp += A[i];
					int x = vi[N-1].sc;
					if(x == i+N){
						x = vi[N-2].sc;
					}
					ll dec = x<N ? A[x] : B[x-N];
					tmp -= dec;
					chmin(dif,tmp);					
				}
			}
			sum += dif;
		}
	}
	chmin(ans,sum);
	cout<<ans<<endl;
}

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
    long int n,k;
   scanf("%ld%ld",&n,&k);
   long int a[n],i,sum=0;
   for(i=0;i<n;++i)
        scanf("%ld",&a[i]);
   
   sort(a,a+n);
   long int ans=n-k;
   for(i=0;i<n-k;++i)
   {
     sum+=a[i];
   }
   
   printf("%ld",sum);
 
	return 0;
}

Measured memory_bytes: 1792
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    std::cin >> s;
    ll a,b,c;
    a = b= c = 0;
    for (int i = 0; i < s.length(); i++) {
        if(s[i] == 'a'){
            a++;
        }else if(s[i]=='b'){
            b++;
        }else{
            c++;
        }
    }
    ll m = min({a,b,c});
    // a,b,c,a,b,c,a,b,c,みたいになりそう
    if(a-m>= 2 || b-m>= 2 || c-m >= 2){
        std::cout << "NO" << std::endl;
    }else{
        std::cout << "YES" << std::endl;
    }
}


Measured memory_bytes: 512
#include <stdio.h>



int main()
{
	int a,b;
	scanf("%d%d", &a,&b);
	if(a<0&&b>0){
		//输出为zero 
		printf("Zero\n");
	}
	else if(a==0 || b == 0){
		//输出为zero 
		printf("Zero\n");
	} 
	else if(a>0&&b>0){
		//Positive
			printf("Positive\n");
	}
	else{
		int i;
		int sum=0;
		for(i=a;i<=b;i++){
			if(i<0) sum++;
		}
		if(sum%2==0){
			//Positive
			printf("Positive\n");
		}
		else{
			printf("Negative\n");
		}
	}
	
	return 0;	
}  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n,m,x[100005],a[100005],s;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    if (n>=m) rc(0);
    fort (i,m)
        cin >> x[i];
    sort (x+1,x+m+1);
    fort (i,m-1)
        a[i]=x[i+1]-x[i], s+=a[i];
    sort (a+1,a+m);
    fort (i,n-1)
        s-=a[m-i];
    cout << max(s,0ll);
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll n;cin>>n;
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    string res="";
    while(n){
        if(n%2==0){
            n /= -2;
            res += "0";
        }
        else{
            n -= 1;
            n /= -2;
            res += "1";
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
}


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

int n,m,a[52][52];
char c;

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>c;
            if(c=='#')
            {
                a[i][j]=-10;
                a[i-1][j-1]++;
                a[i-1][j]++;
                a[i-1][j+1]++;
                a[i][j-1]++;
                a[i][j+1]++;
                a[i+1][j-1]++;
                a[i+1][j]++;
                a[i+1][j+1]++;
            }
        }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            if(a[i][j]<0)cout<<"#";
            else cout<<a[i][j];
        cout<<endl;
    }   
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll K;
	cin >> K;
	vector<ll> a(50, 0);
	if (0 < K) {
		ll sum = K / 50;
		ll amari = K % 50;
		REP(i, 50) {
			a[i] = i + sum;
		}
		REP(i, amari) {
			a[49 - i]++;
		}
	}

	cout << 50 << endl;
	REP(i, 50) {
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}


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


typedef long long ll;
template<class V, int NV> class SegTree {
public:
	static V const def = (1LL << 31) - 1;
	V comp(V l, V r) { return min(l, r); };

	vector<V> val;
	SegTree() { val = vector<V>(NV * 2, def); }

	V getval(int l, int r) { //[l,r]
		l += NV; r += NV + 1;
		V ret = def;
		while (l < r) {
			if (l & 1) ret = comp(ret, val[l++]);
			if (r & 1) ret = comp(ret, val[--r]);
			l /= 2; r /= 2;
		}
		return ret;
	}
	void update(int i, V v) {
		i += NV;
		val[i] = v;
		while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
	}
};
//-----------------------------------------------------------------
int N;
int a[201010];
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &a[i]);

	SegTree<int, 1 << 20> st;
	rep(i, 0, N) st.update(i, a[i]);

	ll ans = 0;
	rep(i, 0, N) {
		int left, right;
		int l, r;

		l = -1;
		r = i;
		while (l + 1 != r) {
			int mid = (l + r) / 2;
			if (st.getval(mid, i) == a[i])
				r = mid;
			else
				l = mid;
		}
		left = r;

		l = i;
		r = N;
		while (l + 1 != r) {
			int mid = (l + r) / 2;
			if (st.getval(i, mid) == a[i])
				l = mid;
			else
				r = mid;
		}
		right = l;

		ans += (ll)a[i] * (ll)(i - left + 1) * (ll)(right - i + 1);
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 9344
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]int, n)
	bs := make([]int, n)
	cs := make([]int, m)
	ds := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i], &bs[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&cs[i], &ds[i])
	}

	for i := 0; i < n; i++ {
		d := math.MaxInt32
		var ans int
		for j := 0; j < m; j++ {
			md := abs(as[i]-cs[j]) + abs(bs[i]-ds[j])
			if md < d {
				d = md
				ans = j + 1
			}
		}
		fmt.Println(ans)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1840
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
s = []
ans = []
for i in range(1,n+1):
    for j in range(a[i-1]):
        s.append(i)
for i in range(h):
    ans.append(s[i*w:(i+1)*w])
for i in range(h):
    if i%2==0:
        print(*ans[i])
    else:
        print(*ans[i][::-1])

Measured memory_bytes: 42224
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char s[15],t[15];
int main(){
	cin>>s>>t;
	int lens=strlen(s),poss=1;
	for(int i=0;i<lens;i++)
		if(s[i]!=t[i]) poss=0;
	if(!poss) printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 3660
use std::io::BufRead;
fn main() {
    let handle = std::io::stdin();
    loop {
        let mut cards = String::new();
        handle.lock().read_line(&mut cards).unwrap();
        cards.pop();
        if cards == "-" { break; }
        let mut num_str = String::new();
        handle.lock().read_line(&mut num_str).unwrap();
        let num = num_str.trim().parse().unwrap();
        for _ in 0..num {
            num_str.clear();
            handle.lock().read_line(&mut num_str).unwrap();
            let sheets = num_str.trim().parse().unwrap();
            for _ in 0..sheets {
                let c = cards.remove(0);
                cards.push(c);
            }
        }
        println!("{}", cards);
    }
}


Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"

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

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n, W;
ll w[110], v[110];

ll dp[110][100010];

int main(void){
	cin>>n>>W;
	for(int i=0;i<n;i++) cin>>w[i]>>v[i];

	for(int i=0;i<n;i++) {
		for(int j=0;j <= W; j++) {
			if(j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			} else {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
		}
	}

	printf("%lld\n", dp[n][W]);

	return 0;
}

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

struct UnionFind{
    vector<int> p;
    vector<int> r;
    vector<int> s;

    UnionFind(int n){
        p.resize(n, -1);
        r.resize(n, 1);
        s.resize(n, 1);
    }

    int find(int x){
        if(p[x] == -1) return x;
        else return p[x] = find(p[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);

        if(x == y) return;
        if(r[x] > r[y]) swap(x, y);
        if(r[x] == r[y]) ++r[y];

        p[x] = y;
        s[y] += s[x];
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

ll calcsm(ll n){
    return n*(n-1)/2;
}

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

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

    vector<int> a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }

    vector<ll> res(m, 0);
    res[m-1] = calcsm(n);

    UnionFind uf(n);
    for(int i = m-1; i>0; --i){

        if(uf.same(a[i], b[i])) res[i-1] = res[i];
        else{
            ll before_a = uf.s[uf.find(a[i])];
            ll before_b = uf.s[uf.find(b[i])];

            uf.unite(a[i], b[i]);
            ll after = uf.s[uf.find(a[i])];

            res[i-1] = res[i] + calcsm(before_a) + calcsm(before_b) - calcsm(after);
        }
    }

    rep(i, m) cout << res[i] << endl;

    return 0;
}

Measured memory_bytes: 6096
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<ll, ll> pr;
bool f[100001];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(a,b)<<" "<<max(a+b-n,0);
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int A[n];
  for(int i = 0; i < n; i++){
	cin >> A[i];
  }
  
  for(int i = 0; i < n; i++){
    if(A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0){
      cout << "DENIED";
      break;
    }
    if(i == (n-1)){
      cout << "APPROVED";
    }
  }
}

Measured memory_bytes: 256