akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::io::stdin;

fn main() {
    let mut input_line: String = String::new();
    io::stdin().read_line(&mut input_line).expect("err");

    let inputs: Vec<&str> = input_line.split_whitespace().collect();

    let h = inputs[0].parse::<i64>().unwrap();

    for _i in 0..h{
        let mut c: String = String::new();
        stdin().read_line(&mut c).expect("err");
        print!("{}",c);
        print!("{}",c);
    }
}

Measured memory_bytes: 2132
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/21/20 20:55:02
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  long long n; cin>>n;
  string ans;
  while (n) {
    n--;
    ans.push_back((n%26) + 'a');
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}


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

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

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

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

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

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

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

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

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

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


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

int main() {
 ios::sync_with_stdio(false);

int  x[6];
for(int i=1;i<=5;i++){
	cin>>x[i];
}

for(int i=1;i<=5;i++){
	if(x[i]==0){
		cout<<i<<endl;
	}
}



return 0;
}




Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll k;
  string s;
  cin >> k >> s;
  ll n = s.size();
  mint ans = 0;
  combination c(2 * 1e6);
  rep(i, k + 1) ans += c(n - 1 + i, i) * mint(25).pow(i) * mint(26).pow(k - i);
  cout << ans << endl;
}

Measured memory_bytes: 35576
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	fmt.Println(n * n * n)
}


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

int main() {
	string o, e;
	cin >> o >> e;

	int i = 0;
	while (o[i] != NULL) {
		cout << o[i];
		if (e[i] != NULL) cout << e[i];
		i++;
	}
	return 0;
}

Measured memory_bytes: 256
//If you can think it, you should implement it
#include<bits/stdc++.h>
using namespace std;
 
#define xlr8 ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define ld long double
#define mod 1000000007
#define eb emplace_back
#define mp make_pair
#define nl "\n"
#define ignore cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

int power(int a,int b,int m=mod){ int ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1LL*a*ans)%m; b>>=1;a=(1LL*a*a)%m;}return ans;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
int gcd(int a,int b){  if(b==0) return a;  return gcd(b,a%b);}
int lcm(int a,int b){return (a* b)/gcd(a,b);}

clock_t time_p=clock();
void rtime(){time_p=clock()-time_p;cerr<<"******************\nTime taken : "<<(ld)(time_p)/CLOCKS_PER_SEC<<"\n";}
//__builtin_popcount()
//memset(a,0,sizeof(a))
//bool next_permutation(a.begin(),a.end())

signed main(){
    xlr8;
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n,k;
        cin>>n>>k;
        vector<int> a(n+1);
        for(int i=1;i<=n;i++)
          cin>>a[i];
        int pos=1;
        bool vis[n+1]={};
        vis[1]=true;
        while(vis[a[pos]]!=true)
        {
          pos=a[pos];
          vis[pos]=true;
        }
        pos=a[pos];
        vector<int> ans;
        ans.eb(pos);
        while(a[*ans.rbegin()]!=ans[0])
        {
          ans.eb(a[*ans.rbegin()]);
        }

        int val=1;
        while(k!=0&&val!=pos)
        {
          val=a[val];
          k--;
        }
        if(k!=0)cout<<ans[k%ans.size()]<<nl;
        else
          cout<<val<<nl;
        




    }
    rtime();


 return 0;
}

Measured memory_bytes: 7012
use std::io::{stdin, stdout, Write};

fn main() {
    let mut first_line = String::new();
    stdin().read_line(&mut first_line).unwrap();
    let target_len = first_line.trim().len();

    let out = stdout();
    let mut out = out.lock();

    for x in 0..target_len {
        write!(out, "x");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    vector<ll>A(3);
    cin >>A[0]>>A[1]>>A[2];
    sort(all(A));
    
    cout << A[2]-A[0] << endl;


    return 0;
    

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> l(n);
	for( auto &k : l ) cin >> k;
	sort( l.begin(), l.end() );
	ll ans = 0;
	for( int i = 0; i < n-2; ++i ){
		for( int j = i+1; j < n-1; ++j ){
			int x = l[i];
			int y = l[j];
			ans += max(0ll, (ll)(( lower_bound( l.begin(), l.end(), x+y ) - l.begin() ) - (j+1) ));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# 高橋君のモンスター　体力A、攻撃力B
# 青木君のモンスター　体力C、攻撃力D
# 高橋->青木->高橋->青木->...の順に攻撃する
# 高橋勝つならYes、負けるならNo

a, b, c, d = map(int, input().split())

while a > 0 and c > 0:
    c -= b
    if c <= 0:
        print("Yes")
        break

    a -= d
    if a <= 0:
        print("No")
        break

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e3, mod = 1e9 + 7;
int n, k, dp[2][nsz + 5], suf[2][nsz + 5];
num ans;

int inline qpow(int a, int p) {
	int res = 1;
	for (; p > 0; p >>= 1) {
		(p & 1) && (res = (num) res * a % mod);
		a = (num) a * a % mod;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> k;
	int o = 0, x = 1;
	dp[o][n + 1] = 1;
	for (int j = n + 1; j >= 1; --j) {
		suf[o][j] = (suf[o][j + 1] + dp[o][j]) % mod;
	}
	cont (i, k - 1) {
		for (int j = n; j >= 1; --j) {
			dp[x][j] = suf[o][j + 1];
			if (j + i - 1 <= n) {
				dp[x][j] = (dp[x][j] + dp[o][j]) % mod;
			}
			suf[x][j] = (suf[x][j + 1] + dp[x][j]) % mod;
		}
		swap(o, x);
		dp[x][n + 1] = suf[x][n + 1] = 0;
	}
	circ (j, 2, n + 1) {
		ans = (ans + dp[o][j]) % mod;
	}
	ans = ans * qpow(2, n - k - 1) % mod;
	cout << ans << ln;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    long long n;
    cin >> n;
    vector<int> juel(n),cost(n);
    int temp;
    for(int i=0; i<n; i++){
        cin >> juel[i];
    }
    for(int i=0; i<n; i++){
        cin >> cost[i];
    }
    long long ans=0;
    long long X,Y;
    for(long long i=0; i<=((long long)1<<21); i++){
        X=0;Y=0;
        for(int j=0; j<n; j++){
            if((i>>j)&1){
                X+=juel[j];
                Y+=cost[j];
            }
        }
        ans=max(ans,X-Y);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int hiki = sc.nextInt();
		int asi = sc.nextInt();
		boolean flg = false;
		for(int i = 0; i <= hiki; i++){
			if((2 * i) + (4 * (hiki - i)) == asi){
				flg = true;
			}
		}
		if(flg){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int dp1[3005][3005];    /* dp1[i][j]: 1-i番目の料理で、j分以内に間食できるおいしさの最大値 */
int dp2[3005][3005];    /* dp2[i][j]: i-n番目の料理で、j分以内に間食できるおいしさの最大値 */
int w[3005], v[3005];

int main(){
    int n, t;
    cin >> n >> t;
    REP(i, n) cin >> w[i+1] >> v[i+1];

    REP(i, n) REP(j, t) {
        if(j < w[i+1]) {
            dp1[i+1][j] = dp1[i][j];
        } else {
            dp1[i+1][j] = max(dp1[i][j], dp1[i][j-w[i+1]] + v[i+1]);
        }
    }

    REPN_REV(i, 1, n+1) REP(j, t) {
        if(j < w[i]) {
            dp2[i][j] = dp2[i+1][j];
        } else {
            dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-w[i]] + v[i]);
        }
    }

    int ans = -1;

    REPN(i, 1, n+1) {
        REPN(j, 0, t){
            ans = max(ans, dp1[i-1][j] + dp2[i+1][t-1-j] + v[i]);
        }
    }

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

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    ll a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    ll x;
    cin >> x;
    ll a = x / 500;
    x = x - a * 500;
    ll b = x / 5;
    print(a*1000 + b*5);
    return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N,M = map(int, input().split())
A = [int(x) for x in input().split()]
ans = sum(A)
if(N<ans):
    print(-1)
else:
    print(int(N-ans))


Measured memory_bytes: 10592
#include <algorithm>
#include <iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int a[200005];
ll suf[200005];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n;i++)
        cin >> a[i];
    suf[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--){
        suf[i] = suf[i + 1] + a[i];
        
    }
        

    ll res=0;

    for (int i = 0; i < n;i++){
        res += (suf[i + 1]%mod * a[i]%mod) % mod;
        res %= mod;

    }
    cout << res;
    return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;
/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[200001];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        a[i] = tmp - i;
    }
    sort(a, a + n);

    int b = a[n / 2];

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


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=0&&b>=0)cout<<"Zero"<<endl;
	else
	{
		if(a>0)cout<<"Positive"<<endl;
		else if((b-a+1)%2)cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
//15-1 ?°´?????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    int A,B,C,D,P;
    cin >> A >> B >> C >> D >> P;
    int X = P*A;
    int Y = B;
    if(P>C){
        Y += D*(P-C);
    }
    if(X>=Y){
        cout << Y << endl;
    }
    else{
        cout << X << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
n, m = map(int, input().split())
x = [int(i) for i in input().split()]
if m > n:
    x = sorted(x)
    diff = [x[i+1] - x[i] for i in range(len(x)-1)]
    diff =sorted(diff)
    ans = sum(diff[0:m-n])
    print(ans)
else:
    print(0)

Measured memory_bytes: 13840
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> get_prime(int n){
    if(n <= 1) return vector<int>();
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j > n) break;
            is_prime[i*j] = false;
            if(i % j == 0) break;
        }
    }
    return prime;
}

int main() {
    auto v = get_prime(10000);
    vector<int> ans;
    for (int i = 0; i+1 < v.size(); ++i) {
        if(v[i+1] - v[i] == 2){
            ans.emplace_back(v[i]+2);
        }
    }
    int n;
    while(cin >> n, n){
        auto x = *--upper_bound(ans.begin(),ans.end(), n);
        printf("%d %d\n", x-2, x);
    }
    return 0;
}


Measured memory_bytes: 3216
n, m = map(int, input().split())
ps = [[0, 0] for i in range(n)]  
wa_count = 0
ac_count = 0
for i in range(m):
    input_p, input_s = input().split()
    if ps[int(input_p)-1][0] <= 0:
        if input_s == 'AC':
            ps[int(input_p)-1][0] += 1
        else:
            ps[int(input_p)-1][1] += 1
for i in ps:
    if i[0] == 1:
        ac_count += 1
        wa_count += i[1]

print(ac_count, wa_count)

Measured memory_bytes: 53920
#include <bits/stdc++.h>
#define MAX_V 10000
using namespace std;

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v] = true;
  for(int i=0; i<G[v].size(); i++){
    int u = G[v][i], w = match[u];
    if(w<0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int Bipartite_Matching(){
  int res=0;
  memset(match, -1, sizeof(match));
  for(int v=0; v<V; v++){
    if(match[v] < 0){
      memset(used,0,sizeof(used));
      if(dfs(v)) res++;
    }
  }
  return res;
}


int main(){
  int n,m,b[500],r[500];
  while(cin>>m>>n,m){
    for(int i=0;i<V;i++)G[i].clear();
    for(int i=0;i<m;i++)cin>>b[i];
    for(int i=0;i<n;i++)cin>>r[i];
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
	if(__gcd(b[i],r[j])!=1)add_edge(i,m+j);
    V=n+m;
    cout <<Bipartite_Matching()<<endl;
  }
  return 0;
}

Measured memory_bytes: 5160
import java.util.Scanner;                      
                                               
 class Main {                                  
    public static void main(String[] args) {   
     Scanner scanner = new Scanner(System.in);      


    	 
         int n = scanner.nextInt(); //		入力する数字の個数を設定
         int[] a;                        //  特定多数の数字を入れるため配列aを設定
         a = new int[n];
         
         for(int i=0;i<n;i++){
        	a[i]= scanner.nextInt(); //      nの数だけ配列に入力
         }
        int b=n;                     //     繰り返し回数の設定のためbにnを代入
         for(int i=0;i<b;i++){
        	if(i == b-1){
        		System.out.println(a[n-1]);  //最後の入力では空白を入れずに出力する
        	}
        	
        	else{	
        	System.out.print(a[n-1]+" "); //配列の大きい数字から順に出力
        	 n--;
        	 
         }}
         
 
  scanner.close();
 }
 }



Measured memory_bytes: 26372
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main() {
	int n1,n2,n3,tyo=0,hisi=0;
	while (scanf("%d,%d,%d",&n1,&n2,&n3)!=EOF) {
		if (n1 == n2)hisi++;
		if (n1*n1 + n2*n2 == n3*n3)tyo++;
	}
	cout << tyo << endl<<hisi<<endl;
	return 0;
}


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

int main(){
    int n;cin>>n;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    string temp;
    for (int i=0;i<n;i++){
        cin >> temp;
        if (temp == "AC"){
            ac++;
        } else if (temp == "WA"){
            wa ++;
        } else if (temp == "TLE"){
            tle++;
        } else{
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3624
import sys
from itertools import accumulate
from bisect import bisect_left as bi_l, bisect_right as bisect_right

n, m, *a = map(int, sys.stdin.read().split())
a.sort()

def possible(border):
    pair_cnt = 0
    for i in range(n):
        aj = border - a[i]
        j = bi_l(a, aj)
        pair_cnt += n - j
    return pair_cnt >= m

def main():
    s = [0] + list(accumulate(a))
    
    lo = 1; hi = a[-1] * 2 + 1
    while lo + 1 < hi:
        border = (lo + hi) // 2
        if possible(border):
            lo = border
        else:
            hi = border
    res = lo
    ans = 0
    minimum = float('inf')
    cnt = 0
    for i in range(n):
        aj = res - a[i]
        j = bi_l(a, aj)
        ans += s[n] - s[j] + a[i] * (n - j)
        cnt += n - j
        if j < n:
            minimum = min(minimum, a[i] + a[j])

    ans -= (cnt - m) * minimum
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)

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

using namespace std;

int main(){
  int  N;
  cin >> N;
  int c = 0;
  if(N <= 999){
    c++;
    if(N <= 888){
      c++;
      if(N <= 777){
        c++;
        if(N <= 666){
          c++;
          if(N <= 555){
            c++;
            if(N <= 444){
              c++;
              if(N <= 333){
                c++;
                if(N <= 222){
                  c++;
                  if(N <= 111){
                    c++;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  int ans = 10;
  cout << (ans - c)*100 + (ans - c)*10 + (ans - c) << endl;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  cin >> n;
  vi a(n+1);
  rep(i,n) cin >> a[i];
  sort(rall(a));
  a[n] = inf;
  ll f = 0, s = 0;
  int cnt = 1;
  rep(i,n){
    if(a[i] != a[i+1]){
      if(cnt >= 2){
        if(f == 0){f = a[i]; cnt -= 2;}
        if(cnt >= 2){
          s = a[i];
          break;
        }
      }
      cnt = 0;
    }
    cnt++;
  }
  ll ans = f*s;
  //cout << f << " " << s << endl;
  cout << ans << endl;
}

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

#define N 200020

int n, k, p[N];

struct RMQ {
    int mn[N][20];
    void build(int *a, int n) {
        for (int i = 1; i <= n; i ++) mn[i][0] = a[i];
        for (int j = 1; (1 << j) <= n; j ++) {
            for (int i = 1; i + (1 << j) - 1 <= n; i ++) {
                mn[i][j] = min(mn[i][j-1], mn[i+(1<<j-1)][j-1]);
            }
        }
    }
    int query(int l, int r) {
        int d = 31 - __builtin_clz(r - l + 1);
        return min(mn[l][d], mn[r-(1<<d)+1][d]);
    }
} T;

struct RMaQ {
    int mn[N][20];
    void build(int *a, int n) {
        for (int i = 1; i <= n; i ++) mn[i][0] = a[i];
        for (int j = 1; (1 << j) <= n; j ++) {
            for (int i = 1; i + (1 << j) - 1 <= n; i ++) {
                mn[i][j] = max(mn[i][j-1], mn[i+(1<<j-1)][j-1]);
            }
        }
    }
    int query(int l, int r) {
        int d = 31 - __builtin_clz(r - l + 1);
        return max(mn[l][d], mn[r-(1<<d)+1][d]);
    }
} U;

int nxt[N], prv[N];

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i ++) scanf("%d", p + i);
	T.build(p, n);
	U.build(p, n);
	nxt[n] = n;
	for (int i = n - 1; i >= 1; i --) {
		if (p[i] < p[i+1]) nxt[i] = nxt[i+1];
		else nxt[i] = i;
	}
	prv[1] = 1;
	for (int i = 2; i<= n; i++) {
		if (p[i-1] < p[i]) prv[i] = prv[i-1];
		else prv[i] = i;
	}
	set<pair<int, int> > s;
	for (int i = 1; i <= n - k + 1; i ++) {
		if (nxt[i] >= i + k - 1) {
			s.emplace(0, 0);
			continue;
		}
		int lo = i, hi = nxt[i] + 1;
		while (hi - lo > 1) {
			int m = hi + lo >> 1;
			if (T.query(m, i + k - 1) > p[m-1]) lo = m;
			else hi = m;
		}
		int le = lo;
		lo = prv[i+k-1], hi = i+k;
		while (hi - lo > 1) {
			int m = hi + lo >> 1;
			if (U.query(i, m-1) < p[m]) hi = m;
			else lo = m;
		}
		int ri = lo;
		s.emplace(le, ri);
	}
	cout<<s.size()<<endl;
}


Measured memory_bytes: 43264
n = int(input())
s = input()
d = []
for c in s:
    if d==[]:
        d.append([c,1])
    else:
        if c == d[-1][0]:
            d[-1][1]+=1
        else:
            d.append([c,1])

endwhite = 0
endblack = 0
white = 0
black = 0
for p in d:
    if p[0] == '.':
        endwhite = black
        endblack = min(endblack+ p[1],endwhite+p[1])
        white += p[1]
    if p[0] == '#':
        endblack = min(endblack,endwhite)
        endwhite += p[1]
        black += p[1]
print(min(endwhite,endblack))


Measured memory_bytes: 23652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int k;
    cin >> k;
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << arr[k-1] << endl;
    return 0;
}

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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

int main() {
    lld N, K;
    lld d[101];
    lld A[101][101];
    lld cnt[101];
    mem0(cnt);
    cin >> N >> K;
    for(int i = 0; i < K; i++) {
        cin >> d[i];
        for(int j = 0; j < d[i]; j++) {
            cin >> A[i][j];
            cnt[A[i][j]]++;
        }
    }
    lld ans = 0;
    for(int i = 1; i <= N; i++) {
        if(cnt[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3736
N, K, Q = map(int, input().split())

players = dict()

for i in range(N):
    players[i + 1] = 0

for _ in range(Q):
    winner = int(input())
    players[winner] += 1

for i in range(N):
    if players[i + 1] > Q - K:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 15084
import sys
input = sys.stdin.readline

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


checked = [False]*N
checked[0] = True

def dfs(stack):
    while True:
        p = stack[-1]
        update = False
        for np in graph[p]:
            if not checked[np]:
                update = True
                stack.append(np)
                checked[np] = True
                break
        if not update:
            break
    return stack

stack1 = dfs([0])
stack2 = dfs([0])
ans = stack1[::-1] + stack2[1:]

print(len(ans))
print(" ".join([str(a+1) for a in ans]))

Measured memory_bytes: 30396
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 1e9+9;
const int mod = 1e9+7;
int a,b,c;
int main(){
    cin>>a>>b>>c;
    swap(a,b),swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,sum = 0;
  cin >> a >> b;
  if(a >= b){
    sum = sum + a;
    a = a-1;
  }
  else {
    sum = sum + b;
    b = b-1;
  }

  if(a >= b){
    sum = sum + a;
  }
  else {
    sum = sum + b;
  }
  cout << sum << endl;
}

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

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  vector<int> nums{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << nums[k-1] << endl;
}

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

main() {
  string S, T; cin >> S >> T;
  int pos;
  int epos = -1;
  int last = S.length() - T.length() + 1;
  for (pos = 0; pos < last + 1; pos++) {
    int cnt = 0;
    if (pos == last) break;
    for (int j = 0; j < T.length(); j++) {
      if (S[pos + j] != '?' && S[pos + j] != T[j]) continue;
      cnt++;
    }
    if (cnt == T.length()) epos = max(epos, pos);
  }
  if (epos == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    S.replace(epos, T.length(), T);
    for (int i = 0; i < S.length(); i++) if (S[i] == '?') S[i] = 'a';
    cout << S << endl;
  }
}


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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N;
    cin >> N;
    vector<tuple<int, int, ll>> nodes[N];
    rep(i, N-1){
        int a, b; ll c;
        cin >> a >> b >> c;
        nodes[a-1].push_back(make_tuple(a-1, b-1, c));
        nodes[b-1].push_back(make_tuple(b-1, a-1, c));
    }
    int Q, K;
    cin >> Q >> K;
    ll costs[N]; //nodes[K-1]へのコスト
    costs[K-1] = 0;
    queue<tuple<int, int, ll>> q;
    rep(i, nodes[K-1].size()) q.push(nodes[K-1][i]);
    while(!q.empty()){
        tuple<int, int, ll> op = q.front();
        q.pop();
        int from = get<0>(op);
        int to = get<1>(op);
        ll cost = get<2>(op);
        costs[to] = costs[from] + cost;
        rep(i, nodes[to].size()) if(from != get<1>(nodes[to][i])) q.push(nodes[to][i]);
    }
    vector<ll> ans;
    rep(i, Q){
        int x, y;
        cin >> x >> y;
        ans.push_back(costs[x-1] + costs[y-1]);
    }
    rep(i, Q) cout << ans[i] << endl;
    
    return 0;
}

void solve(){}

Measured memory_bytes: 12312
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define LEN(c) ((int)c.size())
#define DUMP(x) cerr<<#x<<":="<<(x)<<endl
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
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){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    string x;
    cin>>x;
    int n=LEN(x);
    int ans=0,s=0;
    REP(i,n) {
        if(x[i]=='S') {
            s++;
        }
        if(x[i]=='T') {
            if(s==0) ans++;
            else s--;
        }
    }
    cout<<ans+s<<endl;
    return 0;
}


Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int,input().split()))
    
    import heapq
    que = []
    S = sum(A[:N])
    S1 = [S]
    for i in range(N):
        heapq.heappush(que,A[i])
    for i in range(N):
        tmp = A[N+i]
        if que[0] < tmp:
            S -= que[0]
            S += tmp
            heapq.heappop(que)
            heapq.heappush(que,tmp)
        S1.append(S)
    
    S = sum(A[2*N:])
    que = []
    S2 = [S]
    for i in range(N):
        j = 3*N-1-i
        heapq.heappush(que,-A[j])
    for i in range(N):
        j = 2*N-1-i
        tmp = A[j]
        if -que[0] > tmp:
            S -= -que[0]
            S += tmp
            heapq.heappop(que)
            heapq.heappush(que,-tmp)
        S2.append(S)
    ans = -float("inf")
    for i in range(N+1):
        ans = max(ans, S1[i] - S2[N-i])
    print(ans)
    
    
main()

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int A, P;

signed main() {
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
}

Measured memory_bytes: 256
def maxcount(x,y):#x以下の整数でyで割り切れる数
    return x//y
def mincount(x,y):#x未満の整数でyで割り切れる数
    if x%y==0:
        return x//y -1
    else:
        return x//y
from fractions import gcd
a,b,c,d=map(int,input().split())
#全体-(cで割り切れる or dで割り切れる)
tot = b-a+1

div_c = maxcount(b,c)-mincount(a,c)
#print(div_c)
div_d = maxcount(b,d)-mincount(a,d)
#print(div_d)
GCD=gcd(c,d)
lcm=(c*d)//GCD
#print(lcm)

div_both = maxcount(b,lcm)-mincount(a,lcm)
#print(div_both)
ans=tot-(div_c+div_d-div_both)
print(ans)

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

using namespace std;

typedef long long lint;

void test_case() {
    lint n;
    vector<int> ps;
    cin >> n;
    for(lint i=2; i * i <= n; i++) {
        if(n%i==0) {
            int p=0;
            while(n%i==0){
                p++;
                n/=i;
            }
            ps.push_back(p);
        }
    }
    if(n != 1) {
        ps.push_back(1);
    }
    int ans=0;
    for(int i=0; i<ps.size(); i++) {
        for(int j=1; j <= ps[i]; j++) {
            ans++;
            ps[i] -= j;
        }
    }
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int q=1;
    //cin >> q;
    while(q--) {
        test_case();
    }
    return 0;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,K;
llvec X;
ll res=LLINF;

void input() {
	cin>>N>>K;
	init(X,N);
}

void solve() {
	for(int i=0; i<N-K+1; i++) {
		int j=i+K-1, tmp=0;
		if(X[i]*X[j]>=0) {
			chmin(res,max(abs(X[i]),abs(X[j])));
		}
		else {
			chmin(res,X[j]-X[i]+min(abs(X[i]),abs(X[j])));
		}
	}
	cout<<res<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3980
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 2e5 + 5;

int h[maxn], dp[maxn];

int main()
{
	int n; scanf("%d",&n);
	memset(dp, 0x3f, sizeof(dp));
	dp[1] = 0;
	for(int i = 1; i <= n; i++)
		scanf("%d",&h[i]);
	for(int i = 1; i <= n; i++)
	{
		dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
		dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
	}
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int m = max(a, max(b, c));
  
  if(a == m) a*= pow(2, k);
  else if(b == m) b *= pow(2, k);
  else c *= pow(2, k);
  cout << a + b + c << endl;
      
    
  return 0;
}

Measured memory_bytes: 3920
bingo = []
for _ in range(3):
    row = input().split()
    for i in row:
        bingo.append(int(i))
        
N = int(input())

for i in range(N):
    num = int(input())
    bingo = [0 if b == num else b for b in bingo]

if bingo[0] == 0 and bingo[1] == 0 and bingo[2] == 0:
    print('Yes')
elif bingo[0] == 0 and bingo[3] == 0 and bingo[6] == 0:
    print('Yes')
elif bingo[0] == 0 and bingo[4] == 0 and bingo[8] == 0:
    print('Yes')
elif bingo[2] == 0 and bingo[4] == 0 and bingo[6] == 0:
    print('Yes')
elif bingo[2] == 0 and bingo[5] == 0 and bingo[8] == 0:
    print('Yes')
elif bingo[6] == 0 and bingo[7] == 0 and bingo[8] == 0:
    print('Yes')
elif bingo[1] == 0 and bingo[4] == 0 and bingo[7] == 0:
    print('Yes')
elif bingo[3] == 0 and bingo[4] == 0 and bingo[5] == 0:
    print('Yes')
else:
    print('No')

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

string s, s1, s2, s3;

int main(){
    cin >> s1 >> s2 >> s3;
    transform (s1.begin (), s1.end (), s1.begin (), ::toupper);
    transform (s2.begin (), s2.end (), s2.begin (), ::toupper);
    transform (s3.begin (), s3.end (), s3.begin (), ::toupper);
    cout << s1[0] << s2[0] << s3[0] << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sosuu []int
var findsosuu int

func sosuuMake(a int) {

	sosuu = make([]int, 1)
	sosuu[0] = 2
	flg := false
	for i := 3; i < a/2; i++ {
		flg = true
		for j := 0; j < len(sosuu); j++ {
			if i%sosuu[j] == 0 {
				flg = false
				break
			}
		}
		if flg {
			sosuu = append(sosuu, i)
		}

	}
}

func sosuuFind(n int) {

	k := n
	sosuuflg := true
	for findsosuu == 1 {
		sosuuflg = true
		for i := 0; i < len(sosuu); i++ {
			if k%sosuu[i] == 0 {
				sosuuflg = false
				break
			}
		}
		if sosuuflg {
			findsosuu = k
		} else {
			k++
		}
	}

}

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	x, _ := strconv.Atoi(sc.Text())
	findsosuu = 1
	if x > 2 {
		sosuuMake(x)

		go sosuuFind(x)
		for findsosuu == 1 {

		}

	} else {
		findsosuu = 2
	}
	fmt.Println(findsosuu)
}


Measured memory_bytes: 896
#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;
ll const MOD=1e9+7;
using ll = long long;

int main(){
  int n,y;
  cin>>n>>y;
  REP(i,n+1){
    REP(j,n-i+1){
      if(y==10000*i+5000*j+1000*(n-i-j)){
        cout<<i<<" "<<j<<" "<<n-i-j<<endl;
        return 0;
      } 
      else if(i==n){
        cout<<"-1 -1 -1"<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int N, sum = 0;
  cin >> N;
  int n = N;

  REP(i, 8) {
    sum += n % 10;
    n /= 10;
    if (n == 0) break;
  }

  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3556
class ModInt:
    def __init__(self, value, mod=10**9 + 7):
        self.mod = mod
        self.value = value % mod

    def __add__(self, other):
        return ModInt(self.value + int(other) % self.mod, self.mod)

    def __sub__(self, other):
        return ModInt(self.value - int(other) % self.mod, self.mod)

    def __mul__(self, other):
        return ModInt(self.value * int(other) % self.mod, self.mod)

    def __pow__(self, power):
        return ModInt(pow(self.value, int(power), self.mod), self.mod)

    def __int__(self):
        return self.value

    def __str__(self):
        return str(self.value)

def main():
    n, k = map(int, input().split())
    g = [0] * k
    a = ModInt(0)
    for i in range(k, 0, -1):
        c = ModInt(k // i)**n
        for j in range(i * 2, k + 1, i):
            c -= g[j - 1]
        g[i - 1] = c
        a += c * i
    print(a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27044
#include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(x) x.begin(), x.end()
    typedef vector<int> vi;
    typedef pair<int,int> ii;
    typedef long long ll;
     
    const ll inf = 3e18 + 5;
     
    const int MAXN = 1 << 19;
    int N = 400000;
    int seg[2 * MAXN], A[MAXN];
    typedef vector<vi> vvi;
     
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
     
        int W,H,N;
        cin >> W >> H >> N;
        vi x(N),y(N),a(N);
        for(int i=0; i<N; i++)
            cin >> x[i] >> y[i] >> a[i];
        int x1=0,x2=W,y1=0,y2=H;
        for(int i=0; i<N; i++){
            if(a[i]==1 && x[i]>x1)
                x1=x[i];
            else if(a[i]==2 && x[i]<x2)
                x2=x[i];
            else if(a[i]==3 && y[i]>y1)
                y1=y[i];
            else if(a[i]==4 && y[i]<y2)
                y2=y[i];
        }
        int w,h;
        w=x2-x1;
        h=y2-y1;
        if(w<0 || h<0)
            cout << 0;
        else
            cout << w*h;
        
    }

Measured memory_bytes: 256
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import fractions
    import functools

    n = int(input())
    as_ = list(map(int, input().split()))
        
    # gcd = functools.reduce(math.gcd, as_)
    gcm = as_[0]
    for i in range(1, n):
        gcm = gcm * as_[i] // fractions.gcd(gcm, as_[i])
        # print(gcm)
    # print(gcm - 1)
    gcm_1 = gcm - 1
    print(functools.reduce(lambda x, y: x + gcm_1 % y, as_, 0))

if __name__ == '__main__':
    main()

Measured memory_bytes: 5372