akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int int_sort (const void *a, const void *b)
{
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main()
{
   int A,B;
   scanf("%d %d", &A, &B);

   int N[3] = {A+B, A-B, A*B};

   qsort(N, 3, sizeof(int), int_sort);
   printf("%d\n", N[2]);

   return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVI = vector<VI>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 2e5 + 5;
const LL MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

VLL fac, invfac;

LL pow2(LL a, LL b)
{
    LL res = 1;
    while (b)
    {
        if ((b & 1) != 0)
        {
            res = (res * a) % MOD;
        }
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

void init(int n)
{
    fac.resize(n + 1);
    invfac.resize(n + 1);
    fac[0] = 1;
    FOR(i, 1, n + 1) { fac[i] = (fac[i - 1] * i) % MOD;}
    invfac[n] = pow2(fac[n], MOD - 2);
    FORD(i, n - 1, 0 - 1) { invfac[i] = (invfac[i + 1] * (i + 1)) % MOD;}
}

int n;
VVI G;
VLL dp, sz, ans;

LL C(int m, int n) { return (fac[m] * invfac[n]) % MOD * invfac[m - n] % MOD; }

void dfs1(int u, int p)
{
    for (int v : G[u])
    {
        if (v == p)
        {
            continue;
        }
        dfs1(v, u);
        sz[u] += sz[v];
        dp[u] = (dp[u] * dp[v] % MOD) * C(sz[u] - 1, sz[v]) % MOD;
    }
}

void dfs2(int u, int p)
{
    for (int v : G[u])
    {
        if (v == p)
        {
            continue;
        }
        ans[v] = ans[u] * pow2(C(n - 1, sz[v]) * dp[v] % MOD, MOD - 2) % MOD;
        ans[v] =
            (ans[v] * dp[v] % MOD) * C(n - 1, n - sz[v]) % MOD;
        dfs2(v, u);
    }
}

int main()
{
    IOS;
    cin >> n;
    G.resize(n + 5);
    dp.resize(n + 5, 1);
    sz.resize(n + 5, 1);
    ans.resize(n + 5);
    init(n);
    FOR(i, 0, n - 1)
    {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(1, -1);
    // FOR(i, 1, n + 1) { cout << dp[i] << '\n'; }
    ans[1] = dp[1];
    dfs2(1, -1);
    FOR(i, 1, n + 1) { cout << ans[i] << '\n'; }
}


Measured memory_bytes: 21748
/*
main is for program 2-1 of AOJ
*/
package main

import (
	"fmt"
	"strconv"
)

func calcHour(sec int) (hour, res int) {
	h := sec / (60 * 60)
	r := sec % (60 * 60)
	return h, r
}

func calcMinute(sec int) (minute, res int) {
	m := sec / 60
	r := sec % 60
	return m, r
}

func main() {

	var in string

	fmt.Scan(&in)
	i, _ := strconv.Atoi(in)

	h, res := calcHour(i)
	m, s := calcMinute(res)

	fmt.Printf("%v:%v:%v\n", h, m, s)
}



Measured memory_bytes: 1120
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
     mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
    ll n,k;
    cin>>n>>k;
    mint ans=0;
    V<mint> memo(k+1,0); 
    for( ll i=k;i>=1;i--){
       ll d=k/i;
       mint res=mint(d).pow(n);
       for(ll j=2;i*j<=k;j++)res-=memo[i*j];
       memo[i]=res;
       ans+=res*mint(i);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 50968
n=int(input())
a=list(map(int,input().split()))

d={}
for i in range(1,n+1):
    d[i]=a[i-1]
# print(d)
A_sorted = sorted(d.items(), key=lambda x:x[1])

print(*list(A_sorted[i][0] for i in range(n)))


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

int main(void){

    int N;
    cin>>N;
    int A[N],B[N];
    int MAX=0;
    int tmp;
    for(int i=0;i<N;i++){
        cin>>tmp;
        A[i]=tmp;
        B[i]=tmp;
        MAX=max(tmp, MAX);
    }

    sort(B,B+N,greater<>());

    for(int i=0;i<N;i++){
        if(A[i]==MAX){
            cout<<B[1]<<endl;
        }else{
            cout<<MAX<<endl;
        }
    }

    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    os << pai.first << ' ' << pai.second;
	return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

char str[100001];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    int a = 0, b = 0;
    rep(i, strlen(str)) {
        a += (str[i] == '0');
        b += (str[i] == '1');
    }
    cout << min(a,b)*2;
}   




Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String[] s = sc.next().split(",");
			int[] l = new int[10];
			int sum = 0;
			for(int i = 0; i < 10; i++) {
				l[i] = Integer.parseInt(s[i]);
				sum += l[i];
			}
			int[]seg = new int[sum + 1];
			int idx = 0;
			int k = l[0];
			for(int i = 0; i <= sum; i++) {
				if(i <= k) {
					seg[i] = idx;
				}else {
					idx++;
					k += l[idx];
					seg[i] = idx;
				}
			}
			double v1 = Double.parseDouble(s[10]);
			double v2 = Double.parseDouble(s[11]);
			double h = (double)(sum * v1 )/ (v1 + v2);
			int id = (int)Math.ceil(h);
			System.out.println(seg[id] + 1);
		}

	}
}


Measured memory_bytes: 26188
#C - Dice and Coin(ABC126)
N,K=map(int, input().split())
ans=0
m=0
for i in range(1,N+1):
    if i<=K:
        m=0
        n=i*(2**m)
        while n<K:
            m+=1
            n=i*(2**m)
        ans+=(1/(N*(2**m)))
    else:
        ans+=(N-K)/N
        break
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    int n,flag=0;
    cin>>n;
    for(int i=1;i<10;i++){
        if(n%i==0&&n/i<10){
            flag=1;
        }else{

        }
    }
    if(flag==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9

int main()
{
    fastio;
    int n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int>v(n);
    for(int i=n-1;i>-1;i--)
    {
        if(s[i]=='x')
        {
            if(i==n-1)
                v[i]=0;
            else
                v[i]=v[i+1];
        }
        else
        {
            if(i==n-1)
                v[i]=1;
            else
            {
                int ind=i+c+1,t=0;
                if(ind<n)
                    t=v[ind];
                v[i]=max(v[i+1],t+1);
            }
        }   
    }
    // for(int i=0;i<n;i++)
    //     cout << v[i] << " ";
    // cout << endl;
    int f=0;
    vector<int>v1=v;
    sort(v1.begin(),v1.end(),greater<int>());
    if(v1[0]!=k)
        f=1;
    if(f==0)
    {
        map<int,vector<int> >m;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='o')
                m[v[i]].push_back(i);
        }
        int  p=0;
        vector<int>ans;
        for(int i=k;i>0;i--)
        {
            int ind=lower_bound(m[i].begin(),m[i].end(),p)-m[i].begin();
            int ne=m[i].size()-ind;
            if(ne==1)
                ans.push_back(m[i][ind]);
            p=m[i][ind]+c+1;
        }
        //cout << ans.size() << endl;
        sort(ans.begin(),ans.end());
        for(int i=0;i<ans.size();i++)
            cout << ans[i]+1 << endl;
    }
}

Measured memory_bytes: 26124
#include <iostream>

int n;

bool get_input()
{
//	std::cout << "get_input" << std::endl;
	return (std::cin >> n);
}

// no_use: Â©¦éÌÂ
int solve(int sum, int no_use)
{
//	std::cout << "solve " << "sum: " << sum << "no_use: " << no_use << std::endl;
	if (no_use == 1) {
		if (0 <= sum && sum <= 9) {
			return 1;
		} else {
			return 0;
		}
	} else {
		int ans = 0;
		for (int i = 9; i >= 0; i--) {
			if (sum < i) continue;
			ans += solve(sum - i, no_use - 1);
		}
		return ans;
	}
}

void output(int ans)
{
	std::cout << ans << std::endl;
}

int main(void)
{
	while (get_input()) {
		output(solve(n, 4));
	}
	return 0;
}

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

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

	if(n%500 <= a) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            dd = sum([(x[i][k] - x[j][k]) ** 2 for k in range(d)])
            if dd == int(dd ** 0.5) ** 2:
                ans += 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
#include <stdio.h>
 
#define N 100000

typedef struct C{
    char pic;
    int num;
    int id;
}card;
 
int part(card arr[], int p, int r){
    int x, i, j;
    card tmp;
    x = arr[r].num;
    i = p-1;
     
    for(j = p; j < r; j++) {
        if(arr[j].num <= x) {
            i++;
            tmp = arr[i];
	    arr[i] = arr[j];
	    arr[j] = tmp;
        } 
    }
    tmp = arr[i+1];
    arr[i+1] = arr[r];
    arr[r] = tmp;
    return i + 1;
}
 
void quick(card arr[], int P, int R){
    int Q;
    if(P < R) {
        Q = part(arr, P, R);
        quick(arr, P, Q - 1);
        quick(arr, Q + 1, R);
    }
}
 
int isSta(card arr[], int n){
    int i;
    for(i=1; i<n; i++) {
        if(arr[i-1].num == arr[i].num) {
            if(arr[i - 1].id > arr[i].id) return 0;
        }
    }
    return 1;
}
 
int main(int argc,char *argv[]){
    int i, n;
    card arr[N];
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf(" %c %d", &arr[i].pic, &arr[i].num);
        arr[i].id=i;
    }
    quick(arr, 0, n-1);
 
    if(isSta(arr, n)) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++) {
        printf("%c %d\n", arr[i].pic, arr[i].num);
    }
    return 0;
}

Measured memory_bytes: 1780
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))


//遅延セグ木ここから

//↓ここを変える
typedef struct sayouso{ll k;}sayouso;
typedef struct atai{ll a;}atai;
//↑ここを変える
typedef struct node{sayouso T;atai x;}node;

node lsegN[1<<18],*lseg;
ll lsegNUM,lsegk;

//↓ここから変える
sayouso id={0};
atai xx(atai x,atai y){
	atai ret;
	ret.a=x.a+y.a;
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.a=T.k+x.a;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.k=S.k+T.k;
	return ret;
}
sayouso fT(sayouso T,ll k){
	sayouso ret;
	ret.k=T.k<<k;
	return ret;
}
//↑ここまで変える

void lseguse(ll n){
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	lsegk=0;while(n/=2)lsegk++;
}
void lseginit(){
	for(ll i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
	rep(i,1,2*lsegNUM)lsegN[i].T=id;
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr,ll ck){
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm,ck-1);
	lsegupdatesub(l,r,T,2*i+1,cm,cr,ck-1);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(fT(lsegN[2*i].T,ck-1),lsegN[2*i].x),Tx(fT(lsegN[2*i+1].T,ck-1),lsegN[2*i+1].x));
	lsegN[i].T=id;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM,lsegk);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr,ll ck){
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(fT(lsegN[i].T,ck),lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(fT(lsegN[i].T,ck),lsegN[i].x);
	lsegN[i].T=id;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm,ck-1);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr,ck-1);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm,ck-1),lsegcalcsub(l,r,2*i+1,cm,cr,ck-1));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM,lsegk);}

//遅延セグ木ここまで


typedef struct interval{ll l,r;}I;
int hikaku(const void*p,const void*q){
	I pp=*(I*)p,qq=*(I*)q;
	ll pplen=pp.r-pp.l,qqlen=qq.r-qq.l;
	return pplen<qqlen?-1:pplen>qqlen?1:0;
}

I kukan[300010];

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
 
	rep(i,0,n){
		int l,r;
		scanf("%d%d",&l,&r);
		kukan[i].l=l;
		kukan[i].r=r+1;
	}
	qsort(kukan,n,sizeof(I),hikaku);
	
 	lseguse(1<<17);
	ll icnt=0;//seg木に投げた区間の個数
	sayouso T={1};
	rep(k,1,m+1){
		while(icnt<n&&kukan[icnt].r-kukan[icnt].l<k){
			//長さk未満の区間をseg木に追加
			lsegupdate(kukan[icnt].l,kukan[icnt].r,T);
			icnt++;
		}
		ll ans=n-icnt;
		//(n-icnt)個の区間は、長さがk以上なので必ず回収できる
		//残りのicnt個の区間は、長さがk未満なので高々1度しか訪問しないため、各駅をチェックすれば良い
		repp(x,k,m+1,k)ans+=lsegcalc(x,x+1).a;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 11004
class UnionFind:
    def __init__(self, n):
        self.root = list(range(n + 1))
        self.size = [1] * (n + 1)

    def find(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        sx, sy = self.size[x], self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy


n, m = map(int, input().split())
p = list(map(int, input().split()))


uf = UnionFind(n)
union = uf.union
find = uf.find


for _ in range(m):
    x, y = map(int, input().split())
    union(x - 1, y - 1)

ans = 0
for i, x in enumerate(p):
    if find(i) == find(x - 1):
        ans += 1

print(ans)

Measured memory_bytes: 13812
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int q[10]={1,1,1,2,1,1,1,2,2,3};
int w[10]={2,2,3,3,2,3,4,3,4,4};
int e[10]={3,4,4,4,5,5,5,5,5,5};
int main(){
  ll n;
  cin>>n;
  vstr s(n);
  vll a(5);
  rep(i,n){
    cin>>s[i];
    if(s[i][0]=='M') a[0]++;
    if(s[i][0]=='A') a[1]++;
    if(s[i][0]=='R') a[2]++;
    if(s[i][0]=='C') a[3]++;
    if(s[i][0]=='H') a[4]++;
  }
  ll cu=0;
  rep(i,5){
    if(a[i]!=0) cu++;
  }
  sort(rall(a));
  if(cu<3) COUT(0);
  else if(cu==3){
    COUT(a[0]*a[1]*a[2]);
  }
  else if(cu==4){
    ll ans=0;
    rep(i,4){
      ans+=a[q[i]-1]*a[w[i]-1]*a[e[i]-1];
    }
    COUT(ans);
  }
  else{
    ll ans=0;
    rep(i,10){
      ans+=a[q[i]-1]*a[w[i]-1]*a[e[i]-1];
    }
    COUT(ans);
  }

}
  

Measured memory_bytes: 6652
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    int N;
    cin>>N;
    int t[100010],x[100010],y[100010],dt[100010],dx[100010],dy[100010];
    
    cin>>t[0]>>x[0]>>y[0];
    if((t[0]+x[0]+y[0])%2==0&&(abs(x[0])+abs(y[0]))<=t[0]){
       for(int i=1;i<N;++i){
           cin>>t[i]>>x[i]>>y[i];
           dt[i-1]=t[i]-t[i-1];
           dx[i-1]=x[i]-x[i-1];
           dy[i-1]=y[i]-y[i-1];
           if((dt[i-1]+dx[i-1]+dy[i-1])%2!=0||(abs(dx[i-1])+abs(dy[i-1]))>dt[i-1]){
               cout<<"No"<<endl;
               goto lol;
           }
        }
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

    lol:
    return 0;
}

Measured memory_bytes: 1408
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

fn main() {
    let l: i64 = input();

    let mut e = vec![];
    g(l, &mut e);

    with_stdout_lock(|mut w| {
        let n = e.len() + 1;
        let m: usize = e.iter().map(|e| e.len()).sum();
        writeln!(w, "{} {}", n, m).unwrap();
        for u in 0..n - 1 {
            for &(v, d) in &e[u] {
                writeln!(w, "{} {} {}", u + 1, v + 1, d).unwrap();
            }
        }
    });
}

fn g(l: i64, e: &mut Vec<Vec<(usize, i64)>>) {
    if l == 2 {
        e.push(vec![(1, 0), (1, 1)]);
    } else if l % 2 == 0 {
        g(l / 2, e);
        for u in 0..e.len() {
            for v in 0..e[u].len() {
                e[u][v].1 *= 2;
            }
        }
        let n = e.len();
        e.push(vec![(n + 1, 0), (n + 1, 1)]);
    } else {
        g(l - 1, e);
        let n = e.len();
        e[0].push((n, l - 1));
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
typedef long long ll;

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

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

int main(){
  ll n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  ll num = lcm(n, m);
  ll a = num/m;
  ll b = num/n;
  ll cntA = 0;
  ll cntB = 0;
  bool isok = true;
  while(cntA < n){
    if(s[cntA] != t[cntB]){
      isok = false;
      break;
    }
    cntA += a;
    cntB += b;
  }
  if(isok) cout << num << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3712
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut a: Vec<i32> = line
        .split_whitespace()
        .map(|n| n.parse::<i32>().unwrap())
        .collect();
    a.sort();
    if a[0] == 5 && a[1] == 5 && a[2] == 7 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
struct Line{
	int id,x,y,z;
};
int n,m;
Line l[50010];
int ls[510],f[510],cnt,anss,ansc,mint;
int min(int a,int b){
	return a<b?a:b;
}
int F(int z){
	if(f[z]!=z)f[z]=F(f[z]);
	return f[z];
}
void init_f(){
	for(int i=0;i<=n;i++)
		f[i]=i;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		l[i].id=i;
		scanf("%d%d%d",&l[i].x,&l[i].y,&l[i].z);
	}
	sort(l, l + m, [](Line a, Line b){ return a.z < b.z; });
	init_f();
	cnt=0,mint=0;
	for(int p=0;cnt<n-1;){
		for(;F(l[p].x)==F(l[p].y);p++);
		mint+=l[p].z;
		f[F(l[p].x)]=F(l[p].y);
		ls[cnt++]=p;
	}
	for(int i=0;i<n-1;i++){
		init_f();
		int t=0,p=0;
		for(cnt=0;cnt<n-1;){
			for(;(p<m)&&(p==ls[i]||F(l[p].x)==F(l[p].y));p++);
			if(p==m){
				t=mint+1;
				break;
			}
			t+=l[p].z;
			f[F(l[p].x)]=F(l[p].y);
			cnt++;
		}
		if(mint<t){
			anss++;
			ansc+=l[ls[i]].z;
		}
	}
	printf("%d %d\n",anss,ansc);
}

Measured memory_bytes: 3972
#include<stdio.h>
int main(void)
{
  int a,x,y,z,i;

  scanf("%d",&x);

  scanf("%d",&a);
  if(x>a)
    y=a;
  else
    {y=x;x=a;}

  scanf("%d",&a);
  if(x<a)
    {z=y;y=x;x=a;}
  else if(y<a)
    {z=y;y=a;}
  else
    z=a;

  for (i=0;i<7;i++)
    {
     scanf("%d",&a);
     if(x<a)
      {z=y;y=x;x=a;}
     else if(y<a)
      {z=y;y=a;}
     else if(z<a)
       z=a;
    }
  printf("%d\n%d\n%d\n",x,y,z);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using namespace atcoder;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int N,D;cin >> N >> D;
    vector<int> X(N),Y(N);
    rep(i,N) cin >> X[i] >> Y[i];

    two_sat ts(2*N);
    rep(i,N) {
        ts.add_clause(i,true,i + N,true);
        ts.add_clause(i,false,i + N,false);
    }
    rep(i,N) {
        for (int j = i + 1;j < N; ++j) {
            if (abs(X[i] - X[j]) < D) {
                ts.add_clause(i + N,true,j + N,true);
            }
            if (abs(X[i] - Y[j]) < D) {
                ts.add_clause(i + N,true,j,true);
            }
            if (abs(Y[i] - X[j]) < D) {
                ts.add_clause(i,true,j + N,true);
            }
            if (abs(Y[i] - Y[j]) < D) {
                ts.add_clause(i,true,j,true);
            }
        }
    }
    if (!ts.satisfiable()) {
        cout << "No" << '\n';
        return 0;
    }
    auto ans = ts.answer();
    cout << "Yes" << '\n';
    rep(i,N) {
        cout << (ans[i] ? X[i]:Y[i]) << '\n';
    }
    return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(n,vector<int>());
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    for(auto s : v[n-1]){
        for(auto t : v[s]){
            if(t==0){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 14908
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long int

// 注目するスイッチを１とし、そうでないスイッチを０として、２進数と捉えた時にi番目の状態での点灯しているスイッチの数
// 入力：ターゲットスイッチ状態の番号、スイッチの状態を格納
// 出力：オンになっているスイッチの数

int numLight(int i, std::set<int>& s) {
  int counter = 0;
  /* BOURYOKU HANTAI
  for (auto it = s.begin(); it != s.end(); ++it) {
    if ((1 << (*it)) && i) {
      counter++;
    }
  }
  */
  int digit = 0;
  while(i > 0) {
    if(i % 2 == 1 && s.count(digit)) {
      counter++;
    }
    i /= 2;
    digit++;
  }
  return counter;
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::set<int> > v(m);
  std::vector<int> p;
  for(int i=0; i<m; i++) {
    int k;
    std::cin >> k;
    for(int j=0; j<k; j++) {
      int sk;
      std::cin >> sk;
      v[i].insert(sk - 1);
    }
  }
  for(int i=0; i<m; i++) {
    int pk;
    std::cin >> pk;
    p.push_back(pk);
  }
  // finish initialization
  int cnt=0;
  for(int i=0; i<(1 << n); i++) { // 2^10
    bool flag=false;
    for(int j=0; j<m; j++) {
      if(numLight(i, v[j])%2 != p[j]) flag=true;
    }
    if(flag == false) {
      cnt++;
    }
  }
  std::cout << cnt << std::endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back


int main(void){
  int n, m, p;
  while(cin >> n >> m >> p, n+m+p){
    int sum = 0;
    int x[128];
    m--;
    rep(i,n){
      cin >> x[i];
      sum += x[i];
    }
    sum*=(100-p);
    if( x[m] == 0){
      cout << 0 << endl;
    }else{
      cout << sum/x[m] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2996
import java.util.*;

public class Main{

		public static boolean[][] isPath;
		public static boolean[] visited;
		public static int ans = 0;
		public static int n;
		public static int m;

	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		
		//N頂点M辺
		n = scan.nextInt();
		m = scan.nextInt();
		

		//頂点カウント
		visited = new boolean[n];

		//組み合わせ格納
		isPath = new boolean[n][n];
		for(int i=0; i<m; i++){
			int a = scan.nextInt();
			int b = scan.nextInt();
			isPath[a-1][b-1] = true;
			isPath[b-1][a-1] = true; 
		}

		//最初の1は訪問済み
		visited[0] = true;

		dfs(0);

		System.out.println(ans);
		//dfsメソッド

		
	}
	public static void dfs(int v){
			
			//すべての頂点を訪問済みならans++
			int t = 0;
			for(int i=0; i<n; i++){
				if(visited[i]==true){t++;}
			}
			if(t==n){ans++; return;}

			for(int i=0; i<n; i++){
				//隣接してるならtrue 未訪問ならfalse
				if(!(isPath[v][i]==true && visited[i]==false)){continue;}
				visited[i] = true;
				dfs(i);
				visited[i] = false;
			}
		}
}



Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int max = -2147483648;
		Scanner san = new Scanner(System.in);
		int listCount = san.nextInt();
		int[] list = new int[listCount];
		for(int i = 0; i < listCount; i++){
			list[i] = san.nextInt();
		}
		int min = list[0];
		for(int i = 1; i < listCount; i++){
			max = Math.max(max, list[i] - min);
			min = Math.min(min, list[i]);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 96476
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, LL> Vec2;
#define Vec2
LL h, w, n, m, s, ans = 0, num = 1, sum = 0, a[10], b[10];
string str,stt;
int main() {
	for (int i = 0; i < 7; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	s += (LL)(a[0] / 2) * 4;
	a[0] %= 2;
	s += a[1] * 2;
	s += (LL)(a[3] / 2) * 4;
	s += (LL)(a[4] / 2) * 4;
	a[3] %= 2;
	a[4] %= 2;
	if (a[0] && a[3] && a[4])
		s += 6;

	if (b[0] && b[3] && b[4]) {
		b[0] -= 1;
		b[3] -= 1;
		b[4] -= 1;
		ans += 6;
	}
	ans += (LL)(b[0] / 2) * 4;
	b[0] %= 2;
	ans += a[1] * 2;
	ans += (LL)(b[3] / 2) * 4;
	ans += (LL)(b[4] / 2) * 4;
	b[3] %= 2;
	b[4] %= 2;
	
	cout << max(s,ans) / 2 << endl;
	return 0;
}


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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

signed main()
{
	string a, b, c;
	cin >> a >> b >> c;
	char x = 'A' - 'a';
	cout << (char) (a[0] + x) << (char) (b[0] + x) << (char) (c[0] + x) << endl;
}



Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,n,ans[105][105]={},a[10005]={},now=1;
  cin >> h >> w >> n;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(i%2==0) {
        ans[i][j]=now;
        a[now]--;
        if(!a[now]) {
          now++;
        }
      }
      else {
        ans[i][w-j-1]=now;
        a[now]--;
        if(!a[now]) {
          now++;
        }
      }
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nml = readln.split.to!(int[]);
    auto N = nml[0];
    auto M = nml[1];
    long L = nml[2];

    auto G = new long[][](N, N);
    foreach (ref g; G) foreach (ref e; g) e = long.max / 3;
    foreach (_; 0..M) {
        auto abc = readln.split.to!(int[]);
        auto A = abc[0]-1;
        auto B = abc[1]-1;
        long C = abc[2];
        if (C > L) continue;
        G[A][B] = C;
        G[B][A] = C;
    }

    foreach (k; 0..N) {
        foreach (i; 0..N) {
            foreach (j; 0..N) {
                if (G[i][j] > G[i][k] + G[k][j])
                    G[i][j] = G[i][k] + G[k][j];
            }
        }
    }

    auto H = new long[][](N, N);
    foreach (i; 0..N) {
        foreach (j; 0..N) {
            H[i][j] = G[i][j] <= L ? 1 : long.max / 3;
        }
    }

    foreach (k; 0..N) {
        foreach (i; 0..N) {
            foreach (j; 0..N) {
                if (H[i][j] > H[i][k] + H[k][j])
                    H[i][j] = H[i][k] + H[k][j];
            }
        }
    }

    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto st = readln.split.to!(int[]);
        auto s = st[0]-1;
        auto t = st[1]-1;
        auto r = H[s][t]-1;
        writeln(r > N ? -1 : r);
    }
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<p> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].second >> v[i].first;
  }
  sort(ALL(v));
  ll tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp += v[i].second;
    if(tmp > v[i].first){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[101][100001], inp[101][2], N;

int thunder(int ind, int capacity){
    //Base Case
    if(ind==N){
        return 0; //No more object left
    }
    if(capacity == 0){
        return 0; //Capacity not left
    }
    if(dp[ind][capacity] != -1){
        return dp[ind][capacity];
    }
    int tmpVal = INT_MIN;
    //Current object can be picked
    if(inp[ind][0] <= capacity){
        tmpVal = max(tmpVal, inp[ind][1]+thunder(ind+1, capacity - inp[ind][0]));
    }
    //Not picked current object
    tmpVal = max(tmpVal, thunder(ind+1, capacity));
    return dp[ind][capacity] = tmpVal ;
}

signed main(){
    memset(dp, -1, sizeof(dp));
    int W;
    cin>>N>>W;
    for(int i=0; i<N; i++){
        cin>>inp[i][0]>>inp[i][1];
    }
    cout<<thunder(0, W)<<endl;
    return 0;
}


Measured memory_bytes: 79104
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int T=sc.nextInt();
        int []t=new int[N];
        for(int i=0;i<N;i++){
            t[i]=sc.nextInt();
        }
        int sum=0;
        for(int i=1;i<N;i++){
            if(t[i]-t[i-1]<=T){
                sum=sum+t[i]-t[i-1];
            }else{
                sum=sum+T;
            }

        }
        System.out.println(sum+T);
        
        
    }
        
     
    }


Measured memory_bytes: 62760
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <limits>

using namespace std;

int main()
{
    int N;//,a;
    long long sum[200001];
    sum[0] = 0;
    long long min_num = 2 * 10000000000;//pow(10, 9.0);

    cin >> N;

    for (int i = 1; i <= N; i++) {
        //cin >> a;
        cin >> sum[i];
        sum[i] += sum[i - 1];// + a;
    }
    
    for ( int i = 1; i < N; i++) {
        min_num = min(min_num, abs(sum[N] - (2 * sum[i])));
    }
    cout << min_num << '\n';

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <bitset>

int main() {
    int H, W, K;
    std::cin >> H >> W >> K;
    std::vector<std::vector<int>> vec;
    vec.resize(H);

    for (int i = 0; i < H; ++i) {
        std::string in;
        std::cin >> in;
        for (int j = 0; j < W; ++j) {

            if (in.at(j) == '#')
                vec.at(i).emplace_back(1);

            else
                vec.at(i).emplace_back(0);
        }
   
    }

    int ans = 0;

    for (int i = 0; i < (1 << H); ++i) {
        std::bitset<6> bit_h(i);

        for (int j = 0; j < (1 << W); ++j) {
            std::bitset<6> bit_w(j);
            int count = 0;

            for (int k = 0; k < H; ++k) {
                if (bit_h[k] == 1)
                    continue;
                
                for (int l = 0; l < W; ++l) {
                    if (bit_w[l] == 1)
                        continue;

                    count += vec.at(k).at(l);
                }
            }
            if (count == K)
                ans++;

        }
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int o_pos;
    for( int i = 1; i <= n; ++i ) {
        int a;
        cin >> a;
        if( a == 1 ) o_pos = i;

    }

    int res;
    --k;
    res = ( o_pos - 1 ) / k;
    int md_l = ( o_pos - 1 ) % k;
    res += ( n - o_pos ) / k;
    int md_r = ( n - o_pos ) % k;
    if( md_l + md_r <= k && ( md_l != 0 || md_r != 0 ) ) ++res;
    else if( md_l != 0 && md_r != 0 ) res += 2;
    
    cout << res << endl;

    return 0;
}



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

int main(){
	int n;
	int t[110000], x[110000], y[110000];
	cin>>n;
	t[0] = x[0] = y[0] =0;
	for(int i=0; i<n; i++) cin>>t[i+1]>>x[i+1]>>y[i+1];
	bool can = true;
	for(int i=0; i<n; i++){
		int dt=t[i+1]-t[i];
		int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
		if(dt<dist) can = false;
		if(dist%2!=dt%2) can = false;
	}
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int maxn = 5e3 + 1;
const ll inf = 1e18;
bool vis[maxn];

void solve() {

   ll n, k, ans = -inf;
   cin >> n >> k;
   vector <ll> a(n + 1), c(n + 1);
   for (int i = 1; i <= n; i++)
      cin >> a[i];
   for (int i = 1; i <= n; i++)
      cin >> c[i];

   for (int i = 1; i <= n; i++) {
      memset(vis, false, sizeof(vis));
      vector <ll> p;
      p.push_back(0ll);
      int x = i;
      while (!vis[x]) {
         vis[x] = true;
         p.push_back(c[x]);
         x = a[x];
      }
      ll m = p.size() - 1;
      for (int i = 1; i <= m; i++) {
         p[i] += p[i - 1];
      }
      for (int i = 1; i <= m; i++) {
         ll rem = k - i;
         if (rem < 0)
            break;
         ans = max({ans, p[i] + p[m] * (rem / m), p[i]});
      }
   }
   cout << ans << '\n';

}

int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);

   solve();

   return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	string s;
	cin >> a >> s;
	if(a%2==1)
	cout << "No" << endl;
	else{
		int fg=0;
		int len=s.size();
		for(int i=0;i<len/2;i++){
			if(s[i]!=s[i+len/2]){
				fg=1;
				break;
			}
		}
		if(fg)
		cout << "No" << endl;
		else
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
#define X first
#define Y second
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

int main(){
	int n;
	while(cin >> n , n){
		map< int,pair<int,int> > data;
		data[0] = make_pair(0,0);
		
		int a=0,b=0,c=0,d=0;
		
		rep(i,n-1){
			int id,di;
			cin >> id >> di;
			int x = data[id].X + dx[di];
			int y = data[id].Y + dy[di];
			
			a = min(x,a) , b = max(x,b);
			c = min(y,c) , d = max(y,d);
			
			data[i+1] = make_pair(x,y);
		}
		cout << b-a+1 << " " << d-c+1 << endl;
	}
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    int T=1;
    //cin >> T;
    while(T--){
        ll n;
        cin>>n;
        ll a[n];
        ll sum=0;
        rep(i,n){
            cin>>a[i];
        }
        sort(a,a+n, greater<ll>());
        sum=a[0];
        int cnt=n-2;
        ll j=2;
        while(cnt){
            sum+=a[(j/2)];
            j++;
            cnt--;
        }
        cout<<sum<<el;
       
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 5368
#include <stdio.h>
#include <stdint.h>
#include <set>

int N, C, K;

std::multiset <int, std::less <int> > list;

int main(){
  scanf("%d %d %d", &N, &C, &K);
  for(int i = 0; i < N; i++){
    int tmp;
    scanf(" %d", &tmp);
    list.insert(tmp);
  }
  int count = 0;
  int c = 0;
  int time_limit = *list.begin();
  for (auto& value : list) {
  //for(int i = 0; i < list_used; i++) {
    if(time_limit < value){
      count++;
      c = 0;
    }
    if(c == C) {
      count++;
      c = 0;
    }
    if(!c){
    	time_limit = value + K;
    }
    c++;
    //printf("%d %d %d\n", value, c, count);
  }
  if(c) count++;
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 4864
def main():
    A, B = map(int, input().split())
    for i in range(1, 2000):
        tmp_A = int(i * 0.08)
        tmp_B = int(i * 0.10)
        if tmp_A == A and tmp_B == B:
            print(i)
            exit()

    print(-1)



if __name__ == "__main__":
    main()

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

    string x = "keyence";

    if(s == x) {
        out("YES");
        re0;
    }

    if(s.substr(0, 7) == x) {
        out("YES");
        re0;
    }

    if(s.substr(n-7, 7) == x) {
        out("YES");
        re0;
    }

    exrep(j, 1, n-2) {
        exrep(k, 1, min((n-1)-j, n-7)) {
            string mae = s.substr(0, j);
            string ushiro = s.substr(j+k, n -(j+k));
            if(mae + ushiro == x) {
                out("YES");
                re0;
            }
        }
    }
    
    out("NO");    
    re0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    int c = b - a;
    if(c <= 0){
        printf("delicious\n");
    }
    else if(c > x)
    {
        printf("dangerous\n");
    }
    else 
    {
        printf("safe\n");
    }
    
    
}

Measured memory_bytes: 128
ans=[]

while True:

	try:

		k=int(input())

		ct=0

		for i in range(10000):

			tmp=str(i)

			while len(tmp)<4:

				tmp="0"+tmp

			tmp_2=0

			for j in tmp:

				tmp_2+=int(j)

			if tmp_2==k:

				ct+=1

		ans.append(ct)

	except:

		break

for i in range(len(ans)):

	if i==len(ans)-1:

		print(ans[i],)

	else:

		print(ans[i])

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    priority_queue <int, vector<int>, greater<int>>  pq;
    priority_queue <int>  pq2;
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<3*n;i++){
        int k;
        cin>>k;
        v.pb(k);
    }
    map<int,ii> score;
    for(int i=n-1;i<2*n;i++){
        score[i]=mp(0,0);
    }
    // score[i]= take until ith for first half i+1th onwards for second half
    ll l=0;
    for(int i=0;i<n;i++){
        pq.push(v[i]);
        l+=v[i];
    }
    score[n-1].fi=l;
    for(int i=n;i<2*n;i++){
        pq.push(v[i]);
        l+=v[i];
        l-=pq.top();
        pq.pop();
        score[i].fi=l;
    }

    ll r=0;
    for(int i=3*n-1;i>=2*n;i--){
        pq2.push(v[i]);
        r+=v[i];
    }
    score[2*n-1].se=r;
    for(int i=2*n-1;i>=n;i--){
        pq2.push(v[i]);
        r+=v[i];
        r-=pq2.top();
        pq2.pop();
        score[i-1].se=r;
    }
    ll ans=score[n-1].fi-score[n-1].se;
    for(int i=n-1;i<2*n;i++){
        if(score[i].fi-score[i].se>ans){
            ans=score[i].fi-score[i].se;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10992