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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll x,y,z; cin>>x>>y>>z;

    swap(x,y); swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();


      if(n<1200){
        System.out.println("ABC");
      }
      if(n>=1200&&n<2800){
        System.out.println("ARC");
      }
      if(n>=2800){
        System.out.println("AGC");
      }

      }

  }


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define pb push_back
#define pob pop.back()
#define forn  for(int i=0;i<n;i++)
int main()
{
 int n;
 cin>>n;
 int a,b;
 if(n==1) cout<<"Hello World";
 else {
     cin>>a>>b;cout<<a+b;}
     return 0;
         
    
    
    
  
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vl cnt(100001);
    rep(i,n){
        ll a;
        cin >> a;
        if(a<=100000)
            cnt[a]++;
    }
    ll res=0;
    rep(i,100001){
        if(i<=cnt[i]){
            res+=i;
        }
    }
    cout << n-res << endl;
}

Measured memory_bytes: 3968
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  vector<int> A(3);
  cin >> A[0] >> A[1];
  A[2] = A[0] + A[1];
  loop(i,0,3) {
    if (A[i]%3==0) {
      cout << "Possible" << endl;
      return;
    }
  }
  cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, MX = 1000;
	cin >> N;
	vector<int> A(N);
	vector<int> sum[2] = {vector<int>(N+1, 0), vector<int>(N+1, 0)};
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		sum[1-i%2][i+1] = sum[1-i%2][i];
		sum[i%2][i+1] = sum[i%2][i] + A[i];
	}
	if(N%2 == 0) {
		cout << max(sum[0][N], sum[1][N]) << " " << min(sum[0][N], sum[1][N]) << "\n";
		return 0;
	}
	int ans_l = abs(sum[0][N]-sum[1][N]), ans_r = abs(sum[0][N]-sum[1][N])+2*MX;
	while(ans_r-ans_l > 1) {
		int ans_m = (ans_l + ans_r) / 2;
		vector<int> valid(N+2, 0);
		valid[0] = 1;
		A.push_back(0);
		set< pair<int, int> > X;
		for(int i = 2; i <= N+1; i += 2) {
			int d = sum[0][i-1]-sum[1][i-2]+sum[1][1];
			if(sum[1][N]-sum[0][N]+2*d >= ans_m && valid[0] && d < A[i-1]) valid[i] = 1;
			auto it = X.lower_bound({(ans_m+sum[0][N]-sum[1][N]+1)/2+sum[1][i-2]-sum[0][i-1], -1});
			if(it != X.end()) {
				if(it->ff < A[i-1]+sum[1][i-2]-sum[0][i-1]) valid[i] = 1;
				else while(it != X.end()) {
					if(it->ff-MX >= sum[1][i-2]-sum[0][i-1]) break;
					if(it->ff-A[it->ss-1] < sum[1][i-2]-sum[0][i-1]) {
						valid[i] = 1;
						break;
					}
					it++;
				}
			}
			if(valid[i]) X.insert({sum[1][i+1]-sum[0][i], i});
		}
		if(valid[N+1]) ans_l = ans_m;
		else ans_r = ans_m;
	}
	cout << (ans_l+sum[0][N]+sum[1][N])/2 << " " << (-ans_l+sum[0][N]+sum[1][N])/2 << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 13964
def main():
	n, q = map(int, input().split())
	s = input()
	Q = [input().split() for _ in range(q)]
	l, r = -1, n
	while r - l > 1:
		c = m = (l + r) // 2
		for t, d in Q:
			if s[c] == t:
				c += 1 if d == "R" else -1
				if c == -1 or c == n:
					break
		if c == -1:
			l = m
		else:
			r = m
	a = l
	l, r = -1, n
	while r - l > 1:
		c = m = (l + r) // 2
		for t, d in Q:
			if s[c] == t:
				c += 1 if d == "R" else -1
				if c == -1 or c == n:
					break
		if c == n:
			r = m
		else:
			l = m
	b = r
	print(0 if b <= a else b - a - 1)

if __name__ == '__main__':
	main()

Measured memory_bytes: 41308
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

typedef std::vector<int> vec;

int power_of_2(int n) {
    return (n & (n - 1)) == 0;
}

int max_divisor(int n) {
    return (~n & (n - 1)) + 1;
}

int g(const vec& sequence) {
    int sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        sum += sequence[i];
    }

    vec table(sum + 1);
    std::fill(table.begin() + 1, table.end(), -1);
    table[0] = 0;

    sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        for (int a = sum & -x; a >= 0; a -= x) {
            if (table[a] >= 0) {
                int b = a + x;
                if (table[b] >= 0) {
                    table[b] = std::max(table[a] + 1, table[b]);
                } else {
                    table[b] = table[a] + 1;
                }
            }
        }
        sum += sequence[i];
    }

    int max = 0;
    for (int i = 1; i <= sum; i <<= 1) {
        max = std::max(max, table[i]);
    }
    return max;
}

vec extract(const vec& sequence, int k) {
    vec subsequence;
    int min = INT_MAX;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        if (x % k == 0 && power_of_2(x / k)) {
            subsequence.push_back(x);
            min = std::min(min, x);
        }
    }
    for (int i = 0; i < subsequence.size(); i++) {
        subsequence[i] /= min;
    }
    return subsequence;
}

int f(const vec& sequence) {
    vec numbers;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        numbers.push_back(x / max_divisor(x));
    }
    std::sort(numbers.begin(), numbers.end());
    numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end());

    int max = 0;
    for (int i = 0; i < numbers.size(); i++) {
        int k = numbers[i];
        const vec& subsequence = extract(sequence, k);
        max = std::max(max, g(subsequence));
    }
    return max;
}

int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        vec sequence(n);
        for (int i = 0; i < n; i++) {
            std::cin >> sequence[i];
        }
        std::cout << f(sequence) << std::endl;
    }
    return 0;
}

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

#define ll long long int
using namespace std;
int main()
{
   ll n,l,r,count=0;
   map<int,int>m;
   cin>>n;
   for(int i=0;i<n;i++ )
   {
       cin>>l;
       m[l]++;
       if(m[l]==2)
       {
           count++;
           m[l]=0;
       }

   }
   cout<<n-(2*count)<<endl;
   m.clear();
    return 0;
}


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

int main() {
	int N;
	cin >> N;
  string S,T;
	cin >> S >> T;
	rep(i,N){
		cout << S[i] << T[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int x = Math.abs(a-c);
    int y = Math.abs(a-b);
    int z = Math.abs(b-c);
    if(x<=d){
      System.out.println("Yes");
    }else{
      if(y<=d && z<=d){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 21844
/**
*    author:  souzai32
*    created: 19.08.2020 00:26:47
**/

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
typedef long long ll;
using namespace std;

int main() {

    string s;
    cin >> s;
    int n=s.size();

    ll sum,num,ans=0;

    for(int bit=0; bit<(1<<n-1); bit++){
        sum=0;
        num=s.at(0)-'0';
        for(int i=0; i<n-1; i++){
            if(bit&(1<<i)){
                sum+=num;
                num=0;
            }else{
                num*=10;
            }
            num+=s.at(i+1)-'0';
        }
            // cout << num << endl;
        if(num) sum+=num;
        ans+=sum;
        // cout << sum << endl;
    }
        cout << ans << endl;
    // num=s.at(0)-'0'+s.at(1)-'0';
    // cout << num << endl;

    return 0;
}

Measured memory_bytes: 3632
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 20, inf = 1e9 + 42;

int a[2][N];

int main() {
	fast_cin();
	int n; cin >> n;
	for (int j = 0; j < 2; ++j) {
		for (int i = 0; i < n; ++i) {
			cin >> a[j][i];
		}
	}
	int best = inf, tot = (1 << n);
	for (int mask = 0; mask < tot; ++mask) {
		vector<pii> v[2];
		for (int i = 0; i < n; ++i) {
			v[((mask >> i) & 1) ^ (i & 1)].pb({a[(mask >> i) & 1][i], i});
		}
		if (v[1].size() != n / 2) {
			continue;
		}
		sort(v[0].begin(), v[0].end());
		sort(v[1].begin(), v[1].end());
		vector<int> p(2, 0);
		vector<pii> w(n);
		int cost = 0;
		for (int i = 0; i < n; ++i) {
			w[i] = v[i & 1][p[i & 1]++];
			if (i > 0 and w[i].first < w[i - 1].first) {
				cost = inf;
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				if (w[i].second > w[j].second) {
					++cost;
				}
			}
		}
		best = min(best, cost);
	}
	if (best >= inf) {
		cout << -1 << '\n';
	} else {
		cout << best << '\n';
	}
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var a, b, c, d int 
  fmt.Scan(&a, &b, &c, &d)
  res := maxInt(0, minInt(b, d) - maxInt(a, c))
  fmt.Println(res)
}

Measured memory_bytes: 512
n = int(input())
dp = [0] * 3
for i in range(n):
	l = list(map(int, input().split()))
	a = dp[0]
	b = dp[1]
	c = dp[2]
	dp[0] = l[0] + max(b,c)
	dp[1] = l[1] + max(a,c)
	dp[2] = l[2] + max(a,b)
print (max(dp))

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  reverse(h.begin(), h.end());
  int ans = 0;
  int val = 0;
  for (int i = 1; i < n; i++) {
    if (h[i-1] <= h[i]) val++;
    else val = 0;
    ans = max(ans, val);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <vector>
using namespace std;

vector<int> v[222222];
int val[222222], sum[222222], visit[222222];

void dfs(int node, int pfx)
{
	int i;

	if (visit[node])
		return;
	visit[node] = 1;

    sum[node] = pfx + val[node];

	for (i = 0; i < v[node].size(); i++)
        dfs(v[node][i], sum[node]);
}

int main(void)
{
    int n, q, i;

    scanf("%d %d" ,&n, &q);
	for (i = 1; i < n; i++)
	{
		int a, b;
		scanf("%d %d" ,&a, &b);
        v[a].push_back(b);
		v[b].push_back(a);
	}

	while (q--)
	{
        int node, src;

        scanf("%d %d" ,&node, &src);

        val[node] += src;
	}

	dfs(1, 0);
 	for (i = 1; i <= n; i++)
		printf("%d " ,sum[i]);
	return 0;
}

Measured memory_bytes: 25472
package main

import (
	"fmt"
)

var (
	finv, inv, fac [MAX]int
)

func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func init() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

const (
	MOD = 1000000007
	MAX = 510000
)

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	value int
	index int
	A, B  int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int64) int64 {
	return a * b / GCD(a, b)
}

func main() {
	var N, M, X int
	fmt.Scanf("%d %d %d\n", &N, &M, &X)

	C := make([]int, N)
	m := [100][]int{}
	for i := 0; i < N; i++ {
		var c int
		fmt.Scan(&c)
		C[i] = c
		for j := 0; j < M; j++ {
			var b int
			fmt.Scan(&b)
			m[i] = append(m[i], b)
		}
	}
	min := int(1e9)
	r := false
	for i := 1; i < 1<<uint(N); i++ {
		sum := make([]int, M)
		coin := 0
		for j := 0; j < N; j++ {
			if i&(1<<uint(j)) > 0 {
				coin += C[j]
				for k := 0; k < M; k++ {
					sum[k] += m[j][k]
				}
			}
		}
		ok := true
		for _, s := range sum {
			if s < X {
				ok = false
				break
			}
		}
		if ok && min > coin {
			r = true
			min = coin
		}
	}
	if r {
		fmt.Println(min)
	} else {
		fmt.Println(-1)
	}
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 14212
#include <stdio.h>

int main(void)
{
	char str[200];
	int i;
	
	gets(str);
	
	i = 0;
	while (str[i] != '\0'){
		if (str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 32;
		}
		i++;
	}
	
	printf("%s\n", str);
	
	return (0);
}

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

class Main{
    public static void main(String[] a)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int data[] = new int[10];

		for(int i = 0; i < 10; i++){
			data[i] = Integer.parseInt(br.readLine());
		}
		Arrays.sort(data);

		for(int i = 9; i >= 7; i--) System.out.printf("%d\n", data[i]);
    }
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = k; i < n; ++i) {
    if (a[i-k] < a[i])
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  return 0;
}

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

using ll = long long;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> dp(n);
    dp[n-1] = s[n-1] - '0';
    int t = 10;
    for(int i = 2; i <= n; i++){
        dp[n-i] = ((s[n-i] - '0')*t + dp[n-i+1]) % 2019;
        t *= 10;
        t %= 2019;
    }

    int ans = 0;
    for(int i = 0; i < 2019; i++){
        int cnt = 0;
        for(int j = 0; j < n; j++){
            if(dp[j] == i) cnt++;
        }
        ans += cnt*(cnt-1)/2;
        if(i == 0) ans += cnt;
    }
    
    cout << ans << endl;
}

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

int main() {
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    vector<bool> win(k+1, 0);
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(a[j] > i)    break;
            win[i] = win[i] | !win[i-a[j]];
        }
    }
    cout << (win[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 256
// Solution for https://atcoder.jp/contests/aising2020/tasks/aising2020_d
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int pop_count(const string& s) {
  int result = 0;
  for (int i = 0 ; i < s.size() ; i++) {
    if (s[i] == '1') {
      result++;
    }
  }
  return result;
}

int pop_count(const int x) {
  return __builtin_popcount(x);
}

// Calculates the number of times x should be divided by
// pop_count(x) until it becomes 0.
int f(int x) {
  int count = 0;
  while (x > 0) {
    x %= pop_count(x);
    count ++;
  }
  return count;
}

// Calculates xs % mod, given pre-caclulated vector<int> mods containing
// remainders of 2^0, 2^1, .. 2^n module mod.
int calc_mod(const string& xs, int mod, vector<int> mods) {
  if (mod == 0) {
    return 0;
  }
  int result = 0;
  
  for (int i = 0 ; i < xs.size() ; i ++) {
    if (xs[i] == '1') {
      result += mods[xs.size() - i - 1];
      result %= mod;
    }
  }
  return result;
}

// Calculates remainders of 2^0, 2^1, .. 2^n module mod.
vector<int> calc_pow2_mod(int mod, int n) {
  vector<int> mods(n+1, 0);
  if (mod == 0) {
    return mods;
  }
  mods[0] = 1;
  for (int i = 1 ; i <= n ; i++) {
    mods[i] = (1L * mods[i-1] * 2) % mod;
  }
  return mods;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  string xs;
  cin >> n;
  cin >> xs;

  int p = pop_count(xs);

  vector<int> pow2_mod_p_minus_1 = calc_pow2_mod(p-1, n);
  vector<int> pow2_mod_p_plus_1 = calc_pow2_mod(p+1, n);

  int xs_mod_p_minus_1 = calc_mod(xs, p-1, pow2_mod_p_minus_1);
  int xs_mod_p_plus_1 = calc_mod(xs, p+1, pow2_mod_p_plus_1);


  // Calculate for each X_i calculate X_i % pop_count(X_i);
  vector<int> fx1(n, 0);
  for (int i = 0 ; i < n; i++) {
    int deg = n - i - 1;
    if (xs[i] == '1') {
      if (p == 1) {
        // if (p == 1), p - 1 = 0 so 
        fx1[i] = -1;
      } else {
        fx1[i] = (xs_mod_p_minus_1 - pow2_mod_p_minus_1[deg] + p - 1) % (p - 1);
      }
    } else {
      // 0
      fx1[i] = (xs_mod_p_plus_1 + pow2_mod_p_plus_1[deg]) % (p + 1);
    }
  }

  // Now after we calculated one time, the numbers in fx1 are small enough to 
  // manually calculate f(X_i).
  for (int i = 0 ; i < n ; i ++) {
    if (fx1[i] == -1) {
      cout << 0;
    } else {
      cout << 1 + f(fx1[i]);
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 6056
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll now = 0;
  rep(i,n){
    if(a[i] == now+1)now++;
  }
  if(now==0){
    cout << -1 << endl;
  }else{
    cout << n - now << endl;
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a; cin >> a;
	string str; cin >> str;
	int l[a + 50] = {0}, r[a + 50] = {0};
	for(int i=0; i<a; i++)
	{
		if(i) l[i] = l[i - 1];
		if(str[i] == 'W') l[i] ++;
	}
	for(int i=a - 1; i >= 0; i--)
	{
		r[i] = r[i + 1];
		if(str[i] == 'E') r[i] ++;
	}
	int ans = 999999999;
	for(int i=1; i < a - 1; i++)
	{
		ans = min(ans, l[i - 1] + r[i + 1]);
	}
	cout << min(ans, min(l[a - 1], r[0])) << '\n';
}

Measured memory_bytes: 2948
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000

using namespace std;

ll count(ll a)
{
  ll cnt=0;
  for(ll i=1;i*i<=a;i++)
  {
     if(a%i==0)
     {
       if(a/i!=i)
       {
       	 cnt+=2;
       }
       else if(a/i==i)
       {
       	 cnt++;
       }
     }
  }
  return cnt;
}


ll n;
ll ans=0;
int main(){
FAST_READ;
cin>>n;

for(ll i=1;i<=n;i++)
{
   if(i%2!=0)
   {
   	 ll sd=count(i);
   	 if(sd==8)ans++;
   }
}
cout<<ans<<endl;






return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL dp[2020][2020] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    vector<pair<LL,int>> A(N);
    REP(i,N){
        LL a; cin >> a;
        A[i] = make_pair(a,i);
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    REP(i,2020) REP(j,2020) dp[i][j] = -LINF;
    dp[0][0] = 0;

    REP(i,N){
        REP(j,2020){
            LL a,n;
            tie(a,n) = A[i];
            if(j != 0) chmax(dp[i+1][j], dp[i][j-1] + a * abs(j-1-n));
            chmax(dp[i+1][j], dp[i][j] + a * abs((N-(i-j)-1)-n));
        }
    }
    LL ans = 0;
    REP(i,2020){
        chmax(ans,dp[N][i]);
    }
    cout << ans << endl;



}


Measured memory_bytes: 35568
#include <iostream>
using namespace std;
int a[10000],n;
int f(int m){
	if(m==1)return 1;
	else{
	if(m==2)return 2;
	else
return f(m-1)+f(m-2);
}
}
int main(){
	int a,b,h;
	//cin>>n;
cin>>a>>b>>h;
cout<<(a+b)*h/2<<endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int MAX_N=100;

int main(){
    ios::sync_with_stdio(false);
    int n,m;
    int a[MAX_N+5];
    cin >> n >> m;
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n,greater<int>());
    double sum=0.000;
    rep(i,n){
        sum+=a[i];
    }
    if(a[m-1]<sum/(4.00000*m)) cout << "No";
    else cout << "Yes";
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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 end



int main(){
    int n,m; scanf("%d%d",&n,&m);
    string s; cin>>s; 
    int idx=n; vector<int> ans;
    while(idx){
        int lb=max(idx-m,0);
        while(s[lb]=='1'){
            lb++;
            if(lb==idx){printf("-1\n"); return 0;}
        }
        ans.push_back(idx-lb); idx=lb;
    }
    rrep(i,ans.size()-1,-1)printf("%d\n",ans[i]);
    return 0;
}

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

int main(){
  int total = 0,book,totala = 0,mach;
  while(true){
    cin>>total;
    if(total==0){
      break;
    }
    for(int i=1;i <= 9;i++){
      cin >> book;
      totala = totala + book;
    }
    mach = total - totala;
    cout << mach << endl;
    totala=0;
    total=0;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

vector<pair<char,int64_t>> run_length_encode(const string &s){
  vector<pair<char,int64_t>> ret;

  for(auto &x : s){
    if(ret.empty()) ret.push_back({x,1});
    else if(ret.back().fst == x) ++ret.back().snd;
    else ret.push_back({x,1});
  }

  return ret;
}


int main(){
  int n;
  string s;
  while(cin >> n >> s){
    auto r = run_length_encode(s);

    cout << r.size() << endl;
  }



  return 0;
}


Measured memory_bytes: 2500
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
	vector<int> a(5);
	for(int i=0; i<5; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for(int i=4; i>0; i--){
		cout << a[i] << " ";
	}
	cout << a[0] << endl;
	return 0;
}

Measured memory_bytes: 3064
n, a, b = map(int, input().split())

s = int(n / (a + b))

if n % (a + b) == 0:
  print(a * s)
else:
  rem = n % (a + b)
  if rem <= a:
    ans = a * s + rem
  else:
    ans = a * s + a
  print(ans)




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

int main(){
  int a, bld[4] = {0};
  char c[5];
  char tmp[4][5] = {"A", "B", "AB", "O"};

  while(scanf("%d,%s", &a, c) != EOF){
    for(int i = 0; i < 4; i++){
      if(strcmp(c, tmp[i]) == 0) bld[i]++;
    }
  }

  for(int i = 0; i < 4; i++) cout << bld[i] << endl;
}

Measured memory_bytes: 1208
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    s = set()
    s.add(A)
    s.add(B)
    s.add(C)
    if len(s) == 2:
        print(YES)
    else:
        print(NO)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


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

int main() {
    double n,k;
    cin >> n >> k;
    double sum = 0;
    double base = 1/n;
    for(int i = 1; i <= n; i++){
        sum = sum + base * min(1.0,pow(0.5, ceil(log2(k/i))));
    }
    cout << fixed << setprecision(15) << sum;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
int T,A;
int H[1010];
double mn=(double)1e9;
int pos;
int main()
{
	cin>>N>>T>>A;
	for(int i=1;i<=N;i++) cin>>H[i];
	for(int i=1;i<=N;i++)
	{
		double val=(double)T-(double)H[i]*0.006;
		double tmp=abs(val-(double)A);
		if(tmp<mn) mn=tmp,pos=i;
	}
	cout<<pos<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 123456789;

vector<int> p[26];
int next(int idx, char c)
{
    int id = c-'a';
    return *lower_bound(all(p[id]),idx);
}

int main()
{
    string a;
    cin >>a;
    int A = a.size();

    rep(i,A) p[a[i]-'a'].pb(i);
    rep(i,26) p[i].pb(A);

    vector<int> dp(A+2,INF);
    vector<int> par(A+2,INF);
    dp[A+1] = 0;
    for(int i=A-1; i>=0; --i)
    {
        rep(j,26)
        {
            int nidx = next(i,'a'+j)+1;
            // printf(" (%d %d)  %d\n", i,j,nidx);

            if(dp[i]>dp[nidx]+1)
            {
                dp[i] = dp[nidx]+1;
                par[i] = nidx;
            }
        }
    }

    // dbg(dp);
    // dbg(par);

    string ans = "";
    int now = 0;
    while(par[now]!=INF)
    {
        rep(i,26)
        {
            char c = i+'a';

            if(next(now,c)+1==par[now])
            {
                ans += c;
                now = next(now,c)+1;
                break;
            }
        }
    }

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


Measured memory_bytes: 2948
//
// Created by keane on 19-6-16.
//
#include <bits/stdc++.h>
using namespace std;
double w,h,x,y;
int main(void){
    scanf("%lf%lf%lf%lf",&w,&h,&x,&y);
    double a=w*h/2;
    int d=0;
    if(x==w/2 && y==h/2){
        d=1;
    }
    printf("%.6lf %d\n",a,d);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 100010
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
bool ispalin(string s,int l,int r){
    string t="";
    string k="";
    for(int i=l-1;i<=r-1;i+=1){
        k+=s[i];
        t+=s[i];
    }
    reverse(t.begin(),t.end());
    if(t==k)
        return 1;
    return 0;
}
signed main()
{
    
    speed
    string s ;cin>>s;
    int n=s.size();
    if(ispalin(s,1,n) && ispalin(s,1,(n-1)/2) && ispalin(s,(n+3/2),n))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    
    


    return 0;
}


Measured memory_bytes: 256
n = input()
dp = [0, 10000]
for d in reversed('0' + n):
    newdp = []
    newdp.append(min(int(d) + dp[0], int(d) + 1 + dp[1]))
    newdp.append(min(10 - int(d) + dp[0], 10 - int(d) - 1 + dp[1]))
    dp = newdp
print(dp[0])


Measured memory_bytes: 76892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace B_Exchange
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            int A = inputs[0];
            int B = inputs[1];
            int K = inputs[2];

            for (int i = 0; i < K; i++)
            {
                if (i % 2 == 0)
                {
                    if (A % 2 == 1)
                    {
                        A--;
                    }
                    B = B + A / 2;
                    A = A / 2;
                }
                else
                {
                    if (B % 2 == 1)
                    {
                        B--;
                    }
                    A = A + B / 2;
                    B = B / 2;

                }
            }

            Console.WriteLine("{0} {1}", A,B);
        }
    }
}


Measured memory_bytes: 13396
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

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

typedef long long LL;
typedef long double LD;

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < a.second;
    }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main()
{
    string S;
    cin >> S;
    int N = S.length();
    vector<int> seq(N, 0);
    for (int i = 0; i < N; i++)
        seq[i] = S[i] - '0';

    vector<pair<int, int>> g(N-2, {0, 0});
    for (int i = 0; i < N-2; i++) {
        g[i].first = abs(seq[i]*100 + seq[i+1]*10 + seq[i+2] - 753);
        g[i].second = i;
    }

    sort(all(g), compare_by_a);
    int idx = g[0].second;
    int ans = abs(seq[idx]*100 + seq[idx+1]*10 + seq[idx+2] - 753);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;
int gcd(int a,int b)
{
    if(a<b){
        swap(a,b);
    }
        if(a%b==0)
            return b;
        return gcd(b,a%b);
    
}
int main()
{
    int i,n,a,b=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        b=(b*a)/gcd(b,a);
    }
    printf("%d\n",b);
    return 0;
}



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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<double, double>> a;
    for (int i = 0; i < n; i++)
    {
        double x, y;
        cin >> x >> y;
        a.EB(x, y);
    }
    vector<int> perm(n);
    for (int i = 0; i < n; i++)
        perm[i] = i;
    double sum = 0;
    int cnt = 0;
    do 
    {
        double cur = 0;
        for (int i = 0; i < n - 1; i++)
        {
            double dx = a[perm[i + 1]].fst - a[perm[i]].fst;
            double dy = a[perm[i + 1]].snd - a[perm[i]].snd;
            cur += sqrt(dx * dx + dy * dy);
        }
        sum += cur;
        cnt++;
    } while (next_permutation(ALL(perm)));
    cout << fixed << setprecision(9) << sum / cnt;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL absval(LL x)
{
    return x>0?x:-x;
}
int main()
{
    LL x,k,d;
    cin>>x>>k>>d;
    LL ans=1e15;
    if(k&1)
    {
        if(x==0)
            ans=d;
        else if(x<0)
        {
            LL num=-x/d;
            if(num<=k)
            {
                if(num&1) ans=-x%d;
                else ans=absval(-x%d-d);
            }
            else
                ans=absval(x+k*d);
        }
        else
        {
            LL num=x/d;
            if(num<=k)
            {
                if(num&1) ans=x%d;
                else ans=absval(x%d-d);
            }
            else
                ans=absval(x-k*d);
        }
    }
    else
    {
        if(x==0)
            ans=0;
        else if(x<0)
        {
            LL num=-x/d;
            if(num<=k)
            {
                if(num&1) ans=absval(-x%d-d);
                else ans=-x%d;
            }
            else
                ans=absval(x+k*d);
        }
        else
        {
            LL num=x/d;
            if(num<=k)
            {
                if(num&1) ans=absval(x%d-d);
                else ans=x%d;
            }
            else
                ans=absval(x-k*d);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
D = divisors(S)
D.sort()

def test(x):
    k = D[x]
    B = []
    for a in A:
        B.append(a%k)
    B.sort()
    cnt = sum(B)//k
    return k*cnt - sum(B[-cnt:]) <= K

p = binary_search_int(0,len(D),test)
q = binary_search_int(p+1,len(D),test)
print(max(D[p],D[q]) if q != p+1 else D[p])

Measured memory_bytes: 66124
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) rep(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i++)
#define reprev(i, n) reprrev(i, 0, n)

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

int main()
{
	ll X, Y;
	cin >> X >> Y;
	int ans = 0;

	while (X <= Y) {
		ans++;
		X *= 2;
	}

	cout << ans << endl;

	return 0;
}




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

int main(){
  int W,H,N,cnt=0;
  cin>>W>>H>>N;
  int x[N],y[N],a[N],ans[H][W];
  for(int i=0;i<N;i++) cin>>x[i]>>y[i]>>a[i];
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) ans[i][j]=0;
  }
  
  for(int i=0;i<N;i++){
    if(a[i]==2){
      for(int j=0;j<H;j++){
        for(int k=x[i];k<W;k++) ans[j][k]++;
      }
    }else if(a[i]==1){
      for(int j=0;j<H;j++){
        for(int k=0;k<x[i];k++) ans[j][k]++;
      }
    }else if(a[i]==4){
      for(int j=y[i];j<H;j++){
        for(int k=0;k<W;k++) ans[j][k]++;
      }
    }else if(a[i]==3){
      for(int j=0;j<y[i];j++){
        for(int k=0;k<W;k++) ans[j][k]++;
      }
    }
  }
  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(ans[i][j]==0) cnt++;
      }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[100];
    int b;
    while(cin>>a)
    {
        b=0;
       int L=strlen(a);
       //cout<<L<<endl;
       for(int i=0;i<L;i++)
       {
           if(a[i]=='9')
           {
               b=1;
                break;
           }

       }
       if(b==1)
       {
           cout<<"Yes"<<endl;
            //cout<<"The one's digit of "<<a<<" is 9."<<endl;
       }
       else
       {
           cout<<"No"<<endl;
           //cout<<a<<" does not contain 9."<<endl;
       }
    }
    return 0;
}


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

using namespace std;

int n;

int main(){
	scanf("%d", &n);
	
	int cnt = 0;
	
	for(int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		while(x % 2 == 0){
			x /= 2;
			cnt++;
		}
	}
	
	printf("%d\n", cnt);
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappushpop
X, Y, Z = map(int, input().split())
xyz = sorted([list(map(int,l.split()))for l in sys.stdin],key=lambda x:x[0]-x[1])

uq = []
cy = 0
for x, y, z in xyz[:Y]:
    heappush(uq, y - z)
    cy += y
Ly = [cy]
for x, y, z in xyz[Y:Y+Z]:
    cy += y - heappushpop(uq, y - z)
    Ly += [cy]

lq = []
cx = 0
for _ in [0] * X:
    x, y, z = xyz.pop()
    heappush(lq, x - z)
    cx += x
Lx = [cx]
for _ in [0] * Z:
    x, y, z = xyz.pop()
    cx += x - heappushpop(lq, x - z)
    Lx += [cx]

print(max(map(sum, zip(Lx, Ly[::-1]))))

Measured memory_bytes: 37952
#include<bits/stdc++.h>
using namespace std;
int n,m;
map<int,int>mp;
int a[101010];
int solve(){
	int i,j,k,l,r,x,y;;
	cin>>n>>m;
	string s;
	for(i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(i=0; i<m; ++i) {
		cin>>x>>y;
		mp[y] += x;
	}
	long long ans=0;
	for(i=0;i<n;i++){
		if(mp.size()&&mp.rbegin()->first>a[i]){
			a[i]=mp.rbegin()->first;
			mp.rbegin()->second--;
			if(mp.rbegin()->second==0){
				mp.erase(mp.rbegin()->first);
			}
		}
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}
int main(){
	string s;
	int i;
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

Measured memory_bytes: 5376