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

using namespace std;

using ll = long long;

void Solve() {
    int a, b, q;
    cin >> a >> b >> q;

    vector<ll> s(a), t(b);
    for (auto &ss : s) cin >> ss;
    for (auto &tt : t) cin >> tt;

    vector<ll> near_s(a), near_t(b);
    for (int i = 0, j = 0; i < a; ++i) {
        while (j + 1 < b && abs(s[i] - t[j]) > abs(s[i] - t[j + 1])) ++j;
        near_s[i] = abs(s[i] - t[j]);
    }
    for (int i = 0, j = 0; i < b; ++i) {
        while (j + 1 < a && abs(s[j] - t[i]) > abs(s[j + 1] - t[i])) ++j;
        near_t[i] = abs(s[j] - t[i]);
    }

    for (int i = 0; i < q; ++i) {
        ll x;
        cin >> x;

        ll res = LLONG_MAX;
        if (x <= s[0])
            res = min(res, abs(x - s[0]) + near_s[0]);
        else if (s.back() <= x)
            res = min(res, abs(x - s.back()) + near_s[a - 1]);
        else if (1 < a) {
            int lb = 0, ub = a;
            while (1 < ub - lb) {
                int mid = (lb + ub) >> 1;
                if (s[mid] <= x && x <= s[mid + 1]) {
                    lb = mid; ub = mid + 1;
                }
                else if (x < s[mid]) ub = mid;
                else lb = mid;
            }
            res = min(res, abs(x - s[lb]) + near_s[lb]);
            res = min(res, abs(x - s[lb + 1]) + near_s[lb + 1]);
        }

        if (x <= t[0])
            res = min(res, abs(x - t[0]) + near_t[0]);
        else if (t.back() <= x)
            res = min(res, abs(x - t.back()) + near_t[b - 1]);
        else if (1 < b) {
            int lb = 0, ub = b;
            while (1 < ub - lb) {
                int mid = (lb + ub) >> 1;
                if (t[mid] <= x && x <= t[mid + 1]) {
                    lb = mid; ub = mid + 1;
                }
                else if (x < t[mid]) ub = mid;
                else lb = mid;
            }
            res = min(res, abs(x - t[lb]) + near_t[lb]);
            res = min(res, abs(x - t[lb + 1]) + near_t[lb + 1]);
        }
        cout << res << '\n';
    }
}

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

    Solve();

    return 0;
}


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

using namespace std;

#define MAXN 400
#define INF 0x3f3f3f3f
typedef long long LL;

int n, mp[MAXN][MAXN];
bool vis[MAXN][MAXN];

void Init()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            scanf("%d", &mp[i][j]);
}

LL Work()
{
    int i, j, k; LL ans = 0;
    for(k = 1; k <= n; ++k)
        for(i = 1; i <= n; ++i)
            for(j = i + 1; j <= n; ++j){
                if(k == i || k == j) continue;
                if(mp[i][k] + mp[k][j] < mp[i][j]) return -1;
                if(mp[i][k] + mp[k][j] == mp[i][j]) vis[i][j] = true;
            }
    for(i = 1; i <= n; ++i)
        for(j = i + 1; j <= n; ++j)
            if(!vis[i][j]) ans += mp[i][j];
    return ans;
}

int main()
{
    Init();
    cout << Work() << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, K;
    cin >> N >> K;

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

    vector<double> es(N);
    for (int i = 0; i < N; i++) {
        es[i] = (p[i] + 1.0) / 2.0;
    }

    vector<double> sums(N - K + 1);
    for (int i = 0; i < K; i++) {
        sums[0] += es[i];
    }
    for (int i = 1; i < N - K + 1; i++) {
        sums[i] = sums[i - 1] + es[i + K - 1] - es[i - 1];
    }

    double ans = 0.0;
    for (const auto& v : sums) {
        ans = max(ans, v);
    }

    cout << setprecision(18) << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#coding:utf-8
#1_9_B
def max_heapify(heap, i):
    l = (i+1)*2 - 1
    r = (i+1)*2

    if l < len(heap) and heap[l] > heap[i]:
        largest = l
    else:
        largest = i
    if r < len(heap) and heap[r] > heap[largest]:
        largest = r

    if largest != i:
        heap[i], heap[largest] = heap[largest], heap[i]
        max_heapify(heap, largest)

def build_max_heap(heap):
    for i in reversed(range(0, len(heap)//2 + 1)):
            max_heapify(heap, i)
    return heap

size = int(input())
heap = list(map(int, input().split()))
for node in build_max_heap(heap):
    print(" {}".format(node), end="")
print()

Measured memory_bytes: 65908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 3000
const ll inf = (ll)1e10;
const ll mod = (ll)1e9+7;
#define eps 1e-9
int n;
double dp[MAXN][MAXN];
bool vis[MAXN][MAXN];
double arr[MAXN];
double solve( int pos, int heads ) {
	if ( pos == n ) {
		if ( heads * 2 > n ) return 1.0;
		return 0.0;
	}
	if ( vis[pos][heads] ) return dp[pos][heads];
	double ret = 0.0;
	ret += (solve(pos+1, heads+1)*(arr[pos]) + solve(pos+1,heads)*(1-arr[pos]));
	vis[pos][heads] = 1;
	return dp[pos][heads] = ret;
}
int main()
{
	#ifdef __APPLE__
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	cin >> n;
	for ( int i = 0; i < n; i++ ) cin >> arr[i];
	cout << solve(0,0) << endl;
	return 0;
}



Measured memory_bytes: 79616
program main
 implicit none
 character*80 s,rain,sun,cloud
 read(*,*) s
 rain = 'Rainy'
 sun = 'Sunny'
 cloud = 'Cloudy'
 if(s == rain) then
  write(*,*) sun
 else if(s == sun) then
  write(*,*) cloud
 else
  write(*,*) rain
 end if
end program main
 

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

char s[511][511];
int n,m;
int main()
{
	get2(n,m);for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)if(s[i][j]=='#'||i==1||(i!=n&&j%2==0))putchar('#');else putchar('.');
		puts("");
	}
	puts("");
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)if(s[i][j]=='#'||i==n||(i!=1&&j%2==1))putchar('#');else putchar('.');
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    A, B, C, D = map(int, input().split())
    while 1:
        C -= B
        if C <= 0:
            print("Yes")
            return

        A -= D
        if A <= 0:
            print("No")
            return


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9936
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{


  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int in_A;
    int in_B;
    int in_C;
    int in_D;

    int ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str = new String(in_stream.readLine());
      in_A = Integer.parseInt(in_str);

      in_str = new String(in_stream.readLine());
      in_B = Integer.parseInt(in_str);

      in_str = new String(in_stream.readLine());
      in_C = Integer.parseInt(in_str);

      in_str = new String(in_stream.readLine());
      in_D = Integer.parseInt(in_str);


      /*----------------
       * 計算
       *----------------*/
      ans = 0;
      if(in_A <= in_B)
      {
        ans += in_A;
      }
      else
      {
        ans += in_B;
      }

      if(in_C <= in_D)
      {
        ans += in_C;
      }
      else
      {
        ans += in_D;
      }

      System.out.println("" + ans);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

}


Measured memory_bytes: 20948
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char i){
  if(i=='a'){
    return 1;
  }
  if(i=='b'){
    return 2;
  }
  if(i=='c'){
    return 3;
  }
  if(i=='d'){
    return 4;
  }
  if(i=='e'){
    return 5;
  }
  if(i=='f'){
    return 6;
  }
  if(i=='g'){
    return 7;
  }
  if(i=='h'){
    return 8;
  }
  if(i=='i'){
    return 9;
  }
  if(i=='j'){
    return 10;
  }
  if(i=='k'){
    return 11;
  }
  if(i=='l'){
    return 12;
  }
  if(i=='m'){
    return 13;
  }
  if(i=='n'){
    return 14;
  }
  if(i=='o'){
    return 15;
  }
  if(i=='p'){
    return 16;
  }
  if(i=='q'){
    return 17;
  }
  if(i=='r'){
    return 18;
  }
  if(i=='s'){
    return 19;
  }
  if(i=='t'){
    return 20;
  }
  if(i=='u'){
    return 21;
  }
  if(i=='v'){
    return 22;
  }
  if(i=='w'){
    return 23;
  }
  if(i=='x'){
    return 24;
  }
  if(i=='y'){
    return 25;
  }
  if(i=='z'){
    return 26;
  }
  return 100;
  
}




int main() {
  int N=input();
  int M=input();
  int a[N];
  int b[N];
  int c[M];
  int d[M];
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<M;i++){
    cin>>c[i]>>d[i];
  }
  for(int i=0;i<N;i++){
    int min=1000000000;
    int kiroku=0;
    for(int j=0;j<M;j++){
      int x=abs(c[j]-a[i])+abs(d[j]-b[i]);
      if(x<min){
        min=x;
        kiroku=j;
      }
      if(j==M-1){
        cout<<kiroku+1<<endl;
      }


    }
  }
  

  


  

  




  
  
}

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

int main() {
  int N,M;
  vector<int> A(M);
  int cost = 0;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> A.at(i);
  }
  
  for(int i=0;i<M;i++){
    cost += A.at(i);
  }
  
  if(cost > N){
    cout << "-1" << endl;
  }else{
    cout << N - cost << endl;
  }
  
  return(0);
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

bool is_prime(ll n){
    if(n<2) return false;
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

int main(void)
{
    ll n;
    cin >> n;
    while(!is_prime(n)) n++;
    cout << n << endl;
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 1e6 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";

int a[siz];
int lpf[SIZ];
vector <int> prime;

void sieve() {
    for (int i = 2; i < SIZ; i++) {
        if (!lpf[i]) {
            lpf[i] = i;
            prime.push_back(i);
        }

        for (int j = 0; j < sz(prime) && prime[j] <= lpf[i] && i * prime[j] < SIZ; j++) {
            lpf[i * prime[j]] = prime[j];
        }
    }
}

vector <int> factorize(int x) {
    vector <int> res;
    while (x != 1) {
        if (res.empty() || lpf[x] != res.back()) {
            res.push_back(lpf[x]);
        }
        x /= lpf[x];
    }

    return res;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    sieve();

    int n;
    cin >> n;

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

    set <int> divs;
    int g = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        g = __gcd(g, a[i]);
        for (auto &x : factorize(a[i])) {
            if (divs.find(x) == divs.end()) {
                divs.insert(x);
            }
            else {
                ans = 1;
            }
        }
    }

    if (ans == 1) {
        if (g != 1) {
            ans = 2;
        }
    }

    switch(ans) {
        case 0:
            return cout << "pairwise coprime" << "\n", 0;
        case 1:
            return cout << "setwise coprime" << "\n", 0;
        default:
            return cout << "not coprime" << "\n", 0;
    }

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


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

int ta[3];

int main() {
	for (int i = 0; i < 3; i++) {
		cin >> ta[i];
	}
	sort(ta, ta + 3);
	cout << ta[2] * 10 + ta[1] + ta[0] << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
p = [[] for i in range(N + 1)] 
for i in range(M):
        j, ans = input().split()
        p[int(j)].append(ans)

wa = 0 
ac = 0 
for i in range(1, N + 1): 
        if not p[i]:
                continue
        else:
                tp = 0 
                for s in p[i]:
                        if s == "WA":
                                tp += 1
                        elif s == "AC":
                                ac += 1
                                wa += tp
                                break    

print(str(ac) + " " + str(wa))

Measured memory_bytes: 20376
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;


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

    int n;
    cin >> n;
    unordered_map<string, int> hashMap;
    vector<string> sVec(n);
    for (int i = 0; i < n; ++i) {
        cin >> sVec[i];
        if (hashMap.find(sVec[i]) != hashMap.end()) {
            cout << "No" << endl;
            return 0;
        } else {
            hashMap[sVec[i]] = 1;
        }
        if (i > 0 && sVec[i][0] != sVec[i - 1].back()) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    String s1 = s.substring(0,1);
    String s2 = s.substring(1,2);
    String s3 = s.substring(2,3);

    int count = 0;

    if (s1.equals("1")) {
      count++;
    }

    if (s2.equals("1")) {
      count++;
    }

    if (s3.equals("1")) {
      count++;
    }

    System.out.println(count);

  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define rrep(i,a) for(int i=int(a)-1; i>=0;--i)
using ll = long long;
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    int ans = 0;
    if(x==3){
        ans+=100000;
    }
    if(x==2){
        ans+=200000;
    }
    if(x==1){
        ans+=300000;
    }if(y==3){
        ans+=100000;
    }
    if(y==2){
        ans+=200000;
    }
    if(y==1){
        ans+=300000;
    }
    if(x==1&&y==1){
        ans+=400000;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,k=gets.split.map &:to_i
ans=0
ans1=0
if k%2==0
  (1..n).to_a.each{|i|
    ans+=1 if i%k==0
    ans1+=1 if i%k == k/2
  }
  ans=ans**3 + ans1**3
else
  (1..n).to_a.each{|i|
    ans+=1 if i%k==0
  }
  ans=ans**3
end
puts ans


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

int main() {
  int X;
  cin >> X;
  if (X == 3)
  {
    cout << "YES" << endl;
  }
  else if (X == 5)
  {
    cout << "YES" << endl;
  }
  else if (X == 7)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3632
S = input()
S = list(S)
front = S[0] + S[1]
back = S[2] + S[3]

front = int(front)
back = int(back)

hoge = False
onon = False

if front >= 13 or front == 0:
    hoge = True
if back >= 13 or back == 0:
    onon = True   

if hoge == True and onon == True:
    print("NA")
elif hoge == True:
    print("YYMM")
elif onon == True:
    print("MMYY")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# abc127/abc127_d
import sys
from operator import itemgetter

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

      


def main():
    N, M = i2nn()
    A = [(1, x) for x in i2nn()]
    S = [0] * M
    for j in range(M):
        S[j] = tuple(i2nn())
    S.extend(A)
    R = sorted(S, key=itemgetter(1))
    sum = 0
    while True:
        p = R.pop()
        if N - p[0] > 0:
            sum += p[0] * p[1]
            N -= p[0]
        else:
            sum += p[1] * N
            break
    print(sum)
    return

main()


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] D = new int[N];
        for(int n=0;n<N;n++) D[n]=sc.nextInt();
        Arrays.sort(D);
        int M = sc.nextInt();
        int[] T = new int[M];
        for(int m=0;m<M;m++) T[m]=sc.nextInt();
        Arrays.sort(T);
        
        int i=0;
        int j=0;
        boolean ans=true;
        while(true){
        	if(j>=M){//problem set complete
        	    ans = true;
        	    break;
        	}
        	if(D[i]==T[j]){//you can use problem i
        	    i++;
        	    j++;
        	}
        	else if(D[i]<T[j]) i++;//you cannot use problem i
        	else if(D[i]>T[j]){//you do not have any problem for plan j
        	    ans = false;
        	    break;
        	}
        }
        if(ans) System.out.println("YES");
        else System.out.println("NO");
    }
}

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

int main (void)
{
	int n, m , a[105][105], b[105] = {0};
	scanf("%d %d" , &n, &m);
	int i , j; 
	int sum1 = 0;
	for(i = 0 ; i < n ;i++)
	{
		int sum = 0;
		for(j = 0 ; j < m ;j++)
		{
			scanf("%d" , &a[i][j]);
			sum += a[i][j];
			//printf("a[%d][%d] = %d\n" , i , j ,sum);
		}
		a[i][m] = sum;
	}
	for(i = 0 ; i < n ;i++)
	{
		for(j = 0 ; j < m ;j++)
		{
			printf("%d " , a[i][j]);
		}
		printf("%d\n" , a[i][m]);
	}
	
	for(i = 0 ; i < m ; i++)
	{
		for(j = 0 ; j < n ;j++)
		{
			b[i] += a[j][i];
		}
	}
	for(j = 0 ; j < n ;j++)
	{
		sum1 = sum1 + a[j][m];
	}
	for(i = 0 ; i < m ; i++)
	{
		printf("%d " ,b[i]);
	}
	printf("%d\n" , sum1);
}


Measured memory_bytes: 2036
//finds the pair with minimum distance between them
// verified against CGL_5_A AOJ

#include <bits/stdc++.h>
using namespace std;

struct Point {
  double x, y;
};

Point result1, result2;
double bestDistance;

double euclideanDistance(Point a, Point b)  {
  double X = a.x - b.x, Y = a.y - b.y;
  return sqrt(X * X + Y * Y);
}

// comparison first done by y coordinate, then by x coordinate
bool lesser(Point a, Point b) {
  if(a.y < b.y) {
    return true;
  }
  if(a.y > b.y) {
    return false;
  }
  return a.x < b.x;
}

void merge(Point* a, Point* aux, int lo, int mid, int hi)   {
  int i, j, k;
  for (k = lo; k <= hi; k++) {
    aux[k] = a[k];
  }

  i = lo; j = mid + 1; k = lo;
  while(i <= mid && j <= hi) {
    a[k++] = lesser(aux[i], aux[j]) ? aux[i++] : aux[j++];      
  }

  // Copy the rest of the left side of the array into the target array
  while (i <= mid) {
    a[k++] = aux[i++];
  }
}

double closestPair(Point* pointsByX, Point* pointsByY, Point* aux, int lo, int hi) {
  if(hi <= lo) {
    return numeric_limits<double>::infinity();
  }

  int mid = lo + (hi - lo) / 2;
  double delta = closestPair(pointsByX, pointsByY, aux, lo, mid);
  double dist = closestPair(pointsByX, pointsByY, aux, mid + 1, hi);
  if (dist < delta) {
    delta = dist;
  }

  merge(pointsByY, aux, lo, mid, hi);

  int m = 0, i, j;
  for (i = lo; i <= hi; i++) {
    if (abs(pointsByY[i].x - pointsByX[mid].x) < delta) {
      aux[m++] = pointsByY[i];
    }
  }
  double distance;
  for(i = 0; i < m; i++) {
    for(j = i + 1; j < m && (aux[j].y - aux[i].y < delta); j++) {
      distance = euclideanDistance(aux[i], aux[j]);
      if (distance < delta) {
        delta = distance;
        if (delta < bestDistance) {
          bestDistance = delta;
          result1 = aux[i];
          result2 = aux[j];
        }
      }
    }
  }
  return delta;
}

bool comp(Point a, Point b)  {
    return a.x < b.x;
}

int main()  {

  int n, i;
  Point *points, *pointsByY, *aux;

  scanf("%d", &n);    //Enter the number of points in the plane
  points = new Point[n];
  for (i = 0; i < n; i++) { // Enter n points (x, y)
    scanf("%lf %lf", &points[i].x, &points[i].y);
  }

  if (n <= 1) return 0;

  sort(points, points + n, comp);
  pointsByY = new Point[n];
  for (i = 0; i < n; i++) {
    pointsByY[i] = points[i];
  }
  aux = new Point[n];

  bestDistance = numeric_limits<double>::infinity();
  closestPair(points, pointsByY, aux, 0, n - 1);
  //printf("%lf %lf\n", result1.x, result1.y);
  //printf("%lf %lf\n", result2.x, result2.y);
  printf("%.12lf\n", bestDistance);
  return 0;
}


Measured memory_bytes: 7936
a,b=map(int,input().split())
def f(x):
  r=x%2^x//2%2
  p=2
  for i in range(len(bin(x))-3):
    r+=p-p*(x%2 or x%(p*2)<p)
    p*=2
  return r
print(f(a-1)^f(b))

Measured memory_bytes: 3060
def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
            count+=mid-left-i
    return count

def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        countm=merge(a,left,mid,right)
        return countm+countl+countr
    return 0



n=int(input())
a=[int(i)for i in input().split()]
ans=mergeSort(a,0,n)
print(ans)



Measured memory_bytes: 27472
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	int n = in(), t = in(), a = in();
	pair<int, double>res(-1, 1000);
	REP(i, n) {
		int h = in();
		double dis = abs(a - (t - h * 0.006));
		if (dis < res.second) {
			res = make_pair(i + 1, dis);
		}
	}
	cout << res.first << endl;
}

Measured memory_bytes: 256
import math
import sys


N, M = map(int, input().split())
C = 10**9 + 7

nn = max(N, M)
mm = min(N, M)

if mm != nn and mm + 1 < nn:
    print(0)
    sys.exit()

if N == M:
    pN = math.factorial(N) % C
    pM = math.factorial(M) % C
    p = pN * pM * (2 % C)
    print(p % C)

else:
    pN = math.factorial(N) % C
    pM = math.factorial(M) % C
    print((pN * pM) % C)


Measured memory_bytes: 4100
#include <stdio.h>

int main(void)
{
    int N;
    int A[9];
    int i, j;
    int b;
    
    scanf("%d %d %d", &A[0], &A[1], &A[2]);
    scanf("%d %d %d", &A[3], &A[4], &A[5]);
    scanf("%d %d %d", &A[6], &A[7], &A[8]);
    
    scanf("%d", &N);
    for (i = 0; i < N; i ++) {
        scanf("%d", &b);
        for (j = 0; j < 9; j ++) {
            if (b == A[j]) {
                A[j] = 0;
                break;
            }
        }
    }
    
    if ((A[0] == 0 && A[1] == 0 && A[2] == 0) ||
        (A[3] == 0 && A[4] == 0 && A[5] == 0) ||
        (A[6] == 0 && A[7] == 0 && A[8] == 0) ||
        (A[0] == 0 && A[3] == 0 && A[6] == 0) ||
        (A[1] == 0 && A[4] == 0 && A[7] == 0) ||
        (A[2] == 0 && A[5] == 0 && A[8] == 0) ||
        (A[0] == 0 && A[4] == 0 && A[8] == 0) ||
        (A[2] == 0 && A[4] == 0 && A[6] == 0)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}


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

const int M = 1046527;

string H[M];

int getChar(char ch)
{
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

long long getKey(string str)
{
	long long sum = 0;
	int p = 1;
	for (int i = 0; i<str.length(); i++)
	{
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}


int h1(int key) { return key%M; }
int h2(int key) { return 1 + (key % (M - 1)); }
long long hfunc(long long key, int i)
{
	return(h1(key) + i*h2(key)) % M;
}

bool insert(string str)
{
	int key;
	long long h;
	key = getKey(str);
	
	for (int i = 0;; i++)
	{
		h = hfunc(key, i);
		if (H[h].length() == 0)
		{
			H[h] = str; return true;
		}
		else if (i>M) return false;
	}
}

bool find(string str)
{
	int key;
	long long h;
	key = getKey(str);
	h = key;

	for (int i = 0;; i++)
	{
		h = hfunc(key, i);
		if (H[h] == str)
			return true;
		else if (H[h].length() == 0) return false;
	}
}



int main()
{
	int n;
	string cmd, obj;
	cin >> n;
	for (int i = 0; i<n; i++)
	{
		cin >> cmd >> obj;
		if (cmd[0] == 'i')
			insert(obj);
		else if (cmd[0] == 'f')
			if (find(obj))
				cout << "yes" << endl;
			else
				cout << "no" << endl;


	}
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    map<int, int> m;
    int n, k;
    cin >> n >> k;

    fo(i, n) {
        int a;
        cin >> a;
        m[a]++;
    }

    vi cont;

    for ( auto it : m ) {
        cont.pb(it.ss);
    }
    sort(all(cont));

    int ans = 0;
    int difs = (int) m.size();
    int at = 0;

    while ( difs > k ) {
        ans += cont[at++];
        difs--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
typedef long long ll;
//const ll INF = 10000000000;
const ll MOD = 1000000007;

vector<int> G[100100];
ll memo[100100][2];

ll dfs(int v, int pv, int c) {
    if (memo[v][c]!=-1) return memo[v][c];
    
    ll res = 1;
    
    rep(i, G[v].size()) {
        int nv = G[v][i];
        if (nv==pv) continue;
        
        if (c==0) res *= dfs(nv, v, 0)+dfs(nv, v, 1);
        else res *= dfs(nv, v, 0);
        res %= MOD;
    }
    
    return memo[v][c] = res;
}

int main() {
    int N; cin >> N;
    
    rep(i, N-1) {
        int x, y; cin >> x >> y;
        G[x-1].push_back(y-1);
        G[y-1].push_back(x-1);
    }
    
    rep(i, N) rep(j, 2) memo[i][j] = -1;
    
    cout << (dfs(0, -1, 0)+dfs(0, -1, 1))%MOD << endl;
}

Measured memory_bytes: 15616
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main() {
	int n, x[100], y[100], d[100];
	double D1, D2, D3, Di;
	D1 = 0;
	D2 = 0;
	D3 = 0;
	Di = 0;

	cin >> n;
	for (int i = 0;i < n;i++)
		cin >> x[i];
	for (int i = 0;i < n;i++) {
		cin >> y[i];
		d[i] = x[i] - y[i];
		if (d[i] < 0)
			d[i] = -1 * d[i];
		D1 += d[i];
		D2 += d[i] * d[i];
		D3 += d[i] * d[i] * d[i];
		if (Di < d[i])
			Di = d[i];
	}
	D2 = sqrt(D2);
	D3 = pow(D3, 1.0/3.0);

	printf("%f\n%f\n%f\n%f\n", D1, D2, D3, Di);

	return 0;
}

Measured memory_bytes: 1224
N = int(input())
num_lis = list(map(int, input().split()))
ans = 0
p = 10**9+7
s = sum(num_lis)
num = 0
for i in range(N):
  num += num_lis[i]
  ans += ((s-num)*num_lis[i])%p
  
print(ans%p)

Measured memory_bytes: 105360
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
int a[100000];

void init()
{
}

void solve()
{
    map<int, int> m;
    int n = 0;
    REP(i, N){
        if(m.find(a[i]) == m.end()) m[a[i]] = 1;
        else m[a[i]]++;
    }
    REP(i, 100000){
        int num = 0;
        if(m.find(i-1) != m.end()) num += m[i-1];
        if(m.find(i) != m.end()) num += m[i];
        if(m.find(i+1) != m.end()) num += m[i+1];
        n = max(n, num);
    }
    cout << n << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 3584
N, A = gets.split.map(&:to_i)
Xs = [nil] + gets.split.map(&:to_i)

XM = (Xs.compact + [A]).max
SM = XM * N
@dp = Array.new(N + 1){Array.new(N + 1){Array.new(SM + 1, 0)}}
@dp[0][0][0] = 1
(1 .. N).each do |i|
  (0 .. i).each do |j|
    (0 .. SM).each do |k|
      @dp[i][j][k] = @dp[i - 1][j][k] + ((j >= 1 && k >= Xs[i]) ? @dp[i - 1][j - 1][k - Xs[i]] : 0)
    end
  end
end
puts (1 .. N).inject(0){|s, j| s + @dp[N][j][j*A]}


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

int p[222222], q[111111], r[111111];
int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for(int i = 0; i < a; i++)
        cin >> p[i];
    for(int i = 0; i < b; i++)
        cin >> q[i];
    for(int i = 0; i < c; i++)
        cin >> r[i];
    nth_element(p, p + x, p + a, greater<>());
    nth_element(q, q + y, q + b, greater<>());
    copy(q, q + y, p + x);
    sort(p, p + x + y);
    sort(r, r + c, greater<>());
    long s = 0;
    for(int i = 0; i < x + y; i++)
        s += max(p[i], i < c ? r[i] : 0);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var N = scan.NextInt();
        var T = scan.ArrayInt(N);
        var M = scan.NextInt();
        var sb = new StringBuilder();
        var sum = T.Sum();
        for (int i = 0; i < M; i++) {
            var p = scan.NextInt() - 1;
            var x = scan.NextInt();
            sb.Append(sum - T[p] + x).AppendLine();
        }
        return sb.ToString();
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}

Measured memory_bytes: 27876
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int n;
vector<vector<int>> g;
vector<vector<ll>> dp;
vector<int> flag;

void f(int x){
	if(flag[x]>0) return;
	flag[x]=1;
	dp[x][0]=1;
	dp[x][1]=1;
	for(int i = 0; i < g[x].size(); i++){
		int y = g[x][i];
		if(flag[y]<0){
			f(y);
			dp[x][0]*=(dp[y][0]+dp[y][1]);
			dp[x][0]%=mod;
			dp[x][1]*=dp[y][0];
			dp[x][1]%=mod;
		}
	}
}


int main()
{
	cin>>n;
	g.resize(n,vector<int>());
	dp.resize(n,vector<ll>(2,0));
	for(int i = 0; i < n-1; i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	flag.resize(n,-1);

	f(0);
	cout << (dp[0][0]+dp[0][1])%mod<<endl;

	return 0;
}

Measured memory_bytes: 15744
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

ll n,x,d;

map<ll,ll>frr;
map<ll,ll>last;

int getidx(ll lo){
	if(d == 0)return 0;
	if(lo < 0){
		ll mul = abs(lo / d);
		lo += (mul + 5) * d;
	}
	return lo % d;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>n>>x>>d;
    
    if(d < 0){
    	x += d * (n-1);
    	d = -d;
	}
	
	ll lo = x, hi = x + (n-1) * d;
	ll ans = 0;
	int add0 = 1;
	REP(i,1,n){
		ll xlo = lo, xhi = hi;
		int idx = getidx(lo);
		if(last.count(idx) != 0){
			xlo = max(xlo, last[idx]);
			xhi = min(xhi, frr[idx]);
		}
		xlo = max(xlo, xhi + max(1LL, d));
		if(xlo <= hi)ans += (hi - xlo) / max(1LL, d) + 1; // right
		if(lo <= xhi)ans += (xhi - lo) / max(1LL, d) + 1; // left
		if(idx == 0 && xlo <= 0 && hi >= 0)add0 = 0;
		if(idx == 0 && lo <= 0 && xhi >= 0)add0 = 0;
		
		last[idx] = hi + max(1LL, d);
		frr[idx] = lo - max(1LL, d);
		
		lo += x + i * d;
		hi += x + (n-i-1) * d;
	}
	
	cout << ans + add0 << endl;
    
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N)cin >> A[i];
    ll sum = 0;
    ll ma = A[0];
    REP(i,N){
        ma = max(ma,A[i]);
        sum += ma - A[i];
    }
    cout << sum << "\n";
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std ;
int main(){
    string S;
    cin >> S;
    int Ans =1;
    for(int i=0;i<S.size()-1;i++)if(S[i]==S[i+1])Ans =0;
    if(Ans == 1)cout << "Good" << endl;
    else cout << "Bad" << endl;
}

Measured memory_bytes: 3620
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long
  
using namespace std;
  
const int N = 1e7 + 7;
const int mod = 1e9 + 7;

int32_t main() {
    speed;
    int a, b, n;
    cin >> a >> b >> n;
    int mx = (a*n)/b - a * (n/b);
    for ( int x = 1; x <= min( 10000000ll, n ); x++ ) {
    	mx = max( mx, (a*x) / b - a * (x/b) );
    }
    for ( int x = n; x >= max( 1ll, n - 10000000ll ); x-- ) {
    	mx = max( mx, (a*x) / b - a * (x/b) );
    }
   	int cnt = 0;
    for ( int x = 10000001; x <= n; x += 1000 ) {
    	mx = max( mx, (a*x) / b - a * (x/b) );
    	cnt++;
    	if ( cnt >= N ) {
    		break;
    	}
    }
    cnt = 0;
    for ( int x = max( 1ll, n - N ); x >= 1; x -= 1000 ) {
    	mx = max( mx, (a*x) / b - a * (x/b) );
    	cnt++;
    	if ( cnt > N ) {
    		break;
    	}
    }
    for ( int x = 10000001; x <= n; x += 100000 ) {
    	mx = max( mx, (a*x) / b - a * (x/b) );
    }
    cout << mx;
}


Measured memory_bytes: 3648
package main

import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  var d, x int
  fmt.Scan(&d, &x)
  a := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a[i])
  }
  cnt := 0
  for _, v := range a {
    day := 1
    for day <= d {
      cnt = cnt + 1
      day = day + v
    }
  }

  fmt.Println(cnt + x)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

#define MAX_N 100010

int uf_par[MAX_N];  //親
int uf_rank[MAX_N]; //木の深さ
int uf_num[MAX_N];  //同じ集合の要素数

//初期化、深さ0のn個の親を作る
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        uf_par[i] = i;
        uf_rank[i] = 0;
        uf_num[i] = 1;
    }
}

//木の根を求める find
int find(int x)
{
    if (uf_par[x] == x) //親が自分なら根
        return x;
    else //自分の親の親を探しに行く
        return uf_par[x] = find(uf_par[x]);
}

//xとyの集合を併合　union
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) //根が同じなら、すでに同一グループ
        return;

    if (uf_rank[x] < uf_rank[y]) //深いほうの根を使う
    {
        uf_par[x] = y;
        uf_num[y] += uf_num[x];
        uf_num[x] = -1;
    }
    else
    {
        uf_par[y] = x;
        uf_num[x] += uf_num[y];
        uf_num[y] = -1;
        if (uf_rank[x] == uf_rank[y]) //深さが同じなら、併合後に1深くなる
            uf_rank[x]++;
    }
}

//xとyが同じ集合かどうか
bool same(int x, int y)
{
    return find(x) == find(y);
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N, M, K;
    cin >> N >> M >> K;

    init(N);
    vi fri;
    fri.resize(N);

    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        unite(a - 1, b - 1);
        fri[a - 1]++;
        fri[b - 1]++;
    }

    vector<vector<int>> vs;
    vs.resize(N);
    REP(i, K)
    {
        int a, b;
        cin >> a >> b;
        vs[a - 1].push_back(b - 1);
        vs[b - 1].push_back(a - 1);
    }

    REP(i, N)
    {
        int kouho = uf_num[find(i)] - 1;
        kouho -= fri[i];
        REP(j, vs[i].size())
        {
            if (same(i, vs[i][j]))
                kouho--;
        }
        cout << kouho;
        if (i == N - 1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 9856
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int t, mini = 10, ans = 0;
	for (int i = 0; i < 5; i++) {
		scanf("%d", &t);
		ans += (((t + 9) / 10) * 10);
		if (t % 10)
			mini = min(mini, (t % 10));
	}
	ans -= (10 - mini);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<int> x_list(N, 0);
	vector<int> o_list(N, 0);

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

	sort(x_list.begin(), x_list.end());

	for (int i = 0; i < N; i++)
	{
		if (o_list[i] <= x_list[N / 2 - 1])
			cout << x_list[N / 2] << "\n";
		else
			cout << x_list[N / 2 - 1] << "\n";
	}

	return 0;
}


Measured memory_bytes: 3840
#abc 166
#d
x = int(input())
n =0
for i in range(-119,120):
    for j in range(-119,120):
        if i**5-j**5 == x:
            print(str(i)+' '+str(j))
            n += 1
            break
        else:
            continue
    if  n !=  0:
        break
        

Measured memory_bytes: 9176
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main(){
int N;
cin>>N;
int a=0,b=0,c=0;
int A,B;
cin>>A>>B;
rep(i,N){
int P;
cin>>P;
if(P<=A){
    a++;

}
else if(P<=B){
    b++;
}
else{
    c++;
}
}
int ans=a;
ans=min(ans,b);
ans=min(ans,c);
cout<<ans<<endl;



return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}


int n,m;
unordered_map<int,vec> mp;
int dp[N];

int dfs(int u) {
    int cnt = 0;
    for(auto it : mp[u] ) {
        if(dp[u] == 0) {
            cnt = max(cnt, dfs(it));
        } else {
            cnt = max(cnt, dp[it]);
        }
    }

    dp[u] = cnt+1;
    return cnt+1;
}



void test_case() {

    cin>>n>>m;
    rep(i,m) {
        int a , b;
        cin>>a>>b;

        mp[a].pb(b);
    }

    for(int i=1; i<=n; i++) {
        if(dp[i] == 0) {
            dfs(i);
        }
    }
    int ans = 1;
    for(int i=1; i<=n; i++) {
       // cout<<dp[i]<<" ";
        ans = max(ans, dp[i]-1);
    }

    cout<<ans<<endl;





}


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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    //cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 14908