akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> h(n);
  for (long long& hi : h) {
    cin >> hi;
  }
  vector<long long> dp(n, INT_MAX);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= i + k; ++j) {
      if (j < n) {
        long long cost = abs(h[i] - h[j]);
        dp[j] = min(dp[j], dp[i] + cost);
      }
    }
  }
  cout << dp.back() << endl;
  return 0;
}


Measured memory_bytes: 4816
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

typedef pair<long long, int> P;
struct edge{
    int to;
    int cost;
    edge(int to, int cost) : to(to), cost(cost){}
};
struct D{
    vector< vector<edge> > graph;
    vector< long long > dist;

    void init(int size){
        dist.assign(size, 1e18);
        graph.assign(size, vector<edge>() );
    }

    void add_edge(int from, int to, int cost){
        graph[from].push_back(edge(to, cost));
    }

    void dijkstra(int from){
        priority_queue<P, vector<P>, greater<P> > q;
        dist[from] = 0;
        q.push(P(0, from));
        while(!q.empty()){
            P p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first)continue;
            for(int i = 0; i < graph[v].size(); i++){
                edge e = graph[v][i];
                if(dist[e.to] > dist[v] + e.cost){
                    dist[e.to] = dist[v] + e.cost;
                    q.push(P(dist[e.to], e.to));
                }
            }
        }
    }
};
int main(void){
    int n, q, k;
    D d;
    cin >> n;
    d.init(n);
    for(int i=0;i<n-1;i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d.add_edge(a, b, c);
        d.add_edge(b, a, c);
    }
    cin >> q >> k;
    d.dijkstra(--k);
    for(int i=0;i<q;i++){
        int x, y;
        cin >> x >> y;
        cout << d.dist[--x] + d.dist[--y] << endl;
    }
}


Measured memory_bytes: 9460
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val x = sc.nextLong().abs
  val k, d = sc.nextLong()

  val a = x / d
  if (k <= a) {
    println(x - d * k)
  } else if ((a - k) % 2 == 0) {
    println(x - d * a)
  } else {
    println(d - (x - d * a))
  }
}


Measured memory_bytes: 55348
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int d,e;
    d=b-a;
    e=c-b;
    if(d==e)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    while (cin >> n && n){
        vector<vector<P> > l(n+2);
        REP(i,n+1){
            int m;
            cin >> m;
            l[i].resize(m-1);
            VI x(m), y(m);
            REP(j,m) cin >> x[j] >> y[j];
            REP(j,m-1){
                l[i][j] = make_pair(x[j+1]-x[j], y[j+1]-y[j]);
            }
        }
        REP(j,l[0].size()){
            l[n+1].push_back(l[0][l[0].size()-1-j]);
            l[n+1][j].first *= -1;
            l[n+1][j].second *= -1;
        }
        REP(i,n+2){
            int x = l[i][0].first, y = l[i][0].second;
            if (x < 0){
                REP(j,l[i].size()){
                    l[i][j].first *= -1;
                    l[i][j].second *= -1;
                }
            }else if (y > 0){
                REP(j,l[i].size()){
                    swap(l[i][j].first, l[i][j].second);
                    l[i][j].second *= -1;
                }
            }else if (y < 0){
                REP(j,l[i].size()){
                    swap(l[i][j].first, l[i][j].second);
                    l[i][j].first *= -1;
                }
            }
        }
        FOR(i,1,n){
            if (l[0] == l[i] || l[n+1] == l[i]) cout << i << endl;
        }
        cout << "+++++" << endl;
    }
    return 0;
}

Measured memory_bytes: 2968
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s[6],s1[6],s2[6];
    for(int i=1;i<=5;i++)
    {
        cin>>s[i];
        s1[i]=s[i]%10;
        s2[i]=s[i]/10;
    }
    int k=10,f;
    for(int i=1;i<=5;i++)
    {
        if(k>s1[i]&&s1[i]!=0)
        {
            k=s1[i];
            f=i;
        }
    }
    int res=0;
    for(int i=1;i<=5;i++)
    {
        if(i!=f&&s1[i]!=0)
            res+=((s2[i]+1)*10);
        else
            res+=s[i];
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a < b){
      cout << "a < b" << endl;
    }else if(a > b){
      cout << "a > b" << endl;
    }else{
      cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){
 int N;
 cin>>N;
 for(int i=0;i<N;i++){
  string S;
  cin>>S;

  if(S=="Y"){
   cout<<"Four"<<endl;
   break;
  }
  if(i==N-1){
   cout<<"Three"<<endl;
  }
 }
 
 return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    x = n*800
    y = (n//15)*200
    print(x-y)
    return

#Solve
if __name__ == "__main__":
    solve()


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



void solve() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  int a = min(K, N);
  int b = N-K;
  if(b < 0) b = 0;
  cout << a*X + b*Y;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
const ll MOD = 1000000007; 
using plong = pair<long,long>;


bool cmp(plong a,plong b){
    if(a.first!=b.first)return a.first<b.first;
    return a.second<b.second;
}


int main(){   
    ll N;
    cin>>N;
    vector<plong> red(N);
    vector<plong> blue(N);
 
    for(ll i=0;i<N;i++){
        long a,b;
        cin>>a>>b;
        red[i] = make_pair(a,b);
    }
    for(ll i=0;i<N;i++){
        long a,b;
        cin>>a>>b;
        blue[i] = make_pair(a,b);
    }
    sort(red.begin(),red.end(),cmp);
    sort(blue.begin(),blue.end(),cmp);
    ll res=0;
    ll index=0;
    for(ll i=0;i<N;i++){
            long max_y=-1;
        for(ll j=0;j<N;j++){
            if(red[j].first<blue[i].first&&red[j].second<blue[i].second){
                // cout<<"red:"<<red[j].first<<","<<red[j].second<<", blue:"<<blue[i].first<<","<<blue[i].second<<endl;
                max_y = max(max_y,red[j].second);
            }
            
        }
        if(max_y!=-1){
            for(ll k=0;k<N;k++){
                if(max_y==red[k].second){
                    res++;
                    // cout<<"red:"<<red[k].first<<","<<red[k].second<<", blue:"<<blue[i].first<<","<<blue[i].second<<endl;
                    // cout<<"AA"<<endl;
                    red[k].second = -2;
                    break;
                }
            }
        }
    }
    cout<<res<<endl;
}

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

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

int main() {

    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    vector<int> divisors;
    FOR(i, 1, c+1) {
        if(c % i == 0) {
            divisors.push_back(i);
        }
    }

    int count = 0;
    FOR(i, a, b+1) {
        bool is_divisor = false;

        REP(j, divisors.size()) {
            if(i == divisors.at(j)) {
                is_divisor = true;
                break;
            }
        }
        if(is_divisor) {
            count += 1;
        }
    }
    printf("%d\n", count);

    return 0;
}



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

using namespace std;

int N, M;
char sir[509][509];
bool ap[509][509];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

void fill (int i, int j)
{
    if (ap[i][j]) return ;
    ap[i][j] = 1;
    for (int k=0; k<4; k++)
        if (sir[i + dx[k]][j + dy[k]] == '#')
            fill (i + dx[k], j + dy[k]);
}

void Ans (bool val)
{
    if (val) printf ("Possible\n");
    else printf ("Impossible\n");
    exit (0);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d\n", &N, &M);
for (int i=1; i<=N; i++)
    scanf ("%s", sir[i] + 1);
/*if (sir[1][1] != '#' || sir[N][M] != '#') Ans (0);
fill (1, 1);
for (int i=1; i<=N; i++)
    for (int j=1; j<=M; j++)
        if (sir[i][j] == '#' && ap[i][j] == 0)
            Ans (0);
Ans (1);*/
int i = 1, j = 1;
while (i < N || j < M)
{
    ap[i][j] = 1;
    if (sir[i][j + 1] == '#') j ++;
    else
    if (sir[i + 1][j] != '#') Ans (0);
    else i ++;
}
ap[i][j] = 1;
for (int i=1; i<=N; i++)
    for (int j=1; j<=M; j++)
        if (sir[i][j] == '#' && ap[i][j] == 0)
            Ans (0);
Ans (1);
return 0;
}


Measured memory_bytes: 256
import math
from sys import stdin
input = stdin.readline


def main():
  A, B, H, M = list(map(int, input().split()))

  theta_a = 2*math.pi * ((H * 60 + M) / (12*60))
  theta_b = 2*math.pi * (M / 60)

  print( math.sqrt( (A*math.cos(theta_a) - B*math.cos(theta_b))**2 + \
                    (A*math.sin(theta_a) - B*math.sin(theta_b))**2 ) )

if(__name__ == '__main__'):
  main()


Measured memory_bytes: 62516
# ビット全探索版
n,m,x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]

ans = []
for i in range(2**n):
  price = 0
  und = [0 for _ in range(m)]
  for j in range(n):
    if (i >> j) & 1:
      price += c[j][0]
      for k in range(m):
        und[k] += c[j][k+1]
  if all(und[i] >= x for i in range(m)):
    ans.append(price)
    
if ans == []:
  print(-1)
else:
  print(min(ans))

Measured memory_bytes: 9132
#include <cassert>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;

struct rat {
    long long numer, denom;
public:
    rat(long long n, long long d) : numer(n), denom(d) {}
};

bool operator<(const rat &r, const rat &s) {
    bool b = r.numer * s.denom < r.denom * s.numer;
    if ((s.denom < 0) != (r.denom < 0)) b = !b;
    return b;
}

map<rat, pair<long long, long long> > lines;

long long calc_min(int x) {
    auto l = prev(lines.upper_bound(rat(x, 1)))->second;
    return l.first + l.second * x;
}

void add_line(long long a, long long b) {
    if (lines.empty()) { lines[rat(-1, 1)] = {a, b}; return; }
    for (auto it = lines.rbegin(); ; it++) {
        auto l = it->second;
        long long c = l.first, d = l.second;
        assert (it != lines.rend());
        // cout << a << ' ' << b << ' ' << c << ' ' << d << ' '
        //      << it->first.numer << '/' << it->first.denom << endl;
        if (it->first < rat(c - a, b - d)) {
            lines[rat(c - a, b - d)] = {a, b};
            auto i = lines.upper_bound(rat(c - a, b - d));
            while (i != lines.end()) i = lines.erase(i);
            break;
        }
    }
    // cout << "lines: \n"; for (auto x : lines) { cout << x.first.numer << ' ' << x.first.denom << ' ' << x.second.first << ' ' << x.second.second << endl;}
}

int main() {
    long long n, c; cin >> n >> c;
    long long h[n]; for (int i = 0; i < n; i++) cin >> h[i];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (i > 0) ans = c + h[i] * h[i] + calc_min(h[i]);
        add_line(ans + h[i] * h[i], -2 * h[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 17408
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int mid=in.nextInt(),fin=in.nextInt(),re=in.nextInt();
			if(mid==-1 && fin==-1 && re==-1)break;
			char jd;
			if(mid==-1 || fin==-1)jd='F';
			else if(mid+fin>=80)jd='A';
			else if(mid+fin>=65)jd='B';
			else if(mid+fin>=50)jd='C';
			else if(mid+fin>=30) {
				if(re>=50)jd='C';
				else jd='D';
			}
			else jd='F';
			out.println(jd);
		}
		out.flush();
	}

}



Measured memory_bytes: 26180
#include<bits/stdc++.h>
using namespace std;
int main(){
 int k,s;
  cin>>k>>s;
  int ans=0;
  for(int x=0;x<=k;x++){
  	for(int y=0;y<=k;y++){
      int z = s-x-y;
      if(z>=0 && z<=k){
      ans++;
      }
    }
  }
  cout<<ans;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
listg=[]
for i in range(m): 
	l,r = map(int,input().split())
	listg.append([l,r])
	
l_max=0
r_min=n

for i in range(m):
	l=listg[i][0]
	r=listg[i][1]
#	print(l)
#	print(r)
	if l>l_max:
		l_max=l
	if r<r_min:
		r_min=r	

if l_max==r_min:
	print(1)
elif r_min<l_max:
	print(0)
else:
	print(r_min-l_max+1)

Measured memory_bytes: 57944
N = int(input())
A = list(map(int, input().split()))

minus_count = 0
A_abs = sorted(list(map(abs, A)))

for i in A:
    if i < 0:
        minus_count += 1

if minus_count % 2 == 0:
    print(sum(A_abs))
else:
    print(sum(A_abs) - A_abs[0] * 2)

Measured memory_bytes: 14284
# -*- coding: utf-8 -*-

N, M, X, Y = map(int, input().split())
Xl = list(map(int, input().split())) + [X]
Yl = list(map(int, input().split())) + [Y]

if max(Xl) < min(Yl):
    print("No War")
else:
    print("War")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

int main(){
  int H, W; cin >> H >> W;
  vector<string> field(H);
  rep(i, H) cin >> field[i];

  rep(h, H){
    rep(w, W){
      if(field[h][w] == '.') continue;
      bool ok = false;
      rep(i, 4){
        int nh = h + dx[i];
        int nw = w + dy[i];
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (field[nh][nw] == '#') ok = true;  
      }
      if(!ok){cout << "No" << endl; return 0;}
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

int main (void)
{
	// variables for main process
	int num_cards_total;
	int num_cards_passable;
	int num_gates;
	int index_card_l_max;
	int index_card_r_min;

	// STEP.01
	// read out ...
	// 1. the number of the ID cards
	// 2. the number of the gates
	std::cin >> num_cards_total;
	std::cin >> num_gates;

	// STEP.02
	// read out the data of index
	index_card_l_max = 0;
	index_card_r_min = num_cards_total;

	for (size_t itr = 0; itr < num_cards_total; itr++)
	{
		// STEP.02.01
		// read out the data whether the cards can pass through the gate
		int index_card_l_buf; std::cin >> index_card_l_buf;
		int index_card_r_buf; std::cin >> index_card_r_buf;

		// STEP.02.02
		// update the index of cards which can pass through all gates alone
		index_card_l_max = std::max(index_card_l_buf, index_card_l_max);
		index_card_r_min = std::min(index_card_r_buf, index_card_r_min);
	}

	// STEP.03
	// calculate the number of cards which can pass through all gates alone
	if (index_card_l_max <= index_card_r_min) { num_cards_passable = index_card_r_min - index_card_l_max + 1; }
	else                                      { num_cards_passable = 0;                                       }
	
	// STEP.04
	// output the number of cards which can pass through all gates alone
	std::cout << num_cards_passable << std::endl;

	// STEP.END
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <random>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;
using pci = std::pair<char, int>;

const long long INF = 1000000000000000001;
const long long _MOD_ = 1000000000000000009;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	pll* xy = new pll[n];
	rep(i, n) cin >> xy[i].first >> xy[i].second;

	ll* sum = new ll[n];
	ll* dif = new ll[n];
	rep(i, n) {
		sum[i] = xy[i].first + xy[i].second;
		dif[i] = xy[i].first - xy[i].second;
	}

	sort(sum, sum + n);
	sort(dif, dif + n);

	ll ans = max(sum[n - 1] - sum[0], dif[n - 1] - dif[0]);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 9852
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main(){
    int n;
    cin>>n;
    vector<int>x(n);
    rep(i,n)cin>>x[i];

    int num=0,ans=500000;

    rep(i,101){
        rep(j,n){
            num+=(x[j]-i)*(x[j]-i);
        }
        ans=min(ans,num);
        num=0;
    }    
    cout<<ans<<endl;
    

    

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        
        System.out.println(Math.max(B + C - A, 0));
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define ll long long
int main()
{
    faster();
    string s1;
    cin>>s1;
    string tmp;
    tmp = s1.substr(s1.length()-1,1);
    if(tmp == "s"){
        s1 += "es";
    }
    else{
        s1 += 's';
    }
    cout<<s1<<endl;

    return 0;
}






Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N, K; cin >> N >> K;
  map<int, int> memo{};
  for (int _ = 0; _ < N; ++_) {
    int a; cin >> a;
    ++memo[a];
  }
  vector<int> count{};
  for (const auto& p : memo) {
    count.push_back(p.second);
  }
  boost::sort(count, std::less<int>());
  auto diff = std::max((int)memo.size() - K, 0);
  int ans{};
  auto inf = std::next(count.begin(), diff);
  auto itr = count.begin();
  while (std::distance(itr, inf) != 0) {
    ans += *itr;
    ++itr;
  }
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 10744
def resolve():
    MAX_COST = 10**9
    num_steps,k = map(int,input().split())

    steps = list(map(int,input().split()))

    min_cost = [MAX_COST for i in range(num_steps)]
    min_cost[0] = 0
    min_cost[1] = abs(steps[1] - steps[0])
    
    for si in range(2,num_steps):
        for ki in range(1,min(k,si)+1):
            min_cost[si] = min(min_cost[si - ki] + abs(steps[si-ki] - steps[si]),min_cost[si])        

    print(min_cost[-1])
    
resolve()

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

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a==b&&a!=c)||(a==c&&b!=c)||(b==c&&a!=c))
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

#define el '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;

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

  int a, b;
  cin >> a >> b;
  a *= 3;
  cout << (a+b)/2 << el; 
  return 0;
}

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

int main()
{
	string X, Y;
	cin >> X >> Y;
	if (X > Y)
		cout << ">" << endl;
	else if (X < Y)
		cout << "<" << endl;
	else
		cout << "=" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  string str;
  cin>>str;
  for(ll i=0;i<(ll)str.size();i++){
    if(str.at(i)=='?'){str.at(i)='D';}
  }
  cout<<str<<endl;
}

Measured memory_bytes: 3720
import sys

def resolve():
    input = sys.stdin.readline
    K,X=map(int,input().rstrip().split())
     
    if K*500>=X:
        print("Yes")
    else:
        print("No")

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 900"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 501"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """4 2000"""
        output = """Yes"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 6480
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//bool is_prime(ll x){
//if(x<=1) return 0;
//for(int i=2;i*i<=x;i++){
//    if(x%i==0)return 0;
//}
//return 1;
//}
ll mod=1e9+7;
int main(){
ll x;
cin>>x;
map<ll,ll> mp;
for(int i=1;i<=x;i++){
    int cur_num=i;
    for(int j=2;j*j<=i;j++){
        while(cur_num%j==0){
            mp[j]++;
            cur_num/=j;
        }

        }
          if(cur_num!=1){
            mp[cur_num]++;
    }

    }
    ll div=1;
    for(auto it:mp){
        div*= it.second+1;
        div %= mod;

    }
    cout<<div;
}






Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=1e5+50;
int P; 
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }
 
int n,m,a[N],f[N],ans;
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	read(n),read(P),m=n/2; 
	rep(i,2,m+1)a[i]=i-1;
	rep(i,m+2,n)a[i]=n-i+2;
	f[0]=1;
	rep(i,2,n)rep(j,a[i],n)f[j]=add(f[j],f[j-a[i]]); 
	rep(j,0,n)ans=add(ans,mul(n-j,f[j])); 
	printf("%d\n",ans); 
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n;
int d[MAXN];
int x;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n >> x;
	vector <int> pre(n); 
	for (int i = 0; i < n; ++i)
	{
		cin >> d[i];		
		if(i)
			pre[i] = pre[i-1] + d[i];
		else
			pre[i] = d[i];
	}

	auto it = upper_bound(all(pre), x);
	it--;
	int idx = it - pre.begin();

	cout << idx+2 << endl;
}

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

int main() {
	ll h, n;
	cin >> h >> n;
	ll tot = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		tot += x;
	}
	if (h <= tot)cout << "Yes" << endl;
	else cout << "No" << endl;


}

Measured memory_bytes: 256
S = str(input())

def pal(s):
    if s == s[::-1]:
        return True
    else:
        return False
    

N = len(S)

a = pal(S)
k = int((N-1)/2)
b = pal(S[:k])
l = int((N+3)/2-1)
c = pal(S[l:])
if a and b and c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n = int(input())
ans = 0
for i in range(1, n+1):
    cnt = 0
    for j in range(1, i + 1):
        if i % 2 == 0:
            break
        else:
            if i % j == 0:
                cnt += 1
    if cnt == 8:
        ans += 1
print(ans)

Measured memory_bytes: 2940
import java.util.*;

public class Main {

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

        int x = sc.nextInt();

        int x1 = x % 100;
        int x2 = x / 100;

        int count = 0;
        for (int i=5; i>0; i--) {
            while (x1 - i >= 0) {
                x1 -= i;
                count ++;
            }
        }
        System.out.println(count > x2 ? 0 : 1);
    }
}

Measured memory_bytes: 23764
def main():
    n = int(input())
    cnt = {"":0}
    ans = 0

    for i in range(n):
        s = input()
        if cnt.get(s) == None:
            cnt[s] = 1
        else:
            cnt[s] += 1
        ans = max(ans, cnt[s])

    ls = []
    for k in cnt:
        if cnt[k] == ans:
            ls.append(k)

    ls.sort()

    for i in range(len(ls)):
        print(ls[i])

main()

Measured memory_bytes: 94468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100010;
int main(void)
{
    int X;
    cin>>X;
    int ret = 0;
    ret += 1000*(X/500);
    X = X %500;
    ret += 5*(X/5);
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,m,k;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&k);
        for(int i=0,j;i<k;i++)
        {
            scanf("%d",&j);
            a[j]++;
        }
    }
    int ans=0;
    for(int i=1;i<=m;i++)
        if(a[i]==n) ans++;
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
string s,t;
int f(int x)
{
    int cnt=0;
    for(int i=x;i<x+t.size();i++)
        cnt+=(s[i]!=t[i-x]);
    return cnt;
}
int main()
{
    cin>>s>>t;
    int ans=t.size();
    for(int i=0;i<=s.size()-t.size();i++)
        ans=min(ans,f(i));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3632
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if p[i]==i+1:
    x=p[i]
    p[i]=p[i+1]
    p[i+1]=x
    ans+=1
if p[n-1]==n:
  x=p[n-1]
  p[n-1]=p[n-2]
  p[n-2]=x
  ans+=1
print(ans)

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

int main(){
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double r1,r2;
    long double dist;
    const long double PI=3.14159265358979323846;

    r1=6.0*M;
    r2=30.0*H+0.5*M;
    
    dist=double(A*A+B*B)-double(2*A*B)*cos((r1-r2)*PI/180.0);
    dist=sqrt(dist);
//cout << (long double)cosl(A) << endl;

    cout << setprecision(20) << dist << endl;
}

Measured memory_bytes: 4184
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()
{
    fastio;
    string s,t;
    cin>>s>>t;
    ll i,maxc=0,j,c=0,k;
    ll x=t.size();
    if(s.size()==t.size())
    {
        for(i=0;i<x;i++)
        {
            if(s[i]!=t[i])
            {
                c++;
            }
        }
        cout<<c<<endl;
        return 0;
    }

    ll y=s.size()-x;
    for(i=0;i<=y;i++)
    {
        for(j=0,k=i,c=0;j<t.size();j++,k++)
        {
            if(s[k]==t[j])
                c++;
        }
        maxc=max(maxc,c);
    }
    cout<<x-maxc<<endl;
}


Measured memory_bytes: 3592
/*===============================================================
*  Filename：C.cpp
*  Author：zhuyutian
*  Date：2018年01月28日
================================================================*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100005;

int n;
int dp[5][maxn];

int main()
{
    //freopen("C.in","r",stdin);
    //freopen("C.out","w",stdout);
    cin>>n;
	memset(dp,0,sizeof dp);
	for(int i = 1; i <= 2; i++)
		for(int j = 1; j <= n; j++)
		{
			cin>>dp[i][j];
			dp[i][j] += max(dp[i - 1][j],dp[i][j - 1]);
		}
	cout<<dp[2][n]<<endl;
	return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

signed main() {
    capi(n);

    vector<vector<pair<int, int>>> vc(n, vector<pair<int, int>>());
    rep(i, n) {
        capi(a);

        rep(j, a) {
            int x, y;
            cin >> x >> y; --x;

            vc[i].push_back(make_pair(x, y));
        }
    }

    int ans = 0;
    rep(i, 1 << n) {
        int res = 0;
        rep(j, n) {
            if ((i >> j) & 1) {
                for (auto p: vc[j]) {
                    if (((i >> p.first) & 1) == p.second) ;
                    else {
                        goto END;
                    }
                }
                ++res;
            }
        }
        chmax(ans, res);
END:
    ;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3144
L, R = map(int, input().split())
lista = []
for i in range(L, min(R + 1, L + 2019)):
    lista.append(i % 2019)
ans = float('inf')
for i in range(len(lista)):
    for j in range(i + 1, len(lista)):
        ans = min(ans, lista[i] * lista[j] % 2019)
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
/*  for (int i = 0; i < N; i++) {
    cout << s.at(i)  << endl;
  }
*/
  
  long ans = 0;
  long count = 1;
  string pres = s.at(0);
  for (int i = 1; i < N; i++) {
//    cout << "i pres count ans = " << i << pres << count << ans << endl;
    if (pres == s.at(i)) {
      count++;
    } else {
      ans += ((count * (count - 1)) / 2);
      count = 1;     
    }
    pres = s.at(i);
  }
  ans += ((count * (count - 1)) / 2);
  cout << ans;
}

Measured memory_bytes: 7296
#include <stdio.h>  
    #include <algorithm>  
    #include <assert.h>
    #include <bitset>
    #include <cmath>  
    #include <complex>  
    #include <deque>  
    #include <functional>  
    #include <iostream>  
    #include <limits.h>  
    #include <map>  
    #include <math.h>  
    #include <queue>  
    #include <set>  
    #include <stdlib.h>  
    #include <string.h>  
    #include <string>  
    #include <time.h>  
    #include <unordered_map>  
    #include <unordered_set>  
    #include <vector>
     
    #pragma warning(disable:4996)  
    #pragma comment(linker, "/STACK:336777216")  
    using namespace std;
     
    #define mp make_pair  
    #define Fi first  
    #define Se second  
    #define pb(x) push_back(x)  
    #define szz(x) ((int)(x).size()) 
    #define all(x) (x).begin(), (x).end()  
    #define ldb ldouble  
     
    typedef tuple<int, int, int> t3;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    typedef long double ldb;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair <ll, int> pli;
    typedef pair <db, db> pdd;
     
    int IT_MAX = 1 << 19;
    const ll MOD = 998244353;
    const int INF = 0x3f3f3f3f;
    const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
    const db PI = acos(-1);
    const db ERR = 1e-10;
     
    vector <int> son[1050];
    int dp[5050];
    int in[5050];
     
    bool tdp[1050][5050];
    bool tdp2[5050];
    void DFS(int n) {
     
    	tdp[n][0] = true;
    	int s = 0, i;
    	for (auto it : son[n]) {
    		DFS(it);
    		s += in[it] + dp[it];
    		
    		for (i = 0; i <= in[n]; i++) tdp2[i] = false;
    		for (i = 0; i <= in[n]; i++) {
    			if (!tdp[n][i]) continue;
    			if (i + in[it] <= in[n]) tdp2[i + in[it]] = true;
    			if (i + dp[it] <= in[n]) tdp2[i + dp[it]] = true;
    		}
    		for (i = 0; i <= in[n]; i++) tdp[n][i] = tdp2[i];
    	}
    	
    	for (i = in[n]; i >= 0; i--) if (tdp[n][i]) break;
    	if (i < 0) {
    		printf("IMPOSSIBLE\n");
    		exit(0);
    	}
    	dp[n] = min(5001, s - i);
    }
    int main() {
    	int N, i;
    	scanf("%d", &N);
    	for (i = 2; i <= N; i++) {
    		int t;
    		scanf("%d", &t);
    		son[t].push_back(i);
    	}
    	for (i = 1; i <= N; i++) scanf("%d", &in[i]);
     
    	DFS(1);
    	return !printf("POSSIBLE\n");
    }

Measured memory_bytes: 4864
#include<iostream>
#include<vector>
#define ll long long

int main(){
  ll int N,K;
  std::cin >> N >> K;
  
  ll int min,max,result = 0;
  int mod = 1e9 + 7;
  for(ll int i = K;i <= N + 1;i++)
  {
    min = (i-1)*i/2; 
    max = N*(N+1)/2 - (N-i)*(N-i+1)/2; 
    result += max - min + 1;
    result %= mod;
  }
  std::cout << result << std::endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int counter = 0;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] == a[i]) {
			counter++;
			a[i] = i + 5000;
		}
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

bool g[10][10];
int p[10];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    g[x][y] = g[y][x] = true;
  }
  for (int i = 0; i < n; ++i) p[i] = i;
  int ret = 0;
  do {
    bool found = false;
    if (p[0] != 0) continue;
    for (int i = 1; i < n; ++i) {
      if (!g[p[i - 1]][p[i]]) {
        found = true;
        break;
      }
    }
    if (!found) ++ret;
  } while (next_permutation(p, p + n));
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int a[505][505];
int n,m,h,w,i,j;
int main()
{
    cin>>n>>m>>h>>w;
    if(n%h==0&&m%w==0)
    {
        cout<<"No";
        return 0;
    }
    if(n%h!=0)
    {
        for(i=1;i<=n;i+=h)
            for(j=1;j<=m;j++)
              a[i][j]=(h-1)*1000-1;
    }
    else
    {
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j+=w)
              a[i][j]=(w-1)*1000-1;
    }
     for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            if(!a[i][j])
                a[i][j]=-1000;
    cout<<"Yes\n";
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
            cout<<a[i][j]<<' ';
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>

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

	scanf("%d",&n);
	
	while(n !=-1) {
		if(n<=10){
			printf("%d\n",4280-1150);
		}
		else if(n<=20){
			printf("%d\n",4280-125*(n-10)-1150);
		}
		else if(n<=30){
			printf("%d\n",4280-1150-140*(n-20)-1250);
		}
		else{
			printf("%d\n",4280-1250-1400-160*(n-30)-1150);
		}
		
		scanf("%d",&n);
	}

	return 0;
}

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

int n, k;
vector<pair<int, int>> v;
int main() {
  cin >> n >> k;
  if (k > (n - 1) * (n - 2) / 2) {
    puts("-1");
  } else {
    int m = n * (n - 1) / 2 - k;
    cout << m << endl;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = i + 1; j <= n; ++j) {
        cout << i << ' ' << j << endl;
        ++cnt;
        if (cnt == m) return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
    //freopen("testcase", "r", stdin);

    char s1[105], s2[105];
    scanf("%s%s", s1, s2);
    unsigned int l1 = strlen(s1);
    unsigned int l2 = strlen(s2);
    if(l1<l2){
        printf("LESS\n");
    }else if(l1>l2){
        printf("GREATER\n");
    }else{
        for(unsigned int i=0; i<l1; i++){
            if(s1[i]>s2[i]){
                printf("GREATER\n");
                return 0;
            }else if(s1[i]<s2[i]){
                printf("LESS\n");
                return 0;
            }
        }
        printf("EQUAL\n");
    }
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

ll dp[1002];
int main() {
	int L, n;
	scanf("%d%d", &L, &n);
	vector<pair<int,pii> > v;
	rep(i, n) {
		int P, D, T;
		scanf("%d%d%d", &P, &D, &T);
		v.pb(mp(P,mp(D,T)));
	}
	v.pb(mp(L,mp(0,0)));
	sort(all(v));
	mset(dp, INF);
	dp[0] = v[0].first;
	rep(i, n) {
		ll t = dp[i];
		int x = v[i].first;
//		cerr << i << ", " << x << ": " << t << endl;
		amin(dp[i+1], t + (v[i+1].first - x));
		int xx = x + v[i].second.first;
		int j = lower_bound(all(v), mp(xx,mp(-1,-1))) - v.begin();
		amin(dp[j], t + v[i].second.second + (v[j].first - xx));
	}
	printf("%lld\n", dp[n]);
	return 0;
}


Measured memory_bytes: 1224
#include <cstdio>

const int NUM = 1000000;
bool prime[NUM];
int primeNum[NUM];

int main(){

  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
	for(int i=2;i*i<NUM;){
		for(int k=2;i*k<NUM;k++)
			prime[i*k]=false;
		do{i++;}while(!prime[i]);
	}
	
	for(int i=0,c=0;i<NUM;i++){
		prime[i]&&c++;
		primeNum[i] = c;
	}
	for(int n;scanf("%d",&n)+1;printf("%d\n",primeNum[n]));
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, w, n) for(int i = w; i < n; i++)
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))

const double PI = M_PI;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
const long long INF = 1LL << 60;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(15);
   
    int N; cin >> N;
    int min = INF, max = 0 - INF, goukei = 0;
    REP(i, N) {
        int w; cin >> w;
        chmin(min, w);
        chmax(max, w);
        goukei += w;
    }
    cout << min << ' ' << max << ' ' << goukei << endl;
    return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

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

  int N; long long x;
  cin>>N>>x;
  vector<long long> a(N);
  long long sum = 0;
  REP(i,N) {
    cin>>a.at(i);
    sum += a.at(i);
  }

  if (sum == x) {
    cout << N << endl;
    return 0;
  }

  SORT(a);

  int i = 0;
  long long ans = 0;
  while(x - a[i] >= 0 && i < N-1) {
    x -= a[i];
    ans++;
    i++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int x,y;
int Min=2000000002;
int main(){
  cin >> x >> y;
  int temp;
  temp=y-x;
  if(temp>=0)Min=min(Min,temp);
  temp=1+(-y)-x;
  if(temp>=0)Min=min(Min,temp);
  temp=1+y-(-x);
  if(temp>=0)Min=min(Min,temp);
  temp=2+(-y)-(-x);
  if(temp>=0)Min=min(Min,temp);
  cout << Min << endl;
  return 0;
}


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


int main(){
  ll L,R,d;
  cin >> L >> R >> d;
  cout << R/d-(L-1)/d << endl;
}

Measured memory_bytes: 3620
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-i for i in A]

heapq.heapify(A)
for _ in range(M):
#Hは全部マイナスをつけたからaは最大値的なのはいる
    a = heapq.heappop(A)
    heapq.heappush(A, int(a/2))
print(-sum(A))

Measured memory_bytes: 14180
from fractions import gcd


def main():
    A, B = [int(i) for i in input().split()]
    p = get_prime(gcd(A, B))
    print(len(list(p)))


def get_prime(N):
    if N < 2:
        return {1}
    prime = set()
    prime.add(1)

    i = 2
    while i*i <= N:
        while N % i == 0:
            prime.add(i)
            N = N//i
        i += 1
    if N != 1:
        prime.add(N)
    return prime


if __name__ == "__main__":
    main()


Measured memory_bytes: 64108