akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}

//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}



int main(){
  int n, m;
  cin >> n >> m;
  vector<int> ac(n);
  vector<int> wa(n);

  rep(i, m){
    int p;
    string s;
    cin >> p >> s;
    p --;
    if(ac[p]) continue;
    if(s == "AC") ac[p] = 1;
    else wa[p] ++;
  }

  int AC = 0, WA = 0;
  rep(i, n){
    AC += ac[i];
    if(ac[i]) WA += wa[i];
  }
  printf("%d %d\n", AC, WA);
}


Measured memory_bytes: 1152
from collections import defaultdict
n, _ = map(int, input().split())
A = list(map(int, input().split()))

MAX_S = []
max_s = 0
for a in A[::-1]:
    if max_s < a:
        max_s = a
    MAX_S.append(max_s)
MAX_S = MAX_S[::-1]
cnt = defaultdict(int)
for a, s in zip(A, MAX_S):
    cnt[s-a] += 1

print(sorted(cnt.items(), reverse=True)[0][1])


Measured memory_bytes: 25436
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>

#define ll long long
using namespace std;

int main()
{
	string s;
	cin>>s;
	int n;
	scanf("%d",&n);
	int  tot=0,sp=0;
	int fl=0;
	while(n--)
	{
		int f;
		scanf("%d",&f);
		if(f==1) 
		{
			tot++;
			sp++;
		}
		else 
		{
			int t;
			scanf("%d",&t);
			char c;
			scanf(" %c",&c);
			if(fl==0)
			{
				if(tot%2==0)
				{
					if(t==2) s.push_back(c);
					else 
					{
						//s=s+c;
						string cc;
						cc.push_back(c);
						s.insert(0,cc);
					}
				}
				else 
				{
					if(t==1) s.push_back(c);
					else 
					{
						string cc;
						cc.push_back(c);
						s.insert(0,cc);
					}
					fl=1;
				}
			}
			else
			{
				if(tot%2==0)
				{
					if(t==1) s.push_back(c);
					else 
					{
						string cc;
						cc.push_back(c);
						s.insert(0,cc);
						
					}
				}
				else 
				{
					if(t==2) s.push_back(c);
					else 
					{
						string cc;
						cc.push_back(c);
						s.insert(0,cc);
					}
					fl=0;
				}
			}
			tot=0;
		}
	}
	if(sp&1) reverse(s.begin(),s.end());
	cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 900
s = input()
t = input()

if len(t) > len(s):
    print('UNRESTORABLE')
    exit()

s = s[::-1]
t = t[::-1]

for i in range(len(s) - len(t) + 1):
    j = 0
    while True:
        if j == len(t):
            ans = s[:i] + t + s[i+len(t):]
            print(ans[::-1].replace('?', 'a', len(ans)))
            exit()
        if t[j] == s[i+j] or s[i+j] == '?':
            j += 1
        else:
            break
print("UNRESTORABLE")

Measured memory_bytes: 9040
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
 
int main(){
	int n;
	cin>>n;
 
	vi a(n),b(n),c(n-1);
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>b[i];
	rep(i,n-1) cin>>c[i];
	int ans=0;
	rep(i,n){
		ans+=b[a[i]-1];
			if(a[i+1]==a[i]+1){
				ans+=c[a[i]-1];
			}
		}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[100] ={}, b[100]={}, c[100]={};
    int count = 0;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=n; i++){
        cin >> b[i];
    }
    for(int i=1; i<=n-1; i++){
        cin >> c[i];
    }
    int tmp = 1000000;
    for(int i=1; i<=n; i++){
        count += b[a[i]];
        if(tmp+1 == a[i]){
            count += c[tmp];
        }
        tmp = a[i];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <sys/time.h>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <chrono>

using namespace std;

// ---------- typedef ----------
typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t uint;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<double, double>> vpdd;
// ---------- define ----------
#define PI  3.1415926535
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = n >= m; i--)
#define FOREACH(it, v) for (it = v.begin(); it != v.end(); it++)

// ---------- template ----------
template < typename T > std::string to_string( const T& n ) {
	std::ostringstream stm;
	stm << n;
	return stm.str();
}
template< typename T > T sqr(const T& v) {
	return v * v;
}
// ---------- random ----------
uint xor128() {
	static uint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	uint t = x ^ (x << 11);
	x = y;
	y = z;
	z = w;
	return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
double sample() {
	return xor128() * 1.0 / numeric_limits<uint>::max();
}
//------------------------------
const int MAX_N = 1000000;
vector<ll> T;
//#define LOCAL
int main() {
#ifdef LOCAL
	freopen("input1.txt", "r", stdin);
	//freopen("out1.txt", "w", stderr);
#endif
	int N, C, K;
	cin >> N >> C >> K;
	for (int i = 0; i < N; i++) {
		int t; cin >> t;
		T.push_back(t);
	}
	sort(T.begin(), T.end());
	ll lastT = T[0];
	int tind = 0;
	int cnt = 0;
	int num = 1;
	for (int i = 1; i < N; i++) {
		ll TT = T[i];
		while (lastT + (ll)K < TT) {
			cnt++;
			tind += min(num, C);
			num -= min(num, C);
			lastT = T[tind];
		}
		num++;
	}
	cnt += num / C;
	if (num % C != 0) cnt++;

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
// const int N = 1e5 + 7;
typedef long long int lli;
// int a[N];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, w, val_max = 0;
    cin >> n >> w;
    vector<lli> val(n), wei(n);
    for (int i = 0; i < n; i++) {
        cin >> wei[i] >> val[i];
        val_max += val[i];
    }

    vector<lli> weight(val_max + 1, INT_MAX);

    weight[0] = 0;

    for (int i = 0; i < n; i++) {
        vector<lli> temp(val_max + 1);
        for (int j = 1; j <= val_max; j++) {
            temp[j] = min(
                weight[j],
                j - val[i] >= 0 ? weight[j - val[i]] + wei[i] : INT_MAX);
        }
        weight = temp;
    }

    // for (int i = 0; i <= val_max; i++) {
    //     cout << weight[i] << " ";
    // }
    // cout << endl;

    int ans = 0;

    for (int i = 0; i <= val_max; i++) {
        if (weight[i] <= w) {
            ans = i;
        }
    }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FOD(i,a,b) for(ll i=(a);i>=(b);--i)
#define name "a"
#define pb push_back
typedef pair < ll , ll > ii;
const ll maxn=1e5+7,oo=1e18,mod=1e9+7;
ll x,kq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);
    cin>>x;
    ll tmp=x/500;
    kq+=tmp*1000;
    x-=500*tmp;
    tmp=x/5;
    kq+=tmp*5;
    cout<<kq;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

int main() {
    LL k, a, b;
    cin >> k >> a >> b;

    if (a + 1 >= b) {
        cout << k + 1 << endl;
        return 0;
    }

    if (k <= a) {
        cout << k + 1 << endl;
        return 0;
    }

    k = k - a + 1;
    LL total = a;
    total += (k / 2) * (b - a);
    if (k % 2 == 1) total++;

    cout << total << endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i,N){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int max = p[N-1] / 2;
    int ans = 0;
    ans += max;
    rep(i,N-1){
        ans += p[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void main() {
    string s, t;
    scan(s);
    scan(t);
    auto n = s.length;
    int ans;
    foreach (i; 0 .. n) {
        ans += s[i] != t[i];
    }
    ans.writeln;
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 3408
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	long long x,ans=0;
	cin>>x;
	for(int i=0;i<x;i++){
		int a=i+1;
		for(int j=0;j<20;j++){
			a*=i+1;
			if(x>=a && a>ans){
				ans=a;
			}
			if(x<a){
				break;
			}
		}
	}
	cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3604
from itertools import permutations as perm

l = [int(input()) for _ in range(5)]
res = 10 ** 100
for p in perm(l):
    tmp = 0
    for i in p:
        tmp = (tmp + 9) // 10 * 10
        tmp += i
    res = min(res, tmp)
print(res)

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

const int MX = 100100;
bool inLS[MX];
vector<pair<int, int>> LS;  // [idx, val]
vector<int> res;

signed main() {
  int N;  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  res.assign(N, 0);
  
  int prv = A[0];
  LS.emplace_back(-1, 0);
  LS.emplace_back(0, prv);
  inLS[0] = true;
  
  for (int i = 1; i < N; ++i) {
    if (prv < A[i]) {
      prv = A[i];
      inLS[i] = true;
      LS.emplace_back(i, A[i]);
    }
  }
  
  reverse(LS.begin(), LS.end());
  
  int cnt = 0;
  ll sum = 0;
  
  priority_queue<int> pq;
  REP(i, N) pq.emplace(A[i]);
  
  int sz = LS.size();
  REP(i, sz - 1) {
    int tcnt = 0;
    ll tsum = 0;
    int until = LS[i + 1].second;
    while (not pq.empty() and pq.top() > until) {
      ++tcnt;
      tsum += pq.top();
      pq.pop();
    }
    int idx = LS[i].first;
    res[idx] += tsum - (ll)until * tcnt;
    res[idx] += (ll)(LS[i].second - until) * cnt;
    cnt += tcnt;
    sum += tsum;
  }
  
  REP(i, N) cout << res[i] << endl;
}

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

using namespace std;

signed main()
{
    long long  n;
    cin >> n;
    unsigned long long  sol =0;
    for(long long i =1; i<=n;i++)
    {
        long long  m = n/i;
        sol+=m*(m+1)/2*i;
    }
    cout<<sol<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	int d;
	set<int> dis;
	rep(i, n) { cin >> d;
		dis.insert(d);
	}
	cout<<dis.size()<<endl;
}

Measured memory_bytes: 3592
r, g, b, n = [int(item) for item in input().split()]

count = 0
for i in range(n + 1):
    for j in range(n + 1):
        if n - i * r - j * g >= 0 and (n - i * r - j * g) % b == 0:
            count += 1
            # print(i, j, n - i - j)

print(count)


Measured memory_bytes: 41324
#include<bits/stdc++.h>
#include<cstdio>
#define ll long long int
#define pb push_back
using namespace std;
int main()
{
    string s[200];
    ll i,j,k,n,f=0,h,w;
    cin>>h>>w;
    for(i=0;i<h;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<w+2;i++)
    {
        cout<<"#";
    }
    cout<<endl;
    for(i=0;i<h;i++)
    {
        cout<<"#"<<s[i]<<"#"<<endl;
    }
     for(i=0;i<w+2;i++)
    {
        cout<<"#";
    }
    cout<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll x, y, z;
  cin >> x >> y >> z;
  ll l = 0, r = 10010101010;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (m * y + (m + 1) * z <= x) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> tree(n);
  for(int i=0; i<n; i++) cin >> tree[i];

  sort(all(tree));
  long Max = tree[k-1];
  long Min = tree[0];
  long ans = Max - Min;
  for(int i=1; i<n; i++){
    if(i+k-1<n){
      Max = tree[k+i-1];
      Min = tree[i];
      ans = min(ans, Max - Min);
    }
  }
  

  cout << ans << ln;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
vector <int> v, c;
vector<int> idx;
int ans = INT_MIN;
int max_dif() {
    int sum = 0, dif = 0;
    for(int elm : idx) {
        sum += v[elm];
        dif += c[elm];
    }
    return sum - dif;
}
void backtrack() {
    ans = max(ans, max_dif());
    int aux = -1;
    if(!idx.empty()) aux = idx.back();
    for(int i = aux + 1; i <= n; i++) {
        idx.push_back(i);
        backtrack();
        idx.pop_back();
    }
}
int main() {
    cin >> n;
    int tmp;
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        v.push_back(tmp);
    }
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        c.push_back(tmp);
    }
    backtrack();
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
s = input()
x = list(map(int, list(s)))
x = x[::-1]
dic = [0 for _ in range(2020)]
ten = 1
y = 0
for i in range(len(s)):
    y = (y+ten*x[i])%2019
    dic[y] += 1
    ten = (ten*10)%2019
result = 0
for i in range(2019):
    result += max([dic[i]*(dic[i]-1)//2, 0])
result += dic[0]
print(result)


Measured memory_bytes: 12256
n = int(input())
b = list(map(int,input().split()))
a = [0]*n
a[n-1] = b[n-2]
for i in range(n-1):
    if b[n-2-i] >= b[n-i-3]:
       a[n-2-i] = b[n-i-3]
    else:
       a[n-2-i] = b[n-i-2]
a[0] = b[0]
print(sum(a))

Measured memory_bytes: 3064
/**
 * ???????????£????????????
??\?????????????????????????????????????????£???????????????????£??????????????????????

insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶???????
delete x: ?????? x
??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????
deleteFirst: ?????????????????????????´???????????????????
deleteLast: ????????????????°????????´???????????????????
??\???
??\????????\????????¢?????§?????????????????????

n
command1
command2
...
commandn
???????????????????????° n ?????????????????????????¶???? n
??????????????????????????????????????????????¨?4?????????????????????????????§?????????????????´??°??¨????????????

??????
??¨??????????????????????????????????????£?????????????????????????????????????????????????????????????????£?¶???????????????????????????????????????§????????£??????????????????????????????

??¶?´?
????????°??? 2,000,000 ????¶?????????????
delete ??????????????°??? 20 ????¶?????????????
0 ??? ???????????? ??? 10^9???
?????????????¨???§????????????????´???°??? 106????¶?????????????
delete, deleteFirst, ????????? deleteLast
??????????????????????????¨?????????????????????????????\??????????´?????????¨????????? ??\?????? 1
7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
????????? 1
6 1 2
??\?????? 2
9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast
????????? 2
1

 */

#include <iostream>
#include <list>
#include <sstream>
#include <iterator>
#include <algorithm>

void printList(const std::list<unsigned int> &l) {
  std::ostringstream oss;
  std::copy(l.begin(), --l.end(),
            std::ostream_iterator<unsigned int>(oss, " "));
  oss << l.back();
  std::cout << oss.str() << std::endl;
}

int main(int argc, char const *argv[]) {
  std::string Param;
  std::istringstream iss;
  std::list<unsigned int> List;
  unsigned int n;
  std::string Command;
  unsigned int x;
  getline(std::cin, Param);
  iss.str(Param);
  iss >> n;
  iss.clear();
  for (size_t i = 0; i < n; i++) {
    getline(std::cin, Param);
    iss.str(Param);
    iss >> Command >> x;
    iss.clear();
    if (Command == "insert") {
      List.push_front(x);
    } else if (Command == "delete") {
      auto itr = std::find(List.begin(), List.end(), x);
      if (itr != List.end()) {
        List.erase(itr);
      }
    } else if (Command == "deleteFirst") {
      List.pop_front();
    } else if (Command == "deleteLast") {
      List.pop_back();
    }
  }
  printList(List);

  return 0;
}

Measured memory_bytes: 34408
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int a,b,c,x,y;
LL sum;
int main(){
	sum=0;
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	int h=min(x,y);
	if(h*a+h*b>h*2*c){
		if(x>=h&&y<=h){
			sum+=h*2*c;
			if((x-h)*a>=2*(x-h)*c) sum+=2*(x-h)*c;
			else sum+=(x-h)*a;
			printf("%lld\n",sum);
		}
		else{
			sum+=h*2*c;
			if((y-h)*b>=2*(y-h)*c) sum+=2*(y-h)*c;
			else sum+=(y-h)*b;
			printf("%lld\n",sum);
		}
	}
	else{
		sum+=h*a+h*b;
		if(x>=h&&y<=h){
			if((x-h)*a>=2*(x-h)*c) sum+=2*(x-h)*c;
			else sum+=(x-h)*a;
			printf("%lld\n",sum);
		}
		else{
			if((y-h)*b>=2*(y-h)*c) sum+=2*(y-h)*c;
			else sum+=(y-h)*b;
			printf("%lld\n",sum);
		}
	}
}

Measured memory_bytes: 256
import sys

def main():
  out = 0
  for i in range(1, n+1):
    if dp[i]:
        di = dp[i]
        if di > out:
            out = di
    else:
        di = cal(i)
        if di > out:
            out = di
  print(out)

def cal(a):
  if xy[a]:
    ans = 0
    for b in xy[a]:
      if dp[b]:
        num = dp[b]
      else:
        num = cal(b)
        dp[b] = num
      if num+1 > ans:
        ans = num+1
    return ans
  return 0

if __name__ == "__main__":
  sys.setrecursionlimit(100000)
  n, m = map(int, input().split())
  xy = [set() for _ in range(n+1)]
  dp = [None]*(n+1)
  for _ in range(m):
    x, y = map(int, input().split())
    xy[x].add(y)
  main()



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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 3e5 + 5, MOD = 1e9 + 7, MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

ll arr[MAX];
ll koyta[MAX][65];
int main(){

    fastio;
    int n;
    cin>>n;
    for(int i=0; i<n; i++) cin>>arr[i];
    for(int i=n-2; i>=0; i--){
        for(int j=0; j<=60; j++){
            koyta[i][j] = koyta[i+1][j];
            if((1ll << j) & arr[i+1]) koyta[i][j]++;
        }
    }

    ll ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=60; j++){
            if((1ll << j) & arr[i]){
                ll temp = ( ((1ll << j) % MOD) * ((n-i-1 - koyta[i][j]) % MOD) ) % MOD;
                ans += temp;
                ans %= MOD;
            }
            else{
                ll temp = ( ((1ll << j) % MOD) * (koyta[i][j] % MOD) ) % MOD;
                ans += temp;
                ans %= MOD;
            }
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 155008
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
#include<stdio.h>
#include<complex>
using namespace std;

#define rep(i,n) for(long long i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

ulli gcd(ulli a, ulli b) {return (b <= 0) ? a : gcd(b, a % b);}
ulli lcm(ulli a, ulli b) {return a * b / gcd(a, b);}

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	int n;
	cin >> n;
	int sum = 0;
	sum += (n / 500) * 1000;
	sum += ((n % 500) / 5) * 5;
	cout << sum << endl;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
using namespace std;
typedef long long ll;
typedef double db;
const int N = 500010;
int n, D, Q, d[N], f[N];
bool ans[N];
int main()
{
	scanf ("%d%d", &n, &D);
	Rep(i, 1, n) scanf ("%d", &d[i]);
	f[n + 1] = 1;
	Dwn(i, n, 1) {
		if (2 * f[i + 1] <= d[i]) f[i] = f[i + 1];
		else f[i] = f[i + 1] + d[i];
			// if (f[i + 1] <= d[i]) f[i] = 
	}
	Rep(i, 1, n) {
		if (f[i + 1] <= D) ans[i] = 1;
		else ans[i] = 0;
		D = min(D, abs(D - d[i]));
	}
	scanf ("%d", &Q);
	while (Q --) {
		int x;
		scanf ("%d", &x);
		puts(ans[x] ? "YES" : "NO");
	}

	return 0;
}

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

#define M 1000000
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  key %= M;
  return key;
}
int h2(int key){
  key = 1 + key % (M - 1);
  return key;
}

int find(char str[]){
  int key1, key2;
  key1 = h1(getKey(str));
  key2 = h2(getKey(str));
  while(H[key1][0] != NULL){
    if(strcmp(H[key1],str) == 0){
      return 1;
    }
    else{
      key1 += key2;
      if(key1 > M){
	key1 -= M;
      }
      continue;
    }
  }
  return NIL;
}

int insert(char str[]){
  int key1, key2;
  key1 = h1(getKey(str));
  key2 = h2(getKey(str));
  while(1){
    if(H[key1][0] == NULL||strcmp(H[key1],str) == 0){
      strcpy(H[key1],str);
      break;
    }
    else{
      key1 += key2;
      if(key1 > M){
	key1 -= M;
      }
      continue;
    }
  }
  return 1;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str) == 1){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

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

using namespace std;

int main() {
   int a, b;
   cin >> a >> b;
   if (b % a == 0) cout << a + b << endl;
   else cout << b - a << endl;
   return 0;
}


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

int main(void) {
	long long H;
	cin >> H;
	long long ans = 0;
	long long monster_cnt = 1;
	while (H>1) {
		ans += monster_cnt;
		H = H/2;
		monster_cnt *= 2;
	}
	ans += monster_cnt;
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>

using namespace std;

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

	for (int i = 1;i <= 1000;i++) {
		int tmp = k * i;
		if (tmp >= a && tmp <= b) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

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

int main(){
	int num;
	int a[100];

	cin >> num;
	for ( int i = 0; i < num; i++) cin >> a[i];
	bool flag = true;
	int idx = 0;

	while (flag){
		flag = false;
		for ( int j = num -1; j >0; j--){
			if ( a[j] < a[j-1]){
				int tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;
				flag = true;
				idx++;
			}
		}
	}
	for ( int i = 0; i < num - 1; i++){
		cout << a[i] << " ";
	}
	cout << a[num - 1] << endl;
	cout << idx << endl;
	return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; ++i) cin >> L[i];
    
    sort(L.begin(), L.end());
    int res = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N; ++j) {
            auto it = lower_bound(L.begin(), L.end(), L[i] + L[j]);
            int ng = (int)distance(it, L.end());
            res += N - 1 - j - ng;
        }
    }
    
    cout << res << endl;
}

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

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e5+5;
const int MOD=1e9+7;
const int MAAX=1e18;
const long double EPS=1e-6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2);
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a * a % MOD;
}

map<string,int> mp;
string s[200010];

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //scanf("%lld",&tc);
    while(tc--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>s[i];
            mp[s[i]]++;
        }
        priority_queue<pair<int,string>> pq;
        for(int i=0;i<n;i++){
            if(mp[s[i]]){
                pq.push({mp[s[i]],s[i]});
                mp[s[i]]=0;
            }
        }
        int x=pq.top().f;
        vector<string> v;
        while(!pq.empty()&&pq.top().f==x){
            v.pb(pq.top().s);
            pq.pop();
        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
            cout<<v[i]<<endl;
        }
    }
    ///matensa4 tegarab el sample w te7ot el freopen w te3mel SCANF
    RETURN;
}


Measured memory_bytes: 34284
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort(reverse=True)
    alice = sum([v for i, v in enumerate(a_list) if i % 2 == 0])
    bob = sum([v for i, v in enumerate(a_list) if i % 2 == 1])
    print(alice - bob)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    string S,T;cin>>S>>T;
    ll ans=0;
    REP(i,S.size()){
        if(S[i]==T[i])ans++;
    }
    cout<<ans<<"\n";
}


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

int main()
{
    int N, K;
    int l[55];
    int sum = 0;

    cin >> N >> K;

    for(int i = 0; i < N; i++) cin >> l[i];

    sort(l, l + N, greater < int > () );

    for(int i = 0; i < K; i++) {
        sum += l[i];
    }

    cout << sum << endl;

    return (0);
}


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

int main() {

    string S;
    cin >> S;

    vector<string> D ={ "dream", "dreamer", "erase", "eraser" };
    int index = S.size();

    bool ok = true;
    int word_size = 0;
    while (ok && index > 1) {
        ok = false;
        for (int i = 0; i <D.size(); i++) {
            word_size = D.at(i).size();

            if (index - word_size < 0) {
                continue;
            }
            
            if (S.substr(index - word_size, word_size) == D.at(i)) {
                ok = true;
                index -= word_size;
                break;
            }
        }
    }

    if (index == 0) {
        cout << "YES" <<endl;
    }
    else {
        cout << "NO" <<endl;
    }

    return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	string s;
	map<string,int> ct;
	for (int i=0; i<n; i++)
		cin>>s, ct[s]++;
	int m; cin>>m;
	for (int i=0; i<m; i++)
		cin>>s, ct[s]--;
	int ret=0;
	for (auto it : ct)
		ret=max(ret,it.second);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  long long n,k,i,j;
  while(scanf("%lld",&n),n){
    k=1e18;
    for(i=0;i*i*i<=n;i++){
      for(j=0;j*j<=n;j++){
	if(i*i*i+j*j>n)continue;
	k=MIN(n-i*i*i-j*j+i+j,k);
      }
    }
    printf("%lld\n",k);
  }
  return 0;
}



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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,m,sum=0,d;
    cin>>n>>m;
    while(m--){
    	cin>>d;
    	sum+=d;
	}
	if(sum>n){
		cout<<-1;
	}
	else{
		cout<<abs(sum-n);
	}
    return 0;
}

Measured memory_bytes: 3644
from itertools import groupby

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

def main():
    for t in T:
        if t in S:
            S.remove(t)
    S.sort() # have to sort before using groupby()
    ans = [len(list(g)) for key, g in groupby(S)]
    print(max([0] + ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

bool res;

pair<int, int> calc(int now, int prv, const vector<int>& num, const vector<vector<int> >& G) {
  vector<pair<int, int> > S;
  for (int nxt : G[now]) {
    if (nxt == prv) continue;
    S.push_back(calc(nxt, now, num, G));
  }
  if (!S.size()) return pair<int, int>(num[now], num[now]);
  int min_sum = 0, max_sum = 0;
  for (auto pr : S) {
//    printf("%d : %d %d\n", now, pr.first, pr.second);
    min_sum += pr.first;
    max_sum += pr.second;
  }
  if (max_sum < num[now] || min_sum > num[now] * 2) {
    res = false;
    return pair<int, int>(0, 0);
  }
//  printf("!\n");

  pair<int, int> ret;
  int use = max_sum - num[now];
//  printf("use = %d\n", use);
  ret.first = ret.second = max_sum - use * 2;
  for (auto pr : S) {
    if ((max_sum - pr.second) < use) {
      res = false;
      return pair<int, int>(0, 0);
    }
  }
//  printf("now : %d %d, res = %d\n", ret.first, ret.second, res);
  return ret;
}

bool ok() {
  int N;
  cin >> N;
  vector<int> num(N);
  for (int i=0; i<N; i++) cin >> num[i];
  vector<vector<int> > G(N);
  for (int i=0; i<N-1; i++) {
    int a, b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  if (N == 2) {
    return (num[0] == num[1]);
  }

  res = true;
  int st = 0;
  while (G[st].size() == 1) st ++;
  pair<int, int> now = calc(st, -1, num, G);

  if (!res) return false;
  if (now.first != 0) return false;
  return true;
}

int main()
{
  if (ok()) printf("YES\n"); else printf("NO\n");
}


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


int main(void){
  int N;
  cin >> N;
  int V[N], C[N], a;
  int i = 0;
  while(cin >> a) {
    V[i] = a;
    i++;
    if(i == N) {
      break;
    }
  }
  i=0;
  while(cin >> a) {
    C[i] = a;
    i++;
    if(i == N) {
      break;
    }
  }

  int x = 0;
  int y = 0;
  for(int j=0;j<N;j++) {
    if(V[j] > C[j]) {
      x += V[j];
      y += C[j];
    }
  }
  cout << x - y << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int n,k,i,ii,iii;
int min = 999;
int sum = 0;
int minsum = 0;
scanf("%d %d",&n,&k);
int l[n];
int t = n - k;
for(i = 0;i < n;i++){
	scanf("%d",&l[i]);
	sum += l[i];
	}

for(i = 0;i < t;i++){
		min = 999;
	for(ii = 0;ii < n;ii++){
		if(min > l[ii])
			min = l[ii];
		}
	for(iii = 0;iii < n;iii++){
		if(min == l[iii]){
			l[iii] = 999;
                        break;
                                       }
		}	
		minsum += min;
		}
printf("%d",sum - minsum);
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root;

void insert(int k){
  Node y = NULL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  while(x!=NULL)
    {
      y=x;
      if(z->key < x->key){
	x=x->left;
      }
      else {
	x=x->right;
      }
    }
  if(y==NULL) root=z;
  else if(y->key > z->key) y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if(u!=NULL)
    {
      inorder(u->left);
      printf(" %d",u->key);
      inorder(u->right);
    } 
}

void preorder(Node u){
  if(u != NULL)
    {
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
}

Node find(int x,Node u){
  while(u!=NULL&&u->key!=x){
    if(x < u->key)
      u=u->left;
    else
      u=u->right;
  }
  return u;
}

int main(){
  int n, i, x,c;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
   
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0]=='f'){
      scanf("%d",&x);
      if(find(x,root)!=NULL){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }

  return 0;
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll c = 0;
    while(X <= Y) {
        X *= 2;
        ++c;
    }
    PR(c);
    
    return 0;
}

/*



*/

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	int n; scanf("%d", &n);
	map<int, int>cnt;
	rep(i, n) {
		int a; scanf("%d", &a);
		cnt[a]++;
	}
	vector<int>v, u;
	for (auto p : cnt) {
		if (p.second >= 2)v.push_back(p.first);
		if (p.second >= 4)u.push_back(p.first);
	}
	sort(v.begin(), v.end(), greater<>());
	sort(u.begin(), u.end(), greater<>());
	if (v.size() < 2) {
		puts("0"); return 0;
	}
	printf("%lld\n", max(v[0] * (ll)v[1], u.size() ? u[0] * (ll)u[0] : 0LL));
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
  lli a,b,x;
  cin>>a>>b>>x;
  if(a%x)
  {
    cout<<(b/x-a/x)<<"\n";
  }
  else
    cout<<1+(b/x-a/x)<<"\n";

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a4 = 0
a2 = 0
a0 = 0
for i in a:
    if i % 4 == 0:
        a4 += 1
    elif i % 2 == 0:
        a2 = 1
    elif i % 2 != 0:
        a0 += 1
if a4 + 1 - a2 < a0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    string s,t;cin>>s>>t;
    string ans="";
    rep(i,n){ans+=s[i];ans+=t[i];}
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))

    snuke = [False] * n

    for i in range(k):
        d = int(input())
        a = list(map(int, readline().split()))
        for num in a:
            snuke[num-1] = True

    ans = snuke.count(False)
    print(ans)

if __name__ == '__main__':
    main()


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n;
string s;

int dp[maxn][3];

int32_t main()
{
    IOS
    cin>>s;
    n=s.length();
    dp[n-1][0]=s.back()-'0';
    dp[n-1][1]=1+10-(s.back()-'0');
    //cout<<dp[n-1][0]<<' '<<dp[n-1][1]<<endl;
    for (int i=n-2;i>=0;i--)
    {
        dp[i][0]=min(dp[i+1][0],dp[i+1][1])+s[i]-'0';
        dp[i][1]=min(dp[i+1][0]+1+10-(s[i]-'0'),dp[i+1][1]+9-(s[i]-'0'));
      //  cout<<dp[i][0]<<' '<<dp[i][1]<<endl;
    }
    cout<<min(dp[0][0],dp[0][1])<<endl;
}



Measured memory_bytes: 13084
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = Counter(A)

for _ in range(Q):
    B, C = map(int, input().split())
    sum_res += (C - B) * counter[B]
    counter[C] += counter[B]
    counter[B] = 0
    print(sum_res)


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

const long long MOD = 1000000007;
const long long MAX = 2000000;

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main()
{
    int H, A;
    cin >> H >> A;
    if(H%A==0){
        cout << H / A << endl;
    }else{
        cout << H / A + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
int main()
{
	// スペース区切りの整数の入力
	long b, c;
	cin >> b >> c;
	int count = 0;
	for (int i = 0; i<b; i++)
	{
		long n, m;
		cin >> n >> m;
		if (((n*n) + (m*m)) <= c*c)
		{
			count++;
		}

	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> image(H);
  
  for (int w = 0; w < W + 2; w++) {
    cout << '#';
  }
  cout << endl;
  
  for (int h = 0; h < H; h++) {
    for (int i = 0; i < 3; i++) {
      if (i == 0) {
        cout << '#';
      } else if (i == 1) {
        string pixels;
        cin >> pixels;
        cout << pixels;
      } else {
        cout << '#' << endl;
      }
    }
  }
  for (int w = 0; w < W + 2; w++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 3608
#include <stdio.h>
 
int main(void){
  float x1,y1,x2,y2,x3,y3,x4,y4;
  double dm,dn;
  int i,n;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
 
    dm=(y2-y1)/(x2-x1);
    dn=(y4-y3)/(x4-x3);
 
    if(dm == dn){
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		map<string,pii>ma;
		bool h=false;int t0=0;
		rep(i,n){
			string a,b,c;
			cin>>a>>a>>b>>c;
			int t=60*stoi(a.substr(0,2))+stoi(a.substr(3,2));
			if(c=="000"){
				h^=1;
				if(h==false)
					for(auto j=ma.begin();j!=ma.end();j++)if(j->second.second){
						j->second.first+=t-max(t0,j->second.second);
					}
				t0=t;
				continue;
			}
			if(b=="I") ma[c].second=t;
			else{
				if(h)ma[c].first+=t-max(t0,ma[c].second);
				ma[c].second=0;
			}
		}
		int out=0;
		for(auto i=ma.begin();i!=ma.end();i++)out=max(out,i->second.first);
		cout<<out<<endl;
	}
}

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


int main(){
  int n,i;
  cin >> n;
  vector<int> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  int ans=0;
  for(i=0;i<n-1;++i){
    if(a[i]==a[i+1]){
      ans++;
      if(a[i]==a[i+2] && i<n-2){
        i++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256