akhauriyash/Code-Regression huggingface dataset:
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Fri Mar 30 07:49:32 2018
//
package main

import (
	"fmt"
)

var x, y, z int

func is_even(x int) bool {
	return x%2 == 0
}

func calc(a, b, c int) int {
	if a < b {
		if b < c {
			return a * b
		} else {
			return c * a
		}
	} else {
		if a < c {
			return a * b
		} else {
			return b * c
		}
	}
}

func main() {
	fmt.Scan(&x, &y, &z)
	if is_even(x) || is_even(y) || is_even(z) {
		fmt.Println(0)
	} else {
		fmt.Println(calc(x, y, z))
	}
}


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

int N,X;
map<int,bool> used;
int find(int X){
  if(!used[X])return X;
  if(X==2*N-1)return find(1);
  else return find(X+1);
}

int main(){
  cin>>N>>X;
  if(X==1||X==2*N-1){
    cout<<"No"<<endl;
    return 0;
  }
  
  cout<<"Yes"<<endl;
  if(N==2){
    cout<<1<<endl<<2<<endl<<3<<endl;
    return 0;
  }
  
  used[2*N-1]=used[1]=used[X]=true;
  vector<int> ans(2*N-1,0);  

  ans[N]=2*N-1;
  ans[N-1]=X;
  ans[N-2]=1;
  
  ans[N-3]=find(X+1);
  used[ ans[N-3] ] = true;
  
  ans[N+1]=find(X-1);
  used[ ans[N+1] ] = true;

  int cc=1;

  for(int i=0;i<2*N-1;i++){
    if(ans[i]!=0)continue;
    while(used[cc])cc++;
    used[cc]=true;
    ans[i]=cc;
  }

  for(int i=0;i<2*N-1;i++)
    cout<<ans[i]<<endl;
  
  return 0;
}



Measured memory_bytes: 11648
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N, M;
	get(N, M);

	std::vector<std::string> pica(N), picb(M);
	for (int i = 0; i < N; i++) {
		get(pica[i]);
	}
	for (int i = 0; i < M; i++) {
		get(picb[i]);
	}

	for (int ni = 0; ni < N; ni++) {
		for (int nj = 0; nj < N; nj++) {
			bool match = true;
			for (int mi = 0; mi < M; mi++) {
				for (int mj = 0; mj < M; mj++) {
					if (((ni + M) > N) || ((nj + M) > N)) {
						match = false;
						break;
					}
					else if (pica[ni + mi][nj + mj] != picb[mi][mj]) {
						match = false;
						break;
					}
				}
				if (!match) break;
			}
			if (match) {
				printf("Yes\n");
				return;
			}
		}
	}
	printf("No\n");
}


Measured memory_bytes: 3528
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n,A;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i]; 
	}
	for (int j = 0; j <n/2; j++) {
		A = a[j];
		a[j] = a[n - j - 1];
		a[n - j - 1] = A;
	}
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1) {
			cout << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll n, k, arr[maxn];

int main() {
	cin>>k>>n;

	ll maxdist = 0LL;
	for(int i=1;i<=n;i++) {
		cin>>arr[i];

		if(i >= 2) maxdist = max(maxdist, arr[i] - arr[i-1]);
	}

	maxdist = max(maxdist, k - arr[n] + arr[1]);
	cout<<k - maxdist<<"\n";
}

Measured memory_bytes: 1792
#%%
#import numpy as np

n, m, Q = map(int ,input().split())
l, r, p, q = [0] * m, [0] * m, [0] * Q, [0] * Q
count = [[0] * n for _ in range(n)]
for i in range(m):
    l[i], r[i] = map(lambda x: int(x) - 1, input().split())
    count[l[i]][r[i]] += 1
for i in range(Q):
    p[i], q[i] = map(lambda x: int(x) - 1, input().split())

#print(np.array(count))

for i in range(0, n):
    for j in range(1, n):
        count[i][j] += count[i][j-1]
    for j in range(1, n):
        if i != 0:
            count[i][j] += count[i-1][j]

#print(np.array(count))

for i in range(Q):
    if 0 <= p[i]-1:
        tmp = count[q[i]][q[i]] - count[p[i]-1][q[i]]
    else:
        tmp = count[q[i]][q[i]]
    print(tmp)

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, Ma, Mb;
int A[100], B[100], C[100];
int dp[41][401][401];

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

    std::cin >> N >> Ma >> Mb;

    for(int i=0;i<N;++i){
        std::cin >> A[i] >> B[i] >> C[i];
    }

    fill(&dp[0][0][0], &dp[0][0][0]+41*401*401, 252521);
    dp[0][0][0] = 0;
    
    for(int i=0;i<N;++i){
        for(int j=0;j<=400;++j){
            for(int k=0;k<=400;++k){
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                if(j + A[i] <= 400 && k + B[i] <= 400){
                    dp[i+1][j+A[i]][k+B[i]] = min(dp[i+1][j+A[i]][k+B[i]], dp[i][j][k] + C[i]);
                }
            }
        }
    }

    int res = 252521;
    for(int i=1;i*Ma<=400&&i*Mb<=400;++i){
        int x = i * Ma, y = i * Mb;

        res = min(res, dp[N][x][y]);
    }

    if(res == 252521){res = -1;}

    std::cout << res << std::endl;
}


Measured memory_bytes: 25984
#include <iostream>

using namespace std;

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    
    long long res;
    if (N == 1) {
        if (A == B) {
            res = 1;
        } else {
            res = 0;
        }
    } else {
        if (A > B) {
            res = 0;
        } else {
            res = (B - A) * (N - 2)  + 1;
        }
    }

    cout << res << endl;
}


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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 4e3 + 10;
const int Mod = 998244353;

int k, n;
int dp[N][N], S[N];
int C[N][N];

void add(int &x, int y) {
	x += y;
	x = x >= Mod ? x - Mod : x;
}

int calc(int a, int b) {
	if (a + b - 1 < 0) return !b;
	return C[a + b - 1][a];
}

int main() {

	scanf("%d%d", &k, &n);

	dp[0][0] = 1;
	For(i, 1, k / 2) {
		dp[i][0] = S[0] = dp[i - 1][0];
		For(j, 1, n) S[j] = (S[j - 1] + dp[i - 1][j]) % Mod;
		For(j, 1, n) dp[i][j] = (2ll * S[j - 1] + dp[i - 1][j]) % Mod;
	}
	For(i, 0, n + k) {
		C[i][0] = 1;
		For(j, 1, i) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;
	}

	For(i, 2, 2 * k) {
		int c = 0;
		For(j, 1, k) if (i - j >= 1 && i - j <= k) ++c;
		int ans = 0;
		For(j, 0, n) ans = (ans + 1ll * dp[c / 2][j] * (calc(n - j, k - c) + ((j == n || i % 2 == 1) ? 0 : calc(n - j - 1, k - c)))) % Mod;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 78592
#include <cstdio>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <utility>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ul;

const int iinf = 1 << 29;
const long long linf = 1l << 61;

int N;
int A[310][310];
int B[310][310];

int main(int argc, char* argv[])
{
	scanf("%d", &N);
	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j < N; j++)
		{
			int l;
			scanf("%d", &l);
			A[i][j] = l;
			B[i][j] = l;
		}
	}

	// B[i][j][k] = min(B[i][j][k - 1], B[i][k][k - 1] + B[k][j][k - 1])
	for(int k = 0; k < N; k++)
	{
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < N; j++)
			{
				B[i][j] = min(B[i][j], B[i][k] + B[k][j]);
			}
		}
	}

	ll ans = 0;
	for(int i = 0; i < N; i++)
	{
		for(int j = i + 1; j < N; j++)
		{
			if(A[i][j] > B[i][j])
			{
				printf("-1\n");
				return 0;
			}
			bool need = true;
			for(int k = 0; k < N; k++)
			{
				if(k == i || k == j) continue;
				if(A[i][j] == A[i][k] + A[k][j])
				{
					need = false;
					break;
				}
			}
			if(need) ans += A[i][j];
		}
	}
	printf("%lld", ans);

	return 0;
}


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

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
    ll A, B;
    cin >> A >> B;
    ll N = __gcd(A, B);

    set<ll> Set;
    for(auto p : prime_factor(N)) {
        while(p.second--) Set.insert(p.first);
    }
    ll cnt = 1;
    auto itr = Set.begin();
    while (itr != Set.end()) {
        cnt++;
        itr++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            int count = 0;
            for (;;) {
                if (isAllEven(A)) {
                    for (int i = 0; i < N; i++) {
                        A[i] /= 2;
                    }
                    count++;
                } else {
                    break;
                }
            }

            System.out.println(count);
        }
    }

    private static boolean isAllEven(int[] A) {
        for (int i = 0; i < A.length; i++) {
            if (A[i] % 2 == 1) {
                return false;
            }
        }
        return true;
    }
}


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

int main(){
	int a[11][12];
	for(int i=1;i<=11;i++){
		a[1][i]=1;
	}
	a[1][0]=0;a[1][11]=0;
	for(int i=2;i<=10;i++){
		for(int j=1;j<=10;j++){
			a[i][j]=a[i-1][j-1]+a[i-1][j]+a[i-1][j+1];
		}
		a[i][0]=0;a[i][11]=0;
	}
	int k,sum=0,m,n,o,f=0;
	cin>>k;
	for(int i=1;i<=10;i++){
		for(int j=2;j<=10;j++){
			if(f==0){
				sum+=a[i][j];
				if(sum>=k){
					m=i;n=j;sum-=a[i][j];f=1;
				}
			}
		}
	}
	int b[m+1];
	for(int i=m;i>=1;i--){
		b[i]=n;
		for(int j=n-1;j<=n+1;j++){
			sum+=a[i-1][j];
			if(sum>=k){
				b[i-1]=j;
				sum-=a[i-1][j];
				n=j;
				j=12;
			}
/*			else if(sum==k){
				b[i-1]=j;
				j=12;
			}*/
		}
		
	}
	for(int l=m;l>=1;l--){
		cout<<b[l]-1;
	}
	
	
	
	return 0;
}
/*
for(int i=1;i<=10;i++){
		for(int j=1;j<=10;j++){
			cout<<setw(6)<<a[i][j]<<' ';
		}
		cout<<'\n';
	}

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef long long ll;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX/2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int d, g;
	cin >> d >> g;
	V<int> p(d), c(d);
	rep(i, d)cin >> p[i] >> c[i];

	int ans = INF;

	rep(i, 1 << d) {
		int score = 0;
		int prob = 0;

		rep(j, d) {
			if ((i >> j) & 1) {
				score += p[j] * (j + 1) * 100 + c[j];
				prob += p[j];
			}
		}

		for (int j = d - 1;j >= 0;j--)if (score < g)if ((i >> j) % 2 == 0) {
			int k = (g - score + (j + 1) * 100 - 1) / ((j + 1) * 100);
			score += min((p[j] - 1),k) * (j + 1) * 100;
			prob += min((p[j] - 1), k);
		}
		
		if (score >= g)ans = min(ans, prob);
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
// Problem : A - Calc
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF 1e1

int main()
{
	io;
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;




int main(void){

    long N, h, n, w;

    cin >> N;

    for (long i = 1; i <= 3500; i++){
        for (long j = 1; j <= 3500; j++){
            long t = 4 * i*j - N*(i + j);
            if (t > 0 && (N*i*j) % t == 0){
                h = i; n = j; w = (N*i*j) / t;
            }
        }
    }

    cout << h <<' '<< n << ' ' << w << endl;


}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
#define ALL(a)  (a).begin(),(a).end()
int n,k,pos=0;

int main(){
    cin>>n>>k;vector<int>x(n);rep(i,n)cin>>x[i];
    if(x[0]>=0){
        cout<<x[k-1]<<endl;
        return 0;
    }
    int min=INF;
    rep(i,n-k+1){
        int diff=x[k+i-1]-x[i];
        if(abs(x[k+i-1])>abs(x[i])){
            diff+=abs(x[i]);
        }
        else diff+=abs(x[k+i-1]);
        if(diff<min)min=diff;
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005


ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


/////////////////////////////////////////////////////////////////


int main(){
    ll n,c;cin>>n>>c;
    ll x1[n+2];ll v1[n+1];rep(i,1,n)cin>>x1[i]>>v1[i];x1[0]=0;x1[n+1]=c;v1[0]=0;v1[n+1]=0;
    ll dp1[n+1];dp1[0]=0;
    rep(i,1,n){
        dp1[i]=dp1[i-1]+v1[i]-x1[i]+x1[i-1];
    }
    rep(i,1,n){
        dp1[i]=max(dp1[i-1],dp1[i]);
    }
    //rep(i,0,n)cout<<i<<" "<<dp1[i]<<endl;
    ll ans1=dp1[n];ll pre=0;
    for(int i=n;i>=1;i--){
        pre=pre+v1[i]+x1[i]-x1[i+1];
        ans1=max(ans1,pre);
        ans1=max(ans1,pre+dp1[i-1]-(c-x1[i]));
    }
    
    
    ll x2[n+2];ll v2[n+1];x2[0]=0;x2[n+1]=c;
    rep(i,1,n){
        x2[i]=c-x1[n+1-i];
        v2[i]=v1[n+1-i];
     //   cout<<"x2v2 "<<x2[i]<<" "<<v2[i]<<endl;
    }
    ll dp2[n+1];dp2[0]=0;
    rep(i,1,n){
        dp2[i]=dp2[i-1]+v2[i]-x2[i]+x2[i-1];
    }
    rep(i,1,n){
        dp2[i]=max(dp2[i-1],dp2[i]);
    }
 //   rep(i,0,n)cout<<i<<" "<<dp2[i]<<endl;
    ll ans2=dp2[n];pre=0;
    for(int i=n;i>=1;i--){
        pre=pre+v2[i]+x2[i]-x2[i+1];
      //  cout<<i<<" "<<pre<<endl;
        ans2=max(ans2,pre);
        ans2=max(ans2,pre+dp2[i-1]-(c-x2[i]));
    }
    cout<<max(ans1,ans2)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

vector<LL> A, B, C;
int X, Y, Z, K;

bool check(LL P) {
  int cnt = 0;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      for (int k = 0; k < Z; ++k) {
        LL v =  A[i] + B[j] + C[k];
        if (v < P) break;
        ++cnt;
        if (cnt >= K) return true;
      }
    }
  }
  return false;
}

int main() {
  cin >> X >> Y >> Z >> K;
  A.resize(X), B.resize(Y), C.resize(Z); cin >> A >> B >> C;
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());

  LL ok = 0, ng = A[0] + B[0] + C[0];
  while (abs(ok-ng) > 1LL) {
    LL mid = (ok + ng) / 2LL;
    if (check(mid)) ok = mid;
    else            ng = mid;
  }

  int cnt = 0;
  vector<LL> ABC;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      for (int k = 0; k < Z; ++k) {
        LL v = A[i] + B[j] + C[k];
        if (v < ok) break;
        ABC.push_back(v);
        ++cnt;
      }
    }
  }
  sort(ABC.rbegin(), ABC.rend());
  for (int i = 0; i < K; ++i) cout << ABC[i] << endl;
}


Measured memory_bytes: 265460
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int q = sc.nextInt();

      String s = sc.next();
      int[] prefixCnt = new int[n];
      for(int i = 1; i < prefixCnt.length; i++) {
        if(s.charAt(i) == 'C' && s.charAt(i-1) == 'A')
          prefixCnt[i] = prefixCnt[i-1] + 1;
        else
          prefixCnt[i] = prefixCnt[i-1];
      }

      for(int i = 0; i < q; i++) 
        System.out.println(-prefixCnt[sc.nextInt()-1] + prefixCnt[sc.nextInt()-1]);
  }
}

Measured memory_bytes: 65880
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll h, w, d;
    cin >> h >> w >> d;

    map<ll, P> mp;  // (a[i][j], (i, j))
    rep(i, h) {
        rep(j, w) {
            ll a;
            cin >> a;
            a--;
            mp[a] = make_pair(i, j);
        }
    }

    vl dp(h*w);  // dp[i] : 0～(d-1)の書かれたいずれかの適切なマスからはじめてiの書かれたマスに移動させるのに必要な魔力
    exrep(i, d, h*w-1) {  // iの書かれたマスに移動させるのに必要な魔力を求める
        ll x1 = mp[i].first;
        ll y1 = mp[i].second;
        ll x2 = mp[i-d].first;
        ll y2 = mp[i-d].second;
        dp[i] = dp[i-d] + abs(x1 - x2) + abs(y1 - y2);
    }

    ll q;
    cin >> q;
    vl ans(q);
    rep(i, q) {
        ll L, R;
        cin >> L >> R;
        L--;  R--;
        ans[i] = dp[R] - dp[L];
    }

    rep(i, q) {
        out(ans[i]);
    }

    re0;
}

Measured memory_bytes: 8192
N = int(input())

E = [None] * (N+1)
for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs

d = [0] * (N+1)
f = [0] * (N+1)
t = 0

def dfs(v):
    global t, d, f
    if d[v]:
        return
    t += 1
    d[v] = t
    for u in E[v]:
        dfs(u)
    t += 1
    f[v] = t

for v in range(1, N+1):
    dfs(v)

for v in range(1, N+1):
    print(v, d[v], f[v])


Measured memory_bytes: 5656
// E - Almost Everywhere Zero
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
string N;
int K;
int lt = 0, eq = 1;//lt: <, eq: =
int dp[100+1][2][4+1];// digit DP, [|N|+1: 1 origin][lt|eq][k:0~3]

int main(){
	cin>>N>>K;
	int dn = N.size();
	dp[0][eq][0] = 1;
	rp(i,0,dn){
		int di = N[i] - '0';
		rp(k,0,4){
			dp[i+1][lt][k] = dp[i][lt][k] * 1 + dp[i][eq][k] * (di?1:0);
			if(k) dp[i+1][lt][k] += dp[i][lt][k-1] * 9 + dp[i][eq][k-1] * max(0,di-1);
			if(dp[i][eq][k]) dp[i+1][eq][k+(di>0)] = 1;
		}
	}
	cout<< dp[dn][lt][K] + dp[dn][eq][K] <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e6 + 17;

int n;
int a[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n)
		scanf("%d", a + i);

	return true;
}

void solve()
{
	llong sum = 0, ps = 0, ans = linf;

	forn (i, n)
		sum += a[i];

	forn (i, n - 1)
	{
		ps += a[i];
		ans = min(ans, abs(sum - 2ll * ps));
	}

	printf("%lld\n", ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};


int main(){
    string n;
    int k;
    cin >> n >> k;
    ll dp[105][2][5]{};
    dp[0][0][0] = 1;
    for(int i=0;i<int(n.size());i++){
        int D = n[i]-'0';
        for(int j=0;j<2;j++){
            for(int k=0;k<=3;k++){
                for(int d=0;d<=(j?9:D);d++){
                    dp[i+1][j||(d<D)][min(k+(d!=0),4)] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[n.size()][0][k] + dp[n.size()][1][k] << endl;
    return 0;
}



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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

inline bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}

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

int h, w;

vector<string> mat(1005);
vector<vector<int>> dist(1005, vector<int>(1005, INF));

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

  IN(h, w);
  rep(i, h) IN(mat[i]);

  queue<pii> que;

  rep(i, h) rep(j, w) {
    if (mat[i][j] == '#') {
      que.emplace(i, j);
      dist[i][j] = 0;
    }
  }

  i64 res = 0;
  while (!que.empty()) {
    int y = que.front().first;
    int x = que.front().second;
    que.pop();

    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];

      if (inside(nx, ny, w, h) &&
          dist[ny][nx] > dist[y][x] + 1 &&
          mat[ny][nx] != '#') {

        int norm = dist[y][x] + 1;
        mat[ny][nx] = '#';
        chmin(dist[ny][nx], norm);
        chmax(res, dist[ny][nx]);
        que.emplace(ny,nx);
      }
    }
  }

  OUTL(res);

  return 0;
}


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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void solve(string S){
    vector<int> ruiseki;
    ruiseki.push_back(0);
    for(int i = 0;i < S.size();i++){
        int j = S.size() - i - 1;
        ruiseki.push_back(ruiseki.back() + modpow(10, j, 2019) * (S[i]-'0'));
        ruiseki.back() %= 2019;
    }
    map<int, int> mp;
    for(int i = 0;i < ruiseki.size();i++)mp[ruiseki[i]]++;
    ll ans = 0;
    for(auto a : mp){
        ans += a.second * (a.second - 1) / 2;
    }
    cout<<ans<<endl;
}

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

string s;
ll k;
void solve() {
    cin >> s >> k;

    int n = sz(s);
    char b = ' ';
    ll res = 1;
    vector<ll> vec;
    rep(i, n - 1) {
        if (s[i] == s[i + 1]) ++res;
        else { vec.emplace_back(res); res = 1; }
    }
    vec.emplace_back(res);
    ll ans = 0;
    auto m = sz(vec);
    if (m == 1) ans = vec[0] * k / 2;
    else if (s[0] == s[n - 1]) {
        loop(i, 1, m - 1) ans += vec[i] / 2;
        ans *= k;
        ans += (vec[0] + vec[m - 1]) / 2 * (k - 1) + vec[0] / 2 + vec[m - 1] / 2;
    }
    else {
        rep(i, m) ans += vec[i] / 2;
        ans *= k;
    }

    cout << ans << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    ll x; cin >> x;
    ll temp = 100;
    ll cnt=0;

    while(1){
        cnt++;
        temp *= 1.01;
        if(temp >= x){
            break;
        }
    }

    cout << cnt << endl;
}

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

int main() {
  int h,w;cin>>h>>w;
  vector<string> list(h);
  for(int i=0;i<h;i++) {
    cin >> list.at(i);
  }
  for (int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(list.at(i).at(j)=='.') {
        int count=0;
        if(i-1>=0) {
          string temp = list.at(i-1);
          if(j-1>=0) {
            if(temp.at(j-1)=='#') {
              count++;
            }
          }
          if(temp.at(j)=='#') {
            count++;
          }
          if(j+1<w) {
            if(temp.at(j+1)=='#') {
              count++;
            }
          }
        }

        if(j-1>=0) {
          if(list.at(i).at(j-1)=='#') {
            count++;
          }
        }
        if(j+1<w) {
          if(list.at(i).at(j+1)=='#') {
            count++;
          }
        }

        if(i+1<h) {
          string temp = list.at(i+1);
          if(j-1>=0) {
            if(temp.at(j-1)=='#') {
              count++;
            }
          }
          if(temp.at(j)=='#') {
            count++;
          }
          if(j+1<w) {
            if(temp.at(j+1)=='#') {
              count++;
            }
          }
        }
        cout << count;
      }
      else {
        cout << list.at(i).at(j);
      }
    }
    cout << endl;
  }
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	int n,m;cin>>n>>m;
	vector<int> a(m);
	int i;
	rep(i,m)cin>>a[i];
	int sum=0;
	rep(i,m)sum+=a[i];
	if(n>=sum)cout<<n-sum<<endl;
	else cout<<-1<<endl;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#define div 1000000000+7
using namespace std;
typedef long long ll;

int main(){
    int h, w;
    cin >> h >> w;
    char a[h][w];

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }

    int count = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] == '#'){
                count++;
            }
        }
    }
    //cout << count << " " << (h+w-1) << endl;
    if(count == (h+w-1)){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    int ans=0;
    int n=s.size();
    for (int i = 0; i < n/2; i++)
    {
        if(s[i]!=s[n-1-i]) ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define bitcount    __builtin_popcountll
#define si(x)       scanf("%d",&x)
#define su(x)       scanf("%u",&x)
#define sll(x)      scanf("%lld",&x)
#define sl(x)       scanf("%ld",&x)     
#define sc(x)       scanf("%c",&x)
#define ss(x)       scanf("%s",x)
#define sf(x)       scanf("%f",&x)
#define slf(x)      scanf("%lf",&x)
#define pri(x)      printf("%d\n",x)
#define prl(x)      printf("%lld\n",x)
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define pll         pair<long long,long long>
#define pil         pair<int,long long>
#define pli         pair<long long,int>
#define vi          vector<int>
#define vl          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<=b;i++)
#define repl(i,a,b) for(long long i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define rrepl(i,a,b) for(long long i=a;i>=b;i--)
#define M           1000000007

const int maxn=1e6+100;

void solve(){
    int n; si(n);
    int prevTime=0,prevX=0,prevY=0;
    rep(i,1,n){
        int curTime,x,y;
        si(curTime); si(x); si(y);
        int dif=abs(x-prevX)+abs(y-prevY);
        int avTime=curTime-prevTime;
        if(avTime<dif){
            puts("No");
            return;
        }
        avTime-=dif;
        if(avTime%2){
            puts("No");
            return;
        }
        prevTime=curTime;
        prevX=x;
        prevY=y;
    }
    puts("Yes");
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;
    //si(t);
    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
mapin = lambda: map(int, sys.stdin.readline().split())
listin = lambda: list(map(int, sys.stdin.readline().split()))
inp = lambda: sys.stdin.readline()

N,M,X,Y = mapin()
veca = listin()
vecb = listin()
max_x = -10000
min_y = 10000
for i in veca:
    if max_x < i:max_x = i
for i in vecb:
    if min_y > i:min_y = i
if max_x < min_y and max_x > X and min_y < Y:
    print("No War")
else:print("War")

Measured memory_bytes: 9404
#include<stdio.h>
#define N 100000
#define Q 50000

int Search();

int S[N];
int n, key;

int main(){
    int T[Q];
    int q, i;
    int count = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &T[i]);
    }

    for(i = 0; i < q; i++){
        key = T[i];
        if(Search() == 1) count++;
    }

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

    return 0;
}

int Search(){
    int mid;
    int left = 0;
    int right = n;

    while(left < right){
        mid = (left + right) / 2;

        if(key == S[mid]) return 1;
        else if(key > S[mid]){
            left = mid + 1;
        }
        else right = mid;
    }

    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue
//#define minn 999999999
//#define maxx 0
int longest_palindrome_prefix(const string &s)
{
    string kmprev = s;
        std::reverse(kmprev.begin(), kmprev.end());
        string kmp = s + "#" + kmprev;

        vector<int> lps(kmp.size(), 0);   // lps[i] = longest suffix length for substring kmp[0..i] where the suffix == prefix
        for (int i = 1; i < (int)lps.size(); ++i)
        {
            int prev_idx = lps[i - 1];

            while (prev_idx > 0 && kmp[i] != kmp[prev_idx])
            {
                prev_idx = lps[prev_idx - 1];
            }

            lps[i] = prev_idx + (kmp[i] == kmp[prev_idx] ? 1 : 0);
        }

        // after KMP's LPS preprocessing, the last index of the LPS array will contain the longest palindrome prefix' length!
        return lps[lps.size() - 1];

}
float maxvolume(float s) 
{ 
    // finding length 
    ld length = s / 3.0; 
  
    s -= length; 
  
    // finding breadth 
    ld breadth = s / 2.0; 
  
    // finding height 
    ld height = s - breadth; 
  
    return length * breadth * height; 
} 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a[n];
    ll cnt[200001]={};
    rep(i,0,n)
    {
        cin>>a[i];
        cnt[ a[i] ]++;
    }
    ll sum=0;
    rep(i,1,200001)
    {
        ll x= (cnt[i])*(cnt[i]-1);
        sum+=x/2;
    }
    rep(i,0,n)
    {
        ll var= cnt[a[i]]*(cnt[a[i]]-1);
        var/=2;
        ll x=sum-var;
        ll y= (cnt[a[i]]-2)*(cnt[a[i]]-1);
        x+=y/2;
        cout<<x<<"\n";
    }
}


Measured memory_bytes: 5760
N, M, K = map(int, input().split())
out = 0
mod = 998244353

c = 1

for k in range(K+1):
  out += M * pow(M-1, N-k-1, mod) * c
  out %= mod
  c *= (N-k-1) * pow(k+1, mod-2, mod)
  c %= mod
print(out)


Measured memory_bytes: 9084
//Don't give up too easy bhai
#pragma GCC optimize("-O3")
 
#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define double long double
#define inf 1e18

typedef pair<int,int> pii;
 
#define forall(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define vi vector<int>
#define vd vector<double>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007
#define br cout<<"\n"
#define whatis(x) cerr << "var "<<#x << " ==> " << x<<"\n"
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define T int __t;cin>>__t;while(__t--)

void solve()
{
 
    int a,b,c;cin>>a>>b>>c;
    int k;cin>>k;

    while(b<=a)
    {
        if(k==0)
        {
            cout<<"No";
            return;
        }
        if(k) b*=2,k--;
    }
    while(c<=b)
    {
        if(k==0) {cout<<"No";return;}
        if(k) c*=2,k--;
    }
    cout<<"Yes";   
}

signed main()
{
    fast;

    solve();
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e6 + 10;
int a[M];
bool cmp(int a, int b) {
    return a > b;
}
int main(){
    int n, m, sum = 0;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
    sort(a + 1, a + n + 1, cmp);
    for(int i = 1; i <= m; i++) {
        if(a[i] * 4 * m < sum) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; ll w;
    cin >> s >> w;
    for(ll i=0; i<s.size(); i+=w) cout << s[i];
    cout << endl;
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	int len;

	cin >> S;
	len = S.length();

	if (len == 2) cout << S << endl;
	else cout << S[2] << S[1] << S[0] << endl;

	return 0;
}


Measured memory_bytes: 256
///============================================================================
/// Name        : Faisal.cpp
/// Author      : Faisal Ahmed
/// Version     :
/// Copyright   : Your copyright notice
/// Description : C++, Ansi-style
///============================================================================

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

bool f[100010];
ll arr[100010];

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

	ll n, m, x;

	cin >> n >> m;

	for(int i = 0; i < m; i++){
        cin >> x;
        f[x] = true;
	}

	arr[0] = 1;
	for(int i = 0; i < n; i++){
        if(!f[i + 1]){
            arr[i + 1] += arr[i];
            arr[i + 1] = arr[i + 1] % 1000000007;
        }
        if(!f[i + 2]){
            arr[i + 2] += arr[i];
            arr[i + 2] = arr[i + 2] % 1000000007;
        }
	}

    cout << arr[n] << endl;

	return 0;
}



Measured memory_bytes: 1152
from collections import deque
from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def main():
    mod = 10**9 + 7
    n = int(input())
    colors = [int(input()) for _ in range(n)]
    pos_dict = {}
    for i, color in enumerate(colors):
        if color not in pos_dict:
            pos_dict[color] = deque([])
            continue
        pos_dict[color].append(i)

    branches = []
    base = 1
    for i, color in enumerate(colors):
        if branches and branches[0][0] == i:
            _, add = heappop(branches)
            base += add
            base %= mod

        if pos_dict[color]:
            next = pos_dict[color].popleft()
            if next == i+1:
                continue
            add = base
            heappush(branches, (next, add))

    print(base % mod)


if __name__ == "__main__":
    main()


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

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

	vector<double> p(n);

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

	double ans = 0;
	double tmpSum = 0;


	for (int i = 0; i <= n - k; i++) {
				
		if (i == 0) {
			for (int j = i; j <= i + k - 1; j++) {
				double tmp = (p[j] + 1) / 2;
				tmpSum += tmp;
			}
		}	
		else {
				tmpSum -= (p[i - 1] + 1) / 2;
				tmpSum += (p[i + k - 1] + 1) / 2;
		}
		
		ans = max(ans, tmpSum);

	}

	cout << fixed << setprecision(11) << ans << endl;

	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<int> P(N), C(N);
  for (auto&& e : P) {
    cin >> e;
    e--;
  }
  for (auto&& e : C) {
    cin >> e;
  }
  const int M = 31;
  vector<vector<int>> nxt(M, vector<int>(N, 0));
  vector<vector<int64_t>> sum(M, vector<int64_t>(N, 0)), all(M, vector<int64_t>(N, 0));
  for (int i = 0; i < N; i++) {
    nxt[0][i] = P[i];
    sum[0][i] = all[0][i] = C[P[i]];
  }
  for (int k = 0; k + 1 < M; k++) {
    for (int i = 0; i < N; i++) {
      nxt[k + 1][i] = nxt[k][nxt[k][i]];
      sum[k + 1][i] = sum[k][i] + sum[k][nxt[k][i]];
      all[k + 1][i] = max(all[k][i], sum[k][i] + all[k][nxt[k][i]]);
    }
  }
  int64_t res = -(INT64_C(1) << 58);
  for (int i = 0; i < N; i++) {
    int cur = i;
    int64_t tot = 0;
    for (int k = 0; k < M; k++) {
      if ((K >> k) & 1) {
        res = max(res, tot + all[k][cur]);
        tot += sum[k][cur];
        cur = nxt[k][cur];
      }
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 6364
n=int(input())
ct=[[0]*10 for i in range(10)]
for i in range(1,10):
  for j in range(1,10):
    if n>=10:
      if i==j:
        ct[i][j]+=1
    if n>=10**2:
      ct[i][j]+=1
    if n>=10**3:
      ct[i][j]+=10
    if n>=10**4:
      ct[i][j]+=100
    if n>=10**5:
      ct[i][j]+=1000
    
    if n<10:
      if n>=i:
        ct[i][j]+=1
    
    elif 10<n<10**2:
      if n>=i*10+j:
        ct[i][j]+=1
    
    elif 10**2<n<10**3:
      if int(str(n)[0])>i:
        ct[i][j]+=10
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1])+1
        else:
          ct[i][j]+=int(str(n)[1])

    elif 10**3<n<10**4:
      if int(str(n)[0])>i:
        ct[i][j]+=10**2
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1:3])+1
        else:
          ct[i][j]+=int(str(n)[1:3])

    elif 10**4<n<10**5:
      if int(str(n)[0])>i:
        ct[i][j]+=10**3
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1:4])+1
        else:
          ct[i][j]+=int(str(n)[1:4])
    
    elif n>10**5:
      if int(str(n)[0])>i:
        ct[i][j]+=10**4
      elif int(str(n)[0])==i:
        if int(str(n)[-1])>=j:
          ct[i][j]+=int(str(n)[1:5])+1
        else:
          ct[i][j]+=int(str(n)[1:5])
ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=ct[i][j]*ct[j][i]
print(ans)

Measured memory_bytes: 3192
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;


//桁和
int digit(int n) {
  if(n < 10) return n;
  return digit(n/10) + n%10;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  bool flag = false;
  if(n % digit(n) == 0) flag = true;
  YesorNo(flag);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256