akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		int nSum = n * (n - 1) / 2;
		int mSum = m * (m - 1) / 2;

		int sum = nSum + mSum;

		System.out.println(sum);

		scanner.close();

	}

}


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

int main(){

  int A,B,tmp;

cin >> A >> B;

if(A+B>A-B){
  tmp = A+B;
}else{
  tmp = A-B;
}

if(tmp>A*B){
    cout<< tmp<<endl;
}else{
    tmp=A*B;
    cout<< tmp <<endl;
}


}


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

int main(){
  string s; cin >> s;
  vector<string> t = {"Sunny", "Cloudy", "Rainy"};
  for (int i = 0; i < 3; i++) {
    if (t.at(i) == s)
    {
      cout << t.at((i+1)%3) << endl;
      break;
    }
  }
}

Measured memory_bytes: 3552
#include<iostream>
#include<map>
#include<algorithm>
using namespace::std;
#define int long long int

int n,ar[200005],val[200005],bit[200005],srt[200005];
map<int,int> m;

int query(int x){
	int maxn=0;
	for(;x;x-=x&(-x))
		maxn=max(maxn,bit[x]);
	return maxn;
}

void upd(int x,int t){
	for(;x<=n;x+=x&(-x))
		bit[x]=max(bit[x],t);
}

main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>ar[i],srt[i]=ar[i];
	for(int i=1;i<=n;i++)
		cin>>val[i];
	sort(srt+1,srt+n+1);
	for(int i=1;i<=n;i++)
		m[srt[i]]=i;
	for(int i=1;i<=n;i++)
		upd(m[ar[i]],val[i]+query(m[ar[i]]));
	cout<<query(n)<<'\n';
}


Measured memory_bytes: 19072
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		boolean f = false;

		for (int i = 1; i <= B; i++) {
			if (A * i % B == C) {
				f = true;
				break;
			}
		}

		if (f == true) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


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

using namespace std;

int main() {
  int n;
  int m = 1000000007;
  cin >> n;
  vector<int> values(n);
  for (int i = 0; i < n; i++) {
    cin >> values[i];
  }

  long long ans = 0;
  long long sum = 0;
  for (int i = n - 2; i >= 0; i--) {
    sum += values[i + 1];
    sum %= m;
    ans += values[i] * sum;
    ans %= m;
  }

  cout << (ans % m) << endl;
}


Measured memory_bytes: 4032
#include<stdio.h>
#define N 100000
#define M 50000


int main(void){
  int i, n, q, S[N], T[M], left, mid, right, key, count;
  scanf("%d", &n);
  for(i=0; i<n ;i++) scanf("%d", &S[i]);
  scanf("%d", &q);
  for(i=0; i<q ;i++)  scanf("%d", &T[i]);

  
  for(i=0; i<q; i++){
    left = 0;
    right = n;
    key = T[i];
    while(left < right){
      mid = (left+right)/2;
      if(S[mid] == key) {
	count++;
	break;
      }
      else if(key < S[mid]) right = mid;
   else if (key > S[mid])left = mid+1;
      
    }
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
 
bool prime[1000001];
 
void sieve(int n) {
    memset(prime, true, sizeof(prime));
    for(int p=2;(ll)p*p<=n;p++) {
        if(prime[p]) {
            for(int i=p*p;i<=n;i+=p) {
                prime[i] = false;
            }
        }
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int x;
    cin >> x;
    sieve(1000001);
    for(int i=x;i<=1000001;i++) {
        if(prime[i]) {
            cout << i << '\n';
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define TEST(A) cout <<A<<endl;
unordered_multiset<long long int>fact(long long int n){
	unordered_multiset<long long int>ret;
	long long int a=2;
	while (a*a<=n){
		while (n%a==0){
			n/=a;
			ret.insert(a);
		}
		a++;
	}
	return ret;
}
int main(){
long long int n,p;
cin >>n>>p;
if (n==1){
	cout <<p;
	return 0;
}
if (n>=40){
	cout <<"1"<<endl;
	return 0;
}
long long int ans=1;
auto l=fact(p);
long long int cnt=0;
for (long long int i=1;p>=pow(i-1,n);++i)
	cnt=i;
rep(i,cnt){
	long long int tmp=l.count(i);
	if(tmp>=n)
		ans*=pow(i,tmp/n);
}
cout <<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
xy = [[int(i) for i in input().split()] for j in range(n)]

mi = 10**10
ma = 0

for i in range(n):
    tmp = xy[i][0] + xy[i][1]
    if tmp > ma:
        ma = tmp
    #print(tmp,mi)
    if tmp < mi:
        mi = tmp
        
ans = ma-mi

mi = 10**10
ma = -10**10

for i in range(n):
    tmp = xy[i][0] - xy[i][1]
    if tmp > ma:
        ma = tmp
    #print(tmp,mi)
    if tmp < mi:
        mi = tmp
        
print(max(ans,ma-mi))

Measured memory_bytes: 106424
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>


using namespace std;
using ll=long long;
using vll=vector<ll>;


int min_u(ll&m, ll v)
{
	if(m>v)
	{
		m=v;
		return 1;
	}
	return 0;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vll a(n+1);
		vll t(n+1);
		vll w(4), tw(4);

		for(int i=1;i<=n;i++)
		{
			scanf("%lld", &a[i]);
			t[i]=t[i-1]+a[i];
		}
		ll ans=t[n];

		int l=1, r=3;
		for(int c=2;c+1<n;c++)
		{
			if(r<c+1) r=c+1;
			for(;l<c;l++)
			{
				if(t[c]-t[l]<=t[l]-t[0]) break;
			}
			w[0]=t[l]-t[0];
			w[1]=t[c]-t[l];
			if(l>1)
			{
				tw[0]=t[l-1]-t[0];
				tw[1]=t[c]-t[l-1];
				if(llabs(w[1]-w[0])>llabs(tw[1]-tw[0]))
				{
					w[0]=tw[0];
					w[1]=tw[1];
				}
			}

			for(;r<n;r++)
			{
				if(t[n]-t[r]<=t[r]-t[c]) break;
			}
			w[2]=t[r]-t[c];
			w[3]=t[n]-t[r];
			if(r-1>c)
			{
				tw[2]=t[r-1]-t[c];
				tw[3]=t[n]-t[r-1];
				if(llabs(w[3]-w[2])>llabs(tw[3]-tw[2]))
				{
					w[2]=tw[2];
					w[3]=tw[3];
				}
			}
			sort(w.begin(), w.end());
			min_u(ans, w[3]-w[0]);
		}

		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 3328
times = (1..5).map { gets.to_i }
mod_times = times.map { |time| time % 10 }
losslessnum = mod_times.sort.uniq.delete_if{ |i| i == 0 }[0]
losslessindex = mod_times.index(losslessnum)

times.each.with_index do |time, i|
  next if i == losslessindex
  times[i] = 10 * (times[i]/10.0).ceil
end

puts times.inject(:+)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int dp[(int)1e5+5];
bool recur(vector<int> &inp,int k){
    if(k<0)return true;
    if(dp[k]!=-1)return dp[k];
    for(int i=0;i<inp.size();i++){
        if (recur(inp,k-inp[i])==false)
        {
            return dp[k]=true;
        }
    }
    return dp[k]=false;
}
void solve(){
    int n,k;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    vector<int> inp(n);
    vector<int> used(n,0);
    for (int i = 0; i < n; i++)
    {
        cin>>inp[i];
    }

    if(recur(inp,k))cout<<"First";
    else cout<<"Second";
    // cout<<dp[5];
}

int main() {
    int t=1;
    for (int i = 0; i < t; i++)
    {
        // cout<<"Case #"<<(i+1)<<": ";
        // cout<<'\n';
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 7120
import sys
readline = sys.stdin.readline
read = sys.stdin.read

N, M = map(int, readline().split())

if M == 0:
    print('Yes')
    exit()

LRD = map(int, read().split())
graph = [[] for _ in range(N + 1)]

# 根からの距離、根は複数の可能性あり
distance = [-1] * (N + 1)
child = [0] * (N + 1)

for L, R, D in zip(LRD, LRD, LRD):
    graph[L].append((R, D))
    child[R] = 1

for i in range(1, N + 1):
    if child[i]:
        continue

    # 以下iは根
    distance[i] = 0
    stack = [i]
    while stack:
        V = stack.pop()
        for v, d in graph[V]:
            if distance[v] == -1:
                distance[v] = distance[V] + d
                stack.append(v)
            else:
                if distance[v] != distance[V] + d:
                    print('No')
                    exit()

# 例4のような循環タイプは上のfor内で処理されない
if -1 in set(distance[1:]):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 73016
#include<stdio.h>
 
int main(void){
int h,i,m;
int mountain[10];
scanf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",&mountain[0],&mountain[1],&mountain[2],&mountain[3],&mountain[4],&mountain[5],&mountain[6],&mountain[7],&mountain[8],&mountain[9]);
for (h=9;h>6;h--){
for(i=0;i<h;i++){
if(mountain[i]>mountain[i+1]) m=mountain[i],mountain[i]=mountain[i+1],mountain[i+1]=m;
}
}
printf("%d\n%d\n%d\n",mountain[9],mountain[8],mountain[7]);
    return 0;
}

Measured memory_bytes: 604
N, L = gets.split.map(&:to_i)

orig = N*L + (N**2 - N)/2

min_diff = if L > 0 then
        L
    elsif L + N > 0 then
        0
    else
        L + N - 1
    end

STDERR.puts "orig: #{orig}, min_diff: #{min_diff}"

p orig - min_diff


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
class Solution {
  typedef long long LL;
  LL myPow(LL a, int x) {
    LL ret = 1;
    while (x--) ret *= a;
    return ret;
  }
  vector<pair<LL, int>> factor(LL a) {
    vector<pair<LL, int>> ret;
    for (LL p = 2; p * p <= a; ++p) {
      if (a % p == 0) {
        ret.emplace_back(p, 0);
        while (a % p == 0) {
          a /= p;
          ++ret.back().second;
        }
      }
    }
    if (a != 1) ret.emplace_back(a, 1);
    sort(ret.begin(), ret.end());
    return ret;
  }
public:
  void run(istream &in, ostream &out) {
    LL n, p;
    in >> n >> p;
    LL ans = 1;
    for (auto P : factor(p)) {
      ans *= myPow(P.first, P.second / n);
    }
    out << ans << '\n';
  }
  
  
};
int main() {
  ios_base::sync_with_stdio(false);
  Solution().run(cin, cout);
  return 0;
}


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

int main(){
    vector<int> x(3);
    for(int i=0;i<=2;i++){
        cin >> x[i];
    }
    sort(x.begin(),x.end());
    if((x[1]-x[0])%2 == 0){
        cout << x[2]-x[1]+ceil((x[1]-x[0])/2) <<endl;
    }
    else{
        cout << x[2]-x[1]+(x[1]+1-x[0])/2+1 <<endl;
    } 
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0

    for i in range(N):
        tmp = A[i] - B[i]
        if tmp < 0:
            ans += A[i]
            if A[i + 1] < -tmp:
                ans += A[i + 1]
                A[i + 1] = 0
            else:
                ans += -tmp
                A[i + 1] += tmp
        else:
            ans += B[i]

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 24276
a_len = int(input())
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(input())
b_ar = [int(n) for n in input().split(" ")]
max_b = max(b_ar)
dp = [0 for n in range(max_b + 1)]
for a in a_ar:
    new_dp = dp[:]
    new_dp[a] = 1
    for i,d in enumerate(dp):
        if d and i + a <= max_b:
            new_dp[i + a] = 1
    dp = new_dp
for b in b_ar:
    if dp[b]:
        print("yes")
    else:
        print("no")

Measured memory_bytes: 7788
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()

int N;
string S;
int dp[200000][2];
int solve(int now, int bef){//0=black,1=white
	if(now == N) return 0;
	if(dp[now][bef] != -1) return dp[now][bef];
	if(bef==0 && S[now] == '.'){
		return dp[now][bef] = solve(now+1, 0) + 1;
	}
	else if(bef==0){
		return dp[now][bef] = solve(now+1, 0);
	}
	else{
		if(S[now] == '.'){
			dp[now][bef] = min(solve(now+1, 0) + 1, solve(now+1, 1));
		}
		else{
			dp[now][bef] = min(solve(now+1, 0), solve(now+1, 1) + 1);
		}
		return dp[now][bef];
	}
}
int main(){
	cin >> N >> S;
	for(int i=0; i<N; i++){
		dp[i][0] = -1;
		dp[i][1] = -1;
	}
	cout << solve(0,1) << endl;

}

Measured memory_bytes: 11524
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), dp(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for(int i = 2; i < n; i++) {
        dp[i] = min(dp[i-2] + abs(v[i] - v[i-2]), dp[i-1] + abs(v[i] - v[i-1]));
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n){
        ll x, y;
        cin>>x>>y;
        a[i]=x-y;
        b[i]=x+y;
    }
    sort(ALL(a));
    sort(ALL(b));
    cout<<max(a[n-1]-a[0],b[n-1]-b[0])<<"\n";
}

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

int main()
{
    char s[3];
    int masu = 0;

    cin >> s;
    
    for (int i = 0; i < 3; i++){
        if (s[i] == '1'){
            masu++;
        }
    }

    cout << masu << endl;

    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	vi T(3);
	rep(i, 3)
		cin >> T[i];
	sort(T.begin(), T.end(), less<int>());
	int ans = T[0] + T[1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = scanner.nextInt();
        while(n != 0) {
            double ave = 0;
            for (int i = 0; i < n; i++) {
                a[i] = scanner.nextInt();
                ave += a[i];
            }
            ave /= n;
            double S = 0;
            for (int i = 0; i < n; i++)
                S += (a[i] - ave) * (a[i] - ave);
            System.out.println(Math.sqrt(S / n));
            n = scanner.nextInt();
        }
    }
}



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

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

  int A, B, C, D;

  A = N / 1000;
  B = N % 1000 /100;
  C = N % 1000 % 100 / 10;
  D = N % 1000 % 100 % 10;

  if (A == B && B == C) {
    cout << "Yes" << endl;
  } else if (B == C && C == D) {
    cout << "Yes" << endl;
  } else {
    cout <<"No" << endl;
  }

} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, k;
	string s;

	cin >> n >> k >> s;
	s[k - 1] += 'a' - 'A';
	cout << s << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int n = sc.nextInt();
		
		int ans = 0;
		for(int i = 1; i <= n; i+=2) {
			int sum = 0;
			for(int j = 1; j <= i; j++) {
				if(i % j == 0) sum++;
			}
			if(sum == 8) ans++;
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int x,y;
    cin>>x>>y;
   bool chk = false;
  for (int i = 0; i <= x; i++) {
    if ( i * 2 + (x-i)*4 == y)
        chk = true;
  }
    if(chk)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}



Measured memory_bytes: 3592
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <string>
#include <iostream>

using namespace std;

int main(){
        int i,N;
        char l;
        string tmp;
        set<string> w;
        bool ans = true;

        cin >> N;
        for ( i = 0; i < N; i++ ) {
               cin >> tmp;
               if (ans){
                 w.insert(tmp);
                 if ( i != 0 && l != tmp.front() ) ans = false;
                 if ( i + 1 != w.size() ) ans = false;
                 l = tmp.back();
               }
        }
        if (ans) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    def gcd(a,b):
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    #[p,q)のgcd
    def query(p,q):
        if p>n-1 or q<1:
            return 0
        if abs(q-p)<=1:
            return a[p]
        p += num-1
        q += num-2
        res=0
        while q>p:
            if p&1 == 0:
                res = gcd(res,seg[p])
            if q&1 == 1:
                res = gcd(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        res = gcd(res,seg[p])
        return res

    n = int(input())
    a = tuple(map(int,input().split()))
    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[0]*2*num

    for i in range(n):
        seg[i+num-1]=a[i]    
    for i in range(num-2,-1,-1) :
        seg[i]=gcd(seg[2*i+1],seg[2*i+2]) 

    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 104664
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  long long N, A, B;
  cin >> N >> A >> B;
  
  long long ans;
  if (A > B) ans = 0;
  else if (N == 1)
  {
    if (A == B) ans = 1;
    else ans = 0;
  }
  else ans = (B * (N - 1) + A) - (A * (N - 1) + B) + 1;
  
  cout << ans << endl;
}

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

int main(){
    int n, x;
    cin >> n >> x;
    int l[101];
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    int d[101];
    int ans=0;
    d[0] = 0;
    for(int i=0; i<=n; i++){
        d[i+1] = d[i] + l[i];
    }
    for(int i=0; i<=n; i++){
        if(d[i] <= x){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3680
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
  int i = 0;
  for(int j = 0; j < k; j++){
    llong s = 0;
    while(s + T[i]<=P){
      s += T[i];
      i++;
      if(i==n) 
         return n;
    }
  }
  return i;
}

int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while(right - left > 1){
     mid = (left + right) / 2;
     int v = check(mid);
     if(v >=n) right = mid;
     else 
          left = mid;
  }
  return right;
}

int main(){
  cin>>n>>k;
  for(int i = 0; i<n;i++) 
       cin>>T[i];
  llong ans = solve();
  cout<<ans<<endl;
}



Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	puta(a*b);
}


Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-12
#define MOD 998244353ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	string s;
	cin >> s;
	for (char x : s)
		if (x == '7')
		{
			cout << "Yes";
			return;
		}
	cout << "No";
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--)
	{
		solve();
		cout << '\n';
	}

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=2005;
int dp[maxn][maxn];
int tree[2*maxn];
void add(int x,int val)
{
    while(x<maxn*2)
    {
        tree[x]+=val;
        x+=x&-x;
    }
}
int query(int x)
{
    int ret=0;
    while(x)
    {
        ret+=tree[x];
        x-=x&-x;
    }
    return ret;
}
int main()
{
    int n;
    cin>>n;
    vi posa(n+1,-1),posb(n+1,-1);
    vi a(2*n);
    for(int i=0;i<2*n;i++)
    {
        string col;
        cin>>col;
        cin>>a[i];
        if(col=="B")
        {
            posa[a[i]]=i+1;
            add(i+1,1);
        }
        else {
            posb[a[i]]=i+1;
        }
    }
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            add(posb[j],1);
        for(int j=0;j<=n;j++)
        {
            if(!i&&!j) continue;
            if(i)
            {
                if(j) add(posb[j],-1);
                dp[i][j]=min(dp[i][j],dp[i-1][j]+query(posa[i]-1));
                if(j) add(posb[j],1);
            }
            if(j)
            {
                if(i) add(posa[i],-1);
                dp[i][j]=min(dp[i][j],dp[i][j-1]+query(posb[j]-1));
                if(i) add(posa[i],1);
            }
            if(j) add(posb[j],-1);
            //dbg(i,j,dp[i][j]);
        }
        if(i)
            add(posa[i],-1);
    }
    print(dp[n][n]);
}

Measured memory_bytes: 16000
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if (a >= 13){
            System.out.println(b);
        }else if(a <= 5){
            System.out.println("0");
        }else{
            System.out.println(b / 2);
        }
    }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    ll dp[N+1][5][5][5];

    for (int n = 0; n < N+1; ++n) {
        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                 for (int k = 0; k < 5; ++k) {
                     dp[n][i][j][k] = 0;
                 }
            }
        }
    }
    dp[0][0][0][0] = 1;

    for (int n = 0; n < N; ++n) {
        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                 for (int k = 0; k < 5; ++k) {
                     for (int l = 1; l < 5; ++l) {
                        if (i == 1 && j == 2 && l == 3) continue;
                        if (i == 1 && k == 2 && l == 3) continue;
                        if (j == 1 && k == 2 && l == 3) continue;
                        if (j == 2 && k == 1 && l == 3) continue;
                        if (j == 1 && k == 3 && l == 2) continue;
                        dp[n+1][j][k][l] += dp[n][i][j][k];
                        dp[n+1][j][k][l] = dp[n+1][j][k][l] % MOD;
                        // cout << dp[n+1][j][k][l] << endl;
                     }
                }
            }
        }
    }

    ll ans = 0;
    REP(i, 5){
        REP(j, 5){
            REP(k, 5){
                // cout << i << ":" << j << ":" << k << ":" << dp[N-1][i][j][k] << endl;;
                ans += dp[N][i][j][k];
                ans = ans % MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int[] a = new int[3];
        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        System.out.print(a[0] + " ");
        System.out.print(a[1] + " ");
        System.out.println(a[2]);

        sc.close();

    }

}


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

int main() {
  int N, K;
  cin >> N >> K;
  int X = 0;
  
  for (int i = 0; i < N; i++) {
  	int x;
    cin >> x;
    if ( x <= K-x) {
    	X += (x*2) ;
    }
    else {
    	X += (K - x)*2;
    }
  }
  
  cout << X;
  
}




Measured memory_bytes: 3596
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

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

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

const int N = 2e5 + 5;
ll gc(ll a, ll b){
    if(b == 0) return a;
    return gc(b, a % b);
}
ll lcm (ll a, ll b){
    return (a * b) / gc(a, b);
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll p1 = b / c - (a - 1) / c;
    ll p2 = b / d - (a - 1) / d;
    ll comm = b / lcm(c, d) - (a - 1) / lcm(c, d);
    ll ans = p1 + p2 - comm;
    cout << b - a + 1 - ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))

N = int(input())
H = inpl()

OK = True
for i in range(N-1):
    if OK:
        H[i] -= 1
    if H[i] > H[i+1]:
        print("No")
        break
    elif H[i] == H[i+1]:
        OK = False
    else:
        OK = True

else:
    print("Yes")

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,string> P;
#define INF (1<<20)

int main(){
  string n;
  while(cin >> n , n!="0000"){
    if(n[0] == n[1] && n[1] == n[2] && n[2] == n[3]){
      cout << "NA" << endl;
      continue;
    }
    int cnt = 0;
    while(n != "6174"){
      cnt++;
      for(int i=0;i<4;i++){
	for(int j=i+1;j<4;j++){
	  if(n[i] < n[j]) swap(n[i],n[j]);
	}
      }
      string next = n;
      swap(next[0],next[3]);
      swap(next[1],next[2]);
      int L=0,S=0;
      for(int i=0;i<4;i++){
	L *= 10;
	S *= 10;
	L += n[i] - '0';
	S += next[i] - '0';
      }
      int N = L - S;
      n = "";
      for(int i=0;i<4;i++){
	int a = N % 10;
	n += ('0'+a);
	N /= 10;
      }
      swap(n[0],n[3]);
      swap(n[1],n[2]);
    }
    if(n == "6174") cout << cnt << endl;
  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string a, b;
	while(cin >> a >> b)
	{
		if((a == "0") && (b == "0"))
		{
			break;
		}
		int count1 = 0;
		for(int i = 0; i < 4; ++i)
		{
			if(a[i] == b[i])
			{
				count1++;
			}
		}
		int count2 = 0;
		for(int i = 0; i < 4; ++i)
		{
			for(int j = 0; j < 4; ++j)
			{
				if(a[i] == b[j])
				{
					count2++;
				}
			}
		}
		cout << count1 << " " << count2 - count1 << endl;
		
	}
}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 1e3+10;
int a[N][N],ci[N],ls[N];
int n;
struct node{
    int u,v,w;
    node(int u=0,int v=0,int w=0):u(u),v(v),w(w){}
};
int main(){
    cin >> n;
    for(int i=1;i<=n;++i){
        for(int j=1;j<n;++j){
            cin >> a[i][j];
        }
        ci[i] = 1;  ls[i] = 0;
    }
    int sign = 0;
    int r =0;
    queue<node> q;
    node cur;
    for(int i=1;i<=n;++i){  
        if(ls[i]==1)    continue;
        int  to = a[i][1];
        if(a[to][1]==i){
            ls[to] = 1; ls[i] = 1;
            q.push({i,to,1});
        }
    }
    while(!q.empty()){      
        cur = q.front();    q.pop();    r = cur.w;
        ci[cur.u]++; ci[cur.v]++;
        int to = a[cur.u][ci[cur.u]];
        if(a[to][ci[to]]==cur.u && ls[to]<=cur.w){
            ls[to] = cur.w+1;   ls[cur.u] = cur.w+1;
            q.push(node{cur.u,to,cur.w+1}); 
        }
        to = a[cur.v][ci[cur.v]];
        if(a[to][ci[to]]==cur.v && ls[to]<=cur.w){
            ls[to] = cur.w+1;   ls[cur.v] = cur.w+1;
            q.push(node{cur.v,to,cur.w+1});
        }
    }
    for(int i=1;i<=n;++i){
        if(ci[i]!=n){
            sign = 1;break;
        }
    }
    if(sign)   cout << -1 << endl;
    else cout << r << endl;
    return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        String odd = "RUD";
        String even = "LUD";
        for(int i=1;i<=s.length;i++){
            if(i%2!=0 && odd.indexOf(s[i-1])==-1){
                System.out.println("No");
                return;
            }else if(i%2==0 && even.indexOf(s[i-1])==-1){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
    
}

Measured memory_bytes: 24276
#include<bits/stdc++.h>
#include<stdint.h>
#define ff first
#define ss second

using namespace std;


#define MOD 1e9+7
#define ll long long int


void solve()
{
	string s;
	cin>>s;
	string t="ABC";
	if(s.compare(t)==0)
		cout<<"ARC\n";
	else
		cout<<"ABC\n";
	
}



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifndef ONLINE_JUDGE 
      	freopen("_input.txt", "r", stdin); 
  	freopen("_output.txt", "w", stdout); 
  	#endif 
	

    solve();

	
}

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

int main() {
  string s;cin >> s;
  bitset<3> bit;
  for (int i=0;i<(1<<3);i++) {
    bitset<3> temp(i);
    int sum=int(s.at(0))-48;
    for(int j=0;j<3;j++) {
      int temp_num=int(s.at(j+1))-48;
      //cout << s.at(j+1) << endl;
      if(temp.test(j)) {
        sum+=temp_num;
      }
      else {
        sum-=temp_num;
      }
    }
    //cout << sum << endl;
    if (sum==7) {
      bit=temp;
      break;
    }
  }
  cout << s.at(0);
  for(int i=0;i<3;i++) {
    if(bit.test(i)) {
      cout << "+";
    }
    else {
      cout <<"-";
    }
    cout << s.at(i+1);
  }
  cout << "=7" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  double a[100], b[100], sum=0;
  int n, i;

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

  sum = 0;

  for (i = 0; i < n; i++) {
    b[i] = 1/a[i];
    sum += b[i];
  }

  sum = 1/sum;
  printf("%lf\n", sum);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    string o,e;
    cin>>o;
    cin>>e;
    for(int i=0;i<min(o.length(),e.length());i++){
        cout<<o[i]<<e[i];
    }
    if(o.length()>e.length()) cout<<o[o.length()-1];
    else if(e.length()>o.length())
    cout<<e[e.length()-1];
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = [0, 0]
for i in [0, 1]:
  total = 0
  for idx, val in enumerate(a):
    total += val
    if (i + idx) % 2 == 0:
      if total >= 0:
        ans[i] += total + 1
        total = -1
    else:
      if total <= 0:
        ans[i] += 1-total
        total = 1
print(min(ans))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
int h, w;
struct node{
    int mn, mx, best;
};
node st[800005];
int add[800005];
void push(int n, int s, int e){
    if(add[n] == 0) return;
    st[n].mn = add[n];
    st[n].mx = add[n];
    if(add[n] == w+1) st[n].best = 1e9;
    else st[n].best = add[n] - e;
    if(s != e){
        add[n+n] = add[n];
        add[n+n+1] = add[n];
    }
    add[n] = 0;
}
void build(int n, int s, int e){
    if(s == e){
        st[n].mn = st[n].mx = s;
        st[n].best = 0;
    }
    else{
        int mid = (s+e)/2;
        build(n+n, s, mid);
        build(n+n+1, mid+1, e);
        st[n].mn = min(st[n+n].mn, st[n+n+1].mn);
        st[n].mx = max(st[n+n].mx, st[n+n+1].mx);
        st[n].best = min(st[n+n].best, st[n+n+1].best);
    }
}
void update(int n, int s, int e, int l, int r, int v){
    push(n, s, e);
    if(s > r || l > e) return;
    if(l <= s && e <= r){
        add[n] = v;
        push(n, s, e);
        return;
    }
    int mid = (s+e)/2;
    update(n+n, s, mid, l, r, v);
    update(n+n+1, mid+1, e, l, r, v);
    st[n].mn = min(st[n+n].mn, st[n+n+1].mn);
    st[n].mx = max(st[n+n].mx, st[n+n+1].mx);
    st[n].best = min(st[n+n].best, st[n+n+1].best);
}
int get_min(int n, int s, int e, int v){
    push(n, s, e);
    if(s == e){
        if(st[n].mx >= v) return s;
        else return 1e9;
    }
    int mid = (s+e)/2;
    push(n+n, s, mid);
    if(st[n+n].mx >= v) return get_min(n+n, s, mid, v);
    else return get_min(n+n+1, mid+1, e, v);
}
int get_max(int n, int s, int e, int v){
    push(n, s, e);
    if(s == e){
        if(st[n].mn <= v) return s;
        else return -1e9;
    }
    int mid = (s+e)/2;
    push(n+n+1, mid+1, e);
    if(st[n+n+1].mn <= v) return get_max(n+n+1, mid+1, e, v);
    else return get_max(n+n, s, mid, v);
}
int query(int n, int s, int e, int l, int r){
    push(n, s, e);
    if(s > r || l > e) return 0;
    if(l <= s && e <= r) return st[n].best;
    int mid = (s+e)/2;
    return min(query(n+n, s, mid, l, r), query(n+n+1, mid+1, e, l, r));
}
int main(){
    scanf("%d%d", &h, &w);
    build(1, 1, w);
    for(int i=1;i<=h;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        int l = get_min(1, 1, w, a);
        int r = get_max(1, 1, w, b);
        if(l <= r) update(1, 1, w, l, r, b+1);

        if(st[1].mn > w) printf("-1\n");
        else printf("%d\n", st[1].best + i);
    }
}

Measured memory_bytes: 12004
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define LL long long
#define MOD 1000000007

LL mod_pow(LL x,LL n,LL mod){
    if (n == 0) {
        return 1;
    }
    LL res = mod_pow(x * x % mod, n / 2, mod);
    if (n & 1) {
        res = res*x %mod;
    }
    return res;
}

LL mul(LL l, LL r){
    LL ret = 1;
    for (int i = 0; i < l - r + 1; i++) {
        ret *=i + r;
        ret %= MOD;
    }
    return ret;
}

LL comb(LL n,LL x){
    LL ret1 = mul(n,n-x+1);
    LL ret2 = mul(x,1);
    LL ret3 = mod_pow(ret2,MOD-2,MOD);
    return ret1 * ret3  % MOD;
}


int main(void){
    int n,a,b;
    scanf("%d %d %d", &n,&a,&b);
    LL ans =  mod_pow(2,n,MOD) - 1 - comb(n,a) - comb(n,b);
    for(;;){
        if (ans >= 0) {
            break;
        }
        ans += MOD;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();
		long N = R;

		if (R > L + 2019) {
			N = L + 2019;
		}
		int ans = Integer.MAX_VALUE;
		for (long i = L; i <= N; i++) {
			for (long j = i + 1; j <= N; j++) {
				ans = (int) Math.min(ans, i * j % 2019);
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

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

int main(){
	int N, i;
	cin >> N;
	char s[N];
	for(i=0; i<N; i++){
		cin >> s[i];
	}
	
	int red=0, bule=0;
	for(i=0; i<N; i++){
		if(s[i]=='R'){
			red++;
		}
		else{
			bule++;
		}
	}
	
	if(red>bule)	cout << "Yes" << endl;
	else		cout << "No" << endl;
	
	return 0;
}


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


int main()
{
    int N,D,X,ans = 0;cin >> N >> D >> X;
    D--;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        ans += D/b+1;
    }
    ans += X;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll X, N;
    ll ans=0;
    cin >> X >> N;
    vector<ll> p(N);
    rep(i,N) cin >> p[i];
    for (ll i=0; i<=100; ++i) {
        if (find(p.begin(), p.end(), X-i) == p.end()) {
            ans = X-i;
            break;
        }
        if (find(p.begin(), p.end(), X+i) == p.end()) {
            ans = X+i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int x;

    cin >> x;
    cout << 360/gcd(360, x) << '\n';

    return 0;
}


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

const double pi = acos(-1);

int main() {
	int n;
	cin >> n;
	int cnt[n + 1];
	memset(cnt, 0, sizeof(cnt));
	for (int i = 0; i < n - 1; i++) {
	  int x;
	  cin >> x;
	  x--;
	  cnt[x]++;
	}
	for (int i = 0; i < n; i++)
	  cout << cnt[i] << '\n';
  return 0;
}


Measured memory_bytes: 4424
def main():
    N = int(input())
    if N % 2 == 1:
        print(0)
    else:
        N //= 2
        ans = 0
        i = 0
        while True:
            i += 1
            v = 5 ** i
            if v > N:
                break
            else:
                ans += N // v
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61892
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *right;
    Node *left;
    Node *parent;
};

Node *root, *NIL;

void Insert(int k);
void Inorder(Node *u);
void Preorder(Node *u);
Node* Find(Node *x, int k);

int main() {
    int n, k;
    cin >> n;
    string com;
    for ( int i = 0; i < n; i++ ) {
        cin >> com;
        if ( "insert" == com ) {
            cin >> k;
            Insert(k);
        } else if ( "find" == com ) {
            cin >> k;
            if ( NIL == Find(root, k) ) {
                cout << "no\n";
            } else {
                cout << "yes\n";
            }
        } else if ( "print" == com ) {
            Inorder(root);
            cout << '\n';
            Preorder(root);
            cout << '\n';
        }
    }
    
    return 0;
}

void Insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while ( x != NIL ) {
        y = x;
        if ( z->key > x->key ) {
            x = x->right;
        } else {
            x = x->left;
        }
    }
    
    z->parent = y;
    if ( NIL == y ) {
        root = z;
    } else if ( z->key > y->key ) {
        y->right = z;
    } else {
        y->left = z;
    }
}

void Inorder(Node *u) {
    if ( NIL == u ) return;
    Inorder(u->left);
    printf(" %d", u->key);
    Inorder(u->right);
}

void Preorder(Node *u) {
    if ( NIL == u ) return;
    printf(" %d", u->key);
    Preorder(u->left);
    Preorder(u->right);
}

Node* Find(Node *x, int k) {
    while ( x != NIL && x->key != k ) {
        if ( k > x->key ) {
            x = x->right;
        } else {
            x = x->left;
        }
    }
    return x;
}

/*
10
insert 30
insert 88
insert 12
insert 1
insert 20
find 20
insert 17
insert 25
find 16
print
 */

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int ans = 0;
  for (int i = 0; i <= 100; i++) {
    if (A < i && i <= B && C < i && i <= D) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256