akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

struct UnionFind {
  vector<int> par;
  vector<int> sz;
  UnionFind(int n) { init(n); }

  void init(int n) {
    par.resize(n);
    sz.resize(n);
    REP(i, n) {
      par[i] = i;
      sz[i] = 1;
    }
  }

  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] < sz[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
    }
  }

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

  int size(int x) { return sz[find(x)]; }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  REP(i, n) cin >> p[i];
  UnionFind uf(n - k + 1);
  vector<int> rev_cnt(n - k + 1);
  int j = 1, cnt = 0;
  REP(i, n - k + 1) {
    while (j < i + k) {
      if (p[j - 1] > p[j]) {
        cnt++;
      }
      j++;
    }
    rev_cnt[i] = cnt;
    if (p[i] > p[i + 1]) {
      cnt--;
    }
  }
  j = -1;
  REP(i, n - k + 1) {
    if (rev_cnt[i] == 0) {
      if (j == -1) {
        j = i;
      } else {
        uf.unite(j, i);
      }
    }
  }
  set<int> st;
  j = 0;
  REP(i, n - k) {
    while (j < i + k + 1) {
      st.insert(p[j]);
      j++;
    }
    int mn = *st.begin();
    int mx = *prev(st.end());
    if (mn == p[i] && mx == p[j - 1]) {
      uf.unite(i, i + 1);
    }
    st.erase(p[i]);
  }
  int ans = 0;
  REP(i, n - k + 1) {
    if (i == uf.find(i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10368
#include <iostream>
using namespace std;
int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  --a;
  --b;
  --c;
  --d;
  int ans = 1e9;
  for(int i = 0; i < n; ++i){
    int w = i+1, h = (n+w-1)/w;
    ans = min(ans, abs(a/w - b/w) + abs(a%w - b%w) + abs(c/w - d/w) + abs(c%w - d%w));
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3048
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush, heapify 
def main():
    N, M = map(int , readline().split())
    hp = [(-int(i), 1) for i in readline().split()]
    heapify(hp)
    for _ in range(M):
        b, c = map(int, readline().split())
        heappush(hp, (-c, b))
    ans = 0
    while 1:
        if N <= 0:
            break
        if not len(hp):
            break
        v, u = heappop(hp)
        v = -v
        if N >= u:
            ans += v*u
            N += -u
        else:
            ans += v*N 
            N += -u
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 27652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		int num = Integer.parseInt(reader.readLine());
		System.out.println(factorial(num));

	}

	public static long factorial(int num) {
		if (num == 1)
			return num;
		else
			return num * factorial(num - 1);
	}
}

Measured memory_bytes: 16920
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 20000
vector<int>a[30];
char b[10];

int solve(int k){
	if (a[k].size() < 3)return a[k][0];
	f(i, a[k].size() / 2){
		printf("? %d %d\n", a[k][2 * i], a[k][(2 * i) + 1]);
		fflush(stdout);
		f(j, 10)b[j] = 0;
		scanf("%s", b);
		if (b[0] == 'Y')a[k + 1].push_back(a[k][(2 * i) + 1]);
	}
	if (a[k + 1].size() % 2 == 0 && a[k].size()%2==1)a[k + 1].push_back(a[k][a[k].size() - 1]);
	return solve(k + 1);
}

int main(){
	int n, m, x;
	char ans[N];
	f(i, N)ans[i] = 0;
	scanf("%d %d", &n, &m);
	if (n <= m){
		printf("Impossible\n");
		return 0;
	}
	f(i, n + m)a[0].push_back(i);
	x = solve(0);
	ans[x] = '1';

	f(i, n+m){
		if (i != x){
			printf("? %d %d\n", x, i);
			fflush(stdout);
			f(j, 10)b[j] = 0;
			scanf("%s", b);
			if (b[0] == 'Y')ans[i] = '1';
			else ans[i] = '0';
		}
	}
	printf("! %s\n",ans);
	fflush(stdout);



	return 0;
}

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

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

    std::vector<int> a(1, 0);
    int sum = 0;
    for(int i = 0; i < n; ++i){
        int val;
        std::cin >> val;
        a.push_back(val);
        sum += std::abs(val - a.at(i));
    }

    a.push_back(0);
    sum += std::abs(a.at(n));

    for(int i = 1; i <= n; ++i){
        int val = std::abs(a.at(i) - a.at(i - 1)) + std::abs(a.at(i + 1) - a.at(i)) - std::abs(a.at(i + 1) - a.at(i - 1));
        std::cout << sum - val << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1784
#C - Streamline(ABC117)
N,M=map(int, input().split())
X=list(map(int, input().split()))
X.sort(reverse=True)
ans=X[0]-X[-1]
A=[]
if N<M:
    for i in range(M-1):
        A.append(X[i]-X[i+1])
    A.sort(reverse=True)
    ans-=sum(A[0:N-1])
else:
    ans=0
print(ans)

Measured memory_bytes: 13964
#include <iostream>

using namespace std;

int main(){
    int A ,B;
    cin >> A >> B;

    int ans = -1;
    for (int i = 0; i < 1250; i++){
        if(((i * 8) / 100 == A) && ((i * 10) / 100 == B)){
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  char s[2001][2001]; int r[h][w], l[h][w], u[h][w], d[h][w], max = 0;
  for (int i=0; i<h; i++) scanf("%s", s[i]);
  for (int i=0; i<h; i++) {
    r[i][w-1] = (s[i][w-1] == '.') ? 1 : 0;
    l[i][0] = (s[i][0] == '.') ? 1 : 0;
  }
  for (int i=0; i<w; i++) {
    u[0][i] = (s[0][i] == '.') ? 1 : 0;
    d[h-1][i] = (s[h-1][i] == '.') ? 1 : 0;
  }
  for (int i=0; i<h; i++) {
    for (int j=1; j<w; j++) {
      if(s[i][j] == '.') l[i][j] = l[i][j-1]+1;
      else l[i][j] = 0;
      if(s[i][w-j-1] == '.') r[i][w-j-1] = r[i][w-j]+1;
      else r[i][w-j-1] = 0;
    }
  }
  for (int j=0; j<w; j++) {
    for (int i=1; i<h; i++) {
      if(s[i][j] == '.') u[i][j] = u[i-1][j]+1;
      else u[i][j] = 0;
      if(s[h-i-1][j] == '.') d[h-i-1][j] = d[h-i][j]+1;
      else d[h-i-1][j] = 0;
    }
  }
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      int sum = u[i][j] + d[i][j] + l[i][j] + r[i][j];
      max = (sum > max) ? sum : max;
    }
  }
  if (max != 0) max -= 3;
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 66560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  double sum=0;
  for (int i=0;i<N;i++){
    double x;
    cin >> x;
    sum+=1/x;
  }
  cout << fixed << setprecision(5);
  cout << 1/sum << endl;
}

Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortresult:
        div.sort()
    return div
# endregion
N = ri()
h = ri_()
dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])

Measured memory_bytes: 77684
n, a, b = map(int, input().split())
mod = 10**9+7
ans = (pow(2,n,mod)-1)%mod

f = 1
for i in range(1, 200001):
  f *= i
  f %= mod

finv = [1]*200001
finv[200000] = pow(f, mod-2, mod)
for i in range(199999, 0, -1):
  finv[i] = finv[i+1]*(i+1)%mod

nCa = 1
for i in range(a):
  nCa *= n-i
  nCa %= mod
nCa *= finv[a]
nCa %= mod
  
nCb = 1
for i in range(b):
  nCb *= n-i
  nCb %= mod
nCb *= finv[b]
nCb %= mod

print((ans-nCa-nCb)%mod)

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K, num = 1;
    cin >> N >> K;
    for (int i = 0; i < N; i++){
        if (num * 2 < num + K){
            num *= 2;
        }
        else num += K;
    }
    cout << num << endl;
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a;
		a = 1e9;
		for(int i = 0; i*i*i <= n; i++){
			for(int j = 0; j*j+i*i*i <= n; j++){
				int t =(n-i*i*i-j*j);
				if(t >= 0)a= min( i+j+t, a);
			}
		}
		cout << a<<endl;
		cin >> n;
	}
	return 0;
}


Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;

int main() {
  ll N,K,ans=0;
  cin>>N>>K;
  vector<ll> a(N+1);
  vector<ll> b(N+1);
  a[0]=0;
  b[0]=N;
  for(int i=1;i<=N;i++){
    a[i]=a[i-1]+i;
  }
  for(int i=1;i<=N;i++){
    b[i]=b[i-1]+(N-i);
  }
  for(int i=K-1;i<=N;i++){
    ans+=(b[i]-a[i]+1);
    ans%=MOD;
   // cout<<ans<<" ";
  }
  cout<<ans;
}

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

int main() {
  int N;
  cin >> N;
  for(int i = 0; i <= N / 4; ++i) {
    auto rest = N - (i * 4);
    if(rest % 7 == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		sc.close();
		
		   if (a < b) System.out.println("a < b");
	        else if (a > b) System.out.println("a > b");
	        else System.out.println("a == b");		
		

	}
}

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

const int TICKET_NUM = 8;
const int CITY_NUM = 30;
const double INF = 10000000000;

bool checkBit(char bit,int n) {
	int b = 1 << n;
	return  bit & b;
}

char setBit(char bit, int n) {
	int b = 1 << n;
	return bit | b;
}

int N, M, P, A, B;
int tickets[TICKET_NUM];
int route[CITY_NUM][CITY_NUM] = { {0} };
double dp[256][30];

double solve(unsigned char t, int c) {
	if (dp[t][c] != -1)return dp[t][c];
	if (c == B) {
		return 0;
	}
	double m = INF;
	for (int i = 0; i < N; i++) {
		if (checkBit(t, i))continue;
		for (int j = 0; j < M; j++) {
			if (route[c][j] == 0)continue;
			double time = route[c][j] / (double)tickets[i];
			m = min(m, solve(setBit(t, i), j) + time);
		}
	}
	return dp[t][c] = m;
}

int main() {

	while (true) {
		for (int i = 0; i < CITY_NUM; i++) {
			for (int j = 0; j < CITY_NUM; j++) {
				route[i][j] = 0;
			}
		}
		for (int i = 0; i < 256; i++) {
			for (int j = 0; j < CITY_NUM; j++) {
				dp[i][j] = -1;
			}
		}

		cin >> N >> M >> P >> A >> B;
		A--; B--;
		if (N == 0)break;
		for (int i = 0; i < N; i++) {
			cin >> tickets[i];
		}

		for (int i = 0; i < P; i++) {
			int x, y, z;
			cin >> x >> y >> z;
			x--; y--;
			route[x][y] = z;
			route[y][x] = z;
		}
		double ans = solve(0, A);
		if (ans == INF) {
			cout << "Impossible" << endl;
		}
		else {
			cout << ans << endl;
		}
	}

	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<long long> a(N*3);
    for (int i = 0; i < N*3; ++i) cin >> a[i];

    // 左から前処理
    vector<long long> S(N*2+1, 0);
    priority_queue<long long, vector<long long>, greater<long long> > que1;
    for (int i = 0; i < N; ++i) {
        S[i+1] = S[i] + a[i];
        que1.push(a[i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long mi = que1.top();
        if (a[i] > mi) {
            S[i+1] = S[i] - mi + a[i];
            que1.pop();
            que1.push(a[i]);
        }
        else S[i+1] = S[i];
    }

    // 右から前処理
    vector<long long> T(N*2+ 1, 0);
    priority_queue<long long> que2;
    for (int i = 0; i < N; ++i) {
        T[i+1] = T[i] + a[N*3-1 - i];
        que2.push(a[N*3-1 - i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long ma = que2.top();
        if (a[N*3-1 - i] < ma) {
            T[i+1] = T[i] - ma + a[N*3-1 - i];
            que2.pop();
            que2.push(a[N*3-1 - i]);
        }
        else T[i+1] = T[i];
    }

    // 集計
    long long res = -(1LL<<60);
    for (int i = N; i <= N*2; ++i) {
        res = max(res, S[i] - T[N*3-i]);
    }
    cout << res << endl;
}

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

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

    int ans = 0;
    int i = 0;
    int j = n-1;
    while(i < j){
        while(c[i] == 'R') i++;
        while(c[j] == 'W') j--;
        if(i < j){
            ans++;
            i++;
            j--;
        }
    }

    cout << ans << endl;
}

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	int n; scanf("%d", &n);
	ld total = 0;
	forn(i, n) {
		int input; scanf("%d", &input);
		total += 1.0/input;
	}
	printf("%Lf", 1/total);
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
#define enl << endl
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    double a, b, x;
    double s;

    cin >> a >> b >> x;

    if(a*a*b/2 > x){
        s = atan(a*b*b/(2*x))*(180/M_PI);
        printf("%.10lf\n", s);
    }else if(a*a*b/2 == x){
        printf("%.10lf\n", 45.0);
    }else{
        s = atan(2*(a*a*b-x) / (a*a*a))*(180/M_PI);
        printf("%.10lf\n", s);
    }

    return 0;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>

//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
ll GetDigit(ll num){ 
    ll digit=0; 
    while(num!=0){num/=10;digit++;} 
    return digit; 
} 


using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
ll n;
struct Edge{
  ll to,dist;
};
ll dy[200000];
ll ds[200000];
vector<Edge> Gy[200000];
vector<Edge> Gs[200000];
void dijkstraY(ll u){
  REP(i,n)dy[i]=INF;
  priority_queue<P,vector<P>,greater<P>> que;
  que.push({0,u});
  while(!que.empty()){
    auto r=que.top();que.pop();
    if(r.first>=dy[r.second])continue;
    dy[r.second]=r.first;
    
    for(Edge& e: Gy[r.second]){
      ll dist=dy[r.second]+e.dist;
      if(dist>=dy[e.to])continue;
      que.push({r.first+e.dist,e.to});
    }
  }
}
void dijkstraS(ll u){
  REP(i,n)ds[i]=INF;
  priority_queue<P,vector<P>,greater<P>> que;
  que.push({0,u});
  while(!que.empty()){
    auto r=que.top();que.pop();
    if(r.first>=ds[r.second])continue;
    ds[r.second]=r.first;
    
    for(Edge& e: Gs[r.second]){
      ll dist=ds[r.second]+e.dist;
      if(dist>=ds[e.to])continue;
      que.push({r.first+e.dist,e.to});
    }
  }
}
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll m,s,t;cin>>n>>m>>s>>t;//n都市,m電車,都市sからtに移動
  s--,t--;
  ll u0,v0,a0,b0;
  REP(i,m){
    cin>>u0>>v0>>a0>>b0;//a円bスヌーク
    u0--,v0--;
    Gy[u0].push_back({v0,a0});
    Gy[v0].push_back({u0,a0});
    Gs[u0].push_back({v0,b0});
    Gs[v0].push_back({u0,b0});
  }
  dijkstraY(s);
  dijkstraS(t);
  
  ll ans[n+1];ans[n]=INF;
  REP(i,n){
    ans[n-i-1]=min(ans[n-i],dy[n-i-1]+ds[n-i-1]);
  }
  REP(i,n){
    cout<<(1000000000000000LL-ans[i])<<"\n";
  }
  return 0;
}


Measured memory_bytes: 26464
N, A, B, C, D = map(int,input().split())
S = input()

if C < D:
    flag = True
    for i in range(A-1,D-1):
        if S[i]=='#' and S[i+1]=='#':
            flag = False
    print('Yes' if flag else 'No')
else:
    flag = False
    for i in range(B-1,D):
        cnt = 0
        for j in {-1,0,1}:
            if S[i+j]=='.':
            	cnt += 1
        if cnt == 3:
            flag = True
    for i in range(A-1,C-1):
        if S[i]=='#' and S[i+1]=='#':
            flag = False

    print('Yes' if flag else 'No')

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

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node *find(Node *u, int k) {
	while (u != NIL&&k != u->key) {
		if (k < u->key)  u = u->left; 
		else  u = u->right; 
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL)return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if (u == NIL)return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'f') {
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL)  printf("yes\n"); 
			else printf("no\n");
		}
		else if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 22048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,m,k,a=0,t=0,w=0,r=0;
	string s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s=="AC")
			a++;
		else if(s=="TLE")
			t++;
		else if(s=="WA")
			w++;
		else if(s=="RE")
			r++;
		// cout<<a<<t<<w<<r<<endl;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;
	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<sstream>
#include<map>
#include<string>
using namespace std;

#define INF 100000000

int main()
{	
	int n;
	string temp;
	int a;
	int cost[201][201],minicost[201];
	while(cin>>n && n!=0){

		for(int i=0;i<=200;i++){
			for(int j=0;j<=200;j++){
				cost[i][j]=INF;
			}
			minicost[i]=INF;
		}


		map<string,int> Idx;
		int num=0;
		for(int i=0;i<n;i++){
			cin>>a;//1
			string s,t,p; cin>>s>>temp>>p>>t;
			if(!Idx.count(s)){Idx[s]=num++;}
			if(!Idx.count(t)){Idx[t]=num++;}
			std::istringstream is(p);
			int k;
			char taa;
			is>>a>>taa>>k;
			cost[Idx[s]][Idx[t]]=k;
			cost[Idx[t]][Idx[s]]=-k;
		}

		int count=0;
		while(true){
			bool update=false;
			for(int i=0;i<num;i++){
				for(int j=0;j<num;j++){
					if(cost[i][j]<INF){
						if(minicost[j]>minicost[i]+cost[i][j]){
							update=true;
							minicost[j]=minicost[i]+cost[i][j];
						}
					}
				}
			}
			if(!update){cout<<"Yes"<<endl;break;}
			count++;
			if(count>n+1){cout<<"No"<<endl;break;}
		}
	}
	return 0;
}

Measured memory_bytes: 1108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  if (s.at(0) == s.at(1) && s.at(1) == s.at(2)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;
int sum(string s,int& i);
int mul(string s,int& i);
ll bracket(string s,int& i);
ll num(string s,int& i);

bool isdigit(char c){
    int x=c-'0';
    return 0<=x&&x<=9;
}



ll bracket(string s,int& i){
    if(isdigit(s[i]))return num(s,i);
    i++;
    vector<ll> v;
    while(s[i]!=']'){
        v.push_back(bracket(s,i));
    }
    i++;
    sort(v.begin(),v.end());
    int m=v.size();
    ll ret=0;
    rep(i,(m+1)/2)ret+=v[i];
    return ret;
}

ll num(string s,int& i){
    int ret=s[i]-'0';
    i++;
    while(isdigit(s[i])){
        ret=10*ret+(int)(s[i]-'0');
        i++;
    }
    return (ret+1)/2;
}
int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        int j=0;
        cout<<bracket(s,j)<<endl;
    }
   return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> p;

#define INF 2000000000
	int main(){
				int n ;cin>>n;
				vector<int> a={1};
				rep(i,100){
					int A = pow(6,i+1);
					if(A<=n){
						a.push_back(A);
					}
					else {
						break;
					}
				}
				rep(i,100){
					int A = pow(9,i+1);
					if(A<=n){
						a.push_back(A);
					}
					else{
						break;
					}
				}
				SORT(a);
				//割る数の候補が何個あるかをcanに入れておく
				int can = a.size();//can={1,6,9,36,81...}
			/*	rep(i,can){
					cout<<a[i]<<endl;
				}*/
			vector<int> bankdp(n+1,INF);
			bankdp[0]=0;
			for(int i = 1 ; i <= n ; i++){
				//n円までのそれぞれの金額に対して何回操作が必要がを入れていく
				for(int j = 0; j<can; j++){
					if(a[j]>i){
						break;
					}
					bankdp[i] = min(bankdp[i] , bankdp[i-a[j]]+1);
				}
			}
			cout<<bankdp[n]<<endl;
			}


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

int main() {
 long long a ,b,n;
  cin>>a>>b;
  for(int i=a;i>0;i--){
    if(a%i==0&&b%i==0){
      n=i;
      break;
    }
  }
  cout<<a*b/n;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N;
string s;
main()
{
	cin>>N>>s;
	int ans=0;
	for(int i=0;i<N;i++)
	{
		if(s[i]!='.')continue;
		int L=0,R=0;
		for(int j=i-1;j>=0;j--)
		{
			if(s[j]=='B')
			{
				L=1;
				break;
			}
			else if(s[j]=='.')break;
		}
		for(int j=i+1;j<N;j++)
		{
			if(s[j]=='B')
			{
				R=1;
				break;
			}
			else if(s[j]=='.')break;
		}
		if(L&&R)continue;
		L=R=0;
		for(int j=i-1;j>=0;j--)
		{
			if(s[j]=='B')L++;
			else if(s[j]=='W')break;
			else if(s[j]=='.')
			{
				L=0;
				break;
			}
			if(j==0)
			{
				L=0;
				break;
			}
		}
		for(int j=i+1;j<N;j++)
		{
			if(s[j]=='B')R++;
			else if(s[j]=='W')break;
			else if(s[j]=='.')
			{
				R=0;
				break;
			}
			if(j+1==N)
			{
				R=0;
				break;
			}
		}
		ans=max(ans,L+R);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int N, K, result = 2000000000, tmp;
    cin >> N >> K;
    vector<int> h(N);
    REP(i, N) {
        cin >> h[i];
    }
    sort(ALL(h));
    REP(i, N-K+1) {
        tmp = h[i+K-1] - h[i];
        if (tmp < result) {
            result = tmp;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n,d,x,y,ans=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(hypot(x,y)<=d){
            ans++;
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3660
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
S = 0

for i in range(N):
    B[A[i]] += 1

for i in range(1, N+1):
    S += B[i]*(B[i]-1)//2

for k in range(N):
    print(S-B[A[k]]+1)

Measured memory_bytes: 32216
import sys
input = sys.stdin.readline

# A - Airport Bus
N, C, K = map(int, input().split())
times = []

for i in range(N):
	T = int(input())
	t = [T, T + K]
	times.append(t)

times.sort(key=lambda x: x[1])

ans = 0
count = 0
departure_time = 0

for t in times:
	if count == 0:
		departure_time = t[1]
		count = 1
	elif count < C:
		if t[0] <= departure_time:
			count += 1
		else:
			ans += 1
			departure_time = t[1]
			count = 1
	elif count == C:
		ans += 1
		departure_time = t[1]
		count = 1

if count <= C:
	ans += 1

print(ans)

Measured memory_bytes: 25396
#include<cstdio>
#include<vector>
using namespace std;
int N,Q,mrk[200005],Ans[200005],cnt;
vector <int> V[200005];
void dfs(int n,int fa)
{
	Ans[n]+=mrk[n];
	for(int i=0,zj;i<V[n].size();i++)
	{
		zj=V[n][i];
		if(zj==fa) continue;
		mrk[zj]+=mrk[n];
		dfs(zj,n);
	}
}
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=1,a,b;i<N;i++)
	{
		scanf("%d %d",&a,&b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	for(int i=1,x,p;i<=Q;i++)
	{
		scanf("%d %d",&p,&x);
		mrk[p]+=x;
	}
	dfs(1,0);
	for(int i=1;i<=N;i++)
	printf("%d ",Ans[i]);
	return 0;
}

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

using namespace std;

#ifdef Adrian
#include "debug.h"
#else
#define debug(...) 9999
#endif

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second
#define ii pair<ll,ll>
template <typename G>
struct triple{G F, S, T;
    bool operator < (triple<G> o)
    { return F < o.F; }
};
#define iii triple<int>



int main()
{

#ifdef Adrian
    //freopen("test.txt", "r", stdin);
#else
    //ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#endif


    char c;
    cin>>c;
    if(c >= 'a')
        cout<<"a\n";
    else
        cout<<"A\n";


    return 0;
}


Measured memory_bytes: 3632
#include "stdio.h"

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == b) {
        printf("a == b\n");
    } else if (a > b) {
        printf("a > b\n");
    } else {
        printf("a < b\n");
    }
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L+7;
int n;
int r,c,k;
vector<vector<ll>> inp;
vector<vector<vector<ll>>> dp;

ll solution (int i,int j,int cnt)
{
    if(i>r or j>c) return 0;
    if(dp[i][j][cnt] != -1) return dp[i][j][cnt];
    else if(i==r and j==c)
    {
        if(cnt<3) return inp[i][j];
        return 0;
    }
    else
    {
        ll best=0;
        if(i+1<=r)
        {
            if(cnt <3 and inp[i][j] != 0) best +=inp[i][j];
            //cout<<best<<endl;
            best += solution (i+1,j,0);
            /*best = max(best,solution(i+1,j,0));
            if(cnt<3) best = max(best,inp[i][j] + solution(i+1,j,0));*/
        }
        if(j+1<=c)
        {
            if(cnt<3)
            {
                best = max(best,inp[i][j]+solution(i,j+1,cnt+1));
            }
            //cout<<best<<endl;
            best = max(best,solution(i,j+1,cnt));
            //cout<<best<<endl;
        }
        /*
        best = max(solution(i+1,j,0),solution(i,j+1,cnt));
        if(cnt<3) best = max(best,inp[i][j]+max(solution(i+1,j,0),solution(i,j+1,cnt+1)));*/
        return dp[i][j][cnt] = best;
    }
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>r>>c>>k;
        inp.assign(r+2,vector<ll> (c+2,0));
        dp.assign(r+2,vector<vector<ll>> (c+2,vector<ll> (4,-1)));

        for(int i=0;i<k;i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            inp[a][b] = c;
        }

        cout<<solution(1,1,0)<<endl;
    }
    
}


Measured memory_bytes: 707872
import bisect

N,M = map(int,input().split())
A = list(map(int,input().split()))
B = [[0,0] for i in range(M)]

for i in range(M):
    B[i][1],B[i][0] = map(int,input().split())

A.sort()
B.sort()
B = B[::-1]

left = bisect.bisect_left(A, B[0][0])
width = left
newsum = 0
border = 0
for i in range(M):
    width = bisect.bisect_left(A, B[i][0]) - border
    if width > 0:
        newsum += B[i][0] * (B[i][1] + min(0,width - B[i][1]))
        border += B[i][1] + min(0,width - B[i][1])

newsum += sum(A[border:])


print(newsum)

Measured memory_bytes: 73752
#include <stdio.h>

int main (){
	int i;
	char s[6];
	scanf("%s",s);
	for (i=0;i<3;i++){
		if(s[i]==s[i+1]){
			printf("Bad\n");
			return 0;
		}
	}
	printf("Good\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll a, b, c, k; cin >> a >> b >> c >> k;
  if (k % 2 == 0) outl(a - b);
  else outl(b - a);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

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

    int n;
    cin>>n;
    int ans = n + n * n + n * n * n;
    cout<<ans<<endl;
    // int t;
    // cin>>t;
    // while(t--)
    // {
        
    // }
}

Measured memory_bytes: 3152
s = list(input())
k = int(input())
sub = []
sub += s[:]
 
for j in range(2,k+1):
    charGram = [''.join(s[i:i+j]) for i in range(len(s)-1)]
    sub += charGram
sub = list(set(sub))
print(sorted(sub)[k-1])

Measured memory_bytes: 5196
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using namespace std;


int N;
queue<int> odd, even, m4;


bool solve(){
	VLL seq;
	while(!odd.empty() || !m4.empty()){
		if(!odd.empty()) seq.pb(odd.front()), odd.pop();
		if(!m4.empty()) seq.pb(m4.front()), m4.pop();
	}
	while(!even.empty()) seq.pb(even.front()), even.pop();
	rep(i, 0, N-1)
		if((seq[i]*seq[i+1])%4 != 0) return false;
		return true;
}


signed main(){
	cin >> N;
	rep(i, 0, N){
		int a;
		cin >> a;
		if(a%4 == 0) m4.push(a);
		else if(a%2 == 0) even.push(a);
		else odd.push(a);
	}
	
	if(solve()) Yes;
	else No;
	
	return 0;
}

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

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

int main(void){
  unsigned long long A = 0;
  double B = 0;
  int N;
  long long ans;
  cin >> A >> B;
  N = B * 1000 / 10;
  ans = A * N / 100;
  cout << ans;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

const long long INF = (long long) 1e11+1;
const long long mod = (long long) 998244353 ;
const long long hell = (long long) 1000000007;


ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x*res);
    x=(x*x);    
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

void solve(){  
    int n,k;
    cin>>n>>k;
    
    set<int> st;
    forn(i,0,k){
        int d;
        cin>>d;
        forn(j,0,d){
            int x;
            cin>>x;
            st.insert(x);
        }
    }
    int sz=st.size();
    cout<<n-sz;
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
   
   while(test--)
   solve();
}

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/

// gcd of strings
/*
string getgcd(string s1,string s2){
    
    while(true){
        if(s1.length()<s2.length()){
            swap(s1,s2);
            continue;
        }
        if(s2.empty())
        return s1;
        
        if(s1.substr(0,s2.length())!=s2)
        return "";
        
        s1=s1.substr(s2.length());
    }
}
*/
/*
// for user defined DS hashmap and set
 
struct hash_pair{
      size_t operator()(const pair<int,pair<int,int>>& p) const{
          auto hash1=hash<int>()(p.F) ;
          auto hash2=hash<int>()(p.S.F) ;
          auto hash3=hash<int>()(p.S.S) ;
          return (hash1^hash2)^hash3;
      }  
};
struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
*/



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

int main(){
    int h,w,T;
    
    while(true){
            int Ah = 1000;
            int Aw = 1000;
        cin >> h >> w;
        T = (h * h) + (w * w) ;
        for (int i=1; i<= 149;i++){
            for(int j = i + 1;j<= 150;j++){
                if(T < (i * i) + (j * j) && (Ah * Ah) + (Aw * Aw) > (i * i) + (j * j)){ 
                    Ah = i;
                    Aw = j;
                break;
                }else if(T == (i * i) + (j * j) && h < i  ){
                    if((Ah * Ah) + (Aw * Aw) > (i * i) + (j * j)){
                    
                    Ah = i;
                    Aw = j;
                    break;
                    }else if(Ah > i){
                    Ah = i;
                    Aw = j;
                    break;
                    }
                }
            }
        }
        
        
        if(h == 0 && w == 0){
        break;
        }
   cout << Ah << " " << Aw <<endl;
   }
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  ll now = 1, ans = 0;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == now) now++;
    else {
      if (a.at(i) % now == 0) ans += (a.at(i) / now) - 1;
      else ans += a.at(i) / now;
      if (now == 1) now++;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18L+5;
struct block{
int w,s;ll v;
};
int main()
{
    int n;
    cin>>n;
    vector<block> vec(n);
    int max_w=0;
    for(int i=0;i<n;i++)
    {
        cin>>vec[i].w>>vec[i].s>>vec[i].v;
        max_w+=vec[i].w;
    }
    sort(vec.begin(),vec.end(),[](block a,block b){
        return a.w+a.s<b.w+b.s;
    });
    //dp[i] max value with total weight i so far
    vector<ll> dp(max_w+5);
   // dp[n-1]=vec[n-1].v;
    for(int i=0;i<n;i++)
    {
        for(int j=min(vec[i].s,max_w-vec[i].w);j>=0;j--)
        {
            // if(j<=vec[i].s)
            
                dp[j+vec[i].w]=max(dp[j+vec[i].w],dp[j]+vec[i].v);
            

        }
    }
    ll ans=-1;
    for(int j=max_w;j>=0;j--)
    {
        ans=max(ans,dp[j]);
    }
    cout<<ans<<endl;

}

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

template<typename T>
class BIT {
    public:
    int n;
    vector<T> dat; // i: [1,n]

    BIT(int size): n(size+1), dat(vector<T>(n+1)) {}

    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }

    T sum(int i) {
        T ret = 0;
        while (i > 0) {
            ret += dat[i];
            i -= i & -i;
        }
        return ret;
    }

    T range(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

using ll = long long;

// i < j, (v[i] op v[j]) を満たす(i,j)の組を数える
template<typename T>
ll inversion(vector<T> v, string op) {
    assert(op == "<=" || op == ">=" || op == ">" || op == "<");
    if (op == ">=" || op == "<") {
        reverse(v.begin(), v.end());
    }

    ll size = v.size();
    vector<pair<T, int>> vp(size);
    rep(i,size) {
        vp[i] = {v[i],i};
    }
    sort(vp.begin(), vp.end());

    // 小さい順に 1..size の連番を振る
    vector<int> order(size);
    rep(i,size) {
        order[vp[i].second] = i+1;
    }

    // i < j, order[i] <= order[j] の個数を数える
    ll result = 0;
    BIT<int> bt(size);
    rep(i,size){
        result += bt.sum(order[i]);
        bt.add(order[i], 1);
    }

    if (op == ">" || op == "<") {
        return size*(size-1)/2 - result;
    } else {
        return result;
    }
}

ll n;
vector<int> a;

bool check(int x) {
    vector<int> b(n);
    rep(i,n){
        b[i] = (a[i] >= x ? +1 : -1);
    }
    vector<ll> s(n+1);
    rep(i,n){
        s[i+1] = s[i] + b[i];
    }
    return (n*(n+1)/2 + 1)/2 <= inversion(s, "<=");
}

int main(void) {
    cin >> n;
    a.resize(n);
    vector<int> meds(n);

    rep(i,n){
        cin >> a[i];
        meds[i] = a[i];
    }
    sort(meds.begin(), meds.end());
    int l = 0, r = n;
    while (l + 1 < r) {
        int mid = (l+r)/2;
        if (check(meds[mid])) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << meds[l] << endl;
    return 0;
}


Measured memory_bytes: 5380
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>m;
typedef map<char,ll>mc;
typedef set<ll>st;
typedef set<char>sc;
const ll mx = 1e5+123;
ll binarySearch(ll arr[], ll p, ll r, ll num) {
   if (p <= r) {
      ll mid = (p + r)/2;
      if (arr[mid] == num)
         return mid ;
      if (arr[mid] > num)
         return binarySearch(arr, p, mid-1, num);
      if (arr[mid] < num)
         return binarySearch(arr, mid+1, r, num);
   }
   return -1;
}
int main()
{
    speed;
    ll t,i,j,a,b,x,y,e=0,ans=0,sum=0;
    cin>>a;
    vi c(mx,0);
    vi d(a);
    rep(i,a){
        cin>>d[i];
        sum+=d[i];
        c[d[i]]++;
    }
    cin>>b;
    while(b--)
    {
        cin>>x>>y;
        sum+=(y-x)*c[x];
        c[y]+=c[x];
        c[x]=0;
        cout<<sum<<endl;
    }

}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<int> t(101, 0);
vector<int> p(101, 0), x(101, 0);

int main(void){
    
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) scanf("%d", &t[i]);
    scanf("%d", &M);
    for(int i = 0; i < M; ++i) scanf("%d %d", &p[i], &x[i]);
    
    vector<int> v;
    int sum = 0;
    for(int i = 0; i < N; ++i) sum += t[i], v.push_back(sum);
    
    for(int i = 0; i < M; ++i){
        int num = abs(t[p[i] - 1] - x[i]);
        printf("%d\n", v[N - 1] + ((t[p[i] - 1] - x[i] >= 0) ? -num : num));
    }
    
    return 0;
}

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

int log_(int k){ return 31 - __builtin_clz(k); }
int alter(int k){ return 1 << log_(k); }

int main(void){
  int N, W;
  cin >> N >> W;

  vector<int> v;
  vector<int> w;
  v.push_back(0);
  w.push_back(0);
  int input_v, input_w, input_m;
  for(int i = 1; i <= N; i++){
    cin >> input_v >> input_w >> input_m;
    for(int j = 0; j < log_(input_m); j++){
      int tmp = 1 << j;
      v.push_back(input_v * tmp);
      w.push_back(input_w * tmp);
    }
    int diff = input_m - alter(input_m) + 1;
    v.push_back(input_v * diff);
    w.push_back(input_w * diff);
  }

  vector<int> dp(W + 1, 0);
  for(int i = 1; i < (int)v.size(); i++){
    for(int j = W; j >= w[i]; j--){
      dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
    }
  }

  
  cout << dp[W] << endl;
  return 0;
}

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

int main() {

 int A=0;
 int B=0;
 int K=0;

 //入力
 int ret = scanf("%d %d", &A , &B);
 if( ret == EOF ) {
    printf( "scanfでエラー\n" );
    return -1;
  }

 //比較
 for ( K=0;K<=1000000000;K++){
  if(abs(A-K)==abs(B-K)){
  	printf("%d",K);
    return(0);
  }
 }
  printf("IMPOSSIBLE");
 return (0);
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;
    deque<char> que;
    for (const char &c : s) que.emplace_back(c);
    
    int q;
    cin >> q;
    bool pal = true;
    while (q--) {
        int op; cin >> op;
        if (op == 1) {
            pal = (!pal);
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (pal) que.emplace_front(c);
                else que.emplace_back(c);
            } else {
                if (pal) que.emplace_back(c);
                else que.emplace_front(c);
            }
        }
    }
    
    
    if (!pal) {
        while (!que.empty()) {
            cout << que.back();
            que.pop_back();
        }
    } else {
        while (!que.empty()) {
            cout << que.front();
            que.pop_front();
        }
    }
}

Measured memory_bytes: 896
n = int(input())
l = [1]
for i in [6,9]:
    j = i
    while j <= n:
        l.append(j)
        j *= i

dp = [0]

for i in range(1,n+1):
    m = n
    for j in l:
        if j <= i:
            m = min(m,dp[i-j]+1)
    dp.append(m)
print(dp[-1])

Measured memory_bytes: 3860