akhauriyash/Code-Regression huggingface dataset:
from functools import reduce
def cmb(r):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod
n,a,b = map(int,(input().split()))
ans=0
mod=10**9+7

ans=pow(2,n,10**9+7)-1
ans-=cmb(a)
ans-=cmb(b)
print(ans%mod)

Measured memory_bytes: 11556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(auto i=a;i<n;i+=x)
#define forD(i,a,n,x) for(auto i=n-1;i>=0;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

ld c[3003]; ld dp[3003][3003];

ld solve(ll n , ll heads , ll tails)
{
	if(n==0)
	{
		if(heads>tails)return 1.0;
		else return 0.0;
	}

	if(dp[n][heads]!=-1) return dp[n][heads];
	ld hp = c[n-1];  ld tp = 1.0-hp; 

	return dp[n][heads]= hp*solve(n-1,heads+1,tails) + tp*solve(n-1,heads,tails+1);
}

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	ll n; cin>>n; forA(i,0,n,1)cin>>c[i];
	forA(i,0,3003,1)forA(j,0,3003,1) dp[i][j]=-1;
	ld ans = solve(n,0,0);
	cout<<fixed<<setprecision(10)<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 74468
import sys


def solve(a):
    ans = 1
    over = False
    for e in a:
        if not over:
            ans *= e
        else:
            if e == 0:
                return 0
        if ans > 10 ** 18:
            over = True
    if not over:
        return ans
    else:
        return -1


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 85572
import sys
n, m = map(int, input().split())

a_grid = [list(input()) for _ in range(n)]
b_grid = [list(input()) for _ in range(m)]

for r in range(n-m+1):
  for c in range(n-m+1):
    for x in range(m):
      if a_grid[r+x][c:c+m] != b_grid[x][:]:
        break
    else:
      print("Yes")
      sys.exit()
print("No")      

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int w,h;
bool valid(int x, int y){
  return (0<=x&&x<w&&0<=y&&y<h);
}
string maxstring(string s1,string s2){
  if(s1.size()>s2.size()) return s1;
  else if(s1.size()<s2.size()) return s2;
  else return max(s1,s2);
}
int main(void){
  while(cin>>w>>h,w){
    char g[70][70];
    string dp[70][70];
    REP(y,h)cin>>g[y];
    bool update = true;
    string ans = "";
    REP(y,h)REP(x,w){
      if(!isdigit(g[y][x])) dp[y][x] = "";
      else{
        string smax = "";
        if(valid(x-1,y)) smax = maxstring(smax,dp[y][x-1]);
        if(valid(x,y-1)) smax = maxstring(smax,dp[y-1][x]);
        if(smax=="0")smax = "";
        dp[y][x] = smax + g[y][x];
      }
      ans = maxstring(ans,dp[y][x]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <unordered_set>
#include <stack>

using namespace std;

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int curI = 0;
  int win = -1;

  while (true) {
    if (curI == 0) {
      if (A.size() == 0) {
        cout << "A" << endl;
        break;
      }
      if (A[0] == 'b') {
        curI = 1;
      } else if (A[0] == 'c') {
        curI = 2;
      }
      A.erase(0, 1);
    } else if (curI == 1) {
      if (B.size() == 0) {
        cout << "B" << endl;
        break;
      }
      if (B[0] == 'a') {
        curI = 0;
      } else if (B[0] == 'c') {
        curI = 2;
      }
      B.erase(0, 1);
    } else if (curI == 2) {
      if (C.size() == 0) {
        cout << "C" << endl;
        break;
      }
      if (C[0] == 'a') {
        curI = 0;
      } else if (C[0] == 'b') {
        curI = 1;
      }
      C.erase(0, 1);
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int N;
    static int counter = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        permutaion("");
        System.out.println(counter);
        sc.close();
    }

    static void permutaion(String str) {
        if (str.length() > 0 && Long.parseLong(str) > N) {
            return;
        }
        if (!str.matches("[^3]*|[^5]*|[^7]*|.*[^357]+.*")) {
            counter++;
        }
        permutaion(str + "3");
        permutaion(str + "5");
        permutaion(str + "7");
    }
}

Measured memory_bytes: 51320
#include <iostream>
#include <cstring>

using namespace std;

int main() {
  const int day = 20190430;

  char S[11];

  cin >> S;

  S[4] = '\0';
  S[7] = '\0';

  int sday = atoi(S) * 10000;
  sday += atoi(&S[5]) * 100;
  sday += atoi(&S[8]);
  
  if (sday <= day) {
    cout << "Heisei\n";
  } else {
    cout << "TBD\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    for(; ;)
    {
    int x,y;
    cin>>x>>y;
    if(x==0&&y==0)
        break;
    for(int i=0;i<x;i++)
    {
        for(int j=0;j<y;j++)
        {
            if(j==0||j==y-1||i==0||i==x-1)
            {
                cout<<"#";
            }
            else{
                cout<<".";
            }
        }
            cout<<"\n";
        }
        cout<<"\n";
    }
    return 0;

}



Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:268435456")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifndef _MSC_VER
#pragma GCC target ("sse4.2")
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;


ll bin_pow(ll a, ll x, ll mod)
{
	ll res = 1;
	while (x)
	{
		if (x & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		x /= 2;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	const ll mod = 998244353;
	ll n, m, k;
	cin >> n >> m >> k;
	vl fact(n + 1);
	fact[0] = 1;
	for (int i = 1; i < sz(fact); i++)
		fact[i] = fact[i - 1] * i % mod;
	auto C = [&](ll k, ll n)
	{
		return fact[n] * bin_pow(fact[n - k], mod - 2, mod) % mod * bin_pow(fact[k], mod - 2, mod) % mod;
	};
	ll res = 0;
	//c(n-1,k1)*m*(m-1)^(n-1-k1)
	for (ll kk = 0; kk <= k; kk++)
	{
		res = (res + C(kk, n - 1) * m % mod * bin_pow(m - 1, n - 1 - kk, mod) % mod) % mod;
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 4804
N = int(input())
S = input()

res = float("inf")

# if "#" not in S or "." not in S:
#     res = 0

counts = []
counts.append((0, 0))
a, b = 0, 0
for s in S:
    if s == "#":
        a += 1
    elif s == ".":
        b += 1
    counts.append((a, b))

for i in range(N + 1):
    res = min(res, counts[i][0] + counts[-1][1] - counts[i][1])

print(res)


Measured memory_bytes: 24168
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin>>n;
	int k=(n%10);
	if(k==3){
		cout<<"bon";
	}
	else if(k==0||k==1||k==6||k==8){
		cout<<"pon";
	}
	else cout<<"hon";
	return 0;	
}

Measured memory_bytes: 3640
n,x,y=map(int,input().split())
def dis(i,j):
  return min(j-i,abs(j-y)+abs(i-x)+1)-1
ans=[0]*(n-1)
for i in range(1,n):
  for j in range(i+1,n+1):
    ans[dis(i,j)]+=1
for i in range(len(ans)):
  print(ans[i])


Measured memory_bytes: 47708
#include<stdio.h>
int main()
{
    int x,a,b,c,c1;
    scanf("%d %d %d",&x,&a,&b);
    if(x>a||x<a){
        if(x>a){
                c=x-a;
    }
    else{
        c=a-x;
    }
    }

     if(x>b||b>x){
            if(x>b){
        c1=x-b;
    }
    else{
        c1=b-x;
    }
     }
    if(c<c1){
        printf("A");
    }
    else{
        printf("B");
    }
    return 0;
}


Measured memory_bytes: 128
from collections import Counter

S = input()
C = Counter(S).most_common()
max_v = C[0][1]
min_count = 9999
for key_string,v in Counter(S).most_common():
    #if v<max_v: break
    #else:
    T = S
    count = 0
    while(len(Counter(T))>1):
        TT = ""
        for i in range(len(T)-1):
            temp = T[i:i+2]
            if key_string in temp:
                TT += key_string
            else:
                TT += temp[0]
        T = TT
        count += 1
    if min_count>count:
        min_count = count
            
print(min_count)

Measured memory_bytes: 3316
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();

    if(S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}





Measured memory_bytes: 22868
N = int(input())
L = input().split(" ")

import collections

even = collections.Counter(L[::2]).most_common(2)
odd = collections.Counter(L[1::2]).most_common(2)

if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
else:
    # even[0][0] == odd[0][0]
    if len(even) == 1 or len(odd) == 1:
        print(N // 2)
    else:
        print(N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

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

string a;
int total;

int main() {
    cin>>a;
    for(int i=0; i<a.length(); i++) {
        if (a[i]=='+') {
            total++;
        } else {
            total--;
        }
    }
    cout << total;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());

    Vl csum(N + 1);
    for (int i = 0; i < N; i++) {
        csum[i + 1] = csum[i] + A[i];
    }

    int idx;
    for (idx = 0; idx < N; idx++) {
        if (idx < P) continue;
        if (A[idx] + M < A[P - 1]) {
            break;
        }
        ll r = max(V - (N - idx) - (P - 1), 0LL);
        ll s = idx - P + 1;
        ll cs = csum[idx] - csum[P - 1];
        if ((A[idx] + M) * s - cs < r * M) {
            break;
        }
    }

    cout << idx << endl;

    return 0;
}

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

int main(){
    int N, X;  cin >> N >> X;
    vector<int> L(N+1,0);
    for(int i=1; i<=N; i++) cin >> L[i];

    int ans = 0;
    int d = 0;
    for(int i=1; i<=N+1; i++){
        if(d<=X) ans++;
        if(i<=N) d += L[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
if N == 1:
    print(0)
elif N == 2:
    print(2)
else:
    a = 10 ** N % (10 **9 + 7)
    m = (9 ** N)  * 2 % (10 **9 + 7) - (8 ** N)  % (10 **9 + 7)
    ans = (a - m ) % (10 **9 + 7)
    print(ans)

Measured memory_bytes: 79572
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

map <long long, long long> fr;
long long n,i,x,l[200005],r,nr;
int main()
{

   cin>>n;
   for(i=1;i<=n;i++)
   {
       cin>>x;
       l[i]=i+x;
       r=i-x;
       fr[r]++;
   }
   for(i=1;i<=n;i++)
   {
       x=l[i];
       nr+=fr[l[i]];
   }
   cout<<nr;

    return 0;

}


Measured memory_bytes: 27844
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;


ll n, k;
vector<ll> a;

void solve() {
    ll dp[n + 1];
    ll dp_g[n + 1];
    dp[0] = 0, dp_g[0] = 0;
    rep(i, n) {
        dp[i + 1] = dp[i] + a[i];
        dp_g[i + 1] = dp_g[i] + max(ll(0), a[i]);
    }
    ll ans = 0;
    for (int i = 0; i + k <= n; ++i) {
        ll temp = dp[i + k] - dp[i];
        ans = max(ans, temp + dp_g[i] + dp_g[n] - dp_g[i + k]);
        ans = max(ans, dp_g[i] + dp_g[n] - dp_g[i + k]);
    }

    cout << ans << endl;
}


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        cin >> n >> k;
        a.resize(n);
        rep(i, n) cin >> a[i];

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
string IntToString(int);
string solve(vector<pair<string,pair<int,int> > > &era,int q){
  string ans = "Unknown";
  for(int i = 0;i < era.size();i++){
    //    cout << era[i].first << "   " << era[i].second.first << " " << era[i].second.second << endl;
    if(era[i].second.first <= q && era[i].second.second >= q){
      //cout << i << endl;
      ans = era[i].first + " " + IntToString(q-era[i].second.first+1);
      return ans;
    }
  }
  return ans;
}
int main(){
  int n,q;
  while(cin >> n >> q,n && q ){
    vector<pair<string,pair<int,int> > > era(n);

    for(int i =0;i < n;i++){
      string name;
      int time,year;
      cin >> name >> time >> year;
      era[i] = pair<string,pair<int,int> >(name,pair<int,int>(year-time+1,year));
    }
    for(int i = 0;i < q;i++){
      int q_year;
      cin >> q_year;
      cout << solve(era,q_year) << endl;
    }

  }
  return 0;
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

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

using namespace std;
using ll = long long;
const ll MOD = 1000003;

bool my_sort(const pair<ll, ll> &fl, const pair<ll, ll> &sl) {
    return fl.second < sl.second;
}

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

    vector<ll> a(n);
    map<ll, ll> m;
    vector<pair<ll, ll>> v;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (m.count(a[i]) == 0) {
            m[a[i]] = 1;
        } else {
            m[a[i]]++;
        }
    }

    if (m.size() <= k) {
        cout << 0 << endl;
        exit(EXIT_SUCCESS);
    }

    v.reserve(m.size());
    for (pair<ll, ll> item : m) {
        v.emplace_back(item.first, item.second);
    }

    sort(v.begin(), v.end(), my_sort);
    ll size = m.size();
    ll cnt = 0;
    ll idx = 0;

    while (size > k) {
        cnt += v.at(idx).second;
        idx++;
        size--;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 17408
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;

int main(){
  char x[1000];

  while(1){
    scanf("%s", x);
    if( x[0] == '0' ) break;
    int sum = 0;
    for (int i = 0; i < strlen(x); i++){
      sum += (x[i] -'0');
    }

    printf("%d\n", sum);

  }


return 0;
}

Measured memory_bytes: 3196
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
ll lcm(ll x, ll y) { return x/gcd(x, y)*y; }

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    int a[n][n];
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
        }
    }
    int dame=0;
    int ans=0;
    bool b[n][n];
    rep(i,n){
        rep(j,n){
            b[i][j]=false;
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans+=a[i][j];
        }
    }
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(i==k||j==k) continue;
                if(a[i][k]+a[k][j]<a[i][j]) dame++;
            }
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(i==k||j==k) continue;
                if(a[i][k]+a[k][j]==a[i][j]){
                    ans-=a[i][j];
                    a[i][j]=a[j][i]=INF;
                }
            }
        }
    }

    if(dame!=0){
        cout<<-1<<endl;
    }
    else{
        cout<<ans<<endl;
        
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define INF 1000000007
#define int long long
using P = pair<int, int>;
using ll = long long;
signed main(){
    vector<vector<int>> m(2019,vector<int>(2019) );
    for(int i=0;i<2019;i++){
        for(int j=0;j<2019;j++){
            m[i][j]=i*j%2019;
        }
    }
    int l,r;
    int ans=INF;
    cin>>l>>r;
    if(r-l>=2018)ans=0;
    else{
        l%=2019;
        r%=2019;
        if(l<r){
            for(int i=l;i<=r;i++){
                for(int j=l+1;j<=r;j++){
                    if(i==j)continue;
                    ans=min(ans,m[i][j]);
                }
            }
        }else{
            ans=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int dv[] = {-1, 0, 1};

struct state {
  int city;
  int from;
  double cost;
  int v;
};

bool operator<(const state &a, const state &b){return a.cost > b.cost;}

int main(){
  cin.sync_with_stdio(false);
  int n, m;

  while(cin >> n >> m, n) {
    int s, g;
    cin >> s >> g;
    s--; g--;

    int d[n][n] = {}, limit[n][n] = {};
    rep(i, m) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      cin >> d[x][y] >> limit[x][y];
      d[y][x] = d[x][y];
      limit[y][x] = limit[x][y];
    }

    priority_queue<state> q;
    bool visited[n][n][31] = {};
    q.push(state{s, s, 0, 0});
    double ans = INF;
    while(!q.empty()) {
      state st = q.top(); q.pop();
      if (st.city == g && st.v == 1) {
        ans = st.cost;
        break;
      }

      if (visited[st.city][st.from][st.v]) continue;
      else visited[st.city][st.from][st.v] = true;

      rep(i, n) {
        if (d[st.city][i] != 0 && i != st.from) {
          rep(j, 3) {
            if (st.v+dv[j] > 0 && st.v+dv[j] <= limit[st.city][i] && !visited[i][st.city][st.v+dv[j]]) {
              q.push(state{i, st.city, st.cost+(double)d[st.city][i]/(st.v+dv[j]), st.v+dv[j]});
            }
          }
        }
      }
    }
    if (ans != INF) {
      printf("%.5f\n", ans);
    } else {
      printf("unreachable\n");
    }
  }

  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n, d;
    cin >> n >> d;

    cout << (n+2*d)/(2*d+1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 20000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;
bool dp[81][81][N];
int main(){
	int h,w;
    cin>>h>>w;
    int a[w][h];
    REP(i,h){
        REP(j,w){
            cin>>a[j][i];
        }
    }
    REP(i,h){
        REP(j,w){
            int t;
            cin>>t;
            a[j][i]=abs(a[j][i]-t);
        }
    }
    dp[0][0][a[0][0]]=true;
    REP(i,h){
        REP(j,w){
            REP(k,N){
                if(dp[j][i][k]){
                    if(j+1<w){
                        dp[j+1][i][abs(k-a[j+1][i])]=true;
                        dp[j+1][i][k+a[j+1][i]]=true;
                    }
                    if(i+1<h){
                        dp[j][i+1][abs(k-a[j][i+1])]=true;
                        dp[j][i+1][k+a[j][i+1]]=true;
                    }
                }
            }
        }
    }
    int ans;
    REP(k,N){
        if(dp[w-1][h-1][k]){
            ans=k;
            break;
        }
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 125824
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using P1 = array<int, 26>;
using P2 = array<char, 365>;

struct state{
    array<int, 26> prv;
    array<char, 365> ans;
    int val;
    bool operator<(const state &a) const { return val > a.val; }
    state(P1 a, P2 b, int x) : prv(a), ans(b), val(x) {};
};


int main() {
    int d;
    cin >> d;
    array<int, 26> A{};
    for (auto &&k : A) cin >> k;
    vector<array<int, 26>> v(d);
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            scanf("%d", &v[i][j]);
        }
    }
    vector<int> ans(d);
    int W = 400;
    vector<state> a;
    a.emplace_back(P1{}, P2{}, 0);
    fill(a[0].prv.begin(),a[0].prv.end(), -1);
    for (int i = 0; i < d; ++i) {
        priority_queue<state> Q;
        for (auto &&s : a){
            for (int l = 0; l < 26; ++l) {
                s.val -= (i-s.prv[l])*A[l];
            }
            for (int k = 0; k < 26; ++k) {
                state ss(s);
                ss.ans[i] = k;
                ss.val += v[i][k]+s.prv[k]*A[k];
                ss.prv[k] = i;
                ss.val -= s.prv[k]*A[k];
                Q.emplace(ss);
                if(Q.size() > W) Q.pop();
            }
        }
        a.clear();
        while(!Q.empty()) a.emplace_back(Q.top()), Q.pop();
    }
    for (auto &&m : a.back().ans) {
        printf("%d\n", m+1);
    }
    return 0;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl #define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
@ExperimentalStdlibApi
fun main(args: Array<String>) = abc163d()

@ExperimentalStdlibApi
fun abc163d() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }

    val list = (0L..n).toList()
    val cSum = list.scan(0L, Long::plus)

    val map = (k..n + 1).map { Math.max((cSum.last() - cSum[cSum.lastIndex - it]) - cSum[it], 0) + 1 }
    val answer = map.fold(0L) { acc, l -> (acc + l) % MOD }

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()


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

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;

	int a[n],sum=0;

	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		sum+=a[i];
	}

	long long int p = sum/n,summ=0,s=0,su=0;
	//cout<<p<<" ";
	for (int i = 0; i < n; ++i)
	{
		summ+= pow( abs(p-a[i]) ,2);
		s+= pow( abs(p+1-a[i]) ,2);
		su+= pow( abs(p-1-a[i]) ,2);
	}
	//cout<<su<<" "<<summ<<" "<<s<<endl;
	cout<<min(s,min(su,summ))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char str[1201];
    fgets(str, sizeof(str), stdin);
    //printf("%s\n", str);
    int i=0;
    while(1){
        if(str[i] == '\0'){
            break;
        }else if('a' <= str[i] && str[i] <= 'z'){
            str[i] -= 32;
        }else if('A' <= str[i] && str[i] <= 'Z'){
            str[i] += 32;
        }
        i++;
    }
    printf("%s", str);
    return 0;
}



Measured memory_bytes: 2032
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int i,j,c;
	int a,d,n;
	char *p;
	
	p = (char *)malloc(sizeof(char)*1000000);
	
	p[0]=0;
	p[1]=0;
	for(i=2;i<1000000;i++)
	{
		p[i]=1;
	}
	
	c = 2;
	
	while(1)
	{
		if(p[c])
		{
			for(i=2*c;i<1000000;i+=c)
			{
				p[i]=0;
			}
		}
		while(p[++c]==0);
		if(c>1000)break;
	}
	
	while(1)
	{
		scanf("%d %d %d ",&a,&d,&n);
		if(a == 0 && d == 0 && n == 0)break;
		c = 0;
		i = 0;
		while(1)
		{
			if(p[a+i*d]){c++;}
			if(n==c)
			{
				printf("%d\n",a+i*d);
				break;
			}
			i++;
		}
	}
	
	return 0;
	
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
  string S;
  cin>>S;
  for(int i=0;i<4;i++){
      int count=0;
      for(int j=0;j<4;j++){
          if(S[i]==S[j]){
              count+=1;
          }
      }
      if(count!=2){
          cout<<"No"<<endl;
          return 0;
      }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 2*1e5+5,M = 105;

using namespace std;

int main()
{
	abdelrahman001
	string s;
	cin >> s;
	for(int i = 0;i<s.sz()-1;i++)
		if(s[i] == s[i+1])
			return cout << i+1 << " "<< i+2,0;
		else if(i<s.sz()-2 && s[i] == s[i+2])
			return cout << i+1 << " " << i+3,0;
	cout << "-1 -1";
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(S == "Cloudy"){
        cout << "Rainy" << endl;
    }
    else if(S == "Rainy"){
       cout << "Sunny" << endl; 
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
string s; 
int main(){
	int ans=0;
    cin >> n >> s;
   	
   	for(int i=0;i<1000;i++){
   		int cnt=0;
   		int t[3]={i/100,(i/10)%10,i%10};
   		for(int j=0;j<n;j++)
	   if(t[cnt]+'0'==s[j]){
	   	if(++cnt==3){
	   		ans++;break;
		   }
	   }
	}
    cout << ans << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;

    int a, b, c;
    cin>>a>>b>>c;
    if (a == b and a != c) cout<<"Yes";
    else if (b == c and b != a) cout<<"Yes";
    else if (a == c and a != b) cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            nums = Enumerable.Repeat(MAX, (int)N + 1).ToArray();
            nums[0] = 0;
            nums[1] = 1;
            WriteLine(dfs(N));
        }
        static long MAX = long.MaxValue / 2;
        static long[] nums;
        static long dfs(long n)
        {
            if (n < 0) return MAX;
            if (MAX != nums[n]) return nums[n];
            var ret = MAX;
            var nv = 9;
            while (0 <= n - nv) nv *= 9;
            nv /= 9;
            while (nv != 1)
            {
                ret = Min(ret, dfs(n - nv));
                nv /= 9;
            }
            var sv = 6;
            while (0 <= n - sv) sv *= 6;
            nv /= 6;
            while (sv != 1)
            {
                ret = Min(ret, dfs(n - sv));
                sv /= 6;
            }

            ret = Min(ret, dfs(n - 1));
            return nums[n] = ret + 1;
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28920
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    if k == 0:
        print(n ** 2)
        exit()

    res = 0
    for b in range(1, n + 1):
        res += (n // b) * max(0, (b - k))
        res += max(0, (n % b) - (k - 1))
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
using namespace std;
using LLI = long long int;

// B P P P B
// B BPPPB P BPPPB B
// B BBPPPBPBPPPBB P BBPPPBPBPPPBB B
// B BBBPPPBPBPPPBBPBBPPPBPBPPPBBB P BBBPPPBPBPPPBBPBBPPPBPBPPPBBB B

// [1]
// (1)[3](1)
// (2)[3](1)[1](1)[3](2)
// (3)[3](1)[1](1)[3](2)[1](2)[3](1)[1](1)[3](3)[1]...


vector<LLI> N(51);
void calc_N() {
    N[0] = 1;
    for (int i=1; i<51; i++) {
        N[i] = N[i-1] * 2 + 3;
    }
}

LLI f(int i, LLI k) {
    if (k == 0 || k == -1) {
        return 0;
    }

    if (k < 0) {
        throw "k < 0";
    }

    
    if (i == 0) {
        if (k != 1) {
            throw "k != 1";
        }
        return 1;
    }

    if (k <= N[i-1] + 1) {
        return f(i-1, k-1);
    } else if (k == N[i-1] + 2) {
        return f(i-1, k-2) + 1;
    } else {
        return f(i-1, N[i-1]) * 2 + 1 - f(i-1, N[i]-k-1);
    }
}

int main(int argc, char *argv[])
{
    int n;
    LLI X;
    cin >> n >> X;

    calc_N();
    LLI p = f(n, X);

    cout << p;

    return 0;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  
  int ans = T.size();
  
  for(int i = 0; i < S.size() - T.size() + 1; i++){
    int count = 0;
    for(int j = 0; j < T.size(); j++){
      if(S[i+j] != T[j])
        count++;
    }
    if(count < ans)
      ans = count;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3572
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        
        long min = a*(N-1)+b;
        long max = a+b*(N-1);
        if(a>b || (N==1 && a<b)) System.out.println(0);
        else System.out.println(max-min+1);
    }
}

Measured memory_bytes: 22868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

int N; ll C;
ll x[100500], v[100500];
ll lsum[100500], rsum[100500];
ll lmx[100500], rmx[100500];


int main(){
	ios::sync_with_stdio(false);
	cin >> N >> C;
	repp(i,N) cin >> x[i] >> v[i];

	ll ans = 0;
	ll sum = 0; 
	for(int i=1;i<=N;i++) lsum[i] = lsum[i-1] + v[i];
	for(int i=N;i>=1;i--) rsum[i] = rsum[i+1] + v[i];

	for(int i=1;i<=N;i++) ans = max(ans, lsum[i] - x[i]);
	for(int i=N;i>=1;i--) ans = max(ans, rsum[i] - (C-x[i]));


	for(int i=1;i<=N;i++) lmx[i] = max(lmx[i-1], lsum[i] - x[i]);
	for(int i=N;i>=1;i--) rmx[i] = max(rmx[i+1], rsum[i] - (C-x[i]) );
	for(int i=1;i<=N;i++) ans = max(ans, lsum[i] - x[i] + rmx[i+1] - x[i] );
	for(int i=N;i>=1;i--) ans = max(ans, rsum[i] - (C-x[i]) + lmx[i-1] - (C-x[i]) );


	
	cout << ans << endl;

}


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

int main() {
  int N, M;
  int a;
  cin >> N >> M;
  int s[N+1]={};
  for (int i=0; i<M; i++) {
    cin >> a;
    s[a]++;
    cin >> a;
    s[a]++;
  }
  for (int i=1; i<=N; i++) 
    cout << s[i] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
  int main(void)
{
 int a,b,op,ans;
   while(1)
  {
    scanf("%d %c %d",&a,&op,&b);
      if(op == '+')
    {
      ans=a+b;
      printf("%d\n",ans);
    }
   else if(op == '-')
    {
      ans=a-b;
      printf("%d\n",ans);
    }
   else if(op == '*')
    {
      ans=a*b;
      printf("%d\n",ans);
    }
   else if(op == '/')
    {
      ans=a/b;
      printf("%d\n",ans);
    }
   else if(op == '?')break;
  }

  return 0;
}

Measured memory_bytes: 2756
import sys

input = sys.stdin.readline

#Dequeを用いたBFS
from collections import deque

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

r = [[] for i in range(N+1)] #ノードの初期化

for i in range(M):
    a,b = map(int,input().split())
    r[a].append(b)
    r[b].append(a)

miteru = deque([1]) #見てる要素
mita = {1} #見た要素
res = [-1]*(N+1)

while  miteru: 
    now = miteru.popleft()
    x =set( r[now])
    x = x - mita
    for i in x:
        miteru.append(i)
        if res[i] == -1:res[i] =now
        mita.add(i)
    
print("Yes")
for i in res[2:]:
    print(i)
#print("\n".join(res))


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

class UnionFind {
  int N;
  vector<int> PS;
public:
  UnionFind() : N(0) {}
  UnionFind(int n) : N(n), PS(n, -1) {}
  int merge(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    int x = leader(a), y = leader(b);
    if (x == y) return x;
    if (-PS.at(x) < -PS.at(y)) swap(x, y);
    PS.at(x) += PS.at(y);
    PS.at(y) = x;
    return x;
  }
  bool same(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    return leader(a) == leader(b);
  }
  int leader(int a) {
    assert(0 <= a && a < N);
    if (PS.at(a) < 0) return a;
    return PS.at(a) = leader(PS.at(a));
  }
  int size(int a) {
    assert(0 <= a && a < N);
    return -PS.at(leader(a));
  }
  vector<vector<int>> groups() {
    vector<int> B(N), S(N);
    for (int i = 0; i < N; i++) {
      B.at(i) = leader(i);
      S.at(B.at(i))++;
    }
    vector<vector<int>> ret(N);
    for (int i = 0; i < N; i++) {
      ret.at(i).reserve(S.at(i));
    }
    for (int i = 0; i < N; i++) {
      ret.at(B.at(i)).push_back(i);
    }
    ret.erase(
      remove_if(ret.begin(), ret.end(), [&](const vector<int>& v) { return v.empty(); }),
      ret.end()
    );
    return ret;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    V.at(i) = {a, b};
  }

  reverse(V.begin(), V.end());

  UnionFind UF(N);
  vector<long> ans;
  long tmp = (long) N * (N - 1) / 2;

  for (int i = 0; i < M; i++) {
    ans.push_back(tmp);
    auto [a, b] = V.at(i);
    if (UF.same(a, b)) continue;
    tmp -= (long) UF.size(a) * UF.size(b);
    UF.merge(a, b);
  }
  reverse(ans.begin(), ans.end());
  for (auto a : ans) cout << a << "\n";
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    ll a,b,c; cin >> a >> b >> c;
    ll A = c - a - b;
    if(A > 0 && A * A > 4 * a * b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "airline.h"
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
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;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    ll sum=0;
    rep(i,n)sum+=v[i];
    bitset<4000005> bit;
    bit.set(0);
    rep(i,n)bit|=(bit<<v[i]);
    for(int i=sum/2;i>=0;i--)if(bit.test(i))dame(sum-i);
}

Measured memory_bytes: 1664
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;

int main() {
	ll n, a, b; cin >> n >> a >> b;

	if (a == b) {
		cout << 1 << endl;
		return 0;
	}
	else if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	else if (n == 1) {
		cout << 0 << endl;
		return 0;
	}

	cout << (n - 2) * b - (n - 2) * a + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.math.BigInt.long2bigInt

object Main extends App {
  val params = io.StdIn.readLine().split(" ").map(_.toLong)
  var x = params(0)
  var k = params(1)
  var d = params(2)
  var ans: Long = 0

  x = Math.abs(x)
  val stright : Long = Math.min(k, x / d)
  k -= stright
  x -= stright * d

  if ((k mod 2) == 0)
    ans = x
  else
    ans = Math.abs(x - d)

  println(ans)
}


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

int main() {
    int n, cnt = 0;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (auto i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        if (a[i].first == a[i].second) cnt++;
        else
            cnt = 0;
        if (cnt == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628