akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int h,n;
	cin >> h >> n;
	vector<ll> dp(h+1, INT_MAX);
	vector<pair<int,int>> spells(n);
	for(int i = 0 ; i < n ; i++){
		int a,b ;
		cin >> a >> b ;
		spells[i] = make_pair(a,b);
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j <= h ; j++){
			int dmg = spells[i].first;
			int cost = spells[i].second;
			ll val = ceil((float)j / (float)dmg) * cost;
			
			if(j-dmg > 0){
				dp[j] = min(dp[j] ,dp[j-dmg]+cost);
			}else{
				dp[j] = min(dp[j], (ll)cost);	
			}
		}
	}
	cout << dp[h] ;

}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 1234567890;

struct Card {
    char suit;
    int value;
};

Card L[100000], R[100000];

void merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = INF;
    R[n2].value = INF;

    int i = 0;
    int j = 0;

    for (int k = left; k < right; k++) {
        if (L[i].value <= R[j].value) A[k] = L[i++];
        else A[k] = R[j++];
    }
}

void mergeSort(Card A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(Card A[], int p, int r) {
    int x = A[r].value;
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j].value <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i + 1;
}

void quickSort(Card A[], int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}

int isStable(Card A1[], Card A2[], int n) {
    for (int i = 0; i < n; i++) {
        if (A1[i].suit != A2[i].suit) return 0;
    }
    return 1;
}

int main(void) {
    int n, i;
    Card A1[150000];
    Card A2[150000];
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s %d", &A1[i].suit, &A1[i].value); 
        A2[i].suit = A1[i].suit;
        A2[i].value = A1[i].value;
    }

    quickSort(A1, 0, n - 1);
    mergeSort(A2, 0, n);

    if (isStable(A1, A2, n)) printf("Stable\n");
    else printf("Not stable\n");

    for (i = 0; i < n; i++) printf("%c %d\n", A1[i].suit, A1[i].value);

    return 0;
}

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

using namespace std;

long long n, m, ans = 1;

int main(){
	cin >> n >> m;
	
	for(int i = 1; i <= n; ++i){
		ans *= i;
		ans %= mod;
	}
	for(int i = 1; i <= m; ++i){
		ans *= i;
		ans %= mod;
	}	
	
	if(abs(n-m) == 0){
		ans *= 2;
		ans %= mod;
	}else if(abs(n-m) != 0 && abs(n-m) != 1){
		ans = 0;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input: string) {
  const lines: string[] = input.split("\n");

  const s = lines[0];
  
  const msg = (s[2] === s[3] && s[4] === s[5])? 'Yes' : 'No';
  
  console.log(msg);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
  int N,T;
  cin>>N>>T;
  vector<pair<int,int>> ct(N);
  for (int i=0; i<N; i++){
    cin>>ct.at(i).first>>ct.at(i).second;
  }
  int mini=1001;
  for (int i=0; i<N; i++){
    if (ct.at(i).second<=T){
      if (mini>ct.at(i).first){
        mini=ct.at(i).first;
      }
    }
  }
  if (mini==1001){
    cout<<"TLE"<<endl;
  }else{
    cout<<mini<<endl;
  }
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

set<string>se;

void init();
void work();
int ca=1;
int main(){
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
//    init();
//    int T;cin>>T;
//    while(T--)
    work();
    return 0;
}
void work(){
    string s;
    int n;cin>>n;
    while(n--){
        cin>>s;
        se.insert(s);
    }
    cout<<se.size();
}


Measured memory_bytes: 19244
#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 main() {
    double a, b, x;
    cin >> a >> b >> x;
    if (2.0*x <= a*a*b) printf("%.10f\n", 180.0*atan(a*b*b/2/x)/M_PI);
    else printf("%.10f\n", 180.0*atan(2.0*(b-x/a/a)/a)/M_PI);

    return 0;
}

Measured memory_bytes: 4140
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

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


Measured memory_bytes: 256
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main();	
	}

	public Main() {
		while(sc.hasNext()){
			new aoj1153().doIt();
		}
	}
	class aoj1153 {
		String ans(int a[],int b[]){
			int asum = 0;
			int bsum = 0;
			int sum = Integer.MAX_VALUE;
			for(int i = 0;i < a.length;i++)asum = asum + a[i];
			for(int i = 0;i < b.length;i++)bsum = bsum + b[i];
			String result = "-1";
			for(int i = 0;i < a.length;i++){
				for(int j = 0;j < b.length;j++){
					if(asum - a[i] + b[j] == bsum - b[j] + a[i]){
						if(a[i] + b[j] < sum){
							result = a[i]+" "+b[j];
							sum = a[i] + b[j];
						}
					}
				}
			}
			return result;
		}
		void doIt() {
			while(true){
				int n = sc.nextInt();
				int m = sc.nextInt();
				if(n+m == 0)break;
				int a[] = new int [n];
				int b[] = new int [m];
				for(int i = 0;i < n;i++)a[i] = sc.nextInt();
				for(int i = 0;i < m;i++)b[i] = sc.nextInt();
				System.out.println(ans(a,b));
			}
		}
	}
}

Measured memory_bytes: 21052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define mod (1000000007)

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

void solve() 
{
    int n;cin>>n;
    ll ans=((power(10,n)+power(8,n))%mod-2*power(9,n))%mod;
    cout<<(ans<0?ans+mod:ans)<<endl;
}

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


Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
struct c{int a, b;};

int N;
c C[111111];

bool comp(const c &c1, const c &c2){
	return c1.a + c1.b > c2.a + c2.b;
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d %d", &C[i].a, &C[i].b);
	sort(C, C + N, comp);
	ll res = 0;
	for(int i = 0; i < N; i++){
		if(i % 2 == 0) res += (C[i].a + C[i].b);
		res -= C[i].b;
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n; cin>>n;
    vector<string>v(n);
    set<string>s;
    rep(i,n) {
        cin>>v[i];
        s.insert(v[i]);
    }
    sort(all(v));
    ll sum=s.size(), tmp=0;
    //cout<<sum<<endl;
    vector<ll>a(sum,1);
    vector<string>ans(sum);
    ans[0]=v[0];
    rep(i,n-1){
        if(v[i]==v[i+1]) a[tmp]++;
        else {
            tmp++;
            ans[tmp]=v[i+1];
        }
    }
    vector<ll>l(sum);
    rep(i,sum) l[i]=a[i];
    sort(all(l));
    reverse(all(l));
    ll ma=l[0];
    //cout<<ma<<endl;
    set<string>S;
    rep(i,sum){
        if(a[i]==ma){
            S.insert(ans[i]);
        }
    }
    //cout<<*rbegin(S)<<endl;
    for(auto val:S){
        cout<<val<<' ';
    }
    cout<<endl;
}

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

int main() {
    int N; string S;
    cin >> N >> S;
    long long r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') ++r;
        else if (c == 'G') ++g;
        else ++b;
    }
    long long all = r * g * b;
    long long sub = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if (S[i] == S[j]) continue;
            int k = j*2-i;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) continue;
            ++sub;
        }
    }
    cout << all - sub << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a>b) {
			System.out.println("a > b");
		}else if(a==b) {
			System.out.println("a == b");
		}else {
			System.out.println("a < b");
		}
	}
}


Measured memory_bytes: 26188
#include <stdio.h>
int main(){
  int n,p,a,i,f=0;
  long r=1;
  scanf("%d%d",&n,&p);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a%2)f=1;
  }
  if(f)for(i=0;i<n-1;i++)r*=2;
  else {
    if(p)r=0;
    else for(i=0;i<n;i++)r*=2;
  }
  printf("%ld",r);
  return 0;
}

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

const int DIM = 1e5 + 5;

int arr[DIM];

int main( void ) {
    
    int n;
    cin >> n;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    int ans = 0;
    for( int i = 1; i <= n; i ++ ) {
        if( arr[arr[i]] == i )
            ans ++;
    }
    
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int num;
    int list_num[10000];

    int num_min;
    int num_max;
    long int num_sum = 0;

    scanf("%d\n", &num);
    for (int i = 0; i < num; i++) {
        scanf("%d", &list_num[i]);
    }

    /* initialize */
    num_min = list_num[0];
    num_max = list_num[0];

    for (int i = 0; i < num; i++) {
        if (list_num[i] > num_max) {
            num_max = list_num[i];
        }
        else if (list_num[i] < num_min) {
            num_min = list_num[i];
        }
        else {
            /* NOP */
        }

        num_sum += list_num[i];

    }

    printf("%d %d %ld\n", num_min, num_max, num_sum);

}


Measured memory_bytes: 2140
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = (int)1e9 + 7;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 500


int dp[N][N], a[N], pref[N];

int depe(int l, int r)
{
	if (dp[l][r] != 0)
		return dp[l][r];

	if (l == r)
		return dp[l][r] = 0;


	int u = oo;
	for (int i = l; i < r; i++)
		inmin(u, depe(l, i) + depe(i + 1, r) + pref[r] - pref[l - 1]);

	return dp[l][r] = u;
}




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

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}
	


	cout << depe(1, n);
	

}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 1920
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

class UnionFind{
  int num_components;
  std::vector<int> parent;
  std::vector<int> weight;
  std::vector<int> rank;
public:
  UnionFind(int N) : num_components(N),
                     parent(std::vector<int>(N)),
                     weight(std::vector<int>(N, 1)),
                     rank(std::vector<int>(N, 0)){
    for(int i = 0; i < N; i++) parent[i] = i;
  }
  
  int find(int x){
    if(x == parent[x]) return x;
    else return parent[x] = find(parent[x]);
  }
  
  int size(int x){
    return weight[find(x)];
  }

  
  bool same(int x, int y){
    return find(x) == find(y);
  }
    
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    
    num_components--;
    if(rank[x] < rank[y]){
      weight[y] += weight[x];
      parent[x] = y;
    }else{
      weight[x] += weight[y];
      parent[y] = x;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
  
  int count(){
    return num_components;
  }
};


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

  int N, M;
  while (cin >> N >> M &&N + M){
    vector<int> H(N);
    REP(i, N){
      cin >> H[i];
    }

    vector<tuple<int, int, int> > es;
    
    REP(i, M){
      int a, b, c;
      cin >> a >> b >> c; a--, b--;
      es.push_back(make_tuple(c, a, b));
    }
    sort(ALL(es));

    vector<int> event_time;
    REP(i, N){
      event_time.push_back(H[i]);
    }
    sort(ALL(event_time));
    event_time.erase(unique(ALL(event_time)), event_time.end());
    reverse(ALL(event_time));
      
    ll res  = 0;
    UnionFind uf1(N);
    UnionFind uf2(N);
    
    for (int time : event_time){
      int last = -1;
      REP(i, M){
        int u = get<1>(es[i]);
        int v = get<2>(es[i]);
        if (H[u] >= time && H[v] >= time) {
          last = u;
          uf1.unite(u, v);
        }
      }

      int live = 0;
      REP(i, N) if (H[i] >= time){
        live++;
      }

      if (last == -1 || uf1.size(last) != live){
        res = 0;
        uf2 = UnionFind(N);
        continue;
      }
        
      REP(i, M){
        int u = get<1>(es[i]);
        int v = get<2>(es[i]);
        int c = get<0>(es[i]);
        if (H[u] >= time && H[v] >= time && !uf2.same(u, v)) {
          // cout << u + 1 << " " << v + 1 << " " << c << " " << time << endl;
          uf2.unite(u, v);
          res += c;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1708
S = input()
T = input()

cnt = len(S)-len(T)+1
man = 0

for i in range(cnt):
    an = 0
    for j in range(len(T)):
        if S[i+j] == T[j]:
            an += 1
    if man < an:
        man = an
        
print(len(T)-man)

Measured memory_bytes: 9108
#include <stdio.h>

int main()
{
  int N,A,B;
  
  scanf("%d %d %d",&N,&A,&B);
  
  int flag=0;
  
  for(int i=A;i<=B;i++)
    if(i%N==0)flag=1;
  
  if(flag)
    printf("OK");
  else
    printf("NG");
}

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

int main() {
    long long n;
    cin >> n;
    vector<long long> h(n);
    long long cnt=0,max1=0;
    rep(i,n) cin >> h[i];
    rep(i,h.size()-1){
        //cout << h.at(i) << " " << h[i+1] << endl;
        if(h[i]>=h[i+1]){
            cnt++;
        }
        else {
            max1=max(cnt,max1);
            cnt = 0;
            continue;
        }
        max1 = max(cnt,max1);
    }
    cout << max1 << endl;

}






Measured memory_bytes: 1024
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

x = x / 50
i = 0
sum = 0

y = Array.new

while 10 * (i + 1) <= x 
  i = i + 1
end

if a < i then
  i = a
end

for j in 0..i do
  x = x - 10 * j
  if x % 2 == 1 then
    if c < x && b < (x - 1) / 2 then
      y[j] = -(x - c) / 2 + b + 1
    elsif c < x then
      y[j] = (c + 1) / 2
    elsif b < (x - 1) /2 then
      y[j] = b + 1
    else
      y[j] = (x + 1)/2
    end
  else
    if c < x && b < x / 2 then
      y[j] = -(x - c) / 2 + b + 1
    elsif c < x then
      y[j] = c / 2 + 1
    elsif b < x / 2 then
      y[j] = b + 1
    else
      y[j] = x/2 + 1
    end
  end
  if y[j] < 0 then
    y[j] = 0
  end
  sum = sum + y[j]
  x = x + 10 * j
end

puts sum


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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans;
    if (k <= a) {
        ans = 1 * k;
    } else {
        ans = 1 * a;
        if (k -a <= b) {
            ans += 0 * (k - a);
        } else {
            ans += 0 * b + -1 * (k - a - b);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3712
import collections
import sys

l = collections.deque(sys.stdin.readlines())
l.pop()
s = ""
while l:
    a = 0
    b = 0
    for i in range(int(l.popleft())):
        x,y = map(int, l.popleft().split())
        if x > y:
            a = a + x + y
        elif x < y:
            b = b + x + y
        else:
            a = a+x
            b = b+y
    print(a,b)

Measured memory_bytes: 8932
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 11234567890123456;
LL N, M, s, t;
std::vector<LL>a, b, c, d, dist;
std::vector<std::vector<edge>>G;

void dijkstra(int s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(dist.begin(), dist.end(), inf);
	dist[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (dist[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to] > dist[v] + e.cost)
			{
				dist[e.to] = dist[v] + e.cost;
				que.push(P(dist[e.to], e.to));
			}
		}
	}
}

int main()
{
	in >> N >> M >> s >> t;
	a.resize(M), b.resize(M), c.resize(M), d.resize(M);
	G.resize(N + 1), dist.resize(N + 1);
	rep(i, M) in >> a[i] >> b[i] >> c[i] >> d[i];
	rep(i, M)
	{
		G[a[i]].push_back({ b[i],d[i] });
		G[b[i]].push_back({ a[i],d[i] });
		G[a[i]].push_back({ c[i],d[i] });
		G[c[i]].push_back({ a[i],d[i] });
		G[b[i]].push_back({ c[i],d[i] });
		G[c[i]].push_back({ b[i],d[i] });
	}
	dijkstra(s);
	out << dist[t] << std::endl;
	return 0;
}


Measured memory_bytes: 26760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
   int H,W;
   cin>>H>>W;
   vector<vector<char>> A(H, vector<char>(W));
   vector<vector<char>> ans(2*H, vector<char>(W));
    rep(i,H){
        rep(j,W){
            cin>>A[i][j];
            ans[i*2][j]=A[i][j];
            ans[i*2+1][j]=A[i][j];
        
        }
    }
    rep(i,2*H){
        rep(j,W){
            cout<<ans[i][j];
        }
      cout<<""<<endl;
    }
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v;
int main() {
	int h[100010]; int w[100010]; int i = 0; int a = 0;
	for (;;) {
		cin >> h[i] >> w[i];
		if (w[i] == 0 && h[i] == 0)
			break;
		i++;
		a = i;
	}
	for (int j = 0; j < a;j++) {
		for (int k = 0; k < h[j]; k++) {
			for (int l = 0; l < w[j]; l++) {
				if ((k + l) % 2 == 0)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


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

using namespace std;

int main(void)
{
	int N;
	int H[21];
	int height;
	int count;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}

	count = 0;
	height = 0;
	for (int i = 0; i < N; i++) {
		if (height <= H[i]) {
			count++;
			height = H[i];
		}
	}

	cout << count << endl;

	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 058_arc_b / Link: https://arc058.contest.atcoder.jp/tasks/arc058_b?lang=en ----- */
/* ------問題------

縦 H マス、横 W マスのマス目があります。 いろはちゃんは、今一番左上のマス目にいます。 そして、右か下に1マス移動することを繰り返し、一番右下のマス目へと移動します。 ただし、下から A 個以内、かつ左から B 個以内のマス目へは移動することは出来ません。
移動する方法は何通りあるか求めてください。
なお、答えは非常に大きくなることがあるので、答えは 109+7 で割ったあまりを出力してください。

-----問題ここまで----- */
/* -----解説等-----

point(A,w)上までの移動とpoint(A,w+1)からの移動を考えたとき、これらはすべて独立した経路を通過する

----解説ここまで---- */


LL F[200005], R[200005];
long long  powmod(long long  x, long long  n, long long  MOD) {
	long long  res = 1;
	while (n > 0) {
		if (n & 1) {
			res = (res*x) % MOD;
		}
		x = (x*x) % MOD;
		n >>= 1;
	}
	return res;
}
void make() {
	F[0] = 1;
	for (int i = 1; i<200005; i++) F[i] = F[i - 1] * i%MOD;
	for (int i = 0; i<200005; i++) R[i] = powmod(F[i], MOD - 2, MOD);
}

LL nCr(int a, int b) {
	return F[a] * R[b] % MOD*R[a - b] % MOD;
}

LL H, W, A, B;
LL ans = 0LL;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> H >> W >> A >> B;
	make();
	FOR(h, 0, H - A) {
		ans += (nCr(B - 1 + h, B - 1) * nCr(W - 1 - B + H - 1 - h, W - 1 - B)) % MOD;
		ans %= MOD;
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main()
{
  char  s[101], tmp;
  int N, r=0, b=0;
  scanf("%d\n",&N);
  for(int i=0; i<N; i++){
    scanf("%c", &tmp);
    if(tmp=='R')r++;
    if(tmp=='B')b++;
  }
  if(r>b)printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;

    vector<vector<mint>> dp(N, vector<mint>(N));
    rep(i,N) dp[0][i] = i+1;

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= N-i; j++) {
            if (S[i-1] == '<') {
                dp[i][j] = dp[i-1][N-i] - dp[i-1][j];
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
        for (int j = 1; j <= N-i; j++) {
            dp[i][j] += dp[i][j-1];
        }
    }

    cout << dp[N-1][0].a << endl;
}

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

int main() {
	int n, a[110];
	int m = n;
	int block = 0;
	cin >> n;
  	for (int i = 0; i < n; i++) {
	    cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
	    for (int j = i + 1; j < n; j++) {
	        if (a[i] == a[j]) a[j] = 0;
	    }
	}
	for (int i = 0; i < n; i++) {
	    if (a[i] > 0) block++;
	}
	cout << block;
	return 0;
}


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

int num[10];
bool chack;

void solve(int R, int L, int i){
    if(i==10) chack = true;
    if(chack == true) return;
    if(num[i]>R) solve(num[i], L, i+1);
    if(num[i]>L) solve(R, num[i], i+1);
    return;
}
int main(void){
    int N;
    cin >> N;
    while(N>0){
        chack = false;
        for(int i=0; i<10; i++)
            cin >> num[i];
        solve(0,0,0);
        if(chack)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
        N--;
    }
}



Measured memory_bytes: 3096
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())

check=1

if b-a!=e-d or e-d!=h-g:
    check=0

if b-c!=e-f or e-f!=h-i:
    check=0

if d-a!=e-b or e-b!=f-c:
    check=0

if d-g!=e-h or e-h!=f-i:
    check=0


if check==1:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using namespace std;

#define int long long

signed main() {
	int N, L;
	string S[101] = {};
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	string ans = "";
	sort(S, S + N);
	for (int i = 0; i < N; i++) {
		ans += S[i];
	}
	cout << ans << endl;
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int k,n;cin>>k>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  
  int sum = a[n-1]-a[0] + (k-a[n-1]+a[0]);
  int tmp = 0;
  rep(i,n){
    if(i){
      chmax(tmp,a[i] - a[i-1]);
    }else{
      chmax(tmp,(k-a[n-1]+a[0]));
    }
  }
  int ans = sum - tmp;
  print(ans);
  return 0;
}


Measured memory_bytes: 1024
import math
import collections

def trial_division(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n /= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 2
    if n != 1: a.append(int(n))
    return a
A, B= map(int,input().split())

Adev = list(collections.Counter(trial_division(A)).keys())
Bdev = list(collections.Counter(trial_division(B)).keys())
print(len(list(set(Adev) & set(Bdev)))+1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = int(1e9)+10;
const ll INFll = ll(1e18)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;


int main() {
	ll N; cin >> N;
	V A(N);
	rep(i, N) cin >> A[i];

	Vll S(N+1);
	rep(i, N) S[i+1] = S[i] + A[i];

	auto div = [&] (int i, int j) {
		ll th = S[i] + (S[j] - S[i])/2;
		int r = upper_bound(S.begin()+i, S.begin()+j, th) - S.begin();
		int l = r - 1;
		if (r == j) r--;
		int al = abs((S[j] - S[l]) - (S[l] - S[i]));
		int ar = abs((S[j] - S[r]) - (S[r] - S[i]));
		if (al < ar) return Pll(S[j] - S[l], S[l] - S[i]);
		else         return Pll(S[j] - S[r], S[r] - S[i]);
	};

	ll cmin = INFll;
	rep2(k, 2, N-1) {
		Pll p1 = div(0, k);
		Pll p2 = div(k, N);
		Pll mima = minmax({p1.first, p1.second, p2.first, p2.second});
		cmin = min(cmin, abs(mima.first - mima.second));
	}

	cout << cmin << endl;
	return 0;
}


Measured memory_bytes: 2560
x = int(input())

if x >= 1800:
    print(1)
elif x >= 1600:
    print(2)
elif x >= 1400:
    print(3)
elif x >= 1200:
    print(4)
elif x >= 1000:
    print(5)
elif x >= 800:
    print(6)
elif x >= 600:
    print(7)
elif x >= 400:
    print(8)


Measured memory_bytes: 9172
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#define ll long long
using namespace std;



int main(){
  ll N;
  bool ans=true;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++) cin>>A[i];

  for(int j=0;j<N;j++){
    if(A[j]%2==0){
      if(A[j]%3==0||A[j]%5==0) ans=true;
      else {ans=false;
            break;}
    }
  }

 if(ans) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;


 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100010],b[100010];
int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  long long sum=0;
  if(n>=m){printf("0");return 0;}
  for(int i=0;i<m;i++)
  {
      scanf("%d",&a[i]);
  }
  sort(a,a+m);
  sum=a[m-1]-a[0];
  for(int i=0;i<m-1;i++)
  {
      b[i]=a[i+1]-a[i];
  }
  sort(b,b+m);
  for(int i=0;i<n-1;i++)sum-=b[m-i-1];
  printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	if(s[2]==s[3]&&s[4]==s[5]){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

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

    int n; cin >> n;
    int a[n];
    REP(i, n) {
        cin >> a[i];
    }
    int q; cin >> q;
    int m[q];
    REP(i, q) {
        cin >> m[i];
    }
    int mm = m[distance(m, max_element(m, m+q))];
    int table[n+1][mm+1];
    REP(i, n+1) {
        table[i][0] = 1;
    }
    FOR(i, 1, mm+1) {
        table[0][i] = 0;
    }
    FOR(i, 1, mm+1) {
        FOR(j, 1, n+1) {
            if (i < a[j-1]) {
                table[j][i] = table[j-1][i];
            } else {
                table[j][i]= 1 - (1-table[j-1][i])*(1-table[j-1][i-a[j-1]]);
            }
        }
    }

    REP(i,q) {
        if (table[n][m[i]]) cout << "yes" << "\n";
        else cout << "no" << "\n";
    }
}


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

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

  int sum=0;
  int num;
  for(int i=1; i<=N; i++) {
    int d[4]={0,0,0,0};
    num=i;
    d[3]=num/10000; num%=10000;
    d[2]=num/1000;  num%= 1000;
    d[1]=num/100;   num%=  100;
    d[0]=num/10;    num%=   10;
    num += d[3]+d[2]+d[1]+d[0];
    // cout<<i<<" "<< d[3]<<" "<<d[2]<< " "<<d[1]<<" "<<d[0]<<" "<<num<<endl;
    if(A <= num && num <= B) sum+= i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main(){
    int n;cin>>n;
    set<string> a;
    for(int i = 0; n > i; i++){
        string s,t;cin>>s>>t;
        if(s=="insert"){
            a.insert(t);
        }else{
            if(a.count(t)!=0)cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 32104
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		// ソースコードの数を取得
		int numN = sc.nextInt();

		// ソースコードの特徴の数を取得
		int numM = sc.nextInt();

		// 演算用値Cを取得
		int numC = sc.nextInt();

		// ソースコードの特徴の数分ループ
		int[] arrayBn = new int[numM];
		for (int i = 0; i < numM; i++) {
			// 演算用の整数Bnをint型配列に取得
			arrayBn[i] = sc.nextInt();
		}

		// ソースコードの数分ループ
		int[][] arrayAn = new int[numN][numM];
		for (int i = 0; i < numN; i++) {
			for (int j = 0; j < numM; j++) {
				// ソースコードの特徴をint型2次元配列に取得
				arrayAn[i][j] = sc.nextInt();
			}
		}

		// ソースコードの数分ループ
		int[] arrayResult = new int[numN];
		for (int i = 0; i < numN; i++) {
			int value = 0;
			for (int j = 0; j < numM; j++) {
				// int型2次元配列を行単位で演算
				value = value + arrayAn[i][j] * arrayBn[j];
			}
			// 結果をint型配列に格納（1:正答する、0:正答しない）
			value = value + numC;
			if (value > 0) {
				// 正答する
				arrayResult[i] = 1;
			} else {
				// 正答しない
				arrayResult[i] = 0;
			}
		}

		// ソースコードの数分ループ
		int count = 0;
		for (int i : arrayResult) {
			if (i == 1) {
				count++;
			}
		}
		System.out.println(count);

		sc.close();
	}
}


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

int dp[101][4][4][4];

int main(){
  int N, mod=1'000'000'007, ans=0;
  cin >> N;
  dp[0][3][3][3]=1;

  for(int i=0; i<N; i++){
    for(int j=0; j<4; j++){
      for(int k=0; k<4; k++){
        for(int l=0; l<4; l++){
          if(dp[i][j][k][l]==0) continue;
          for(int m=0; m<4; m++){
            if(m==2 && l==1 && k==0) continue;
            if(m==2 && l==0 && k==1) continue;
            if(m==1 && l==2 && k==0) continue;
            if(m==2 && l==1 && j==0) continue;
            if(m==2 && k==1 && j==0) continue;
            
            dp[i+1][k][l][m] += dp[i][j][k][l];
            dp[i+1][k][l][m] %= mod;
            
          }
        }
      }
    }
  }

  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      for(int k=0; k<4; k++){
        ans += dp[N][i][j][k];
        ans %= mod;
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,m,x,y;
	cin >> n >> m >> x >> y;
	int P = 999999999;
	int N = -(P+1);
	if(n%x == 0 && m%y == 0) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(j > 0) {cout << " ";}
				if(i%x == 0 && j%y == 0) {
					cout << P;
				} else if(i%x == x-1 && j%y == y-1) {
					cout << N;
				} else {
					cout << 0;
				}
			}
			cout << '\n';
		}
	}
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    vector<pair<ll,ll> > c(4);
    ll tmp=8;
    for(int i=0;i<4;i++){
        ll a;
        cin >> a;
        c[i] = make_pair(tmp*a,a);
        tmp /= 2;

    }
    ll N; cin >> N;
    tmp = 0;
    if(N==1){
        cout << min(c[0].first,min(c[1].first,c[2].first))/2 << endl;
    }else{
        if(N%2==1){
            tmp = min(c[0].first,min(c[1].first,c[2].first))/2;
        }
        cerr << tmp << "\t";
        sort(c.begin(),c.end());
        tmp += N/2*c[0].first;
        cout << tmp << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll Prev[2019], Next[2019];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    Prev[0] = 1;
    ll ans = 0;
    ll now = 0;
    for(int i = 0; i < S.size(); i++) {
        for(int j = 0; j < 2019; j++) Next[j] = 0;
        now *= 10;
        now += (int)(S[i] - '0');
        now %= 2019;
        for(int j = 0; j < 2019; j++) {
            Next[j*10%2019] += Prev[j];
        }
        ans += Next[now];
        Next[now]++;
        swap(Prev, Next);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3808
N,x=map(int,input().split())
a=list(map(int, input().split()))
a.sort()
m=0
i=0
if a[0]>x:
    print(0)
else:
    while m<x and i<N and (m+a[i])<=x:
        m += a[i]
        i +=1
    if i==N and m!=x:
        i -=1
        print(i)
    else:
        print(i)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
    int n,k[10000];
    int i,flag,cnt;

    while(1){
	scanf("%d",&n);
	if(n==0) break;
	
	flag=1,cnt=0;
	for(i=0;i<n;i++){
	    scanf("%d",&k[i]);
	    if(k[i]>=2) flag=0;
	    if(k[i]>=1) cnt++;
	}

	if(flag) printf("NA\n");
	else printf("%d\n",cnt+1);
    }

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int h = n / 100;
  int a = (h * 100 + h * 10 + h);
  if (a >= n) {
    cout << a << endl;
  } else {
    cout << a + 111 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000];
int m = 1000000001;
int cnt = 0;
int id;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    while (true)
    {
        cnt = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] > 0)
            {
                if (a[i] < m)
                {
                    m = a[i];
                    id = i;
                }
                cnt++;
            }
        }
        if (cnt == 1)
        {
            break;
        }
        for (int i = 0; i < n; i++)
        {
            if (i != id)
                a[i] %= m;
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 640
# A - Connection and Disconnection
S = input()
K = int(input())
S = S + '1'# 番兵

# 連続する文字数をカウント
cnt = []
conti = 1
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
        
# 最初と最後の文字が同じときの補正値
comp = 0
if S[0] == S[-2]:
    # 奇数個 + 奇数個のとき
    if cnt[0]%2 == 1 and cnt[-1]%2 == 1:
        comp = K - 1
    # S =aaa などのとき
    if len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1:
        comp = K // 2
        
ans = [a//2 for a in cnt if a >= 2]
ans = sum(ans)*K + comp
print(ans)        

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=1000050;
const int mod=998244353;
int mul(int x, int y){ return (ll)x*y%mod;}
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
int sub(int x, int y){ return add(x,mod-y);}
int pow(int x, int k){ int ans=1;for(;k;k>>=1,x=mul(x,x)) if(k&1) ans=mul(ans,x);return ans;}
int inv(int x){ return pow(x,mod-2);}
/*int go[N];
vector<int> primes;
void FindPrimes()
{

}*/
int sum[N],a[N],cnt[N];
int main()
{
	int n;
	scanf("%i",&n);
	for(int i=1;i<=n;i++) scanf("%i",&a[i]),cnt[a[i]]++;
	for(int i=1;i<N;i++)
	{
		int tmp=0,all=0;
		for(int j=i;j<N;j+=i)
		{
			all=add(all,mul(tmp,mul(j,cnt[j])));
			all=add(all,mul(mul(j,j),((ll)cnt[j]*(cnt[j]-1)/2)%mod));
			tmp=add(tmp,mul(j,cnt[j]));
		}
		sum[i]=all;
	}
	int ans=0;
    for(int i=N-1;i>=1;i--)
	{
		for(int j=i*2;j<N;j+=i) sum[i]=sub(sum[i],sum[j]);
		ans=add(ans,mul(sum[i],inv(i)));
	}
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,a;
vector<int> vecx, vecy;
int main(){
	cin>>n>>m>>x>>y;
	for(int i=0;i<n;i++){
		cin>>a;
		vecx.push_back(a);
	}
	sort(vecx.begin(),vecx.end());
	for(int i=0;i<m;i++) {
		cin>>a;
		vecy.push_back(a);
	}
	sort(vecy.begin(),vecy.end());
	for(int i=vecx[n-1]+1;i<=vecy[0];i++){
		if(x<i&&i<=y){
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=3123;

int n,a[312],cnt[4],sum,a1,a2,a3;
double dp[312][312][312],res;

double solve(int a,int b)
{
    return (double)a/b;
}

int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        scanf("%d",&a[i]);
        ++cnt[a[i]];
    }
    sum=cnt[1]+cnt[2]+cnt[3];
    dp[cnt[1]][cnt[2]][cnt[3]]=1;
    for(int i=cnt[3]; i>=0; --i)
    {
        a2=cnt[2]+cnt[3]-i;
        for(int j=a2; j>=0; --j)
        {
            a3=cnt[1]+a2-j;
            for(int k=a3; k>=0; --k)
            {
                if(k!=0)
                    dp[k][j][i]+=dp[k-1][j+1][i]*solve(j+1,k+j+i);
                if(j!=0)
                    dp[k][j][i]+=dp[k][j-1][i+1]*solve(i+1,k+j+i);
                dp[k][j][i]+=dp[k+1][j][i]*solve(k+1,k+j+i+1);
                if(i+j+k!=0)
                    res+=dp[k][j][i]*solve(sum,i+j+k);
            }
        }
    }
    printf("%.9f",res);
    return 0;
}


Measured memory_bytes: 229504
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] c = new char[H][W];
        ArrayList<int[]> delta = new ArrayList<int[]>();
        int[] arr_1 = {1, 0};int[] arr_2 = {0, 1};int[] arr_3 = {-1, 0};int[] arr_4 = {0, -1};
        delta.add(arr_1);delta.add(arr_2);delta.add(arr_3);delta.add(arr_4);
        for (int i=0;i<H;i++) {
            String S = sc.next();
            for (int j=0;j<W;j++) {
                c[i][j] = S.charAt(j);
            }
        }

        long ans = 0L;
        boolean[][] flag = new boolean[H][W];
        for (int i=0;i<H;i++) {
            for (int j=0;j<W;j++) {
                if (c[i][j]=='.') continue;
                if (flag[i][j]) continue;

                ArrayDeque<int[]> q = new ArrayDeque<int[]>();
                int[] first = {i, j, 0};
                q.add(first);
                int b_cnt = 0;
                int w_cnt = 0;
                while (!q.isEmpty()) {
                    int[] rem = q.poll();
                    if (rem[0]<0 || H<=rem[0] || rem[1]<0 || W<=rem[1]) continue;
                    if (rem[2]%2==0 && c[rem[0]][rem[1]]=='.') continue;
                    if (rem[2]%2==1 && c[rem[0]][rem[1]]=='#') continue;
                    if (flag[rem[0]][rem[1]]) continue;
                    flag[rem[0]][rem[1]] = true;
                    if (rem[2]%2==0) b_cnt++;
                    if (rem[2]%2==1) w_cnt++;
                    for (int[] del : delta) {
                        int[] add = {rem[0]+del[0], rem[1]+del[1], rem[2]+1};
                        q.add(add);
                    }
                }
                // System.out.println("b, w "+b_cnt+" "+w_cnt);

                ans += (long)b_cnt*w_cnt;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 44392