akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e4) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, w[105]{};
    cin >> n;
    REP(i,n) {
        cin >> w[i+1];
        w[i+1] += w[i];
    }
    int ans = IINF/2;
    for(int i=1;i<n;i++){
        ans = min(ans, abs(w[n]-w[i]-w[i]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
    if (parseInt(input) >= 30 ) {
        console.log(`Yes`);
    } else {
        console.log(`No`);
    }
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29680
from collections import deque
N, M = map(int, input().split())
INF = -1
dist = [[INF]*3 for _ in range(N)]
vector = [[] for _ in range(N)]

for i in range(M):
    graf1, graf2 = map(int, input().split())
    vector[graf1-1].append(graf2-1)
S, T = map(int, input().split())
S, T = S-1, T-1

# BFS
dist[S][0] = 0
q = deque()
q.append((S, 0))
while q:
    v, l = q.popleft()
    for i in vector[v]:
        new_l = (l+1)%3
        if dist[i][new_l] != INF:
            continue
        dist[i][new_l] = dist[v][l] + 1
        q.append((i, new_l))

ans = dist[T][0]
if ans == INF:
    print("-1")
else:
    print(int(ans/3))

Measured memory_bytes: 38104
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    printf("%d\n", fibonacci(n));
    return 0;
}
int fibonacci(int n){
    int i;
    int a=1, b=1, c=1;
    for(i=2; i<=n; i++){
        a=b+c;
        c=b;
        b=a;
    }
    return b;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int K;
    cin >> K;
    vector<lli> A(K);
    REP (i, 0, K) cin >> A[i];
//    int t_m = 100000, t_M = -1;
//     REP (i, 1, 10000) {
//         int a = i;
//         bool ok = true;
//         for (int md : A) {
//             if (a < md) ok = false;
//             a = a / md * md;
//         }
//         if (ok && a == 2) {
// //            cout << i << endl;
//             t_m = min(t_m, i);
//             t_M = max(t_M, i);
//         }
//     }
//     cout << "debug: " << t_m << " " << t_M << endl;



    if (A[K - 1] != 2) {
        cout << -1 << endl;
        return 0;
    }
    lli m = 2, M = 3;
    for (int i = K - 2; i >= 0; i--) {
        if (m % A[i] != 0) {
            m = (m / A[i] + 1) * A[i];
        }
        if (M % A[i] != 0) {
            M = M / A[i] * A[i];
        }
        //dump(m);
        //dump(M);
        if (m > M) {
            cout << -1 << endl;
            return 0;
        }
        M = max(M, m) + A[i] - 1;
    }
    cout << m << " " << M << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

ll gcd(ll a, ll b){
	if(b == 0)
		return a;
	return gcd(b,a%b);
}

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

	ll n;
	cin>>n;

	map<pair<int,int>,ll> f;

	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		ll a=0,b=0;
		for(int j=0;j<s.length();j++){
			if(s[j] == '.'){
				b = 1;
				continue;
			}

			int idx = s[j]-'0';
			a = a*10 + idx;
			b = b*10;
		}

		if(b == 0)
			b = 1;
			
		int r1=0,r2=0;
		while(a%2 == 0){
			++r1;
			a /= 2;
		}

		while(b%2 == 0){
			--r1;
			b /= 2;
		}

		while(a%5 == 0){
			++r2;
			a /= 5;
		}

		while(b%5 == 0){
			--r2;
			b /= 5;
		}

		++f[{r1,r2}];
	}			



	ll ans = 0;
	map<pair<int,int>,ll>::iterator it1,it2;
	// for(it1 = f.begin(); it1 != f.end(); it1++){
	// 	cout<< (it1->ff).ff << " " << (it1->ff).ss << " " << it1->ss << "\n";
	// }


	for(it1 = f.begin(); it1 != f.end(); it1++){
		it2 = it1;
		++it2;
		while(it2 != f.end()){
			if((it1->ff).ff + (it2->ff).ff >= 0 && (it1->ff).ss + (it2->ff).ss >= 0)
				ans += (it1->ss)*(it2->ss);
			it2++;
		}

		if((it1->ff).ff >=0 && (it1->ff).ss >= 0)
			ans += (it1->ss)*(it1->ss-1)/2;
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 3676
package main

import "fmt"

func main() {
	// Code for A - Study Scheduling
	var H1, M1, H2, M2, K int
	fmt.Scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K)

	before := 60*H1 + M1
	after := 60*H2 + M2

	fmt.Println(after - before - K)
}


Measured memory_bytes: 1836
use std::io;

fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split(' ').flat_map(str::parse).collect()
}

fn main() {
    let l1 = read::<u32>();

    let a = l1[0];
    let b = l1[1];
    let c = l1[2];

    let ans = match () {
        () if a < b && b < c => "Yes",
        _ => "No"
    };

    println!("{}", ans);
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
   string s;
   vector<string> ans(s.size());
   cin >> s;
   rep(i,s.size()){
       s[i]='x';
   }
   cout << s << endl;

 }


Measured memory_bytes: 256
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True) + [-1]
B = sorted(list(map(int, input().split())), reverse=True) + [-2]
MOD = 10 ** 9 + 7


ans = 1
i, j = 0, 0
for n in range(N * M, 0, -1):
    if A[i] == B[j] == n:
        i += 1
        j += 1
        
    elif A[i] == n:
        ans *= j
        ans %= MOD
        i += 1
        
    elif B[j] == n:
        ans *= i
        ans %= MOD
        j += 1
    
    else:
        ans *= ((i * j) - ((N * M) - n))
        ans %= MOD

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int uu=0;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(t%2==1){
			uu++;
		}
	}
	if(uu%2==1)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
pagos=0
lines = sys.stdin.readlines()
for linea in lines:
    c = linea.split()
    c = list(map(int,c))
list(c)
p = c[0]
x = c[0]*800
for k in range(1,(p+1)):
  if k%15 ==0:
    pagos+=200
total = x-pagos
print(total)   

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using edge = tuple<int, int, int>;
using ll = long long;
using pq = priority_queue <int>;
using minHeap = priority_queue <int, vector<int>, greater<int> >;
// INSERIR EM TUPLA std::get<0>(mytuple) = 0 << " and " << std::get<1>(mytuple);
// std::map<key, value> map;

int main(int argc, char const *argv[])
{
  int n;
  std::cin >> n;
  int total;
  std::cin >> total;
  std::vector<int> v;;
  int aux = 0;
  int gram;
  for (size_t i = 0; i < n; i++)
  {
    std::cin >> gram;
    v.push_back(gram);
  }
  sort(v.begin(),v.end());
  for (size_t i = 0; i < v.size(); i++)
  {
    aux = aux + v[i];
  }
  int menor = v[0];
  int cont = n;
  total  = total - aux;

  while (total>=menor)
  {
    total = total - menor;
    cont++;
  }

  std::cout << cont << '\n';
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll ans = 1000000000000;
  for (ll i = 1; i*i <= n; i++) {
    ll j = n/i;
    if (i*j == n) {
      ans = min(ans, i+j-2);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

struct info
{
	int c, m;
};

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<info> a;
	for (int k; m--; )
	{
		a.push_back({ 0, 0 });
		cin >> a.back().c >> k;
		for (int i = 0, x; i < k; ++i)
		{
			cin >> x;
			a.back().m |= 1<<(x-1);
		}
	}

	vector<int> dp(1<<n, 1e9);
	dp[0] = 0;
	for (int i = 0; i < 1<<n; ++i)
		for (auto j : a)
			dp[i | j.m] = min(dp[i | j.m], dp[i] + j.c);

	int ans = dp[(1<<n)-1];
	if (ans >= 1e9) ans = -1;
	cout << ans << "\n";

	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> C(N);

    REP(i, N){
        cin >> C[i];
    }

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

    vector<ll> MP(N+1, 0);

    // 2^Nの前処理
    REP(i, N+1){
        if(i == 0){
            MP[0] = 1;
            continue;
        }
        MP[i] = MP[i-1]*2;
        MP[i] = MP[i] % MOD;
        // cout << MP[i] << endl;
    }

    ll ans = 0;

    REP(i, N){
        ll temp = 0;
        temp += (MP[N-1]*C[i]) % MOD;
        temp = temp % MOD;

        temp += (((MP[N-2]*(N-1-i))%MOD)*C[i])%MOD;
        temp = temp % MOD;
        // cout << temp << endl;
        ans += temp;
        ans = ans % MOD;
    }
    ans = (ans*MP[N]) % MOD;

    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 6408
N, K = map(int, input().split())
dislike = list(input().split())

while True:
    M = str(N)
    numbers = list(M)
    matchedlist = []
    for a in dislike:
        for b in numbers:
            if a == b:
                matchedlist.append(a)
    
    if matchedlist == []:
        break

    N += 1

print(N)
        

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

int gcd(int a, int b){return (a % b)? gcd(b, a % b) : b;}
int lcm(int a, int b){return a * b / gcd(a, b);}

void solve_A(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int hour1 = h1 * 60 + m1;
    int hour2 = h2 * 60 + m2;
    cout << hour2 - hour1 - k << endl;
}

int main(void){
    solve_A();
    
    return 0;
}

Measured memory_bytes: 3624
//...START BY DOING WHAT IS NECESSARY, THEN WHAT IS POSSIBLE AND SUDDENLY YOU ARE DOING THE IMPOSSIBLE... 
// ................. WORK UNTILL YOUR IDOLS BECOME YOUR RIVALS................................

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pb emplace_back
#define f first
#define mp make_pair
#define s second
#define delrep  a.erase(unique(a.begin(),a.end()),a.end());
#define all(a)  (a).begin(),(a).end()
#define sz(x)   (int)x.size()
#define lll __int64
const int N=1000;
const int mod=998244353;
using namespace std;
int get_second( pair<int, int> i ){ return i.second; }  
int trail_zero(int n){while (n % 10 == 0) n /= 10 ; return n;}
typedef long long ll;
map<ll,ll> m11;
multiset<ll> s1;
map<pair<ll,ll>,ll> m1;
vector<pair<int,int>>v;
vector<int>ans;
map<char,int>m4;
map<char,int>m5;
char s111[N];
ll p2[N],p3[N];
//ll h[N];
ll n,k,m,x,y,ans1=INT_MAX;
bool check(int a,int b) { if(a>=0 || a<n) return true; if(b>=0 || b<m) return true; else return false;}
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
// char s[500][500];
vector<vector<ll>> adj(N);
vector<ll> vis(N),in(N),out(N),cnt(N);
vector<ll>ansx;
map<ll,ll>mx;
bool used[111][11];
void dfs( ll x, ll y )
{
    if( x<1 || x>10000 || used[x][y] || y>10000 ) return;
    if( x==m ) ans1=min(ans1, y);
    used[x][y]=1;
    dfs( x-1, y+1 );
    dfs( x*2, y+1 );
}
vector<pair<int, int>> e(100002), o(100002);
bool prime_check(ll a)
{
    if(a == 2)
        return true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i)
            continue;
        return false;
    }
    return true;
}
int smallest_divisor(ll a)
{
  for(int i=2;i*i<=a;i++)
  {
    if(a%i==0) return i;
  }
  return a;
}
 
int main()
{
  ll n,ans=INT_MAX,k; cin>>n>>k; ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n-k+1;i++) 
  { ans=min(ans,abs(a[i])+abs(a[i+k-1]-a[i])); ans=min(ans,abs(a[i+k-1])+abs(a[i+k-1]-a[i])); }
  cout<<ans;
  return 0;
}
 



Measured memory_bytes: 2688
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
bi=[0]* N
children = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    b-=1
    bi[i]=b
    children[a-1].append(b)

queue = deque([0])
colors = [0] * N
maxColor = 0
while queue:
    node = queue.popleft()
    nodeColor = colors[node]
    color = 1
    for child in children[node]:
        if color == nodeColor: color += 1
        colors[child] = color
        queue.append(child)
        color += 1
    maxColor = max(maxColor, color-1)

print(maxColor)
for i in range(N-1):
    print(colors[bi[i]])

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


int main(){
    int H,W;
    cin >> H >> W;
    int c[10][10];
    int cnt[10] = {0};
    int a;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> a;
            if(a!=-1) cnt[a]++;
        }
        
    }
    
    for (int k = 0; k < 10; k++)
    {
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 10; i++)
    {
        ans += cnt[i]*c[i][1];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N,ans,r,j,i,l;
    cin >> N;
  	int h[1100] = {0};
    for(int i = 0; i < N; ++i) cin >> h[i];
    ans = 0;
    for(int l=0; l<N; l++){
        while(h[l]>0){
            
            for(r = l+1; r<N; r++){
                if(h[r] == 0) break;
            }

            for(int i = l; i<r; i++) --h[i];
            ans++;
        }
    }

    cout << ans << endl;
}


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

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

signed main() {
  int n, m;
  cin >> n >> m;

  int x[1010][3];
  rep(i, n) rep(j, 3) cin >> x[i][j];

  int ans = 0;
  rep(bit, 8) {
    vector<int> v(n);
    rep(i, n) rep(j, 3) v[i] += (bit & (1 << j) ? -1 : 1) * x[i][j];

    sort(v.rbegin(), v.rend());
    ans = max(ans, accumulate(v.begin(), v.begin() + m, 0ll));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX_CAND 50 // 候補者の最大数

int main (void){
  int n; // 候補者の数
  int p; // 石の総数
  
  while(scanf("%d %d",&n,&p) != EOF){
    int stones_in_ball = p; // 碗に入っている石の数
    int now_candidate = 0; // 現在の候補者
    int cand_stones[MAX_CAND]; // 各候補者が持っている石の数
    int i;

    /* 0 0が入力されたら終了 */
    if(n==0 && p==0)
      break;
    
    /* 初めは全ての候補者はひとつも石を持っていない */
    for(i=0;i<n;i++) // n人分だけ初期化
      cand_stones[i] = 0; 

    /* ゲーム開始 */
    while(1){
      /* 碗に一つも石が入っていなかったとき */
      if (stones_in_ball == 0){
	/* 今の候補車の手持ち石を全て碗に戻す */
	stones_in_ball = cand_stones[now_candidate]; 
	cand_stones[now_candidate]=0;
      /* 碗に石が入っていた時 */
      } else {
	stones_in_ball--; // 碗から石を一つとって
	cand_stones[now_candidate]++; // 今の人の手持ちに加える

	if(cand_stones[now_candidate]==p) // もし，今の人の手持ちが石の総数と同じなら，他の人は石をひとつも持っていないので
	  break; // 今の候補者が次期町長となる	
      }
	
      now_candidate++; // 次の候補者に番を回す
      if(now_candidate==n) // 候補者一巡したら現町長に順を戻す
	now_candidate=0;
      
    }

    /* 当選者を表示 */
    printf("%d\n", now_candidate);
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (c-(a-b) > 0){
        cout << c-(a-b) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
'''
https://atcoder.jp/contests/s8pc-3/tasks/s8pc_3_b
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    h,w,k = map(int, input().split())
    banmen = []
    for _ in range(h):
        s = input().rstrip()
        s = list(s)
        s = list(map(int, s))
        banmen.append(s)

    def update():
        while 1:
            cnt = 0
            for i in range(h-1):
                for j in range(w):
                    if c[i+1][j] == 0 and c[i][j] != 0:
                        c[i][j], c[i+1][j] = c[i+1][j], c[i][j]
                        cnt += 1
            if cnt == 0:
                return

    #n回目(0~)
    def get(n):
        total = 0
        for i in range(h):
            for j in range(0, w-k+1, 1):
                ten = c[i][j]
                cnt = 1
                while c[i][j] == c[i][j+1]:
                    cnt += 1
                    j += 1
                    if j == w-1:
                        break
                if cnt >= k:
                    total += 2**n * (ten*cnt)
                    c[i][j-(cnt-1):j+1] = [0]*cnt
        return total

    def solve(i, j):
        c[i][j] = 0
        res = 0
        n = 0
        while 1:
            update()
            total = get(n)
            if total == 0:
                break
            n += 1
            res += total
        return res

    import copy
    res = 0
    for i in range(h):
        for j in range(w):
            c = copy.deepcopy(banmen) 
            res = max(res, solve(i, j))
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 54492
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const bool DEBUG = true;

const int MAX = 10000001;
//int dp[MAX][10]; // dp[i][j]:i桁目がj円のときの最小の払い方
ll dp[MAX][2]; // 繰りこしあり，なし

int main(){

    string n;
    cin >> n;

    for(int i = 0; i < MAX; i++){
        dp[i][0] = INT_MAX;
        dp[i][1] = INT_MAX;
    } 

    vector<int> v( n.size() );
    for(int i = 0; i < n.size(); i++){
        v[ v.size() - i - 1 ] = (n[i] - '0');
    }

    dp[0][0] = v[0]; 
    dp[0][1] = 1 + 10 - v[0];

    for(int i = 1; i < v.size(); i++){

        ll v1, v2;
        // nashi / ari
        v1 = dp[i-1][1] + v[i];
        // nashi / nashi
        v2 = dp[i-1][0] + v[i];

        dp[i][0] = min(v1, v2);


        //ari / nashi
        v1 = dp[i - 1][0] + (10 - v[i]) + 1;

        //ari / ari
        v2 = dp[i - 1][1] - 1 + (10 - v[i])  ;
        dp[i][1] = min(v1, v2);


    }
    /*
    for(int i = 0; i <= 2; i++){
        for(int j = 0; j < 2; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */

    cout << min( dp[n.size() - 1][0], dp[n.size() - 1][1] ) << endl;

    /*
    for (size_t i = 0; i < n.size(); i++)
    {   
        cout << v[i] << " "; 
    }
    */
    
    /*
    for(int i = 0; i < MAX; i++){
        for(int j = 0; j <= 9; j++){
            dp[i][j] = n.size() * 10;
        }
    }


    for(int i = 0; i <= 9; i++){
        dp[0][i] = min( i, ( 1 + 10 - i ) );
        cout << dp[0][i] << " ";
    }
    cout << endl;


    for(int i = 1; i < MAX; i++){
        for(int j = 0; j <= 9; j++){
            vector<ll> v(3);
            // ぴったり
            v[0] = dp[i - 1][j] + 1;

            // 一枚多い

            // ゼロ枚

        }
    }
    */


    



}

Measured memory_bytes: 161668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for(ll i=(a);i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mpp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define ln(a) a.length()
#define sz(a) a.size()
#define endl "\n"
int M=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

int h,w;cin>>h>>w;string a[h];
f(i,0,h)cin>>a[i];
ll dp[h+1][w+1];
memset(dp,0,sizeof dp);
dp[0][0]=1;
f(i,1,h){if(a[i][0]=='.')dp[i][0]=dp[i-1][0]%M;}
f(i,1,w){if(a[0][i]=='.')dp[0][i]=dp[0][i-1]%M;}
f(i,1,h)
{
    f(j,1,w)
    {
        if(a[i][j]=='.')
        {
            dp[i][j]=(dp[i-1][j]%M+dp[i][j-1]%M)%M;
        }
    }
}
cout<<dp[h-1][w-1]%M<<endl;
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

string s;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>s;
  int mx=0;
  set<char> st;
  st.insert('A');
  st.insert('C');
  st.insert('G');
  st.insert('T');  
  for(int i=0;i<sz(s);i++){
      int cnt=0;
      for(int j=i;j<sz(s)&&st.count(s[j]);j++)cnt++;
      mx=max(mx,cnt);
  }
  cout<<mx;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int n, l, q;
//nx[i][j] := x[j]からスタートして、2^i日後に行ける最も遠いホテルの番号(xの添字)
int nx[20][100010];
int main(void){
	cin >> n;
	vector<int> x(n);
	rep(i, n) cin >> x[i];
	cin >> l >> q;

	//ダブリング
	for (int j = 0; j < n; ++j){
		nx[0][j] = upper_bound(x.begin(), x.end(), x[j] + l) - x.begin() - 1;
	}
	for (int i = 1; i < 20; ++i){
		for (int j = 0; j < n; ++j){
			nx[i][j] = nx[i - 1][nx[i - 1][j]];
		}
	}

	for (int k = 0; k < q; ++k){
		int a, b; cin >> a >> b;
		--a; --b;
		if(b < a) swap(a, b);
		int ans = 0;
		int now = a;
		for (int i = 19; i >= 0; --i){
			if(nx[i][now] < b){
				now = nx[i][now];
				ans += 1 << i;
			}
		}
		cout << ans + 1 << endl;
	}
}

Measured memory_bytes: 9088
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    x = [int(xi) for xi in input().split()]
    print(x.index(0) + 1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 65204
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	tx-=sx;
	ty-=sy;
	for(int i=0;i<tx;i++){
		cout << 'R';
	}
	for(int i=0;i<ty;i++){
		cout << 'U';
	}
	for(int i=0;i<tx;i++){
		cout << 'L';
	}
	for(int i=0;i<ty+1;i++){
		cout << 'D';
	}
	for(int i=0;i<tx+1;i++){
		cout << 'R';
	}
	for(int i=0;i<ty+1;i++){
		cout << 'U';
	}
	cout << "LU";
	for(int i=0;i<tx+1;i++){
		cout << 'L';
	}
	for(int i=0;i<ty+1;i++){
		cout << 'D';
	}
	cout << 'R' << endl;

	return 0;
}



Measured memory_bytes: 256
fun main() {
    val w = next().toCharArray().sorted()
    var c = w[0]
    var count = 0
    w.forEach {
        when {
            c == it -> count++
            count % 2 == 0 -> {
                c = it
                count = 1
            }
            else -> {
                println("No")
                return
            }
        }
    }
    println(
        if (count % 2 == 0) {
            "Yes"
        } else {
            "No"
        }
    )
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

const ld pi = acos(-1.0);

int main(){
  fastio

  ld a, b, x;
  cin >> a >> b >> x;
  ld f = x * 2;
  f /= a;
  f /= b;
  f /= b;
  f = atan(f);
  f *= 180.00;
  f /= pi;
  f = 90.000 - f;

  ld g = 2 * x;
  g /= a;
  g /= a;
  g -= b;
  if(g > 1e-6){
    b -= g;
    a /= b;
    g = atan(a);
    g *= 180.000;
    g /= pi;
    g = 90.000 - g;
    f = min(f, g);
  }

  decimal_digits
  cout << f << '\n';

  ktj();
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,n;
    cin>>k>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int pre[n + 5];
    int ans = 1e18;
    int cnt = a[0];
    pre[0] = a[0];
    // cout<<a[0]<<" ";
    for(int i=1;i<=n;i++){
        if(i == n){
            pre[i] = k - a[i - 1];
            // pre[i] += a[0];
        }else{
            pre[i] = a[i] - a[i - 1];
        }
        cnt += pre[i];
        // cout<<pre[i]<<" ";
    }
    // cout<<endl;
    // cerr<<cnt<<endl;
    int sub = 0;
    for(int i=0;i<n;i++){
        if(i == 0){
            int x = cnt;
            x -= pre[0];
            x -= pre[n];
            // cerr<<x<<endl;
            ans = min(ans,x);
        }else{
            int x = cnt;
            x -= pre[i];
            // x -= sub;
            // cerr<<x<<endl;
            ans = min(ans,x);
        }
        sub += pre[i];

    }
    cout<<ans<<endl;
    return 0;
    
}



Measured memory_bytes: 3328
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    const Q = parseInt(arg[2].split(" ")[0]);
    const BC = arg.slice(3, Q + 3);
    
    let map = {};
    let sum = A.reduce((m,n)=>m+n);
    
    let answer = [];
    
    for(let i=0; i<N; i++) {
        if(!map[A[i]]) {
            map[A[i]] = 1;
        } else {
            map[A[i]]++;
        }
    }
    
    // console.log(JSON.stringify(map));
    // console.log(BC);

    for(let i=0; i<Q; i++) {
        const B = parseInt(BC[i].split(" ")[0]);
        const C = parseInt(BC[i].split(" ")[1]);
        
        let abs = C - B;
        
        
        if(map[B]) {
            sum += abs * map[B];
            
            if(map[C]) {
                map[C] += map[B];
            } else {
                map[C] = map[B];
            }
            
            map[B] = false;
        }
        
        answer.push(sum);
    }
    
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 66912
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int a=1;
  for(int i=0;i<n;i++){
    if(a<k)
      a*=2;
    else
      a+=k;
  }
  cout<<a;
}

Measured memory_bytes: 256
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 103000;

    void solve() {
    	string a, b;
    	cin >> a >> b;
    	if(a.length() != b.length()){
    		cout << ( a.length() > b.length() ? "GREATER" : "LESS" ) << endl;
    	} else {
    		rep(i, a.length()){
    			if(a[i] > b[i]) {
    				cout << "GREATER" << endl;
    				return;
    			} else if(b[i] > a[i]) {
    				cout << "LESS" << endl;
    				return;
    			}
    		}
    		cout << "EQUAL" << endl;
    	}
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //te
      solve();
      return 0;
    } 

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

using namespace std;

int main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL);

    string S;
    cin >> S;
    
    int count = 0, ret = 0;
    
    for(int i = 0; i < S.length(); i++) {
        if(S[i] == 'R') {
            count++;
        } else {
            ret = max(ret, count); //returns biggest value -> ret
            count = 0; //update count
        }
    }
    ret = max(ret, count);

    cout << ret << endl;

    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n; string s;
    cin>>n;
    cin.ignore();
    cin>>s;
    if(n%2) {cout<<"No";return 0;}
    for(int i=0;i<n/2;++i)
    {
        if(s[i]!=s[n/2+i]) {cout<<"No";return 0;}
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
N=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))

ans=0
for i in range(N):
  if l1[i]>=l2[i]:
    ans+=l2[i]
  elif l1[i+1]+l1[i]>=l2[i]:
    l1[i+1]=l1[i+1]-(l2[i]-l1[i])
    ans+=l2[i]
  else:
    ans+=l1[i]+l1[i+1]
    l1[i+1]=0
print(ans)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
long long dp[1001][1001];
long long a[1001],b[1001],c[1001];
int x,y,z;
int n,m;
bool vis[1001][1001];
long long DP(int i,int j)
{
    if (i==n && j==m)return 0;
    if (i==n) return -(1LL<<55);
    if (vis[i][j])return dp[i][j];
    vis[i][j]=1;
    return dp[i][j]=max(DP(i+1,j),DP(i+1,j+1)+x*a[i]+y*b[i]+z*c[i]);
}
int main()
{
    cin>>n>>m;
    for (int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    long long ret = -(1LL<<55);
    for (x=-1;x<=1;x+=2)
    {
        for (y=-1;y<=1;y+=2)
        {
            for (z=-1;z<=1;z++)
            {
                memset(vis,0,sizeof(vis));
                ret=max(ret,DP(0,0));
            }
        }
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<class Monoid>
class SegmentTree{
private:
  using T = typename Monoid::T;
  const size_t n;
  vector<T> d;

  void build(){
    for(size_t b = n - 1; b > 0; b--) d[b] = Monoid::op(d[b << 1], d[b << 1 | 1]);
  }

public:
  SegmentTree() {}

  SegmentTree(size_t n)
    : n(n), d(2 * n, Monoid::identify()) {}

  template<typename InputItr>
  SegmentTree(InputItr first, InputItr last)
    : n(distance(first, last)), d(2 * n, Monoid::identify()){
    copy(first, last, next(d.begin(), n));
    build();
  }

  /* set one value */
  void modify(size_t k, T v){
    for(d[k += n] = v; k > 1; k >>= 1) d[k >> 1] = Monoid::op(d[k], d[k ^ 1]);
  }

  /* return [l, r) value */
  T query(size_t l, size_t r){
    T res {Monoid::identify()};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l&1) res = Monoid::op(res, d[l++]);
      if (r&1) res = Monoid::op(res, d[--r]);
    }
    return res;
  }
  
  void dump(){
    REP(i, 2 * n) cout << i << ": " << d[i].first << ", " << d[i].second << " " << endl;
  }
};

/* Range Min Query */
template<typename U = ll>
struct RMQ{
  using T = pair<U, U>;
  static T op(const T& a, const T& b){ return min<T>(a, b); };
  static constexpr T identify(){ return make_pair(numeric_limits<U>::max(), numeric_limits<U>::max()); };
};

using graph = vector<vector<int>>;

/* for tree, not graph */
class LCA{
private:
  const int n;
  const graph g;
  vector<int> vs, depth, id;
  SegmentTree<RMQ<int>> tree;

  /* init vs, depth, id */
  void dfs(int v, int pv, int d, int& k){
    vs.push_back(v);
    depth.push_back(d);
    id[v] = vs.size() - 1;

    for(const int u: g[v]){
      if(u != pv){
        k++;
        dfs(u, v, d+1, k);
        vs.push_back(v);
        depth.push_back(d);
      }
    }
  }

  /* build SegmentTree */
  void build_rmq(){
    REP(i, 2 * n - 1){
      tree.modify(i, {depth[i], vs[i]});
    }
  }

public:
  LCA(int n, const graph& g)
    : n(n), g(g), id(n, 2*n), tree(2*n-1){
    int k = 0;
    dfs(0, -1, 0, k);
    
    build_rmq();
  }
  
  int query(int u, int v){
    if(id[u] > id[v]) swap(u, v);
    auto res = tree.query(id[u], id[v] + 1);

    return res.second;
  }

};

int main() {
  int n; cin >> n;
  graph g(n);
  
  REP(u, n){
    int k; cin >> k;
    REP(j, k){
      int v; cin >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }

  LCA lca(n, g);

  int q; cin >> q;
  while(q--){
    int x, y; cin >> x >> y;
    
    cout << lca.query(x, y) << endl;
  }

  return 0;
}



Measured memory_bytes: 23060
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

ll comb(ll N_, ll C_) {
	const int NUM_ = 3000001;
	static ll fact[3000002], factr[3000002], inv[3000002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}
ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

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

	//int N, M, K; cin >> N >> M >> K;
	int N, K; cin >> N >> K;
	int n = N - K + 1;
	eFOR(i, 1, K) {
		cout << comb(n, i)*comb(K - 1, i - 1) % mod << endl;
	}
	//comb(N + K - 1, N - 1)

	
	return 0;
}



Measured memory_bytes: 73944
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

void solve(void)
{
  int H, A; cin >> H >> A;
  auto ans = (H + A - 1) / A;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;
	return 0; 
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

W = list(map(int,read().rstrip()))

N = len(W)

def Z_Algorithm(S):
    # 共通接頭辞の長さを返す
    N=len(S)
    arr = [0]*N
    arr[0] = N
    i,j = 1,0
    while i<N:
        while i+j<N and S[j]==S[i+j]:
            j += 1
        arr[i]=j
        if not j:
            i += 1
            continue
        k = 1
        while i+k<N and k+arr[k]<j:
            arr[i+k] = arr[k]
            k += 1
        i += k; j -= k
    return arr

def find_good_substr(W):
    Z = Z_Algorithm(W)
    is_good = [True]*(N+1) # 長さをインデックス
    for n in range(1,N//2+1):
        # n文字での周期をもってくる
        if not is_good[n]:
            continue
        for i in range(n+n,Z[n]+n+1,n):
            is_good[i] = False
    return is_good

def solve():
    G1 = find_good_substr(W)
    G2 = find_good_substr(W[::-1])[::-1]
    if G1[-1]:
        # 自分自身がoptimal
        return 1,1
    if len(set(W)) == 1:
        return N,1
    # 2個にできるはず
    x = sum(x and y for x,y in zip(G1[1:-1],G2[1:-1]))
    return 2,x

x,y = solve()
print(x)
print(y)

Measured memory_bytes: 38520