akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> job(N);
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        job[i] = {A, B};
    }
    
    sort(job.begin(), job.end());
    int ans = 0, cnt = 0;
    priority_queue<int> pq;
    REP(i, M + 1) {
        while (cnt < N) {
            if (job[cnt].first == i) {
                pq.push(job[cnt].second);
                ++cnt;
            } else {
                break;
            }
        }
        if (pq.size()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int a, b, c ;
  cin >> a >> b >> c ;
  
  cout <<a*b/2<<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#define pb push_back
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    int a;
    if(n&1) a = n/2+1;
    else a = n/2;
    cout << fixed << setprecision(10) << (double)a/n << endl;

}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    static long power(int n){
      long ans = 1;
      long x = 2L;
      while(n!=0){
        if(n%2==1){
          ans = ans * x % 1000000;
          n -= 1;
        }
        else{
          x = x * x % 1000000;
          n /= 2;
        }
      }
      return ans;
    }
          
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int p = 1000000;
        if(m==1){
          System.out.println(power(n));
        }
        else{
          int[][] dp = new int[n][5];
          dp[0][0] = 3;
          dp[0][1] = 3;
          dp[0][2] = 2;
          dp[0][3] = 1;
          dp[0][4] = 4;
          for(int i=1; i<n; i++){
            dp[i][0] = (((dp[i-1][0] + dp[i-1][1])%p + dp[i-1][3])%p + dp[i-1][4])%p;
            dp[i][1] = ((dp[i-1][0] + dp[i-1][1])%p +  dp[i-1][4])%p;
            dp[i][2] = (dp[i-1][0] + dp[i-1][2])%p;
            dp[i][3] = (dp[i-1][3] + dp[i-1][4])%p;
            dp[i][4] = (((dp[i-1][0] + dp[i-1][1])%p + dp[i-1][2])%p + dp[i-1][4])%p;
          }
          System.out.println(dp[n-1][4]%p);
        }
      }
  }


Measured memory_bytes: 26340
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::{HashSet,HashMap};
#[allow(unused_imports)]
use std::cmp::{min,max};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin 
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input!{
        x:usize,
        a:usize,
        b:usize,
    }
    if b <= a {
        println!("delicious");
    } else if b <= a + x {
        println!("safe");
    } else {
        println!("dangerous");
    }
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct Coord{
    int x,y;
};

int main() {
    ll H,W,D; cin >> H >> W >> D;

    vector<Coord> A(H*W+1);
    REP(i,H){
        REP(j,W){
            int a; cin >> a;
            A[a].x = i;
            A[a].y = j;
        }
    }

    vector<ll> cost(H*W+1,0);

    FOR(i,1,H*W){
        if(i+D<=H*W){
            cost[i+D] += cost[i] + abs(A[i+D].x - A[i].x) + abs(A[i+D].y - A[i].y);
        }
    }

    int Q; cin >> Q;
    REP(i,Q){
        int L,R; cin >> L >> R;
        cout << cost[R] - cost[L] << endl;
    }

    return 0;
}

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

int n;
int memo[2][2] = {0};
int cnt[100005][2] = {0}, mnum;

int main() {
  cin >> n;
  mnum = n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ++cnt[x][i % 2];
    if(cnt[x][i % 2] >= cnt[memo[i % 2][0]][i % 2] &&
       memo[i % 2][0] != x) {
      memo[i % 2][1] = memo[i % 2][0];
      memo[i % 2][0] = x;
    }
  }
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j) {
      if(memo[0][i] != memo[1][j])
        mnum = min(mnum, n - cnt[memo[0][i]][0] -
                             cnt[memo[1][j]][1]);
    }
  cout << mnum << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXP=100050;
PII p[MAXP];
int H, W, N;
ll ans[15];
vector<PII> check;

void f(int x,int y) {
	int cnt=0;
	for(int dx=0;dx<=2;dx++)
		for(int dy=0;dy<=2;dy++)
			if(binary_search(p,p+N,MP(x+dx,y+dy)))
				cnt++;
	debug("%d,%d  %d\n",x,y,cnt);
	ans[cnt]++;
}

int main() {
	scanf("%d%d%d",&H,&W,&N);
	for(int i=0;i<N;i++) scanf("%d%d",&p[i].F, &p[i].S);
	sort(p, p+N);
	for(int i=0;i<N;i++)
		for(int dx=-2;dx<=0;dx++)
			for(int dy=-2;dy<=0;dy++)
				check.PB(MP(p[i].F+dx, p[i].S+dy));
	sort(ALL(check));
	for(int i=0;i<SZ(check);i++) {
		int x=check[i].F, y=check[i].S;
		if(x<=0 || x+2>H || y<=0 || y+2>W) continue;
		if(i>0 && check[i]==check[i-1]) continue;
		f(x,y);
	}
	ll all=1ll*(H-2)*(W-2);
	ans[0]=all;
	for(int i=1;i<=9;i++) ans[0]-=ans[i];
	for(int i=0;i<=9;i++) printf("%lld\n",ans[i]);
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main(int argc, char const *argv[]) {
  int i,j;
  double eps=1e-6;
  while(1){
    int n;
    cin >>n;
    if(n==0) break;

    vector<double> x(n),y(n);
    rep(i,n) scanf(" %lf,%lf", &x[i], &y[i]);

    int ans=0;
    for(double X=0; X<=10; X+=0.01){
      for(double Y=0; Y<=10; Y+=0.01){
        int tmp=0;
        rep(i,n){
          if(pow(X-x[i],2)+pow(Y-y[i],2) < 1.0+eps)
            ++tmp;
        }
        ans=max(ans,tmp);
      }
    }

    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int main(){
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		int a=max(x,y);
		int b=min(x,y);
		sum+=a-b+1;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

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

void solve() {
    ll N, A, B, C, D;
    cin >> N;
    cin >> A >> B >> C >> D;
    map<ll, ll> mp;
    priority_queue<l_l> que;
    que.push({N, 0});
    while(!que.empty()) {
        l_l tmp = que.top();
        ll now = tmp.first;
        que.pop();
        if(mp.count(now) == 0 or mp[0] > mp[now] + mul(now, D)) {
            mp[0] = mp[now] + mul(now, D);
        }
        ll tmp1 = now % 2;
        ll c = mp[now] + tmp1 * D + A;
        ll to = (now - tmp1) / 2;
        //cerr << now << "->" << to << endl;
        if(mp.count(to) == 0 or mp[to] > c) {
            mp[to] = c;
            que.push({to, c});
        }
        tmp1 = (2 - tmp1) % 2;
        c = mp[now] + tmp1 * D + A;
        to = (now + tmp1) / 2;
        //cerr << now << "->" << to << endl;
        if(mp.count(to) == 0 or mp[to] > c) {
            mp[to] = c;
            que.push({to, c});
        }
        tmp1 = now % 3;
        c = mp[now] + tmp1 * D + B;
        to = (now - tmp1) / 3;
        //cerr << now << "->" << to << endl;
        if(mp.count(to) == 0 or mp[to] > c) {
            mp[to] = c;
            que.push({to, c});
        }
        tmp1 = (3 - tmp1) % 3;
        c = mp[now] + tmp1 * D + B;
        to = (now + tmp1) / 3;
        //cerr << now << "->" << to << endl;
        if(mp.count(to) == 0 or mp[to] > c) {
            mp[to] = c;
            que.push({to, c});
        }
        tmp1 = now % 5;
        c = mp[now] + tmp1 * D + C;
        to = (now - tmp1) / 5;
        //cerr << now << "->" << to << endl;
        if(mp.count(to) == 0 or mp[to] > c) {
            mp[to] = c;
            que.push({to, c});
        }
        tmp1 = (5 - tmp1) % 5;
        c = mp[now] + tmp1 * D + C;
        to = (now + tmp1) / 5;
        //cerr << now << "->" << to << endl;
        if(mp.count(to) == 0 or mp[to] > c) {
            mp[to] = c;
            que.push({to, c});
        }
    }
    /*
    for(auto tmp : mp) {
        cerr << tmp.first << " " << tmp.second << endl;
    }
    */
    cout << mp[0] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T;
    cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 4592
import math
def getinputdata():

    array_result = []

    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if (data != ""):

                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

power = 1

print(math.factorial(n) % (10 ** 9 + 7))

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
    char C;
    cin>>C;
    ll k=C-'A';
    if(k<=25){
      cout<<'A'<<endl;
      return 0;
    }
  	cout<<'a'<<endl;
}

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

int n;
int p[7];

int main()
{
	cin >> n;

	while (n) {
		memset(p, 0, sizeof(p));

		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;

			a /= 10;

			if (a > 5)
				p[6]++;
			else
				p[a]++;
		}

		for (int i = 0; i < 7; i++)
			cout << p[i] << endl;

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3000
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp
#?´???°??????
#x????´???°y???2 < y < sqrt(x)??????????????¨??????

from math import sqrt,ceil

def check_prime_number(n):
    sqrt_num = ceil(sqrt(n))
    
    if n == 2:
        return True
    elif n < 2:
        return False
    elif (n % 2) == 0:
        return False
    div = 3
    while div <= sqrt_num:
        if (n % div) == 0:
            return False
        div += 2
        
    return True

def count_prime_numbers(n_list):
    ans = 0
    for n in n_list:
        if check_prime_number(n):
            ans += 1
    return ans

def main():
    num = int(input())
    target_list = [int(input()) for i in range(num)]
    print(count_prime_numbers(target_list))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 7952
///----> bismillahir rahmanir rahim <---- -- { ^ _ ^ }
///     { ^_^ }   { ^ _ ^ }
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;

//<--------------------------------------------typo section--------------------------------------------->
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
typedef priority_queue<int>piwi;
typedef queue<int>kiwi;
typedef map<int,int>mi;
typedef map<string,int>mis;
typedef multimap<int,int>muli;
typedef multimap<string,int>muls;
typedef multiset<int>si;

//<----------------------------------------------------Narcos----------------------------------------------->
#define endl "\n"
#define Y cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define sp " "
#define PB push_back
#define F first
#define S second
#define as(a) (a).begin(),(a).end()
#define ras(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define ki 1LL
#define MOD 1000000007
#define over return 0;
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define test int t;cin>>t;while(t--)


//<-----------------------------------------------------Const--------------------------------------------------->
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


//<--------------------------------------------------------------------------------------------------->
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for(int j=0;j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
int man_seive(int n){ manipulated_seive(n); for(int i=0;i<prime.size() && prime[i]<=n;i++)
cout<<prime[i]<<endl;
}
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }

//continue;

//-----------------------------> YOUR JOURNEY STARTS HERE ------------------------------------>>

int main(){
    optimize();
    int x;
    cin>>x;
    if(x==0){
        cout<<1<<endl;

    }
    else{
        cout<<0<<endl;
    }

over
}


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

int main()
{
  int N, K;
  int h[110000];
  int res=0;
  cin >> N >> K;

  rep(i,N) cin >> h[i];

  sort(h,h+N);

  int diff[110000];

  rep(i,N-K+1){
    diff[i] = h[i+K-1]-h[i];
  }

  sort(diff, diff+N-K+1);

  cout << diff[0] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;

  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll maxi = a[0];
  ll ans = 0;

  for (int i = 1; i < n; i++) {
    if (a[i] < maxi) {
      ans += maxi - a[i];
    } else {
      maxi = a[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4744
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int [] num = new int[10];
        for (int i = 0; i < 4; ++i) {
            int n = scanner.nextInt();
            num[n]++;
        }
        if (num[1] == 1 && num[9] == 1 && num[7] == 1 && num[4] == 1) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int T, X;
    cin >> T >> X;
    cout << (double)T / (double)X << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
b=""
a=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(len(s)):
   for j in range(26):
       if s[i]==a[j]:
           b+=a[j+n-26]
print(b)

Measured memory_bytes: 41692
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = b/x-a/x;
    if(a%x == 0) {
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string tmp;
  cin >> tmp;
  vector<int> a(4);
  for(int i = 0; i < 4; ++i){
    a[i] = tmp[i] - '0';
  }

  int res = 0;
  for(int i = 0; i < 1 << 4; ++i){
    int res = a[0];
    for(int j = 1; j < 4; ++j){
      int op = (i >> j) & 1;
      if(op) res += a[j];
      else res -= a[j];
    }
    if(res == 7){
      cout << a[0];
      for(int j = 1; j < 4; ++j){
	int op = (i >> j) & 1;
	if(op) cout << "+" << a[j];
	else cout << "-" << a[j];
      }
      break;
    }
  }
  cout << "=7"<<  endl;
  
  
}


Measured memory_bytes: 256
let func w h n =
  let rec f xl xr yl yr cnt =
    if cnt == n then (xl, xr, yl, yr)
    else
      let x, y, a = Scanf.scanf "%d %d %d\n" (fun a b c -> a, b, c)
      in
      match a with
    | 1 -> f (max xl x) xr yl yr (cnt+1)
    | 2 -> f xl (min xr x) yl yr (cnt+1)
    | 3 -> f xl xr (max y yl) yr (cnt+1)
    | 4 -> f xl xr yl (min y yr) (cnt+1)
    | _ -> raise @@ Sys_error "error"
  in f 0 w 0 h 0

let calc (xl, xr, yl, yr) =
  if xl > xr || yl > yr then 0
  else (xr - xl) * (yr - yl)

let () =
  let w, h, n = Scanf.scanf "%d %d %d\n" (fun a b c -> a, b, c)
  in func w h n
  |> calc
  |> print_int
  |> print_newline


Measured memory_bytes: 512
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import itertools

N = int(readline())
P = tuple(map(int, readline().split()))
Q = tuple(map(int, readline().split()))

per = itertools.permutations(range(1, N+1))
for i, seq in enumerate(per):
    if seq == P:
        p_index = i + 1
    if seq == Q:
        q_index = i + 1

ans = abs(p_index - q_index)
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
    #define M 1000000007
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define mem0(a) memset(a,0,sizeof(a))
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    using namespace std;
    int main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=0;
    	cin>>t;
    	cout<<(t/500)*(1000)+((t-(t/500)*500)/5)*5;
    	return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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()
typedef long long ll;
using namespace std;

int main(){
    string s;
    cin >> s;
   
   sort(s.begin(),s.end());

   if(s[0] == s[1] && s[2]==s[3] && s[1] != s[2]){
       cout << "Yes" <<endl;
   }else{
       cout << "No" <<endl;
   }



    return 0;
}

Measured memory_bytes: 256
#volume0 0003
N = int(input())
for i in range(N):
    x , y , z= map(int,input().split())
    if x > y:
        min = x
        x = y
        y = min
    if y > z:
        mid = y
        y = z
        z = mid
    if x > y:
        min = x
        x = y
        y = min
    if z**2 == x**2 + y**2:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5596
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) {
		Reader rd = new Reader();
		int n = rd.nextInt();
		int w = rd.nextInt();
		int[][] list = new int[n+1][3];
		int flag = 0;
		for(int nn=1; nn<=n; nn++){
			list[nn][1] = rd.nextInt();
			list[nn][2] = rd.nextInt();
		}
		long[][] dp = new long[n+1][w+1];
		
		for(int i=1; i<=n; i++){
			for(int j=1; j<=w; j++){
				
				//System.out.println("list[i][1] : " + list[i][1] + " j : " + j);
				if(list[i][1] <= j){
					//System.out.println(dp[i-1][j]  + " " + dp[i-1][j-list[i][1]] + list[i][2]); 
 					dp[i][j] = Math.max(dp[i-1][j] , dp[i-1][j-list[i][1]] + list[i][2]);
				}
				else{
					//System.out.println("here");
					dp[i][j] = dp[i-1][j];
				}
				//System.out.println(Arrays.toString(dp[i]));
			}
		}
		/*
		for(long[] i : dp){
			System.out.println(Arrays.toString(i));
		}
		* */
		System.out.println(dp[n][w]);
	}

	static void sort(int[] ar){
		ArrayList<Integer> ls = new ArrayList<>();
		for(int i=0; i<ar.length; i++) ls.add(ar[i]);
		Collections.sort(ls);
		for(int i =0; i<ls.size(); i++) ar[i] = ls.get(i);
	}
}

class Reader { 
	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer tok = new StringTokenizer("");
	static String next() {
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(bf.readLine());
			}
			catch(IOException e) {
				e.printStackTrace();
			}
		}
		return tok.nextToken();
	} 
	static int nextInt() {
		return Integer.parseInt(next());
	}
}


Measured memory_bytes: 135324
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

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

  cout << n - (k - 1) << endl;

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

static const double pi = 3.14159265358979323846;

int main(){
  int x, a, b;
  cin >> x >> a >> b;

  if(abs(x-a) < abs(x-b)) cout << "A" << endl;
  else cout << "B" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    while(1)
    {
        int w,h;
        cin>>w>>h;if(!w)return 0;
        long long dp[101][101][4]={{{0}}};
        dp[2][1][0]=1;
        dp[1][2][1]=1;
        for(int i=1;i<=h;++i){
            for(int j=1;j<=w;++j){
                if(dp[i][j][0]){
                    if(i!=h){
                        dp[i+1][j][0]+=dp[i][j][0];
                        dp[i+1][j][0]%=100000;
                    }
                    if(j!=w){
                        dp[i][j+1][3]+=dp[i][j][0];
                        dp[i][j+1][3]%=100000;
                    }
                }
                if(dp[i][j][1]){
                    if(i!=h){
                        dp[i+1][j][2]+=dp[i][j][1];
                        dp[i+1][j][2]%=100000;
                    }
                    if(j!=w){
                        dp[i][j+1][1]+=dp[i][j][1];
                        dp[i][j+1][1]%=100000;
                    }
                }
                if(dp[i][j][2]){
                    if(i!=h){
                        dp[i+1][j][0]+=dp[i][j][2];
                        dp[i+1][j][0]%=100000;
                    }
                }
                if(dp[i][j][3]){
                    if(j!=w){
                        dp[i][j+1][1]+=dp[i][j][3];
                        dp[i][j+1][3]%=100000;
                    }
                }
            }
        }
        long long ans=0;
        for(int i=0;i<4;++i){
            ans+=dp[h][w][i];
        }
        cout<<ans%100000<<endl;
    }
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    string S;
    cin >> S;
    YES(15 - S.size() + character_count(S, 'o') >= 8);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
namespace AOJ
{
    class Program
    {

        
        //private static string solve(int n)
        //{
        //    string[,] cnvTbl = new string[,]{
        //        {"7","9"}
        //        ,{"6","8"}
        //        ,{"5","7"}
        //        ,{"4","5"}
        //    };

        //    string str8 = Convert.ToString(n, 8);
            
        //    for (int i = 0; i < cnvTbl.GetLength(0);i++ )
        //    {
        //        str8 = str8.Replace(cnvTbl[i, 0], cnvTbl[i, 1]);
        //    }
        //    return str8;
        //}
        private static void solve(int n)
        {
            char[,] cnvTbl = new char[,]{
                {'7','9'}
                ,{'6','8'}
                ,{'5','7'}
                ,{'4','5'}
            };

            string str8 = Convert.ToString(n, 8);

            char[] char8 = str8.ToCharArray();
            
            for (int j = 0; j < char8.Length; j++)
            {
                for (int i = 0; i < cnvTbl.GetLength(0); i++)
                {
                    if (cnvTbl[i, 0] == char8[j])
                    {
                        char8[j] = cnvTbl[i, 1];
                        break;
                    }
                }
            }
            for (int i = 0; i < char8.Length; i++) Console.Write(char8[i]);
            Console.WriteLine();
        }
        static void Main(string[] args)
        {

            while (true) {
                int n  = int.Parse(Console.ReadLine());
                if (n == 0) break;
                solve(n);
            }
        }
    }
}

Measured memory_bytes: 5592
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using vv = vector<V<T>>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  string s;
  cin >> n >> s;
  int r = 0,b = 0;
  REP(i,n){
    if(s[i]=='R') ++r;
    else ++b;
  }
  cout << (r>b?"Yes":"No") << endl;
}



Measured memory_bytes: 256
import itertools
H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]
A = [[0 for _ in range(W)] for _ in range(H)]


def dfs(p, q):
    if A[p][q] == 1:
        return 0
    count = {'#': 0, '.': 0}
    stack = [[p, q]]
    while stack:
        x, y = stack.pop()
        if A[x][y] != 1:
            count[S[x][y]] += 1
            A[x][y] = 1
            dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and S[x][y] != S[nx][ny]:
                    stack += [[nx, ny]]
    return count['#'] * count['.']


print(sum([dfs(i, j) for i, j in itertools.product(range(H), range(W))]))


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

int main()
{
    int n;
    cin >> n;
    bool p, w, g, y = false;
    for (int i = 0; i < n; i++)
    {
        string color;
        cin >> color;
        if (color == "P")
            p = true;
        else if (color == "W")
            w = true;
        else if (color == "G")
            g = true;
        else if (color == "Y")
            y = true;
    }
    if (p && w && g && y)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}

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

int n,m;

vector<vector<int> > vl;

bool findEndPoint(int idx,vector<bool> &v,int pre=-1){
	if(v[idx]){
		return false;
	}
	v[idx] = true;
	if(pre != -1 && vl[idx].size() == 1){
		return true;
	}

	if(vl[idx][0] == pre){
		return findEndPoint(vl[idx][1],v,idx);
	}
	else{
		return findEndPoint(vl[idx][0],v,idx);
	}
}
bool loopNotExist(int idx,vector<bool> &v){
	if(vl[idx].size() == 0){
		return true;
	}
	if(vl[idx].size() == 1){
		return findEndPoint(idx,v);
	}
	bool b1 = findEndPoint(vl[idx][0],v,idx);
	bool b2 = findEndPoint(vl[idx][1],v,idx);
	return b1 && b2;
}

// no branch, no loop
int main(){
	while(scanf("%d%d",&n,&m), !(n==0 && m==0)){
		vl = vector<vector<int> >(n); // adj list
		for(int i = 0; i < n; i++){
			vl[i] = vector<int>();
		}
		for(int i = 0; i < m; i++){
			int u,v;
			scanf("%d%d",&u,&v);
			u--;
			v--;
			vl[u].push_back(v);
			vl[v].push_back(u);
		}
		if(m >= n){
			cout << "no" << endl;
			continue;
		}
		
		// check branch
		bool ok = true;
		for(int i = 0; i < n; i++){
			if(vl[i].size() > 2){
				ok = false;
				break;
			}
		}
		if(!ok){
			cout << "no" << endl;
			continue;
		}


		// check loop
		vector<bool> visited = vector<bool>(n,false);
		int idx = 0;
		while(idx < n){
			if(!visited[idx]){
				ok = loopNotExist(idx,visited);
				if(!ok){
					break;
				}
			}
			idx++;
		}
		if(ok){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 8080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    int x;
    cin >> x;
    if ( x == 1 ) {
        cout << 1 << endl;
        return 0;
    }
    int ans = 0;
    for ( int i = 2; i < x; i++ ) {
        int tmp_num = i * i;
        bool ok = false; 
        while ( 1 ) {
            if ( tmp_num > x ) {
                tmp_num /= i;
                break;
            }
            ok = true;
            tmp_num *= i;
        }
        if ( ok ) ans = max(ans, tmp_num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    string s;
    cin >> n >> s;
    vector<int> cnt1(n + 1), cnt2(n + 1);
    rep(i, n)
    {
        if (s[i] == '.')
            cnt1[i + 1]++;
        else
            cnt2[i + 1]++;
    }
    rep(i, n) cnt1[i + 1] += cnt1[i], cnt2[i + 1] += cnt2[i];
    int ans = INF;
    rep(i, n) ans = min(ans, cnt2[i] - cnt2[0] + cnt1[n] - cnt1[i + 1]);
    cout << ans << endl;
}

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


ll dp[555][101];
string str;
int ans=200005,wh[200005]={},b[200005]={},n;
int main() {
	cin>>n;
	cin>>str;
	rep(i,0,n){
		if(str[i]=='.')b[i+1]++;
		else wh[i+1]++;
		b[i+1]+=b[i];
		wh[i+1]+=wh[i];
	}
	rep(i,0,n+1){
		ans=min(ans,wh[i]+b[n]-b[i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

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

    // abc/x = (ax*d + k)*(bx*e + l)*(cx*f + m) = gx + klm
    long long int power = 1;
    for (int i = 1; i <= n; i++) {
        power *= i % 1000000007;
        if (power/1000000007 != 0) {
            power %= 1000000007;
        }
    }

    cout << power << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;


int main(){
    int n;
    cin >> n;
    int A[1000010];
    bool B[1000010];
    for (int i = 0; i < 1000010; i++) {
        B[i] = true;
    }
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    int a = 1, cnt = 0;
    while(B[a]){
        B[a] = false;
        a = A[a];
        cnt++;
        if(a==2){
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


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

int main() {
    ll N;
    cin >> N;
    vector<pair<ll,ll>> V(N);
    for (ll i = 0; i < N; i++) {
        cin >> V.at(i).first >> V.at(i).second;
    }

    vector<ll> W(N);
    vector<ll> X(N);

    for (ll j = 0; j < N; j++) {
        W.at(j) = V.at(j).first + V.at(j).second;
    }

    for (ll k = 0; k < N; k++) {
        X.at(k) = V.at(k).first - V.at(k).second;
    }
    sort(W.begin(),W.end());
    sort(X.begin(),X.end());
    
    cout << max(W.at(N-1)-W.at(0),X.at(N-1)-X.at(0)) << endl;
}


Measured memory_bytes: 9572
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <iomanip>
using namespace std;
constexpr int64_t INF = 1LL << 60;


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

  int32_t N;
  cin >> N;
  vector<int64_t> A(N+1);
  for (auto& a : A) {
    cin >> a;
  }
  int64_t cnt = 0;
  vector<pair<int64_t,int64_t>> range(N+1);
  range[0].second = 1;
  if (N == 0 && A[0] != 1) {
    goto NG;
  } else if (N == 0) {
    cout << 1 << endl;
    return 0;
  } else if (N != 0 && A[0] != 0) {
    goto NG;
  } else {
    range[0].first = 1;
  }

  for (int d = 1; d < N; d++) {
    range[d].first = max(1L, range[d-1].first);
    range[d].second = min((range[d-1].second - A[d-1]) * 2, INF);
    if (range[d].second <= A[d]) {
      goto NG;
    }
  }
  // d == N
  if (A[N] > (range[N-1].second - A[N-1]) * 2) {
    goto NG;
  } else {
    range[N].first = A[N];
    range[N].second = A[N];
  }

  cnt = A[N];
  for (int d = N-1; d >= 0; d--) {
    int64_t ch = range[d+1].second;
    if (A[d] + (ch + 1) / 2 > range[d].second) {
      goto NG;
    } else {
      if (ch <= range[d].second - A[d]) {
        cnt += ch + A[d];
        range[d].second = (ch + A[d]);
      } else {
        cnt += range[d].second;
      }
    }
  }
  cout << cnt << endl;
  return 0;
 


NG:
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 5568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define offset 
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 223455
ll D;
ll m;
map<ll,ll> ways;
ll vexp[tam],pot[tam];
ll f(ll pos,ll D2)
{
    if (pos==m)
    {
        return (D2==D);
    }
    ll formas=0;
    ll maxx=-9,minn=9;
    forr(delt,-9,10)
    {
        if (D2+vexp[pos]*delt<=D)
            maxx=delt;
        if (D2+vexp[pos]*delt>D)
            minn=min(minn,delt);
    }
    formas+=f(pos+1,minn*vexp[pos]+D2)*ways[minn];
    if (maxx!=minn)
    formas+=f(pos+1,maxx*vexp[pos]+D2)*ways[maxx];
    return formas;
}
ll go(ll digs)
{
    m=(digs/2);
    //cout<<digs<<' '<<m<<": ";
    forr(i,0,m)
    {
        vexp[i]=(pot[digs-1-i]-pot[i]);
        //cout<<vexp[i]<<" ";
    }
    //cout<<endl;
    ll total=0;
    forr(i,-9,10)
    {
        total+=f(1,vexp[0]*i)*(ways[i]-1);
        //cout<<total<<" "<<i<<' '<<ways[i]-1<<endl;
    }
    if (digs%2==1)
        total= total*10;
        return total;
}
int  main()
{
    forr(i,0,10)
    {
        forr(j,0,10)
        {
            ways[i-j]++;
        }
    }
    
    pot[0]=1;
    forr(i,1,19)
        pot[i]=pot[i-1]*10;
    cin>>D;
    ll formas=0;
    forr(digs,2,19)
    {
        formas+=go(digs);
        //cout<<formas<<'\n';
    }
    cout<<formas<<endl;
}
// PLUS ULTRA!ac

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
n = int(input())
class Node:
  def __init__(self,v):
    self.p = None
    self.key = v
    self.left = None
    self.right = None

sys.setrecursionlimit(1500)
r = None
def insert(z):
  global r
  y = None
  x = r
  while x != None:
    y = x
    if z.key < x.key:
      x = x.left
    else:
      x = x.right
  z.p = y

  if y == None:
    r = z
  elif z.key < y.key:
    y.left = z
  else:
    y.right = z

ret = []
def inorder(r):
  if r == None: return
  inorder(r.left)
  ret.append(r.key)
  inorder(r.right)

def preorder(r):
  if r == None: return
  ret.append(r.key)
  preorder(r.left)
  preorder(r.right)

for i in range(n):
  s = input()
  if s[0]=="i":
    insert(Node(int(s.split()[1])))
  else:
    ret = []
    inorder(r)
    print(""," ".join(map(str,ret)))
    ret = []
    preorder(r)
    print(""," ".join(map(str,ret)))


Measured memory_bytes: 143992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> ans(n, 1);
    rep(i, 0, n-1) {
        if(s[i]=='R' && s[i+1]=='R') {
            ans[i+2] += ans[i];
            ans[i] = 0;
        }
    }
    for(ll i=n-1; i >= 1; --i) {
        if(s[i]=='L' && s[i-1]=='L') {
            ans[i-2] += ans[i];
            ans[i] = 0;
        }
    }
    rep(i, 0, n) cout << ans[i] << " ";
    cout << endl;
}

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

int main()
{
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < q; i++) {
        int u, v;
        cin >> u >> v;
        if(n == 1) {
            cout << min(u, v) << endl;
        }
        else {
            if(u == 1 || v == 1) {
                cout << 1 << endl;
                continue;
            }
            while(u != v) {
                if(u < v) v = (v + n - 2) / n;
                else u = (u + n - 2) / n;
            }
            cout << u << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main(){
    int n, k, q;
    cin >> n;
    cin >> k;
    cin >> q;
    vector<int> member(n, 0);
    for(int i = 0; i < q; i++){
        int a;
        cin >> a;
        ++member[a - 1];
    }
    for(int l = 0; l < n; l++){
        if(k - q + member.at(l) <= 0){
            cout << "No\n";
        }else{
            cout << "Yes\n";
        }
    }
}

Measured memory_bytes: 1152