akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 *   ﷽
 * In the name of Allah, the Most Gracious, the Most Merciful
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <climits>

using namespace std;

int main()
{
	string s, t;
	cin>>s>>t;
	int n = s.size();
	int ans = 0;
	for(int sa=0;sa<n;sa++)
	{
		if(s[sa] != t[sa]) ans++;
	}
	cout << ans;
	return 0;
}

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

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto& e : s) cin >> e;

  int n = h * w;
  vector<vector<int>> d(n, vector<int>(n, 1e9));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      if (i + 1 < h && s[i + 1][j] != '#') d[i * w + j][(i + 1) * w + j] = d[(i + 1) * w + j][i * w + j] = 1;
      if (j + 1 < w && s[i][j + 1] != '#') d[i * w + j][i * w + (j + 1)] = d[i * w + (j + 1)][i * w + j] = 1;
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
      }
    }
  }

  int r = 0;
  for (int i = 0; i < n; i++) {
    if (s[i / w][i % w] == '#') continue;
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if (s[j / w][j % w] == '#') continue;
      r = max(r, d[i][j]);
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int x,y;
    cin >> x >> y;
    if(x >= y && x % y == 0)
    cout << -1 << endl;
    else
    {
        for(int i = x; i < 1e18; i += x){
        if(i % y != 0)
        {
            cout << i << endl;
            return 0;
        }
        }
    }
    
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int x,y;
  cin>>x>>y;
  if (x == y || x % y == 0) {
    cout << -1;
    return 0;
  }
  for (ull i = x; i <= 1000000000000000000; i += x) {
    if (i % y != 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}


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

using namespace std;

const int N = 2e5 + 10;
int mxprefdp[N], mxsufdp[N];
int l[N], r[N];

void solve() {
    int n, k, c; cin >> n >> k >> c;
    string s; cin >> s;
    s = "#" + s;
    for (int i = 1; i <= n; i++) {
        mxprefdp[i] = mxprefdp[i - 1];
        int mx = 0;
        if (i - c - 1 >= 1)
            mx = mxprefdp[i - c - 1];
        if (s[i] == 'o')
            mxprefdp[i] = mx + 1;
    }
    for (int i = n; i >= 1; i--) {
        mxsufdp[i] = mxsufdp[i + 1];
        int mx = 0;
        if (i + c + 1 <= n)
            mx = mxsufdp[i + c + 1];
        if (s[i] == 'o')
            mxsufdp[i] = mx + 1;
    }
    for (int i = 1; i <= n; i++) {
        int mxpref = 0, mxsuf = 0;
        if (i - c - 1 >= 1)
            mxpref = mxprefdp[i - c - 1];
        if (i + c + 1 <= n)
            mxsuf = mxsufdp[i + c + 1];
        if (s[i] == 'o') {
            if (mxpref + mxsuf + 1 == k) {
                if (!l[mxpref + 1])
                    l[mxpref + 1] = i;
                r[mxpref + 1] = i;
            }
        }
    }
    for (int i = 1; i <= k; i++) {
        if (l[i] && l[i] == r[i])
            cout << l[i] << " ";
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 4944
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
using namespace std;
long long gcd(long long a,long long b){
	if(a<b){
		swap(a,b);
	}
	if(a%b==0){
		return b;
	}else{
		return gcd(b,a%b);
	}
}
int main(){
	int n;
	cin>>n;
	if(n%10==7){
		cout<<"Yes"<<endl;
	}else if(700<=n&&n<=799){
		cout<<"Yes"<<endl;
	}else if(170<=n&&n<=179){
		cout<<"Yes"<<endl;
	}else if(270<=n&&n<=279){
		cout<<"Yes"<<endl;
	}else if(370<=n&&n<=379){
		cout<<"Yes"<<endl;
	}else if(470<=n&&n<=479){
		cout<<"Yes"<<endl;
	}else if(570<=n&&n<=579){
		cout<<"Yes"<<endl;
	}else if(670<=n&&n<=679){
		cout<<"Yes"<<endl;
	}else if(770<=n&&n<=779){
		cout<<"Yes"<<endl;
	}else if(870<=n&&n<=879){
		cout<<"Yes"<<endl;
	}else if(970<=n&&n<=979){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3648
n, m = map(int, input().split())
graph = [[]*n for _ in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)

import itertools
np = [i for i in range(1,n)]
p = list(itertools.permutations(np))
ans = 0
for pi in p:
  flag = True
  sta = 0
  for j in range(n-1):
    if pi[j] not in graph[sta]:
      flag = False
      break
    else:
      sta = pi[j]
  if flag:
    ans += 1

print(ans)

Measured memory_bytes: 3572
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const ll MAX = 210000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
const ll ainf = 998244353;

void solv() {

	ll n;

	cin >> n;

	ll prims[100];
	fill(prims,prims + 100, 1);
	for (ll i = 2; i <= 100; i++)
	{
		if (prims[i] == 0) continue;
		ll pr = i * 2;
		while (pr <= 100)
		{
			prims[pr] = 0;
			pr += i;
		}
	}

	ll t[101];
	memset(t, 0, sizeof(t));
	for (size_t i = 2; i <= n; i++)
	{
		ll ti = i;
		for (ll j = 2; j <= 100; j++)
		{
			if (prims[j] == 0) continue;
			while (ti % j == 0)
			{
				t[j]++;
				ti /= j;
			}
		}
	}

	ll dp[101][101];

	memset(dp, 0, sizeof(dp));
	dp[1][1] = 1;
	ll bef = 1;
	for (ll i = 2; i <= 100; i++)
	{

		if (t[i] == 0) continue;

		for (ll c = 1; c <= t[i] + 1; c++)
		{
			for (ll j = 1; j <= 75; j++)
			{
				if (c * j <= 75)
					dp[i][c * j] += dp[bef][j];
			}
		}
		bef = i;
	}

	cout << dp[bef][75] << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    bool ok=true;
    for(int i=0;i<s.length();i++){
        if(i==a){
            if(s[i]!='-') ok = false;
        }
        else if('0'<=s[i]&&s[i]<='9') continue;
        else ok = false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  Int n;
  cin>>n;
  const Int N = 1<<n;
  vector<Int> A(N);
  cin>>A;

  set<P> Top2[N];
  auto insert=[&](Int i,P t){
    Top2[i].insert(t);
    while(Top2[i].size() > 2) Top2[i].erase(Top2[i].begin());
  };
  
  for(Int i=1;i<N;i++){
    insert(i ,P(A[i], i));
    for(Int j=0;j<n;j++){
      if(!(i>>j&1)) continue;
      Int k = i ^ (1<<j);
      insert(i, P(A[k],k));
      for(auto t:Top2[k]) insert(i, t);
    }
  }
  

  Int ans = -INF;
  for(Int i=1;i<N;i++){
    if(Top2[i].size() >=2){
      Int a = (Top2[i].begin())->first;
      Int b = (++Top2[i].begin())->first;
      Max(ans, a + b);
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 50176
#include <iostream>
#include <vector>
#include <iomanip>	// require setw
//#include <fstream>	// require freopen

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.jpeg", "r", stdin );
	int n;
	int count = 1;
	vector <int> N ;

	while (cin >> n && n ){
		N.push_back(n);
	} // end while

	
	for (int i = 0; i < N.size(); ++i ){
		n = N[i];
		vector <vector <int> > M (n, vector <int> (n, 0 ) );

		int row = 0, col = 0;
		int i = 1;

		M[row][col] = i++;
		if (col < n ){
			++col;
		} // end if

		while (1){
			for (; col >= 0 && row < n; --col, ++row ){
				M[row][col] = i++;
				if (i > n*n ){
					goto result;
				} // end if
			} // end if
			++col; --row;
			if (row + 1 < n ){
				++row;
			}else if (col + 1 < n ){
				++col;
			} // end if

			for (; col < n && row >= 0; ++col, --row ){
				M[row][col] = i++;
				if (i > n*n ){
					goto result;
				} // end if
			} // end if
			--col;
			if (col + 1 < n ){
				++col;
			}else if (row + 1 < n ){
				++row;
			} // end if
			if (row + 1 < n ){
				 ++row;
			} // end if
		} // end while

result:	
		cout << "Case " << count++ << ':' << endl;
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j){
				cout << setw(3) << M[i][j];
			} // end for
			cout << endl;
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
int main(){
	ll n;
	cin>>n;
	ll a[100010]={0};
	ll max=0;
	ll ans=0;
	rep(i,0,n){
		ll s;
		cin>>s;
		if(s>100000){
			ans++;
		}
		else{	
			a[s]++;
			if(s>max)max=s;
		}
	}
	rep(i,0,max+1){
		if(a[i]>0&&i>a[i])ans+=a[i];
		if(a[i]>0&&a[i]>i)ans+=(a[i]-i);
	}
	cout<<ans<<endl;
}

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

std::string cards[52], cards2[52];
int n;

void bubblesort(void)
{
	for(int i = 0; i < n; i++) {
		for(int j = n - 1; j > i; j--) {
			if(cards[j][1] < cards[j - 1][1]) {
				std::string tmp = cards[j];
				cards[j] = cards[j - 1];
				cards[j - 1] = tmp;
			}
		}
	}
}

void selectionsort(void)
{
	for(int i = 0; i < n; i++) {
		int minj = i;
		for(int j = i; j < n; j++) {
			if(cards2[j][1] < cards2[minj][1]) {
				minj = j;
			}
		}
		std::string tmp = cards2[i];
		cards2[i] = cards2[minj];
		cards2[minj] = tmp;
	}
}

int main(void)
{
	std::cin >> n;
	for(int i = 0; i < n; i++) {
		std::cin >> cards[i];
		cards2[i] = cards[i];
	}
	bubblesort();
	selectionsort();
	for(int i = 0; i < n; i++) {
		std::cout << cards[i] << (i == n - 1 ? '\n' : ' ');
	}
	std::cout << "Stable" << std::endl;
	bool flg = true;
	for(int i = 0; i < n; i++) {
		std::cout << cards2[i] << (i == n - 1 ? '\n' : ' ');
		if(cards2[i].compare(cards[i]) != 0) flg = false;
	}
	std::cout << (flg ? "Stable" : "Not stable") << std::endl;
	return 0;
}


Measured memory_bytes: 3228
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]
CD = [tuple(map(int,input().split())) for _ in range(M)]

Ans = [-1]*N
for i in range(N):
    a,b = AB[i]
    md0 = 10**10

    for j in range(M):
        c,d = CD[j]
        md = abs(a-c) + abs(b-d)
        if md < md0:
            md0 = md
            Ans[i] = (j+1)

for ans in Ans:
    print(ans)


Measured memory_bytes: 3064
a, b, c, d = map(int, input().split())

def gcd(x, y):
    if y > x:
        x, y = y, x
    if y == 1:
        return 1
    elif y == 0:
        return x
    else:
        return gcd(y, x-y*(x//y))

def num_divide(p, q, r):
    if p % r == 0:
        rmin = p
    else:
        rmin = p + (r-p%r)
    rmax = q - q%r
    return (rmax-rmin)//r + 1

print(b - a + 1 - (num_divide(a, b, c) + num_divide(a, b, d) - num_divide(a, b, c * d // gcd(c, d))))


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

// I/O
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}


// Node
typedef struct NodeKey {
    int board[16];
    int space;
    // heuristic: manhattan distance
    int est;
} NodeKey;


// solve
int dfs(const int lim, const int depth, const int prev, const NodeKey *node, const int M, const int L1[][16]) {
    if(node->est == 0) return 1;
    if(depth + node->est > lim) return 0;

    static const int dx[] = {-1, 0, 1, 0};
    static const int dy[] = {0, -1, 0, 1};
    const int x = node->space % M;
    const int y = node->space / M;

    for(int i = 0; i < 4; ++i) {
        const int nx = x + dx[i];
        const int ny = y + dy[i];
        if(nx < 0 || M <= nx || ny < 0 || M <= ny) continue;
        if(abs(prev - i) == 2) continue;

        const int next_space = nx + ny * M;
        NodeKey next_node = *node;
        next_node.est -= L1[next_space][next_node.board[next_space] - 1];
        next_node.est += L1[next_node.space][next_node.board[next_space] - 1];
        next_node.board[next_node.space] = next_node.board[next_space];
        next_node.board[next_space] = 0;
        next_node.space = next_space;
        if(dfs(lim, depth + 1, i, &next_node, M, L1)) return 1;
    }
    return 0;
}

int interative_deepening(NodeKey *node) {
    const int N = 16;
    const int M = 4;
    int L1[N][N];
    for(int i = 0; i < N; ++i)
        for(int j = 0; j < N; ++j) L1[i][j] = abs(i % M - j % M) + abs(i / M - j / M);

    int min = 0;
    for(int i = 0; i < N; ++i)
        if(i != node->space) min += L1[i][node->board[i] - 1];
    node->est = min;
    for(const int lim = 46; min < lim; ++min)
        if(dfs(min, 0, 9, node, M, L1)) return min;
    return -1;
}

int main(int argc, char **argv) {
    NodeKey initial;
    for(int i = 0; i < 16; ++i) {
        int x = get_uint();
        initial.board[i] = x;
        if(x == 0) initial.space = i;
    }
    put_uint(interative_deepening(&initial));
    putchar_unlocked('\n');
    return 0;
}



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

int main() {
  string T;
  cin >> T;
  int s = T.size();
  int cnt = 0;
  rep(i,s){
    if(T.at(i) == '?') {
      T.at(i) = 'D';
    }
  }
/*  rep(i,s){
    if(T.at(i)  == 'D'){
      cnt++;
      if(i != 0){
        if( T.at(i-1) == 'P') {
          cnt++;
        }
      }
    }
  }
  */
  cout << T << endl;
}



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

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int in = Integer.parseInt(br.readLine());
			 System.out.println(in==3||in==5||in==7?"YES":"NO");
		}
	}
}

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

int main() {
    int N;
    cin >> N;
    if (N < 10) cout << N << endl;
    else if (N < 100) cout << 9 << endl;
    else if (N < 1000) cout << N - 90 << endl;
    else if (N < 10000) cout << 909 << endl;
    else if (N < 100000) cout << N - 9090 << endl;
    else if (N == 100000) cout << 90909 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll D,ans=0;
  cin>>D;
  ll c[26];
  ll s[D][26];
  rep(i,26){
    cin>>c[i];
    //c[i]=0;
  }
  rep(i,D){
    rep(j,26){
      cin>>s[i][j];
      //s[i][j]=1;
    }
  }
  ll t[D];
  rep(i,D){
    t[i]=rand()%26;
  }
  
  
  ll satis=0;
  rep(i,D){
    ll last[26];
    rep(j,26){
      last[j]=-1;
    }
    satis=0;
    satis+=s[i][t[i]];
    last[t[i]]=i;
    rep(j,26){
      satis-=c[j]*(i-last[j]);
    }
  }
  
  ans=satis;
  while(clock()<1900000){
    ll w=rand()%365,u=rand()%26;
    satis=0;
    ll last[26];
    rep(i,26){
      last[i]=-1;
    }
    ll g=t[w];
    t[w]=u;
    rep(i,D){
      satis+=s[i][t[i]];
      last[t[i]]=i;
      rep(j,26){
        satis-=c[j]*(i-last[j]);
      }
      
    }
    if(ans>satis){
      t[w]=g;
    }
    ans=max(ans,satis);
  }
  rep(i,D){
    cout<<t[i]+1<<endl;
    
  }
  //cout<<ans;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 100000000;
 
int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n){
        cin >> p[i];
    }
    int count = 0;
    REP(i, n){
        if(p[i] == i + 1){
            count++;
        }
    }
    if(count == n || count == n - 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int a[114];
signed main() {
    cin >> N;
    int cur = 1;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    a[N] = -1;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (a[i] != a[i - 1]) {
            ans += cur / 2;
            cur = 1;
        } else {
            cur++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        answer += 1 / A[i];
    }
    
    console.log(1 / answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

int main() {

  string s;
  cin>>s;
  sort(all(s));
  rep(i, s.size()-1) {
    if(s.at(i)==s.at(i+1)) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout<<"yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int a[60], b[60];
int main(void)
{
    while (1) {
        int n, r, i;
        scanf("%d%d", &n, &r);
        if (n==0 && r==0) break;
        for(i=0;i<n;++i) a[n-i]=i+1;
        while (r--) {
            int p, c;
            scanf("%d%d", &p, &c);
            for(i=1;i<=n;++i) b[i]=a[i];
            for(i=1;i<=c;++i) a[i]=b[i+p-1];
            for(i=1;i<p;++i) a[i+c]=b[i];
        }
        printf("%d\n", a[1]);
    }
    return 0;
}


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

int main(){
	long long N, a, b, aa, bb, kk, ss;
		cin>>N;
		for(int i = 0; i < N; ++i){
		cin>>a>>b;
		if(i == 0){
			aa = a;
			bb = b;
		}
		else{
			if(aa%a==0)kk=(aa/a);
			else{
				kk=aa/a+1;
			}
			if(bb%b==0)ss=(bb/b);
			else{
				ss=bb/b+1;
			}
			long long mx = max(kk, ss);
			aa = a * mx;
			bb = b * mx;		   
		}
	}
	cout<<aa+bb<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = readline()
T = readline()
S = list(S.rstrip())
T = list(T.rstrip())
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

g = gcd(N, M)
l = N * M // g
x = l // N
y = l // M

for i,s in enumerate(S[::y]):
    if s != T[x*i]:
        print(-1)
        exit()
print(l)

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

int main(void)
{
  while (true)
  {
    int goal;
    cin >> goal;
    if ( goal == 0 ) break;
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
      int start, finish;
      cin >> start >> finish;
      sum += finish - start;
    }
    if (sum < goal)
    {
      cout << goal - sum << endl;
    }
    else
    {
      cout << "OK" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
using ll = long long;
#define INF 1LL << 59
//西暦⇒時代の歴

ll N, M;
ll d[101], pre[101];
ll cost[1010][1010];
bool used[101];
bool check[101][101];

bool t[101][101];
void dijkstra(int s)
{
    for (int i = 0; i < N; ++i)
    {
        d[i] = INF;
        pre[i] = -1;
        used[i] = false;
    }
    d[s] = 0;
    while (true)
    {
        int v = -1;
        for (int u = 0; u < N; ++u)
        {
            if (!used[u] && (v == -1 || d[u] < d[v]))
                v = u;
        }
        if (v == -1)
            break;
        used[v] = true;
        for (int u = 0; u < N; ++u)
        {
            if (d[u] > d[v] + cost[v][u])
            {
                d[u] = d[v] + cost[v][u];
                pre[u] = v;
            }
        }
    }
}

void get_path(int t)
{
    for (; t != -1; t = pre[t])
        check[pre[t]][t] = false;
}

int main()
{
    cin >> N >> M;
    for (int i = 0; i < 101; ++i)
    {
        for (int j = 0; j < 101; ++j)
        {
            cost[i][j] = 1e9;
        }
    }

    for (int i = 0; i < 101; ++i)
        cost[i][i] = 0;

    for (int i = 0; i < M; ++i)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        cost[a][b] = c;
        cost[b][a] = c;
        check[a][b] = true;
        check[b][a] = true;
        // G[a].push_back({b, c});
        // G[b].push_back({a, c});
    }
    ll cnt = 0;
    for (int i = 0; i < N; ++i)
    {
        dijkstra(i);
        for (int j = 0; j < N; ++j)
        {
            if (i != j)
                get_path(j);
        }
    }

    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            if (cost[i][j])
            {
                if (check[i][j])
                {
                    cnt++;
                    check[i][j] = false;
                    check[j][i] = false;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll k;
    string s;
    cin >> k >> s;
    if(s.size()<=k) cout << s << endl;
    else{
    	rep(i,0,k-1) cout << s[i];
    	cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,sum=0,ans=0,Max=1,Min=1e9+1;
  string s,t,u;
  bool ok = true;
  cin >> n >> k;
  x = n;
  while(1){
    x = x/k;
    if(x>0)
      sum++;
    else{
      sum++;
      break;
    }
  }
  cout << sum << endl;
  return 0;
}

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

//	vector
template<typename T>
vector<T> trialDivision(T a) {
	vector<T> res;
	T i = 2;
	while (i * i <= a) {
		if (a % i == 0) {
			a /= i;
			res.push_back(i);
		}
		else ++i;
	}
	if (a != 1) res.push_back(a);
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<int> tmp = trialDivision(n);
	tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
	double ans = n;
	for (int& i : tmp) ans *= 1.0 - 1.0 / i;
	printf("%.f\n", ans);
}


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

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


int main() {

int n;
cin >> n;

int a[n];
rep(i,n)cin >> a[i];

sort(a,a+n);


cout << -a[0] + a[n-1] << endl;
 
return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<vector<bool>> s;
	vi anys;
	int KH = 2;
	anys.push_back(-1);
	rep(i, H) {
		string stmp;
		cin >> stmp;
		vector<bool> sstmp;
		bool anystmp = 0;
		rep(j, W) {
			if (stmp[j] == '#') {
				anystmp = 1;
				sstmp.push_back(1);
			}
			else
				sstmp.push_back(0);
		}
		if (anystmp) {
			anys.push_back(i);
			KH++;
		}
		s.push_back(sstmp);
	}
	anys.push_back(H - 1);
	vector<vi> ans;
	int count = 0;
	rep(i, KH) {
		if (i == 0)
			continue;
		if (i == KH - 1)
			continue;
		count++;
		int h = anys[i];
		//cout << h << endl;
		vi anstmp;
		int snum = 0;
		rep(j, W) {
			if (s[h][j]) {
				snum++;
				if (snum >= 2) {
					count++;
					count = min(count, K);
				}
			}
			anstmp.push_back(count);
		}
		int countprev = anys[i - 1];
		int countnext;
		if (i == KH - 2) {
			countnext = anys[i + 1];
		}
		else
			countnext = anys[i];
		//cout << countprev << " " << countnext << endl;
		int count = countnext - countprev;
		rep(p, count) {
			ans.push_back(anstmp);
		}
	}
	rep(i, H) {
		rep(j, W) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> num;
    if(s.at(0)=='0')num.push_back(0);

    for(int i=0; i<n;){
        int j=i;
        while(j<n and s.at(j)==s.at(i)){
            j++;
        }
        num.push_back(j-i);
        i=j;
    }

    if(s.at(n-1)=='0')num.push_back(0);

    vector<int> sum(num.size()+1,0);
    rep(i,0,num.size()){
        sum.at(i+1)=sum.at(i)+num.at(i);
    }

    int ans=0;
    for(int i=0; i<sum.size();i+=2){
        int j=i+k*2+1;
        if(j>=sum.size())j=sum.size()-1;
        ans=max(ans,sum.at(j)-sum.at(i));
    }
    cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1272
/**
 *      ABC 85 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-02 16:14:39
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, Y; cin >> N >> Y;
    int a = min(2000, Y / 1000); int b = min(2000, Y / 5000);

    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            if (i * 1000 + j * 5000 + (N - i - j) * 10000 == Y && i + j <= N){
                cout << N - i - j << " " << j << " " << i << endl;
                return 0;
            }
        }        
    }
    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
int  main(){
	ll n,k;
	cin>>n>>k;
	if(n==1){
		cout<<1<<endl;
		exit(0);
	}
	ll c=1;
	ll k1=k;
	while(k<n){
		c++;
		k=k*k1;
	}
	if(n==k){
		cout<<c+1<<endl;
		exit(0);
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long A, B, X; //ここをlongにしないせいでずっとエラー吐いてた
  long CC = 0;
  cin >> A >> B >> X;
  if (A > 0){
    A -= 1;
    CC = B/X - A/X;
  }
  else{
    CC = B / X;
    CC ++;
  }
  
  cout << CC << endl;
  
  /* int i = 0;
  int count = 0;
  if (B < X){
    cout << 0 << endl;
    exit(0);
  }
  while ((i <= X) and ((A+i) < B)){
    if ((A + i) % X == 0){
      CC = A + i;
      count = 1;
      break;
  	}
    i++;
  }
  if (CC == 0) and (count == 0)){
    cout << CC;
  }
  else{
    cout << (B - CC)/X + 1 << endl;
  }
  */
  //以上愚策、while使ったのが運の尽き
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
int n,m,Q;
vector<ll> primes;
map<ll,ll> change;
pair<ll,ll> norm(ll x){
	ll ret1=1,ret2=1;
	for(int i=0;i<primes.size();i++){
		ll p=primes[i];
		if(x<p)break;
		int cnt=0;
		while(x%p==0){
			//cout<<p<<endl;
			x/=p;
			cnt++;
		}
		cnt=cnt%3;
		if(cnt==1)ret1*=p,ret2*=(p*p);
		if(cnt==2)ret1*=(p*p),ret2*=p;
	}
	ret1*=x;
	ll y=sqrt(x);
	if(y*y==x)ret2*=y;
	else ret2*=(x*x);
	return mp(ret1,ret2);
}

int main(){
	cin>>n;
	vector<ll> data(n);
	//前準備
	for(ll i=2;i*i*i<=1e10;i++){
		bool flag=true;
		for(int j=0;j<primes.size();j++){
			if(i%primes[j]==0)flag=false;
		}
		if(flag)primes.pb(i);
	}
	//multiset<ll> anss;
	map<ll,int> anss;
	for(int i=0;i<n;i++){
		cin>>data[i];
		pair<ll,ll> hoge=norm(data[i]);
		change[hoge.first]=hoge.second;
		data[i]=hoge.first;
		anss[data[i]]++;
	}
	int ans=0;
	bool fflag=false;
	for(int i=0;i<n;i++){
		if(data[i]==1){fflag=true;continue;}
		//cout<<data[i]<<" "<<change[data[i]]<<endl;
		ll num1=anss[data[i]],num2=anss[change[data[i]]];
		if(num1>num2)ans+=2;
		else if(num1==num2)ans++;
		//cout<<num1<<" "<<num2<<endl;
	}
	ans/=2;
	if(fflag) ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dx2[] = { -1 , -1 , -1, 0 , 0 , 1 , 1 , 1};
int dy2[] = { -1 , 0 , 1 , -1, 1 , -1, 0, 1};

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int n; cin >> n;
	int c = 0;
	n--;
	for (int i = 1; i <= n; i++) c += (n / i);
	cout << c;
	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int v[1<<18];
int w[1<<18];
int q;
int V[1<<18];
int L[1<<18];

int dp[1<<9][100100];

void solve() {
    const int t = 9;
    for (int i = 1; i < min(n+1,1<<t); i++) {
        for (int j = 0; j <= 100000; j++) {
            dp[i][j] = dp[i/2][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], v[i]+dp[i/2][j-w[i]]);
            }
        }
    }

    for (int i = 0; i < q; i++) {
        if (V[i] < (1<<t)) {
            cout << dp[V[i]][L[i]] << endl;
        } else {
            vector<P> vec;
            int idx = V[i];
            while (idx >= (1<<t)) {
                vec.push_back(P(v[idx], w[idx]));
                idx /= 2;
            }
            int res = 0;
            const int sz = (int)vec.size();
            for (int j = 0; j < (1<<sz); j++) {
                int sum_v = 0, sum_w = 0;
                for (int k = 0; k < sz; k++) {
                    if ((j>>k)&1) {
                        sum_v += vec[k].first;
                        sum_w += vec[k].second;
                    }
                }
                if (sum_w <= L[i]) {
                    res = max(res, sum_v+dp[idx][L[i]-sum_w]);
                }
            }
            cout << res << endl;
        }
    }
}

void input() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
    cin >> q;
    for (int i = 0; i < q; i++) cin >> V[i] >> L[i];
        
}

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

    input();
    solve();
}


Measured memory_bytes: 205748
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,ans,pw=1;
int main()
{
	cin>>n;
	while(n!=0)
	{
		ans+=pw;
		pw*=2;
		n/=2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

list_a = []
for part in input().split():
    list_a.append(int(part))

a_len = len(list_a) - K
cnt = 1
while True:

    if (K-1) <= a_len:
        a_len -= K - 1
        cnt += 1    
    else:
        if a_len != 0:
            cnt += 1
        break

print(cnt)

Measured memory_bytes: 13880
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<pair<string,pair<int,int> > > store;

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

    for(int i = 0;i < N;i++) {
        string s;
        int p;
        cin>>s>>p;
        pair<string, pair<int,int>> temp;
        temp.first = s;
        temp.second.first = -p;
        temp.second.second = i+1;
        store.push_back(temp);
    }

    sort(store.begin(),store.end());

    for(int i = 0;i < N;i++) {
        cout<<store[i].second.second<<endl;
    }

    return 0;
}


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

#define SIZE 500000
#define INFTY 1200000000
int count = 0;

void show(int* a, int size)
{
    int i;
    cout << a[0];
    for(i = 1; i < size; i++) cout << " " << a[i];
    cout << endl;
}

void Merge(int* A, int left, int mid, int right)
{
    int R[SIZE], L[SIZE];
    int i, j, k, n1, n2;
    n1 = mid - left;
    n2 = right - mid;
    for(i = 0; i < n1; i++) L[i] = A[i + left];
    for(j = 0; j < n2; j++) R[j] = A[j + mid];

    L[n1] = INFTY;
    R[n2] = INFTY;
    i = j = 0;

    for(k = left; k < right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
        count++;
    }
}

void MergeSort(int* A, int left, int right)
{
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
    }
    return;
}

int main()
{
    int i, n, S[SIZE];
    cin >> n;
    for(i = 0; i < n; i++) cin >> S[i];

    MergeSort(S, 0, n);
    show(S, n);
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 5076
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
pair<ll,ll> ps[1<<20];
const ll INF=1e15;
int main()
{
	int n;cin>>n;
	ll W;cin>>W;
	ll v[40],w[40];
	for(int i=0;i<n;i++)cin>>v[i]>>w[i];
	int n2=n/2;
	for(int i=0;i<1<<n2;i++)
	{
		ll sw=0,sv=0;
		for(int j=0;j<n2;j++)
		{
			if(i>>j&1)
			{
				sw+=w[j];
				sv+=v[j];
			}
		}
		ps[i]=make_pair(sw,sv);
	}
	sort(ps,ps+(1<<n2));
	int m=1;
	for(int i=1;i<1<<n2;i++)
	{
		if(ps[m-1].second<ps[i].second)
		{
			ps[m++]=ps[i];
		}
	}
	
	ll res=0;
	for(int i=0;i<1<<(n-n2);i++)
	{
		ll sw=0,sv=0;
		for(int j=0;j<n-n2;j++)
		{
			if(i>>j&1)
			{
				sw+=w[n2+j];
				sv+=v[n2+j];
			}
		}
		if(sw<=W)
		{
			ll tv=(lower_bound(ps,ps+m,make_pair(W-sw,INF))-1)->second;
			res=max(res,sv+tv);
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 19484
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
//#define P pair<ll, ll>

#define P pair<int, int>
#define PP pair<P, P>
int n, k;

int gcd(int a, int b) {
    return (b == 0 ? a : gcd(b, a % b));
}
P solve(P x){
    if (x.second == 0) return {INF, 0};
    else if (x.first == 0) return {0, 1};
    else if(x.second < 0){
        x.first *= -1;
        x.second *= -1;
    }
    int g = gcd(x.first, x.second);
    x.first /= g;
    x.second /= g;
    return x;
}
int x[3100], y[3100];
int main(){
    cin >> n >> k;
    REP(i, n){
        cin >> x[i] >> y[i];
    }
    REP(i, n){
        map<PP, int> mp;
        FOR(j, i + 1, n){
            int x1 = x[i], x2 = x[j], y1 = y[i], y2 = y[j];
            P a = solve({y2 - y1, x2 - x1});
            P b;
            if (a == P(INF, 0)) b = {x1, 0};
            else if(a == P(0, 1)) b = {y1, 1};
            else{
                b = solve({y1 * a.second - a.first * x1, a.second});
            }
            mp[{a, b}]++;
            if(mp[{a, b}] >= k - 1){
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}




Measured memory_bytes: 3288
#include<stdio.h>
int main(void)
{
	int A,B,C,D,N,M;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	if(A*B>=C*D){
			M=A*B;
			printf("%d\n",M);
	}
	if(A*B<C*D){
			N=C*D;
			printf("%d\n",N);
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main() {
  int n;
  cin>>n;
  int w[n];
  int sum=0;
  for(int i=0;i<n;i++) {
    cin>>w[i];
    sum+=w[i];
  }
  sum-=w[0];
  int s=w[0];
  int ans=abs(s-sum);
  for(int t=1;t<n-1;t++){
    s+=w[t];
    sum-=w[t];
    ans=min(ans,abs(s-sum));
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n;
    cin >> n;
    double sum=0;
    rep(i,n){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY")sum += x;
        else sum += x*380000;
    }
    cout << fixed << setprecision(10) << sum << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void) {
     
    for(;;){
        int i;
        int sum = 0;
        double avg,sd;
        int n;
        int s[1000] = {0};
     
        scanf("%d",&n);
        if(n == 0)break;
        else {}
         
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum = sum +s[i];
        }
     
        avg = 1.0000 * sum/n;
     
        //printf("%d %lf\n",sum,avg);
     
        sd = 0;
        for(i = 0;i<n;i++){
            sd = sd+(s[i]-avg)*(s[i]-avg);
        }
        sd = sqrt(sd / n);
     
        printf("%lf\n",sd);
    }   
    return 0;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    char c = scanner.next().charAt(0);
    switch (c) {
      case 'a':
      case 'i':
      case 'u':
      case 'e':
      case 'o':
        System.out.println("vowel");
        break;
      default:
        System.out.println("consonant");
    }
  }
}


Measured memory_bytes: 21588