akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec  8 12:23:26 PST 2019
 **/

signed main() {
    Int n = in(), X = in(), D = in();
    if (D == 0) {
        cout << (X == 0 ? 1 : n + 1) << endl;
        return 0;
    }
    if (D < 0) {
        X = -X, D = -D;
    }
    unordered_map<Int, vector<ii>> mp;
    REP(k, n + 1) {
        Int rem = (k * X % D + D) % D;
        assert((k * X - rem) % D == 0);
        Int l = k * (k - 1) / 2 + (k * X - rem) / D;
        Int r = (2 * n - k - 1) * k / 2 + (k * X - rem) / D;
        mp[rem].push_back({l, r});
    }
    Int ans = 0;
    const Int INF = 1e18;
    for (auto& pp : mp) {
        auto& v = pp.se;
        sort(v.begin(), v.end());
        Int ma = -INF;
        for (auto p : v) {
            ans += max(0LL, p.se - max(ma + 1, p.fi) + 1);
            chmax(ma, p.se);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 17864
V, E = map(int, input().split())
dist = [[float('inf') for j in range(V)] for i in range(V)]
for i in range(V):
    dist[i][i] = 0
for i in range(E):
    s, t, d = map(int, input().split())
    dist[s][t] = d

negative_cycle = False

for k in range(V):
    for i in range(V):
        for j in range(V):
            if dist[i][k] == float('inf') or dist[k][j] == float('inf'):
                continue
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]

for i in range(V):
    if dist[i][i] < 0:
        negative_cycle = True

if negative_cycle:
    print('NEGATIVE CYCLE')
else:
    for i in range(V):
        d = ['INF' if e == float('inf') else e for e in  dist[i]]
        print(*d)

Measured memory_bytes: 8560
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	long long m,n;
	cin >> n >> m;

	vector<long long> a(n);
	long long total = 0;

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

	float check = static_cast<float>( total )  / static_cast<float>(4 * m);
	bool ok = false;
	int count = 0;

	for (int i = 0; i < n; ++i)
	{
		if (static_cast<float>(a[i]) >= check)
		{
			count++;
			if (count >= m)
			{
				ok = true;
				break;
			}
		}
	}

	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
class UnionFind:
    """素集合を木構造として管理する"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.cnt = n

    def root(self, x):
        """要素xの根を求める"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """要素xを含む集合と要素yを含む集合を統合する"""
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        self.cnt -= 1

    def is_same(self, x, y):
        """要素x, yが同じ集合に属するかどうかを求める"""
        return self.root(x) == self.root(y)

    def get_size(self, x):
        """要素xを含む集合の要素数を求める"""
        return -self.parent[self.root(x)]


n, m, k = map(int, input().split())
b = [list(map(int, input().split())) for i in range(m)]
c = [list(map(int, input().split())) for i in range(k)]

uf = UnionFind(n)
b_graph = [[] for i in range(n)]
for u, v in b:
    u -= 1
    v -= 1
    uf.merge(u, v)
    b_graph[u].append(v)
    b_graph[v].append(u)
    
c_graph = [[] for i in range(n)]
for u, v in c:
    u -= 1
    v -= 1
    c_graph[u].append(v)
    c_graph[v].append(u)

ans = []
for i in range(n):
    res = uf.get_size(i) - 1
    res -= len(b_graph[i])
    for v in c_graph[i]:
        if uf.is_same(i, v):
            res -= 1
    ans.append(res)
print(*ans)   

Measured memory_bytes: 128772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e18;
vector<pair<ll,ll>> a;
multiset<ll>r,b;
int n;
ll ans;
int main(){
    cin >> n;
    a.resize(n);
    ans = maxn;
    for(int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
        if(a[i].first > a[i].second)
            swap(a[i].first,a[i].second);
    }
    sort(a.begin(), a.end());
    for(auto p:a){
        r.insert(p.first);
        b.insert(p.second);
    }
    ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);
    for(auto p:a){
        r.erase(r.find(p.first));
        b.erase(b.find(p.second));
        r.insert(p.second);
        b.insert(p.first);
        ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);     
    }
    printf("%lld\n", ans);
    return 0;
}

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

struct union_find{
      vector<int> par;
      vector<int> rank;
      union_find(int sz){
            par.resize(sz);
            rank.assign(sz,0);
            for(int i=0;i < sz;i++) par[i]=i;
      }
      int find(int a){
            if(par[a]==a) return a;
            else return par[a] = find(par[a]);
      }
      void unite(int a,int b){
            int root_a,root_b;
            root_a = find(a),root_b = find(b);
            if(rank[root_a]>rank[root_b]){
                  par[root_b] = root_a;
            }else if(rank[root_a]<rank[root_b]){
                  par[root_a] = root_b;
            }else{
                  rank[root_a]++;
                  par[root_b] = root_a;
            }
      }
      bool same(int a,int b){return find(a)==find(b);}
};

int main(){ 
      int n,q; cin >>n>>q;
      union_find tree(n);
      for(int i=0;i<q;i++){
            int com,x,y; cin >>com>>x>>y;
            if(com == 0){
                  tree.unite(x,y);
            }else{
                  int ans = tree.same(x,y);
                  cout << ans << endl;
            }
      }
}


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

using namespace std;

#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef pair <ll, ll> pi;

ll a[3], ans;

int main() {
    fio;
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    sort(a, a + 3);
    ans = 2 * a[2] - a[1] - a[0];
    ans = ans / 2 + 2 * (ans % 2);
    cout << ans << endl;
    return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}


bool is_prime(ll n){
    if(n == 2) return true;
    if(n == 1 or !(n & 1)) return false;

    random_device rnd;
    ll d = (n-1) >> 1;
    while(!(d&1))
        d >>= 1;

    rep(k, 100){

        ll a = rnd() % (n-1) + 1;
        ll t = d;
        ll y = powMod(a, t, n);

        while(t != (n-1) and y != 1 and y != (n-1)){
            y = powMod(y,2,n);
            t <<= 1;
        }

        if(y != n-1 and !(t & 1)){
            return false;
        }
    }

    return true;
}



int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    s.insert(4, " ");
    ppp(s);


    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
if n == 0 then
  puts 0
  exit
end
ans = ""
while n != 1 do
  a = n % -2
  if a == -1 then
    ans = "1" + ans
    if a == -1 then
      n -= 1
    end
  else
    ans = "0" + ans
  end
  n = n / -2
end
ans = "1" + ans
puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, d;std::cin >> a >> b >> c >> d;
  if(a+b>c+d) std::cout << "Left" << '\n';
  else if(a+b<c+d) std::cout << "Right" << '\n';
  else std::cout << "Balanced" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int dx[]={-1,-1,0,0,1,1};
int dy[]={0,-1,1,-1,1,0};
const int inf=1000000010;
string s;
int t;
vi f(){
	vvi in;
	string w="";
	while(t<s.size()){
		if(s[t]=='('){
			t++;
			in.pb(f());
			t++;
		}else{
			int a=0;
			while(t<s.size()&&isdigit(s[t])){
				a*=10;
				a+=s[t]-'0';
				t++;
			}
			in.pb({a});
		}
		if(s.size()==t)break;
		if(s[t]==')')break;
		w+=s[t];
		t++;
	}
	vi out;
	vi per(w.size());
	rep(i,w.size())per[i]=i;
	do{
		vvi tmp=in;
		vi used(w.size()+1);
		rep(i,w.size()){
			int l=per[i],r=per[i]+1;
			while(used[l])l--;
			while(used[r])r++;
			vi nt;

			rep(j,tmp[l].size())rep(k,tmp[r].size()){
				if(w[per[i]]=='+')nt.pb(tmp[l][j]+tmp[r][k]);
				if(w[per[i]]=='-')nt.pb(tmp[l][j]-tmp[r][k]);
				if(w[per[i]]=='*')nt.pb(tmp[l][j]*tmp[r][k]);
				if(tmp[r][k]&&w[per[i]]=='/')nt.pb(tmp[l][j]/tmp[r][k]);
			}
			used[l]=true;
			tmp[l]=vi(0);
			tmp[r]=nt;
		}
		rep(j,tmp.size()){rep(i,tmp[j].size())out.pb(tmp[j][i]);}
	}while(next_permutation(all(per)));
	sort(all(out));
	out.erase(unique(all(out)),out.end());

	return out;
}
int main(){
	while(cin>>s,s!="#"){
		t=0;
		cout<<f().size()<<endl;
	}
}









Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7;

long long dp[101][4][4][4];
//文字数 最後から 3 2 1文字目の3つ
//dp[10][3][2][2]は10文字で最後が322の文字数
int main(void){
	int N;
	cin >> N;
	//長さ0の文字列は1である
	//0,1,2に関する制約しかないので
	//Sは333Sと考えてもよい
	//iが文字列の文字数
	for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
		dp[3][i][j][k]=1;
	}
	dp[3][0][1][2]=0;
	dp[3][0][2][1]=0;
	dp[3][1][0][2]=0;
	for(int i=0;i<N;i++){
		//jが最後から3文字目の文字
		for(int j=0;j<4;j++){
			//kが最後から2文字目の文字
			for(int k=0;k<4;k++){
				//lが最後から1文字目の文字
				for(int l=0;l<4;l++){
					//条件に当てはまるものがないときcontinue;
					if(dp[i][j][k][l]==0)continue;
					//新しく追加する文字
					for(int a=0;a<4;a++){
						if(a==2&&k==0&&l==1)continue;
						if(a==2&&k==1&&l==0)continue;
						if(a==1&&k==0&&l==2)continue;
						if(a==2&&j==0&&l==1)continue;
						if(a==2&&j==0&&k==1)continue;
						dp[i+1][k][l][a]+=dp[i][j][k][l];
						dp[i+1][k][l][a]%=mod;
					}
				}
			}
		}
	}
	long long ans = 0;
	for(int i=0;i<4;i++)for(int j=0;j<4;j++)for(int k=0;k<4;k++){
		ans+=dp[N][i][j][k];
		ans%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main ( void )
{
	int K, X;

	cin >> K >> X;

	if ( ( K < 1 ) || ( 100 < K ) ){
		cout << "ERROR!\n";
		return 0;
	}

	if ( ( X < 1 ) || ( 100000 < X ) ){
		cout << "ERROR!\n";
		return 0;
	}

	if ( ( 500 * K ) >= X ){
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    
    return sorted(divisors)


def main():
    X = int(input())
    divisors = make_divisors(X)
    root_X = int(X ** 0.5)
    for d in divisors:
        lim = int(X ** 0.25)
        for b in range(-lim, lim+1):
            a = b + d
            if a ** 4 + (a**3) * b + (a ** 2) * (b** 2) + (a) * (b ** 3) + b ** 4 == X // d:
                print(a, b)
                sys.exit()
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 9348
import Data.List
import qualified Data.Set as Set
import Data.Char
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS8

main=do
    n <- fst . fromJust . BS8.readInt <$> BS8.getLine
    a <- unfoldr (BS8.readInteger . BS8.dropWhile isSpace) <$> BS8.getLine
    
    let s = foldl (\a b->Set.insert b a) (Set.empty) a
        ans = if Set.size s == n then "YES" else "NO"
    
    putStrLn ans


Measured memory_bytes: 31100
var
f:array[0..1000]of longint;
n,t,i,j,k,x1,x2,s,min:longint;
begin
read(n,t);
for i:=0 to 1000 do
f[i]:=0;
s:=0;
min:=maxlongint;
for i:=1 to n do
begin
read(x1,x2);
inc(s,x1);
 for j:=s downto x1 do
 begin
  if f[j-x1]+100*i*x1+x2>f[j] then
  f[j]:=f[j-x1]+100*i*x1+x2;
  if (f[j]>=t) and (j<min) then
  min:=j;
 end;
 for j:=x1-1 downto 1 do
  for k:=x1-1 downto 1 do
  begin
   if f[k-1]+100*i>f[k] then
   f[k]:=f[k-1]+100*i;
   if (f[k]>=t) and (k<min) then
   min:=k;
  end;
end;
writeln(min);
end.

Measured memory_bytes: 128
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    x.sort()
    diffs = []
    for i in range(m - 1):
        diffs.append((x[i+1] - x[i], i))
    diffs.sort(reverse=True)
    diffs = diffs[:n-1]

    idxs = sorted([0] + [diff[1] + 1 for diff in diffs], reverse=True)

    ans = 0
    pos = -1
    for i in range(m):
        if idxs and i == idxs[-1]:
            pos = x[idxs.pop()]
        else:
            ans += x[i] - pos
            pos = x[i]
    print(ans)


Measured memory_bytes: 61096
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;


int main(void)
{
    IOS

    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<uint> c(m);
    bitset<12> ca = 0;
    REP(i,m) {
        cin >> a[i];
        int b; cin >> b;
        REP(j,b) {
            uint d; cin >> d;
            c[i] += 1LL << (d-1);
            ca[d-1] = true;
        }
    }

    ll bmax = pow(2,n);
    cerr << bmax << endl;
    vector<vector<int>> dp(m,vector<int>(bmax,1LL << 30)); 
    dp[0][0] = 0;
    dp[0][c[0]] = a[0];


    if (ca.count() == n) {
        FOR(i,1,m) {
            REP(j,bmax) {
                //cerr << j << " ";
                //cerr << j << " " << dp[i][j] << " ";
                dp[i][j | c[i]] = min(dp[i][j | c[i]],min(dp[i-1][j | c[i]],dp[i-1][j]+a[i]));
                dp[i][j] = min(dp[i][j],dp[i-1][j]);
                //cerr << (j | c[i]) << " " << dp[i][j | c[i]] << endl;
            }
        }

        cout << dp[m-1][bmax-1] << endl;
    } else cout << -1 << endl;


    return 0;
}

Measured memory_bytes: 16384
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;



int n,x,re;
int main()
{
    cin>>n;
    vector<int>v; 
    while(n--)
    {
        cin>>x;
        if(x%2==0)
        v.push_back(x);
    }
    for(int i=0;i<v.size();i++)
    {
        while(v[i]%2==0)
        {v[i]=v[i]/2;
        re++;}
    }
    cout<<re;
   // system("pause");
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

int a[100010];
PII p[100010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];

  if(a[n-1] != 2) {
    cout << -1 << endl;
    return 0;
  }

  p[n-1] = {2, 3};
  for(int i=n-2; i>=0; --i) {
    // a[i] p[i+1]
    // p[i+1] の区間でa[i]が入ってるやつ
    int mi = (p[i+1].first / a[i] + !!(p[i+1].first%a[i])) * a[i];
    int ma = (p[i+1].second / a[i] ) * a[i];
    if(p[i+1].second/a[i] - (p[i+1].first-1)/a[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    // cout << i << " " << mi << " " << ma+(a[i]-1) << endl;
    p[i] = {mi, ma+(a[i]-1)};
  }
  cout << p[0].first << " " << p[0].second << endl;

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll sx, sy, tx, ty;
    ll dx, dy;
    cin >> sx >> sy >> tx >> ty;
    dx = tx - sx;
    dy = ty - sy;
    rep(i, dy) cout << "U";
    rep(i, dx) cout << "R";
    rep(i, dy) cout << "D";
    rep(i, dx) cout << "L";
    cout << "L";
    rep(i, dy + 1) cout << "U";
    rep(i, dx + 1) cout << "R";
    cout << "D";
    cout << "R";
    rep(i, dy + 1) cout << "D";
    rep(i, dx + 1) cout << "L";
    cout << "U";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
<?php 
// ABC168 - A 
    fscanf(STDIN, "%s", $n);

    $ones_place = substr($n, -1);
    if($ones_place == 2 || $ones_place == 4 || $ones_place == 5 || $ones_place == 7 || $ones_place == 9){
        echo "hon";
    } else if ($ones_place == 0 || $ones_place == 1 || $ones_place == 6 || $ones_place == 8){
        echo "pon";
    } else if ($ones_place == 3){
        echo "bon";
    };

Measured memory_bytes: 16104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    
    if(s == "Y"){
      cout << "Four" << endl;
      break;
    }
    
    if(i == N-1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

# 同じ値が複数存在するかチェックする用のカウンタ
counter = Counter(A)

# D[a] = True: Aにaより小さいaの約数が存在する
A_max = max(A)
dp = {a: False for a in A}

for a in A:
    # xが数列Aに含まれているとき、aより大きいaの倍数tについて、dp[a * t]をTrueに変更する
    if counter[a] > 0:
        t = 2
        while a * t <= A_max:
            dp[a * t] = True
            t += 1

ans = 0
for a in A:
    if counter[a] == 1 and dp[a] is False:
        ans += 1

print(ans)


Measured memory_bytes: 104964
N=int(input())

for h in range(1,3501):
    for n in range(1,3501):
        if 4*n*h>N*(h+n) and N*n*h%(4*n*h-N*(h+n))==0:
            w=N*n*h//(4*n*h-N*(h+n))
            print('{} {} {}'.format(h,n,w))
            exit(0)

Measured memory_bytes: 66596
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

const int maxn=200000+10;
int a[maxn];

int main()
{
	int n;cin>>n;
	rep(i,1,n) a[i]=read();
	int M=0,M2=0;
	rep(i,1,n)
	{
		if(a[i]>M) M2=M,M=a[i];
		else if(a[i]>M2) M2=a[i];	
	}
	rep(i,1,n) printf("%d ",a[i]==M?M2:M);
	return 0;
}


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

int main()
{
   string s,t;
   cin>>s>>t;
   int count=0;
   for(int i=0;i<3;i++){
      if(s[i]==t[i]){
	 count++;
      }
   }
   cout<<count<<endl;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

char m[1100][1100];

void solve(long long H, long long W){
	char ans[1100][1100] = {};
  
  FOR(h,1,H*2+1) FOR(w,1,W+1){
      int preH = (h+1)/(2);
      ans[h-1][w-1] = m[preH-1][w-1];
  }
  
  FOR(h,1,H*2+1) {
    FOR(w,1,W+1){
        cout << ans[h-1][w-1];
    }
    cout << endl;
  }
}

int main(){	
	ios::sync_with_stdio(false);
	long long H;
	long long W;
	cin >> H;
	// vector<string> C(H-1+1);
	cin >> W;
	for(int i = 0 ; i <= H-1 ; i++){
    string buf;
    cin >> buf;
    REP(w,W){
      m[i][w] = buf[w];
    }
		// cin >> C[i];
	}
	solve(H, W);
	return 0;
}


Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対グラフ

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

ll GCD(ll a,ll b){
    ll temp;
    ll c;
    if(b>a){
        temp=a;
        a=b;
        b=temp;
    }
    while(b>0){
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}

ll LCM(ll c,ll d){
    ll f=GCD(c,d);
    return c*d/f;
}


int main(){
    ll a, b, c, d,k;
    cin >> a>>b>>c>>d;
    k=(b-a+1)-((b/c+b/d-b/LCM(c,d))-((a-1)/c+(a-1)/d-(a-1)/LCM(c,d)));
    cout<<k<<endl;
    return 0;
}

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

const int Mod = 1e9 + 7;
int N, M;
int s[2003], t[2003];
long long Ans, f[2003], psum[2003];

inline int Rd() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	cin >> N >> M;
	register int i, j;
	f[0] = 1;
	for(i = 1; i <= N; ++i)
		s[i] = Rd();
	for(i = 1; i <= M; ++i)
		t[i] = Rd();
	for(i = 1; i <= N; ++i) {
		for(j = 1; j <= M; ++j)
			psum[j] = (psum[j - 1] + f[j - 1]) % Mod;
		for(j = 1; j <= M; ++j)
			if(s[i] == t[j])
				(Ans += psum[j]) %= Mod, (f[j] += psum[j]) %= Mod;
	}
	cout << Ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main(){
    int n,m,a[10000]={0};
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    int sum=0,ans;
    
    for(int i=0;i<m;i++){
        sum=sum+a[i];
    }
    ans=n-sum;
    if(ans>=0){
        cout<<ans<<"\n";
    }else{
        cout<<-1<<"\n";
    }
    return 0;
}

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

void conv(int n)
{
    if(n/4!=0){
        conv(n/4);
    }

    cout << n%4;
}

int main() {

    long int n;

    while(1){

        scanf(" %ld",&n);

        if(n==-1){
            break;
        }

        conv(n);

        cout << '\n';

    }

    return 0;
}

Measured memory_bytes: 3112
n = int(input())
s = input()
ans = 0
for i in range(n):
  s1 = s[:i]
  s2 = s[i:]
  lst = []
  for k in s1:
    if k in s2:
      lst.append(k)
  ans = max(ans, len(list(set(lst))))

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]){
	unsigned int A, B, C, X, Y, min_num, dif, sum;
	cin >> A >> B >> C >> X >> Y;

	min_num = X > Y ? Y : X;
	dif = A + B > 2*C ? 2*C : A + B;
	sum = min_num * dif;

	if (X > Y){
		if (A < 2*C)
			sum += (X - Y) * A;
		else
			sum += (X - Y) * 2*C;
	}
	else if(X < Y){
		if(B < 2*C)
			sum += (Y - X) * B;
		else
			sum += (Y - X) * 2*C;

	}

	cout << sum;

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

ll h[200005];

struct line{
	ll m,c;
	ll get(ll x){return m*x+c;}
};

struct node{
	int s,e,m;
	line v;
	node *l,*r;
	node(int S,int E){
		s=S;e=E;m=(s+e)/2;
		v=line{0,INF};
		if(s!=e){
			l=new node(s,m);r=new node(m+1,e);
		}
	}
	void upd(line x){
		if(s==e){
			if(x.get(s)<v.get(s))swap(x,v);
			return;
		}
		bool left=(x.get(s)<v.get(s));
		bool mid=(x.get(m+1)<v.get(m+1));
		if(mid)swap(x,v);
		if(left!=mid)l->upd(x); //crossing on left
		else r->upd(x); //crossing on right
	}
	ll qry(int x){
		if(s==e)return v.get(x);
		if(x<=m)return min(l->qry(x),v.get(x));
		return min(r->qry(x),v.get(x));
	}
}*root;

int main(){
	int n;ll c;
	scanf("%d%lld",&n,&c);
	for(int i=0;i<n;i++){
		scanf("%lld",&h[i]);
	}
	root=new node(0,1000005);
	ll dp[n];dp[0]=0;
	for(int i=0;i<n;i++){
		if(i>0)dp[i]=root->qry(h[i])+c+h[i]*h[i];
		root->upd(line{-2*h[i],h[i]*h[i]+(i==0?0:dp[i])});
	}
	printf("%lld",dp[n-1]);
}


Measured memory_bytes: 131884
n = int(input())
t, a = map(int, input().split())
ans, at = 0, float('inf')
for i, h in enumerate(map(int, input().split())):
    tt = abs(t - h * 0.006 - a)
    if at > tt:
        ans = i + 1
        at = tt
print(ans)


Measured memory_bytes: 3060
enc_s = " |'|,|-|.|?|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"
enc_i = "101|000000|000011|10010001|010001|000001|100101|10011010|0101|0001|110|01001|10011011|010000|0111|10011000|0110|00100|10011001|10011110|00101|111|10011111|1000|00110|00111|10011100|10011101|000010|10010010|10010011|10010000"
enc = dict(zip([i for i in enc_s.split("|")],[i for i in enc_i.split("|")]))
dec_s = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z| |.|,|-|'|?"
dec_i = "00000|00001|00010|00011|00100|00101|00110|00111|01000|01001|01010|01011|01100|01101|01110|01111|10000|10001|10010|10011|10100|10101|10110|10111|11000|11001|11010|11011|11100|11101|11110|11111"
dec = dict(zip([i for i in dec_i.split("|")],[i for i in dec_s.split("|")]))
def encode(a):
    return "".join([enc[i] for i in list(a)])
def decode(a):
    return "".join([dec[i] for i in a])

while(1):
    try:
        a = input()
        encoded = encode(a)
        l = len(encoded)%5
        l = 5 if l == 0 else l
        encoded = encoded + "0"*(5-l)
        l_ = int(len(encoded)/5)
        enc_list = [encoded[5*i:5*(i+1)] for i in range(l_)]
        decoded = decode(enc_list)
        print(decoded)
    except EOFError:
        break



Measured memory_bytes: 5576
#include <stdio.h>

int calcmoney(int,int);

int main(void)
{
  int n,x,y,h,w;
  int i;
  int sum=0;
  int money=0;

  while(1)
    {
      scanf("%d",&n);
      if(n == 0) break;

      money = 0;

      for(i = 0 ; i < n ; i++)
	{
	  
	  scanf("%d %d %d %d",&x,&y,&h,&w);
	  sum = x + y + h;
	  money += calcmoney(sum,w);
	  sum = 0;
	}
      printf("%d\n",money);
    }
  return 0;
}

int calcmoney(sum,w)
{
  char size;
  int result=0;

  if(sum <= 60 && w <= 2) size = 'A';
  else if(sum <= 80 && w <= 5) size = 'B';
  else if(sum <= 100 && w <= 10) size = 'C';
  else if(sum <= 120 && w <= 15) size = 'D';
  else if(sum <= 140 && w <= 20) size = 'E';
  else if(sum <= 160 && w <= 25) size = 'F';

  if(size == 'A') result = 600;
  else if(size == 'B') result = 800;
  else if(size == 'C') result = 1000;
  else if(size == 'D') result = 1200;
  else if(size == 'E') result = 1400;
  else if(size == 'F') result = 1600;
  
  return result;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
int main(){
	FAST
	ll n, k, mod=1e9+7;
	cin>>n>>k;
	vector<ll> A(k+1,0);
	FOR(i,1,k)cin>>A[i];
	vector<ll>f(n+1,0),inv(n+1,0);
	auto qexp=[&](ll x,ll e){ll sum=1;for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;return sum;};
	f[0]=inv[0]=1; FOR(i,1,n)f[i]=f[i-1]*i%mod,inv[i]=qexp(f[i],mod-2);
	vector<vector<ll>> C(n+1,vector<ll>(n+1,0));
	FOR(i,0,n)C[i][0]=1;
	FOR(i,1,n)FOR(j,1,n)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	vector<vector<ll>> dp(k+1,vector<ll>(n+1,0));
	dp[0][n]=1;
	FOR(i,1,k){
		FOR(j,0,n){
			FOR(l,j,min(j+A[i],n)){
				dp[i][j] += dp[i-1][l] * C[l][l-j] % mod * 
					C[n-(l-j)][A[i]-(l-j)] % mod, 
				dp[i][j] %= mod;
			}
			// cerr<<i<<' '<<j<<": "<<dp[i][j]<<'\n';
		}
	}
	cout<<dp[k][0]<<'\n';
}


Measured memory_bytes: 11652
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <stack>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <bitset>

/*----------------------------------------------------------------*/

using ld = long double;
using vld = std::vector<ld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using str = std::string;
using vstr = std::vector<str>;
using vb = std::vector<bool>;
using vvb = std::vector<vb>;

/*----------------------------------------------------------------*/

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }
template<typename T> T square(T a) { return a * a; }

/*----------------------------------------------------------------*/

constexpr ld PI = 3.141592653589793L;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e12;

/*----------------------------------------------------------------*/

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
ll ctz(ll n) { ll ans = 0; for (; ~n & 1; n >>= 1) ans++; return ans; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
ll popcnt(ll n) {
    n = ((n & 0xaaaaaaaaaaaaaaaa) >> 1) + (n & 0x5555555555555555);
    n = ((n & 0xcccccccccccccccc) >> 2) + (n & 0x3333333333333333);
    n = ((n & 0xf0f0f0f0f0f0f0f0) >> 4) + (n & 0x0f0f0f0f0f0f0f0f);
    n = ((n & 0xff00ff00ff00ff00) >> 8) + (n & 0x00ff00ff00ff00ff);
    n = ((n & 0xffff0000ffff0000) >> 16) + (n & 0x0000ffff0000ffff);
    n = ((n & 0xffffffff00000000) >> 32) + (n & 0x00000000ffffffff);
    return n;
}
str zfill(str s, ll n) { return str(n - s.length(), '0') + s; }
ll to_ll(char c) { return (ll)c - '0'; }
ll to_ll(str s) {
    ll ans = 0;
    for (ll i = 0; i < s.length(); i++)
        ans = 10 * ans + to_ll(s[i]);
    return ans;
}

/*----------------------------------------------------------------*/

void Solve();

/*----------------------------------------------------------------*/

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    Solve();
}

void Solve() {
    ll n; std::cin >> n;

    vll s(n);
    for (ll i = 0; i < n; i++)
        std::cin >> s[i];

    ll q; std::cin >> q;

    auto f = [=](ll t) {
        ll left = 0, right = n;
        while (left <= right) {
            ll mid = (left + right) / 2;
            if (n <= mid) return false;
            if (s[mid] == t) return true;
            if (s[mid] < t) left = mid + 1;
            else right = mid - 1;
        }
        return false;
    };

    ll ans = 0;
    for (ll i = 0; i < q; i++) {
        ll t; std::cin >> t;
        ans += f(t);
    }

    std::cout << ans << '\n';
}



Measured memory_bytes: 4368
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		while (n - 500 >= 0)
			n -= 500;
		if (n <= a)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char s1[11];
char s3[11];
char s2[11];

scanf("%s %s %s", s1,s2,s3);
if( s1[strlen(s1)-1] == s2[0] && s2[strlen(s2)-1]==s3[0])
 printf("YES\n");
else printf("NO\n");

return 0;
}

Measured memory_bytes: 128
#include <cstdlib>
#include <iostream>
#include <istream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int N;
  	int cnt=1;
    cin >> N;
    string tmp1,tmp2;
    string buf;
    vector<string> H;
    string s[N+1];
    for(int i=0; i<N+1; ++i) {
        getline(cin,s[i]);
        stringstream ss{s[i]};
        while (getline(ss, buf, ' ')) {
            H.push_back(buf);
	    }
    }
    int max=0;
  	for(int i=0; i<N-1; ++i) {
      tmp1=H[i];
      tmp2=H[i+1];
      if(max<=stoi(tmp1)) max=stoi(tmp1);
      if(stoi(tmp1)<=stoi(tmp2)) {
        if(max<=stoi(tmp2)) {
            ++cnt;
            max=stoi(tmp2);
        }
      }
    }
  	cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
q = int(input())
num = {}
for i in a:
    if i in num:
        num[i] += 1
    else:
        num[i] = 1
ans = 0
for i in num:
    ans += i*num[i]
for i in range(q):
    b,c = map(int,input().split())
    if not b in num:
        num[b] = 0
    if not c in num:
        num[c] = 0
    ans += (c-b)*num[b]
    p = num[b]
    num[c] += num[b]
    num[b] = 0
    print(ans)


Measured memory_bytes: 23768
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
  ll n,x;
  cin >>n>>x;
  ll a[n],sum=0;
  for(ll i=0;i<n;i++) {
    cin >>a[i];
    sum+=a[i];
  }
  if(sum==x){
    cout<<n<<endl;
    return 0;
  }
  ll cnt=0;
  sort(a,a+n);
  for(ll i=n-1;i>=0;i--){
    sum-=a[i];
    cnt++;
    if(sum<=x) {
      cout << n-cnt<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
		
	public static void main(String args[]){
		  
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a >= 13) {
			System.out.println(b);
		}else if(a < 13 && a >= 6) {
			System.out.println(b/2);
		}else {
			System.out.println(0);
		}	
	}
}


Measured memory_bytes: 21588
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}


signed main(){
	IOS
	string s;	cin >> s;
	int ans = 0;
	int n = SZ(s);
	rep(i,n){
		if(i == n-1){
			if(s[n-i-1] - '0' <= 5)	ans += s[n-1-i] - '0';
			else	ans += 10 - s[n-i-1] + '0'+ 1;
		}
		else if(i == 0){
			if(s[n-i-1] - '0' < 5)	ans += s[n-1-i] - '0';
			else if(s[n-i-1] - '0' == 5 && s[n-i-2] - '0' <= 4){
				ans += s[n-i-1] - '0';
			}
			else{
				ans += 10 - s[n-i-1] + '0', s[n-i-2] ++,s[n-i-1] = '0';
			}
		}
		else{
			if(s[n-i-1] - '0' + (s[n-i] == 10) < 5)	ans += s[n-1-i] - '0';
			else if(s[n-i-1] - '0' + (s[n-i] == 10) == 5 && s[n-i-2] - '0' <= 4){
				ans += s[n-i-1] - '0';
			}
			else{
				ans += 10 - s[n-i-1] + '0', s[n-i-2] ++,s[n-i-1] = '0';
			}
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 1948
#include <stdio.h>

int main(){

  int i,j,k,v;

  int N;
  
  scanf("%d",&N);

  int A[N];

  for(k=0;k<N;k++){
    scanf("%d",&A[k]);
  }

  for(k=0;k<N;k++){
    printf("%d",A[k]);
    if(k!=N-1){
	printf(" ");
      }
    
  }
  printf("\n");

  for(i=1;i<N;i++){
  
    v=A[i];
    j=i-1;

    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
 
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k!=N-1){
	printf(" ");
      }
    }


      printf("\n");
    
  }


  return 0;
}
  



Measured memory_bytes: 2068
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a * c <= b) {
			System.out.println(c);
		}else {
			System.out.println(b/a);
		}
	}

}


Measured memory_bytes: 23252
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

#include <vector>

// ------ Class ------ //
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

#endif

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct edge { int s, t, c; };
bool operator<(const edge& e1, const edge& e2) { return e1.c < e2.c; }
int n, m;
int main() {
	while (scanf("%d%d", &n, &m), n | m) {
		vector<edge> v(m);
		for (int i = 0; i < m; i++) {
			scanf("%d%d%d", &v[i].s, &v[i].t, &v[i].c);
			v[i].s--, v[i].t--;
		}
		sort(v.begin(), v.end());
		int cnt = 0;
		UnionFind uf(n);
		for (int i = 0; i < n; i++) {
			if (!uf.same(v[i].s, v[i].t)) {
				uf.unite(v[i].s, v[i].t);
				cnt++;
			}
			if (cnt == n / 2) {
				printf("%d\n", v[i].c);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2732
#include <bits/stdc++.h>
#include <atcoder/all>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using namespace atcoder;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  int N,Q;
  cin >> N >> Q;
  VEC(ll,A,N);
  fenwick_tree<ll> fw(N);
  REP(i,N){
    fw.add(i,A[i]);
  }
  vector<ll> ans;
  REP(i,Q){
    int a;
    cin >> a;
    if(a==0){
      int p,x;
      cin >> p >> x;
      fw.add(p,x);
    }else{
      int l,r;
      cin >> l >> r;
      cout << fw.sum(l,r) << endl;
    }
  }
}


Measured memory_bytes: 12132
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
using namespace std;
int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll a,b;
		cin>>a>>b;
		cout<<(a*b)<<endl;
		
	}
}

Measured memory_bytes: 3632
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 } ;

int main() 
{
   ll a,b;
   cin>>a>>b;
   cout<<lcm(a,b);
	 
	}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText();
            return S=="ABC"?"ARC":"ABC";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 25788
H, W, K = map(int, input().split())

C = [list(input()) for _ in range(H)]

hbit = [[0]*H for _ in range(2**H)]
wbit = [[0]*W for _ in range(2**W)]

for i in range(2**H):
    for j in range(H):
        if ((i >> j)&1):
            hbit[i][j] = 1

for i in range(2**W):
    for j in range(W):
        if ((i >> j)&1):
            wbit[i][j] = 1

ans = 0
for hbi in range(2**H):
    for wbi in range(2**W):
        tmp = 0
        for i in range(H):
            for j in range(W):
                if hbit[hbi][i] or wbit[wbi][j]:
                    continue
                if C[i][j] =="#":
                    tmp += 1
        if tmp == K:
            ans += 1
print(ans)

Measured memory_bytes: 9248