akhauriyash/Code-Regression huggingface dataset:
N = int(input())
NN = input().split()
D = int(NN[0])
X = int(NN[1])
count = 0
list1 =[]
for i in range(N):
  a = int(input())
  list1.append(a)
for i in list1:
  x = 1
  while x <= D:
    count +=1
    x += i
print(count+X)

Measured memory_bytes: 9084
@N, @A, @B, @C = gets.strip.split.map(&:to_i)
@sticks = @N.times.map { gets.strip.to_i }

def chkmin(a, b) a < b ? a : b end

INF = 100000

def dfd(n, a, b, c)
  if n == @N
    if a > 0 && b > 0 && c > 0
      return (@A - a).abs + (@B - b).abs + (@C - c).abs
    else
      return INF
    end
  end

  res = dfd(n + 1, a, b, c)

  res = chkmin(res, dfd(n + 1, a + @sticks[n], b, c) + (a > 0 ? 10 : 0))
  res = chkmin(res, dfd(n + 1, a, b + @sticks[n], c) + (b > 0 ? 10 : 0))
  res = chkmin(res, dfd(n + 1, a, b, c + @sticks[n]) + (c > 0 ? 10 : 0))
 
  return res
end

puts dfd(0, 0, 0, 0)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int> 
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define mod 998244353
//#define int long long
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)

int max(int a, int b) { return (a > b)? a : b; } 
using namespace std;

// ll funct(int a[], int n, int s)
// {
//     sort(a,a+n);
//     int sum=0,c=0;
//     while(sum<=s){
//         c+=1;
//         sum+=s;
//     }
//     return c;
// }

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t=1,ca=1;
   //cin>>t;
   while(ca<=t)
   {
      ca+=1;
      int n,m;
      cin>>n>>m;
      cout<<(n*(n-1))/2+(m*(m-1))/2<<endl;
   }
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int>A(N+1),B(N);
  for(int i=0;i<N+1;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  int64_t sum=0;
  for(int i=0;i<N;i++){
    if(A[i]<=B[i]){
      sum+=A[i];
      int sp=B[i]-A[i];
      A[i]=0;
      if(A[i+1]<=sp){
        sum+=A[i+1];
        A[i+1]=0;
      }
      else{
        A[i+1]-=sp;
        sum+=sp;
      }
    }
    else{
      sum+=B[i];
      A[i]-=B[i];
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3952
while line = gets do
  h, w = line.split.map(&:to_i)
  if h == 0 && w == 0 then break end
  h.times do |i|
    w.times do |j|
      if (i + j + 4) % 2 == 0
        print "#"
      else
        print "."
      end
    end
    puts
  end
  puts
end

Measured memory_bytes: 8776
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  let [, s, , t] = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => +n));

  let cnt = 0;
  for (let num of t) {
    if (s.includes(num)) {
      cnt++;
    }
  }

  console.log(cnt);
});



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

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

const long long INF = 1LL << 60;

int main(){
  int l, r, d;
  cin >> l >> r >> d;

  cout << r/d - (l-1)/d << endl;

  return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        final Task task = new Task();
        task.solve();
    }
}

class Task {

    public void solve() {
        try(final Scanner scanner = new Scanner(System.in);) {
            final int ab = Integer.parseInt(scanner.next());
            final int bc = Integer.parseInt(scanner.next());

            System.out.println(ab * bc / 2);
        }
    }
}

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

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

sum_rain = sum(t)

ans=[]

for i in range(n):
    if i%2==1:
        sum_rain -= t[i]*2
ans.append(sum_rain)

for i in range(n-1):
    ans.append((t[i]-ans[-1]//2)*2)

print(*ans)

Measured memory_bytes: 69988
require 'bigdecimal'

N = gets.to_i
c = N.times.map { gets.chomp.split }

sum = BigDecimal('0.0')

N.times { |i|
  tanni = c[i][1]
  num = BigDecimal(c[i][0])

  jpy = BigDecimal('0.0')
  if tanni == 'JPY'
    jpy = num
  else
    jpy = (BigDecimal('380000.0') * num)
  end
  sum = sum + jpy
}
puts sum.to_s('F')

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
const int INF=100000000;


int main()
{
    int n,a,b;
    cin >> n;
    vector<int> x(n),y(n);
    for(int i=0;i<n;i++)cin >> x.at(i);
    y=x;
    sort(ALL(y));
    a=y[n/2];b=y[n/2-1];
    for(int i=0;i<n;i++){
        if(x[i]<=b){
            cout << a << endl;
        }else{
            cout << b << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// Receive number
    	Scanner sc = new Scanner(System.in);
    	int west = sc.nextInt();
    	int east = sc.nextInt();
    	double diff = east - west;

    	// calc
    	double ave = diff / 2;
    	int height = (int) (ave * (diff - 1));

    	// Display
    	System.out.print(height - west);
	}
}

Measured memory_bytes: 22868
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define pb push_back

const int MAX_N = 1000000;
int n;
bool sieve[MAX_N];
vector<int> pl;

void solve() {
  ll res = 0;
  for (int i = 0; i < n; i += 1) {
		//cout<<pl[i]<<endl;
		res += pl[i];
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  // set sieve
  memset(sieve, true, sizeof sieve);
  for(int i=4;i<MAX_N;i+=2) sieve[i] = false;
  pl.pb(2);

  for(int i=3;i<MAX_N;i+=2)
  if (sieve[i]) {
    pl.pb(i);
    for(int j=i+i;j<MAX_N;j+=i)
    if (sieve[j])
    sieve[j] = false;
  }
  
  // solve 
  while (cin>>n, n) {
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int m,f,b;
    cin>>m>>f>>b;
    if(b>m+f){
        cout<<"NA"<<endl;
    }
    else if(b>m){
        cout<<b-m<<endl;
    }
    else{
        cout<<0<<endl;
    }
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

multiset<int> tops;

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,tmp; cin>>n;
    FOR(i, 0, n) {
    	cin>>tmp;
		auto itr = tops.lower_bound(tmp);
		if(itr == tops.begin()) {
			tops.insert(tmp);
		} else {
			--itr;
			tops.erase(itr);
			tops.insert(tmp);
		}
    }
    cout<<tops.size();

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}


int main() {
  int N,M;
  cin>>N>>M;
  int s[10];
  int c[10];
  for(int i=0;i<M;i++){
    cin>>s[i]>>c[i];
  }
  for(int j=0;j<=999;j++){
   vector<int>d(1,j%10);
   int x=j/10;
   while(x>0){
     d.push_back(x%10);
     x/=10;
   }
   bool ok=true;
   reverse(d.begin(),d.end());

   if(d.size()!=N){continue;}

   for(int i=0;i<M;i++){
    if(d[s[i]-1]!=c[i]){ok=false;}
  }
  if(ok){cout<<j<<endl;return 0;}
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);
 
  /*for(o=1;o<=n;o++)
    {
      if(o == n){printf("%d\n",A[o]);}
      else printf("%d ",A[o]);
    }
  */
  for(j=1;j<=n;j++)
    {   
          key = A[j];       
          i = j-1;
          while(i>0 && A[i]>key)
        {
          A[i+1]=A[i];  
          i = i-1;
        }
          A[i+1] = key;
          for(k=1;k<=n;k++){
        if(k == n)printf("%d\n",A[k]);
        else printf("%d ",A[k]);
          }
    }
   
  return 0;
}


Measured memory_bytes: 1828
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var HW = Sarray();
            var H = HW[0];
            var W = HW[1];
            var ban = new string[H + 2];
            ban[0] = ban[H + 1] = new string('#', (int)W + 2);
            var siroMasu = 0L;
            for (var h = 1; h <= H; ++h)
            {
                ban[h] = "#" + ReadLine() + "#";
                siroMasu += ban[h].Count(b => b == '.');
            }
            var dh = new long[] { 0, -1, 1, 0 };
            var dw = new long[] { -1, 0, 0, 1 };

            var dst = Enumerable.Range(0, (int)H + 2).Select(_ => Enumerable.Repeat(-1L, (int)W + 2).ToArray()).ToArray();
            var q = new Queue<Tuple<long, long,long>>();//h,w,dst
            q.Enqueue(Tuple.Create(1L, 1L,0L));//h,w
            while(q.Any())
            {
                var p = q.Dequeue();
                var nowH = p.Item1;
                var nowW = p.Item2;
                var nowD = p.Item3;
                if (-1 != dst[nowH][nowW] || '#' == ban[nowH][(int)nowW]) continue;
                dst[nowH][nowW] = nowD;
                for (var i = 0; i < 4; ++i)
                    q.Enqueue(Tuple.Create(nowH + dh[i], nowW + dw[i], nowD + 1));
            }
            var ans = siroMasu - (dst[H][W] + 1);
            if (dst[H][W] == -1)
                ans = -1;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

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

int main() {
	int flag = 0;
	char S[3];
	for (int i = 0; i < 3; i++) cin >> S[i];

	if (S[0] == 'A') {
		for (int i = 0; i < 3; i++) {
			if (S[i] == 'B') flag = 1;
		}
	}

	if (S[0] == 'B') {
		for (int i = 0; i < 3; i++) {
			if (S[i] == 'A') flag = 1;
		}
	}

	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
def solve(s):
    if all(a == b for a, b in zip(s, s[1:])):
        return 1
    if len(s) == 2:
        return 2
    elif len(s) == 3:
        if s[0] == s[1] or s[1] == s[2]:
            return 6
        elif s[0] == s[2]:
            return 7
        else:
            return 3
    # dp[has succession][mod 3][last char]
    dp = [[[0] * 3 for _ in range(3)] for _ in range(2)]
    dp[0][0][0] = 1
    dp[0][1][1] = 1
    dp[0][2][2] = 1
    MOD = 998244353
    for _ in range(len(s) - 1):
        ndp = [[[0] * 3 for _ in range(3)] for _ in range(2)]
        dp0, dp1 = dp
        ndp0, ndp1 = ndp
        sdp10, sdp11, sdp12 = sum(dp1[0]), sum(dp1[1]), sum(dp1[2])
        ndp0[0][0] = (dp0[0][1] + dp0[0][2]) % MOD
        ndp0[1][0] = (dp0[1][1] + dp0[1][2]) % MOD
        ndp0[2][0] = (dp0[2][1] + dp0[2][2]) % MOD
        ndp0[0][1] = (dp0[2][0] + dp0[2][2]) % MOD
        ndp0[1][1] = (dp0[0][0] + dp0[0][2]) % MOD
        ndp0[2][1] = (dp0[1][0] + dp0[1][2]) % MOD
        ndp0[0][2] = (dp0[1][0] + dp0[1][1]) % MOD
        ndp0[1][2] = (dp0[2][0] + dp0[2][1]) % MOD
        ndp0[2][2] = (dp0[0][0] + dp0[0][1]) % MOD
        ndp1[0][0] = (dp0[0][0] + sdp10) % MOD
        ndp1[1][0] = (dp0[1][0] + sdp11) % MOD
        ndp1[2][0] = (dp0[2][0] + sdp12) % MOD
        ndp1[0][1] = (dp0[2][1] + sdp12) % MOD
        ndp1[1][1] = (dp0[0][1] + sdp10) % MOD
        ndp1[2][1] = (dp0[1][1] + sdp11) % MOD
        ndp1[0][2] = (dp0[1][2] + sdp11) % MOD
        ndp1[1][2] = (dp0[2][2] + sdp12) % MOD
        ndp1[2][2] = (dp0[0][2] + sdp10) % MOD
        dp = ndp
    return (sum(dp[1][sum(map(ord, s)) % 3]) + all(a != b for a, b in zip(s, s[1:]))) % MOD


s = input()
print(solve(s))


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

int sum(int N) {
	return N / 10000 + N % 10000 / 1000 + N % 1000 / 100 + N % 100 / 10 + N % 10;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	for (int i = 1;i <= N;++i) {
		if (A <= sum(i) && sum(i) <= B) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#define N 100005
#define K 200005
#define MOD 998244353
#define ll long long int
using namespace std;
 
int main() {
int n;
cin>>n;
vector<int> dp(3,0);
while(n--)
{
    vector<int> c(3);
    for(int i=0;i<3;i++)
    {
        cin>>c[i];
    }
    vector<int> newdp(3,0);
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(i!=j)
            newdp[j]=max(newdp[j],dp[i]+c[j]);
        }

    }
    dp=newdp;
}
int max2=max(dp[0],dp[1]);
cout<<max(max2,dp[2])<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll A, B;
    cin >> A >> B;
    cout << 6 - A - B << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	int x = 0, ma = 0;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == 'R') {
			x++;
		}
		else {
			ma = max(ma, x);
			x = 0;
		}
		if (i == 2) {
			ma = max(ma, x);
		}
	}
	cout << ma << endl;
}

Measured memory_bytes: 3596
A,B = map(int,input().split())

flag = True
num = 1
if A>B:

    while flag:
        temp = A * num
        if temp % B == 0:
            break
        num += 1

else:
    while flag:
        temp = B * num
        if temp % A == 0:
            break
        num += 1

print(temp)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb(a) push_back(a)
#define ms(x,y) memset(x,y,sizeof(x))
#define sci(a) scanf("%d",&a) 
#define scl(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a) 
#define ll long long 
using namespace std;
/* --------------- fast io --------------- */ // begin
namespace Fread{
const int SIZE=1<<20;
char buf[SIZE],*S,*T;
inline char getchar(){
	if(S==T){
		T=(S=buf)+fread(buf,1,SIZE,stdin);
		if(S==T)return EOF;
	}
	return *S++;
}
}//namespace Fread
namespace Fwrite{
const int SIZE=1<<20;
char buf[SIZE],*S=buf,*T=buf+SIZE;
inline void flush(){
	fwrite(buf,1,S-buf,stdout);
	S=buf;
}
inline void putchar(char c){
	*S++=c;
	if(S==T)flush();
}
struct _{
	~_(){flush();}
}__;
}//namespace Fwrite

#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
	#define putchar Fwrite::putchar
#endif

template<typename T>inline void read(T& x){
	x=0;int f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+(c-'0'),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x,bool _enter=0,bool _space=0){
	if (!x)putchar('0');else{
		if(x<0)putchar('-'),x=-x;
		static char dig[41];
		int top=0;
		while(x)dig[++top]=(x%10)+'0',x/=10;
		while(top)putchar(dig[top--]);
	}
	if(_enter)putchar('\n');
	if(_space)putchar(' ');
}

namespace Fastio{
struct reader{
	template<typename T>reader& operator>>(T& x){::read(x);return *this;}
	reader& operator>>(char& c){
		c=getchar();
		while(c=='\n'||c==' ')c=getchar();
		return *this;
	}
	reader& operator>>(char* str){
		int len=0;
		char c=getchar();
		while(c=='\n'||c==' ')c=getchar();
		while(c!='\n'&&c!=' ')str[len++]=c,c=getchar();
		str[len]='\0';
		return *this;
	}
}cin;
const char endl='\n';
struct writer{
	template<typename T>writer& operator<<(T x){::write(x,0,0);return *this;}
	writer& operator<<(char c){putchar(c);return *this;}
	writer& operator<<(const char* str){
		int cur=0;
		while(str[cur])putchar(str[cur++]);
		return *this;
	}
}cout;
}//namespace Fastio
//#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
/* --------------- fast io --------------- */ // end

const int maxn=100005;
int main(){
		//#define int ll
	string s1,s2;
	while(cin>>s1>>s2){
		int n1=s1.length(),n2=s2.length();
		int ans=n2;
		for(int i=0;i<=n1-n2;++i){
			int t=0;
			for(int j=0;j<n2;++j)
				if(s1[i+j]!=s2[j])
					t++;
				ans=min(ans,t);
		}
			
		cout<<ans<<endl;
	 }
	return 0;
} 

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<int64> a(N), b(N);
  cin >> a >> b;
  int64 addone = 0;
  int64 addtwo = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == b[i]) continue;
    if (a[i] > b[i]) {
      addone += a[i] - b[i];
    } else {
      if ((b[i] - a[i]) % 2 == 0) {
        addtwo += (b[i] - a[i]) / 2;
      } else {
        addone++;
        addtwo += (b[i] + 1 - a[i]) / 2;
      }
    }
  }
  debug(addone, addtwo);
  if (addone > addtwo) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

int main(void){
  string a, b;
  while(cin >> a >> b && a != "0" && b != "0"){
    int hit = 0, blow = 0;
    for(int i = 0; i < 4; i++){
      if(a[i] == b[i]) hit++;
      for(int j = 0; j < 4; j++){
        if(i != j && a[i] == b[j]) blow++;
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
n, k = map(int, input().split())
c = 0
A = []
for i in range(n):
    A.append(list(map(int, input().split())))
A = sorted(A)
for i in A:
    if c + i[1] >= k:
        print(i[0])
        exit()
    else:
        c += i[1]

Measured memory_bytes: 28640
h, n = gets.strip.split.map(&:to_i)

a = gets.chomp.split
n.times do |i|
  a[i] = a[i].to_i
end

result = false
n.times do |i|
  h -= a[i]
  if h <= 0
    result = true
    break
  end
end

puts result ? "Yes" : "No"

Measured memory_bytes: 7940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ss(n);
    rep(i,n) ss[i]=s[i]-'0';
    ll ans = 0;
    rep(bit,1<<(n-1)){
        ll res = 0;
        ll now = ss[0];
        rep(i,n-1){
            if(bit>>i&1){
                res += now;
                now = ss[i+1];
            }else{
                now = 10*now+ss[i+1];
            }
        }
        res+=now;
        ans+=res;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3736
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
zu = 0
ans = []
for i in A:
    num[i-1]+=1
for i in range(N):
    temp = 1/2*num[i]*(num[i]-1)
    zu += temp
for i in A:
    kawari =zu
    temp1 = 1/2*num[i-1]*(num[i-1]-1)
    num[i-1] -= 1
    temp2 = 1/2*num[i-1]*(num[i-1]-1)
    kawari += -temp1+temp2
    num[i-1] += 1
    print(int(kawari))



Measured memory_bytes: 86864
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x, k, d := abs(iScan()), iScan(), iScan()
	p := x / d
	if p >= k {
		fmt.Println(x - k*d)
	} else {
		x = x - p*d
		k -= p
		if k%2 == 0 {
			fmt.Println(x)
		} else {
			fmt.Println(abs(x - d))
		}
	}
}


Measured memory_bytes: 1772
K = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K - 1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
 
using namespace std;
 
constexpr long long INF64 = 1e18;
 
using Weight=long long;

using Array=vector<Weight>;
using Matrix=vector<Array>;

struct flow{
    int n;
    Matrix g;
    vector<int> itr,level;

    flow(int n):n(n){g.assign(n,Array(n,0));}

    void add_edge(int from,int to,int cap){
        g[from][to]+=cap;
    }

    void bfs(int s){
        level.assign(n,-1);
        queue<int>q;
        level[s]=0;
        q.push(s);
        while(!q.empty()){
            int u=q.front();q.pop();
            for(int v=0;v<n;++v){
                if(g[u][v]>0 && level[v]<0){
                    level[v]=level[u]+1;
                    q.push(v);
                }
            }
        }
    }

    Weight dfs(int u,int t,Weight f){
        if(u==t)return f;
        for(int &i=itr[u];i<n;++i){
            if(g[u][i]>0 && level[u]<level[i]){
                Weight d=dfs(i,t,min(f,g[u][i]));
                if(d>0){
                    g[u][i]-=d;
                    g[i][u]+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    Weight run(int s,int t){
        Weight ret=0,f;
        while(bfs(s),level[t]>=0){
            itr.assign(n,0);
            while((f=dfs(s,t,INF64))>0)ret+=f;
        }
        return ret;
    }
};
 
int main(){
    int n,m;
    cin>>n>>m;
    flow g(n);
    for(int i=0;i<m;++i){
        int u,v;
        Weight c;
        cin>>u>>v>>c;
        g.add_edge(u,v,c);
    }
    cout<<g.run(0,n-1)<<endl;
}

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

MOD =  1000000007

def f(N, A):
    c0 = 0
    c1 = 1

    for i in range(1, N+1):
        c0, c1 = c1, (c0+c1)%MOD

        if i in A:
            c1 = 0

    return c1
            


def main():
    N,M = map(int, input().split())
    A = set(int(input()) for i in range(M))
    print(f(N, A))


if __name__ == '__main__':
    main()


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

using namespace std;
const int MAXN=2005;
struct edge{int to,nxt;}e[MAXN<<2];
int n,k,x,y,head[MAXN],dist[MAXN],tot=0,tmp=0,res=0,S=0;

void add_edge(int from,int to)
{
	e[++tot].nxt=head[from];e[tot].to=to;head[from]=tot;
	e[++tot].nxt=head[to];e[tot].to=from;head[to]=tot;
}

int dfs(int x,int anc,int lmt)
{
	int ret=1;if(x==S) dist[x]=0;
	for(int i=head[x];i;i=e[i].nxt)
	{
		if(e[i].to==anc) continue;
		dist[e[i].to]=dist[x]+1;
		if(dist[e[i].to]<=lmt) ret+=dfs(e[i].to,x,lmt);
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
		scanf("%d%d",&x,&y),add_edge(x,y);
		
	for(int i=1;i<=n;i++)
		res=max(res,dfs((S=i),0,k/2));
	if(!(k&1)) return printf("%d",n-res),0;
	
	for(int i=1;i<=n;i++)
		for(int j=head[i];j;j=e[j].nxt)
			res=max(res,dfs((S=i),e[j].to,(k-1)>>1)+dfs((S=e[j].to),i,(k-1)>>1));
	printf("%d",n-res);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<queue>
#include<vector>
#include<list>
#include<stack>
using namespace std;
typedef long long ll;

int a[100];

int main()
{
	int n,i,j;
	cin >> n;
	for (i = 0; i < n; i ++)
		scanf ("%d",&a[i]);
	int cnt = 0;
	for (i = 1; i < n; i ++)
		if (a[i] < a[i - 1])
			cnt ++;
	if (cnt == 0)
	{
		cout << "YES";
		return 0;
	}
	for (i = 0; i < n; i ++)
	{
		for (j = 0; j < n; j ++)
		{
			bool f = 0;
			swap(a[i],a[j]);
			for (int p = 0; p < n; p ++)
			{
				if (a[p] < a[p - 1])
				{
					f = 1;
					break;
				}
			}
			if (f == 0)
			{
				cout << "YES" << endl;
				return 0;
			}
			swap(a[i],a[j]);
		}
	}
	cout << "NO";
	return 0;
}

Measured memory_bytes: 256
import math

def s(number):
    if number <= 2:
        return 0
    for i in range(2,math.floor(math.sqrt(number))+1):
        if number % i == 0:
            return 0
    for i in range(2,math.floor(math.sqrt((number+1)//2))+1):
        if ((number+1)//2) % i == 0:
            return 0
    return 1

num = [s(i) for i in range(1,10 ** 5+1)]
li = [0]
for nu in num:
    li.append(li[-1]+nu)

q = int(input())

for _ in range(q):
    l,r = map(int,input().split())
    print(li[r]-li[l-1])

Measured memory_bytes: 7320
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;


void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	sort(all(A));
	ll ans = 0;
	REP(i, N - 2) {
		FOR(j, i + 1, N - 1) {
			FOR(k, j + 1, N) {
				if (A[i] + A[j] <= A[k])continue;
				if (A[i] < A[j] + A[k] && A[j] < A[i] + A[k] && A[k] < A[i] + A[j])ans++;
			}
		}
	}
	print(ans);
}


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

	solve();
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
     	Scanner sc = new Scanner(System.in);
    	int N = Integer.parseInt(sc.nextLine());
		String SecondLine = sc.nextLine();
		int[] ArrayNint = new int[N];
		for (int i = 0; i < N; i++) {
			ArrayNint[i]= Integer.parseInt(SecondLine.split(" ")[i]);
		}
		int cnt = 0;
		boolean trigger;
		trigger = true;
		while (trigger) {
			for (int i =0 ; i< ArrayNint.length ; i++ ) {
				if (ArrayNint[i]% 2 == 1) {
					trigger = false ;
					break;
				} else {
					ArrayNint[i] = ArrayNint[i] / 2;
				} // if
			} // for
			if (trigger) {
			cnt++;
			}
		} // while
		System.out.println(cnt);
	}
}


Measured memory_bytes: 27732
import java.util.*;

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

		int n = scanner.nextInt();

		long[][] mint = new long[n][n];
		long[] xr = new long[n];
		long[] xc = new long[n];

		for (int r = 0; r < n; r++) {
			mint[r][r] = 0;
			xr[r] = scanner.nextInt();
			xc[r] = scanner.nextInt();
		}

		scanner.close();
	
		for (int r = 0; r < n - 1; r ++) {
			int i = r + 1;
			for (int l = 0; l <= r; l ++) {
				mint[l][i] = mint[l][r];
				mint[l][i] += xr[l] * xc[r] * xc[i];

				for (int m = l; m < r; m ++) {
					long t = mint[l][m] + mint[m + 1][r];
					t += xr[m + 1] * xc[r] * xc[i];
					t += xr[l] * xc[m] * xc[i];
					if (mint[l][i] > t) {
						mint[l][i] = t;
					}
				}
				
				if (i >= n - 1) break;
			}
		}
		System.out.println(mint[0][n - 1]);
	}
} 



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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

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

	string s, tmp1, tmp2;
	cin >> s;

	ll ans = 0;
	ll i = 0, j = 0;
	tmp1.push_back(s[0]);
	while(s[i] != '\0'){
		while(s[i] != '\0'){
			j = i + 1;
			if(s[j] != ' '){
				tmp2.push_back(s[j]);
			}
			if(tmp1 != tmp2){
				ans += 1;
//				cout << tmp1 << " " << tmp2 << endl;
//				i += tmp1.size();
				i += tmp2.size();
				tmp1 = tmp2;
				tmp2.clear();
				break;
			}
		}
	}

	cout << ans << endl;


    return 0;
}



Measured memory_bytes: 720
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0


# =============================================================================
# for i in range(N):
#     if(A[i] > B[i]):
#         # 全て倒せない
#         ans += B[i]
#         A[i] -= B[i]
#     else:
#         # 全て倒せる
#         B[i] -= A[i]
#         ans += A[i]
#         A[i] = 0
#         # 次の場所へ
#         if(A[i+1] > B[i]):
#             #次の場所はすべて倒せない
#             ans += B[i]
#             A[i+1] -= B[i]
#         else:
#             #次の場所もすべて倒せる
#             ans += A[i+1]
#             A[i+1] = 0
# =============================================================================

for i in range(N):
    c = min(A[i],B[i])
    ans += c
    B[i] -= c
    if(B[i] > 0):
        c = min(A[i+1], B[i])
        ans += c
        A[i+1] -= c
        B[i] -= c

print(ans)

Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 2e5+100;
const ll INF = 1e9;
const ll mod1=998244353;
const ll mod2=2e9+11;
int f[MAXN];
ll addd(ll a,ll b)
{
    a+=b;
    if (a>=mod1)
        return a-mod1;
    return a;
}

ll mult(ll a,ll b)
{
    return (a*b)%mod1;
}

ll sub(ll a,ll b)
{
    a-=b;
    if (a<0)
        return a+mod1;
    return a;
}

ll bin_pow(ll base,ll deg)
{
    if (deg==0)
        return 1;
    ll t=bin_pow(base,deg/2);
    if (deg&1)
        return (((t*t)%mod1)*base)%mod1;
    else
        return (t*t)%mod1;
}
void add(int pos, int x)
{
    for (;pos<MAXN;pos|=pos+1)
        f[pos]=addd(f[pos],x);
}

int res(int l)
{
    int sum=0;
    for (;l>=0;l=((l+1)&l)-1)
        sum=addd(sum,f[l]);
    return sum;
}

int res(int l,int r)
{
    return sub(res(r),res(l-1));
}
void solve()
{
    int n,k;
    cin>>n>>k;
    vector <pii> s(k);
    for (int i=0;i<k;i++)
        cin>>s[i].fi>>s[i].se;
    vector <int> dp(n+1);
    dp[1]=1;
    for (int i=1;i<n;i++)
    {
        dp[i]=addd(dp[i],res(i));
        for (auto to:s)
        {
            int l=to.fi,r=to.se;
            if (l+i>n)
                continue;
            add(l+i,dp[i]);
            if (r+i+1<=n)
                add(r+i+1,(mod1-dp[i])%mod1);
        }
    }
    cout<<res(n);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
    _t=1;
   // cin>>_t;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 4848
public partial class IntroductionToProgramming{
	public static void Main(){
		string[] line = System.Console.ReadLine().Split(' ');
		int a = int.Parse(line[0]);
		int b = int.Parse(line[1]);
		int c = int.Parse(line[2]);

		int counter = 0;
		for (int i = a; i <= b; i++)
		{
			if (c % i == 0)
			{
				counter++;
			}
		}

		System.Console.WriteLine(counter.ToString());
	}
}

Measured memory_bytes: 5612
#include <iostream>
#include <queue>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;


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

bool used[30];
int x[30], y[30], r[30], c[30], over[30];
int n;
map<int,int> dp;

int sqr(int x){ return x*x; }

bool istop(int node){
  int i;
  rep(i,node) if( !used[i] ) {
    if( sqr(x[i] - x[node]) + sqr(y[i] - y[node]) < sqr(r[i]) + 2*r[i]*r[node] + sqr(r[node]) ) return false;
  }
  return true;
}

int solve(int S){
  int i,j, res = 0;

  if( dp.count(S) ) return dp[S];
  
  rep(i,n) if( !used[i] && ((S&over[i]) == over[i]) ){
    REP(j,i+1,n) if( !used[j] && c[i] == c[j] && ((S&over[j]) == over[j]) ){
      used[i] = used[j] = true;
      //printf("(%d,%d), S=%d\n",i,j,S|(1<<i)|(1<<j));
      res = max(res, solve(S|(1<<i)|(1<<j)) + 2);
      used[i] = used[j] = false;
    }
  }
  return dp[S] = res;
}

int main(){
  int i,j;
  
  while( scanf("%d",&n), n ){
    memset(used, false, sizeof(used));
    dp.clear();
    rep(i,n) scanf("%d %d %d %d",x+i,y+i,r+i,c+i);

    rep(i,n){
      int S = 0;
      rep(j,i){
        if( sqr(x[i] - x[j]) + sqr(y[i] - y[j]) < sqr(r[i]) + 2*r[i]*r[j] + sqr(r[j]) ){
          S |= 1<<j;
        }
      }
      over[i] = S;
    }

    /*
    rep(i,n){
      printf("over[%d] = %d\n",i,over[i]);
    }
      */

    /*
    cout << "n=" << n << endl;
    rep(i,n){
      printf("x[%2d] = %3d, y[%2d] = %3d, r[%2d] = %3d, c[%2d] = %3d\n",i,x[i],i,y[i],i,r[i],i,c[i]);
    }
    rep(i,n){
        printf("istop(%d) = %d\n",i,istop(i));
    }
      */

    cout << solve(0) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 32000
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  int a,b,k; cin>>a>>b>>k;
  int c=0;
  int am;
  if(a>b){
    for(int i=b;i>=0;i--){
      if(a%i==0&&b%i==0){
        c++;
      }
      if(c==k){
        am=i;
        break;
      }
    }
  }else{
    for(int i=a;i>=0;i--){
      if(a%i==0&&b%i==0){
        c++;
      }
      if(c==k){
        am=i;
        break;
      }
    }
  }
  cout<<am<<endl;
  return 0;
}


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

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<ll> ps(n + 1, 0);
    rep(i, n) ps[i + 1] = ps[i] + a[i];

    ll lb = 0, rb = 200200;
    while (lb + 1 < rb) {
        ll x = (lb + rb) / 2;
        ll sz = 0;
        rep(i, n) {
            int j = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin();
            sz += n - j;
        }
        if (sz >= m) {
            lb = x;
        } else {
            rb = x;
        }
    }
    ll ans = 0, cnt = 0;
    rep(i, n) {
        int j = lower_bound(a.begin(), a.end(), lb - a[i]) - a.begin();
        cnt += n - j;
        ans += ps[n] - ps[j];
        ans += a[i] * (n - j);
    }
    ans -= max(cnt - m, 0ll) * lb;
    cout << ans << endl;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define int long long
int T;
int n, a, b, c, d;
unordered_map<int, int> M;

int  dfs(int n)
{
	if (!n) return 0;
	if (n == 1) return d;
	if (M[n]) return M[n];
	int res = 1e18;
	if (n < res / d) res = n * d;
	res = min(res, n % 2 * d + dfs(n / 2) + a); res = min(res, (2 - n % 2) * d + dfs( (n + 1) / 2) + a);
	res = min(res, n % 3 * d + dfs(n / 3) + b); res = min(res, (3 - n % 3) * d + dfs( (n + 2) / 3) + b);
	res = min(res, n % 5 * d + dfs(n / 5) + c); res = min(res, (5 - n % 5) * d + dfs( (n + 4) / 5) + c);
	M[n] = res;
	return res;
}
signed main()
{

	scanf("%lld", &T);
	while (T--)
	{
		M.clear();
		scanf("%lld %lld %lld %lld%lld", &n, &a, &b, &c, &d);
		printf("%lld\n", dfs(n));
	}
	return 0;
}

Measured memory_bytes: 4160
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;

ll n, mat[60][60];

void matpro(ll a[60][60], ll b[60][60])
{
    ll i, j, k, c[60][60];
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            c[i][j] = 0;

    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            for (k = 0; k < n; k++)
                c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % mod) % mod;

    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            a[i][j] = c[i][j];
}

void pwr(ll k)
{
    ll id[60][60], i, j;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            id[i][j] = (i == j) ? (1) : (0);

    while (k)
    {
        if (k & 1)
            matpro(id, mat);
        matpro(mat, mat);
        k >>= 1;
    }

    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            mat[i][j] = id[i][j];
}

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

    ll i, j, k, total = 0;
    cin >> n >> k;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            cin >> mat[i][j];

    pwr(k);

    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            total = (total + mat[i][j]) % mod;

    cout << total << "\n";

    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
// using ll = long long;
// using P = pair<int,int>;
// using vi = vector<int>;
// using vvi = vector<vi>;







template <typename T>
T gcd(T a, T b) {
  if(b == 0) return a;
  else return gcd(b,a%b);
}



int main() {
  int K;
  cin >> K;
  string s;
  cin >> s;
  int N = s.size();
  if(N <= K) cout << s << endl;
  else cout << s.substr(0,K) << "..." << endl; 
  return 0;
}





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

int main(){
int x,y; cin >>x>>y;
bool ans = false;

for(int i=0;i<=x;i++){
  if(i*2+(x-i)*4 == y) ans = true;
}

if(ans) cout <<"Yes" <<endl;
else cout << "No" <<endl;
}


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

using namespace std;
typedef long long ll;




int main()
{
    const ll mod = 1000000007;
    int N;
    cin >> N;
    vector<int> C;
    rep(i,N){
        int c;
        cin >> c;
        if(i == 0) C.push_back(c);
        else if(C.back() == c) continue;
        else C.push_back(c);
    }
    vector<ll> V(200005, 0);
    
    ll ans = 1;
    
    for (int i = 0; i < int(C.size()); i++) {
        
        if(V[C[i]] > 0) ans += V[C[i]];
        ans %= mod;
        V[C[i]] = ans;
        
    }
    
    cout << ans << endl;
    
    
    return 0;
}



Measured memory_bytes: 2676
def solve():
  from itertools import groupby as gb 
  n=int(input())
  l=[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))]
  sl,vl=[list(a) for a in zip(*l)]
  m=int(input())
  lm=[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))]
  slm,vlm=[list(a) for a in zip(*lm)]
  for i in set(sl)&set(slm):
    vl[sl.index(i)]+=vlm[slm.index(i)]
  print(max(0,max(vl)))
  
if __name__=="__main__":
  solve()

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int n, x, y, h, w;
	int sum;
	int m;
	
	m = 0;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		while (n--){
			scanf("%d %d %d %d", &x, &y, &h, &w);
			sum = x + y + h;
			
			if (sum <= 60 && w <= 2){
				m = m + 600;
			}
			else if (sum <= 80 && w <= 5){
				m = m + 800;
			}
			else if (sum <= 100 && w <= 10){
				m = m + 1000;
			}
			else if (sum <= 120 && w <= 15){
				m = m + 1200;
			}
			else if (sum <= 140 && w <= 20){
				m = m + 1400;
			}
			else if (sum <= 160 && w <= 25){
				m = m + 1600;
			}
		}
		printf("%d\n", m);
		m = 0;
	}
	
	return (0);
}

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

#define N 100005

int n,m,x[N],y[N];

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	read(n);read(m);read(x[0]);read(y[0]);
	for(int i=1;i<=n;++i)
	read(x[i]);
	for(int i=1;i<=m;++i)
	read(y[i]);
}

int main(){
	init();
	int xx,yy;
	xx=x[1];yy=y[1];
	for(int i=1;i<=n;++i)
	xx=max(xx,x[i]);
	for(int i=1;i<=m;++i)
	yy=min(yy,y[i]);
	for(int i=x[0]+1;i<=y[0];++i)
	if(xx<i&&i<=yy){
		puts("No War");
		return 0;
	}
	puts("War");
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/


int main()
{
  ll r;cin>>r;
  printf("%.20f",M_PI*2*r);
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

ll ToNumber(const vector<int>& v, const vector<int>& valid){
    ll res = 0;
    for(auto n : v){
        if(n==-1) break;
        res = res*10 + valid[n];
    }
    return res;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    ll Di;
    set<int> valid = {0,1,2,3,4,5,6,7,8,9};
    for(int i=0;i<K;i++){
        cin >> Di;
        valid.erase(Di);
    }
    vector<int> validv(valid.begin(), valid.end());
    ll res = N;
    vector<int> x(to_string(N).size()+1, 0);
    x.back() = -1;
    while(true){
        if(ToNumber(x, validv) >= N){
            cout<<ToNumber(x, validv)<<endl;
            return 0;
        }
        x[0]++;
        for(int i=0;i<x.size();i++){
            if(x[i]<valid.size()) break;
            x[i]=0;
            x[i+1]++;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   
   int n;
   cin>>n;
   int cnt[n+1]={0};
   long long ans=1;
   for(int i=2;i<=n;i++){
    int k=i;
     for(int j=2;j<=sqrt(i);j++){
      while(k%j==0){
        cnt[j]++;
        k=k/j;
      }
     }
     if(k>1){
      cnt[k]++;
     }
   }
   //cout<<ans<<"\n";
   for(int i=2;i<=n;i++){
       ll d=cnt[i]+1;
      ans*=d;
      ans%=mod;
   }
   cout<<ans<<"\n";




}

Measured memory_bytes: 3532
#include <cstdio>
#include <queue>
#include <string>

using namespace std;

template <class T>
using gp_queue=priority_queue<T, vector<T>, less<T>>;

int main() {
    gp_queue<int> q;
    for (char buf[1<<3]; scanf("%s", buf)!=EOF;) {
        string instr(buf);
        if (instr == "insert") {
            int key;
            scanf("%d", &key);
            q.push(key);
        } else if (instr == "extract") {
            printf("%d\n", q.top());
            q.pop();
        } else if (instr == "end") {
            return 0;
        }
    }
}

Measured memory_bytes: 6636