akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)

N, M, Q = map(int, input().split())
a = [None] * Q
b = [None] * Q
c = [None] * Q
d = [None] * Q

for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0

def recu(l):
    global ans
    if len(l) == N:
        # dの総和を計算
        tmp = 0
        for j in range(Q):
            if l[b[j]-1] - l[a[j]-1] == c[j]:
                tmp += d[j]
        ans = max(ans, tmp)
    else:
        for i in range(l[-1],M+1):
            recu(l + [i])

def main():
    
    l = [1]
    recu(l)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9236
#include<iostream>

using namespace std;

int main()
{int n,k,i;
string s;
	cin >> n;
	cin >> s;
	cin >> k;
	for(i=0;i<n;i++)
	{
		if(s[i] != s[k-1])
		{
			s[i] = '*';
		}
	}
	cout << s << endl;
}

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

bool isPrime(ll n){
    if(n == 1) return false;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(ll i = 3; i <= sqrt(n); i += 2){
        if(n % i == 0){
            return false;
        }
    }
    return true;
}


int main(){
    ll N,N_save;
    cin >> N;
    N_save = N;
    ll cnt = 0;
    vector<ll> div;
    div.clear();

    if(N == 1){
        cout << 0 << endl;
        return 0;
    }

    if(isPrime(N)){
        cout << 1 << endl;
        return 0;
    }

    for(ll i = 2; i <= sqrt(N); i++){
        if(isPrime(i) != 1) continue;
        ll tmp = i;
        while(N % i == 0){
            div.push_back(tmp);
            N /= i;
            tmp *= i;
        }
    }

    if(isPrime(N)){
        bool flag = true;
        for(int i = 0; i < int(div.size()); i++){
            if(div[i] == N){
                flag = false;
            }
        }
        if(flag){
            div.push_back(N);
        }
    }

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

    

    for(int i = 0; i < int(div.size()); i++){
        if(N_save % div[i] == 0){

            N_save /= div[i];
            
            cnt++;
        }
    }
    
    cout << cnt << endl;
}





Measured memory_bytes: 3724
#include <iostream>
#include <string>

using namespace std;

int main(void){

  string s;
  int JOI,IOI;

  while( cin >> s ){
    
    JOI = IOI = 0;

    for( int i = 0 ; i < s.size() - 2 ; i++ ){
      if( s.find("JOI" , i ) == i ) JOI++;
      if( s.find("IOI" , i ) == i ) IOI++;
    }
    cout << JOI << endl;
    cout << IOI << endl;

  }
  return 0;
}

Measured memory_bytes: 1200
from numpy import*
_,s,_,k=open(0)
s=array(list('='+s[:-1]))
d,m,c=[s==t for t in'DMC']
x,y=map(cumsum,(d,m))
for k in int32(k.split()):
  t=copy(x)
  t[k:]-=x[:-k]
  t*=m
  t[k+1:]-=d[1:-k]*(y[k:-1]-y[:~k])
  print(sum(cumsum(t)*c))

Measured memory_bytes: 58428
def readinput():
    s=input()
    t=input()
    return s,t

def main(s,t):
    count=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            count+=1
    return count

if __name__=='__main__':
    s,t=readinput()
    ans=main(s,t)
    print(ans)


Measured memory_bytes: 9440
main(k){long long int n,x,y;for(scanf("%lld%d",&n,&k);k--;printf("%d\n",(x<n/2)?(x-1)%3+1:(n-x)%3+1)){scanf("%lld%lld",&x,&y);if(y<n-y&&y<x &&y<n-x||n-y<x&&n-y<n-x)x=y;}exit(0);}

Measured memory_bytes: 0
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c)
#define     M               32000
int main()
{
    string s;
    cin>>s;
    string ss;
    cin>>ss;
    ss+=s;
    cout<<ss<<endl;
return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c,x;
	cin >> a >> b >> c;
	if (a > b&&a>c) {
		x = a * 10 + b + c;
	}
	else if (c > b&&c>a) {
		x = c * 10 + b + a;
	}
	else if (b > a&&b>c) {
		x = b* 10 + a + c;
	}
	else {
		x = a *10+ b + c;
	}
	cout << x << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define si set<int>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    GAME_OVER;
}

Measured memory_bytes: 3628
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    G = [[] for i in range(N)]
    for i in range(N - 1):
        a, b, c = map(int, readline().split())
        G[a-1].append((b-1, c))
        G[b-1].append((a-1, c))

    dist = [-1 for i in range(N)]
    Q, K = map(int, readline().split())
    dist[K-1] = 0
    q = deque([[K - 1, 0, -1]])
    while q:
        v, d, parent = q.popleft()
        dist[v] = d
        for child in G[v]:
            if child[0] == parent:
                continue
            q.append([child[0], d + child[1], v])

    for i in range(Q):
        x, y = map(int, readline().split())
        print(dist[x - 1] + dist[y - 1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 50312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N;
char res[222];
vector<int>v;
string s;

string query(vector<int>V) {
	cout << '?';
	for (int i : V) {
		cout << sp << i;
	}
	cout << endl;
	string a;
	cin >> a;
	return a;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		v.push_back(i);
	}
	int l = 1;
	int r = N + 1;
	if (query(v) == "Red") {
		while (l + 1 != r) {
			int m = (l + r) / 2;
			for (int i = 0; i < N; i++) {
				v[i] = m + i;
			}
			if (query(v) == "Red") {
				l = m;
			}
			else {
				r = m;
			}
		}
	}
	else {
		while (l + 1 != r) {
			int m = (l + r) / 2;
			for (int i = 0; i < N; i++) {
				v[i] = m + i;
			}
			if (query(v) == "Blue") {
				l = m;
			}
			else {
				r = m;
			}
		}
	}
	vector<int>p(N), q;
	for (int i = 0; i < N - 1; i++) {
		p[i] = r + i;
	}
	for (int i = 1; i < l; i++) {
		q.push_back(i);
	}
	for (int i = r + N; i <= N + N; i++) {
		q.push_back(i);
	}
	q.push_back(0);
	for (int i = 1; i <= N + N; i++) {
		if (r <= i&&i <= l + N - 1) {
			q[N - 1] = i;
			res[i] = query(q)[0];
		}
		else {
			p[N - 1] = i;
			res[i] = query(p)[0];
		}
	}
	cout << "! ";
	for (int i = 1; i <= N + N; i++) {
		cout << res[i];
	}
	cout << endl;
}

Measured memory_bytes: 724
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

#define _x first
#define _y second

enum type {
    TYPE_CCW,
    TYPE_CW,
    TYPE_ONBACK,
    TYPE_ONFRONT,
    TYPE_ONSEG,
};

string table[] = {
    "COUNTER_CLOCKWISE",
    "CLOCKWISE",
    "ONLINE_BACK",
    "ONLINE_FRONT",
    "ON_SEGMENT",
};

#define EPS (1e-6)
double outer_prod(pdd p1, pdd p2) {
    return p1._x * p2._y - p2._x * p1._y;
}

double norm(pdd p1) {
    return sqrt(p1._x*p1._x + p1._y*p1._y);
}

pdd get_incline(pdd p1, pdd p2, double* len) {
    pdd inc = make_pair(
        p2._x - p1._x,
        p2._y - p1._y
    );
    double leng = norm(inc);
    *len = leng;
    return make_pair(
        inc._x / leng,
        inc._y / leng
    );
}

bool is_equal(pdd p1, pdd p2) {
    return abs(p1._x - p2._x) < EPS && abs(p1._y - p2._y) < EPS;
}

int main(void) {
    pdd base, p2;
    cin >> base._x >> base._y;
    cin >> p2._x >> p2._y;
    double len1;
    pdd inc = get_incline(base, p2, &len1);
    int qs;
    cin >> qs;
    for(int i = 0; i < qs; i++) {
        pdd p;
        cin >> p._x >> p._y;
        double len2;
        pdd diff = get_incline(base, p, &len2);
        debug("%lf\n", len2);
        double val = outer_prod(inc, diff);
        int type;
        if(val > EPS) {
            type = TYPE_CCW;
        } else if(val < -EPS) {
            type = TYPE_CW;
        } else {
            // abs(val) < EPS
            if(abs(inc._x + diff._x) < EPS && \
                abs(inc._y + diff._y) < EPS) {
                type = TYPE_ONBACK;
            } else {
                if(is_equal(p2, p)) {
                    type = TYPE_ONSEG;
                } else {
                    type = (len1 > len2) ? TYPE_ONSEG : TYPE_ONFRONT;
                }
            }
        }
        cout << table[type] << endl;
    }
    return 0;
}


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

int main() {
    int k,s;
    cin>>k>>s;

    int cnt=0;

    for (int i=0;i<=k;i++) {
        for (int j=0;j<=k;j++) {
            if(s-i-j<=k&&s-i-j>=0){
                    cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,d,x; cin>>n>>d>>x;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll sum=x;
    rep(i,n){
        for(int day=1;day<=d;day+=a[i]){
            sum++;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, q; cin >> k >> q;
    V<int> d(k);
    for (int i = 0; i < k; i++) cin >> d[i];
    while (q-->0) {
        int n, m; ll x;
        cin >> n >> x >> m;
        x %= m;
        vll drem(k);
        V<int> cnt0(k, 0);
        for (int i = 0; i < k; i++) {
            drem[i] = (ll)(d[i] % m);
            if (drem[i] == 0) cnt0[i] = 1;
        }

        ll totald = accumulate(ALL(drem), 0LL);
        ll total0 = accumulate(ALL(cnt0), 0LL);
        totald *= (ll)((n - 1) / k);
        total0 *= (ll)((n - 1) / k);
        for (int i = 0; i < (n - 1) % k; i++) totald += drem[i], total0 += cnt0[i];
        ll lt = (totald + x) / m;
        cout << n - lt - total0 - 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
using namespace std;

int main() {
    int a;
    cin >> a;
    vector<int> d;
    for (int i = 0; i < a; i++) {
        int b;
        cin >> b;
        if (d.size()==0) {
            d.push_back(b);
            continue;
        }
        if(d.at(d.size()-1)>=b) d.push_back(b);
        else {

            int right = d.size();
            int left = -1;
            while (abs(right - left) > 1) {
                int mid = left + (right - left) / 2;

                if (d.at(mid)<b) right = mid;
                else left = mid;

            }
            d.at(right) = b;
        }
    }    
    cout << d.size() << endl;
}

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

using namespace std;

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

  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1')  ans++;
  }

  cout << ans << endl;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    string s;
    cin >> s;
    int z = 0, a = s.length() - 1;
    for (int i = 0; i < (int)s.length(); ++i) if (s[i] == 'Z') z = i;
    for (int i = s.length() - 1; i >= 0; --i) if (s[i] == 'A') a = i;
    cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// 0 1 ナップサック
class Main{
	public static void main(String[] args) {

		int[] value;
		int kazu=0;
		int kaisi=0,owari=0;
		int wa=0;
		int wa1_max=-2147483646;
		int total_max=-2147483646;
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		try {
			while(true) {
				str=bfr.readLine();
				kazu=Integer.parseInt(str);
				if(kazu==0) {
					System.exit(0);
				}
				else{
					value=new int[kazu];

					for(int i=0; i<kazu; i++) {
						str=bfr.readLine();
						value[i]=Integer.parseInt(str);
					}
					for(int i=0; i<kazu; i++) {
						kaisi=i;
						for(int j=i; j<kazu; j++) {
							wa+=value[j];
							if(wa>wa1_max) {
								wa1_max=wa;
								owari=j;
							}
							else {}
							if(wa1_max>total_max) {
								total_max=wa1_max;
							}
							else {}
						}
						wa1_max=-2147483646; wa=0;
					}
					System.out.println(total_max);
					total_max=-2147483646; kazu=-2147483646;
				}
			}
		}catch(IOException e) {
		}
	}
}


Measured memory_bytes: 25792
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif


piii dp[3005][3005], ans;
void solve()
{
	string a,b;
	cin >> a >> b;
	int n = a.length(), m = b.length();
	repA(i,0,n) repA(j,0,m) dp[i][j].ss.ff = dp[i][j].ss.ss = -inf ;
	for(int i = 0 ; i < n ; ++i)
		for(int j = 0 ; j < m ; ++j){
			if(a[i] == b[j])
				dp[i+1][j+1] = max(dp[i+1][j+1], {dp[i][j].ff + 1, {i,j}}) ;
			dp[i+1][j] = max(dp[i+1][j], {dp[i][j].ff,{i,j}}) ;
			dp[i][j+1] = max(dp[i][j+1], {dp[i][j].ff,{i,j}}) ;
		}
	repA(i,0,n) repA(j,0,m) ans=max(ans,{dp[i][j].ff,{i,j}}) ;
	// cout << ans.ff << '\n' ;
	string res = "" ;
	int x= ans.ss.ff, y= ans.ss.ss;
	do{
		int prex = dp[x][y].ss.ff, prey = dp[x][y].ss.ss ;
		if(prex < 0 || prey < 0) break ;
		if(x - prex == 1 && y - prey == 1)
			res += a[prex];
		x = prex, y = prey; 
	}while(x && y); 
	reverse(all(res));
	cout << res;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

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

using namespace std;

static long long MOD = 1e9 + 7;

long long calc_perm (long long n, long long r) {
    long long ret = 1;
    for ( int i = 0; i < r; i++ ) {
        ret *= n;
        ret %= MOD;
        n--;
    }
    return ret;
}

int main (void) {
    int N, M;
    cin >> N >> M;

    if ( abs(N - M) > 1 ) {
        cout << 0 << endl;
        return 0;
    }

    long long n_perm = calc_perm(N, N);
    long long m_perm = calc_perm(M, M);
    long long ans = (n_perm * m_perm) % MOD;
    if ( abs(N - M) != 1 )
        ans = (2 * ans) % MOD;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long
#define vi vector<int>
using namespace std;
struct objects
{
    int weight, value;
};
ll solve()
{
    int n, w;
    cin >> n >> w;
    objects object[n];
    int totalvalue = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> object[i].weight >> object[i].value;
        totalvalue += object[i].value;
    }
    ll dp[n + 1][totalvalue + 1];
    //dp[i][j] denotes the least weight to get a value of
    // j from the first i objects
    dp[0][0] = 0; //It takes 0 weight here
    int ans = 0;
    for (int i = 1; i <= totalvalue; i++)
    {
        dp[0][i] = w + 1;
        // Just set it arbitrarily large
        //because it's not possible
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= totalvalue; j++)
        {
            if (j >= object[i].value)
            {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - object[i].value] + object[i].weight);
                //Either don't choose this object(dp[i][j]) or choose this object
                //The value without it would be j-object[i].value
                //the minimum weight would be the minimum weight needed to
                //get a value of j- object[i].value and add the weight of this object.
            }
            else
            {
                //If I choose this object the value will go over j
                dp[i + 1][j] = dp[i][j];
            }
            if (dp[i + 1][j] <= w)
            {                      //Is it possible to get value of j in less than w weight
                ans = max(ans, j); //Find maximum such j
            }
        }
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << solve();
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    vector<int32> m,p;
    int32 cntZero = 0;
    REP(i,n){
        int32 a;
        cin >> a;
        if(a < 0){
            m.pb(a);
        }else if(a > 0){
            p.pb(a);
        }else{
            cntZero++;
        }
    }
    int32 mCnt = m.size() * p.size();
    if(k <= mCnt){
        sort(m.rbegin(),m.rend());
        sort(p.rbegin(),p.rend());
        int32 l = -LLINF;
        int32 r = 0;
        while(r - l > 1){
            int32 mid = (l + r) / 2;
            int32 y=0;
            int32 cnt = 0;
            REP(x,m.size()){
                while(y < p.size() && m[x] * p[y] <= mid)y++;
                cnt += y;
            }
            // cout << mid << " " << cnt << endl;
            if(cnt < k){
                l = mid;
            }else{
                r = mid;
            }
        }
        ANS(r);
    }else if(k <= mCnt + cntZero * (cntZero - 1) / 2 + (n - cntZero) * cntZero){
        ANS(0);
    }else{
        sort(m.rbegin(),m.rend());
        sort(ALL(p));
        int32 l = 0,r=(1e18)+5;
        while(r - l > 1){
            int32 mid = (l + r) / 2;
            int32 cnt = 0;
            int32 y=0;
            FORR(x,m.size()-1,0){
                while(y < m.size() && m[x] * m[y] <= mid)y++;
                cnt += y;
                if(y > x)cnt--;
            }
            y=0;
            FORR(x,p.size()-1,0){
                while(y < p.size() && p[x] * p[y] <= mid)y++;
                cnt += y;
                if(y > x)cnt--;
            }
            cnt /= 2;
            cnt += mCnt + cntZero * (cntZero - 1) / 2 + (n - cntZero) * cntZero;
            // cout << mid << " " << cnt << endl;
            if(cnt < k){
                l = mid;
            }else{
                r = mid;
            }
        }
        ANS(r);
    }
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;

  int spsheet[r + 1][c + 1] = {};
  int tmp;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> tmp;
      spsheet[i][j] = tmp;
      spsheet[i][c] += tmp;
      spsheet[r][j] += tmp;
    }
    spsheet[r][c] += spsheet[i][c];
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j < c; j++) {
      cout << spsheet[i][j] << " ";
    }
    cout << spsheet[i][c] << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int n, t, hd = 0;
int a[100000];
i_i stk[100000];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d%d", &n, &t);
    rep(i, n)scanf("%d", &a[i]);

    int cnt = 0, ma = 0, maid, mx = 0;
    per(i, n){
      if(ma < a[i])maid = i;
      ma = max(ma, a[i]);
      if(mx < ma - a[i]){
        hd = 0;
        mx = max(mx, ma - a[i]);
        stk[hd++] = mp(i, maid);
      }else if(mx == ma - a[i]){
        stk[hd++] = mp(i, maid);
      }
    }

    pri(hd);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ld long double
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
// ll mod=1e9+7;
ll mod2=998244353;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactive problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll power(ll x, ll y, ll p){
    ll res=1;
    while(y>0){
        if(y%2==1){
            res = (res*x)%p;
        }
        x = (x*x)%p;
        y=y/2;
    }
    return res;
}

int main(){ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n,x,m;
    cin>>n>>x>>m;

    set<ll> s1;
    vector<ll> v;
    s1.insert(x);
    v.push_back(x);
    ll pow1=2;
    ll num=x;
    ll ans=x;
    ll left=n-1;

    while((s1.find(power(num, pow1, m))==s1.end()) && (left!=0)){
        num = power(num, pow1, m);
        s1.insert(num);
        v.push_back(num);
        ans+=num;
        left--;
    }

    if(left==0){
        cout<<ans;
        return 0;
    }

    num = power(num, pow1, m);
    vector<ll> v1;
    ll ind=0;
    for (int i = 0; i < v.size(); ++i)
    {
        if(v[i]==num){
            ind=i;
            break;
        }
    }

    for (int i = ind; i < v.size(); ++i)
    {
        v1.push_back(v[i]);
    }

    ll sum=0;
    for (int i = 0; i < v1.size(); ++i)
    {
        sum+=v1[i];
    }
    ll q = left/v1.size();
    ll r = left%v1.size();

    ans = ans + (sum*q);

    for (int i = 0; i < r; ++i)
    {
        ans+=v1[i];
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 6680
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int result = 0;
    int ahead;
    int current = 100000;
    for (int i = 0; i < N - 1; i++) {
      ahead = current;
      current = sc.nextInt();
      result += Math.min(ahead, current);
    }
    result += current;
    System.out.println(result);
  }
}

Measured memory_bytes: 24916
# C
H, W = map(int, input().split())

res = min(H, W)
# split H
for h in range(H // 3, H // 3 + 3):
    w = W // 2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    res = min(res, max(s1,s2,s3) - min(s1,s2,s3))
# split W
for w in range(W // 3, W // 3 + 3):
    h = H // 2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    res = min(res, max(s1,s2,s3) - min(s1,s2,s3))

# 3
if H % 3 == 0 or W % 3 == 0:
    res = 0
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll);  -> a/=b;  result: a = 3
struct ModInt{
	ll val;
	ModInt():val(0ll){}
	ModInt(ll v):val(((v%MOD)+MOD)%MOD){}
	ModInt exp(ll y)const{
		if(!y)return ModInt(1ll);
		ModInt a = exp(y/2ll);
		a *= a;
		if(y&1)a*=(*this);
		return a;
	}
	bool operator==(const ModInt& x)const{return val==x.val;}
	inline bool operator!=(const ModInt& x)const{return !(*this==x);}
	bool operator<(const ModInt& x)const{return val<x.val;}
	bool operator>(const ModInt& x)const{return val>x.val;}
	inline bool operator>=(const ModInt& x)const{return !(*this<x);}
	inline bool operator<=(const ModInt& x)const{return !(*this>x);}
	ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;}
	ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;}
};
istream& operator>>(istream&i,ModInt&x){i>>x.val;return i;}
ostream& operator<<(ostream&o,const ModInt&x){o<<x.val;return o;}
const int SIZE = 100100;
ModInt inv[SIZE+10],fac[SIZE+10],facinv[SIZE+10];
// notice: 0C0 = 1 
ModInt nCr(int n,int r){
	assert(!(n<r));
	assert(!(n<0||r<0));
	return fac[n]*facinv[r]*facinv[n-r];
}
void init(){
	fac[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)fac[i]=fac[i-1]*ModInt(i);
	inv[1]=ModInt(1ll);
	for(int i=2;i<=SIZE;i++)inv[i]=ModInt(0ll)-ModInt(MOD/i)*inv[MOD%i];
	facinv[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)facinv[i]=facinv[i-1]*inv[i];
	return;
}
int N;
ModInt A[100100];
ModInt invrui[100100];
int main(){
	init();
	scanf("%d",&N);
	for(int i=0;i<N;i++)cin >> A[i];
	invrui[1]=inv[1];
	for(int i=2;i<=N;i++)invrui[i]=invrui[i-1]+inv[i];
	ModInt ans;
	for(int i=0;i<N;i++){
		ans += A[i]*fac[N]*(invrui[N-i]+invrui[i+1]-inv[1]);
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <stdio.h>
using namespace std;


void solve(long long H, long long W){
    // 横に
    if(H == 1 && W == 1){
        cout << 1 << endl;
        return;
    }

    if(H == 1) {
        if(H % 2 == 0) cout << H/2 << endl;
        else cout << H/2 + 1 << endl;
        return;
    }

    if(W == 1) {
        if(W % 2 == 0) cout << W/2 << endl;
        else cout << W/2 + 1 << endl;
        return;
    }

    long long c;
    if(W % 2 == 0) c = W / 2;
    else c = W/2 + 1;
    long long c_r = W - c; // 次の横列

    long long d;// 最初の列が入る行数
    if(H % 2 == 0) d = H/2;
    else d = H/2 + 1;
    long long d_r = H - d; // 次の横列が入る行数

    cout << c*d + c_r*d_r << endl;
}

// 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)
int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(H, W);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int64_t N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    for(int i=0; i<N; i++) {
        cin >> a[i] >> b[i];
    }
    int64_t m = *max_element(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    int i;
    for(i=0; i<N; i++) {
        if(b[i] >= m) {
            H -= b[i];
            if(H <= 0) {
                cout << i+1 << endl;
                return 0;
            }
        } else {
            break;
        }
    }
    cout << i + (H+m-1)/m << endl;
    return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto item : (x))
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    string s,t;cin>>s>>t;
    printf("%s%s",t.c_str(),s.c_str());
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
string S; unsigned long c=0, d=1, e=1, g=0, ans=0, K; cin >> S >> K;
int l=S.size(); bool f=false;
for(int i=1; i<l; i++){ if(S[i-1]==S[i]){i++;c++;if(i==l){f=true;}} }  
for(int i=l-2; i>=0; i--){ if(S[i+1]==S[i]){i--;if(i==-1){f=true;}} }

if(S[0]!=S[l-1]||f){ans=c*K;}
else{ 
   for(int i=1; i<l; i++){if(S[i]!=S[i-1]){break;}else{d++;}}
   if(d==l){ans=l*K/2;} 
   else{ for(int i=l-2; i>=0; i--){if(S[i]!=S[i+1]){break;}else{e++;}}
         for(int i=d+1; i<l-e; i++){if(S[i]==S[i-1]){i++;g++;}}
         ans=((d+e)/2)*(K-1)+(g*K)+(d/2)+(e/2);
       }
}  
cout << ans << "\n";
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

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

func gcd(x int, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x % y)
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b, c := nextInt(), nextInt(), nextInt()
	
	d := gcd(a, b)

	if c % d == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int w;
	while(cin >> w && w + 1)
	{
		int dw[] = {125, 140, 160};
		int res = 1150;
		
		w -= 10;
		for(int i = 0; 0 < w--; i++)
			res += dw[min(i / 10, 2)];

		cout << 4280 - res << endl;
	}
}

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

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

    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int i=0; i<=N; ++i) {
        for (int j=0; i+j<=N; ++j) {
            int k = N - i - j;
            int total = 10000*i + 5000*j + 1000*k;
            if (k>=0 && total == Y) {
                res10000 = i;
                res5000 = j;
                res1000 = k;
            }
        }
    }

    cout << res10000 << " " << res5000 << " " << res1000 << endl; 
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)998244353

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N,A[202020];
ll w[1010101];
ll mk[1010101],mk2[1010101];

ll i, j, k,ans;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        mk[A[i]]++;
    }
    fornum(i,1,1000001){
        w[i] = (moddiv(1, i) + MOD - w[i]) % MOD;
        for (j = i*2; j <= 1000000;j+=i){
            w[j] = (w[j] + w[i]) % MOD;
        }
    }
    fornum(i,1,1000001){
        ll a = 0, b = 0;
        for (j = i; j <= 1000000;j+=i){
            fornum(k,0,mk[j]){
                a = (a + b * j)%MOD;
                b = (b + j) % MOD;
            }
        }
        ans = (ans + w[i] * a) % MOD;
        /*
        for (j = i; j <= 1000000;j+=i){
            mk2[j] = (mk2[j] + w[i]) % MOD;
        }
        if(mk2[i]*i%MOD!=1)
        printf("%lld:%lld ", i, mk2[i] * i%MOD);
        */
    }
    printf("%lld", ans);
    return 0;
}

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

int main(void) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= 2000; i++) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int k,n,a[200009],b[200009];
int main(){
    cin>>k>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(i!=n-1)b[i]=a[i+1]-a[i];
        else b[i]=k-a[n-1]+a[0];
    }
    sort(b,b+n);
    cout<<k-b[n-1]<<endl;
}


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

int main() {
  vector<pair<int,int>>odd(100005);
  vector<pair<int,int>>even(100005);
  int N;
  cin >> N;
  for(int i=0;i<N/2;i++){
    int x,y;
    cin >> x >> y;
    odd.at(x).first++;
    odd.at(x).second=x;
    even.at(y).first++;
    even.at(y).second=y;
  }
  sort(odd.begin(),odd.end());
  reverse(odd.begin(),odd.end());
  sort(even.begin(),even.end());
  reverse(even.begin(),even.end());
  if(odd.at(0).second==even.at(0).second){
    if(odd.at(1).first+even.at(0).first>even.at(1).first+odd.at(0).first) cout << N-odd.at(1).first-even.at(0).first;
    else cout << N-even.at(1).first-odd.at(0).first;
  }
  else cout << N-odd.at(0).first-even.at(0).first;
}

Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll ret = 0;
    for(int i = 0;i < N;i++) {
        ret += vec.at(i);
    }
    for(int i = 1;i <= N;i++) {
        ret -= i;
    }
    cout << ret << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
int a,b,c,d,e,f,max,ans;
scanf("%d %d %d",&a,&b,&c);
d=a-b;
e=b-c;
f=c-a;
if(d<0) d=d*(-1);
if(e<0) e=e*(-1);
if(f<0) f=f*(-1);
max=d;
if(d<e) max=e;
if(max<f) max=f;
ans=d+e+f-max;
printf("%d",ans);
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Rep(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define ALL(V) (V).begin(),(V).end()
const ll  Inf = 1LL << 60;
 
int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    cout << z  << " " << x << " " << y <<endl;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<int> VI;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

int min(int i, int j) {
	if (i < j)
		return i;
	else
		return j;

}

int max(int i, int j) {

	if (i > j)
		return i;
	else
		return j;
}


//グラフの隣接リスト
VI g[100010];
//頂点の入次数を管理
int h[100010];
int day[100010];
int vis[100010];
signed main(void)
{

	string S, T;

	cin >> S >> T;
	int d = 0;
	REP(i, S.size()) {
		if (S[i] == T[i]) {
			d++;
		}
	}

	cout << d << endl;
	return 0;
}

Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n; cin >> n;
	vector<ll> a(n+1), b(n);
	rep(i,n+1) cin >> a[i];
	rep(i,n) cin >> b[i];
	a.push_back(0);
	ll ans = 0;
	ll mons = a[0] + a[1];
	rep(i,n){
		if(b[i] >= mons){
			ans+=mons;
			mons=0;
		}else{
			ans+=b[i];
			mons-=b[i];
		}
		mons+=a[i+2];
		mons = min(mons, a[i+1]+a[i+2]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
/* this code is generated by shikhar verma . Dont try to copy it. You may be booked under plaigarism. */
int numberofPaths(int h,int w,int a,int b);
int main()
{
    ll n,i,j,len1,a,b,h,w,t;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	cout<<n*(n+1)/2<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long LL;
LL gi () {
    LL ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
const int N = 100000 + 10;
int n,k,a[N],b[N];
int main () {
    n = gi(); k = gi()+1;
    for(int i=1;i<=n;i+=1) a[i] = gi(), b[i] = gi();
    LL ans = 0;
    for(int i=0;i<=30;i+=1) {
        if(~(k>>i)&1) continue;
        int lim = (k^(1<<i)) | ((1<<i)-1);
        LL cur = 0;
        for(int j=1;j<=n;j+=1) if((a[j]&lim)==a[j]) cur += b[j];
        ans = max(ans,cur);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
n, m = (int(x) for x in input().split())
num_point = [int(x) for x in input().split()]
count = 0
 
for n in num_point:
    if n >= (sum(num_point) / (4 * m)):
        count += 1
 
if count >= m:
    print("Yes")
else:
    print("No")

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

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

int main(){
  int X,A;
  cin>>X>>A;
  if(X<A)
    cout<<0<<endl;
  else
    cout<<10<<endl;

  return 0;
}


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

int main() {

 int A,B,C;
 cin >> A >> B >>C;
int ans = 1000;
  ans = min(ans,abs(B-A)+abs(C-B));
    ans = min(ans,abs(C-A)+abs(C-B));
      ans = min(ans,abs(A-B)+abs(C-A));
        ans = min(ans,abs(C-B)+abs(A-C));
          ans = min(ans,abs(A-C)+abs(A-B));
            ans = min(ans,abs(B-C)+abs(A-C));

cout <<ans<<endl;



  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {        
    long long int res = 0;
    long long int n, k;
    cin >> n >> k;
    if (k == 0) {
        cout << n * n << endl;
        return 0;
    }
    for (long long int b = k + 1; b <= n; b++) {
        res += (n / b) * (b - 1 - k + 1) + max((long long int)0, n % b - k + 1);
        // cout << res << endl;
    }
    cout << res << endl;
}


Measured memory_bytes: 3596