akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int S = 20000010;
int fact[S+10], finv[S+10];

int mod_pow(int n, int k) {
    int res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return res;
}

void init() {
    fact[0] = 1;
    for(int i=1; i<=S; i++) fact[i] = (fact[i-1] * i) % MOD;
    finv[S] = mod_pow(fact[S], MOD-2);
    for(int i=S-1; i>=0; i--) finv[i] = (finv[i+1] * (i+1)) % MOD;
}

int perm(int n, int r) {
    if(r < 0 or n < r) return 0;
    return fact[n] * finv[n-r] % MOD;
}
 
signed main() {
    init();
    int H, W, K; cin >> H >> W >> K;
    int N = H + W;

    // 2 個切る必要がある、1 個切る必要がある、1 個も切る必要ない
    int c1 = 0, c2 = 0, c3 = perm(N, K) * K % MOD;
    for(int i=1; i<=K; i++) {
        // i 番目で初めて切れた
        if(i >= 2) {
            int temp = 2 * (i - 1);
            (temp *= perm(N-2, K-2)) %= MOD;
            (temp *= K - i + 1) %= MOD;
            (c1 += temp) %= MOD;
        }
        if(i >= 1) {
            int temp = perm(N-1, K-1);
            (temp *= K - i + 1) %= MOD;
            (c2 += temp) %= MOD;
        }
    }
    // fprintf(stderr, "c1 = %lld, c2 = %lld, c3 = %lld\n", c1, c2, c3);

    int h1 = H * W % MOD;
    int h2 = (H + W) % MOD;
    int h3 = 1;

    int ans = 0;
    (ans += h1 * c1) %= MOD;
    (ans += h2 * c2) %= MOD;
    (ans += h3 * c3) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 312832
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define INF 0xc0c0c0c0
#define NINF 0x3f3f3f3f

#define FOR(i, a, b) for((i)=a; i<b; ++(i))
#define EFOR(i, a, b) for((i)=a; i>b; --(i))

#define MLC(n, type) (type*)malloc(n*sizeof(type))
#define CLC(n, type) (type*)calloc(n, sizeof(type))

#define MAXN 100000

int solver(int *data, int length, int k) {
	if (data == NULL || length <= 0 || k <= 0 || k > length)
		return -1;

	sort(data, data+length);

	int i;
	int minDiffHeight = 0x3fffffff;
	int tmpDiffHeight = 0;

	for (i = 0; i <= length - k; ++i) {
		tmpDiffHeight = data[i+k-1] - data[i];

		if (tmpDiffHeight < minDiffHeight) {
			minDiffHeight = tmpDiffHeight;
		}
	}

	return minDiffHeight;
}

int main() {
	int i,n,k;
	int a[MAXN] = {0};

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

	FOR(i, 0, n) {
		scanf("%d", &a[i]);
	}

	int result = solver(a, n, k);
	printf("%d\n", result);
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
int main(void) {
	int N, T;
	scanf("%d%d", &N, &T);
	int c[100];
	int t[100];
	int c1[100];
	int t1[100];
	int count = 0;
	int min = 1000;
	int a = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &c[i], &t[i]);
		if (T >= t[i]) {
			t1[count] = t[i];
			c1[count] = c[i];
			count++;
		}
	}


	if (count == 0) {
		printf("TLE");
	}
	else {

	for (int i = 0; i < count; i++) {
		if (c1[i] < min) {
			min = c1[i];
			a = i;
		}
	}

	printf("%d", c1[a]);

}



	return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int dsc(const void *a, const void *b){
  return *(int *)b - *(int *)a;
}

int
main(int argc, char *argv[])
{
  int n, h, a, amax = -1, b[100001];
  scanf("%d %d", &n, &h);
  REP(i, n){
    scanf("%d %d", &a, &b[i]);
    amax = Max(a, amax);
  }

  qsort(b, n, sizeof(int), dsc);

  int k = 0, ans = 0;
  while(h > 0){
    if(b[k] > amax){
      h -= b[k];
      ans++; k++;
    }else{
      ans += (h - 1) / amax + 1;
      break;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a = number.nextInt();
		int b = number.nextInt();
		int c = number.nextInt();
		int d;
		if(a > b) {
			d = a;
			a = b;
			b = d;
		}
		if(a > c) {
			d = a;
			a = c;
			c = d;
		}
		if(b > c) {
			d = b;
			b = c;
			c = d;
		}
		System.out.println(a + " " + b + " " + c);
	}
}



Measured memory_bytes: 26212
a,b=map(int,input().split())
list1=[0]*(a+1)
for i in range(b):
    c=int(input())
    d=list(map(int,input().split()))
    for j in d:
        list1[j]+=1
for i in range(list1.count(0)):
    list1.remove(0)
print(a-len(list1))

Measured memory_bytes: 67668
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        scanner.close();

        int[] out = new int[n];

        int xor = 0;
        for (int i = 1; i <  n; i++) {
            xor ^= a[i];
        }

        out[0] = xor;
        for (int i = 1; i < n; i++) {
            xor ^= a[i-1];
            xor ^= a[i];
            out[i] = xor;
        }

        for (int i = 0; i < out.length; i++) {
            System.out.print(out[i]);
            String s = i == out.length - 1 ? "\n" : " ";
            System.out.print(s);
        }
    }
    
}

Measured memory_bytes: 58492
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int q,n,m;
struct node{
	int s,t,x,id;
}a[200005],la[200005];
set<P<int,int> > s1,s2;
bool cmp(node x1,node y1){
	return x1.s<y1.s;
}
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m;
	FOR(i,1,n){
		cin>>a[i].s>>a[i].t>>a[i].x;
		a[i].t--;
		a[i].s-=a[i].x;
		a[i].t-=a[i].x;
		a[i].id=i;
		la[i]=a[i];
	}
	sort(a+1,a+n+1,cmp);
	int l=1;
	FOR(i,1,m){
		cin>>q;
		while(l<=n&&a[l].s<=q){
			s1.insert(MP(a[l].x,a[l].id));s2.insert(MP(a[l].t,a[l].id));
			l++;
		}
		while(s2.size()&&(*s2.begin()).F<q){
			P<int,int> tp=(*s2.begin());s2.erase(s2.begin());
			s1.erase(s1.find(MP(la[tp.S].x,tp.S)));
		}
		if(s1.size()){
			cout<<(*s1.begin()).F<<'\n';
		}else cout<<"-1\n";
	}
	RE 0;
}




Measured memory_bytes: 26240
import math

N, M = map(int, input().split())

candidate = []
for i in range(1000):
    if N == len(str(i)):
        candidate.append(i)

for _ in range(M):
    s, c = map(int, input().split())
    tmp = []
    for n in candidate:
        if int(str(n)[s - 1]) == c:
            tmp.append(n)
    candidate = tmp

if candidate:
    print(candidate[0])
else:
    print(-1)

Measured memory_bytes: 38256
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools


def get_input() -> int:
    """
    標準入力を取得.

    Returns:\n
        int: 標準入力
    """
    N = int(input())
    return N


def main(N: int) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 整数（1<=N<=100）
    """
    # 求解処理
    ans = "No"
    for i, j in itertools.product(range(1, 10), range(1, 10)):
        n = i * j
        if n == N:
            ans = "Yes"
            break

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N = get_input()

    # メイン処理
    main(N)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int n;
	while(cin>>n,n){
		string s[1001];

		REP(i,0,n){
			cin>>s[i];
			REP(j,0,(int)s[i].size()){
				if(s[i][j]=='.') continue;
				if(j>0){
					s[i][j-1]='+';
					for(int k=1;s[i-k][j-1]=='.';k++){
						s[i-k][j-1]='|';
					}
				}
				break;
			}
		}
		REP(i,0,n){
			REP(j,0,(int)s[i].size()){
				if(s[i][j]=='.') cout<<' ';
				else cout<<s[i][j];
			}
			p("");
		}
	}

	return 0;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N,K;
  string s;
  cin>>N>>K>>s;
  REP(i,N){
    if(i==K-1){
      cout << (char)(s[i] - ('A'- 'a'));
    }else{
      cout << s[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int a,b;
		string op;
		cin >> a >> op >> b;

		int ans;
		if (op == "?") break;

		if (op=="+") ans=a+b;
		if (op=="-") ans=a-b;
		if (op=="*") ans=a*b;
		if (op=="/") ans=a/b;
	cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    string n;
    int ns;
    int k;
    cin >> n;
    cin >> k;

    ns = n.size();
    vector<vector<LL>> dp0(ns+1, vector<LL>(k+1, 0));
    vector<vector<LL>> dp1(ns+1, vector<LL>(k+1, 0));

    dp0[0][0]=1;
    dp1[1][1]=1;

    int tmp;
    for(int i=0; i<ns; i++){
        tmp = n[i]-'0';
        for(int j=0; j<=k; j++){
            if(tmp==0){
                dp0[i+1][j]+=dp0[i][j];
                if(j+1<=k){
                    dp0[i+1][j+1]+=dp0[i][j]*9;
                }
                if(j!=0){
                    dp1[i+1][j]+=dp1[i][j];
                }
            }else{
                dp0[i+1][j]+=dp0[i][j]+dp1[i][j];
                if(i==0 && j==0){
                    dp0[i+1][j+1]+=dp0[i][j]*(tmp-1);
                }else if(j+1<=k){
                    dp0[i+1][j+1]+=dp0[i][j]*9+dp1[i][j]*(tmp-1);
                }
                if(j!=0 && j+1<=k){
                    dp1[i+1][j+1]+=dp1[i][j];
                }
            }
        }
    }

    /*
    cout << "test0" << endl; 

    for(int i=1; i<=ns; i++){
        for(int j=0; j<=k; j++){
            cout << i << " " << j << " " << dp0[i][j] << endl;
        }
    }

    cout << "test1" << endl; 

    for(int i=1; i<=ns; i++){
        for(int j=0; j<=k; j++){
            cout << i << " " << j << " " << dp1[i][j] << endl;
        }
    }
    */
    

    cout << dp0[ns][k]+dp1[ns][k] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	ll i,j,n,m,k,kk; k=0;kk=maxn;
	 cin>>m>>n;
	for(i=0;i<n;i++)
	cin>>d[i];
	sort(d,d+n);
	k=d[n-1]-d[0];
	for(i=1;i<n;i++)
	kk=min(m-d[i]+d[i-1],kk);
	printf("%lld\n",min(k,kk));

}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL n;
    cin>>n;
    LL ans=0;
    LL a=n/500;
    n=n%500;
    ans=a*1000;
    LL b=n/5;
    ans=ans+b*5;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

bool vM(int i) {
    return 1<=i && i<=12;
}

bool vY(int i) {
    return 0 <=i;
}

int main() {
    string S;
    cin >> S;
    
    auto s1 = S.substr(0, 2);
    auto s2 = S.substr(2, 2);
    
    auto i1 = stoi(s1);
    auto i2 = stoi(s2);
    
    if (vM(i1) && vM(i2)) {
        cout << "AMBIGUOUS"<< endl;
    } else if(vY(i1) && vY(i2)) {
        if (vM(i1)) {
            cout << "MMYY" << endl;
        } else if(vM(i2)) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    } else {
        cout << "NA" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int maxn = 200010;
const int maxm = 1000010;

int a[maxn];
int f[maxm];

int main() {
  static int n, ans;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) f[a[i]]++;
  for (int i = 1000000; i; --i) if (f[i]) {
    for (int j = i + i; j <= 1000000; j += i) {
      f[j] += f[i];
    }
  }
//  for (int i = 1; i <= 24; ++i) printf("%d %d\n", i, f[i]);
  for (int i = 1; i <= n; ++i) ans += (f[a[i]] == 1);
  printf("%d\n", ans);
  return 0;
}

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

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a*a+b*b==c*c) printf("%d",a*b/2);
    else if(a*a+c*c==b*b) printf("%d",a*c/2);
    else printf("%d",b*c/2);
    return 0;
}


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

int main() {
	int n,a,b;
	cin>>n>>a>>b;
	if(a+b-n>=0){
		cout<<min(a,b)<<" "<<a+b-n<<endl;
	}else{
		cout<<min(a,b)<<" "<<0<<endl;
	}
	return 0;

}



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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int H, W; cin >> H >> W;
	vector<string>a(H); rep(i, 0, H) { cin >> a[i]; }
	vector<string>b(H, string(W, '.')), c(b);
	rep(i, 0, H)b[i][0] = c[i][W - 1] = '#';
	rep(i, 0, H) {
		string &s = (i & 1 ? c[i] : b[i]);
		rep(j, 1, W - 1)s[j] = '#';
	}
	rep(i, 0, H) { dump(b[i]); }
	rep(i, 0, H) { dump(c[i]); }
	rep(i, 0, H)rep(j, 0, W) {
		if (a[i][j] == '#') {
			b[i][j] = c[i][j] = a[i][j];
		}
	}
	rep(i, 0, H)cout << b[i] << endl;
	cout << endl;
	rep(i, 0, H)cout << c[i] << endl;


	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	bool ok = false;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i * m + j * n - 2 * i * j == k) {
				ok = true;
				break;
			}
		}
		if (ok) {
			break;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
class aizu{
    public static int Main(){
        int i;
    	int[] n = new int[100];
    	string[] str = new string[100];
    	str = Console.ReadLine().Split(' ');
        for(i=0;i<3;i++)
    	   n[i] = int.Parse(str[i]);
        if(n[0] < n[1] && n[1] < n[2])
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
        return 0;
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N=(int)2e5+7;

int n;
map<int,ll>dp;
set<int>s;
int h[N],a[N];

void ins(int h)
{
    auto it=s.lower_bound(h);
    it--;
    if(dp[h]>dp[*it])
    {
        while(!s.empty())
        {
            auto it=s.lower_bound(h);
            if(it!=s.end() && dp[h]>dp[*it])
            {
                s.erase(*it);
            }
            else
            {
                break;
            }
        }
        s.insert(h);
    }
}

void print()
{
    return;
    cout<<": ";
    for(auto &it:s)
    {
        cout<<it<<" ";
    }
    return;
    for(auto &it:s)
    {
        cout<<"{ "<<it<<" => "<<dp[it]<<" } ";
    }
    cout<<"\n";
}

int main()
{
   // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   // set<int>s;
   // s.insert(0);
   // s.insert(100);
   // s.insert(1000);
   // auto it=s.lower_bound(10);
   // cout<<*it<<"\n";
   // return 0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n;i++) cin>>a[i];
    s.insert(-10);
    ll res=0LL;
    for(int i=1;i<=n;i++)
    {
        auto it=s.lower_bound(h[i]);
        it--;
        dp[h[i]]=dp[*it]+a[i];
        ins(h[i]);
        res=max(res,dp[h[i]]);
        print();
    }
    cout<<res<<"\n";
    return 0;
}
/**


>= 1         :                      1
>= 2         :                      2
>= 3         :                      3
>= 4         :                      4
>= 5         :                      5
>= 6         :                      4
>= 7         :                      7



**/


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

using namespace std;

struct treap
{
    string name;
    int val;
};

treap t;
queue<treap> que;
int main()
{
    int n, q;
    cin >> n >> q;
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> t.name >> t.val;
        que.push(t);
    }
    while (!que.empty())
    {
        treap a = que.front();
        if (a.val > q)
        {
            a.val -= q;
            count += q;
            que.pop();
            que.push(a);
        }
        else
        {
            
            cout << a.name << " " << a.val + count << endl;
            count += a.val;
            que.pop();
        }
    }

    return 0;
}


Measured memory_bytes: 6212
#include <bits/stdc++.h>
//#include "./libb/lib.hpp"
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;
const uint64_t MOD = 1000000007;
const double PI = acos(-1);
 
int main()
{
    string ss;
    string tt;
    uint32_t len = 0;
    uint32_t num = 0;

    cin >> ss >> tt;
    
    len = ss.length();

    rep(i, len){
        if(ss[i] != tt[i])
            num++;
    }

    cout << num << endl;
    return 0;
}


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

int main(){
	string a;
	int b[26]={};
	char c;
	int d=1;
	for(int q=0;;q++){
	getline(cin,a);
	if(a==""){d=0;}
	if(d==0)break;
	for(int i=0;i<a.length();i++){
		if('A'<=a[i]&&a[i]<='Z'){
			a[i]=a[i]-'A'+'a';
		}
	}
	for(int i=0;i<a.length();i++){
		for(int j=0;j<26;j++){
			if(a[i]=='a'+j){
			b[j]++;
			}
		}
	}
	}
	for(int i=0;i<26;i++){
		c=(char)i+97;
		cout <<c<<" : "<<b[i]<< endl;
	}
	return 0;
}

Measured memory_bytes: 3176
import java.util.Scanner;
 
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final long N = sc.nextInt();
        final long M = sc.nextInt();
    	
        if (N > 1 && M > 1) {
        	System.out.println((N - 2) * (M - 2));
        } else if (N == 1 && M == 1){
        	System.out.println(1);
        } else {
        	System.out.println(Math.max(N, M) - 2);
        }
        
    }
    
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

  
int main(){
  int H, W; cin >> H >> W; int G[H][W];
  rep(i, H){
    rep(j, W){
      cin >> G[i][j];
    }
  }
  vector<pair<pair<int, int>, pair<int, int>>> odd;
  rep(i, H){
    rep(j, W-1){
      if(G[i][j]%2) {
        odd.push_back({{i, j}, {i, j+1}});
        G[i][j]--;
        G[i][j+1]++;
      }
    }
  }
  rep(i, H-1){
    if(G[i][W-1]%2) {
      odd.push_back({{i, W-1}, {i+1, W-1}});
      G[i][W-1]--;
      G[i+1][W-1]++;
    }
  }
  cout << odd.size() << endl;
  rep(i, odd.size()){
    cout << odd[i].first.first+1 << " " <<  odd[i].first.second+1 << " "  << odd[i].second.first+1 <<" " <<  odd[i].second.second+1 << endl;
  }
}

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

vector<int> P = {2, 3, 5, 7, 11, 13, 17, 19,
                 23, 29, 31, 37, 41, 43, 47};
int Psize = P.size();

int countIndex(int A, int N) // N! を素因数分解したときの A の指数
{
  int R = 0;
  for (int i = A; i <= N; i *= A)
  {
    R += N / i;
  }
  return R;
}

vector<int> Q(Psize);

int num(int N) // 指数が N 以上の素因数の数
{
  int R = 0;
  for (int i = 0; i < Psize; i++)
  {
    if (Q.at(i) < N) return R;
    R++;
  }
}

int main()
{
  int N;
  cin >> N;
  
  for (int i = 0; i < Psize; i++)
  {
    Q.at(i) = countIndex(P.at(i), N);
    //cout << Q.at(i) << endl;
  }
  
  int ans = 0;
  ans += num(74);
  ans += (num(4) - 1) * num(14);
  ans += (num(2) - 1) * num(24);
  ans += num(4) * (num(4) - 1) * (num(2) - 2) / 2;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

// Problem https://atcoder.jp/contests/arc094/tasks/arc094_a


// 戦略 下限はまず全部の数字の一番大きいところを目標とすれば良い。
//      (理由 両方の操作も足すだけで引くことが出来ない)
//      また、両方とも合計2を足すため偶数値しか増やせない
//      一番大きな数字と残り二つの差の、和が偶数であれば単純にそれを2で割る
//      もし奇数であれば、下限+1をターゲットとすれば全部の数字との差が偶数になる
int solver(int A,int B,int C){
    int result;
    result=0;
    int lower_limit;
    lower_limit = max(A,max(B,C));
    int remainN;
    remainN = (lower_limit-A)+(lower_limit-B)+(lower_limit-C);
    if(remainN % 2 == 0){ // 埋める値が偶数の時
        result = remainN / 2;
    }
    else{// 埋める値が奇数になったとき -> lower_limitに1加えて再計算
        remainN = ((lower_limit+1)-A)+((lower_limit+1)-B)+((lower_limit+1)-C);
        result = remainN / 2;
    }
    return result;
}

int main(void){
    int answer;
    answer=0;
    int A,B,C;
    cin >> A >> B >> C;
    answer = solver(A,B,C);
    cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int ans;
	int n; cin >> n;
	vector<int> data(n-1);
	rep(i,n-1){
		cin >> data[i];
	}
	cin >> ans;
	long long dp[100][21] = {0};
	dp[0][data[0]] = 1;
	rep(i,data.size()-1){
		rep(j,21){
			int t = j + data[i+1];
			if(t < 0 || t > 20)continue;
			dp[i+1][t] += dp[i][j];
		}
		rep(j,21){
			int t = j - data[i+1];
			if(t < 0 || t > 20)continue;
			dp[i+1][t] += dp[i][j];
		}
	}
	cout << dp[data.size()-1][ans] << endl;
}

Measured memory_bytes: 0
(defn formula [ X Y x y]
  (unchecked-add-int (Math/abs (unchecked-subtract-int X x)) (Math/abs (unchecked-subtract-int Y y))))
 
(def formula (memoize formula))
 
(defn zero-case [X Y zs]
  (apply min (map (fn [[x y _]] (formula X Y x y)) zs)))
 
(defn Pyramid [ls]
  (let [{lsn false zs true} (group-by (fn [[_ _ h]] (zero? h)) ls)
        ^const range_it (range (unchecked-int 0) (unchecked-int 101))]
    (first
      (for [X range_it
            Y range_it
            :let [Hs (map (fn [[x y h]] (unchecked-add-int h (formula X Y x y))) lsn)
                  H  (first Hs)]
            :when (and (every? #(= H %) (rest Hs))
                    (if (nil? zs)
                      (<= 1 H)
                      (>= (zero-case X Y zs) H)))]
        (format "%d %d %d" X Y H)))))
 
(defn input [N]
  (when-not (zero? N)
    (let [x (unchecked-int (read)) y (unchecked-int (read)) h (unchecked-int (read))]
      (cons [x y h] (input (unchecked-dec-int N))))))
(-> (read) int input Pyramid println) 

Measured memory_bytes: 211660
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll n,ans=0;
void solve(string s,string t){
    for (ll i=0;i<10;i++){

    }
}

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans=0;

    for (ll i=k;i<=n+1;i++){
        ll l=(i-1)*i/2;
        ll r=(n+n-i+1)*i/2;
        ans+=r-l+1;
        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

// using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	std::string s;
	std::cin >> s;

	int ans = 0;

	// 愚直にできないか 1文字，もしくは2文字がよい
	// 2文字にする場合は，同じ文字が連続するときのみ
	// いける

	int n = static_cast<int>(s.size());

	char prevS = s[0];
	ans++;
	Rep(i, 1, n) {
		if (s[i] == prevS) {
			prevS = 'A'; // 適当な文字
			i++;
			if (i != n) ans++;
		}
		else {
			prevS = s[i];
			ans++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int n, m;
    while (cin >> n) {
        int t[n];
        FOR(i,0,n)
            cin >> t[i];
        cin >> m;
        int p[m], x[m];
        FOR(i,0,m)
            cin >> p[i] >> x[i];
        int ans = 0;
        FOR(j,0,m) {
            ans = 0;
            FOR(i,0,n)
                ans += t[i];
            int a = p[j] - 1;
            ans = ans - t[a] + x[j];
            cout << ans << endl;
        }
    }
}


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

using namespace std;

bool solve(const std::array<int, 4>& roads) {
  int onlyOneRoads = 0;
  for (auto const road : roads) {
    if (road == 0) {
      return false;
    }
    if (road == 1) {
      onlyOneRoads++;
    }
  }
  return onlyOneRoads == 2;
}

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

  std::array<int, 4> roads{0};
  for (int i = 0; i < 3; ++i) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    roads[a]++;
    roads[b]++;
  }
  std::cout << (solve(roads) ? "YES" : "NO") << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const ll INF = 2 * 1e9;
const ll MAX_VALUE = 1e5+1;

int main(){
    int n, W; cin >> n >> W;
    vector<ll> dp(MAX_VALUE, INF);
    dp[0] = 0;
    int w, v;
    for(int i=0; i<n; i++){
        cin >> w >> v;
        for(int j=MAX_VALUE-1; j>-1; j--){
            if(dp[j] == INF){continue;}
            dp[j+v] = min(dp[j+v], dp[j] + w);
        }
    }
    // for(auto& v:dp){
    //     cout << v << " ";
    // }
    // cout << "\n";

    int ans = 0;
    for(int i=0; i<MAX_VALUE; i++){
        if(dp[i] <= W){
            ans = max(ans, i);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s, s_c;
    int m, h;
    while (1 > 0) {
      s = sc.next();
      if (s.equals("-")) break;
      m = sc.nextInt();
      for (int i = 0; i < m; i++) {
        h = sc.nextInt();
        s_c = s.substring(0, h);
        s = s.substring(h, s.length());
        s += s_c;
      }
      System.out.printf("%s\n", s);
    }

    sc.close();
  }
}



Measured memory_bytes: 26636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split();
        Console.WriteLine(long.Parse(ab[0]) * long.Parse(ab[1].Replace(".", "")) / 100);
    }
}


Measured memory_bytes: 27544
ammount = int(input())

player_input2 = input()

lst_of_heights = player_input2.split(" ")

tallest = int(lst_of_heights[0])

step_value = 0



for i in range(1, ammount):
    if int(lst_of_heights[i]) >= tallest:
        tallest = int(lst_of_heights[i])
    else:

        step_value += (tallest - int(lst_of_heights[i]))

print(step_value)


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n), a(n);
    for(int i = 0;i < n; i++){
        cin >> p[i];
    }
    for(int i = 0; i<n;i++){
        cin >> q[i];
    }
    for(int i = 0; i<n;i++){
        a[i] = i+1;
    }
    map<vector<int>, int> mp;
    do{
        mp[a] = mp.size();
    }while(next_permutation(a.begin(), a.end()));
    int ans = abs(mp[p]-mp[q]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
using namespace std;
int n, a[100005], d[100005];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    d[1] = 0;
    d[2] = abs(a[1] - a[2]);
    for (int i = 3; i <= n; i++)
        d[i] = min(d[i - 1] + abs(a[i - 1] - a[i]),
                   d[i - 2] + abs(a[i - 2] - a[i]));
    cout << d[n] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(c);
    rep(i,a) {cin>>p[i];}
    rep(i,b) {cin>>q[i];}
    rep(i,c) {cin>>r[i];}
    sort(begin(p), end(p), greater<ll>());
    sort(begin(q), end(q), greater<ll>());
    sort(begin(r), end(r), greater<ll>());
    priority_queue<ll, vector<ll>, greater<ll>> pq[2];
    rep(i,x) {
        pq[0].push(p[i]);
    }
    rep(i,y) {
        pq[1].push(q[i]);
    }
    rep(i,c) {
        int idx = 0;
        if (pq[0].top()>=pq[1].top()) {
            idx = 1;
        }
        if (pq[idx].top()<r[i]) {
            pq[idx].pop();
            pq[idx].push(r[i]);
        }
    }
    ll res = 0;
    rep(i,2) {
        while (!pq[i].empty()) {
            res+= pq[i].top();
            pq[i].pop();
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const ll Mod = 1000000007;
/* --- */
using MT = decay<decltype(Mod)>::type;

MT inverse (MT a, MT n) {
	MT u = 0, v = 1;
	while (a != 0) {
		MT q = n / a;
		swap(u, v); v -= q * u;
		swap(n, a); a -= q * n;
	}
	assert(n == 1);
	return u;
}

class mint {
private: MT x;
public:
	void normalize() {
		if (x >= Mod || x < 0) x = (x % Mod) + Mod;
		if (x > Mod) x -= Mod;
	}
	mint(): x(0) {}
	mint(MT z): x(z) { normalize(); }
	const MT& operator() () const { return x; }

	mint operator+ (const mint& z) { MT r = x + z(); if (r > Mod) r -= Mod; return mint(r); }
	mint operator- (const mint& z) { MT r = x - z(); if (r < 0) r += Mod; return mint(r); }
	mint operator* (const mint& z) { MT r = x * z(); if (r > Mod) r %= Mod; return mint(r); }
	mint operator/ (const mint& z) { return (*this) * mint(inverse(z(), Mod)); }

	mint operator+= (const mint& z) { (*this) = (*this) + z; return (*this); }
	mint operator-= (const mint& z) { (*this) = (*this) - z; return (*this); }
	mint operator*= (const mint& z) { (*this) = (*this) * z; return (*this); }
	mint operator/= (const mint& z) { (*this) = (*this) / z; return (*this); }

	friend std::istream& operator>> (std::istream&, mint&);
};

std::istream& operator>> (std::istream& stream, mint& p) {
	MT v; stream >> v; p.x = v; p.normalize(); return stream;
}
std::ostream& operator<< (std::ostream& stream, const mint& p) { return stream << p(); }
mint operator+ (const MT& p, const mint& q) { return mint(p) + q; }
mint operator- (const MT& p, const mint& q) { return mint(p) - q; }
mint operator* (const MT& p, const mint& q) { return mint(p) * q; }
mint operator/ (const MT& p, const mint& q) { return mint(p) / q; }
string to_string (const mint& p) { return to_string(p()); }

mint powMod (mint a, MT b) {
	mint res = 1, x = a;
	while (b > 0) {
		if (b & 1) res *= x;
		x *= x;
		b >>= 1;
	}
	return res;
}
/* --- */

const int N = 110;
const int M = 10;
mint f[N][M];
int n, m, k;

bool isValid (int mask) {
  for (int i = 0; i < (m - 2); i++)
    if ((mask & (1 << i)) && (mask & (1 << (i+1)))) return false;
  return true;
}

int main() {
  scanf("%d%d%d", &n, &m, &k);  
  f[0][0] = 1; 
  for (int i = 0; i < n; i++) {
    for (int mask = 0; mask < (1 << (m - 1)); mask++) if (isValid(mask)) {
      for (int j = 0; j < m; j++) {
        mint lf = (j > 0 && (mask & (1 << (j - 1))) > 0) ? f[i][j - 1] : 0;
        mint rt = (mask & (1 << j)) ? f[i][j + 1] : 0;
        mint mid = ((mask & (1 << j)) == 0 && (j == 0 || (mask & (1 << (j - 1))) == 0)) ? f[i][j] : 0;

        f[i + 1][j] += lf + rt + mid;
      }
    }    
  }
  printf("%lld\n", f[n][k - 1]());
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 10000005
#define maxm 500005
#define inf 0x7fffffff
#define ll unsigned long long
#define rint register ll
#define debug(x) cerr<<#x<<": "<<x<<endl
#define fgx cerr<<"--------------"<<endl
#define dgx cerr<<"=============="<<endl

using namespace std;
ll N,A,B,C,D;
map<ll,ll> ans; 

inline ll read(){
    ll x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}

inline ll solve(ll n){
	if(!n) return 0;
	if(n==1) return D;
	if(ans[n]) return ans[n];
	//cout<<n<<endl; 
	ll res=n*D;
	ll la=n-(n%2),ra=(!(n%2))?la:la+2;
	res=min(res,(n-la)*D+solve(la/2)+A);
	res=min(res,(ra-n)*D+solve(ra/2)+A);
	ll lb=n-(n%3),rb=(!(n%3))?lb:lb+3;
	res=min(res,(n-lb)*D+solve(lb/3)+B);
	res=min(res,(rb-n)*D+solve(rb/3)+B);
	ll lc=n-(n%5),rc=(!(n%5))?lc:lc+5;
	res=min(res,(n-lc)*D+solve(lc/5)+C);
	res=min(res,(rc-n)*D+solve(rc/5)+C);
	ans[n]=res; 
	return res;
}

int main(){
	int T=read();
	while(T--){
		ans.clear();
		N=read(),A=read(),B=read(),C=read(),D=read();
		printf("%lld\n",solve(N));
	}
	return 0;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> data(6);
  int judge =0 ;
  for (int i = 0; i < 6; i++) {
    cin >> data.at(i);
  }
  judge = data.at(4)-data.at(0);
  
  if(judge > data.at(5)){
  cout << ":(" << endl;    
  }
  else{
      cout << "Yay!" << endl;
  }
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

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

template <typename T>
void tk_input(vector<T> &arr){
    for(T &i: arr)
        cin>>i;
}

//1.Check for overflows and don't panic
//
//2.If you cannot think of a solution, try 
//  to think from backwards
void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({(a * d), (b * d), (b * c),(a * c)});
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        freopen("Debug.txt", "w", stderr);
    #else
    #endif
        solve();
}

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

using namespace std;

int main(){
    int N,max=0;
    cin >> N;
    vector<string> vec(N);
    map<string,int> mp;
    for(int i=0;i<N;i++){
        cin >> vec[i];
        mp[vec[i]]++;
    }

    for(int i=0;i<N;i++){
        if(max<mp[vec[i]]){
            max = mp[vec[i]];
        }
    }

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

    for(int i=0;i<N;i++){
        if(mp[vec[i]]==max){
            cout << vec[i] << endl;
            i += max-1;
        }
    }
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  typedef pair<int,int> P;
  std::vector<P> w(M);
  for(int i=0;i<M;i++){
    int b,c;cin>>b>>c;
    w[i]=P(c,b);
  }
  sort(w.rbegin(),w.rend());
  int now=-1;int ans=0;
  for(int i=0;i<M;i++){
    if(now==N-1){
      break;
    }
    if(now+w[i].second>=N){
      w[i].second=N-now-1;
    }
    if(v[now+w[i].second]<=w[i].first){
      ans+=w[i].second*w[i].first;
      now+=w[i].second;
    }
    else{
      int qq=now+1;
      while(v[qq]<w[i].first)qq++;
      ans+=(qq-now-1)*w[i].first;
      now=qq-1;
    }
  }
  for(int i=now+1;i<N;i++)ans+=v[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
/**
 *    author:  tourist
 *    created: 26.11.2019 04:23:46       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int p = 0;
  for (int i = 1; i < n; i++) {
    if (abs(a[i]) > abs(a[p])) {
      p = i;
    }
  }
  auto Do = [&](int x, int y) {
    cout << y + 1 << " " << x + 1 << '\n';
    a[x] += a[y];
  };
  cout << 2 * n - 1 << '\n';
  if (a[p] > 0) {
    for (int i = 0; i < n; i++) {
      Do(i, p);
    }
    for (int i = 1; i < n; i++) {
      Do(i, i - 1);
    }
  } else {
    for (int i = 0; i < n; i++) {
      Do(i, p);
    }
    for (int i = n - 2; i >= 0; i--) {
      Do(i, i + 1);
    }
  }
  assert(is_sorted(a.begin(), a.end()));
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int A, B, C, X, Y;


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

  cin >> A >> B >> C >> X >> Y;

  int ans1 = A*X+ B*Y;

  int s,t, d,e;
  if (X>Y){
    s=X; t=Y;
    d = A; e = B; 
  } else{
    s=Y; t=X;
    d = B; e = A;
  }
  int ans2 = C*2*t + d*(s-t);
  int ans = min(ans1, ans2);
  int ans3 = C*2*s; 
  ans =  min(ans,ans3);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
double a, b, x;
double pi = 3.14159265358979;
signed main() {
	cin >> a >> b >> x;
	x /= a;
	if (a*b / 2 <= x) {
		double p = (a*b - x)*2 / a;
		printf("%.10f\n",atan(p / a) / pi * 180);
	}
	else {
		double p = x * 2 / b;
		printf("%.10f\n", 90 - atan(p / b) / pi * 180);
	}
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int> v(n+1);
	v[0]=-1;
	vector<int> ans;
	for(int i=1;i<=n;i++)
		cin>>v[i];
	for(int i=n;i>=1;i--){
		int j;
		for(j=i;j>=1;j--){
			if(j==v[j]){
				ans.emplace_back(j);
				v.erase(v.begin()+j);
				break;
			}
		}
		if(j==0){
			cout<<-1<<endl;
			return 0;
		}
	}
	reverse(ans.begin(),ans.end());
	for(int it:ans)
		cout<<it<<endl;
}


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


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)cout<<"No"<<endl;
    else if(a!=b && b!=c && c!=a) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	ll a, b;
	cin >> a >> b;
	cout << a * b / gcd(a, b);
}

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

int main(){
    string s;cin >> s;
    map<char, int> mp;
    for (int i=0;i<s.size();i++){
        mp[s[i]]++;
    }

    for (auto& t:mp){
        if (t.second > 1){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256