akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define NIL -1

using namespace std;

struct node{int parent, left, right, depth;};
struct node tree[100010];

void searchDepth(int start){
    int currentNumber = start;
    int answer = 0;
    while(tree[currentNumber].parent != NIL){
        currentNumber = tree[currentNumber].parent;
        answer++;
    }
    tree[start].depth = answer;
}

int main(){
    int n, k, currentNumber, tmp1, tmp2;
    cin >> n;
    
    for(int i = 0; i < n; i++) tree[i].parent = tree[i].left = tree[i].right = NIL;
    
    tmp2 = 0;
    for(int i = 0; i < n; i++){
        cin >> currentNumber >> k;
            if(k == 0){
                tree[currentNumber].left = NIL;
            }else{
                for(int j = 0; j < k; j++){
                    cin >> tmp2;
                    tree[tmp2].parent = currentNumber;
                    if(j == 0){
                        tree[currentNumber].left = tmp2;
                        tmp1 = tmp2;
                    }else{
                        tree[tmp1].right = tmp2;
                        tmp1 = tmp2;
                    }
                }
                tree[tmp2].right = NIL;
            }
    }
    int currentNode;
    for(int i = 0; i < n; i++){
        searchDepth(i);
        cout << "node " << i << ": parent = " << tree[i].parent << ", depth = " << tree[i].depth;
            if(tree[i].parent == NIL){
                cout << ", root, [";
            }else if(tree[i].left == NIL){
                cout << ", leaf, [";
            }else{
                cout << ", internal node, [";
            }
        currentNode = tree[i].left;
        int j = 0;
        while(1){
            if(currentNode == NIL) break;
            if(j != 0) cout << ", ";
            cout << currentNode;
            currentNode = tree[currentNode].right;
            j++;
        }
        cout << "]" << endl;
    }
    return 0;
}

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

int main(){
  int A , B , i = 0;
  cin >> A >> B;
  for (int k = 0; A <= B; k++){
    if (A % 10 == A / 10000 &&  A % 100 /10 == A % 10000 /1000){
      i += 1;
    }
    A++;
  }
  cout << i << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#define N 36

using namespace std;

int main(void) {
	int hash[10] = {0}, hashB[10] = {0}, hashS[10] = {0};
	char suit[N], suitB[N], suitS[N];
	int value[N], valueB[N], valueS[N];
	int n;
	bool stableB = true, stableS = true;

	cin >> n;
	for(int i = 0; i < n; ++i) {
		string tmp;
		cin >> tmp;
		suit[i] = tmp[0];
		value[i] = tmp[1] - '0';

		suitB[i] = suitS[i] = suit[i];
		valueB[i] = valueS[i] = value[i];

		int d_hash = 0;
		switch(suit[i]) {
			case 'S':
				d_hash = 1;
				break;
			case 'H':
				d_hash = 2;
				break;
			case 'C':
				d_hash = 3;
				break;
			case 'D':
				d_hash = 4;
				break;
		}
		hash[value[i]] = hash[value[i]] * 10 + d_hash;
	}

	// bubble
	for(int i = 0; i < n; ++i) {
		for(int j = n-1; j > i; --j) {
			if(valueB[j] < valueB[j-1]) {
				char ch = suitB[j];
				int tmp = valueB[j];
				suitB[j] = suitB[j-1];
				valueB[j] = valueB[j-1];
				suitB[j-1] = ch;
				valueB[j-1] = tmp;
			}
		}
	}

	for(int i = 0; i < n; ++i) {
		if(i != 0) {
			cout << ' ';
		}
		cout << suitB[i] << valueB[i];
	}
	cout << endl;

	for(int i = 0; i < n; ++i) {
		int d_hash = 0;
		switch(suitB[i]) {
			case 'S':
				d_hash = 1;
				break;
			case 'H':
				d_hash = 2;
				break;
			case 'C':
				d_hash = 3;
				break;
			case 'D':
				d_hash = 4;
				break;
		}
		hashB[valueB[i]] = hashB[valueB[i]] * 10 + d_hash;
	}

	for(int i = 1; i <= 9; ++i) {
		if(hash[i] != hashB[i]) {
			stableB = false;
			break;
		}
	}

	if(stableB) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}

	// selection
	for(int i = 0; i < n; ++i) {
		int mini = i;
		for(int j = i; j < n; ++j) {
			if(valueS[j] < valueS[mini]) {
				mini = j;
			}
		}
		if(mini != i) {
			char ch = suitS[i];
			int tmp = valueS[i];
			suitS[i] = suitS[mini];
			valueS[i] = valueS[mini];
			suitS[mini] = ch;
			valueS[mini] = tmp;
		}
	}

	for(int i = 0; i < n; ++i) {
		if(i != 0) {
			cout << ' ';
		}
		cout << suitS[i] << valueS[i];
	}
	cout << endl;

	for(int i = 0; i < n; ++i) {
		int d_hash = 0;
		switch(suitS[i]) {
			case 'S':
				d_hash = 1;
				break;
			case 'H':
				d_hash = 2;
				break;
			case 'C':
				d_hash = 3;
				break;
			case 'D':
				d_hash = 4;
				break;
		}
		hashS[valueS[i]] = hashS[valueS[i]] * 10 + d_hash;
	}

	for(int i = 1; i <= 9; ++i) {
		if(hash[i] != hashS[i]) {
			stableS = false;
			break;
		}
	}

	if(stableS) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[sc.nextInt()]++;
    }
    long ans = 0;
    int pp = 0;
    long MOD = (long)Math.pow(10, 9) + 7;
    if((n % 2) == 0) {
      int p = 0;
      for(int i = 1; i <= (n - 1); i += 2) {
        if(a[i] != 2) p++;
      }
      if(p == 0) pp = 1;
    } else {
      int p = 0;
      if(a[0] != 1) p++;
      for(int i = 2; i <= (n - 1); i += 2) {
        if(a[i] != 2) p++;
      }
      if(p == 0) pp = 1;
    }
    if(pp == 1) {
      ans = 1;
      for(int i = 0; i < (n / 2); i++) {
        ans = (ans * 2) % MOD;
      }
    }
    System.out.println(ans);
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  int max = H.at(0);
  int num = 1;
  for (int i = 1; i < N; i++) {
    if (max <= H.at(i)) {
      num++;
      max = H.at(i);
    }
  }

  cout << num << endl;
}


Measured memory_bytes: 256
import itertools

N,M=map(int,input().split())
C=[[] for j in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  C[a-1].append(b-1)
  C[b-1].append(a-1)

d=[int(x)+1 for x in range(N-1)]
ans=0
for exam in itertools.permutations(d):
  cnt=list(exam)
  cnt.insert(0,0)
  flg=True
  for i in range(N-1):
    if not(cnt[i+1] in C[cnt[i]]):
      flg=False
      break
  if flg:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,k;
    cin >> n >> k;
    intl h[n];
    cin(i,h);
    intl cnt = 0;
    rep(i,n){
        cnt += (k <= h[i]);
    }
    cout << cnt << endl;
    return 0;
}

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

N = int(input())
S = input()

if N % 2 != 0:
    print('No')
else:
    # print((N / 2) - 1)
    left = S[0: int((N / 2))]
    right = S[int((N / 2)): N]

    # print("left:{0},right:{1}".format(left, right))
    if left == right:
        print('Yes')
    else:
        print('No')


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

int main() {
  int donut_num, ing_amount;
  cin >> donut_num >> ing_amount;
  
  int total_donut = 0;
  int min_donut = 1 << 20;
  
  for(int i = 0; i < donut_num; i++){
    int donut;
    cin >> donut;
    total_donut += donut;
    if(donut < min_donut){
      min_donut = donut;
    }
  }
  
  int make_maxdonut = 0;
  cout << ((ing_amount - total_donut)/min_donut) + donut_num << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

while (true) {
int m = sc.nextInt();
int f = sc.nextInt();
int r = sc.nextInt();

if (m == -1 && f == -1 && r == -1) {
    break;
} else if (m == -1 || f == -1){
    System.out.println("F");
} else if(m+f>=80){
    System.out.println("A");
} else if(65<=m+f && m+f<80){
    System.out.println("B");
} else if(50<=m+f && m+f<65){
    System.out.println("C");
} else if(30<=m+f && m+f<50 && r<50){
    System.out.println("D");
} else if(30<=m+f && m+f<50 && r>=50){
    System.out.println("C");
} else {
    System.out.println("F");
}
    }
}
}


Measured memory_bytes: 26324
from collections import defaultdict
n = int(input())
s = input()
d = defaultdict(int)
for c in s:
  d[c] += 1
ans = d['R'] * d['G'] * d['B']
for i in range(1, n):
  for j in range(n-2*i):
    if s[j] != s[j+i] and s[j+i] != s[j+2*i] and s[j+2*i] != s[j]:
      ans -= 1
print(ans)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = min(n % k, abs(n % k - k));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)



int main()
{
      int a,b;
      scf(a),scf(b);
      
      int ctr=0,d=b-a;
      
      rep(i,1,d)
      ctr+=i;

      prin(ctr-a);
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0);
const int M = 1e9+7;
using namespace std;
int n;
string str;
ll dp[3005][3005];

int main(){
    AC
    cin>>n;
    cin>>str;
    dp[1][1] = 1;
    for(int i=2; i<=n; i++){
        if(str[i-2]=='>'){
            for(int s=i; s>=1; s--)
                dp[i][s] = (dp[i][s+1]+dp[i-1][s])%M;
        }
        else{
            for(int s=1; s<=i; s++)
                dp[i][s] = (dp[i][s-1] + dp[i-1][s-1])%M;
        }
    }

    ll ans = 0;
    for(int i=1; i<=n; i++)
        ans = (ans+dp[n][i])%M;
    cout<<ans<<endl;
}

Measured memory_bytes: 49724
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 1e9 + 7;
const int inf = 1 << 30;
const int maxn = 1000000 + 5;

namespace Comb {
  const int maxc = 2000000 + 5;
  int f[maxc], inv[maxc], finv[maxc];
  void init() {
    inv[1] = 1;
    for (int i = 2; i < maxc; i++)
      inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;
    f[0] = finv[0] = 1;
    for (int i = 1; i < maxc; i++) {
      f[i] = f[i - 1] * 1ll * i % mod;
      finv[i] = finv[i - 1] * 1ll * inv[i] % mod;
    }
  }
  int C(int n, int m) {
    if (m < 0 || m > n) return 0;
    return f[n] * 1ll * finv[n - m] % mod * finv[m] % mod;
  }
}
using Comb::C;

int x, y;

int main() {
  Comb::init();
  cin >> x >> y;
  // (i+2j, 2i+j)
  int ans = 0;
  for (int i = 0; i <= x; i++) {
    if ((x - i) % 2) continue;
    int j = (x - i) / 2;
    if (2 * i + j != y) continue;
    ans = (ans + C(i + j, i));
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;

int N;
int64_t L;
vector<string> s;
constexpr int64_t M = 2000010;
using P = pair<int, int>;
vector<vector<int64_t>> pool;
int64_t ans = 0;

int64_t g(int64_t depth){
    int64_t n = 1;
    int64_t m = n;
    while(true){
        if(depth % n == 0) m = n;
        n *= 2;
        if(n > depth) break;
    }
    return m;
}

void dfs(int64_t a, int64_t d){
    if(pool[a][0] == -1 && pool[a][1] == -1) return;
    if(pool[a][0] != -1){
        if(pool[a][1] == -1){
            ans ^= g(L - d);
        }
        dfs(pool[a][0], d + 1);
    }
    if(pool[a][1] != -1){
        if(pool[a][0] == -1){
            ans ^= g(L - d);
        }
        dfs(pool[a][1], d + 1);
    }
}

int main(){
    cin >> N >> L;
    
    s.resize(N);
    pool.resize(M, vector<int64_t>(2));
    for(int i = 0; i < M; ++i){
        pool[i][0] = -1;
        pool[i][1] = -1;
    }

    int64_t m = 1;
    for(int i = 0; i < N; ++i){
        cin >> s[i];
        int64_t v = 0;
        for(auto c : s[i]){
            int a = int(c - '0');
            if(pool[v][a] == -1){
                pool[v][a] = m++;
            }
            v = pool[v][a];
        }
    }
    dfs(0, 0);
    cout << (ans != 0 ? "Alice" : "Bob") << endl;
}

Measured memory_bytes: 111360
#include <stdio.h>
#define N 100
  
int main() {
  int i,j;
  int a,b,c,d;
  int array[N][N];
     
    for(i = 0; i < N; i++){
        for(j = 0; j < N; j++){
      array[i][j] = 0;
        }
    }
     
    scanf("%d",&a);
 
    for(i = 0; i < a; i++){
         
      scanf("%d",&d);
      scanf("%d",&c);
       
      for(j = 0; j < c; j++){
    scanf("%d", &b);
    array[i][b-1] = 1;
      }
    }
     
    for(i = 0; i < a; i++){
      for(j = 0 ; j < a - 1 ; j++){
     
    printf("%d ", array[i][j]);
     
      }
       
        printf("%d\n", array[i][a-1]);
     
    }
     
    return 0;
     
}

Measured memory_bytes: 640
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long H, W, A, B;
    scan(H, W, A, B);
    foreach (_; 0 .. B)
        writeln(repeat('1').take(A).chain(repeat('0').take(W - A)).array);
    foreach (_; 0 .. H - B)
        writeln(repeat('0').take(A).chain(repeat('1').take(W - A)).array);
}


Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

int main()
{
	int k, a, b;
	cin >> k >> a >> b;
	for(int i=a; i<=b; i++){
		if(i%k == 0){
			cout << "OK";
			return 0;
		}
	}

	cout << "NG";

    return 0;
}


Measured memory_bytes: 3624
import std.stdio;
import std.string;

string[] s;
int h, w, ans;

void main(){
	while (readf("%d %d\n", &h, &w), h != 0 || w != 0) {
		s = [];
		ans = 0;
		for (int i = 0; i < h; i++) {
			s ~= chomp(readln());
		}
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				if (s[y][x] != ' ') {
					ans++;
					scan(s[y][x], x, y);
				}
			}
		}
		writeln(ans);
	}
}

void scan(char fruit, int x, int y){
	s[y] = s[y][0..x] ~ ' ' ~ s[y][x+1..$];
	if(x+1 < w && s[y][x+1] == fruit) scan(fruit, x+1, y);
	if(x-1 >= 0 && s[y][x-1] == fruit) scan(fruit, x-1, y);
	if(y+1 < h && s[y+1][x] == fruit) scan(fruit, x, y+1);
	if(y-1 >= 0 && s[y-1][x] == fruit) scan(fruit, x, y-1);
}

Measured memory_bytes: 5784
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++) 

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<tuple<string,int,int>> vec;
  for(int i=1;i<=n;i++){
    string s;
    int a;
    cin>>s>>a;
    a=-a;
    vec.push_back(tie(s,a,i));
  }
  sort(vec.begin(),vec.end());
   rep(i,n){
  cout<<get<2>(vec[i])<<endl;
   }
}
                                   

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
  int n;
  cin >> n;
  rep(i,10)rep(j,10){
    if(i*j==n){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	int a, b;
	cin >> a >> b;

	cout << a * a - b << endl;

	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n, m;
	while (cin >> n >> m, m) {
		vector<int>p(n);
		for (int i = 0; i < n; i++)cin >> p[i];
		sort(p.rbegin(), p.rend());
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if ((i + 1) % m == 0)continue;
			sum += p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	
	cout << s.substr(0, 3) << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 998244353

ll dp[4][2][200010];

void chmax(ll& a, ll b) {
	a = max(a, b);
}

int main() {
	for (int i = 0;i < 200010;i++) {
		for (int j = 0;j < 4;j++) {
			dp[j][0][i] = dp[j][1][i] = LLONG_MIN / 3;
		}
	}
	int N;
	cin >> N;
	ll A;
	for (int i = 0;i < N;i++) {
		cin >> A;
		if (i == 0) {
			//选 
			dp[3][1][0] = A;
			//不选 
			dp[1][0][0] = 0;
			continue;
		}
		//选 
		chmax(dp[1][1][i], dp[0][0][i - 1] + A);
		chmax(dp[2][1][i], dp[1][0][i - 1] + A);
		chmax(dp[3][1][i], dp[2][0][i - 1] + A);
		//不选 
		chmax(dp[0][0][i], dp[1][0][i - 1]);
		chmax(dp[0][0][i], dp[1][1][i - 1]);
		chmax(dp[1][0][i], dp[2][0][i - 1]);
		chmax(dp[1][0][i], dp[2][1][i - 1]);
		chmax(dp[2][0][i], dp[3][0][i - 1]);
		chmax(dp[2][0][i], dp[3][1][i - 1]);
	}
	
	if (N & 1) {
		cout << max(dp[1][0][N - 1], dp[1][1][N - 1]) << '\n';
	}
	else {
		cout << max(dp[2][0][N - 1], dp[2][1][N - 1]) << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 16148
A,B,C,D,E,F = map(int,input().split())

W = set()
for a in range(0,F+1,100*A) :
    for b in range(0, F-a+1,100*B) :
        water = a+b
        W.add(water)
W.remove(0)

S = set()
for c in range(0,F+1,C) :
    for d in range(0,F-c+1,D) :
        sugar = c+d
        S.add(sugar)

ans_water = -1
ans_sugar = -1
ans_sugar_water = -1
ans_density = -1

W = sorted(list(W))
S = sorted(list(S))

for i in W :
    for j in S :
        if (i+j) > F :
            break
        if i*E < j*100 :
            break
        density = (j/(i+j))
        if density > ans_density :
            ans_density = density
            ans_water = i
            ans_sugar = j
            ans_sugar_water = ans_water + ans_sugar
print(ans_sugar_water, ans_sugar)


Measured memory_bytes: 3188
function Main(input) {
    input = input.split("\n");
    const nd = input[0].split(" ");
    const n = parseInt(nd[0], 10);
    const d = parseInt(nd[1], 10);

    let count = 0;
    for(let i = 1; i <= n; i++) {
        const xy = input[i].split(" ");
        const x = parseInt(xy[0], 10);
        const y = parseInt(xy[1], 10);

        const r = Math.sqrt(x ** 2 + y ** 2);
        if(r <= d) {
            count++;
        }
    }

    console.log(count);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 62652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i,j,k;
ll kaijou[2000+1];
ll gyakugen[2000+1];
long long ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%mod,y/2);
    else return x*ruijou(x,y-1)%mod;
}

ll combination(ll n,ll c){
    if(n<c)return 0;
    return ((kaijou[n]*gyakugen[c])%mod)*gyakugen[n-c]%mod;
}
ll mo(ll x){
    ll ans=x%mod;
    if(x>=0)return ans;
    return ans+mod;
}


int main(){
    string S;
    cin>>S;
    ll N=S.length();
    ll cnt=0;
    ll dnt=0;
    rep(i,N)if(S[i]=='0')cnt++;
    rep(i,N)if(S[i]=='1')dnt++;

    cout<<2*min(cnt,dnt)<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    int a, b;
    cin >> a >> b;
    cout << a - b + 1 << endl;
    
    return 0;
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


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

using namespace std;

namespace {

    ostream& operator<<(ostream& os, const vector<int>& xs) {
        os << "[" << xs[0];
        for (int i = 1; i < xs.size(); i++) os << " " << xs[i];
        return os << "]";
    }

    int N, C;
    vector< vector<int> > F;
    bool input() {
        cin >> N >> C;
        if (N == 0 && C == 0) return false;
        F.clear(); F.resize(N);
        for (int i = 0; i < N; i++) {
            F[i].resize(i + 1);
            for (int j = 0; j <= i; j++) {
                cin >> F[i][j];
            }
        }
        return true;
    }

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

    vector< vector<int> > X;

    void dfs(int y, int x) {
        if (X[y][x]) return;
        int c = F[y][x];
        X[y][x] = 1;
        for (int i = 0; i < 6; i++) {
            int ny = y + dy[i],
                nx = x + dx[i];
            if (ny < 0 || ny >= N) continue;
            if (nx < 0 || nx >= ny + 1) continue;
            if (c != F[ny][nx]) continue;
            dfs(ny, nx);
        }
    }

    int calc() {
        X.clear(); X.resize(N);
        for (int i = 0; i < N; i++) {
            X[i].resize(i + 1);
            for (int j = 0; j <= i; j++) {
                X[i][j] = 0;
            }
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                if (F[i][j] != 0) continue;
                for (int k = 0; k < 6; k++) {
                    int ny = i + dy[k],
                        nx = j + dx[k];
                    if (ny < 0 || ny >= N) continue;
                    if (nx < 0 || nx >= ny + 1) continue;
                    if (F[ny][nx] == 0) continue;
                    dfs(ny, nx);
                }
            }
        }
        int ret = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                if (X[i][j]) continue;
                if (F[i][j] == 0) continue;
                if (F[i][j] == C) {
                    ret--;
                } else {
                    ret++;
                }
            }
        }
        if (false) {
            for (int i = 0; i < N; i++) { cout << F[i] << endl; }
            for (int i = 0; i < N; i++) { cout << X[i] << endl; }
            cout << endl;
        }
        return ret;
    }

    const int INF = 1<<28;

    void solve() {
        int ans = -INF;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                if (F[i][j] == 0) {
                    F[i][j] = C;
                    ans = max(ans, calc());
                    F[i][j] = 0;
                }
            }
        }
        cout << ans << endl;
    }
}

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

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

ll gcd(ll a, ll b){
	return (b==0)? a : gcd(b , a%b);
}
ll lcm(ll x , ll y){
	return (x*y)/gcd(max(x,y) , min(x,y));
}
void doit(){
	ll x;
	cin >> x;
	cout << lcm(360 , x) / x << nl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	// cin >> t;
	for(ll i = 1; i <= t; i++){
		doit();
	}
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
int n, m;
vector<int> g[100001];
int dp[100001];
bool seen[100001];

int dfs(int now)
{
    if (seen[now])
    {
        return dp[now];
    }
    seen[now] = true;
    int res = 0;
    for (auto next : g[now])
    {
        chmax(res, dfs(next) + 1);
    }
    dp[now] = res;
    return dp[now];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x - 1].push_back(y - 1);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        chmax(ans, dfs(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 8320
W, a, b = map(int, input().split())
if a<b:
    if b<=a+W:
        print(0)
    else:
        print(b-a-W)
elif a == b:
    print(0)
else:
    if a<=b+W:
        print(0)
    else:
        print(a-b-W)

Measured memory_bytes: 38384
#include <cstdio>
#include <vector>
#include <array>
using namespace std;

int main(){
    int N;
    scanf("%d",&N);
    vector<array<int,3>> ar(N),cnt(100);
    for(auto& x : ar){
        scanf("%d%d%d",&x[0],&x[1],&x[2]);
        for(int i=0;i<3;i++){
            x[i]--;
            cnt[x[i]][i]++;
        }
    }
    for(auto x : ar){
        int pt=0;
        for(int i=0;i<3;i++) if(cnt[x[i]][i]<=1) pt+=x[i]+1;
        printf("%d\n",pt);
    }
}

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

int main(){
    int n, k, t;
    cin >> n;
    ll x = 0, e = pow(2, n);
    cin >> k;
    rep(i, k){
        cin >> t;
        x += (1<<t);
    }
    repc(i, 0LL, e){
        if((i & x) == i){
            bitset<30> xx(i);
            cout << i << ":";
            rep(j, n){
                if (xx.test(j)){
                    cout << " " << j;
                }
            }
        cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3268
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
using ll = long long;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
static const int INFTY = (1<<21);


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

    vector<ll> a;
    rep(i,9) a.push_back(i+1);

    while(1){
        //a.size():次の桁ルンルン数の数が、Kより小さければ、K個目の数でOK
        if(K <= a.size()){
                cout << a[K-1] << endl;
                return 0;
        }
        vector<ll> old;
        //今の桁の数をKから引く
        K -= a.size();
        swap(a,old);

        for(ll num: old){
            for (int i = -1; i <2; i++){
                int d = num % 10 + i;
                if(d != -1 && d != 10){
                    a.push_back(10*num+d);
                }
            }

        }
    }
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;
const ldbl pi = 3.141592653589793238462643383279l;

int main() {
	ldbl a, b, x;
	cin >> a >> b >> x;
	ldbl V = a * a * b;

	if (x == V / 2.0) {
		cout << "45.000000000000000000" << endl;
	} else if (x < V / 2.0) {
		ldbl c = (2.0 * x) / (a * b);
		cout << fixed << setprecision(30) << atan2(b, c) * 180.0 / pi << endl;
	} else {
		ldbl c = 2.0 * b - (2.0 * x) / (a * a);
		cout << fixed << setprecision(30) << atan2(c, a) * 180.0 / pi << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 300010;
const int INF = 2147483600;

int N,M; int a[MAXN+1];

inline bool check(int x){
	for(int i=1;i<=N-x;i++){
		if(a[i+x]+a[N-i+1]<M) return 0;
	} return 1;
} 
inline int calc(int x){
	int ans=0;
	for(int i=1;i<=x;i++){
		if(a[i]+a[x-i+1]>=M) return INF;
		ans=max(ans,a[i]+a[x-i+1]);
	}
	for(int i=1;i<=N-x;i++){
		if(a[x+i]+a[N-i+1]<M) return INF;
		ans=max(ans,a[x+i]+a[N-i+1]-M);
	} return ans;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(); M=read(); N<<=1;
	for(int i=1;i<=N;i++) a[i]=read();
	sort(a+1,a+N+1);
	int l=0,r=N/2,pos=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid*2)) pos=mid*2,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",min(calc(pos),min(calc(0),calc(N))));
	return 0;
}




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

using namespace std;

template <typename T, typename = typename std::enable_if<
                          std::is_integral<T>::value, T>::type>
vector<pair<T, int>> prime_factorize(T n) {
  vector<pair<T, int>> cnts{};
  if (n == 1) {
    return cnts;
  }

  T a = 2;
  while (n >= a * a) {
    int cnt = 0;
    while (n % a == 0) {
      n /= a;
      cnt++;
    }

    if (cnt > 0) {
      cnts.push_back({a, cnt});
    }

    a++;
  }

  if (n != 1) {
    cnts.push_back({n, 1});
  }

  return cnts;
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << '\n';
    return 0;
  }

  map<int, int> cnts;
  for (int i = 2; i <= n; ++i) {
    auto factors = prime_factorize(i);
    for (auto &f : factors) {
      cnts[f.first] += f.second;
    }
  }

  long long ans = 1, md = 1e9 + 7;
  for (auto &p : cnts) {
    ans = (((p.second % md) + 1) % md) * ans;
    ans = ans % md;
  }

  cout << ans << '\n';
  return 0;
}

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

vector<pii> g[55];
long long bits[1<<20];

bool dfs(int u, int p, int f, int j){
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i].first, idx = g[u][i].second;
        if(v == p) continue;
        if(v == f){
            bits[1<<j] |= (1ll<<idx);
            return 1;
        }
        if(dfs(v, u, f, j)){
            bits[1<<j] |= (1ll<<idx);
            return 1;
        }
    }
    return 0;
}
int main(){
    int n, m;
    scanf("%d", &n);
    for(int i=0;i<n-1;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].push_back(pii(b, i));
        g[b].push_back(pii(a, i));
    }
    scanf("%d", &m);
    for(int i=0;i<m;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        dfs(a, 0, b, i);
    }
    for(int i=1;i<(1<<m);i++){
        if(__builtin_popcount(i) == 1) continue;
        for(int j=0;j<m;j++){
            if((i>>j)&1) bits[i] |= bits[1<<j];
        }
    }

    LL ans = (1ll<<(n-1));
    for(int i=1;i<(1<<m);i++){
        int cnt = n-1-__builtin_popcountll(bits[i]);
        if(__builtin_popcount(i)%2 == 1){
            ans = (ans - (1ll<<cnt));
        }
        else{
            ans = (ans + (1ll<<cnt));
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 8448
fun main() {
    abc160e()
}

private const val MAX_VALUE = 1_000_000_001L

fun abc160e() {
    val (x, y, a, b, c) = readLine()!!.split(" ").map { it.toLong() }
    val p = readLine()!!.split(" ").map { it.toLong() }.sortedDescending().toMutableList()
    val q = readLine()!!.split(" ").map { it.toLong() }.sortedDescending().toMutableList()
    val r = readLine()!!.split(" ").map { it.toLong() }.sortedDescending()
    var i = x.toInt()
    var j = y.toInt()
    var k = 0
    var taste = p.subList(0, i).sum() + q.subList(0, j).sum()
    p.add(0, MAX_VALUE)
    q.add(0, MAX_VALUE)
    while(k < c && (p[i] < r[k] || q[j] < r[k])) {
        val minus = if (p[i] < q[j]) {
            i--
            p[i + 1]
        } else {
            j--
            q[j + 1]
        }
        taste += r[k] - minus
        k++
    }
    println(taste)
}

Measured memory_bytes: 69180
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <string>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);
  std::sort(a.begin(), a.end());
  a.erase(std::unique(a.begin(), a.end()), a.end());

  puts((a.size() == n)? "YES": "NO");
}


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

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    vector<vector<int>> mp(n);

    int l, r;

    for(int i = 0; i < m; ++i) {
        cin >> l >> r;
        mp.at(l - 1).push_back(r);
        mp.at(r - 1).push_back(l);
    }

    vector<int> p(n);
    vector<int> tmp = {1}, tmp2;
    int room = n - 1, route = m;
    p.at(0) = -1;

    while(tmp.size() != 0) {
        tmp2 = tmp;
        tmp = {};
        for(int i: tmp2) {
            for(int j: mp.at(i - 1)) {
                if(p.at(j - 1) == 0) {
                    tmp.push_back(j);
                    p.at(j - 1) = i;
                }
            }
        }
        for(int i: tmp) --room;
    }

    if(room != 0) printf("No\n");
    else {
        printf("Yes\n");
        for(int i = 1; i < n; ++i) printf("%d\n", p.at(i));
    }
    return 0;
}

Measured memory_bytes: 10664
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, X;
const ll MAX_N = 100;
ll L[MAX_N];

int main(){
  cin >> N >> X;
  REP(i, N) cin >> L[i];

  ll crt = 0;
  ll ans = 1;
  REP(i, N) {
    crt += L[i];
    if(crt > X) break;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,x=list(map(int ,input().split()))
sample_gram=0
l1=[]
for i in range(0,n):
    m=int(input())
    sample_gram+=m
    l1.append(m)

if(sample_gram > x):
    noofdonut=(sample_gram//x)
    print(int(noofdonut))
elif(sample_gram==x):
    print(int(sample_gram/m))
elif(sample_gram < x):
    initial_donut=n
    reamaning_gram=x-sample_gram
    l=[]
    for j in range(0,n):
        a=reamaning_gram/l1[j]
        l.append(int(a))

    print(initial_donut+int(max(l)))

Measured memory_bytes: 9208
#include <vector>

using namespace std; //ごめんなさい

struct UF{
  vector<int>par;
  vector<int>rank;
  UF(int sz){
    rank.resize(sz,0);
    par.resize(sz);
    for(int i=0;i<sz;i++)par[i]=i;
  }
  void u(int x,int y){
    x=root(x);
    y=root(y);
    if(rank[x]==rank[y])rank[x]++;
    if(rank[x]>rank[y])par[y]=x;
    else par[x]=y;
  }
  int root(int x){
    if(par[x]==x)return x;
    return root(x=par[x]);
  }
  bool isu(int x,int y){
    return root(x)==root(y);
  }
};

#include <bits/stdc++.h>

int main(){
  int n,q;
  cin>>n>>q;
  UF uf(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c==0){
      uf.u(x,y);
    }
    if(c==1){
      cout<<uf.isu(x,y)<<endl;
    }
  }
}



Measured memory_bytes: 3196
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N, x[361] = {};
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int M, D, V, S;
    cin >> M >> D >> V >> S;
    int a = (M - 1) * 30 + D + V - 1;
    int b = (M - 1) * 30 + D;
    for (int k = 0; k < V; k++) {
      // if ((b + k) > 360) { b = (b + k) % 360; }
      // x[(M - 1) * 30 + D + k] = max(S, x[(M - 1) * 30 + D + k]);
      x[(b + k) % 360] = max(S, x[(b + k) % 360]);
    }
    // b = (M - 1) * 30 + D;
    for (int j = 1; j <= 360; j++) {
      // if ((a + j) > 360)
      //   a = a - 360;
      // else if ((b - j) < 1)
      //   b = b + 360;
      x[(a + j) % 360] = max(S - j, x[(a + j) % 360]);
      x[(b - j + 360) % 360] = max(S - j, x[(b - j + 360) % 360]);
    }
  }
  /*for (int i = 1; i <= 360; i++) {
      cout << i<<"="<<x[i] << endl;
  }*/
  sort(x, x + 361);
  cout << x[1] << endl;
  return 0;
}

Measured memory_bytes: 3152
# include <stdio.h>
# include <stdlib.h>

int ord(const void * a, const void * b){
    int x = *((int *) a), y = *((int *) b);

    if (x > y)
        return -1;
    if (x < y)
        return 1;
    return 0;
}

int main(){
    int n, k, vec[1022];
    scanf("%d %d", &n, &k);
    int sum = 0;

    for (int i = 0; i < n; ++i){
        scanf("%d", &vec[i]);
    }
    qsort(vec, n, sizeof(vec[0]), ord);

    for (int j = 0; j < k; ++j){
        sum += vec[j];
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 128
def makePrimeChecker(n):
    isPrime = [True] * (n + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not isPrime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            isPrime[j] = False
    return isPrime

is_prime = makePrimeChecker(1000001)

X = Y = 500

dx = [1,0,-1,0]
dy = [0,-1,0,1]

yx2n = [[-1] * 1010 for _ in range(1010)]
n2yx = [(-1, -1)] * 1010100
n=0
nn = 1
bn = 0
x=y=0
dir = 0
for i in range(1, 1000001):
    yx2n[Y+y][X+x] = i
    n2yx[i] = (Y+y, X+x)
    #table[Y+y][X+x] = i#is_prime[i]

    #print(f"x={x}, y={y}, n={n}, nn={nn}")

    x += dx[dir]
    y += dy[dir]

    n += 1
    if n==nn:
        dir += 1
        dir %= 4
        if bn==1:
            nn += 1
        n=0
        bn ^= 1


while True:
    M, N = map(int, input().split())
    if M==N==0:
        break
    table = [[0] * 1010 for _ in range(1010)]
    for i, ((y, x), p) in enumerate(zip(n2yx[1:M+1], is_prime[1:M+1]), 1):
        table[y][x] = p

    cnt = [[0] * 1010 for _ in range(1010)]
    from_ = [[-1] * 1010 for _ in range(1010)]
    for i, y in enumerate(range(n2yx[N][0], 1005)):
        for x in range(max(0, n2yx[N][1]-i), min(1005, n2yx[N][1]+i+1)):
            c = cnt[y][x]
            if table[y][x]:
                c += 1
                n = yx2n[y][x]
            else:
                n = from_[y][x]

            if cnt[y + 1][x] < c:
                cnt[y + 1][x] = c
                from_[y + 1][x] = n
            elif cnt[y + 1][x] == c:
                if from_[y + 1][x] < n:
                    from_[y + 1][x] = n

            if cnt[y + 1][x-1] < c:
                cnt[y + 1][x-1] = c
                from_[y + 1][x-1] = n
            elif cnt[y + 1][x-1] == c:
                if from_[y + 1][x-1] < n:
                    from_[y + 1][x-1] = n

            if cnt[y + 1][x+1] < c:
                cnt[y + 1][x+1] = c
                from_[y + 1][x+1] = n
            elif cnt[y + 1][x+1] == c:
                if from_[y + 1][x+1] < n:
                    from_[y + 1][x+1] = n

            # cnt[y + 1][x] = max(cnt[y + 1][x], c)
            # cnt[y + 1][x-1] = max(cnt[y + 1][x-1], c)
            # cnt[y + 1][x+1] = max(cnt[y + 1][x+1], c)

    ma, ama = 0, 0
    for c, f in zip(cnt[1005], from_[1005]):
        if c > ma:
            ama = f
            ma = c
        elif c == ma:
            if f > ama:
                ama = f
    if ma==0:
        ama = 0
    #a = max(cnt[1005])

    print(ma, ama)



Measured memory_bytes: 211920
n = int(input())
a_list = [int(i) for i in input().split()]
minus_count_even_flug = True
zero_exist_flug = False
  
for a in a_list:
    if a < 0:
        minus_count_even_flug = not minus_count_even_flug
    if a == 0:
        zero_exist_flug = True
     
a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug or zero_exist_flug:
    print(sum_a_abs_list)
else:
    print(sum_a_abs_list - 2 * min(a_abs_list))

Measured memory_bytes: 14412
#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(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



int main(){
   int a, b, c, x, y;
   cin >> a >> b >> c >> x >> y;

   
   int  sum=0;
   if(a+b<2*c){ //c*2>a+bならABピザを買うメリットが全くない
       sum=a*x+b*y;
   }
   else{
       sum += 2*c*min(x,y); //xとyのうち少ない方を全部ABピザで賄う
       if(x>y){
           sum += (x-y)*min(a,c*2);
       }
       else{
           sum += (y-x)*min(b,c*2);
       }
   }
   cout << sum << endl;

}

Measured memory_bytes: 3612
#include<iostream>
int main(){
    int n;
    std::cin>>n;
    int A[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j]=0;
        }
    }
    int tmp,s,e;
    for(int i=0;i<n;i++){
        std::cin>>s;
        std::cin>>tmp;
        for(int j=0;j<tmp;j++){
            std::cin>>e;
            A[s-1][e-1]=1;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j==0){
                std::cout<<A[i][j];
            }else std::cout<<" "<<A[i][j];
        }
        std::cout<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>
 
using namespace std;
 
#define BUF_SIZE 1024
#define ARRAY_SIZE 100
 
 
void selectionSort(int array[],int n,int& change_count)
{
    int min;
    for(int i = 0; i < n-1; i++){
        min = i;    //?????????
        for(int j = i+1; j < n; j++){
            if(array[j] < array[min]){
                min = j;
            }
        }
        if(i != min){
            swap(array[i],array[min]);
            change_count++;
        }
    }
 
}
 
int main(){
 
    char buf[BUF_SIZE];
    int n = atoi(fgets(buf,BUF_SIZE,stdin));
    int array[ARRAY_SIZE];
    int change_count = 0;
 
    for(int i = 0; i < n; i++){
        cin >> array[i];
    }
 
    selectionSort(array,n,change_count);
 
    for(int i = 0; i < n; i++){
        if(i != n-1){
            printf("%d ",array[i]);
        }else{
            printf("%d\n",array[i]);
        }
    }
    printf("%d\n",change_count);
}


Measured memory_bytes: 3224
/* ex3_2
   moka223711 */

#include <stdio.h>

int main(void){
  int N, K, i = 1;
  scanf("%d %d", &N, &K);
  
  while(N >= K){
    N /= K;
    i++;
  }
  
  printf("%d", i);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL p=1e9+7;
const LL N=1e5+10;
inline LL pw(LL x,LL y){
	LL ans=1; while(y){
		if(y&1)(ans*=x)%=p;
		x=x*x%p; y>>=1;
	}
	return ans;
}
LL n,a[N];
LL s[N];
int main(){
	scanf("%lld",&n);
	for(LL i=1; i<=n; ++i)scanf("%lld",&a[i]);
	for(LL i=1; i<=n; ++i)s[i]=(pw(i,p-2)+s[i-1])%p;
	LL ans=0;
	for(LL i=1; i<=n; ++i)
		(ans+=(s[i]+s[n-i+1]-1)*a[i]%p)%=p;
	for(LL i=1; i<=n; ++i)(ans*=i)%=p;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <array>
#include <bitset>

constexpr int K = 10;
constexpr int L = 1 << K;
constexpr int N = 100;
constexpr int inf = 2e9 + 334;
std::array<std::bitset<K>, N> D;
std::array<std::array<int, K+1>, N> P;
std::array<int, N> C;

int main(void){
    int n; scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < K; ++j){
            getchar(); D[i][j] = getchar() - '0';
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= K; ++j) scanf("%d", &P[i][j]);
    }
    int res = -inf;
    for(int x = 1; x < L; ++x){
        for(int i = 0; i < n; ++i) C[i] = 0;
        for(int j = 0; j < K; ++j) if((x >> j) & 1){
            for(int i = 0; i < n; ++i) if(D[i][j]) C[i]++;
        }
        int d = 0;
        for(int i = 0; i < n; ++i) d += P[i][C[i]];
        if(res < d) res = d;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 128