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

const int MAXN = 300010;
int W, H, n, ans;
struct _ { int x, y; } ps[MAXN];
int tag[MAXN << 3], tree[MAXN << 3], li[MAXN << 1], bak;
void mkadd(int u, int v) { tree[u] += v, tag[u] += v; }
void pushdown(int u) {
	if (int & t = tag[u]) {
		mkadd(u << 1, t);
		mkadd(u << 1 | 1, t);
		t = 0;
	}
}
void mdf(int u, int l, int r, int L, int R, int v) {
	if (L <= l && r <= R) return mkadd(u, v);
	int mid = l + r >> 1;
	pushdown(u);
	if (L <= mid) mdf(u << 1, l, mid, L, R, v);
	if (mid < R) mdf(u << 1 | 1, mid + 1, r, L, R, v);
	tree[u] = std::max(tree[u << 1], tree[u << 1 | 1]);
}
int qry(int u, int l, int r, int L, int R) {
	if (L <= l && r <= R) return tree[u];
	int mid = l + r >> 1, res = 0;
	pushdown(u);
	if (L <= mid) res = qry(u << 1, l, mid, L, R);
	if (mid < R) res = std::max(res, qry(u << 1 | 1, mid + 1, r, L, R));
	return res;
}
_ sl[MAXN], sr[MAXN]; int tl, tr;
void solve() {
	const int mx = W + 1 >> 1;
	memset(tree, 0, sizeof tree);
	memset(tag, 0, sizeof tag);
	std::sort(ps + 1, ps + 1 + n, [] (_ a, _ b) { return a.y < b.y; });
	for (int i = 1; i <= bak; ++i) mdf(1, 1, bak, i, i, W - li[i]);
	sl[tl = 1] = (_) {mx, 1}, sr[tr = 1] = (_) {mx + 1, 1};
	int cur = 1;
	for (int i = 1; i <= bak && li[i] <= H; ++i) {
		ans = std::max(ans, qry(1, 1, bak, 1, i) + li[i]);
		while (cur <= n && ps[cur].y == i) {
			bool b = li[ps[cur].x] <= mx;
			int & top = b ? tl : tr; _ * st = b ? sl : sr;
			mdf(1, 1, bak, st[top].y, bak, b ? -mx : mx - W);
			while (top > 1 && (b ? st[top].x <= ps[cur].x : st[top].x >= ps[cur].x)) {
				mdf(1, 1, bak, st[top - 1].y, st[top].y - 1, -std::abs(mx - li[st[top].x]));
				--top;
			}
			if (ps[cur].y > st[top].y) {
				st[++top] = ps[cur];
				mdf(1, 1, bak, st[top - 1].y, st[top].y - 1, std::abs(mx - li[st[top].x]));
			}
			mdf(1, 1, bak, st[top].y, bak, b ? mx : W - mx);
			++cur;
		}
	}
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> W >> H >> n; ans = std::max(H, W) + 1;
	for (int i = 1; i <= n; ++i) std::cin >> ps[i].x >> ps[i].y;
	for (int i = 1; i <= n; ++i) li[++bak] = ps[i].x;
	for (int i = 1; i <= n; ++i) li[++bak] = ps[i].y;
	li[++bak] = 0, li[++bak] = H, li[++bak] = W;
	std::sort(li + 1, li + 1 + bak);
	bak = std::unique(li + 1, li + 1 + bak) - li - 1;
	for (int i = 1; i <= n; ++i)
		ps[i].x = std::lower_bound(li + 1, li + 1 + bak, ps[i].x) - li;
	for (int i = 1; i <= n; ++i)
		ps[i].y = std::lower_bound(li + 1, li + 1 + bak, ps[i].y) - li;
	solve();
	std::swap(H, W);
	for (int i = 1; i <= n; ++i) std::swap(ps[i].x, ps[i].y);
	solve();
	std::cout << ans * 2 << std::endl;
	return 0;
}


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

int mod = 1e9 + 7;
int add(int a, int b){
    return (a + b % mod) % mod;
}

int sub(int a, int b){
    return (a + mod - b % mod) % mod;
}

int dp[102][100002];
int main(){
  ios::sync_with_stdio(0);
  int n, k; cin >> n >> k;
  vector<int>a(n);
  for(int i = 0; i < n; i++)
    cin >> a[i];

  dp[n][0] = 1;
  for(int i = n - 1; i >= 0; i--){
    for(int j = 0; j <= k; j++){
      int low = max(0, j - a[i]);
      dp[i][j] = add(dp[i][j], sub(dp[i + 1][j], (low ? dp[i + 1][low - 1] : 0)));
      if(j)
        dp[i][j] = add(dp[i][j], dp[i][j - 1]);
    }
  }
  cout << dp[0][k] << endl;
  return 0;
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
signed main(){
    fast();
    int n, ans = 0;
    cin >> n;
    for(int i=0, j; i<n; i++){
        cin >> j;
        if(j&1 && i%2 == 0)     ans++;
    }
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int p = 0;
    String ans = "Yes";
    for(int i = 0; i < n; i++) {
      int h = sc.nextInt();
      if(h > p) {
        h--;
        p = h;
      } else if(h == p) {
      
      } else {
        ans = "No";
        break;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 47760
program max_min_sums
    implicit none
    integer(8):: n, k, i, smax, smin
    integer(8), parameter:: mod_ = 1000000007
    integer(8), allocatable:: a(:), fac(:), finv(:)
    ! import --------------------------
    read*, n, k
    allocate(a(n), fac(0:n), finv(0:n))
    read*, a(:)
    ! init_combination table
    call com_init(fac(:), finv(:), mod_)

    ! sort a --------------------------
    call marge_sort(a(:), 1_8, n)
    smax = 0; smin = 0
    do i=1,n; block; integer(8):: mi, cof
        mi = n-i+1
        cof = comb(i-1, k-1)
        smax = mod(smax + cof*a(i), mod_)
        smin = mod(smin + cof*a(mi), mod_)
    end block; end do

    print*, mod(smax - smin, mod_)

contains
recursive subroutine marge_sort(arr, first, last)
    integer(8):: arr(:), first, last
    integer(8):: mean, tmp

    if (last - first <= 1) then
        ! sort
        if (arr(last) < arr(first)) then
            tmp = arr(last)
            arr(last) = arr(first)
            arr(first) = tmp
        end if
        return
    end if

    !  only : (last - first) > 1
    mean = (first + last) / 2
    call marge_sort(arr, first, mean)
    call marge_sort(arr, mean+1, last)
    call marge(arr, first, last, mean)
end subroutine


subroutine marge(arr, first, last, mean)
    integer(8):: arr(:), first, last, mean
    integer(8):: il, ir, i
    integer(8), allocatable:: tmp(:)

    allocate(tmp(last-first+1))
    il = first
    ir = mean+1
    i = 1

    do while (il <= mean .and. ir <= last)
        if (arr(il) <= arr(ir)) then
            tmp(i) = arr(il)
            i = i+1
            il = il+1
        else
            tmp(i) = arr(ir)
            i = i+1
            ir = ir+1
        end if        
    end do

    if (il > mean)then
        tmp(i:) = arr(ir:last)
    else
        tmp(i:) = arr(il:mean)
    end if
    arr(first:last) = tmp(:)
    end subroutine


    subroutine com_init(fac, finv, mod_)
        integer(8):: fac(0:), finv(0:), mod_
        integer(8):: i

        fac(0:1) = 1
        finv(0:1) = 1


        do i=2, size(fac(1:))
            fac(i) = mod(fac(i-1)*i, mod_)
            finv(i) = calc_inv(fac(i), mod_)             
        end do
    end subroutine


    function comb(n, k) result(ret)
        integer(8):: ret, n, k
        if(n<k) then
            ret = 0
        else if(n < 0 .or. k < 0) then
            ret = 0
        else
            ret = mod(fac(n)*mod(finv(k)*finv(n-k), mod_), mod_)
        end if        
    end function


    function calc_inv(i,mod_) result(inv)
        integer(8):: i, mod_, inv
        integer(8):: lev, a
        lev = mod_ - 2
        inv = 1
        a = i

        do while(lev /= 0)
            if(mod(lev, 2)/=0) inv = mod(inv*a, mod_)
            lev = lev/2
            a = mod(a*a, mod_)
        end do
    end function


end program max_min_sums

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t n;
  cin>>n;
  if(n%2!=0)
  {
    cout<<0<<endl;
    return 0;
  }
  int64_t ans=0,cnt=5;
  while(cnt<n)
  {
    ans+=(n/cnt)/2;
    cnt*=5;
  }
  cout<<ans<<endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1010;




int n, k;



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

    cin>>n>>k;
    vector<int> v(n);
    for (int i=0; i<n; i++) {
	cin>>v[i];
    }

    sort(v.begin(), v.end());
    v.resize(k);
    cout<<accumulate(v.begin(),v.end(),0)<<endl;
    
    
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i += 2){
        int cnt = 0;
        for(int j = 1; j <= i; j++){
            if(i%j == 0) cnt++;
        }
        if(cnt == 8) ans++;
    }

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

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  int n,x,kumi;
  while(1){
    kumi=0;
    scanf("%d %d",&n,&x);
    if(n==0&&x==0)break;
    for(int a=1;a<=n;a++){
      for(int b=1;b<=n;b++){
	if(a==b)continue;
	for(int c=1;c<=n;c++){
	  if(b==c||a==c)continue;
	  if(a+b+c==x)kumi++;
	}
      }
    }
    printf("%d\n",kumi/6);
  }
  return 0;
}

Measured memory_bytes: 2668
N = int(input())
A = list(map(int,input().split()))
jud = 0
cnt = 0
while True:
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
            jud += 1
        else:
            continue
    if jud == N:
        cnt += 1
        jud = 0
        continue
    else:
        break
print(cnt)

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

int main(void) {
    int x1,x2,x3,x4,x5;cin>>x1>>x2>>x3>>x4>>x5;
    if (x1 == 0) cout << 1 << endl;
    else if (x2 == 0) cout << 2 << endl;
    else if (x3 == 0) cout << 3 << endl;
    else if (x4 == 0) cout << 4 << endl;
    else if (x5 == 0) cout << 5 << endl;

    return 0;
}

Measured memory_bytes: 3164
N = int(input())
H = list(map(int, input().split())) + [10**10]

cnt = -1
pre = 10**10
ans = -1

for h in H:
    if pre >= h:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
    pre = h
print(ans)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
inline long long int read()
{
    char c=getchar();
    long long int x=0,f=1;
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
int main()
{
    int n = read(),f = 0;
    for(int i = 0; i < n; i++)
    {
        if(f == 1) continue;
        int a = read();
        if(a%2 == 0)
        {
            if(a%3 == 0 ||a%5 == 0) ;
            else f = 1;
        }
    }
    if(f == 0) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
# 左から取り出すパターンは最大50通り
# 右から取り出すパターンは最大50通り
# その組み合わせは2500通り
# その全通りに対して、マイナスの石を引けるだけ引くパターンを試すと50
# 125000
# すべて試す

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
V = [0] + list(map(int,readline().split())) + [0]
N += 2
K += 2

leftsum = 0
leftminus = []
ans = -(10 ** 9)
for left in range(min(N,K)):
  leftsum += V[left]
  if V[left] < 0:
    leftminus += [V[left]]
  rightsum = 0
  rightminus = []
  limit = min(N - (left + 1) , K - (left + 1))
  for right in range(N - 1, N - limit - 1, -1):
    rightsum += V[right]
    if V[right] < 0:
      rightminus += [V[right]]
    allsum = leftsum + rightsum
    rest = max(K - ((left + 1) + (N - right)),0)
    allminus = sorted(leftminus + rightminus)
    allsum -= sum(allminus[:rest])
    if allsum > ans:
      ans = allsum
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n,k,x,y; cin >> n >> k >> x >> y;
    if(n<=k) out(n*x);
    else out(x*k+(n-k)*y);

    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N, M;
vector<long long> A;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	long long tot = 0;
	for(int i=0; i<M; i++){
		long long a;
		cin >> a;
		A.push_back(a);
		tot += a;
	}
	if(tot > N){
		printf("-1\n");
	}
	else{
		printf("%lld\n", N - tot);
	}
	return 0;
}

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP (i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector <vector<int>>;
using vvll = vector <vector<ll>>;

#define inf(T) (numeric_limits<T>::max() / 2)
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;

template<typename T>
void warshall_floyd(vector<vector<T>> &g) {
    const T INF = numeric_limits<T>::max();
    int n = g.size();
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (g[i][k] == INF or g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

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

    for (;;) {
        int n, m, s, g1, g2;
        cin >> n >> m >> s >> g1 >> g2;
        --s, --g1, --g2;
        if (n == 0) break;

        vvi G(n, vi(n, numeric_limits<int>::max()));
        REP (i, n) G[i][i] = 0;
        REP (i, m) {
            int u, v, c;
            cin >> u >> v >> c;
            --u, --v;
            G[u][v] = c;
        }

        warshall_floyd(G);

        int ans = inf(int);

        REP (i, n) {
            if (G[s][i] >= inf(int) or G[i][g1] >= inf(int)
                or G[i][g2] >= inf(int)) continue;

            chmin(ans, G[s][i] + G[i][g1] + G[i][g2]);
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a + b == 3) {
			System.out.println(3);
		}
		if(a + b == 4) {
			System.out.println(2);
		}
		if(a + b == 5) {
			System.out.println(1);
		}

		sc.close();



	}

}


Measured memory_bytes: 21844
import sys
import math


def sin(x):
    return math.sin(math.radians(x))


def cos(x):
    return math.cos(math.radians(x))


A, B, H, M = map(int, sys.stdin.readline().strip().split())

Ay = A * sin(90 - (360/12 * H + (360/12)/60 * M))
Ax = A * cos(90 - (360/12 * H + (360/12)/60 * M))
By = B * sin(90 - 360/60 * M)
Bx = B * cos(90 - 360/60 * M)

distance = math.sqrt((Ax - Bx) ** 2 + (Ay - By) ** 2)
print(distance)

Measured memory_bytes: 9528
#include <iostream>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main() {
	ll n;
	priority_queue<ll, vector<ll>, greater<ll>> a;
	cin >> n;
	ll temp;
	for (int i = 0; i < 5; i++) {
		cin >> temp;
		a.push(temp);
	}
	ll division;
	if (n % a.top() == 0)
		division = n / a.top();
	else
		division = n / a.top() + 1;
	cout << division + 4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int ds;
	int a;
	int b;
	int c;
	int i;
	
	scanf("%d", &ds);
	
	for (i = 1; i <= ds; i++){
		scanf("%d %d %d", &a, &b, &c);
		if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[1000007]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
*/
using namespace std;
signed main(){
  fast;
  //usefile;
  //test
  {
    int n,a,b;
    cin>>n>>a>>b;
    int ans=(n/(a+b))*a+min(a,n%(a+b));
    cout<<ans<<endl;


  }
  //time("");
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
l=list(map(int,input().split()))
maxi=0
suml=sum(l[:k])
maxl=sum(l[:k])
for i in range(n-k):
    if suml-l[i]+l[k+i]>maxl:
        maxl=suml-l[i]+l[k+i]
        maxi=i+1
    suml=suml-l[i]+l[k+i]
sumsum=0
for j in range(maxi,maxi+k):
    sumsum+=(l[j]+1)/2
print(sumsum)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int ans = (x - z) / (y + z);
  cout << ans << endl;
  return 0;
}


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

aa = set(A)
ans = 1
for i in range(len(A)):
    if(ans > 10**18):
        if(0 not in aa):
            ans = -1
            break
        else:
            ans = 0
    ans *= A[i]

if(ans > 10**18):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 21576
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

ll dp[20010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll h, n;
  cin >> h >> n;
  vll a(n), b(n);
  rep(i, n){
    cin >> a[i] >> b[i];
  }
  repr(i, 10001, 20010){
    dp[i] = INF;
  }
  repr(i, 10001, h+10001){
    
    rep(j, n){
      chmin(dp[i], dp[i-a[j]]+b[j]);
    }
  }
  print(dp[10000+h]);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll m,d;

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

  cin>>m>>d;
  ll res=0;
  repl(i,1,m+1){
    repl(j,10,d+1){
      if((j%10)>=2&&(j/10)>=2&&(j%10)*(j/10)==i){
        res++;
      }
    }
  }
  cout<<res<<endl;

  return 0;
}


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

int main() {
  string a; cin >> a;
  if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3]))
    cout << "Yes" << endl;
  else cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
//#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>

const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int a;string s;
    cin>>a>>s;
    cout<<(a>=3200?s:"red")<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const double EPS = 1e-9;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

long double compute_prob(int K, int n){
    long double p = 1.0;
    while(n < K){
        n *= 2;
        p *= 0.5;
    }

    return p;
}

int main(void){
    int N, K;

    cin >> N >> K;

    long double p = 0;

    For(n, 1, N + 1){
        p += compute_prob(K, n) / N;
    }

    cout << std::setprecision(20) << p << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll> A(N);
  vector<vector<ll> > BC(M);
  FORi(N){
    cin>>A[i];
  }
  FORi(M){
    vector <ll> tmp(2);
    cin>>tmp[0]>>tmp[1]; 
    BC[i]=tmp;
  }
  vector<ll> A2(N);
  sort(BC.begin(),BC.end(),[](auto n,auto m){return n[1]>m[1];});
  sort(A.rbegin(),A.rend());
  ll ii=0;
  FORi(M){
    for(ll j=0;j<BC[i][0];++j){
      if(ii+j>=N)break;
      A2[ii+j]=BC[i][1];
    }
    ii+=BC[i][0];
    if(ii>=N)break;
  }
  ll sum=0;
  FORi(N){
    sum+=max(A[i],A2[N-1-i]);
  }
  cout<<sum<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

void solve() {
  int n;
  cin >> n;

  vector<ll> a(n);
  map<int, int> cnt;

  ll sum = 0;

  for (auto i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }

  int q;
  cin >> q;

  for (auto i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;

    sum += (cnt[b])*(c-b);
    cnt[c] += cnt[b];
    cnt[b] = 0;

    print(sum);
  }
}

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  solve();

  return 0;
}


Measured memory_bytes: 8376
import itertools
def main():
    N,K = map(int, input().split())
    MOD = pow(10,9)+7

    # 和としてありうる種類数が知りたい
    # 10^100が非常に大きいので、選ぶ個数が異なる時、必ず和は異なる事が分かるので、
    # 10^100を取り除いて、0,1,2,...,N-1,N という要素数(N+1)の数列からm個とるときに、
    # ありうる和の種類数を求めて、K<=m<=N+1でシグマすると考えられる
    # ここで、数列からm個とる時の和でありうるのは、
    # 最小値: 小さい順にm個 -> 0+1+...+(m-1) = m*(m-1)/2
    # 最大値: 大きい順にm個 -> N+(N-1)+...+(N-m+1) = m*(2N-m+1)/2
    # さらに、最小値から最大値までは全ての数を作る事が可能なので、
    # (求める値) = Σ(K<=m<=N+1){(N-m+1)*m+1}

    ans  = 0
    for m in range(K,N+2):
        ans += ((N-m+1)*m+1)%MOD
    print(ans%MOD)


main()


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

int n, m;
vector<int> e[8];
bool saw[8];
int ans = 0;

void dfs(int v, int d){
    saw[v] = true;
    if(d == n){
        ans++;
        saw[v] = false;
        return;
    }
    rep(i,e[v].size()){
        if(saw[e[v][i]]) continue;
        dfs(e[v][i],d+1);
    }
    saw[v] = false;
}

int main(){
    I(n,m);
    rep(i,m){
        int a, b; cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    dfs(0,1);
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
s = input()
t = input()

ans = len(s) + len(t)
index = 0
tmp = 0
for i in range(len(s)):
    if s[-i - 1] == t[index]:
        index += 1
        for j in range(len(s) - i, len(s)):
            if s[j] == t[index]:
                index += 1
            else:
                break
        tmp = max(tmp, index)
        index = 0


print(ans - tmp)

Measured memory_bytes: 3064
#!/bin/bash

read input

hoge+=$input

if [ ${hoge:0:1} -eq ${hoge:1:1} ] || [ ${hoge:2:1} -eq ${hoge:3:1} ] && [ ${hoge:1:1} -eq ${hoge:2:1} ]
then
  echo "Yes"
else
  echo "No"
fi

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

 using namespace std;

 int main() {
   string S;

   cin >> S;

   if (stoi(S.substr(0, 2)) > 12 && stoi(S.substr(2, 2)) > 12) cout << "NA" << endl;
   else if (stoi(S.substr(0, 2)) > 12) {
     if (S.substr(2, 2) == "00") cout << "NA" << endl;
     else cout << "YYMM" << endl;
   }
   else if (stoi(S.substr(2, 2)) > 12) {
     if (S.substr(0, 2) == "00") cout << "NA" << endl;
     else cout << "MMYY" << endl;
   }
   else if (S.substr(0, 2) == "00") {
     if (S.substr(2, 2) == "00") cout << "NA" << endl;
     else cout << "YYMM" << endl;
   }
   else if (S.substr(2, 2) == "00") cout << "MMYY" << endl;
   else cout << "AMBIGUOUS" << endl;

}


Measured memory_bytes: 384
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
A = map(int, raw_input().split())

DP = [0] + [-1] * N
ans = [0] * N + [0]

for i in range(1, N + 1):
    for j in range(10)[::-1]:
        if not j in A:
            continue
        if cost[j] > i:
            continue
        if DP[i - cost[j]] < 0:
            continue
        if DP[i] < DP[i - cost[j]] + 1:
            DP[i] = DP[i - cost[j]] + 1
            ans[i] = j

S = ""
pos = N
while pos != 0:
    S += str(ans[pos])
    pos -= cost[ans[pos]]

print S

Measured memory_bytes: 3448
package main

import "fmt"

func main() {
	a := make([]int, 5)
	for i := range a {
		fmt.Scan(&a[i])
	}
	min := 10
	for i := range a {
		if a[i]%10 < min && a[i]%10 != 0 {
			min = a[i] % 10
		}
	}
	var ans int
	for _, v := range a {
		ans += (v + 9) / 10 * 10
	}
	fmt.Println(ans - 10 + min)
}


Measured memory_bytes: 512
import bisect
from itertools import product

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(input())
    idx1, idx2 = bisect.bisect_left(S, x), bisect.bisect_left(T, x)
    s_cand = [S[idx1 - 1], S[idx1]]
    t_cand = [T[idx2 - 1], T[idx2]]
    dist = INF
    for s, t in product(s_cand, t_cand):
        temp = min(abs(s - x), abs(t - x)) + abs(s - t)
        dist = min(dist, temp)
    print(dist)

Measured memory_bytes: 12824
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
 
  ll n;
  cin >> n;
  /*int test=0;
  int root_n = sqrt(n);
  for(int i = 2; i<root_n; i++){
    if(n%i==0) {
      test=i;
      break;
    }
    else continue;
  }*/

  cout << n*(n-1)/2;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long int L[100];
	long long int N;
	cin >> N;
	 L[0] = 2;
	 L[1] = 1;
	 for (int i = 0; i < 99; i++) {
		 L[i + 2] = L[i] + L[i + 1];
	 }
	 cout << L[N] << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
using namespace std;
struct node{
	int p,num;
}a[100007];
int find(int x)
{
	if(a[x].p==x&&a[x].num==0){
		return x;
	}
	else 
	{
		int t=find(a[x].p);
		a[x].num=a[a[x].p].num+a[x].num;
		a[x].p=t;
		return t;
	}
}
int main()
{
	int n,m,i;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		a[i].p=i;a[i].num=0;
	}
		
	for(i=1;i<=m;i++)
	{
		int l,r,x;
		scanf("%d%d%d",&l,&r,&x);
		int pl=find(l),pr=find(r);
		if(pl!=pr)
		{
			if(pl>pr)
			{
				a[pl].p=pr;
				a[pl].num=-(a[l].num-a[r].num+x);
			}
			else 
			{
				a[pr].p=pl;
				a[pr].num=a[l].num-a[r].num+x;
			}
		}
		else{
			if(a[r].num-a[l].num!=x)
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main(){
    long long h,w;
    cin >> h >> w;
    if(h == 1 || w == 1) cout << 1 << endl;
    else{
        if(h%2 == 1 && w%2 == 1) cout << (h*w-1)/2 + 1 << endl;
        else cout << h*w/2 << endl;
    }
}


Measured memory_bytes: 256
import java.math.BigInteger;

public class Main {
  private static void solve() {
    int n = ni();
    int[] a = na(n);
    
    BigInteger ret = BigInteger.valueOf(1L);
    BigInteger sub = BigInteger.valueOf(1L);

    BigInteger v3 = BigInteger.valueOf(3L);

    for (int v : a) {
      ret = ret.multiply(v3);
      int count = 0;
      for (int x = Math.max(0, v - 1); x <= v + 1; x ++) {
        if (x % 2 == 1) {
          count ++;
        }
      }
      sub = sub.multiply(BigInteger.valueOf(count));
    }
    
    System.out.println(ret.subtract(sub));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 21588
#include<bits/stdc++.h>
//#include "/Users/student/Documents/Sublime/stdc++.h"

typedef unsigned long long ll;

using namespace std;

#define MOD (ll)1000000007

ll arr[1000000], powers[100];

int main() {
//    freopen("input.in", "r", stdin);
//    freopen("output.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    powers[0] = 1;
    for(int i = 1; i <= 60; i++){
        powers[i] = (powers[i-1]*2)%MOD;
    }

    ll n;
    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> arr[i];
    }
    ll sum = 0;
    for(ll i = 0; i < 60; i++){
        ll oc = 0, zc = 0;
        for(ll j = 0; j < n; j++){
            if(arr[j]%2 == 0){
                zc++;
            }
            else{
                oc++;
            }
            arr[j] = arr[j]/2;
        }
        sum = ( (sum%MOD) + ( ( ( (oc%MOD) * (zc%MOD) )%MOD) * (powers[i]%MOD) )%MOD )%MOD;
    }
    cout << sum;
}

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

int main () {
	int sn, tn, t, l, r, m, c = 0;
	cin >> sn;
	int *s = new int[sn];
	for (int i = 0; i < sn; i++)
		cin >> s[i];
	cin >> tn;
	for (int i = 0; i < tn; i++) {
		cin >> t;
		l = 0;
		r = sn + 2;
		while(l < r) {
			m = (l + r) / 2;
			if (s[m] == t) {
				c++;
				break;
			}
			else if (t < s[m])
				r = m;
			else
				l = m + 1;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3416
N=int(input())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
cnt=0
for i in reversed(range(N)):
    if(A[i]%B[i]==0):
        cnt+=0
    elif(A[i]<B[i]):
        cnt+=B[i]-A[i]
    elif(A[i]>B[i]):
        cnt+=B[i]-(A[i]%B[i])
    if(i>0):
        A[i-1]+=cnt
print(cnt)

Measured memory_bytes: 14988
class SegmentTree:
    def __init__(self, lis, ele, op):
        self.len = len(lis)
        self.n = 1 << ((self.len - 1).bit_length())
        self.op = op
        self.ele = ele
        self.tree = self._build(lis)
    def _build(self, lis):
        res_tree = [self.ele] * (self.n - 1) + lis + [self.ele] * (self.n - self.len)
        for i in range(self.n - 2, -1, -1):
            res_tree[i] = self.op(res_tree[i * 2 + 1], res_tree[i * 2 + 2])
        return res_tree
    def __get__(self, i):
        return self.tree[self.n + i - 1]
    def update(self, i, x):
        i += self.n - 1
        self.tree[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.tree[i] = self.op(self.tree[i * 2 + 1], self.tree[i * 2 + 2])
    def query(self, l, r):
        l +=  self.n - 1
        r += self.n - 1
        L = self.ele
        R = self.ele
        while l < r:
            if l & 1 == 0:
                L = self.op(L, self.tree[l])
                l += 1
            if r & 1 == 0:
                r -= 1
                R = self.op(R, self.tree[r])
            l -= 1
            l >>= 1
            r >>= 1
        return self.op(L, R)
n, k = map(int, input().split())
ST = SegmentTree([0] * 600000, 0, max)
for i in range(n):
    a = int(input())
    res = ST.query(max(0, a - k), min(600000, a + k + 1))
    ST.update(a, res + 1)
print(ST.tree[1])

Measured memory_bytes: 134448
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 1; i <= n; i++)
		{
			int x = i;
			if (i % 3 == 0)
			{
				System.out.print(" " + i);
				continue;
			}
			
			do
			{			
				
				if (x % 10 == 3)
				{
					System.out.print(" " + i);
					break;
					
				}
				x=x/10;
			}while(x>0);
		}
		System.out.println("");

	}

}

Measured memory_bytes: 28564
# ABC133C - Remainder Minimization 2019
def main():
    L, R = list(map(int, input().rstrip().split()))
    MOD = 2019
    if (R // MOD) - (L // MOD) > 0:  # L <= 2019n <= R
        print(0)
    else:
        ans = float("inf")
        for i in range(L, R):
            for j in range(i + 1, R + 1):
                i, j = i % MOD, j % MOD
                ans = min(ans, (i * j) % MOD)
        print(ans)


if __name__ == "__main__":
    main()

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

#define NAME "L - Deque"
#define show(x) cout << (#x) << " is " << (x) << endl
#define ll long long
#define ms(arr,val) memset(arr,val,sizeof(arr))
#define len length()

const int maxn = 3e3;
ll dp[maxn][maxn];
int a[maxn];
int n;
ll cal(int l, int r){
    if(dp[l][r]!=LLONG_MIN) return dp[l][r];
    if (l==r) return dp[l][r] = a[l];
    return dp[l][r] = max(a[l]-cal(l+1,r), a[r]-cal(l,r-1) );
}

int main(){
    //ifstream cin(NAME".inp");
    //ofstream cout(NAME".out");
    cin>>n;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++) dp[i][j]=LLONG_MIN;
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<cal(0,n-1)<<endl;

}


Measured memory_bytes: 74072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);

int main() {
    ios;
    int n;
    cin>>n;
    vector<int>v,v1,vv;
    
    f(i,0,n)
    {
        int x;cin>>x;
        v.pb(x);
    }
    f(i,0,n)
    {
        int x;cin>>x;
        v1.pb(x);
    }
    f(i,0,n)
    vv.pb(i+1);
  int c=2; int a,b,cc=1;
     while(c!=0)
     {
          if(vv==v)c--,a=cc;
          if(vv==v1)c--,b=cc;
          next_permutation(vv.begin(),vv.end());
          cc++;
     }
     cout<<abs(b-a);
}

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

using namespace std;

const int MAX_N = 105;

int h,w,dp[MAX_N][MAX_N][2];
bool a[MAX_N][MAX_N];

int f(int i, int j, bool p)
{
	int cost = a[i][j] != p && p;	
	if (i == h && j == w)
		return cost + a[i][j];
	if (dp[i][j][p] != -1)
		return dp[i][j][p];
	int ans = INT_MAX;
	if (i < h)
		ans = f(i+1,j,a[i][j]);
	if (j < w)
		ans = min(ans,f(i,j+1,a[i][j]));
	return dp[i][j][p] = ans + cost;
}

int main()
{
	scanf("%d %d",&h,&w);
	char s[MAX_N];
	for (int i=1; i<=h; i++)
	{
		scanf("%s",s+1);
		for (int j=1; j<=w; j++)
		{
			a[i][j] = s[j] == '#';
			dp[i][j][0] = dp[i][j][1] = -1;
		}
	}
	int ans = f(1,1,a[1][1]^1);
	if (!a[1][1])
		ans--;
	printf("%d\n", ans);
	return 0;
}

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

typedef long long ll;

int N,M;
ll A[100010];
ll app[200020] = {0},dis[200020] = {0} ,num[200020] = {0};
ll neg[200020] = {0};
ll ans = 0;

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < N; i++)scanf("%d",&A[i]);
    for(int i = 1; i < N; i++)
    {
        int length,l = A[i - 1],r = A[i];
        if(l <= r)length = r - l;
        else length = M + (r - l);
        ans += length;
        if(length < 2)continue;
        int s = l + 1;
        num[s + length - 1] += length - 1;
        app[s]++;
        dis[s + length - 1]--;
    }
    ll now = 0,dif = 0;
    for(int i = 0; i < M * 2 + 10; i++)
    {
        neg[i] = now;
        now -= num[i];
        dif += app[i];
        dif += dis[i];
        now += dif;
    }
    ll sum = 0;
    for(int i = 1; i < M + 1; i++)
    {//printf("%d %d\n",i,neg[i] + neg[i + M]);
        sum = max(sum,neg[i] + neg[i + M]);
    }
    printf("%lld\n",ans - sum);
    return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> sum(n+1);
    
    for (int i = 0; i < n; i++) {
        sum[i+1] = sum[i]+i+1;
    }
    
    ll index = distance(sum.begin(),lower_bound(sum.begin(),sum.end(),n));
    
    for (int i = 1; i <= index; i++) {
        if(i!=sum[index]-n){
            std::cout << i << std::endl;
        }
    }
}
 

Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

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

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

//nCr
ll combination(ll n, ll r) {

  ll i, p = 1;

  for(i=1; i<=r; ++i) {
    p = p*(n-i+1)/i;
  }

  return p;
}

ll A[200001];
ll B[200001];
map<ll, ll> M;

int main() {

  ll N;
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    B[i] = A[i];
  }

  sort(A, A+N);

  ll res = 0;
  ll t = A[0];
  ll cnt = 1;
  for(ll i=1; i<N; ++i) {
    if(t==A[i]) {
      ++cnt;
    }else {
      M[t] = cnt;
      res += combination(cnt, 2);
      t = A[i];
      cnt = 1;
    }
  }

  M[t] = cnt;
  res += combination(cnt, 2);
  rep(i, N) {
    cout << res-combination(M[B[i]], 2)+combination(M[B[i]]-1, 2) << endl;
  }

  return 0;
}


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

int main() {
    int K, a, b;
    string ret = "NG";

    cin >> K >> a >> b;

    for(int i = a; i <= b; i++) {
        if(i % K == 0) {
            ret = "OK";
            break;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3628