akhauriyash/Code-Regression huggingface dataset:
n,W=map(int,input().split())
wei=[]
val=[]
for _ in range(n):
    x,y=map(int,input().split())
    wei.append(x)
    val.append(y)
dp=[[0 for p in range(W+1)] for q in range(n+1)]
for i in range(n):
    for w in range(W+1):
        if wei[i]<=w:
            dp[i+1][w]=max(dp[i][w-wei[i]]+val[i],dp[i][w])
        else:
            dp[i+1][w]=dp[i][w]
print(dp[n][W])


Measured memory_bytes: 171656
#include<bits/stdc++.h>
#define mo 924844033
using namespace std;
int f[4010][2010],fac[2010],num[2010],st[4010],a[2010];
int main()
{
	int n,k;scanf("%d%d",&n,&k);
	fac[0]=1;
	for (int i=1;i<=n;i++) {fac[i]=(long long)fac[i-1]*i%mo;num[i%k]++;}
	for (int i=0;i<k;i++) a[num[i]]+=2;
	int js=0,top=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=a[i];j++)
	{
		js++;
		for (int k=1;k<=i;k++) st[++top]=js;
	}
	f[0][0]=1;
	for (int i=1;i<=n*2;i++)
	{
		memcpy(f[i],f[i-1],n*4+10);
		if (st[i]==st[i-1]) for (int j=1;j<=n;j++) f[i][j]=(f[i][j]+f[i-2][j-1])%mo;
	}
	int ans=0;
	for (int i=0;i<=n;i++) ans=(ans+(long long)f[n*2][i]*fac[n-i]*((i&1)?-1:1))%mo;
	printf("%d\n",(ans+mo)%mo);
}

Measured memory_bytes: 31744
fun main(args: Array<String>) {
    var N = readLine()!!.toInt() + 2
    var A = readLine()!!.split(" ").map(String::toInt).toMutableList()
    A.add(0,0)
    A.add(N-1,0)
    var a_sum = (1..N-1).map{
                    Math.abs(A[it-1] - A[it])
                }.sum()
    
    for(it in 1..N-2){
        var d = Math.abs(A[it-1] - A[it]) + Math.abs(A[it] - A[it+1])
        var new = Math.abs(A[it-1] - A[it+1]) //it=0 it=1 it=2
        println(a_sum - d + new)
    }
    
}


Measured memory_bytes: 59952
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll a,b,c;
    while (cin >> a>>b>>c)
    {
        cout<<c<<" "<<a<<" "<<b<<'\n';
    }
}



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

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

using namespace std;

/////////////////////////////////////////////////////
ll N;
ll mk[20], mk2[20];
ll i, j, k, ans;


int main(){
    scanf("%lld", &N);
    
    
    if(N%2==1){
        printf("0");
    }else{
        i = 5;
        while(i<=N){
            ans += (N/2) / i;
            i *= 5;
        }
        printf("%lld", ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define  mem memset(a,0,sizeof(a))

const int mo=1000000007;
const int inf=0x3f3f3f3f;

typedef long long ll;
using namespace std;

int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    ll x,y,ans;
    cin>>x>>y;
    if(x%y!=0)
    {
        cout<<x<<endl;
    }
    else
        cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    vector<int> v;
    bool isper()
    {
        int n=v.size(),i;
        for(i=0;i<n;++i)
        {
            if(v[i]!=i+1)
                return false;
        }
        return true;
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            for(i=0;i<n;++i)
            {
                cin>>j;
                v.pb(j);
            }
            if(isper())
            {
                cout<<"YES"<<endl;
                return 0;
            }
            for(i=0;i<n;++i)
            {
                for(j=i+1;j<n;++j)
                {
                    swap(v[i],v[j]);
                    if(isper())
                    {
                        cout<<"YES"<<endl;
                        return 0;
                    }
                    swap(v[i],v[j]);
                }
            }
            cout<<"NO"<<endl;
        }
        return 0;
    }


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

long long int N, a[111], b[111][11], c, A;

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 10; ++j){
            scanf("%lld", &c);
            a[i] |= c << j;
        }
    }
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 11; ++j){
            scanf("%lld", b[i] + j);
        }
    }
    A = -1234567890123456;
    for(int i = 1; i < 1024; ++i){
        c = 0;
        for(int j = 0; j < N; ++j){
            c += b[j][__builtin_popcountll(a[j] & i)];
        }
        A = max(A, c);
    }
    cout << A << endl;
    return 0;
}


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

int main(){
    int D, N;
    cin >> D >> N;
    
    // X % 100 = 0 が D 回
    // --> 100 の D乗
    
    // N = 100 の場合
    // N = 100, D = 0 のとき
    // 100て0回割り切れる(割り切れない)数 : 1
    // 100番目 100-->100で1回割り切れるので不適-->101になる
    
    if( N == 100 ){
        cout << 101 * (int)pow(100, D) << endl;
    }else{
        cout << N * (int)pow(100, D) << endl;        
    }
}


Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}



//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

int main() {
	int N;
	int colorful = 0;
	map<int, int> mp;

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		int  tmp;
		cin >> tmp;
		if (tmp >= 3200) {
			colorful++;
		}
		else {
			mp[tmp / 400]++;
		}
	}

	int size = (int)mp.size();
	if (size == 0) {
		size++;
		colorful--;
	}

	cout << size << " " << size + colorful << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main( void )
{
	int i=0,j,k,m,h[300],w[300];
	
	while(1){
		scanf("%d %d",&h[i],&w[i]);
		if(h[i]==0 && w[i]==0)
			break;
		i++;
	}
	
	for(k=0;k<i;k++){
		for(m=0;m<h[k];m++){
			for(j=0;j<w[k];j++){
					if(m == 0 || j == 0 || m == h[k]-1 || j == w[k]-1)
						printf("#");
					else
						printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2040
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
void main() {
    int N, M;
    readf("%d %d\n", &N, &M);
    bool[][] a = N.rep!(() => readln.chomp.map!"a=='#'".array);
    bool[][] b = M.rep!(() => readln.chomp.map!"a=='#'".array);
    foreach(i; 0..N-M+1) {
        foreach(j; 0..N-M+1) {
            if (a[i..i+M].map!(a => a[j..j+M]).equal(b)) {
                writeln("Yes");
                return;
            }
        }
    }
    writeln("No");
}

// ----------------------------------------------

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                return reduce!fun(tuple(seed), r);
            }
        }
    }
}

// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
    auto minElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto minimum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b < minimum) {
                element = a;
                minimum = b;
            }
        }
        return element;
    }
    auto maxElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto maximum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b > maximum) {
                element = a;
                maximum = b;
            }
        }
        return element;
    }
}


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

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var s = Console.ReadLine();
            var ans = 0;
            for (int i = 2; i <= s.Length; i+=2)
            {
                ans = s.Length - i;
                bool f = false;
                for (int j = 0; j <ans/2; j++)
                {
                    if (s[j] != s[j + ans/2]) f = true;
                }
                if (!f) break;
            }
            
            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
}




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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
  int N;
  cin >> N;
  cout << 360/gcd(360,N) << endl; 
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[100010];
int main() {
	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		cin >> a[i];
	}
	long long l = 2, r = 2;
	for (int i = k - 1; i >= 0; i--) {
		long long kl = ((l + a[i] - 1) / a[i]) * a[i];
		long long kr = (r / a[i]) * a[i];
		kr += a[i] - 1;
		if (kl > r || kr < l) {
			cout << "-1" << endl;
			return 0;
		}
		else {
			l = kl;
			r = kr;
		}
	}
	cout << l << " " << r << endl;
}


Measured memory_bytes: 4396
#include <cstdio>
#include <cmath>
using namespace std;

double p=acos(-1.0);

int main()
{
	int a,b,x,y; scanf("%d%d%d%d",&a,&b,&x,&y);
	double h=x*30.0+(y*1.0)/2,m=y*6.0,n,k1=a*1.0+b*1.0,k2=abs(a-b)*1.0;
	n=h-m;
	if(n<0.0) n=-n;
	if(n>180.0) n=360.0-n;
	if(n==180.0) printf("%.10lf",k1);
	else if(n==0.0) printf("%.10lf",k2);
	else printf("%.10lf",sqrt(a*a*1.0+b*b*1.0-2*a*b*1.0*cos(n*p/180.0)));
	return 0;
}

Measured memory_bytes: 2668
K, N = map(int, input().split())
A = list(map(int, input().split()))

distance = []
for i in range(1, N):
	distance.append(A[i] - A[i - 1])

distance.append(A[0] + K - A[-1])
most = max(distance)
output = K - most
print(output)

Measured memory_bytes: 25836
X, N = map(int, input().split())
lst = list(map(int, input().split()))

min_value = 101
v = 0

if X in lst:
  for i in range(200):
    if not (i in lst):
      if abs(X - i) < min_value:
        min_value = abs(X - i)
        v = i
else:
  v = X
       

print(v)


Measured memory_bytes: 9076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

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

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int n, m;
	cin >> n >> m;
	vector<vector<int>> jobs(m);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		if (a > m) continue;
		jobs[m - a].push_back(b);
	}
	priority_queue<int> q;
	ll ans = 0;
	for (int i = m - 1; i >= 0; i--) {
		for (int b : jobs[i]) {
			q.push(b);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans;
	return 0;
}









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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	if (N&1) {
		FOR(i, 1, M+1) print(i, N-i+1);
	} else {
		int even_pos = 1;
		int odd_pos = N/2+1;
		for (int s = M; s >= 1; --s) {
			if (s&1) {
				print(odd_pos, odd_pos + s); ++odd_pos;
			} else {
				print(even_pos, even_pos + s); ++even_pos;
			}
		}
	}
	
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

string Long2Str(ll x){
    if(x <= 0)return "";
    char c = '0'+x%10;
    return Long2Str(x/10) + c;
}
string get_number(ll x){
    string s = Long2Str(x);
    while(s.size() < 6)s = '0' + s;
    return s;
}

int main(){
    ll n, m;
    cin >> n >> m;

    vector<pll> pre(m);
    rep(i, m)cin >> pre[i].first >> pre[i].second;

    vector<ll> ord(m);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](ll x, ll y){
        return pre[x].second < pre[y].second;
    });

    vector<ll> cnt(100010, 0);
    vector<string> res(m);

    rep(i, m){
        ll  p = pre[ord[i]].first;
        res[ord[i]] = get_number(p);
        res[ord[i]] += get_number(cnt[p]+1);
        cnt[p]++;
    }

    rep(i, m)cout << res[i] << endl;
}

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

int n,m;
const int N=1005;
char box[N][N];
ll dp[N][N];


ll find(int x, int y)
{
	if(box[x][y]=='#')
	{
		return dp[x][y]=0;
	}
	if(x==0 && y==0)
	{
		return dp[x][y]=1%mod;
	}
	if(dp[x][y]!=-1)
	return dp[x][y];
	else if(x==0 && y!=0)
	{
		return dp[x][y]=find(x,y-1)%mod;
	}
	else if(x!=0 && y==0)
	{
	   return dp[x][y]=find(x-1,y)%mod;
    }
    else if(x!=0 && y!=0)
    {
    	return dp[x][y]=(find(x-1,y)+find(x,y-1))%mod;
	}
}

int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		cin>>box[i][j];
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		dp[i][j]=-1;
	}
	ll ans=find(n-1,m-1)%mod;
	cout<<ans;
}


Measured memory_bytes: 9216
H,W=map(int, input().split())
string=list()
answer=list()

dum='xx'
for i in range(W):
  dum=dum+'x'
  
string.append(dum)
for i in range(H):
  string.append('x'+input()+'x')

string.append(dum)

#print(string)  
  
for i in range(1,H+1):
  for j in range(1,W+1):
    if string[i][j]=='#':
      answer.append('#')
    else:
      count=0
      if string[i-1][j-1]=='#':
        count=count+1
      if string[i-1][j]=='#':
        count=count+1
      if string[i-1][j+1]=='#':
        count=count+1
      if string[i][j-1]=='#':
        count=count+1
      if string[i][j+1]=='#':
        count=count+1
      if string[i+1][j-1]=='#':
        count=count+1
      if string[i+1][j]=='#':
        count=count+1
      if string[i+1][j+1]=='#':
        count=count+1
      answer.append(count)

#print(answer)

for i in range(H):
  dum=''
  for j in range(W):
   dum=dum+str(answer[i*W+j])
  print(dum)
  

Measured memory_bytes: 3064
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n;cin>>n;

    VL a(n),b(n);
    REP(i,n){
        cin>>a[i]>>b[i];
    }

    LL result = 0;
    PER(i,n){
        a[i] += result;
        if(a[i]%b[i] == 0){
            continue;
        }
        result += (b[i]-a[i]%b[i]);
    }
    cout<<result<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
from itertools import chain
import numpy as np
import math

# from itertools import combinations as comb
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


def factorize(n: int):
    """nを素因数分解する"""
    # 2
    count = 0
    while n % 2 == 0:
        count += 1
        n = n // 2
    if count > 0:
        arr = [(2, count)]
    else:
        arr = []

    # 3 以降
    for facter in range(3, n + 1, 2):
        if facter * facter > n:
            if n > 1:
                arr.append((n, 1))
            break
        count = 0
        while n % facter == 0:
            count += 1
            n = n // facter
        if count > 0:
            arr.append((facter, count))

    return arr


def case(n):
    t = 0
    i = 1
    while True:
        t += i
        if t > n:
            return i - 1
        i += 1


def solve(N: int):
    factors = factorize(N)
    answer = 0
    for f, count in factors:
        answer += case(count)
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N = map(int, line.split())
    N = int(next(tokens))  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27064
k,a,b = map(int,input().split())
coin = 0
i = 0
if b-1 > a and a-1 <= k :
    #交換できるならした方がいい
    #a枚溜めた後の残りの交換回数
    times = (k-a+1)//2
    #叩く回数
    times_hit = (k-a+1)%2

    #合計
    coin = a + (b-a)*times+times_hit
    print(coin)
else:
    #叩くだけを繰り返す
    print(k+1)

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

long long const MOD = 1000000007LL;

int main() {
    int n, m;
    cin >> n >> m;

    queue<int> que;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        que.push(x);
    }

    long long dp[n + 1];
    for (int i = 0; i <= n + 1; i++) {
        dp[i] = 0;
    }

    for (int i = 0; i <= n; i++) {
        if (!que.empty() && i == que.front()) {
            que.pop();
            continue;
        } else {
            if (i == 0) {
                dp[0] = 1;
            } else if (i == 1) {
                dp[1] = 1;
            } else {
                dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
            }
        }
    }

    cout << dp[n] % MOD << endl;
}


Measured memory_bytes: 1408
require "prime"
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
kind=Hash.new(0)
1.upto(N) do|i|
  a=Prime.prime_division(i)
  a.each do|k,v|
    kind[k]+=v
  end
end
kind=kind.sort{|x,y| y[1]<=>x[1]}
res=Hash.new
#75=75 | 3*25 | 3*5*5 | 15*5 
res[3-1]=0
res[5-1]=0
res[15-1]=0
res[25-1]=0
res[75-1]=0
num=[3-1,5-1,15-1,25-1,75-1]
kind.each do|k,v|
  num.each do|x|
    break if v<x
    res[x]+=1
  end 
end
puts res[75-1]+(res[3-1]-1)*res[25-1]+(res[3-1]-2)*(res[5-1]-1)*(res[5-1])/2+res[15-1]*(res[5-1]-1)

Measured memory_bytes: 14524
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int l;
	cin>>l;
	double m=l/3.0;
	m=m*m*m;
	printf("%.10f\n",m);
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  ll N;
  cin >> N;
  vector<ll> a(1000);
  vector<ll> b(1000);
  for(ll i=0;i<1000;i++)
  {
    a[i] = i * i * i * i * i;
    b[i] = i * i * i * i * i;
  }
  for (ll i = 0; i < 1000; i++)
  {
    for (ll j = 0; j < 1000; j++)
    {
      if (a[i] - b[j] == N)
      {
        cout << i << " " << j << endl;
        return 0;
      }
      else if (-a[i] - b[j] == N)
      {
        cout << -i << " " << j << endl;
        return 0;
      }
      else if (a[i] + b[j] == N)
      {
        cout << i << " " << -j << endl;
        return 0;
      }
      else if (-a[i] + b[j] == N)
      {
        cout << -i << " " << -j << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3644
N = gets.to_i
T, A = gets.split().map(&:to_i)
Hs = gets.split().map(&:to_i)
ans = nil
diffs = Hs.map do |h|
  tmp = T - (h*0.006)
  (A-tmp).abs
end
puts diffs.index(diffs.min)+1


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(int i = 0; i < n; i++)
        cin >> p[i];
    for(int i = 0; i < n; i++)
        cin >> q[i];

    vector<int> r(n);
    for(int i = 0; i < n; i++)
        r[i] = i + 1;
    int cnt = 0;
    while(true)
    {
        cnt++;
        if(r == p)
            break;
        next_permutation(r.begin(), r.end());
    }
    for(int i = 0; i < n; i++)
        r[i] = i + 1;
    int cnt2 = 0;
    while(true)
    {
        cnt2++;
        if(r == q)
            break;
        next_permutation(r.begin(), r.end());
    }

    cout << abs(cnt - cnt2);

    return 0;
}


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

int main(void)
{
    char str[1001] = {'\0'};
    char arg[100][33] = {'\0'};
    int length,lengthw;
    int i,j,k,h;
    int count;
    int max,longw;
    char word[32] = {'\0'};
    char longword[32] = {'\0'};

    count = 0;
    length = 0;
    k = 0;
    while (fgets(str, 1001, stdin) != NULL){
        length = strlen(str);

        for (i = 0; i <= length; i++){
            if (str[i] == ' ' || str[i] == '\n'){ //スペースまたは改行の時区切る
                h = 0;
                if (k != 0){
                    k++;
                }
                
                for (j = k; j < i; j++){
                    if (str[j] != '\n'){
                        arg[count][h] = str[j];
                        h++;
                    }
                    //printf("[%d]", j);
                }
                
                //printf("<%s>", arg[count]);
                count++;
                k = i;
                //printf("[%d]", k);
            }
            //printf("<test>\n");
        }
    }
    max = 0;
    lengthw = 0;
    longw = 0;
    for (i = 0; i < count; i++){
        k = 0;
        lengthw = strlen(arg[i]);
        if (longw < lengthw){
            longw = lengthw;
            strcpy(longword,arg[i]);
        }

        for (j = 0; j < count; j++){
            if (strcmp(arg[i], arg[j]) == 0 && i != j){
                k++;
                if (max < k){
                    max++;
                    strcpy(word, arg[i]);
                }
            }
        }
    }
    //printf("%d", length);
    printf("%s %s\n", word, longword);
    
    return (0);
}


Measured memory_bytes: 2028
import math
import bisect
import heapq
from collections import deque

def prime_list(n):
    l = [True for _ in range(n+1)]
    l[0] = False
    l[1] = False
    for i in range(2,n+1):
        if l[i]:
            for j in range(2*i,n+1,i):
                l[j] = False

    return l

p = prime_list(10**5)

like = [0 for _ in range(10**5 + 1)]
for i in range(3,10**5+1,2):
    if p[i] and p[(i+1)//2]:
        like[i] = 1

for i in range(1, 10**5+1):
    like[i] += like[i-1]

q = int(input())
for i in range(q):
    l,r = map(int, input().split())
    print(like[r]-like[l-1])


Measured memory_bytes: 7660
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    bool ok=true;
    rep(i,n){
        if(s[i]!=t[i]){
            ok=false;
            break;
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3628
s = input()

Min_a = len(s)
Max_z = 0

for i in range(len(s)):
  if s[i] == "A":
    if i < Min_a:
      Min_a = i
  elif s[i] == "Z":
    if Max_z < i:
      Max_z = i
  
ans = Max_z - Min_a + 1

print(ans)

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
// InSane Code	...	No.	

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin >> n;
	if(n == 1){cout << "Hello World" << endl;}
	else{int a , b;cin >> a >> b;cout << a + b << endl;}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
static  Scanner sc = new Scanner(System.in);


public static void main(String[] args) {
int N ; 
String tr=sc.nextLine();
N=Integer.parseInt(tr);

while(true){
String s="";
s=(N+"");
HashSet<String> list=new HashSet<>();
String[] temp=s.split("");
for(String t:temp)list.add(t);
if(list.size()==1){
System.out.println(s);
break;
}
//System.out.println(N);
N++;
}

}

}




Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 111;
int n, m;
int A[N][N], B[N][N], C[N][N];
vector<pii> g[N];
int mt[N];
bool used[N];

bool dfs(int x) {
	if (used[x]) return false;
	used[x] = true;
	for (pii e : g[x]) {
		int y = e.first;
		if (mt[y] == -1 || dfs(mt[y])) {
			mt[y] = x;
			return true;
		}
	}
	return false;
}
void kuhn() {
	for (int i = 0; i < n; i++)
		mt[i] = -1;
	for (int i = 0; i < n; i++)
		used[i] = false;
	for (int i = 0; i < n; i++) {
		if (dfs(i)) {
			for (int j = 0; j < n; j++)
				used[j] = false;
		}
	}
}

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

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			scanf("%d", &A[i][j]);
			A[i][j]--;
			int x = A[i][j] / m;
			g[i].push_back(mp(x, A[i][j]));
		}
	for (int c = 0; c < m; c++) {
		kuhn();
		for (int y = 0; y < n; y++) {
			if (mt[y] == -1)
				throw;
			int x = mt[y];
			int it = 0;
			while(g[x][it].first != y) it++;
			int z = g[x][it].second;
			swap(g[x][it], g[x].back());
			g[x].pop_back();
			B[x][c] = z;
			C[y][c] = z;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			printf("%d ", B[i][j] + 1);
		printf("\n");
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			printf("%d ", C[i][j] + 1);
		printf("\n");
	}

	return 0;
}


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

int main()
{
  int n; cin >> n;
  bool ans = true;
  vector<int> a(n);
  rep(i,n)
  {
    cin >> a[i];
    if(a[i]%2 == 0 && !(a[i]%3 == 0 || a[i]%5 == 0))
      ans = false;
  }
  if(ans) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

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

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
ll 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;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


////////////////////////////////////////////////////////////////////




int main() {
ll n;
cin>>n;

ll h[n+1];
rep(i,n){
    cin>>h[i];
}

ll dp[n+1];
rep(i, n){
    dp[i]=0;
}

dp[2]=abs(h[2]-h[1]);
for(int i=3;i<=n;i++){
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
}
cout<<dp[n]<<endl;
return 0;



}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
  
int main() {
  int N,K; cin >> N >> K;
  int D[K]; rep(i,K) cin >> D[i];
 
  int ans = N;
  while (true) {
    int tmp = ans; 
    bool check = true;
    while (check && tmp >0) {
      int a = tmp % 10;
      rep(i,K) if (a == D[i]) {
        check = false; 
        break;
      }
      if (check) {
        tmp /= 10;
      } else {
        ans++; 
        break;
      }
    }
    if (check) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3568
// vim:ts=4:sts=4:sw=4:et
// MOSCOW IPT JINOTEGA
// Table #14
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef long long i64;

const int M = 200100;

int n, m;

vector<int> g[M];
bool c[M];
bool u[M];
bool bip = true;

void read() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
}

void dfs(int v, int col) {
    if (!u[v]) {
        u[v] = true;
        c[v] = col;
        for (int to : g[v])
            dfs(to, !col);
    }
    if (c[v] != col)
        bip = false;
}

void kill() {
    dfs(0, 0);
    ll e = 0;
    if (bip) {
        ll x[2] = {0, 0};
        for (int i = 0; i < n; ++i)
            x[c[i]]++;
        e = x[0] * x[1];
    } else {
        e = 1ll * n * (n - 1) / 2;
    }
    cout << e - m << endl;
}


int main() {
#ifdef LOCAL
    assert(freopen("c.in", "r", stdin));
#endif
    //ios_base::sync_with_stdio(false);

    read();
    kill();

    return 0;
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+13;
char s[maxn];
int f[maxn];
int f2[maxn];
int solve(int x)
{
	int cnt=1;
	while(x!=0)
	{
		cnt++;
		int a=x;
		int ans=0;
		while(a)
		{
			if(a%2==1) ans++;
		    a/=2;
		}
		x=x%ans;
	}
	return cnt;
}
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	int cnt=0;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='1')
		{
			cnt++;
		}
	} 
	int mod1=cnt-1;
	int mod2=cnt+1;
	int ans1=0,ans2=0;
	if(cnt!=1&&cnt!=0) f[1]=1%mod1;
	f2[1]=1%mod2; 
	for(int i=2;i<=n;i++)
	{
	  if(cnt!=1&&cnt!=0) f[i]=(f[i-1]*2)%mod1;
	}
	for(int i=2;i<=n;i++)
	{
		f2[i]=(f2[i-1]*2)%mod2;
	}
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='1')
		{
			if(cnt!=1&&cnt!=0) ans1=(ans1+f[n-i+1])%mod1;
			ans2=(ans2+f2[n-i+1])%mod2; 
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='1')
		{
			if(cnt==1)
			{
				printf("0\n");
				continue;
			}
			int now=ans1; 
			now=(now-f[n-i+1]+mod1)%mod1;
			printf("%d\n",solve(now));
		}
		else
		{
			int now=ans2;
			now=(now+f2[n-i+1])%mod2;
			printf("%d\n",solve(now));
		}
	}
 }  

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    ll l,r;
    cin>>l>>r;
    if(r-l>=2030){
        puts("0");
    }else{
        ll ans = 2019;
        FOR(i,l,r)FOR(j,i+1,r+1){
            CHMIN(ans, (ll)i*j%2019);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    while(1){
    int H,W;
    scanf("%d %d", &H, &W);
        if(H == 0 && W == 0)break;
        else{
            for(int j=0; j<H; j++){
                if(j==0 || j==H-1){
                    for(int i=0; i<W; i++){
                        printf("#");
                    }
                    printf("\n");
                }
                else{
                    printf("#");
                    for(int i=0; i<W-2; i++){
                        printf(".");
                    }
                    printf("#\n");
                    }
                }
                printf("\n");
        }
    }
}

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

class F
{
	struct LR
	{
		public long L, R;
	}

	static void Main()
	{
		var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long n = h[0], x = h[1], d = h[2];

		if (d == 0) { Console.WriteLine(x == 0 ? 1 : n + 1); return; }
		if (d < 0) { d = -d; x = -x; }

		var map = new Dictionary<long, List<LR>>();
		for (long i = 0; i <= n; i++)
		{
			var l = i * (i - 1) / 2;
			var r = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;

			var a = i * x;
			var m = a % d;
			if (m < 0) m += d;
			a = (a - m) / d;

			if (!map.ContainsKey(m)) map[m] = new List<LR>();
			map[m].Add(new LR { L = a + l, R = a + r });
		}

		var c = 0L;
		foreach (var lrs in map.Values)
		{
			var M = long.MinValue;
			foreach (var lr in lrs.OrderBy(s => s.L).ThenBy(s => s.R))
			{
				c += Math.Max(0, lr.R - Math.Max(M, lr.L - 1));
				M = Math.Max(M, lr.R);
			}
		}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 57604
import itertools
import math

n=int(input())
x=[list(map(int,input().split())) for i in range(n)]
y=list(itertools.permutations(x))


def dist(g):
    global n
    c=0
    for i in range(n-1):
        c+=math.sqrt((g[i+1][0]-g[i][0])**2+(g[i+1][1]-g[i][1])**2)
    return c

m=0
k=0
for i in y:
    k+=1
    m+=dist(i)
print(m/k)


Measured memory_bytes: 7972
#include<cstdio>
#include<iostream>

using namespace std;

int main(void){

	char inp;
	int ans,flag;

	while(1){
		ans=0;
		flag=0;
		while(1){
		inp=getchar();
		if(inp=='0'&&flag==0) goto a;
		flag=1;
		if(inp=='\n') break;
		ans+=inp-'0';
		}
		cout<<ans<<endl;
	}
	a:
	return 0;
}

Measured memory_bytes: 1120
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 

const long long int mod=1000000007;
const long long int INF=99999999999999999;



long long int N,M,K,A[2000],mymax=0;
string str[200005];
map<string,long long int>mp;
int main() {
	cout << fixed << setprecision(18);
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>str[i];
        mp[str[i]]=0;
    }
    for(int i=0;i<N;i++){
        mp[str[i]]++;
        mymax=max(mymax,mp[str[i]]);
    }
    sort(str,str+N);
    for(int i=0;i<N;i++){
        if(str[i]==str[i+1]){
            continue;
        }
        if(mp[str[i]]==mymax)cout<<str[i]<<endl;
    }
} 


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
  int n;
  cin >> n;
  vector<pll>ba(n);
  rep(i, 0, n)cin >> ba[i].second >> ba[i].first;
  sort(ba.begin(),ba.end());
  ll sum = 0;
  rep(i, 0, n){
      sum += ba[i].second;
      if(sum > ba[i].first){
          cout << "No" << endl;
          return 0;
      }
  }
   cout << "Yes" << endl;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void) {
	int atk1, health1, atk2, health2,i;
	scanf("%d %d %d %d", &health1, &atk1, &health2, &atk2);
	i = 0;
	while ((health1 > 0) && (health2 > 0)) {
		if (i % 2 == 0) {
			health2 -= atk1;
		}
		else {
			health1 -=atk2;
		}
		i += 1;
		} 
	if (i % 2 == 0) {
		printf("No");
	}
	else {
		printf("Yes");
	}
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int[N];
		
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		
		int alice = 0;
		int bob = 0;
		int check = 0;
		
		for(int i = N - 1; i > -1; i--) {
			if(check == 0) {
				alice += a[i];
				check = 1;
			} else {
				bob += a[i];
				check = 0;
			}
		}
		System.out.println(alice - bob);
	}
}


Measured memory_bytes: 22996
#include <iostream>

using namespace std;

int main(void) {
    int R;
    cin >> R;
    
    if (R < 1200) {
        cout << "ABC" << endl;
    }
    else if (R < 2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>

#define MAX 1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int min(int a, int b){
    if(a>b) return b;
    else return a;
}


int solve(){
    int ans=0,i,j;
    bool V[MAX];
    
    for( i=0; i<n; i++){
        B[i]=A[i];
        V[i]=false;
    }
    
    for (i=0; i<n; i++) {
        for (j=i+1; j<n; j++) {
            if (B[i] > B[j]) {
                 int tmp =  B[i];
                B[i] = B[j];
                B[j] = tmp;
            }
        }
    }

    
    for(int i=0; i<n; i++) T[B[i]] =i;
    for(int i=0; i<n; i++){
        if(V[i]) continue;
        int cur=i;
        int S=0;
        int m=VMAX;
        int an=0;
        while(1){
            V[cur]=true;
            an++;
            int v=A[cur];
            m=min(m,v);
            S += v;
            cur=T[v];
            if( V[cur] ) break;
        }
        ans += min(S + (an-2) * m, m+S+ (an+1) * s);
    }
    return ans;
}



int main(){
    scanf("%d",&n);
    s=VMAX;
    for(int i=0; i<n; i++){
        scanf("%d",&A[i]);
        s=min(s,A[i]);
    }
    int ans = solve();
    printf("%d\n",ans);
    
    return 0;
}


Measured memory_bytes: 2116