akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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(){
  ll n;
  cin >> n;
  ll a = n % 10;
  ll b = n / 10;
  if(a==9||b==9){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N = 1e9+7;
ll maxProductSubarrayOfSizeK(ll A[], ll n, ll k)
{
    sort(A, A + n);
 
 
    ll product = 1;
 
 
    if (A[n - 1] == 0 && (k & 1))
        return 0;
 
 
    if (A[n - 1] <= 0 && (k & 1))
    {
        for (ll i = n - 1; i >= n - k; i--)
        {
            product = (product*A[i])%N;
            product = (product+N)%N;
        }
        return product;
    }
    ll i = 0;
 
    ll j = n - 1;
 
 
    if (k & 1)
    {
        product = (product*A[j])%N;
        product = (product+N)%N;
        j--;
        k--;
    }
 
    k >>= 1;
    for (ll itr = 0; itr < k; itr++)
    {
        //cout<<i<<" "<<product<<endl;
        ll left_product = A[i] * A[i + 1];
 
        ll right_product = A[j] * A[j - 1];
 
        if (left_product > right_product)
        {
            product = (product*A[i])%N;
            product = (product*A[i+1])%N;
            product = (product+N)%N;
            i += 2;
        }
        else
        {
            product = (product*A[j])%N;
            product = (product*A[j-1])%N;
            product = (product+N)%N;
            j -= 2;
        }
    }
 
 
    return product;
}
 
int main()
{
    ll a[200009];
    ll i,j,k,n,m,x;
    cin>>n>>k;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    cout << maxProductSubarrayOfSizeK(a, n, k);
 
    return 0;
}

Measured memory_bytes: 5108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

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

int i;

int main(void){
    
    int  x,a,b;
    cin >> x >> a >> b;
    int c=b-a;
    if(c>x)cout<<"dangerous";
    else if(c<=x){
        if(a>=b)cout<<"delicious";
        else cout<<"safe";
    }
    
    
    
    return 0;
    
}


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

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

int main(){
  int n;
  cin>>n;
  set<int> s;
  rep(i,n){
    int tmp = 0; 
    cin >> tmp;
    if(s.count(tmp))s.erase(tmp);
    else s.insert(tmp);
  }
  cout<<s.size()<<endl;
  return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

void fastio(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	return;
}
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
	if (n == 0)return 1;
	if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
	return (x * modexp((x * x) % md, n / 2, md)) % md;
}


int main() {
	fastio();
	//clock_t tm = clock();
	ll x;
	cin>>x;
	ll curr=100,ans=0;
	while(curr<x){
		curr=floor(curr*1.01);
		ans++;
	}
	cout<<ans<<endl;
	//cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 3760
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>
#define mod 1000000007 

int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long int mount[100001] = {}, temp[100001];
int check_mount[100001] = {};
int n;

long long int amari(int i) {
	if(i == n) return 1;
	if(check_mount[i] == 0) {
		return mount[i] * amari(i+1) % mod;
	}
	else return amari(i+1);
}

int main() {


	cin >> n;
	check_mount[0] = 1;
	check_mount[n-1] = 1;

	for(int i = 0; i < n; i++) {
		cin >> mount[i];
		if(i != 0) {
			if(mount[i] != mount[i-1]) check_mount[i] = 1;
		}
	}

	int max_mount = mount[n-1];

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

	for(int i = n-1; i > -1; i--) {
		if(mount[i] > mount[i-1] && mount[i] > temp[i]) { cout << 0 <<endl; return 0; }
		if(temp[i] > max_mount) { cout << 0 <<endl; return 0; }
		if(i == n-1) mount[i] = temp[i];
		else {
			if(mount[i] > temp[i]) mount[i] = temp[i];
			if(temp[i] != temp[i+1]) check_mount[i] = 1;
		}
	}

	cout << amari(0) <<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main()
{
int x,y,a,b,c;
cin>>x>>y;
a=x-y;
b=x+y;
c=x*y;
if(a>=b && a>=c) cout<<a<<endl;
else if (b>=a && b>=c ) cout<<b<<endl;
else cout<<c<<endl;

    return 0;
}


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

#define int long long

using namespace std;

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

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    int n, k, answ = LLONG_MIN;
    cin >> n >> k;

    int p[n], c[n];
    for(int i = 0; i < n; i++)
        cin >> p[i];
    for(int i = 0; i < n; i++)
        cin >> c[i];

    vector<int> v;
    v.reserve(n+100);

    for(int pos = 0; pos < n; pos++) {
        int cnt[n+5] = {0};
        v.clear();
        int cur = pos;
        while(cnt[cur] == 0) {
            cnt[cur]++;
            v.push_back(c[cur]);
            cur = p[cur]-1;
        }
        int sz = (int)v.size();
        int s[sz] = {0}, val = LLONG_MIN;
        s[0] = v[0];
        for(int i = 1; i < sz; i++)
            s[i] = s[i-1] + v[i];
        if(k <= sz) {
            for(int i = 0; i < k; i++)
                val = max(val, s[i]);
            answ = max(answ, val);
        }
        else {
            for(int i = 0; i < sz; i++)
                val = max(val, s[i]);
            int temp_val = 0;
            for(int i = 0; i < (k % sz ? k%sz : sz); i++)
                temp_val = max(temp_val, s[i]);
            answ = max(answ, max(val, (s[sz-1])*(k/sz - (k%sz==0))+temp_val));
        }
    }

    cout << answ;

    return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
int main(void)
{
    int x, y, z;

    cin >> x >> y >> z;

    int i = 0;
    int t = 0;
    int ans = 0;
    while(t+y+z <= x) {
        if (i % 2 == 0) {
            t += z;
        }
        else {
            t += y;
            ans++;
        }
        i++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// D - Widespread
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define roundup(a,b) (((a)+(b)-1)/(b))

int main(){
	int N,A,B; cin>>N>>A>>B;
	vector<int> H(N); for(int i=0; i<N; ++i) cin>>H[i];
	int ans = INT_MAX;
	LL ab = (LL)A - B;//additional damage
	int L = 0, R = 1e9;
	while(L <= R){
		int t = (L + R)/2;//mid
		LL tb = (LL)t * B;
		LL s = 0;
		for(int hi:H){
			LL h = hi - tb;
			if(h > 0) s += roundup(h, ab);
		}
		if(t >= s){
			R = t - 1;//mid-1
			ans = t;
		}
		else L = t + 1;//mid+1
	}
	cout<< ans <<endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll x;
    cin >> x;
    cout << (x==1 ? 0 : 1) << endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int selectionSort(int *a, int n);

int main()
{
	int n;
	int a[100];

	scanf("%d", &n);

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

	int cnt;
    cnt = selectionSort(a, n);

	for (int i = 0; i < n; i++){
		if (i == n - 1){
			cout << a[i] << endl;
		}
		else {
			cout << a[i] << " ";
		}
	}

	cout << cnt << endl;

	return (0);
}

int selectionSort(int *a, int n)
{
	int cnt = 0;

	for (int i = 0; i < n - 1; i++){
		int minj = i;
		for (int j = i; j < n; j++){
			if (a[j] < a[minj]){
				minj = j;
			}
		}
		swap(a[i], a[minj]);
		if (i != minj){
			cnt++;
		}
	}

	return (cnt);
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    int M, T;
    scanf("%d%d", &M, &T);
    VI a(N);
    for_each(ALL(a), [](int &e){scanf("%d", &e);});
    int ans = a[0] - M;
    FOR(i, 1, N) {
        if (a[i] - a[i - 1] > 2 * M) {
            ans += a[i] - a[i - 1] - 2 * M;
        }
    }
    if (T - a.back() - M > 0) {
        ans += T - a.back() - M;
    }
    cout << ans << endl;
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        return 0;
    }
}

Measured memory_bytes: 3144
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
  ll N;
  while (cin >> N) {
    // (4 * ab - N * (a + b)) c = N(ab)
    for (ll a = 1; a <= 3500; a++) {
      for (ll b = 1; b <= 3500; b++) {
        ll k = 4 * a * b - N * (a + b);
        ll v = N * a * b;
        if (k == 0) continue;
        if (k < 0) {
          k = -k;
          v = -v;
        }
        if (v >= k && v % k == 0) {
          ll c = v / k;
          cout << a << " " << b << " " << c << " " << endl;
          goto end;
        }
      }
    }
  end:;
  }
  return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string S;
signed main() {
    cin >> N >> S;
    int ans = 0;
    for (int i = 2; i < N; i++) {
        if (S[i - 2] == 'A' && S[i - 1] == 'B' && S[i] == 'C') { ans++; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	cout << (h2-h1)*60+m2-m1-k << endl;

}


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

typedef long long ll;

const int N = 2000+5;
const int MOD = 1e9+7;
int a[N];

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

	int n, k;
	cin >> n >> k;
	for(int i=1; i<=n; i++)
		cin >> a[i];

	ll ans = 0;
	for(int i=1; i<=n; i++){
		ll cntMax = 0;
		for(int j=1; j<=n; j++)
			cntMax += (a[i] < a[j]);

		ll tmp = 1LL * k * (k-1) / 2 % MOD;
		tmp = tmp * cntMax % MOD;
		(ans += tmp) %= MOD;

		for(int j=1; j<i; j++)
			if(a[j] > a[i])
				(ans += k) %= MOD;
	}
	
	cout << (ans + MOD) % MOD;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int K; cin >> K;
    queue<ll> Q;

    for(int i=1; i<=9; i++) Q.push(i);

    REP(i,K-1){
        ll x = Q.front();
        Q.pop();
        //cout << "x= " << x << endl;
        if(x%10!=0) Q.push(10ll*x + (x%10) -1);
        Q.push(10*x + x%10);
        if(x%10!=9) Q.push(10ll*x + (x%10) +1);
    }

    cout << Q.front() << endl;


    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	if(a==b-1) puts("Borys");
	else{
		for(int i=1;i<=n;i++){
			a++;
			if(a==b-1){
				puts("Alice");
				exit(0);
			}
			b--;
			if(a==b-1){
				puts("Borys");
				exit(0);
			}
		}
	}
	return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 100005;
int n, m, q[MX], u, v, p[MX];
ll a[MX], b[MX], dp[MX], s[MX];
vi adj[MX], to[MX];
bitset<MX> bs;
int parent (int a) { return p[a] == a ? a : p[a] = parent(p[a]); }

void dfs (int u) {
	for (int v : to[u]) dfs(v), s[u] += s[v];
	s[u] += b[u], dp[u] = to[u].size() ? 1e18 : a[u] + b[u];
	for (int v : to[u]) dp[u] = min(dp[u], s[u] - s[v] + max(dp[v], a[u]));
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	iota(p, p+MX, 0);
	iota(q, q+MX, 1);

	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		a[i] = max(a[i] - b[i], 0ll);
	}

	while (m--) {
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	sort(q, q+n, [&] (int i, int j) {
		return a[i] < a[j];
	});

	for (int i = 0; i < n; i++) {
		u = q[i];
		bs[u] = 1; 
		for (int v : adj[u]) {
			if (parent(u) == parent(v) || !bs[v]) continue;
			v = parent(v);
			to[u].pb(v);
			p[v] = u;
		}
	}

	dfs(q[n-1]);
	cout << dp[q[n-1]] << endl;

	return 0;
}


Measured memory_bytes: 18940
#include <bits/stdc++.h>
using namespace std;
int a[111];
int n,l=0,r=0,minn=111;
int main()
{
	cin >>n;
	for(int i=0;i<n;i++)
	{
		cin >>a[i];
		r+=a[i];
	}
	minn=abs(r-l);
	for(int i=0;i<n;i++)
	{
		r-=a[i];
		l+=a[i];
		minn=min(minn,abs(r-l));
	}
	cout <<minn<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int matiCount = inpt[0];
        int roadCount = inpt[1];

        int[] road = new int[matiCount];
        for (int i = 0; i < roadCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a) - 1).ToArray();
            road[inpt[0]]++;
            road[inpt[1]]++;
        }
        StringBuilder ans = new StringBuilder();
        road.ToList().ForEach(a=>ans.AppendLine(a.ToString()));
        Console.Write(ans.ToString());
    }




	public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


4 3
1 2
2 3
1 4



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<ll> a(x), b(y), c(z);
	rep(i, x) {
		cin >> a[i];
	}
	rep(i, y) {
		cin >> b[i];
	}
	rep(i, z) {
		cin >> c[i];
	}

	vector<ll> ab;

	rep(i, x) {
		rep(j, y) {
			ab.push_back(a[i] + b[j]);
		}
	}

	sort(allof(ab), greater<ll>());

	vector<ll> abc;

	rep(i, x * y) {
		if (i == k) break;
		rep(j, z) {
			if (j == k) break;
			abc.push_back(ab[i] + c[j]);
		}
	}

	sort(allof(abc), greater<ll>());

	rep(i, k) {
		cout << abc[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 43096
#include <bits/stdc++.h>
#define ll long long int
#include<list>
#include<algorithm>
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define EF else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define UMP unordered_map
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;

    /*
    **  author : mahiman12
    **  created : 2020-05-10 17:33 
    */
    cin>>a>>b>>c>>k;
    ll res = 0;
    res += min(a,k);
    k -= min(a,k);
    k -= min(b,k);
    res -= min(c,k);
    cout<<res;
}




Measured memory_bytes: 3672
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    if n % 2 != 0:
        print(0)
    else:
        f = [2] * 30
        for i in range(29):
            f[i + 1] = 5 * f[i]
        ans = 0
        for i in range(1, 30):
            ans += (n // f[i])
        print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			List<String> list = new ArrayList<>();
			int n = in.nextInt();
			int l = in.nextInt();
			for (int i = 0; i < n; i++) {
				list.add(in.nextString());
			}
			Collections.sort(list);
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < n; i++) {
				sb.append(list.get(i));
			}
			out.println(sb.toString());

		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

int main() {
  int A,B;
  string S,T,U;
  cin >> S >> T >> A >> B >> U;
  
  if(S == U) cout << A - 1 << " " << B << endl;
  
  else cout << A << " " << B - 1 << endl;
  
}


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;
int res = 0;
vector<vector<int> > g;
vector<bool> visited;

void dfs(int s = 0, int p = -1) {
    bool ok = true;
    rep (i, n) if (!visited[i]) ok = false;
    if (ok) {
        res++;
        return;
    }
    rep (i, g[s].size()) {
        int v = g[s][i];
        if (p == v) continue;
        if (visited[v]) continue;
        visited[v] = true;
        dfs(v, s);
        visited[v] = false;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int m;
    cin >> n >> m;
    g.resize(n);
    visited.resize(n);
    rep (i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    visited[0] = true;
    dfs();
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MOD 1000000007

int main(){
    int n,m,i;
    int a[100000];
     long long int stair[100001];
   
    scanf("%d %d",&n,&m);
    
    for(i=0;i<=n;i++){
        stair[i] = -1;
    }

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

    stair[0] = 1;

    if(a[0]==1){
        stair[1] = 0;
    }
    else{
    stair[1] = 1;
    }

    for(i=0;i<m;i++){
        stair[a[i]]=0;
    }

    for(i=2;i<=n;i++){
        if(stair[i]==0){
        }
        else{
        stair[i] = (stair[i-2]+stair[i-1])%MOD;
        }
    }

    printf("%lld\n",stair[n]);
    return 0;
}


Measured memory_bytes: 1280
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int a, b;
  readf("%s %s\n", &a, &b);
  if (a < b) {
    foreach (_; 0..b) {
      write(a);
    }
  } else {
    foreach (_; 0..a) {
      write(b);
    }
  }
  writeln();
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Integer> set = new HashSet<Integer>();
		for(int i = 0; i < N; i++) {
			set.add(sc.nextInt());
		}
		sc.close();
		System.out.println(set.size());
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

signed main(){
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
    return 0;
}

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

int main()
{
  int data[3][3];

  int i, tmp = 0;
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> data[i][j];
    }
  }

  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      if (data[i][j] + data[i + 1][j + 1] != data[i][j + 1] + data[i + 1][j])
      {
        // cout << "i:" << i << ",j:" << j << endl;
        cout << "No" << endl;
        return 0;
      }
    }
  }

  if (data[0][2] + data[2][0] != data[0][0] + data[2][2])
  {
    // cout << "i:" << 0 << ",j:" << 2 << endl;
    cout << "No" << endl;
    return 0;
  }

  // if (data[0][1] + data[2][1] != data[1][0] + data[1][2])
  // {
  //   cout << "No" << endl;
  //   return 0;
  // }

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

Measured memory_bytes: 256
s[50],j,p,q;
main(i){for(;j=i=atoi(gets(s));printf("%d\n",i)){
for(;i;s[j-i--]=strlen(gets(s+j)));
for(;j;)for(p=i++,q=j=117933;q>0;j/=9)for(q=j%9;q>1;)q-=s[p++];
}}

Measured memory_bytes: 532
#include <stdio.h>

int main(void){
    char a[1999999], b[1999999];
    int cor=0;
    scanf("%s %s", &a[0], &b[0]);
    for(int i=0; a[i]!='\0'; i++){
        if(a[i]!=b[i]){
            cor++;
        }
    }
    printf("%d", cor);
    return 0;
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int x,y;
    cin>>x>>y;
    if ( y&1 ){
        cout<<"No"<<endl;
        return;
    }
    if ( y <= 4*x && y >= 2*x ){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n;
		n=in.nextInt();
		int [] a = new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextInt();
		}
		Arrays.sort(a);
		int sum=0;
		for(int i=0;i<n-1;i++)
		{
			sum+=a[i+1]-a[i];
		}
		System.out.println(sum);
   
	}

	

	

}

Measured memory_bytes: 22868
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        s:Chars,
        t:Chars,
    }
    let mut mps = BTreeMap::new();
    let mut mpt = BTreeMap::new();
    for (&s, &t) in s.iter().zip(t.iter()) {
        *mps.entry(s).or_insert(0) += 1;
        *mpt.entry(t).or_insert(0) += 1;
    }
    let mut vs = vec![];
    let mut vt = vec![];
    for (key, value) in mps {
        vs.push(value);
    }
    for (key, value) in mpt {
        vt.push(value);
    }
    vs.sort();
    vt.sort();
    for (&s, &t) in vs.iter().zip(vt.iter()) {
        if s != t {
            yn(false);
            return;
        }
    }
    yn(true);
}

pub fn yn(ans: bool) {
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define for1(i, a, b) for(i = a; i <= b; ++i)
#define for0(i, a, b) for(i = a; i < b; ++i)
#define forw1(i, a, b) for(i = a; i >= b; --i)
#define forw0(i, a, b) for(i = a - 1; i >= b; --i)
#define fora(v, a) for(auto v : a)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

using namespace std;
using cd = complex<double>;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<cd> vcd;
typedef vector<ii> vii;
typedef vector<vector<int> > vvi;

const int modd1 = 1e9 + 7, modd2 = 998244353, maxn = 1111;
const double pi = acos(-1);

void solve(){
    int n, i, j;
    cin >> n;
    int a[4], b[4];
    for0(i, 0, 3){
        cin >> a[i];
    }
    for0(i, 0, 3){
        cin >> b[i];
    }
    int dp1[n + 10] = {0};
    for0(i, 0, 3){
        for0(j, 0, n + 1){
            if(j >= a[i]){
                dp1[j] = max(dp1[j], dp1[j - a[i]] + b[i] - a[i]);
            }
            //cout << dp1[j] << ' ';
        }
    }
    //cout <<'\n';
    int tar = dp1[n] + n;
    int dp2[tar + 10] = {0};
    for0(i, 0, 3){
        for0(j, 0, tar + 1){
            if(j >= b[i]){
                dp2[j] = max(dp2[j], dp2[j - b[i]] + a[i] - b[i]);
            }
        }
    }
    cout << tar + dp2[tar];
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}

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

int N;

int main(){
    cin>>N;
    long long a[1000000],ans=1;
    for(int i=0;i<N;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0;i<N;i++){
        if(a[i]>1000000000000000000/ans){
            cout<<-1<<endl;
            return 0;
        }else {
            ans*=a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll N,M,l;
	cin >> N >> M;
	vector<ll> v(M);
	vector<ll> a(M-1);
	for (ll i = 0; i< M;i++){
		cin >> l;
		v[i] = l;
	}
	sort(ALL(v));
	ll sum = 0;
	for (ll i = 0; i< M-1;i++){
		a[i] = abs(v[i]-v[i+1]);
		sum += a[i];
	}
	sort(ALL(a));
	for (ll i = 0; i < N - 1;i++){
		if (sum > 0)
			sum -= a[M - 2 -i];
		else{
			sum = 0;
			break;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(b+c-a,0)<<endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int s[M], c[M];
    rep(i,M) cin >> s[i] >> c[i];

    int start;
    if (N == 1) {
        start = 0;
    } else {
        start = pow(10, N - 1);
    }

    for (int i = start; i < pow(10, N); i++) {
        bool ok = true;
        rep(j, M) {
            if(i / (int)pow(10, N - s[j]) % 10 != c[j]) ok = false;
        }
        if(ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
typedef long long ll;



int main() {
	int n, m;
	cin >> n >> m;
	VVI v(m, vector<int>(3, 0));
	REP(i, m) {
		cin >> v[i][0] >> v[i][1];
		v[i][2] = i;
	}
	sort(ALL(v));
	VVI x(m, vector<int>(2, 0));
	int a = 0;
	int b = 0;
	REP(i, m) {
		x[v[i][2]][0] = v[i][0];
		if (b != v[i][0]) {
			b = v[i][0];
			a = 1;
		}
		else a++;
		x[v[i][2]][1] = a;
	}
	REP(i, m) {
		REP(j, 2) {
			cout << setfill('0') << right << setw(6)<< x[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

const int mn=2e5+7;
int n,m,k;
long long a[mn],b[mn];

bool check(int x)
{
    for(int i=0;i<=x;++i) {
        if(i>n||x-i>m) continue;
        if(a[i]+b[x-i]<=k) return 1;
    }
    return 0;
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;++i) {scanf("%lld",a+i);a[i]+=a[i-1];}
    for(int i=1;i<=m;++i) {scanf("%lld",b+i);b[i]+=b[i-1];}
    int l=0,r=n+m+1;
    while(l<r) {
        int mid=(l+r+1)>>1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    cout<<l;
}

Measured memory_bytes: 6808
#include <stdio.h>

int main(){
  int N,A[1000002],B[1000002];
  int c;
  int tmp;
  int ans=0;
  int min=1000001,max=0;
  
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&tmp);
    A[tmp]++;
    if(max<tmp) max=tmp;
    if(tmp<min) min=tmp;
  }
  for(int i=min;i<=max;i++){
    if(A[i]==1) B[i]=1;
    else B[i]=0;
  }

  for(int i=min;i<=max;i++)
    if(A[i]>=1)
      for(int j=i*2;j<=max;j+=i)
        B[j]=0;
  
  for(int i=min;i<=max;i++)
    if(B[i]!=0) ans++;
  
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 9548
bldg=[[[0 for i in range(10)]for j in range(3)]for k in range(4)]
n=int(input())
for i in range(n):
    var=input()
    var=var.split()
    b=int(var[0])-1
    f=int(var[1])-1
    r=int(var[2])-1
    v=int(var[3])
    bldg[b][f][r]+=v
count=0
for building in bldg:
    for floor in building:
        for room in floor:
            print(" "+str(room),end='')
        print()
    if(count==3):
        break
    print("####################")
    count+=1


Measured memory_bytes: 5620
object Main {
  def main(args: Array[String]) {
    var count = 0
    var point = 0
    var step  = 1000000000
    for(line <- io.Source.stdin.getLines()) {
      val temp_point = line.split(' ').map{_.toInt}
      if(count == 0) {
        point = temp_point(1)
      }
      else {
        for(c <- temp_point) {
          val diff = (c - point).abs

          if(step  == 1000000000) {
            step = diff
          }
          else {
            val temp_gcd = gcd(step, diff%step)
            if(step > temp_gcd) {
              step = temp_gcd
            }
          }
        }
      }
      count += 1
    }

    println(step)
  }

  def gcd(a: Int, b: Int): Int = {
    if (b == 0) {
      a
    }
    else {
      gcd(b, a%b)
    } 
  }
}


Measured memory_bytes: 42396
import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ") //ブランクで区切られている場合

var a = Int(split[0])!
//String -> Intの型変換はnilが返る可能性があるので、ラップされたOptional<Int>型が返るので強制アンラップ
var b = Int(split[1])!

var maxValue = a+b

if (maxValue < a-b){
    maxValue = a-b
}

if (maxValue < a*b){
    maxValue = a*b
}

print(maxValue)


Measured memory_bytes: 14160
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    ll s;
    cin >> s;
    int i = 1;
    ll t = s;
    while(t / 10 != 0) {i++; t /= 10;}
    ll ans = 1000;
    for(int j = i; j >= 3 ;j--){
        ans = min(abs(753 - s % (ll)pow(10, j) / (ll)pow(10, j - 3)), ans);
    }
    cout << ans << endl;
    return 0;
}

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

int n, m;
map<pair<int, int>, bool> mp;
bool ans = 0;
void prians(bool answer) {
  if(answer)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    mp[make_pair(min(x, y), max(x, y))] = 1;
  }
  for(int i = 2; i < n; ++i)
    if(mp[make_pair(1, i)] && mp[make_pair(i, n)]) ans = 1;
  prians(ans);
  return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

struct Edge
{
  i64 to, silver, time;
};

struct Ex
{
  i64 silver, time;
};

int main()
{
  i64 N, M, S;
  cin >> N >> M >> S;
  vector<Edge> edge[N];
  for (i64 i = 0; i < M; i++)
  {
    i64 U, V, A, B;
    cin >> U >> V >> A >> B;
    U--;
    V--;
    edge[U].push_back({V, A, B});
    edge[V].push_back({U, A, B});
  }
  vector<Ex> ex(N);
  for (i64 i = 0; i < N; i++)
    cin >> ex[i].silver >> ex[i].time;
  vector<vector<i64>> far(N, vector<i64>(2501, 1e18));
  priority_queue<pair<i64, pair<i64, i64>>, vector<pair<i64, pair<i64, i64>>>, greater<pair<i64, pair<i64, i64>>>> que;
  S = min(S, 2500LL);
  far[0][S] = 0;
  que.push({0, {0, S}});
  while (que.size())
  {
    pair<i64, pair<i64, i64>> p = que.top();
    que.pop();
    i64 time = p.first, now = p.second.first, silver = p.second.second;
    if (far[now][silver] < time)
      continue;
    for (Edge i : edge[now])
      for (i64 j = 0; silver + j * ex[now].silver - i.silver <= 2500; j++)
      {
        i64 s = silver + j * ex[now].silver - i.silver;
        if (0 <= s)
          far[now][s] = min(far[now][s], far[now][silver] + ex[now].time * j);
        if (0 <= s && far[now][silver] + ex[now].time * j + i.time < far[i.to][s])
        {
          far[i.to][s] = far[now][silver] + ex[now].time * j + i.time;
          que.push({far[i.to][s], {i.to, s}});
        }
      }
  }
  for (i64 i = 1; i < N; i++)
  {
    i64 ans = 1e18;
    for (i64 j = 0; j <= 2500; j++)
      ans = min(ans, far[i][j]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 28904
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAX_V 10000000
#define INF 10000000000

int main(){
    int n, k; cin >> n >> k;
    vector<ll> dp(n, INF);
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int l = 1; l <= min(i, k); l++){
            dp[i] = min(dp[i-l] + abs(a[i-l] - a[i]), dp[i]); 
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1408
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 2019
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

S = input()
N = len(S)

d = defaultdict(int)
d[0] += 1
# nums = [0]*(N+1)
m = 0
last = 0
dd = 1
for i in range(N):
    m += int(S[N-i-1])*dd
    m %= MOD
    # val = (int(S[i])*m + nums[i])%MOD
    # cnt += d[val]
    dd = (dd*10)%MOD
    d[m] += 1

cnt = 0
for i, v in d.items():
    cnt += v*(v-1)//2
print(cnt)

Measured memory_bytes: 74932
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int N;
vector<vector<pair<int,ll>>> to;
int Q,K;

vector<ll> fromK;


ll dikstra(int a){
    vector<ll> D(N,-1);
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
    pq.push({0,a});
    int u = a;
    while (!pq.empty()) {
        pair<ll,int> g = pq.top();
        pq.pop();
        
        if(D[g.second]==-1){
            u = g.second;
            D[u] = g.first;
            fromK[u] = g.first;
            for (pair<int,ll> k : to[u]) {
                if(k.first == u) continue;
                pq.push({g.first+k.second,k.first});
            }
        }
    }
    return 0;
    
}




int main()
{
    cin >> N;
    to.resize(N);
    fromK.resize(N);
    rep(i,N-1){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--;b--;
        to[a].push_back({b,c});
        to[b].push_back({a,c});
    }
    cin >> Q >> K;
    vector<pair<int,int>> queri;
    rep(i,Q){
        int x,y;
        cin >> x >> y;
        x--;y--;
        queri.push_back({x,y});
    }
    
    dikstra(K-1);
    //rep(i,N) cout << fromK[i] << " ";cout << endl;
    rep(i,Q){
        cout << fromK[queri[i].first] + fromK[queri[i].second] << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 13296