akhauriyash/Code-Regression huggingface dataset:
import sys
import math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    Q = [0 for k in range(N+1)]
    for M in range(1,N+1):
        k = 2
        while k*k <= M:
            if M%k == 0:
                M //= k
                Q[k] += 1
            else:
                k += 1
        if M > 1:
            Q[M] += 1
    ans = 1
    for k in range(N+1):
        ans *= Q[k]+1
        ans %= 10**9 + 7
    print(ans)

if __name__ == '__main__':
    main()


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        System.out.printf("%d %d %.5f\n",a/b,a%b,(double)a/(double)b);
        
        
    }
}

Measured memory_bytes: 24772
#include<iostream>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/g*b;
}
int main(){
  int n;
  cin>>n;
  ll ans;
  ans=1LL;
  for(int i=0;i<n;i++){
    ll t;
    cin>>t;
    ans=lcm(ans,t);
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int main() {
    int h, w, k, count = 0;
    cin >> h >> w >> k;
    vector<string> mat(h);
    for (int i = 0; i < h; ++i) {
        cin >> mat[i];
    }

    for (int row = 0; row < (1 << h); ++row) {
        for (int col = 0; col < (1 << w); ++col) {
            int blacks = 0;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (((row >> i) & 1) == 0 && (((col >> j) & 1) == 0) && mat[i][j] == '#')
                        blacks++;
                }
            }
            if (blacks == k)
                count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3604
N, M = map(int, input().split())
l, r = map(int, input().split())
for _ in range(M-1):
    new_l, new_r = map(int, input().split())
    if l < new_l:
        l = new_l
    if new_r < r:
        r = new_r

score = r-l+1
if score > 0:
    print(score)
else:
    print(0)


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

int main()
{
    int n;
    cin>>n;
    int arr[n], temp[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        temp[i] = arr[i];
    }
    sort(temp, temp+n);
    int count = 0;
    for(int i=0; i<n; i++)
    {
        if(arr[i] != temp[i])
            count++;
    }
    if(count<=2)
        cout<<"YES";
    else
        cout<<"NO";
}


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();
		if((A*B)%2==1){
			System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}
}


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

int extgcd(int a, int b, int&x, int&y) {
	int d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
int main() {
	int a, b, x, y; cin >> a >> b;
	extgcd(a, b, x, y);
	cout << x << ' ' << y << endl;
}

Measured memory_bytes: 3108
#include <stdio.h>

void swap(int* a, int* b);

int main(void)
{
    int i, j;

    int length;
    scanf("%d", &length);

    int line[100];

    for (i = 0; i < length; i++) {
        scanf("%d", &line[i]);
    }

    int min;
    int swap_cnt = 0;
    for (i = 0; i < length; i++) {
        min = i;
        for (j = i; j < length; j++) {
            if (line[j] < line[min]) {
                min = j;
            }
        }
        if (min != i) {
            swap(&line[i], &line[min]);
            swap_cnt++;
        }
    }

    for (i = 0; i < length; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%d", line[i]);
    }
    printf("\n");

    printf("%d\n", swap_cnt);

    return 0;
}

void swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

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

int main(){
    ll N;
    cin >> N;
    ll H[N];
    rep(i,N) cin >> H[i];

    ll max_c=0;
    ll c=0;
    rep(i,N-1){
        if(H[i]>=H[i+1]){
            c++;
        }else{
            c = 0;
        }
        max_c = max(max_c,c);
    }
    cout << max_c << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = list(map(str, input()))
a = []
cnt = s.count("E")
s.insert(0, 0)
s.append(0)
for i in range(1, n + 1):
    if s[i - 1] == "W":
        cnt += 1
    if s[i] == "E" and cnt != 0:
        cnt -= 1
    a.append(cnt)
print(min(a))


Measured memory_bytes: 17528
# coding: utf-8
s = input()
strlen = len(s)
cnt = 0
for i in range(0, strlen, 2):
    if s[i] != '0':
        cnt += 1
for j in range(1, strlen, 2):
    if s[j] != '1':
        cnt += 1
print(min(cnt, strlen - cnt))


Measured memory_bytes: 3188
import java.util.Scanner;
import java.lang.Math;

class Main{

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        scanner.close();

        long result1 = n/(a+b)*a;
        long result2 = n%(a+b);
        if(result2>=a){
            System.out.println(result1+a);
            return;
        }else{
            System.out.println(result1+result2);
            return;
        }

    }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int l, d, r;
    cin >> l >> r >> d;
    cout << r / d - (l - 1) / d << endl;
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define flood(arr, char, size) for (int i=0; i<size; i++) arr[i] = char
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 1e5 + 2;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int s = 0;
    for (int i = n - k; i < n; i++) s += a[i];
    cout << s;
    return 0;
}

Measured memory_bytes: 256
def asu(a,b):
    a,b=str(a),str(b)
    a=sum(map(int,list(a)))
    b=sum(map(int,list(b)))
    return a+b

n=int(input())
mins=999999999
for i in range(1,n):
    asun=asu(i,n-i)
    if mins>asun:
        mins=asun
print(mins)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <cstring>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;
ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
    return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
    return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
    return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
    return forall_a_in_P.second > forall_b_in_P.second;
}
ll GCD(ll x, ll y) {
	return x ? GCD(y % x, x) : y;
}

ll LCM(ll m, ll n)
{
	if ((0 == m) || (0 == n))
		return 0;

	return ((m / GCD(m, n)) * n); // lcm = m * n / GCD(m,n)
}
void solve(){
   int n;
   cin>>n;
   vector<string>s(n);
   map<string,int>cnt;
   rep(i,n){
       cin>>s[i];
       cnt[s[i]]++;
   }
   int ma=0;
   rep(i,n){
       ma=max(ma,cnt[s[i]]);
   }
   map<string,int>used;
   vector<string>ans;
   rep(i,n){
       if(ma==cnt[s[i]]){
           if(!used[s[i]]){
               ans.push_back(s[i]);
               used[s[i]]++;
           }
       }
   }
   sort(all(ans));
   rep(i,ans.size()){
       cout<<ans[i]<<endl;
   }
   

}


int main()
{
    solve();
}

Measured memory_bytes: 41712
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
using namespace std;
using ii = long long;
char c[1001][1001];
int dp[1002][1002];
const int mod = 1e9 + 7;
void modadd(int &a, int b)
{
    if ((a += b) >= mod) a -= mod;
}
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> c[i][j];
        }
    }
    for (int i = n; i >= 1; --i) {
        for (int j = m; j >= 1; --j) {
            if (i == n && j == m) {
                dp[i][j] = 1;
                continue;
            }
            if (c[i][j] == '#') continue;
            modadd(dp[i][j], dp[i + 1][j]);
            modadd(dp[i][j], dp[i][j + 1]);
        }
    }
    cout << dp[1][1] << "\n";
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
const int N=200005; 
int n,k,num[N],p=1,cnt;
char s[N];
signed main(){
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for (int i=1;i<=n;i++)num[i]=s[i]-'A';
    int st=num[1];
    while (k--){
    	if (st==0){
			st^=1;
			num[p]^=1;
		}
   		else {
        	p++;cnt++;
        	st=num[p];
        	st^=(cnt&1);
    	}
    	if (p>n)break;
    }
    if (p<=n){
    	for (int i=p;i<=n;i++)putchar('A'+(num[i]^(cnt&1)));
    	int t=n-(n-p+1),c=(cnt-1)&1;
    	while (t--){
        	putchar('A'+c);
        	c^=1;
    	}
    }
    else {
    	if ((cnt-1)&1){
        	for (int i=1;i<=n;i++)putchar('A'+(i&1));
    	}
   		else {
			putchar('A'+(k&1));
        	for (int i=1;i<n;i++)putchar('A'+(i&1));
    	}
    }
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<double> x(n), y(n);
	rep(i,n) cin >> x[i] >> y[i];
	vector<int> v(n);
	rep(i,n) v[i] = i;
	double ans = 0, div = 0;
	do{
		double dist = 0;
		div += 1;
		rep(i,n-1){
			dist += sqrt((x[v[i+1]]-x[v[i]])*(x[v[i+1]]-x[v[i]]) + (y[v[i+1]]-y[v[i]])*(y[v[i+1]]-y[v[i]]));
		}
		ans += dist;
	} while(next_permutation(v.begin(), v.end()));
	ans /= div;
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var num = int.Parse(Console.ReadLine());
        var dict = new Dictionary<string, int>();
        for(var i = 0; i < num; i++)
        {
            var item = Console.ReadLine();
            if (dict.ContainsKey(item))
            {
                dict[item] += 1;
            }
            else
            {
                dict.Add(item, 1);
            }
        }


        Console.WriteLine(dict.Count);
        Console.Read();


    }
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;


const int MOD = 1000000007;
const int MX = 2e6 + 5;
int fact[MX], factInv[MX];
int r1, r2, c1, c2;


ll inv(ll a, ll b) {
	return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

int c(int n, int k) {
	ll ret = fact[n];
	ret = (ret * factInv[k]) % MOD;
	ret = (ret * factInv[n - k]) % MOD;
	return ret;
}


int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	fact[0] = 1;
	factInv[0] = inv(fact[0], MOD);
	for (int i = 1; i < MX; ++i) {
		fact[i] = (fact[i - 1] * 1LL * i) % MOD;
		factInv[i] = (factInv[i - 1] * 1LL * inv(i, MOD)) % MOD;
	}

	cin >> r1 >> c1 >> r2 >> c2;

	int ans = 0;

	for (int r = r1; r <= r2; ++r) {
		ans = (ans + c(r + c2 + 1, r + 1)) % MOD;
		ans = (ans - c(r + c1, r + 1) + MOD) % MOD;
	}

	cout << ans << '\n';

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


Measured memory_bytes: 15872
n , m , x = map(int,input().split())
A = list(map(int,input().split()))
B = 0
C = 0
for i in range(m):
         if  x <A[i] < n:
             B += 1
         if  0 < A[i] < x:
             C +=1
print(min(B, C))

Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        if(D[a]==0): continue
        k=a.bit_length()
        d=(1<<k)-a
        if(a!=d):
            if(D[d]):
                ans+=1
                D[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    print(ans)
resolve()

Measured memory_bytes: 129616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,S1=0,S2=0,minabs=100000,j;
  cin>>N;
  vector<int>W(N);for(int i=0;i<N;i++)cin>>W[i];
  for(int i=0;i<N-1;i++){
    j=i;
    while(true){
      S1+=W[j];
      if(j==0)break;
      j--;
    }
    j=i;
    while(true){
      S2+=W[j+1];
      if(j==N-2)break;
      j++;
    }
    minabs=min(minabs,abs(S1-S2));
    S1=0;
    S2=0;
  }
  cout<<minabs<<endl;
}

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

int main() {
	while (1) {
		int n, m, A[MAXA], maxt = 0;
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> A[i];
		}
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if (A[i] + A[j] > maxt&&A[i] + A[j] <= m)maxt = A[i] + A[j];
			}
		}
		if (maxt == 0)cout << "NONE" << endl;
		else cout << maxt << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N, K;
  cin >> N >> K;

  if (N % K == 0)
    cout << 0 << endl;
  else
    cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

class UnionFind {
private:
    vector<int> parent_;
    vector<int> node_rank_;
    vector<int> sizes_;
public:
    UnionFind(int node_num):
        parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) {
        for (int i = 0; i < node_num; ++i) {
            parent_[i] = i;
            node_rank_[i] = 0;
            sizes_[i] = 1;
        }
    }
    int getRoot(int u) {
        return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]);
    }
    bool isSame(int u, int v) {
        return getRoot(u) == getRoot(v);
    }
    void unite(int u, int v) {
        u = getRoot(u);
        v = getRoot(v);
        if (u == v) return;
        if (node_rank_[u] < node_rank_[v]) {
            parent_[u] = v;
            sizes_[v] += sizes_[u];
        }
        else {
            parent_[v] = u;
            sizes_[u] += sizes_[v];
            if (node_rank_[u] == node_rank_[v]) {
                node_rank_[u]++;
            }
        }
    }
    int getSize(int u) {
        return sizes_[getRoot(u)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    UnionFind uf(N);
    int t, u, v;
    rep(i, 0, Q) {
        cin >> t >> u >> v;
        if (t) {
            if (uf.isSame(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        } else {
            uf.unite(u, v);
        }
    }
    return 0;
}

Measured memory_bytes: 5384
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if (n < 1200) {
			System.out.println("ABC");
			return;
		} else if (1200 <= n && n < 2800) {
			System.out.println("ARC");
			return;
		} 
		System.out.println("AGC");
	}
}


Measured memory_bytes: 22996
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int main() {
	string N;
	cin >> N;
	

	if (N[0] == '9' || N[1] == '9') {
		cout << "Yes" << endl;
		return 0;
	} 

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>

#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 998244353
#define ll long long
#define vll vector<long long>  

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

// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())

// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())

using namespace std;



int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO

    int l,r,d;
    cin>>l>>r>>d;
    cout<<r/d - (l-1)/d;
}

Measured memory_bytes: 3156
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn search<F>(n: usize, f: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut low = 0;
    let mut high = n;

    while low < high {
        let mid = (low + high) / 2;
        if f(mid) {
            high = mid;
        } else {
            low = mid + 1;
        }
    }
    low
}

fn main() {
    let _ = scan!(usize);
    let mut a = scan!(i64;;);
    let mut b = scan!(i64;;);
    let mut c = scan!(i64;;);
    a.sort();
    b.sort();
    c.sort();

    let mut ans = 0;
    for n in b.iter() {
        let j = search(a.len(), |i| *n <= a[i]);
        let k = search(c.len(), |i| *n < c[i]);
        ans += j * (c.len() - k)
    }
    println!("{}", ans)
}


Measured memory_bytes: 13560
#include<iostream>

using namespace std;

int n, M[100][100], W = 0, G = 1, B = 2;

int prim () {

    int u, minv, i, v, d[100], p[100], color[100], sum;

    for (i = 0; i < n; i++) {
        d[i] = (1 << 21);
        p[i] = -1;
        color[i] = W;
    }

    d[0] = 0;

    while (1) {

        minv = (1 << 21);
        u = -1;
        for (i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != B) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = B;
        for (v = 0; v < n; v++) {
            if (color[v] != B && M[u][v] != (1 << 21)) {
                if (d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = G;
                }
            }
        }

    }

    sum = 0;
    for (i = 0; i < n; i++) {
        if (p[i] != -1) {
            sum += M[i][p[i]];
        }
    }

    return sum;

}

int main () {

    int i, j, e;

    cin >> n;

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            cin >> e;
            M[i][j] = (e == -1) ? (1 << 21) : e;
        }
    }

    cout << prim () << endl;

    return 0;

}

Measured memory_bytes: 3092
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] h = new int[N];

    for (int i = 0; i < N; i++) {
      h[i] = sc.nextInt();
    }

    sc.close();

    int count = 0;
    int number = 0;

    for (int i = 0; i < N; i++) {
      if (number > h[i]) {
        count += number - h[i];
      }
      number = h[i];
    }

    count += number;

    System.out.println(count);

  }

}

Measured memory_bytes: 21844
from collections import deque

def BFS(s):
 tree=[[] for i in range(n)]
 for i in list:
  tree[i[0]-1].append(i[1]-1)
  tree[i[1]-1].append(i[0]-1)

 dist=[-1 for i in range(n)]
 dist[s-1]=0

 que=deque()
 que.append(s-1)
 while que:
  x=que.popleft()
  for p in tree[x]:
   if dist[p]==-1:
    que.append(p)
    dist[p]=dist[x]+1
 return dist

n,u,v=map(int,input().split())
list=[list(map(int,input().split())) for i in range(n-1)]

u_dist=BFS(u)
v_dist=BFS(v)

l=0
for u_d,v_d in zip(u_dist,v_dist):
 if u_d<v_d:
  l=max(l,v_d)

print(l-1)

Measured memory_bytes: 49104
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let read() = Console.ReadLine()
let reads () = Console.ReadLine().Split()
let read2 () = reads() |> (fun x -> x.[0], x.[1])
let read3 () = reads() |> (fun x -> x.[0], x.[1], x.[2])
let read4 () = reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let tmap2 f1 f2 (t1, t2) = (f1 t1, f2 t2)
let tmap3 f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let tmap4 f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)
let readAs f = read() |> f
let readAs2 f1 f2 = read2 () |> tmap2 f1 f2
let readAs3 f1 f2  f3 = read3 () |> tmap3 f1 f2 f3
let readAs4 f1 f2 f3 f4 = read4 () |> tmap4 f1 f2 f3 f4

let readInt () = readAs int
let readInt2 () = readAs2 int int
let readInt3 () = readAs3 int int int
let readInt4 () = readAs4 int int int int
let readLong () = readAs int64
let readLong2 () = readAs2 int64 int64
let readLong3 () = readAs3 int64 int64 int64
let readLong4 () = readAs4 int64 int64 int64 int64
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"
let sayYesNo b = if b then puts "Yes" else puts "No"
let generateSeq n f = seq { for _ in 1 .. n do yield f () }

let assertLength n arr = if Array.length arr = n then arr else failwith "length doesn not match"


let toIntArray (s:string) = s.ToCharArray() |> Array.map (fun c -> int c - int '0')

let readIntMatrix h w =
 generateSeq h (reads >> Array.map int ) |> Seq.toArray
let readLongMatrix h w =
 generateSeq h (reads >> Array.map int64) |> Seq.toArray

let bitCount (n : int) =
    let count2 = n - ((n >>> 1) &&& 0x55555555)
    let count4 = (count2 &&& 0x33333333) + ((count2 >>> 2) &&& 0x33333333)
    let count8 = (count4 + (count4 >>> 4)) &&& 0x0f0f0f0f
    (count8 * 0x01010101) >>> 24


// The main contents of this submission are below this line.

let n= readInt ()
let f = readIntMatrix n 10 |> Array.map (Array.fold (fun (acc :int) (x : int)-> acc  * 2 + x) 0)
let p = readIntMatrix n 11
let benefit pattern shop = f.[shop] &&& pattern |> bitCount |> fun x ->  p.[shop].[x]
let totalBenefit pattern =  seq { 0 .. n - 1 } |> Seq.map (benefit pattern) |> Seq.sum

seq { 1 .. 0b1111111111 } |> Seq.map totalBenefit |> Seq.max |> puts


Measured memory_bytes: 13652
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n], as[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
        as[i] = a[i];
    }
    sort(as, as+n, greater<int>());
    for (auto ai:a) {
        if (ai == as[0]) cout << as[1] << endl;
        else             cout << as[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
public class Main {

  private static void solve() {
    int x = ni();
    int y = ni();

    int ret = 0;
    if (x == 1) {
      ret += 3;
    } else if (x == 2) {
      ret += 2;
    } else if (x == 3) {
      ret += 1;
    }
    if (y == 1) {
      ret += 3;
    } else if (y == 2) {
      ret += 2;
    } else if (y == 3) {
      ret += 1;
    }
    if (x == 1 && y == 1) {
      ret += 4;
    }
    System.out.println(ret * 100000);

  }

  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: 21332
#include <iostream>
using namespace std;

int main()
{
	int n=0;
	cin>>n;
	long long c = 100000;
	for ( int i=0; i<n; i++ )
	{
		c += c/20;
		c = (c+999)/1000*1000;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 0
L, R = list(map(int, input().split(' ')))
#print(L, R)
 
min = 2019
for i in range(L, R):
    for j in range(i + 1, R + 1):
        mod_ij = (i * j) % 2019
        if min > mod_ij:
            min = mod_ij
            if min == 0:
                break
    if min == 0:
        break
print(min)

Measured memory_bytes: 3060
n=int(input())
tbl=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
    b,f,r,v=map(int,input().split())
    tbl[b-1][f-1][r-1]+=v
for i in range(4):
    for j in range(3):
        print("",*tbl[i][j])
    if i!=3:
        print("#"*20)


Measured memory_bytes: 5624
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = a[i]
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Measured memory_bytes: 14084
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	A := getInt()
	B := getInt()
	
	diff := A - B * 2
	if diff < 0 {
		diff = 0
	}
	fmt.Println(diff)
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 21
#endif // LOCAL
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
string hidden = "#RBRRBBRBBR";
//#define debug

bool ask(int l,int r){
    #ifndef debug
    printf("?");
    for(int i = l ;i <= r ;i ++)
    printf(" %d", i);
    printf("\n");
    fflush(stdout);
    char c[5];
    scanf("%s", c);
    if(c[0] == '-') throw;
    return c[0] == 'R';
    #else
        int R = 0, B = 0;
        for(int i = l ; i <= r; i ++)
            if(hidden[i] == 'R') R ++;
            else B ++;
        return R > B;
    #endif
}
bool ask(vector<int> &p){
    #ifndef debug
    printf("?");
    for(int i: p)
        printf(" %d",i);
    printf("\n");
    fflush(stdout);
    char c[6];
    scanf("%s", c);
    if(c[0] == '-') throw;
    return c[0] == 'R';
    #else
    int R = 0, B = 0;
    for(int i: p){
        if(hidden[i] == 'R') R ++;
        else B ++;
    }
    return R > B;
    #endif
}/// red greater than blue
char ans[nax];

int main(){
    scanf("%d", &n);
    bool o = ask(1 , n);
    int idx = -1;
    {
        int l = 2, r = n + 1, mid;
        while(l <= r){
            mid = l + r >> 1;
         //   printf("%d %d %d\n", l, r, mid);
            bool now = ask(mid, mid + n - 1);
            if(now != o){
                idx = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        //printf("%d\n", idx);
    }
    if(idx == -1) throw;
    vector<int> toAsk ;
    for(int i = idx ; i < idx + n -1; i++)
        toAsk.push_back(i);
    auto inrange = [&] (int x){
        return x >= idx & x <= idx + n - 1;
    };
    for(int i = 1 ;i <= 2 * n ; i++){
        if(!inrange(i)){
            toAsk.push_back(i);
            bool go = ask(toAsk);
            if(go)
                ans[i] = 'R';
            else
                ans[i] = 'B';
            toAsk.pop_back();
        }
    }
    toAsk.clear();
    int r = 0, b = 0;
    for(int i = 1 ;i <= 2 * n ; i ++){
        if(!inrange(i)) {
            toAsk.push_back(i);
            if(ans[i] == 'R') r ++;
            else if(ans[i] == 'B') b ++;
            else throw;
        }
    }
    for(auto it = toAsk.begin() ; it != toAsk.end() ; ++ it){
        if(r > b && ans[*it] == 'R'){
            toAsk.erase(it);
            break;
        }
        else if(b > r && ans[*it] == 'B'){
            toAsk.erase(it);
            break;
        }
    }
    for(int i = 1 ;i <= 2 * n ; i++){
        if(inrange(i)){
            toAsk.push_back(i);
            bool go = ask(toAsk);
            if(go) ans[i] = 'R';
            else ans[i] = 'B';
            toAsk.pop_back();
        }
    }
    printf("! ");
    for(int i = 1 ;i <= 2 * n ; i++)
        printf("%c", ans[i]);
    printf("\n");
    fflush(stdout);
}
/*
Fuck didn't have enough time to code
*/
/*
    Long time no see!
    Atcoder...
*/


Measured memory_bytes: 724
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def C(n,r):
    return f[n]*pow(f[n-r],mod-2,mod)*pow(f[r],mod-2,mod) % mod

n,k = LI()
a = LI()
a.sort()
f = [1]*(n+1)
for i in range(1,n+1):
    f[i] = i*f[i-1]
    f[i] %= mod

ans = 0
for i in range(n):
    if k-1 <= i <= n-k:
        ans += C(i,k-1)*a[i]
        ans %= mod
        ans -= C(n-(i+1),k-1)*a[i]
        ans %= mod
    elif i < k-1 and i+k-1 < n:
        ans -= C(n-(i+1),k-1)*a[i]
        ans %= mod
    elif i > n-k and i-(k-1) >= 0:
        ans += C(i,k-1)*a[i]
        ans %= mod
print(ans)


Measured memory_bytes: 59248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #     
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;

    int a[5];
    rep(i, 0, 5)
            cin >>
        a[i];
    rep(i, 0, 5)
    {
        if (a[i] == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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; }

int main() {
    int n;
    cin >> n;
    ll T, A, t, a, m;
    cin >> T >> A;
    FOR1(i, n) {
        cin >> t >> a;
        m = max(T / t + (bool)(T % t), A / a + (bool)(A % a));
        T = t * m, A = a * m;
    }
    cout << T + A << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7

int main(){

    int n;
    cin >> n;
    int ans = INF;
    for(int i = 1;i <= n/2;i++){

        int a = i,b = n-i;
        int sum = 0;
        while(a/2 != 0){
            sum += a%10;
            a /= 10;
        }
        sum += a;
        while(b/2 != 0){
            sum += b%10;
            b /= 10;
        }
        sum += b;
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = [map(int, input().split()) for _ in range(N)]
M = int(input())
W = [int(input()) for _ in range(M)]
INF = 10 ** 9
maxW = 393
dp = [-INF] * (maxW + 1)
dp[0] = 0

for i in range(N):
    s, l, p = P[i]
    for j in range(s, maxW + 1):
        d = max(dp[max(0, j - l):max(1, j - s + 1)])
        dp[j] = max(dp[j], d + p)

ans = [dp[w] for w in W]
if min(ans) < 0:
    print(-1)
else:
    print(*ans, sep='\n')



Measured memory_bytes: 5840
package main

import "fmt"

func main() {
	var n int
	var A [100]int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	
	for i := 0; i < n; i++ {
		if i != n - 1 {
			fmt.Printf("%d ", A[n - i - 1])
		} else {
			fmt.Printf("%d\n", A[n - i - 1])
		}
	}
}


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

int main(){
    long long n, k;
    cin >> n >> k;
    long long cnt = 0;

    if(k == 0){
        cout << n*n << endl;
        return 0;
    }

    for(long long b=1; b<=n; b++){
        long long p = n/b;
        long long r = n%b;
        cnt += p*max(0LL, b-k) + max(0LL, r-k+1LL);
    }
    cout << cnt << endl;
    return 0;
}

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


def main():
    # 再帰の上限回数のデフォルトを変更
    from sys import setrecursionlimit
    setrecursionlimit(10 ** 7)

    n = int(input())
    graph = [list() for _ in range(n)]
    ans = [0 for _ in range(n - 1)]

    # KeyInsight:
    # 木の問題と再帰関数は相性がいい
    # See:
    # https://www.youtube.com/watch?v=7IlBVSglZqc
    for i in range(n - 1):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        graph[ai].append((bi, i))
        graph[bi].append((ai, i))

    # 実装できなかったところ
    # 1. 色のカウントをどう管理するか?
    # 2. 辺のidをどう管理するか?

    # 親方向からの色番号を引数に持つ
    def dfs(vertex, parent=-1, edge_color=-1):
        # 一般的なポイント: 頂点に関する処理を書く
        color_code = 1

        # 基本形: 親の頂点周りを探索
        for to, edge_id in graph[vertex]:
            if to == parent:
                continue

            # 一般的なポイント: 辺に関する処理を書く
            if color_code == edge_color:
                color_code += 1

            ans[edge_id] = color_code
            color_code += 1

            dfs(to, vertex, ans[edge_id])
            # 一般的なポイント: 辺に関する処理を書く

        # 一般的なポイント: 頂点に関する処理を書く

    dfs(0)
    count = 0

    for g in graph:
        count = max(count, len(g))

    print(count)
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


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

const ll MOD = 1e9 + 7;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};
using Int = ModInt<MOD>;


ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    Int s = 0, s2 = 0;
    for ( int i = 0; i < N; i++ ) {
        s += A[i];
        s2 += Int(A[i])*Int(A[i]);
    }
    Int t = s*s;
    t -= s2;
    t /= 2;
    ll ans = t.value;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4776
_n1, _n2, _n3, n = gets.strip.split.map(&:to_i)
d = 3.times.map { gets.strip.split.map(&:to_i) }

s = []
d[0].each do |i|
  d[1].each do |j|
		s << i + j
  end
end

s = s.sort.reverse.slice(0, n) if s.size > n

s2 = []
s.each do |i|
	d[2].each do |j|
		s2 << i + j
	end
end	

s2.sort!.reverse!
n.times { |i| puts s2[i] }


Measured memory_bytes: 85872
#include <stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i<=n;i++){
		if(n % i==0) return 0;
	}
	return 1;
}
int main(){
	int n,i, max=0;
	while(1){
		  scanf("%d",&n);
		  if(n==0) break;
		  for(i=n;i>=1;i--){
		  	if(isprime(i)==1 && isprime(i-2)==1){
			max=i;
			break;
			}
	    }
	    printf("%d %d\n",max-2,max);
	}
	return 0;
}

Measured memory_bytes: 1736