akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  cin>>n;
  int a[n+1];
  repi(i,1,n+1) cin>>a[i];
  int cnt=0,now=1;
  while(1){
    now=a[now];
    cnt++;
    if(now==2){cout<<cnt<<endl;return 0;}
    if(cnt>n) break;
  }
  cout<<-1<<endl;
  return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll k;
    cin >> k;
    vector<ll> ans(50,0);
    for(ll i = 0; i < 50; i++){
        ans[i] = i + k / 50;
    }
    if(k % 50){
        ll d = k % 50;
        for(ll i = 0;i < d; i++)
            ans[i] += 50 - (d - 1);
        for(ll i = d; i < 50; i++){
            ans[i] -= d;
        }
    }
    cout << 50 << endl;
    for(ll i = 0; i < 50; i++)
        cout << ans[i] << " ";
        cout << endl;
}

Measured memory_bytes: 3596
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
if n>=m:
  print(0)
  exit()
data=[0]*(m-1)
for i in range(m-1):
  data[i]=x[i+1]-x[i]
data.sort()
res=0
for i in range(n-1):
  res+=data[m-2-i]
print(sum(data)-res)

Measured memory_bytes: 20532
#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 ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin>>a>>b;
    b = 2*b;
    if(b >= a) {
    	cout<<"0\n";
    } 
    else {
    	cout<<a - b<<"\n";
    }
}

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

    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    vector<int> so = v;
    sort(so.begin(), so.end());

    int medi1 = so[n/2 - 1];
    int medi2 = so[n/2];

    rep(i, n){
        if(v[i] < so[n/2]){
            cout << medi2 << endl;
        }
        else{
            cout << medi1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
A=abs
_,*p=[list(map(int,t.split()[::-1]))for t in open(0)]
h,y,x=sorted(p)[-1]
r=range(101)
for i in r:
 for j in r:H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for u,t,s in p))

Measured memory_bytes: 3700
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXM 100000
#define MO 1000000007
using namespace std;
struct Matrix
{
	int M[4][4];
	Matrix operator * (const Matrix &b)
	{
		Matrix ret;
		for(int i=1;i<=3;i++)
			for(int j=1;j<=3;j++)
			{
				ret.M[i][j]=0;
				for(int k=1;k<=3;k++)
					ret.M[i][j]=(1LL*ret.M[i][j]+1LL*M[i][k]*b.M[k][j]%MO)%MO;
			}
		return ret;
	}
};
int x[MAXM+5],N,M;
int finans[4],d[4];
Matrix PowMod(Matrix a,int b)
{
	Matrix ret;
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
		{
			if(i==j)
				ret.M[i][j]=1;
			else
				ret.M[i][j]=0;
		}
	while(b)
	{
		if(b&1)
			ret=ret*a;
		a=a*a;
		b>>=1;
	}
	return ret;
}
int main()
{
	scanf("%d %d",&N,&M);
	for(int i=1;i<=M;i++)
		scanf("%d",&x[i]),x[i]++;
	sort(x+1,x+1+M);
	Matrix ans,usu,ususpe;
	//===========================================
	usu.M[1][1]=1,usu.M[1][2]=0,usu.M[1][3]=0;
	usu.M[2][1]=1,usu.M[2][2]=1,usu.M[2][3]=0;
	usu.M[3][1]=1,usu.M[3][2]=2,usu.M[3][3]=1;
	//===========================================
	ususpe.M[1][1]=1,ususpe.M[1][2]=0,ususpe.M[1][3]=1;
	ususpe.M[2][1]=1,ususpe.M[2][2]=1,ususpe.M[2][3]=1;
	ususpe.M[3][1]=1,ususpe.M[3][2]=2,ususpe.M[3][3]=2;
	//===========================================
	d[1]=d[2]=d[3]=1;
	int pre=1;
	for(int i=1;i<=M;i++)
	{
		ans=PowMod(ususpe,x[i]-pre-1);
		memset(finans,0,sizeof(finans));
		for(int j=1;j<=3;j++)
			for(int k=1;k<=3;k++)
				finans[j]=(1LL*finans[j]+1LL*ans.M[j][k]*d[k]%MO)%MO;
		d[1]=finans[1],d[2]=finans[2],d[3]=finans[3];
		ans=usu;
		memset(finans,0,sizeof(finans));
		for(int j=1;j<=3;j++)
			for(int k=1;k<=3;k++)
				finans[j]=(1LL*finans[j]+1LL*ans.M[j][k]*d[k]%MO)%MO;
		d[1]=finans[1],d[2]=finans[2],d[3]=finans[3];
		pre=x[i];
	}
	ans=PowMod(ususpe,N-pre);
	memset(finans,0,sizeof(finans));
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			finans[i]=(1LL*finans[i]+1LL*ans.M[i][j]*d[j]%MO)%MO;
	printf("%d\n",finans[3]);
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int[] bits = new int[12]; //26進数を記録
        int top = 0; //26進表記何桁か
        
        //26進数に変換
        while(n > 0) {
            bits[top] = (int)(n % 26);
            n /= 26;
            top++;
        }

        //下から1以上になるように補正
        for(int i = 0; i < top - 1; i++) {
            if(bits[i] <= 0) {
                bits[i] += 26;
                bits[i + 1]--;
            }
        }
        //最上位の桁(bits[top - 1])が0に繰り下がった場合、topを１減らす
        if(bits[top - 1] == 0) top--;

        //上の桁から出力
        for(int i = top - 1; i >= 0; i--) {
            System.out.print((char)('a' + bits[i] - 1));
        }
        System.out.println();
    }
}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int fun(int x, int d)
{
	if (x <= 0)
		return 0;
	int ans = (x / d);
	return ans;
}
int32_t main()
{
	AB_BHI_NI_DEGI
	//freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	//cout.precision(20);
	//cout << fixed;
	int l, r, d;
	cin >> l >> r >> d;
	cout << fun(r, d) - fun(l - 1, d) << "\n";
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.size();
    int ans=n;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]){
            ans=min(ans,max(i,n-i));
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }
        static void Main() {
            int N = int.Parse(Console.ReadLine());
            Dictionary<int, int> History = new Dictionary<int, int>();
            int a;
            for (int i = 0; i < N; i++) {
                a = int.Parse(Console.ReadLine());
                if (!History.ContainsKey(a)) {
                    History.Add(a, 1);
                    continue;
                }
                if (History[a] == 0) {
                    History[a] = 1;
                } else {
                    History[a] = 0;
                }
            }
            Console.WriteLine(History.Values.Sum());
        }
    }
}


Measured memory_bytes: 20316
#include <stdio.h>
#include <stdlib.h>
#define swap(X, Y) {int Z; Z = Y; Y = X; X = Z;}

int main(void) {
    int x, y;
    
	while(true)
	{
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0)
		{
			break;
		}
		
		if(x>y)
		{
			//swap(x, y);
			printf("%d %d\n", y, x); 
		}
		else
		{
			printf("%d %d\n", x, y); 
		}
		
	}
    return 0;
}


Measured memory_bytes: 2596
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int ans = ((N - M) * 100 + 1900 * M ) * (int)Math.pow(2,M);
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
llint N,M;
int depth[100100];
int par[100100];

class UnionFind {
    public:
    //親の番号を格納、親ならばー(その集合のサイズ)
    vector<int> Parent;
    //作るときはParentの値を全て―1にする
    //これですべてバラバラにできる
    UnionFind(int n){
        Parent = vector<int>(n,-1);
    }
    //Aがどのグループに属しているか調べる
    int root(int A){
        if(Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -Parent[root(A)];//親をとる
    }
    //AとBをくっつける
    bool connect(int A,int B){
        //AとBを直接つなぐのではなく、root(A)とroot(B)をつなげる
        A = root(A);
        B = root(B);
        if(A == B) return false;//すでにくっついている
        //大きい方(A)に小さいほう(B)をくっつけたい
        //大小が逆ならひっくり返す
        if(size(A) < size(B)) swap(A,B);
        //Aのサイズを更新
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        return true;
    }
};
bool check(int a, int b){
    return a > b;
}
int main(){
    cin >> N >> M;
    vector<pair<llint, llint>> a(M);
    for(int i = 0; i < M; i++){
        cin >> a[i].first >> a[i].second;
        a[i].first--;
        a[i].second--;
    }
    vector<llint> ans(M);
    ans[M-1] = N*(N-1)/2;
    UnionFind Uni(N);
    for(int i = M-2; i >= 0; i--){
        if(Uni.root(a[i+1].first) != Uni.root(a[i+1].second)){
            ans[i] = (llint)ans[i+1] - Uni.size(a[i+1].first)*Uni.size(a[i+1].second);
            Uni.connect(a[i+1].first,a[i+1].second);
        } else {
            ans[i] = ans[i+1];
        }
    }
    for(int i = 0; i < M; i++){
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 4096
#include <stdio.h>

int main(){
	int a,b,c,d,e,sum=0,ave=0;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
 	scanf("%d",&d);
	scanf("%d",&e);
	if(a<40){
		a=40;
	}
	if(b<40){
		b=40;
	}
	if(c<40){
		c=40;
	}
	if(d<40){
		d=40;
	}
	if(e<40){
		e=40;
	}
	sum=a+b+c+d+e;
	ave=sum/5;
	printf("%d\n",ave);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define mod 1000000007
#define mx 10005

using namespace std;
long long factorial[mx];

long long modExp(long long base,long long power)
{
    if(power==0) return 1;
    if(power%2==0) {
        return modExp((base*base)%mod,power/2);
    }
    else {
        return (base*modExp((base*base)%mod,(power-1)/2))%mod;
    }
}
long long modInv(long long base)
{
    return modExp(base,mod-2);
}
void fact()
{
    factorial[0]=1;
    for(int i=1;i<=mx;i++){
        factorial[i]=(factorial[i-1]*i)%mod;
    }
}

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

    long long x,y;
    fact();
    for(int i=1;i<=k;i++){
        int newB=k-i;
        int newR=n-k-i+1;

        if(newR<0) {
            cout << 0 <<endl;
            continue;
        }else {
            long long inv1=modInv(((factorial[i]%mod)*(factorial[n-k+1-i])%mod)%mod);
            long long x=((factorial[n-k+1]%mod)*(inv1%mod))%mod;

            long long inv2=modInv(((factorial[i-1]%mod)*(factorial[k-i])%mod)%mod);
            long long y=((factorial[k-1]%mod)*(inv2%mod))%mod;

            cout << ((x%mod)*(y%mod))%mod <<endl;
        }

    }

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll vet[n+2];
    rep(i,0,n){
        cin>>vet[i];
    }
    sort(vet,vet+n);
    ll ans =0;
    rep(i,0,k)ans+=vet[i];
    cout<<ans<<'\n';
    return 0;  
}   

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) scanf("%d", &h[i]); '\n';
	if (n == 1) { cout << "Yes"; return 0; }
	rep2(i,1, n -1) {
		if (h[i] > h[i - 1]) --h[i];
	}
	rep(i, n - 1) {
		if (h[i] > h[i + 1]) {
			cout << "No"; return 0;
		}
	}
	cout << "Yes";
}
	

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll W,H,x,y;
    cin>>W>>H>>x>>y;
    double sub=W*H/2.0;
    cout<<sub<<" ";
    if(x==W/2.0&&y==H/2.0){cout<<1<<endl;}
    else cout<<0<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Set<Card> cards = new TreeSet<>();
	static {
		for(String suit : Card.suitRank.keySet()){
			for(int i = 1; i <= 13; i++){
				Card card = new Card(suit, i);
				cards.add(card);
			}
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			Card card = new Card(sc.next(), sc.nextInt());
			cards.remove(card);
		}
		for(Card card : cards){
			System.out.println(card.suit + " " + card.num);
		}
	}
}
class Card implements Comparable{
	static Map<String, Integer> suitRank = new TreeMap<>();
	static{
		suitRank.put("S", 1);
		suitRank.put("H", 2);
		suitRank.put("C", 3);
		suitRank.put("D", 4);
	}
	String suit;
	int num;
	Card(String suit, int num){
		this.suit = suit;
		this.num = num;
	}
	String getSuit(){
		return this.suit;
	}
	
	@Override
	public int compareTo(Object o) {
		Card card = ((Card) o);
		int ret = 0;
		Comparator<Card> comparator
				= Comparator.comparing((Card c) -> suitRank.get(c.getSuit()))
				.thenComparing(c -> c.num);
		return comparator.compare(this, card);
	}
}



Measured memory_bytes: 32604
#include <iostream>
#define llint long long int
#define mod 1000000007

using namespace std;

llint N, D, X;
llint dp[2005][2005];
llint sum[2005][2005];
llint fact[2005];

llint pow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2) return ((a % mod) * (pow(a, n-1) % mod)) % mod;
	llint t = pow(a, n/2) % mod;
	return ( (t%mod) * (t%mod) ) % mod;
}

void make_fact()
{
	llint seki = 1;
	for(llint i = 1; i <= 2005; i++){
		seki *= i;
		seki %= mod;
		fact[i] = pow(seki, mod-2) % mod;
	}
}
	

llint comb(llint n, llint r)
{
	llint seki = 1;
	for(llint i = 0; i < r; i++){
		seki *= (n-i) % mod;
		seki %= mod;
	}
	seki *= fact[r];
	return seki % mod;
}

int main(void)
{
	make_fact();
	
	while(1){
		cin >> N >> D >> X;
		if(N == 0 && D == 0 && X == 0) break;
		
		for(llint n = 1; n <= N; n++) sum[n][0] = 0;
		
		for(llint m = 1; m <= N; m++){
			dp[1][m] = 1;
			if(m >= X) dp[1][m] = 0;
			sum[1][m] = (sum[1][m-1] + dp[1][m]) % mod;
		}
		
		for(llint n = 2; n <= N; n++){
			for(llint m = 1; m <= N; m++){
				if(m < n) dp[n][m] = 0;
				else dp[n][m] = sum[n-1][m-1] - sum[n-1][max((llint)0, m-X)] + mod;
				dp[n][m] %= mod;
				sum[n][m] = (sum[n][m-1] + dp[n][m]) % mod;
			}
		}
		
		llint ans = 0;
		for(llint i = 1; i <= min(D, N); i++){
			ans += ((comb(D, i)%mod) * (dp[i][N]%mod)) % mod;
			ans %= mod;
		}
		cout << ans << endl;
	}
	
	return 0;
}
		

Measured memory_bytes: 65788
#include<iostream>
#include<string>
using namespace std;
int main(void) {
	string s;
	cin >> s;
	int cnt0(0);
	int cnt1(0);
	for (int i(0); i < s.size(); i++) {
		if (s[i] == '0')cnt0++;
		else if (s[i] == '1')cnt1++;
	}
	int smaller(cnt0);
	if (smaller > cnt1)smaller = cnt1;
	cout << smaller * 2 << endl;
	return 0;
}

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

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    L = lmi()
    L.sort()
    minimum = L[0]
    cnt = 0
    for i in range(n):
        if L[i] == minimum:
            cnt += 1
    print(math.ceil((n - cnt) / (k - 1)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 13812
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;

using namespace std;

int N[300010];

int main()
{
  int n, m;
  cin >> n >> m;
  vector<VI> E((n+1)*3);
  REP(i,m) {
    int u, v;
    scanf("%d %d", &u, &v);
    E[u*3].push_back(v*3+1);
    E[u*3+1].push_back(v*3+2);
    E[u*3+2].push_back(v*3);
  }
  int s, t;
  cin >> s >> t;
  std::queue<pair<int, int>> q;
  q.push(make_pair(s*3, 0));
  const int goal = t*3;
  while(!q.empty())
  {
    pair<int, int> p = q.front();
    q.pop();
    N[p.first] = 1;
    if (p.first == goal)
    {
      cout << p.second / 3 << endl;
      return 0;
    }
    for (const int next : E[p.first])
    {
      if (N[next]) continue;
      q.push(make_pair(next, p.second+1));
      N[next] = 1;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 17792
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var ini int
	fmt.Scan(&ini)
	a := ini
	m := 0
	for i := 1; i < n; i++ {
		var h int
		fmt.Scan(&h)
		m = max(m, h)
		if a <= h {
			a = h
			continue
		} else if a-1 == h && m == h+1 {
			a = h
			continue
		} else {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;
const int Nmax=114514;
bool vis[Nmax];
vi g[Nmax];

bool dfs(int v,vi& dst){
	if(vis[v])return false;
	vis[v]=true;
	dst.PB(v);
	for(auto to:g[v])
		if(dfs(to,dst))return true;
	return true;
}

void check(int v){
	if(vis[v])return;
	vis[v]=true;
	for(auto to:g[v])check(to);
}

signed main(){
	int n=read(),m=read();
	assert(1<=n&&n<=100000);
	assert(1<=n&&n<=100000);
	set<pi> es;
	REP(i,m){
		int a=read()-1,b=read()-1;
		assert(0<=a&&a<b&&b<n);
		assert(es.find(pi(a,b))==es.end());
		es.insert(pi(a,b));
		g[a].PB(b);
		g[b].PB(a);
	}
	{
		check(0);
		REP(i,n)assert(vis[i]);
		memset(vis,0,sizeof(vis));
	}
	int root=rand()%n;
	vi ans;
	dfs(root,ans);
	vis[root]=0;
	reverse(ALL(ans));
	ans.pop_back();
	dfs(root,ans);
	print(ans.size());
	REP(i,ans.size())
		print(ans[i]+1,i==int(ans.size())-1?1:2);
}


Measured memory_bytes: 19320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int ssize = (int)s.size();
  int tsize = (int)t.size();
  int lcs[ssize+1][tsize+1];
  for (int is=0; is<=ssize; is++) {
    for (int it=0; it<=tsize; it++) {    
      lcs[is][it] = 0;
    }
  }

  for (int is=0; is<ssize; is++) {
    for (int it=0; it<tsize; it++) {
      if (s[is] == t[it]) {
	lcs[is+1][it+1] = lcs[is][it] + 1;
      } else {
	if (lcs[is][it+1] > lcs[is+1][it]) {
	  lcs[is+1][it+1] = lcs[is][it+1];
	} else {
	  lcs[is+1][it+1] = lcs[is+1][it];
	}
      }
    }
  }
  string res;
  int i = ssize;
  int j = tsize;
  while (i > 0 && j > 0) {
    if (lcs[i][j] == lcs[i][j-1]) {
      --j;
    } else if (lcs[i][j] == lcs[i-1][j]) {
      --i;
    } else if (lcs[i][j] == lcs[i-1][j-1]+1) {
      res = s[i-1]+res;
      --j;
      --i;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 35456
#[allow(unused_macros)]
macro_rules! p {
    ($($x:expr),*) => {
        $(println!("{:?}", $x);)*
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
         #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n:usize,
        mut h:[i32;n]
    }
    let mut flag = true;
    if h[0] > 0 {
        h[0] -= 1
    }
    for i in 1..n {
        if h[i - 1] < h[i] {
            h[i] -= 1;
        }
        if h[i - 1] > h[i] {
            flag = false;
            break;
        }
    }
    println!("{}", if flag { "Yes" } else { "No" });
}


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

const int N = 1e5;
int a[N + 7];
int n;

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		if(i > 1 && a[i] == a[i - 1]) {
			i--;
			n--;
		}
	}
	
	int res = 1;
	int lt = a[1];
	int kie = 0;
	
	for(int i = 2; i <= n; ++i) {
		int nkie;
		if(a[i] < lt) nkie = -1;
		else nkie = 1;
		
		if(kie == 0) kie = nkie;
		else {
			if(kie != nkie) {
				res++;
				lt = a[i];
				kie = 0;
			}
		}
		lt = a[i];
	}
	
	cout << res << endl;
	return 0;	
}

Measured memory_bytes: 764
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
A,B,Q = map(int,input().split())
S = [-float("inf")] + [int(input()) for _ in range(A)] + [float("inf")] # 両端にダミーを追加
T = [-float("inf")] + [int(input()) for _ in range(B)] + [float("inf")] # 両端にダミーを追加
X = [int(input()) for _ in range(Q)]
 
from bisect import bisect_left

for x in X:
    Si,Ti = bisect_left(S,x),bisect_left(T,x)
    Sw,Se = abs(x-S[Si-1]),abs(x-S[Si])
    Tw,Te = abs(x-T[Ti-1]),abs(x-T[Ti])
    ans = [0]*4
    ans[0] = max(Sw,Tw) # 両方ともwest
    ans[1] = max(Se,Te) # 両方ともeast
    ans[2] = 2*min(Sw,Te)+max(Sw,Te) # SwとTeの近い方に行き、反転して行ってない方に行く 
    ans[3] = 2*min(Tw,Se)+max(Tw,Se) # TwとSeの近い方に行き、反転して行ってない方に行く 
    print(min(ans))

Measured memory_bytes: 18044
#include<bits/stdc++.h>
#include<vector>
using namespace std;
typedef long long ll; 
ll a[200];
ll n;
int main(void)
{
	ll i;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a,a+n);
	ll ans=100000000000000000;
	ll mi=a[0],ma=a[n-1];
	for(ll i=mi;i<=ma;i++)
	{
		ll so=0;
		for(ll j=0;j<n;j++)
		{
			so+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,so);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
if __name__ == "__main__":
    N, W = map(lambda x: int(x), input().split())
    items = [(0, 0)] * N
    for i in range(N):
        v, w = map(lambda x: int(x), input().split())
        items[i] = (v, w)
    dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

    for i in range(N):
        value, weight = items[i]
        for j in range(W + 1):
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
            next_weight = j + weight
            next_value = dp[i][j] + value
            if (next_weight <= W and next_value > dp[i + 1][next_weight]):
                dp[i + 1][next_weight] = next_value

    print(max(dp[N]))



Measured memory_bytes: 25972
#include<iostream>
using namespace std;
long long a,b;
string st;
int main()
{
	cin>>st;
	for (int i=0;i<st.size();i++)
	{
		if (st[i]=='C') a=1;
		if (st[i]=='F'&&a==1) b=1;
	}
	if (b==1) cout<<"Yes"; else cout<<"No";
	return 0;
}

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

int main() {
    int N,A;
    cin >> N >> A;
    cout << N*N - A << endl;
}


Measured memory_bytes: 256
S= input()
DP = [[0,0] for i in range(len(S)+1)]
tr = [[-1,-1] for i in range(len(S)+1)]
for i in range(1,len(S)+1):
  ch = S[i-1]
  # D,P
  if ch == "D":
    DP[i][0] = max(
      DP[i-1][0]+1,
      DP[i-1][1]+2)
    if DP[i][0] == DP[i-1][0]+1:
      tr[i][0] = 0
    else:
      tr[i][0] = 1
    tr[i][1] = -1
    DP[i][1] = 0
    
  elif ch == "P":
    DP[i][0] = 0
    DP[i][1] = max(
      DP[i-1][0],
      DP[i-1][1])
    
    if DP[i][1] == DP[i-1][0]:
      tr[i][1] =0
    else:
      tr[i][1] = 1
    tr[i][0] = -1
    
  else:
    DP[i][0] = max(
      DP[i-1][0]+1,
      DP[i-1][1]+2)
    
    if DP[i][0] == DP[i-1][0]+1:
      tr[i][0] = 0
    else:
      tr[i][0] = 1
      
    DP[i][1] = max(
      DP[i-1][0],
      DP[i-1][1])
    if DP[i][1] == DP[i-1][0]:
      tr[i][1] = 0
    else:
      tr[i][1] = 1
      

if max(DP[i]) == DP[i][0]:
  pointer = 0
else:
  pointer = 1
ans = ""
for i in range(len(S)):
  ans += ["D","P"][pointer]
  pointer = tr[-i-1][pointer]
print("".join(reversed(ans)))

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

using namespace std;

int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(s-i-j<=k && i+j<=s) ans++;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n,t=map(int,input().split())
a=list(map(int,input().split()))
d=[]
l=0
for i in range(n-1,0,-1):
    l=max(l,a[i])
    d.append(l)
d=d[::-1]
h=0
k=0
for i in range(n-1):
    if a[i]-d[i]==h:
        k+=1
    elif a[i]-d[i]<h:
        h=a[i]-d[i]
        k=1
print(k)

Measured memory_bytes: 14252
// 2011/09/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int w, h;
		cin >> w >> h;
		if(w==0&&h==0)
			break;

		int X[100][100];
		for(int x=0; x<w; x++)
			X[0][x] = 1;
		for(int y=0; y<h; y++)
			X[y][0] = 0;
		for(int x=1; x<w; x++)
			X[1][x] = 1;
		for(int y=1; y<h; y++)
			X[y][1] = 1;

		int Y[100][100];
		for(int x=0; x<w; x++)
			Y[0][x] = 0;
		for(int y=0; y<h; y++)
			Y[y][0] = 1;
		for(int x=1; x<w; x++)
			Y[1][x] = 1;
		for(int y=1; y<h; y++)
			Y[y][1] = 1;

		for(int y=2; y<h; y++){
			for(int x=2; x<w; x++){
				X[y][x] = (X[y][x-1]+Y[y-1][x-1])%100000;
				Y[y][x] = (Y[y-1][x]+X[y-1][x-1])%100000;
			}
		}

		cout << (X[h-1][w-1]+Y[h-1][w-1])%100000 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _overload2(_1,_2,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(ll i=a;i<b;++i)
#define _repc(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) _overload4(__VA_ARGS__,_repc,_repi,_rep)(__VA_ARGS__)
#define _rrepi(i,a,b) for(ll i=b-1;i>=a;i--)
#define _rrep(i,n) _rrepi(i,0,n)
#define _rrepc(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rrep(...) _overload4(__VA_ARGS__,_rrepc,_rrepi,_rrep)(__VA_ARGS__)
#define sum(...) accumulate(range(__VA_ARGS__),0)
#define _range(i) (i).begin(),(i).end()
#define _rangek(i,k) (i).begin(),(i).begin()+k
#define range(...) _overload2(__VA_ARGS__,_rangek,_range)(__VA_ARGS__)
#define LINF (ll)1000000000000000000
#define MOD (ll)1000000007
#define INF (int)1000000007
#define Yes(i) out(i?"Yes":"No")
#define YES(i) out(i?"YES":"NO")
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,size) vector<type> name(size);
#define VEC(type,name,size) vector<type> name(size);in(name)
struct aaa{aaa(){cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}aaaaaaa;
inline void in() {}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec);
template<typename T,typename L>
istream& operator >> (istream& is, pair<T,L>& p);
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec);
template<typename T,typename L>
ostream& operator << (ostream& os, pair<T,L>& p);
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename T,typename L>
istream& operator >> (istream& is, pair<T,L>& p){is >> p.first;is >> p.second;return is;}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){os << vec[0];rep(i,1,vec.size()){os << ' ' << vec[i];}return os;}
template<typename T,typename L>
ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){cin>>head;in(move(tail)...);}
template <class T>
inline void out(T t){cout<<t<<'\n';}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){cout<<head<<' ';out(move(tail)...);}

int gcd ( int a, int b ) { int c; while ( a != 0 ) { c = a; a = b%a; b = c; } return b; }
int main(){
    INT(a,b,n);
    rep(i,n){
        INT(s,g);
        if(s<b&&a<g){
            out(1);
            return 0;
        }
    }
    out(0);
}















Measured memory_bytes: 3208
#include<iostream>
#include<cstdlib>
using namespace std;
#define MAX 500000

struct Node{
  int key;
  Node *p, *r, *l;
};

int m;
Node *root, *NIL;

void inorder(Node* r){
  if ( r->l != NIL){
    inorder(r->l);
  }
  cout << " " << r->key;
  if ( r->r != NIL){
    inorder(r->r);
  }
}

void preorder(Node* r){
  cout << " " << r->key;
  if ( r->l != NIL){
    preorder(r->l);
  }
  if ( r->r != NIL){
    preorder(r->r);
  }
}

void print(){
  inorder(root);
  cout << endl;
  preorder(root);
  cout << endl;
}

void insert(int key){
  Node *y = NIL; // xの親
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));

  z->key = key;
  z->l = NIL;
  z->r = NIL;
  while( x != NIL){
    y = x;
    if ( z->key < x->key){
      x = x->l;
    } else {
      x = x->r;
    }
  }

  z->p = y;
  if ( y == NIL){
    root = z;
  } else if ( z->key < y->key){
    y->l = z;
  } else {
    y->r = z;
  }
}

int main(){
  cin >> m;
  string order;
  int key;
  for ( int i = 0; i < m; i++){
    cin >> order;
    if (order == "insert"){
      cin >> key;
      insert(key);
    } else {
      print();
    }
  }

  return 0;
}


Measured memory_bytes: 26604
s = gets.chomp.split("")
k = s.length

win = 0
lose = 0
s.each do |i|
    win += 1 if i == 'o'
    lose += 1 if i == 'x'
end

if k < 8
    puts "YES"
elsif win + (15 - k) > 7
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int mo=1e9+7;
const int maxn=1e6+10;
int n,m;
long long p[maxn],inv[maxn],ans;
long long po(long long a,long long b)
{
	if (b==0) return 1;
	if (b==1) return a%mo;
	long long c=po(a,b/2);
	if (b&1) return c*c%mo*a%mo;else return c*c%mo;
}
long long C(int n,int m){return p[n]*inv[m]%mo*inv[n-m]%mo;}
long long calc(int k,int n){return C(n+k-1,k-1);}
int main()
{
	scanf("%d%d",&n,&m); ans=1;
	p[0]=1; for (int i=1;i<=400000;i++) p[i]=p[i-1]*i%mo;
	inv[400000]=po(p[400000],mo-2);
	for (int i=399999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mo;
	for (int i=1;i<=min(n-1,m);i++) ans=(ans+C(n,i)*calc(n-i,i)%mo)%mo;
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 10496
s = input()
n = len(s)
ans = 0
# print(len(s))

for i in range(n):
	if i % 2 == 0:
		# print(s[i])
		if s[i] == '0':
			ans += 1
			# print('a')
	else:
		if s[i] == '1':
			ans += 1
# print(ans)

print(min(ans,n-ans))

Measured memory_bytes: 3188
//Water Rate
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D, P;
    cin >> A >> B >> C >> D >> P;

    int x, y;
    x = A * P;
    y = max(B, B + D * (P - C));

    cout << min(x, y) << endl;
}


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

using namespace std;

int main() {
  vector<bool> p(101010, true);
  p[0] = false;
  p[1] = false;

  vector<int> sum(101011);

  for (int i = 2; i < 101010; i++) {
    sum[i + 1] = sum[i];
    if (p[i]) {
      if (p[i] && p[(i + 1) / 2]) {
        sum[i + 1]++;
      }
      for (int j = i * 2; j < 101010; j += i) {
        p[j] = false;
      }
    }
  }

  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << sum[r + 1] - sum[l] << endl;
  }
}


Measured memory_bytes: 1024
#include <iostream> 

using namespace std;


int main() {
    int n;
    int a[1001];

    cin >> n;

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

    for (int x = n; 1 < x; --x){
        cout << a[x - 1];
        cout << " ";
    }
        cout << a[0];
        cout << endl;
    return 0;
}



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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll H, W;
llvec e[3000];
vector<string> s;
ll id(ll i, ll j){
  return i*W+j;
}

ll iniblk=0;
void gen_map(){
  rep(i, H){
    rep(j, W){
      if(s[i][j]=='.'){
        if(j-1>=0)if(s[i][j-1]=='.')e[id(i, j)].push_back(id(i, j-1));
        if(j+1<W)if(s[i][j+1]=='.')e[id(i, j)].push_back(id(i, j+1));
        if(i-1>=0)if(s[i-1][j]=='.')e[id(i, j)].push_back(id(i-1, j));
        if(i+1<H)if(s[i+1][j]=='.')e[id(i, j)].push_back(id(i+1, j));
      }else{
        iniblk++;
      }
    }
  }
  return;
}

ll bfs(){
  queue<ll> q;
  llvec d(H*W, 1e10);
  q.push(0);
  d[0] = 1;
  while(!q.empty()){
    ll c = q.front();q.pop();
    rep(i, e[c].size()){
      if(d[e[c][i]]==1e10){
        d[e[c][i]]=d[c]+1;
        q.push(e[c][i]);
      }
    }
  }
  return d[H*W-1];
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> H >> W;
  rep(i, H){
    string h;
    cin >> h;
    s.push_back(h);
  }
  gen_map();
  cerr << iniblk << endl;
  ll tmp = bfs();
  if(tmp==1e10){
    cout << -1 << endl;
  }else{
    cout << H*W - iniblk - tmp<<endl;
  }
  
    
  return 0;
}


Measured memory_bytes: 512
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    counter = Counter(A)
    ans = []

    sm = sum(A)
    Q = int(input())
    for i in range(Q):
        b, c = map(int,input().split())
        sm -= counter[b] * b
        sm += counter[b] * c
        counter[c] += counter[b]
        counter[b] = 0
        ans.append(sm)
    
    print(*ans, sep='\n')

if __name__ == '__main__':
    solve()


Measured memory_bytes: 101804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=305,INF=1<<30;

ll dp[MAX][MAX][MAX*2];
ll imo[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    int K;cin>>K;
    S='0'+S;
    S+='0';
    
    vector<int> cnt,can;
    for(int i=0;i<si(S);i++){
        if(S[i]=='1') continue;
        for(int j=i+1;j<si(S);j++){
            if(S[j]=='0'){
                cnt.push_back(j-i-1);
                break;
            }
        }
    }
    
    can=cnt;
    can.push_back(0);
    
    int N=si(cnt);
    for(int i=N-1;i>=0;i--) can[i]+=can[i+1];
    
    dp[N][0][0]=1;
    
    for(int i=N;i>=1;i--){
        
        memset(imo,0,sizeof(imo));
        
        for(int j=0;j<=300;j++){
            for(int k=0;k<=can[i];k++){
                
                if(dp[i][j][k]==0) continue;
                
                for(int diff=0;diff<cnt[i-1]&&k+diff<=can[i-1];diff++){
                    dp[i-1][j+cnt[i-1]-diff][k+diff]+=dp[i][j][k];
                    if(dp[i-1][j+cnt[i-1]-diff][k+diff]>=mod) dp[i-1][j+cnt[i-1]-diff][k+diff]-=mod;
                }
                
                imo[j][k+cnt[i-1]]+=dp[i][j][k];
                if(imo[j][k+cnt[i-1]]>=mod) imo[j][k+cnt[i-1]]-=mod;
            }
        }
        
        for(int j=0;j<=300;j++){
            for(int k=0;k<=can[i-1];k++){
                if(k) imo[j][k]+=imo[j][k-1];
                if(imo[j][k]>=mod) imo[j][k]-=mod;
                
                dp[i-1][j][k]+=imo[j][k];
                if(dp[i-1][j][k]>=mod) dp[i-1][j][k]-=mod;
            }
        }
    }
    
    ll ans=0;
    
    for(int j=0;j<=min(300,K);j++){
        ans+=dp[0][j][can[0]];
        ans%=mod;
    }
    
    cout<<ans<<endl;
}



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

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

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

	int output = 0;
	while (true) {
		bool flag = true;
		for (int i = 0; i < n; i++) {
			if ((a[i] % 2) == 1) {
				flag = false;
				break;
			}
		}

		if (flag) {
			for (int i = 0; i < n; i++)
				a[i] /= 2;
			output++;
		} else {
			break;
		}
	}

	cout << output << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){


    ll n;
    cin>>n;

    vector<ll> data(n);
    rep(i,n){
        ll tmp;
        cin>>tmp;
        data.at(i)=tmp;
    }

    ll answer=0;

    ll tmp=0;

    rep(i,n){
        tmp+=data.at(i);
        tmp%=MOD;
    }

    ll tmp2=0;

    rep(i,n){
        ll nijo=(data.at(i)*data.at(i))%MOD;
        tmp2+=nijo;
        tmp2%=MOD;
    }

    answer=((tmp*tmp)%MOD)-tmp2;

    if (answer<0){
        answer+=MOD;
    }

    if (answer%2==1){
        answer+=MOD;
    }

    cout<<(answer/2)%MOD<<endl;

    






}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll MAXN = 150000;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);
uniform_int_distribution<> DD(0, 1000000000);

ll random(ll r){
    return (ll(DD(eng))*1000000000 + ll(DD(eng)))%r;
}

vector<vl> C(100001, vl());
vl fours;

bool mark[100001] = {0};

ll dfs(ll i){
    mark[i] = 1;
    ll ans = 1;
    for(int c1 = 0; c1 < sz(C[i]); c1++){
        if(!mark[C[i][c1]])ans += dfs(C[i][c1]);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n >> m;
    for(int c1 = 0; c1 < m; c1++){
        cin >> a >> b;
        a--;
        b--;
        C[a].push_back(b);
        C[b].push_back(a);
    }
    string ans = "Yes";
   int madeg = 0;
    for(int c1 = 0; c1 < n; c1++){
        if(sz(C[c1])%2 == 1){
            cout << "No\n";
            return 0;
        }
        if(sz(C[c1]) == 4){
            fours.push_back(c1);
        }
        madeg = max(madeg, sz(C[c1]));
    }

    if(madeg >= 6){
        cout << "Yes\n";
        return 0;
    }

    if(sz(fours) > 2){
        cout << "Yes\n";
        return 0;
    }
    if(sz(fours) < 2){
        cout << "No\n";
        return 0;
    }
  //  cout << "No\n";
  //  return 0;
    mark[fours[0]] = 1;
    a = dfs(fours[1]);
    if(a != n-1){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 7040