akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;

using int64 = long long;

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

  int n, a, b;
  cin >> n >> a >> b;

  cout << min(a, b) << " " << max(0, (a + b) - n) << endl;

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  long long N,A,B;
  long long i;
  long long max,min,ans;
  scanf("%lld%lld%lld",&N,&A,&B);
  if(A > B){
    ans = 0;
  }else if(N == 1 && A != B){
    ans = 0;
  }else{
    min = A*(N-1)+B;
    max = B*(N-1)+A;
    ans = max-min+1;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <math.h>
#include <stdio.h>
using namespace std;

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

    if(k==0)
    {
        int f=0;
        for(int i=1;i<=pow(2,m+1);i++)
        {
            if(f<2)
            {
                f++;
                printf("%d ",k);

            }
            else
            {
                f=1;
                k++;
                printf("%d ",k);
            }
        }
    }

    else
    {
        int sum=0;
        for(int i=0;i<=pow(2,m)-1;i++)
        {
            if(i!=k)
                sum^=i;
        }
        if(sum!=k)
        {
             puts("-1\n");return 0;

        }
        printf("%d ",k);
        for(int i=0;i<(1<<m);i++)
        {
            if(i!=k)
                printf("%d ",i);
        }
        printf("%d ",k);
        for(int i=(1<<m)-1;i>=0;i--)
        {
            if(i!=k)printf("%d ",i);
        }
        puts("");
    }
    return 0;
}












Measured memory_bytes: 1792
#include <iostream>
#include <cstdint>
#include <utility>
#include <vector>
#include <cassert>

const uint32_t MAX_P = 19;

uint64_t pow10[MAX_P];

void calc_pow() {
	pow10[0] = 1;
	for (uint32_t i = 1;i < MAX_P;i++) {
		pow10[i] = pow10[i - 1] * 10;
	}
}

void generate_snoke(uint64_t num, uint64_t digSum, uint32_t digI, std::vector<uint64_t> &ans, uint32_t minDig = 0) {
	uint32_t dig = num / pow10[digI] % 10;

	//std::cerr << "num: " << num << " digS: " << digSum << " i: " << digI << std::endl;

	uint32_t curD = dig;
	uint64_t curNum = num;
	uint64_t curSum = digSum;

	while (curD > minDig) {
		if (curSum * pow10[digI] >= curNum) { 
			curNum = curNum - pow10[digI];
			curSum--;
			curD--;
		} else {
			break;
		}
	}
	for (uint32_t i = curD;i <= dig;i++) {
		if (digI > 0) {
			generate_snoke(curNum, curSum, digI - 1, ans);
		} else {
			ans.push_back(curNum);
		}
		curNum += pow10[digI];
		curSum++;
	}

}

std::vector<uint64_t> generate_snoke() {
	std::vector<uint64_t> ans;
	uint64_t curNines = 9;
	for (uint32_t i = 1;i < 16;i++) {
		generate_snoke(curNines, 9 * i, i - 1, ans, 1);
		curNines = curNines * 10 + 9;
	}
	return ans;

}

int main() {
	calc_pow();
	std::vector<uint64_t> snokes = generate_snoke();
	uint32_t k;
	std::cin >> k;
	for (uint32_t i = 0;i < k;i++) {
		std::cout << snokes[i] << "\n";
	}
	//std::cerr << snokes.size() << "\n";
	//std::cerr << snokes.back() << "\n";


}




Measured memory_bytes: 256
N = int(input())
c = [list(map(int, input().split()))for _ in range(N - 1)]
for j in range(N):
    nowt = 0
    for i in range(j, N - 1):
        f = c[i][2]
        nowt = max(c[i][1], (nowt + f - 1) // f * f) + c[i][0]
    print(nowt)

Measured memory_bytes: 42092
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int i,j,len,k,n,a[405];
long long dp[405][405],sum[405];
int main()
{
    scanf("%d",&n);
    for(i = 1;i <= n;i++)
        scanf("%d",&a[i]);
	sum[1]=a[1];
	for(i=2;i<=n;i++)
        sum[i] = sum[i-1] + a[i];
    for(len = 2;len <= n;len++)
    {
        for(i = 1;i <= n + len - 1;i++)
        {
            j = i + len - 1;
            if(j>n)
            	break;
            for(k =i;k <= j - 1;k++)
            {
                if(dp[i][j] != 0)
					dp[i][j] = min(dp[i][j],dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1]);
                else
					dp[i][j] = dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1];
            }
        }
    }
    printf("%lld",dp[1][n]);
}

Measured memory_bytes: 2968
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
m=v[a-1]
mm=v.count(m)
cnt=0
for i in range(n):
    if v[i]>m:
        cnt+=1
    else:
        break

def fact(n):
    if n==0 or n==-1:
        return 1
    return fact(n-1)*n
def comb(n,k):
    return fact(n)//fact(n-k)//fact(k)

    
ans=0
#print('mm,cnt',mm,cnt)
for i in range(min(mm+cnt-a,b-a+cnt)+1):
    ans+=comb(mm,a-cnt+i)
    #print(i,ans)
if m!=v[0]:
    ans=comb(mm,a-cnt)
print(sum(v[0:a])/a)
print(ans)


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	m := make(map[int]int)
	idx := 1
	m[n] = idx
	for {
		idx++
		if n % 2 == 0 {
			n = n / 2
		} else {
			n = 3 * n + 1
		}
		_, ok := m[n]
		if ok {
			fmt.Println(idx)
			return
		}
		m[n] = idx
	}
}

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


int main(){
  long long a,b,c,k,i;
  cin >> a >> b >> c >> k;
  long long ans=0;
  if(abs(a-b)>1000000000000000000){
    cout << "unfair" << endl;
  }else{
    if(k%2!=0){
      ans=a-b;
      ans=ans*(-1);
    }else{
      ans=a-b;
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> mp;
    vector<int> l(n);
    rep (i, n) cin >> l[i];
    sort(l.begin(), l.end());
    ll ans = 0;
    rep (i, n) {
        FOR (j, i + 1, n) {
            auto iter = lower_bound(l.begin() + j + 1, l.end(), l[j]);
            if ((l[i] < l[j] + *iter) && (l[j] < l[i] + *iter) && (*iter < l[i] + l[j])) {
                ans += l.end() - iter;
                auto itr = lower_bound(l.begin() + j + 1, l.end(), l[i] + l[j]);
                ans -= l.end() - itr;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
vector<ll>divisor_enum(ll n){
  vector<ll>ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      if(i*i==n)ret.PB(i);
      else{
        ret.PB(i);
        ret.PB(n/i);
      }
    }
  }
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  res+=divisor_enum(n-1).size();
  res--;
  auto v=divisor_enum(n);
  for(auto z:v){
    ll k=n;
    if(z==1)continue;
    //cout<<k spa z<<endl;
    while(k%z==0)k/=z;
    if(k%z==1)res++;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    long long ans = 0;
    for (int i = 1; i <= N; i++) {
        string s = to_string(i);
        int sum = 0;
        for (int j = 0; j < (int)s.size(); j++) {
            sum += (int)(s[j] - '0');
        }
        if (A <= sum && sum <= B) {
            ans += i;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s,t;
int main(){
    cin>>s>>t;
    int n = s.size();
    for(int i=0;i<n;i++){
        int flg = 1;
        for(int j=0;j<n;j++){
            if(s[j]!=t[(i+j)%n]){
                flg=0;break;
            }
        }
        if(flg){
            cout<<"Yes"<<'\n';
            return 0;
        }
    }
    cout<<"No"<<'\n';
    return 0;
}


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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

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

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}



 
int main() {
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;

  string ans = "";

  rep(i, 0, N){
    ans += S[i];
    ans += T[i];
  }

  cout << ans << endl;

  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 256
from math import gcd

def setwise_coprime_check_fun(A_list, N):
    gcd_all = A_list[0]
    for i in range(N - 1):
        gcd_all = gcd(gcd_all, A_list[i + 1])
        if gcd_all == 1:
            break
    return gcd_all

def preprocess_fun(A_max):
    p_flg = [True] * (A_max + 1)
    D = [0] * (A_max + 1)
    p_flg[0] = False
    p_flg[1] = False
    for i in range(2, A_max + 1, 1):
        if p_flg[i]:
            for j in range(i, A_max + 1, i):
                p_flg[j] = False
                D[j] = i
    return D

def pairwise_coprime_check(A_list, D, A_max):
    p_count = [0] * (A_max + 1)
    for A in A_list:
        temp = A
        d = 0
        while temp != 1:
            if p_count[D[temp]] == 1 and d != D[temp]:
                return 0
            p_count[D[temp]] = 1
            d = D[temp]
            temp = temp // D[temp]
    return 1

## 標準入力
N = int(input())
A_list = list(map(int, input().split(" ")))

# 整数の最大値を取得
A_max = max(A_list)

# 本体
if(setwise_coprime_check_fun(A_list, N) != 1):
    print("not coprime")
else:
    D = preprocess_fun(A_max)
    if pairwise_coprime_check(A_list, D, A_max) == 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")

Measured memory_bytes: 134708
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    int A, B, C;
    A = X;
    B = Y;
    C = Z;

    cout << Z << " "<< X << " " <<Y;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, c, k, arr[100005], range, capacity=0, count=0;
    cin >> n >> c >> k;
    for(int i=1; i<=n; i++){
        cin >> arr[i];
    }
    sort(arr+1, arr+n+1);
    range=arr[1]+k;
    capacity++;
    count++;
    for(int i=2;i<=n;i++){
        if(arr[i]<=range && capacity<c) {
            capacity++;
        }
        else{
            range=arr[i]+k;
            capacity=1;
            count++;
        }
    }
    cout <<count;
    return 0;
}


Measured memory_bytes: 3904
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans;

int main(void) {
    char s, t;
    cin >> s;
    if (isupper(s)) t = 'A';
    else t = 'a';
    cout << t << endl;

    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
bool validate_odd(char c) {
  // cout << c;
  if(c == 'R' || c == 'U' || c == 'D') {
    // cout << c;
    return true;
  }
  else return false;
}
bool validate_even(char c) {
  if(c == 'L' || c == 'U' || c == 'D') return true;
  else return false;
}

int main() {
  bool flag = true;
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++) {
    
    if(i % 2 == 1) {
      if(!validate_even(s[i])) flag = false;
    } else {
      if(!validate_odd(s[i])) flag = false;
    }
    // cout << flag;
  }
  if(flag) cout << "Yes\n";
  else cout << "No\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  // 頂点数と辺数
  int N, M;
  cin >> N >> M;
  vector<int> check(N, 1);

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // BFS のためのデータ構造
  vector<int> dist(N, -1);  // 全頂点を「未訪問」に初期化
  queue<int> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0] = 0;
  que.push(0);  // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    int v = que.front();  // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv : G[v]) {
      if (dist[nv] != -1) continue;  // すでに発見済みの頂点は探索しない

      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv] = dist[v] + 1;
      check[nv] = v + 1;
      que.push(nv);
    }
  }

  // 結果出力 (各頂点の頂点 0 からの距離を見る)
  cout << "Yes" << endl;
  for (int v = 1; v < N; ++v) cout << check[v] << endl;
}


Measured memory_bytes: 10624
"""
A - Still TBD
"""

from datetime import datetime as dt


def solve():
    target_day = dt.strptime(input(), '%Y/%m/%d')
    limit_day = dt(2019, 4, 30)
    if target_day > limit_day:
        print('TBD')
    else:
        print('Heisei')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 4592
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,a,b = gi
puts min a*n,b


Measured memory_bytes: 2556
n = int(input())
l = list(map(int,input().split()))

nums = set([])
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if l[i] == l[j] or l[i] == l[k] or l[j] == l[k]:
                continue
            else:
                ver = [l[i],l[j],l[k]]
                num = [i,j,k]
                ver.sort()
                num.sort()
                if ver[0] + ver[1] > ver[2]:
                    nums.add(tuple(num))

print(len(nums))


Measured memory_bytes: 31012
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }

inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }



int main()
{
    long long int n,a,b,ans=0;
    cin>>n>>a>>b;
    ans=a*(n/(a+b));
    n=n%(a+b);
    if(n>=a)
        ans+=a;
    else ans+=n;
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n ;
      cin >> n;
      bool b=false;
      for(int i=0;i<n;i++){
        string c;
        cin >>c;
        if (c=="Y")b=true;
      }
      if(b) cout<<"Four"<<endl;
      else cout<<"Three";
        
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

int main()
{
	int k=read();
	if (k<=500)
	{
		cout << k << endl;
		for (int i=1;i<=k;i++)
		{
			for (int j=1;j<=k;j++)
				cout << j << " ";
			cout << endl;
		}
		return 0;
	}
	cout << 500 << endl;
	int a[505][505]={0};
	for (int i=1;i<=500;i++)
	{
		for (int j=1;j<=500;j++)
			a[i][j]=(i+j-2)%500+1;
	}
	for (int i=501;i<=k;i++)
	{
		for (int j=1;j<=500;j++)
		{
			if (j&1)
				a[(i-j+500-2)%500+1][j]=i;
		}
	}
	for (int i=1;i<=500;i++)
	{
		for (int j=1;j<=500;j++)
			cout << a[i][j] << " ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
import copy

def main():
	N = int(input())
	X = [int(x) for x in input().split(" ")]
	sortedX = copy.deepcopy(X)
	sortedX.sort()
	cand = [sortedX[int(N / 2) - 1], sortedX[int(N / 2)]]

	for xi in X:
		if xi <= cand[0]:
			print(cand[1])
		else:
			print(cand[0])

main()


Measured memory_bytes: 32508
#include<cstdio>
int main()
{
    int a,b,m;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        m=a*b;
        if(m%2==1)
            printf("Odd\n");
        if(m%2==0)
            printf("Even\n");
    }
    return 0;
}


Measured memory_bytes: 128
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

#define int long long

int t, n, p;
const int N = 2e5+50;

int pre[N];

int cnt[N];
char s[N];
int len[N];

int bin(int a, int b, int p) {
    int res = 1;
    for (a%=p; b; b>>=1, a=a*a%p)
        if (b & 1)
            res = res * a % p;
    return res;
}

int check() {
    int ans = 0;
    for (int i=1; i<=n; ++i)
        for (int j=i; j<=n; ++j) {
            int res = 0;
            for (int k=i; k<=j; ++k)
                res = (res * 10 + s[k] - '0') % p;
            // dbg(i, j, res);
            ans += res == 0;
        }
    return ans;
}

signed main() {
    // code

    scanf("%lld%lld%s", &n, &p, s+1);

    if (p == 2 || p == 5) {
        LL ans = 0;
        for (int i=1; i<=n; ++i) {
            if ((s[i] - '0') % p == 0)
                ans += i;
        }
        cout << ans << endl;
        return 0;
    }
    // pre[0] = 1;
    for (int i=1; i<=n; ++i)
        pre[i] = (pre[i-1] * 10 + s[i] - '0') % p;
    int inv10 = bin(10, p-2, p);
    // dbg(inv10);

    len[0] = 1;
    for (int i=1; i<=n; ++i)
        len[i] = len[i-1] * inv10 % p;
    for (int i=1; i<=n; ++i) {
        ++cnt[pre[i] * len[i] % p];
        // dbg(i, pre[i]);
    }


    LL ans = cnt[0];
    // dbg(ans);
    --cnt[pre[1] * len[1] % p];
    for (int i=2; i<=n; ++i) {
        ans += cnt[pre[i-1] * len[i-1] % p];
        --cnt[pre[i] * len[i] % p];
    }
    cout << ans << endl;
    // cout << check() << endl;
    // dbg(check());
    return 0;
}


Measured memory_bytes: 4864
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    D, X = li_input()

    eaten = 0

    for i in range(N):
        a = int(input())
        eaten += math.ceil(D / a)

    print(eaten + X)


main()


Measured memory_bytes: 5140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
        }
        for(int i=0; i<n; i++) {
            b[i] = in.nextInt();
        }
        for(int i=0; i<n-1; i++) {
            c[i] = in.nextInt();
        }

        int s = 0;
        int prev = Integer.MIN_VALUE;
        for(int i=0; i<n; i++) {
            s += b[a[i]-1];
            if(prev+1 == a[i]) {
                s += c[prev-1];
            }
            prev = a[i];
        }
        System.out.println(s);
    }
}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 枚数の入力
		int K = sc.nextInt();
		// 合計金額の入力
		int X = sc.nextInt();
		
		// 出力
		if(K*500 >= X){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int min1 = a;
	int min2 = b;
	if (a >= b) {
		min1 = b;
		min2 = a;
	}
	if (c <= min1) {
		min2 = min1;
		min1 = c;
	}
	if (min1 < c&&c <= min2) {
		min2 = c;
	}
	cout << min1 + min2;
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

for i in range(10**n):
  i2=str(i)
  if len(i2)==n and all([i2[s-1]==str(c) for s,c in sc]):
      print(i2)
      exit()
print(-1)

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

int main() {

    while (1) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0)
            break;

        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                for (int k = j + 1; k <= n; ++k) {
                    if (i + j + k == x)
                        ++ans;
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;
    ll lg=0,sm=0;

    int n;
    cin >>n;
    vector<int> a(n);

    rep(i,n)cin>>a[i];
    sort(all(a),greater<int>());

    if(n%2==0){
        ll big=0,small=0;

        rep(i,(n/2)-1){
            big += a[i]*2;
        }
        big += a[(n/2)-1];
        small += a[n/2];

        rep1(i,n/2+1,n){
            small += a[i]*2;
        }

        ans = abs(big-small);

    }else{

        ll ans1=0,ans2=0;
        ll big=0,small=0;

        rep(i,n/2)big += a[i]*2;
        small += a[n/2]+a[(n/2)+1];
        rep1(i,(n/2)+2,n)small += a[i]*2;

        ans1 = abs(big-small);

        reverse(all(a));

        big = 0; small = 0;

        rep(i,n/2)big += a[i]*2;
        small += a[n/2]+a[(n/2)+1];
        rep1(i,(n/2)+2,n)small += a[i]*2;

        ans2 = abs(big-small);

        ans = max(ans1,ans2);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, Q;
    cin >> N >> Q;

    string s;
    cin >> s;
    ll L = s.size();

    vector<ll> A(N);

    FOR(i, 1, L){
        A[i] = A[i-1];
        if(s[i-1]=='A' && s[i]=='C'){
            A[i]++;
        }
    }
    // vprint(A);

    FOR(i, 0, Q){
        ll left, right;
        cin >> left >> right;
        left--;
        right--;

        ll num;
        if(left>0){
            // if(s[left]=='C'){
            //     num = A[right] - A[left];
            // }
            // else if(s[left]=='A'){
            //     num = A[right] - A[left];
            // }
            // else{

            // }
            num = A[right] - A[left];
        }else{
            num = A[right];
        }
        p(num);
    }
    
    return 0;
}

Measured memory_bytes: 1872
from fractions import gcd
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if a < b or d < b:
        print("No")
        continue
    if c >= b-1:
        print("Yes")
        continue
    g = gcd(b, d)
    print("Yes" if b + a%g - g <= c else "No")

Measured memory_bytes: 5048
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
import itertools
a = list(itertools.permutations(range(1,N+1)))
for i in range(0,len(a)):
    if a[i] == P:
        s = i
    if a[i] == Q:
        t = i
print (abs(s-t))

Measured memory_bytes: 8052
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<time.h>
#include<sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f3f3f;
//const ll mod=;

//map<string,ll> m;
//map<ll,ll> m;

//set<ll> s;

//vector<ll> v;

//ios_base::sync_with_stdio(0); cin.tie(0);

//scanf("%lld",&t);
//scanf("%lld%lld",&,&);

//cout<<  <<"\n";
//cout<<fixed<<setprecision()<<;

//ll n,m,t,a,x,ans,res;
ll n,x,a[2010],b[2010];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];b[i]=a[i];
	}
	ll minn=INF;
	for(int k=0;k<n;k++)
	{
		ll sum=k*x;
		for(int j=0;j<n;j++)
		{
			b[(j+k)%n]=min(b[(j+k)%n],a[j]);
			sum+=b[(j+k)%n];
		}
		minn=min(sum,minn);
	}
	cout<<minn<<endl;
	return 0;
}





//ll powmod(ll a,ll b)     //快速幂 
//{
//	ll tmp=a;
//	ll ans=1;
//	while(b)
//	{
//		if(b&1)ans=ans*tmp%mod;
//		tmp=tmp*tmp%mod;
//		b>>=1;
//	}
//	return ans%mod;
//}


//bool is_prime(ll a)     //判断素数 
//{
//	if(a==2)return 1;
//	else if(a==1||a%2==0)return 0;
//	else
//	{
//		for(ll i=3;i*i<=a;++i)
//		{
//			if(a%i==0)return 0;
//		}
//	}
//	return 1;
//}









Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
   
int countFreq(string &pat, string &txt) 
{ 
    int M = pat.length(); 
    int N = txt.length(); 
    int res = 0; 
    
    /* A loop to slide pat[] one by one */
    for (int i = 0; i <= N - M; i++) 
    {  
        /* For current index i, check for  
           pattern match */
        int j; 
        for (j = 0; j < M; j++) 
            if (txt[i+j] != pat[j]) 
                break; 
   
        // if pat[0...M-1] = txt[i, i+1, ...i+M-1] 
        if (j == M)   
        { 
           res++; 
           j = 0; 
        } 
    } 
    return res; 
} 
    
/* Driver program to test above function */
int main() 
{ 
   string txt ;
    int n;
    cin>>n>>txt;
   string pat = "ABC"; 
   cout << countFreq(pat, txt); 
   return 0; 
}

Measured memory_bytes: 256
import java.util.*
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val sc = Scanner(System.`in`)
    val N = 2*sc.nextInt()
    var Larray: Array<Int> = Array(N, { sc.nextInt()})
    var LList:MutableList<Int> = mutableListOf()
    Larray.sort()
    for (l in Larray)
    {
      LList.add(l)
    }
    var sum:Int=0
    while (!LList.isEmpty())
    {
      val k = LList.take(2)
      sum+=LList.take(2).min()!!
      for (i in k)
      {
       LList.remove(i)
      }
    }
    println(sum)
  }
}


Measured memory_bytes: 20612
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printf("%d %d\n", min(b, c), b + c > a ? c + b - a : 0);
	
	Please AC;
}


Measured memory_bytes: 256
def is_matched(i, inputS, T):
  for s,t in zip(inputS, T):
    if s == '?': continue
    if s != t: return False
  return True

S, T = input(), input()
lenS, lenT = len(S), len(T)
matched_i = None
ans = []
for i in range(lenS-lenT+1):
  if is_matched(i, S[i:i+lenT], T):
    tmpS = S.replace('?', 'a')
    ans.append(''.join([s for s in S[:i].replace('?', 'a') + T + S[i+lenT:].replace('?', 'a')]))
if ans == []: print('UNRESTORABLE')
else: print(sorted(ans)[0])

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
 
const ll INF = 2e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod){ll x=1;while(b){while(!(b&1)){(a*=a)%=mod;b>>=1;}(x*=a)%=mod;b--;}return x;}
void YES(bool cond){ if(cond){ p("YES");}else{ p("NO");} return;}
void Yes(bool cond){ if(cond){ p("Yes");}else{ p("No");} return;}


ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}


bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k, ans;

ll x[500005], y[500005], z[500005];
ll dp[5005][5005];
string s;

ll mul(ll a, ll b){
    if(b == 0)return 0;
    if(a > INF / b){
        return INF;
    }else{
        return a * b;
    }
}

void solve(){
    cin >> a >> b;
    p(a * b);

    return;
}


int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}
















Measured memory_bytes: 3612
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int H,W;
    cin >> H >> W;
    char S[H][W];
    int dist[H][W];
    int bcnt = 0;
    for(int i = 0;i < H;i++)for(int j = 0;j < W;j++){
        cin >> S[i][j];
        dist[i][j] = INF;
        if(S[i][j] == '#')bcnt++;
    }
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    dist[0][0] = 0;
    queue<pair<int,int> >que;
    que.push(make_pair(0,0));
    while(!que.empty()){
        auto q = que.front();
        int x = q.first, y = q.second;
        que.pop();
        for(int i = 0;i < 4;i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= W || ny < 0 || ny >= H)continue;
            if(S[ny][nx] == '#')continue;
            int ndist = dist[y][x] + 1;
            if(dist[ny][nx] > ndist){
                dist[ny][nx] = ndist;
                que.push(make_pair(nx, ny));
            }
        }
    }
    int ans;
    if(dist[H-1][W-1] == INF)ans = -1;
    else{
        ans = H*W - dist[H-1][W-1] - 1 - bcnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def dup(A, B):
    r = 0
    for x in A:
        if x in B:
          r = r + 1
    return r-1 if r != 0 else 0


a, b, c, d = (int(i) for i in input().split())

A = range(a, b+1)
B = range(c, d+1)

result = dup(A, B) if len(A) <= len(B) else dup(B, A)

print(result)


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int n1,n2,S[10000],T[100000];
  int i,j,count=0;

  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%d",&S[i]);

  }
  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&T[i]);

  }
  for(i=0;i<n2;i++){
    for(j=0;j<n1;j++){
      if(T[i]==S[j]){count++;break;}
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
vector<int> g[110000];
int memo[110000];
int dp(int now){
    if(g[now].size() == 0)return 0;
    if(memo[now])return memo[now];
    int ret = 0;
    for(auto next:g[now]){
        ret = max(ret,dp(next));
    }
    return memo[now] = ret+1;
}
signed main(){
    int n,m;cin >> n >> m;
    rep(i,m){
        int a,b;cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
    }
    int ret = 0;
    rep(i,n)ret = max(ret,dp(i));
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 11984
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<long long, long long>>A(N), C(M);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i).first >> A.at(i).second;
	}
	for (int j = 0; j < M; j++) {
		cin >> C.at(j).first >> C.at(j).second;
	}
	long long manhattan = 9999999999;
	vector<int>ans(N);
	for (int i = 0; i < N; i++) {
		manhattan = 9999999999;
		for (int j = 0; j < M; j++) {
			long long length = abs(A.at(i).first - C.at(j).first) + abs(A.at(i).second - C.at(j).second);
			if (manhattan > length) {
				ans.at(i) = j + 1;
				manhattan = length;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans.at(i) << endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int m = Integer.parseInt(tokenizer.nextToken());
        tokenizer = new StringTokenizer(input.readLine());
        int [] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = Integer.parseInt(tokenizer.nextToken());
        }
        Arrays. sort(values);
        long sum = 0;
        for (int i = n - 1; i >= n - m; i--) {
            sum += values[i];
        }
        System.out.println(sum);
    }
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/d.in", "r", stdin);
//  freopen("../IO/d.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int N = (int)2e5 +15496;
constexpr int mod = (int)1e9 + 7;
vector<int> g[N];
int fac[N+1],ifac[N+1], ans[N], dp[N], sz[N],n;

int powmod(int64_t a, int64_t b) {
  int64_t res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

void init() {
  fac[0] = ifac[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = (int64_t) fac[i - 1] * i % mod;
  }
  ifac[N - 1] = powmod(fac[N - 1], mod - 2);
  for (int i = N - 2; i >= 1; --i) {
    ifac[i] = (int64_t) ifac[i + 1] * (i + 1) % mod;
  }
}

void dfs1(int v, int p = -1) {
  int prod = 1;
  for (int u : g[v]) if (u != p) {
    dfs1(u, v);
    prod = (int64_t) prod * dp[u] % mod * ifac[sz[u]] % mod;
    sz[v] += sz[u];
  }
  sz[v] += 1;
  dp[v] = (int64_t) prod * fac[sz[v] - 1] % mod;
}

void dfs2(int v, int a, int p = -1) {
  ans[v] = (int64_t) dp[v] * a % mod * ifac[sz[v] - 1] % mod;
  for (int u : g[v]) {
    if (u != p) {
      dfs2(u, (int64_t) ans[v] * fac[sz[u]] % mod * powmod(dp[u], mod - 2) % mod * ifac[n - sz[u]] % mod * fac[n - sz[u] - 1] % mod, v);
    }
  }
}

void solve(std::istream &in, std::ostream &out) {
  init();
  in >> n;
  for (int i = 0, a, b; i < n - 1; ++i) {
    in >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(0);
  dfs2(0, 1);
  for (int i = 0; i < n; ++i) {
    out << (int64_t)ans[i]*fac[n-1]%mod << '\n';
  }
}



Measured memory_bytes: 18420
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define F(i,n) for(int i=0;i<n;i++)
#define VE(i,v) for(int i = 0;i < (v).size();i++)
using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned int ui;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll; 


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	
	
	

	for(int tc = 0; tc < T; tc++)
	{
		string s, t;
		cin>>s>>t;
		vvi dp(sz(s)+1, vi(sz(t)+1));
		for(int i=1; i <= sz(s); i++)
		{
			for(int j =1; j <= sz(t); j++)
			{
				if(s[i-1]==t[j-1])
				{
					dp[i][j] = dp[i-1][j-1]+1;
				}
				else
				{
					if(dp[i-1][j] > dp[i][j-1])
					{
						dp[i][j] = dp[i-1][j];
					}
					else
					{
						dp[i][j] = dp[i][j-1];
					}
				}
			}
		}
		int ux = sz(s);
		int uy = sz(t);
		string ans="";
		while((ux!=0) &&(uy!=0))
		{
			//cout<<ux<<" "<<uy<<" "<<ans<<"\n";
			if(s[ux-1]==t[uy-1])
			{
				ans += s[ux-1];
				ux = ux-1;
				uy = uy-1;
			}
			else if(dp[ux][uy] == dp[ux-1][uy])
			{
				ux = ux-1;
			}
			else
			{
				uy = uy-1;
			}
		}

		reverse(all(ans));








		
		cout<<ans<<"\n";
	}

 
 
 
	return 0;
}
 
 


Measured memory_bytes: 35584