akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO
using namespace std;

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

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

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

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, M;
    cin >> N >> M;
    vector<Pii> dems(M);
    for (ll i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        dems[i] = make_pair(a, b);
    }
    sort(dems.begin(), dems.end());

    ll ans = 0;
    ll rmn = dems[0].second;
    for (ll i = 1; i < M; i++) {
        ll l, r;
        tie(l, r) = dems[i];
        if (l >= rmn) {
            ++ans;
            rmn = r;
        }
        else {
            rmn = min(rmn, r);
        }
    }

    ++ans;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=-1
for i in range(10**3):
    if (len(str(i))==n):
        flag=1
        for s,c in sc:
            if str(i)[s-1] != str(c):
                flag=0
        if flag==1:
            ans =i
            break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	int n;
	string s;

	cin >> n;

	while(n--){
		int imax, imin;
		cin >> s;
		sort(s.begin(), s.end());
		imin = atoi(s.c_str());
		reverse(s.begin(), s.end());
		imax = atoi(s.c_str());

		cout << imax - imin << endl;
	}


	return 0;
} 

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

typedef long long ll;

ll Gcd(ll a, ll b) {
    if (b == 0) return a;
    else return Gcd(b, a%b);
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = Gcd(a, b);
    vector<int> Ans;
    for (int i = 2; i <= sqrt(ans); i++) {
        if (ans % i == 0) {
            Ans.push_back(i);
            do{
                ans = ans / i;
            }while (ans % i == 0);
        }
    }
    if (ans > 1) Ans.push_back(ans);
    cout << (int)Ans.size() + 1 << endl;
    return 0;
}


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

int main(){
  int N,M;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++){
    cin >> T.at(i);
  }
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for (int i = 0; i < M; i++){
    cin >> P.at(i) >> X.at(i);
  }
  int ans = 0;
  for (int i = 0; i < M; i++){
    for (int j = 0; j < N; j++){
      if (j == (P.at(i) - 1)){
        ans += X.at(i);
      }
      else{
        ans += T.at(j);
      }
    }
    cout << ans << endl;
    ans = 0;
  }
}


Measured memory_bytes: 256
class int(int):  
  def times(self, callback):
    for times in range(0,self):
      callback()

class list(list):
  def maps(self, callback):
    return list(map(callback, self))

  def each(self, callback):
    list(map(callback, self))
    return self

  # index will sent to the function as a second parameter.
  def each_with_index(self,callback):
    list(map(callback, self, range(0,len(self))))
    return self

n, k = input().split()
n = int(n)
k = int(k)

p = list(input().split())

def convert(arg):
    return int(arg)
nums = p.maps(convert)

nums.sort()
print(sum(nums[0:k]))


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

ac = 0
wa = 0

hist_ac = [0] * N
hist_wa = [0] * N
for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if hist_ac[p] == 0:
        if s == 'AC':
            hist_ac[p] = 1
            ac += 1
            wa += hist_wa[p]
        else:
            hist_wa[p] += 1

print(ac, wa)


Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll n, a, b;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	string s; cin >> s;
	cin >> a;
	n = (int)s.size();

	vector<string> list;
	rep(i, 0, n) {
		rep(j, 1, a + 1) {
			list.push_back(s.substr(i, j));
		}
	}
	sort(list.begin(), list.end());
	list.erase(unique(list.begin(), list.end()), list.end());

	cout << list[a - 1] << endl;
	return 0;
}

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

long long gcd(int m, int n) {
    if((0 == m) || (0 == n)) return 0;
    while(m != n) {
        if(m > n) m = m - n;
        else n = n - m;
    }
    return m;
}

long long lcm(int m, int n) {
    if((0 == m) || (0 == n)) return 0;
    return((m / gcd(m, n)) * n);
}

int main() {
    vector<int> v1;
    vector<int> v2;
    while(cin) {
        int a, b;
        cin >> a >> b;
        v1.push_back(a);
        v2.push_back(b);
    }
    for(int i=0; i<v1.size() - 1;i++) {
        cout << gcd(v1[i], v2[i]) << " " << lcm(v1[i], v2[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>

#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
 
using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n';
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
    #define eprintf(...) 42
#endif

clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll INF = (ll)1e18;
ll MOD;

ll add(ll x, ll y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
ll sub(ll x, ll y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
ll mul(ll x, ll y) {
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(x, bin_pow(x, p - 1));
    return bin_pow(mul(x, x), p / 2);
}

const int N = 2000100;
ll W, H;
vector <pll> q;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    startTime = clock();
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    cin >> W >> H;
    for (int i = 0; i < W; ++i) {
        int x;
        cin >> x;
        q.pb({x, 0});
    }
    for (int i = 0; i < H; ++i) {
        int x;
        cin >> x;
        q.pb({x, 1});
    }
    
    sort(q.begin(), q.end());
    ll ans = 0;
    ++H; ++W;
    for (auto [val, type] : q) {
        if (type) {
            ans += W * val;
            --H;
        }
        else {
            ans += H * val;
            --W;
        }
    }
    cout << ans << endl;
    
    return 0;
}


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

int main() {
  int D;
  cin>>D;
  vector<int> sage(26);
  for(int i=0;i<26;i++){
    cin>>sage.at(i);
  }
  vector<vector<int>> man(D,vector<int>(26));
  for(int i=0;i<D;i++){
    for(int j=0;j<26;j++){
      cin>>man.at(i).at(j);
    }
  }
  vector<int> hini(D);
  vector<vector<int>> rkai(D+1,vector<int>(26,1));
  for(int i=0;i<D;i++){
    int A=0,W=man.at(i).at(0)-5*rkai.at(i).at(0)*sage.at(0);
    for(int j=1;j<26;j++){
      int Y=man.at(i).at(j)-5*rkai.at(i).at(j)*sage.at(j);
      if(Y>W){
        W=Y,A=j;
      }
      rkai.at(i+1).at(j)=rkai.at(i).at(j)+1;
    }
    hini.at(i)=A;
    rkai.at(i).at(A)=0;
    rkai.at(i+1).at(A)=1;
  }
  /*for(int i=0;i<D;i++){
    Z+=man.at(i).at(hini.at(i));
    for(int j=0;j<26;j++){
      Z-=rkai.at(i).at(j)*sage.at(j);
    }
    cout<<Z<<endl;
  }*/
  int a=167,b=167;
  for(int i=0;i<3000000;i++){
    a=i%D;
      b=i%26;
      int Z=0;
    if(rkai.at(a).at(b)==0){
      continue;
    }
    int K=rkai.at(a).at(b),C=0;
    for(int j=a;j<D;j++){
      if(rkai.at(j).at(b)==0){
        break;
      }
      else{
        C++;
      }
    }
    Z+=K*C*sage.at(b);
    Z+=man.at(a).at(b);
    int e=hini.at(a);
    C=0;
      int G;
    if(a==0){
      G=1;
    }
    else{
      G=rkai.at(a-1).at(e)+1;
    }
    for(int j=a;j<D;j++){
      if(rkai.at(j).at(e)==0&&j!=a){
        break;
      }
      else{
        C++;
      }
    }
    Z-=G*C*sage.at(e);
    Z-=man.at(a).at(e);
      if(Z>0){
        for(int j=a;j<D;j++){
      if(rkai.at(j).at(b)==0){
        break;
      }
      else{
        rkai.at(j).at(b)-=K;
      }
    }
        for(int j=a;j<D;j++){
      if(rkai.at(j).at(e)==0&&j!=a){
        break;
      }
      else{
        rkai.at(j).at(e)+=G;
      }
    }
        hini.at(a)=b;
      }
    }
  
    
  for(int i=0;i<D;i++){
    cout<<hini.at(i)+1<<endl;
  }
}


Measured memory_bytes: 3744
/*
title:C - Attention

url:

尺取り法で解く
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans[n] = {};
    for (int i = 1; i < n; i++)
    {
        if (s[i] == 'E')
            ans[0]++;
    }

    for (int i = 1; i < n; i++)
    {
        ans[i] = ans[i - 1];
        if (s[i] == 'E')
            ans[i]--;
        if (s[i - 1] == 'W')
            ans[i]++;
    }

    cout << *min_element(ans, ans + n) << endl;
}

Measured memory_bytes: 1796
#include <stdio.h>
#include <string.h>

#define N 100000

int main() {
	static char s[N + 1];
	int n, i, k0;

	scanf("%s", s);
	n = strlen(s);
	k0 = 0;
	for (i = 0; i < n; i++)
		if (s[i] == '0')
			k0++;
	printf("%d\n", (k0 < n - k0 ? k0 : n - k0) * 2);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unordered_set<ll> set;
#define N 100010
#define D 40
ll n;
vector<ll> g[N];
set solve(ll x,ll from){
  ll cnt[D]; for(int i=0;i<D;i++)cnt[i]=0;
  for(auto y:g[x])if(y!=from){
    for(auto z:solve(y,x))cnt[z]++;
  }
  ll clash=-1;
  for(ll i=0;i<D;i++){
    if(cnt[i]>=2)clash=i;
  }
  ll gen;
  for(ll i=clash+1;;i++){
    if(cnt[i]==0){gen=i; break;}
  }
  set res; res.insert(gen);
  for(ll i=gen+1;i<D;i++){
    if(cnt[i]>0)res.insert(i);
  }
  return res;
}
int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    ll a,b;cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  set res=solve(1,0);
  ll ans=0;
  for(auto x:res)ans=max(ans,x);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 39936
//
// Created by Md Rashedul Islam on 6/21/2020.
//

#include <bits/stdc++.h>

using namespace std;

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

//    freopen("../in", "r", stdin);

    int n, k;
    cin >> n >> k;

    vector<int> cost_list(n);
    for (int &i : cost_list)
    {
        cin >> i;
    }
    sort(cost_list.begin(), cost_list.end());

    int ans = 0;
    for (int i = 0; i < k; ++i)
    {
        ans += cost_list[i];
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

struct WF{
  void solve(vector<vector<pair<int, ll> > >&G, vvl&v){
    int n = sz(G);
    v.resize(n);
    FOR(i, 0, n){
      v[i] = vl(n);
      fill(v[i].begin(), v[i].end(), linf);
    }
    FOR(i, 0, n){
      each(itr, G[i]){
        v[i][itr->fi] = itr->se;
      }
      v[i][i] = 0;
    }
    FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n) mins(v[i][j], v[i][k] + v[k][j]);
  }
};

typedef pair<int, ll> T;
typedef vector<T> vt;
vector<vt> G;

int n, m, a, b;
ll c;
vvl v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  G.resize(n);
  FOR(i, 0, m){
    cin >> a >> b >> c;
    a--; b--;
    G[a].pb(mp(b, c));
    G[b].pb(mp(a, c));
  }
  WF wf;
  wf.solve(G, v);
  ll ans = 0;
  FOR(i, 0, n) each(itr, G[i]) if(v[i][itr->fi] < itr->se) ans++;
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 384
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


h, w = LI()
s = SRL(h)
ans = []
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        v = [[-1] * w for _ in range(h)]
        q = deque()
        q.append((i, j))
        v[i][j] = 1
        goal = tuple()
        while q:
            r, c = q.popleft()
            for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)):
                if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0:
                    continue
                v[r + x][c + y] = v[r][c] + 1
                q.append((r + x, c + y))
        ans.append(max(chain.from_iterable(v)) - 1)
print(max(ans))


Measured memory_bytes: 76080
s=gets.chomp
t=s[0...-1]
if s[0]=='0'||s[-1]=='1'||t!=t.reverse
  p -1
  exit
end
s[-1]='1'
q=[]
s.size.times{|i|q<<i if s[i]=='1'}
(s.size-1).times{|i|q.shift if i==q[0];puts [i+1,q[0]+1]*' '}

Measured memory_bytes: 4348
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define acc(v) accumulate(v.begin(), v.end(),0);
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

//桁和
int digit_sum(int n){
   if(n < 10)  return n;
   return digit_sum(n/10) + n%10;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int res = inf;
  reps(a,1,n/2+1) {
    int b = n - a;
    int sum = digit_sum(a) + digit_sum(b);
    res = min(res, sum);
  }
  cout << res << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
fn main() {
    let (h, n): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut ws = buf.split_whitespace();
        let h = ws.next().unwrap().parse().unwrap();
        let n = ws.next().unwrap().parse().unwrap();
        (h, n)
    };
    let mut a: Vec<i32> = vec![0; n];
    let mut b: Vec<i32> = vec![0; n];

    for i in 0..n {
        let (x, y): (i32, i32) = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut ws = buf.split_whitespace();
            let x = ws.next().unwrap().parse().unwrap();
            let y = ws.next().unwrap().parse().unwrap();
            (x, y)
        };
        a[i] = x;
        b[i] = y;
    }
    let mut dp: Vec<i32> = vec![100000000; h + 10];
    dp[0] = 0;
    for i in 1..(h + 1) {
        for j in 0..n {
            let x = std::cmp::max(0, i as i32 - a[j]) as usize;
            dp[i] = std::cmp::min(dp[i], dp[x] + b[j]);
        }
    }
    println!("{}", dp[h]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if((a==1&&b==2)||(a==2&&b==1))
	cout<<3;
	if((a==3&&b==2)||(a==2&&b==3))
	cout<<1;
	if((a==1&&b==3)||(a==3&&b==1))
	cout<<2;
	return 0;
}

Measured memory_bytes: 256
/*
4 個の数字 N1,N2,N3,N4 が与えられます．これらを並べ替えて 1974 という数字の列を作ることが出来るかを判定してください．
 */

#include <iostream>
#include <vector>

int main(int argc, char const *argv[])
{
    int n[4];
    for (int i=0; i<4; ++i) {std::cin >> n[i];}

    std::vector<int> N;
    N.resize(4*3*2*1);
    int count = 0;
    int answer = 1974;
    for (int a=0; a<4; ++a)
    {
        for (int b=0; b<4; ++b)
        {
            if (a!=b)
            {
                for (int c=0; c<4; ++c)
                {
                    if (a!=c && b!=c)
                    {
                        for (int d=0; d<4; ++d)
                        {
                            if (a!=d && b!=d && c!=d)
                            {
                                N[count] = n[a]*1000 + n[b]*100 + n[c]*10 + n[d];
                                ++count;
                            }
                        }
                    }
                }
            }
        }
    }
    
    bool check = false;
    for (int i=0; i<N.size(); ++i)
    {
        if (answer == N[i]) 
        {
            check = true;
        }
    }
    if (check) {std::cout << "YES" << std::endl;}
    else {std::cout << "NO" << std::endl;}

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B; cin >> A >> B;
    if (A - 2*B > 0) cout << A - 2*B << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		
		for(int i = n; i < 1000; i++) {
			if(i % 111 == 0) {
				System.out.println(i);
				return;
			}
			
			
		}
		
		
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
using ll = long long;

constexpr ll mod = 1e9 + 7;

ll mpow(ll x, ll n){
  if(n <= 0) return 1;
  ll res = mpow(x * x % mod, n / 2);
  if(n % 2) res *= x % mod;
  return res % mod;
}

ll combination_2(ll n){
  return n * (n-1) / 2 % mod;
}

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

  int a[n], c[n], q[n];
  for(int i=0; i<n; i++){
    a[i] = c[i] = q[i] = 0;
  }

  if(s[0] == 'A') a[0] = 1;
  if(s[0] == 'C') c[0] = 1;
  if(s[0] == '?') q[0] = 1;

  for(int i=1; i<n; i++){
    if(s[i] == 'A') a[i]++;
    if(s[i] == 'C') c[i]++;
    if(s[i] == '?') q[i]++;

    a[i] += a[i-1];
    c[i] += c[i-1];
    q[i] += q[i-1];
  }

  ll ans = 0;
  for(int i=1; i<n-1; i++){
    if(s[i] == 'B' || s[i] == '?'){
      ll al = a[i-1], cr = c[n-1] - c[i];
      ll ql = q[i-1], qr = q[n-1] - q[i];
      ans += al * cr % mod * mpow(3, ql) % mod * mpow(3, qr) % mod;
      ans %= mod;
      ans += ql * qr % mod * mpow(3, ql-1) % mod * mpow(3, qr-1) % mod;
      ans %= mod;
      ans += al * qr % mod * mpow(3, ql) % mod * mpow(3, qr-1) % mod;
      ans %= mod;
      ans += ql * cr % mod * mpow(3, ql-1) % mod * mpow(3, qr) % mod;
      ans %= mod;
    }
  }

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


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    double t1,t2;
    double a1,a2;
    double b1,b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll ans = 0;
    if((a1 > b1 && a2 >= b2) || (b1 > a1 && b2 >= a2)){
        cout << ans << endl;
        return 0;
    }else if(t1*a1 + t2*a2 == t1*b1 + t2*b2){
        cout << "infinity" << endl;
        return 0;
    }else if((a1 > b1 && t1*a1 + t2*a2 > t1*b1 + t2*b2) || (a1 < b1 && t1*a1 + t2*a2 < t1*b1 + t2*b2)){
        cout << ans << endl;
        return 0;
    }else{
        ans += 1;
        if(b1 > a1){
            swap(a1,b1);    swap(a2,b2);
        }
        ll dif = (t2*b2 + t1*b1 - t2*a2 - t1*a1);
        ll dif2 = t1*(a1 - b1);
        if(dif2%dif == 0){
            ans += (dif2/dif-1)*2;
            ans += 1;
        }else{
            ans += (dif2/dif-1)*2;
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    info=[int(raw_input()) for _ in xrange(n)]
    sai=[int(raw_input()) for _ in xrange(m)]
    now=0
    cnt=0
    for i in xrange(m):
        cnt+=1
        now+=sai[i]
        if now>=n-1:
            print(cnt)
            break
        now+=info[now]
        if now>=n-1:
            print(cnt)
            break

Measured memory_bytes: 6400
#include<iostream>
#include<stdio.h>  

int main(void){
    int n, m;
    int a[100][100];
    int b[100],c[100] = {0};
    std::cin>>n>>m;
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++){
            std::cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        std::cin>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[i] =c[i]+a[i][j]*b[j];
        }
    }
    for (int i=0;i<n;i++){
           std::cout<<c[i]<<std::endl;
    }
     return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;


int main(void) {

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

  vector<int> c(100011, 0);
  for(int i=0; i<n; i++){
    c[ a[i] ]++;
    c[ a[i]+1 ]++;
    if( a[i] - 1 >= 0 ) c[ a[i]-1 ]++;
  }

  cout << *max_element(c.begin(), c.end()) << endl;

  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int n, m, i, j, Vector[100], Matrix[100][100], sum[100];

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

	for ( i = 0; i < n; i++){
		for ( j = 0; j < m; j++){
			scanf("%d", &Matrix[j][i]);
		}
		
	}
	for ( i = 0; i < m; i++){
		scanf("%d", &Vector[i]);
	}
	for ( i = 0; i < n; i++){
		for (j = 0; j < m; j++) {
			sum[i] += Matrix[j][i] * Vector[j];
		}
	}
	for ( i = 0; i < n; i++){
		printf("%d\n", sum[i]);
	}
}

Measured memory_bytes: 1884
while True:
 a,b=map(int, input().split())
 
 if a+b==0:
  break

 for i in range(a):
  for j in range(b):
   if i==0 or i==a-1 or j==0 or j==b-1:
    print('#',end='')
   else:
    print('.',end='')
  print()
 print()


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

int n , m , par[N];
vector<int> adj[N];
bool vis[N];

void bfs()
{
    queue<int> q;
    q.push(1) , vis[1]=1;
    while(q.size())
    {
        int node = q.front();
        for(auto ch : adj[node])
        {
            if (!vis[ch])
            {
                par[ch] = node;
                vis[ch]=1;
                q.push(ch);
            }
        }
        q.pop();
    }
}

int main()
{
    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin >> x >> y;
        adj[x].push_back(y) , adj[y].push_back(x);
    }

    bfs();
    cout << "Yes\n";
    for(int i=2; i<=n; i++)
        cout << par[i] << '\n';
  
    return 0;
}

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

ll solve(ll num);

ll t, n, a, b, c, d;
map<ll, ll> memo;
ll ans;

int main(){

    cin >> t;

    for (int i=0; i<t; ++i){
        //  条件ごとにmapをクリア
        memo.clear();
        cin >> n >> a >> b >> c >> d;

        //  再帰関数を呼び出し
        ans = solve(n);
        cout << ans << endl;
    }

    return 0;
}

ll solve(ll num){

    ll cost, l2, r2, l3, r3, l5, r5;

    // 再帰を抜ける処理
    if (num == 0) return 0;
    if (num == 1) return d;
    if (memo.count(num)) return memo.at(num);

    // 2, 3, 5で割り切れる数値に移動して商を計算
    // numが2, 3, 5で割り切れる値の場合は、numをそのままl(num), r(num)とする
    l2 = (num/2)*2;
    r2 = ((num+1)/2)*2;
    l3 = (num/3)*3;
    r3 = ((num+2)/3)*3;
    l5 = (num/5)*5;
    r5 = ((num+4)/5)*5;

    //  numまで操作dを実施した場合のコストで初期化
    //  costをn+dとするとオーバーフローするが、下だとオーバーフローしない
    //  なんでif処理が必要なのか理解できない・・・
    cost = 1e18;
    if (num < cost/d) cost = num*d;

    // コストを計算
    // 割った回数だけa, b, cをコストに加算、割り切れない分はdとして加算
    cost = min(cost, (llabs(num-l2))*d + a + solve(l2/2));
    cost = min(cost, (llabs(num-r2))*d + a + solve(r2/2));
    cost = min(cost, (llabs(num-l3))*d + b + solve(l3/3));
    cost = min(cost, (llabs(num-r3))*d + b + solve(r3/3));
    cost = min(cost, (llabs(num-l5))*d + c + solve(l5/5));
    cost = min(cost, (llabs(num-r5))*d + c + solve(r5/5));

    // 計算したコストをmapに記憶
    memo[num] = cost;

    return cost;
}

Measured memory_bytes: 4292
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 100005
using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
int n,num[maxn],k;
double pow_(double x,int y){
  double res = 1;
  for(int i = 1;i <= y;i++) res *= x;
  return res;
}
int main(){
  n = getint(), k = getint();
  double ans = 0;
  for(int i = k - 1;i >= 1;i--){
    if(i * 2 >= k) num[i] = 1;
    else num[i] = num[i << 1] + 1;
  }
  if(n >= k){
    for(int i = k;i <= n;i++) ans += 1.0 / n;
    for(int i = 1;i <= k - 1;i++){
      ans += pow_(0.5,num[i]) / n;
    }
  }else{
    for(int i = 1;i <= n;i++){
      ans += pow_(0.5,num[i]) / n;
    }
  }
  printf("%.12f\n",ans);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n, k;
  int a[50]={};
  cin >> n >> k;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a, a+n);
  reverse(a, a+n);
  int ans=0;

  for(int i=0; i<k; i++){
    ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int a,b,C;
  double S,L,h;

  scanf("%d %d %d",&a,&b,&C);

  S = (double)0.5 * (double)a * (double)b * (double)sin((double)C/180*M_PI);
  L = (double)a + (double)b + sqrt ( pow ( (double)a , 2 ) + pow ( (double)b , \
2) - 2 * (double)a * (double)b * cos((double)C/180*M_PI ) );
  h = (double)b * sin((double)C/180*M_PI);

  printf("%lf\n%lf\n%lf\n",S,L,h);

  return 0;
}

Measured memory_bytes: 684
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    string s;cin>>s;
    int Q;cin>>Q;
    vector<ll[2]> dp(N+1);
    vector<ll> c(N+1);
    REP(i,N){
        dp[i+1][0]=dp[i][0];
        dp[i+1][1]=dp[i][1];
        c[i+1]=c[i];
        if(s[i]=='M') dp[i+1][0]++;
        if(s[i]=='C'){
            dp[i+1][1]+=dp[i][0];
            c[i+1]++;
        }
    }
    REP(_,Q){
        int k;cin>>k;
        ll ans=0;
        REP(i,N) if(s[i]=='D'){
            int r=min(i+k,N);
            ans+=dp[r][1]-dp[i][1]-dp[i][0]*(c[r]-c[i]);
        }
        cout<<ans<<endl;
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll N;
vll dp;

ll search(vll& P){
  ll ans = 0;
  REP(i,N){
    ans += (P[i]-1)*dp[N-1-i];
    FOR(j,i+1,N){
      if(P[j]>P[i]) P[j]--;
    }
  }
  return ans;
}

int main(){
  IN(N);
  vll P(N), Q(N);
  REP(i,N) IN(P[i]);
  REP(i,N) IN(Q[i]);

  dp.resize(N,1);
  REP(i,N-1){
    dp[i+1] = (i+1)*dp[i];
  }

  ll ans1 = search(P);
  ll ans2 = search(Q);

  //printf("%lld %lld\n", ans1, ans2);
  printf("%lld\n", abs(ans1-ans2));


  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := make(map[string]struct{})
	for i := 0; i < n; i++ {
		ans[Scan()] = struct{}{}
	}
	if len(ans) == 4 {
		fmt.Println("Four")
	} else {
		fmt.Println("Three")
	}
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  int ans = 999999999;
  for(int i = 0; i < N - K + 1; i++){
    int dif = abs(x[i] - x[i+K-1]);
    int tmp = min(abs(x[i]) + dif, abs(x[i+K-1]) + dif);
    if(ans > tmp){
      ans = tmp;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3660
import sys
def solve():
    N, K = map(int, input().split(" "))
    heights = [int(c) for c in input().split(" ")]
    dp = [sys.maxsize] * N
    dp[0] = 0
    for i in range(1, N):
        for j in range(1, K+1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i-j] + abs(heights[i] - heights[i-j]))
            else:
                break
    print(dp[N-1])
solve() 

Measured memory_bytes: 52192
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    int d; cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26) cin >> s[i][j];
    vector<vector<int>> last(d, vector<int>(26));
    rep(i, d)rep(j, 26) last[i][j] = 0;
    vector<int> ans(d + 1, 0);
    int max_score;
    int max_con;
    int score, sum;
    rep(i, d){
        max_score = 0;
        rep(j, 26){
            sum = 0;
            rep(k, 26){
                if(k != j) sum += c[k] * ((i + 1) - last[i][k]);
            }
            score = s[i][j] - sum;
            if(max_score < score){
                max_score = score;
                max_con = j;
            }
        }
        last[i][max_con] = i + 1;
        ans[i] = max_con + 1;
    }
    rep(i, d) cout << ans[i] << endl;
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<double> a(n);
    double sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += 1 / a[i];
    }
    printf("%.7f\n", 1 / sum);
    return 0;
}


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

#define int long long

#define Vanya Unstoppable

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    string a;
    cin >> a;
    
    int cnt = 0, ans = 0;
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] == 'R') ++cnt;
        else cnt = 0;
        ans = max(ans, cnt);
    }
    
    cout << ans;
}


Measured memory_bytes: 3608
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
blue = sorted(blue, key=lambda x: x[0])

used = []
for i in range(N):
    c, d = blue[i]
    m, tmp = -1, -1
    for j in range(N):
        if j in used:
            continue
        a, b = red[j]
        if a < c and b < d:
            if b > m:
                m = b
                tmp = j
    if tmp != -1:
        used.append(tmp)
print(len(used))


Measured memory_bytes: 9212
import collections
n = int(raw_input())
cities = collections.deque(map(int, raw_input().split(' ')))
q = collections.deque(map(int, raw_input().split(' ')))
res = 0
p = 0
while(q):
	w = q.pop()
	if cities[-1]:
		m = min(w, cities[-1])
		cities[-1]-=m
		w -= m
		res += m
	cities.pop()
	if cities[-1]:
		m = min(w, cities[-1])
		cities[-1]-=m
		w -= m
		res += m
print res

Measured memory_bytes: 50004
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 2132
#C
import itertools
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(M)]

path = [(i+1) for i in range(N)]
p_list = list(itertools.permutations(path,N))

ans = 0
for pl in p_list:
    if pl[0] == 1:
        flag = 0
        for i in range(N-1):
            ab1 = [pl[i],pl[i+1]]
            ab2 = [pl[i+1],pl[i]]
            if ab1 in AB or ab2 in AB:
                pass
            else:
                flag = 1
                break
        if flag == 0:
            ans+=1
            
print(ans)

Measured memory_bytes: 8052
#include<stdio.h>
int minnum(int[], int);

int main(){
  int n, i, j, max, min;
  int R[200000];
  scanf("%d",&n);
  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&R[i]);
  }
  
  min = R[0];
  max = R[1] - R[0];
  for( i = 1 ; i < n ; ++i ){
    if( max < R[i]-min ) max = R[i]- min;
    if( min > R[i] ) min = R[i];
  }
  
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2576
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias DF = Tuple!(size_t, "idx", long, "up");

long[10^^5] BS, LS, US, SUM_D;
DF[10^^5] DFS;

void main()
{
    auto nx = readln.split.to!(long[]);
    auto N = nx[0];
    auto X = nx[1];

    long sum_d;
    foreach (i; 0..N) {
        auto blu = readln.split.to!(long[]);
        auto b = blu[0];
        auto l = blu[1];
        auto u = blu[2];
        BS[i] = b;
        LS[i] = l;
        US[i] = u;
        DFS[i] = DF(i, X * u - b * u + b * l);
        sum_d -= b * l;
    }

    sort!"a.up > b.up"(DFS[0..N]);

    foreach (i; 0..N) {
        if (!i) {
            SUM_D[i] = sum_d;
        } else {
            auto idx = DFS[i-1].idx;
            SUM_D[i] = SUM_D[i-1] + BS[idx] * LS[idx] - BS[idx] * US[idx] + X * US[idx];
        }
    }

    long min_r = -1, max_r = X * N;
    while (min_r + 1 != max_r) {
        auto mid_r = (min_r + max_r) / 2;
        bool can_win;
        auto len = mid_r / X;
        auto ap = mid_r % X;

        foreach (i; 0..N) {
            auto D = SUM_D[len];
            auto idx = DFS[i].idx;
            if (i < len) {
                auto ldx = DFS[len].idx;
                D = D - X * US[idx] + X * US[ldx];
                D = D + BS[idx] * US[idx] - BS[idx] * LS[idx];
                D = D + BS[ldx] * LS[ldx] - BS[ldx] * US[ldx];
            }
            if (ap < BS[idx]) {
                D += ap * LS[idx];
            } else {
                D = D + BS[idx] * LS[idx] - BS[idx] * US[idx];
                D = D + ap * US[idx];
            }
            
            if (D >= 0) {
                can_win = true;
                break;
            }
        }

        if (can_win) {
            max_r = mid_r;
        } else {
            min_r = mid_r;
        }
    }

    writeln(max_r);
}

Measured memory_bytes: 6012
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<string> S(n);
    rep(i, n) cin >> S[i];

    string prefix = "MARCH";
    vector<ll> cnt('Z' - 'A');
    rep(i, n) {
        if (prefix.find(S[i][0]) != std::string::npos) {
            cnt[S[i][0] - 'A']++;
        }
    }

    ll sum = 0;
    for (int i = 0; i < prefix.size() - 2; i++) {
        for (int j = i + 1; j < prefix.size() - 1; j++) {
            for (int k = j + 1; k < prefix.size(); k++) {
                sum += cnt[prefix[i] - 'A'] * cnt[prefix[j] - 'A'] * cnt[prefix[k] - 'A'];
            }
        }
    }

    put(sum);

    return 0;
}

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

using namespace std; 
  
int main()
{
 char s[10];
 scanf("%s", s);
 if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])printf("Yes\n");
 else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])printf("Yes\n");
 else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])printf("Yes\n");
 else printf("No\n");
}

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

using namespace std;


signed main(){

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(auto& x : a)
        cin >> x;
    int sum = accumulate(a.begin(), a.end(), 0LL);
    int div = sum / (n + 1);
    int mod = sum % (n + 1);
    cout << div + bool(mod) << endl;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  rep(i, n) cin >> arr[i];
  int cnt = 0;
  while (all_of(arr.begin(), arr.end(), [](auto value){return value % 2 == 0;})) {
    ++cnt;
    for_each(arr.begin(), arr.end(), [](auto& value){value /= 2;});
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
text=input()
string=input()


#common_length[i]は、探索列がstring[i]で探索を終了したときに、
# string[i-common_lneght[i] + 1] 〜string[i]で構成される文字列が、探索価値を持つことを示す


len_string=len(string)
common_length=[0]*len_string
tmp=0
tmp_tmp=0
for i in range(1,len_string):
    if(string[i]==string[tmp]):
        tmp_tmp=tmp
        while(string[i]==string[tmp_tmp] and tmp_tmp >0):
            tmp_tmp=common_length[max([tmp_tmp-1,0])]
        common_length[i-1]=tmp_tmp
        tmp+=1
    else:
        common_length[i-1]=tmp
        while(string[i]!=string[tmp] and tmp>0):
            tmp=common_length[max([tmp-1,0])]

if(string[-1]==string[tmp-1]):
    common_length[-1]=tmp
common_length[0]=0


tmp=0

for i in range(len(text)):
    if(text[i]!=string[tmp]):
        while(text[i]!=string[tmp] and tmp>0):
            tmp=common_length[max([tmp-1,0])]
        if(text[i]==string[tmp]):
            tmp+=1
    else:
        tmp+=1
        if(tmp==len_string):
            print(i-tmp+1)
            tmp=common_length[-1]


Measured memory_bytes: 5584
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#define ll long long
#define maxn 500015
using namespace std;
struct node{
	int next,v,u,w;
}p[maxn];
int head[maxn],cnt,vis[maxn],n,k,maxx;
 
void add(int u,int v)
{
	p[cnt].v=v;
	p[cnt].next=head[u];
	head[u]=cnt++;
}
 
void dfs(int now,int fa,int step)
{
	maxx++;
	if(step==0)
	return ;
	for(int i=head[now];~i;i=p[i].next)
	{
		if(p[i].v==fa)
		continue;
		dfs(p[i].v,now,step-1);
	}
}
 
int main()
{
	int i,j,x,y;
	scanf("%d%d",&n,&k);
	for(i=0;i<=n;i++)
	head[i]=-1;
	for(i=0;i<n-1;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	int ans=0;
	if(k%2)    //k为奇数，枚举边，跑k/2的点 
	{
		for(i=1;i<=n;i++)
		{
			for(j=head[i];~j;j=p[j].next)
			{
				maxx=0;
				int t=p[j].v;
				dfs(t,i,k/2);
				dfs(i,t,k/2);
				ans=max(maxx,ans);
			}
		}
	}
	else      //k为偶数，枚举点，跑k/2的点 
	{
		for(i=1;i<=n;i++)
		{
			maxx=0;
			dfs(i,0,k/2);
			ans=max(maxx,ans);
		}
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
main()
{
	long long int a,b,c,d,p1,p2,p3,p4;
	cin>>a>>b>>c>>d;
	p1=a*c;
	p2=a*d;
	p3=b*c;
	p4=b*d;
	if(p1>=p2 && p1>=p3 && p1>=p4)
	{
		cout<<p1<<endl;
	}
	else if(p2>=p1 && p2>=p3 && p2>=p4)
	{
		cout<<p2<<endl;
	}
	else if(p3>=p2 && p3>=p1 && p3>=p4)
	{
		cout<<p3<<endl;
	}
	else if(p4>=p2 && p4>=p3 && p4>=p1)
	{
		cout<<p4<<endl;
	}
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
  T r;
  while (a)
    r = b, b = a, a = r % a;
  return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n;
int x, y;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d||(abs(a - b) <= d && abs(b - c) <= d ))
    Yes();
  else
    No();
}


Measured memory_bytes: 3616
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
if n<m:
  print('NO')
  exit()
d.sort()
t.sort()
i=0
j=0
while i<n and j<m:
  if d[i]==t[j]:
    i+=1
    j+=1
  else:
    i+=1
if j==m:
  print('YES')
else:
  print('NO')

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

int main()
{
    int n;
    cin>>n;
    int a[n],cnt=0;
    map<int,int> x;

    map<int,int>::iterator i;

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

    for(i=x.begin();i!=x.end();i++)
    {
        if(i->first!=i->second)
        {
            if(i->first>i->second)
                cnt+=i->second;
            else
                cnt+=i->second-i->first;
        }
    }


        cout<<cnt<<endl;
}


Measured memory_bytes: 5120