akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

// Bit Indexed Tree
template <typename T>
struct BIT {
  std::vector<T> dat;

  BIT(int n) : dat(n + 1, 0) {}
  void init(int n) { dat.assign(n + 1, 0); }

  inline void add(int a, T x) {
    for (auto i = a; i < dat.size(); i += i & -i) {
      dat[i] += x;
    }
  }

  // partial sum of [1,to) (1-origin).
  inline T sum(int to) {
    T ret{0};
    for (auto i = to; i > 0; i -= i & -i) {
      ret += dat[i];
    }
    return ret;
  }

  // partial sum of [from,to) (1-origin).
  inline T sum(int from, int to) { return sum(to - 1) - sum(from - 1); }

  // find index at which a_1 + ... + a_i >= w
  int lower_bound(T w) {
    if (w <= 0) {
      return 0;
    } else {
      int x = 0, r = 1;
      while (r < dat.size()) r <<= 1;
      for (auto len = r; len; len >>= 1) {
        if(x+len < dat.size() && dat[x+len] < w) {
          w -= dat[x+len];
          x += len;
        }
      }
      return x + 1;
    }    
  }

  // print all 
  void print() {
    for (auto i = 1; i < dat.size(); ++i) {
      std::cout << (i == 1 ? "" : ", ") << sum(i, i + 1);
    }
    std::cout << std::endl;
  }
};


int main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> c(N);
  for (int &x: c) cin >> x;
  vector<pair<int,int>> q(Q);
  vector<int> ans(Q), ind(Q);
  iota(begin(ind),end(ind),0);
  for (auto &[l,r]: q) cin >> l >> r;
  sort(begin(ind),end(ind),
       [&q](int x, int y) {return q[x].second < q[y].second;});
  vector<int> last(N);
  int lastR{};
  BIT<int> b(N+1);
  for (int i = 0; i != Q; ++i) {
    int R = q[ind[i]].second;
    if (R > lastR) {
      for (int j = lastR; j < R; ++j) {
        if (last[c[j]]) b.add(last[c[j]],-1);
        last[c[j]] = j+1;
        b.add(last[c[j]],1);
      }
      lastR = R;
    }
    ans[ind[i]] = b.sum(q[ind[i]].first,q[ind[i]].second);
  }
  for (int x: ans) cout << x+1 << endl;
}


Measured memory_bytes: 17376
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	cout << n * n;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int D;
  int64_t G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }

  int ans = 10000;
  for (int i = 0; i < (1 << D); i++) {
    int64_t tmp = 0;
    int solved = 0;
    vector<int> used(D);
    for (int j = 0; j < D; j++) {
      if ((i >> j) & 0x1) {
        tmp += (j + 1) * 100 * p[j] + c[j];
        solved += p[j];
        used[j] = 1;
      }
    }
    bool found = tmp >= G;
    if (!found) {
      int j = used.size() - 1;
      for (; j >= 0; j--) {
        if (!used[j]) break;
      }
      const int score = (j + 1) * 100;
      for (int k = 1; k < p[j]; ++k) {
        tmp += score;
        solved++;
        if (tmp >= G) {
          found = true;
          break;
        }
      }
    }

    if (found) {
      ans = min(ans, solved);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>cnt;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,i,j,k,l;

    ll sum=0LL,a,m,x;
    cin >> n >> m;
    cnt[0] = 1LL;
    ll ans = 0LL;
    for(i=1;i<=n;i++)
    {
        cin >> a;
        sum += a;
        x = sum%m;
        ans += cnt[x];
        cnt[x]++;

    }
    cout << ans << endl;
}


Measured memory_bytes: 7556
N = int(input())
X = [0]*N
L = [0]*N
Y = []

for i in range(N):
    X, L = map(int, input().split())
    Y.append([X+L, X-L])

Y.sort()

count = 0
length = -10**10
for i in range(N):
    if Y[i][1] >= length:
        count += 1
        length = Y[i][0]

print(count)


Measured memory_bytes: 20020
#include<stdio.h>
int main(void){
    int i,y=0,e=0,g,m=0,q,z=0,de,r[100][6]={0},f[100][6]={0},as=0,u=0,x=0,j=0,v=0;
    scanf("%d",&x);
    for(de=0;de<x;de++){
	    for(i=0;i<6;i++){
	    	scanf("%d",&r[de][i]);
	    }
    }

    for(de=0;de<x;de++){
	    memcpy(f[de],r[de],6);
    }
   de=0;
   for(de=0;de<x;de++){
	    for(g=0;g<200;g++){
	    	m=0;
	    	u=0;
	    	while(r[de][0]!=r[0][0]||r[de][5]!=r[0][5]){
		    	u=r[de][0];
		    	r[de][0]=r[de][4];
		    	r[de][4]=r[de][5];
		    	r[de][5]=r[de][1];
		    	r[de][1]=u;
		    	m++;
		    	if(m==4){
		    		v=0;
		    		while(r[de][0]!=r[0][0]||r[de][5]!=r[0][5]||v<7){
		    	u=r[de][0];
		    	r[de][0]=r[de][2];
		    	r[de][2]=r[de][5];
		    	r[de][5]=r[de][3];
		    	r[de][3]=u;
		    	v++;
		    	if(v==7)break;
		    		}if(v==7)break;
		    	if(m==7){
		    		break;
		    	}
	    	}
	    	}
	    	y=0;
	    	u=0;
	  	  while(r[de][1]!=r[0][1]||r[de][4]!=r[0][4]){
		    	u=r[de][1];
		    	r[de][1]=r[de][2];
		    	r[de][2]=r[de][4];
		    	r[de][4]=r[de][3];
		    	r[de][3]=u;
		    	y++;
		    	if(y==20)break;
		    	if(y==7){
		    		as=0;
		    		while(r[de][0]!=r[0][0]&&r[de][5]!=r[0][5]){
		    	u=r[de][0];
		    	r[de][0]=r[de][4];
		    	r[de][4]=r[de][5];
		    	r[de][5]=r[de][1];
		    	r[de][1]=u;
		    	as++;
		    	if(as>20)break;
		    		}
		    		if(as>20)break;
		    	}
	   	 }
	   	 	y=0;
	   	 	u=0;
	  	  while(r[de][1]!=r[0][1]&&r[de][5]!=r[0][5]){
		    	u=r[de][1];
		    	r[de][1]=r[de][2];
		    	r[de][2]=r[de][4];
		    	r[de][4]=r[de][3];
		    	r[de][3]=u;
		    	y++;
		    	if(y==20)break;
		    	if(y==7){
		    		as=0;
		    		while(r[de][0]!=r[0][0]&&r[de][5]!=r[0][5]){
		    	u=r[de][0];
		    	r[de][0]=r[de][4];
		    	r[de][4]=r[de][5];
		    	r[de][5]=r[de][1];
		    	r[de][1]=u;
		    	as++;
		    	if(as>20)break;
		    		}if(as>20)break;
		    	}
	   	 }
	    }
   }
  
   for(de=1;de<x;de++){
	if(r[0][0]==r[de][0]&&r[0][1]==r[de][1]&&r[0][2]==r[de][2]&&r[0][3]==r[de][3]&&r[0][4]==r[de][4]&&r[0][5]==r[de][5])
	{
		j++;
	}
   }
   if(j>0){
   		printf("No\n");
   }else{
   	printf("Yes\n");
   }
    return 0;
}

Measured memory_bytes: 584
using System;

namespace ABC124
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int b = int.Parse(input[0]);
            int c = int.Parse(input[1]);

            int maxValue = 0;

            for (int i = 0; i < 2; i++){
                if (b >= c)
                {
                    maxValue += b;
                    b--;
                }
                else
                {
                    maxValue += c;
                    c--;
                }
            }

            Console.WriteLine(maxValue);
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <stdbool.h>

#define N 8
#define FREE 1
#define NOT_FREE -1

int row[N],col[N],dpos[2 * N - 1],dneg[2 * N - 1];
bool X[N][N];

void initialize(void){
  int i;
  for(i = 0;i < N;i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i = 0;i < 2 * N - 1;i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printBoard(void){
  int i,j;

  for(i = 0;i < N;i++){
    for(j = 0;j < N;j++){
      if(X[i][j]){
	if(row[i] != j){
	  return;
	}
      }
    }
  }

  for(i = 0;i < N;i++){
    for(j = 0;j < N;j++){
      if(row[i] == j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}


void recursive(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }

  for(j = 0;j < N;j++){
    if(col[j] == NOT_FREE || dpos[i + j] == NOT_FREE || dneg[i + N -j -1] == NOT_FREE){
      continue;
    }
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i + N - j - 1] = NOT_FREE;
    recursive(i + 1);
    row[i] = col[j] = dpos[i + j] = dneg[i + N - j - 1] = FREE;
  }
}

int main(void){
  int i,j,k,r,c;

  initialize();

  for(i = 0;i < N;i++){
    for(j = 0;j < N;j++){
      X[i][j] = false;
    }
  }

  scanf("%d",&k);
  for(i = 0;i < k;i++){
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
#include <atcoder/dsu>
using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a / gcd(a, b) * b;}
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int n; cin >> n;
    dsu tree(n);
    int q; cin >> q;
    while(q--){
        int t, a, b; cin >> t >> a >> b;
        if(t){
            if(tree.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
        else{
            tree.merge(a, b);
        }
    }
} 

Measured memory_bytes: 3944
from fractions import gcd
from functools import reduce
def gcds(*numbers):
    return reduce(gcd, numbers)

def resolve():
    (A, B, C, D) = list(map(int, input().split(" ")))
    
    xC = (B//C) - ((A-1)//C)
    xD = (B//D) - ((A-1)//D)
    CD = int(C * D / gcds(C, D))
    xCD = (B//CD) - ((A-1)//CD)
    ALL = B - A + 1
    print(ALL - xC - xD + xCD)


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 66028
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	//ループ無し
	int N;
	cin>>N;
	vector<vector<pair<int,int>>> table(N);
	vector<int> color(N,-1);
	

	for(int i=0; i<N-1; i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		u--;
		v--;
		w = w % 2;

		table[u].push_back(make_pair(v,w));
		table[v].push_back(make_pair(u,w));
	}
	
	queue<int> q;
	color[0] = 0;
	q.push(0);

	while(!q.empty())
	{
		int index = q.front();
		q.pop();
		int table_size = table[index].size();
		for(int i=0; i<table_size; i++)
		{
			int next = table[index][i].first;
			int next_w = table[index][i].second;
			if( color[next] == -1 )
			{
				q.push(next);
				color[next]=(next_w + color[index]) % 2;
			}
		}
	}

	for(int i=0; i<N; i++)
	{
		cout<<color[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6784
n = int(input())
S = []
A = {}
for i in range(n):
  S.append(input())
for i in range(n):
  A[S[i]] = A.get(S[i])+1 if A.get(S[i]) != None else 1
A = sorted(A.items(), key=lambda x:x[1], reverse=True)
maxNum = A[0][1]
ans = []
for i in range(len(A)):
  if A[i][1] == maxNum:
    ans.append(A[i][0])
ans.sort()
for a in ans:
  print(a)

Measured memory_bytes: 44688
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#define ll long long
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー
int length(char* str) {
	int len = strlen(str);
	return len;
}
ll GCD(ll a,ll b)
{

    ll r, tmp;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }


    return b;
}
ll LCM(ll a,ll b)
{

    ll r, x, tmp;
    ll i, j;
    ll lcm;
    i = a;
    j = b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    lcm = (i / b) * j;

    return lcm;
}

int main()
{
    int N;
    int S[200010];
    cin >> N;
    int count = 0;
    int check = 1;
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        if (S[i] == check) {
            check++;
        }
        else {
            count++;
        }
    }
    if (check == 1) {
        cout << -1;
        return 0;
    }
    cout << count << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
string a;
int l,r;
int main()
{
	cin>>a;
	for(int i=0;i<a.size();i++)
	if(a[i]=='A'){l=i;break;}
	for(int i=0;i<a.size();i++)
	if(a[i]=='Z')r=i;
	cout<<r-l+1<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
//constexpr auto MAX = 100000;

// ──────────────────────────────────────────────────────────────────

int n, dp[1010][1010];
vi w;

int rec(int l, int r) {
	if (dp[l][r] != -1) return dp[l][r];
	if (abs(l - r) <= 1) return 0;

	int res = 0;

	if (abs(w[l] - w[r - 1]) <= 1 && rec(l + 1, r - 1) == r - l - 2) {
		res = r - l;
	}

	for (int mid = l + 1; mid <= r - 1; ++mid) {
		res = max(res, rec(l, mid) + rec(mid, r));
	}
	return dp[l][r] = res;
}

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

		if (!n) break;

		w.resize(n);
		rep(i, n) cin >> w[i];

		memset(dp, -1, sizeof(dp));
		cout << rec(0, n) << endl;
	}
}


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

int main(){
	int D[123],k,check=0;
	
	for(int i=0;i<5;i++)
		cin>>D[i];
	
	cin>>k;
	
	for(int i=1;i<5;i++){
		if(D[i]-D[0]>k){
			cout<<":(";
			check=1;
			break;
		}
	}
		
	if(check==0)
		cout<<"Yay!";
	
	return 0;
}

Measured memory_bytes: 256
#PythonだとTLE、PyPyだとAC
N,W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int, input().split())

V = sum(v)
inf=float("inf")
dp = [[inf for i in range(V)] for j in range(N)]

for i in range(N):
    for j in range(v[i]):
        dp[i][j] = w[i]

for i in range(1,N):
    for j in range(V):
        if j >= v[i]:
            dp[i][j] = min(dp[i][j],dp[i-1][j],dp[i-1][j-v[i]]+w[i])
        else:
            dp[i][j] = min(dp[i][j],dp[i-1][j])

cnt = 0
for i in dp[-1]:
    if i <= W:
        cnt += 1
print(cnt)


Measured memory_bytes: 337460
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

int main() {
	int a, b; 
	cin >> a >> b;
	if (a + b >= 10 ) cout << "error";
	else cout << a + b << "\n";

	return 0;
}




Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;


int main(){

	int n,minimum,maximum,sum,tmp;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		sum = 0;
		minimum = 100000;
		maximum = -1;

		for(int i = 0; i < n; i++){
			scanf("%d",&tmp);
			sum += tmp;
			minimum = min(minimum,tmp);
			maximum = max(maximum,tmp);
		}

		sum -= minimum;
		sum -= maximum;

		printf("%d\n",sum/(n-2));

	}

	return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int k, r;
    cin >> k >> r;

    if (k > 10)
        cout << r << endl;
    else
        cout << r + 100 * (10 - k) << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
count=1
flag = [True]*n
for i in range(n):
  x = int(input())-1
  a.append(x)
i=0

while a[i]!=1:
  if not flag[i]:
    print(-1)
    exit()
  flag[i]=False
  i=a[i]
  count+=1
  
print(count)

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

using namespace std;

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

const int N = 1e5 + 5;

ll n,a,b,l,r;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> a >> b;
  l = (n - 1) * a + b;
  r = (n - 1) * b + a;
  if (a > b || (n == 1 && a != b))
    cout << 0 << endl;
  else
    cout << r - l + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <queue>

using namespace std;

const int MAXN = 500 + 100;

int n, p[MAXN];
int ans[MAXN * MAXN];

struct Cmp
{
	bool operator () (int x, int y) const
	{
		return p[x] < p[y];
	}
};

int cnt[MAXN];
priority_queue<int, vector<int>, Cmp> pq;
queue<int> que;

void no()
{
	cout << "No" << endl;
	exit(0);
}

void yes()
{
	cout << "Yes" << endl;
	for(int i = 1; i <= n * n; i++)
		cout << ans[i] << ' ';
	cout << endl;
	exit(0);
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	for(int i = 1; i <= n; i++)
	{
		cnt[i] = n - i;
		for(int j = 1; j <= n - i; j++)
			pq.push(i);
		ans[p[i]] = i;
	}
	for(int i = n * n; i >= 1; i--)
		if(ans[i])
		{
			// cerr << i << ' ' << ans[i] << endl;
			if(cnt[ans[i]]) no();
			for(int j = 1; j <= ans[i] - 1; j++)
				que.push(ans[i]);
		}
		else
		{
			if(!pq.empty())
				cnt[pq.top()]--, ans[i] = pq.top(), pq.pop();
			else if(!que.empty())
				ans[i] = que.front(), que.pop();
			else
				no();
		}
	yes();

	return 0;
}


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


int gcd(int x, int y){
    if(y == 0) return x;
    gcd(y, x % y);
}

int main() {
    int x,y;
    cin >> x >> y;
    if(x >= y) cout << gcd(x, y) << endl;
    else cout << gcd(y, x) << endl;
}


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

template<class T>
struct LIS {
	const vector<T> val;
	const T INF;
	using F = function<bool(T, T)>;
	const F comp;
	// dp[i] := サイズiのLISにおける右端の最小値
	vector<int> dp;
	LIS(const vector<T> &val, const T INF, const F comp) :
		val(val),
		INF(INF),
		comp(comp),
		dp(vector<T>(val.size() + 1, INF))
		{
			build();
		}
	void build() {
		for(int i = 0; i < (int)val.size(); ++i) {
			auto itr = lower_bound(dp.begin(), dp.end(), val[i], comp);
			*itr = val[i];
		}
	}
	int ans() {
		auto itr = lower_bound(dp.begin(), dp.end(), INF, comp);
		return itr - dp.begin();
	}
	vector<T> restore() {
		int n = ans() - 1;
		vector<T> ret(n + 1);
		for(int i = val.size() - 1; i >= 0 and n >= 0; --i) {
			if((dp[n] == val[i] or comp(dp[n], val[i])) and comp(val[i], dp[n + 1])){
				ret[n] = val[i];
				n--;
			}
		}
		return ret;
	}
};

int main() {
	int n; cin >> n;
	vector<int> a(n); for(int i = 0; i < n; ++i) cin >> a[i];
	LIS<int> lis(a, 1e9 + 10, [](int a, int b){return a < b;});
	cout << lis.ans() << endl;
	return 0;
}


Measured memory_bytes: 3952
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 1e5 + 7;
int mod;
int n;
vector <int> G[N];

int dp[N];
int wynik[N];
vector <int> dzieci[N];
vector <int> iloL[N];
vector <int> iloR[N];

void dfs0(int v, int p) {
    for (int u : G[v]) {
        if (u != p) {
            dfs0(u, v);
        }
    }
    
    long long pom = 1;
    for (int u : G[v]) {
        if (u != p) {
            pom = (pom * (dp[u] + 1)) % mod;
        }
    }
    
    dp[v] = pom;
}

void dfs1(int v, int p, int gora) {
    wynik[v] = (1ll * dp[v] * (gora + 1)) % mod;
    for (int u : G[v]) {
        if (u != p) {
            dzieci[v].push_back(u);
        }
    }
    
    iloL[v].resize(dzieci[v].size());
    iloR[v].resize(dzieci[v].size());
    int ile = dzieci[v].size();
    for (int i = 0; i < ile; ++i) {
        long long rr = dp[dzieci[v][i]] + 1;
        if (i > 0) rr = (rr * iloL[v][i - 1]) % mod;
        iloL[v][i] = rr;
    }
    for (int i = ile - 1; i >= 0; --i) {
        long long rr = dp[dzieci[v][i]] + 1;
        if (i + 1 < ile) rr = (rr * iloR[v][i + 1]) % mod;
        iloR[v][i] = rr;
    }
    
    for (int i = 0; i < ile; ++i) {
        long long pom = gora + 1;
        if (i > 0) pom = (pom * iloL[v][i - 1]) % mod;
        if (i + 1 < ile) pom = (pom * iloR[v][i + 1]) % mod;
        dfs1(dzieci[v][i], v, pom);
    }
}

int main() {
    scanf("%d %d", &n, &mod);
    for (int i = 1; i < n; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    dfs0(1, 0);
    dfs1(1, 0, 0);
    for (int i = 1; i <= n; ++i) printf("%d\n", wynik[i]);
    return 0;
}


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

using namespace std;
#define N 101010
#define F first
#define S second

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


int n, m;
ii v[N];
set<ii> s;

bool intersect(ii a, ii b){
	return a.S > b.F;
}

ii intersection(ii a, ii b){
	return ii(max(a.F, b.F), min(a.S, b.S));
}

int main(){
	
	
	scanf("%d %d", &n, &m);
	
	for(int i=0; i<m; i++) scanf("%d %d", &v[i].F, &v[i].S);
	sort(v, v+m, [](ii a, ii b){return a > b;});
	
	//~ for(int i=0; i<m; i++) printf("%d %d\n", v[i].F, v[i].S);

	for(int i=0; i<m; i++){
		
		if(s.empty()) {
			s.insert(v[i]);
			continue;
		}
		
		if(!intersect(v[i], *s.begin())) {
			s.insert(v[i]);
			continue;
		}
		
		ii aux = intersection(v[i], *s.begin());
		s.erase(s.begin());
		s.insert(aux);
	}
	
	printf("%d\n", (int)s.size());

}


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

int N;
int s[100];

int main(){
    int sum = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s[i];
        sum += s[i];
    }
    sort(s, s+N);
    if(sum % 10 == 0){
    for(int i = 0; i < N; i++){
        if(s[i] % 10 != 0){
            cout << sum-s[i];
            return 0;
        }
    }
        cout << "0";
        return 0;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str_as = br.readLine().split(" ");
        int[] as = new int[3];
        as[0] = Integer.parseInt(str_as[0]);
        as[1] = Integer.parseInt(str_as[1]);
        as[2] = Integer.parseInt(str_as[2]);
        Arrays.sort(as);
        int ans = 0;
        
        
        System.out.println(Math.abs(as[1]-as[0]) + Math.abs(as[2]-as[1]));
    }
}


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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef unsigned long long int ll;
typedef long double ld;

const int NMax = 1e5 + 50;

ll v[NMax];

int main() {
	Boost();

	int n;
	cin >> n;

	for(int i = 1; i <= n; ++i) cin >> v[i];

	if(v[n] != 2) {
		cout << -1;
		exit(0);
	}

	ll a, b;
	a = 2; b = 3;

	for(int i = n - 1; i > 0; --i) {
		ll ma, mb;
		ma = ((a - 1) / v[i] + 1) * v[i];
		mb = (b / v[i]) * v[i] + v[i] - 1;

		if(ma <= b) {
			a = ma;
			b = mb;
		} else {
			cout << -1;
			exit(0);
		}
	}

	cout << a << " " << b;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>

using ll = long long;

int main() {
    int N;
    std::cin >> N;

    std::vector<int> p(N);
    for (int i = 0; i < N; i++) {
        std::cin >> p[i];
    }

    std::sort(p.begin(), p.end());
    p[N - 1] /= 2;
    std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N, A;
    cin >> N >> A;
    if (N % 500 <= A) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

const int di[] = {1,0,1,0,-1,0,-1};
const int dj[] = {1,1,0,0,0,-1,-1};

int next[128];
vector<pair<int, int> > pos;
int G[10][10], nG[10][10];

bool rec(int k) {
  if(k == pos.size()) {
    for(int i = 0; i < 7; ++i) {
      int bit = 0;
      for(int j = 0; j < 7; ++j) {
        int pi = 2 + di[i] + di[j];
        int pj = 2 + dj[i] + dj[j];
        bit |= (G[pi][pj]) << j;
      }
      nG[2+di[i]][2+dj[i]] = next[bit] >> 3 & 1;
    }
    int bit = 0;
    for(int j = 0; j < 7; ++j) {
      int pi = 2 + di[j];
      int pj = 2 + dj[j];
      bit |= (nG[pi][pj]) << j;
    }
    return next[bit] != bit;
  }
  for(int r = 0; r < 2; ++r) {
    G[pos[k].first][pos[k].second] = r;
    if(rec(k+1)) return true;
  }
  return false;
}

int main() {
  for(int i = 0; i < 7; ++i) {
    pos.push_back(make_pair(2+di[i], 2+dj[i]));
    for(int j = 0; j < 7; ++j) {
      int pi = 2 + di[i] + di[j];
      int pj = 2 + dj[i] + dj[j];
      pos.push_back(make_pair(pi, pj));
    }
  }
  sort(pos.begin(), pos.end());
  pos.erase(unique(pos.begin(), pos.end()), pos.end());

  for(string s; cin >> s && s != "#"; ) {
    for(int i = 0; i < 128; ++i) {
      next[i] = (i & ~(1 << 3)) | ((s[i]-'0') << 3);
    }
    if(rec(0)) cout << "no" << endl;
    else cout << "yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>

int sx,sy,tx,ty;

int main()
{
    scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
    int xdis=tx-sx;
    int ydis=ty-sy;

    for(int i=0;i<ydis;i++) printf("U");
    for(int i=0;i<xdis;i++) printf("R");

    printf("D");
    for(int i=0;i<xdis-1;i++) printf("L");
    for(int i=0;i<ydis-1;i++) printf("D");
    printf("L");

    printf("L");
    for(int i=0;i<ydis+1;i++) printf("U");
    for(int i=0;i<xdis+1;i++) printf("R");
    printf("D");

    printf("R");
    for(int i=0;i<ydis+1;i++) printf("D");
    for(int i=0;i<xdis+1;i++) printf("L");
    printf("U");
    printf("\n");

}

Measured memory_bytes: 128
N=int(input())
dic={0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j'}
ans=[["a",1]]
for i in range(1,N):
    tmp=[]
    for prev,val in ans:
        for j in range(val+1):
            if j!=val:
                tmp.append([prev+dic[j],val])
            else:
                tmp.append([prev+dic[j],val+1])
    ans=tmp
ans=sorted(ans,key=lambda x:x[0])
for i in range(len(ans)):
    print(ans[i][0])

Measured memory_bytes: 76380
import java.util.*;

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

		char[] s1 = "CODEFESTIVAL2016".toCharArray();
		char[] s2 = scan.next().toCharArray();

		int result = 0;
		for(int i = 0; i < s1.length; i++) {
			result += (s1[i]!=s2[i])?1:0;
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 8916
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		
		Scanner scanner = new Scanner(System.in);
		//サイコロの面の数
		int N = scanner.nextInt();
		//勝ち得点
		int K = scanner.nextInt();
		//サイコロを振る数
		int count;
		//各サイコロの目のときの確率
		double p = 0;
		//答え
		double answer = 0;
		
		//サイコロの目でループ
		for(int i = 1; i <= N; i++){
			count = i;
			p = 1.0/N;
				//サイコロの目が勝ち得点を超えるまでループ
				while(count < K){
					count *= 2;
					p /= 2.0;
				}
				answer += p;
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
constexpr int INF = 1e9;

int main() {
    int N;
    while(cin >> N, N) {
        vector<string> v2(N);
        for(int i=0; i<N; ++i) {
            cin >> v2[i];
        }
        vector<string> v;
        for(int i=0; i<N; ++i) {
            bool f = false;
            for(int j=0; j<N; ++j) {
                if(i == j) {
                    continue;
                }
                for(int k=0; k+v2[i].size() < v2[j].size()+1; ++k) {
                    f |= v2[i] == v2[j].substr(k, v2[i].size());
                }
            }
            if(!f) {
                v.push_back(v2[i]);
            }
        }
        N = v.size();
        vector<vector<int>> dp(N, vector<int>(1 << N, INF));
        for(int i=0; i<N; ++i) {
            dp[i][1<<i] = v[i].size();
        }
        vector<vector<int>> cost(N, vector<int>(N));
        for(int i=0; i<N; ++i) {
            for(int j=0; j<N; ++j) {
                cost[i][j] = v[j].size();
                for(int k=0; k<min(v[i].size(), v[j].size()); ++k) {
                    if(v[i].substr(v[i].size()-k) == v[j].substr(0, k)) {
                        cost[i][j] = min(cost[i][j], (int)v[j].size()-k);
                    }
                }
            }
        }
        for(int b=0; b<(1<<N); ++b) {
            for(int i=0; i<N; ++i) {
                if(!(b & (1 << i))) {
                    continue;
                }
                for(int j=0; j<N; ++j) {
                    if(b & (1 << j)) {
                        continue;
                    }
                    int next = b | (1 << j);
                    dp[j][next] = min(dp[j][next], dp[i][b] + cost[i][j]);
                }
            }
        }
        int res = INF;
        for(int i=0; i<N; ++i) {
            res = min(res, dp[i][(1<<N)-1]);
        }
        cout << res << endl;
    }
}


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

int main(){
  int n; cin >> n;
  string s, t;
  cin >> s >> t;

  int ans = 2*n;
  for(int i=0; i<n; i++){
    if(s.substr(i, n - i) == t.substr(0, n - i)){
      ans = 2*n - (n - i);
      break;
    }
  } 

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,w = map(int, input().split())
max_value = [[0]*(w+1) for _ in range(n+1)]
for i in range(1, n+1):
    weight, value = map(int, input().split())
    for j in range(1, weight):
        max_value[i][j] = max_value[i-1][j]
    for j in range(weight, w+1):
        max_value[i][j] = max(max_value[i-1][j], max_value[i-1][j-weight] + value)

print(max_value[n][w])

Measured memory_bytes: 119532
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;



int main()
{
	unsigned long long N,A,B,C;
	cin>>N>>A>>B;
	C = min( N%(A+B),A);

	cout<< C + A*(N/(A+B))<<endl;
	return 0;
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 998244353;

const int MAXN = 3e5 + 5;

int v[MAXN];

ll f[MAXN];

int l[MAXN], r[MAXN];
int coord[MAXN];

void solve(){
	f[0] = 1;
	REP(i, 1, MAXN) {
		f[i] = (f[i - 1] * i) % MOD;
	}
	
	
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d", &v[i]);
	}
	if (v[0] == 1 && v[n - 1] == 1) {
		int s = n - 1;
		for(; s >= 0 && v[s] == 1; s--);
		if (s < 0) {
			printf("%lld\n", f[n]);
			return;
		}
		rotate(v, v + s + 1, v + n);
	}
	
	/*REP(i, 0, n) {
		printf("%d ", v[i]);
	}*/
	
	int s = 0;
	for(; s < n && v[s] != 1; s++);
	if (s == n) {
		printf("0\n");
		return;
	}
	
	rotate(v, v + s, v + n);
	int k = 0;
	for(k = 0; k < n && v[k] == 1; k++);
	
	l[1] = 0; r[1] = k - 1;
	REPN(i, k, n) {
		if (v[i] != v[i - 1]) {
			r[v[i - 1]] = i - 1;
			if (i != n) {
				if (v[i] == 1 || l[v[i]]) {
					
					printf("0\n");
					return;
				}
				l[v[i]] = i;
			}
		}
	}

	ll ans = 1ll;
	int vv = 0;
	REPN(i, 2, n) {
		if (!l[i]) {
			if (vv == 0) {
				
				printf("0\n");
				return;
			}
			ans = (ans * vv) % MOD;
			vv--;
			continue;
		}
		if (r[i] - l[i] >= k) {
			//printf("0\n");
			printf("0\n");
			return;
		}
		
		int lpos = -1, rpos = -1;
		int prv_i = v[l[i] - 1], nxt_i = v[(r[i] + 1) % n];
		if (prv_i > i) {
			if (nxt_i > i && r[i] - l[i] < k - 1) {
				//printf("0\n");
				printf("0\n");
				return;
			}
			//printf("1\n");
			lpos = l[i];
			rpos = l[i];
			coord[i] = lpos;
			
			if (nxt_i < i) {
				vv += r[i] - l[i];
			}
		} else if (nxt_i > i) {
			//printf("2\n");
			lpos = r[i] - k + 1;
			rpos = r[i] - k + 1;
			coord[i] = lpos;
			
			vv += r[i] - l[i];
		} else {
			//printf("3\n");
			lpos = max(r[i] - k + 1, coord[prv_i] + 1);
			rpos = min(l[i], (coord[nxt_i] - 1 + n) % n);
			
			vv += (coord[nxt_i] + n - coord[prv_i] - 2) % n;
		}
		
		/*if (v[(l[i] - 1 + n) % n] < i) {
			vv += l[i] - l[v[l[i] - 1]] - 1;
		}
		if (v[(r[i] + 1) % n] < i) {
			vv += -r[i] + r[v[r[i] + 1]] - 1;
		}*/
		//printf("%d\n", k);
		//printf("%d %d %d %d %d %d\n", i, l[i], r[i], lpos, rpos, vv);
		
		ans = (ans * (rpos - lpos + 1)) % MOD;
	}
	//printf("0\n");
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 7296
n,m = gets.strip.split.map(&:to_i)
left = []
right = []
m.times do
  l,r = gets.strip.split.map(&:to_i)
  left << l
  right << r
end
if left.max <= right.min
  puts right.min-left.max+1
else
  puts 0
end

Measured memory_bytes: 16200
#include <iostream>
#include <vector>

using namespace std;

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

    int dist = 0;
    for (int i=1; i<=n+1; i++) {
        dist += abs(a[i-1] - a[i]);
    }

    for (int i=1; i<=n; i++) {
        int m = abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]);
        int p = abs(a[i-1] - a[i+1]);
        cout << dist - m + p << endl;
    }
}

Measured memory_bytes: 1664
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]

w1 = 0
w2 = w
h1 = 0
h2 = h
for x, y, a in xya:
    if a == 1:
        w1= max(w1, x)
    if a == 2:
        w2 = min(w2, x)
    if a == 3:
        h1 = max(h1, y)
    if a == 4:
        h2 = min(h2, y)
        
print(max(0, (w2-w1))*max(0, (h2-h1)))

Measured memory_bytes: 3064
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
 
 
 
 
 
int main(){
    long long a,b,c;
    cin >> a >> b >> c;
    long long d = c-a-b;

    if ( 4*a*b < d*d && d > 0){
        cout << "Yes" <<endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }
}

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

using namespace std;
const int MN = 201234;

int n, q;
long long r[MN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> q;
	vector <long long> s;
	s.push_back(n);
	long long qu;
	for (int i = 0; i < q; i++) {
		cin >> qu;
		while (!s.empty() && qu <= s.back())
			s.pop_back();
		s.push_back(qu);
	}
	map<long long, long long> c;
	c[s.back()] = 1;
	s.pop_back();
	while (s.size()) {
		long long l = s.back();
		s.pop_back();
		long long s = 0;
		auto it = c.lower_bound(l + 1);
		while (it != c.end()) {
			long long cl = it->first;
			long long cs = it->second;
			c.erase(it++);
			s += (cl / l) * cs;
			cl %= l;
			if (cl != 0)
				c[cl] += cs;
		}
		if (s != 0)
			c[l] += s;
	}
	for (auto &p: c)
		r[1] += p.second, r[p.first + 1] -= p.second;
	for (int i = 1; i <= n; i++) {
		r[i] += r[i - 1];
		cout << r[i] << "\n";
	}
}



Measured memory_bytes: 9460
# 31年5月以降が与えられたら-30する
while 1:
    day_string = str(input())
    if day_string[0] == '#':
        exit()

    g, y, m, d = day_string.split()

    if int(y) > 31 or (int(y) == 31 and int(m) >= 5):
        print(f'? {int(y)-30} {m} {d}')
    else:
        print(f'{g} {y} {m} {d}')



Measured memory_bytes: 5604
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;

int main(){
	int a,b,c;
	string s;
	cin>>s;
	cout<<2018;
	for (int i=4;i<s.size();i++)cout<<s[i];
}

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

int main() {

    std::string str;
    int S;
    cin >> S;
    str = std::to_string(S);
    bool flag = true;
    for (int i = 0; i < 3; i++) {
        if (str[i] == str[i + 1]) flag = false;
    }

    if (flag) cout << "Good" << endl;
    else cout << "Bad" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[1001][1001];
int wi[8]={1,1,0,-1,-1,-1,0,1};
int wj[8]={0,-1,-1,-1,0,1,1,1},n=0,m=0;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
            {
                cout<<'#';
            }
            else
            {
                int num=0;
                for(int m=0;m<8;m++)
                {
                    if(a[i][j]!='.')
                    {
                    	continue;
                    }
                    if(a[i+wi[m]][j+wj[m]]=='#')
                    {
                        num++;
                    }
                }
                cout<<num;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
let () =
  let rec insertionSort arr n m =
    for i = 0 to n - 2 do
      Printf.printf "%d " arr.(i)
    done;
    Printf.printf "%d\n" arr.(n-1);
    if m = n then ()
    else 
      let v = arr.(m) in
      let j = ref (m - 1) in
      while !j >= 0 && arr.(!j) > v do
        arr.(!j+1) <- arr.(!j); j := !j - 1
      done;
      arr.(!j+1) <- v; insertionSort arr n (m+1) in
  Scanf.scanf "%d\n" @@ fun n -> 
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  insertionSort arr n 1


Measured memory_bytes: 4060
# 1<=N<=K<=15
import itertools
N, K = list(map(int, input().split()))
buildings = list(map(int, input().split()))
indexes = [i for i in range(len(buildings))]
building_combinations = [
    combination for combination in itertools.combinations(indexes, K)]

costs = []
for building_combination in building_combinations:
    max_height = 0
    cost = 0
    for i, building in enumerate(buildings):
        if i in building_combination:  # 選んだ建物の場合
            if building <= max_height:
                cost += max_height - building + 1
                max_height = max_height + 1
            else:
                max_height = building
        else:
            if building >= max_height:
                max_height = building
    costs.append(cost)
# print(costs)
print(min(costs))


Measured memory_bytes: 40304
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

int main(){
    ll N; cin>>N;
    N%=10;
    if(N==3) cout<<"bon"<<endl;
    else if(N==1 || N==0 || N==6 || N==8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}

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

const int MAXN = 100000;
const int MAXM = 100000;

int N, M, K, L, parent[MAXN+MAXM];

int root(int x) {
    if (parent[x] == -1) return x;
    return parent[x] = root(parent[x]); // path compression + return
}

bool isConnected(int A, int B) {
	int rootA = root(A);
	int rootB = root(B);
	return (rootA == rootB);
}

void connect(int x, int y) {
	int rootX = root(x);
	int rootY = root(y);
	if (rootX != rootY) parent[rootX] = rootY;
}
// person is i
// language is MAXN + L

int main() {
	memset(parent, -1, sizeof parent);
	cin >> N >> M;
    for (int i=1;i<=N;i++) {
        cin >> K;
        for (int j=1;j<=K;j++) {
            cin >> L;
            connect(i, MAXN + L); // connecting person to language.
        }
    }
    int cnt=1;
    for (int i=2;i<=N;i++) {
        if (isConnected(i,1)) cnt++;
    }
    if (cnt==N) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int main(){
    char str1[1000],str2[1000],str3[1000];
    scanf("%s %s",str1,str2);
    strcpy(str3,str1);
    strcat(str1,str3);
    if ( strstr(str1, str2) == NULL ){    
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
}


Measured memory_bytes: 3160
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        r = bisect.bisect_left(l,l[i]+l[j])
        ans += r-(j+1)
print(ans)

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

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int tmp=i*1.08;
        if(tmp==n){
            cout<<i<<endl;
            break;
        }else if(tmp>n) {
            cout<<":("<<endl;
            break;
        }
    }
    return 0;
}

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

int main() {
	int X, N;
	unordered_map<int, int> p;
	int count = 0;

	cin >> X >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		p[tmp]++;
	}

	if (p[X] == 0) {
		cout << X;
	}
	else if (p[X] > 0) {
		for (int i = 1; i < 200; i++) {
			int y = X - i;
			if (p[y] == 0) { //pに含まれない
				cout << y;
				break;
			}
			else if (p[y] > 0) { //ｐに含まれる
				count++;
				if (count >= N) {
					cout << y - 1;
					break;
				}
			}

			int x = X + i;
			if (p[x] == 0) { //pに含まれない
				cout << x;
				break;
			}
			else if (p[x] > 0) { //ｐに含まれる
				count++;
				if (count >= N) {
					cout << x + 1;
					break;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3232
//In the name of God
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int , int> pii;

const int N = 1e5 + 10;

map<pii , bool> block , mark;
ll res[10] , h , w;
int n , a[N] , b[N] , cnt;

void check(int x , int y){
        if(x <= 1 || x >= h || y <= 1 || y >= w || mark[{x,y}])
                return;
        int now = 0; 
        for(int dx = -1 ; dx < 2 ; dx++) 
                for(int dy = -1 ; dy < 2 ; dy++)
                                now += (block[{x+dx , y+dy}] == 1);
        res[now]++;
        mark[{x,y}] = 1;
        cnt++;
}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> h >> w >> n; 
        for(int i=0 ; i < n ; i++){
                cin >> a[i] >> b[i];
                block[{a[i],b[i]}] = 1;
        }
        for(int i=0 ; i < n ; i++)
                for(int dx = -1 ; dx < 2 ; dx++)
                        for(int dy = -1 ; dy < 2 ; dy++)
                                check(a[i] + dx , b[i] + dy);
        res[0] = (h-2) * (w-2) - cnt;
        for(int i=0 ; i < 10 ; i++)
                cout << res[i] << "\n";
        return 0;
}

Measured memory_bytes: 213504
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,j,k,l,n,m,c=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
for(i=0;i<n;i++)
{
	if(a[i]%2==0)
	{
		if(a[i]%3!=0&&a[i]%5!=0)
		{
			c++;
			break;
		}
	}
}
if(c!=0)
{
	cout<<"DENIED\n";
}
else
cout<<"APPROVED\n";
return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
allSousa = sum(B)-sum(A)
atob = 0
for a, b in zip(A, B):
  if a < b:
    atob += (b-a)//2+(b-a)%2
if allSousa < atob:
  print("No")
else:
  print("Yes")


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll tk, ao;
    cin >> tk >> ao;
    rep(i, N-1){
        ll a, b; cin >> a >> b;
        //a:bになる
        //tk+X : ao+Y = a:b
        //a(ao + Y) = b(tk+X)
        //Y = b(tk+X)/a - ao
        //aとbは互いに素なのでtk+Xはaの倍数
        //同様にao+Yはbの倍数
        //よってtk+X = n*a, ao*Y = n*bとなる(ここでnは高橋くんと青木くんの票数が減らない範囲でなるべく小さく取る)
        //つまりX >= 0 && Y >= 0
        //ll n = max( ceil((double)tk/(double)a), ceil((double)ao/(double)b));
        ll n;
        ll n1, n2;
        if(tk % a == 0) n1 = tk/a;
        else n1 = tk/a + 1;
        if(ao % b == 0) n2 = ao/b;
        else n2 = ao/b + 1;
        n = max(n1, n2);
        assert(tk <= n*a && ao <= n*b);
        tk = n*a;
        ao = n*b;
        //cout << tk << " " << ao << endl;
    }
    cout << tk+ao << endl;
    return 0;
}

Measured memory_bytes: 256