akhauriyash/Code-Regression huggingface dataset:
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    k = int(sys.stdin.readline())
    a, b = map(int, sys.stdin.readline().split())
    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            break
    else:
        print("NG")


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


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

int main(){
  int n, l;
  cin >> n >> l;
  int sum = (2*l+n-1)*n/2;
  if(l*(l+n-1)<=0)cout << sum;
  else{
    if(l<0)cout << sum-(l+n-1);
    else cout << sum-l;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long g,q,re=1e18;
    cin>>q;
    for(g=1;g*g<=q;g++)if(q%g==0){
        re=min(re,(g+(q/g))-2);
    }
    cout<<re<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)
    x := nextInt()
    h1 := (x / 500)*1000
    h2 := (x%500/5)*5
    fmt.Println(h1 + h2)
}




//===========================
//
// Library
//
//===========================

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

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

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

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

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 640
#!/usr/bin/env python

from sys import stdin, stderr

def main():
   a, b, c = map(int, stdin.readline().split())

   print('Yes' if c-a-b >= 0 and 4*a*b < (c-a-b)**2 else 'No')

   return 0

if __name__ == '__main__': main()


Measured memory_bytes: 2568
#include <iostream>

using namespace std;
int n;
int dat[100][100];
int cost[100];
int done[100];

void prim(){
	for(int i=0;i<n;i++){
		cost[i]=1<<21;
		done[i]=0;
	}
	int s=0;	
	int next, ncost=1<<21;
	done[s]=1;
	cost[s]=0;
	while(1){
		ncost=1<<21;
		for(int j=0;j<n;j++){
			if(done[j]){
				for(int i=0;i<n;i++){
					if(dat[j][i]!=-1){
						if(cost[i]>=dat[j][i]&&!done[i]){
							cost[i]=dat[j][i];
						}
						if(ncost>cost[i]&&!done[i]){
							next=i;
							ncost=cost[i];
						}
					}
				}
			}
		}
//		cout<<"next:"<<next<<" cost:"<<cost[next]<<endl;
		done[next]=1;
		int flag=true;
		for(int i=0;i<n;i++){
			if(!done[i]) flag = false;
		}
		if(flag)
			return;
	}
}


int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>dat[i][j];
		}
	}
	prim();
	int sum=0;
	for(int i=0;i<n;i++){
		sum+=cost[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1200
import heapq
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**13
def dijkstra(s):
    color = [WHITE for i in range(N)]
    d = [INFTY for i in range(N)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v, c in VC[u]:
            if color[v] != BLACK:
                if d[u] + c < d[v]:
                    d[v] = d[u] + c
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

N = int(input())
VC = [[] for i in range(N)]
for i in range(N):
    ukvc = list(map(int, input().split()))
    u, k, vc = ukvc[0], ukvc[1], ukvc[2:]
    for v, c in zip(vc[0::2], vc[1::2]):
        VC[u].append([v, c])

d = dijkstra(0)

for i in range(N):
    print(i, d[i])



Measured memory_bytes: 76720
#include <stdio.h>
int main(void)
{
    int n,i,ans,multi=0;
    scanf("%d", &n);
    int a[n],sorta[100005];
    for(i=0; i<100005; i++) sorta[i]=0;
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        sorta[a[i]-1]++;
    }
    for(i=0; i<100005; i++)
    {
        if(sorta[i]>1) multi+=(sorta[i]-1);
    }
    if(multi==0) ans=n;
    else if(multi%2==0) ans=n-multi;
    else ans=n-multi-1;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1
#define INF (1<<21)

int n,a[N][N];

int prim(void)
{
  int i,u,v,min,sum=0;
  int d[N],pi[N],color[N];

  for(i=0;i<n;i++){
    d[i]=INF;
    pi[i]=NIL;
    color[i]=WHITE;
  }
  d[0]=0;

  while(1){
    min=INF;
    u=NIL;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<min){
        u=i;
        min=d[i];
      }
    }
    if(u==NIL) break;
    color[u]=BLACK;

    for(v=0;v<n;v++){
      if(color[v]!=BLACK && a[u][v]!=INF){
        if(d[v]>a[u][v]){
          d[v]=a[u][v];
          pi[v]=u;
          color[v]=GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i]!=NIL){
      sum+=a[i][pi[i]];
    }
  }
  return sum;
}

int main(){
  int e,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      a[i][j]=(e==-1)?INF:e;
    }
  }
  printf("%d\n",prim());

  return 0;
}




Measured memory_bytes: 2112
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define deba(a) cout << #a << a << endl;
#define debab(a,b) cout << #a << a << #b << b << endl;
int main()
{
	fast;
	ll n, l;
	cin >> n >> l;
	vector<string> st;
	rep(i, 0, n)
	{
		string s;
		cin >> s;
		st.pb(s);
	}
	sort(all(st));
	for (auto i : st)
		cout << i;
	return 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,i,s=0,k=0,a,b,p;
cin>>n;
if(n==1||n==2)
cout<<0;
else{
    if(n%2==0){
        for(i=1;i<(n/2);i++){
            s++;
        }cout<<s;}
        else{
            for(i=1;i<(n/2)+1;i++){
            s++;
        }cout<<s;
        }
    
}
  return 0;
}


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

using namespace std;

#define MAX(a, b)	(((a) < (b)) ? (b) : (a))

struct Seito {
	int no;
	int	num;
};

bool comp(const Seito &a, const Seito &b)
{
	return a.num < b.num;
}

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

	vector<Seito> A(N);
	for (int i = 0; i < N; i++) {
		A[i].no = i;
		cin >> A[i].num;
	}

	sort(A.begin(), A.end(), comp);
	
	for (int i = 0; i < N; i++) {
		cout << A[i].no + 1 << '\n';
	}

	return 0;

}


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

using namespace std;
using ll = long long;

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

int main() {
  int n, m;
  cin >> m >> m;
  int l = 0;
  int r = 1001001;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    l = max(l, x);
    r = min(r, y);
  }

  int d = r - l + 1;
  d = max(d, 0);
  cout << d << endl;
  return 0;
}


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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int MAXN = 2 * 105000;

int n;
int cnt[MAXN];

int main() {

    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        int boss;
        scanf("%d", &boss);
        cnt[boss]++;
    }

    for (int i = 1; i <= n; i++) {
        printf("%d\n", cnt[i]);
    }

    return 0;
}


Measured memory_bytes: 4504
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll            long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const ll mx = 1e6;
void solve() 
{
    li k,count = 1;
    cin>>k;
    ll num = 7%k;
    while(num && count <=mx)  
    {
        count++;
        num = (num*10+7)%k;
    }
    if(count > mx)  cout<<-1<<endl;
    else
    cout<<count<<endl;
}
int main() {
    ioS
    int t;
    // cin>>t;
    // while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

main(){
    int time;
    int h;
    int m;
    int s;
    scanf("%d", &time);
    h = time / 3600;
    m = (time % 3600) / 60;
    s = time - h*3600 - m*60;
    printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2108
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            double ret = 0;
            for (int i = 0; i < N; i++)
            {
                ret += (1 / inputs[i]);
            }
            Console.WriteLine(1 / ret);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

LL gcd(LL a,LL b) {
    LL bigger = max(a,b);
    LL smaller = min(a,b);
    if (bigger % smaller != 0) {
        return gcd(smaller,(bigger % smaller));
    }
    return smaller;
}

int main(int argc, char const* argv[])
{
    LL n,x;
    cin >> n >> x;
    VL y(n);
    for (int i = 0; i < n; i++) {
        cin >> y[i];
        y[i] = abs(y[i] - x);
    }
    LL a = y[0];
    for (int i = 1; i < n; i++) {
        LL b = y[i];
        a = gcd(a,b);
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

int calc(int k, int[] xs) {
    int[int] d;
    foreach (x; xs) d[x]++;

    int ans = 0;
    auto values = d.values.sort();
    for (int i = 0; i < (cast(int)values.length - k); i++) {
        ans += values[i];
    }
    return ans;
}

void main() {
    auto nk = readints;
    int k = nk[1];
    auto xs = readints;

    int ans = calc(k, xs);
    writeln(ans);
}

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

int n, m, a[50], b[50], ta = 0;

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[j] == i) {
				ta++;
			}
			else if (b[j] == i) {
				ta++;
			}
		}
		cout << ta << endl;
		ta = 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

const int N = 100005;

bool ch[N];
vector<int> g[N];

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

  vector<int> deg(n,0);

  fill(ch, ch+n, false);
  rep(i,n+m-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    ch[b] = true;
    g[a].pb(b);
    deg[b]++;
  }

  int root = 0;
  rep(i,n) if(!ch[i]) root = i;

  vector<int> par(n,0);

  queue<int> que;
  que.push(root);
  while(!que.empty()){
    int v = que.front(); que.pop();
    for(auto to : g[v]){
      deg[to]--;
      if(deg[to]==0){
        par[to] = v+1;
        que.push(to);
      }
    }
  }

  rep(i,n) cout << par[i] << "\n";

  return 0;
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
 ll a,b,k;
  cin>>a>>b>>k;
  if(a>=k) cout<<a-k<<" "<<b;
  else
  {
    if(b>=k-a) cout<<0<<" "<<b-k+a;
    else cout<<0<<" "<<0;

  }
  
  
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = set()

for _ in range(m):
    a.add(int(input()))

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = int(1 not in a)

mod = 10**9 + 7

for i in range(2, n + 1):
    dp[i] = dp[i - 2]*(i - 2 not in a) + dp[i - 1]*(i - 1 not in a)

print(dp[-1] % mod)


Measured memory_bytes: 502580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1e9+7

vll prime_factrize(ll n){
    vll prime_factrize_ret;
    ll temp=n;
    for(ll i=2;i*i<=n;i++){
        while(temp%i==0){
            prime_factrize_ret.push_back(i);
            temp/=i;
        }
    }
    if(temp!=1) prime_factrize_ret.push_back(temp);
    return prime_factrize_ret;
}

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

ll mod_inv(ll n, ll mod){
    return fast_pow(n,mod-2,mod);
}

ll comb(ll n, ll r, ll mod){
    ll temp=1;
    for(int i=r+1;i<=n;i++){
        temp=(temp*i)%mod;
    }
    ll temp2=1;
    for(int i=2;i<=n-r;i++){
        temp2=(temp2*i)%mod;
    }
    return temp*mod_inv(temp2,mod)%mod;
}

struct UnionFind {
    vector<int> r;
    int num;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
        num=N;
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        num--;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    bool same(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return true;
        else return false;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};

int main(){
    int n;
    cin >> n;
    vector<pair<pair<int,int>,int>> x(n), y(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        x[i]={{a,b},i};
        y[i]={{b,a},i};
    }  
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    vector<pair<int,pair<int,int>>> edge;
    for(int i=1;i<n;i++){
        int dist=min(x[i].first.first-x[i-1].first.first,abs(x[i].first.second-x[i-1].first.second));
        edge.push_back({dist,{x[i].second,x[i-1].second}});
        dist=min(y[i].first.first-y[i-1].first.first,abs(y[i].first.second-y[i-1].first.second));
        edge.push_back({dist,{y[i].second,y[i-1].second}});
    }

    sort(edge.begin(),edge.end());

    int ans=0;
    UnionFind uf(n);
    for(auto x:edge){
        //cout << x.first << " " << x.second.first << " " << x.second.second << endl;
        if(uf.same(x.second.first,x.second.second)) continue;
        uf.unite(x.second.first,x.second.second);
        ans+=x.first;
        if(uf.size(0)==n) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8744
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc154/tasks/abc154_e

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
LL A[200001];

LL ans = 0;

void solve(){
	//ループにハマるタイミングを調べる
	LL now = 1;
	vector<LL> used(N+1,-1);
	used[1] = 0;
	LL remain = 0;
	LL roop_size = 0;
	while(1){
		if(used[A[now]]==-1){
			used[A[now]] = used[now] + 1;
			now = A[now];
		}else{
			remain = used[A[now]];
			roop_size = used[now] - used[A[now]] + 1;
			break;
		}
	}
	 // for(int i=1;i<=N;i++){
	 // 	cout << used[i] << " ";
	 // }
	 // cout << endl;
	 // cout << remain << " " << roop_size << endl;
	
	LL counter = K;
	if(counter>remain){
		counter = K - remain;
		counter = counter%roop_size;
		counter += remain;
	}
	// cout << "counter:" << counter << endl;
	now = 1;
	for(LL i=0;i<counter;i++){
		now = A[now];
	}
	ans = now;
}

int main(){
    cin >> N >> K;
    for(int i=1;i<=N;i++) cin >> A[i];

    solve();

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

Measured memory_bytes: 6048
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int min(a, b)
{
    return a < b ? a : b;
}

int main(int argc, char **argv)
{
    int n, k;
    scanf("%d %d", &n, &k);
    int h[n];
    int c[n];
    c[0] = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", h + i);
        if (i == 0) continue;
        int cm = INT_MAX;
        for (int j = 0; j < min(i, k); j++) {
            cm = min(cm, c[i - j - 1] + abs(h[i - j - 1] - h[i]));
        }
        c[i] = cm;
    }
    printf("%d\n", c[n - 1]);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=1e6+5;
const LL mo=998244353;

int n,m;

LL mi(LL x,LL y)
{
	LL re=1;
	for(; y; y>>=1, x=x*x%mo) if (y&1) re=re*x%mo;
	return re;
}

LL fac[4*maxn],ny[4*maxn];
void Pre(int n)
{
	fac[0]=1;
	fo(i,1,n) fac[i]=fac[i-1]*i%mo;
	ny[n]=mi(fac[n],mo-2);
	fd(i,n-1,0) ny[i]=ny[i+1]*(i+1)%mo;
}
LL C(int n,int m) {return (n<m) ?0 :fac[n]*ny[m]%mo*ny[n-m]%mo;}

LL calc(int n,int sum,int m)
{
	LL re=0;
	fo(i,0,m) if (!((sum-i)&1)) (re+=C(n,i)*C((sum-i)/2+n-1,n-1))%=mo;
	return re;
}

int main()
{
	scanf("%d %d",&n,&m);
	
	Pre(3*m+n);
	
	LL ans=calc(n,3*m,m)-(calc(n,m,m)-calc(n-1,m,m))%mo*n;
	
	printf("%lld\n",(ans%mo+mo)%mo);
}

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

int main(){
  int ans=0;
  vector<char> s(3), t(3);
  for (int i = 0; i < 3; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < 3; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < 3; i++) {
    if(s[i]==t[i])
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	
	int i;
 
	/* 文字列 */
	char str[1200];
 
	fgets(str,sizeof(str),stdin);
 
	/* アルファベットの小文字を大文字に変換 */
	for(i=0;i<=strlen(str);i++){
		
		if(str[i]>=97&&str[i]<=122){
			/* アルファベットの小文字なら大文字に変換 */
			str[i]=str[i]-32;
		} else if(str[i]>=65&&str[i]<=90){
			/* アルファベットの大文字なら小文字に変換 */
			str[i]=str[i]+32;
		}
	}
	
	printf("%s", str);
	
	return 0;
}


Measured memory_bytes: 3088
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

prepare_sum = sum(A)
dif_sum = sum(B)
if prepare_sum < dif_sum:
    print(-1)

else:
    husoku = []
    enough = []
    idx = 0
    for a, b in zip(A,B):
        if a < b:
            husoku.append(idx)
        else:
            enough.append(idx)
        idx += 1

    residual = sorted(np.array(A)[enough] - np.array(B)[enough])

    score = 0
    budget = prepare_sum - dif_sum
    for r in residual:
        if r <= budget:
            score += 1
            budget -= r
        else:
            break
    print(len(A) - score)

Measured memory_bytes: 35028
import math

X = int(input())


def explor_B(A):
    tmp = X - A**5
    if tmp < 0:
        B = 0
        while True:
            if abs(B**5) == abs(tmp):
                return True, B
            elif abs(B**5) > abs(tmp):
                return False, 0
            else:
                B += 1  
    else:
        B = -1
        while True:
            if abs(B**5) == abs(tmp):
                return True, B
            elif abs(B**5) > abs(tmp):
                return False, 0
            else:
                B -= 1  

A = 0

while True:
    flag, B = explor_B(A)
    if flag:
        break
    else:
        A += 1

print("{} {}".format(A, B))


Measured memory_bytes: 9124
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
vector<bool> isprime(1000000,true);

void sieve(int n){
  int i,j;
  isprime[0] = isprime[1] = false;
  for(i = 2; i*i <= n; i++) if(isprime[i]){
    for(j = 2*i; j <= n; j += i) isprime[j] = false;
  }
}

int main(){
  int i,j,k,n;
  int in;

  sieve(1000000);

  while(1){
    cin >> in; if(in == 0) break;
    ll sum = 0;
    int cnt = 0;
    for(i = 0; cnt < in; i++) if(isprime[i]){ cnt++; sum += i;}
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
 
const int maxn = 2e5 + 20;

ll a[maxn] , t[maxn];

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

	int n , m;
	cin >> n >> m;

	a[0] = n;
	for(int i = 1; i <= m; i++)
	{
		cin >> a[i];
		int j = i - 1;
		while(j >= 0 && a[i] <= a[j])
			j--;

		a[j + 1] = a[i];
		m -= (i - j - 1);
		i = j + 1;
	}

	map<ll , ll> mp;
	mp[a[m]]++;

	for(int i = m; i > 0; i--)
		while(1)
		{
			ll x = mp.rbegin() -> first , y = mp.rbegin() -> second;
			if(x > a[i - 1])
			{
				if(x % a[i - 1])
					mp[x % a[i - 1]] += y;
				mp[a[i - 1]] += x / a[i - 1] * y;
				mp.erase(x);
			}
			else
				break;
		}

	for(auto x : mp)
		t[x.first] += x.second;

	for(int i = n; i >= 0; i--)
		t[i] += t[i + 1];

	for(int i = 1; i <= n; i++)
		cout << t[i] << endl;
}


















Measured memory_bytes: 9472
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define PB push_back
#define MP make_pair
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>())

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
using ll = long long;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


void Main() {
  ll r;
  IN(r);
  OUT(r*r);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();

  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
        #include<iostream>
        #include<algorithm>
        #include<set>
        #include<map>
        #include<math.h>
        //#include <ttmath.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        using namespace std;
        int power(int x,int y)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2))%modulo;
        if (y%2 == 0)
        return ((temp%modulo)*temp)%modulo;
        else
        return ((x*temp%modulo)*temp)%modulo;
        }
        int inv(int x)
        {
        return (power(x,modulo-2)+modulo)%modulo;
        }
        /*#include "testlib.h"
        int main(int argc, char* argv[])
        {
        iostream::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        registerGen(argc, argv, 1);
        int n,k;
        n=rnd.next(1,50);
        k=rnd.next(1,n);
        cout<<n<<' '<<k;
        }*/
        bool comp(pair<int,int>a,pair<int,int> b)
        {
            return a.second>b.second;
        }
        set<int>lol;
        void factorize(int n){
        if(n==1)
        return;
        for(int i=2;i*i<=n;i++){
        if(n%i==0){
        factorize(n/i);
        lol.insert(i);
        return;
        }
        }
        lol.insert(n);
        }
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input4.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int a,b;
            cin>>a>>b;
            int result=(__gcd(a,b));
            factorize(result);
            cout<<lol.size()+1;
            return 0;
        }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long H,N,A,B,tmp;
cin>>H>>N;
//前と後のデータだけ保持
//2つめはjのダメーずを与える上で最小の魔力
long long dp[2][H+10];
dp[0][0]=0;
dp[1][0]=0;
//初期化
for(long long i=0;i<2;++i){
  for(long long j=1;j<H+10;++j){
    dp[i][j]=10000000000;
  }
}
//1かい目の施行
cin>>A>>B;
for(long long j=1;j<H+10;++j){
  dp[0][j]=B*((j-1)/A+1);
}

for(long long i=1;i<N;++i){
  //iばんめの魔法について
  cin>>A>>B;
  
  for(long long j=0;j<H+10;++j){
    if(j-A>=0){
      tmp=min(dp[0][j-A]+B,dp[0][j]);
      tmp=min(dp[1][j-A]+B,tmp);
      dp[1][j]=tmp;
    }
    else{
      dp[1][j]=min(dp[0][j],dp[1][0]+B);
    }
  }
  //dp tableの更新
  for(long long j=0;j<H+10;++j){
    dp[0][j]=dp[1][j];
    dp[1][j]=1000000000;
  }
  dp[1][0]=0;
}

cout<<dp[0][H]<<"\n";

return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll H, W;
    cin >> H >> W;
    ll a1 = ((W + 1) / 2) * ((H + 1) / 2);
    ll a2 = (W / 2) * (H / 2);

    if (H <= 1 || W <= 1) {
        cout << 1 << endl;
        return 0;
    }

    cout << a1 + a2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int n;
    string s; cin >> n >> s;
    int ans = 0;
    for(int i=0;i<n-2;i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N ;
  cin >> N ;
  string S ;
  int AC = 0, WA = 0, TLE = 0, RE = 0 ; 

  for (int i = 0; i < N; i++) {
    cin >> S ;
    if (S == "AC") {
      AC ++ ;
    } else if (S == "WA") {
      WA ++ ;
    } else if (S == "TLE") {
      TLE ++ ;
    } else if (S == "RE") {
      RE ++ ;
    }
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), B(M);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];
  sort(ALL(A), greater<ll>());
  sort(ALL(B), greater<ll>());

  ll a = 0, b = 0;
  ll ans = 1;
  for (ll x = N*M; x > 0; x--) {
    int cnt = 0;
    if (a < N && x == A[a]) a++, cnt++;
    if (b < M && x == B[b]) b++, cnt++;
    if (cnt == 2) {
      ans *= 1;
    } else if (cnt == 1) {
      if (x == A[a - 1]) ans *= b;
      else ans *= a;
    } else ans *= max(0LL, a*b - (N*M - x));
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
using namespace std;
int n,m,a[15][15],ans;
void read(int &v){int k=0,l=1;char ch;ch=getchar();while (ch>'9' || ch<'0'){if (ch=='-') l=-1;ch=getchar();}while (ch>='0' && ch<='9') k=k*10+ch-'0',ch=getchar();v=l*k;}
void print(int v){if (v<0) putchar('-'),v=-v;if (v>9) print(v/10);putchar(v%10+'0');}
int max(int a, int b) { return a>b ? a: b;}
int min(int a, int b) { return a<b ? a: b;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			int sum=0;
			for(int k=1;k<=m;k++)
				sum+=sqr(a[i][k]-a[j][k]);
			int t=(int)sqrt(sum);
			if(t*t==sum)ans++;
		}
	printf("%d",ans);
	return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

int n , k ;
int s = 0 ;
int ans = 0 ;
vi v ;

void f ( int d ) // divisor of the sum of numbers i.e s
{
    vi rem ( n ) ; // contains all the remainders
    for ( int i=0 ; i < n ; i++ )
        rem[i] = v[i] % d ;

    sort ( all ( rem ) ) ;

    int i=0 ;
    for ( ; i < n && rem[i] == 0 ; i++ ) ;

    if ( i == n ) { ans = max ( ans , d ) ; return ; }

    int j = n-1 ;
    int operations = 0 ;

    for ( ; i <= j ; )
    {
        int t = min ( rem[i] , d - rem[j] ) ;

        rem[i] -= t ;
        rem[j] += t ;

        if ( rem[i] == 0 ) i++ ;
        else j-- ;

        operations += t ;
    }

    // if ( d == 28 ) { cout << operations ; line ; }
    if ( operations > k ) return ;
    ans = max ( ans , d ) ;
}

void solve ( int test_case )
{
    cin >> n >> k ;
    v.resize ( n ) ;
    for ( int i=0 ; i < n ; i++ )
    {
        cin >> v[i] ;
        s += v[i] ;
    }

    for ( int i=1 ; i*i <= s ; i++ )
    {
        if ( s % i ) C ;

        f ( i ) ;
        f ( s / i ) ;
    }

    cout << ans ; line

}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}


Measured memory_bytes: 2044
//B - Comparison 2017/04/22
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef unsigned long long ull;

int main(){
    string a,b;
    cin >> a >> b;
    int len_a=a.length(); int len_b=b.length();
    if(len_a > len_b) { cout << "GREATER" << endl; return 0;}
    else if (len_a < len_b) { cout << "LESS" << endl; return 0;}
    else {
        for(int i=0;i<len_a;++i){
            if(a[i]>b[i]){cout << "GREATER" << endl; return 0;}
            else if(a[i]<b[i]){cout << "LESS" << endl; return 0;}
        }
        cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
long long Q,H,S,D,N,Ans;
int main(){
	scanf("%lld%lld%lld%lld",&Q,&H,&S,&D);
	if (2*Q<H) H = 2*Q;
	if (2*H<S) S = 2*H;
	if (2*S<D) D = 2*S;
	scanf("%lld",&N);
	N = N * 4; 
	Ans = 0;
	Ans = Ans + N / 8 * D;
	N = N % 8;
	Ans = Ans + N / 4 * S;
	N = N % 4;
	Ans = Ans + N / 2 * H;
	N = N % 2;
	Ans = Ans + N / 1 * Q;
	printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	int n=scan.nextInt();
         	for(int i=0;i<10;i++){
         		if(n%2==1){
         		System.out.print((int)Math.pow(2,i));
         		if(i!=9&&n!=1)System.out.print(" ");
         		}
         		n/=2;
         	}
         	System.out.println();
        }
    }
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

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

  ll N;
  cin >> N;
  map <ll, ll> m;
  m = prime_factor(N);

  int cnt = 0;
  for (auto ite = m.begin(); ite != m.end(); ite++) {
    for (int i = 1; i <= ite->_2; i++) {
      cnt++;
      if (i*(i+1) > ite->_2*2) {
        cnt--;
        break;
      }
    }
    // cout << ite->_1 << ' ' << ite->_2 << endl;
  }
  cout << cnt << endl;
}


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

int cnt[200][200];
int n;
string s;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      cnt[i][(int)s[j]]++;
    }
  }
  for(int i = 'a'; i <= 'z'; i++) {
    int mx = 1e9 + 10;
    for(int j = 0; j < n; j++) {
      mx = min(mx, cnt[j][i]);
    }
    for(int j = 0; j < mx; j++) {
      printf("%c", (char)i);
    }
  }
  puts("");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int a=0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      a+=vec.at(i)*vec.at(j);
    }
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int maxn=2e3+5;
map<int,int>mp;
int dis[maxn][maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            dis[i][j]=j-i;
        }
    }

    for(int i=1;i<=x;i++)//左到中
    {
        for(int j=x+1;j<y;j++)
        {
            dis[i][j]=min(dis[i][j],y-j+1+x-i);
        }
    }
    //中到中
    for(int i=x+1;i<y-1;i++)
    {
        for(int j=i+1;j<=y-1;j++)
        {
            dis[i][j]=min(dis[i][j],y-j+1+i-x);
        }
    }
    for(int i=1;i<=x;i++)//左到右
    {
        for(int j=y;j<=n;j++)
        {
            dis[i][j]-=y-x-1;
        }
    }
    for(int i=x+1;i<=y-1;i++)//中到右
    {
        for(int j=y;j<=n;j++)
        {
            dis[i][j]=min(dis[i][j],i-x+1+j-y);
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            mp[dis[i][j]]++;
        }
    }
    for(int i=1;i<n;i++)
    {
        cout<<mp[i]<<'\n';
    }







}




Measured memory_bytes: 15488
from itertools import product

def calc(x):
    c = 0; y = 1
    while 1:
        if abs(x - y) <= (y - 1) // 2:
            R = [0]*(c+1)
            R[c] = 1
            if x < y:
                r = calc(y - x)
                for i in range(len(r)):
                    R[i] = -r[i]
            elif x > y:
                r = calc(x - y)
                for i in range(len(r)):
                    R[i] = r[i]
            return R
        y *= 3
        c += 1
print(*map({-1: '-', 0: '0', 1: '+'}.__getitem__, reversed(calc(int(input())))), sep='')


Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, a, sum = 0;
  cin >> n;
  rep(i,n)
  {
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      sum++;
    }
  }
  cout << sum;
}


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

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N = 1000;
const int M = 1000010;

int a[N], dp[M] = {}, dp1[M] = {};

void prepare()
{
    rep(i, N) a[i] = 1;
    rep(i, N - 1) a[i + 1] += a[i];
    rep(i, N - 1) a[i + 1] += a[i];
    rep(i, N - 1) a[i + 1] += a[i];

    repi(i, 1, M) dp[i] = dp1[i] = M;

    rep(i, N) {
        if (a[i] >= M) break;
        for (int j = a[i]; j < M; ++j) {
            dp[j] = min(dp[j], dp[j - a[i]] + 1);
            if (a[i] & 1) dp1[j] = min(dp1[j], dp1[j - a[i]] + 1);
        }
    }
}

int main()
{
    prepare();

    int n;
    while (cin >> n and n) {
        cout << dp[n] << ' ' << dp1[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 8976
n=int(input())
s=[]
for _ in range(n):
    s.append(int(input()))
su=sum(s)
ans=-float('inf')
if su%10:
    ans=su
    print(ans)
    import sys
    sys.exit()
for i in s:
    if i%10:
        ans=max(ans,su-i)
if ans==-float('inf'):
    ans=0
print(ans) if ans%10 else print(0)



Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
	int i;
	char s[1024], temp;
	for (i = 0; (temp = getchar()) != '\n'; i++) {
		if (temp <= 'z' && temp >= 'a') {
			s[i] = temp + ('A' - 'a');
		}
		else {
			s[i] = temp;
		}
	}
	s[i] = EOF;
	for (i = 0; s[i] != EOF; i++)
		printf("%c", s[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 900
//don't go gentle into
// the goodnight.

#include<bits/stdc++.h>
using namespace std;

#define int       long long
#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define i_m_speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
    }
    return r;
}
void solve(){
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    int maxx,minn;
    if(n%2){
        minn = a[n/2];
        maxx = b[n/2];
    }
    else{
        minn = a[n/2-1]+a[n/2];
        maxx = b[n/2-1]+b[n/2];
    }
    cout << maxx-minn+1 << endl;
    return;
}
int32_t main(){
    i_m_speed
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 6732
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<stack>
#include<cmath>
//#define ll long long
using namespace std;
const int maxn=100010;
const int INF=1000000000;
int a[maxn][3];
int dp[maxn][3];

int main()
{
    int n,i,j,k,ans,sum=0,temp=4;
    cin>>n;
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    for(i=0;i<3;i++)
    {
        dp[0][i]=a[0][i];
    }
    for(i=1;i<n;i++)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 2560