akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    long N = sc.nextLong();
	    sc.close();

	    String S = Long.toString(N);
	    
	    
	    if (N<19)
	    	System.out.println(Math.min(N, 9));
	    
	    
	    else {
	    	boolean check_1= false;
	    	boolean check_9=false;
	    	
	    	if (S.charAt(0)=='1'){
	    		check_1=true;
	    	}
	    	if (S.charAt(S.length()-1)=='9'){
	    		check_9=true;
	    	}
	    
	    	int nine = 9*(S.length()-1);
	    	int temp = 0;
	    	for (int i=0; i<S.length(); i++){
	    		temp+=Character.getNumericValue(S.charAt(i));
	    	}
	    
	    	if (check_1==false && check_9==false) {
	    		System.out.println(nine+Character.getNumericValue(S.charAt(0))-1);
	    	}
	    	else if (check_9==true)
	    		System.out.println(Math.max(temp,nine+Character.getNumericValue(S.charAt(0))));
	    	else
	    		System.out.println(nine);
	    }
	}

}


Measured memory_bytes: 23892
def main():
	# n,m = map(int,input().split())
	n = int(input())
	s = str(input())
	# a = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# print(s+s)
	if s[:(int(n/2))] + s[:int(n/2)] == s:
		print("Yes")

	else:
		print("No")


if __name__ == '__main__':
	main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int d(int n){
	if(n==0) return 0;
	return n%10+d(n/10);
}
int32_t main(){
	int n,a,b,ans=0;cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		ans+=(d(i)>=a&&d(i)<=b)*i;
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;

typedef long long ll;

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

    ll a[N];
    for (int i = 0; i < N; ++i) {
        scanf("%lld", &a[i]);
    }

    sort(a, a + N, greater<ll>());

    map<ll, int> m;
    for (int i = 0; i < N; ++i) {
        if (m.find(a[i]) == m.end()) {
            m.insert(make_pair(a[i], 1));
        } else {
            map<ll, int>::iterator it = m.find(a[i]);
            // printf("%d\n", it->second);
            m[a[i]] = it->second + 1;
        }
    }

    map<ll, int>::reverse_iterator it = m.rbegin();
    ll h = 0;
    ll v = 0;
    for (it = m.rbegin(); it != m.rend(); ++it) {
        if (it->second >= 4) {
            if (h == 0) h = it->first;
            if (v == 0) v = it->first;
        }
        else if (it->second >= 2) {
            if (h == 0) h = it->first;
            else if (v == 0) v = it->first;
            else {}
        }
        else {}

        if (h != 0 && v != 0) break;
    }

    printf("%lld\n", h * v);

    return 0;
}


Measured memory_bytes: 7296
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

priority_queue<pair<int, int>, std::vector<pair<int, int> >, std::greater<pair<int, int> > > Q;
vector<pair<int, int> > adj[100000];
int dist[100000], v, u, q, D, K;

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

	for (int i = 0; i < K; i++) {
		adj[i].push_back(make_pair(0, (i * 10) % K));
		adj[i].push_back(make_pair(1, (i + 1) % K));
	}
	
	for (int i = 0; i < K; i++) {
		dist[i] = 1000000;
	}
	dist[1] = 1;

	Q.push(make_pair(0, 1));

	while(1){
		v = Q.top().second;
		Q.pop();
		for (int i = 0; i < adj[v].size(); i++) {
			u = adj[v][i].second;
			D = dist[v] + adj[v][i].first;
			if (u == 0) {
				printf("%d\n", D);
				return 0;
			}
			if (dist[u] > D) {
				dist[u] = D;
				Q.push(make_pair(dist[u], u));
			}
		}

	}

}

Measured memory_bytes: 6780
#include <stdio.h>
int main()
{
    int a, b, x;
    int ans = 0;
    scanf("%d %d %d", &a, &b, &x);
    for (int i = a; i <= b; i++)
    {
        if (i % x == 0)
        {
            ans++;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 1676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<map<char, int> > vm(n);
  rep(i, 0, n) {
    string s;
    cin >> s;
    int L = s.size();
    rep(j, 0, L)
      vm[i][s[j]]++;
  }
  
  vector<int> b(26, 51);
  rep(i, 0, n) {
    rep(j, 0, 26) {
      b[j] = min(b[j], vm[i][j+'a']);
    }
  }
  
  rep(i, 0, 26) {
    rep(j, 0, b[i]) {
      cout << char(i+'a');
    }
  }
  cout << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int h,w;
int a[85][85];
int b[85][85];
int c[85][85];
bool d[12810][85][85]={};
int main(){
	cin>>h>>w;
	REP(i,h){
		REP(j,w){
			cin>>a[i][j];
		}
	}
	REP(i,h){
		REP(j,w){
			cin>>b[i][j];
			c[i][j]=abs(a[i][j]-b[i][j]);
		}
	}
	d[c[0][0]][0][0]=1;
	REP(i,h){
		REP(j,w){
			//if(i==0&&j==0)continue;
			if(i!=0){
				for(int t=0;t<12810;t++){
					if(d[t][i-1][j]){
						d[t+c[i][j]][i][j]=1;
						d[abs(t-c[i][j])][i][j]=1;
					}
				}
			}
			if(j!=0){
				for(int t=0;t<12810;t++){
					if(d[t][i][j-1]){
						d[t+c[i][j]][i][j]=1;
						d[abs(t-c[i][j])][i][j]=1;
					}
				}
			}
		}
	}
	for(int i=0;i<12810;i++){
		if(d[i][h-1][w-1]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 90496
def resolve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()
    ans = 0
    for start in range(K):
        dp = [[0] * 3 for _ in range(2)]
        switch = 0
        for i in range(start, len(T), K):
            hand = T[i]
            dp[1][0] = max(dp[0][1], dp[0][2])
            dp[1][1] = max(dp[0][0], dp[0][2])
            dp[1][2] = max(dp[0][0], dp[0][1])
            if hand == 's':
                dp[1][0] += R
            elif hand == 'p':
                dp[1][1] += S
            else:
                dp[1][2] += P
            dp[0][:] = dp[1]
        ans += max(dp[1])
    print(ans)
resolve()

Measured memory_bytes: 47580
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

i = 0
A = 0
B = 0
while i < N:
    A += a[i]
    if i+1 < N:
        B += a[i+1]
    i += 2
print(A - B)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

namespace AOJ
{
    class Program
    {
        private static int judge(int a, int b)
        {
            if (a == b) { return 0; }
            if (a > b && a - 1 == b) { return -1; }
            if (a < b && b - 1 == a) { return 1; }
            if (a > b) return 1;
            else return -1;
        }

        private static void solve(int[] hand)
        {
            
            int win_hand = 0;
            for (int i = 1; i < 5; i++)
            {
                int j = judge(hand[i - 1], hand[i]);
                if (j == 0) continue;
                int tmp = (j > 0) ? hand[i - 1] : hand[i];

                if (win_hand != 0 && win_hand != tmp)
                {
                    win_hand = 0;
                    break;
                }
                win_hand = tmp;
            }

            for (int i = 0; i < 5; i++)
            {
                if (win_hand == 0) Console.WriteLine(3);
                else Console.WriteLine((win_hand == hand[i]) ? 1 : 2);
            }
        }
        
        static void Main(string[] args)
        {
            int[] hand = new int[5];

            while (true) { 
                for (int i = 0; i < 5; i++)
                {
                    hand[i] = int.Parse(Console.ReadLine());
                    if (hand[i] == 0) return;
                }
                solve(hand);
            }
        }
    }
}

Measured memory_bytes: 5584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k;i <= n+1;i++){
    ans += (i*(2*n-i+1)/2 - i*(i-1)/2 +1);
    ans %= mod;
  
    //ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = null;
         int[][] grid = new int[3][3];
         for(int i=0; i < 3; i++)
            grid[i] = readArr(3, infile, st);
         int N = Integer.parseInt(infile.readLine());
         HashSet<Integer> set = new HashSet<Integer>();
         while(N-->0)
            set.add(Integer.parseInt(infile.readLine()));
         boolean[][] marked = new boolean[3][3];
         for(int r=0; r < 3; r++)
            for(int c=0; c < 3; c++)
               if(set.contains(grid[r][c]))
                  marked[r][c] = true;
         String res = "No";
         for(int r=0; r < 3; r++)
         {
            int cnt = 0;
            for(boolean b: marked[r])
               if(b)
                  cnt++;
            if(cnt==3)
               res = "Yes";
         }
         for(int c=0; c < 3; c++)
         {
            int cnt = 0;
            for(int r=0; r < 3; r++)   
               if(marked[r][c])
                  cnt++;
            if(cnt==3)
               res = "Yes";
         }
         if(marked[0][0]&&marked[1][1]&&marked[2][2])
            res = "Yes";
         if(marked[2][0]&&marked[1][1]&&marked[0][2])
            res = "Yes";
         System.out.println(res);
      }
      public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
      {
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         return arr;
      }
   }

Measured memory_bytes: 22484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long answer = (n - 2) * 180;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27428
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;cin>>n;
    vector<int> v(n),d(n);
    rep(i,n)cin>>v[i];
    rep(i,n){
        if(i-v[i]+1 < 0){
            cout << -1 << endl;
            return 0;
        }
        d[i] = i-v[i]+1;
    }
    vector<int> ans;
    rep(i,n){
        int index = -1;
        rep(j,n){
            if(d[j]==0)index = j;
        }
        if(index != -1){
            for(int j = index; j < n;j++)d[j]--;
            ans.push_back(v[index]);
        }
    }
    if (ans.size()!=n){
       cout << -1 << endl;
        return 0;
    }
    rep(i,n){
        cout << ans[n-1-i] << endl;
    }
}



Measured memory_bytes: 256
import statistics

N = int(input())

A = list(map(int, input().split()))
c = 0

B = [A[i]-(i+1) for i in range(len(A))]
b = int(statistics.median(B))

for i, a in enumerate(A):
    c += abs(a - (b + i+1))

print(c)


Measured memory_bytes: 27256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int s[210][210],f1[210][210][210],f2[210][210][210],n,m;
char a[210][210];
bool chk(int x1,int y1,int x2,int y2){
	int tmp=s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
	return tmp==0||tmp==(x2-x1+1)*(y2-y1+1);
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i]+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(a[i][j]=='.');
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			for(int k=m;k;k--){
				if(k<m&&f1[i][j][k+1]&&chk(i,k,j,f1[i][j][k+1])) f1[i][j][k]=f1[i][j][k+1];
				else if(chk(i,k,j,k)) f1[i][j][k]=k;
			}
	for(int i=1;i<=m;i++)
		for(int j=i;j<=m;j++)
			for(int k=n;k;k--)
				if(k<n&&f2[i][j][k+1]&&chk(k,i,f2[i][j][k+1],j)) f2[i][j][k]=f2[i][j][k+1];
				else if(chk(k,i,k,j)) f2[i][j][k]=k;
	if(f1[1][n][1]==m){
		puts("0");
		return 0;
	}
	int ans=1;
	while(1){
		for(int i=1;i<=n;i++)
			for(int j=i;j<=n;j++)
				for(int k=1;k<=m;k++)
					if(f1[i][j][f1[i][j][k]+1]>0) 
						f1[i][j][k]=f1[i][j][f1[i][j][k]+1];
		for(int i=1;i<=m;i++)
			for(int j=i;j<=m;j++)
				for(int k=1;k<=n;k++)
					if(f2[i][j][f2[i][j][k]+1]) f2[i][j][k]=f2[i][j][f2[i][j][k]+1];
		for(int x=1;x<=n;x++)
			for(int y=1;y<=m;y++){
				int now=m;
				for(int i=x;i<=n;i++){
					while(now&&f2[y][now][x]<i) now--;
					f1[x][i][y]=max(f1[x][i][y],now);
				}
				now=n;
				for(int i=y;i<=m;i++){
					while(now&&f1[x][now][y]<i) now--;
					f2[y][i][x]=max(f2[y][i][x],now);
				}
			}
		if(f1[1][n][1]==m){
			cout<<ans<<'\n';
			return 0;
		}
		ans++;
	}
	return 0;
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

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

main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];

  sort(rall(a));

  //rep(i,n) cout << a[i];

  int b = 0, c = 0;
  rep(i,n) if(i%2==0) b+=a[i]; else c+=a[i];
  cout << b-c << endl;
}

Measured memory_bytes: 256
#%%
import bisect

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]


for i in range(q):
    st = x[i]
    #print('----------------')
    #print(st)

    #s_t
    sr = bisect.bisect_left(s, st)
    sl = sr - 1
    ans_s = 10**20
    for j in [sr, sl]:
        if 0 <= j <= a-1:
            tmp = abs(st - s[j])
            tr = bisect.bisect_left(t, s[j])
            tl = tr - 1
            for k in [tr, tl]:
                if 0 <= k <= b-1:
                    #print(tmp+abs(s[j] - t[k]))
                    ans_s = min(ans_s, tmp+abs(s[j] - t[k]))
    #print(' ')
    #t_s
    tr = bisect.bisect_left(t, st)
    tl = tr - 1
    ans_t = 10**20
    for j in [tr, tl]:
        if 0 <= j <= b-1:
            tmp = abs(st - t[j])
            sr = bisect.bisect_left(s, t[j])
            sl = sr - 1
            for k in [sr, sl]:
                if 0 <= k <= a-1:
                    #print(tmp+abs(s[k] - t[j]))
                    ans_t = min(ans_t, tmp+abs(s[k] - t[j]))
    
    print(min(ans_s, ans_t))
    #print('---------------------')

Measured memory_bytes: 16164
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	string s;cin>>s;
	lint n=s.size(),ans=0,ctr=0;
	rep(i,n)if(s[i]=='W'){
		ans+=i-ctr;
		++ctr;
	}cout<<ans<<endl;
}

//sub-EOF


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



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

}



ll mypower(ll x, ll n){
    ll answer=1;
    rep(i,n){
        answer*=x;
    }
    return answer;
}

    






int main(){

    ll n;
    cin>>n;

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

    ll q;
    cin>>q;


    map<ll,ll> mymap;
    rep(i,n){
        if (mymap.find(data.at(i))==mymap.end()){
            mymap[data.at(i)]=1;
        }
        else {
            mymap.at(data.at(i))++;
        }

    }








    ll answer=0;

    rep(i,n){
        answer+=data.at(i);
    }






    rep(i,q){
      	ll b,c;
        cin>>b>>c;

        if (mymap.find(b)==mymap.end()){
            cout<<answer<<endl;
        }
        else {
            if (mymap.find(c)==mymap.end()){
                mymap[c]=mymap.at(b);
                answer=answer-b*mymap.at(b)+c*mymap.at(b);
                cout<<answer<<endl;
                mymap.at(b)=0;
                
            }
            else {
                mymap.at(c)+=mymap.at(b);
                answer=answer-b*mymap.at(b)+c*mymap.at(b);
                cout<<answer<<endl;
                mymap.at(b)=0;
                
            }



        }



    }

    


}

Measured memory_bytes: 8980
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

const int N = 1e6 + 11;
bool isprime[N], dp[N];
vector<int> primes;

void solve(){
	fill(isprime + 2, isprime + N, true);
  for(int i = 2; i < N; i++){
	   if (isprime[i]){
		   primes.push_back(i);
		   for(int j = 2 ; i * j < N; j ++){
			  isprime[i * j] = false;   
			 }  
		 } 
	 }
  int n;
  while(cin >> n, n){
	int ret = 0;
	for(int i = 0; i < n; i++)  
		 ret += primes[i];
	cout << ret << endl;
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 4744
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int x,max = 1;
    cin >> x;
    if(x == 1){cout << 1 << endl; return 0;}
    for(int i = 2;i <= x;i++)
    {
        for(int j = 2;;j++)
        {
            if(pow(i,j) > x){break;}
            else{if(max < pow(i,j)){max = pow(i,j);}}
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
const int N = 5005;
int fact[N], invfact[N];
int n,k ;
void pre(){
   fact[0] = 1;
   invfact[0] = modinv(fact[0]);
   for(int i = 1; i < N ; i++){
	     fact[i] = i * fact[i-1];
	     fact[i] %= MOD;
	     invfact[i] = modinv(fact[i]); 
	  }	
}
int nCr(int n,int r){
  if(r > n)
     return 0;
  int ret = fact[n];
  ret *= invfact[n-r];
  ret %= MOD;
  ret *= invfact[r];
  ret %= MOD;
  return ret;  	
}
void solve(){
	pre();
	cin >> n >> k;
	int blue = k, red = n - k;
	for(int i = 1; i <= k; i++){
	   int ret = nCr(red + 1, i);
	   int y = nCr(blue - 1,i - 1);
	   ret *= y;
	   ret %= MOD;
	   cout << ret << endl; 	
	}
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
 
int n, T, a, s, en, st, i;
int main()
{
	cin >> n >> T;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a);
		if (en < a) {
			s += en - st;
			st = a;
		}
		en = a + T;
	}
	s += en - st;
	cout << s;
    return 0;
}

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;
using P = pair<int,int>;

int x[505][505],a[100010],b[100010];

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    rep(i,m){
        int l,r;
        cin>>l>>r;
        x[l][r]++;
    }
    for(int i=1; i<=n; ++i){
        for(int j=2; j<=n; ++j){
            x[i][j]+=x[i][j-1];
        }
    }
    rep(i,q)cin>>a[i]>>b[i];
    rep(i,q){
        int ans=0;
        for(int j=a[i]; j<=b[i]; ++j){
            ans+=x[j][b[i]];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5384
#include<stdio.h>

int main()
{
 int n,k,x,y,f1,f2,f;

 scanf("%d%d%d%d",&n,&k,&x,&y);

 if(k<n)
 {
     f1=k*x;
     f2=(n-k)*y;

     f=f1+f2;

     printf("\n%d\n",f);
 }

 else
 {
   f=n*x;

   printf("\n%d\n",f);
 }

 return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int check(vector<int> tanka){
	int roule[] = {5,7,5,7,7};
	int index = 0, i = 0, t = 0;
	int sum = 0;
	while(i < 5){
		do{
			sum += tanka[index+t];
			t++;
		}while(sum < roule[i]);
		if(sum > roule[i]){
			index++;
			i = 0;
			t = 0;
		}else{
			i++;
		}
		sum = 0;
	}
	return index+1;
}

int main(){
	vector<int> tanka;
	vector<int> res;
	int n;
	do{
		cin >> n;
		for(int i=0;i<n;i++){
			string tmp;
			cin >> tmp;
			tanka.push_back(tmp.size());
		}
		if(n > 0)
			res.push_back(check(tanka));
		tanka.clear();
		tanka.shrink_to_fit();
	}while(n > 0);

	for(auto num : res){
		cout << num << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
 
void solve(){
  int main,temp,count=0;
  cin>>main;

  temp=floor(main/500);
  main=main-temp*500;
  count=count+temp*1000;
  count=count+floor(main/5)*5;
  cout<<count;
  return;

}



int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int t=1;
  //cin>>t;
  while(t--) solve();
}


Measured memory_bytes: 3648
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, fromMaybe)
import qualified Data.Map.Strict as M


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

type PQ = M.Map Int Int
fromListPQ :: [Int] -> PQ
fromListPQ nums = foldr insertPQ M.empty nums

toListPQ :: PQ -> [(Int, Int)]
toListPQ pq =  M.toList pq

insertPQ :: Int -> PQ -> PQ
insertPQ n pq = case M.lookup n pq of
    Nothing -> M.insert n 1 pq
    Just a -> M.insert n (a + 1) pq

takePQ :: Int -> PQ -> PQ
takePQ n pq = let
    updator old = if old < 2 then Nothing else Just $ old - 1
    in
        M.update updator n pq

getLargest :: PQ -> Int
getLargest pq = fst  $ M.findMax pq

modifyLargest :: (Int -> Int) -> PQ -> PQ
modifyLargest f pq = let
    largest = getLargest pq
    deleted = takePQ largest pq
    newVal = f largest
    in 
        insertPQ newVal deleted


solve :: [Int] -> Int -> Int
solve as waribiki = let
    inner :: PQ -> Int -> Int
    inner pq 0 = sum $ (\(num, count) ->  num * count) <$>  toListPQ pq
    inner pq waribiki = inner (modifyLargest (`div`2) pq) $ waribiki - 1
    in
        inner (fromListPQ as) waribiki

main = do
    (n, m) <- readTuple2
    as <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    print $ solve as m


Measured memory_bytes: 19836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector <ll> vi;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
#define mod 1000000007
#define pb push_back
ll max3(ll a,ll b,ll c)
{
    return max(max(a,b),max(a,c));
}
int main()
{
    ll n,W;
    cin>>n>>W;
    ll we[n+1];
    ll v[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>we[i]>>v[i];
    }
    ll dp[n+1][W+1];
    for(ll i=0;i<=W;i++)
    {
        dp[0][i]=0;
    }
    for(ll i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(ll w=1;w<=W;w++)
    {
        for(ll i=1;i<=n;i++)
        {
            if(we[i]<=w)
            dp[i][w]=max(dp[i-1][w],dp[i-1][w-we[i]]+v[i]);
            else
                dp[i][w]=dp[i-1][w];
        }
    }
    cout<<dp[n][W]<<endl;
}


Measured memory_bytes: 79104
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>


using namespace std;

int main() {

	int q[11] = {6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2};

	string input;
	cin >> input;

	int qpoint;
	int sum = 0;

	for(int i=0; i<12; i++) {
		if(input[i] == '?')
			qpoint = i;
		else if(i < 11)
			sum += ((int)input[i] - '0') * q[i];
	}

	int ans;
	bool check = false;
	int temp;
	if(qpoint == 11)
		ans = 11 - sum%11;
		if(ans > 9) ans = 0;
	else {
		for(int i=0; i<10; i++) {
			temp = 11 - (sum + i*q[qpoint])%11;
			if(temp > 9) temp = 0;
			if(temp == (int)(input[11] - '0')) {
				if(check == true) {
					cout << "MULTIPLE" << endl;
					return 0;
				}
				ans = i;
				check = true;
			}
		}
	}

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

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

signed main()
{
   int N, A, B; cin >> N >> A >> B;

   if (N < A+B-1 || A*B < N) {
      cout << -1 << endl;
      return 0;
   }

   if (B == 1) {
      if (N != A) {
         cout << -1 << endl;
         return 0;
      }
      FORE(i, 1, N) {
         cout << i << " ";
      }
      cout << endl;
      return 0;
   }

   int D = A*B - N;
   int p = D / (B-1), q = D % (B-1);
   V<int> ans;
   FORE(i, 1, p) {
      ans.PB(i);
   }
   RFORE(i, 1, B-q) {
      ans.PB(p+i);
   }
   FOR(i, 0, A-(p+1)) {
      RFORE(j, 1, B) {
         ans.PB(p+B-q + B*i+j);
      }
   }
   REP(i, SZ(ans)) {
      cout << ans[i] << " ";
   }
   cout << endl;

   return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	string x,y;
	std::cin >> x >> y;
	for (size_t i = 0; i < y.size(); i++) {
		std::cout << x[i] << y[i];
	}
	if (x.size() > y.size()) {
		std::cout << x[x.size() - 1];
	}
	std::cout << '\n';

	return 0;
}


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

const ll INF = 1e18L + 33;
int n,w,suma_wart;
int waga[103], val[103];
ll dp[(int) 1e5 + 33];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> w;
	for(int i = 1; i <= n; i++) {
		cin >> waga[i] >> val[i];
		suma_wart += val[i];
	}
	//cout << suma_wart << endl;
	fill(dp, dp + suma_wart + 5, INF);
	dp[0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = suma_wart - val[i]; j >= 0; j--) {
			dp[j + val[i]] = min(dp[j + val[i]], dp[j] + waga[i]);
		}
	}

	ll wy = 0;	

	for(int i = 0; i <= suma_wart; i++) {
	//	cout << i << ": " << dp[i] << "\n";
		if(dp[i] <= w)
			wy = max(wy, (ll) i);
	}
	cout << wy ;
}

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

int a[100000];
int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	ll A=2,B=2;
	for(int i=n-1;i>=0;i--){
		A=(A+a[i]-1)/a[i]*a[i];
		B=(B/a[i])*a[i]+a[i]-1;
	}
	if(A>B){
		puts("-1");
	}
	else cout<<A<<' '<<B<<endl;
}

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

int main()
{
  int h,w;cin>>h>>w;
  vector<vector<char>> C(2*h,vector<char>(w));
  for (int i=0;i<h;i++)
  {
    for (int j=0;j<w;j++)
    {
      char c;cin>>c;
      C[2*i][j]= c;
      C[2*i+1][j]=c;
    }
  }
  
  for (int i=0;i<2*h;i++)
  {
    for(int j=0;j<w;j++)
    {
      cout<<C[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin >> n;
    vi c(n), s(n), f(n);
    rep(i, 0, n - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, 0, n)
    {
        int time = s[i];
        rep(j, i, n - 1)
        {
            if (time <= s[j])
            {
                time = s[j];
            }
            else
            {
                time += f[j] - ((time - 1) % f[j]) - 1;
            }
            //cout << "start" << time << endl;
            time += c[j];
            //cout << "arrive" << time << endl;
        }
        cout << time << endl;
    }
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define FOR2(i,a,b) for (int i=(a);i<(b);i++)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define ROF2(i,x,y) for(int i = (y) ; i >= (x) ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define FAST ios_base::sync_with_stdio(false); cin.tie(0)

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

template<class T>
ostream &operator<<(ostream &os,const vector<T> &x) {
    os << '[';
    if ( !x.empty() ) {
        std::copy (x.begin(), x.end(), std::ostream_iterator<T>(os, ","));
        os << "\b";
    }
    os << "]";
    return os;
}
template<class T>
ostream &operator<<(ostream &os,const vector<vector<T> > &x) {
    os << '[';
    if ( !x.empty() ) {
        os << x[0];
        for (int i=1;i<x.size();i++) os << endl << " " << x[i];
    } else os << "[]";
    os << "]";
    return os;
}

int main() {
    FAST;
   // freopen ("in.txt", "r", stdin);
    string s,t;
    cin>>s>>t;
    int i=0;
    vi starts;
    for(int j=0;j<t.size();j++) if (t[j]==s[0]) starts.push_back(j);
    for(int jj:starts){
        i=0;
        int j=jj;
        bool is=true;
        while(i<s.size()){
            if (s[i]!=t[j]){
                is=false;
                break;
            }
            i++;
            if (++j==s.size()) j=0;
        }
        if (is){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000

typedef struct kyu{
  char name[10];
  int time;
}process;

void enqueue(process);
process dequeue(void);
void initialize(void);
int isEmpty(void);
int isFull(void);

process Q[MAX];
int head,tail,n;

int main(){
  int total = 0,min,i,qms;
  process stream;

  scanf("%d%d",&n,&qms);
  for(i = 0;i < n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }

  head = 0;
  tail = n;

  while(tail != head){
    stream = dequeue();
    if(qms > stream.time) min = stream.time;
    else min = qms;
    stream.time -= min;
    total += min;
    if(stream.time > 0) enqueue(stream);
    else printf("%s %d\n",stream.name,total);
  }
  
  return 0;
}

void enqueue(process x){
  if(isFull() == 1){
    printf("エラー（オーバーフロー）\n");
    exit(7);
  }
  Q[tail] = x;
  if((tail + 1) == MAX) tail = 0;
  else tail++;
}

process dequeue(){
  process x;
  if(isEmpty() == 1){
    printf("エラー（アンダーフロー）\n");
    exit(8);
  }
  x = Q[head];
  if((head + 1) == MAX) head = 0;
  else head++;
  return x;
}

void initialize(){
  head = tail = 0;
}

int isEmpty(){
  if(head == tail) return 1;
  else return 0;
}

int isFull(){
  if(head == (tail + 1) % MAX) return 1;
  else return 0;
}



Measured memory_bytes: 3292
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
 
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>


using namespace std;



#define ll long long
#define ld long double
#define null NULL
#define prev prev228
#define next next228
#define index index228
#define count count228



signed main() {
	ll a, b, c, d;
	cin >> a 
	>> b >> c >> d;
	ll n;
	cin >> n;
	c = min(c, min(b * 2, a * 4));
	d = min(d, 2 * c);
	ll res = 0;
	res += d * (n / 2);
	n %= 2;
	if (n == 1) {
		res += c;
	}
	cout << res << endl;
    return 0;
}












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

int main()
{
	int n, x;

	while(true){
		int count = 0;
		cin >> n >> x;
		if(n == 0 && x == 0){
			break;
		}
		for(int i = 1; i <= n - 2; i++){
			for(int j = i + 1; j <= n - 1; j++){
				for(int k = j + 1; k <= n; k++){
					if((i + j + k) == x){
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    
    int mi = 0;
    int mx = 0;

    vector<int> arr(9, 0);
    int cur;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        if (cur >= 1 && cur <= 399 && arr[0] == 0) {
            arr[0]++;
            sum++;
        } 
        if (cur >= 400 && cur <= 799 && arr[1] == 0) {
            arr[1]++;
            sum++;
        } 
        if (cur >= 800 && cur <= 1199 && arr[2] == 0) {
            arr[2]++;
            sum++;
        } 
        if (cur >= 1200 && cur <= 1599 && arr[3] == 0) {
            arr[3]++;
            sum++;
        } 
        if (cur >= 1600 && cur <= 1999 && arr[4] == 0) {
            arr[4]++;
            sum++;
        } 
        if (cur >= 2000 && cur <= 2399 && arr[5] == 0) {
            arr[5]++;
            sum++;
        } 
        if (cur >= 2400 && cur <= 2799 && arr[6] == 0) {
            arr[6]++;
            sum++;
        } 
        if (cur >= 2800 && cur <= 3199 && arr[7] == 0) {
            arr[7]++;
            sum++;
        } 
        if (cur >= 3200) {
            arr[8]++;
        } 
    }

    int summin = sum;
    if (sum == 0 && arr[8] > 0) {
        summin = 1;
    }
    int summax = sum + arr[8];
    cout << summin << " " << summax << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

const int N = 200'010;
char s[N];
int cnt[2][N], idx[2][N];

int main() {
    int n, k, c;
    scanf("%d%d%d", &n, &k, &c);
    scanf("%s", s + 1);
    idx[0][0] = -N;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'o' && i - idx[0][i - 1] > c) {
            cnt[0][i] = cnt[0][i - 1] + 1;
            idx[0][i] = i;
        } else {
            cnt[0][i] = cnt[0][i - 1];
            idx[0][i] = idx[0][i - 1];
        }
    }
    idx[1][n + 1] = 2 * N;
    for (int i = n; i >= 1; i--) {
        if (s[i] == 'o' && idx[1][i + 1] - i > c) {
            cnt[1][i] = cnt[1][i + 1] + 1;
            idx[1][i] = i;
        } else {
            cnt[1][i] = cnt[1][i + 1];
            idx[1][i] = idx[1][i + 1];
        }
    }
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'x') continue;
        if ((cnt[0][i - 1] + cnt[1][i + 1] < k) ||
            (cnt[0][i - 1] + cnt[1][i + 1] == k && idx[1][i + 1] - idx[0][i - 1] <= c))
            ans.push_back(i);
    }
    for (auto e : ans) printf("%d\n", e);
}


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

const int mod = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long int> a(N+1);
  if (M == 0) {
    a[0] = 1;
    a[1] = 1;
    for(int i=2;i<=N;i++) {
      a[i] = (a[i-1] + a[i-2]) % mod; 
    }

    cout << a[N] << endl;
  } else {
    vector<int> broken(M);
    for(int i=0;i<M;i++) {
      cin >> broken[i];
    }

    int brokenIndex = M-1;
    a[0] = 1;
    if(broken[M-1] == N-1) {
      a[1] = 0;
      brokenIndex--;
    } else {
      a[1] = 1;
    }

    for(int i=2;i<=N;i++) {
      if(brokenIndex == -1) {
        a[i] = (a[i-1] + a[i-2]) % mod;
        continue;
      }
      if(i == N - broken[brokenIndex]) {
        a[i] = 0;
        brokenIndex--;
      } else {
        a[i] = (a[i-1] + a[i-2]) % mod;
      }
    }

    cout << a[N] << endl;
  }

  return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    ll n, a, b;
    cin >> n >> a >> b;
    ll x[n];
    rep(i, n) cin >> x[i];

    ll sum = 0;
    rep(i, n - 1) { sum += min((x[i + 1] - x[i]) * a, b); }

    cout << sum << endl;

    return 0;
}

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

int main() {
  string str;
  cin >> str;
  int n = 0, w = 0, s = 0, e = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == 'N') n++;
    if (str.at(i) == 'W') w++;
    if (str.at(i) == 'S') s++;
    if (str.at(i) == 'E') e++;
  }
  string ans = "No";
  if ((n > 0) && (s > 0)) {
    if (((w > 0) && (e > 0)) || ((w == 0) && (e == 0))) {
      ans = "Yes";
    }
  } else if ((w > 0) && (e > 0)) {
    if (((n > 0) && (s > 0)) || ((n == 0) && (s == 0))) {
      ans = "Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int w = sc.nextInt();
        for (int i = 0 ; i < s.length(); i++) {
            String t = s.substring(i, i + 1);
            if (i % w == 0) {
                System.out.print(t);
            }
        }

        System.out.println("");
    }

}


Measured memory_bytes: 21204
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s []string

	var tmp string
	fmt.Scan(&n, &tmp)
	s = strings.Split(tmp, "")

	var eList, wList []int
	for i, v := range s {
		if i == 0 {
			if v == "E" {
				eList = append(eList, 1)
				wList = append(wList, 0)
			} else {
				eList = append(eList, 0)
				wList = append(wList, 1)
			}
		} else {
			if v == "E" {
				eList = append(eList, eList[i-1]+1)
				wList = append(wList, wList[i-1])
			} else {
				eList = append(eList, eList[i-1])
				wList = append(wList, wList[i-1]+1)
			}
		}
	}

	min := 3 * 100000
	for i := range s {
		var num int
		if i == 0 {
			num = eList[n-1] - eList[i]
		} else {
			num = wList[i-1] + eList[n-1] - eList[i]
		}
		if num < min {
			min = num
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 24960
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a,b,dep,p,q;
int vis[N],path[N];
vector<int>e[N];
int dfs1(int now,int deep)
{
    vis[now]=1;
    if(now==n)
    {
        dep=deep;
        return 1;
    }
    for(int i=0;i<e[now].size();i++)
    {
        if(vis[e[now][i]])
            continue;
        path[deep]=e[now][i];
        if(dfs1(e[now][i],deep+1))
            return 1;
    }
    return 0;
}
int dfs2(int now)
{
    vis[now]=1;
    int sum=1;
    for(int i=0;i<e[now].size();i++)
        if(!vis[e[now][i]])
            sum+=dfs2(e[now][i]);
    return sum;
}
int main()

{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        e[a].push_back(b);
        e[b].push_back(a);
    }
    path[0]=1;
    dfs1(1,1);
    //1:(0)---(dep/2),(dep/2+1)---(dep-1)  2:(0)---(dep/2-1),(dep/2)---(dep-1)
    memset(vis,0,sizeof(vis));
    p=dfs2(1);
    if(dep%2)
    {
        memset(vis,0,sizeof(vis));
        for(int i=0;i<=dep/2;i++)
            vis[path[i]]=1;
        q=dfs2(path[dep/2+1]);
        if(p-q>q)
            printf("Fennec\n");
        else
            printf("Snuke\n");
    }
    else
    {
        memset(vis,0,sizeof(vis));
        for(int i=0;i<=dep/2-1;i++)
            vis[path[i]]=1;
        q=dfs2(path[dep/2]);
        if(p-q>q)
            printf("Fennec\n");
        else
            printf("Snuke\n");
    }
    return 0;
}

Measured memory_bytes: 11136