akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val INF = 1001001001
    val (N, A, B, C) = listOfInt()
    val L = (0 until N).map { nextInt() }.sortedDescending()
    fun min(a: Int, b: Int, c: Int, d: Int = INF) = Math.min(a, Math.min(b, Math.min(c, d)))
    fun dfs(cur: Int, a: Int, b: Int, c: Int): Int {
        if (cur == N) return if (min(a, b, c) > 0) Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C) - 30 else INF
        val r0 = dfs(cur + 1, a, b, c)
        val r1 = dfs(cur + 1, a + L[cur], b, c) + 10
        val r2 = dfs(cur + 1, a, b + L[cur], c) + 10
        val r3 = dfs(cur + 1, a, b, c + L[cur]) + 10
        return min(r0, r1, r2, r3)
    }
    println(dfs(0, 0, 0, 0))
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 38948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()
 
const int MOD = 1000000007;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> p(N);
  
  rep(i,N) cin>> p[i];
    
  sort(all(p));
  
  ll ans=0;
  
  rep(i,K) ans+=p[i];
  
  cout << ans << endl;
  
 
return 0;
 
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <math.h>
#include<cmath>
 #include <sstream> // std::stringstream
 #include <istream> // std::getline
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }else if(a < 6){
        cout << '0' << endl;
    }else{
      cout << b/2 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpp make_pair
using namespace std;

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

	ll i;

	ll cnt=-1;

	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			cnt=i;
		}
	}
	if(cnt==-1)
		cnt=n;
	ll temp=n/cnt;

	cout<<temp+cnt-2;
}

Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    ll a;
    string b;
    cin>>a>>b;
    int c = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
    //ll c = b*100;
    //cout<<c<<endl;
    ll res = (a*c)/100;
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,a,b,c,d,x=0,i,j,l,m;
	char s[10000],k[10000];
	scanf("%d %s", &n, s);
	a=strlen(s);
	for(i=0; i<n; i++)
	{
		scanf("%s", k);
		b=strlen(k);
		d=0;
		for(j=0; j<b-2; j++)
		{
			if(s[0]==k[j])
			{
				for(l=j+1; l<b-1; l++)
				{
					if(s[1]==k[l])
					{
						c=2;
						for(m=l+l-j; m<b; m+=l-j)
						{
							if(s[c]!=k[m])
							break;
							else
							{
								c++;
								if(c==a)
								{
									d=1;
									break;
								}
							}
						}
					}
				}
			}
		}
		x+=d;
	}
	printf("%d\n", x);
	
	return 0;
}


Measured memory_bytes: 2040
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

typedef struct union_find {
  int32_t *parent;
  int32_t size;
} union_find;

void init_union_find (union_find * const u) {
  for (int32_t i = 0; i < u->size; ++i){
    u->parent[i] = -1;
  }
}

union_find* new_union_find (const int32_t size) {
  union_find * const u = (union_find *) calloc (1, sizeof (union_find));
  u->parent = (int32_t *) calloc (size, sizeof (int32_t));
  u->size = size;
  init_union_find (u);
  return u;
}

int32_t root (union_find * const u, int32_t x) {
  if (u->parent[x] < 0) return x;
  return u->parent[x] = root (u, u->parent[x]);
}

void unite (union_find * const u, int32_t x, int32_t y) {
  x = root (u, x);
  y = root (u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    const int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}

typedef struct node {
  i32 a, b, k;
} node;

int cmp_node (const void *a, const void *b) {
  const node *p = a;
  const node *q = b;
  i32 d = p->a - q->a;
  if (d != 0) return d < 0 ? -1 : 1;
  d = p->b - q->b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, k, l;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &k, &l);
  union_find *u = new_union_find (n + 1);
  while (k--) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    unite (u, a, b);
  }
  union_find *v = new_union_find (n + 1);
  while (l--) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    unite (v, a, b);
  }
  node *p = ALLOC (n, node);
  for (i32 i = 1; i <= n; ++i) {
    p[i - 1] = (node) {root (u, i), root (v, i), i - 1};
  }
  SORT (p, n, cmp_node);
  i32 *ans = ALLOC (n, i32);
  for (i32 i = 0; i < n;) {
    i32 j = i + 1;
    while (j < n && cmp_node (p + i, p + j) == 0) ++j;
    i32 d = j - i;
    for (; i < j; ++i) {
      ans[p[i].k] = d;
    }
  }
  for (i32 i = 0; i < n; ++i) {
    printf ("%" PRIi32, ans[i]);
    putchar (i == n - 1 ? '\n' : ' ');
  }
}

int main (void) {
  run();
  return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back


int main() {
  int x; cin>>x;
  if(x) cout<<0<<endl;
  else cout<<1<<endl;
}


Measured memory_bytes: 3632
def count(field, y, x)
  result = 1
  color = field[y][x]
  field[y][x] = "."
  dy = [-1, 1, 0, 0]
  dx = [0, 0, -1, 1]
  for i in 0...4 do
    result += count(field, y + dy[i], x + dx[i]) if field[y + dy[i]][x + dx[i]] == color
  end
  field[y][x] = color
  result
end

def vanish(field, y, x)
  color = field[y][x]
  field[y][x] = "."
  dy = [-1, 1, 0, 0]
  dx = [0, 0, -1, 1]
  for i in 0...4 do
    vanish(field, y + dy[i], x + dx[i]) if field[y + dy[i]][x + dx[i]] == color
    field[y + dy[i]][x + dx[i]] = "." if field[y + dy[i]][x + dx[i]] == "O"
  end
end

def delete!(field)
  deleted = false
  for i in 1..H do
    for j in 1..W do
      next if field[i][j] == "." || field[i][j] == "O"
      next if count(field, i, j) < 4
      vanish(field, i, j)
      deleted = true
    end
  end
  deleted
end

def fall!(field)
  for j in 1..W do
    H.downto(1) do |i|
      next if field[i][j] != "."
      i.downto(1) do |k|
        next if field[k][j] == "."
        field[i][j], field[k][j] = field[k][j], field[i][j]
        break
      end
    end
  end
end

H = 12
W = 6
gets.to_i.times do
  field = Array.new(H + 2) {Array.new(W + 2, ".")}
  for i in 1..H do
    field[i][1, W] = gets.chomp.chars
  end

  chain = 0
  while delete!(field) do
    fall!(field)
    chain += 1
  end
  puts chain
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  string S,T;
  cin >> S >> T;

  int cnt = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) != T.at(i)){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3860
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long a, b;

int main(){
    scanf("%ld%ld", &a, &b);
    if(a < 10 && b < 10){
        printf("%ld\n", a*b);
    }else{
        printf("-1\n");
    }
}


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

int main()
{
    string a;
    while(cin>>a)
    {
        int ans;
        if(a=="SUN")
            ans=7;
        else if(a=="MON")
            ans=6;
        else if(a=="TUE")
            ans=5;
        else if(a=="WED")
            ans=4;
        else if(a=="THU")
            ans=3;
        else if(a=="FRI")
            ans=2;
        else if(a=="SAT")
            ans=1;
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  
  vector <int> donut(N);
  for (int i = 0; i < N; i++) cin >> donut.at(i);
  sort (donut.begin(),donut.end());
  
  int total = 0;
  int count = 0;
  for (int x: donut) total += x;
  cout << N + (X-total)/donut.at(0) << endl;
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 13:15:15 2020

@author: liang
"""

"""
1.全探索 i,j,kを固定してそれぞれの番号を調べる => O(N^3)
2.全探索3桁の暗証番号000~999が文字列Sにあるか調べる =>O(N)
"""
"""
解1.コード　=> TLE
#使用済みリストを用意することで枝刈り
N = int(input())
S = list(map(int,input().split()))
num_used = [list() for i in range(10)]
numbers = list()
for i in range(N):
    for j in range(i+1, N):
        if S[j] in num_used[S[i]]:
            continue
        else:
            num_used[S[i]].append(S[j])
            for k in range(j+1,N):
                number = str(S[i]) + str(S[j]) + str(S[k])
                if number not in numbers:
                    numbers.append(number)
print(len(numbers))
"""
#解2コード => O(N)
N = int(input())
S = input()
ans = 0
for i in range(1000):
#0で埋めるプログラム
#    a = i//100
#    b = i%100//10 ###400//10 = 40
#    c = i%10
#    num = str(a) + str(b) + str(c) 
    t = str(i).zfill(3) #0で埋めるメソッド
#フラグを立てて探す => O(N)    
#    flag = 0
#    for j in range(N) :
#        if S[j] == t[flag]:
#            flag += 1
#        if flag == 3:
#            ans += 1
    a = S.find(t[0])
    b = S.find(t[1],a+1)
    c = S.find(t[2],b+1)
    if a != -1 and b != -1 and c != -1:
        ans += 1
print(ans)

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

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

bool check(vint A){
    int latte=0;
    rep(i,A.size())if(A[i]&1)latte++;
    if(latte!=1)return false;

    int t=-1;
    rep(i,A.size())if(A[i]%2)t=i;
    if(A[t]==1)return false;
    A[t]--;
    int g=A[0];
    for(int i=1;i<A.size();i++)g=gcd(g,A[i]);

    int cnt=0;
    rep(i,A.size()){
        A[i]/=g;
        if(A[i]%2)cnt++;
    }

    if(cnt!=1)return cnt%2;
    return !check(A);
}

bool check2(vint A){
    rep(i,2){
        if(A[i]==1)return false;
    }
    rep(i,2){
        vint AA=A;
        A[i]--;
        int g=gcd(AA[0],AA[1]);
        AA[0]/=g;AA[1]/=g;
        if(!check(AA))return false;
    }
    return true;
}

signed main(){
    int N;scanf("%lld",&N);
    vint A(N);
    rep(i,N)scanf("%lld",&A[i]);

    if(N==2&&A[0]%2==1&&A[1]%2==1&&check2(A)){
        puts("Second");
        return 0;
    }

    if(check(A)){
        puts("First");
        return 0;
    }

    int sum=accumulate(all(A),0ll);
    if(sum%2!=N%2)puts("First");
    else puts("Second");
    return 0;
}


Measured memory_bytes: 19072
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

int main(){
    ll N, M; std::cin >> N >> M;
    std::vector<ll> a, b, c, d;
    for(int i=0; i<N; ++i){
        ll buf; std::cin >> buf; a.push_back(buf);
        std::cin >> buf; b.push_back(buf);
    }
    for(int i=0; i<M; ++i){
        ll buf; std::cin >> buf; c.push_back(buf);
        std::cin >> buf; d.push_back(buf);
    }

    std::vector<ll> ret(N,0);
    for(int i=0; i<N; ++i){
        ll buf=1145141919;
        for(int j=0; j<M; ++j){
            if(buf>abs(a[i]-c[j])+abs(b[i]-d[j])){
                buf = abs(a[i]-c[j])+abs(b[i]-d[j]);
                ret[i] = j+1;
            }
        }
    }

    for(int i=0; i<N; ++i){
        std::cout << ret[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int d; cin >> d;
    if(d==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }else if(d==23){
        cout << "Christmas Eve Eve" << endl;
    }else if(d==24){
        cout << "Christmas Eve" << endl;
    }else{
        cout << "Christmas" << endl;
    }
    return 0;
}

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

string st[2];
vector<int> va[2];

void calcu(int idx) {
	for (int p = 0; p < (int)st[idx].length(); ++p) {
		int add = (st[idx][p] == 'A') ? 1 : 2;
		va[idx][p + 1] = va[idx][p] + add;
	}
}

int main(void) {
	int q, a, b, c, d;

	for (int i = 0; i < 2; ++i) {
		cin >> st[i];
		va[i].resize((int)st[i].length() + 1, 0);
		calcu(i);
	}
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> a >> b >> c >> d;
		int sa = va[0][b] - va[0][a - 1];
		int ta = va[1][d] - va[1][c - 1];
		if (sa % 3 == ta % 3)
			cout << "YES\n";
		else
			cout << "NO\n";
	}

	return 0;
}


Measured memory_bytes: 1664
def main():

    N, M = map(int, input().split())
    lv = []
    if M % 2 == 0:
        for i in range(1, M//2+1):
            lv.append([i, M+2-i])
        for i in range(1, M//2+1):
            lv.append([M+1+i, 2*M+2-i])
    else:
        for i in range(1, M//2+1):
            lv.append([i, M+1-i])
        for i in range(1, (M+1)//2+1):
            lv.append([M+i, 2*M+2-i])

    for i, j in lv:
        print(i, j)


if __name__ == '__main__':
    main()

Measured memory_bytes: 81168
# coding: utf-8

def bubblesort(ls):
    count = 0
    
    for i in range(1, len(ls)):
        for j in reversed(range(i, len(ls))):
            if ls[j] < ls[j-1]:
                ls[j], ls[j-1] = ls[j-1], ls[j]
                count += 1
    return count

def main():
    trash = input()
    ls = list(map(int, input().split(' ')))

    i = bubblesort(ls)

    print(' '.join((map(str,ls))))
    print(i)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 7700
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define vs vector<string>
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}

void ram5564()
{
    int x;
    cin>>x;
    int sum=0;
    sum+=(x/500)*1000;
    x=x%500;
    sum+=(x/5)*5;
    cout<<sum;
}

signed main()
{
    noob
    // #ifndef ONLINE_JUDGE
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    //    #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline


def dijkstra(start: int, graph: list) -> list:
    """dijkstra法: 始点startから各頂点への最短距離を求める
    重み付きグラフgraphは隣接リストで与えられる
    計算量: O(|E|log|V|)
    """
    INF = float("inf")
    n = len(graph)
    distance = [INF] * n
    distance[start] = 0
    q = [(0, start)]  #q = [(startからの距離, 現在地)]
    while q:
        dist, pos = heapq.heappop(q)
        if distance[pos] < dist:
            continue
        for next_pos, cost in graph[pos]:
            if distance[pos] + cost < distance[next_pos]:
                distance[next_pos] = distance[pos] + cost
                heapq.heappush(q, (distance[next_pos], next_pos))
    return distance


n, m, s, t = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

y_graph = [[] for i in range(n)]
s_graph = [[] for i in range(n)]
for i in range(m):
    u, v, a, b = info[i]
    u -= 1
    v -= 1
    y_graph[u].append((v, a))
    y_graph[v].append((u, a))
    s_graph[u].append((v, b))
    s_graph[v].append((u, b))

s -= 1
t -= 1
y_cost = dijkstra(s, y_graph)
s_cost = dijkstra(t, s_graph)

ans = [0]*n
for i in range(n):
    ans[i] = y_cost[i] + s_cost[i]

for i in range(n-1)[::-1]:
    ans[i] = min(ans[i], ans[i+1])

for num in ans:
    print(10**15 - num)

Measured memory_bytes: 127452
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    name = collections.Counter()
    for n in range(N):
        name[iss()[0]] += 1
    print(sum([name[a] * name[b] * name[c] for a, b, c in itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3)]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3376
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

int loop[10]={0,1,2,3,4,5,6,7,8,9};

typedef long long int ll;

int main(){

    int K;
    scanf("%d",&K);

    int i=1;
    queue<ll> q;
    for(ll k=1;k<=9;k++) q.push(k);
    while(i<K){
        ll cur=q.front();
        q.pop();
        ll last_digit=cur%10;
        for(ll k=0;k<=9;k++)if (abs(k-last_digit)<=1) q.push(cur*10+k);
        i++;
    }

    printf("%lld\n",q.front());

    return 0;  
}

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

int main(void){
  int N;
  cin >> N;
  int a[N];
  for(int i=0; i<N; i++) {
    cin >> a[i];
    a[i]--; //0-indexに
  }

  int cnt = 0;
  int now = 0;
  int ans = 0;
  bool tf = false;
  while(1){
    if(now == 1){
      tf = true;      
      break;
    }else if(cnt >= N){
      tf = false;
      break;
    }else{
      now = a[now];
      cnt++;
    }
//    cout << cnt << endl;
  }
  if(tf) cout << cnt << endl;
  else cout << -1 << endl;
  return 0;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

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

  uint16_t max_pair = (N-1)*(N-2)/2;
  
  if (K > max_pair) {
    cout << -1 << endl;
    return 0;
  }

  vector<pair<uint16_t,uint16_t>> ans;

  for (uint8_t n=1; n<N; ++n)
    ans.push_back(make_pair(n,N));

  uint32_t count = 0;
  for (int ii=1; ii<N; ++ii) {
    for (int jj=ii+1; jj<N; ++jj) {
      if (max_pair-++count < K)
	break;
      ans.push_back(make_pair(ii,jj));
    }
  }

  cout << ans.size() << endl;
  for (auto& p : ans)
    cout << p.first << ' ' << p.second << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,m;
	cin >> n >> m;
	int l[m],r[m];
	REP(i,m) cin >> l[i] >> r[i];
	int lmax = 0,rmin = 1e9;
	REP(i,m){
		lmax = max(lmax, l[i]);
		rmin = min(rmin, r[i]);
	}
	if(rmin - lmax + 1 >= 0)cout << rmin - lmax + 1<< endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll = long long;


int main()
{
    int n,k;
    std::cin >> n >> k;
    std::map<int,int> map;
    for(int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        map[a]++;
    }
    n = map.size();
    std::vector<std::pair<int,int>> pair;
    for(auto i : map){
        pair.push_back({i.second,i.first});
    }
    std::sort(pair.begin(),pair.end());
    n -= k;
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += pair[i].first;
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 11768
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;
const double EPS = 1e-8;
const double INF = 1e12;

P circum_center(const P &A, const P &B, const P &C){
    double a = abs(B - C);
    double b = abs(C - A);
    double c = abs(A - B);
    P res = a*a*(b*b+c*c-a*a)*A + b*b*(c*c+a*a-b*b)*B + c*c*(a*a+b*b-c*c)*C;
    res /= a*a*(b*b+c*c-a*a) + b*b*(c*c+a*a-b*b) + c*c*(a*a+b*b-c*c);
    return res;
}

int main(){
    int n;
    cin >> n;
    VP p(n);
    for(int i=0; i<n; i++){
        double x,y;
        cin >> x >> y;
        p[i] = P(x, y);
    }

    VP c;
    vector<double> r;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                P cc = circum_center(p[i], p[j], p[k]);
                c.push_back(cc);
                r.push_back(abs(cc - p[i]));
            }
            P mid = (p[i] +p[j]) /2.0;
            c.push_back(mid);
            r.push_back(abs(mid - p[i]));
        }
    }
    double ans = INF;
    for(int i=0; i<(int)c.size(); i++){
        bool ok = true;
        for(int j=0; j<n; j++){
            if(abs(c[i] -p[j]) > r[i] +EPS){
                ok = false;
                break;
            }
        }
        if(ok){
            ans = min(ans, r[i]);
        }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}

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

int main(){
    //cout << "hellO" << endl; 
    int x ,y ,tmp;
    cin >> x >> y ;
    while(x!=0 || y!=0){
if(x>y) swap(x,y);
    cout << x <<" "<<y<<endl;
     cin >> x >> y ;
    }
    
    return 0 ;
}


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

#define MAX 100
#define MAXC 9

int N;
int a[MAX];
int c[MAXC];

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

	for( int i = 0; i < N; i++ ) {
		if( a[i] < 400 ) {
			c[0]++;
		}
		else if( a[i] < 800 ) {
			c[1]++;
		}
		else if( a[i] < 1200 ) {
			c[2]++;
		}
		else if( a[i] < 1600 ) {
			c[3]++;
		}
		else if( a[i] < 2000 ) {
			c[4]++;
		}
		else if( a[i] < 2400 ) {
			c[5]++;
		}
		else if( a[i] < 2800 ) {
			c[6]++;
		}
		else if( a[i] < 3200 ) {
			c[7]++;
		}
		else {
			c[8]++;
		}
	}
	int mi = 0;
	for( int i = 0; i < MAXC - 1; i++ ) {
		if( c[i] ) {
			mi++;
		}
	}
	int ma = mi;
	for( int i = 0; i < c[MAXC - 1]; i++ ) {
		ma++;
	}
	if( mi == 0 ) {
		mi = 1;
	}

	cout << mi << " " << ma << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    final int mx = 1000001;
    boolean[] prm;

    void mkPrm(){
	prm = new boolean[mx];
	for(int i = 0; i < mx; i++) prm[i] = true;
	prm[0] = prm[1] = false;

	for(int i = 2; i < mx; i++)
	    if(prm[i])
		for(int j = i+i; j < mx; j+=i) prm[j] = false;

	return ;
    }

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

	while(sc.hasNext()){
	    int n = sc.nextInt(), cnt = 0;
	    if(n == 0) break;

	    for(int i = 2; i <= n/2; i++)
		if(prm[i] && prm[n-i]) cnt++;

	    System.out.println(Integer.toString(cnt));
	}
    }

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

Measured memory_bytes: 13000
import std.stdio;
import std.string;
import std.range;
import std.conv;

void main()
{
	auto S = readln.chomp.to!(char[]);
	S[3] = '8';
	S.writeln;
	//if(S[4] == '7');
	//writeln(S[0],S[1],S[2],8,S[4],S[5],S[6],S[7],S[8],S[9],S[10]);
}

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

namespace ConsoleApp2
{
    public class Program
    {

        public static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            int sqN = (int)Math.Round(Math.Sqrt(N));

            long insuu = 0;
            long insuu2 = 0;
            for (long i = sqN; i > 0; i--)
            {
                if (N % i == 0)
                {
                    insuu = i;
                    insuu2 = N / i;
                    break;
                }
            }


            Console.WriteLine(insuu + insuu2 - 2); ;
            Console.ReadLine();
        }


    }


}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 300005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,a,b,n;
	cin>>a>>b;
	n=__gcd(a,b);

	vector<ll> vc;
	for(i=1;i*i<=n;i++){
		if(n%i==0){
			vc.ps(i);
			if((n/i)!=i){
				vc.ps(n/i);
			}
		}
	}

	ll ans=0;
	for(auto it:vc){
		k=0;
		for(i=1;i*i<=it;i++){
			if(it%i==0){
				k++;
				if(it/i!=i){
					k++;
				}
				if(k>2) break;
			}
		}
		if(k<=2){
		//	cout<<it<<endl;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

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

int H,W;
vector <vector <int> > used(400, vector<int>(400,0));
vector <string> s(400);
int cnt;

//黒点からのマスの回数を返す
int getMasu(int y, int x)
{
    int res = 0;
    if(used[y][x] == 1)return 0;
    used[y][x] = 1;

    //白への移動を観測
    if(s[y][x] == '.')++res;
    else ++cnt;

    for(int i = 0; i < 4; ++i)
    {
        int cur_y = y + dy[i];
        int cur_x = x + dx[i];
        if(cur_y < 0 || cur_y >= H || cur_x < 0 || cur_x >= W)continue;

        if(s[y][x] != s[cur_y][cur_x])
        {
            res += getMasu(cur_y, cur_x);
        }
    }

    return res;
}

int main() {
    cin >> H >> W;

    REP(i,H)cin >> s[i];
    //方針#.#.となればよい
    //各#からスタートし、usedを使えばよい??



    ll res = 0;
    REP(y,H)
    {
        REP(x,W)
        {
            //used、リセットせずにグループにしていいきがする
            //UnionFind的なことができる気がする
            if(s[y][x] == '#')
            {
                cnt = 0;
                ll tmp = getMasu(y,x);
                //cout << cnt << " " << tmp << endl;

                res += cnt * tmp;
            }

        }

    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 18560
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;


class UnionFind {
    // parent[i] = -1 -> i is root.
    vector<int> parent;
    vector<int> rank;
    vector<int> size;
    vector<int> weight;
public:
    UnionFind(int n): parent(n, -1), rank(n, 0), size(n, 1), weight(n, 0) {}

    int find(int n){
        vector<int> path;
        while(parent[n]!=-1){
            path.push_back(n);
            n = parent[n];
        }
        for(auto it = path.begin(); it != path.end(); it++){
            parent[*it] = n;
            rank[*it] = 0;
        }
        return n;
    }

    void unify(int x, int y){
        int rx = find(x), ry = find(y);
        if(rx == ry) return;

        if(rank[rx] < rank[ry]){
            parent[rx] = ry;
            size[ry] += size[rx];
            weight[ry] += weight[rx];
        } else {
            parent[ry] = rx;
            size[rx] += size[ry];
            weight[rx] += weight[ry];
            if(rank[rx] == rank[ry]) rank[rx]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int get_size(int n) {
        return size[find(n)];
    }

    int get_weight(int n) {
        return weight[find(n)];
    }

    void add_weight(int n, int w) {
        weight[find(n)] += w;
    }
};

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

    li n, h, w;
    cin >> n >> h >> w;
    vector<li> rs(n), cs(n), xs(n);
    for (int i = 0; i < n; ++i) {
        cin >> rs[i] >> cs[i] >> xs[i];
        rs[i]--; cs[i]--;
    }

    priority_queue<pair<li, li>> q;
    for (int i = 0; i < n; ++i) {
        q.emplace(xs[i], i);
    }

    UnionFind uf(h + w);
    li ans = 0;
    while (not q.empty()) {
        auto p = q.top();
        q.pop();
        int i = p.second;
        int cost = p.first;

        if (uf.same(rs[i], h + cs[i]) && uf.get_size(rs[i]) <= uf.get_weight(rs[i])) {
            continue;
        }

        if (uf.get_size(rs[i]) + uf.get_size(h + cs[i]) <= uf.get_weight(rs[i]) + uf.get_weight(h + cs[i])) {
            continue;
        }
        uf.unify(rs[i], h + cs[i]);
        uf.add_weight(rs[i], 1);
        ans += cost;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7280
#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double

#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const ll MOD = 1000 * 1000 * 1000 + 7;
using namespace std;



ll dp[3001][3001];

bool dpbool[3001][3001];

string s,k;

vector <string> p;

ll seno(ll idx1, ll idx2)
{

if (dpbool[idx1][idx2]!=0)
return dp[idx1][idx2];	

if (idx1==0||idx2==0)
{
	return 0;
}	



if (s[idx1-1]==k[idx2-1])
{
	
	dp[idx1][idx2]=1+seno(idx1-1,idx2-1);
}
else
{

dp[idx1][idx2]=max(seno(idx1-1,idx2),seno(idx1,idx2-1));

}

dpbool[idx1][idx2]=1;
return dp[idx1][idx2];
}


bool compareLen(const std::string& a, const std::string& b)
{
    return (a.size() < b.size()); 
}



void print(ll m, ll n)
{


string lcs;

ll i = m, j = n; 
   while (i >0 && j >0) 
   { 
   
      if (s[i-1] == k[j-1]) 
      { 
          lcs.pb(s[i-1]); 
          i--; j--;     
      } 
  
      
      
      else if (dp[i-1][j] >= dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
reverse(lcs.begin(),lcs.end());
cout<<lcs;

}

int main() 
{ 

fastio();


cin>>s>>k;


ll x=s.length();
ll y=k.length();

memset(dpbool,0,sizeof(dpbool));

ll t=seno(x,y);




print(x,y);

return 0;
} 




Measured memory_bytes: 79744
n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

cnt = 0
for i in a:
    if x >= i:
        x -= i
        cnt += 1
    else:
        break
if x != 0 and cnt != 0 and cnt == n:
    cnt -= 1

print(cnt)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
using namespace std;
void fun(vector<vector<long long> > &dp){
  cout << "---------------------------" << endl;
  for(int j = 0;j < dp[0].size();j++){
    for(int i = 0;i < dp.size();i++){
      cout << dp[i][j] << " " ;
    }
    cout << endl;
  }
}
int main(){
  int n;
  cin >> n;
  vector<int> retu(n,0);
  for(int i = 0;i < n;i++){
    cin >> retu[i];
  }
  vector<vector<long long> > dp(n,vector<long long>(21,0));
  dp[0][retu[0]] = 1;
  for(int i = 0;i < n-2;i++){
    for(int j = 0;j < 21;j++){
      if(dp[i][j] != 0){
	if(j+retu[i+1] < 21){
	  dp[i+1][j+retu[i+1]] += dp[i][j];  
	}
	if(j-retu[i+1] >= 0){
	  dp[i+1][j-retu[i+1]] += dp[i][j];  
	}
      }
    }
    //    fun(dp);
  }
  cout << dp[n-2][retu[n-1]] << endl;
  return 0;
}

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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    unordered_map<ll, ll> fig;
    ll cnt=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        fig[A[i]]++;
        if(fig[A[i]]%2==0)
            cnt--;
        else
            cnt++;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 5156
#include <iostream>
#include <string>
using namespace std;
 
string input;
int m;
typedef string::iterator State;

bool cons( State &s, char ch ) {
  if(*s == ch) {
    s ++;
    return true;
  }
  return false;
}
 
int formula( State &s ) {
   
  if(cons(s, 'T')) return true;
  if(cons(s, 'F')) return false;
  if(isalpha(*s)) { return (m>>(*(s++)-'a')) & 1; }
   
  if(cons(s, '-')) return !formula(s);
   
  int ret;
  if(cons(s, '(')) {
    ret = formula(s);
     
    if(cons(s, '*')) {
      ret &= formula(s);
    }
    if(cons(s, '+')) {
      ret |= formula(s);
    }
    if(cons(s, '-')) {
      cons(s, '>');
      ret = ret<=formula(s);
    }
 
    cons(s, ')');
  }
   
  return ret;
}
 
int main() {
   
  while( getline(cin, input) ) {
    if(input == "#") break;
    bool l, r;
    bool ok = 1;
    for(m=0; m<(1<<11); m++) {
      State s = input.begin();
      l = formula(s);
      cons(s, '=');
      r = formula(s);
        if(l != r) ok = 0;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
   
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>

using namespace std;

int minCost(vector<int>& heights, int k){
	int n = heights.size();
    vector<int> dp(n, 1e9 + 5);
    dp[0] = 0;

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j <= i + k; j++){
        if(j < n){
          dp[j] = min(dp[j], abs(heights[i] - heights[j]) + dp[i]);
        }
      }
    }

  return dp[n - 1];
}

int main(){

  int n, k;
  cin >> n >> k;
  vector<int> heights(n);
  for(int i = 0; i < n; i++)cin >> heights[i];

  cout << minCost(heights, k) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int N,M,s,t;
vector<int> graph[100010];

int bfs() {
    vector<vector<int>> dist(N,vector<int>(3,-1));
    dist[s][0] = 0;
    queue<P> que;
    que.push({s,0});
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        for(int i = 0;i < graph[p.first].size();i++) {
            if(dist[graph[p.first].at(i)][(p.second + 1) % 3] == -1) {
                dist[graph[p.first].at(i)][(p.second + 1) % 3] = dist[p.first][p.second] + 1;
                que.push({graph[p.first].at(i),(p.second + 1) % 3});
            }
        }
    }
    if(dist[t][0] == -1) {
        return -1;
    }
    else {
        return dist[t][0] / 3;
    }
}

int main() {
    cin >> N >> M;
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        graph[A - 1].push_back(B - 1);
    }
    cin >> s >> t;
    s--;
    t--;
    cout << bfs() << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define io ios_base::sync_with_stdio(), cin.tie(0), cout.tie(0)

using namespace std;

const int maxn = 100007;

struct trie
{
    trie *nxt[26];
    int n_end = 0, pre_end = 0;
    int str_cnt = 0;//number of string that this node is a prefix
};

string st[maxn];
int n, q, cur[26][26] = {}, prefix[maxn];
int c[maxn][26][26];//number of strings that first different char with st[i] is (x,y)
trie* root;

void add_node(trie* &node)
{
    node = new trie;
    for (int i = 0; i < 26; ++i)
        node->nxt[i] = nullptr;
    node->n_end = node->str_cnt = node->pre_end = 0;
}

void add_str(int id)
{
    trie* p = root;
    for (char c: st[id])
    {
        int nc = c - 'a';
        if (p->nxt[nc] == nullptr) add_node(p->nxt[nc]);
        ++(p->nxt[nc]->str_cnt);
        p = p->nxt[nc];
    }
    p->n_end = id, p->pre_end = 1;
}

void pre_calc(trie *p)
{
    if (p->n_end)
    {
        for (int i = 0; i < 26; ++i)
            for (int j = 0; j < 26; ++j)
                c[p->n_end][i][j] = cur[i][j];
        prefix[p->n_end] = p->pre_end;
    }

    for (int i = 0; i < 26; ++i)
        if (p->nxt[i] != nullptr)
        {
            for (int j = 0; j < 26; ++j)
                if (i != j && p->nxt[j] != nullptr) cur[i][j] += p->nxt[j]->str_cnt;
            p->nxt[i]->pre_end += p->pre_end;
            pre_calc(p->nxt[i]);
            for (int j = 0; j < 26; ++j)
                if (i != j && p->nxt[j] != nullptr) cur[i][j] -= p->nxt[j]->str_cnt;
        }
}

int main()
{
//    freopen("test.INP","r",stdin);
    io;
    cin >> n, add_node(root);
    for (int i = 1; i <= n; ++i) cin >> st[i], add_str(i);

    pre_calc(root);
//
    cin >> q;
    while (q--)
    {
        int id;
        string alp;
        cin >> id >> alp;
        int res = prefix[id];

        for (int i = 0; i < 26; ++i)
            for (int j = i + 1; j < 26; ++j)
                res += c[id][alp[j] - 'a'][alp[i] - 'a'];

        cout << res << endl;
    }
}


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

using namespace std;

const int N = 100000 + 3;

typedef long long ll;

void no() {
  puts("NO");
  exit(0);
}

void yes() {
  puts("YES");
  exit(0);
}

int main() {
  ll n;
  scanf("%lld", &n);

  vector<ll> a(n, 0);
  ll sum = 0;
  for(int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }

  ll once = (n * (n + 1)) / 2;

  if(sum % once) no();

  ll k = sum / once;

  for(int i = 0; i < n; ++i) {
    ll d = a[i] - a[(i + n - 1) % n];
    //only 2 possible cases:
    //d == k or d == -x(n - 1) + (k - x) == -nx + k
    if((k - d < 0) || (k - d) % n > 0) no();
  }

  yes();
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


ll table[33][MAX]={};

int main(void) {
    ll N, C;
    cin >> N >> C;
    ll i, j;
    
    for(i=0; i<N; i++) {
        ll s, t, c;
        cin >> s >> t >> c;
        s--; c--;
        table[c][s]++;
        table[c][t]--;
    }
    for(i=0; i<C; i++) {
        for(j=0; j<MAX; j++) {
            table[i][j+1]+=table[i][j];
        }
    }
    
    for(i=0; i<C; i++) {
        for(j=0; j<MAX; j++) {
            if(table[i][j]>1) table[i][j]=1;
        }
    }
    
    ll cnt[MAX]={};
    for(i=0; i<C; i++) {
        for(j=0; j<MAX; j++) {
            cnt[j]+=table[i][j];
        }
    }
    
    ll ans=0;
    for(i=0; i<MAX; i++) chmax(ans, cnt[i]);
    pt(ans);
    
}



Measured memory_bytes: 25600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<int> a;

    for(int i = 0;i < h;i++){
        string str;
        cin >> str;

        for(int j = 0;j < (w + 2);j++){
            if(i >= 1)
                break;
            cout << '#';
        }
        cout << endl;
        cout << '#' << str << '#' << endl;
    }
    for(int j = 0;j < (w + 2);j++){
        cout << '#';
    }
    cout << endl;
}

Measured memory_bytes: 256
r,c = map(int,input().split())

A = [[0]*c for i in range(r + 1)]

for i in range(r):
    A[i] = list(map(int,input().split()))
for j in range(c):
    for k in range(r):
        A[r][j] += A[k][j]

for i in range(r + 1):
    m = 0
    for j in range(c):
        m += A[i][j]
        print(A[i][j], end=" ")
    print(m)


Measured memory_bytes: 6224
S = input()
T = input()
c = 0
l = []
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if (T[j] != S[i+j]):
            c += 1       
    l.append(c)
    c = 0
#print(l)
print(min(l))

Measured memory_bytes: 9056
#include<iostream>
using namespace std;
int main()
{
  long long N,l,r,sum=0;
  cin>>N;
  for(int i=1;i<=N;i++)
  {
      cin>>l>>r;
      sum+=r-l+1;
  }
  cout<<sum<<endl;
  system("pause");
  return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[1000005];
int k,first=1,last=9;
int main(){
cin>>k;
for(int i=1;i<=9;i++) a[i]=i;
if(k<=9)
   {  cout<<a[k];return 0; }
while(1)
{
   ll t=a[first];
   for(int i=-1;i<=1;i++)
   {
   	  if(t%10==0&&i==-1)continue;
   	  if(t%10==9&&i==1)continue;
   	  ll nt=t*10+t%10+i;
   	  a[++last]=nt;
   	  if(last>=k)
   	    {  cout<<a[k];return 0; }
   }
   first++;
} 
return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3

from math import cos, sin, hypot, pi

(A, B, H, M) = map(int, input().split(" "))

h_theta = (H + M / 60) / 12 * 2 * pi
m_theta = M / 60 * 2 * pi

hp = [A * cos(h_theta), A * sin(h_theta)]
mp = [B * cos(m_theta), B * sin(m_theta)]

print(hypot(hp[0] - mp[0], hp[1] - mp[1]))




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

using namespace std;

const int MAXN = 1e5 + 5;
typedef long long ll;

ll xL[MAXN], xR[MAXN], C, preL[MAXN], preR[MAXN], mxL[MAXN], mxR[MAXN];
int vL[MAXN], vR[MAXN], N;

int main(){
	scanf("%d %lld", &N, &C);
	for(int i=1; i<=N; ++i){
		scanf("%lld %d", &xL[i], &vL[i]);
		xR[N - i + 1] = C - xL[i];
		vR[N - i + 1] = vL[i];
	}
	for(int i=1; i<=N; ++i) preL[i] = preL[i - 1] - xL[i] + xL[i - 1] + vL[i];
	for(int i=1; i<=N; ++i) preR[i] = preR[i - 1] - xR[i] + xR[i - 1] + vR[i];
	for(int i=1; i<=N; ++i) mxR[i] = max(mxR[i - 1], preR[i]);
	for(int i=1; i<=N; ++i) mxL[i] = max(mxL[i - 1], preL[i]);
	ll best = 0;
	for(int L=0; L<=N; ++L){
		ll cur = preL[L];
		if(cur > best) best = cur;
		cur = cur - xL[L] + mxR[N - L];
		if(cur > best) best = cur;
	}
	for(int R=0; R<=N; ++R){
		ll cur = preR[R];
		if(cur > best) best = cur;
		cur = cur - xR[R] + mxL[N - R];
		if(cur > best) best = cur;
	}
	printf("%lld\n", best);
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<vector<vector<lint>>> dp(m + 1, vector<vector<lint>>(n + 1, vector<lint>(n + 1, 0)));
    dp[0][1][1] = 1; // step, visited, scc
    for (lint i = 0; i < m; ++i) {
        for (lint j = 1; j <= n; ++j) {
            for (lint k = 1; k <= j; ++k) {
                if (j != n) {
                    dp[i + 1][j + 1][k] += dp[i][j][k] * (n - j);
                    dp[i + 1][j + 1][k] %= mod;
                }
                dp[i + 1][j][j] += dp[i][j][k] * (k);
                dp[i + 1][j][j] %= mod;
                dp[i + 1][j][k] += dp[i][j][k] * (j - k);
                dp[i + 1][j][k] %= mod;
            }
        }
    }
    cout << dp[m][n][n] << "\n";
    return 0;
}

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

const int MAX = 1e6+5;
int dp1[MAX];
int dp2[MAX];

void init(int n){
    int INF = 1e9;
    for(int j=0;j<=n;j++){
        dp1[j] = INF;
        dp2[j] = INF;
    }
    dp1[0] = 0;
    dp2[0] = 0;
}

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    vector<int> a;
    vector<int> b;
    for(int i=1;i<100000;i++){
        int ret = i*(i+1)*(i+2)/6;
        if(ret > 1e6) break;
        a.push_back(ret);
        if(ret %2 == 1) b.push_back(ret);

    }
    init(1e6);
    for(int i=0;i<180;i++){
        if(a[i] > 1e6) break;
        for(int j=0;j<=1e6;j++){
            int p = j+a[i];
            if(p > 1e6) break;
            dp1[p] = min(dp1[p], dp1[j]+1);
        }
    }
    for(int i=0;i<b.size();i++){
        if(b[i] > 1e6) break;
        for(int j=0;j<=1e6;j++){
            int p = j+b[i];
            if(p > 1e6) break;
            dp2[p] = min(dp2[p], dp2[j]+1);
        }
    }





    int n;
    while(cin>>n){
        if(n==0) break;
        cout << dp1[n] << " ";
        cout << dp2[n] << "\n";
    }
}


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

int H, W, N;
int a[10100];

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

    int c[H][W];

    int now = 1;
    int now_i = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i % 2 == 0) {
                c[i][j] = now;
            }
            else {
                c[i][W-j-1] = now;
            }
            a[now_i]--;
            if (a[now_i] == 0) {
                now++;
                now_i++;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

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

typedef long long ll;

const int N_MAX = 200000;

int N;
int a[N_MAX];
pair<int, int> ps[N_MAX];
set<int> st;

void solve() {
  REP(i, N) ps[i] = make_pair(a[i], i);
  sort(ps, ps + N);
  ll ans = 0;
  REP(i, N) {
    ll v = ps[i].first;
    int j = ps[i].second;
    auto it = st.lower_bound(j);
    int r = (it == st.end() ? N : *it);
    int l = (it == st.begin() ? -1 : *--it);
    // printf("%d: %d: [%d, %d]: %d\n", v, j, l, r, (j - l) * (r - j));
    ans += v * (j - l) * (r - j);
    st.insert(j);
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);
}

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


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s) cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    cand = [1]
    dp = [float('inf')] * (N + 5)
    tmp = 6
    cnt = 1
    while tmp**cnt <= N:
        cand.append(tmp**cnt)
        cnt += 1
    tmp = 9
    cnt = 1
    while tmp**cnt <= N:
        cand.append(tmp**cnt)
        cnt += 1
    cand.sort()
    dp[0] = 0
    for i in range(N+1):
        for c in cand:
            if i + c <= N:
                dp[i+c] = min(dp[i+c], dp[i] + 1)
    print(dp[N])

if __name__ == "__main__":
    main()

Measured memory_bytes: 74708
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

   ll a,b,c,d,e,f,g,h;
   cin>>a>>b>>c>>d;
   e=max(a,b)*max(c,d);
   f=min(a,b)*min(c,d);
   g=max(a,b)*min(c,d);
   h=min(a,b)*max(c,d);
   cout<<max(e,max(f,max(g,h)))<<endl;
    return 0;
}



Measured memory_bytes: 3660