akhauriyash/Code-Regression huggingface dataset:
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)             \
    do {                         \
        cout << #args << " -> "; \
        err(args);               \
    } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
    std::cout << a << ' ';
    err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &... args) {
    for (auto &v : arg)
        std::cout << v << ' ';
    err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII   = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD   = 1000000007;
const int MAXN  = 200005;


void run() {
    int a;
    cin >> a;
    cout << (a+a*a+a*a*a) << endl;
}

// Debug Input Redirection
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    run();
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


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

int main() {
ll n;
cin>>n;
ll a[n+1];
ll b[n+1];
rep(i, n){
	cin>>a[i]>>b[i];
}

ll d=0;
rep(i,n){
	d+=max((ll)0,a[i]-b[i]);
}
if(d==0){cout<<0<<endl;
return 0;}

ll ans=0;
ll sum=0;
rep(i, n){
	sum+=b[i];
	if(a[i]==b[i])ans+=a[i];
	if(a[i]<b[i]) ans+=b[i];
}



ll di[n];
ll val=99999999999;
rep(i, n){
	if(a[i]>b[i]) val=min(val,b[i]);

}


cout<<sum-val<<endl;



return 0;




}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
 
int main(void){
    char str[201] = { 0 };
    char str1[201] = { 0 };
    char str2[201] = { 0 };
    int n;
    int m;
    int h;
    int i;
 
    while (1){
        scanf("%s", str);
 
        if (strcmp(str, "-") == 0){
            break;
        }
 
        n = strlen(str);
 
        scanf("%d", &m);
 
        for (i = 0; i < m; i++){
            scanf("%d", &h);
            strncpy(str2, str, h);
            strncpy(str1, str+h, n - h);
            strcpy(str, strcat(str1, str2));
            memset(str1, '\0', n);
            memset(str2, '\0', h);
        }
     
        printf("%s\n", str);
        memset(str, '\0', n);
    }
 
    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	if (n == 0) s = '0';
	while (n != 0) {
		if (n % 2 != 0) {
			n--;
			s = '1' + s;
		}
		else s = '0' + s;
		n /= -2;
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const int BINF = 100000000000000001;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = 0;
    for (int i = 1; i < N; ++i)ans += i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(long a,long b){
    long c;
    if(a<b){a+=b;b=a-b;a-=b;}
    while(b!=0){c=a%b;a=b;b=c;}
    return a;
}
int main(void){
  int N,i;
  long A,ans;
  scanf("%d",&N);
  scanf("%ld",&ans);
  for(i=1;i<N;i++)
  {
    scanf(" %ld",&A);
    ans=gcd(ans,A);
  }
  printf("%ld",ans);
  return 0;
}


Measured memory_bytes: 128
n = int(input())
l = [0]*5
for i in range(n):
    s = input()
    ini = s[0]
    if ini == 'M':
        l[0] += 1
    elif ini == 'A':
        l[1] += 1
    elif ini == 'R':
        l[2] += 1
    elif ini == 'C':
        l[3] += 1
    elif ini == 'H':
        l[4] += 1
com = [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
ans = 0
for i in com:
    ans += l[i[0]]*l[i[1]]*l[i[2]]
print(ans)

Measured memory_bytes: 44392
import itertools
import numpy as np
H, W, K = map(int, input().split())
C = [[w=='#' for w in input()] for _ in range(H)]

def count(h_slice, w_slice):
    cnt = 0
    for i in range(H):
        if h_slice[i] == 0:
            continue
        for j in range(W):
            if w_slice[j] == 0:
                continue
            cnt += C[i][j]
    return cnt

ans = 0
for h_slice in itertools.product([0, 1], repeat=H):
    h_slice = np.array(h_slice).astype(bool)
    for w_slice in itertools.product([0, 1], repeat=W):
        w_slice = np.array(w_slice).astype(bool)
        ans += count(h_slice, w_slice) == K
print(ans)



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

int main()
{
    int n;
    cin >> n;
    vector<int> d;
    int flg[101];
    int x;
    for (int i = 0; i < 101; i++)
    {
        flg[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        d.push_back(x);
        flg[x] = 1;
    }

    int ans = 0;

    for (int i = 0; i < 101; i++)
    {
        ans += flg[i];
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

int getDigit(int num) {
    return std::to_string(num).length();
}

ll intpow(const int &a, const int &n) {
    if (n == 0)
        return 1;
    else if (n & 1)
        return intpow(a * a, n / 2) * a;
    else
        return intpow(a * a, n / 2);
}

signed main() {
    cin >> N;
    int cnt[10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cnt[i][j] = 0;
        }
    }
    for (int i = 1; i <= N; i++) {
        int d = getDigit(i);
        int f = i / intpow(10, d - 1);
        int l = i % 10;
        dump(i, f, l);
        cnt[f][l]++;
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
}

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

int n, k, a[100];
bool dp[1<<17] = {0};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j < n and a[j] <= i; ++j) {
      dp[i] |= !dp[i - a[j]];
    }
  }
  cout << (dp[k] ? "First" : "Second") << '\n';
}


Measured memory_bytes: 384
#!/usr/bin/env python3

from itertools import chain
from collections import Counter

N,M = map(int, input().split())
PY = [ (i, P, Y) for i, (P, Y) in enumerate([tuple(map(int, input().split())) for _ in range(M)])]

answers = [0 for x in range(M)]
counter = Counter()

for index, P, Y in sorted(PY, key = lambda x : x[2]):
    counter[P] += 1
    answers[index] = "{:06}{:06}".format(P, counter[P])

print("\n".join(answers))


Measured memory_bytes: 38056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct StronglyConnectedComponentsint {
    int n;
    vector<int> ord, comp, used;
    vector<vector<int>> rg;
    StronglyConnectedComponentsint(vector<vector<int>>& g,
                                   vector<vector<int>>& t)
        : n(sz(g)), comp(n, -1), used(n, 0), rg(n) {
        rep(u, n) {
            for (int v : g[u]) {
                rg[v].push_back(u);
            }
        }
        rep(i, n) dfs(i, g);
        reverse(all(ord));
        int k = 0;
        for (int i : ord) {
            if (comp[i] == -1) {
                rdfs(i, k);
                k++;
            }
        }
        t.resize(k);
        rep(now, n) {
            for (int nxt : g[now]) {
                if (comp[now] != comp[nxt]) {
                    t[comp[now]].push_back(comp[nxt]);
                }
            }
        }
    }
    StronglyConnectedComponentsint(vector<vector<int>>& g)
        : n(sz(g)), comp(n, -1), used(n, 0), rg(n) {
        rep(u, n) {
            for (int v : g[u]) {
                rg[v].push_back(u);
            }
        }
        rep(i, n) dfs(i, g);

        reverse(all(ord));
        int k = 0;
        for (int i : ord) {
            if (comp[i] == -1) {
                rdfs(i, k);
                k++;
            }
        }
    }

    void dfs(int now, vector<vector<int>>& g) {
        if (used[now]) return;
        used[now] = 1;
        for (int nxt : g[now]) {
            dfs(nxt, g);
        }
        ord.push_back(now);
    }

    void rdfs(int now, int k) {
        if (comp[now] != -1) return;
        comp[now] = k;
        for (int nxt : rg[now]) {
            rdfs(nxt, k);
        }
    }
    int operator[](int x) {
        return comp[x];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    while (m--) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    vector<vector<int>> t;
    StronglyConnectedComponentsint scc(g);

    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        cout << (scc[u] == scc[v]) << endl;
    }
}



Measured memory_bytes: 4468
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int C = sc.nextInt();
			if (C == 0) {
				sc.close();
				break;
			}

			int[] cycle = new int[C];
			for (int i = 0; i < C; i++) {
				cycle[i] = sc.nextInt();
			}

			int N = sc.nextInt();
			int[] meeting = new int[100];
			for (int i = 0; i < N; i++) {
				int day = sc.nextInt();
				int meet = sc.nextInt();
				if (meeting[day - 1] != 0) {
					meeting[day - 1] = Math.min(meet, meeting[day - 1]);
				} else {
					meeting[day - 1] = meet;
				}
			}

			// dp[i日目に][サイクルjがきてる]ときのカフェイン最小回数
			int[][] dp = new int[100][C];
			for (int i = 0; i < dp.length; i++) {
				Arrays.fill(dp[i], 100);
			}
			dp[0][0] = 0;

			for (int i = 0; i < dp.length - 1; i++) {
				for (int j = 0; j < C; j++) {
					// 間に合う時
					if (cycle[(j + 1) % C] <= meeting[i + 1] || meeting[i + 1] == 0) {
						dp[i + 1][(j + 1) % C] = Math.min(dp[i][j], dp[i + 1][(j + 1) % C]);
					}
					// カフェインを摂取する時
					dp[i + 1][0] = Math.min(dp[i][j] + 1, dp[i + 1][0]);
				}
			}

			int caffeine = Integer.MAX_VALUE;
			for (int i = 0; i < dp[99].length; i++) {
				caffeine = Math.min(caffeine, dp[99][i]);
			}
			System.out.println(caffeine);
		}
	}
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll gcd_impl(ll n, ll m){
  for(int i = 0; i < 10; ++i ) {
    ll t = n - m;
    bool q = m > t;
    n = q ? m : t;
    m = q ? t : m;
    if( m == 0 ) { return n; }
  }
  return gcd_impl( m, n % m );
}

ll gcd(ll n, ll m){
  return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

ll lcd(ll x, ll y){
  ll a = gcd(x,y);
  return x*y/a;
}

ll modPow(ll a, ll b){
  if(!b)
    return 1;

  ll power = a;
  ll res = 1;
  while(b>0){
    if(b&1)
      res = (res*a)%MOD;
    a = a*a%MOD;
    b >>= 1;
  }
  return res;


}

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

  ll n;
  cin >> n;
  vll a(n);
  REP(i, n)
    cin >> a[i];
  sort(a.begin(), a.end());

  map<ll,ll> m;
  REP(i, n){
    ll x = a[i];
    for(ll k = 2; k*k<=a[i]; k++){
      ll t = 0;
      while(x%k==0){
        t++;
        x/=k;
      }

      if(m[k]<t)
        m[k]=t;
    }

    if(x!=1 && m[x]==0)
      m[x]=1;
  }

  ll lcd=1;
  for(auto t:m){
    REP(i,t.SE)
      lcd = (lcd*t.FI)%MOD;
  }

  ll ans=0;
  REP(i,n)
    ans = (ans+lcd*modPow(a[i], MOD-2)%MOD)%MOD;

  cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n; cin >>n;
    vector<ll> v(n); REP(i,n) cin >> v[i];

    vector<ll> cums((ll)v.size()+1, 0);
    for (ll i = 0; i < (ll)v.size(); i++) {
        cums[i+1] = cums[i] + v[i];
    }

    ll res = INFLL;
    for (ll i = 1; i < n; i++) {
        ll x = cums[i];
        ll y = cums[n] - x;
        res = min(res, abs(x-y));
    }

    cout << res << endl;
    return 0;
}




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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int k;cin >> k;
    queue<ll> Q;
    rep1(i,10){
        Q.push(i);
    }
    ll num;
    rep(i,k){
        num = Q.front(); Q.pop();
        int mod = num % 10;
        if(mod != 0) Q.push(num*10+mod-1);
        Q.push(num*10+mod);
        if(num % 10 != 9) Q.push(num*10+mod+1);
    }
    cout << num << endl;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,A,B=map(int,input().split())
    ans=0
    z=N//(A+B)
    ans+=z*A
    ans+=min(A,N-z*(A+B))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mkp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 150005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W, D;
ll a[400][400];
ll Q;
ll l, r;
ll cost[MAX];

int main(void) {
    ll i, j;
    cin >> H >> W >> D;
    P pos[MAX];
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            cin >> a[i][j];
            pos[a[i][j]]=mkp(i, j);
        }
    }
    
    for(i=1; i+D<=H*W; i++) {
        cost[i+D]=cost[i]+abs(pos[i+D].first-pos[i].first)+abs(pos[i+D].second-pos[i].second);
    }
    
    cin >> Q;
    for(i=0; i<Q; i++) {
        cin >> l >> r;
        pr(cost[r]-cost[l]);
    }
    
}




















Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1001001001;

int N, C;
int panel[30], button[30];
int dp[31][1<<16];

int popCount(int n){
  int res = 0;
  REP(i, 16){
  	if(n >> i & 1){res += 1;}
  }
  return res;
}

int rec(int index, int state){
	if(index >= N){return 0;}
	if(dp[index][state] != -1){return dp[index][state];}
	
	int p = state | panel[index];
	int res = 0;
    REP(i, C){
    	int match = p & button[i];
    	res = std::max(res, popCount(match) + rec(index+1, p ^ match));
    }
    
    return dp[index][state] = res;
}

int main(){
	while(scanf("%d %d", &N, &C), N && C){
	std::fill(panel, panel+30, 0);
	std::fill(button, button+30, 0);
	std::fill(&dp[0][0], &dp[0][0]+31*(1<<16), -1);
	
	REP(i, N){
		REP(j, 16){
			int a;
			scanf("%d", &a);
			panel[i] = panel[i] * 2 + a;
		}
	}
	
	REP(i, C){
		REP(j, 16){
			int b;
			scanf("%d", &b);
			button[i] = button[i] * 2 + b;
		}
	}

    rec(0, 0);
	
	printf("%d\n", dp[0][0]);
	}
}

Measured memory_bytes: 9124
n = int(input())

dp = [10**6 for _ in range(n+1)]
dp[0] = 0

for i in range(n+1):
    j6 = 1
    while i+j6<=n:
        dp[i+j6] = min(dp[i]+1,dp[i+j6])
        j6 *= 6
    j9 = 1
    while i+j9<=n:
        dp[i+j9] = min(dp[i]+1,dp[i+j9])
        j9 *= 9
print(dp[n])


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

int main()
{
    string n;
    cin >> n;
    if ((n[0] == n[1] & n[1] == n[2]) | (n[1] == n[2] & n[2] == n[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

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

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

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

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

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

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

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

	ll res = 0;
	int r = 0, sum = 0;
	rep(l, n) {
		while (r < n && (sum ^ a[r]) == (sum + a[r])) {
			sum += a[r];
			r++;
		}

		res += r - l;

		if (r == l) r++;
		else sum -= a[l];
	}
	cout << res << endl;
}

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

#define ll long long

int main() {
    double n, m, sm = 0;    cin >> n >> m;
    vector <double> a(n);   for (ll i = 0; i < n; i ++){
            cin >> a[i];    sm += a[i];
    }
    sort(a.begin(), a.end(), greater <double> ());
    // cout << sm << "\n";
	
    // cout << (275 >= 275.5) << "\n";
    // cout << (275 >= int(275)) << "\n";
   
    //out << int(float(1.0/(4.0*m)) * (sm * 1.0)) << "\n";
	//cout << a[m - 1] << "\n";
    
    // cout << 1 * 1.0 << "\n";

    // cout << (1/(4*m)) * sm << "\n"; 

    if (a[m - 1] >=  (1/(4*m)) * sm) {
            cout << "Yes\n";
    }
    else {
            cout << "No\n";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 200005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


llu arr[maxii];
llu arr2[maxii];
//bool check[maxii];
bool check2[1000][1000];
//lln n,m;
llu gcd(llu a,llu b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}


int main()
{
    int n;
    cin>>n;
    if(n==1){cout<<1;return 0;}
    int maxi=0,ans=0;
    for(int i=2;i<=n;i++)
    {
        int p=i;
        int res=0;
        while(p%2==0)
        {
            p/=2;
            res++;
        }
        if(maxi<=res)
        {
            ans=i;
            maxi=res;
        }
    }
    cout<<ans;

}






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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    string s;
    cin >> s;

    int N = s.length();

    int ans = 0;
    REP(i, N) {
        char c = s[i];
        int p = i % 2;

        if (p) {
            if (c == 'g') ans++;
        } else {
            if (c == 'p') ans--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll arr[n];
    multiset<ll> mst;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        mst.insert(arr[i]);
    }
    multiset< pair<ll,ll> > store;
    for(int i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        store.insert(mp(b,a));
    }
    multiset< pair<ll,ll> >::reverse_iterator itr;
    multiset<ll>::iterator itr1;
    int flag=0;
    for(itr=store.rbegin();itr!=store.rend();++itr)
    {
        vector<ll> v;
        for(itr1=mst.begin();itr1!=mst.end();++itr1)
        {
            if(v.size()==itr->second)
                break;
            if(*itr1<itr->first)
            {
                v.pb(*itr1);
                continue;
            }
            else if(*itr1>=itr->first)
            {
                flag=1;
                break;
            }
        }
        for(int i=0;i<v.size();i++)
        {
            itr1=mst.find(v[i]);
            mst.erase(itr1);
            mst.insert(itr->first);
        }
        if(flag==1)
            break;
    }
    ll sum=0;
    for(itr1=mst.begin();itr1!=mst.end();++itr1)
    {
      //  cout<<*itr1<<endl;
        sum=sum+(*itr1);
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 13176
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 998244353;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  string s;
  int q;
  cin >> s >> q;

  deque<char> deq(s.size());
  rep(i, 0, s.size()) deq[i] = s[i];

  int rev = 0;
  rep(i, 0, q) {
    int t;
    cin >> t;

    if(t == 1) {
      rev = (rev + 1) % 2;
    }
    else {
      int f;
      char c;
      cin >> f >> c;

      if(f == 1) {
        if(rev == 0) deq.push_front(c);
        else deq.push_back(c);
      }
      else {
        if(rev == 0) deq.push_back(c);
        else deq.push_front(c);
      }
    }
  }

  if(rev == 1) reverse(all(deq));
  rep(i, 0, deq.size()) cout << deq[i];
  cout << endl;
}

Measured memory_bytes: 976
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2,dis,X,Y;
    cin >>x1>>y1>>x2>>y2;
    X=pow(x1-x2,2);
    Y=pow(y1-y2,2);
    dis = sqrt(X+Y);
   cout<<fixed<<dis<<endl;
   
    return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <utility>
using namespace std;

typedef long long ll;

int main(){
  int n; cin >> n;
  int a[n+1], t[n+1];
  for(int i=1; i<=n; i++){
    cin >> a[i];
  }

  a[0] = -1;

  ll ans = 0;
  for(int i=1; i<=n; i++){
    t[i] = a[i] - a[i-1];
    if(t[i] > 1){
      cout << -1 << endl;
      return 0;
    }
    else if(t[i] <= 0){
      ans += a[i];
    }
    else{
      ans++;
    }
  }

  cout << ans-1 << endl;

  return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <cstring>
#include <sstream>
#include <iostream>
#include <string>

int main(void)
{
    int a, b;
    char res[256];

    std::string str;

    while (getline(std::cin, str)) {
        std::istringstream str_s(str);
        str_s >> a >> b;

        sprintf(res, "%d", a+b);

        std::cout << strlen(res) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N, numB = 0;
	long long ans = 0;
	scanf("%d", &N);
	char rgb[N];
	bool b[N];
	for (int i = 0; i < N; ++i) scanf(" %c", &rgb[i]);
	for (int i = 0; i < N; ++i) b[i] = rgb[i] == 'B';
	for (int i = 0; i < N; ++i) numB += b[i];
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (rgb[i] == 'R' && rgb[j] == 'G') {
				ans += numB;
				if (0 <= 2 * i - j && 2 * i - j < N && b[2 * i - j]) --ans;
				if (0 <= 2 * j - i && 2 * j - i < N && b[2 * j - i]) --ans;
				if ((j - i) % 2 == 0 && b[i + (j - i) / 2]) --ans;
			}
		}
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm> // sort
#include <map>       // pair
#include <vector>
using namespace std;

#define REP(a,b) for(int i =(a);i < (b);i++)
#define FOR(n) for(int i = 0; i<(n); i++)
#define COUT(c)  cout<<(c)<<endl


const int INF = 100100100;
const int MOD = (int)1e9 +7;
const double EPS = 1e-9; 

typedef long long int ll;

//char in[120];
//ex. pair
//pair<pair<string,int>,int> p[110];

int main(){

    int n; cin >> n;
    vector<int> v(n,0),v2(n,0);
    FOR(n){
        int tmp;cin>>tmp;
        v[i] = tmp;
        v2[i] = tmp;
    }
    sort(v2.begin(),v2.end());
    int cnt = 0;
    FOR(n){
        if(v[i]!=v2[i]) cnt++;
    }

    if (cnt < 3) COUT("YES");
    else COUT("NO");

    return 0;    
}

Measured memory_bytes: 256
k = int(input())
a,b = input().strip().split()
a,b = [int(a),int(b)]
counter = 0
for i in range(a,b+1):
    if i%k ==0:
        counter +=1
    else:
        continue
if counter >=1:
    print("OK")
else:
    print("NG")


Measured memory_bytes: 9172
import sys
sys.setrecursionlimit(10**9)

input = sys.stdin.readline

N = int(input())

T = [[] for _ in range(N+1)]

for _ in range(N-1) :
    a,b,c = map(int,input().split())
    T[a].append([b,c])
    T[b].append([a,c])

Q,K = map(int,input().split())

dist = [None]*(N+1)

def dfs(now,d) :
    dist[now] = d
    for to,c in T[now] :
        if dist[to] is not None :
            continue
        dfs(to,d+c)

dfs(K,0)

ans = [0]*Q

for i in range(Q) :
    u,v = map(int,input().split())
    ans[i] = dist[u]+dist[v]

print(*ans,sep="\n")



Measured memory_bytes: 140492
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __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 debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e4 + 10;

ll a[N];
ll dp[2][N][2];

// ll solve(int i, int j, int turn);

int main() {
    fast_io();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    // for (int i = 0; i < 2; i++) {
    //     for (int j = 0; j < N; j++) {
    //         dp[i][j][0] = dp[i][j][1] = -1;
    //     }
    // }
    for (ll i = n - 1; i >= 0; i--) {
        for (ll j = 0; j < n; j++) {
            if (i > j) {
                continue;
            }
            for (ll turn = 0; turn <= 1; turn++) {
                dp[i % 2][j][turn] = max(a[i] - dp[(i + 1) % 2][j][turn ^ 1], a[j] - dp[i % 2][j - 1][turn ^ 1]);
            }
        }
    }
    // debug(dp[0][n - 1][0]);
    cout << dp[0][n - 1][0] << "\n";
    // for (ll i = 0; i < n; i++) {
    //     for (ll j = 0; j < n; j++) {
    //         debug(i, j, dp[i % 2][j][0], dp[i % 2][j][1]);
    //     }
    // }
    return 0;
}

// ll solve(int i, int j, int turn) {
//     auto &ans = dp[i % 2][j][turn];
//     if (ans != -1 ) {
//         return ans;
//     }
//     if (i > j) {
//         ans = 0;
//         return ans;
//     }
//     ans = max(a[i] - solve(i + 1, j, turn ^ 1), a[j] - solve(i, j - 1, turn ^ 1));
//     return ans;
// }


Measured memory_bytes: 384
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
  int m,k;
  cin>>m>>k;
  LL thres=1LL<<m;
  if(k==0){
    FOR(i,0,(1LL<<m)){
      cout<<i<<" "<<i<<" ";
    }
    return 0;
  }
  if(m==1){
    cout<<-1<<endl;
    return 0;
  }
  if(thres<=k){
    cout<<-1<<endl;
    return 0;
  }
  int t=0;
  cout<<k<<" ";
  FOR(i,0,(1LL<<m)){
    if(i!=k&&i!=t)cout<<i<<" ";
  }
  cout<<k<<" "<<t<<" ";
  FORD(i,(1LL<<m),0){
    if(i!=k&&i!=t)cout<<i<<" ";
  }
  cout<<t<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
vector<bool> used(100010, 0);
vector<int> ans(100010, -1);
int N;
int K = 1;
vector<pair<int, int>> v[100010];
void paint(int s = 1, int c = 0) {
    used[s] = 1;
    int a = 1;
    for (auto g: v[s]) {
        int t = g.first;
        int n = g.second;
        if (used[t]) continue;
        if (a == c) {
            a++;
        }
        ans[n] = a;
        K = max(K, a);
        paint(t, a);
        a++;
    }
}
int main () {
    cin >> N;
    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(make_pair(b, i));
        v[b].push_back(make_pair(a, i));
    }
    paint();
    cout << K << endl;
    for (int i = 1; i <= N-1; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

ll f(ll x) {
  ll res = 0;
  res = ((x + 1) / 2) % 2;
  if(x % 2 == 0) res ^= x;
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, M = input_number_list()
    H = input_number_list()
    d = defaultdict(lambda: True)

    for i in range(M):
        a, b = input_number_list()
        if H[a - 1] <= H[b - 1]:
            d[a - 1] = False
        if H[a - 1] >= H[b - 1]:
            d[b - 1] = False
    cnt = 0
    for i in range(N):
        if d[i]:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24800
n = input()
A = list(map(int, input().split()))
print(*A)
for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    print(*A)

Measured memory_bytes: 6756
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

ll partition(vector<ll>&a,ll p,ll r)
{
    ll ret=p-1;
    for(ll i=p;i<=r;++i)
        if(a[i]<=a[r])
            swap(a[++ret],a[i]);
    return ret;
}
int main()
{
    ll n=in();vector<ll>a(n);for(ll i=0;i<n;++i)a[i]=in();
    ll p=partition(a,0,a.size()-1);
    for(ll i=0;i<n;++i){
        if(i!=0)cout<<' ';
        if(i==p)cout<<'['<<a[i]<<']';
        else cout<<a[i];
    }
    cout<<endl;
}


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

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

int main(void) {
    mp::cpp_int A,B,N;

    cin >> A >> B >> N;

    if(B == 1) {
        cout << "0\n";
    } else {
        if(B > (N+1)){
            cout << ((A * N)/B) << "\n"; 
        } else {
            cout << ((A * (B-1))/B) << "\n"; 
        }
    }
    return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    set<int> st;
    int val = 0;
    rep(i, n){
        int a;
        cin >> a;
        st.insert(a);
        val ^= a;
    }

    int ans = 0;
    rrep(i, 31){
        if(val >> i & 1){
            for(auto it = st.begin() ; it != st.end() ; ++it){
                if(((*it) >> i & 1) != 1){
                    continue;
                }
                bool flag = true;
                rep(j, i){
                    if((*it) >> j & 1){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    val ^= (1 << i);
                    val ^= ((1 << i) - 1);
                    st.erase(it);
                    ++ans;
                    break;
                }
            }
        }
    }

    if(val == 0){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif

const int MAXN = 3010;
const LL mod = 998244353;

LL F[MAXN][MAXN];
LL S[MAXN][MAXN];

LL esp(LL x, LL e) {
    if (e == 0) return 1;
    if (e % 2 == 1) return (x*esp((x*x)%mod, e/2))%mod;
    return esp((x*x)%mod, e/2);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    for (int X = A; X <= C; X++) F[X][B] = esp(B, X-A);
    for (int Y = B; Y <= D; Y++) F[A][Y] = esp(A, Y-B);
    for (int X = A+1; X <= C; X++) {
        for (int Y = B+1; Y <= D; Y++) {
            S[X][Y] = S[X][Y-1]*(X-1) + F[X][Y-1];
            S[X][Y] %= mod;
            F[X][Y] = Y* F[X-1][Y] + S[X][Y];
            F[X][Y] %= mod;
        }
    }
    //~ for (int X = A; X <= C; X++) for (int Y = B; Y <= D; Y++) cout << X << " " << Y  << ": " << S[X][Y] << " " << F[X][Y] << endl;
    cout << F[C][D] << "\n";
    
}


Measured memory_bytes: 144636
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	vector<int> stu_num;
	for (int i = 0; i < 28; i++){
		int tmp;
		cin >> tmp;
		stu_num.push_back(tmp);
	}

	bool f = false;

	//for all size number 
	for (int i = 1; i <= 30; i++) {
		f = false;
		for (int j = 0; j < (int)stu_num.size(); j++){
			if(i == stu_num[j])
				f = true;
		}
		if(!f)
			cout << i << endl;

	}
	return 0;
}

Measured memory_bytes: 1216
import math
import sys
import collections
import sys

sys.setrecursionlimit(200000)

input = sys.stdin.readline
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
# for i in range(H):
#     for j in range(W):
#         if C[i][j] == ".":
#             C[i][j] = 0
#         else:
#             C[i][j] = 1
d = [[1, 0], [0, 1]]
dp = [[0] * (W  ) for i in range(H ) ]
sx = 1
sy = 1
MOD = 10 ** 9 + 7
dp[0][0] = 1
for w in range(W):
    for h in range(H):
        if h  <  H - 1  and C[h + 1][w] == ".":
            dp[h + 1][w] += dp[h][w]
            dp[h + 1][w] %= MOD
        if w  <  W - 1  and C[h][w + 1] == ".":
            dp[h][w + 1] += dp[h][w]
            dp[h][w + 1] %= MOD

print(dp[H-1][W-1])



Measured memory_bytes: 89068
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
#define REP(i,n) for(long long (i)=0;(i)<(long long)(n);(i)++)
#define RREP(i,n) for(long long (i)=(long long)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
int main() {

    string S;
    cin >> S;

    cout << S.substr(0, S.size() - 8) << endl;
 

    return 0;
}

Measured memory_bytes: 768
#include <iostream> 
#include <sstream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <algorithm> 
#include <functional> 
#include <utility> 
#include <bitset> 
#include <cmath> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
using namespace std;

int main(){
	long long k;
	cin>>k;
	cout<<50<<endl;
	long long a=k/50;
	long long r=k%50;
	for(long long i=1;i<=50;i++){
		if(i<=r) cout<<51-i+a<<' ';
		else cout<<50-i+a<<' ';
	}
return 0;
}

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

void dfs(int i,int s,bool* count,vector<int>* link,int* value){
	count[i]=1;
	value[i]+=s;
	for(int j=0;j<link[i].size();j++){
		int next=link[i][j];
		if(count[next]==1) continue;
		else{
			dfs(next,value[i],count,link,value);
		}
	}
}

int main(){
	int N,Q,a,b,p,x;
	cin >>N>>Q;
	vector<int> link[N];
	bool count[N];
	int value[N];
	for(int i=0;i<N;i++){
		count[i]=0;
		value[i]=0;
	}
	for(int i=0;i<N-1;i++){
		cin >>a>>b;
		a=a-1;
		b=b-1;
		link[a].push_back(b);
		link[b].push_back(a);
	}
	for(int i=0;i<Q;i++){
		cin >>p>>x;
		value[p-1]+=x;
	}
	dfs(0,0,count,link,value);
	for(int i=0;i<N;i++){
		cout <<value[i];
		if(i!=N-1) cout <<" ";
	}
	cout <<endl;
}

Measured memory_bytes: 26752
#include<stdio.h>
int main(void)
{
 int i,n,max=0,maxn=1,s=0,a;
 scanf("%d",&n);
  
if(2<=n)
for(i=2;i<=n;i+=2)
{
  a=i;
  while(a%2==0)
  {
    s++;
    a=a/2;
  }
  if(s>max){max=s;maxn=i;}
  s=0;
}

  printf("%d",maxn);
 return 0;
}

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

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)


#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//code	
    ll d,n;
    cin >> d>> n;
    if(n==100){
        if(d==0)
            n=101;
        else if(d==1)
            n=10100;
        else
            n=1010000;
    }
    else
    forn(i,d){
        n*=100;
    }
    cout << n;
	
	return 0;

}



Measured memory_bytes: 256