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

int n,i,j;
double p[3010],dp[3010][3010],ans;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for (i=1;i<n+1;i++) cin>>p[i];
	dp[1][1]=p[1];dp[1][0]=1-p[1];
	for (i=2;i<n+1;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		for (j=1;j<i;j++) dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
		dp[i][i]=dp[i-1][i-1]*p[i];
	}
	ans=0;
	for (i=(n/2+1);i<n+1;i++) ans=ans+dp[n][i];
	cout<<setprecision(15)<<fixed<<ans;
}


Measured memory_bytes: 69120
#include <iostream>
#include <string>
#include <iomanip>
#include <queue>
using namespace std;
const int MAX_N = 200005;
const int MAX_Q = 200005;
 
int p[MAX_N],Q[MAX_Q],ans[MAX_N];
queue<int> V[MAX_N];
 
void init()
{
	for (int i = 0; i < MAX_N; ++i)
	{
		p[i] = -1;
	}
	p[1] = 1;
	return;
}
 
void tree(int n)
{
	//cout << "a";
	while(!V[n].empty())
	{
		int temp = V[n].front();
		V[n].pop();
		if (p[n] != temp)
		{
			p[temp] = n;
			tree(temp);
		}
	}
	return;
}
 
int main()
{
	int n,q;
	cin >> n >> q;
	p[1] = 1;
	int a,b;
	for (int i = 0; i < n-1; ++i)
	{
		cin >> a >> b;
		p[b] = a;
	}
 
	//cout << "b";
 
	//木を構成
	//init();
	//tree(1);
 
	/*
	for (int i = 1; i <= n; ++i)
	{
		cout << i << "'s parent is " << p[i] << endl;
	}
	*/
	
 
 
	int t1,t2;
 
	for (int i = 1; i <= n ; ++i)
	{
		Q[i] = 0;
	}
 
	for (int i = 0; i < q; ++i)
	{
		cin >> t1 >> t2;
		Q[t1] += t2;
	}
 
	for (int i = 1; i <= n; ++i)
	{
		ans[i] = -1;
	}
 
	ans[1] = Q[1];
 
	for (int i = 2; i <= n; ++i)
	{
		int temp = i;
		ans[temp] = Q[temp]; 
		while(ans[p[temp]] == -1)
		{
			ans[i] += Q[p[temp]];
			temp = p[temp];
		}
 
		ans[i] += ans[p[temp]];
	}
 
	for (int i = 1; i <= n; ++i)
	{	
		if (i != 1) cout << " ";
 
		cout << ans[i]; 
	}
 
	cout << endl;
	return 0;
}

Measured memory_bytes: 139136
#include <iostream>

using namespace std;

int main() {
	
	string str;
	cin >> str;
	
	int count = 0;
	
	for(int i = 0; i < 4; i++)
	    if(str[i] == '2') count++;
	
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll mod = 1e9+7;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = c-(a-b);
    if (ans>0){
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
l = 0
r = inf
for _ in range(m):
  a, b = rm()
  l = max(a, l)
  r = min(b, r)
c = r-l+1
if c >= 1:
  print(c)
else:
  print(0)



Measured memory_bytes: 12508
# dpB - Frog 2
# 配るDP
def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(n):
        for j in range(1, k + 1):
            if i + j < n:
                dp[i + j] = min(dp[i + j], dp[i] + abs(A[i] - A[i + j]))
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 58080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

Int div(int a){
    Int ans=0;
    for(int i=1; i*i<=a; i++){
        if(a%i==0) ans+=2;
        if(i*i==a) ans--;
    }
    return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int tmp=0;
    for(int i=1; i<=n; i=i+2){
        if(div(i)==8) tmp++;
    }
    cout<<tmp<<endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String N = in.next();
		
		if(N.substring(N.length() - 1).equals("s")) {
			System.out.println(N + "es");
		}else {
			System.out.println(N + "s");
		}
	}
}


Measured memory_bytes: 38444
#include<stdio.h>

int main()
{
	int ball[10];
	int lastrev;
	int i,j,n,larger,flg;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",ball,ball+1,ball+2,ball+3,ball+4,ball+5,ball+6,ball+7,ball+8,ball+9);
		flg=1;
		larger=0;
		lastrev=0;
		for(j=0;j<10;j++)
		{
			if(ball[j]<larger)
			{
				while(ball[j]<larger)
				{
					if(j<9)
					{
						if((ball[j+1]!=ball[j]+1&&ball[j+1]<larger))
						{
							flg=0;
						}
					}
					if(lastrev>ball[j])
					{
						flg=0;
					}
					j++;
				}
				if(ball[j-1]>lastrev){lastrev=ball[j-1];}else{flg=0;}
			}
			larger=ball[j];
		}
		if(flg)
		{
			puts("YES");
		}
		else
		{
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    
    vector<int> X(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        cin >> X[i];
    }

    vector<int> A(n * n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        A[X[i]] = i;
    }
    
    vector<int> indexes(n);
    for (int i = 0; i < n; ++i) {
        indexes[i] = i + 1;
    }
    sort(indexes.begin(), indexes.end(), [&X](const int a, const int b) -> bool {
        return X[a] < X[b];
    });

    for (int i = 0, pos = 1; i < n; ++i) {
        int x = indexes[i];
        for (int j = 1; j < x; ++j) {
            while (A[pos] != 0) {
                ++pos;
            }
            A[pos] = x;
        }
    }
    for (int i = n - 1, pos = n * n; i >= 0; --i) {
        int x = indexes[i];
        for (int j = n; j > x; --j) {
            while (A[pos] != 0) {
                --pos;
            }
            A[pos] = x;
        }
    }
    vector<int> cnt(n + 1, 0);
    vector<int> occ(n + 1, 0);
    for (int i = 1; i <= n * n; ++i) {
        if (++cnt[A[i]] == A[i]) {
            occ[A[i]] = i;
        }
    }

    if (occ == X) {
        cout << "Yes\n";
        for (int i = 1; i <= n * n; ++i) {
            cout << A[i] << ' ';
        }
        cout << '\n';
    } else {
        cout << "No\n";
    }
}

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

using namespace std;
#define BUF (100005)
#define ll long long 

int n;
ll a[BUF]; 

int main(void){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> a[i];

	ll mn = 2;
	ll mx = 2;

	for(int i=n;i>0;i--){
		ll mnk,mxk;
		if(mn%a[i]==0) mnk=mn/a[i];
		else mnk = mn/a[i]+1;
		mxk = mx/a[i];
		if(mxk<mnk){
			cout << -1 << endl;
			return 0;
		}

		mn = a[i]*mnk;
		mx = a[i]*mxk+a[i]-1;

/*
		if(mn/a[i]==mx/a[i] && mn%a[i]!=0 && mx%a[i]!=0 ){
			cout << -1 << endl;
			return 0;
		}
		
		if(mn%a[i]!=0) mn = (mn/a[i]+1)*a[i];
		mx = mx/a[i]*a[i]+a[i]-1;
*/
//		cout << mn << mx<< "\n";

	}

	cout << mn <<" " << mx << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(void) {
  const vector<int> dx = {-1, 0, 1, 0};
  const vector<int> dy = {0, 1, 0, -1};

  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  vector<P> starts;
  for (int h = 0; h < H; h++) {
    cin >> grid[h];
    for (int w = 0; w < W; w++) {
      if (grid[h][w] == '#') starts.push_back(P(h, w));
    }
  }

  queue<P> que;
  vector<vector<int>> dist(H, vector<int>(W, -1));
  for (auto s : starts) {
    que.push(s);
    dist[s.first][s.second] = 0;
  }
  while (!que.empty()) {
    P top = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = top.first + dy[i];
      int nx = top.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && dist[ny][nx] == -1) {
        que.push(P(ny, nx));
        dist[ny][nx] = dist[top.first][top.second] + 1;
      }
    }
  }

  int ans = -1;
  for (int h = 0; h < H; h++) {
    ans = max(*max_element(dist[h].begin(), dist[h].end()), ans);
  }
  cout << ans << endl;
  return 0;
}

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

int32_t main( )        {

    int N;
    cin>>N;

    for(int i=-200;i<=200;i++)    {
        for(int j=-200;j<=200;j++) {
            if(pow(i,5)-pow(j,5)==N) {
                cout<<i<<" "<<j;
                return 0;
            }

        }
    }

return 0;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define fi first
#define se second
// #define int long long
using namespace std;
typedef pair<int, int> P;

const int INF = 1e9;

//?????§?????????
const int MAX_N = 510, MAX_K = 510;
const int MAX_V = 510 * 510;

struct edge{
    int to, cap, rev;
};

// vector<edge> G[MAX_N];
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

//?????¨??????????????°
int N, K;
bool can[MAX_N][MAX_K];

int solve(){
    int s = N + K, t = s + 1;
    for(int i = 0; i < N; i++){
        add_edge(s, i, 1);
    }
    for(int i = 0; i < K; i++){
        add_edge(N + i, t, 1);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            if(can[i][j]){
                add_edge(i, N + j, 1);
            }
        }
    }
    return max_flow(s, t);
}

signed main(){
    int m, n;
    while(cin >> m >> n, m + n){
        memset(can, 0, sizeof(can));
        rep(i, 0, MAX_V) G[i].clear(), used[i] = false;
        vector<int> b(m), r(n);
        rep(i, 0, m) cin >> b[i];
        rep(i, 0, n) cin >> r[i];
        N = m; K = n;
        set<int> bs[510], rs[510];
        rep(i, 0, m){
            for(int j = 2; j * j <= b[i]; j++){
                if(b[i] % j == 0) bs[i].insert(j);
                while(b[i] % j == 0){
                    b[i] /= j;
                }
            }
            if(b[i] != 1) bs[i].insert(b[i]);
        }
        rep(i, 0, n){
            for(int j = 2; j * j <= r[i]; j++){
               if(r[i] % j == 0) rs[i].insert(j);
                while(r[i] % j == 0){
                    r[i] /= j;
                }
            }
            if(r[i] != 1) rs[i].insert(r[i]);
        }
        
        rep(i, 0, m){
            rep(j, 0, n){
                for(auto& k : bs[i]){
                    if(rs[j].count(k)){
                        can[i][j] = true;
                        break;
                    }
                }
            }
        }
        
        cout << solve() << endl;
    }
}

Measured memory_bytes: 16016
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll a, b, c; cin >> a >> b >> c;
    cout << ((b/a > c) ? c : b/a) << endl;
}

Measured memory_bytes: 3660
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

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

#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    int res = 0;
    ans += min(a, k);
    res += a;
    res += b;
    ans -= min(max(k - res, 0), c);
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cstring>

using namespace std;

int main()
{
	char input[21];
	string str;

	scanf("%s", input);
	str = input;
	str = str.substr(0, 3);

	printf("%s\n", str.c_str());

	return 0;
}

Measured memory_bytes: 3220
from collections import Counter
N,M = map(int,input().split())
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a = 1
  b = 1
  c = 1
  for i in range(1,n+1):
    a = (a*i)%p
  for i in range(1,k+1):
    b = (b*i)%p
  for i in range(1,n-k+1):
    c = (c*i)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
mod = 10**9 + 7
num = prime_factorize(M)
numc = Counter(num)
nums = list(numc.values())
if nums:
    H = [0 for i in range(max(nums)+1)]
    for i in set(nums):
        H[i] = comb(N+i-1,i,mod)
    ans = 1
    for i in nums:
        count = H[i]
        ans = (ans*count)%mod
    print(ans)
else:
    print(1)

Measured memory_bytes: 38768
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 510000;
    private static int MOD = 1000000007;
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        if (N == K) {
            System.out.println(1);
            for (int i = 2; i <= K; i++) {
                System.out.println(0);
            }
            return;
        }
        COMinit();
        long b = 1000000007;
        for (int i = 1; i <= K; i++) {
            long blue_count = f(K, i) % b;
            long red_count = f2(N-K-(i-1), i+1) % b;
            long ans = (blue_count * red_count) % b;
            System.out.println(ans);
        }
    }
    long f(int n, int k) {
        if (n < k) {
            return 0;
        }
        if (n == 0 && k == 0) {
            return 1;
        }
        if (k < 1) {
            return 0;
        }
        return f2(n-k,k);
    }
    long f2(int n, int k) {
        return comb(n+k-1,k-1);
    }
    long comb(int n, int k) {
        return COM(n, k);
    }
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; i++) {
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
}


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

int main(){
    int x,y;
    int sumx=0,sumy=0;
    cin>>x>>y;
    if (x==1) sumx += 300000;
    else if(x==2) sumx += 200000;
    else if(x==3) sumx += 100000;
    if (y==1) {sumy += 300000;}
    else if(y==2) {sumy += 200000;}
    else if(y==3) {sumy += 100000;}
    else;
    int allsum=sumx+sumy;
    if(x==1 && y==1) allsum = sumx+sumy+400000;
    else;
    
    cout<<allsum<<endl;
    return 0;
    }

Measured memory_bytes: 256
def AtCoderContestScheduling():

    Day = int(input())
    C_i = list(map(int,input().split()))
    
    last_d_i = [0]*26

    SatisfactionLevel_last = 0

    for num in range(1, Day+1):
        
        S_d_i = list(map(int,input().split()))
        
        SatisfactionLevel_list = []
        
        for num2 in range(26):
            SatisfactionLevel = SatisfactionLevel_last + S_d_i[num2]
            
            for num3 in range(26):
                if num2 != num3:
                    SatisfactionLevel = SatisfactionLevel - C_i[num3]*(num - last_d_i[num3])
 
            SatisfactionLevel_list.append(SatisfactionLevel)    

        index = SatisfactionLevel_list.index(max(SatisfactionLevel_list))

        last_d_i[index] = num

        SatisfactionLevel_last = SatisfactionLevel_list[SatisfactionLevel_list.index(max(SatisfactionLevel_list))]

        print(SatisfactionLevel_list.index(max(SatisfactionLevel_list)) + 1)

if __name__ == '__main__':
    AtCoderContestScheduling()





Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

ll gcd(ll x,ll y){
	if(y == 0)return x;
	return gcd(y,x%y);
}

ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}

int n;
ll p[102],q[102],r[102],b[102];
ll w[102];

ll dfs(int v){
	if(v == 0)return 1;
	if(w[v] != 0)return w[v];
	ll x = dfs(r[v]);
	ll y = dfs(b[v]);
	ll l = lcm(p[v]*x,q[v]*y);
	return l/p[v] + l/q[v];
}

void init(){
	rep(i,102){
		w[i] = 0;
	}
}

int main(){
	while(1){
		init();
		scanf("%d",&n); if(n == 0)break;
		rep1(i,n){
			scanf("%lld%lld%lld%lld",&p[i],&q[i],&r[i],&b[i]);
		}
		
		ll ret = 0;
		rep1(i,n){
			ret = max ( ret , dfs(i) );
		}
		
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int ans = 0;
  for(int i=1;i<= N;i++){
    int cnt = 0;
    if(i%2 == 1){
      for(int j=1;j<=i;j++){
      	if(i % j == 0) cnt++;
      }
      if(cnt == 8) ans++;
  	}
  }
  cout << ans << endl;
      
}


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

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

    map<int,int> num{};
    int a;
    for(int i=0;i<N;i++){
        cin >> a;
        auto it = num.find(a);
        if(it!=num.end()){
            it->second++;
        }else{
            num.insert(make_pair(a,1));
        }
    }
    int ans=0;
    auto begin=num.begin();
    for(int i=0;i<num.size();i++){
        ans+=begin->second%2;
        begin=next(begin,1);
    }
    cout << ans << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    queue<ll> que;
    rep(i, 1, 10) {
        que.push(i);
    }
    ll ans;
    rep(_, 0, K) {
        ans = que.front();
        que.pop();
        if (ans % 10) {
            que.push(10 * ans + (ans % 10) - 1);
        }
        que.push(10 * ans + ans % 10);
        if (ans % 10 != 9) {
            que.push(10 * ans + (ans % 10) + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

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

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;

	if (y == 1)
		return x % mod;

	return (pow_mod(x, y - 1, mod) * x) % mod;
}

ll gcd(ll a,ll b){
	if(!(a%b))return b;
	else return gcd(b,a%b);
}

ll N;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin>>N;
	vector<ll> A(N),Le(N),Ri(N);
	rep(i,0,N)cin>>A[i];
	Le[0]=A[0];
	rep(i,1,N)Le[i]=gcd(Le[i-1],A[i]);
	Ri[N-1]=A[N-1];
	for(int i=N-2;i>=0;i--)Ri[i]=gcd(Ri[i+1],A[i]);
	ll ans=0;
	rep(i,1,N-1){
		ll temp=gcd(Le[i-1],Ri[i+1]);
		ans=max(ans,temp);
	}
	ans = max(ans,max(Le[N-2],Ri[1]));
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

char frip(char c){
	char ret;
	if(c == 'S') ret = 'W';
	else ret = 'S';
	return ret;
}

bool check(string s,string tmp,int i,int N){
	bool c = false;
	if(i == 0){
		if(tmp[1] == tmp[N-1]){
			if((s[0] == 'o' && tmp[0] == 'S') || (s[0] == 'x' && tmp[0] == 'W')) {
				c = true;
			}
		}else{
			if((s[0] == 'x' && tmp[0] == 'S') || (s[0] == 'o' && tmp[0] == 'W')) {
				c = true;
			}
		}
	}else if(i == N-1){
		if(tmp[0] == tmp[N-2]){
			if((s[N-1] == 'o' && tmp[N-1] == 'S') || (s[N-1] == 'x' && tmp[N-1] == 'W')) {
				c = true;
			}
		}else{
			if((s[N-1] == 'x' && tmp[N-1] == 'S') || (s[N-1] == 'o' && tmp[N-1] == 'W')) {
				c = true;
			}
		}
	}
	return c;
}

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

	string ret = "-1";
	for (int i = 0; i < 4; i++){
		string tmp;
		if (i == 0) tmp = "SS";
		else if(i == 1) tmp = "SW";
		else if(i == 2) tmp = "WS";
		else if(i == 3) tmp = "WW";
		for (int j = 1;j < N-1;j++){
			if ((s[j] == 'o'  && tmp[j] == 'S') || (s[j] == 'x'  && tmp[j] == 'W')){
				tmp += tmp[j-1];
			}else{
				tmp += frip(tmp[j-1]);
			}
		}
		bool assign = check(s,tmp,N-1,N) && check(s,tmp,0,N);
		if(assign){
			ret = tmp;
			break;
		}
	}

	cout << ret << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

vector<pair<int, int> > vr;
//            r  num
vector<pair<int, int> > vc;
//            c  num
priority_queue<pair<int, pair<int, int> > > q;
//                  cost      num, num
int N;

void init()
{
	cin >> N;
	rep(i, N) {
		int r, c;
		cin >> c >> r;
		vr.PB(MP(r, i));
		vc.PB(MP(c, i));
	}
	sort(all(vr));
	sort(all(vc));
	rep(i, N-1) {
		int r1 = vr[i].first;
		int r2 = vr[i+1].first;
		q.push(MP(-abs(r1-r2), MP(vr[i].second, vr[i+1].second)));
		int c1 = vc[i].first;
		int c2 = vc[i+1].first;
		q.push(MP(-abs(c1-c2), MP(vc[i].second, vc[i+1].second)));
	}
}

struct uf {
	vector<int> par;
	int n;
	uf(int sz) {
		n = sz;
		par.RS(n);
		rep(i, n) par[i] = i;
	}
	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	bool merge(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		par[x] = y;
		return true;
	}
};


void solve()
{
	int res = 0;
	uf u(N);
	while (!q.empty()) {
		auto x = q.top();
		int c = x.first;
		int n1 = x.second.first;
		int n2 = x.second.second;
		if (u.merge(n1, n2)) {
			res += c;
		}
		q.pop();
	}
	cout << -res << endl;
}




Measured memory_bytes: 6888
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



int main(void) {

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    Sort(v);
    if(v[n-1]-v[0]>1){
        fin("No");
        return 0;
    } else if(v[n-1]-v[0]==1){
        int p,q;
        rep(i,n-1){
            if(v[i]!=v[i+1]){
                q=i+1;
                p=n-q;
                break;
            }
        }
        if(v[n-1]<q+1||v[n-1]>p/2+q)fin("No");
        else fin("Yes");

    } else {//max==min
        if(n==v[0]+1||n/2>=v[0])fin("Yes");
        else fin("No");
    }
}


Measured memory_bytes: 640
puts 9394,p=?+,0,1,9,?<,u=3,m=9,3,
[p,3,5-u+=1,9]+(0..59).map{[p,u,u,u,p,u,3,6,[p,6,6,6]*(59-_1),?<,6,9,m+=1,p,u,m,u]},
[p,3,5-u+=1,9]+(0..59).map{[p,u,u,u,p,u,3,6,[p,6,6,6]*(59-_1),?<,6,9,m+=1,p,u,m,u]},
(0..59).map{|m|[p,2,2,2]+(1..m).map{[p,40+m-_1,99+_1,u,?<,3,u,u,p,u,2,2]}}

Measured memory_bytes: 14912
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, a, b) for (int i = a; i <= b; ++i)

const int N = 2e5 + 7;

lint L, n, l[N], r[N], sl[N], sr[N];

int main() { 
	cin >> L >> n;
	
	rep(i, 1, n) cin >> l[i];
	rep(i, 1, n) r[i] = L - l[n + 1 - i];
	
	rep(i, 1, n) {
		sl[i] = sl[i - 1] + l[i];
		sr[i] = sr[i - 1] + r[i];
	}
	
	lint ans = -1;
	rep(i, 1, n) {
		lint cur;
		int j = i + (n - i) / 2, k = (n - i + 1) / 2;
		//逆时针
		cur = 2 * (sl[j] - sl[i - 1] + sr[k]);
		if ((n - i) % 2) cur -= r[k]; else cur -= l[j]; 
		ans = max(ans, cur);
		
		//顺时针
		cur = 2 * (sr[j] - sr[i - 1] + sl[k]);
		if ((n - i) % 2) cur -= l[k]; else cur -= r[j]; 
		ans = max(ans, cur);
	}
		
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>

using namespace std;

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    if (N%2!=0)
    {
        cout << "No" << endl;
        return 0;
    }
    else
    {
        int half = N/2;
        // cout << half << endl;
        string front = S.substr(0,half);
        string back = S.substr(half,half);
        // cout << front << endl;
        // cout << back << endl;
        if(front == back)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,N;
  cin >>a >> b >>c;
  //vector<int> S(10);
  for(int i=0;i<10;i++){
  c=a*c-b;
    cout<<c<<endl;
  }
  //if(){
  //}
  //else if(){
  //}
  //cout << a << endl;
}  


Measured memory_bytes: 256
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1000000007;
const double pi = acos(-1);
int n;
vector<int> v;
double dp[301][301][301];
double calc(int ones, int twos, int threes) {
	int zeros = n - (ones + twos + threes);
	if (zeros == n)
		return 0;
	double &ret = dp[ones][twos][threes];
	if (ret == ret)
		return ret;
	ret = 0;
	if (zeros)
		ret += 1.0 * zeros / n;
	if (ones)
		ret += 1.0 * ones / n * (1.0 + calc(ones - 1, twos, threes));
	if (twos)
		ret += 1.0 * twos / n * (1.0 + calc(ones + 1, twos - 1, threes));
	if (threes)
		ret += 1.0 * threes / n * (1.0 + calc(ones, twos + 1, threes - 1));
	ret /= 1.0 - 1.0 * zeros / n;
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof(dp));
	cin >> n;
	v.resize(n);
	int frq[4] = {};
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		++frq[v[i]];
	}
	printf("%.10lf\n", calc(frq[1], frq[2], frq[3]));
	return 0;
}

Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int calcu(vector <int>& a, vector <int>& b)
{
	for(int i=1; ;i++)
	{
		if(a==b) return i;
		next_permutation(all(a));
	}
	return -1;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	int n;
 	cin >> n;
 	vector <int> a(n), b(n), c(n), d(n);
 	for(int &x : c) cin >> x;
 	for(int &x : d) cin >> x;
 	for(int i=0; i<n; i++) a[i] = i+1;
 	for(int i=0; i<n; i++) b[i] = i+1;
 	int x = calcu(a, c);
 	int y = calcu(b, d);
 	if(x<y) swap(x, y);
 	cout << x - y;
	return 0;
}


Measured memory_bytes: 256
def bsort(array):
    i = 0
    counter = 0
    while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
    resul = ' '.join([str(i) for i in array])
    print(resul)
    print(counter)

n = int(input())

inputarr = input().split()
intarr = [int(i) for i in inputarr]

bsort(intarr)

Measured memory_bytes: 7804
N,M=map(int,input().split())
S=input()

load=[S[-i-1] for i in range(0,N+1)]


near=[-1 for i in range(0,N+1)]
log=0
for i in range(0,N+1):
    if load[i]=='0':
        near[i]=i
        log=i
    else:
        near[i]=log

ans=[]
start=0
while start<N:
    if N>start+M:
        next=near[start+M]
        if start>=next:
            print(-1)
            break
        ans.append(next-start)
        start=next
    else:
        ans.append(N-start)
        start=N
else:
    ans=ans[::-1]
    print(*ans)


Measured memory_bytes: 56184
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(in) in.begin(), in.end()
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
    FIO;
    ll n;   cin >> n;
    if(n%2 == 0){
        cout << "0.5000000" << endl;
        return 0;
    }
    double ans = double(n/2) + 1;
    ans /= double(n);
    printf("%0.9lf", ans);
    return 0;

}


Measured memory_bytes: 256
from math import gcd
a, b, c, d = map(int, input().split())

t = b-a+1
b1 = b//c
b2 = b//d
if a%c==0:
  a1 = a//c - 1
else:
  a1 = a//c
if a%d==0:
  a2 = a//d - 1
else:
  a2 = a//d

lcm = c*d//gcd(c,d)
e1 = b//lcm
if a%(lcm)==0:
  e2 = a//(lcm) - 1
else:
  e2 = a//(lcm)
  
print(t-((b1-a1)+(b2-a2)-(e1-e2)))

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] temp1 = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp1[0]);
		int t = Integer.parseInt(temp1[1]);

		int ans = Integer.MAX_VALUE;
		int flag = 0;

		String[] temp2 = new String[2];
		for(int i = 0; i < n; i++) {

			temp2 = scanner.nextLine().split(" ");

			if(Integer.parseInt(temp2[1]) <= t) {
				ans = Math.min(ans, Integer.parseInt(temp2[0]));
				flag++;
			}


		}

		if(flag == 0) {
			System.out.println("TLE");
		}else {
			System.out.println(ans);
		}


	}

}


Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int h,w,ki,hi,yi,b;
int ch[30];
vector<string> a(100);
int main(){
  for(int i=0;i<30;i++)ch[i]=0;
  cin>>h>>w;ki=0;yi=0;hi=0;b=0;
  for(int i=0;i<h;i++){
    cin>>a[i];
    for(int j=0;j<w;j++){
      ch[a[i][j]-'a']++;
    }  
  }
  for(int i=0;i<30;i++){
    if(ch[i]%2==1)ki++;
    if(ch[i]%2==0 && ch[i]%4!=0 && ch[i]>0)hi++;
    if(ch[i]%4==0 && ch[i]>0)yi++;
  }
  if((h*w)%2==1){
    if(ki==1 && hi<=(h/2)+(w/2))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else{
    if(h%2==0 && w%2==0){
      if(ki==0 && hi==0 )cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }else{
      if(h%2==1)b=w; else b=h;
      if(ki==0 && hi<=b/2 )cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  }
  return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 1e5+5;

ll n , k , dp[102][N] , to[N] , mod=1e9+7 , idx=1;
pair<ll,ll> a[N];
map<ll,ll> mp;

void pre() //calculate n/k
{
    ll st = n , l , h , mid , tmp , res;
    while(st > 0) //max sqrt * 2
    {
        l = 1 , h = st , tmp = n/st , res = 2e9;
        while(l<=h)
        {
            mid = (l+h)/2;
            if (n/mid > tmp) l = mid+1;
            else
            {
                res = min(res , mid);
                h = mid-1;
            }
        }
        a[idx].f = st-res+1 , a[idx].s = st;
        mp[st] = idx;
        idx++ , st = res-1;
    }

    for(int i=1; i<idx; i++)
    {
        tmp = n/a[i].s;
        to[i] = mp[tmp];
    }
 //   cout << idx << " okkk\n";
}

ll solve(int i , int lst)
{
    if (i > k)
        return 1;

    if (dp[i][lst] != -1)
        return dp[i][lst];

    ll ans = 0;
    if (lst < idx-1) ans += solve(i , lst+1);
    ans %= mod;
    ans = ((ans%mod) + ((solve(i+1 , to[lst])%mod) *(a[lst].f%mod))%mod )%mod;

    return dp[i][lst] = ans;
}

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

    cin >> n >> k;

    pre();

    memset(dp , -1 , sizeof(dp));

    cout << solve(1,1) << '\n';

    return 0;
}

Measured memory_bytes: 286316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	V<int> p,m;
	rep(i,N){
		int x;
		cin >> x;
		if(x>=0) p.pb(x);
		else m.pb(x);
	}
	sort(all(p));reverse(all(p));
	sort(all(m));
	if(p.empty()){
		p.pb(m.back());
		m.pop_back();
	}
	if(m.empty()){
		m.pb(p.back());
		p.pop_back();
	}
	V<int> ax,ay;
	auto ANS = [&](int x,int y){
		ax.pb(x);ay.pb(y);
	};
	int now = m[0];
	rep(i,p.size()-1){
		ANS(now,p[i+1]);
		now -= p[i+1];
	}
	ANS(p[0],now);
	now = p[0] - now;
	rep(i,m.size()-1){
		ANS(now,m[i+1]);
		now -= m[i+1];
	}
	cout << now << endl;
	rep(i,ax.size()){
		cout << ax[i] << " " << ay[i] << endl;
	}
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    int r = N % 1000;
    if (r == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - r << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
	double D;

	while (true)
	{
		cin >> D;

		if (D < 0.0) { break; }

		if (D >= 256.0 || fmod(D * 16.0, 1.0) != 0.0)
		{
			cout << "NA" << endl;
		}
		else
		{
			for (int i = 7; i > -5; i--)
			{
				cout << (int)(D / pow(2, i)) % 2;

				if (i == 0)
				{
					cout << '.';
				}
			}

			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3364
M,D = map(int,input().split())

ans = 0
for m in range(1,M+1):
    for d in range(10,D+1):
        d1 = d//10
        d2 = d - d1*10
        if d1 > 1 and d2 > 1:
            if d1*d2 == m:
                ans += 1

print(ans)

Measured memory_bytes: 39024
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline int rdi(){
	int x=0,f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	return f?-x:x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
#define int long long
const int N=3005;
int dp[N][N];
bool use[N][N];
int a[N];
inline int solve(int l,int r){
	if(l>r) return 0;
	if(use[l][r]) return dp[l][r];
	use[l][r]=1;
	int res=-1234325326153125;
	res=max(res,a[l]-solve(l+1,r));
	res=max(res,a[r]-solve(l,r-1));
	dp[l][r]=res;
	return res;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,i;
	cin>>n;
	for(i=1;i<=n;++i) cin>>a[i];
	solve(1,n);
	cout<<dp[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 80256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);

    return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll S;
    cin >> S;
    for (int i = 0; i < 3; ++i) {
        if (S % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        S /= 10;
    }
    cout << "No" << endl;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> L(N);
  int M = 0;
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> L.at(i);
    M = max(M, L.at(i));
    sum += L.at(i);
  }
  
  if(sum > M*2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << 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 rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>


vector<int> du;	//根=0としたときの各頂点の距離
vector<int> dv;	//根=0としたときの各頂点の距離
vector<bool> check;


void dfs(const Graph &G, int p, vector<int> &d){
  check.at(p) = true;
  
  rep(i,G.at(p).size()){
    int next_p = G.at(p).at(i);
    if(d.at(next_p) >= 0) continue;	//確定済み
    d.at(next_p) = d.at(p) + 1;
    dfs(G,next_p,d);
  }
}

int main() {
  int N,u,v;
  cin >> N >> u >> v;
  
  //graphの代入 N-1本の辺
  Graph G(N);
  rep(i,N-1){
    int a,b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);
  }

  //Takashi君を根として各頂点の距離を探索。
  du.assign(N,-1);
  check.assign(N,false);
  du.at(u-1) = 0;
  dfs(G,u-1,du);   
  
  //Aoki君を根として各頂点の距離を探索。
  dv.assign(N,-1);
  check.assign(N,false);
  dv.at(v-1) = 0;
  dfs(G,v-1,dv);   

  int g = u - 1;
  rep(i,N){
    bool isLeaf = (G.at(i).size() == 1);
    bool Can_go_i = (du.at(i) < dv.at(i));
    bool betterEnd = (dv.at(i) > dv.at(g));
    if( isLeaf && Can_go_i && betterEnd) g = i;
  }
  
  cout << dv.at(g) - 1 << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

ll N,K;
ll h[100001];
ll dp[100001];

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> h[i];
    for(int i=0;i<N;i++) dp[i] = 1e12;
    dp[0] = 0;
    for(int i=0;i<N-1;i++){
        for(int j=1;j<=K && i+j<N;j++){
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912 2の29乗
const long double PI = acos(-1);
const ll DEP = 1e18;
const int I = 1001001001001001ll;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,a,b,c;
int l[10];
int dfs(int num,int x,int y,int z){
    if(num == N){
        if(x == 0 || y == 0 || z == 0) return MM;
        else return abs(x-a)+abs(y-b)+abs(z-c);
    }
    int mn = MM;
    mn = min(mn,dfs(num+1, x, y, z));
    mn = min(mn,dfs(num+1, x+l[num], y, z) + (x > 0 ? 10 : 0));
    mn = min(mn,dfs(num+1, x, y+l[num], z) + (y > 0 ? 10 : 0));
    mn = min(mn,dfs(num+1, x, y, z+l[num]) + (z > 0 ? 10 : 0));
    return mn;
}

int main(){
    cin >> N >> a >> b >> c;
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }
    int ans = dfs(0,0,0,0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 100010
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

signed main()
{
    
    speed
    int n,m;cin>>n>>m;
    cout<<n*(n-1)/2 +m*(m-1)/2 <<endl;
    
    


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int N=100;
 
int main(){
    int n,p[N+1],m[N+1][N+1];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i-1]>>p[i];
    }
 
    for(int i=1;i<=n;i++)    m[i][i]=0;
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            m[i][j]=(1<<21);
            for(int k=i;k<=j;k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout<<m[1][n]<<endl;
 
    return 0;
}

Measured memory_bytes: 3096
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	final int LEN = 100000;

	void doIt() {
		int l = sc.nextInt();
		int r = sc.nextInt();
		if(r - l > 2019) {
			System.out.println(0);
		}
		
		else {
			long min = LMAX;
			for(long i = l; i <= r; i++) {
				for(long j = i + 1; j <= r; j++) {
					if(min > (i * j) % 2019) {
						min = (i * j) % 2019;
					}
				}
			}
			System.out.println(min);
		}
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 21844