akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1) {
    
    if(Q1 == 0) break;
    
    cin >> B >> C1 >> C2 >> Q2;
    
    assert(Q2 >= 0);
    
    /*
    if(B/C1 == 0) {
      failed(); continue;
    }
    */
    
    int AizuCh = min(B/C1, Q2);
    if(AizuCh <= 0) { failed(); continue; }
    int NCh = 0;
    for(;;) {
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int ,int> P;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, d; cin >> H >> W >> d;
  string col = "YBRG";
  FOR(i,0,H) {
    FOR(j,0,W) {
      int x = ((i + j) % (2 * d) + 2 * d) % (2 * d) / d;
      int y = ((i - j) % (2 * d) + 2 * d) % (2 * d) / d;
      cout << col[2 * x + y];
    }
    cout << '\n';
  }
  return 0;
}

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

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define si(x) int((x).size())
#define mp make_pair

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using ll=long long;
using pi=pair<int,int>;
using vi=vc<int>;

template<class t>
struct BIT{
	vc<t> buf;
	int s;
	BIT(int n=0){init(n);}
	void init(int n){buf.assign(s=n,0);}
	void add(int i,t v){
		for(;i<s;i+=(i+1)&(-i-1))
			buf[i]+=v;
	}
	t get(int i){
		t res=0;
		for(;i>=0;i-=(i+1)&(-i-1))
			res+=buf[i];
		return res;
	}
	t sum(int b,int e){
		return get(e-1)-get(b-1);
	}
	/*int kth(int k){
		int res=0;
		for(int i=topbit(s);i>=0;i--){
			int w=res+(1<<i);
			if(w<=s&&buf[w-1]<=k){
				k-=buf[w-1];
				res=w;
			}
		}
		return res;
	}*/
};

const int mmax=1.1e5;
vi rs[mmax];
vi facs[mmax];
int ans[mmax];

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

	int n,m;cin>>n>>m;
	rep(i,n){
		int l,r;cin>>l>>r;
		rs[l].pb(r);
	}

	rng(i,1,m+1)for(int j=i;j<=m;j+=i)
		facs[j].pb(i);

	BIT<int> bit(m+1);
	rng(l,1,m+1){
		for(auto r:rs[l])
			bit.add(r,1);
		for(auto d:facs[l])
			ans[d]+=bit.sum(l,min(m+1,l+d));
	}

	rng(d,1,m+1)
		cout<<ans[d]<<'\n';
}


Measured memory_bytes: 17536
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=0; i<q; i++)
    {
        int a;
        cin>>a;
        arr[a]++;
    }
    for(int i=1;i<=n;i++){
        int cur=(k+arr[i])-q;
        if(cur>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 4024
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        ans += (i*(i+1))/2;
    }
    for(ll i=0,x,y;i<n-1;i++)
    {
        cin >> x >> y;
        if(x>y)   swap(x,y);
        ll how = x * (n+1-y);
        ans -= how;
    }
    cout<<ans;
}

int main()
{
    FAST;
    ll t = 1;
  //  cin >> t;
    while(t--)
    {
      solve();
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int num[26];

int main()
{
  ll a,b,c,k,ans,n;
  cin>>n>>a>>b;
  ans = (b-a)*(n-2) + 1;
  if (n == 1){
    if (a==b)
      ans = 1;
    else
      ans = 0;
  }
  if (a > b)
    ans = 0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

A,B,C,X,Y = map(int,input().split())

if 2*C < A+B:
    ans = inf 
    for i in range(min(X,Y),max(X,Y)+1):
        ans = min(ans,max(0,(X-i))*A+max(0,(Y-i))*B+i*2*C)
    print(ans)

else:
    print(X*A+Y*B)

Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 




////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl a(n+1), b(n);
    rep(i, 0, n+1) cin >> a[i];
    rep(i, 0, n) cin >> b[i];

    ll ans = 0;
    rep(i, 0, n){
        if(b[i] > a[i]){
            ans += a[i];
            b[i] -= a[i];
            if(b[i] >= a[i+1]){
                ans += a[i+1];
                a[i+1] = 0;
            }else{
                ans += b[i];
                a[i+1] -= b[i];
            }
        }else{
            ans += b[i];
        }
    }

    co(ans);

    return 0;
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

const ll mod = 1e9+7;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    ll dp[3];
    ll ans = 1;
    dp[0] = dp[1] = dp[2] = 0;
    rep(i, n) {
        ll a;
        cin >> a;

        ll cnt = 0;
        rep(j, 3) {
            if (dp[j] == a) {
                if (cnt == 0) dp[j]++;
                cnt++;
            }
        }
        ans = ans * cnt % mod;
    }

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
n,m=map(int,input().split())
es=[[[] for j in range(n)] for i in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    for j in range(m):
        if i!=j:
            es[j][a].append(b)
            es[j][b].append(a)
sw = [[True for i in range(n)] for i in range(m)]# 頂点0とのパスが存在すればFalse, 存在しないならTrue と定義する
def dfs(v,k):
    sw[k][v] = False
    for i in es[k][v]:
        if sw[k][i]:
            dfs(i,k)
for i in range(m):
    dfs(0,i)
ans=0
for j in range(m):
    for i in range(n):
        if sw[j][i]:
            ans+=1
            break
print(ans)


Measured memory_bytes: 3316
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

x = 0
y = 0
z = 0

for i in range(N):
    if P[i] <= A:
        x += 1
    elif A + 1 <= P[i] <= B:
        y += 1
    else:
        z += 1

print(min(x, y, z))

Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

#define _GLIBCXX_DEBAC
using namespace std;


int main() {
	int n;
	cin >> n;
	int ans = 0;
	if (n % 2 == 0) {
		ans = n / 2-1;
	}
	else {
		ans = n / 2;
	}
	cout << ans;
		return 0;
}









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

using namespace std;

#define ll long long

int main()
{
	ll N, K;
	cin >> N >> K;
	vector < ll > A(N + 1);
	for (ll i = 1; i <= N; i++) {
		cin >> A[i];
	}

	set < ll > went;
	ll current = 1;
	ll roopStartNum = 0;
	for (ll i = 1; i <= N; i++) {
		if (went.find(current) != went.end()) {
			roopStartNum = current;
			break;
		}
		went.insert(current);
		current = A[current];
	}

	current = 1;
	for (ll i = 0; i <= K; i++) {
		if (current == roopStartNum) {
			K = i + (K - i) % (went.size() - i);
			break;
		}
		current = A[current];
	}

	current = 1;
	for (ll i = 0; i < K; i++) {
		current = A[current];
	}

	cout << current << endl;

	return 0;
}


Measured memory_bytes: 13956
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
using namespace std;
//using namespace __gnu_pbds;
#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
double PI=3.1415926535897932384626;
//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	double n;
	cin>>n;
	ll arr[5];
	for(int i=0;i<5;i++)
	{
		cin>>arr[i];
	}
	ll pos=min_element(arr,arr+5)-arr;
	ll pos1=pos+1;
	ll pos2=5-pos1;
	ll tmp=ceil(n/arr[pos]);
	cout<<(tmp+pos2+pos);
    return 0;
}

Measured memory_bytes: 256
// 22
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
  M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
  for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 5
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, len(v)) o << setw(7) << left << v[i];
  return o << endc << endl << coutc;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
template <class T, class... Ts>
void debug(const T &e, const Ts &... r) {
#ifdef DEBUG
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
#endif
}
// 3
void _main(int tc) {
  ld r;
  cin >> r;
  const ld pi = acos(-1);
  cout << (2 * r * pi) << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 3788
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] odd=new int[1000001];
        int[] even=new int[1000001];
        for(int i=0;i<odd.length;i++){
            odd[i]=0; even[i]=0;
        }
        for(int i=0;i<n;i++){
            if(i%2==0){
                even[sc.nextInt()]++;
            }
            else{
                odd[sc.nextInt()]++;
            }
        }
        int odd1=0; int odd1_idx=0; int odd2=0; int odd2_idx=0;
        int even1=0; int even1_idx=0; int even2=0; int even2_idx=0;
        for(int i=1;i<1000001;i++){
            if(odd[i]>odd1){
                odd2_idx=odd1_idx; odd2=odd1;
                odd1_idx=i; odd1=odd[i];
            }
            else if(odd[i]>odd2){
                odd2_idx=i; odd2=odd[i];
            }
            if(even[i]>even1){
                even2_idx=even1_idx; even2=even1;
                even1_idx=i; even1=even[i];
            }
            else if(even[i]>even2){
                even2_idx=i; even2=even[i];
            }
        }
        if(odd1==n/2 && even1==n/2 && odd1_idx!=even1_idx){
            System.out.println(0);
        }
        else if(odd1==n/2 && even1==n/2 && odd1_idx==even1_idx){
            System.out.println(n/2);
        }
        else if(odd1==n/2 || even1==n/2){
            int out=odd1==n/2 ? n/2-even1 : n/2-odd1;
            System.out.println(out);
        }
        else if(odd1_idx!=even1_idx){
            System.out.println(n-odd1-even1);
        }
        else{
            if(odd1-odd2>even1-even2)
                System.out.println(n-even2-odd1);
            else
                System.out.println(n-odd2-even1);
        }
    }
}


Measured memory_bytes: 70316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ1_9_C
{
    class Program
    {
        static string[] _vs = new string[2];
        static string[] _vsSorted = new string[2];
        static int[] _score = new int[2];

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; ++i)
            {
                _vs = Console.ReadLine().Split(' ');
                Judge(_vs[0], _vs[1]);
            }
            Console.WriteLine(_score[0] + " " + _score[1]);
        }
        private static void Judge(string A, string B)
        {
            if (A == B)
            {
                _score[0] += 1;
                _score[1] += 1;
            }
            else
            {
                _vsSorted[0] = A;
                _vsSorted[1] = B;
                Array.Sort(_vsSorted, StringComparer.OrdinalIgnoreCase);
                if (A == _vsSorted[1])
                {
                    _score[0] += 3;
                }
                else
                {
                    _score[1] += 3;
                }
            }
        }
    }
}



Measured memory_bytes: 17972
#include <iostream>
#include <algorithm>

int main() {
    long long n, x;
    std::cin >> n >> x;
    long long h = n - x, l = x;
    long long sum = n;
    while (h) {
        sum += l / h * 2ll * h;
        auto tmp = h;
        h = l % h;
        l = tmp;
    }
    sum -= l;
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
P = set(map(int, input().split()))
kouho = x
for i in range(100):
    kouho1 = kouho - i
    kouho2 = kouho + i
    if kouho1 not in P:
        print(kouho1)
        exit()
    elif kouho2 not in P:
        print(kouho2)
        exit()
print("error")


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

void dfs(void);

int n,a,b,c,l,ans = INF;
vector<int> v;
stack<int> s;

signed main() {
    cin >> n >> a >> b >> c;
    rep(i,n) cin >> l,v.pb(l);
    dfs();
    cout << ans << endl;
}

void dfs(void) {
    if (s.size() == n) {
        int asum=0,bsum=0,csum=0,cnt=0;
        stack<int> tmp = s;
        rep(i,n) {
            if (tmp.top() == 1) {
                if (asum) cnt+=10;
                asum += v[i];
            }
            else if (tmp.top() == 2) {
                if (bsum) cnt+=10;
                bsum += v[i];
            }
            else if (tmp.top() == 3) {
                if (csum) cnt+=10;
                csum += v[i];
            }
            tmp.pop();
        }
        if (asum && bsum && csum) {
            ans = min(ans,cnt+abs(a-asum)+abs(b-bsum)+abs(c-csum));
        }
    } else {
        rep(i,4) {
            s.push(i);
            dfs();
        }
    }
    s.pop();
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

n = int(input())
d, x = list(map(int, input().split()))
a = []
sum = 0

for i in range(n):
    z = int(input())
    shou = math.floor(d / z)
    #print("shou: " + str(shou))
    if z != 1:
        shou += 1
        if d % z == 0:
            shou -= 1
    sum += shou
    #print("sum: " + str(sum))

print(sum + x)


Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {
	static class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		public long[] readLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static final FS sc = new FS();
	static final PrintWriter out = new PrintWriter(System.out);
	static final int mod = 1000000007;

	public static void main(String[] args) {
		solve();
		out.close();
	}

	static void solve() {

		String s1 = sc.next();
		String s2 = sc.next();
		out.flush();
		boolean ok = true;

		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) != s2.charAt(i)) {
				ok = false;
				break;
			}
			

		}
		out.println(ok == true ? "Yes" : "No");
	}
}


Measured memory_bytes: 32912
#include <cstdio>
#include <queue>
using namespace std;

int main() {
	int a, b, ans = 0;
	priority_queue<int, vector<int>, less<int> > que;
	scanf("%d%d", &a, &b);
	que.push(a);
	que.push(b);
	ans = que.top();
	que.pop();
	que.push(ans - 1);
	ans += que.top();
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
string s;
bool seen[27];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    memset(seen, 0, sizeof(seen));
    for(int i = 0; i < s.length(); i++){
        seen[s[i]-'a'] = true;
    }
    for(int i = 0; i < 26; i++){
        if(!seen[i]){
            cout << (char) ('a'+i);
            return 0;
        }
    }
    cout << "None";
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			if (count != 0) {
				System.out.println();
			}
			Map<String, Integer> map = new LinkedHashMap<String, Integer>();
			List<Integer> list = new ArrayList<Integer>();
			while (n-- > 0) {
				String str = scanner.next();
				int a = scanner.nextInt();
				scanner.next();
				int b = scanner.nextInt();
				int c = a * 3 + b;
				map.put(str, c);
				list.add(c);
			}
			Collections.sort(list);
			for (int i = list.size() - 1; i >= 0; i--) {
				String delete = "";
				for (Entry<String, Integer> entry : map.entrySet()) {
					if (entry.getValue() == list.get(i)) {
						System.out.println(entry.getKey() + ","
								+ entry.getValue());
						delete = entry.getKey();
						break;
					}
				}
				map.remove(delete);
			}
			count++;
		}
	}
}

Measured memory_bytes: 20544
#include<bits/stdc++.h>
using namespace std;
const int mod=int(1e9)+7;
const int maxn=int(1e9),maxrn=int(sqrt(maxn));
int n,k,rn;
long long s[103][maxrn+2],b[103][maxrn+2],ss[103][maxrn+2],sb[103][maxrn+2];
long long ans;
int main(){
    int i,j;
    scanf("%d %d",&n,&k);
    rn=(int)sqrt(n);
    s[0][1]=1;
    for(i=1;i<=rn;i++) ss[0][i]=1;
    for(i=1;i<=k;i++){
        for(j=1;j<=rn;j++){
            s[i][j]=ss[i-1][rn]+sb[i-1][rn]-sb[i-1][j-1]+mod;
            b[i][j]=ss[i-1][j]*(n/j-n/(j+1));
            if (j == n / j) b[i][j] = 0; //j와 n/j 가 같은 경우는 s에
            s[i][j]%=mod;
            b[i][j]%=mod;
            ss[i][j]+=s[i][j]+ss[i][j-1];
            sb[i][j]+=b[i][j]+sb[i][j-1];
            ss[i][j]%=mod;
            sb[i][j]%=mod;
        }
    }
    for(i=1;i<=rn;i++){
        ans+=s[k][i]+b[k][i];
        ans%=mod;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 101248
N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])  

Measured memory_bytes: 7748
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 0x7FFFFFFF

using namespace std;

long long dp[100005];

int main() {
  int n, w, weight, value;
  cin >> n >> w;
  for (int i = 0; i < n; i++) {
    cin >> weight >> value;
    for (int j = w; j >= weight; j--)
      dp[j] = max(dp[j], dp[j - weight] + value);
  }
  cout << dp[w] << endl;
  return 0;
}

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

int main() {
    int c11, c12, c13, c21, c22, c23, c31, c32, c33;
    cin >> c11 >> c12 >> c13
        >> c21 >> c22 >> c23
        >> c31 >> c32 >> c33;
    if (c11+c22+c33 == c12+c23+c31 && c11+c22+c33 == c13+c21+c32) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long int a,b,c;
	cin>>a>>b>>c;
	long long int sum=a/(b+c)*b;
	long long int l=a%(b+c);
	sum+=min(l,b);
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
	var arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
	console.log(arr[input-1])
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0031
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            long[] intArray =
                Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            long result = 0;
            long tmp = 0;

            for (int i = 0; i < intArray.Length - 1; i++)
            {
                if (intArray[i] >= intArray[i + 1])
                {
                    tmp++;
                }
                else
                {
                    if (result < tmp)
                    {
                        result = tmp;
                    }

                    tmp = 0;
                }

            }

            if (result < tmp)
            {
                result = tmp;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 39280
// Aizu 1167: Pollock's conjecture
// 2017.9.14 bal4u@uu

#include <stdio.h>

#define min(a,b) ((a)<=(b)?(a):(b))
#define MAX 1000000
#define N 181
int tbl[N+3], a[MAX+3], b[MAX+3];

int main()
{
	int n, i, j;

	for (n = 1; n <= N; n++) tbl[n] = tbl[n-1] + (n*(n+1) >> 1);
	for (i = 1; i <= MAX; i++) {
		a[i] = b[i] = i;
		for (j = 0; tbl[j] <= i; j++) {
			a[i] = min(a[i], a[i-tbl[j]]+1);
			if (tbl[j] & 1) b[i] = min(b[i], b[i-tbl[j]]+1);
		}
	}
	while(scanf("%d", &n) && n)	printf("%d %d\n", a[n], b[n]);
	return 0;
}

Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define debug(x) cout<<x<<endl
#define int long long 
const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
inline int read() {int num=0, w=0;char ch=0;while (!isdigit(ch)) {w|=ch=='-';ch = getchar();}while (isdigit(ch)) {num = (num<<3) + (num<<1) + (ch^48);ch = getchar();}return w? -num: num;}
// cin.tie(0);
// ios::sync_with_stdio(false);
// head
// long long *long long 		**
//all 
signed main()
{
	int n;
	n=read();
	if(n>=30){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{


    ll i,j,k,a,b,c,n,t,m;
    set<ll> v,s,su;
    set<ll> :: iterator it;
    string st,et;
    cin>>a>>b>>k;
    for(i=a,c=1;c<=k;i++,c++){
        if(i>b){
            break;
        }
        v.insert(i);
    }
    for(i=b,c=1;c<=k;i--,c++){
        if(i<a){break;}v.insert(i);
    }
    //sort(v.begin(),v.end());
    for(it = v.begin();it!=v.end();it++){
        cout<<*it<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(12); solve(); return 0;}
template<typename T> void prv(vector<T> v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void prm(vector<vector<T>> v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}
template<typename... T> void err(const T&... cod) {pr(cod...); exit(0);}

void solve() {
  rd(int, n);
  rdv(int, a, n);
  multiset<int> ms;
  for (int x : a) ms.insert(x);
  rep(i, 0, n) {
    ms.erase(ms.find(a[i]));
    pr(*prev(ms.end()));
    ms.insert(a[i]);
  }
}

Measured memory_bytes: 11776
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=2019;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

// C function for extended Euclidean Algorithm 
int gcdExtended(int a, int b, int *x, int *y); 
  
// Function to find modulo inverse of a 
int modInversenp(int a, int m) 
{ 
    int x, y; 
    int g = gcdExtended(a, m, &x, &y); 
    
        int res = (x%m + m) % m; 
    return res;
} 
  
// C function for extended Euclidean Algorithm 
int gcdExtended(int a, int b, int *x, int *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    int x1, y1; // To store results of recursive call 
    int gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

int main() {
    string s;
    cin >> s;
    unordered_map<int, int> data;
    data[0] = 1;
    int curr = 0;
    ll ans = 0;
    for (int i = 0; i < (int)s.length(); i++) {
        curr = curr*10 + s[i] - '0';
        curr %= 2019;
        int val = (curr*modInversenp(powmod(10, i), mod))%mod;
        //cout << s[i] << " " << curr << " " << val << "\n";
        ans += data[val];
        data[val]++;
    }
    cout << ans << "\n";
}



Measured memory_bytes: 3740
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << v[i].second; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A&lang=ja
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  // cout << " a: "; print_vec(a);
  const int INF = 20 * 2000;
  //dp[i][j]: 要素i-1まで考えて jを作る方法が何通りあるか
  //作れるかどうかだと += のとこを = にしてしまい，上書きされて一度trueになってもfalseにされてしまい上手くいかないみたい
  vector<vector<int>> dp(n+1, vector<int>(INF+1, 0));
  dp[0][0] = 1;
  for(int i=0; i<n; i++){
    for(int j=0; j<=INF; j++){
      dp[i+1][j] += dp[i][j];// a[i]を使わない
      if(j+a[i] <= INF){
        dp[i+1][j+a[i]] += dp[i][j];//a[i]を使う
        // if(dp[i][j]) cout << " i: " << i << "   j: " << j << "  a[i]: " << a[i] << "  dp[i][j]: " << dp[i][j] << "  dp[i+1][j+a[i]]: " << dp[i+1][j+a[i]]  << endl;
      }
    }
  }

  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int m;
    cin >> m;
    if(dp[n][m]) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  // cout << " dp: "; print_vec2(dp);

  return 0;
}




Measured memory_bytes: 6292
N,S = list(map(int,input().split()))
A = list(map(int,input().split()))
dp = [[0]*(N+1) for i in range(S+1)]
p = 998244353

twos = [1]*N
for i in range(1,N):
    twos[i] = (twos[i-1]*2)%p

for j in range(1,N+1):
    flag = 0
    for i in range(1,S+1):
        if flag==0:
            dp[i][j] = (dp[i][j-1]*2)%p
        else:
            dp[i][j] = (dp[i][j-1]*2+dp[i-A[j-1]][j-1])%p
        if i==A[j-1]:
            dp[i][j] += twos[j-1]
            flag = 1
print(dp[-1][-1]%p)

Measured memory_bytes: 139160
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    while (n) {
        if (n % 10 == 7) {
            cout << "Yes\n";
            return 0;
        }
        n /= 10;
    }   cout << "No\n";

    //----------------------------------------------------------------------
    #ifdef LOCAL
        cerr << "Time elapsed: " << (double)clock()/CLOCKS_PER_SEC << "s.\n";
    #endif
}
/*

*/


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
	READARR(a, n);
	int b[n + 1];
	FOR (i, 1, n) b[i] = a[i];
	sort (b + 1, b + n + 1, greater<int>());
	
	FOR (i, 1, n)
		if (b[1] == a[i]) cout << b[2] << endl;
		else cout << b[1] << endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll e = lcm(c, d);

    cout << b - a + 1 - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d) - (b / e - (a - 1) / e)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<(k);i++)
#define mp make_pair
#define sz(a) (int)(a).size()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef long double ld;
//----head----
char str[100005];
int main()
{
	scanf("%s",str);
	int n=strlen(str);
	int ans1=n,ans2=n;
	rep(i,0,n)
	{
		if(str[i]=='0')ans1=min(ans1,max(i,n-i-1));
		else ans2=min(ans2,max(i,n-i-1));
	}
	printf("%d\n",max(ans1,ans2));
	return 0;
}
	

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

using namespace std;
using ll = long long;

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

  int k;
  string s;
  cin >> k >> s;

  if (s.size() <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) << "..." << endl;
  }

  return 0;
}


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

void solve(void) {
  int N; cin >> N;
  vector<int> vec(N);
  for(int ni = 0; ni < N; ++ni) cin >> vec[ni];

  sort(vec.begin(), vec.end());

  vector<double> gousei(N+1);
  gousei[0] = (double)vec[0];
  for (int gi = 0; gi < N; ++gi) {
    gousei[gi+1] = (gousei[gi] + vec[gi]) / 2.0;
  }

  cout << gousei[N] << endl;
}
int main(void) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
 
using namespace std;
long long Pow[45];
long long all[200005];
struct A
{
    long long how;
    long long con;
}num[200005];
bool F(long long a,long long b)
{
    return a>b;
}
int main()
{
    long long N,i,j,now=0,ans=0,l,r,t;
    Pow[0]=1;
    for(i=1;i<=35;i++) Pow[i]=Pow[i-1]*2;
    scanf("%lld",&N);
    for(i=0;i<N;i++) scanf("%lld",&all[i]);
    sort(all,all+N,F);
    num[now].how=all[0];
    num[now].con=1;
    /*for(i=0;i<N;i++) printf("%lld ",all[i]);
	printf("\n"); */
    for(i=1;i<N;i++)
    {
        if(all[i]==all[i-1]) num[now].con++;
        else
        {
            now++;
            num[now].how=all[i];
            num[now].con=1;
        }
    }
    for(i=0;i<=now;i++)
    {
        for(j=35;j>=0;j--)
        {
            if(Pow[j]-num[i].how<=0) continue;
            if(Pow[j]-num[i].how==num[i].how)
            {
                ans+=num[i].con/2;
                num[i].con%=2;
            }
            else
            {
                l=i;
                r=now;
                while((r-l)>1)
                {
                    if(num[(r+l)/2].how>=Pow[j]-num[i].how) l=(r+l)/2;
                    else r=(r+l)/2;
                }
                if(num[l].how+num[i].how==Pow[j])
                {
                    t=min(num[l].con,num[i].con);
                    num[l].con-=t;
                    num[i].con-=t;
                    ans+=t;
                }
                else if(num[r].how+num[i].how==Pow[j])
                {
                    t=min(num[r].con,num[i].con);
                    num[r].con-=t;
                    num[i].con-=t;
                    ans+=t;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4992
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def getOrder(a: list, n):
    numbers = [i for i in range(1,n+1)]
    
    factorial = 1
    for i in range(1,n):
        factorial *= i

    ret = 0
    for i in range(n):
        ai = a[i]
        idx = numbers.index(a[i])
        ret += idx * factorial
        numbers.pop(idx)
        factorial //= max(1,(n-1-i))# Avoid ZeroDivisionError
    return ret


def main():
    n = ni()
    ps = na()
    qs = na()
    print(abs(getOrder(qs,n) - getOrder(ps,n)))
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

rules = []
for m in range(M):
    rules.append(list(map(int, input().split())))

def ok(k):
    k_str = str(k)
    if N != len(k_str): return False
    for s, c in rules:
        if s > len(k_str): return False
        if int(k_str[s - 1]) != c: return False
    return True


ans = -1
for i in range(1000):
    if ok(i):
        ans = i
        break
print(ans)



Measured memory_bytes: 6576
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sx[4] = { 0, 1, 0, -1 };
int sy[4] = { 1, 0, -1, 0 };

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	string S[H];
	rep(i, H) cin >> S[i];
	//rep(i, H) cout << S[i] << endl;
	rep(i, H) {
		rep(j, W) {
			if (S[i][j] == '#') {
				int cnt = 0;
				rep(k, 4) {
					int x = i + sx[k];
					int y = j + sy[k];
					if (x < 0 || y < 0) continue;
					if (x >= H || y >= W) continue;
					if (S[x][y] == '#') cnt++;
				}
				// dump(cnt);
				if (cnt == 0) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll dp[51][51][3010];

int main() {
    cin >> n >> m;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
    }
    dp[0][0][0] = 1;
    REP(i,n) {
        REP(j,n) {
            REP(k,2500) {
                if(dp[i][j][k]){
                    dp[i + 1][j][k] += dp[i][j][k];
                    dp[i + 1][j + 1][k + v[i]] += dp[i][j][k];
                }
            }
        }
    }
    FOR(i,1,n+1) {
        ans += dp[n][i][i * m];
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 58240
# import time


A = int(input())
B = int(input())
C = int(input())
X = int(input())
# t1 = time.time()
ans = 0

for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0,C+1):
            if 500*i+100*j+50*k == X:
                ans +=1

print(ans)
# t2 = time.time()
# print(t2-t1)


Measured memory_bytes: 3060
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

dic = dict()
free = 0
for a in A:
    if a <= 399:
        if 1 not in dic:
            dic[1] = 1
    elif a <= 799:
        if 2 not in dic:
            dic[2] = 1
    elif a <= 1199:
        if 3 not in dic:
            dic[3] = 1
    elif a <= 1599:
        if 4 not in dic:
            dic[4] = 1
    elif a <= 1999:
        if 5 not in dic:
            dic[5] = 1
    elif a <= 2399:
        if 6 not in dic:
            dic[6] = 1
    elif a <= 2799:
        if 7 not in dic:
            dic[7] = 1
    elif a <= 3199:
        if 8 not in dic:
            dic[8] = 1
    else:
        free += 1

res = len(dic.items())
print(max(1, res), res + free)


Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
t=s=f=0
for i in a:
  if i%4==0:f+=1
  elif i%2==0:s+=1
  else:t+=1
if s>0:t+=1
if t>f+1:print("No")
else:print("Yes")

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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N * (N - 1) / 2; ++i) {
			int A = sc.nextInt() - 1;
			int B = sc.nextInt() - 1;
			int C = sc.nextInt();
			int D = sc.nextInt();
			if (C > D) {
				p[A] += 3;
			} else if (C < D) {
				p[B] += 3;
			} else {
				p[A]++;
				p[B]++;
			}
		}
		int[] v = new int[N];
		for (int i = 0; i < N; ++i) {
			v[i] = (p[i] << 10) + i;
		}
		Arrays.sort(v);
		int[] rank = new int[N];
		int r = 0;
		int prev = 1 << 30;
		for (int i = N - 1; i >= 0; --i) {
			if ((v[i] >> 10) != prev) {
				r = N - i;
			}
			rank[v[i] & 0xFF] = r;
			prev = v[i] >> 10;
		}
		for (int i = 0; i < N; ++i) {
			System.out.println(rank[i]);
		}
	}
}

Measured memory_bytes: 42112