akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

class Map : public map<char,int> {
public:
  void add(char& c) {
    if (this->count(c) > 0)
      this->at(c)++;
    else
      (*this)[c] = 1;
  }

  void del(char& c) {
    if (this->at(c) > 1)
      this->at(c)--;
    else
      this->erase(c);
  }

  // void print() {
  //   for (auto x : *this) {
  //     cerr << x.first << x.second << ' ';
  //   }
  //   cerr << endl;
  // }
};

int common_keys(Map& X, Map& Y)
{
  vector<char> v(30);
  auto it = v.begin();

  // X.print();
  // Y.print();  
  
  vector<char> X_keys, Y_keys;
  for (auto& x : X)
    X_keys.push_back(x.first);
  for (auto& y : Y)
    Y_keys.push_back(y.first);
  
  it = set_intersection(X_keys.begin(),X_keys.end(),Y_keys.begin(),Y_keys.end(),v.begin());
  
  v.resize(it-v.begin());

  // cerr << "common:";
  // for (auto& vv : v)
  //   cerr << vv << ' ';
  // cerr << endl;
  
  return v.size();
}

int main()
{
  int N;
  string S;
  cin >> N;
  cin >> S;

  Map X,Y;

  for (char& c : S) {
    Y.add(c);
  }

  int max_keys = 0;

  for (int ii=0; ii<N; ++ii) {    
    X.add(S[ii]);
    Y.del(S[ii]);
    max_keys = max(max_keys,common_keys(X,Y));
  }

  cout << max_keys << endl;
  
  return 0;
}


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

using namespace std;
int main(){
    int N,M;
    cin >>N>>M;
    int s[N+1]={};
    int ml=1;
    int mr=N;
    for(int i=1;i<=M;i++){
        int L,R;
        cin >>L >>R;
        ml=max(ml,L);
        mr=min(mr,R);
         }
         if(ml>mr){
             cout <<"0"<<endl;
         }
         else{
             cout <<mr-ml+1<<endl;
         }
 return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> B(N);
  REP(i, N) cin >> B[i];

  priority_queue<pair<int, int>> q;
  REP(i, N) q.push({B[i], i});

  int cnt = 0;
  while(!q.empty()){
    auto p = q.top(); q.pop();
    if(B[p.second]-B[(p.second+N-1)%N]-B[(p.second+1)%N] >= A[p.second]){
      int mi = B[(p.second+N-1)%N]+B[(p.second+1)%N];
      int now = (B[p.second]-A[p.second])/mi;
      B[p.second] -= now*mi;
      cnt += now;
      if(B[p.second] != A[p.second]) q.push({B[p.second], p.second});
    }
  }

  REP(i, N){
    if(A[i] != B[i]){
      cout << -1 << "\n";
      return 0;
    }
  }
  cout << cnt << "\n";

  return 0;
}

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

ans = 0
max_match = 0
match = 0
for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] == t[j]:
            match += 1
    else:
        max_match = max(max_match, match)
        match = 0

ans = len(t) - max_match

print(ans)



Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 110


ll h,w;
char a[M][M];
ll dp[M][M][3];
ll ok(ll i,ll j){
	if(i<0 or j<0 or i>=h or j>=w)return 0;
	if(a[i][j]=='.')return 1;
	return 2;
}	
ll f(ll i,ll j,ll pev){
	if(!ok(i,j))return inf;
	if(i==h-1 and j==w-1){
		if(pev==2)return 0;
		return ok(i,j)==2?1:0;
	}
	if(dp[i][j][pev]!=-1)return dp[i][j][pev];
	ll ans1=0,ans2=0,now=ok(i,j);
	if(pev==2){
		if(now==2)ans1=f(i+1,j,2),ans2=f(i,j+1,2);
		if(now==1)ans1=f(i+1,j,1),ans2=f(i,j+1,1);
	}
	else {
		if(now==2)ans1=1+f(i+1,j,2),ans2=1+f(i,j+1,2);
		if(now==1)ans1=f(i+1,j,1),ans2=f(i,j+1,1);
	}
	return dp[i][j][pev]=min(ans1,ans2);
}
int main(){
	IOS;
	tihs;

	memset(dp,-1,sizeof(dp));
	cin>>h>>w;
	rep(i,0,h)rep(j,0,w)cin>>a[i][j];
	cout<<f(0,0,0);
	


	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; i + j <= k; j++)
		{
			ans = max(ans, (int)(a * pow(2, i) + b * pow(2, j) + c * pow(2, k - i - j)));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c,a*d,b*c,b*d}) << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string a;
  cin >> a;
  
  for(int s= 0; s < 8; s++) {
    int total = a[0] - '0';
    string totalText;
    totalText += a[0];
    for(int i = 0; i < 3; i++){
        if((s >> i) & 1) {
          total += a[i+1] - '0';
          string partText;
          partText += "+";
          partText += a[i+1];
          totalText += partText;
        } else {
          total -= a[i+1] - '0';
          string partText;
          partText += "-";
          partText += a[i+1];
          totalText += partText;
        }
    }
    if (total == 7) {
      cout << totalText << "=7" << endl;
      break;
    }
  }
 
}


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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    LL a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k % 2) cout << b-a; else cout << a-b;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
num=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  a-=1;b-=1
  num[a]+=1;num[b]+=1
flag=0
for i in num:
  if i%2==1:
    flag=1
    break
if bool(flag):print("NO")
else:print("YES")


Measured memory_bytes: 3828
function Main(input) {
  const [x, k, d] = input.trim().split(" ").map((a) => parseInt(a, 10));
  const absX = Math.abs(x);
  const n = Math.floor(absX / d);
  if (k <= n) {
    console.log(absX - k * d);
  } else {
    const rem = k - n;
    if (rem % 2 === 0) {
      console.log(absX - d * n);
    } else {
      console.log(d - (absX - d * n));
    }
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29616
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
using namespace std;
int main()
{
//fastio;
int n,m,x,y,q=-101,w=101,d,f,temp;
cin>>n>>m>>x>>y;
int b[m];
for(int i=0;i<n;i++)
{cin>>temp;
if(q<temp)
q=temp;
}
for(int i=0;i<m;i++)
{cin>>temp;
if(w>temp)
w=temp;
}
d=max(x,q);
f=min(y,w);
if(d<f)
cout<<"No War";
else
cout<<"War";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char c1 = getchar();
  int ans = 0;
  while(1){
    char c2 = getchar();
    if (c2 == 'B' || c2 == 'W'){
      if(c1 != c2){
        ans++;
      }
    }else{
      break;
    }
    c1 = c2;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{ 
    char S[5];
    scanf("%s",S);
   
    if(S[0]==S[1]) printf("Bad\n");
    else if(S[1]==S[2]) printf("Bad\n");
    else if(S[2]==S[3]) printf("Bad\n");
    else printf("Good\n");
    return 0;
}

Measured memory_bytes: 1660
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 998244353

N, S, *As = map(int, read().split())

U = 3010
answer = 0
f = np.zeros(U, np.int64)
for A in As:
    f[0] += 1
    f[A:] += f[:-A].copy()
    f %= MOD
    answer += f[S]

answer %= MOD
print(answer)


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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* main */
void Main(void)
{
    while (true)
    {
        string s;
        cin >> s;
        if (s == "0")
            return;
        int sum = 0;
        for (int i = 0; i < s.size(); i++)
        {
            sum += (s[i] - '0');
        }
        cout << sum << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    ll N;
    ll A, B;
    cin >> N >> A >> B;
    ll ans = N / (A + B) * A;
    double kari = (double)(A + B) / N;

    ans += min(A,N % (A + B));
    cout << ans << endl;
}

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

using namespace std;
int main(){
    int N = 0;
    cin >> N;
    vector<long long> A(N,0);
    for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    int temp = 0;
    int ans = 0;
    bool now = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (temp == A.at(i))
        {
            if (now)
            {
                ans--;
                now = 0;
            }
            else
            {
                ans++;
                now = 1;
            }
            
        }
        else
        {
            ans++;
            now = 1;
        }
        
        temp = A.at(i);
    }
    cout << ans << endl;
    
}

/*
int main() {
    int N = 0;
    cin >> N;
    vector<int> A(1000000001,0);
    long long temp;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> temp;
        if(A.at(temp)) {
            ans--;
            A.at(temp)--;
        } else {
            ans++;
            A.at(temp)++;
        }
    }
    cout << ans << endl;

    return 0;
}
*/

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n, k;
  cin >> n >> k;
  ll cnt = 0;
  for (int b = 1; b <= n; ++b)
  {
    int p = n / b;
    if (b > k)
    {
      cnt += p * (b - k);
      int r = n % b;
      if (r >= k)
        cnt += r - k + 1;
      if (k == 0)
        cnt--;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define P pair<int,int>
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n+1]={0};
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	P p[m+1];
	for(int i=0;i<m;i++)
	{
		int b,c;
		cin>>b>>c;
		p[i].first=c;
		p[i].second=b;
	}
	sort(p,p+m,greater<pair<int,int>>());
	int ctr=1;
	int ans=0;
	int f=0;
	for(int i=0;i<m;i++)
	{
		if(ctr==n+1||f)
			break;
		int add=p[i].first,times=p[i].second;
		for(int j=0;j<times;j++)
		{
			if(ctr==n+1)
				break;
			if(add>=a[ctr])
			{
				ans+=add;
				++ctr;
			}
			else
			{
				f=1;
				break;
			}
			
		}

	}
	// cout<<ans;
	if(ctr<n+1)
	{
		for(int i=ctr;i<=n;i++)
			ans+=a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    ll A, B, N;
    cin >> A >> B >> N;

    // cout << (A * (N - 1)) / B - A * ((N - 1) / B) << endl;
    if (B <= N) {
        cout << (A * (B - 1)) / B - A * ((B - 1) / B) << endl;
    } else {
        cout << A * N / B - A * (N / B) << endl;
    }

    // if (N % B == 0) {
    //     cout << A * (N - 1) / B - A * ((N - 1) / B) << endl;
    // } else {
    //     cout << A * N / B - A * (N / B) << endl;
    // }

    return 0;
}


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

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

main(){
  string s;
  cin >> s;
  int ans=0,l=0;
  for (int i=0;i<s.size();i++){
    if (s.at(i)=='A' || s.at(i)=='C' || s.at(i)=='G' || s.at(i)=='T'){
      l++;
    }
    else l=0;
    if (l>ans) ans=l;
  }
  cout << ans << endl;
}

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    long long A, B;
    cin >> A >> B;
    cout << A / GCD(A, B) * B << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

typedef long long ll;

const int MaxN = 100005;

int n, m;
std::vector<std::pair<int, bool>> G[MaxN];

int col[MaxN];
int num[3], deg; bool flag;

void dfs(int u, int c) {
	col[u] = c;
	num[c] += 1;
	deg += (int)G[u].size();
	for (auto e: G[u]) {
		int v = e.first;
		bool rev = e.second;
		int c_v = (col[u] + (rev ? 2 : 1)) % 3;
		if (col[v] == -1) {
			dfs(v, c_v);
		} else if (col[v] != c_v) {
			flag = true;
		}
	}
}

ll solve(int u) {
	std::fill(num, num + 3, 0);
	deg = 0;
	flag = false;
	dfs(u, 0);
	if (flag) {
		int tot = num[0] + num[1] + num[2];
		return (ll)tot * tot;
	} else if (num[1] == 0 || num[2] == 0) {
		return deg / 2;
	} else {
		return (ll)num[0] * num[1] + (ll)num[1] * num[2] + (ll)num[2] * num[0];
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		G[a].push_back({b, 0});
		G[b].push_back({a, 1});
	}
	std::fill(col + 1, col + n + 1, -1);
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (col[i] == -1) ans += solve(i);
	}
	printf("%lld\n", ans);
	return 0;
}

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

int decode(string s) {

  int res=0,c=1;
  for(int i=0; i<s.length(); i++) {
    if( s.at(i) >= '2' && s.at(i) <= '9' ) c = s.at(i) - '0';
    else if( s.at(i) == 'm' ) {
      res += c*1000;
      c = 1;
    }else if( s.at(i) == 'c' ) {
      res += c*100;
      c = 1;
    }else if( s.at(i) == 'x' ) {
      res += c*10;
      c = 1;
    }else if( s.at(i) == 'i' ) {
      res += c;
      c = 1;
    }
  }

  return res;

}

string encode(int i) {

  stringstream ss;
  string res = "";

  if( i >= 1000 ) {
    if( i/1000 >= 2 ) {
      ss << i/1000;
      res += ss.str();
    }
    res += "m";
    ss.str("");
    i %= 1000;
  }
  if( i >= 100 ) {
    if( i/100 >= 2 ) {
      ss << i/100;
      res += ss.str();
    }
    res += "c";
    ss.str("");

    i %= 100;
  }
  if( i >= 10 ) {
    if( i/10 >= 2 ) {
      ss << i/10;
      res += ss.str();
    }
    res += "x";
    ss.str("");

    i %= 10;
  }

  if( i != 0 ) {
    if( i >= 2 ) {
      ss << i;
      res += ss.str();
    }
    res += "i";
    ss.str("");
  }

  return res;
}

int main() {

  int m;
  cin>>m;
  string r,l;

  while(m--) {
    cin>>r>>l;

    cout<<encode(decode(r) + decode(l))<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

struct point{
	point(){};
	point(int a,int b){
		x=a,y=b;
	}
	int x,y;
};


point data[300];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int main(){
	data[0]=point(0,0);
	int N;
	while(cin>>N &&N){
		int l=0,r=0,u=0,md=0;
		for(int i=1;i<N;i++){
			int n,d;
			cin>>n>>d;
			data[i]=point(data[n].x+dx[d],data[n].y+dy[d]);
			l=min(l,data[i].x),r=max(r,data[i].x),u=max(u,data[i].y),md=min(md,data[i].y);
		}
		cout<<r-l+1<<" "<<u-md+1<<endl;
	}
}

Measured memory_bytes: 1160
/*
	Auth: Loxilante
	Time: 2020/09/19
	Prog: ABC179A
	Lang: cpp
*/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#endif
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
signed main(void)
{
	clock_t Begin = clock();

	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string str = next<string>();
	if (str[str.length()-1] == 's') str += "es";
	else str += "s";
	cout<<str<<endl;
	
	clock_t InputFinished = clock();
	
	
	
	clock_t End = clock();
	
	D((double)(End-Begin)/CLOCKS_PER_SEC);
	D((double)(End-InputFinished)/CLOCKS_PER_SEC);
	
	return 0;
}
/*

 */

Measured memory_bytes: 3688
package main
import "fmt"

func main(){
	var S,T string
	var a,b int
	var U string
	fmt.Scanf("%s %s", &S, &T)
	fmt.Scanf("%d %d", &a, &b)
	fmt.Scanf("%s", &U)

	if S == U{
		a -= 1
	}else{
		b -= 1
	}
	fmt.Println(a,b)
}

Measured memory_bytes: 512
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
    long mod = 1000000007;
		string s = Console.ReadLine();
    long[][] dp = new long[s.Length+1][];
    for(long i = 0; i < s.Length+1; i++)
    {
      dp[i] = new long[4];
    }
    
    dp[0][0] = 1;
    
    for(int i = 1; i < s.Length+1; i++)
    {
      if(s[i-1] != '?') dp[i][0] = dp[i-1][0];
      else dp[i][0] = dp[i-1][0] * 3;
      dp[i][0] %= mod;
      
      if(s[i-1] == 'A' || s[i-1] == '?') dp[i][1] += dp[i-1][0];
      if(s[i-1] != '?') dp[i][1] += dp[i-1][1];
      else dp[i][1] += dp[i-1][1] * 3;
      dp[i][1] %= mod;

      if(s[i-1] == 'B' || s[i-1] == '?') dp[i][2] += dp[i-1][1];
      if(s[i-1] != '?') dp[i][2] += dp[i-1][2];
      else dp[i][2] += dp[i-1][2] * 3;
      dp[i][2] %= mod;

      if(s[i-1] == 'C' || s[i-1] == '?') dp[i][3] += dp[i-1][2];
      if(s[i-1] != '?') dp[i][3] += dp[i-1][3];
      else dp[i][3] += dp[i-1][3] * 3;
      dp[i][3] %= mod;
    }
		Console.WriteLine(dp[s.Length][3]);//WriteLineをWriteとすると、改行なしで出力。
	}
}

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

using namespace std;

int main(void)
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double hRad = 2.0 * M_PI * (H / 12.0 + (M / 60.0 / 12.0));
    double mRad = 2.0 * M_PI * M / 60.0;

    printf("%.10lf", sqrt(A*A + B*B - 2 * A * B * cos(hRad - mRad)));
    cout << endl;
    return 0;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

int main()
{
    int N;
    cin >> N;
    cout << (N - 2) * 180 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
//C++14 (GCC 5.4.1)
int main() {
    int N,Y;
    cin >>N >>Y;
    //-----------------------------------
    int Ans=0;
    Y/=1000;
    //10,5,1Nコで
    int s=Y%5;
    N-=s;
    Y-=s;
    int Y_a,Y_b,N_a;
    for(int i=0;i<=N;i++){
        Y_a=Y-10*i;
        N_a=N-i;
        for(int j=0;j<=N_a;j++){
            Y_b=Y_a-5*j;
            if(Y_b==N_a-j){
                cout << i <<" " << j <<" "<< Y_b+s <<endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" <<endl;
}

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

#define FASTIO1 ios_base::sync_with_stdio(false)
#define FASTIO2 cin.tie(NULL),cout.tie(NULL)
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll power(ll x,ll y,ll p);
const ll inf=999999999;
const ll mod=1e9+7;
bool tc=false;

void solve()
{
	ll a,b,c,d; cin>>a>>b>>c>>d;
	cout<<max(a*c,max(a*d,max(b*c,b*d)));
}

int main() 
{
    FASTIO1;
    FASTIO2;
    clock_t start=clock();
    ll t=1; 
    if(tc) cin>>t;
    while(t--)
        solve();
    cerr<<fixed<<setprecision(6);
    cerr<<(double)(clock()-start)/CLOCKS_PER_SEC<<endl;
    return 0;
}

ll power(ll x,ll y,ll p)  
{  
    ll res=1; x=x%p;
    if(x==0) return 0;
    while(y>0)  
    {
        if(y&1) res=(res*x)%p;
        y=y>>1; x=(x*x)%p;  
    }
    return res;  
}  


Measured memory_bytes: 3792
a,b,c = map(int, input().split())
l = list(map(int, input().split()))
cost = [0] * (a+1)
for i in range(a):
  if i in l:
    cost[i] = 1

sum1 = sum(cost[0:c:])
sum2 = sum(cost[c::])
print(min(sum1,sum2))

Measured memory_bytes: 3064
package main

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

func main() {
	a := readi() // 1
	b := readi() // 0
	_ = readi() // -1
	k := readi()
	if a > k {
		fmt.Println(k)
	} else if a + b >= k {
		fmt.Println(a)
	} else {
		fmt.Println(a - (k-(a+b)))
	}
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}


Measured memory_bytes: 1856
#include<iostream>
using namespace std ;
int main(){
    int n,i,x;
    cin>>n;
    for (i=1;i<=n;i++){
        x=i;
        if(x%3==0){
            cout<<" "<<i;
        }else{
            while(x>0){
                if(x%10 == 3){
                    cout <<" "<< i;
                    break;
                }
                x/=10;
            }
        }
    }
    cout<<endl;
    return 0;
}
        





Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int a[5]={0};
  int b[5]={0};
    int f,i,sum;
  for(i=0;i<5;i++){
  cin>>a[i];
    b[i]=(a[i]-1)%10;
  }
  sort(a,a+5);
  sort(b,b+5);
  for(i=0;i<5;i++){
  sum=sum+(a[i]-1)/10*10;
  }
  sum=sum+40+b[0]+1;
  cout<<sum<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
 
main()
{
int a,b;
   while(1){
    scanf("%d %d",&a,&b);
    if((a|b)==0)break;
    if(b<a)std::swap(a,b);
    printf("%d %d\n",a,b);
    }
}


Measured memory_bytes: 3228
#include "bits/stdc++.h"
using namespace std;
#define shandom_ruffle random_shuffle
#define pb push_back
#define nl puts("")
using ll = long long;
using pii = pair<ll,ll>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vlll = vector<vll>;
using mpll = map<ll,ll>;
using stch = stack<char>;
using stvll = stack<vll>;
const ll nax = 1000*1007;
const ll mno = 1007;
const ll mod = 1e9 + 7;
const ll mxN = 1e5;
const ll rc = 64;
const ll MOD = 998244353; 
int main() {
  string n; 
  cin >> n;
  if(n[0] == '7' || n[1] == '7' || n[2] == '7') puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
prev = N
sum = 0
for a in A:
    sum += B[a-1]
    if prev+1 == a-1:
        sum += C[prev]
    prev = a-1
print(sum) 

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int main(){
	int N;
	scanf("%d",&N);
	char s[maxn],t[maxn];
	scanf(" %s%s",s,t);
	for(int i = 0;i < N;i++){
		printf("%c%c",s[i],t[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

void dfs(int vp, int current, vector<vector<int> > &edges, vector<int> &visit)
{

    if(visit[current] != -1){
        return;
    }
    visit[current] = vp;
    for(int i = 0; i < edges[current].size(); i++){
        dfs(vp, edges[current][i], edges, visit);
    }
}

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

    vector<vector<int> > edges(n, vector<int>());
    for(int i = 0; i < m; i++){
        int x,y,z;
        cin >>x >>y >>z;
        edges[x-1].push_back(y-1);
        edges[y-1].push_back(x-1);
    }

    vector<int> visit(n, -1);


    for(int i = 0; i < n; i++){
        dfs(i, i, edges, visit);
    }

    set<int> ans;
    for(int i = 0; i < n; i++){
        ans.insert(visit[i]);
    }
    printf("%d\n", ans.size());
}

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

using namespace std;

int N, K;
vector<int> g[2010];

void dfs(int cur, int par, vector<int>& d) {
	for (int nex : g[cur]) {
		if (nex == par) continue;
		d[nex] = d[cur] + 1;
		dfs(nex, cur, d);
	}
}

int solve_even(int center) {
	vector<int> d(N, N);
	d[center] = 0;
	dfs(center, -1, d);
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += (d[i] > K / 2);
	}
	return res;
}

int solve_odd(int center1, int center2) {
	vector<int> d1(N, 0), d2(N, 0);
	dfs(center1, center2, d1);
	dfs(center2, center1, d2);
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += (d1[i] > K / 2);
		res += (d2[i] > K / 2);
	}
	return res;	
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int ans = N;
	if (K % 2 == 0) {
		for (int i = 0; i < N; i++) {
			ans = min(ans, solve_even(i));
		}		
	} else {
		for (int i = 0; i < N; i++) {
			for (int j : g[i]) {
				ans = min(ans, solve_odd(i, j));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>

#define p pair<long long,int>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<p > que;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        que.push(p(a, 1));
    }
    for (int i = 0; i < m; i++) {
        int b, c;
        cin >> b >> c;
        que.push(p(c, b));
    }

    long long ret = 0;
    while (n > 0) {
        p x = que.top();
        que.pop();
        ret += x.first * min(x.second, n);
        n -= min(x.second, n);;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 6520
#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> A(N);
  vector<i64> cnt(100001);
  i64 sm = 0;
  for (auto& x : A) {
    cin >> x;
    cnt[x]++;
    sm += x;
  }

  int Q;
  cin >> Q;
  REP(i, Q) {
    i64 b, c;
    cin >> b >> c;
    sm += (c - b) * cnt[b];
    cout << sm << '\n';
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
}


Measured memory_bytes: 4764
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL r, D, x;
	in >> r >> D >> x;

	rep(i, 10)
	{
		x = r * x - D;
		out << x << std::endl;
	}
}


Measured memory_bytes: 764
n,*t=map(int,open(0).read().split())
s=i=j=0
for t,x,y in zip(t[::3],t[1::3],t[2::3]):
  d=abs(y-i)+abs(x-j)
  if t-s<d or d%2!=(t-s)%2:
    print('No')
    exit()
  s,i,j=t,y,x
print('Yes')

Measured memory_bytes: 98604
S = input()
N = len(S)
MOD = 998244353

dp = [[0]*(N+1) for i in range(N+1)] #dp[r][b]
if S[0] == '0':
    dp[0][1] = 1
elif S[0] == '1':
    dp[1][0] = 1
    dp[0][1] = 1
else:
    dp[1][0] = 1

for k in range(1,N):
    c = int(S[k])
    for r in range(k+1):
        b = k-r
        if c == 1:
            dp[r][b+1] += dp[r][b]
            dp[r][b+1] %= MOD
            dp[r+1][b] += dp[r][b]
            dp[r+1][b] %= MOD
        elif c == 0:
            dp[r][b+1] += dp[r][b]
            dp[r][b+1] %= MOD
            if r > 0:
                dp[r-1][b+2] += dp[r][b]
                dp[r-1][b+2] %= MOD
        else:
            if b > 0:
                dp[r+2][b-1] += dp[r][b]
                dp[r+2][b-1] %= MOD
            dp[r+1][b] += dp[r][b]
            dp[r+1][b] %= MOD

M = N+5
fac = [1,1] + [0]*M
finv = [1,1] + [0]*M
inv = [0,1] + [0]*M
for i in range(2,M+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 0
for k in range(N+1):
    ans += ncr(N,k) * dp[k][N-k]

print(ans % MOD)

Measured memory_bytes: 75612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
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;}



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

int n,r;
cin >> n >> r;
if(n >= 10) cout << r << endl;
else cout << r + 100*(10-n) << endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	string s, prev, curr;
	cin >> s;
	int ans = 0;
	for (char c : s) {
		curr += c;
		if (curr != prev) {
			++ans;
			prev = curr;
			curr = "";
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

map<int,int> mp;
int n,seq[200050];

bool chk(int mid)
{
	mp.clear();
	for(int i = 2;i <= n; ++ i)
		if(seq[i] <= seq[i - 1])
		{
			while(!mp.empty())
			{
				if((mp.rbegin() -> first) > seq[i]) mp.erase(mp.rbegin() -> first);
				else break;
			}
			int ps = seq[i];
			while(ps && mp[ps] + 1 == mid) mp.erase(ps), ps --;
			if(!ps) return false;
			mp[ps] ++;
		}
	return true;
}

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n; ++ i) scanf("%d",&seq[i]);
	int flg = 0;
	for(int i = 2;i <= n; ++ i)
		if(seq[i] <= seq[i - 1])
		{
			flg = 1;break;
		}
	if(!flg)
	{
		printf("1\n");
		return 0;
	}
	int l = 2,r = n,ans;
	while(l <= r)
	{
		int mid = (l + r) >> 1;
		if(chk(mid)) r = mid - 1,ans = mid;
		else l = mid + 1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_B&lang=jp
 
 ??????????????????????????? II
 N ?????????????????????????????????????????????????????????????????????ai ?????§??????E ??????, ????????????K ?????????????????????????????¨?????£?????????, ?????????????¨????L ?????\??? R ?????\?????????????????¨?????£???????????????????????????????????????????????????????????????????????§????????????? ?????????, ????????????????????????????????\??????????????¨????????????
 
 Constraints
 1 ??? K ??? N ??? 40
 1 ??? ai ??? 1016
 1 ??? L ??? R ??? 1016
 ??\?????????????????´??°??§???????????????
 
 Output
 ?????????????????°??? 1 ???????????????????????????
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,K,L,R; cin >> N >> K >> L >> R;
    vector<ll> a(N);
    for(int i = 0; i < N;i++) cin >> a[i];
    
    
    /*
     bit?????¨???????????§N/2?????¨????????´????????¨???????????????
     ??????????????????N - N/2??????????????? L - X <= (Y) <= R - X?????¨???????????????
     O(N^20) + O(N^20*logM)
     */
    vector<vector<ll>> half_Sum(N/2 + 1);
    ll n1 = N/2;
    for(int i = 0; i < (1<<n1);i++){
        ll Sum = 0;
        ll cnt = 0;
        for(int j = 0; j < n1;j++){
            if((i >> j)&1){
                cnt++;
                Sum += a[j];
            }
        }
        half_Sum[cnt].emplace_back(Sum);
    }
    for(int i = 0; i < n1;i++) sort(half_Sum[i].begin(),half_Sum[i].end());
    ll ans = 0;
    ll n2 = N - n1;
    for(int i = 0; i < (1<<n2);i++){
        ll Sum = 0;
        ll cnt = 0;
        for(int j = 0; j < n2;j++){
            if((i>>j)&1){
                cnt++;
                Sum += a[n1 + j];
            }
        }
        
        if(!(K - cnt >= 0)|| n1 + cnt < K)continue;
        
        ll it1 = upper_bound(half_Sum[K - cnt].begin(), half_Sum[K-cnt].end(), R-Sum) - half_Sum[K-cnt].begin();
        ll it2 = lower_bound(half_Sum[K-cnt].begin(), half_Sum[K-cnt].end(), L-Sum) - half_Sum [K-cnt].begin();
        
        if(it1 - it2 <= 0) continue;
        ans += it1 - it2;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	ll n,p; cin >> n >> p;

	if(n == 1){
		cout << p << endl;
		return 0;
	}

	ll ans = 1;
	for (int i = 2;i < p;i++){
		ll a = 1;
		for (int j = 0;j < n;j++){
			a *= i;
			if(a > p){
				cout << ans << endl;
				return 0;
			}
		}
		if(p%a == 0) ans = i;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

void printArray(vector<int> v){
    rep(i, v.size()){
        if(i) cout << " ";
        cout<< v[i];
    }
    cout << endl;
}

void print2dArray(vector<vector<int> > vv){
    rep(i, vv.size()){
        rep(j, vv[i].size()){
            if(j) cout << " ";
            cout << vv[i][j];
        }
        cout << endl;
    }
}

//--global--//


/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll a, b;
    cin >> a >> b;
    
    cout << lcm(a, b) << endl;
    
    return 0;
}


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

#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;

using vecint = vector<int>;
using ll = int64_t;

int main() {
  while(1){
    int n,m;
    cin>>n>>m;
    if (!n) break;
    vecint h(n),w(m),s(n+1),t(m+1);
    REP(i,n) cin>>h[i];
    REP(i,m) cin>>w[i];
    partial_sum(ALL(h),begin(s)+1);
    partial_sum(ALL(w),begin(t)+1);
    vecint y,x;
    REP(i,n+1)REP(j,i) y.push_back(s[i]-s[j]);
    REP(i,m+1)REP(j,i) x.push_back(t[i]-t[j]);
    sort(ALL(x));
    ll count = 0;
    for (int d:y) {
      auto p = equal_range(ALL(x),d);
      count += distance(p.first, p.second);
    }
    cout << count << endl;
  }
  return 0;
}

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

int main() {
  
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  
  sort(a.begin(), a.end());
  
  cout << a[2]*10 + a[0]+a[1] << endl;
    
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char inp[200];
int main()
{
	int len;
	bool pdc=false,pdf=false;
	scanf("%s",inp);
	len=strlen(inp);
	for(int i=0;i<len;i++)
	{
		if(inp[i]=='C')
		{
			pdc=true;
			for(int j=i+1;j<len;j++)
			{
				if(inp[j]=='F')
				{
					pdf=true;
					break;
				}
			}
			break;
		}
	}
	if(pdc&&pdf) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let n: usize = s.trim().parse().unwrap();
	let mut v: Vec<u32> = Vec::new();
	for i in 0..n {
		let mut s = String::new();
		std::io::stdin().read_line(&mut s).unwrap();
		let a: u32 = s.trim().parse().unwrap();
		v.push(a);
	}
	v.sort();
	let mut p = 0;
	let mut c = 1;
	let mut pc = v.len();
	for i in 0..v.len() {
		if v[i] != p {
			p = v[i];
			c = 1;
		} else if v[i] == p {
			c += 1;
		}
		if c % 2 == 0 {
			pc -= 2;
		}
	}
	println!("{}", pc);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    double w,h,x,y;
    ll ans;
    cin >> w >> h >> x >> y;
    if(w/2==x && h/2==y) ans=1;
    else ans=0;
    printf("%.10f %d\n",w*h/2,ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

int a[MAXN];

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

    int N;
    cin >> N;
    rep(i,1,N) {
        cin >> a[i];
    }
    ll num = 0;

    for(int i = N;i >= 2;i --) {
        if (a[i] < a[i-1]) {
            a[i-1] --;
            if (a[i] < a[i-1]) {
                num += 2;
            }
        }
    }
    if (num >= 2) cout << "No" << endl;
    else          cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
#define MAX 1000
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int count = 0;
    rep(i, n){
        if(h[i] >= k) ++count;
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 640