akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  vl a(3);
  rep(i, 3) cin >> a[i];
  sort(all(a));
  cout << (a[0] % 2 && a[1] % 2 && a[2] % 2 ? a[0] * a[1] : 0) << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long

typedef pair<int,int> P;

int main(){
    int n; cin>>n;
    vector<P> claim[15];
    rep(i,n){
        int a; cin>>a;
        rep(j,a){
            int x, y; cin>>x>>y;
            x--;
            claim[i].push_back(make_pair(x, y));
        } 
    }

    int all = 1<<n;
    int ans = 0;
    rep(i, all){
        int x = i;
        vector<bool> honest;
        int count = 0;
        while(honest.size() < n){
            if (x % 2 == 1){
                honest.push_back(true);
                count ++;
            }
            else{
                honest.push_back(false);
            }
            x = x / 2;
        }

        bool isOK = true;
        rep(k, n){
            if(!honest[k]) continue;
            for(P& c : claim[k]){
                if(c.second == 0){
                    if(honest[c.first] == true){
                        isOK = false;
                        break;
                    }
                }
                else{
                    if(honest[c.first] == false){
                        isOK = false;
                        break;
                    }
                }
            }
            if(!isOK) break;
        }

        if(isOK){
            ans = max(ans, count);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
  ll x,y;
  cin>>x>>y;
  if(y<x*2||y>x*4||y&1)
    No
    else
    {
       Yes
    }  
}
return 0;
}

Measured memory_bytes: 3636
def bellman_ford():
    edges = []
    inf = 1

    n, m, s = map(int, input().split())

    for i in range(m):
        src, tgt, cost = map(int, input().split())
        edges.append({'source': src, 'target': tgt, 'cost': cost})
        if cost > 0:
            inf += cost

    graph = [{'cost': inf, 'source': -1} for i in range(n)]
    graph[s]['cost'] = 0

    for i in range(n - 1):
        for edge in edges:
            src = edge['source']
            tgt = edge['target']
            if graph[src]['cost'] == inf:
                continue
            if graph[tgt]['cost'] > graph[src]['cost'] + edge['cost']:
                graph[tgt]['cost'] = graph[src]['cost'] + edge['cost']
                graph[tgt]['source'] = src

    for edge in edges:
        src = edge['source']
        tgt = edge['target']
        if graph[src]['cost'] == inf:
            continue
        if graph[tgt]['cost'] > graph[src]['cost'] + edge['cost']:
            print('NEGATIVE CYCLE')
            return

    for vertex in graph:
        print(vertex['cost']) if vertex['cost'] < inf else print('INF')


bellman_ford()



Measured memory_bytes: 6572
#include <iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#define endl '\n'
#define Bedoazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

const long long mod = 1e9 + 7, N = 1e6 + 5;
long long fact[N], inv[N];

long long ncr(long long n, long long r) {

	return ((fact[n] * inv[n - r]) % mod * inv[r]) % mod;

}


int fastpower(int base, int power) {

	if (power == 0)
		return 1;

	long long halfpower = fastpower(base, power / 2) % mod;

	long long ret = (halfpower * halfpower) % mod;

	if (power % 2) {

		ret = (ret * base) % mod;
	}
	return ret;


}



void pre() {

	fact[0] = 1;

	inv[0] = 1;

	for (long long i = 1; i < N; i++) {

		fact[i] = ((i)*fact[i - 1]) % mod;

		inv[i] = fastpower(fact[i], mod - 2) % mod;

	}

}


int main() {

	Bedoazim

		pre();

	long long n, k, max, min, ans = 0;
		
	vector<long long>v;

	cin >> n >> k;


	for (int i = 0; i < n; i++) {
		long long j;
		
		cin >> j;
	
		v.push_back(j);
	
	}

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

	for (int i = 0; i < n; i++) {

		if (i < k - 1)
			max = 0;

		else
			max = ncr(i, k - 1);


		if (n - i - 1 < k - 1)
			min = 0;

		else
			min = ncr(n - i - 1, k - 1);



		ans += ((v[i] % mod) * ((max - min) % mod) % mod);

		ans %= mod;

	}

	cout << ans << endl;

}

Measured memory_bytes: 17016
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  ll x;cin >> x;
  ll ans=0;
  ans+=(x/500)*1000;
  x-=(x/500)*500;
  ans+=(x/5)*5;
  cout << ans << endl;
}

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

using namespace std;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
const int dy[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
inline bool between(int a, int b, int c){
	return a <= b && b < c;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<string> field(n);
	for(int i = 0; i < n; ++i){ cin >> field[i]; }
	for(int j = 0; j < m; ++j){
		if(field[0][j] == '-'){ field[0][j] = '*'; }
	}
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			int s = 0;
			if(field[i][j] == 'o'){
				s = 4;
			}else if(field[i][j] == 'x'){
				s = 1;
			}else{
				continue;
			}
			for(int d = 0; d < 8; d += s){
				const int y = i + dy[d], x = j + dx[d];
				if(between(0, y, n) && between(0, x, m) && field[y][x] == '-'){
					field[y][x] = '*';
				}
			}
		}
	}
	int answer = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			if(field[i][j] == '-'){ ++answer; }
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<pair<long long, int> >v, v2;
    vector<long long>mx(n + 3, -1);
    for(int i = 0; i < n; i++){
        long long x;
        int t;
        cin >> t >> x;
        v.push_back(make_pair(x, t));
        mx[t] = max(mx[t], x);
    }
    for(int i = 1; i <= n; i++){
        if(mx[i] != -1){
            v2.push_back(make_pair(mx[i], i));
        }
    }
    sort(v.rbegin(), v.rend());
    sort(v2.rbegin(), v2.rend());
    int p = v2.size();
    vector<long long>sum(p), idx(p), sum2(n);
    sum2[0] = v[0].first;
    for(int i = 1; i < n; i++){
        sum2[i] = sum2[i - 1] + v[i].first;
    }
    sum[0] = v2[0].first;
    idx[0] = lower_bound(v.begin(), v.end(), v2[0], greater<pair<long long, int> >()) - v.begin();
    for(int i = 1; i < p; i++){
        sum[i] = sum[i - 1] + v2[i].first;
        idx[i] = lower_bound(v.begin(), v.end(), v2[i], greater<pair<long long, int> >()) - v.begin();
    }
    long long ans = 0;
    for(int i = 0; i < min(k, p); i++){
        long long cur = sum[i];
        int lo = 0, hi = n - 1;
        while(hi - lo >= 2){
            int mid = (hi + lo)/2;
            int p = upper_bound(idx.begin(), idx.end(), mid) - idx.begin();
            p = min(p, i + 1);
            if(mid + 1 - p >= k - i - 1){
                hi = mid;
            }
            else{
                lo = mid;
            }
        }
        for(int mid = lo; mid <= hi; mid++){
            int p = upper_bound(idx.begin(), idx.end(), mid) - idx.begin();
            p = min(p, i + 1);
            if(mid + 1 - p >= k - i - 1){
                cur = cur - sum[p - 1] + sum2[mid] + 1LL * (i + 1) * (i + 1);
                break;
            }
        }
        ans = max(ans, cur);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 9424
// 2016-12-03
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int m, min, max, n;
	int p[200];
	while (cin >> m >> min >> max, m) {
		for (int i = 0; i < m; i++) {
			cin >> p[i];
		}
		n = min - 1;
		for (int i = min; i < max; i++) {
			if (p[i] - p[i + 1] >= p[n] - p[n + 1]) {
				n = i;
			}
		}
		cout << n + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let c = s.trim();
    fn is_vowel(c: &str) -> &str {
        if {c == "a"} | {c == "e"} | {c == "u"} | {c == "i"} | {c == "o"} {"vowel"}
        else {"consonant"}
    }
    println!("{}", is_vowel(c));
}



Measured memory_bytes: 4352
import Numeric

main :: IO ()
main = do
  input <- getLine
  let [a, b] = map read $ words input :: [Int]
  let [a', b'] = map read $ words input :: [Double]
  putStrLn $ unwords $ (map show [a `div` b, a `mod` b]) ++ ([showFFloat Nothing (a' / b') ""])

Measured memory_bytes: 4080
#include <cstdio>
int sum[20000],tmp[20000];
void inv(int n,int r,int *tar) {
	int m=1;
	for(int i=0;i<2*r;i++) {
		tar[i]=m/n;
		m=(m%n)*10;
	}
}
void add(int r) {
	int carry=0;
	for(int i=2*r-1;i>=0;i--) {
		sum[i]+=tmp[i]+carry;
		carry=sum[i]/10;
		sum[i]%=10;
	}
}
int main() {
	int n,k,m,r;
	while(scanf("%d %d %d %d",&n,&k,&m,&r),n) {
		inv(n,r,sum);
		if(m==1) {
			for(int i=1;i<n;i++) {
				inv(n*i,r,tmp);
				add(r);
			}
		}
		putchar(sum[0]+'0');
		putchar('.');
		for(int i=1;i<=r;i++) putchar(sum[i]+'0');
		putchar('\n');
	}
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 1005;

int main() {

	FAST;

	string s;
	cin >> s;
	deque <char> dq(s.begin(), s.end());
	bool remained = true;
	int q;
	cin >> q;
	while (q -- ) {
		int t;
		cin >> t;
		if (t == 1) remained = !remained;
		else {
			int f;
			char c;
			cin >> f >> c;
			(remained ^ (f - 1)) ? dq.push_front(c) : dq.push_back(c);
		}
	}
	while (!dq.empty()) {
		cout << ((remained) ? dq.front() : dq.back());
		(remained) ? dq.pop_front() : dq.pop_back();
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

typedef long long int ll;
#define MAX_N 100000
#define MAX_M 100000

int N, M;
int P[MAX_M];
ll Y[MAX_M];

int main() {
  std::cin >> N >> M;
  for(int i = 0; i < M; ++i) {
    std::cin >> P[i] >> Y[i];
  }

  std::vector<int> py[N+1];
  for(int i = 0; i < M; ++i) {
    py[P[i]].emplace_back(Y[i]);
  }

  for(auto &v : py) {
    std::sort(v.begin(), v.end());
  }

  for(int i = 0; i < M; ++i) {
    int order = std::lower_bound(py[P[i]].begin(), py[P[i]].end(), Y[i]) - py[P[i]].begin() + 1;
    std::printf("%06d%06d\n", P[i], order);
  }

  return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define test int t;cin>>t;while(t--)
void fastcode()
{
    /*
    cout<<fixed<<setprecision(2);
    π = 3.141592653;
    itoa to convert any system itoa(n,bin,2)
    */
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    /*freopen(" ","r",stdin);
    freopen(" ","w",stdout);*/
    fastcode();
    double n;
    cin>>n;
    cout<<ceil(n/1000)*1000-n;
    return 0;
}


Measured memory_bytes: 3744
#include<stdio.h>
int main(){
int a[4];
for(int n=0;n<4;n++){
 scanf("%1d",&a[n]);
}
//a[0]-a[1]
int m=7-a[0]+a[1];
if(a[2]+a[3]==m){
 printf("%d-%d+%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(a[2]-a[3]==m){
 printf("%d-%d+%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]-a[3]==m){
 printf("%d-%d-%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]+a[3]==m){
 printf("%d-%d-%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}

//a[0]+a[1]
m=7-a[0]-a[1];
if(a[2]+a[3]==m){
 printf("%d+%d+%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(a[2]-a[3]==m){
 printf("%d+%d+%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]-a[3]==m){
 printf("%d+%d-%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]+a[3]==m){
 printf("%d+%d-%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}

//-a[0]+a[1]
m=7+a[0]-a[1];
if(a[2]+a[3]==m){
 printf("-%d+%d+%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(a[2]-a[3]==m){
 printf("-%d+%d+%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]-a[3]==m){
 printf("-%d+%d-%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]+a[3]==m){
 printf("-%d+%d-%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}

//-a[0]-a[1]
m=7+a[0]+a[1];
if(a[2]+a[3]==m){
 printf("-%d-%d+%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(a[2]-a[3]==m){
 printf("-%d-%d+%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]-a[3]==m){
 printf("-%d-%d-%d-%d=7",a[0],a[1],a[2],a[3]);
 return 0;}
if(-a[2]+a[3]==m){
 printf("-%d-%d-%d+%d=7",a[0],a[1],a[2],a[3]);
 return 0;}

}

Measured memory_bytes: 128
S = input()
flag = True
for i in range(len(S)):
    if (i+1) % 2 == 1:
        if not(S[i] in ('RUD')):
            #print(S[i]+":"+"not RUD!!")
            flag = False
            break
    else:
        if not(S[i] in ('LUD')):
            #print(S[i]+":"+"not LUD!!")
            flag = False
            break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n, w;
  ll dp[MAX_N][2];
  int weight, value;
  int now = 0, prev;
  cin >> n >> w;

  for (int i = 0; i <= w; i++){
    dp[i][now] = 0;
  }

  for (int i = 0; i < n; i++){
    cin >> weight >> value;
    prev = now;
    now = 1 - now;
    for (int j = 0; j <= w; j++){
      dp[j][now] = dp[j][prev];
    }
    for (int j = 0; j <= w; j++){
      if (j - weight >= 0){
        dp[j][now] = max(dp[j][now], dp[j - weight][prev] + value);
        // printf("dp[%d][%d] = %lld\n", j, now, dp[j][now]);
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i <= w; i++){
    ans = max(ans, dp[i][now]);
  }

  cout << ans << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1792
// In the name of God

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

int a[maxn],b[maxn],dp[maxn],sm[maxn],tot;
map<int,vector<pii> >mp;
vector<int>v;
set<pii>s;

void add(int id,int num){
    tot=(tot+num)%mod;
    while(id<maxn){
	sm[id]=(sm[id]+num)%mod;
	id+=(id & -id);
    }
}
int ask(int id){
    int ans=0;
    while(id>0){
	ans=(ans+sm[id])%mod;
	id-=(id & -id);
    }
    return ans;
}

int main(){
    int n,m;cin>>n>>m;
    for(int i=0;i<n;i++)
	cin>>a[i];
    for(int i=0;i<m;i++)
	cin>>b[i];
    for(int i=0;i<n;i++){
	if(a[i]<b[0] || b[m-1]<a[i])continue;
	int id=upper_bound(b,b+m,a[i])-b;
	int A=a[i]-b[id-1],B=b[id]-a[i];
	if(s.count({A,B})) continue;
	s.insert({A,B});
	mp[A].PB({B,i});
	v.PB(B);
    }
    mp[-1].PB({-1,n});
    v.PB(-1);
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    tot=1;
    for(auto it=mp.rbegin();it!=mp.rend();it++){
	vector<pii>&vec=it->S;
	for(pii p:vec){
	    p.F=lower_bound(v.begin(),v.end(),p.F)-v.begin()+1;
	    dp[p.S]=(tot-ask(p.F))%mod;
	}
	for(pii p:vec){
	    p.F=lower_bound(v.begin(),v.end(),p.F)-v.begin()+1;
	    add(p.F,dp[p.S]);
	}
    }
    if(dp[n]<0) dp[n]+=mod;
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    vi v(n),c(n);
    cin>v>c;
    int ans=0;
    REP(i,n){
        if(v[i]>c[i])ans+=v[i]-c[i];
    }
    cout<ans<endl;
    return 0;
}


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

int main(void)
{
    int N;
    cin >> N;
    vector<int> a(N);
    map<int, int> counts;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        
    }

    for(int i = 0; i < N; i++){
        counts[a[i]]++;
    }

    vector<int> keys;
    for (auto it = counts.begin(); it != counts.end(); it++)
    {
        keys.push_back(it -> first);
    }

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

    int entries = keys.size();
    

    if(entries == 1){
        if(keys[0] == 0){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else if(entries == 2){
        if(keys[0] == 0){
            if(counts[keys[0]] * 3 == N){
                cout << "Yes" <<endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    } else if(entries == 3){
        if(counts[keys[0]] == counts[keys[1]] && counts[keys[1]]== counts[keys[2]]){
            if((keys[0] ^ keys[1]) == keys[2]){
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 7640
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
	int N,D,ten=1;
	scanf("%d %d",&D, &N);

	for(int i=0; i<D; i++){
		ten *= 100;
	}
	if(N == 100){
		N = 101;
	}
	printf("%d",ten * N);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int H = sc.nextInt();
            int N = sc.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
            }

            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += A[i];
            }

            System.out.println(sum >= H ? "Yes" : "No");
        }
    }
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin >> n;
  
  vector<ll> x(n);
  REP(i, n)
    cin >> x[i];
  
  vector<ll> c = x;
  sort(c.begin(), c.end());
  pll medi = make_pair(c[n/2-1], c[n/2]);
  
  REP(i, n){
    if(x[i] <= medi.FI)
      cout << medi.SE << endl;
    else
      cout << medi.FI << endl;
  }
  
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a&&c<=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	ll a=1,b=1;
	rep(i,0,n){
		ll p,q;
		scanf("%lld%lld",&p,&q);
		ll d=max((a-1+p)/p,(b-1+q)/q);
		a=p*d;
		b=q*d;
	}
	printf("%lld\n",a+b);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, M; cin >> N >> M;
	map<int, bool> red_mp;
	map<int, int> cnt_mp;
	red_mp[0] = true;
	REP(i, N) {
		cnt_mp[i] = 1;
	}
	REP(i, M) {
		int x, y; cin >> x >> y;
		--x; --y;
		if (red_mp[x]) {
			red_mp[y] = true;
			if (cnt_mp[x] == 1) {
				red_mp[x] = false;
			}
		}
		--cnt_mp[x];
		++cnt_mp[y];
	}
	int res = 0;
	REP(i, N) {
		if (red_mp[i]) ++res;
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

int N,Q;
map<int,int>M;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>Q;
	FOR(i,1,N){
		int x;cin>>x;
		M[x]++;
	}
	FOR(i,1,Q){
		int b,c;cin>>b>>c;
		M[c]+=b;
	}
	ll ans=0;
	for(auto it=M.rbegin();N>0&&it!=M.rend();it++){
		if(it->snd<=N){
			ans+=(ll)it->fst*it->snd;
			N-=it->snd;
		}
		else{
			ans+=(ll)it->fst*N;
			N=0;
		}
	}
	cout<<ans<<"\n";
}
/*
1 3
#.#


2 3
#.#
..#

3 3
##.
#.#
..#

3
2 5
6 1
3 7
Ans:6

4
3 7
2 9
8 16
10 8
Ans:9
*/


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;
ll are=1000000007;

int main() {
    int n,ans=0;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n) cin >> a.at(i+1);
    for (int i=2;i<n;i++){
        if (i==a.at(i)){
            if (i-1==a.at(i-1)) swap(a.at(i),a.at(i-1));
            else swap(a.at(i),a.at(i+1));
            ans++;
        }
    }
    if (a.at(1)==1) ans++;
    if (a.at(n)==n && n>=3) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll x;
    cin >> x;
    ll a = 100, c = 0;
    while(a < x){
        ll ans = (1*a)/100;
        a += ans;
        ++c;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=3010;
int a[N],win[N];
namespace T{
	const int E=N<<1;
	int to[E],bro[E],head[N],e=0;
	inline void init(){
		memset(head,-1,sizeof(head));
	}
	inline void ae(int u,int v){
		to[e]=v,bro[e]=head[u],head[u]=e++;
	}
	inline void add(int u,int v){
		ae(u,v),ae(v,u);
	}
	int deg[N],que[N],qh=0,qt=0;
	inline void bfs(int n){
		memset(deg,0,sizeof(deg));
		for(int x=1;x<=n;x++){
			for(int i=head[x];~i;i=bro[i]){
				deg[x]+=a[to[i]]<a[x];
			}
			if(deg[x]==0){
				win[x]=-1,que[qt++]=x;
			}
		}
		while(qh<qt){
			int x=que[qh++];
			for(int i=head[x],v;~i;i=bro[i]){
				if(win[v=to[i]]==0){
					if(win[x]==1){
						if(a[x]<a[v]){
							deg[v]--;
						}
						if(deg[v]==0){
							win[v]=-1,que[qt++]=v;
						}
					}else if(a[x]<a[v]){
						win[v]=1,que[qt++]=v;
					}
				}
			}
		}
	}
}
int main(){
	int n=ni;
	for(int i=1;i<=n;i++){
		a[i]=ni;
	}
	T::init();
	for(int i=1;i<n;T::add(ni,ni),i++);
	memset(win,0,sizeof(win));
	T::bfs(n);
	for(int i=1;i<=n;i++){
		assert(win[i]);
		if(win[i]==1){
			printf("%d ",i);
		}
	}
	putchar('\n');
	return 0;
}

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

int main() {
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
        cout<<s<<endl;
    else
    {
        s.erase(s.begin()+k,s.end());
        cout<<s<<"..."<<endl;
    }

    return 0;
}


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

int N;
int a[110];

int main(){
    cin>>N;

    for (int i = 0; i < N; i++)
    {
        cin>>a[i];
    }

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

    int ans = 0;

    for (int i = 0; i < N; i++)
    {
        if(i%2 == 0) ans += a[i];
        else  ans -= a[i];
    }
    
    cout << ans << endl;


    return 0;
}


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

using namespace std;

int main() {

	long n;
	cin >> n;
	string s;
	cin >> s;

	long x = 0;
	long maxx = 0;
	for (long i = 0; i < s.size(); i++) {

		if (s[i] == 'I') { x++; }
		else { x--; }
		maxx = max(maxx, x);
	}

	cout << maxx << endl;
	return 0;
}

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

using namespace std;

const int N = 2e3 + 10;
const int M = 4e5 + 10;

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

PII a[N];
int n;
int b[N];

double f[N][N];

double fun(int x1, int y1, int x2,  int y2)
{
	return sqrt( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
	{
		scanf("%d%d", &a[i].first, &a[i].second);
		b[i] = i;
	}
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= n; j ++)
		{
			f[i][j] = fun(a[i].first, a[i].second, a[j].first, a[j].second);
		}
	double sum = 0;
	int z = 0;
	do
	{
		z ++;
		for (int i = 1; i <= n - 1; i ++)
		{
		//	cout << b[i] << " " << b[i + 1] << endl;
			sum += fun(a[b[i]].first, a[b[i]].second, a[b[i + 1]].first, a[b[i + 1]].second);
		}
	//	cout << sum << endl;
	}while(next_permutation(b + 1, b + n +1));
	printf("%.10lf\n", 1.0 * sum / z);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[10001],b[10001];
long long sum1,sum2;
long long QAQ,qwq;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i],sum1+=a[i];
    for(int i=1;i<=n;i++)cin>>b[i],sum2+=b[i];
    if(sum1>sum2) 
	{
        puts("No");
		return 0;
    }
    QAQ=sum2-sum1;
    for(int i=1;i<=n;i++)
    if(b[i]>a[i])
    qwq+=(b[i]+1-a[i])/2;
    if(qwq>QAQ)puts("No");
    else puts("Yes");
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int w,a,b;
  cin>>w>>a>>b;
  if(a>b) swap(a,b);
  if(b-(w+a)<0) cout<<0;
  else cout<<b-(w+a);
  cout<<'\n';
  return 0;
}


Measured memory_bytes: 256
from itertools import permutations


class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
adj = [[float('inf') for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
    A, B, C = map(int, input().split())
    adj[A][B] = C
    adj[B][A] = C

wf = WarshallFloyd(adj)

ans = float('inf')
tours = list(map(list, permutations(r, R)))
for tour in tours:
    cost = 0
    for i in range(1, len(tour)):
        cost += wf.distance(tour[i - 1], tour[i])
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 66520
/*
AizuOnline A2409
Power
*/
#include <stdio.h>

int M,N;
int a[101],b[101];
int start;
int cnt  ;
void init_test()
{
  M=8;N=4;
  a[1]=3;b[1]=4;  a[2]=1;b[2]=2;
  a[3]=5;b[3]=6;  a[4]=7;b[4]=8;
  start=1;
  cnt=0;
}
void init()
{ int i;
  scanf("%d %d",&M,&N);
  for(i=1;i<=N;i++)
    scanf("%d %d",&(a[i]),&(b[i]));
}
void print()
{ int i;
  printf("M,N=%d %d\n",M,N);
  for(i=1;i<=N;i++)
    printf("%d %d \n",(a[i]),(b[i]));
}
int search()
{
  int i;
  int mx;
  int find;
  mx=0;find=0;
  for(i=1;i<=N;i++)
    if(a[i] <= start)
      {
	//printf("a=%d b=%d mx=%d\n",a[i],b[i],mx); 
      if(mx < b[i])
	{ find=i;
	  mx = b[i];
	}
      }
  if(find==0 ||mx < start)
    return(0);
  start=mx+1;
  cnt++;
  return(mx);
}
main()
{
  int ret;
  init(); //print();

  start=1;
  while(1)
    {
      //printf("start=%d\n",start); 
      ret=search();
      //printf("next=%d\n",ret); 
      if(ret==0 || ret >= M)
	break;
    }
  if(ret==0)
    printf("Impossible\n");
  else
    printf("%d\n",cnt);
return(0);
}

Measured memory_bytes: 596
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,K = LI()
A = LI()

visited = [-1]*N
s = 0
visited[s] = 0
count = 1
while True:
    x = A[s]-1
    if visited[x] < 0:
        visited[x] = count
        s = x
        count += 1
    else:
        break

r = count-visited[x]
y = visited[x]

if K >= y:
    k = (K-y)%r
    s = x
    for i in range(k):
        s = A[s]-1
    print(s+1)
else:
    s = 0
    for i in range(K):
        s = A[s]-1
    print(s+1)

Measured memory_bytes: 91340
//author : raghav_0901

#include <bits/stdc++.h>
using namespace std;

// #define int long long int

void _main();
signed main(void){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    _main();
}

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


void _main(){

    int a,b,c,k;cin>>a>>b>>c>>k;
    int ans = min(a, k);
    k = k - ans;
    k = k - min(b, k);
    ans = ans - k;
    cout<<ans<<endl;
    return;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, m;
    cin >> n >> m;

    if(abs(n - m) >= 2){
        cout << 0 << endl;
    }else{
        ll ans = 1;
        ll tmp = 1;
        for (int i = 1; i <= n; ++i) {
            tmp *= i;
            tmp %= MOD;
        }

        if(n != m){
            ll res = 1;
            for (int i = 1; i <= m; ++i) {
                res *= i;
                res %= MOD;
            }

            ans = res * tmp;
            ans %= MOD;
            cout << ans << endl;
        }else{
            ans = tmp * tmp * 2 % MOD;
            cout << ans << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 256
n , m = map(int , input().split())
A = list(map(int , input().split()))
B_C = []
for i in range(m):
    b , c = map(int , input().split())
    B_C.append([b , c])
A.sort()
B_C.sort(key = lambda x : -x[1])
k = 0
for b , c in B_C:
    for i in range(k ,min( k + b, n)):
        A[i] = max(A[i] , c)
    k += b
print(sum(A))

Measured memory_bytes: 28436
#!/usr/bin/env python3
import sys


def solve(a: int, b: int):
    ans = a
    if b < a and a != 1:
        ans -= 1
    print(ans)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21728
fun main(args: Array<String>) {
    abc058c()
}

fun abc058c() {
    val n = readLine()!!.toInt()
    val sList = (1..n).map { readLine()!!.toList().sorted().toCharArray() }

    val alphaCount = ('a'..'z').map { c -> Pair(c, sList.map { s -> s.count { sc -> sc == c } }.min()) }

    val answer = alphaCount.map { alp -> alp.second?.let { alp.first.toString().repeat(it) } }
        .joinToString(separator = "")

    println(answer)
}


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

int a,b,c;
void solve(){
    cin >> a >> b >> c;
    cout << c  << " " << a << " " << b << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	string s, t;
	cin >> s >> t;

	Int lens = s.size();
	Int lent = t.size();

	vector<vector<Int>> dp(lens + 1, vector<Int>(lent + 1, 0));

	for (Int i = 0; i < lens; i++) {
		for (Int j = 0; j < lent; j++) {
			if (s[i] == t[j])dp[i + 1][j + 1] = dp[i][j] + 1;
			else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
		}
	}

	string ans;

	while (dp[lens][lent]) {
		while (dp[lens][lent] == dp[lens][lent - 1]) {
			lent--;
		}
		while(dp[lens][lent] == dp[lens - 1][lent]) {
			lens--;
		}
		ans += s[lens - 1];
		lens--;
		lent--;
    }

	reverse(ans.begin(), ans.end());
	cout << ans<< "\n";

}

Measured memory_bytes: 70784
class ABC140B:

    def __init__(self):
        self.nNum = int(input())
        self.aList = list(map(int, input().split()))
        self.bList = list(map(int, input().split()))
        self.cList = list(map(int, input().split()))

    def solve(self):
        prev = -2
        point = 0
        for aNum in self.aList:
            aNum -= 1
            point += self.bList[aNum]
            if prev + 1 == aNum:
                point += self.cList[prev]
            prev = aNum

        print(point)


if __name__ == '__main__':
    ABC140B().solve()


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

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

int n;
ll a[10000],b[10000];
ll A,B;
bool flg=true;

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

	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) cin>>b[i];
	REP(i,n) {
		if(a[i]<b[i]) {
			A+=(b[i]-a[i]+1)/2;
			if((b[i]-a[i])%2!=0) B++;
		}
		else if(a[i]>b[i]) {
			B+=(a[i]-b[i]);
		}
	}
	//if(A<B) a[0]+=2*(B-A);
	//else if(B<A) b[0]+=(A-B);
	if(B>A) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

bool check1[100000];
bool check2[100000];

ll dist_t[100000];

ll ans = 0;
vector<ll> node[100000];
void dfs1(ll no, ll dps){
    if(check1[no]){
        return;
    }else{
        check1[no] = true;
        dist_t[no] = dps;

        fore(a, node[no]){
            dfs1(a, dps + 1);
        }
    }
    return;
}

void dfs2(ll no, ll dps){
    if(check2[no]){
        return;
    }else{
        check2[no] = true;
        if(dps >= dist_t[no]){
            return;
        }else{
            ans = max(ans, dist_t[no]);
            fore(a, node[no]){
                dfs2(a, dps + 1);
            }
        }
    }
}

int main(void){
    ll n, u, v;
    cin >> n >> v >> u;
    u--;
    v--;

    rep(i, 0, n - 1){
        ll t1, t2;
        cin >> t1 >> t2;
        t1--;
        t2--;
        node[t1].push_back(t2);
        node[t2].push_back(t1);
    }

    dfs1(u, 0);
    dfs2(v, 0);

    if(ans == 0){
        cout << 0 << endl;
        return 0;
    }
    cout << ans - 1<< endl;
    return 0;
}




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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll A,B,C;

void solve(){
    if(A <= C && C <= B)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    cin >> A >> B >> C;

    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
const ll mod=1e9+7;

#define INF ll(1e9)
int32_t main()
{
    SPEED;
    int n,k;
    cin>>n>>k;
    ll h[n+1];
    for (int i = 1; i <= n; ++i)
    {
        cin>>h[i];
    }
    int dp[n+1];
    for (int i = 2; i <= n; ++i)
    {
        dp[i]=ll(1e9);
    }
    dp[1]=0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= k; ++j)
        {
            if(i+j<=n)
                dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
            //cout<<dp[i+j]<<endl;
        }
       // cout<<dp[i]<<endl;
    }
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
from itertools import product
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))
A, B, Q = inpl()
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    ans = 1e12
    ls, lt = S[max(0, bisect(S, x)-1)], T[max(0, bisect(T, x)-1)]
    rs, rt = S[min(A-1, bisect_left(S, x))], T[min(B-1, bisect_left(T, x))]
    for s in [ls, rs]:
        for t in [lt, rt]:
            if s < t:
                a, b = s, t
            else:
                a, b = t, s

            if x < a:
                if ans > b-x:
                    ans = b-x
            elif b < x:
                if ans > x-a:
                    ans = x-a
            else:
                if ans > 2*(x-a) + (b-x):
                    ans = 2*(x-a) + (b-x)
                if ans > (x-a) + 2*(b-x):
                    ans = (x-a) + 2*(b-x)
    print(ans)

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

int main(){
  int r;
  cin >> r;
  
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true){
        string s;
        int n;
        cin>>s;
        if(s=="-")break;
        cin>>n;
        for (int i = 0; i < n; i++){
            int k;
            string s1,s2;
            cin>>k;
            s2=s.substr(0,k);
            s1=s.erase(0,k);
            s=s1+s2;
        }
        cout<<s<<endl;
    }
}


Measured memory_bytes: 3216