akhauriyash/Code-Regression huggingface dataset:
import itertools

N, K = map(int, input().split())
d_list = []
A_list = []
for _ in range(K):
    d_list.append([int(input())])
    A_list.append([int(i) for i in input().split()])

p_set = set([j for j in range(1, N+1)])

A_set = set(list(itertools.chain.from_iterable(A_list)))

print(len(list(p_set-A_set)))

Measured memory_bytes: 9256
s = input()
L = len(s)
MOD = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(L + 1)]
dp[0][0] = 1

for i in range(1, L + 1):
    if s[i - 1] == "?":
        for j in range(10):
            for k in range(13):
                dp[i][(k * 10 + j) % 13] += dp[i - 1][k] % MOD
    else:
        for k in range(13):
            dp[i][(k * 10 + int(s[i - 1])) % 13] += dp[i - 1][k] % MOD

print(dp[-1][5] % MOD)


Measured memory_bytes: 66012
/*package whatever //do not write package name here */

import java.io.*;

import java.util.*;
public class Main{
	public static void main (String[] args) {
	Scanner s=new Scanner(System.in);
	int a=s.nextInt();
	int b=s.nextInt();
	int c=s.nextInt();
	System.out.println(c+" "+a+" "+b);
	}
}

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

vector<ll> num;
int n,k;

ll calc(int a,int b){
  if(a+b>n || a+b>k) return 0;
  int c=k-a-b;
  priority_queue<ll> pq;
  for(int i=0;i<a;i++){
    pq.push(num[i]);
  }
  for(int i=n-1;i>n-1-b;i--){
    pq.push(num[i]);
  }
  for(int i=0;i<c && !pq.empty();i++){
    if(pq.top()<0) break;
    pq.pop();
  }ll sum=0;
  while(!pq.empty()){
    sum+=pq.top(); pq.pop();
  }
  return sum;
}

int main(){
  cin>>n>>k;
  num.resize(n,-1);
  for(int i=0;i<n;i++){
    ll v; cin>>v;
    num[i]*=v;
  }
  ll ans=0;
  for(int i=0;i<=50;i++){
    for(int j=0;j<=50;j++){
      ans=min(ans,calc(i,j));
    }
  }
  cout<<-ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        sc.close();
        if(N==K)
            System.out.println(1);
        else{
            if((N-1)%(K-1) == 0)
                System.out.println((N-1)/(K-1));
            else
                System.out.println((N-1)/(K-1) + 1);
        }
    }

    static int min_index(int[] a){
        int index = 0;
        int min = a[0];
        for(int i = 0; i < a.length; i++){
            if(a[i] < min){
                min = a[i];
                index = i;
            }
        }
        return index;
    }
}

Measured memory_bytes: 52180
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define open freopen(input.txt,"r",stdin); freopen(output.txt,"w",stdout);
#define precise(t) cout << fixed << setprecision(t)
#define forr(i,n) for(int i(0);i<n;++i)
#define repup(i,a,b) for(int i(a); i <=b; ++i)
#define repdown(i,a,b) for(int i(a);i>=b;i--)
#define testcase(t) int t; cin >> t; wl(t)
#define input(n) int n; cin >> n;
#define sz(a) int((a).size())
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define bb begin()
#define ee end()
#define all(c) c.bb, c.ee
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;

const int inf = INT_MAX; 
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;

/*
int main(){
	char arr[4];
	forr(i,4) {cin >> arr[i];}
	sort(arr,arr+4);
	if(arr[0]==arr[1] && arr[2]==arr[3]){
		cout << "Yes";
	}
	else{
		cout << "No";
	}

}*/

int main(){
	int n,ans=0;
	cin >> n;
	int arr[n];
	forr(i,n) cin >> arr[i];
	for(int i(1);i<n-1;++i){
		if((arr[i]<arr[i+1] && arr[i]>arr[i-1]) || (arr[i]>arr[i+1] && arr[i]<arr[i-1])){
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddx[4] = {1,0,-1,0};
const int ddy[4] = {0,1,0,-1};
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}

int main(){
	//in_o();
	int n;
	cin>>n;
	int a[n];
	int min_not_mul=110;
	int sum=0;
	FOR(i,0,n){
		cin>>a[i];
		sum+=a[i];
		if(a[i]%10)
			min_not_mul=min(min_not_mul,a[i]);
	}
	if(sum%10)
		cout<<sum<<endl;
	else
		if(min_not_mul%10)
			cout<<sum-min_not_mul<<endl;
		else
			cout<<0<<endl;
	return 0;
}

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

struct process {
  string name ;
  int time ;
} ;

queue<process> x ;

void solve( int n, int q ) {
  int sum = 0 ;
  while(!x.empty()){
    process p ;
    p = x.front() ;
    x.pop() ;
    if ( p.time > q ) {
      p.time -= q ;
      sum += q ;
      x.push(p) ;
    }else{
      sum += p.time ;
      cout << p.name << " " << sum << endl ;
    }
  }
}

int main()
{
  int n, q ;
  cin >> n >> q ;

  for (int i = 0; i < n; i++) {
    process p ;
    cin >> p.name >> p.time ;
    // cout << p.name << " " << p.time << endl ;
    x.push(p) ;
  }

  solve(n,q) ;

  return 0 ;
}


Measured memory_bytes: 6184
#include<stdio.h>
#include<algorithm>
using namespace std;
struct team{
	int id,univ,solved,pen;
};
team dat[300];
int u[1001];
inline bool operator<(const team&a,const team&b){
	if(a.solved!=b.solved)return a.solved>b.solved;
	if(a.pen!=b.pen)return a.pen<b.pen;
	return a.id<b.id;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<=1000;i++)u[i]=0;
		for(int i=0;i<a;i++){
			scanf("%d%d%d%d",&dat[i].id,&dat[i].univ,&dat[i].solved,&dat[i].pen);
		}
		std::sort(dat,dat+a);
		int now=0;
		for(int i=0;i<a;i++){
			if(now==26)break;
			if((now<10&&u[dat[i].univ]<3)||(now<20&&u[dat[i].univ]<2)||(u[dat[i].univ]==0)){
				now++;
				printf("%d\n",dat[i].id);
				u[dat[i].univ]++;
			}
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    int n,i,k=2;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    int a[k],m=0,x,l,min;
    for(i=0;i<k;i++){a[i]=0;}
    for(i=n-2;i>=0;i--)
    {
        if(m<k){m++;}
        for(l=0;l<m;l++)
        {
            x=abs(arr[i]-arr[i+1+l])+a[l];
            if(l==0){min=x;}
            else{if(min>x){min=x;} a[l]=a[l-1];}
        }
        a[0]=min;
    }
    cout<<a[0];
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int s; cin >> s;
  int max = 1000000;

  vector<int> term;
  term.push_back(s);
  int ans;
  bool flag = false;
  for(int i = 1;i<=max;i++){
    int tmp = term[i-1];
    if(tmp%2==0) tmp = tmp/2;
    else tmp = 3*tmp+1;
    rep(j,term.size()) if(tmp==term[j]){
      ans = i+1;
      flag = true;
    }    
    term.push_back(tmp);
    if(flag) break;
  }

  cout << ans << endl;
  
  return 0;
}


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

namespace abc117_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = (Console.ReadLine().Split().Select(x => int.Parse(x))).ToList();
            var N = NM[0];
            var M = NM[1];

            var X = (Console.ReadLine().Split().Select(x => int.Parse(x))).ToList();
            X.Sort();
            var xs = new List<int>();
            var rmd = new Dictionary<int, List<int>>();

            // 差のリスト
            for (int i = 0; i < X.Count - 1; i++)
            {
                var sub = Math.Abs(X[i] - X[i + 1]);
                xs.Add(sub);
                if (!rmd.ContainsKey(sub)) rmd.Add(sub, new List<int>());
                rmd[sub].Add(i);
            }

            if (M == 1 || N >= M)
                // 地点1個または石が地点以上にある
                Console.WriteLine(0);
            else if (N == 1)
                // 石1個
                Console.WriteLine(Math.Abs(X.Last() - X.First()));
            else
            {
                var xsm = xs.OrderBy(x => x).ToList();
                var bun = new List<int>();

                // 差が大きいところで分割
                for (int i = 0; i < N - 1; i++)
                {
                    var im = xsm[xsm.Count() - i - 1];
                    var im_idxs = rmd[im];
                    bun.Add(im_idxs[0]);
                    im_idxs.RemoveAt(0);
                }
                
                bun.Sort();

                int re = 0;
                // 区間毎に移動量を算出
                for (int i = 0; i < N; i++)
                {
                    int l = 0;
                    int r = 0;

                    if (i == 0)
                    {
                        l = 0;
                        r = bun[0];
                    }
                    else if (i == N - 1)
                    {
                        l = bun[i - 1] + 1;
                        r = X.Count() - 1;
                    }
                    else
                    {
                        l = bun[i - 1] + 1;
                        r = bun[i];
                    }

                    re += Math.Abs(X[l] - X[r]);
                }

                Console.WriteLine(re);

            }

        }
        
    }
}


Measured memory_bytes: 25696
M, D = input().split(" ")
M = int(M)
D = int(D)
count = 0
for j in range(1, M+1):
    for i in range(10, D+1):
        d2 = i // 10
        d1 = i - (d2 * 10)
        if(d1 >= 2 and d2 >= 2):
            if (d1 * d2 == j):
                count += 1
print(count)


Measured memory_bytes: 3060
import java.util.Scanner
object Main {
  def main(args:Array[String]) = {
  	val sc = new java.util.Scanner(System.in)
  	val n:Long = sc.nextLong 
  	val m:Long = sc.nextLong
    
	println((n*(n-1))/2 + (m*(m-1))/2)
  }
}

Measured memory_bytes: 25900
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  string ans="NG";
  for(int i=A;i<=B;i++){
    if(i%K==0) ans="OK";
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3624
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class v:
    def __init__(self, f):
        self.f = f
        self.v = None
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    N = int(input())
    A = read_list()
    D = {}
    for a in A:
        D[a] = D.setdefault(a, 0) + 1
    
    S = sum(i * (i - 1) for i in D.values()) // 2
    for k in range(N):
        print(S - (D[A[k]] - 1))


if __name__ == "__main__":
    main()

Measured memory_bytes: 25652
n, m = map(int, input().split())
wa = [0]*(10**5)
ac = [0]*(10**5)
WA = 0
for i in range(m):
    p, s = input().split()
    P = int(p)
    if ac[P] != 1:
        if s == "WA":
            wa[P] += 1
        else:
            ac[P] += 1
            WA += wa[P]
print(sum(ac), WA)

Measured memory_bytes: 51416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cerr<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

int main(){
    int x,y,z,k;cin >> x >> y >> z >> k;
    vl a(x), b(y), c(z);
    rep(i,x) cin >> a[i];
    rep(i,y) cin >> b[i];
    rep(i,z) cin >> c[i];
    vl d;
    rep(i,x){
        rep(j,y){
            d.emplace_back(a[i] + b[j]);
        }
    }
    sort(d.begin(), d.end(), greater<ll>());
    while(d.size() > k){
        d.pop_back();
    }

    a.clear();
    rep(i,c.size()){
        rep(j,d.size()){
            a.push_back(c[i] + d[j]);
        }
    }
    sort(a.begin(), a.end(), greater<ll>());
    rep(i,k){
        cout << a[i] << "\n";
    }
}

Measured memory_bytes: 50088
def main():
    n = int(input())
    n_list = list(map(int, input().split()))

    previous = 0
    for i in range(n):
        if n_list[i] == previous + 1:
            previous += 1

    if previous == 0:
        print("-1")
    else:
        print(n - previous)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24744
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
ll a[50];
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
	 cin>>a[i];
	 if(i>=2){
		if((a[i-2]>a[i-1]&&a[i-1]>a[i])||(a[i-2]<a[i-1]&&a[i-1]<a[i])) ans++;
	 }
}
cout<<ans<<'\n';
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))

AB = [list(map(int, input().split())) for _ in range(M)]

check = [True] * N

for ab in AB:
    # 左みる
    if H[ab[0]-1] < H[ab[1] - 1]:
        check[ab[0]-1] = False
        
    elif H[ab[1]-1] < H[ab[0] - 1]:
        check[ab[1]-1] = False
    else:
        check[ab[0]-1] = False
        check[ab[1]-1] = False
    
print(sum(check))


Measured memory_bytes: 32012
n = int(input())

ans = n
for i in range(n+1):
    count = 0
    t = i
    while(t):
        count += t % 6
        t = int(t/6)
    t = n-i
    while(t):
        count += t % 9
        t = int(t/9)
    ans = min(ans, count)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>

using namespace std;
int main(){
    int n;
    cin>>n;
    int i,a,c=0;
    set<int> s;
    for(i=0;i<n;i++){
        cin>>a;
        if(a<=399&&s.count(1)==0){
            s.insert(1);
        }else if(a>=400&&a<=799&&s.count(2)==0){
            s.insert(2);
        }else if(a>=800&&a<=1199&&s.count(3)==0){
            s.insert(3);
        }else if(a>=1200&&a<=1599&&s.count(4)==0){
            s.insert(4);
        }else if(a>=1600&&a<=1999&&s.count(5)==0){
            s.insert(5);
        }else if(a>=2000&&a<=2399&&s.count(6)==0){
            s.insert(6);
        }else if(a>=2400&&a<=2799&&s.count(7)==0){
            s.insert(7);
        }else if(a>=2800&&a<=3199&&s.count(8)==0){
            s.insert(8);
        }else if(a>=3200){
            c++;
        }
    }
    
    if(s.size()==0){
        cout<<1<<' '<<c<<endl;
    }else{
        cout<<s.size()<<' '<<s.size()+c<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

int main(){
    ll N; cin >> N;
    vector<ll> a(N);
    REP(i,N) cin >> a[i];

    sort(a.begin(),a.end());
    // check
    if(N % 2 == 0){
        if(a[0] == 0){
            cout << 0 << endl;
            return 0;
        }
        for(int i = 0; i < N; i += 2){
            if(a[i] != a[i+1]){
                cout << 0 << endl;
                return 0;
            }
        }
     } else {
        if(a[0] != 0){
            cout << 0 << endl;
            return 0;
        }
        for(int i = 1; i < N; i += 2){
            if(a[i] != a[i+1]){
                cout << 0 << endl;
                return 0;
            }
        }
     }
    //
    ll ans = 1;
    REP(i,N/2){
        ans *= 2;
        if(ans > MOD) ans -= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;

int main(){
	string s;
	cin >> s;
	ll cnt_W = 0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='W') cnt_W++;
	}
	ll b_num=0;
	ll w_num=0;
	for(int i=0;i<s.size();i++){
		if(i<cnt_W){
			if(s[i]=='B') b_num+=i;
		}
		else
			if(s[i]=='W') w_num+=i;
	}
	cout << w_num-b_num << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
    string str;
    cin >> str;

    int cnt = 0;
    int max = -1;
    for(int i = 0; i < str.length(); i++){
        char ch = str[i];
        if(ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T'){
            cnt++;
        } else {
            if(max <= cnt){
                max = cnt;
            }
            cnt = 0;
        }
        if(i == str.length() - 1){
            if(max <= cnt){
                max = cnt;
            }
        }
    }
    
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np

raw = input()
rawl = raw.split()
A = int(rawl[0])
B = int(rawl[1])
H = int(rawl[2])
M = int(rawl[3])
theta = 2*np.pi*(H/12+M/720-M/60)
print((A*A+B*B-2*A*B*np.cos(theta))**(0.5))


Measured memory_bytes: 27244
#include<bits/stdc++.h>
using namespace std;
map<string ,int> mp;
map<string ,int> ::iterator it;
int main()
{
    int n,m;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]=mp[s]+1;
    }
    cin>>m;
    while(m--)
    {
        string s;
        cin>>s;
        mp[s]=mp[s]-1;
    }
    it=mp.begin();
    int max=0;
    for(it;it!=mp.end();++it)
    {
        if((it->second)>max)
            max=it->second;
    }
    cout<<max<<endl;


}


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

using namespace std;

int main(void){
    vector<int>list;
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
    
        int count = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) {
                        count++;
                    }
                }
            }
        }
        
        list.push_back(count);
    }
    
    for (auto count : list) {
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 3028
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int X=sc.nextInt();
		int[] m=new int[N];
		int ans=N;
		int min=0;

		for(int i=0;i<N;i++){
			m[i]=sc.nextInt();
			X-=m[i];
			if(i==0){
				min=m[i];
			}else{
				min=Math.min(min,m[i]);
			}
		}

		if(X==0){
			System.out.println(ans);
		}else{
			ans+=X/min;
			System.out.println(ans);
		}
		
	}
}

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

using namespace std;

int D, N, M;
vector<int> BranchStore;

int main() {
	int d, k;
	unsigned long long int sum;
	vector<int>::iterator pos;

	while (cin >> D, D) {
		cin >> N >> M;
		BranchStore.clear();
		BranchStore.push_back(0);
		BranchStore.push_back(D);
		for (int i = 1; i < N; ++i) {
			cin >> d;
			BranchStore.push_back(d);
		}
		sort(BranchStore.begin(), BranchStore.end());
		sum = 0;
		for (int i = 0; i < M; ++i) {
			cin >> k;
			pos = lower_bound(BranchStore.begin(), BranchStore.end(), k);
			sum += min(*pos - k, k - *(pos - 1));
		}
		cout << sum << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3532
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


int main(){
    
    ll N;
    cin >> N;
    for(ll i = 0; i <= N; i+=4){
        for(ll j = 0; j <= N; j += 7){
            if(i + j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)

int main(){
    long int n, k;
    cin >> n >> k;
    long int h[n];
    rep(i, n) cin >> h[i];
    sort(h, h + n, greater<long int>());
    long int ans = 0;
    for (long int i = k; i < n; i++){
        ans += h[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int num[]=new int[100000];
        long S=0;
        int index=0;
        for(int i=0; i<N; i++){
            index=sc.nextInt()-1;
            num[index]++;
            S+=(index+1);
        }
        int Q=sc.nextInt();
        int B[]= new int[Q];
        int C[]= new int[Q];
        long s[]= new long[Q+1];
        s[0]=S;
        for(int i=0; i<Q; i++){
            B[i]= sc.nextInt();
            C[i]= sc.nextInt();
            if(num[B[i]-1]>0){
                s[i+1]= s[i]-(long)(num[B[i]-1]*(B[i]-C[i]));
                num[C[i]-1]+=num[B[i]-1];
                num[B[i]-1]=0;
            }else{
                s[i+1]=s[i];
            }
        }
        for(int i=1; i<Q+1; i++){
            System.out.println(s[i]);
        }
    }
}


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

int Sumofdigits(int n){
  int sum=0;
  while (n>0){
    sum += n%10;
    n /=10;
  }
  return sum;
}
  
int main() {
  int N, min;
  cin >> N;
  min = 100000;
  
  for (int i=1; i<N; i++){
    int sum1 = Sumofdigits(i);
    int sum2 = Sumofdigits(N-i);
    int sum = sum1 + sum2;
    if (min > sum){
      min = sum;
    }
  }
   cout << min << endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <utility>
#include <queue>
#include <vector>
#include <array>
#include <stack>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define bs(n) (1ull<<(n))

int main() {
	ll n, a, b, x[100000];
	cin >> n >> a >> b;
	rep(i, n)cin >> x[i];
	ll s = 0;
	rep(i, n - 1) {
		ll sa = (x[i + 1] - x[i]) * a;
		s += min(sa, b);
	}
	cout << s << endl;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
l=[[int(x),1] for x in input().split()]
for i in range(m):
  b,c=map(int,input().split())
  l.append([c,b])

s = sorted(l, key=lambda x:x[0], reverse=True)

c=n
t=0
i=0
while c>0:
  n = s[i][1] if c>=s[i][1] else c
  t += s[i][0] * n
  c -= n
  i += 1

print(t)


Measured memory_bytes: 38520
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a <= b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

int main() {
	string s, t;
	cin >> s >> t;
	ll ls, lt;
	ls = s.size();
	lt = t.size();
	vector<int> cnt1(26, 0), cnt2(26, 0);
	REP(i, ls) {
		cnt1[s[i] - 'a']++;
	}
	REP(i, lt) {
		cnt2[t[i] - 'a']++;
	}
	//bool flag = true;
	REP(i, 26) {
		if ((cnt1[i] == 0) & (cnt2[i] > 0)) {
			put(-1);
			return 0;
		}
	}
	ll res = 0;
	ll temp = 0;
	vector<vector<int>> cn = calcNext(s);
	REP(i, lt) {
		temp = (ll)cn[temp][t[i] - 'a']+1;
		if (temp == ls+1) {
			res++;
			temp = 0;
			temp = (ll)cn[temp][t[i] - 'a'] + 1;
		}
	}
	put(res*ls+ temp);
	return 0;
}

Measured memory_bytes: 13696
h=int(input())
w=int(input())
n=int(input())
if h>=w:
    for i in range(1,w+1):
        ans=h*i
        if ans>=n:
            print(i)
            exit()
else:
    for i in range(1,h+1):
        ans=w*i
        if ans>=n:
            print(i)
            exit()

Measured memory_bytes: 3060
from collections import defaultdict
N,M = map(int,input().split(' '))

a = []
b = []
c = []
for i in range(1,M+1):
	a_,b_ = map(int,input().split(' '))
	a.append(a_)
	#b.append(b_)
	c_ = list(map(int,input().split(' ')))
	op = 0
	for t in c_:
		op += (1 << (t-1))
	c.append(op)

dic = defaultdict(lambda: sum(a)+1)
dic[0] = 0
for i in range(M):
	val = a[i]
	op = c[i]
	keys = list(dic.keys())
	for k in keys:
		dic[k | op] = min(dic[k|op] , dic[k] + val)

if dic[2**N-1] == sum(a)+1:
	print(-1)
else:
	print(dic[2**N-1])






Measured memory_bytes: 48088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll diff=abs(b-a);
	ll x=diff/2;
	if(diff%2==0)
	    cout<<x<<endl;
	else
	  {
	  	ll must=min({a-1,b-1,n-a,n-b});
	  	cout<<must+1+(diff-1)/2<<endl;
	  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int K, N;
  cin >> N >> K;
  vi p(N);
  REP(i, N) cin >> p.at(i);
  sort(p.begin(), p.end());
  int ans = 0;
  REP(i, K) ans += p.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

struct Sieve{
  int n;
  vector<int> f, primes;
  Sieve(int n = 1): n(n), f(n+1, 0){
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; i++){
      if(f[i]) continue;
      primes.emplace_back(i);
      f[i] = i;
      for(ll j = i*i; j <= n; j += i) if(!f[j]) f[j] = i;
    }
  }
  bool isPrime(const int x){ return f[x] == x; }
  vector<int> factorList(int x){
    vector<int> res;
    while(x != 1){
      res.emplace_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<pair<int, int>> factor(const int x){
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
    for(int p : fl){
      if(res.back().first == p) res.back().second++;
      else res.emplace_back(pair<int, int>(p, 1));
    }
    return res;
  }
};

int main(void){
  int n;
  cin >> n;
  Sieve sieve(n);
  map<ll, ll> mp;
  REP(i, n){
    auto f = sieve.factor(i+1);
    for(auto p : f){
      mp[p.first] += p.second;
    }
  }
  mint ans = 1;
  for(auto p : mp){
    ans *= p.second+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = map(int, readline().split())
    S = readline().strip()
    *LR, = map(lambda x: int(x) - 1, read().split())
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()


Measured memory_bytes: 24928
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int k = 0;
    std::cin >> k;

    int n = 0;
    std::cin >> n;

    std::vector<int> houses(n);
    for (auto& val : houses)
    {
        std::cin >> val;
    }

    int maxDist = k - houses.back() + houses.front();
    for (auto index = 0; index < houses.size() - 1; ++index)
    {
        auto dist = houses[index + 1] - houses[index];
        if (dist > maxDist)
        {
            maxDist = dist;
        }
    }
    std::cout << (k - maxDist);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(ll, N);
  if(N % 2) {
    fin(0);
  } else {
    N /= 2;
    ll res = 0;
    ll div = 5;
    while(N) {
      res += N / div;
      N /= div;
    }
    fin(res);
  }
}


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

int main()
{
	ll n, m, sum  = 0;
	cin >> n >> m;
	ll arr[n+34];
	for(int i = 0; i < n; i ++){
		cin >> arr[i];
	}
	for(int i = 1; i < n; i++){
		if((arr[i] + arr[i-1]) > m){
			ll d = (arr[i] + arr[i-1]) - m;
			sum  = sum + d;
			if(arr[i] >=d){
				arr[i] = arr[i] - d;
			}else{
				arr[i] = 0;
			}
		}
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <queue>
using namespace std;
int main(void){
	char n[5],t[5];
	cin>>n;
	t[0]=n[2];
	t[1]=n[1];
	t[2]=n[0];
	if(n[0]==t[0]&&n[1]==t[1]&&n[2]==t[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int dp[51][5];

void init() {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i <= 50; ++i) {
    for (int j = 1; j <= 4; ++j) {
      for (int t = 0; t < 10 && t <= i; ++t) {
        dp[i][j] += dp[i-t][j-1];
      }
    }
  }
}

int main() {
  //freopen("SumOf4Integers.in", "r", stdin);
  int n;
  init();
  while (scanf("%d", &n) == 1) {
    int result = dp[n][4];
    printf("%d\n", result);
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
/* -- template -- */

int main() {
    int N; cin >> N;
    while(N > 0){
        if(N % 10 == 7){
            cout << "Yes" << endl;
            return 0;
        }
        N /= 10;
    }
    cout << "No" << endl;
}
//python3 makeDirectoryABC 160


Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;


int main(){
    ll n; cin >> n;
    vl a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n+1){
        if(i>0){
            if(b[i-1] > 0){
                if(a[i] >= b[i-1]){
                    a[i] -= b[i-1];
                    ans += b[i-1];
                    b[i-1] = 0;
                }else{
                    ans += a[i];
                    b[i-1] -= a[i];
                    a[i] = 0;
                }
            }
        }
        if(i<n){
            if(a[i] >= b[i]){
                ans += b[i];
                a[i] -= b[i];
                b[i] = 0;
            }else{
                //cout << "A" << a[i] << endl;
                ans += a[i];
                b[i] -= a[i];
                a[i] = 0;
                //cout << b[i] << endl;
            }
        }
        //cout << ans << endl;
    }
    //rep(i,n) cout << a[i] << " " << b[i];
    //cout << a[n] << endl;
    cout << ans << endl;
}

Measured memory_bytes: 1792
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007ll
#define X    first
#define Y    second
using namespace std;
int n;
ll f[100];
vector<pair<ll,ll> >v[100];
set<pair<ll,ll> >s;
int main(){
    f[1]=1,f[2]=2;
    for(int i=3;i<=88;++i)f[i]=f[i-1]+f[i-2];
    v[1].pb(mp(1,2)),v[1].pb(mp(1,3));
    for(int i=1;i<86;++i){
        s.clear();
        for(int j=0;j<v[i].size();++j){
            ll x=v[i][j].X,y=v[i][j].Y;
            x+=y;
            while(x<=f[i+3]){
                if(s.count(mp(y,x))) continue;
                s.insert(mp(y,x));
                v[i+1].pb(mp(y,x));
                x+=y;
            }
        }
    }
    int q;
    ll x,y;
    scanf("%d",&q);
    while(q--){
        scanf("%lld%lld",&x,&y);
        if(x>y)swap(x,y);
        int k=1;
        for(int i=2;i<=86;++i)if(f[i]<=x&&f[i+1]<=y)k=i;
        printf("%d ",k);
        ll ans=0;
        if(k==1){
            if(x==1)printf("%lld\n",y%orz);
            else printf("4\n");
            continue;
        }
        for(int i=0;i<v[k-1].size();++i){
            ll xx=v[k-1][i].X,yy=v[k-1][i].Y;
            if(yy>x) continue;
            ans+=(y-xx)/yy;
            ans%=orz;
        }
        for(int i=0;i<v[k-1].size();++i){
            ll xx=v[k-1][i].X,yy=v[k-1][i].Y;
            if(yy>y) continue;
            ans+=(x-xx)/yy;
            ans%=orz;
        }
        printf("%lld\n",ans);
    }
    //system("pause");
    return 0;
}


Measured memory_bytes: 4096
import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static void bubbleSort(int[] A, int N)
  {
	  int swapNum = 0;
    StringBuilder sb = new StringBuilder(); 
    for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    }
    show(A,sb);
    System.out.println(Integer.toString(swapNum));
    
  }
  
  public static void show(int[] A,StringBuilder sb){
	    for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    }
	    System.out.println(sb.toString());
	    sb.setLength(0);
  }
}

Measured memory_bytes: 24456
#include<iostream>
using namespace std;
int main(void)
{
	int a,b,c,d,e,s=0,sa=0;
	cin>>a>>b>>c>>d>>e;
	if(a<0){
		a=a*-1;
		s=a*c;
		sa=b;
		s=s+d;
	}
	else sa=b-a;
	s=s+e*sa;
	cout<<s<<endl;
	return 0;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    int n;
    cin >> n;
    vector<int> c(n - 1);
    vector<int> s(n - 1);
    vector<int> f(n - 1);
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i] >> s[i] >> f[i];
    }
    vector<ll> ans(n, 0);
    for (int i = 0; i < n - 1; i++)
    {
        ll tmp = 0;
        for (int j = i; j < n - 1; j++)
        {
            if (tmp < s[j])
            {
                tmp = s[j];
                tmp += c[j];
            }
            else
            {
                if ((tmp - s[j]) % f[j] == 0)
                {
                    tmp += c[j];
                }
                else
                {
                    tmp = tmp + f[j] - (tmp - s[j]) % f[j] + c[j];
                }
            }
            // debug(tmp);
        }
        ans[i] = tmp;
    }
    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		if(D==25){
			System.out.print("Christmas");
		}else if(D==24){
			System.out.print("Christmas Eve");
		}else if(D==23){
			System.out.print("Christmas Eve Eve");
		}else if(D==22){
			System.out.print("Christmas Eve Eve Eve");
		}
	}	
}

Measured memory_bytes: 21716
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  string s;
  cin >> s;  
  ll ans = 0, tmp = 0;
  ans = s[0]-'1' + 9*(s.size()-1);

  REP(i, s.size()) tmp += s[i]-'0';

  ans = max(ans, tmp);
  
  cout << ans << endl;
    
  return 0;
}


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

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

    int eat = 101, pointer = 0;
    for ( int i = 0; i < N; i++ ) {
        if( eat >= abs(a[i]) ){
            eat = abs(a[i]);
            pointer = i;
        }
    }

    cout << sum - a[pointer] << endl;
}

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

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

const long long INF = 1LL << 60;

int main ()
{
    long long h,cnt=0,a=0;
    cin >> h;
    while(h/2!=0){
        h=h/2;
        cnt++;
    }
    for(int i=0;i<=cnt;i++){
        a+=pow(2,i);
    }
    cout << a << endl;
}


Measured memory_bytes: 256