akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int f[n][10],p[n][10];
    for(int i=0;i<n;i++)for(int j=0;j<10;j++)cin>>f[i][j];
    for(int i=0;i<n;i++)for(int j=0;j<=10;j++)cin>>p[i][j];
    int m=-1000000000;
    for(int i=1;i<1024;i++){
        int money=0,I=i;
        int same[n]={};
        for(int j=0;j<10;j++){
            if(I%2){
                for(int k=0;k<n;k++)if(f[k][j])same[k]++;
            }
            I/=2;
        }
        for(int j=0;j<n;j++)money+=p[j][same[j]];
        m=max(m,money);
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    if (a1 + a2 + a3 >= 22) {
        cout << "bust";
    } else {
        cout << "win";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long i;
string s;
int main()
{
	cin>>s;
	if (s.length()%2!=0) printf("No");
	else
	{
	for (i=s.length()-1;i>=s.length()/2-1;i--)
		{
			if (s[i]=='b'&&(s[s.length()-i-1]!='d')) 
			{
				printf("No");
				return 0;
			}
			if (s[i]=='d'&&(s[s.length()-i-1]!='b')) 
			{
				printf("No");
				return 0;
			}
			if (s[i]=='p'&&(s[s.length()-i-1]!='q')) 
			{
				printf("No");
				return 0;
			}
			if (s[i]=='q'&&(s[s.length()-i-1]!='p')) 
			{
				printf("No");
				return 0;
			}
		}
		printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 512
using System;
        using System.Linq;

        public class Program
        {
            public static void Main(string[] args)
            {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] sec = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int sum = input[1];

            for(int i = 1; i < input[0]; i++) sum += Math.Min(input[1], sec[i] - sec[i - 1]);

            Console.WriteLine(sum);
            }
        }

Measured memory_bytes: 28384
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};





int main() {
	int n;
	cin >> n;
	double *x = new double[n];
	string *u = new string[n];
	double total = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> u[i];
		if (u[i] == "JPY") {
			total += x[i];
		}
		else {
			total += x[i] * 380000.0;
		}
	}
	cout << total;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
	int N;
	
	vector<vector<int>> A(3, vector<int>(3));
	vector<vector<int>> C(3, vector<int>(3,0));

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A.at(i).at(j);
			C.at(i).at(j) = 0;
		}
	}

	cin >> N;

	vector<int> b(N);
	for (int i = 0; i < N; i++)cin >> b.at(i);


	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < N; k++) {
				if (A.at(i).at(j) == b.at(k))C.at(i).at(j) = 1;
				
			}
		}
	}
	if (C.at(0).at(0) == 1 && C.at(0).at(1) == 1 && C.at(0).at(2) == 1)cout << "Yes" << endl;
	else if (C.at(1).at(0) == 1 && C.at(1).at(1) == 1 && C.at(1).at(2) == 1)cout << "Yes" << endl;
	else if (C.at(2).at(0) == 1 && C.at(2).at(1) == 1 && C.at(2).at(2) == 1)cout << "Yes" << endl;
	else if (C.at(0).at(0) == 1 && C.at(1).at(1) == 1 && C.at(2).at(2) == 1)cout << "Yes" << endl;
	else if (C.at(0).at(2) == 1 && C.at(1).at(1) == 1 && C.at(2).at(0) == 1)cout << "Yes" << endl;
	else if (C.at(0).at(0) == 1 && C.at(1).at(0) == 1 && C.at(2).at(0) == 1)cout << "Yes" << endl;
	else if (C.at(0).at(1) == 1 && C.at(1).at(1) == 1 && C.at(2).at(1) == 1)cout << "Yes" << endl;
	else if (C.at(0).at(2) == 1 && C.at(1).at(2) == 1 && C.at(2).at(2) == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
	int i,j,k,dis;
	char str[81],tmp[81];

	while(gets(str)){
		i = 0;
		while(str[i] != '\0'){
			dis = 't'-str[i];
			j = i;
			tmp[0] = '\0';
			while(isalpha(str[j])){
				tmp[j-i] = (str[j]+7+dis)%26+'a';
				j++;
				tmp[j-i] = '\0';
			}
			if(!strcmp(tmp,"the") || !strcmp(tmp,"this") || !strcmp(tmp,"that")){
				for(k = 0;str[k] != '\0';k++){
					if(isalpha(str[k])){
						str[k] = (str[k]+7+dis)%26+'a';
					}
					printf("%c",str[k]);
				}
				printf("\n");
				break;
			}
			i = j+1;
		}
	}

	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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; }

__attribute__ ((constructor))
void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

//高速な素因数分解(abc 177-e)
//前処理O(N*logN), クエリO(Q*log(x_i))
template<typename T>
vector<T> smallest_prime_factors(T n) {
    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;
    for (T i = 2; i * i <= n; i++) {
    // 素数だったら
        if (spf[i] == i) {
            for (T j = i * i; j <= n; j += i) {
            // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }
    return spf;
}

template<typename T>
vector<T> factolization(T x, vector<T> &spf) {
    vector<T> ret;
    while (x != 1) {
        ret.push_back(spf[x]);
            x /= spf[x];
        }
    sort(ret.begin(), ret.end());
    return ret;
}

signed main(){
  int x;
  cin >> x;
  auto spf = smallest_prime_factors(100010);
  int index = 0;
  for(auto ans : spf){
    //   cout << ans << endl;
      if(ans==index && x <= ans){
          cout << index << endl;
          return 0;
      }
      index++;
  } 

  return 0;
}

Measured memory_bytes: 3788
n, m = map(int, input().split())
freq = [0 for i in range(m+1)]
counter = 0
for i in range(n):
    foods = list(map(int, input().split()))
    foods = foods[1:]
    for j in foods:
        freq[j] += 1
for i in range(1,m+1):
    if freq[i] == n:
        counter += 1
print(counter)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,k,i,j=1;
    cin >> n >> k;
    ll a[n+1],visited[n+1]={0};
    for(i=1;i<=n;i++) cin >> a[i];
    visited[1]=j;
	ll cnt=1;
	k--;
	i=1;
	while(!visited[a[i]] && k) {
		i = a[i];
		visited[i] = ++j;
		k--;
	}
	//cout << k << "\n";
	if(i!=a[i]) {
		ll cycleLength = visited[i]-visited[a[i]]+1;
		//cout << cycleLength << "\n";
		k = k%cycleLength;
		while(k--) {
			//cout << k << "\n";
			i=a[i];
		}
	}
	cout << a[i] << "\n";
    return 0;
}


Measured memory_bytes: 6776
#include <iostream>
using namespace std;
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX/2 + 2], R[MAX/2 + 2];

llong merge(int A[], int left, int mid, int right)
{
    llong cnt = 0;
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

llong merge_sort(int A[], int left, int right)
{
    llong v1, v2, v3;
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        v1 = merge_sort(A, left, mid);
        v2 = merge_sort(A, mid, right);
        v3 = merge(A, left, mid, right);
        return v1 + v2 + v3;
    } else {
        return 0;
    }
}

int main(int argc, char const *argv[])
{
    int n;
    int A[MAX];
    cin >> n;
    llong ans;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    ans = merge_sort(A, 0, n);

    cout << ans << endl;

    return 0;
}




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

using ll=long long;
const ll MOD=1e9+7;

ll pw(ll n,ll k){
    ll res=1;
    while(k){
        if(k&1)(res*=n)%=MOD;
        (n*=n)%=MOD;
        k>>=1;
    }
    return res;
}

int main(){
    int n,m;cin>>n>>m;
    cout<<pw(n,m)<<endl;
}


Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int main()
{
	int N;
	int M;
	int p;
	char tmp[100];
	int flag[110000];
	long long int ans = 0;
	long long int ans2 = 0;

	scanf("%d%d",&N,&M);

	for (int i = 0; i < 110000; i++)
		flag[i] = 1;

	for (int i = 0; i < M; i++)
	{
		scanf("%d%s", &p, tmp);

		if (p <= N)
		{
			if (strcmp(tmp, "AC") == 0)
			{
				if (flag[p - 1] == 1)
				{
					ans2++;
					flag[p - 1]=0;
				}
				else if(flag[p-1]>1)
				{
					ans += flag[p - 1]-1;
					ans2++;
					flag[p - 1] = 0;
				}
			}

			if (strcmp(tmp, "WA") == 0)
			{
				if (flag[p - 1] >= 1)
				{
					//ans++;
					flag[p - 1]++;
				}
			}
		}
	}

	printf("%lld %lld\n", ans2,ans);
}

Measured memory_bytes: 1272
# -*- coding: utf-8 -*-
"""
Created on Fri May 17 12:54:56 2019

@author: avina
"""

S = input()
T = input()
S_map = {}
T_map = {}
l = len(S)
k = 0
S_cnt = 0
T_cnt = 0
for i in range(l):
	s,t = S[i], T[i]
	if s in S_map:
		s_id = S_map[s]
	else:
		s_id = S_cnt
		S_map[s] = S_cnt
		S_cnt += 1
	if t in T_map:
		t_id = T_map[t]
	else:
		t_id = T_cnt
		T_map[t] = T_cnt
		T_cnt += 1
	if s_id != t_id:
		print("No");k+=1
		break
if k == 0:
    print("Yes")

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 2000001
#define VMAX 10000
#define SENTINEL 2000000000

int C[VMAX + 1];

void CountingSort(int A[], int B[], int n, int k){
    /*
    A???1?§????????????????, ????????????n
    A??????????´??????????k??\???
     */
    int i,j;
    for(i = 0; i <= k; i++) C[i] = 0;

    for(j = 1; j <= n; j++) C[A[j]]++;

    for(i = 1; i <= k; i++) C[i] = C[i] + C[i-1];

    for(j = n; j >= 1; j--){
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
}

int main(int argc, char const *argv[])
{
    int n, i, j, A[MAX+1], B[MAX+1];
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &A[i+1]);
    }

    CountingSort(A, B, n, VMAX);
    for (int i = 1; i <= n; ++i)
    {
        if(i>1) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 18808
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var s = ToInt32(ReadLine());
        var fig = 1;
        for(var i = 0; i < num; i++)
        {
            if (s + fig <= 2 * fig) fig += s;
            else fig *= 2;
        }
        WriteLine(fig);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <map> 
using namespace std;
 
const int MAX= 10000100;
 
int main(void){
  int n,cnt;
  cin>>n;
  cnt = 0;

  while(n > 1) {
    int x = n/3;
    n = min(max(x, n-2*x), max(x+1, n-2*(x+1)));
    cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1164
//close stdin
//https://codeforces.com/problemset?order=BY_RATING_ASC&tags=binary+search%2C1300-
#include <bits/stdc++.h>
using namespace std;
long long  gcd(long long  a, long long b){ 
	if (a == 0) 
		return b;  
	return gcd(b % a, a);  
	} 
long long lcmm(long long a,long long b){
	
return (a*b)/gcd(a, b);
}
	
int mod=998244353;
long long summ(long long x){
	long long ans=0;
	while(x!=0){
		ans+=(x%10);
		x=x/10;
	}
	return ans;
	
}
bool prime[1000003]; 
void SieveOfEratosthenes() 
{ 
	int n=1000002;
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 

} 

int main(){
	//freopen ("t.txt","r",stdin);
	int n;
	scanf("%d",&n);
	vector<vector<int>> arr(n,vector<int>(3,0)),cost(n,vector<int>(3,0));
	for(int i=0;i<n;i++)
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	cost[0][0]=arr[0][0];cost[0][1]=arr[0][1];cost[0][2]=arr[0][2];

	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j!=k){
					cost[i][j]=max(cost[i-1][k]+arr[i][j],cost[i][j]);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<3;i++)
		ans=max(ans,cost[n-1][i]);
	
	cout<<ans;
	



return 0;
}


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

class WeightedUnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.weight = [0] * (n + 1)

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            y = self.find(self.parent[x])
            self.weight[x] += self.weight[self.parent[x]]
            self.parent[x] = y
            return y

    def union(self, x, y, w):
        x_root = self.find(x)
        y_root = self.find(y)
        if x_root == y_root:
            return
        if self.rank[x_root] < self.rank[y_root]:
            self.parent[x_root] = y_root
            self.weight[x_root] = w - self.weight[x] + self.weight[y]
        else:
            self.parent[y_root] = x_root
            self.weight[y_root] = - w - self.weight[y] + self.weight[x]
            if self.rank[x_root] == self.rank[y_root]:
                self.rank[x_root] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


def main():
    N, M = map(int, input().split())
    wuf = WeightedUnionFind(N)
    for _ in range(M):
        l, r, d = map(int, input().split())
        if wuf.is_same(l, r):
            if wuf.diff(r, l) == d:
                continue
            else:
                print("No")
                sys.exit()
        else:
            wuf.union(r, l, d)
    print("Yes")

if __name__ == '__main__':
    main()

Measured memory_bytes: 95920
using System;
using System.Linq;
using System.Collections.Generic;

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();

            double sum = 0.0;
            for(var i = 0; i < N; i++)
            {
                sum += (1 / A[i]);
            }
            Console.WriteLine(1 / sum);
        }
    }
}


Measured memory_bytes: 13396
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int collatzProblem(int n){
	return ((n % 2) ? (3 * n + 1) : (n / 2));
}

int main(int argc, char const *argv[])
{
	int cir[503];

	scanf("%d",&cir[1]);
	for (int i = 2; i < 500; ++i)	cir[i] = collatzProblem(cir[i - 1]);
	for (int i = 1; i < 500; ++i)
	{
		for (int j = i + 1; j < 500; ++j)
		{
			if(cir[i] == cir[j]){
				printf("%d\n",j);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 128
import sys, collections

stdin = sys.stdin
n, m = map(int, stdin.readline().split())

par = [i for i in range(n)]
size = [1] * n  # size of tree
rank = [1] * n  # distance from parent


def find(x, par):
    if par[x] == x:
        return x
    else:
        return find(par[x], par)


def unite(x, y):
    x = find(x, par)
    y = find(y, par)

    if x != y:
        # xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


for _ in range(m):
    x, y, z = map(int, stdin.readline().split())
    unite(x - 1, y - 1)
    
ans = set()
for i in range(n):
    ans.add(find(i, par))
print(len(ans))

Measured memory_bytes: 23368
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
# Node
class Node
  attr_accessor :id, :edges, :visited, :cost

  def initialize(id, edges = [], visited = false, cost = nil)
    @id, @edges, @visited, @cost = id, edges, visited, cost
  end
end

# Edge
class Edge
  attr_accessor :to

  def initialize(to)
    @to = to
  end
end

# Graph
class Graph
  attr_accessor :nodes

  def initialize(data)
    @nodes = data.each_with_object({}) do |(id, edges), hash|
      edges.map! { |edge| Edge.new(*edge) }
      hash[id] = Node.new(id, edges)
    end
  end

  def bfs(start)
    @nodes.each do |id, node|
      node.visited = false
      node.cost = (id == start) ? 0 : -1
    end

    queue = [@nodes[start]]

    while queue.any?
      node = queue.shift
      node.visited = true
      node.edges.each do |edge|
        id = edge.to
        visited_node = @nodes[id]
        unless visited_node.visited
          visited_node.cost = node.cost + 1 if visited_node.cost == -1
          queue << visited_node
        end
      end
    end
  end
end

n = gets.chop.to_i

data = {}

n.times do
  u, k, *v = gets.chop.split.map(&:to_i)
  data[u] = v
end

g = Graph.new data
g.bfs(1)

g.nodes.each do |id, node|
  puts "#{id} #{(node.visited) ? node.cost : -1}"
end

Measured memory_bytes: 6652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#define f first
#define s second
using namespace std;

vector<pair<int,int> > V;

void dfs(string s,int d)
{
  if(s.length()==0)return;
  if(s[0]=='['){
    dfs(s.substr(1),d+1);
  }
  else if(s[0]==']'){
    int a=V.back().s;
    vector<int> v;
    while(1){
      if(V.back().s!=a)break;
      v.push_back(V.back().f);
      V.pop_back();
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<v.size()/2+1;i++)ans+=v[i];   
    V.push_back(make_pair(ans,d-1));
    dfs(s.substr(1),d-1);
  }
  else {
    string S="";
    S+=s[0];
    for(int i=1;;i++){
      if(s[i]==']'){
	V.push_back(make_pair(atoi(S.c_str())/2+1,d));
	dfs(s.substr(i+1),d-1);
	break;
      }
      S+=s[i];
    }
  }
}

int main()
{
  int n;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    V.clear();
    dfs(s,0);
    cout<<V[0].f<<endl;
  }
  return 0;
}

Measured memory_bytes: 44736
#include <stdio.h>

int main(void){
    int a,b,i,cnt=0;
    while(1){
        scanf("%d %d",&a,&b);
        if(a==0&&b==0) break;
        else if(cnt!=0)printf("\n");
        cnt=0;
        for(i=a;i<=b;i++){
            if(i%400==0){
                printf("%d\n",i);
                cnt++;
            }
            else if(i%4==0&&i%100!=0){
                printf("%d\n",i);
                cnt++;
            }
        }
        if(cnt==0) printf("NA\n");cnt++;
    }
    
    return 0;
}

Measured memory_bytes: 616
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = [x for x in a if '#' in x]
aT = list(zip(*a))
aT = [x for x in aT if '#' in x]
a = list(zip(*aT))
for i in a:
    print(''.join(i))


Measured memory_bytes: 9188
n=int(input())
hoge=list(map(int,input().split()))

color=[0]*9
for i in range(n):
  if(hoge[i]<3200):
    color[hoge[i]//400]+=1
  else:
    color[8]+=1

ans=0
for i in color[:8]:
  if(i!=0):
    ans+=1

if(color[8]==n):
  print(1,n)
else:
  print(ans,ans+color[8])

Measured memory_bytes: 3064
import sys
import itertools
readline = sys.stdin.buffer.readline

X, Y, Z, K = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
C = list(map(int, readline().split()))
AB = [a+b for (a,b) in list(itertools.product(A,B))]
AB.sort(reverse=True)
ans = [ab + c for (ab,c) in list(itertools.product(AB[:K],C))]
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Measured memory_bytes: 273352
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  const double PI = acos(-1);
  double a,b,x;
  cin>>a>>b>>x;
  double v = a*a*b;
  double s1 = a*a;
  double h1 = (v-x)*2.0/s1;
  double s2 = a*b;
  double h2 = x*2.0/s2;
  if (h1 <= b) {
    double theta = atan2(h1, a);
    cout<<setprecision(10)<<fixed<<theta/PI*180<<endl;
  } else {
    double theta = PI / 2.0 - atan2(h2, b);
    cout<<setprecision(10)<<fixed<<theta/PI*180<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
K, A, B = map(int, input().split())
if B - A <= 2:
    print(1 + K)
elif K <= A:
    print(1 + K)
else:
    change_num = (K - (A - 1)) // 2
    print(change_num * B - (change_num - 1) * A + (K - (A - 1)) % 2)


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

using namespace std;

long long contant[300005];

int main(){
    int N;
    long long ans = 0;
    cin >> N;
    for(int i=1; i<=3*N; i++){
        cin >> contant[i];
    }
    sort(contant+1, contant+3*N+1);
    for(int i=0; i<N; i++){
        ans+= contant[N*3-1-i*2];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
		
		if(x > 29) {
			System.out.print("Yes");
		}else {
			System.out.print("No");
		}
	}

}


Measured memory_bytes: 35844
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);i++)
using namespace std;
int main(){
  int n;
  long long total=0;
  cin >> n;
  vector<int> a(n+1,0);
  vector<int> b(n,0);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n){
    //左を倒せる限りすべて倒す
    int left = min(a[i],b[i]);
    total += left;
    a[i]-=left;
    b[i]-=left;
    //残った戦力で右を倒す
    int right = min(a[i+1],b[i]);
    total += right;
    a[i+1] -=right;
    b[i]-=right;
  }
  cout << total << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main() {
  while(1) {
    int n,w;
    cin >> n >>w;
    if(n==0 && w==0) break;
    int cnt[101]= {};
    int size = 0, ima = w,maxcnt = -1;
    for(int i=0;i<n;i++){
      int a;
      cin >> a;
      cnt[a/w]++;
      if(maxcnt < cnt[a/w]) maxcnt = cnt[a/w];
      if(a/w > size)  size = a/w;
    }
    size++;
    double ans = 0.01;
    for(int i=0;i<size;i++) ans += (1.0*cnt[i]/maxcnt)*(1.0*(size-i-1)/(size-1));
    printf("%.16f\n",ans);
    
  }
  return 0;
}

Measured memory_bytes: 1188
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    ans = 0
    for n in range(N + 1):
        if n % 3 and n % 5:
            ans += n

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 72856
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V
 
getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]
 
type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)
 
mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac
 
(.<.) f g -- combination
    | f < g = 0 
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)
 
unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)
 
mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a
 
countIf f = length . filter f
 
-- 
--
--

main = do
  [n, t] <- getIs
  inp <- replicateM n getIs
  let oks = dropWhile (\x -> last x > t) . sortOn head$ inp
  if oks == [] then putStrLn "TLE"
  else putStrLn . show . head . head $ oks


Measured memory_bytes: 1020
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n;cin>>n;
    double ans = 0.0;
    rep(i,n){
        double tmp; cin>>tmp;
        ans += 1.0/tmp;
    }
    ans = 1.0/ans;
    cout<<fixed<<setprecision(10)<< ans <<endl;return 0;
}


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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  string S;cin>>S;
  map<pair<string,string>,ll> cnt;
  for(ll s=0;s<1<<N;s++){
    string a,b;
    for(ll i=0;i<N;i++){
      ((s>>i)&1? a:b)+=S[N+i];
    }
    /*
    debug(a);
    debug(b);
    */
    cnt[{a,b}]++;
  }
  ll ans = 0;
  for(ll s=0;s<1<<N;s++){
    string a,b;
    for(ll i=0;i<N;i++){
      ((s>>i)&1? a:b)+=S[N-1-i];
    }
    ans += cnt[{b,a}];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 91904
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}


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

  int ans = 0;
  for(int i=1;i<=n;i++){
    if(i%2==0) continue;
    int tmp = i;
    int cnt = 0;
    for(int j=1;j<=i;j++){
      if(tmp%j==0) cnt++;
    }
    if(cnt==8) ans++;
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

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

LL N,M;
vector<vector<LL>> adj;

vector<LL> ans;

void solve(){
    //pair<頂点iまでの現時点で分かっている最短距離,i>
    priority_queue<pair<LL,LL>,vector<pair<LL,LL>>,greater<pair<LL,LL>>> pq;
    //pair<距離、どこからきたか>
    vector<pair<LL,LL>> dist(N+1,pair<LL,LL>(INF,-1));
    dist[1] = pair<LL,LL>(0,1);
    pq.push(pair<LL,LL>(0,1));
    while(!pq.empty()){
        LL now_cost = pq.top().first;
        LL now = pq.top().second;
        pq.pop();
        if(now_cost>dist[now].first) continue;
        for(int i=0;i<adj[now].size();i++){
            LL next = adj[now][i];
            if(dist[now].first+1<dist[next].first){
                dist[next].first = dist[now].first+1;
                pq.push(pair<LL,LL>(dist[next].first,next));
                dist[next].second = now;
            }
        }
    }
    for(int i=2;i<=N;i++){
        if(dist[i].first==-1){
            ans = vector<LL>(0);
            return;
        }
        ans.push_back(dist[i].second);
    }
}

int main(){
    cin >> N >> M;
    adj = vector<vector<LL>>(N+1);
    for(int i=0;i<M;i++){
        LL a,b;cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    solve();

    if(ans.size()==0) cout << "No" << endl;
	if(ans.size()>=1){
        cout << "Yes" << endl;
        for(int i=0;i<ans.size();i++){
            cout << ans[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15852
#include<stdio.h>
int main(){
	int a[100010],b,i,s=0;
	scanf("%d",&b);
	for(i=1;i<=b;i++){
		scanf("%d",a+i);
	}
	for(i=1;i<=b;i++){
		if(i==a[a[i]]) s++;
	}
	printf("%d\n",s/2);
}

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

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

int main(void)
{
    ll s; cin>>s;
    ll h=s/3600;
    s%=3600;
    ll m=s/60;
    s%=60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
} 


Measured memory_bytes: 3088
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1'000'000'007;
constexpr ll mod = 998244353;
const double PI = 3.14159265358;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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 main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  cin >> H >> W;
  vector<string> G(H);
  for(int i=0; i<H; i++) cin >> G[i];
  vector<vector<char>> ans(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(G[i][j] == '#'){
        ans[i][j] = G[i][j];
      }else{
        int cnt = 0;
        for(int k=0; k<8; k++){
          int ny = i+dy[k];
          int nx = j+dx[k];
          if(ny<0 || ny>=H || nx<0 || nx>=W) continue;
          if(G[ny][nx] == '#') cnt++;
        }
        ans[i][j] = '0' + cnt;
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cout << ans[i][j];      
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,M; cin >> N >> M;
    vector<Pi> ba(M);
    rep(i,M){
        cin >> ba[i].second >> ba[i].first;
    }
    sort(ba.begin(),ba.end());
    int now = 0;
    int ans = 0;
    rep(i,M){
        if(now <= ba[i].second){
            ans++;
            now = ba[i].first;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
import sys

a,b=map(int,input().split())
ss=input().strip()

if len(ss) != (a+b+1):
  print("No")
  sys.exit()

#a 3  123-345
nums=["0","1","2","3","4","5","6","7","8","9"]

for i in range(len(ss)):
  if i==a:
    if ss[i]!="-":
      print("No")
      sys.exit()
  elif ss[i] not in nums:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    string s = to_string(n);
    reverse(s.begin(), s.end());
    if(s[0] == '3'){
        cout<<"bon"<<endl;
    }
    else if(s[0] == '0' || s[0] == '1' || s[0] == '6' || s[0] == '8'){
        cout<<"pon"<<endl;
    }
    else cout<<"hon"<<endl;
    return 0;
}

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

int mod = 1000000007;

int main()
{
    int X;
    cin >> X;
    bool x = false;

    for (int64_t i = -1000; i < 1001; i++)
    {
        for (int64_t j = -1000; j < 1001; j++)
        {
            if (i * i * i * i * i - j * j * j * j * j == X)
            {
                cout << i << " " << j;
                x = true;
                break;
            }
        }
        if(x)
            break;
    }
}

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

#include <bits/stdc++.h>
//https://atcoder.jp/contests/abc151/submissions/9449187参考

using namespace std;
typedef long long ll;

//modも条件事に設定する.
ll mod = 1e9+7;

//infは条件事に設定しておく. 
ll inf = 1e6+10;
vector<ll> fac(inf);

//階乗の計算 O(N)
void modfac(){
    fac[0] = 1;
    for(ll i=1;i<inf;i++){
      fac[i] = (fac[i-1]*i)%mod;  
    }
}

//modの逆元の計算
ll modinv(ll a){
    ll b = mod, u=1,v=0;
    while(b){
        ll t = a/b;
        a -= t*b; swap(a,b);
        u -= t*v; swap(u,v);
    }
    u %= mod;
    if(u<0) u+= mod;
    return u;
}

//順列の計算
ll modperm(ll n,ll k){
    if(n<0 || k<0 || n<k) return 0;
    else return(fac[n] * modinv(fac[n-k])) %mod;
}

//組み合わせの計算
ll modcomb(ll n,ll k){
    if(n<0 || k<0 || n<k) return 0;
    else return ((fac[n] * modinv(fac[k])) % mod*modinv(fac[n - k])) % mod;
}

int main(void){
    ll N,K;cin>>N>>K;
    modfac();
    vector<ll> A(N);
    for(ll i=0;i<N;i++)cin>>A[i];
    sort(A.begin(),A.end());
    
    ll CA =modcomb(N,K);
    ll res =0;
    for(ll i=1;i<N;i++){
        ll dif = A[i]-A[i-1];
        ll L = modcomb(i,K);
        ll R = modcomb(N-i,K);
        ll T = CA - L -R;
        if(T<0)T += mod;
        ll plus = (T*dif)%mod;
        res = (res+plus)%mod;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 8832
import java.util.HashSet;
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
	    HashSet hs = new HashSet();
	    for(int i = 0 ; i < n ; i++) {
	    	hs.add(sc.next());
	    }
	    
	    System.out.println(hs.size());
	    
	}

}


Measured memory_bytes: 65564
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 99999999;
const double PI = acos(-1.0);

int G[201][201];
int N, M, R;
int r[8];
int mindist[8][8];

void WarshallFloyd(){
    REP(i, N) REP(j,N) REP(k, N) G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> R;
    REP(i, R){
        cin >> r[i];
        r[i]--;
    }
    REP(i, N){
        REP(j, N){
            if(i == j) G[i][j] = 0;
            else G[i][j] = INF;
        }
    }
    REP(i, M){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a][b] = c;
        G[b][a] = c;
    }

    WarshallFloyd();

    int v[8];
    REP(i, R){
        v[i] = i;
    }
    REP(i, R){
        REP(j, R){
            mindist[i][j] = G[r[i]][r[j]];
        }
    }

    int ans = INF;
    do {
        int tmp = 0;
        int s = v[0];
        FOR(j, 1, R){
            int g = v[j];
            tmp += mindist[s][g];
            s = g;
        }
        if(tmp < ans) ans = tmp;
    } while( next_permutation(v, v+R));

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 384
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int K,S;
int main(){
	cin>>K>>S;

	int ans=0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            if(S-(i+j)<=K && S-(i+j)>=0) ans++;
        }
    }



     cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;

ll num[10005]={0};
ll n,a,b,c,d;
map<ll,ll>mm;
ll ans = 0 ;
ll dfs(ll n){
    if(mm[n])
        return mm[n];
    if(n==0)
        return 0 ;
    mm[n]=1e18;
    if(mm[n]/n>=d) mm[n]=min(mm[n],n*d);
    if(n%2){
        mm[n]=min(mm[n],dfs(n/2)+a+d);
        mm[n]=min(mm[n],dfs(n/2+1)+a+d);
    }
    else
        mm[n]=min(mm[n],dfs(n/2)+a);
    if(n%3){
        mm[n]=min(mm[n],dfs(n/3)+b+(n%3)*d);
        mm[n]=min(mm[n],dfs(n/3+1)+b+(3-n%3)*d);
    }
    else
        mm[n]=min(mm[n],dfs(n/3)+b);
    if(n%5){
        mm[n]=min(mm[n],dfs(n/5)+c+(n%5)*d);
        mm[n]=min(mm[n],dfs(n/5+1)+c+(5-n%5)*d);
    }
    else
        mm[n]=min(mm[n],dfs(n/5)+c);
    return mm[n];
}
int main()
{
    int t;
    cin >> t;
    while(t--){
        mm.clear();
        cin >> n >> a >> b >> c >>d;
        for(int i=2;i<=1000;++i)
            num[i]=1e18;
        num[1]=d;
        mm[0]=0;
        for(int i=1;i<1000;++i){
            num[i]=min({num[i],num[i-1]+d,num[i+1]+d});
            if(2*i<1000)
                num[2*i]=min(num[2*i],num[i]+a);
            if(3*i<1000)
                num[3*i]=min(num[3*i],num[i]+b);
            if(5*i<1000)
                num[5*i]=min(num[5*i],num[i]+c);
            mm[i]=num[i];
        }
        dfs(n);
        cout << mm[n] << endl;
    }
    return 0;
}


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

int main(){
    ll max = 1e18;
    int n;
    cin >> n;
    ve<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = a[0];
    if(ans == 0) {
        cout << ans << endl;
        return 0;
    }
    rep(i,n-1){
        if(a[i+1] > (double)(max/ans)){
            ans = -1;
            break;
        }
        ans *= a[i+1];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int x1;
  cin >> x1;
  int x2;
  cin >> x2;
  int x3;
  cin >> x3;
  int x4;
  cin >> x4;
  int x5;
  cin >> x5;
  
  if (x1 == 0) {
    cout << 1;
  } else if (x2 == 0) {
    cout << 2;
  } else if (x3 == 0) {
    cout << 3;
  } else if (x4 == 0) {
    cout << 4;
  } else if (x5 == 0) {
    cout << 5;
  }
	return 0;
}


Measured memory_bytes: 3588
A, B, C, X, Y = map(int, input().split())
if A + B <= C * 2:
    ans = A * X + B * Y
else:
    ans = min(X, Y)*C*2
    if X < Y:
        if C * 2 < B:
            ans += (Y-X)*2*C
        else:
            ans += (Y - X) * B
    elif X > Y:
        if C * 2 < A:
            ans += (X-Y)*2*C
        else:
            ans += (X-Y)*A
    else:
        pass

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N;
}

int solve(){
    ll ans=0;
    for (size_t a = 1; a <= N; a++)
    for (size_t b = 1; b <= N; b++)
    for (size_t c = 1; c <= N; c++)
    {
        ans+=gcd(a,gcd(b,c));
    }
    cout << ans << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define pb                          push_back
#define repn(i, a, b)               for(int i=a; i< b; ++i)
#define forn(i, a, b)               for(int i=a; i<=b; ++i)
typedef long long ll;
const int N = 1e5 +10;
ll ans = 0;
int n;
ll child[N];
vector<pair<ll, ll>> e[N];
struct Edge {
    ll u, v, c;
    Edge(){};
    Edge(ll u, ll v, ll c): u(u), v(v), c(c) {};
} edge[N];
void dfs1(int u, int p = 0) {
    child[u] = 1;
    for(auto x: e[u]) if (x.first != p) {
        dfs1(x.first, u);
        child[u] += child[x.first];
    }
}
void dfs2(int u, int p = 0, int w = 0) {
    for(auto v: e[u]) if (v.first != p && child[v.first] > n/2)
        dfs2(v.first, u, v.second);
    for(auto v: e[u]) if (v.first != p && child[v.first] == n/2 && n%2 == 0) {
        cout << ans - v.second;
        exit(0);
    }
    bool ok = child[u] >= n/2;
    for(auto v: e[u]) if (v.first != p) ok &= !(child[v.first] > n/2);
    ll  mn = w;
    if (ok) {
        for(auto v: e[u]) mn = min(mn, v.second);
        cout << ans - mn;
        exit(0);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin >> n;
    repn(i, 1, n) {
        int u, v, c;
        cin >> u >> v >> c;
        edge[i] = {u, v, c};
        e[u].pb({v, c});
        e[v].pb({u, c});
    }
    dfs1(1);
    repn(i, 1, n) if (child[edge[i].u] > child[edge[i].v]) swap(edge[i].u, edge[i].v);
    repn(i, 1, n) {
        //cout << edge[i].u << ' ' << edge[i].v << '\n';
        ans += 2*edge[i].c*min(child[edge[i].u], n-child[edge[i].u]);
    }
    dfs2(1);
    cout << ans;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int x[n];
	for(int i=0;i<n;i++){
		if(i==0){
			x[i]=0;
		}
		else if(i==1){
			x[i]=abs(a[i]-a[i-1]);
		}
		else{
		x[i]=min(x[i-1]+abs(a[i]-a[i-1]),x[i-2]+abs(a[i]-a[i-2]));}
	}
	cout<<x[n-1]<<endl;
	return 0;
}


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

using namespace std;

using D = double;

const int N = 301;

int n, x, y, z, a[ N ];
D DP[ N ][ N ][ N ];

D dfs(int i = x, int j = y, int k = z) {
    if( (i + j + k) == 0 ) return 0.0;
    D &ret = DP[ i ][ j ][ k ];
    if( ret != -1.0 ) return ret;
    ret = 0.0;
    D p = (n * 1.0) / (i + j + k);
    if( i ) ret += dfs(i - 1, j, k) * i;
    if( j ) ret += dfs(i + 1, j - 1, k) * j;
    if( k ) ret += dfs(i, j + 1, k - 1) * k;
    ret = ret * 1.0 / (i + j + k);
    ret += n * 1.0 / (i + j + k);
    return ret;
}

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

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

    x = y = z = 0;
    for(int i = 1; i <= n; i += 1) {
        if( a[ i ] == 1 ) x += 1;
        else if( a[ i ] == 2 ) y += 1;
        else z += 1;
    }
    for(int i = 0; i <= n; i += 1)
        for(int j = 0; j <= n; j += 1)
            for(int k = 0; k <= n; k += 1)
                DP[ i ][ j ][ k ] = -1.0;
    cout << setprecision(10) << fixed << dfs() << '\n';
    return 0;
}


Measured memory_bytes: 213376