akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int N,i;
  long a[100005],b[100005],count;
  char str[5000000],*p;
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  a[0]=atol(p);
  
  for(i=1;i<N+1;i++){
    p=strtok(NULL," \n");
  	a[i]=atol(p);
  }
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  b[0]=atol(p);
  
  for(i=1;i<N;i++){
    p=strtok(NULL," \n");
  	b[i]=atol(p);
  }
  
  for(i=0;i<N;i++){
    if(a[i]>=b[i]){
      count+=b[i];
    }else{
      b[i]-=a[i];
      count+=a[i];
      if(b[i]>=a[i+1]){
        count+=a[i+1];
        a[i+1]=0;
      }else{
        a[i+1]-=b[i];
        count+=b[i];
      }
    }
  }
  
  printf("%ld\n",count);
  
  return 0;
}

Measured memory_bytes: 6656
#include<iostream>
#include<queue>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;//x, y
typedef pair<int, pii> piii;//cost, x, y
int dx[2][6] = {
  {0, 1, 0, -1, -1, -1},
  {1, 1, 1,  0, -1,  0}
};
int dy[2][6] = {
  {-1, 0, 1, 1, 0, -1},
  {-1, 0, 1, 1, 0, -1}
};
int grid[110][110];
int n, m, a;

int bfs(int grid[110][110], int sx, int sy){
  queue<piii> que;
  int ans = 1;
  grid[sy][sx] = 0;
  que.push(mp(0, mp(sx, sy)));
  while(!que.empty()){
    piii p = que.front();que.pop();
    int cost = p.first;
    int x    = p.second.first;
    int y    = p.second.second;
    for (int i = 0; i < 6; i++) {
      int nx = x + dx[y&1][i], ny = y + dy[y&1][i];
      if(0 <= ny && ny < n &&
         0 <= nx && nx < m &&
         grid[ny][nx] > cost + 1){
        ans++;
        grid[ny][nx] = cost + 1;
        que.push(mp(cost + 1, mp(nx, ny)));
      }
    }
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < m; j++) {
  //     std::cout << grid[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  // std::cout << std::endl;

  return ans;
}

int main(int argc, char *argv[]){
  while(cin >> m >> n, n){
    int ans = 0, t;
    cin >> a;
    int sx[a], sy[a];
    for (int i = 0; i < a; i++) {
      cin >> sx[i] >> sy[i];
      sx[i]--;sy[i]--;
    }
    cin >> t;
    int px[t], py[t];
    for (int i = 0; i < t; i++) {
      cin >> px[i] >> py[i];
      px[i]--;py[i]--;
    }
    
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        grid[i][j] = 1e8;
      }
    }
    
    for (int i = 0; i < a; i++) {
      bfs(grid, sx[i], sy[i]);
    }

    for (int i = 0; i < t; i++) {
      int tmp[110][110];
      
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < m; k++) {
          tmp[j][k] = grid[j][k];
        }
      }
      
      ans = max(ans, bfs(tmp, px[i], py[i]));
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;


 
int main(){
    ll a,b,c;

    cin >> a >> b >> c;
    ll d = max(a,max(b,c));
    ll sum = a + b + c;
    ll ans = 0;
 
    if( (3 * d - sum) % 2 == 0 ){
        cout << (3 * d - sum) / 2 << endl;
    }else{
        ans += 1;
        d++;
        sum += 2;
        cout << (3 * d - sum) / 2 + ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
li=[chr(i) for i in range(97, 97+26)]
ans=['a']
def nex(ans,n):
    d=[]
    for i in ans:
        for j in range(n):
            if li[j]in i:
                d.append(i+str(li[j]))
            else:            
                k=len(set(i))
                if k+1>=j+1:
                    d.append(i+str(li[j]))
    return d
for i in range(2,N+1):
    ans=nex(ans,i)
for i in ans:
    print(i)
    

Measured memory_bytes: 12984
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#define ll long long int
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
using namespace std; 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll findGCD(ll arr[], ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 
ll findMaxGCD(ll arr[], ll n) 
{ 
	ll high = 0; 
	for (ll i = 0; i < n; i++) 
		high = max(high, arr[i]);  
	ll count[high + 1] = {0}; 
	for (ll i = 0; i < n; i++) 
		count[arr[i]]++;  
	ll counter = 0; 
	for (ll i = high; i >= 1; i--) 
	{ 
		ll j = i; 
	counter = 0; 
		while (j <= high) 
		{ 

			if(count[j] >=2) 
			return j; 

		else if (count[j] == 1)		 
				counter++;		  
			j += i; 

			
			if (counter == 2)		 
				return i; 
		} 
	} 
} 
int main() 
{ 
	ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll val=findGCD(a,n);
	ll ans= findMaxGCD(a, n); 
    if(ans==1)
    cout<<"pairwise coprime"<<endl;
    else if(val==1)
    cout<<"setwise coprime"<<endl;
    else
    cout<<"not coprime"<<endl;
} 


Measured memory_bytes: 19160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.awt.geom.Point2D.Double;

import static java.lang.Integer.parseInt;

public class Main {

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

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines;
      Point2D[] s = new Point2D[2];
      StringBuilder buf = new StringBuilder();

      lines = br.readLine().split(" ");
      int x, y;
      for(int j=0,k=0; j<s.length; j++) {
        x = parseInt(lines[k++]);
        y = parseInt(lines[k++]);
        s[j] = new Point2D(x, y);
      }

      int q = parseInt(br.readLine());
      Vector v = new Vector();

      for(int i=0; i<q; i++) {
        lines = br.readLine().split(" ");
        Point2D p = new Point2D(parseInt(lines[0]), parseInt(lines[1]));
        Point2D result = v.project(s[0], s[1], p);
        buf.append(result.x).append(" ").append(result.y).append("\n");
      }

      System.out.print(buf);
    }
    catch(IOException e) {
      System.out.println(e);
    }
  }

  private class Point2D extends Double {
    private static final long serialVersionUID = 1L;
    double EPS = 1e-10;

    public Point2D() { super(); }
    public Point2D(double x, double y) { super(x, y); }

    public boolean equals (double a, double b) {
      return Math.abs(a-b) < EPS;
    }
    public Point2D sum(Point2D b) {
      return new Point2D(x+b.x, y+b.y);
    }
    public Point2D diff(Point2D b) {
      return new Point2D(x-b.x, y-b.y);
    }
    public Point2D multiple(double k) {
      return new Point2D(x*k, y*k);
    }

    @Override
    public String toString() {
      return "[" + x + "," + y + "]";
    }
  }

  private class Vector extends Point2D {

    private static final long serialVersionUID = 1L;

    public Vector() { super(); }
    public Vector(double x, double y) { super(x, y); }
    public Vector(Point2D p) { super(p.x, p.y); }

    public double norm() {
      return x * x + y * y;
    }
    public double dot(Point2D a, Point2D b) {
      return a.x * b.x + a.y * b.y;
    }
    public double cross(Point2D a, Point2D b) {
      return a.x * b.y - a.y * b.x;
    }
    public boolean isOrthogonal(Point2D a, Point2D b) {
      return equals(dot(a,b) , 0.0);
    }
    public boolean isOrthogonal(Point2D a1, Point2D a2, Point2D b1, Point2D b2) {
      return isOrthogonal(a1.diff(a2), b1.diff(b2));
    }
    public boolean isParallel(Point2D a, Point2D b) {
      return equals(cross(a, b), 0.0);
    }
    public boolean isParallel(Point2D a1, Point2D a2, Point2D b1, Point2D b2) {
      return isParallel(a1.diff(a2), b1.diff(b2));
    }

    public Point2D project(Point2D sp1, Point2D sp2, Point2D p) {
      Vector base = new Vector( sp2.diff(sp1) );
      double r = dot(p.diff(sp1), base) / base.norm();

      return sp1.sum(base.multiple(r));
    }
  }
}


Measured memory_bytes: 28364
# N = gets.chomp.to_i
K, N = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars
A.sort!  # increasing order

maxDiff = 0
0.upto(N-1).each do |i|
  if (i == N-1) 
    diff = (K+A[0]) - A[N-1]
  else 
    diff = A[i+1] - A[i]
  end
  diff = diff *(-1) if diff < 0
  maxDiff = [diff, maxDiff].max
end

p (K - maxDiff)

Measured memory_bytes: 20592
import sys
import math

n = int(input())
a = list(map(int, input().split()))
a.sort()
limit = max(a)
dp = [True] * (limit + 1)
archives = set()
for i in a:
    if i in archives:
        dp[i] = False
        continue
    archives.add(i)
    n = 2
    while i * n <= limit:
        dp[i * n] = False
        n += 1

# print(dp)
ans = 0
for i in a:
    if dp[i] is True:
        ans += 1


print(ans)

Measured memory_bytes: 40232
#include<stdio.h>
#define MAX 101

int main(){
  int a[MAX][MAX],n,u,k,v,i,j;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      a[i][j]=0;
    }}

  for(i=1;i<=n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[i][v]=1;
    }}

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j==n)printf("%d",a[i][j]);
      else printf("%d ",a[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

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

    int n, m, K; cin >> n >> m >> K;
    vector<vi> F(n);
    vector<vi> B(n);
    UnionFind uf(n);
    rep(_, m){
        int a, b; cin >> a >> b;
        a--, b--;
        F[a].emplace_back(b);
        F[b].emplace_back(a);
        uf.unionSet(a, b);
    }
    rep(_, K){
        int a, b; cin >> a >> b;
        a--, b--;
        B[a].emplace_back(b);
        B[b].emplace_back(a);
    }

    rep(i, n){
        int res = uf.size(i) - 1;
        for(auto& e : F[i]){
            if(uf.findSet(i, e)){
                res--;
            }
        }
        for(auto& e : B[i]){
            if(uf.findSet(i, e)){
                res--;
            }
        }
        cout << (i ? " ":"") << res;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 12280
#include <cstdio>
using namespace std;
#define S 1000000
typedef struct{char n[10];int t;}QUE;
QUE que[S];
main(){
int i=0,T=0,h=0,t,n,q;
scanf("%d %d",&n,&q);
for(t=n;i<n;)scanf("%s %d",que[i++].n,&que[i].t);
while(h!=t){
bool f=que[h].t<=q||t-h==1;
T+=f?que[h].t:q;
if(f)printf("%s %d\n",que[h].n,T);
else{que[h].t-=q;que[t]=que[h];if(++t==S)t=0;}
if(++h==S)h=0;
}
}


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

int main(){
  int n,a,b;
  cin >> n;
  while(n--){
    int sx,sy,ex,ey,w,h;
    cin >> sx >> sy >> w >> h;
    ex = sx + w;
    ey = sy + h;
    int cnt = 0,N;
    cin >> N;
    for(int i=0;i<N;i++){
      cin >> a >> b;
      if(sx <= a && a <= ex && sy <= b && b <= ey){
	cnt++;
      }
    }
    cout << cnt << endl;
  }
}
    

Measured memory_bytes: 1160
#include<stdio.h>

int main(void){
    int r,g,b;
    scanf("%d%d%d",&r,&g,&b);

    if((g*10 + b*1) % 4 == 0) {
        printf("YES");
        return 0;
    }

    printf("NO");
    return 0;
    
}

Measured memory_bytes: 128
h, w = gets.split.map(&:to_i)
a = (1..h).map { gets.split("").map(&:to_i) }

queue = []
(1..h-1).each do |i|
    (0..w-1).each do |j|
        next if a[i][j] == 0
        (i-1..i+1).each do |y|
            (j-1..j+1).each do |x|
                a[i][j] -= 1 if a[y][x] == 0
            end
        end
        if a[i][j] <= 0
            queue << [i, j]
            a[i][j] = 'd'
        end
    end
end
queue.each do |i, j|
    a[i][j] = 0
end

count = 0
until queue.empty?
    new_queue = []
    queue.each do |i, j|
        (i-1..i+1).each do |y|
            (j-1..j+1).each do |x|
                next if y == i && x == j
                if a[y][x] != ?d && a[y][x] > 0
                    a[y][x] -= 1
                    if a[y][x] <= 0
                        new_queue << [y, x]
                        a[y][x] = ?d
                    end
                end
            end
        end
    end
    queue = new_queue
    queue.each do |i, j|
        a[i][j] = 0
    end
    count += 1
end
p count



Measured memory_bytes: 16020
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

q = 10**9+7

x_sum = 0
y_sum = 0
for i in range(n):
    x_sum += (2*i - n + 1) * x[i]
    
for i in range(m):
    y_sum += (2*i - m + 1) * y[i]

print(  ((x_sum * y_sum )%q) )

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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  vector< vector<bool> > dp1(n + 1, vector<bool>(k, false));
  vector< vector<bool> > dp2(n + 1, vector<bool>(k, false)); 
  dp1[0][0] = dp2[n][0] = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      dp1[i + 1][j] = dp1[i][j] or j - a[i] >= 0 and dp1[i][j - a[i]];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < k; j++) {
      dp2[i][j] = dp2[i + 1][j] or j - a[i] >= 0 and dp2[i + 1][j - a[i]];
    }
  }
  auto needed = [&](int i) {
    if (a[i] >= k) return true;
    for (int j = k - a[i]; j < k; j++) {
      if (dp1[i][j] or dp2[i + 1][j]) return true;
    }
    for (int j = k - a[i]; j < k; j++) {
      for (int l = 0; l <= j; l++) {
        if (dp1[i][l] and dp2[i + 1][j - l]) return true;
      }
    }
    return false;
  };
  int l = -1, r = n;
  while (true) {
    int m = (l + r) / 2;
    if (needed(m)) r = m;
    else l = m;
    if (r - l == 1) break;
  }
  cout << r << '\n';
  return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
struct edge {ll to,cost;};

int main() {
    ll v,e,r;
    cin>>v>>e>>r;
    vector<edge> g[v];
    rep(i,e){
        ll j,k,d;
        cin>>j>>k>>d;
        g[j].push_back({k,d});
    }
    
    vll d(v,maxn);
    d.at(r)=0;
    
    queue<ll> q;
    q.push(r);
    while(!q.empty()){
        ll s=q.front();
        q.pop();
        for(auto p:g[s]){
            ll ns=p.to;
            ll kyori=p.cost;
            if(d.at(ns)>kyori+d.at(s)){
                d.at(ns)=kyori+d.at(s);
                q.push(ns);
            }
        }
    }
    
    rep(i,v){
        if(d.at(i)==maxn)cout<<"INF"<<endl;
        else cout<<d.at(i)<<endl;
    }
}



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

using namespace std;

long long calcInverseNumber(vector<long long> v) {
	if(v.empty()) return 0;
	long long r = 0;
	long long num1 = 0;
	for(int i = 0; i < v.size(); ++i) {
		if(v[i] == 0) {
			r += num1;
		} else {
			++num1;
		}
	}
	return r;
}

int main(void) {
	string s;
	cin >> s;
	long long ans = 0;
	vector<long long> v;
	for(int i = 0; i <= s.length(); ++i) {
		if(i == s.length()) {
			ans += calcInverseNumber(v);
			break;
		}
		if(s[i] == 'A') {
			v.push_back(1LL);
		} else if(i + 1 < s.length() && s[i] == 'B' && s[i + 1] == 'C') {
			v.push_back(0LL);
			++i;
		} else {
			ans += calcInverseNumber(v);
			v.clear();
		}
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 3700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
  
class Main{
public static void main(String[] args) throws IOException{
final int[] alphas={1,3,5,7,9,11,15,17,19,21,23,25};
final int[] betas={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> array=new ArrayList<String>();
HashMap<Character,Character> dic=new HashMap<Character,Character>();
int ga;
int gb;
String line;
int n=Integer.parseInt(br.readLine());
while(n-->0){
ga=0;
gb=0;
line=br.readLine();
char[] chararray=line.toCharArray();
for(String s : line.split(" ")){
if(s.length()==4){
array.add(s);
}
}
outside: for(int p=0;p<array.size();p++){
         char[] uc=array.get(p).toCharArray();
         for(int a=0;a<alphas.length;a++){
         for(int b=0;b<betas.length;b++){
         char ct=(char)((alphas[a]*('t'-97)+betas[b])%26+97);
         char ch=(char)((alphas[a]*('h'-97)+betas[b])%26+97);
         char ci=(char)((alphas[a]*('i'-97)+betas[b])%26+97);
         char cs=(char)((alphas[a]*('s'-97)+betas[b])%26+97);
         char ca=(char)(betas[b]%26+97);
         if(uc[0]==ct&&uc[1]==ch){
         if((uc[2]==ci&&uc[3]==cs)||(uc[2]==ca&&uc[3]==ct)){
         ga=alphas[a];
         gb=betas[b];
         break outside;
         }
         }
         }
         }
         }
for(int i=0;i<26;i++){
char nc=(char)((ga*i+gb)%26+97);
char c=(char)(i+97);
dic.put(nc,c);
}
for(int i=0;i<chararray.length;i++){
if(chararray[i]>='a'&&chararray[i]<='z'){
chararray[i]=dic.get(chararray[i]);
}
}
System.out.println(chararray);
array.clear();
dic.clear();
}
}
}

Measured memory_bytes: 17820
n = gets.to_i
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i).sort

def ub(a, n, i)
  l, r = 0, n - 1
  while l <= r
    m = l + (r - l) / 2
    if a[m] <= i
      l = m + 1
    else
      r = m - 1
    end
  end
  l == n ? nil : l
end

def lb(a, n, i)
  l, r = 0, n - 1
  while l <= r
    m = l + (r - l) / 2
    if a[m] < i
      l = m + 1
    else
      r = m - 1
    end
  end
  l
end

ans = 0
bc = 0
ab = 0
n.times {|i|
if bc = ub(c, n, b[i])
  ans += lb(a, n, b[i]) * (n - bc)
end
}

p ans


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

int main()
{
    int n;
    cin>>n;
    int ar[n+1];
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    sort(ar+1,ar+n+1);

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            for(int k=j;k<=n;k++)
            {
                if(ar[i]!=ar[j] && ar[j]!=ar[k] && ar[i]!=ar[k])
                {
                    if(ar[i]+ar[j]>ar[k])
                        cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
#define ll long long int
//n jumlah bola yang even
// m jumlah bola yang odd
//n+m >= 2
int main(){
	int n, m, even = 0;
	scanf("%d %d", &n, &m);
	even = n * (n -1) /2 + m * (m - 1) /2;
	printf("%d\n", even);
	
	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*-------------------------------------------------------------*/
// Weighted Union Find
typedef struct{
    ll num; //number
    ll par; //parent
    ll height; //height
    ll wdif;
    ll weight;
}WUF;
void WUFmake(ll n, WUF b[n]){for(ll i=0;i<n;i++){
    b[i].par = i;
    b[i].num = i;
    b[i].height = 1;
    b[i].wdif = 0;
    b[i].weight = 0;
    }
}
ll WUFroot(ll n, ll a, WUF b[n]){
    ll c= a==b[a].par ? a : WUFroot(n,b[a].par,b) ;
    b[a].weight = b[b[a].par].weight + b[a].wdif;
    return c;
}
// b[x]+z=b[y]
void WUFunite(ll n, ll x, ll y, ll z, WUF b[n]){
    ll xroot = WUFroot(n,x,b), yroot = WUFroot(n,y,b);
    if(b[xroot].height > b[yroot].height){ b[yroot].par = xroot;  b[yroot].wdif = b[x].weight+z-b[y].weight;
    }else{ b[xroot].par = yroot;  b[yroot].height = max2(b[yroot].height,b[xroot].height+1);  b[xroot].wdif = b[y].weight-b[x].weight-z;}
}
ll WUFsame(ll n, ll x, ll y, WUF b[n]){ return WUFroot(n,x,b) == WUFroot(n,y,b) ? 1 : 0; }

int main(void){
    // char ;
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll l[m],r[m],d[m];
    rep(i,0,m){
        scanf("%lld%lld%lld",&l[i],&r[i],&d[i]);
    }
    WUF peo[n];
    WUFmake(n,peo);
    rep(i,0,m){
        if(WUFsame(n,l[i]-1,r[i]-1,peo)==0){
            WUFunite(n,l[i]-1,r[i]-1,d[i],peo);
        }else{
            if(peo[r[i]-1].weight-peo[l[i]-1].weight!=d[i]){
                NO;
                return 0;
            }
        }
    }
    YES;
    
    return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007 
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define double long double

int n,h[155];
double dp[165][325];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>h[i];
	for(int i=0;i<165;i++) for(int j=0;j<325;j++) dp[i][j] = 1e18;
	dp[0][1] = 0.0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=322;j++){
			if(dp[i][j] > 1e17) continue;
			for(int k=1;k<=322;k++){
				//(i,j) -> (i+1,k)
				//(i,h[i+1]) -> (i+1,h[i+1])
				double cm;
				if(j < h[i+1] && k < h[i+1]){
					cm = (double)(j+k)/2.0;
				}
				else if(j >= h[i+1] && k >= h[i+1]){
					cm = (double)(h[i+1]);
				}
				else if(j >= h[i+1] && k < h[i+1]){
					int tate = j-k;
					int tate2 = h[i+1]-k;
					cm = (double)(h[i+1]) - (double)(tate2)*(double)(tate2)/(double)(tate)/2.0;
				}
				else{
					swap(j,k);
					int tate = j-k;
					int tate2 = h[i+1]-k;
					cm = (double)(h[i+1]) - (double)(tate2)*(double)(tate2)/(double)(tate)/2.0;
					swap(j,k);
				}
				dp[i+1][k] = min(dp[i+1][k],dp[i][j]+(double)(j+k)/2.0+(double)(h[i+1])-cm*2.0);
			}
		}
	}
	double ans = 1e18;
	for(int i=1;i<=322;i++) ans = min(ans,dp[n][i]);
	printf("%.8Lf\n",ans);
}


Measured memory_bytes: 4040
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
import time
ts=time.time()
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
a=LI()
b=LI()
c=LI()
ans=sum(b)

for i in range(1,n):
    if a[i]-a[i-1]==1:
        ans+=c[a[i]-1-1]
    
    
print(ans)


Measured memory_bytes: 38636
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//???????????£?¨??????????
		Scanner sc = new Scanner(System.in);
		int list1 [][];

		//list??????????????§????????¨??¨????????§???????????¨???
		//2?¬???????????????????
		int tate = sc.nextInt();
		int yoko = sc.nextInt();
		list1 = new int[tate][yoko];

		//2?¬?????????????????????????????????????
		for(int i = 0; i < tate; i++){
			for(int j = 0; j < yoko; j++){
				list1[i][j] = sc.nextInt();
				//System.out.print(list1[i][j]);
			}
			//System.out.println("");
		}

		//???????????£?¨?
		int list2 [];
		list2 = new int[yoko];

		//????????????????????\????????????
		for(int i = 0; i < yoko; i++){
			list2[i] = sc.nextInt();
			//System.out.println(list2[i]);
		}

		//?¨????????????????
		for(int i = 0; i < tate; i++){
			int goukei = 0;
			for(int j = 0; j < yoko; j++){
				goukei += list1[i][j] * list2[j];
			}
				System.out.println(goukei);
		}
		sc.close();
	}
}

Measured memory_bytes: 40844
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<sstream>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

class Parsing{
private:

  int pos;
public:
  string parse;
 
  Parsing(string s){
    parse = s;
    pos = 0;
  }
  int fact(){
    if(parse[pos] == '('){
      pos++;
      int p = expression();
      pos++;
      return p;
    }else{
      int p=0;
      
      while('0' <= parse[pos] && parse[pos] <= '9'){
    p *= 10;
    p += parse[pos]-'0';
    pos++;
      }
      return p;
    }
  }
 
 int term(){
    int p = fact();
    while(parse[pos] == '*' || parse[pos] == '/'){
      if(parse[pos] == '*'){pos++;p *= fact();}
      else {pos++;p /= fact();}
    }
    return p;
  }
 
 int expression(){
    int p = term();
    while(parse[pos] == '+' || parse[pos] == '-'){
      if(parse[pos] == '+'){pos++;p+=term();}
      else {pos++;p-=term();}
    }
    return p;
  } 
 
};

map<string,int> index;

string itos(int v)
{
  stringstream ss;
  ss << v;
  return ss.str();
}

string toFigure(string line)
{
  string ret;
  rep(i,line.size())
    {
      if(line[i] == '(' || line[i] == ')')
	{
	  if(line[i] == ')')
	    {
	      ret = ret.substr(0,ret.size()-1);
	    }
	  ret += line.substr(i,1)+(line[i]==')'?"+":"");
	  continue;
	}
      if(!('A' <= line[i] && line[i] <= 'Z'))
	{
	  if(!('a' <= line[i] && line[i] <= 'z'))
	    {
	      if(i-1>=0 && ret[ret.size()-1]=='+')
		{
		  ret = ret.substr(0,ret.size()-1);
		}
	      int pos = i;
	      while(pos < line.size() && '0' <= line[pos] && line[pos] <= '9')pos++;
	      
	      ret += "*"+line.substr(i,pos-i)+"+";
	      i = pos-1;
	    }
	  continue;
	}
      if(i+1 < (int)line.size() && ('a' <= line[i+1] && line[i+1] <= 'z'))
	{
	  if(index.find(line.substr(i,2)) == index.end())ret += "$";
	  else                                           ret += itos(index[line.substr(i,2)])+"+";
	  continue;
	}
      if(index.find(line.substr(i,1)) == index.end())ret += "$";
      else                                          ret += itos(index[line.substr(i,1)])+"+";
    }
  if(ret[ret.size()-1] == '+')ret = ret.substr(0,ret.size()-1);
  return ret;
}

int main()
{
  
  index.clear();
  string s;
  int v;
  while(true)
    {
      cin >> s;
      if(s == "END_OF_FIRST_PART")break;
      cin >> v;
      index[s] = v;
    }

  while(true)
    {
      cin >> s;
      if(s == "0")break;
      Parsing par(toFigure(s));
      if(par.parse.find("$") != string::npos)cout << "UNKNOWN" << endl;
      else                                      cout << par.expression() << endl;
    }

    
  return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  if(n == 1 && m == 1) cout << 1 << endl;
  else if(n == 1 || m == 1) cout << n * m - 2 << endl;
  else if(n == 2 || m == 2) cout << 0 << endl;
  else cout << (n-2) * (m-2) << endl;

  return 0;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int r = c + d;
    int l = a + b;
    if(r < l) cout << "Left" << endl;
    else if(r > l) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
n, a, d = list(map(int, input().split(' ')))

if d == 0:
    print(1 if a == 0 else n + 1)
    sys.exit()

if d < 0:
    a, d = -a, -d

dic = defaultdict(list)
for i in range(n + 1):
    l = a * i + i * (i - 1) // 2 * d
    r = a * i + (n-i + n-1)*i // 2 * d
    dic[l % d].append((l // d, r // d + 1))

ans = 0
for p in dic.values():
    end = -1e18
    p.sort()
    for t in p:
        s, e = t
        if end < s:
            ans += (e-s)
            end = e
        if end < e:
            ans += (e - end)
            end = e

print(ans)

Measured memory_bytes: 71372
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n];
	for (int i=0; i<n; i++)  cin >> a[i];
	int cnt=0, i;
	do{
		for(i=0;i<n;i++)
		   if(a[i]%2==1){
		   	cout<<cnt;
		   	return 0;
		   }
		   else
		      a[i]=a[i]/2;
		cnt++;
	}while (1);

	cout<<n;
	return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint L;
class trie{
public:
	trie *zero,*one;
	int fuka;
	trie(int in){zero=nullptr;one=nullptr;fuka=in;}
	void make_zero(void){if(zero==nullptr){zero=new trie(fuka+1);}}
	void make_one(void){if(one==nullptr){one=new trie(fuka+1);}}
	llint solve(void){
		llint ans=0;
		if(fuka==L){return 0;}
		if(zero==nullptr){ans^=(L-fuka)-((L-fuka)&(L-fuka-1));}//再開bit
		else{ans^=zero->solve();}
		if(one==nullptr){ans^=(L-fuka)-((L-fuka)&(L-fuka-1));}//再開bit
		else{ans^=one->solve();}
		return ans;
	}
};
int main(void){
	int n,i;cin>>n;
	cin>>L;
	trie ki(0);
	for(i=0;i<n;i++){
		string str;cin>>str;
		trie *it=(&ki);
		for(int j=0;j<str.size();j++){
			if(str[j]=='0'){it->make_zero();it=it->zero;}
			else{it->make_one();it=it->one;}
		}
	}
	llint ret=ki.solve();
	if(ret==0){cout<<"Bob"<<endl;}
	else{cout<<"Alice"<<endl;}
	RE;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int N, M, V, P;
vector<int> A;

bool f(int x) {
    int num = A[x] + M;
    int nV = V - 1;

    // Ax + M よりも最初から大きいものに投票する
    int countUp = A.end() - upper_bound(A.begin(), A.end(), num);
    nV -= countUp;

    if (nV <= 0) return countUp + 1 <= P;

    // Ai + M <= Ax + M なるAi に投票する
    rep(i, N) {
        if (i == x) continue;
        if (num <= A[i]) break;

        if (A[i] + M <= num) {
            nV--;
        }
    }

    if (nV <= 0) return countUp + 1 <= P;

    ll plus = (ll)M * nV;

    rep(i, N) {
        if (i == x) continue;
        if (num <= A[i]) break;
        if (A[i] + M <= num) continue;

        plus -= num - A[i];
    }

    if (plus <= 0) return countUp + 1 <= P;

    int i = N - 1;
    while (0 < plus) {
        if (i == x) {
            i--;
            continue;
        }
        if (A[i] + M <= num) {
            i--;
            continue;
        }
        if (num < A[i]) {
            i--;
            continue;
        }

        plus -= M - (num - A[i]);
        i--;
        countUp++;
    }

    return countUp + 1 <= P;
}

int main(){
    cin >> N >> M >> V >> P;

    A = vector<int>(N);
    rep(i, N) cin >> A[i];

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

    int l = -1, r = N;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (f(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }

    cout << N - r << endl;
}

Measured memory_bytes: 640
using System;
using static System.Console;
public class Hello{
    public static void Main(){
//        string[] a = ReadLine().Split(' ');
//        int x = int.Parse(a[0]);
//        int y = int.Parse(a[1]);
//        int z = int.Parse(a[2]);
        string b = ReadLine();
//        int count = 0;
//        if(b[0] == 'o'){ count++; }
//        if(b[1] == 'o'){ count++; }
//        if(b[2] == 'o'){ count++; }
        
        WriteLine("{0}{1}{2}",b[0],b.Length-2,b[b.Length-1]);
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
 
 
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  vector<int> vals(v[n-1]+1,0);
  for(int i=0;i<n;i++){
    for(int j=v[i];j<=v[n-1];j+=v[i]){
      vals[j]++;
    }
  }
  int ans=0;
  for(int i=0;i<v.size();i++){
    if(vals[v[i]]==1){
      ans++;
    }
  }
  cout<<ans<<endl;

  


  }
 
 
 
 

Measured memory_bytes: 7920
#include <bits/stdc++.h>
#define N 100005
#define LL long long 
#define sp " "
using namespace std;
int ar[N],n,m;
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	int a,b;
	for(int i=1;i<=m;i++)
		cin>>a>>b,ar[a]++,ar[b]++;
	for(int i=1;i<=n;i++)
	{
		if(ar[i]%2==1)
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";	
}


Measured memory_bytes: 640
import math
import sys
input = sys.stdin.readline

N = int(input())
anslist = []

if N == 0:
    print(0)
else:
    while N != 1:
        anslist.append(str(abs(N%2)))
        N = math.ceil(N/(-2))
    anslist.append('1')

print(''.join(anslist[::-1]))

Measured memory_bytes: 3060
N = int(input())
d = list(map(int, input().split()))

def delicious(x: int, y: int) -> int:
    delicious = x * y
    return delicious

total = 0
for i in range(len(d)):
    for j in range(i + 1, len(d)):
        total += delicious(d[i], d[j])

print(total)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

int main()
{
    IOS
    int n;
    cin>>n;
    int a[n+1],b[n];
    ll sum=0;
    for(int i=0;i<n+1;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(a[i]+a[i+1]<=b[i]){
            sum+=(ll)a[i]+(ll)a[i+1];
            a[i]=0;
            a[i+1]=0;
        }
        else{
            if(b[i]>=a[i]){
                sum+=(ll)a[i];
                b[i]=b[i]-a[i];
                a[i]=0;
                if(b[i]>0){
                    sum+=(ll)b[i];
                    a[i+1]-=b[i];
                }
            }
            else{
                sum+=(ll)b[i];
            }
        }
        //cout<<a[i]<<" "<<a[i+1]<<" "<<b[i]<<"\n";
        //cout<<sum<<"\n";
    }
    cout<<sum;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll k;
ll a[125252];
int cnt1[62];


int main(){
  scanf("%d%lld", &n, &k);
  REP(i,n)scanf("%lld",a+i);
  REP(i,n)REP(b,62)cnt1[b] += (a[i]>>b&1);

  ll lowbest = 0, lowless = 0;
  REP(low,1<<20){
    ll v = 0;
    REP(i,20)if(low>>i&1){
      v += ((ll)(n-cnt1[i]))<<i;
    }else{
      v += ((ll)cnt1[i])<<i;
    }
    CHMAX(lowbest, v);
    if(low <= (k&0xfffff))CHMAX(lowless, v);
  }
  ll ans = 0;
  ll hh = k>>20;
  REP(high,1<<20){
    ll v = 0;
    REP(i,20)if(high>>i&1){
      v += ((ll)(n-cnt1[i+20]))<<(i+20);
    }else{
      v += ((ll)cnt1[i+20])<<(i+20);
    }
    if(high<hh)CHMAX(ans, lowbest+v);
    if(high==hh)CHMAX(ans, lowless+v);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
#define mod 1000000007
/****************************/
using namespace std;
ll n;
ll a[200010];
int main()
{
	cin>>n;
	ll ans=0;
	ll cnt;
	cin>>a[0];
	cnt=a[0];
	rep3(i,1,n)
	{
		cin>>a[i];
		ans+=(cnt%mod)*(a[i]%mod);
		ans%=mod;
		cnt+=a[i];
	}
	ans%=mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5148
n,p = gets.split.map(&:to_i)
ans = []
while n !=0 && p !=0
	i = 0
	tmp = p
	a = Array.new(n,0)
	while p != 0 
		if tmp != 0
			a [i] += 1
			tmp -= 1
		elsif tmp == 0 && a[i] == p
			break
		else
			tmp = a[i]
			a[i] = 0
		end
		i = i + 1
		i = 0 if i == n
	end
	ans.push(i)
	n,p = gets.split.map(&:to_i)
end
puts ans

Measured memory_bytes: 8604
package main

import (
	"fmt"
)

func main() {
	var n, m, x int
	fmt.Scan(&n, &m, &x)

	arr := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&arr[i])
	}

	costToEnd := 0
	costToStart := 0
	for _, e := range arr {
		if e < x {
			costToStart++
		} else {
			costToEnd++
		}
	}

	if costToStart < costToEnd {
		fmt.Println(costToStart)
	} else {
		fmt.Println(costToEnd)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
template<typename T>
vector<T> divisor(T N) {
    vector<T> res;
    for(T i = 2; i * i <= N; i++){
        if(N % i == 0){
            res.push_back(i);
            if(i * i != N)res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
template<typename T> 
map<T,int> factorize(T x){
    map<T,int> mp;
    for (T i = 2; i*i <= x; i++){
        while (x%i == 0) {
            x /= i;
            mp[i]++;
        }
        if (x == 1) break;
    }
    if (x != 1) mp[x]++;
    return mp;
}


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

    ll N;
    cin >> N;
    if(N == 1){
        cout << 0 << endl;
        return 0;
    }
    vec<ll> sum(100);
    sum[0] = 1;
    for(int i = 1; i < 100; i++){
        sum[i] = sum[i-1] + (i+1);
    }
    auto v = factorize(N);
    ll ans = 0;
    for(auto &p: v){
        int cnt = p.second;
        int idx = upper_bound(all(sum), cnt) - sum.begin();
        ans += idx;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

typedef long long ll;

const ll mod = 1000000007;
ll M, N;
vector<ll > p;
vector<ll > factorial;

ll square(ll x){
    return (x * x) % mod;
}

ll pow(ll x, ll y){
    if(y == 0) return 1;
    if(y == 1) return x % mod;
    x %= mod;
    if(y % 2 == 1) return (pow(square(x), y/2) * x) % mod;
    else return pow(square(x), y/2) % mod;
}

ll nCr(ll n, ll r){
    ll rev_n = pow(factorial[r], mod - 2);
    ll rev_nr = pow(factorial[n-r], mod - 2);
    ll ans = (((factorial[n] * rev_n) % mod) * rev_nr) % mod;
    return ans;
}


int main(){
    cin >> N >> M;
    for(ll i = 2; i <= (ll) sqrt(M) + 2; i ++){
        bool flag = true;
        for(ll j = 2; j < i; i++){
            if(i % j == 0) flag = false; break;
        }
        if(flag) p.push_back(i);
    }
    vector<ll > ind;
    ll tmp_M = M;
    ll max_ind = 0;
    for(ll i = 0; i < p.size(); i++){
        ll tmp_ind = 0;
        ll tmp_p = p[i];
        while(tmp_M % tmp_p == 0){
            tmp_ind += 1;
            tmp_M /= tmp_p;
        }
        if(tmp_ind > 0){
            //cout << "p: " << tmp_p << ", index: " << tmp_ind << endl;
            if(tmp_ind > max_ind) max_ind = tmp_ind;
            ind.push_back(tmp_ind);
        }
    }
    if(tmp_M > 1) ind.push_back(1);

    factorial.push_back(1);
    for(int i = 1; i <= N + 2 * max_ind; i ++){
        ll next_fact = (factorial[i-1] * (i % mod)) % mod;
        factorial.push_back(next_fact);
    }


    ll ans;
    ans = 1;
    for(ll i = 0; i < ind.size(); i++){
        //cout << ind[i] + N - 1 << "C" << N - 1 << " = " << nCr(ind[i] + N - 1, N - 1) << endl;
        ans *= nCr(ind[i] + N - 1, N - 1);
        ans %= mod;
    }

    ans %= mod;

    cout << ans << endl;

}


Measured memory_bytes: 1528