akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep0(i, n)cin >> a[i];
    sort(all(a));
    if(n % 2 == 0){
        ll ans = 0;
        rep0(i, n / 2)ans -= a[i] * 2;
        nfor(i, n / 2, n)ans += a[i] * 2;
        pf(ans + a[n / 2 - 1] - a[n / 2]);
    }else{
        ll ans = 0,cnt = 0;
        rep0(i, n / 2)ans -= a[i] * 2;
        nfor(i, n / 2, n)ans += a[i] * 2;
        ans = ans - a[n / 2] - a[n / 2 + 1];
        rep0(i, n / 2 + 1)cnt -= a[i] * 2;
        nfor(i, n / 2 + 1, n)cnt += a[i] * 2;
        cnt = cnt + a[n / 2 - 1] + a[n / 2];
        pf(max(ans,cnt));
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

using Array = vector<double>;
using Matrix = vector<Array>;
const double eps = 1e-10;

Array GaussJordan(const Matrix& A, const Array& b) {
	int n = A.size();
	Matrix B(n, Array(n + 1));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)	B[i][j] = A[i][j];
	for(int i = 0; i < n; i++) B[i][n] = b[i];
	for(int i = 0; i < n; i++) {
		int pivot = i;
		for(int j = i; j < n; j++) {
			if(abs(B[i][j]) > abs(B[pivot][i])) pivot = i;
		}
		swap(B[i], B[pivot]);
		if(abs(B[i][i]) < eps) return Array();
		for(int j = i + 1; j <= n; j++) B[i][j] /= B[i][i];
		for(int j = 0; j < n; j++) {
			if(i != j) {
				for(int k = i + 1; k <= n; k++) B[j][k] -= B[j][i] * B[i][k];
			}
		}
	}

	Array x(n);
	for(int i = 0; i < n; i++) x[i] = B[i][n];
	return x;
}

double a[10];

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

	int d;
	while(cin >> d, d) {
		for(int i = 0; i < d + 3; i++) {
			cin >> a[i];
		}

		vector<int> ans;
		for(int i = 0; i < d + 3; i++) {
			Array y;
			bool flag = true;
			for(int j = 0; j < d + 3; j++) {
				if(i == j) continue;
				Matrix A;
				Array b;
				for(int x = 0; x < d + 3; x++) {
					if(i == x || j == x) continue;
					Array arr(d + 1);
					for(int k = 0; k <= d; k++) {
						arr[k] = pow(x, k);
					}
					A.push_back(arr);
					b.push_back(a[x]);
				}

				Array r = GaussJordan(A, b);
				if(r.size()) {
					if(y.size() == 0) y = r;
					else {
						for(int k = 0; k < r.size(); k++) {
							if(abs(r[k] - y[k]) > 1e-1) {
								flag = false;
								break;
							}
						}
					}
				}
				else {
					flag = false;
				}
				if(!flag) break;
			}
			if(flag) ans.push_back(i);
		}

		cout << ans[0] << endl;
	}
}

Measured memory_bytes: 3380
// Author: 23forever
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 5000;
const int P = 1e9 + 7;
using namespace std;

inline int read() {
  int x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x;
}

int dp[MAXN + 5][MAXN + 5], g[MAXN + 5];

namespace tree {

int tot, head[MAXN + 5];

const int MAXM = 2 * MAXN;

struct Edge {
  int to, nxt;
  Edge() {}
  Edge(int _to, int _nxt) : to(_to), nxt(_nxt) {}
} edge[MAXM + 5];

void addEdge(int u, int v) {
  edge[tot] = Edge(v, head[u]), head[u] = tot++;
  edge[tot] = Edge(u, head[v]), head[v] = tot++;
}

void init() {
  tot = 0, memset(head, -1, sizeof(head));
}

int tmp[MAXN + 5], sz[MAXN + 5];

void dfs(int u, int fa) {
  dp[u][1] = 1; sz[u] = 1;

  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);

    for (int j = 1; j <= sz[u] + sz[v]; ++j) tmp[j] = 0;
    for (int j = 1; j <= sz[u]; ++j) {
      for (int k = 0; k <= sz[v]; ++k) {
        tmp[j + k] = (tmp[j + k] + 1LL * dp[u][j] * dp[v][k] % P) % P;
      }
    }
    for (int j = 1; j <= sz[u] + sz[v]; ++j) dp[u][j] = tmp[j];

    sz[u] += sz[v];
  }

  for (int i = 2; i <= sz[u]; i += 2) {
    //if (u == 1) cout << dp[u][0] <<' ';
    dp[u][0] = (dp[u][0] - 1LL * dp[u][i] * g[i] % P + P) % P;
  }
}

}

int n;

void init() {
  n = read();
  tree::init();

  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    tree::addEdge(u, v);
  }
}


int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();

  g[0] = 1;
  for (int i = 2; i <= n; i += 2) { 
    g[i] = 1LL * g[i - 2] * (i - 1) % P;
  }
  tree::dfs(1, 0);
  printf("%d\n", P - dp[1][0]);

#ifdef forever23
	printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC));
#endif
  return 0;
}

Measured memory_bytes: 97280
from sys import stdin
from math import ceil
def main():
	readline=stdin.readline
	N=int(readline())
	a=list(map(int,readline().split()))
	b=list(map(int,readline().split()))
	a_count=0
	s=sum(b)-sum(a)

	for i in range(N):
		if a[i]<b[i]:
			a_count+=ceil((b[i]-a[i])/2)

	if a_count<=s:
		print("Yes")
	else:
		print("No")

if __name__=="__main__":
	main()

Measured memory_bytes: 4596
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        long ans = 0;
        if(A == 0)
        {
            System.out.println(ans);
        }
        else
        {
            long a = A + B; //青と赤の足し算
            long b = N % a; // 余
            long c = N / a; // 商
            if(b<A)
            {
                ans = A * c + b;
                System.out.println(ans); 
            }
            else if(b>=A)
            {
                ans = A * c + A;
                System.out.println(ans); 
            }
            else 
            {
                ans = A * c;
                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int a, b;
	cin >> a >> b;
	if ((a <= 8) && (b <= 8)) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	
	return(0);
}


Measured memory_bytes: 256
li = input().split()
# li  = [3,5,-4,-2]
li1 = li[0:2]
li2 = li[2:4]

ans = -999999999999999999999999999999999

for x in li1:
    for y in li2:
        tmp = int(x)*int(y)
        if tmp > ans:
            ans = tmp
print(ans)

Measured memory_bytes: 61836
#ABC093

a,b,k = list(map(int,input().split()))

if 2 * k > b-a:
    for i in range(a,b+1):
        print(i)
else:
    for i in range(0,k):
        print(a+i)
    
    for i in range(1,k+1):
        print(b-k+i)



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

int main() {
  int N, F, a;
  cin >> N;
  F=0;
  a=N;
  
  while (a>0) {
    F += a%10;
    a /= 10;
  }
  

  if (N%F==0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	string s;
	int n,bw=0,br=0;
	cin>>n;
	cin>>s;
	for(int t=0;t<n;t++)
	{
		if(s[t]=='R')
		{
			br++;
		}
	}
	for(int t=0;t<br;t++)
	{
		if(s[t]=='W')
		{
			bw++;
		}
	}
	cout<<bw;
	return 0;
}

Measured memory_bytes: 3724
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;


int32_t main(){
    FAST;

    string s;
    cin >> s;
    cout << char(s[0]-32);
    cin >> s;
    cout << char(s[0]-32);
    cin >> s;
    cout << char(s[0]-32);

    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
#define set setprecision
#include<numeric>
using namespace std;
int gcd(int a, int b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)
{return a * b / gcd(a, b);
}
int main() {
	int n;
	cin >> n;
	vec a(n);
	int lcd = 1;
	rip(i, n) {
		cin >> a[i];
		lcd = lcm(a[i], lcd);
	}
	cout << lcd << endl;
}


Measured memory_bytes: 3120
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int K, Q;
	cin >> K >> Q;
	int D[5000];
	rep(i, K) cin >> D[i];

	rep(i, Q) {
		ll N, X, M;
		cin >> N >> X >> M;
		N--;
		X %= M;

		ll N2 = N / K;
		N %= K;

		ll kosuu = 0;
		ll kazu = 0;
		rep(i, K) {
			if (D[i] % M) {
				kosuu++;
				kazu += D[i] % M;
			}
		}
		kazu *= N2;
		kosuu *= N2;
		kosuu -= kazu / M;
		ll amari = kazu % M;

		X += amari;
		rep(i, N) {
			if (D[i] % M) {
				kosuu++;
				X += D[i] % M;
			}
		}
		kosuu -= X / M;

		co(kosuu);
	}



	Would you please return 0;
}

Measured memory_bytes: 384
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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


const ll MOD = 1000000007;
const ll inf = 1LL << 60;

struct Mint {
    ll v;
    ll _mod;
    Mint() : v(0) {}
    Mint(signed v, ll _mod = MOD) : v(v), _mod(_mod) {}
    Mint(ll t, ll _mod = MOD) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    Mint pow(ll k) {
        Mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static Mint add_identity() { return Mint(0); }
    static Mint mul_identity() { return Mint(1); }
    Mint inv() { return pow(_mod - 2); }

    Mint& operator+=(Mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    Mint& operator-=(Mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    Mint& operator*=(Mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    Mint& operator/=(Mint a) { return (*this) *= a.inv(); }

    Mint operator+(Mint a) const { return Mint(v) += a; };
    Mint operator-(Mint a) const { return Mint(v) -= a; };
    Mint operator*(Mint a) const { return Mint(v) *= a; };
    Mint operator/(Mint a) const { return Mint(v) /= a; };

    Mint operator-() const { return v ? Mint(_mod - v) : Mint(v); }

    bool operator==(const Mint a) const { return v == a.v; }
    bool operator!=(const Mint a) const { return v != a.v; }
    bool operator<(const Mint a) const { return v < a.v; }
};
ostream& operator<<(ostream& os, Mint m) { return os << m.v; }

Mint nCk(int n, int k) {
    Mint ret = 1;
    for (int i = n; i > n - k; --i) {
        ret *= i;
    }
    for (int i = 1; i <= k; ++i) {
        ret /= i;
    }
    return ret;
}



// ***************************************


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

    Mint ans = 0;
    FOR(i, K, N+2){
        Mint mn = (i - 1) * i / 2;
        Mint mx = i * (N + N - i + 1) / 2;
        ans += (mx - mn + 1);
    }

    cout << ans.v << endl;

    return 0;
}


Measured memory_bytes: 3636
n, k, q = map(int, input().split())
A = []
for i in range(q):
    A.append(int(input()))

# 正解数でリストを作る
count_ans = [0 for _ in range(n)]
for i in range(q):
    count_ans[A[i]-1] += 1

for j in range(n):
    if q - k < count_ans[j]:
        print('Yes')
    else:
        print('No')

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    for(ll k=1;k*(k-1)/2<=N;k++){
        if(k*(k-1)/2==N){
            cout << "Yes" << endl << k << endl;
            set<int> ans[1000];
            int l=1,r=2;
            for(int idx=1;idx<=N;idx++){
                ans[l].insert(idx);
                ans[r].insert(idx);
                r++;
                if(r>k){
                    l++;
                    r=l+1;
                }
            }
            for(int i=1;i<=k;i++){
                cout << k-1;
                for(int x:ans[i]) cout << " " << x;
                cout << endl;
            }
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}

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

int digits(int n){
  int res=0;
  while(n){
    n = n/10;
    res++;
  }
  return res;
}

int main(){
  int x,y;
  while(cin >> x >> y)
    cout << digits(x+y) << endl;
  return 0;
}

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

int main(){
    int k,m,ans;
    cin >> k;
    if(k%2==0){
        m = k/2;
        ans = m*m;
    }else{
        m=k/2;
        ans = m * (m+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int n,m;
	LinkedList<Integer>[] friends;
	@SuppressWarnings("unchecked")
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt();
			m = sc.nextInt();
			if( (n|m) == 0 ) break;
			friends = new LinkedList[n];
			for(int i=0;i<n;i++) friends[i] = new LinkedList<Integer>();
			for(int i=0;i<m;i++) {
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				friends[a].add(b);
				friends[b].add(a);
			}
			HashSet<Integer> set = new HashSet<Integer>();
			for(int a: friends[0]) {
				set.add(a);
				for(int b: friends[a])
					set.add(b);
			}
//			debug(set);
			System.out.println( ( set.size()==0? 0:set.size() - 1 ) );
			
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	string s;
	cin >> s;
	string ans="";
	for(int i=0;i<s.size();i++){
		if(i%2==0)ans+=s[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3688
#include <iostream>
using namespace std;
int main (){
    string a;
    cin >> a;
    if(a == "Sunny")
    cout << "Cloudy";
    if(a == "Cloudy")
    cout << "Rainy";
    if(a == "Rainy")
    cout << "Sunny";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
int n,k;
n=0;
k=0;
cin >> n >> k;
if(n%2!=0){
    if((n+1)/2>=k){
        cout <<"YES"<<endl;
    }else{
        cout <<"NO"<<endl;
    }
}else{
    if(n/2>=k){
        cout <<"YES"<<endl;
}else{
        cout <<"NO"<<endl;

}
}
return 0;
}


Measured memory_bytes: 256
import bisect
import time

start = time.time()

D = int(input())
c = [0] + list(map(int, input().split()))
s = [0] + [[0] + list(map(int, input().split())) for _ in range(D)]
sch, held = [0], [[0] for _ in range(27)]

for d in range(1, D+1):
    SLvar = [s[d][i] + c[i] * (d - held[i][-1]) for i in range(1, 27)]
    t = SLvar.index(max(SLvar)) + 1
    sch.append(t)
    held[t].append(d)

for i in range(1, 27):
    held[i].append(D+1)

s_sort = [0] + [[0] + sorted([[s[d][i], i] for i in range(1, 27)], key=lambda x: x[0], reverse=True) for d in range(1, D+1)]

i, j = 1, 1
while time.time() - start < 1.8 and i <= D and j < 27:
    d, q = i, s_sort[i][j][1]

    if sch[d] != q:
        SLvar = s[d][q] - s[d][sch[d]]

        ind_p = bisect.bisect_left(held[sch[d]], d)
        k = d - held[sch[d]][ind_p-1]
        l = held[sch[d]][ind_p+1] - d
        SLvar -= c[sch[d]] * k * l

        ind_n = bisect.bisect_left(held[q], d)
        k = d - held[q][ind_n-1]
        l = held[q][ind_n] - d
        SLvar += c[q] * k * l

        if SLvar > 0:
            del held[sch[d]][ind_p]
            held[q].insert(ind_n, d)
            sch[d] = q

    i += 1
    if i > D:
        i = 1
        j += 1

for i in range(1, D+1):
    print(sch[i])

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

int N;
string S;
int imos1[330000], imos2[330000];
signed main() {
    cin >> N >> S;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'E') {
            imos1[i] = imos2[i] = 1;
        }
    }
    for (int i = 1; i < N; i++) imos1[i] += imos1[i - 1];
    for (int i = N - 2; i >= 0; i--) imos2[i] += imos2[i + 1];
    int ans = 1111111111;
    for (int i = 0; i < N; i++) {
        int cur = 0;
        if (i != 0) cur += i - imos1[i - 1];
        if (i != N - 1) cur += imos2[i + 1];
        ans = min(ans, cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5636
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int x[3], k; cin >> x[0] >> x[1] >> x[2] >> k;
    sort(x, x+3);
    cout << x[0] + x[1] + (x[2]<<k) << endl;
}

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

#define sz(a) (int)a.size()
#define rep(i,x,n,j) for(int i=x; i<n; i+=j)

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

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        String ans = "";
        if (a < b) {
            for (int i = 0; i < b; i++) {
                ans += a;
            }
        } else {
            for (int i = 0; i < a; i++) {
                ans += b;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int inf=1000000000;
int main(){
    int n;
    cin>>n;
    int x[n],y[n];
    P X[n],Y[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        X[i]={x[i],i};
        Y[i]={y[i],i};
    }
    sort(X,X+n);
    sort(Y,Y+n);
    vector<vector<P>>pas(n);
    for(int i=0;i<n-1;i++){
        pas[X[i].second].push_back({X[i+1].second,X[i+1].first-X[i].first});
        pas[X[i+1].second].push_back({X[i].second,X[i+1].first-X[i].first});
        pas[Y[i].second].push_back({Y[i+1].second,Y[i+1].first-Y[i].first});
        pas[Y[i+1].second].push_back({Y[i].second,Y[i+1].first-Y[i].first});
    }
    priority_queue<P,vector<P>,greater<P>>q;//cost vertex
    vector<int>used(n,0);
    vector<int>cost(n,inf);
    q.push({0,0});
    cost[0]=0;
    int ans=0;
    while(q.size()){
        int v=q.top().second;
        q.pop();
        if(used[v]==1)continue;
        used[v]=1;
        ans+=cost[v];
        for(int i=0;i<pas[v].size();i++){
            if(cost[pas[v][i].first]>pas[v][i].second){
                cost[pas[v][i].first]=pas[v][i].second;
                q.push({pas[v][i].second,pas[v][i].first});
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14976
def primes(n):
    primes = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            primes.append(i)
    return is_prime


Q = int(input())

ps = primes(100000)
like_numbers = [False] * 100001
for i in range(3, 100001, 2):
    if ps[i] and ps[(i + 1) // 2]:
        like_numbers[i] = True

like_numbers_cnt = [0] * 100001

for i in range(1, 100001):
    if like_numbers[i]:
        like_numbers_cnt[i] = like_numbers_cnt[i - 1] + 1
    else:
        like_numbers_cnt[i] = like_numbers_cnt[i - 1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(like_numbers_cnt[r] - like_numbers_cnt[l - 1])


Measured memory_bytes: 53720
#include<bits/stdc++.h>
using namespace std;
static const int N_MAX = 1000;
int main(){
    int n;
    cin >> n;
    double V[N_MAX];
    double sum = 0;
    for (int i=0;i<n;i++){
        cin >> V[i];
    }
    sort(V,V+n);
    for (int i=0;i<n;i++){
        int j;
        if (i==0){
            j = 1;
        }else{
            j = i;
        }
        sum += (V[i]/pow(2,n-j));
    }
    cout << sum  << endl;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Sol();
        }

        public void Sol()
        {
            string s = Console.ReadLine();
            int a = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'A')
                {
                    a = i;
                    break;
                }
            }

            int z = 0;
            for (int i = s.Length - 1; i >= 0; i--)
            {
                if (s[i] == 'Z')
                {
                    z = i;
                    break;
                }
                
            }
            
            Console.WriteLine(z-a+1);
        }
    }
}

Measured memory_bytes: 11616
N=int(input())
a=0
d=0
for i in range(1,N+1):
    a=i*(i+1)/2
    if a==N:
        for j in range(1,i+1):
            print(j)
        break
    if a>N:
        c=a-N
        for k in range(1,i+1):
            if k!=c:
                print(k)
        break

Measured memory_bytes: 3316
def z_algo(S):
  N = len(S)
  A = [0]*N
  i = 1; j = 0
  A[0] = l = len(S)
  while i < l:
    while i+j < l and S[j] == S[i+j]:
      j += 1
    if not j:
      i += 1
      continue
    A[i] = j
    k = 1
    while l-i > k < j - A[k]:
      A[i+k] = A[k]
      k += 1
    i += k; j -= k
  return A

N = int(input())
S = input()

ans = 0
for i in range(N):
  SS = S[i:]
  Z = z_algo(SS)
  #print(Z)
  for j in range(1,len(SS)):
    if Z[j] > j:
      l = j
    else:
      l = Z[j]
    ans = max(l,ans)
print(ans)


Measured memory_bytes: 50268
x,n=map(int,input().split())
if n==0:
  print(x)
else:
 p=list(map(int,input().split()))
 k=0
 d=x-n
 for i in range(n):
       if (x-i not in p):
          d=x-i
          break
       elif (x+i) not in p:
          d=x+i
          break
 print(d)
  
 
 
          
       
  

Measured memory_bytes: 61792
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e11
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

ll dp[1009][5009];
ll key[1009];
ll cost[1009];
ll n,m;
ll sol(ll keyno,ll mask)
{
    if(dp[keyno][mask]!=-1)
    {
        return dp[keyno][mask];
    }
    if(keyno==m)
    {
        if(mask==(1<<n)-1)
            return dp[keyno][mask] =0;
        return dp[keyno][mask] =inf;
    }
    ll res = inf;

    res = min(res,cost[keyno]+sol(keyno+1,mask | key[keyno]));
    res = min(res,sol(keyno+1,mask));

    return dp[keyno][mask] = res;
}
int main()
{
    ll i,t,k,j,x=0,y=0;
    FAST
    cin>>n>>m;

    for(i=0;i<m;i++)
    {
        ll cnt;
        cin>>cost[i]>>cnt;
        k = 0;
        while(cnt--)
        {
            cin>>x;
            k  =k| (1<<(x-1));
        }
        key[i] = k;

    }
    memset(dp,-1,sizeof dp);
    x = sol(0,0);
    if(x>=inf)
        cout<<-1<<endl;
    else cout<<x<<endl;

    return 0;
}



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

const int N=30010;

char s[N];
int cnt[N][10];
int first[10],last[10];

void solve(){
    int n;
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;i++){
        int v=s[i]-'0';
        memcpy(cnt[i], cnt[i-1], sizeof(cnt[i]));
        cnt[i][v]++;
        if(first[v]==0) first[v]=i;
        last[v]=i;
    }
    int ans=0;
    for(int i=0;i<10;i++){
        if(first[i]==0) continue;
        for(int j=0;j<10;j++){
            if(last[j]==0) continue;
            if(first[i]+1==last[j]) continue;
            int l=first[i],r=last[j];
            for(int k=0;k<10;k++){
                if(cnt[r-1][k]-cnt[l][k]>0) ans++;
            }
        }
    }
    printf("%d\n",ans);
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>

int i;
int main(void)
{
    char s[100001];
    char t[4][8]={"maerd","remaerd","esare","resare"};// <-4種
    char tmp;
    scanf("%s",s);
    int len_s=(int)strlen(s);
    for(int k=0;k<len_s/2;k++){
        tmp=s[k];
        s[k]=s[len_s-1-k];
        s[len_s-1-k]=tmp;
    }
    //printf("%s\n",s);
    while(s[0]){
        int a=0;//aの値をリセット
        for(i=0;i<4;i++){
            //printf("-------\n");
            int c=0,same=0;//カウントをリセット
            for(int j=0;t[i][j]!='\0';j++){
                //printf("t[%d][%d]=%c\n",i,j,t[i][j]);
                c++;
                if(s[j]==t[i][j]){
                    same++;
                }
            }
            //printf("c=%d,same=%d\n",c,same);
            if(c==same){//tの文字列の長さと同じだけ一致してたら
                a=same;//aにsameを保存
            }
            //
        }
        //printf("a=%d\n",a);
        if(a==0){
            printf("NO\n");
            return 0;
        }
        //4種と比べ終わったら
        for(int j=0;s[j]!='\0';j++){
            s[j]=s[j+a];
        }
    }
    printf("YES\n");
    return 0;
}



Measured memory_bytes: 256
num = "2***9*2*6*1199*"
as = [0,1,2,3,4,6,7,8,9]
#num = "5*57*"
#as = [3,9]

def isum(ns)
	Enumerator.new {|y|
		ns.reverse.each.each_with_index {|n,idx|
			if idx.odd?
				n2 = 2*n
				y << n2 % 10 + n2/10
			else
				y<< n
			end
		}
	}.inject(:+)
end

def holes(str)
	a = 0
	e = 0
	str.chars.reverse.each_with_index {|n,idx|
		if n == "*"
			a+=1
			if idx.odd?
				e+=1
			end
		end
	}
	[a,e]
end

def factrial(n)
	(1..n).inject(:*)
end

def count_perm(arr)
	h = Hash.new(0)
	l = arr.length
	arr.each {|x|
		h[x]+=1
	}
	ret = factrial(l)
	h.values.each {|x|
		ret /= factrial(x)
	}
	ret
end
gets
num = gets.chomp
gets.to_i
as = gets.chomp.split(" ").map(&:to_i)

all,even = holes num
sum = isum num.chars.map(&:to_i)
#p num.chars.map(&:to_i)
#p sum,all,even
p as.repeated_combination(all-even).map {|arr|
	as.repeated_combination(even).map {|arr2|
		s1 = arr.inject(:+) || 0
		s2 = arr2.map {|x|
		(2*x/10) + (2*x%10)
		}.inject(:+) || 0 
		if (sum+s1+s2) % 10 == 0
			(count_perm(arr)||1)*(count_perm(arr2)||1)
		else
			0
		end
	}
}.flatten.inject(:+)

Measured memory_bytes: 34228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>

int main()
{
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    if ((std::abs(b - a) <= d &&std::abs(c - b) <= d) || std::abs(c - a) <= d)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
robots = []
for i in range(n):
    x,l = map(int,input().split())
    robots.append((x+l,x-l))
robots.sort()
count = 1
cur = robots[0][0]
for i in range(1,n):
    if robots[i][1] >= cur:
        cur = robots[i][0]
        count += 1
print(count)

Measured memory_bytes: 16984
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int f[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main(){
	ll n,k;
	scanf("%lld %lld", &n,&k);
	ll ans = 0;
	if (k % 2==0) {
		ans = (n / (k / 2) - n / k)*(n / (k / 2) - n / k)*(n / (k / 2) - n / k);
		ans += (n / k)*(n/k)*(n/k);
	}
	else {
		ans = (n / k)*(n / k)*(n / k);
	}
	PRINTL(ans);
	
}

Measured memory_bytes: 128
import math

len=0
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
for i in range(N-1):
  for j in range(i+1,N):
    len+=math.sqrt((P[i][0]-P[j][0])**2+(P[i][1]-P[j][1])**2)
    
print(2*len*math.factorial(N-1)/math.factorial(N))    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn=110000;
vector<int> oa,ob;
int n;
char s[maxn];
int fa[maxn];
int check()
{
	if(s[n]=='1') return 0;
	for(int i=1;i<=n-1;i++) 
	{
		if(s[i]==s[n-i]) continue;
		return 0;
	}
	if(s[1]=='0') return 0;
	return 1;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if(!check()) return printf("-1\n"),0;
	int root=n;
	for(int i=n-1;i>=1;i--) 
	{
		if(s[i]=='0') fa[i]=root;
		else fa[i]=root,root=i;
	}
	for(int i=1;i<=n-1;i++)
	{
		if(fa[i]==i) continue;
		printf("%d %d\n",i,fa[i]);
	}
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxm = 1e5 + 5;

int n, m, l, r, bit[maxm];

void add(int idx, int val)
{
    for(++idx; idx < maxm; idx += idx & -idx)
        bit[idx] += val;
}

int sum(int idx)
{
    int curans = 0;
    for(++idx; idx > 0; idx -= idx & -idx)
        curans += bit[idx];
    return curans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    vector<pair<int, pii>> segments;
    for(int i = 0; i < n; i++)
    {
        cin >> l >> r;
        add(l, 1);
        add(r + 1, -1);
        segments.push_back({r - l + 1, {l, r}});
    }
    sort(segments.begin(), segments.end(), greater<>());
    int always = 0;
    vector<int> ans;
    for(int i = m; i >= 1; i--)
    {
        while(always < n && segments[always].first >= i)
        {
            add(segments[always].second.first, -1);
            add(segments[always].second.second + 1, 1);
            always++;
        }
        int curans = always;
        for(int j = 1; i * j <= m; j++)
            curans += sum(i * j);
        ans.push_back(curans);
    }
    reverse(ans.begin(), ans.end());
    for(auto x : ans)
        cout << x << "\n";
    return 0;
}

Measured memory_bytes: 16216
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut a: [u64; n],
    }
    let mut cnt = 0;
    loop {
        a = a.iter().filter(|&x| x % 2 == 0).map(|&x| x / 2).collect();
        if a.len() == 0 {
            break;
        } else {
            cnt += a.len()
        };
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
import numpy as np
import sys
a,b,c=[int(i) for i in input().split()]
v=np.array([abs((b-a)-(c-a)), abs((a-b)-(c-b)), abs((a-c)-(b-c))])

if a==b==c:
    if a%2==0: print(-1)
    else: print(0) 
    sys.exit()

count = 0
# Shift Only
while all(v%2==0):
    # print(v)
    v = v / 2
    count += 1
print(count)

Measured memory_bytes: 12464
#include<stdio.h>
 
int main(void){
  int R;
  scanf("%d",&R);
  
  if(0<=R&&R<1200){
    printf("ABC");
  }else if(1200<=R&&R<2800){
    printf("ARC");
  }else if(2800<=R&&R<=4208){
    printf("AGC");
  }
  
  return 0;
}

Measured memory_bytes: 128
a, b = [ int(v) for v in input().split() ]
if a == 1 and b == 1:
    print(1000000)
else:
    ans = 0
    if a < 4:
        ans += 100000 * (4-a)
    if b < 4:
        ans += 100000 * (4-b)
    print(ans)

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

int main() {
  int n, m;
  int dltv = -999999999;
  int minv = 2000000000;

  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> m;
    dltv = max(dltv, m - minv);
    minv = min(minv, m);
  }
    cout << dltv << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
string s, t;
int mincost[16][1<<16];
int sbit, tbit;

struct State {
  int now, cost, bit;
  State(){}
  State(int now, int cost, int bit):now(now), cost(cost), bit(bit){}
  bool operator < (const State &st) const {
    return cost > st.cost;
  }
};

int dijkstra(int pos) {
  fill(mincost[0], mincost[16], inf);
  mincost[pos][sbit] = 0;
  priority_queue<State> que;
  que.emplace(pos, 0, sbit);
  while(!que.empty()) {
    State st = que.top(); que.pop();
    int now = st.now, cost = st.cost, bit = st.bit;
    //cout << now << " "<< cost << endl;
    //rep(i, N) cout << (int)((bit>>i)&1);
    //cout << endl;
    if(bit == tbit) return cost;
    if(mincost[now][bit] < cost) continue;
    rep(i, N) if(i != now) {
      int ncost = cost + abs(i-now);
      if(ncost < mincost[i][bit]) {
	mincost[i][bit] = ncost;
	que.emplace(i, ncost, bit);
      }
      if(((bit>>i)&1) == ((bit>>now)&1)) continue;
      int nbit = bit^(1<<i)^(1<<now);
      //rep(i, N) cout << (int)((bit>>i)&1);cout<<endl;
      //cout<<now<<" "<<i<<endl;
      //cout << (int)((bit>>i)&1) << " "<<(int)((bit>>now)&1) << endl;
      //cout<<(int)(((bit>>i)&1) == ((bit>>now)&1)) << endl;
      //rep(i, N) cout << (int)((nbit>>i)&1);cout<<endl;
      //assert(__builtin_popcount(nbit) == __builtin_popcount(bit));
      if(ncost < mincost[i][nbit]) {
	mincost[i][nbit] = ncost;
	que.emplace(i, ncost, nbit);
      }
    }
  }
  return inf;
}

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

  while(cin >> N, N) {
    cin >> s >> t;
    sbit = tbit = 0;
    rep(i, N) if(s[i] == 'B') sbit |= 1<<i;
    rep(i, N) if(t[i] == 'B') tbit |= 1<<i;
    int ans = inf;
    rep(i, N) {
      chmin(ans, dijkstra(i));
      //cout<<ans<<endl;//exit(0);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 21156
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int m, n;
int p[100005];
int x[100005];
int y[100005];
vector<int> adj[100005];
bool visited[100005];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    adj[x[i]].push_back(y[i]);
    adj[y[i]].push_back(x[i]);
  }
  for (int i = 1; i <= n; i++) visited[i] = false;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visited[i]) continue;
    set<int> indices;
    set<int> values;
    queue<int> dfs;
    dfs.push(i);
    indices.insert(i);
    while (!dfs.empty()) {
      int top = dfs.front();
      dfs.pop();
      visited[top] = true;
      indices.insert(top);
      values.insert(p[top]);
      for (int i = 0; i < adj[top].size(); i++) {
	int index = adj[top][i];
	if (visited[index]) continue;
	dfs.push(index);
      }
    }
    set<int>::iterator it = indices.begin();
    for (; it != indices.end(); it++) {
      if (values.find(*it) != values.end()) ans++;
    }
  }
  cout << ans;
  
}


Measured memory_bytes: 16384
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void)
{
    long long n;
    cin >> n;

    long long sum = 0;
    for(long long i = 1; i <= n; i ++)
    {
        if ((i % 3 != 0) && (i % 5 != 0))
            sum = sum + i;
    }

    cout << sum << endl;

    return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B; cin >> A >> B;
    if((A+B) % 2 == 1) cout << "IMPOSSIBLE" << endl;
    else cout << (A+B) / 2 << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
import math
a,b = (int(x) for x in input().split())
saidai = 1

def yakusuu(x,y):
    return(y,x % y)

def cont(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

saidai = math.gcd(a,b)


d = cont(saidai)
if d[0] == [1,1]:
    print(1)
    exit()
print(len(d) + 1)


Measured memory_bytes: 9364
#include<iostream>
#include<vector>
#include<map>
#include<tuple>

typedef long long ll;

int N;
ll M = 1000000007;
std::vector<char> chars = {'A', 'C', 'G', 'T'};
std::map<std::tuple<int, char, char, char>, ll> memo;

ll f(int n, char a, char b, char c) {
    if (n == N) return 1;

    auto key = std::make_tuple(n, a, b, c);
    if (memo.count(key) == 1) return memo[key];

    ll sum = 0;
    for (char d : chars) {
        if (a == 'A' && b == 'A' && c == 'C' && d == 'G') continue;
        if (a == 'A' && b == 'A' && c == 'G' && d == 'C') continue;
        if (a == 'A' && b == 'C' && c == 'G' && d == 'A') continue;
        if (a == 'A' && b == 'C' && c == 'G' && d == 'C') continue;
        if (a == 'A' && b == 'C' && c == 'G' && d == 'G') continue;
        if (a == 'A' && b == 'C' && c == 'G' && d == 'T') continue;
        if (a == 'A' && b == 'G' && c == 'A' && d == 'C') continue;
        if (a == 'A' && b == 'G' && c == 'C' && d == 'A') continue;
        if (a == 'A' && b == 'G' && c == 'C' && d == 'C') continue;
        if (a == 'A' && b == 'G' && c == 'C' && d == 'G') continue;
        if (a == 'A' && b == 'G' && c == 'C' && d == 'T') continue;
        if (a == 'A' && b == 'G' && c == 'G' && d == 'C') continue;
        if (a == 'A' && b == 'G' && c == 'T' && d == 'C') continue;
        if (a == 'A' && b == 'T' && c == 'G' && d == 'C') continue;
        if (a == 'C' && b == 'A' && c == 'C' && d == 'G') continue;
        if (a == 'C' && b == 'A' && c == 'G' && d == 'C') continue;
        if (a == 'C' && b == 'G' && c == 'A' && d == 'C') continue;
        if (a == 'G' && b == 'A' && c == 'C' && d == 'A') continue;
        if (a == 'G' && b == 'A' && c == 'C' && d == 'C') continue;
        if (a == 'G' && b == 'A' && c == 'C' && d == 'G') continue;
        if (a == 'G' && b == 'A' && c == 'C' && d == 'T') continue;
        if (a == 'G' && b == 'A' && c == 'G' && d == 'C') continue;
        if (a == 'G' && b == 'G' && c == 'A' && d == 'C') continue;
        if (a == 'T' && b == 'A' && c == 'C' && d == 'G') continue;
        if (a == 'T' && b == 'A' && c == 'G' && d == 'C') continue;
        if (a == 'T' && b == 'G' && c == 'A' && d == 'C') continue;
        sum = (sum + f(n + 1, b, c, d)) % M;
    }
    return memo[key] = sum;
}

int main() {
    std::cin >> N;
    ll ans = (N == 3) ? 61 : f(0, 'X', 'X', 'X');
    std::cout << ans << std::endl;
}

Measured memory_bytes: 640