akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct List {
	struct List *next;
	int v, cost, tmp;
} list;

typedef struct {
	long long key;
	int id;
} data;
 
typedef struct {
	data *obj;
	int size;
} min_heap;
 
void push(data x, min_heap* h)
{
	int i = h->size;
	data tmp;
	h->obj[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->obj[i].key < h->obj[(i-1)/2].key) {
			tmp = h->obj[(i-1)/2];
			h->obj[(i-1)/2] = h->obj[i];
			h->obj[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}
 
data pop(min_heap* h)
{
	int i = 0, j;
	data output = h->obj[0], tmp;
	h->obj[0] = h->obj[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->obj[i*2+1].key < h->obj[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

long long* dijkstra(list **adj, int s, int n, int m)
{
	int i, *prev = (int*)malloc(sizeof(int) * (n + 1));
	long long *dist = (long long*)malloc(sizeof(long long) * (n + 1));
	for (i = 1; i <= n; i++) {
		dist[i] = (long long)1 << 60;
		prev[i] = 0;
	}
	dist[s] = 0;
	prev[s] = -s;
	
	int u, w;
	list *p;
	data d;
	min_heap h;
	h.obj = (data*)malloc(sizeof(data) * (m * 2 + 1));
	h.size = 0;
	d.key = 0;
	d.id = s;
	push(d, &h);
	while (h.size > 0) {
		u = pop(&h).id;
		if (prev[u] > 0) continue;
		prev[u] *= -1;
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (dist[u] + p->cost < dist[w]) {
				dist[w] = dist[u] + p->cost;
				prev[w] = -u;
				d.key = dist[w];
				d.id = w;
				push(d, &h);
			}
		}
	}
	
	free(prev);
	free(h.obj);
	return dist;
}

int main()
{
	int i, n, m, s, t, u, w, a, b;
	scanf("%d %d %d %d", &n, &m, &s, &t);
	list **adj = (list**)malloc(sizeof(list*) * (n + 1)), *e = (list*)malloc(sizeof(list) * m * 2);
	for (i = 1; i <= n; i++) adj[i] = NULL;
	for (i = 0; i < m; i++) {
		scanf("%d %d %d %d", &u, &w, &a, &b);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].cost = a;
		e[i*2+1].cost = a;
		e[i*2].tmp = b;
		e[i*2+1].tmp = b;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	long long *dist[2];
	dist[0] = dijkstra(adj, s, n, m);
	for (i = 0; i < m * 2; i++) e[i].cost = e[i].tmp;
	dist[1] = dijkstra(adj, t, n, m);
	
	data d;
	min_heap h;
	h.size = 0;
	h.obj = (data*)malloc(sizeof(data) * (n + 1));
	for (i = 1; i <= n; i++) {
		d.key = dist[0][i] + dist[1][i];
		d.id = i;
		push(d, &h);
	}
	
	d.id = 0;
	for (i = 0; i < n; i++) {
		while (d.id <= i) d = pop(&h);
		printf("%lld\n", (long long)1000000000000000 - d.key);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 10868
import sys
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
N = int(input())
M = [int(input()) for i in range(N)]
for m in range(len(M)):
	if M[m] in A:
		A[A.index(M[m])] = 0
	elif M[m] in B:
		B[B.index(M[m])] = 0
	elif M[m] in C:
		C[C.index(M[m])] = 0
for t in range(3):
	if A[t] + B[t] + C[t] == 0:
		print('Yes')
		sys.exit()
if sum(A) == 0 or sum(B) == 0 or sum(C) ==0:
	print('Yes')
	sys.exit()
elif A[0] + B[1] + C[2] == 0:
	print('Yes')
	sys.exit()
elif A[2] + B[1] +C[0] == 0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l, l[i] + l[j]) - (j + 1)

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43932
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,t;
  cin>>n>>x>>t;
  int r=n;
  int m=t;
  for(;;)
  {
   r=r-x;
    if(r<=0)
      break;
    else if(r<x)
    {
      m=m+t;
      break;
    }
    m=m+t;
  }
    cout<<m<<endl;

 return 0;
}

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

using namespace std;

int main(){
  string a, b;
  char op;
  cin >> a >> op >> b;
  
  int i = 0;
  
  if (op == '+') {
    i = stoi(a) + stoi(b);
  }
  else {
    i = stoi(a) - stoi(b);
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string S;
  cin >> S;
  int w = 0;
  int r = 0;
  int ans = 0;
  for (int i = 0; i < n; i++){
    if (S.at(i) == 'R') {
      r++;
    } else {
      w++;
    }
  }
  if (w == 0 || r == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < r; i++){
    if (S.at(i) == 'W') {ans++;}
  }
  cout << ans << endl;
}

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

const int INF = 1 << 30;

int t[22][22];
int dp[101010];

void solve(int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n + 1; j++) cin >> t[i][j];
    }
    for (int i = 1; i < 1 << n; i++) dp[i] = INF;
    dp[0] = 0;
    for (int mask = 1; mask < 1 << n; mask++) {
        for (int j = 0; j < n; j++) {
            if (!(mask & (1 << j))) continue;
            int min_time = t[j][0];
            int prev_set = mask & (~(1 << j));
            if (prev_set == 0) {
                dp[mask] = min_time;
                break;
            }
            for (int k = 0; k < n; k++) {
                if (!(prev_set & (1 << k))) continue;
                min_time = min(min_time, t[j][k + 1]);
            }
            dp[mask] = min(dp[mask], dp[prev_set] + min_time);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while (true) {
        cin >> N;
        if (N == 0) break;
        solve(N);
    }
    return 0;
}


Measured memory_bytes: 3356
#coding:utf-8
n = int(input())
numbers = list(map(int,input().split()))

print(*numbers)

for i in range(1,n):
    tmp = numbers[i]
    j = i - 1

    while j >= 0 and numbers[j] > tmp:
        numbers[j+1] = numbers[j]
        j -= 1
    numbers[j+1] = tmp

    print(*numbers)

Measured memory_bytes: 6756
#include <stdio.h>

int main()
{
  int kazu1,kazu2,K,k,amari;
  scanf("%d%d",&kazu1,&kazu2);
  if(kazu1>kazu2){K=kazu1;k=kazu2;}
  else{K=kazu2;k=kazu1;}

  while(1)
    {
      amari=K%k;
      if(amari==0)break;
      K=k;
      k=amari;
    }

  printf("%d\n",k);
  return 0;
}
  
  



Measured memory_bytes: 2108
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (500*a)+(100*b)+(50*c) == X:
                ans += 1

print(ans)


Measured memory_bytes: 3060
import sys

input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    k = [set([int(i) for i in input().split()[1:]]) for _ in range(n)]
    ans = k[0]
    for i in k[1:]:
        ans &= i
    print(len(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.io.*
import java.util.*

fun solve(N: Long){
    var count = 0
    for (n in 1..N step 2){
        if(countDivisor(n)==8) count++
    }
    println(count)
    return
}

fun countDivisor(n: Long): Int{
    var count = 0
    for (i in 1..n){
        if (n % i == 0L ) count++
    }
    return count
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    solve(N)
}



Measured memory_bytes: 31520
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
int main() {
    int n, w, h, s, t;
    int f[100][100];  // field

    while (cin >> n, n) {
        cin >> w >> h;

        memset(f, 0, sizeof(f));
        int x, y;
        for (int i = 0; i < n; i++) {
            cin >> x >> y;
            f[y][x] = 1;
        }

        cin >> s >> t;
        int max = 0;
        for (int y = 1; y <= h; y++) {
            for (int x = 1; x <= w; x++) {
                int cnt = 0;
                for (int y2 = 0; y2 < t; y2++) {
                    if (y + y2 > h) {
                        break;
                    }
                    for (int x2 = 0; x2 < s; x2++) {
                        if (x + x2 > w) {
                            break;
                        }

                        cnt += f[y + y2][x + x2];
                        if (cnt > max) {
                            max = cnt;
                        }
                    }
                }
            }
        }
        cout << max << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int keta(ll n)
{
    return to_string(n).size();
}

int F(ll a, ll b)
{
    return max(keta(a), keta(b));
}

int main(void)
{
    ll N,rootN;
    ll a , b;
    ll Min = INF;
    cin >> N;
    rootN = sqrt(N)+1;
    REP1(i, rootN) {
        if(N % i == 0) {
            Min = min(Min, (ll)F(i, (ll)N / i));
        }
    }
    cout << Min << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static final int MAX = (int)1e5*2+9;
    public static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] c = new int[MAX];
        HashMap<Integer, TreeSet<Integer>> h = new HashMap<>();
        for(int i=0; i<n; i++){
            c[i] = Integer.parseInt(sc.next());
            if(h.get(c[i]) != null){
                h.get(c[i]).add(i);
            }else{
                TreeSet<Integer> t = new TreeSet<>();
                t.add(MAX);
                h.put(c[i], t);
            }
        }
        
        long sum = 0;
        long[] d = new long[n];
        for(int i=0; i<n; i++){
            sum += d[i];
            sum %= MOD;
            TreeSet<Integer> t = h.get(c[i]);
            int tmp = t.higher(i);
            if(tmp < n && i+1!=tmp){
                d[tmp] += sum+1;
                d[tmp] %= MOD;
            }
        }
        
        System.out.println((sum+1)%MOD);
    }
}


Measured memory_bytes: 103312
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

string S;

int main(void){
	cin>>S;
	if(S[0]=='Y' && S[1]=='A' && S[2]=='K'&&S[3]=='I'){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

const long inf = 1e18;
int h, w, m;
int si, sj, ti, tj;
vector<string> s; 

const int di[] = { 1, 0, -1, 0 };
const int dj[] = { 0, 1, 0, -1 };
using PP = pair<long, long>;
using TT = pair<PP, PP>;
long sub() {
  vector<vector<vector<long>>>
    dist(h + 2, vector<vector<long>>(w + 2, vector<long>(4, inf)));
  priority_queue<TT, vector<TT>, greater<TT>> q;
  for (int k = 0; k < 4; ++k) {
    q.push(TT(PP(0, k), PP(si, sj)));
  }
  while (!q.empty()) {
    auto t = q.top(); q.pop();
    long d = t.first.first;
    int k = t.first.second;
    int i = t.second.first;
    int j = t.second.second;
    if (dist[i][j][k] != inf) continue;
    if (s[i][j] == '@') continue;
    dist[i][j][k] = d;
    q.push(TT(PP(d + 1, k), PP(i + di[k], j + dj[k])));
    for (int nk = 0; nk < 4; ++nk) {
      if (nk == k) continue;
      long nd = (d + m - 1) / m * m;
      q.push(TT(PP(nd, nk), PP(i, j)));
    }
  }
  
  long mn = inf;
  for (int k = 0; k < 4; ++k) {
    mn = min(mn, dist[ti][tj][k]);
  }
  return mn;
}

int main() {
  cin >> h >> w >> m;
  cin >> si >> sj >> ti >> tj;
  s.push_back(string(w + 2, '@'));
  for (int i = 0; i < h; ++i) {
    string t;
    cin >> t;
    s.push_back('@' + t + '@');
  }
  s.push_back(string(w + 2, '@'));
  long ans = sub();
  cout << (ans == inf ? -1 : (ans + m - 1) / m) << endl;
}

Measured memory_bytes: 287440
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)

ll dp[100005][2][100];

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

    string s; cin >> s;
    int n=s.size();
    int D; cin >> D;

    dp[0][0][0]=1;
    rep(i, n) rep(j, 2) rep(k, D){
        int lim= j?9:s[i]-'0';
        rep(d, lim+1) (dp[i+1][j || d<lim][ (k+d)%D ] += dp[i][j][k]) %= mod;
    }

    ll ans=0;
    rep(j, 2) ans+=dp[n][j][0];
    --ans;
    chmod(ans);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 16640
n=int(input())
w=list(map(int,input().split()))
z=100
for i in range(n):
  s1=0
  s2=0
  for j in range(i+1):
    s1+=w[j]
  for k in range((n-i)-1):
    s2+=w[-(k+1)]
  if z>abs(s1-s2):
    z=abs(s1-s2)
print(z)

Measured memory_bytes: 9180
package main

import "fmt"

func main() {

	mod := 998244353

	n := 0
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	b := make([]int, n+1)
	for _, v := range a {
		b[v]++
	}

	if a[0] != 0 || b[0] != 1 {
		fmt.Println(0)
		return
	}

	n--
	ans := 1

	idx := 1
	for n > 0 {
		for i := 0; i < b[idx]; i++ {
			ans *= b[idx-1]
			ans %= mod
			n--
		}
		idx++
	}

	fmt.Println(ans)
}


Measured memory_bytes: 7424
import sys

n = int(sys.stdin.readline().strip())
arr = []
for _ in range(n):
    a,b,c = map(int, sys.stdin.readline().strip().split(' '))
    arr.append((a,b,c))


dp = [[-1, -1, -1] for _ in range(n)]
dp[0][0] = arr[0][0]
dp[0][1] = arr[0][1]
dp[0][2] = arr[0][2]
for i in range(1,n):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + arr[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + arr[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + arr[i][2]

print(max(dp[n-1]))

Measured memory_bytes: 40240
/*
Powered by 0736TuT
Code + Music + Games = Life
*/

#include<iostream>
#include<cstdio>
#define MAXN 100

typedef long long qwq;

using namespace std;

class Vector
{
public:
    double x,y;
    double operator *(const Vector &rhs) const {return x*rhs.y-y*rhs.x;}
    Vector operator -(const Vector &rhs) const
    {
	Vector res;
	res.x=x-rhs.x; res.y=y-rhs.y;
	return res;
    }
}v[MAXN],lft;

int n;
double ans=0;

int main()
{
    for(int T=1; ;T++)
    {
	scanf("%d",&n); if(!n) break;
	lft.x=123456;
	for(int i=1;i<=n;i++)
	{
	    scanf("%lf%lf",&v[i].x,&v[i].y);
	    if(v[i].x<lft.x) lft=v[i];
	}
	for(int i=1;i<=n;i++) v[i]=v[i]-lft;
	ans=0;
	for(int i=1;i<n;i++)
	    ans+=v[i+1]*v[i];
	ans+=v[1]*v[n];
	printf("%d %.1lf\n",T,ans/2);
    }
    return 0;
}

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

int main() {
  int N, W;
  cin >> N >> W;
  vector<pair<int, int>> items(N+1);
  items[0] = make_pair(0, 0); //1オリジンに設定
  for (int i = 1; i <= N; i++) {
    int v, w;
    cin >> v >> w;
    items[i] = make_pair(v, w);
  }


  vector<vector<int>> dp(N+1, vector<int>(W+1, 0));

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= W; j++) {
      dp[i][j] = dp[i-1][j];
      if (j < items[i].second) continue;
      if (items[i].first + dp[i-1][j-items[i].second] > dp[i][j]){
        dp[i][j] = items[i].first + dp[i-1][j-items[i].second];
      }
    }
  }

  int maxValue = dp[N][W];
  cout << maxValue << endl;
  return 0;
}



Measured memory_bytes: 6848
def merge(A, left, mid, right):
	global cnt

	L = A[left:mid] + [1000000001]
	R = A[mid:right] + [1000000001]

	i = j = 0
	for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	cnt += right - left

def mergeSort(A, left, right):
	if left + 1 < right:
		mid = (left + right) // 2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)

if __name__ == '__main__':
	n = int(input())
	A = list(map(int, input().split()))
	cnt = 0
	mergeSort(A, 0, n)
	print(*A)
print(cnt)



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

typedef struct{
  string name;
  long long start;
  long long end;
}Era;

int main()
{
  Era E[1000];
  int N,Q,s;

  while(1){
    cin>>N>>Q;
    if(N==0&&Q==0)break;
    for(int i=0;i<N;i++){
      cin>>E[i].name>>s>>E[i].end;
      E[i].start=(E[i].end-s);
    }
    for(int i=0;i<Q;i++){
      cin>>s;
      for(int j=0;j<N;j++){
	if(E[j].start<s && s<=E[j].end){
	  cout<<E[j].name<<" "<<(s-E[j].start)<<endl;
	  break;
	}
        if(j==N-1)cout<<"Unknown"<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1312
import sys
import math
import collections
import bisect
import itertools
import decimal
import copy
import heapq

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
flush = lambda: sys.stdout.flush()


# ===CODE===
def main():
    s = input()
    if s[-1] == "s":
        s += "es"
    else:
        s += "s"

    print(s)


if __name__ == '__main__':
    main()


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

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
// 1. dpを書く
ll dp[51][2501][51]={};
// 2. nを書く
int N,A;
ll X[51];
// 7. calcを書く
ll calc(int p,int m,int r){
	// 8. dpがあれば出力
	if(dp[p][m][r]>=0)return dp[p][m][r];
	// 9. dpを計算

	dp[p][m][r]=calc(p-1,m,r);
	if(m>=X[p])dp[p][m][r]+=calc(p-1,m-X[p],r-1);
	return dp[p][m][r];
}
int main() {
	cin>>N>>A;

	//3.初期化
	for(int i=1;i<51;i++){
		for(int j=1;j<2501;j++){
			for(int k=1;k<51;k++){
				dp[i][j][k]=-1;
			}
		}
	}
	for(int i=0;i<N+1;i++){
		dp[i][0][0]=1;
	}
	//4.入力

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

	//5.はじに注意

	//6.出力
	ll total=0;
	for(int i=1;i<N+1;i++){
		total+=calc(N,i*A,i);
	}


	cout<<total<<endl;


	return 0;
}


Measured memory_bytes: 50048
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	vector<int> a = { A,B,C };
	sort(a.begin(), a.end());
	int cn = 0;
	if (a[0] % 2 == a[1] % 2 && a[0] % 2 != a[2] % 2) {
		a[0]++;
		a[1]++;
		cn++;
	}
	if (a[0] % 2 == a[2] % 2 && a[0] % 2 != a[1] % 2) {
		a[0]++;
		a[2]++;
		cn++;
	}
	if (a[2] % 2 == a[1] % 2 && a[0] % 2 != a[2] % 2) {
		a[2]++;
		a[1]++;
		cn++;
	}
	cout << ((a[2] - a[0]) + (a[2] - a[1])) / 2 + cn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  char S[100];
  scanf ("%s",S);
  if (S[0] == 'S') puts("Cloudy");
  if (S[0] == 'C') puts("Rainy");
  if (S[0] == 'R') puts("Sunny");
return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MAX_N (1010)
#define MAX_W (10010)
typedef long long ll;

int CountingSort( int A[], int B[] );

int A[MAX_N];
int B[MAX_N];
int C[MAX_W + 1];
bool used[MAX_N];
int n;

int main()
{
    ll ans = 0;
    int min_v = MAX_W;
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
	scanf("%d", &A[i]);
	min_v = min( min_v, A[i] );
    }

    CountingSort( A, B );

    for ( int i = 0; i < n; i++ ) {
	if ( !used[i] ) {
	    int cur_i = i;
	    int part_min_v = MAX_W;
	    ll sum_w = 0;
	    int num = 0;
	    ll v0, v1;

	    while ( true ) {
		if ( used[cur_i] ) break;
		used[cur_i] = true;
		num++;
		part_min_v = min( part_min_v, A[cur_i] );
		sum_w += A[cur_i];
		cur_i = C[A[cur_i]];
	    }

	    v0 = sum_w + ( num - 2 ) * part_min_v;
	    v1 = sum_w + part_min_v + ( num + 1 ) * min_v;

	    ans += min( v0, v1 );
	}
    }

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

    return 0;
}


int CountingSort( int A[], int B[] )
{
    for ( int i = 0; i < n; i++ ) {
	C[A[i]]++;
    }

    for ( int i = 1; i < MAX_W; i++ ) {
	C[i] = C[i] + C[i-1];
    }

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

    return 0;
}

Measured memory_bytes: 1072
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int l = s.length();
		String ans = "";

        for (int i = 0; i < l; i++) {
        	ans += "x";
        }
        System.out.println(ans);
		}
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl

class UnionFind {
    public:
        vector<ll> par;     // 親
        vector<ll> rank;    // 木の深さ

        UnionFind() {}
        UnionFind(ll n) {
            par.resize(n, -1);
            rank.resize(n, 0);
            REP(i, n) {
                par[i] = i;
                rank[i] = 1;
            }
        }

        // 木の根を求める
        ll find(ll x) {
            if (x != par[x]) par[x] = find(par[x]);
            return par[x];
        }

        // xとyの属する集合を併合
        void unite(ll x, ll y) {
            x = find(x); y = find(y);
            if (x == y) return;
            if (rank[x] > rank[y]) {
                par[y] = x;
                rank[x] += rank[y];
            } else {
                par[x] = y;
                rank[y] += rank[x];
            }
        }

        // xとyが同じ集合に属するか否か
        bool same(ll x, ll y) {
            return find(x) == find(y);
        }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    ll N, M; cin >> N >> M;

    UnionFind uf = UnionFind(N + 1);

    REP(i, M) {
        ll A, B; cin >> A >> B;
        uf.unite(A, B);
    }

    ll ans = *max_element(uf.rank.begin(), uf.rank.end());
    cout << ans << "\n";
}

Measured memory_bytes: 6372
import java.util.Arrays;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] p = new int[n];
		int res = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		for (int i = 1; i < n - 1; i++) {
			int[] a = { p[i - 1], p[i], p[i + 1] };
			Arrays.sort(a);
			if (a[1] == p[i]) {
				res++;
			}
		}

		System.out.println(res);
	}
}

Measured memory_bytes: 23636
def prime_factorize(n):
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1

N = int(input())
a = [0]*(N+1)
for i in range(2, N+1):
    prime_factorize(i)
ans = 1
for i in a:
    if i > 0:
        ans *= (i+1)
big = 10**9 + 7
print(ans % big)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(),vec.end()
#define ll long long

int main(){
    int n;
    cin >> n;
    map<string, ll> m;
    rep(i,n){
        string s;
        cin >> s;
        sort(all(s));
        m[s]++;
    }
    ll sum = 0;
    for(auto x : m){
        sum += (x.second * (x.second - 1)) / 2;
    }
    cout << sum << endl;
}

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

x = int(input())
ans = 1
for i in range(2, x + 1):
    j = i
    while True:
        j *= i
        if j > x:
            if abs(x - ans) >= abs(x - j//i) and j//i != i:
                ans = j//i
            break
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define MOD 1000000007
#define _GLIBCXX_DEBUG

string n;
int s;

ll solve(int k, int start, int size){
    if(k==1){
        return 9*(size-1) + n[start] - '0';
    }
    int next;
    for(next=start+1; next<s; next++){
        if(n[next] != '0') break;
    }
    if(next==s){
        if(k==2){
            return (size-1)*(size-2)/2*9*9 + (size-1)*9*(n[start]-'0'-1);
        }else{
            return (size-1)*(size-2)*(size-3)/6*9*9*9 + (size-1)*(size-2)/2*9*9*(n[start]-'0'-1);
        }
    }
    if(k==2){
        return (size-1)*(size-2)/2*9*9 + (n[start]-'0'-1)*(size-1)*9 + solve(1, next, s-next);
    }else{
        return (size-1)*(size-2)*(size-3)/6*9*9*9 + (n[start]-'0'-1)*(size-1)*(size-2)/2*9*9 + solve(2, next, s-next);
    }
}

int main(void){
    int k;
    cin >> n >> k;
    s = n.size();
    cout << solve(k, 0, s) << endl;
}

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


int main()
{
    int n;
    while(cin>>n)
    {
        int i;
        int k=0;
        for(i=1;i<=n;i++)
        {
            int m=log10(i)+1;
            if(m%2)
                k++;
        }
        cout<<k<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    string S;

int main(){
    cin>>S;


    cout<<(S.substr(0,4)=="YAKI"?("Yes"):("No"));
    return 0;

}


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

int main()
{
    int numa, numb;
    scanf("%d %d",&numa,&numb);
    vector<int> v;
    for(int i=0;i<numa;i++){
        int current;
        cin >> current;
        v.push_back(current);
    }
    sort(v.begin(),v.end(),greater<int>());
    int ans = 0;
    for(int i=0;i<min(numa, numb);i++){
        ans += v[i];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#include <algorithm>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;
 
int main(){
  int n, m;
  long long k, x, max=0;
  cin >> n >> m >> k;
  long long a[n+1], b[m+1];
  a[0]=0; b[0]=0;
  rep(i,n) {
    cin >> x;
    a[i+1] = a[i]+x;
  }
  rep(i,m) {
    cin >> x;
    b[i+1] = b[i]+x;
  }
  int j=m;
  rep(i,n+1){
    if(a[i]>k) break;
    while(b[j]+a[i]>k&&j>0) j--;
    if(max<i+j) max=i+j;
  }

  cout << max << endl;
 
  
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int x,y;
    cin >> x >> y;
    int i[] = {0,1,2,1,3,1,3,1,1,3,1,3,1};
    if(i[x] ==  i[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
if __name__ == "__main__":
  x, y = [int(a) for a in input().split()]
  t = 2
  k = 4
  cnt = 0
  ans = "No"
  for i in range(x+1):
    cnt += i * t
    cnt += (x - i) * k
    if cnt == y:
      ans = "Yes"
      break
    cnt = 0
  print(ans)


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

int n;
int kt[4];
double dp[310][310][310];

double dfs(int i, int j, int k){
	if(dp[i][j][k] >= 0) return dp[i][j][k];
	if(i+j+k == 0) return 0.0;
	double res = 0.0;
	if(i > 0) res += dfs(i-1, j, k) * i;
	if(j > 0) res += dfs(i+1, j-1, k) * j;
	if(k > 0) res += dfs(i, j+1, k-1) * k;
	res += n;
	res /= i+j+k;
	return dp[i][j][k] = res;
}

int main(){
	int a;
	scanf("%d", &n);
	for(int i=0; i < n; i++) {
		scanf("%d", &a);    kt[a]++;
	}
	for(int i=0; i <= n; i++)
		for(int j=0; j <= n; j++)
			for(int k=0; k <= n; k++)
				dp[i][j][k] = -1;
	printf("%.12lf", dfs(kt[1], kt[2], kt[3]));
}


Measured memory_bytes: 227712
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl

using namespace std;
using lli = long long int;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli type1[100010] = {};
lli type2[100010] = {};

int main(void) {

	lli n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		lli v;
		cin >> v;
		if (i % 2) {
			type1[v]++;
		}
		else {
			type2[v]++;
		}
	}

	lli type1_num = max_element(type1, type1 + 100001) - type1;
	lli ans1 = n - (type1[type1_num] + max(*max_element(type2 + type1_num + 1, type2 + 100001), *max_element(type2, type2 + type1_num - 1)));

	lli type2_num = max_element(type2, type2 + 100001) - type2;
	lli ans2 = n - (type2[type2_num] + max(*max_element(type1 + type2_num + 1, type1 + 100001), *max_element(type1, type1 + type2_num - 1)));

	COUT(min(ans1,ans2));

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[200005], v[200005];
signed main() {
  int n, k;
  cin>>n>>k;
  int i, j;
  for(i = 1; i <= n; i++)  cin>>a[i];
  for(i = 1, j = 1; !v[i] && k; i = a[i], j++, k--)
    v[i] = j; //timer at which you went to this city
  k = k % (j - v[i]); //mod k with loop length
  for(; k; i=a[i], k--);
  cout<<i<<"\n";
  return 0;
}


Measured memory_bytes: 6716
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int sn;

int main(){
    string s;cin>>s;
    int value=stoi(s);
    for(int i=0;i<s.length();i++){
        sn+=s[i]-'0';
    }
    if(value%sn==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
 
using namespace std;
 
int main(){
    int n;
    scanf("%d\n", &n);

    int num_ab = 0;
    int x2a = 0;
    int b2a = 0;
    int b2x = 0;

    for(int i = 0; i < n; ++i){
        string s;
        getline(cin, s);

        if(s.at(0) == 'B' && s.back() == 'A'){
            b2a++;
        }else if(s.at(0) == 'B'){
            b2x++;
        }else if(s.back() == 'A'){
            x2a++;
        }
        for(int j = 0; j < s.size() - 1; ++j){
            if(s.at(j) == 'A' && s.at(j+1) == 'B'){
                num_ab++;
            }
        }
    }

    int ans = num_ab;
    while(true){
        if(b2a > 0 && b2x > 0){
            int m = min(b2a, b2x);
            ans += m;
            b2a -= m;
        }else if(x2a > 0 && b2a > 0){
            int m = min(x2a, b2a);
            ans += m;
            b2a -= m;
        }else if(x2a > 0 && b2x > 0){
            int m = min(x2a, b2x);
            ans += m;
            x2a -= m;
            b2x -= m;
        }else if(b2a > 1){
            int m = b2a / 2;
            ans += m;
            b2a -= m;
        }else{
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main()
{
	int a, b, c, br=0;
	cin >> a >> b >> c;
	while(a > c && a > b){
		c++;
		b++;
		br++;
	}
	while(b > c && b > a){
		c++;
		a++;
		br++;
	}
	while(c > a && c >b){
		a++;
		b++;
		br++;
	}

	while(a+2 <= max(b, c)){
		a+=2;
		br++;
	}
	while(b+2 <= max(a, c)){
		b+=2;
		br++;
	}
	while(c+2 <= max(b, a)){
		c+=2;
		br++;
	}

	if(a == b && a == c && b == c){
		cout << br <<endl;
		return 0;
	}

	if(a < min(b,c) || b < min(a,c) || c < min(a,b)){
		br+=2;
		cout << br <<endl;
		return 0;
	}

	br++;
	cout << br <<endl;

    return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
divlist = []
ans = 100000
for i in range(1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        divlist.append(i)
for i in divlist:
    fa = len(str(i))
    fb = len(str(int(n / i)))
    ans = min(ans, max(fa, fb))
print(ans)

Measured memory_bytes: 39152
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed Jun  6 20:42:36 2018
//
package main

import "fmt"

var N int64
var arr []int64

func main() {
	fmt.Scan(&N)

	arr := make([]int64, N)
	var total int64
	for i := range arr {
		fmt.Scan(&arr[i])
		total += arr[i]
	}

	sums := N * (N + 1) / 2
	if total%sums != 0 {
		fmt.Println("NO")
		return
	}

	m := total / sums
	diff := make([]int64, N)
	for i := int64(0); i < N; i++ {
		diff[i] = arr[(i+1)%N] - arr[i] - m
	}

	//fmt.Println(diff)

	total = 0
	for _, v := range diff {
		if v > 0 || (-v)%N != 0 {
			fmt.Println("NO")
			return
		}
		total += v
	}

	if (-total)/N == m {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 5504
import numpy as np
from numpy import linalg as LA

N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X = np.array(X)

counter = 0
    
for i in range(N-1):
    for j in range(N-i-1):
        if LA.norm(X[i]-X[i+j+1], 2).is_integer() == True:
            counter += 1
            
print(counter)

Measured memory_bytes: 12496
using System;
namespace ino{
    class ABC84c{
        static void Main(){

            int n = int.Parse(Console.ReadLine());
            int[] c = new int[n-1];
            int[] s = new int[n-1];
            int[] f = new int[n-1];
            string[] csf;
            for(int i=0;i<n-1;i++){
                csf = Console.ReadLine().Split(' ');
                c[i] = int.Parse(csf[0]);
                s[i] = int.Parse(csf[1]);
                f[i] = int.Parse(csf[2]);
            }

            for(int i=0;i<n-1;i++){
                int ans = 0;
                for(int j=i;j<n-1;j++){
                    if(ans<=s[j]){
                        ans = s[j];
                        ans += c[j];
                    }else{
                      if(ans%f[j]==0){
                        ans += c[j];
                      }else{
                        ans += f[j] - ans%f[j];
                        ans += c[j];
                      }
                        
                    }
                }
                Console.WriteLine(ans);
            }
            Console.WriteLine(0);
        }
    }
}

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

int main() {
   string S,T;
   cin >> S >> T;
   int total;
   for (int i=0; i<S.size(); i++) {
       int count=0;
       for (int j=0; j<T.size(); j++) {
           if (i+j>=S.size()) break;
           if (S[i+j]!=T[j]) count++;
           if (j==T.size()-1) {
               if (i==0) total=count;
               else if (count<total) total=count;
           }
       }
   }
   cout << total << endl;
}

Measured memory_bytes: 3596
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

auto start = chrono::system_clock::now();

inline double get_time() {
    auto end = chrono::system_clock::now();
    auto dur = end - start;
    double msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
    return msec;
}

int D;
vector<int> c(26);
vector<vector<int>> s;

inline int compute_score(const vector<int>& out) {
    int score = 0;
    vector<int> last(26, -1);
    rep(d, sz(out)) {
        score += s[d][out[d]];
        last[out[d]] = d;
        rep(i, 26) {
            score -= c[i] * (d - last[i]);
        }
    }
    return score;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> D;
    rep(i, 26) cin >> c[i];
    s.resize(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> out;
    
    rep(_, D) {
        int max_score = numeric_limits<int>::lowest();
        int best_i = 0;
        rep(i, 26) {
            out.push_back(i);
            int score = compute_score(out);
            if (chmax(max_score, score)) best_i = i;
            out.pop_back();
        }
        out.push_back(best_i);
    }

    rep(d, D) cout << out[d] + 1 << endl;
    
    // random_device rnd;
    // mt19937 mt(rnd());
    // uniform_int_distribution<> rand_d(0, D-1);
    // uniform_int_distribution<> rand_t(0, 25);
    // int to_d = rand_d(mt);
    // int to_t = rand_t(mt);
    
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int n,m,a[310][310];
bool use[310];

int dfs(){
	int li[310] = {};
	
	REP(i,0,n){
		REP(j,0,m){
			if(use[a[i][j]]){
				li[a[i][j]]++;
				break;
			}
		}
	}
	
	int ma = -1, pos;
	REP(i,0,m) if(use[i] and ma < li[i]) ma = li[i], pos = i;
	if(ma != -1) use[pos] = false;
	else return INF;
	
	return min(ma, dfs());
}

int main(){
	cin >> n >> m;
	REP(i,0,n) REP(j,0,m) cin >> a[i][j], a[i][j]--;
	
	REP(i,0,m) use[i] = true;
	cout << dfs() << endl;
	return 0;
}


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

int main(void){
  int N;
  cin >> N;
  
  int P[N];
  int i=0;
  while(cin>>P[i]){
  i++;
  }
  
  int sum=0,min=P[0];
  
  for(i=0;i<N;i++){
	if(P[i]<=min){
      sum++;
      min=P[i];
  	}
  }
  
  cout << sum << endl;
  
	return 0; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int d;
vi c(26);
vvi s;

int calc (vi v) {
    vi last(26,-1);
    int ret = 0;
    rep(i,d) {
        ret += s[i][v[i]];
        last[v[i]] = i;
        rep(j,26) ret -= c[j]*(i-last[j]);
        cout << ret << "\n";
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> d;
    s.resize(d);
    rep(i,d) s[i].resize(26);
    cin >> c >> s;
    vi t(d);
    cin >> t;
    rep(i,d) t[i]--;
    calc(t);
}


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

#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define i64 long long int
#define MEM(a,x) memset(a,x,sizeof(x))
#define INF 1000000000
#define mod 998244353

using namespace std ;

typedef pair<int,int> pi ;

#define maxn 1000005

i64 a[maxn] ;

int main()
{
    i64 i , j , k , l , m , n ;

    scanf("%lld",&n) ;
    for(i=1; i<=n ; i++) scanf("%lld",&a[i]) ;
    sort(a+1,a+n+1) ;

    i64 sum = 0LL , ans = 1LL ;

    for(i=1 ; i<=n ; i++)
    {
        sum += a[i] ;
    }

    sum -= a[n] ;

    for(i=n-1 ; i>=1 ; i--)
    {
        if( sum*2 >= a[i+1] ) ans++ ;
        else break ;
        sum -= a[i] ;
    }

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

    return 0 ;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int n, m, c, temp, count = 0;
	scanf("%d %d %d", &n, &m, &c);
	int B[m+1], sol;
	for(int i = 1; i <= m; i++)
		scanf("%d", &B[i]);
	for(int i = 1; i <= n; i++){
		sol = 0;
		for(int j = 1; j <= m; j++){
			scanf("%d", &temp);
			sol += B[j]*temp;
		}
		if(sol + c > 0) count++;
	}
	cout << count << "\n";
	return 0;
}

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

const int X[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int Y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int W, H;
vector<vector<int>> Field;

void dfs(int y, int x){
    Field[y][x] = 0;
    for(int i = 0; i < 8; i++){
        int NeX = x + X[i];
        int NeY = y + Y[i];
        if(NeX < 0 || W <= NeX || NeY < 0 || H <= NeY)continue;
        if(Field[NeY][NeX] == 0)continue;
        dfs(NeY, NeX);
    }
}

int main(){
    while(cin >> W >> H){
        if(W == 0 && H == 0)break;
        Field.assign(H, vector<int>(W, 0));
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cin >> Field[i][j];
            }
        }
        
        int ans = 0;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(Field[i][j] == 0)continue;
                dfs(i, j);
                ans++;
            }
        }
        
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int main() {
    int n;
    vector<P3> es;
    cin >> n;
    REP(i,n-1){
        ll a, b, c;
        cin >> a >> b >> c;
        es.push_back({c,{a,b}});
    }
    sort(ALL(es));
    UnionFindTree g;
    g.init(n);
    ll ans = 0;
    REP(i,n){
        ll a, b, c;
        a = es[i].second.first;
        b = es[i].second.second;
        c = es[i].first;
        ans += c*ll(g.size(a))*ll(g.size(b));
        g.unite(a,b);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 9808