akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

int cnt[2][4005][4005];

int getCount(int xmax, int ymax, int xmin, int ymin, int color){
    if (xmin == 0 && ymin == 0) return cnt[color][xmax][ymax];
    if (xmin == 0) return cnt[color][xmax][ymax]-cnt[color][xmax][ymin-1];
    if (ymin == 0) return cnt[color][xmax][ymax]-cnt[color][xmin-1][ymax];
    return cnt[color][xmax][ymax] + cnt[color][xmin-1][ymin-1] - cnt[color][xmin-1][ymax] - cnt[color][xmax][ymin-1];
}
int main(){
    int n, k;
    scanf("%d%d",&n, &k);
    char str[2];
    int x, y;
    for(int i = 0; i < n; i ++){
        scanf("%d%d%s", &x, &y, str);
        x %= 2*k;
        y %= 2*k;
        int color = (str[0]=='W')?0:1;
        cnt[color][x][y] ++;
        cnt[color][x+2*k][y] ++;
        cnt[color][x][y+2*k] ++;
        cnt[color][x+2*k][y+2*k] ++;
    }
    for(int color = 0; color < 2; color ++){
        for(int i = 1; i < 4*k; i ++){
            cnt[color][0][i] += cnt[color][0][i-1];
        }
        for(int i = 1; i < 4*k; i ++){
            for(int j = 0; j < 4*k; j ++){
                if (j == 0) cnt[color][i][j] += cnt[color][i-1][j];
                else cnt[color][i][j] += cnt[color][i][j-1] + cnt[color][i-1][j] - cnt[color][i-1][j-1];
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 2*k; i ++){
        for(int j = 0; j < 2*k; j ++){
            int a = getCount(i+k-1, j+k-1, i, j, 0);
            int b = getCount(i+k-1, j+2*k-1, i, j+k, 1);
            int c = getCount(i+2*k-1, j+k-1, i+k, j, 1);
            int d = getCount(i+2*k-1, j+2*k-1, i+k, j+k, 0);
            ans = max(ans, a+b+c+d);
        }
    }
    printf("%d\n", ans);
    
}


Measured memory_bytes: 125440
#include <cstdio>
#include <cmath>
using namespace std;
int a[7]={ 1,2,4,8,16,32,64 };
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        int i;
        for(i=0;i<7;i++)
            if(a[i]>n)break;
        printf("%d\n",a[i-1]);
    }
    return 0;
}


Measured memory_bytes: 128
import math
n,k=map(int,input().split())
i=1
sum=0.0
for i in range(1,n+1):
    cnt=k/i
    temp=1/n
    # cznt=i
    #
    # while cnt < k:
    #     cnt*=2
    #     m+=1
    m=math.ceil(math.log2(cnt))

    if i < k:
        sum+=temp * (1/2)**m
    else:
        sum+=temp
    # print(1/n * (1/2)**m)
print(sum)


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

int main(void)
{
    int n, m;
    vector<int> a;
    cin >> n >> m;
    int all_t = 0;
    for(int i = 0; i < n; ++i) {
        int a_tmp;
        cin >> a_tmp;
        a.push_back(a_tmp);
        all_t += a_tmp;
    }
    sort(a.begin(), a.end(), greater<int>());
    if(a.at(m-1) * 4 * m < all_t) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
from itertools import combinations
n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

ans = 0
for i, j in combinations(x, 2):
    tmp = 0
    for k, l in zip(i, j):
        tmp += (k-l)**2
    if round(tmp**0.5)**2==tmp:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int n;


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

    vector<priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>> py(n);

    rep(i, m) {
        int p, y;
        cin >> p >> y;
        --p;
        py[p].push(make_pair(y, i));
    }

    vector<pair<int, int>> res(m);
    rep(i, n) {
        int j = 1;
        while(!py[i].empty()) {
            pair<int, int> v = py[i].top();
            py[i].pop();
            res[v.second] = make_pair(i+1, j);
            ++j;
        }
    }
    
    rep(i, m) {
        cout << setw(6) << setfill('0') << res[i].first;
        cout << setw(6) << setfill('0') << res[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N, M;
  cin >> N >> M;
  int c_min = 1;
  int c_max = N;
  int L, R;
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    c_min = max(c_min, L);
    c_max = min(c_max, R);
    if (c_min > c_max) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << c_max - c_min + 1 << endl;
  return 0;
}

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

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string S[300];
    vector<int> st[300];
    for(int i=0; i<H; i++){
        cin >> S[i];
        for(int j=0; j<W; j++) if(S[i][j] == '#') st[i].push_back(j);
    }
    vector<vector<int>> ans;
    int first_row = -1;
    for(int i=0; i<H; i++){
        if(st[i].size() == 0) continue;
        if(first_row == -1) first_row = i;
        int a = (i==first_row ? 0 : i);
        int b = i;
        while(b < H-1 && st[b+1].size() == 0) b++;
        int sz = st[i].size();
        for(int j=0; j<sz; j++){
            int s = (j==0 ? 0 : st[i][j]);
            int t = (j==sz-1 ? W-1 : st[i][j+1]-1);
            ans.push_back({a, b, s, t});
        }
    }
    int Ans[300][300];
    for(int k=0; k<K; k++){
        for(int i=ans[k][0]; i<=ans[k][1]; i++) for(int j=ans[k][2]; j<=ans[k][3]; j++) Ans[i][j] = k+1;
    }
    for(int i=0; i<H; i++) for(int j=0; j<W; j++) cout << Ans[i][j] << " \n"[j==W-1];
    return 0;
}


Measured memory_bytes: 7540
#include "iostream"
#include <vector>
#include <array>

int main()
{
    uint32_t X;
    std::cin >> X;

    while(true) {
        bool isPrime = true;
        for (uint32_t num = 2; num < X; num++) {
            if (X % num == 0) {
                isPrime = false;
                break;
            }
        }

        if (isPrime) {
            std::cout << X << std::endl;
            break;
        }

        X++;
    }

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
#define repr(i,s,t) for (i64 i = (s); i >= (t); --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a ? (a=b,1) : 0;}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a ? (a=b,1) : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template <class T>
void _trace(const char *s, T&& x)
{
    clog << '{';
    while(*s != '0' && *s != ',') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail)
{
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

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

    const auto id = [](int n) {
        switch(n) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            return 1;
        case 4:
        case 6:
        case 9:
        case 11:
            return 2;
        default:
            return 3;
        }
    };

    int x, y;
    cin >> x >> y;

    cout << ((id(x) == id(y)) ? "Yes" : "No") << "\n";


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

struct Info{
	bool operator<(const struct Info &arg) const{
			return ((time > arg.time) || (time == arg.time && div > arg.div));
	};
	Info(int arg_time,int arg_div){
		time = arg_time;
		div = arg_div;
	}

	int time,div;
};

void func(int N){

	int m,start,end;
	priority_queue<Info> Q;

	for(int i = 0; i < N; i++){
		scanf("%d %d %d",&m,&start,&end);
		Q.push(Info(start,m));
		Q.push(Info(end,(-1)*m));
	}

	int sum = 0;
	bool FLG = true;

	while(!Q.empty()){
		sum += Q.top().div;
		//printf("time %d\n",Q.top().time);

		if(sum > 150){
			FLG = false;
			printf("NG\n");
			break;
		}

		Q.pop();
	}

	if(FLG){
		printf("OK\n");
	}

}

int main(){

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func(N);
	}

	return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n, i;
	cin >> n;
	vector<ll> sum(100010, 0);
	for (i = 1; sum[i - 1] < n; i++) sum[i] += sum[i - 1] + i;
	cout << i - 1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

int n, prefix[101], suffix[101], x;
vector <int> a, b;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        cin >> prefix[i];
    for(int i = 0 ; i < n ; i++)
        cin >> suffix[i];
    for(int i = 1 ; i < n ; i++)
        prefix[i] += prefix[i-1];
    for(int i = n-2 ; i >= 0 ; i--)
        suffix[i] += suffix[i+1];
    int ans = 0;
    for(int i = 0 ; i < n ; i++)
        ans = max(ans, prefix[i]+suffix[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <cstdio>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10
const int MAX_N =10000000;


bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll func(ll a,ll b,ll& ans_x,ll& ans_y){
    if(b == 0){
        ans_x = 1;
        ans_y = 0;
        return a;
    }else{
        ll ret = func(b,(a%b),ans_y,ans_x);
        ans_y -= (a/b)*ans_x;
        return ret;
    }
}

ll par[MAX_N],ranking[MAX_N];

void init(ll n){
    rep(i,n){
        par[i]=i;
        ranking[i]=0;
    }
}

ll find(ll x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}

void unite(ll x,ll y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    
    if(ranking[x]<ranking[y]) par[x]=y;
    else{
        par[y]=x;
        if(ranking[x]==ranking[y]) ranking[x]++;
    }
}

bool same(ll x,ll y){
    return find(x)==find(y);
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    map<ll,ll> mp;
    for(ll i=1;i*i<=m;i++){
        if(m%i==0){
            if(i==m/i) mp[i]+=m/i;
            else {
                mp[m/i]+=i;
                mp[i]+=m/i;
            }
        }
    }
    ll maxi=1;
    for(auto p:mp){
        if(p.second>=n || p.first<=m/n) maxi=max(p.first,maxi);
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 3684
# -*- coding: utf-8 -*-
A, B, K = map(int, input().split())

def is_even(num):
    return num % 2 == 0

for i in range(K):
    if is_even(i):
        if not is_even(A):
            A = A -1
        A, B = A/2, A/2 + B
    else:
        if not is_even(B):
            B = B -1
        B, A = B/2, B/2 + A
    
print(int(A), int(B))

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
const int INFN = 1e9+7;
const int MAXN = 1e5+5;
int dp[MAXN];
int H[MAXN];
int N;

int solve() {
  for (int i = 1; i <= N; ++i) {
    dp[i] = INFN;
  }
  dp[1] = 0;
  for (int i = 1; i < N; ++i) {
    dp[i+1] = std::min(dp[i] + std::abs(H[i] - H[i+1]), dp[i+1]);
    if (i+2 > N) continue;
    dp[i+2] = std::min(dp[i] + std::abs(H[i] - H[i+2]), dp[i+2]);
  }
  return dp[N];
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
  }
  printf("%d\n", solve());
  return 0;
}

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

using namespace std;

const int N=2e5+5,M=N<<1;

typedef long long LL;

typedef long double db;

int n,a[N],m,H[M],w[N],h[N],e[N],nxt[N],tot,f[N],Id[N],Top,st[N],ff[N],V[N],nn,ii[N];

struct Data
{
	db pd; int l,r,sz,Top;
}A[M],tmp;

LL ans;

bool vis[M];

char c;

int read()
{
	int x=0,sig=1;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}

void Add(int x,int y)
{
	e[++tot]=y; nxt[tot]=h[x]; h[x]=tot; a[y]=x;
}

int Get(int x)
{
	return (f[x]==x)?x:f[x]=Get(f[x]);
}

void Up(int x)
{
	for (;x>1 && A[H[x]].pd>A[H[x>>1]].pd;x>>=1) swap(H[x],H[x>>1]);
}

void Down()
{
	for (int i=1,j;i*2<=m;)
	{
		j=(i*2==m || A[H[i<<1]].pd>A[H[i<<1|1]].pd)?i<<1:i<<1|1;
		if (A[H[i]].pd>A[H[j]].pd) break;
		swap(H[i],H[j]); i=j;
	}
}

int main()
{
	nn=read(); nn++;
	for (int i=3;i<=nn;i++) ff[i]=read()+1; ff[2]=1;
	for (int i=2;i<=nn;i++) V[i]=read(); V[1]=1;
	ii[1]=n=ff[1]=1;
	for (int i=2;i<=nn;i++)
	{
		if (V[i])
		{
			Add(ii[ff[ff[i]]],++n); ff[i]=i; ii[i]=n;
		}else ff[i]=ff[ff[i]],A[ii[ff[i]]].pd++;
	}
	for (int i=1;i<=n;i++)
	{
		A[i].Top=i; A[i].sz=1; H[++m]=i; Up(m);
	}
	memset(vis,0,sizeof(vis));
	for (int i=1;i<=n;i++) f[i]=Id[i]=i;
	tot=n;
	for (int i=1;i<=n;i++)
	{
		int I=H[1]; H[1]=H[m--]; Down();
		for (;vis[I];)
		{
			I=H[1]; H[1]=H[m--]; Down();
		}
		tmp=A[I];
		int j=Get(a[tmp.Top]);
		vis[Id[j]]=1;
		f[tmp.Top]=a[tmp.Top]; tot++;
		A[tot].Top=j; A[tot].l=Id[j]; A[tot].r=I; A[tot].sz=A[Id[j]].sz+tmp.sz;
		A[tot].pd=(A[Id[j]].pd*A[Id[j]].sz+tmp.pd*tmp.sz)/A[tot].sz;
		Id[j]=tot;
		if (j)
		{
			H[++m]=tot; Up(m);
		}
	}
	tot=0;
	for (st[Top=1]=Id[0];Top>0;)
	{
		int x=st[Top];
		if (x<=n)
		{
			tot++; ans+=1ll*tot*A[x].pd; Top--; continue;
		}
		if (!A[x].l)
		{
			if (!A[x].r)
			{
				Top--; continue;
			}
			st[++Top]=A[x].r; A[x].r=0;
		}else
		{
			st[++Top]=A[x].l; A[x].l=0;
		}
	}
	for (int i=2;i<=nn;i++) if (!V[i]) ans--;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23296
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int vist[1000010];
int main(){
  int a,b;
  while(cin>>a>>b){
    a%=b;
    for(int i=0;i<1000010;i++)vist[i]=-1;
    int len=0;
    while(a){
      if(vist[a]==-1)vist[a]=len;
      else break;
      //cout<<"#"<<a<<" ";
      a*=10;
      int tmp=a/b;
      a%=b;
      //cout<<a<<" "<<vist[a]<<" "<<tmp<<endl;
      len++;
      cout<<tmp;
    }
    cout<<endl;
    if(vist[a]==-1)continue;
    for(int i=0;i<len;i++){
      if(i<vist[a])cout<<" ";
      else cout<<"^";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 6984
use proconio::input;

fn main() {
    input! {
        n: u64,
        s: [String; n]
    }

    solve(&s);
}

fn solve(s: &[String]) {
    let mut ac_cnt = 0;
    let mut wa_cnt = 0;
    let mut tle_cnt = 0;
    let mut re_cnt = 0;

    for x in s.iter() {
        match x.as_str() {
            "AC" => ac_cnt += 1,
            "WA" => wa_cnt += 1,
            "TLE" => tle_cnt += 1,
            _ => re_cnt += 1,
        }
    }
    println!("AC x {}", ac_cnt);
    println!("WA x {}", wa_cnt);
    println!("TLE x {}", tle_cnt);
    println!("RE x {}", re_cnt);
}


Measured memory_bytes: 7924
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  if(V<=W){cout<<"NO"<<endl;}
  else{
    ll x=V-W;
    if(x*T>=max(B-A,A-B)){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
  }
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

// https://atcoder.jp/contests/abc167/tasks/abc167_d
var hashMap map[int]int
var history map[int]int
var muraCount int
func main() {

	firstLine := strings.Split(readLine(), " ")
	secondLine := strings.Split(readLine(), " ")

	// line 1 N札 M個 目標値
	// line over 2 値段 アルゴ理解度......
	muraCount, _ = strconv.Atoi(firstLine[0])
	jumpNum, _ := strconv.Atoi(firstLine[1])

	hashMap = make(map[int]int, muraCount)
	history = make(map[int]int, muraCount)
	for i, v := range secondLine {
		n, _ := strconv.Atoi(v)
		hashMap[i+1] = n
	}

	jump(jumpNum, 1, 0)

}

func jump(k int, index int, cnt int) {

	if cnt == k {
		fmt.Println(index)
		os.Exit(0)
	}

	if history[index] != 0 {
		// ループしたことになる 現在 cnt - i 分移動すると また香り高い街に移動する。
		// 残りの移動量は k - cnt となり、 (k-cnt) % (cnt - i) 分移動すれば答えとなる。
		nokori := (k - cnt) % (cnt - history[index])
		history = make(map[int]int, muraCount)
		jump(nokori, index, 0)
	}
	history[index] = cnt

	jump(k, hashMap[index], cnt+1)

}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

#define maxn 500010
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define inf 1e10
#define ll long long
int ans;
char s[maxn];
int read() {
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main() {
	int n=rd;
	fo(i,1,n)
	{
		cin>>s[i];
		if(s[i]!=s[i-1])ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int n, m;
    float a[100], sum = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++){
        if (a[i] >= sum / (4 * m)) count++;
    }
    if (count >= m) cout << "Yes";
    else cout << "No";
    return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    ll x , k , d;
    cin>>x>>k>>d;
    if(x < 0){
        x *= -1;
    }
    ll moves = x / d;
    moves = min(k , moves);
    ll nx = x - (d * moves);
    k -= moves;
    if(k % 2 == 0){
        cout<<nx;
    }else{
        cout<<abs(nx - d);
    }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;



template< typename T >
pair< T, int > tree_dfs(const WG< T > &g, int idx, int par) {
  pair< T, int > ret(0, idx);
  for(auto &e : g[idx]) {
    if(e.to == par) continue;
    auto cost = tree_dfs(g, e.to, idx);
    cost.first += e.cost;
    ret = max(ret, cost);
  }
  return ret;
}

template< typename T >
T tree_diameter(const WG< T > &g) {
  auto p = tree_dfs(g, 0, -1);
  auto q = tree_dfs(g, p.second, -1);
  return (q.first);
}

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

  int n;
  cin>>n;
  WG<int> es(n);
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    es[a].PB(edge<int>(b,c));
    es[b].PB(edge<int>(a,c));
  }

  cout<<tree_diameter(es)<<endl;


}


Measured memory_bytes: 19032
#include<cstdio>
#include<algorithm>
#define MN 300005
using namespace std;
int n,a[MN];
bool check(int l,int r){
	int maxx=0,minx=n;
	for(int i=l;i<=r;i++)maxx=max(maxx,a[i]),minx=min(minx,a[i]);
	if(minx!=l||maxx!=r)return 0;int tmpx=0,tmpy=0;
	for(int i=l;i<=r;i+=2){
		if(a[i]>tmpx)tmpx=a[i];
		else if(a[i]>tmpy)tmpy=a[i];
		else return 0;
	}return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)if((a[i]&1)^(i&1))return 0*puts("No");
	for(int i=1,j;i<=n;i=j+1){
		j=i;
		if(a[i]!=i){
			while(1){
				if(j+2>n||a[j+1]!=j+1||a[j+2]==j+2)break;
				j+=2;
			}
			if(!check(i,j))return 0*puts("No");
		}	
	}puts("Yes");
}


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

int main(){
    long long int n;
    cin>>n;
    long long int d=n,k=26,c=0;
    list<char> l;
    while(d>0){
        d-=k;
        c++;
        k*=26;
    }
    n-= ( ( (26*( pow(26,c-1)-1) )/25 ) + 1 ) ;
    d=1;
    for(int i=c-1;i>=0;i--){
        char ch = (n/d)%26 + 97 ;
        d*=26;
        l.push_front(ch);
    }
    auto it =l.begin();
    while(it!=l.end()){
        cout<<(*it);
        it++;
    }
}

Measured memory_bytes: 4104
n,m = map(int, input().split())

from collections import defaultdict
d = defaultdict(int)
a=1
b=n

def nxt(a,b):
    b-=1
    while True:
        a+=1
        if b-a != n-b+a and d[b-a] != 1 and d[n-b+a] != 1:
            break
    d[b-a]+=1
    d[n-b+a]+=1
    return a,b


for i in range(m):
    print(a,b)
    a,b = nxt(a,b)

Measured memory_bytes: 93104
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
using namespace std;
constexpr int64_t MOD = 1000000007;

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

  int32_t N;
  cin >> N;
  std::string S;
  cin >> S;

  int32_t cnt = 0;
  int idx = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A') {
      idx = 1;
    } else if (idx == 1 && S[i] == 'B') {
      idx = 2;
    } else if (idx == 2 && S[i] == 'C') {
      idx = 0;
      cnt++;
    } else {
      idx = 0;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <deque>
#include <map>
#include <stack>
#include <queue>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <complex>
#include <iterator>

#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define linf ((ll) 1e18)
#define inf ((int) 1e5)
#define eps ((double) 1e-10)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef vector<ll> vl;
typedef vector<pll> vpl;
typedef vector<ppl> vppl;
typedef vector<vl> vvl;
typedef vector<vpl> vvpl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<pdd> vpd;
typedef vector<vd> vvd;
typedef deque<ll> dql;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fors(i, n, s) for (int i = 0; i < (int)(n); i[curPos++] = s)
#define forn1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forn11(i, n) for (int i = 1; i < (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#define prOk(ok) cout << ((ok) ? "VALID\n" : "INVALID\n")
#define in insert
#define rem remove
#define er erase
#define isUpperCase(c) (c <= 'Z' && c >= 'A')


int main()
{
    ll r;
	cin >>r;
	if(r < 1200)
	    cout << "ABC" <<endl;
	else if ( r <2800)
	    cout << "ARC" << endl;
	else
	    cout << "AGC"<<endl;
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	if(s.length() < 3){
		cout << "No" << endl;
		return 0;
	}
	while(s != "ABC"){
		string t = "";
		for(int i = 0;i < s.length() - 2;i++){
			if(s.substr(i,3) == "ABC"){
				for(int j = 0;j < 3;j++) s[i + j] = ' ';
			}
		}
		bool a = false,b = false,c = false;
		for(int i = 0;i < s.length();i++){
			if(s[i] == 'A') a = true;
			else if(s[i] == 'B') b = true;
			else if(s[i] == 'C') c = true;
		}
		char cha = ' ';
		if(a && b) cha = 'C';
		if(b && c) cha = 'A';
		if(c && a) cha = 'B';
		if(cha == ' ' || (a && b && c)){
			cout << "No" << endl;
			return 0;
		}
		for(int i = 0;i < s.length();i++){
			if(s[i] == ' ') {
				t = t + cha;
				i += 2;
			}
			else t = t + s[i];
		}
		if(t == s){
			cout << "No" << endl;
			return 0;
		}
		s = t;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3224
#include <iostream>
using namespace std;
#define MAXL 300000

int main(){
    //char str[MAXL + 1] = "atcoder";
    int n, ans = MAXL;
    char str[MAXL + 1];
    cin >> n;

    int num_e = 0, num_w = 0;
    for(int i = 0; i < n; i++){
        cin >> str[i];
        if(str[i] == 'E'){
            num_e++;
        }else{
            num_w++;
        }
    }
    //cout << num_e << endl;
    //cout << num_w << endl;
    
    int num_w_left = 0, change_left, num_w_right, num_e_right;
    for(int i = 0; i < n; i++){
        if(str[i] == 'W'){
            num_w_left++;
            change_left = (num_w_left == 0)? 0 : num_w_left - 1;
            //num_w_right = num_w - num_w_left;
        }else{
            change_left = num_w_left;
        }
        //int change_left = (num_w_left == 0)? 0 : num_w_left - 1;
        num_w_right = num_w - num_w_left;
        num_e_right = n - i - 1 - num_w_right;
        
        int change_all = change_left + num_e_right;
        if(change_all < ans){
            ans = change_all;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
p = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(m)]

par = [0]
rank = [0]
def init(n):
    for i in range(n):
        par.append(i+1)
        rank.append(0)

def find(x):
    if par[x]==x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x==y:
        return
    elif rank[x]<rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x]+=1

def same(x,y):
    return find(x)==find(y)

init(n)
for i in range(m):
    unite(x[i][0],x[i][1])

ans = 0
for i in range(n):
    if same(i+1,p[i]):
        ans+=1
print(ans)

Measured memory_bytes: 37564
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

const long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> D(N);
    for(int i = 0; i < N; i++){
        int D1, D2;
        cin >> D1 >> D2;
        D.at(i).first = D1;
        D.at(i).second = D2;
    }
    
    for(int i = 0; i < N - 2; i++){
        if(D.at(i).first == D.at(i).second && D.at(i + 1).first == D.at(i + 1).second && D.at(i + 2).first == D.at(i + 2).second){
            cout << "Yes" <<endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3528
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String s = scan.next();
    String t = scan.next();

    String a = "abcdefghijklmnopqrstuvwxyz";

    ArrayList<ArrayList<Integer>> b = new ArrayList<ArrayList<Integer>>();
    ArrayList<ArrayList<Integer>> c = new ArrayList<ArrayList<Integer>>();
    ArrayList<Character> b2 = new ArrayList<Character>();
    ArrayList<Character> c2 = new ArrayList<Character>();


    for (int i=0;i<26;i++){
      ArrayList<Integer> b1 = new ArrayList<Integer>();
      b.add(b1);
      ArrayList<Integer> c1 = new ArrayList<Integer>();
      c.add(c1);
    }

    for (int i=0;i<s.length();i++){
      for (int j=0;j<26;j++){
        if (a.charAt(j) == s.charAt(i)){
          ArrayList<Integer> d = b.get(j);
          d.add(i);
        }

        if (b2.contains(a.charAt(j)) == false){
          b2.add(a.charAt(j));
        }
      }

      for (int j=0;j<26;j++){
        if (a.charAt(j) == t.charAt(i)){
          ArrayList<Integer> e = c.get(j);
          e.add(i);
        }

        if (c2.contains(a.charAt(j)) == false){
          c2.add(a.charAt(j));
        }
      }

    }

    if (b2.size() != c2.size()){
      System.out.println("No");
      return;
    }

    for (int j=0;j<26;j++){
      ArrayList<Integer> m = b.get(j);
      if (m.size() == 0){
        continue;
      }

      char g = t.charAt(m.get(0));
      ArrayList<Integer> what = c.get(g-'a');

      if (what.size() != m.size()){
        System.out.println("No");
        return;
      }
      
      if (m.size() == 1){
        if (what.size() != 1){
          System.out.println("No");
          return;
        }
        continue;
      }
      for (int p : m){
        if (t.charAt(p) != g){
          System.out.println("No");
          return;
        }
      }
    }

    System.out.println("Yes");

  }
}


Measured memory_bytes: 66540
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],n;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(a[1]<a[n]-1)return puts("No"),0;
	if(a[1]==a[n])return puts(a[1]==n-1||n>=(a[1]<<1)?"Yes":"No"),0;
	R int t=1;for(;a[t]==a[t+1];++t);
	puts(a[n]>t&&n>=t+((a[n]-t)<<1)?"Yes":"No");
	return 0;
}

Measured memory_bytes: 640
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;

    vector<pair<int,int>> edges;

    if(n % 2 == 0){
        for(int i = n; i >= 1; i--){
            for(int j = i - 1; j >= 1; j--){
                if(j == (n + 1) - i) continue;
                if(j > i) continue;
                edges.push_back(make_pair(i, j));
            }
        }
    } else {
        for(int i = n - 1; i >= 1; i--){
            edges.push_back(make_pair(n, i));
        }
        for(int i = n - 1; i >= 1; i--){
            for(int j = i - 1; j >= 1; j--){
                if(j == n - i) continue;
                if(j > i) continue;
                edges.push_back(make_pair(i, j));
            }
        }
    }

    cout << edges.size() << endl;
    for(int i = 0; i < edges.size(); i++){
        cout << edges[i].first << " " << edges[i].second << endl;
    }


}

Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! {
        n: usize,
        haba: [(usize, usize); n]
    }

    let (ass,bss): (Vec<usize>,Vec<usize>) = {
        let mut ass = Vec::new();
        let mut bss = Vec::new();
        for &(a,b) in haba.iter() {
            ass.push(a);
            bss.push(b);
        }
        ass.sort_by(|x, y| x.cmp(y));
        bss.sort_by(|x, y| x.cmp(y));
        (ass,bss)
    };

    let ans = {
        if n%2 == 1 {
            bss[n/2]-ass[n/2]+1
        } else {
            (bss[(n-1)/2]+bss[(n-1)/2+1])-(ass[(n-1)/2]+ass[(n-1)/2+1])+1
        }
    };

    println!("{}",ans)
}

Measured memory_bytes: 12908
#include <iostream>
using namespace std;
#include <vector>
#include <utility>
#include <math.h>
#include <climits>
#include <string.h>
#include <algorithm>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <iomanip>

#define loopi(i,n) for(int i=0;i<n;i++)
#define loopi1(i,n) for(int i=1;i<=n;i++)
#define vin vector<int>v(n,0)
#define pi pair<int,int>
#define f first
#define s second
#define lli long long int
#define ll long long
#define li long int
#define MODPRM  1000000009
#define MOD 1000000007



int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

    // Printing the Output to output.txt file
    freopen("output.txt", "w", stdout);

	#endif // ONLINE_JUDGE*/
   int n;
   cin>>n;
   vector<double>x(n),y(n);
   loopi(i,n){
       cin>>x[i]>>y[i];
   }
   int total=(n*(n-1))/2;
   double fact=1;
   loopi1(i,n-1){
   fact=fact*i;
   }
   //vector<double>paths(total);
   double ans=0.0;
   loopi(i,n){
       for(int j=i+1;j<n;j++){
        double distance=sqrt(((x[i]-x[j])*(x[i]-x[j]))+((y[i]-y[j])*(y[i]-y[j])));
        ans=ans+distance*fact;
       }
   }
   ans=ans/(double)(fact*n);
   cout<<fixed;
   cout<<setprecision(7)<<ans*2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
    using namespace std;
     
    int main()
    {
      int a,b,c,x,i,j,k;
      cin >> a >> b >> c >> x;
      int count = 0;
      int total;
      for(i = 0; i <= a; i++)
      {
        for(j = 0; j <= b; j++)
        {
          for(k = 0; k <= c; k++)
          {
            total = 500 * i + 100 * j + 50 * k;
            if(total == x)
            {
              count++;
            }
          }
        }
      }
      cout << count << endl;
      return 0;
    }


Measured memory_bytes: 256
#include <stdio.h>

int N,X,M,m,i;

int main(void)
{
  M = 2147483647;
  scanf("%d %d", &N, &X);
  for(i = 0; i < N; ++i) {
    scanf("%d", &m);
    X -= m;
    if(M>m) M = m;
  }

  while(X-M >= 0) {
    ++N;
    X -= M;
  }
  printf("%d", N);
  
  return 0;
}

Measured memory_bytes: 128
#encoding=utf-8

x = input()
for i in xrange(x):
	num,a,b = [],[0],[0]
	num = map(int, raw_input().split())
	for i in xrange(10):
		if num[i] > a[0]:
			a.insert(0,num[i])
		elif num[i] > b[0]:
			b.insert(0,num[i])
		else:
			pass

	if len(a) + len(b) == 12:
		print "YES"
	else:
		print "NO"

Measured memory_bytes: 6392
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const ll INF = 	922337203685477580;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
ll dp[100010];

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  sort(a,a+n);
  // for(int i = 0; i < n; i++){
  //   cout<<a[i];
  // }
  int l = a[n-1];
  int id = l/2;
  int mx = 1e9;
  int ans = l;
  // cout<<l<<endl;

  for(int i = 0; i < n-1; i++){
    if(abs(id-a[i])<=mx){
      ans = a[i];
      mx = abs(id-a[i]);
      // cout<<a[i]<<" "<<mx<<" "<<abs(id-a[i])<<endl;
    }
  }
  cout<<l<<" "<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    ll N;
    cin >> N;
    int K = 5;
    vector<ll> vec(K);
    REP(i, K) cin >> vec[i];
   
    sort(vec.begin(), vec.end());
    ll minValue = vec[0];
    ll ans = ceil(((double)N / minValue)) + 4;
    print(ans);
}

int main() {

    solve();
    return 0;
}

Measured memory_bytes: 256
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def check():
    N, M = map(int, input().split())
    S = input()
    T = input()
    length = lcm(N,M)
        
    for i in [a*(length//N) for a in range(N)]:
        if i%(length//M)==0:
            if S[i//(length//N)] != T[i//(length//M)]:
                return -1
    return length
  
print(check())

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i = a; i < b; ++i)
#define rep_(i,a,b) for (ll i = a; i > b; --i)
#define endl '\n'
const ll mod = 1e9 + 7;

const ll maxn = 1e5;

ll n, x, t;

// #include "debug.h"
void solve() {
	cin >> n >> x >> t;
	cout << (((n + x - 1)/x) * t) << endl;
}

void aux() {
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout<<fixed<<setprecision(10);
	aux();
	ll _ = 1;
	// cin>>_;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3604
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
	fastio();
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int mi=inf;
	mi=min(mi,a*x+b*y);
	if(x>y)
	{
		swap(x,y);
		swap(a,b);
	}
	mi=min(mi,2*c*y);
	mi=min(mi,2*c*x+(y-x)*b);
	cout<<mi<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 998244353;
const int maxn = 3e5 + 5;
ll fact[maxn], rev_fact[maxn];

ll rev(ll a, ll m = MOD) {
    if (a == 1) {
        return 1;
    }
    return (1 - rev(m % a, a) * m) / a + m;
}

void pre_calc(int n) {
    fact[0] = rev_fact[0] = fact[1] = rev_fact[1] = 1;
    for (ll i = 2; i <= n; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD;
        rev_fact[i] = rev(fact[i]);
    }
}

ll get_c(ll n, ll k) {
    //cerr << fact[n] << ' ' << rev_fact[k] << ' ' << rev_fact[n - k] << '\n';
    return (((fact[n] * rev_fact[k]) % MOD) * rev_fact[n - k]) % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    pre_calc(n);
    // for (int i = 0; i <= n; i++) {
        // cout << fact[i] << ' ' << rev_fact[i] << '\n';
    // }
    ll ans = 0;
    for (ll x = 0; x <= n; ++x) {
        ll need = k - a * x;
        if (need < 0 || need % b != 0) {
            continue;
        }
        ll y = need / b;
        if (y > n) {
            continue;
        }
        //cout << get_c(n, x) << ' ' << get_c(n, y) << '\n';
        ans = (ans + get_c(n, x) *  get_c(n, y)) % MOD;
    }
    cout << ans << '\n';

}

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

int main(void){
    int a,b;int s[3];
    cin >> a >> b;
    s[0] = a+b;
    s[1] = a-b;
    s[2] = a*b;
    sort(s,s+3,greater<int>());
    cout << s[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll num[11]={0,2,5,5,4,5,6,3,7,6};
string dp[11111];
bool str_compare(string s,string ss){
  if(s.size()==ss.size()){
    for(int i=0;i<s.size();i++){
      if(s[i]<ss[i]){
	return true;
      }else if(s[i]>ss[i])
	return false;
    }
    return false;
  }else return s.size()<ss.size();
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  vi A(m);
  for(int i=0;i<11111;i++)dp[i]="";
  dp[0]='0';
  for(auto &a:A)cin>>a;
  for(int i=0;i<n+10;i++){
    for(auto a:A){
      if(dp[i].size()>0){
      string s=dp[i];
      s+=(char)('0'+a);
      if(str_compare(dp[i+num[a]],s)){
	dp[i+num[a]]=s;
      }
      }
    }
  }
  for(int i=1;i<dp[n].size();i++)cout<<dp[n][i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 45696
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
 int n,m;
  cin >> n >> m;
 long long int ans=0;
  vector<pair<long long int,long long int> > pairs(n);
  for(int i=0;i<n;i++){
    cin >> pairs.at(i).first >> pairs.at(i).second;
  }
  sort(pairs.begin(), pairs.end());
  for(int i=0;i<n;i++){
    ans=ans+pairs.at(i).first*pairs.at(i).second;
    m=m-pairs.at(i).second;
    if(m<=0){
      ans=ans+pairs.at(i).first*m;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import numpy as np
from collections import defaultdict

s = list(map(int, input().split()))
n=s[0]
a = np.array(list(map(int, input().split())))
s = list(map(int, input().split()))
q=s[0]
num=defaultdict(int)
ans=0

for i in a:
    num[i]+=1
    ans+=i

for i in range(q):
    s = list(map(int, input().split()))
    a=s[0]
    b=s[1]
    ans=ans-a*num[a]-b*num[b]
    num[b]=num[a]+num[b]
    ans = ans+b*num[b]
    num[a]=0
    print(ans)  


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


int n;
long long a[200];


bool check_even()
{
  bool flag=true;

  for ( int i=0; i<n; i++ ) {
    if ( a[i]%2 == 1 ) {
      flag=false;
      break;
    }
    a[i] = a[i]/2;
  }
  return flag;
}


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

  int cnt=0;
  bool flag;
  while ( true ) {
    flag = check_even();
    if ( !flag ) break;
    cnt++;
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256