akhauriyash/Code-Regression huggingface dataset:
def primes(n,thr):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(thr, n + 1) if is_prime[i]]

def main():
    X = int(input())
    arr = primes(X+1000000, X)
    print(arr[0])

main()


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

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


ll x;

void check(ll a, ll b){
    if(a*a*a*a*a -  b*b*b*b*b == x){
        cout << a << " " << b;
        exit(0);
    }
    //return (a*a*a*a*a -  b*b*b*b*b == x);
}



int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    //ll x;
    cin >> x;
    ff(i,-1000,1000){
        ff(j,-1000,1000){
            check(i,j);
        }
    }
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int H[N];
    rep(i, N) cin >> H[i];
    int A[M], B[M];
    rep(i, M) cin >> A[i] >> B[i];

    int nice[N];
    rep(i, N) nice[i]=1;
    rep(i, M){
        if(H[A[i]-1] > H[B[i]-1]) nice[B[i]-1]=0;
        else if(H[A[i]-1] < H[B[i]-1])nice[A[i]-1]=0;
        else if(H[A[i]-1] == H[B[i]-1]){
            nice[A[i]-1]=0;
            nice[B[i]-1]=0;
        }
    }

    int ans=0;
    rep(i, N) if(nice[i]==1) ans++;

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

Measured memory_bytes: 5116
n,A,B,C = map(int,input().split())
li = [int(input()) for _ in range(n)]

def searchans(count,a,b,c):
    if count == n:
        if not 0 in [a,b,c]:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**100
    else:
        ret0 = searchans(count+1,a,b,c)
        ret1 = searchans(count+1,a+li[count],b,c) + 10
        ret2 = searchans(count+1,a,b+li[count],c) + 10
        ret3 = searchans(count+1,a,b,c+li[count]) + 10
        return min([ret0,ret1,ret2,ret3])

print(searchans(0,0,0,0))


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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T>
auto make_vector(int n, int m, const T &value){
  return std::vector<std::vector<T>>(n, std::vector<T>(m, value));
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}



namespace solver{
  void init(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(12);
    std::cerr << std::fixed << std::setprecision(12);
    std::cin.exceptions(std::ios_base::failbit);
  }
  
  void solve(){
    int D, T, S; std::cin >> D >> T >> S;

    std::cout << (T * S >= D ? "Yes" : "No") << "\n";
    
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int length = S.length();
  for (int i = 0; i < length; ++i) {
    printf("x");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
import itertools


def solve(n, ds):
    cs = sorted(ds)
    cur_num_items = 0
    k_lb = None
    k_ub = None
    table = [(k, len(tuple(g))) for k, g in itertools.groupby(cs)]
    for k, m in table:
        cur_num_items += m
        if k_lb is not None:
            k_ub = k
            break
        elif cur_num_items == n // 2:
            k_lb = k + 1
        elif cur_num_items > n // 2:
            return 0
    res = k_ub - k_lb + 1
    return res


def main():
    n = int(input())
    ds = [int(d) for d in input().split()]
    res = solve(n, ds)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 55404
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

ll lcm(ll x, ll y) {
    return x / gcd(x,y) * y;
}

int main(void)
{
    IOS
    ll a, b;
    cin >> a >> b;
    ll c, d;
    cin >> c >> d;

    a--;
    ll lc = lcm(c,d);
    ll ans = b - b/c - b/d + b/lc;
    ans -= a - a/c - a/d + a/lc;

    cout << ans << '\n';


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

#define chmin(a,b) a=min(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

int d[100][100];

signed main()
{
	int N, K;
	
	while (scanf("%d %d", &N, &K), N || K) {
		fill(d[0], d[N], inf);
		rep(i, N) d[i][i] = 0;

		rep(i, K) {
			int t; scanf("%d", &t);
			if (t) {
				int a, b, c; scanf("%d %d %d", &a, &b, &c); a--; b--;
				chmin(d[a][b], c);
				chmin(d[b][a], c);
				rep(j, N) rep(k, N) {
					chmin(d[j][k], min(d[j][a] + d[a][b] + d[b][k], d[j][b] + d[b][a] + d[a][k]));
				}
			} else {
				int a, b; scanf("%d %d", &a, &b); a--; b--;
				printf("%d\n", d[a][b] == inf ? -1 : d[a][b]);
			}
		}
	}
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<LL,LL> PII;
const int INF=0x3f3f3f3f;
const int MAX_N=1e5 + 10;
const LL mod=1e9+7;
const double PI=acos(-1);

int num[MAX_N];
LL to[MAX_N];
LL be[MAX_N];
LL tot[MAX_N];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)    scanf("%d", &num[i]);
    LL mmax = 0;
    for(int i = 2; i <= n; ++i){
        if(num[i] >= num[i - 1]){
            mmax += num[i] - num[i - 1];           // 计算没有跳的时候的次数
            if(num[i] > num[i - 1] + 1){
                be[num[i - 1] + 1]++;              // 计录从这个位置出发的数量
                to[num[i]] += num[i - 1] + 1;      // 计录所有到这个位置的数字的和
                tot[num[i]]++;                     // 记录到这个位置的数量
            }
        }
        else{
            mmax += num[i] + m - num[i - 1];
            to[num[i]] += num[i - 1] - m + 1;
            tot[num[i]]++;
            if(num[i - 1] == m) be[1]++;
            else{
                be[num[i - 1] + 1]++;
                to[m] += num[i - 1] + 1;
                tot[m]++;
            }
        }
    }
    //cout << mmax << endl;
    LL ans = 0, stot = 0, now = 0;
    for(int i = m; i >= 1; --i){
        stot += tot[i] - be[i];
        now += to[i] - be[i] * i;
        //printf("i = %d, ans = %lld\n", i, mmax - (i * stot - now));
        ans = max(ans, i * stot - now);
    }
    printf("%lld\n", mmax - ans);
    return 0;
}


Measured memory_bytes: 2944
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void)
{
    int n,i,j;
    while(scanf("%d",&n)==1)
    {
        int sum = 0;
        for(i=1;;i++)
        {
            sum += i;
            if(sum >= n)
                break;
        }
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const ll mod = 998244353;
int x[maxn],y[maxn],z[maxn];
int fa[maxn];
int findfa(int p)
{
    return (p == fa[p])?p:fa[p] = findfa(fa[p]);
}
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i = 0; i < m; ++i)
        {
            cin>>x[i]>>y[i]>>z[i];
            z[i] = z[i]&1;
        }
        for(int i = 1; i <= n; ++i)fa[i] = i;
        for(int i = 0; i < m; ++i)
        {
            int xx = findfa(x[i]);
            int yy = findfa(y[i]);
            if(xx == yy)continue;
            fa[xx] = yy;
        }
        for(int i = 1; i <= n; ++i)fa[i] = findfa(i);
        sort(fa+1,fa+n+1);
        int ans = 0;
        int now = -1;
        for(int i = 1; i <= n; ++i)
            if(fa[i] != now)
            {
                ans++;
                now = fa[i];
            }
        cout<<ans<<endl;
    }
}




















Measured memory_bytes: 11392
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
#include <iomanip>
using namespace std;

//??°?????????????????°

void function()
{
	//??¢??°
}

int main()
{
	string s, p;
	cin >> s >> p;

	s = s + s;
	for (int i = 0; i < (int)(s.length() - p.length()); i++)
	{
		if (s.substr(i, p.length()) == p)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1192
from copy import deepcopy
dp = {0: 0}

N = int(input())
A = list(map(int, input().split()))

balls = {}
fact = 1
for (i, a) in enumerate(A):
  count = i+1
  dp[count] = count * (count-1) // 2
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

res = 0
for count in balls.values():
  res += dp[count]

for a in A:
  print(res - dp[balls[a]] + dp[balls[a]-1])

Measured memory_bytes: 108228
n,m = map(int,input().split())
b = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
c = 0
for i in range(1 << n):
    a = [0]*n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            a[j] = 1
    for k in range(m):
        if sum(a[l-1] for l in b[k][1:])%2 == p[k]:
            continue
        else:
            break
    else:
        c += 1
print(c)

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

int main() {
char b;
cin >>b;
if(b=='A')cout<<'T'<<endl;
if(b=='C')cout<<'G'<<endl;
if(b=='G')cout<<'C'<<endl;
if(b=='T')cout<<'A'<<endl;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007   
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}


int dp[100][100];
void solve(){
    int n;
    cin >> n;
    vi v(n);
    vi f(n+1, 0);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        f[v[i]]++;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += (f[i]*(f[i]-1))/2;
        // cout << ans << endl;
    }
    for(int i = 0; i < n; i++){
        ans -= (f[v[i]]*(f[v[i]]-1))/2;
        f[v[i]]--;
        ans += (f[v[i]]*(f[v[i]]-1))/2;
        cout <<  ans <<  endl;
        ans -= (f[v[i]]*(f[v[i]]-1))/2;
        f[v[i]]++;
        ans += (f[v[i]]*(f[v[i]]-1))/2;
    }
}

signed main(){  
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
    // cin >> t;  
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}

Measured memory_bytes: 5760
import itertools

N = int(input())
key = "MARCH"
S = [x for x in [input() for i in range(N)] if x[0] in key]
march = {}
for x in S:
    march.setdefault(x[0], []).append(x)

sizes = [len(x) for x in march.values()]
print(sum([a*b*c for a, b, c in itertools.combinations(sizes, 3)]))


Measured memory_bytes: 11040
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }
  vector<tuple<int, int, int, int>> op;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W - 1; j++){
      if (a[i][j] % 2 == 1){
        a[i][j]--;
        a[i][j + 1]++;
        op.push_back(make_tuple(i + 1, j + 1, i + 1, j + 2));
      }
    }
  }
  for (int i = 0; i < H - 1; i++){
    if (a[i][W - 1] % 2 == 1){
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
      op.push_back(make_tuple(i + 1, W, i + 2, W));
    }
  }
  int N = op.size();
  cout << N << endl;
  for (int i = 0; i < N; i++){
    cout << get<0>(op[i]) << ' ' << get<1>(op[i]) << ' ' << get<2>(op[i]) << ' ' << get<3>(op[i]) << endl;
  }
}

Measured memory_bytes: 5232
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 200002;

int n;
char a[MAX];

int main(void) {
	// in = fopen("A.in", "rt");
	
	fscanf(in, "%s", a);
	n = (int)strlen(a);
	
	long long ans = 0, cnt = 0;
	for (int i = 0; i < n; i++) {
	    if (a[i] == 'B') {
	        cnt++;
        } else {
            ans += cnt;
        }
    }
    fprintf(out, "%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 384
my ($n,$m)=get.words;
my$a=(get)xx $n;
my$b=lines;
for 0..$n-$m X 0..$n-$m ->($i,$j) {
	my$f=1;
	for ^$m ->$k {if !$a[$i+$k].substr-eq($b[$k],$j) {$f=0;last;}}
    if $f {say "Yes";exit}
}
say "No"

Measured memory_bytes: 77444
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());



int main() {
    int N, K;
    cin >> N >> K;

    double ans = 0.0;
    for(int i=N;i>0;i--) {
        int NNN = i;
        int cnt = 0;
        while (NNN < K) {
            NNN *= 2;
            cnt++;
        }
        ans += pow(0.5, cnt);
    }

    double Nans = double(N);
    double ansx = ans / Nans;

    printf("%.10f\n", ansx);
}

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

int main(){
	int N;
	cin >> N;
	int d = 0;
	rep(i,N) {
		int a, b;
		cin >> a >> b;
		if (a == b) d++;
		else d = 0;
		if (d == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}


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

int main()
{
    long long n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    const int mod = 1000000007;
    long long p = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                p++;
                p %= mod;
            }
        }
    }

    p *= k;
    p %= mod;

    long long q = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) {
                q++;
                q %= mod;
            }
        }
    }

    q *= (k * (k - 1) / 2 % mod);
    p += q;
    p %= mod;
    std::cout << p << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 998244353;
constexpr long long inf = 3e18;

template<typename Monoid,typename OperatorMonoid,typename F,typename G,typename H>
struct Segtree{
	int size=1;
	vector<Monoid>dat;
	vector<OperatorMonoid>lazy;
	const F f;
	const G g;
	const H h;
	Monoid M;
	OperatorMonoid OM;
	void set(int a,Monoid x){
		dat[a+size-1]=x;
	}
	void init(){
		for(int i=size-2;i>=0;i--){
			dat[i]=f(dat[i*2+1],dat[i*2+2]);
		}
	}
	void eval(int k,int l,int r){
		if(lazy[k]!=OM){
			dat[k]=g(dat[k],lazy[k],(r-l));
			if(r-l>1){
				lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2],lazy[k]);
			}
			lazy[k]=OM;
		}
	}
	void update(int a,int b,OperatorMonoid M,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=h(lazy[k],M);
			eval(k,l,r);
			return;
		}
		update(a,b,M,k*2+1,l,(l+r)/2);
		update(a,b,M,k*2+2,(l+r)/2,r);
		dat[k]=f(dat[k*2+1],dat[k*2+2]);
	}
	Monoid query(int a,int b,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return M;
		if(a<=l&&r<=b)return dat[k];
		Monoid lv=query(a,b,k*2+1,l,(l+r)/2);
		Monoid rv=query(a,b,k*2+2,(l+r)/2,r);
		return f(lv,rv);
	}
	template<class C>
	int minLeft(int a,int b,C &check,Monoid x,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l||!check(dat[k],x))return -1;
		if(r-l==1)return l;
		int lv=minLeft(a,b,check,x,k*2+1,l,(l+r)/2);
		if(lv!=-1)return lv;
		return minLeft(a,b,check,x,k*2+2,(l+r)/2,r);
	}
	template<class C>
	int maxRight(int a,int b,C &check,Monoid x,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l||!check(dat[k],x))return -1;
		if(r-l==1)return l;
		int rv=maxRight(a,b,check,x,k*2+2,(l+r)/2,r);
		if(rv!=-1)return rv;
		return maxRight(a,b,check,x,k*2+1,l,(l+r)/2);
	}
	Segtree(int x,F f,G g,H h,Monoid M,OperatorMonoid OM)
	:f(f),g(g),h(h),M(M),OM(OM){
		while(size<x)size*=2;
		dat.resize(size*2-1,M);
		lazy.resize(size*2-1,OM);
	}
};

auto f=[](int a,int b)->int{return (a+b)%mod;};
auto g=[](int a,P b,int sz)->int{return (a*b.first+b.second*sz)%mod;};
auto h=[](P a,P b)->P{return P(a.first*b.first%mod,(a.second*b.first+b.second)%mod);};

signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,Q;
	cin>>N>>Q;
	Segtree<int,P,decltype(f),decltype(g),decltype(h)>segtree(N,f,g,h,0,P(1,0));
	rep(i,N){
		int a;cin>>a;
		segtree.set(i,a);
	}
	segtree.init();
	while(Q--){
		int t;cin>>t;
		if(!t){
			int l,r,b,c;cin>>l>>r>>b>>c;
			segtree.update(l,r,P(b,c));
		}else {
			int l,r;cin>>l>>r;
			cout<<segtree.query(l,r)<<"\n";
		}
	}
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
int keta(ll n){
  int count=1;
  while(n/10>0){
    n/=10;
    count++;
    }
  return count;
}


int F(ll A,ll B){
  int m;
  m=max(keta(A),keta(B));
    return m;

}
int main(){
  ll N;
  cin >>N;
  int m=100000;
  for(ll i=1;i<1000000;i++){
    if(N%i==0)
      m=min(m,F(i,(ll)N/i));
    

  }

  cout<<m<<endl;

  return 0;
}


Measured memory_bytes: 256
INF = int(1e9 + 7)


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    return a * b % INF


def factorial(x):
    FCT = 1
    for i in range(2, x + 1):
        FCT = modmulti(i, FCT)
    return FCT


def main():
    N, M = map(int, input().split())
    MIN_NM = factorial(min(N, M))
    if N == M:
        print(modmulti(2, modmulti(MIN_NM, MIN_NM)))
    elif abs(N - M) <= 1:
        print(modmulti(MIN_NM, modmulti(MIN_NM, max(N, M))))
    else:
        print(0)

    return


main()


Measured memory_bytes: 3064
main = do
    [a, b, h, m] <- (map read . words) <$> getLine
    putStrLn $ show $ clockDistance a b h m

clockDistance :: Double -> Double -> Double -> Double -> Double
clockDistance hlen mlen h m =
    sqrt $ (hlen ** 2) + (mlen ** 2) - 2.0 * hlen * mlen * (cos angle)
    where
        ha = 2.0 * pi * (h / 12.0 + m / 720.0) 
        ma = 2.0 * pi * (m / 60.0)
        angle1 = abs $ ha - ma
        angle = min angle1 (pi * 2.0 - angle1)

Measured memory_bytes: 4520
#include <stdio.h>
int main()
{
	int n, i;
	
	scanf("%d", &n);
	int a[n];
	for(i = 0; i < n; i++){	
		scanf("%d", &a[i]);
	}
	
	for(i = n-1; i >= 0; i--){
		printf("%d", a[i]);
		if(i>0)printf(" ");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2032
#include <stdio.h>
 
int main(){

    // number of scans
    int n;
    scanf("%d", &n);

    int b,f,r,v;
    int array[4][3][10] = {};

    for (int i=0; i<n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        array[b-1][f-1][r-1] += v;
    }

    for (int i=0; i<4; i++) {

        for (int j=0; j<3; j++) {

            for (int k=0; k<10; k++) {
                printf(" %d", array[i][j][k]);
            }
            putchar('\n');
        }
        if (i<=2)
            printf("####################\n");
    }

    return 0;
}


Measured memory_bytes: 2676
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<int,int> P;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
vin dp(1000,0);
int main(){
  int n;
  cin>>n;
  vll p(n),q(n);
  int a=0,b=0;
  REP(i,n){
    cin>>p[i];
  }
  REP(i,n){
    cin>>q[i];
  }
  vll s(n);
  REP(i,n){
    s[i]=i+1;
  }
  int i=0;
  do{
    if(s==p){a=i;}
    if(s==q){b=i;}
    i++;
  }while(next_permutation(s.begin(),s.end()));
  cout<<abs(a-b)<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;



int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);

    int k;
    cin>>k;

    if(k%2 == 0 || k%5 == 0){
        cout<<"-1\n";
        return 0;
    }

    int cnt = 7;
    int res = 1;
    while(true){
        cnt%=k;
        if(cnt == 0){
            cout<<res<<endl;
            return 0;
        }
        res++;
        cnt*=10;
        cnt+=7;
    }

    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int P = sc.nextInt();
        int ans = solve(A, P);

        System.out.println(ans);
    }

    private static int solve(int A, int P) {
        int sum = A*3 + P;

        return sum/2;
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <utility>
#include <unordered_map>
#include <algorithm>

using namespace std;

int N;
string S;

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator () (const std::pair<T1, T2> &p) const {
		auto h1 = std::hash<T1>{}(p.first);
		auto h2 = std::hash<T2>{}(p.second);

		// Mainly for demonstration purposes, i.e. works but is overly simple
		// In the real world, use sth. like boost.hash_combine
		return h1 ^ h2;
	}
};

using P = pair<string, string>;

void solve() {
	long long ans;
	cin >> N >> S;
	string S1, S2;
	S1 = S.substr(0, N);
	S2 = S.substr(N, N);
	reverse(S2.begin(), S2.end());

	unordered_map<P, int, pair_hash> um;
	for (int Nbits_i = 0; Nbits_i < 1 << N; Nbits_i++)
	{
		string A1 = "", B1 = "";
		for (int S1_i = 0; S1_i < N; S1_i++)
		{
			if (Nbits_i >> S1_i & 1) {
				A1 += S1[S1_i];
			}
			else {
				B1 += S1[S1_i];
			}
		}
		um[P(A1, B1)]++;
	}
	long long sum = 0;
	for (int Nbits_i = 0; Nbits_i < 1 << N; Nbits_i++)
	{
		string A2 = "", B2 = "";
		for (int S2_i = 0; S2_i < N; S2_i++)
		{
			if (Nbits_i >> S2_i & 1) {
				A2 += S2[S2_i];
			}
			else {
				B2 += S2[S2_i];
			}
		}
		sum += um[P(A2, B2)];
	}

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

int main() {
	solve();

	return 0;
}


Measured memory_bytes: 95348
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  int N; cin>>N;
  int k;
  for(int i=0;pow(2,i)<=N;i++)
  {
    k=i;
  }
  k++;
  //cout<<k<<endl;
  int sum=0;
  vector<int> a(N);
  rep(i,N)
  {
    cin>>a.at(i);
    int hoge=a.at(i);
    sum=(sum^hoge);
  }
  
  rep(i,N)
  {
    if(i!=0) {cout<<" ";}
    int hoge=a.at(i);
    cout<<(ll)(sum^hoge);
  }  
  return 0;
}


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

int main(){
	int a,b;
	cin >> a >> b;
	cout << "a ";
	if(a<b) cout << "< ";
	if(a==b) cout << "== ";
	if(a>b) cout << "> ";
	cout << "b" << endl;
	
	
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;

const ll dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
char s[100][100];
ll n,m,sum,d[100][100];
struct node{
	ll x,y;
};
queue<node> q;

inline void bfs(){
	q.push(node{1,1}); d[1][1]=1;
	while(!q.empty()){
		ll x=q.front().x,y=q.front().y; q.pop();
		for(ll i=0; i<4; i++){
			ll X=x+dx[i],Y=y+dy[i];
			if(X>=1&&X<=n&&Y>=1&&Y<=m&&!d[X][Y]&&s[X][Y]=='.'){
				q.push(node{X,Y});
				d[X][Y]=d[x][y]+1;
				if(X==n&&Y==m) return;
			}
		}
	}
}

int main(){
	cin>>n>>m;
	for(ll i=1; i<=n; i++){
		scanf("%s",s[i]+1);
		for(ll j=1; j<=m; j++){
			if(s[i][j]=='.') sum++;
		}
	}
	bfs();
	if(d[n][m]) cout<<sum-d[n][m]<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}

int main(void){
    int n,k,i;
    scanf("%d %d",&n,&k);
    int p[n];

    for(i = 0;i <= n - 1 ;i++ ){
        p[i] = '\0';
    }

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

    int sam = 0;

    for(i = 0 ; i <= k - 1 ; i++){
        sam = sam + p[i];
    }
    printf("%d",sam);

    return 0;
}



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

#define                 ll            long long
#define                 mx            100005
#define                 read          freopen("in.txt", "r", stdin);
#define                 optimize      ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

int main()
{
	optimize

	int a, b;

	cin >> a >> b;

	cout << max(a+b, max(a-b, a*b)) << endl;


	return 0;
}

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

int main(){
	int N,a;
  	cin>>N;
  	cin>>a;
  	int maxv=a,minv=a;
  	for(int i=1;i<N;++i){
    	cin>>a;
      	maxv=max(a,maxv);
      	minv=min(a,minv);
    }
  	cout<<maxv-minv<<endl;
  	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int x;
  scanf("%d",&x);
  int tmp=x;
  while(1){
    int flag=0;
    for(int i=2;i<x;i++){
      if(tmp%i==0){
        flag=1;
      }
    }
    if(flag==0){
      printf("%d\n",tmp);
      return 0;
    }
    tmp++;
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <stack>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << 31) - 1);
const signed long long llf = (signed long long)((1ull << 61) - 1);
const double eps = 1e-6;
const int binary_limit = 128;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
    char x;
    int aFlag = 1;
    while(!isdigit((x = getchar())) && x != '-' && x != -1);
    if(x == -1) {
        ungetc(x, stdin);    
        return false;
    }
    if(x == '-'){
        x = getchar();
        aFlag = -1;
    }
    for(u = x - '0'; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x - '0');
    ungetc(x, stdin);
    u *= aFlag;
    return true;
}

#define LL long long

int n;
LL a[55];
inline void init() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf(Auto, a + i);
}

LL K = 0;
int id = 0;
LL check() {
	LL ret = 0;
	for(int i = 1; i <= n; i++)
		if(a[i] + K > ret)
			ret = a[i] + K, id = i;
	return ret;
}

inline void solve() {
	LL c;
	while((c = check()) >= n) {
		K += c / n;
		a[id] -= (c / n) * (n + 1);
	}
	printf(Auto, K);
}

int main() {
	init();
	solve();
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int zero = 0;
    int one = 0;

    for (int i = 0; i < s.size(); ++i){
        char c = s[i];
        if (c == '0') zero++;
        else one++;
    }
    cout << min(zero, one) * 2 << endl;
}

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

int main(void){
    int N;
    cin>>N;
    int p[N],sum=0;
    for(int i=0;i<N;i++)
        cin>>p[i];
    sort(p,p+N);
    for(int i=0;i<N;i++){
        if(i==N-1)
            p[i]/=2;
        sum+=p[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
true_list = ["5","7","5"]
val = input()
splited_val = val.split()
diff = set(true_list) ^ set(splited_val)

if len(diff) == 0:
    splited_val_int = [int(s) for s in splited_val]
    if sum(splited_val_int) == 17:
        print("YES")
    else:
        print("NO")
else:
    print("NO")
    

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;

int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	map<string, int> f;
	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string s;
		cin>>s;
		f[s]++;
	}	

	cout<<"AC x "<<f["AC"]<<"\n";
	cout<<"WA x "<<f["WA"]<<"\n";
	cout<<"TLE x "<<f["TLE"]<<"\n";
	cout<<"RE x "<<f["RE"]<<"\n";
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
int N,M;
vector<vector<int>> edge(100010, vector<int>(0));
int dp[100010];
bool visited[100010];

ll dfs(int x){//xからy
    if(visited[x]){
        return dp[x];
    }
    visited[x] = 1;
    
    int M = 0;
    for(int i = 0; i < edge.at(x).size(); i++){
        int m;
        m = dfs(edge.at(x).at(i));
        M = max(M, m);
    }
    
    return dp[x] += M + 1;
    
}





int main(void){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        edge.at(a).push_back(b);
    }
    for(int i = 0; i < 100010; i++){
        visited[i] = 0;
        dp[i] = 0;
    }
    
    for(int i = 0; i < N; i++){
        if(visited[i] == 0){
            dfs(i);
        }
    }
    int Ans = 0;
    for(int i = 0; i < N; i++){
        int ans = dfs(i);
        Ans = max(Ans, ans);
    }
    cout << Ans - 1 << endl;
    
}


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

int main()
{
 
  string s;
  cin>>s;
  int flag = 1;
  
  for(int i=0;i<s.length();i+=2)
  {
    if(s[i]!='h' || s[i+1]!='i')
    {
     	 flag = 0;
      	break;
    }
    
  }
  
  if(flag) cout<<"Yes";
  else cout<<"No";
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <deque>
#include <string>
#include <utility>

#define phb push_back
#define ppf pop_front
#define mkp make_pair
#define r first
#define c second
using namespace std;

typedef pair< int, int > Pr;
const int kDir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int R, C, SR, SC;
char M[25][25];

void read();
void solve();

int main() {
  while (cin >> C >> R, R != 0 && C != 0)
    read(), solve();

  return 0;
}

void read() {
  fill(&M[0][0], &M[25][0], '#');
  for (int i = 1; i <= R; ++i)
    for (int j = 1; j <= C; ++j) {
      cin >> M[i][j];
      if (M[i][j] == '@')
        SR = i, SC = j;
    }
}

void solve() {
  static int vst[25][25], vst_cnt;
  int res = 0;
  deque< Pr > que;

  que.phb(mkp(SR, SC)), vst[SR][SC] = ++vst_cnt;
  while (!que.empty()) {
    Pr cur = que.front(); que.ppf(), ++res;
    for (int di = 0; di < 4; ++di) {
      Pr nxt(cur.r + kDir[di][0], cur.c + kDir[di][1]);
      if (M[nxt.r][nxt.c] == '.' && vst[nxt.r][nxt.c] != vst_cnt)
        que.phb(nxt), vst[nxt.r][nxt.c] = vst_cnt;
    }
  }

  cout << res << "\n";
}

Measured memory_bytes: 1208
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
typedef long long ll;


int main(void){
    // Your code here
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }
    else if(a == c){
        cout << b << endl;
    }
    else{
        cout << a << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int a[n+2];
    a[0] = a[n+1] = 0;
    int sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += abs(a[i] - a[i-1]);
    }
    sum += abs(a[n] - a[n+1]);

    for(int i = 1; i <= n; i++){
        cout << sum + abs(a[i-1] - a[i+1]) - (abs(a[i-1] -a[i]) + abs(a[i] - a[i+1])) << endl;
    }

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 1000000000
int h,w,k,d[1005][1005],sx,sy,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0},ans=INF;
int main(void){
    scanf("%d%d%d",&h,&w,&k);
    for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;
			scanf(" %c",&c);
			if(c=='S')sx=j,sy=i;
			if(c=='#')d[i][j]=INF;
			else d[i][j]=-1;
		}
	}
	queue<P>bfs;
	d[sy][sx]=0;
	bfs.push(P(sy,sx));
	while(!bfs.empty()){
		int x=bfs.front().S,y=bfs.front().F;
		bfs.pop();
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(nx>=0&&nx<w&&ny>=0&&ny<h&&d[ny][nx]==-1){
				d[ny][nx]=d[y][x]+1;
				bfs.push(P(ny,nx));
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(d[i][j]!=-1&&d[i][j]<=k){
				int p=min(min(i,h-i-1),min(j,w-j-1));
				ans=min(ans,(p+k-1)/k+1);
			}
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,cnt=1;
	cin>>a;
	set<ll> s;
	s.insert(a);
	while(1){
		cnt++;
		if(a%2==0){
			a/=2;
		}
		else{
			a=a*3+1;
		}
		if(s.find(a)!=s.end()){
			cout<<cnt<<endl;
			return 0;
		}
		s.insert(a);
	}
}	


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define f(a,b,c,d) for(a=b; a<=c; a+=d)
#define fd(a,b,c,d) for(a=b; a>=c; a-=d)
#define readD(n) scanf("%d", &n)
#define readC(n) scanf("%c", &c)
#define readLLD(n) scanf("I64t", &n)
#define NMAX 100050
#define INF 999999999

using namespace std;

int n, i, rez, mat[NMAX][5], val[NMAX][5];

int main(){
   readD(n);
   f(i,1,n,1){
        readD(mat[i][1]);
        readD(mat[i][2]);
        readD(mat[i][3]);
        }
    val[1][1] = mat[1][1];
    val[1][2] = mat[1][2];
    val[1][3] = mat[1][3];
    f(i,2,n,1){
        val[i][1] = max(val[i-1][2], val[i-1][3]) + mat[i][1];
        val[i][2] = max(val[i-1][1], val[i-1][3]) + mat[i][2];
        val[i][3] = max(val[i-1][2], val[i-1][1]) + mat[i][3];
        }
    rez = max(max(val[n][1], val[n][2]),val[n][3]);
    printf("%d", rez);
   return 0;
   }


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(), (obj).end()

int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  printf("%d\n", (H-h) * (W-w));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
//	ios_base::sync_with_stdio(0); cin.tie(0);
	#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	uint64_t n;
	cin>>n;
	uint64_t a=1;
	uint64_t b=1;
	uint64_t x,y;
	uint64_t ans = 0;
	while(n--)
	{
		cin>>x>>y;
		uint64_t first=x;
		uint64_t second=y;
		//cout<<"before"<<x<<" "<<y<<" "<<a<<" "<<b<<'\n';
		if(x<a || y<b)
		if(a/x > b/y)
		{
			//cout<<a/x<<" "<<b/y<<"mon\n";

			y = y * ((a/x) + (a%x!=0));
			x = x * ((a/x) + (a%x!=0));
		}
		else
		{
			//cout<<x/a<<" "<<y/b<<"mon\n";
			x = x * ((b/y) + (b%y!=0));
			y = y * ((b/y) + (b%y!=0));
		}
		//cout<<x<<" "<<y<<" "<<a<<" "<<b<<'\n';
		a=x;
		b=y;
	}
	cout<<(a+b)<<'\n';
	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;

  int ct2=0;
  int ct4=0;

  rep(i,N){
    int a;
    cin>>a;
    if(a%4==0){
      ++ct4;
    }
    else if(a%2==0){
      ++ct2;
    }

  }

  bool ans=false;

  if(N%2==0){
    if(2*ct4+ct2>=N) ans=true;
  }
  else{
    if(ct4+(ct2-1)/2>=(N/2)) ans=true;
  }

  cout<< ( ans ? "Yes" : "No" )<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  bool a = false;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    if (vec.at(i) == "Y") {
      a = true;
      break;
    }
  }
  if (a) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

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

using namespace std;

int main() {
    bool nafisa = true;
    string s;
    cin >> s;
    int n = s.size();
    string rs = s;
    reverse(rs.begin(),rs.end());
    if (s != rs) {
        nafisa = false;
    }
    string ss = s.substr(0,(n-1)/2);
    string rss = ss;
    reverse(rss.begin(),rss.end());
    if(ss != rss) {
        nafisa = false;
    }
    string sss = s.substr((n+3)/2-1);
    string rsss = sss;
    reverse(rsss.begin(),rsss.end());
    if(sss != rsss) {
        nafisa = false;
    }
    if(nafisa) {
        cout <<"Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

typedef tuple<int, int, int, int, int, int> TP;
const int K = 18;
const int KM = 1 << (K - 1);
pair<int, int> dat1[1 << K], dat2[1 << K];

pair<int, int> check1(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat1[A];
	if (r <= L || R <= l) return mp(1e9, 0);
	return min(check1(L, R, A * 2, l, (l + r) / 2), check1(L, R, A * 2 + 1, (l + r) / 2, r));
}

pair<int, int> query1(int L, int R) {
	return check1(L, R, 1, 0, KM);
}

pair<int, int> check2(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat2[A];
	if (r <= L || R <= l) return mp(1e9, 0);
	return min(check2(L, R, A * 2, l, (l + r) / 2), check2(L, R, A * 2 + 1, (l + r) / 2, r));
}

pair<int, int> query2(int L, int R) {
	return check2(L, R, 1, 0, KM);
}

TP keisan(int A, int B) {
	pair<int, int> p1, p2;
	if (A & 1) {
		p1 = query2(A / 2, B / 2);
		p2 = query1(p1.second / 2 + 1, B / 2 + 1);
	}
	else {
		p1 = query1(A / 2, B / 2 + 1);
		p2 = query2(p1.second / 2, B / 2 + 1);
	}
	return make_tuple(p1.first, p2.first, A, p1.second, p2.second, B);
}

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


	int N;
	cin >> N;
	rep(i, N) {
		int P;
		cin >> P;
		if(i % 2) dat2[i / 2 + KM] = mp(P, i);
		else dat1[i / 2 + KM] = mp(P, i);
	}
	for (int i = KM - 1; i >= 1; i--) {
		dat1[i] = min(dat1[2 * i], dat1[2 * i + 1]);
		dat2[i] = min(dat2[2 * i], dat2[2 * i + 1]);
	}

	priority_queue<TP, vector<TP>, greater<TP>> que;
	auto p1 = query1(0, N / 2);
	auto p2 = query2(p1.second / 2, N / 2);
	que.push(make_tuple(p1.first, p2.first, 0, p1.second, p2.second, N - 1));

	while (que.size()) {
		auto Q = que.top();
		que.pop();
		cosp(get<0>(Q));
		cosp(get<1>(Q));
		if (get<2>(Q) != get<3>(Q)) {
			que.push(keisan(get<2>(Q), get<3>(Q) - 1));
		}
		if (get<3>(Q) + 1 != get<4>(Q)) {
			que.push(keisan(get<3>(Q) + 1, get<4>(Q) - 1));
		}
		if (get<4>(Q) != get<5>(Q)) {
			que.push(keisan(get<4>(Q) + 1, get<5>(Q)));
		}
	}

	Would you please return 0;
}

Measured memory_bytes: 6516
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h> 
#define pb emplace_back
#define mp make_pair 
#define st first 
#define nd second 
#define all(v) v.begin(),v.end()
#define umap unordered_map
#define L nd<<1
#define R (L)|1
#define mid ((s + e)>>1)
#define ln '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n;
ll ans;
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
  cin >> n;
  for(int i = 1; i <= n; i++){
  	if(i%3 != 0 && i%5 != 0)ans+=i;
  }	
  cout << ans;
}

Measured memory_bytes: 3640
import sys
import math
from fractions import gcd
inputs = sys.stdin.readlines()
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)
 
num_b = b - b // c - b // d + b // e
num_a = (a-1) - (a-1) // c - (a-1) // d + (a-1) // e
 
print(num_b - num_a)

Measured memory_bytes: 5048
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int i = 1;
    while(true){
        int x = sc.nextInt();
        if(x == 0){
            break;
        }
        System.out.println("Case " + i + ": " + x);
        i++;
        
    }
  }

}



Measured memory_bytes: 43268