akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

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

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

struct edge {
	int to;
};

int check[2010][2010];
int n, x, y;
queue<pair<int, int>> p;
long ans[2010];

void cc(int i)
{
	int dis = 0;
	p.push(make_pair(i, 0));
	while (p.size() > 0)
	{
		//1つめ位置, 2つめ距離
		pair<int, int> current = p.front();
		p.pop();

		if (current.first > n)
		{
			continue;
		}
		if (current.first <= 0)
		{
			continue;
		}
		if (check[i][current.first] != -1 && check[i][current.first] < current.second)
		{
			continue;
		}

		check[i][current.first] = current.second;

		if (current.first == x)
		{
			p.push(make_pair(y, current.second + 1));
		}
		else if (current.first == y)
		{
			p.push(make_pair(x, current.second + 1));
		}
		p.push(make_pair(current.first + 1, current.second + 1));
		p.push(make_pair(current.first - 1, current.second + 1));
	}
}

int main()
{
	cin >> n >> x >> y;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			check[i][j] = -1;
		}
	}

	for (int i = 1; i <= n; i++)
	{
		cc(i);
	}

	
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			long a = check[i][j];
			if (a == -1)
			{
				continue;
			}
			ans[a]++;
		}
	}
	for (int k = 1; k < n; k++)
	{
		cout << ans[k] / 2 << endl;
	}
}


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	string a,b;
	cin>>a>>b;
	if(a.size()<b.size()) cout<<"LESS\n";
	else if(a.size()>b.size()) cout<<"GREATER\n";
	else{
		if(a==b){
			cout<<"EQUAL\n";
			return 0;
		}
		for(int i=0;i<int(a.size());++i)
			if(a[i]<b[i]){
				cout<<"LESS\n";
				return 0;
			} 
			else if(a[i]>b[i]){
				cout<<"GREATER\n";
				return 0;
			}
	}
}




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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
///////////////////////

int const N = 5e3 + 41;
int const INF = 1e9 + 41;

int d[N][N];
vector<int> e[N];
int n, x[N];

string YES = "POSSIBLE";
string NO = "IMPOSSIBLE";

void bad(){
	printf("%s\n",NO.c_str());
	exit(0);
}

void clear(int m){
	fr(i, 0, m) fr(j, 0, N) d[i][j] = INF;
}

int dfs(int u, int p){
	if(p == -1) e[u].pb(-1);
	if(sz(e[u]) == 1) return 0;
	fr(i, 0, sz(e[u])){
		if(e[u][i] == p) swap(e[u][i], e[u][0]);
	}

	int m = sz(e[u]);
	vector<pii> a;
	
	fr(i, 1, m){
		int to = e[u][i];
		int v1 = x[to];
		int v2 = dfs(to, u);
		a.pb(mp(v1, v2));
		fr(j, 0, N){
			if(j + v1 < N) d[i][j+v1] = min(d[i][j+v1], d[i-1][j] + v2);
			if(j + v2 < N) d[i][j+v2] = min(d[i][j+v2], d[i-1][j] + v1);
		}
	}

	clear(m);
	d[0][0] = 0;
	fr(i, 1, m){
		int v1 = a[i-1].first;
		int v2 = a[i-1].second;
		fr(j, 0, N){
			if(j + v1 < N) d[i][j+v1] = min(d[i][j+v1], d[i-1][j] + v2);
			if(j + v2 < N) d[i][j+v2] = min(d[i][j+v2], d[i-1][j] + v1);
		}
	}


//#ifdef _DEBUG
//	printf("u = %d\n", u);
//	fr(i, 0, 10){
//		int v = d[m-1][i];
//		if(v == INF) v = -1;
//		printf("i = %d d[i] = %d\n",i,v);
//	}
//#endif

	int ret = INF;
	fr(i, 0, x[u]+1){
		ret = min(ret, d[m-1][i]);
	}
	if(ret == INF) bad();
	return ret;
}

void solve(){
	scanf("%d",&n);
	fr(i, 2, n+1){
		int pi;
		scanf("%d",&pi);
		e[pi-1].pb(i-1);
		e[i-1].pb(pi-1);
	}
	fr(i, 0, n) scanf("%d",&x[i]);
	dfs(0, -1);
	
	printf("%s\n",YES.c_str());
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 20736
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a,b,c; cin >> a >> b >> c;
    
    cout << max(a,max(b,c))-min(a,min(b,c)) << ln;
    return 0;
}

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

using namespace std;

typedef vector<int> VI;
typedef long long LL;
#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 IN(v) cin>>v
#define OUT(v) cout<<v<<endl


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

  VI A;
  REP(i, N) {
    int a;
    cin >> a;
    A.PB(a);
  }

  int r = 0;
  LL sum = 0;
  LL count = 0;
  REP(l, N) {
    while (r < N && (sum + A[r]) == (sum ^ A[r])) {
      sum += A[r];
      ++r;
    }
    count += (r - l);
    sum -= A[l];
  }

  OUT(count);
  return 0;
}


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

bool solve(const int N, const vector<int>& values)
{
    const auto total_stones = accumulate(begin(values), end(values), 0LL);
    const auto stones_per_move = (long long)(N)*(N+1)/2;
    if (total_stones % stones_per_move != 0) return false;
    const auto moves_needed = total_stones / stones_per_move;

    auto moves_so_far = 0LL;
    for (auto i = 0; i < N; i++)
    {
        const auto x = moves_needed + values[i] - values[(i+1)%N];
        if (x % N != 0) return false;
        const auto moves_here = x / N;
        if (moves_here < 0) return false;
        moves_so_far += moves_here;
    }
    return moves_so_far == moves_needed;
}

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

    auto values = vector<int>(N);
    for (auto& x : values) cin >> x;

    cout << (solve(N, values) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 640
// 23;23
#include <algorithm>
#include <iostream>
#include <cstdio>
#define rint register int
#define N 200005
#define M 2003
using namespace std;
const int Mod = 1e9 + 7;
const int eps = 2001;

int n, a[N], b[N], f[M << 1][M << 1];
int fac[M << 2], inv[M << 2], ifac[M << 2];

inline void prework() {
    fac[0] = inv[1] = ifac[0] = 1;
    for (rint i = 1; i <= eps << 2; ++i)
        fac[i] = 1ll * fac[i - 1] * i % Mod;
    for (rint i = 2; i <= eps << 2; ++i)
        inv[i] = 1ll * inv[Mod % i] * (Mod - Mod / i) % Mod;
    for (rint i = 1; i <= eps << 2; ++i)
        ifac[i] = 1ll * ifac[i - 1] * inv[i] % Mod;
}

inline int C(int x, int y) {
    return 1ll * fac[x + y] * ifac[x] % Mod * ifac[y] % Mod;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    prework(); cin >> n;
    for (rint i = 1; i <= n; ++i)
        scanf("%d%d", a + i, b + i),
        ++f[eps - a[i]][eps - b[i]];
    for (rint i = 1; i <= eps << 1; ++i)
        for (rint j = 1; j <= eps << 1; ++j)
            (f[i][j] += (f[i - 1][j] + f[i][j - 1]) % Mod) %= Mod;
    long long ans = 0;
    for (rint i = 1; i <= n; ++i)
        (ans += f[eps + a[i]][eps + b[i]]) %= Mod;
    for (rint i = 1; i <= n; ++i)
        (ans -= C(a[i] << 1, b[i] << 1)) %= Mod;
    cout << 1ll * (ans % Mod + Mod) % Mod * ((Mod + 1) >> 1) % Mod;
    return 0;
}


Measured memory_bytes: 64640
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


x,y = map(int,input().split())

if (x+y)%3!=0:
    print(0)
    exit()


mod = 10**9+7
division = (x+y)//3

#combを求める前処理（階乗とその逆数）

g1 = [1, 1] #元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, division + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#################################

r = min(x,y)-division
ans = cmb(division,r,mod)

print(ans)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Sum of Interior Angles
            int n = int.Parse(Console.ReadLine());

            Console.WriteLine((n - 2) * 180);
        }
    }
}

Measured memory_bytes: 11092
n = gets.to_i
A = []
n.times do
  A << gets.to_i
end
A.sort!

succ = 1
num = 0

while !A.empty?
  a = A.shift
  while a == A.first
    succ += 1
    a = A.shift
  end
  if (succ % 2) == 1
    num += 1
  end
  succ = 1
end

p num


Measured memory_bytes: 4016
N=int(input())

dp=[[0 for i in range(3)]for j in range(N)]

for index in range(N):
  a,b,c=map(int,input().split())
  if index==0:
    dp[index][0]=a
    dp[index][1]=b
    dp[index][2]=c
  else:
    dp[index][0]=max(dp[index-1][1],dp[index-1][2])+a
    dp[index][1]=max(dp[index-1][0],dp[index-1][2])+b
    dp[index][2]=max(dp[index-1][1],dp[index-1][0])+c

print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

Measured memory_bytes: 24308
A = [[0 for i in range(3)] for i in range(3)]

A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))

N = int(input())

b = [0 for i in range(9)]

for i in range(N):
    b_in = int(input())

    for a in range(3):
        for aa in range(3):
            tmp = A[a][aa]
            
            if (b_in == tmp):
                index = 3 * a + aa
                b[index] += 1

b_judge = []
b_judge.append(sum(b[0:3]))
b_judge.append(sum(b[3:6]))
b_judge.append(sum(b[6:9]))
b_judge.append(b[0] + b[3] + b[6])
b_judge.append(b[1] + b[4] + b[7])
b_judge.append(b[2] + b[5] + b[8])
b_judge.append(b[0] + b[4] + b[8])
b_judge.append(b[2] + b[4] + b[6])

if (3 in b_judge):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////
#define R(i,n) for(int i=0;i<(n);i=i+1)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	/*
	LL test=1;
	for (int i = 0; i < 3; ++i) {
		test = (test * 3) % MOD;
	}
	cout << (test * 5*4) % MOD << endl;
	*/
	string S;
	cin >> S;
	int N = S.size();
	vector<vector<LL>>dp(N+1, vector<LL>(3, 0));
	dp[0][0] = 0;
	LL mul = 1;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'A') {
			dp[i + 1][0] = dp[i][0] + mul;
			dp[i + 1][1] = dp[i][1];
			dp[i + 1][2] = dp[i][2];
		}
		else if (S[i] == 'B') {
			dp[i + 1][0] = dp[i][0];
			dp[i + 1][1] = dp[i][1] + dp[i][0];
			dp[i + 1][2] = dp[i][2];
		}
		else if (S[i] == 'C') {
			dp[i + 1][0] = dp[i][0];
			dp[i + 1][1] = dp[i][1];
			dp[i + 1][2] = dp[i][2]+dp[i][1];
		}
		else if (S[i] == '?') {
			dp[i + 1][0] = dp[i][0] * 3 + mul;
			dp[i + 1][1] = dp[i][1] * 3 + dp[i][0];
			dp[i + 1][2] = dp[i][2] * 3 + dp[i][1];
			
			mul = (mul * 3);
		}
		for (int k = 0; k < 3; ++k) {
			dp[i + 1][k] %= MOD;
			mul %= MOD;
		}
	}
	cout << dp[N][2]%MOD << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 5840
#include<bits/stdc++.h>
using namespace std;
 
const int N=20;
const int S=1<<N;
const int mod=1000000007;
 
int n,sz,x,y,m,ans;
int dp[S],g[N],cnt[S],bin[S];
 
void init(){
	int i,j;
	for (i=0;i<=sz;i++)
		for (j=0;j<n;j++) if ((i>>j)&1) cnt[i]++;
}
 
int main(){
	int i,s,ss,u,w;
	bin[0]=1; for (i=1;i<S;i++) bin[i]=2ll*bin[i-1]%mod;
	scanf("%d%d",&n,&m); sz=(1<<n)-1;
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y); x--; y--;
		g[x]|=1<<y;
	}
	init();
	dp[0]=1;
	for (s=1;s<=sz;s++) if ((s&1)==((s>>1)&1)){
		for (ss=s;ss;ss=(ss-1)&s) if ((ss&1)==((ss>>1)&1)){
			u=ss^s; w=1;
			for (i=0;i<n;i++) if ((s>>i)&1){
				if ((u>>i)&1) w=1ll*w*(bin[cnt[g[i]&ss]]-1)%mod;
				else w=1ll*w*bin[cnt[g[i]&u]]%mod;
			}
			(dp[s]+=1ll*dp[u]*w%mod)%=mod;
		}
	}
	ans=(bin[m]-dp[sz]+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8448
import java.util.Scanner;

public class Main {
  private static void solve(int n, int[] a, int[] b, int[] c) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += b[a[i] - 1];
      if (i > 0 && a[i] == a[i - 1] + 1) sum += c[a[i - 1] - 1];
    }
    System.out.println(sum);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String[] as = sc.nextLine().split(" ");
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = Integer.parseInt(as[i]);
    String[] bs = sc.nextLine().split(" ");
    int[] b = new int[n];
    for (int i = 0; i < n; i++) b[i] = Integer.parseInt(bs[i]);
    String[] cs = sc.nextLine().split(" ");
    int[] c = new int[n - 1];
    for (int i = 0; i < n - 1; i++) c[i] = Integer.parseInt(cs[i]);
    sc.close();
    solve(n, a, b, c);
  }
}


Measured memory_bytes: 21588
#include <iostream>
#define F51 1
#define F52 2
#define F7 4
#define ALL 7

using namespace std;

int main(void)
{
	int a[3];
	int flag = 0;

	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
		if (flag & F51)
		{
			if (a[i] == 5) flag |= F52;
		}
		else
		{
			if (a[i] == 5) flag |= F51;
		}
		if (a[i] == 7) flag |= F7;
	}

	if (flag == ALL) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

int main()

{
	int a=1,i=0;
	
	int b=1;
	int s[1000];
	for(int a=1;a<=9;a++)
	{
		for(int b=1;b<=9;b++)
		{
			s[i]=a*b;
			i++;
		}
	}
	
	int z;
	cin>>z;
	int len=i+1;
	bool foo=false;
	
	for(int i=0;i<len;i++)
	{
		if(z==s[i])
		{
			foo=true;
			break;
		}
	}
	if(foo)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}




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

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  if (n > 1)
    sum += n * (n - 1) / 2;
  if (m > 1)
    sum += m * (m - 1) / 2;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
#include <cstdio>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;

ll pp(ll n)
{
    return (n-1)*n/2;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n,m;
    while(cin>>n>>m)
    {
        ll ans;
        ans=pp(n)+pp(m);
        cout<<ans<<'\n';
    }
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n,m;
    in(n,m);
    vector<vector<int>> graph(n+1);
    int a,b;
    rep(i,m){
        in(a,b);
        //debug(a,b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> ans(n+1,-1);
    queue<int> queue1;
    queue1.push(1);
    int c,d;
    while(!(queue1.empty())){
        c=queue1.front();
        //debug(c);
        for(int i=0;i<graph[c].size();i++){
            d=graph[c][i];
            if(ans[d]==-1){
                ans[d]=c;
                queue1.push(d);
            }
        }
        queue1.pop();
    }
    //debug(ans);
    yn(count(all(ans),-1)==1);
    if(count(all(ans),-1)==1){
        for(int i=2;i<n+1;i++){
            out(ans[i]);
        }
    }
}

Measured memory_bytes: 10096
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

int inputValue();
void inputArray(int *, int);
void inputVector(vector<int> *, int);
template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3, y3, x4, y4;

    x3 = x2 + y1 - y2;
    y3 = y2 - x1 + x2;

    x4 = x1 + y1 - y2;
    y4 = y1 - x1 + x2;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

int inputValue() {
    int a;
    cin >> a;
    return a;
}

void inputArray(int *p, int a) {
    rep(i, a) { cin >> p[i]; }
}

void inputVector(vector<int> *p, int a) {
    rep(i, a) {
        int input;
        cin >> input;
        p->push_back(input);
    }
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

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


Measured memory_bytes: 256
#include <stdio.h>
int min(int a, int b){
    return a > b ? b : a;
}
long long int minll(long long int a, long long int b){
    return a > b ? b : a;
}
int a[2000];
int tree[400000], n;
int inf;
void segment_tree(){
    inf = 2000000000;
    long long int i;
    long long int tmp = 1;
    long long int n_ = n;
    while(tmp <= n){
        tmp *= 2;
    }
    n = tmp;
    //fill_data
    for(i = 0; i < n; i++){
        tree[i + n - 1] = inf;
    }
    //initialize
    for(i = 0; i < n_; i++){
        tree[i + n - 1] = a[i];
    }
    for(i = n - 2; i >= 0; i--){
        tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]);
    }
}
int rmq(int a, int b, int k, int l, int r){//[x, y)(0オリジン)の配列内の最小値を求める
    if(l >= r){
        r = n;
    }
    if(r <= a || b <= l){
        return inf;
    }
    if(a <= l && r <= b){
        return tree[k];
    }
    int vl = rmq(a, b, 2*k + 1, l, (l + r)/2);
    int vr = rmq(a, b, 2*k + 2, (l + r)/2, r);
    return min(vl, vr);
}
int main(void){
    long long int x;
    scanf("%d%d", &n, &x);
    int n_init = n;
    long long int i, j, k;
    long long int ans;
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    segment_tree();
    //魔法をかける回数(0からn―1回)で全探索
    long long int Ans = 100000000000001;
    for(i = 0; i < n; i++){
        //1,魔法をかけるためのコストを計算
        ans = i*x;

        //2,それぞれのスライムjを召喚する最小のコストを計算し，足す
        for(j = 0; j < n_init; j++){
            long long int tmp = 2000000000;

            //a[j - i, j]の最小値を求める
            // for(k = 0; k <= i; k++){//k：返信させる回数
            //     int ind = j - k;
            //     if(ind < 0){
            //         ind += n;
            //     }
            //     tmp = min(tmp, a[ind]);
            // }
            //上記を高速化
            long long int tmp1 = inf;
            long long int tmp2 = inf;
            if(j - i < 0){
                tmp1 = rmq(0, j+1, 0, 0, 0);
                tmp2 = rmq(j - i + n_init, n_init, 0, 0, 0);
                tmp = min(tmp1, tmp2);
            }else{
                tmp = rmq(j - i, j + 1, 0, 0, 0);
            }
            ans += tmp;
        }
        Ans = minll(ans, Ans);
    }
    printf("%lld\n", Ans);
}

Measured memory_bytes: 1744
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val c = Array.fill(Scanner.nextInt)(1)

	loop(0, Scanner.nextInt) { _ => Seq.fill(Scanner.nextInt)(Scanner.nextInt-1) foreach { i => c(i) = 0 } }

	pw.println(c.sum)
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


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

int bsort(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++;
      }
    }
  }
  return sw;
}
int main(){
  int A[100],N,sw;
  cin>>N;
  for(int i=0;i<N;i++) cin>>A[i];
  sw=bsort(A,N);
  for(int i=0;i<N;i++){
    if(i) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  cout<<sw<<endl;
  return 0;
}

Measured memory_bytes: 3064
//  __      __       .__           .____________                   __________        __ ________   __                 
// /  \    /  \ ____ |_________  __| _\______   \__ __  ____  _____\______   \__ ___/  |\_____  \ |  | ______  ___.__.
// \   \/\/   _/ __ \|  \_  __ \/ __ | |    |  _|  |  \/ ___\/  ___/|    |  _|  |  \   __/   |   \|  |/ \__  \<   |  |
//  \        /\  ___/|  ||  | \/ /_/ | |    |   |  |  / /_/  \___ \ |    |   |  |  /|  |/    |    |    < / __ \\___  |
//   \__/\  /  \___  |__||__|  \____ | |______  |____/\___  /____  >|______  |____/ |__|\_______  |__|_ (____  / ____|
//        \/       \/               \/        \/     /_____/     \/        \/                   \/     \/    \/\/     

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\n'

using namespace std;

ll pow3(ll a, ll b, ll m)
{
	ll res = 1;
	while(b > 0)
	{
		if(b & 1)
			res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}

void solve()
{
    ll n, k;
    cin >> n >> k;
    ll ans[k + 1];
    ans[k] = 1;
    ll inf = 1e9 + 7;
    for(ll i = k - 1; i > 0; i--)
    {
        ans[i] = pow3(k / i, n, inf);
        for(ll j = 2 * i; j <= k; j += i)
            ans[i] = (ans[i] + inf - ans[j]) % inf;
    }
    ll out = 0;
    for(ll i = 1; i <= k; i++)
        out = (out + i * ans[i]) % inf;
    cout << out << endl;
}

int main()
{
	int q = 1;
	//scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 4336
N = int(input())
P = list(map(float, input().split()))
dp = [[0]*(N+1) for i in range(N+1)]
dp[0][0] = 1
# dp[X][I] := X回目の操作を終えてi回面が出る確率
for i in range(1, N+1):
    p = P[i-1]
    for j in range(i+1):
        if j >= 1:
            dp[i][j] = dp[i-1][j]*(1-p) + dp[i-1][j-1]*p
        else:
            dp[i][j] = dp[i-1][j]*(1-p)
ans = 0
for i in range(N//2+1, N+1):
    ans += dp[N][i]
print(ans)

Measured memory_bytes: 222632
#include<iostream>
#include<string.h>
using namespace std;

const int INF = 100000000;
int adj[100][100];
int radj[100][100];

int main() {
  int n,m,s,g1,g2,b1,b2,c;

  while(cin>>n>>m>>s>>g1>>g2, n|m|s|g1|g2) {
    memset(adj, INF, sizeof(adj));
    memset(radj, INF, sizeof(radj));
    s--,g1--,g2--;

    for(int i=0; i<100; ++i)
      for(int j=0; j<100; ++j) {
	adj[i][j] = INF;
	radj[i][j] = INF;
      }

    for(int i=0; i<100; ++i)
      adj[i][i] = 0;

    for(int i=0; i<m; ++i) {
      cin>>b1>>b2>>c;
      b1--,b2--;
      adj[b1][b2] = c;
      radj[b2][b1] = c;
    }


    for(int k=0; k<n; ++k) {
      for(int i=0; i<n; ++i) {
	for(int j=0; j<n; ++j) {
	  adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
	  radj[i][j] = min(radj[i][j], radj[i][k]+radj[k][j]);
	}
      }
    }

    int minc = INF;
    for(int i=0; i<n; ++i) {
      minc = min(minc, (adj[s][i]+adj[i][g1]+adj[i][g2]));
    }

    cout<<minc<<endl;
  }
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000 
const long long  MOD =1e9+7;
#define MAXR 100000 
int main(){
    string S;
    cin >> S;
    int Ans = -1;
    for(int i=0;i<S.size();i++){
        if(i%2==0){
            if(S[i]=='L')Ans=1;
        }else{
            if(S[i]=='R')Ans=1;
        }
    }
    if(Ans==-1)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc  = new Scanner(System.in);
int x = sc.nextInt();
int result =0;
int div=0;

   div = x/500;
    result = div*2*500;



x = x-(div*500);


result+= x;

if(x%5!=0){
result=result- (x%5);


}
System.out.println(result);
}

}

Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    if(a==b)
        cout<<c<<endl;
    else if(a==c)
        cout<<b<<endl;
    else if(b==c)
        cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int x;
    cin >> x;
    for(int i=x/100;i*100 <= x;i++){
        int y = x - i * 100;
        if(y <= i * 5){
            puts("1");
            return 0;
        }
    }
    puts("0");
    return 0;
}


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

vector<int> v[200000], a, ret, tmp;
int n;

void dfs(int par, int pos){
    int len = lower_bound(tmp.begin(), tmp.end(), a[pos])-tmp.begin();
    int bef = tmp[len];
    tmp[len] = a[pos];
    ret[pos] = lower_bound(tmp.begin(), tmp.end(), 1<<30)-tmp.begin();
    for(int next : v[pos]){
        if(next == par) continue;
        dfs(pos, next);
    }
    tmp[len] = bef;
}

int main(){
    cin >> n;
    a.resize(n);
    ret.resize(n);
    tmp.resize(n+1, 1<<30);
    for(int i = 0; i < n; i++)  cin >> a[i];
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        x--, y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(-1, 0);
    for(int i = 0; i < n; i++){
        cout << ret[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 27956
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    int N; cin >> N;
    bool f[101];
    for(int i =0; i < 101; i++){
        f[i] =  false;
    }
    int d;
    for(int i =0; i < N; i++){
        cin >> d;
        f[d] =  true;
    }
    int c = 0;
    for(int i =0; i < 101; i++){
        if(f[i]) c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
h,w,m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
x = [0]*h
y = [0]*w
used = set()
for hh,ww in hw:
    hh -= 1
    ww -= 1
    x[hh] += 1
    y[ww] += 1
    used.add((hh,ww))

x_max = max(x)
y_max = max(y)
x_pos = [i for i in range(h) if x[i] == x_max]
y_pos = [i for i in range(w) if y[i] == y_max]

ans = x_max+y_max-1
end = False
for x in x_pos:
    for y in y_pos:
        if (x,y) in used:
            continue
        else:
            ans += 1
            end = True
            break
    if end:
        break
print(ans)



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

int main(){
  int n;
  cin >> n;
  //vecotr<int> p(n);
  int min;
  cin >> min;
  int ans = 1;
  rep(i, n-1){
    int pp;
    cin >> pp;

    if(pp <= min){
      min = pp;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = br.readLine().split(" ");
    int[] nums = new int[3];
    
    for (int i = 0; i < strs.length; i++) {
      nums[i] = Integer.parseInt(strs[i]);
    }
    Arrays.sort(nums);
    System.out.println((nums[2] - nums[1]) + (nums[1] - nums[0]));
    
  }
}

Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;
int rl[100100];
int main(){
	cin>>s;
	int near_r=0;
	REP(i,s.size()){
		if(s[i]=='R'){
			near_r=i;
		}else{
			rl[i]=near_r;
		}
	}
	int near_l=s.size()-1;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='L'){
			near_l=i;
		}else{
			rl[i]=near_l;
		}
	}
	int ans[s.size()]={};
	REP(i,s.size()){
		if(s[i]=='R'){
			if((rl[i]-i)%2==1){
				ans[rl[i]-1]++;
			}else{
				ans[rl[i]]++;
			}
		}else{
			if((i-rl[i])%2==1){
				ans[rl[i]+1]++;
			}else{
				ans[rl[i]]++;
			}
		}
	}
	REP(i,s.size()){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int x;
    cin>>x;
    int y[x];
    for(int i=0;i<x;i++)
    
    {
        cin>>y[i];
    }
    int s=1,p=0;
    for(int i=0;i<x;i++)
    {
        for(int j=0;j<x;j++)
        {
            if(i!=j)
            {
                s=y[i]*y[j];
                p+=s;
                
            }
        }
    }
    cout<<p/2;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int count=0;
void Merge(int*,int,int,int);
void MergeSort(int*,int,int);
int main(){
  int n,i;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  MergeSort(A,0,n);
  
    
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}

void Merge(int *a,int l,int m,int r){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=m - l;
  n2=r - m;
  L=(int *)malloc((n1+1) * sizeof(int));
  R=(int *)malloc((n2+1) * sizeof(int));
  for(i=0;i<n1;i++){
    L[i]=a[l+i];
  }
 
  for(i=0;i<n2;i++){
    R[i]=a[m+i];
   
  }
 
  L[n1]=INFINITY;
  R[n2]=INFINITY;
  i=0;
  j=0;
  for(k=l;k<r;k++){
    if(L[i]<R[j]){
      a[k] = L[i];
      i=i+1;
    }
    else{
      a[k] = R[j];
      j=j+1;
    }
    count++; }
  free(R);
  free(L);
  
}


void MergeSort(int*a,int l,int r){
  int m;
  if(l+1<r){
    m = (l+r)/2;
   
    MergeSort(a,l,m);
    MergeSort(a,m,r);
    Merge(a,l,m,r);
  }
}



Measured memory_bytes: 5420
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int [] ans=new int [n];
		for(int i=0;i<n;i++)
		{
			int t=in.nextInt()-1;
			ans[t]=i;
		}
		for(int i=0;i<n;i++)
		{
			System.out.print(ans[i]+1+" ");
		}
	}
}
	

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

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int cnt1 = 0;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == s[i]) {
            s[i] = (char)(((s[i] - '0') ^ 1) + '0');
            cnt1++;
        }
    }
    int cnt2 = 0;
    s[0] = (char)(((s[0] - '0') ^ 1) + '0');
    cnt2++;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == s[i]) {
            s[i] = (char)(((s[i] - '0') ^ 1) + '0');
            cnt2++;
        }
    }

    cout << min(cnt1, cnt2) << endl;
}

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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

int main(int argc, char *argv[])
{
    ll A, B, N;
    cin >> A >> B >> N;

    ll x;
    x = ((N < B) ? N : B-1);


    ll ans;
    ll fla, flb;
    fla = ((A * x)/B);
    flb = x/B;

    ans = fla - A * flb;

    cout << ans << endl;;

    return 0;
}


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

int main(){
	int N,L,R,ans = 2020;
	cin >> L >> R;
	N = R-L;
	for(int i=L; i < L+min(2019,N); i++){
		for(int j=i+1; j <= min(R,i+2019); j++){
			ans = min(((i%2019)*(j%2019)) % 2019,ans);
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
int n,q,c,d;

ll dp[555][101];
ll reg(int s,int m){
	if(dp[s][m]!=-1)return dp[s][m];
	if(m==n)return 1;
	ll res=0;
	int k=100,l=s;
	int b[3];
	for(int i=0;i<3;++i){
		b[i]=l/k;
		l%=k;
		k/=10;
	}
	l=s;
	l*=10;
	l%=1000;
	l+=3;
	res+=reg(l,m+1);
	res%=r197;
	l=s;
	l*=10;
	l%=1000;
	l+=0;
	res+=reg(l,m+1);
	res%=r197;

	if(!(b[0]==0&&b[1]==2)&&!(b[1]==0&&b[2]==2)&&!(b[1]==2&&b[2]==0)&&!(b[0]==0&&b[2]==2)){
		l=s;
		l*=10;
		l%=1000;
		l+=1;
		res+=reg(l,m+1);
		res%=r197;
	}
	if(!(b[1]==0&&b[2]==1)){
		l=s;
		l*=10;
		l%=1000;
		l+=2;
		res+=reg(l,m+1);
		res%=r197;
	}
//	cout<<s<<" "<<m<<" "<<res<<endl;
	return dp[s][m]=res;
}
int main() {
	memset(dp,-1,sizeof(dp));
	cin>>n;
	cout<<reg(444,0)<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ratio>
const long long INF = LLONG_MAX / 2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int

template <typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0, sum = 0, n, k, t;
string s;

ll counter = 0;
ll a, b, p, q;
ll rt;
bool flg;

int main()
{
	cin >> n;
	cin >> a >> b;
	REP(i,n-1)
	{
		cin >> p >> q;
		if(p>a&&q>b)
		{
			a = p;
			b = q;
		}
		else if(p<a&&q<b)
		{
			if(a/p>b/q)
			{
				rt = a / p;
				rt += a%p ? 1 : 0;
			}
			else {
				rt = b / q;
				rt += b%q ? 1 : 0;
			}
			a = rt*p;
			b = q*rt;
		}
		else if(p<a)
		{
			rt = a / p;
			rt += a%p ? 1 : 0;
			a = rt*p;
			b = q*rt;
		}
		else if (q<b)
		{
			rt = b / q;
			rt += b%q ? 1 : 0;
			b = rt*q;
			a = p*rt;
		}
		else if(p>a)
		{
			a = p;
			if(q>b)
			{
				b = q;
			}
		}
		else if(q>b)
		{
			b= q;
		}
	}
	cout << a+b << endl;
}

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

i = 1
ans = 0
while True:
    if i * i > M + 1:
        break
    j = M // i
    if M % i == 0 and M // i >= N:
        ans = max(ans, i)
    if M % j == 0 and M // j >= N:
        ans = max(ans, j)
    i += 1
    

print(ans)


Measured memory_bytes: 2940
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
#include <numeric>
#include <ext/pb_ds/assoc_container.hpp>
#define MOD 1000000007
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	long long int n;
	cin>>n;
	vector<pair<long long int, long long int>> p(n);
	vector<long long int> s(n),d(n);
	for(int i=0;i<p.size();++i){
		cin>>p[i].first>>p[i].second;
		s[i]=p[i].first+p[i].second;
		d[i]=p[i].first-p[i].second;
	}
	sort(s.begin(),s.end());
	sort(d.begin(),d.end());
	cout<<max(s[n-1]-s[0],d[n-1]-d[0])<<endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(3 * N);
  for (auto&& e : A) {
    cin >> e;
  }
  vector<int64_t> res(3 * N, -(INT64_C(1) << 58));
  {
    priority_queue<int, vector<int>, greater<int>> que;
    int64_t l = 0;
    for (int i = 0; i < N; i++) {
      que.push(A[i]);
      l += A[i];
    }
    res[N - 1] = l;
    for (int i = N; i < 2 * N; i++) {
      que.push(A[i]);
      l += A[i] - que.top();
      que.pop();
      res[i] = l;
    }
  }
  {
    priority_queue<int> que;
    int64_t r = 0;
    for (int i = 3 * N - 1; i > 2 * N - 1; i--) {
      que.push(A[i]);
      r += A[i];
    }
    res[2 * N - 1] -= r;
    for (int i = 2 * N - 1; i > N - 1; i--) {
      que.push(A[i]);
      r += A[i] - que.top();
      que.pop();
      res[i - 1] -= r;
    }
  }
  cout << *max_element(res.begin(), res.end()) << '\n';
  return 0;
}


Measured memory_bytes: 7516
import math

N,K = list(map(int,input().split()))
odd = 0

if N >= K:
  odd += (N-K+1)/N
  for i in range(K-1):
    if (math.log2(K/(i+1)))%1==0:
      odd += (i+1)/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/(i+1)))+1))
else:
  for i in range(N):
    if (math.log2(K/(i+1)))%1==0:
      odd += (i+1)/(K*N)
    else:
      odd += (1/N)*(0.5**(int(math.log2(K/(i+1)))+1))
      
print(odd)
    

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

int main() {
	
	int n;
	cin >> n;
	vector<int> w(n);
	rep(i, n) cin >> w[i];
	
	int s1 = 0, s2 = 0, min = 100100;
	
	for(int i=0; i<n-1; i++){
		s1 += w[i];
		for(int j=i+1; j<n; j++){
			s2 += w[j];
		}
		int diff = abs(s2 - s1);
		if(diff < min) min = diff;
		s2 = 0;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        1000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}   

signed main()
{
    showoff;
    int n,k,dp[maxn],ans = 0;
    cin >> n >> k;
    RFOR(i,k,0){
        dp[i] = power(k/i,n);
        FOR(j,2,k+1){
            if(k < (i*j))break;
            dp[i] = dp[i]+mod-dp[i*j];
            dp[i] %= mod;
        }
    }
    FOR(i,1,k+1)ans += dp[i]*i,ans %= mod;
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

string s;
int ans;

main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

//	srand(time(NULL));

	cin >> s;
	
	for(int i = 0, j = s.size() - 1; i <= j; i++, j--)
		ans += (s[i] != s[j]);
		
	cout << ans;		
	                            
    return 0;                                        
}

Measured memory_bytes: 256