akhauriyash/Code-Regression huggingface dataset:
#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 < (int)(n); i++)
using namespace std;

int main()
{
    int a, b, c, k,sum=0;
    cin >> a >> b >> c >> k;
    //cout << a << b << c << k << endl;
        
    int xa = min(k, a);
    k -= xa;
    sum += xa;

    if (k > 0) {
        int xb = min(k, b);
        k -= xb;
    }
    if (k > 0) {
        sum -= k;
    }

    cout << sum << endl;
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n;
    cin >> n;
    
    string ans;
    while (n){
        n--;
        ans += (n % 26) + 'a';
        n /= 26;
    }
    
    reverse(ans.begin(), ans.end());

    cout << ans << '\n';


    return 0;
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define fr(i, n) for (ll i = 0; i < n; i++)
#define frab(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 2e18 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ll N = 1e6 + 10;

ll a[N], b[N], c[N];

pair <int, int> solve(int n) {
    int li = INF, ri = -1;
    frab(i, 0, 1000) {
        int x = i;
        fr(j, n) {
            x = x / a[j] * a[j];
        }
        if (x == 2) {
            li = min(li, (int)i);
            ri = max(ri, (int)i);
        }
    }
    if (li == INF)
        li = -1;
    return mp(li, ri);
}

ll bp1(ll a1, ll a, ll x) {
    ll l = -1, r = INF / a1;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (m * a1 / a >= x / a)
            r = m;
        else
            l = m;
    }
    return r;
}

ll bp2(ll a1, ll a, ll x) {
    ll l = 0, r = INF / a1;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (m * a1 / a > x / a)
            r = m;
        else
            l = m;
    }
    return l;
}

pair <ll, ll> solveOK(int k) {
    if (a[k - 1] != 2) return {-1, -1};

    int x = 2;
    b[k] = c[k] = 2;
    for (int i = k - 1; i >= 1; i--) {
        ll t = bp1(a[i - 1], a[i], b[i + 1]);
        //if (t * a[i - 1] / a[i] != b[i + 1] / a[i]) return {-1, -1};
        b[i] = t * a[i - 1];

        t = bp2(a[i - 1], a[i], c[i + 1]);
        //if (t * a[i - 1] / a[i] != c[i + 1] / a[i]) break;//return {-1, -1};
        c[i] = t * a[i - 1];
        if (b[i] > c[i] || b[i] == 0 || c[i] == 0) return {-1, -1};
    }

    b[0] = b[1];
    c[0] = c[1] + a[0] - 1;

//    fr(i, k)        cout << b[i] << " ";cout << endl;
//    fr(i, k)        cout << c[i] << " ";cout << endl;


    return mp(b[0], c[0]);
}

int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    int k;
    cin >> k;
    fr(i,k)
        cin >> a[i];

    auto ans = solveOK(k);
    if (ans.first != -1)
        cout << ans.first << " " << ans.second;
    else
        cout << -1;


//    fr(i, 1000) {
//        int n = rand() % 10 + 3;
//        fr(j, n)
//            a[j] = rand() % 10 + 2;
//        a[n - 1] = 2;
//        auto ans1 = solve(n);
//        auto ans2 = solveOK(n);
//        if (ans1 != ans2) {
//            cout << "Error\n " << n << endl;
//            fr(j, n)
//                cout << a[j] << ' ';
//            cout << endl;
//            cout << ans1.first << " " << ans1.second << "\n" <<
//             ans2.first << " " << ans2.second << endl;
//            return 0;
//        }
//        if (ans1.first != -1) {
//            cout << "ok\n " << n << endl;
//            fr(j, n)
//                cout << a[j] << ' ';
//            cout << endl;
//            cout << ans1.first << " " << ans1.second << "\n" <<
//             ans2.first << " " << ans2.second << endl << endl << endl;
//        }
//    }
}



Measured memory_bytes: 9216
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,m;
    cin>>n>>m;
    VL a(m);
    REP(i,m)cin>>a[i];
    LL sum = 0;
    REP(i,m)sum+=a[i];
    LL ans = n - sum;
    PUTS(ans < 0 ? -1 : ans);
}

Measured memory_bytes: 3696
#include<stdio.h>

int main(){
  int n,q,i,key,j,k=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  int T[q];
  int A[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  S[n]=key;
  for(j=0;j<q;j++){
    i=0;
    while(1){
      if(T[j]==S[i]){
	k++;
	break;
      }
      if(i==n){
	break;
      }
      i++;
    }
  }
  printf("%d\n",k);

  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
const int maxn=100007;
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int sum1[maxn],sum2[maxn],a[maxn];
int main(){
    int ans=0;
    int n;cin>>n;for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) sum1[i]=gcd(sum1[i-1],a[i]);
    for(int i=n;i;i--) sum2[i]=gcd(sum2[i+1],a[i]);
    for(int i=1;i<=n;i++) ans=max(ans,gcd(sum1[i-1],sum2[i+1]));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nmk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nmk[0];
			int m = nmk[1];
			int k = nmk[2];

			for (int i = 0; i <= n; i++) {
				for (int j = 0; j <= m; j++) {
					int num = i * m;
					int delta = n - i - i;
					num += delta * j;
					if (k == num) {
						Console.WriteLine("Yes");
						return;
					}
				}
			}

			Console.WriteLine("No");
		}
	}
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(void){
    int N,i,j,count=2,num=0;
    scanf("%d",&N);
    if(N<105){
        printf("%d\n",0);
        return 0;
    }else{
        for(i=105;i<=N;i+=2){
            for(j=3;j<i;j++){
                if(i%j==0) count++;
            }
            if(count==8) num++;
            count = 2;
        }
    }
    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    ll n, k; cin >> n >> k;
    vector<int> ans;
    while(n){
        ans.emplace_back(n % k);
        n /= k;
    }
    reverse(All(ans));
    cout << ans.size() << endl;
    system("pause");
}

//https://www.geisya.or.jp/~mwm48961/kou3/base2.htm
//https://math.nakaken88.com/textbook/basic-base-conversion-of-integers/


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  string S;
  cin >> S;
  bool ans = true;
  REP(i, S.size()){
    if(i % 2){
      if(S[i] != 'L' && S[i] != 'U' && S[i] != 'D'){
        ans = false;
      }
    }
    else{
      if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D'){
        ans = false;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

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

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << 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)

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

const int MAX = 2 * 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, Q;
vector<int> G[MAX];
vector<int> ans(MAX);

void dfs(int n, int x, map<int, int>& m){
    ans[n] = x + m[n];
    for(auto i : G[n]){
        dfs(i, ans[n], m);
    }
}

int main(){
    cin >> N >> Q;
    rep(i, N - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    map<int, int> m;
    rep(i, Q){
        int p, x;
        cin >> p >> x;
        p--;
        m[p] += x;
    }

    dfs(0, 0, m);

    rep(i, N) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 39168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int main(){
	ll n;
	cin >> n;
	ll x, y;
	x = sqrt(n);
	while (x*x < n) ++x;
	//cout << x*x << endl;
	y = x*x - n;
	cout << 0 << " " << 0 << " " << x << " " << 1 << " " << y << " " << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define pi acos(-1)
main()
{

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

    long long i,j,k,l,m,n,o,p;
     char s[10000];
     while(cin>>s){
            l=strlen(s);
        j=s[l-1]-48;
        if(j==2||j==4||j==5||j==7||j==9)cout<<"hon"<<endl;
        else if(j==0||j==1||j==6||j==8)cout<<"pon"<<endl;
        else cout<<"bon"<<endl;
     }
    return 0;

}


Measured memory_bytes: 3660
s = range(1,14)
h = range(1,14)
c = range(1,14)
d = range(1,14)

n = input()

for i in range(n):
	mark, number = raw_input().split()

	if mark == 'S':
		s[int(number)-1] = 0
	elif mark == 'H':
		h[int(number)-1] = 0
	elif mark == 'C':
		c[int(number)-1] = 0
	elif mark == 'D':
		d[int(number)-1] = 0

for i in range(13):
	if s[i] != 0:
		print "S %d" %s[i]
for i in range(13):
	if h[i] != 0:
		print "H %d" %h[i]
for i in range(13):
	if c[i] != 0:
		print "C %d" %c[i]
for i in range(13):
	if d[i] != 0:
		print "D %d" %d[i]

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

#define pb push_back
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

using namespace std;
using ll = long long;

void solve() {
}

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

  int a;
  cin >> a;
  cout << 3 * a * a << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

s = 0

for i in range(n):
  s += b[a[i]-1]
  if i == n-1:
    break
  if a[i+1]-a[i] == 1:
    s += c[a[i]-1]

print(s)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


#define PI 3.1415926535897

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

	int n, m, x, y, i, j, k;
	cin >> n >> m >> x >> y;
	vector<int> xx(n), yy(m);
	for (i = 0; i < n; i++) cin >> xx[i];
	sort(xx.begin(), xx.end());
	for (i = 0; i < m; i++) cin >> yy[i];
	sort(yy.begin(), yy.end());

	bool valid = false;
	for (i = x + 1; i <= y; i++) {
		if ((i > xx[n - 1]) && (i <= yy[0])) valid = true;
	}
	if (valid) cout << "No War\n";
	else cout << "War\n";

	return 0;
}


Measured memory_bytes: 256
/*
  
*/
#include <stdio.h>
#include <stdlib.h>

#define TRUE 1
#define FALSE 0
#define OP_MAX 100
#define BUFSIZE 8

int pop(int op[]);
void push(int op[], int);
int isFull();
int isEmpty();

int top = 0;     /*スタックの一番上の要素の添え字を表す*/

int main()
{
  int opL, opR, tmp, op[OP_MAX];
  char buf[BUFSIZE];

  while(1)
    {
      if( scanf("%s", buf) == EOF )
	break;

      /*読み込んだものが演算子だった場合*/
      if( buf[0] == '+' || buf[0] == '-' || buf[0] == '*' )
	{
	  opR = pop(op);
	  opL = pop(op);

	  switch( buf[0] )
	    {
	     case '+':
	       tmp = opR + opL;
	       break;
	     case '-':
	       tmp = opL - opR;
	       break;
	     case '*':
	       tmp = opR * opL;
	       break;
	     defalut:
	       exit(4);
	    }
	  push(op, tmp);
	}
      else
	{
	  /* 読み込んだものが数値だった場合 */
	  tmp = atoi(buf);
	  push(op, tmp);
	}
    }

  /* 計算結果を出力 */
  printf("%d\n", pop(op));

  return 0;
}

/* スタックからデータをpopする関数 
   戻り値： 取り出したデータ    */
int pop(int op[])
{
  if( isEmpty() == TRUE )
    {
      fprintf(stderr, "Error! underflow\n");
      exit(2);
    }

  return op[top--];
}


/* スタックにデータをpushする関数 */
void push(int op[], int data)
{
  if( isFull() == TRUE )
    {
      fprintf(stderr, "Error! overflow\n");
      exit(3);
    }

  op[++top] = data;
}


/* スタックか空であるか判定する関数 
   戻り値： 空->TRUE  空でない->FALSE */
int isEmpty(void)
{
  if( top == 0 )
    return TRUE;
  else
    return FALSE;
}


/* スタックが満杯であるか判定する関数
   戻り値： 満杯->TRUE 空がある->FALSE */
int isFull(void)
{
  if( top == OP_MAX )
    return TRUE;
  else
    return FALSE;
}



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

#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
#define DEBUG(x) cerr << #x << " = " << x << endl

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 100005;
int x[N];
ll dp[N][2];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	int n;

	cin >> n;
	ll ans = 0;
	REPU(i, 0, n) cin >> x[i];
	dp[0][0] = x[0] / 2;
	dp[0][1] = x[0] == 0 ? -1 : (x[0] - 1) / 2;
	REPU(i, 1, n) {
		if (x[i] == 0) {
			dp[i][0] = 0;
			dp[i][1] = -1;
		}
		else {
			dp[i][0] = tmax(dp[i - 1][0] + x[i] / 2, dp[i - 1][1] + (x[i] + 1) / 2);
			dp[i][1] = tmax(dp[i - 1][0] + (x[i] - 1) / 2, dp[i - 1][1] + x[i] / 2);
		}
	}
	int i;
	for (i = 0; i < n; ++i) {
		if (x[i] == 0 && i > 0) ans += tmax(dp[i - 1][0], dp[i - 1][1]);
	}
	ans += tmax(dp[i - 1][0], dp[i - 1][1]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a,b;
  cin>>a;
  b=0;
  for(ll i=1;i<=a;i++){
    if(i%3!=0&&i%5!=0){
      b+=i;
    }
  }
  cout<<b<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool prime[100000];
ll N=100000;
void seive()
{
    int sqrtn,i,j;
    prime[0]=1,prime[1]=1,prime[2]=0;
    for(i=4;i<=N;i++)
    {
        prime[i]=0;
        if(i%2==0)
            prime[i]=1;
    }
    sqrtn=((int)sqrt((double)N));
    for(i=3;i<=sqrtn;i+=2)
    {
        if(prime[i]==0)
        {
            for(j=i*i;j<=N;j+=i+i)
            {
                prime[j]=1;
            }
        }
    }
}
int main()
{
    seive();
    ll q;
    ll a,b;
    ll sum=0;
    ll ans[100045];
    for(int i=0;i<100005;i++)
    {
        a=(i+1)/2;
        if(prime[i]==0&&prime[a]==0)
        {
            ans[i]=ans[i-1]+1;
        }
        else
        {
            ans[i]=ans[i-1];
        }
    }
   /* for(int i=0;i<10;i++)
    {
        cout<<ans[i]<<endl;
    }*/
    scanf("%lld",&q);
    for(int i=0;i<q;i++)
    {
        ll cnt=0;
        scanf("%lld %lld",&a,&b);
        cnt=ans[b]-ans[a-1];
        printf("%lld\n",cnt);
    }
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextLong();

        for (int i = (int) Math.sqrt(n); i >= 0; --i) {
            if (n % i == 0) {
                int digit = Long.toString(Math.max(n / i, i)).length();
                System.out.println(digit);
                break;
            }
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
    double a, b, c;
    double theta;
    cin >> a >> b >> c;
    theta = c * M_PI / 180;
    double S, L, h;
    S = a * b * sin(theta) / 2;
    L = a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(theta));
    h = b * sin(theta);
    cout << fixed << setprecision(4);
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;
}


Measured memory_bytes: 3528
//    https://youtu.be/mRHBP3xwgn4

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))

int main(){
    fast;
    ll t,n,m,i,j,k,temp,flag,ans;
    string s;
    cin>>n>>s;
    if(n>=3200) cout<<s;
    else cout<<"red";
    return 0;
}



Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
    nss <- map (map read . words) . lines <$> getContents
    mapM_ putStrLn $ map (unwords . (map show)) $ solve nss

solve :: [[Integer]] -> [[Integer]]
solve [] = []
solve (n:ns) = (solve'):(solve ns)
    where
        a = maximum n
        b = minimum n
        g = gcd a b
        l = (fromIntegral $ a * b) `div` (fromIntegral g)
        solve' = [g, l]

Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin << n
#define co(n) cout << n << endl
using namespace std;

int main(){
  int n;
  string x;
  cin >> n;
  int a[n];
  string s[n];
  rep(i,0,n) cin >> s[i] >> a[i];
  cin >> x;
  int c=0, d=0;
  rep(i,0,n){
    if(s[i]==x) break;
    else c++;
  }
  
  rep(i,c+1,n) d+=a[i];
  
  co(d);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb emplace_back
#define pob pop_back()
#define ff first
#define ss second
typedef long long int ll;
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define prq priority_queue<ll>
#define psq priority_queue<ll,vector<ll>,greater<ll>>
#define m_p make_pair
#define vcc vector<char>
#define vss vector<string>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define setbit(n) __builtin_popcountll(n)
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t = 1;
	//cin>>t;
	while (t--)
	{
		ll i, j, k, n, m, p2 = 0, p3 = 0, p5 = 0, ans = 1;
		cin >> n;
		m = n;
		while (m % 2 == 0)
		{m = m / 2; p2++;}
		m = n;
		while (m % 3 == 0)
		{m = m / 3; p3++;}
		m = n;
		while (m % 5 == 0)
		{m = m / 5; p5++;}
		for (i = p2 + 1; i <= 3; i++)
			ans *= 2;
		for (i = p3 + 1; i <= 2; i++)
			ans *= 3;
		for (i = p5 + 1; i <= 1; i++)
			ans *= 5;
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) ll x;cin>>x; while(x--)
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin>>n;
	string s;
	ll ac=0,tle=0,wa=0,re=0;
	for(ll i=0; i<n; i++){
		cin>>s;
		if(s=="AC")ac++;
		if(s=="WA")wa++;
		if(s=="TLE")tle++;
		if(s=="RE")re++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re;

}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace  std;

using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<int , int > pairs;
typedef complex<ll> G;
const int N=2e5+5;

const ll INF = 1e18;

void done() {
    int best = 0;
    int n;cin >> n;
    map<string, int>a;
    for(int i=0;i < n;i++) {
        string s;cin >> s;
        a[s]++;
        best = max(best, a[s]);
    }
    for(auto x : a) {
        if(x.second==best) {
            cout << x.first << '\n';
        }
    }



}
void solve() {

    int n;
    cin >>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<long double>c;
    for(int i=0;i < n;i++) {
        cin >> a[i];
    }
    int r = 0;
    for(int i=0;i < n;i++) {
        cin >> b[i];
        if(a[i]!=0) {
            c.push_back(b[i]/a[i]*1.0);
        }else if(b[i]=='0') {
            r++;
            c.push_back(-999999999);
        }
        else {
            c.push_back(-999999999);
        }
    }
    int sum = 1;
    int best = 0;
    sort(c.begin(), c.end());
    for(int i=1;i < n;i++) {
        if(c[i]==c[i-1] && c[i-1]!=-999999999) {
                sum++;
        }
        else {
            if(sum > best && c[i-1]!=-999999999) {
                best = sum;
                sum = 1;
            }
        }
    }
    if(sum > best && c[n-1]!=-999999999) {
        best = sum;
    }
    cout << best+r << '\n';
}
void another() {
    int n;cin >> n;

    string s;
    cin >> s;
    int left= 0, right = 0;
    int d = (s[0]=='<') ?1 : 0;
    int c = (s[n-1]=='>')?1 : 0;

    for(int i=0;i < n;i++) {
        if(i!=0 && s[i]=='<')left++;
        else if(i!=n-1 && s[i]=='>')right++;
    }
    if(left <= right) {
        swap(left, right);
        swap(d, c);
    }
    if(d) {
        cout << max(1, right-1) << '\n';
    }
    else cout << max(0, right-1) << '\n';



}
void test_case() {
    int t;
    cin >> t;
    while(t--)solve();
}
int main() {

    fast;
    done();

}



Measured memory_bytes: 19272
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
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=2010,INF=0x7f7f7f7f;
char a[N],b[N];
int n,ans=INF;
struct pii{
	int a,b;
	inline friend bool operator < (const pii &x,const pii &y){
		return x.a!=y.a?x.a<y.a:x.b<y.b;
	}
}ext[N];
int cnt[N];
int pre[N],nxt[N];
inline void work(){
	if(b[0]=='1'){
		pre[0]=0;
	}else for(int &i=pre[0]=1;b[n-i]=='0';i++);
	for(int i=1;i<n;i++){
		pre[i]=b[i]=='1'?0:pre[i-1]+1;
	}
	if(b[n-1]=='1'){
		nxt[n-1]=0;
	}else for(int &i=nxt[n-1]=1;b[i-1]=='0';i++);
	for(int i=n-2;i>=0;i--){
		nxt[i]=b[i]=='1'?0:nxt[i+1]+1;
	}
	for(int sh=0;sh<n;sh++){//a[i]->a[i+sh]
		int diff=0,ps=0;
		memset(cnt,0,n<<2);
		for(int i=0;i<n;i++){
			if(a[i]!=b[(i+sh)%n]){
				diff++;
				int l=pre[i],r=nxt[i];
				if(r<=sh)continue;
				ext[ps++]=(pii){l,r-sh};
				cnt[r-sh]++;
			}
		}
		sort(ext,ext+ps);
		int p=n-1;
		for(;p>0&&cnt[p]==0;p--);
		apmin(ans,sh+(p<<1)+diff);
		for(int i=0;i<ps;i++){
			cnt[ext[i].b]--;
			for(;p>0&&cnt[p]==0;p--);
			apmin(ans,sh+((ext[i].a+p)<<1)+diff);
		}
	}
}
inline int Main(){
	scanf("%s%s",a,b);
	n=strlen(a);
	bool same=true,one=false;
	for(int i=0;i<n;i++){
		same&=a[i]==b[i];
		one|=b[i]=='1';
	}
	if(same)return 0;
	if(!one)return -1;
	work();
	reverse(a,a+n);
	reverse(b,b+n);
	work();
	return ans;
}
int main(){
	printf("%d\n",Main());
	return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    R = inputInt()
    G = inputInt()
    
    print((2*G)-R)
    
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<ctime>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 400000;
int n,m,a[N],b[N],dot[N]; ll ans;
Vi e[N]; bool gg[N];
inline ui R() {
	static ui seed=time(0);
	return seed^=seed<<13,seed^=seed>>7,seed^=seed<<17;
}
struct node {
	int u;
	node(int X=0) {u=X;}
	bool operator > (const node &x) const {
		return b[u]-a[u]>b[x.u]-a[x.u];
	}
	bool operator < (const node &x) const {
		return b[u]-a[u]<b[x.u]-a[x.u];
	}
};
priority_queue<node> heap;
ll getans(int p) {
	ll ans=0; memset(gg,0,sizeof(gg));
	ans=max(b[p],a[p]); gg[p]=1; //printf("%d : %d \n",p,b[p]-a[p]);
	per(i,SZ(e[p])-1,0) if (!gg[e[p][i]]) heap.push(node(e[p][i]));
	while (!heap.empty()) {
		int u=heap.top().u; heap.pop(); if (gg[u]) continue;
		gg[u]=1; ans=max(a[u]*1LL,b[u]+ans);
		per(i,SZ(e[u])-1,0) if (!gg[e[u][i]]) heap.push(node(e[u][i]));
	}
	return ans;
}
bool cmp(int i, int j) {return b[i]-a[i]>b[j]-a[j];}
int main() {
	read(n);read(m);
	rep(i,1,n)read(a[i]),read(b[i]);
	rep(i,1,m){int u,v;read(u);read(v);e[u].push_back(v);e[v].push_back(u);}
	
	ll ans=6e18;
	rep(i,1,n) dot[i]=i;
	sort(dot+1,dot+n+1,cmp);
	for (int i=1; i<=n&&clock()<=1.70*CLOCKS_PER_SEC; i++) 
		ans=min(ans,getans(dot[i]));
	cout<<ans;
	return 0;
}


Measured memory_bytes: 19840
# -*- coding: utf-8 -*-

from math import sqrt, floor

def readInts():
  return [int(s) for s in input().split(" ")]

def solve(N):
  ans = N - 1
  for i in range(1, floor(sqrt(N)) + 1):
    if N % i == 0:
      ans = min(ans, (i - 1) + ((N // i) - 1))
  return ans

def main():
  N = readInts()[0]
  print(solve(N))

if __name__ == "__main__":
  main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  cin >> c;
  if(c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' || 
     c == 'G' || c == 'H' || c == 'I' || c == 'J' || c == 'K' || c == 'L' || 
     c == 'M' || c == 'N' || c == 'O' || c == 'P' || c == 'Q' || c == 'R' || 
     c == 'S' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X' || 
     c == 'Y' || c == 'Z')
    cout << "A" << endl;
  else
    cout << "a" << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

#define int long long

using namespace std;

signed main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int a = k + 1; a <= n; a++) {
		ans += (a - k) * (n / a);
		int c = n % a;
		ans += max((int)0, c - k + 1);
		// cout << a << ' ' << ans << '\n';
	}
	if (k == 0) {
		ans -= n;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);
//or-> ||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	string T;
	cin>>T;
	if(T[0]=='?'){
		T[0]='D';
	}
	reverse(all(T));
	if(T[0]=='?'){
		T[0]='D';
	}
	rep(i,1,T.size()-1){
		if(T.at(i)=='?'){
			if(T.at(i-1)=='D'){
				if(T.at(i+1)!='P'){
					T[i]='P';
				}
				else{
					T[i]='D';
				}
			}
			else{
				T[i]='D';
			}
		}
	}
	reverse(all(T));
	cout<<T<<endl;
	return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;
  if(A+B==3)cout << 3 << endl;
  if(A+B==4)cout << 2 << endl;
  if(A+B==5)cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [input() for _ in range(N)]

D = [[0 for j in range(40)] for i in range(60)]

for a in A:
    #まずは分子の整数Bと分母の指数kに分けていく
    B=0;k=0
    for j in range(len(a)):
        if a[j]!='.':
            B=B*10
            B=B+int(a[j])
        if a[j]=='.':
            k=len(a)-j-1
    
    #次にBに2と5がいくつ含まれるかを求める
    t=0;f=0
    b=B
    while b%2==0:
        t+=1
        b=b//2
    b=B
    while b%5==0:
        f+=1
        b=b//5
    
    #D[t-k][f-k]をインクリメントする
    #…と言いたいところだがマイナスになりうるので+10したものを入れる
    
    D[t-k+10][f-k+10]+=1
    

Ans=0
for i in range(len(D)):
    for j in range(len(D[i])):
        for k in range(len(D)):
            for l in range(len(D[k])):
                #(hoge*2^i*5^j)*(fuga*2^k*5^l)がOKならAnsに足し入れる
                if i+k-20>=0 and j+l-20>=0 and not(i==k and j==l):
                    Ans = Ans+D[i][j]*D[k][l]

#D[i][j]*D[k][l]とD[i][l]*D[i][j]で同じものを２回かけているので2で割っておく
Ans = Ans//2

#違うA_iでも同じt-k,f-kを持つことはある
#ので、それを処理する
for i in range(len(D)):
    for j in range(len(D[i])):
        if i-10>=0 and j-10>=0:
            Ans = Ans + D[i][j]*(D[i][j]-1)//2

print(Ans)        

Measured memory_bytes: 95988
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
fn main(){
    input!{
        s:Chars,
        t:Chars,
    }
    let mut ans = t.len();
    for i in 0..s.len() {
        let mut count_dif_char = 0;
        if i + t.len() > s.len() {
            break;
        }
        for j in 0..t.len() {
            if &s[i + j] != &t[j] {
                count_dif_char += 1;
            }
        }
        if count_dif_char < ans {
            ans = count_dif_char;
        }
    }
    println!("{}", ans);
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S;
    cin >> S;
    ll N = (ll)S.size();

    ll ans = 0;
    string stmp;
    for (ll mask = 0; mask < (1LL << (N - 1)); mask++) {
        ll il = 0;
        for (ll i = 0; i < N - 1; i++) {
            if ((mask >> i) & 1) {
                stmp = S.substr(il, i + 1 - il);
                ans += stol(stmp);
                il = i + 1;
            }
        }
        stmp = S.substr(il);
        ans += stol(stmp);
    }
    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 256
import java.util.*
import java.math.*
import java.lang.Math.*


private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }
//private val MOD = 1e9.toLong()+7
//private val INF = Int.MAX_VALUE/2
//private val LINF = Long.MAX_VALUE/2


class GridBfs(val G: List<String>, val Start:Char = '#',
              val ToPaint:Char = '.') {
    var H:Int = 0
    var W:Int = 0
    data class Pos(val x: Int, val y: Int)
    private val starts = ArrayList<Pos>()
    init {
        H = G.size
        W = G[0].length
        G.forEachIndexed{i, row ->
            row.forEachIndexed{j, cell ->
                if (cell == Start) starts.add(Pos(i,j))
            }
        }
    }
    private val dx = intArrayOf(0,1,0,-1)
    private val dy = intArrayOf(1,0,-1,-0)
    private val INF = Int.MAX_VALUE/2
    fun fill(): Int {
        //val que = ArrayDeque<Pos>()
        val qx = ArrayDeque<Int>()
        val qy = ArrayDeque<Int>()
        val step = Array(H){IntArray(W){INF} }
        for (ps in starts) {
            //que.addLast(ps)
            qx.addLast(ps.x)
            qy.addLast(ps.y)
            step[ps.x][ps.y] = 0
        }
        while (qx.isNotEmpty()) {
            val x = qx.removeFirst()
            val y = qy.removeFirst()
            for (i in dx.indices) {
                val nx = x + dx[i]; val ny = y + dy[i]
                if (nx<0 || H<=nx || ny<0 || W<=ny) {
                    continue
                }
                if (step[nx][ny] > step[x][y] + 1) {
                    step[nx][ny] = step[x][y] + 1
                    //que.addLast(Pos(nx, ny))
                    qx.addLast(nx)
                    qy.addLast(ny)
                }
            }
        }

        var res = -INF
        step.forEach { it.forEach { res = max(res, it) } }
        return res
    }
}


fun solveA(A: Array<String>): Int {
    val bfs = GridBfs(A.toList())
    return bfs.fill()
}


fun main(args: Array<String>) {
    val (H, W) = readListInt()
    val A = Array<String>(H){""}
    for (i in 0 until H) {
        A[i] = readString()
    }

    val ans = solveA(A)

    println(ans)
}


Measured memory_bytes: 161044
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n+1];
		long res = 0;
		for(int i = 0; i < n+1; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			long d = sc.nextInt();
			if(A[i] + A[i+1] >= d){
				res += d;
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
			}
			else{
				res += A[i] + A[i+1];
				A[i] -= d;
				if(A[i] < 0) A[i+1] += A[i];
				if(A[i+1] < 0) A[i+1] = 0;
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 65728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
int x;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> x;
	if (x >= 30){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

//cout.flush()

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

int main(){
	while(1){
		int n;
		cin>>n;

		if(n==0)
			break;
		
		char c[100];
		for(int i=0;i<n;i++){
			cin>>c[i];
		}

		int cnt[26]={0};

		for(int i=0;i<n;i++){
			cnt[(int)(c[i]-'A')]++;
			
			int max1=-1;
			int max2=-1;

			for(int j=0;j<26;j++){
				if(cnt[j]>max1){
					max2=max1;
					max1=cnt[j];
				}
				else if(cnt[j]>max2){
					max2=cnt[j];
				}
			}
		
			if(max1-max2>n-(i+1)){
				for(int j=0;j<26;j++){
					if(cnt[j]==max1){
						cout<<(char)(j+'A')<<" ";
						break;
					}
				}
				cout<<(i+1)<<endl;
				break;
			}

			if(i==(n-1)){
				cout<<"TIE"<<endl;
				break;
			}
		}
	}
		
	return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))

int main()
{
    int n;
    int a, b, c, d;

    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

    printf("%d\n", min(((n + (a - 1)) / a) * b, ((n + (c - 1)) / c) * d));
    
    return 0;
}



Measured memory_bytes: 1992
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let m = nm[1];
    let lr: Vec<Vec<u32>> = read_vec2(m);

    let mut l: u32 = 0;
    let mut r: u32 = 100001;
    for i in 0..m {
        if lr[i][0] > l {
            l = lr[i][0];
        }
        if lr[i][1] < r {
            r = lr[i][1];
        }
        if l > r {
            break;
        }
    }

    if l > r {
        println!("0");
    } else {
        println!("{}", r - l + 1);
    }
}


Measured memory_bytes: 8444
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    int check[9];
    REP(0, i, 9) {
        check[i] = 0;
    }

    REP(0, i, N) {
        int a;
        cin >> a;

        if (a < 3200) {
            check[a / 400] = 1;
        } else {
            check[8]++;
        }
    }

    int cnt = 0;
    REP(0, i, 8) {
        cnt += check[i];
    }

    if (cnt == 0) {
        cout << 1 << ' ' << check[8] << endl;
    } else {
        cout << cnt << ' ' << cnt + check[8] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = arrayInt(sc, n);
		sc.close();
		int cur = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != cur) {
				ans++;
			} else {
				cur++;
			}
		}
		System.out.println(ans == n ? -1 : ans);
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static long arrayMax(long[] array) {
		long ans = Long.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}

	public static String[] arrayString(Scanner sc, int n) {
		String[] array = new String[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.next();
		}
		return array;
	}

	static String nextPermutation(String s) {

		ArrayList<Character> list = new ArrayList<>();
		for (int i = 0; i < s.length(); i++)
			list.add(s.charAt(i));

		int pivotPos = -1;
		char pivot = 0;
		for (int i = list.size() - 2; i >= 0; i--) {
			if (list.get(i) < list.get(i + 1)) {
				pivotPos = i;
				pivot = list.get(i);
				break;
			}
		}

		if (pivotPos == -1 && pivot == 0)
			return "Final";

		int L = pivotPos + 1, R = list.size() - 1;
		int minPos = -1;
		char min = Character.MAX_VALUE;
		for (int i = R; i >= L; i--) {
			if (pivot < list.get(i)) {
				if (list.get(i) < min) {
					min = list.get(i);
					minPos = i;
				}
			}
		}

		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R + 1));

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++)
			sb.append(list.get(i));

		return sb.toString();
	}
}


Measured memory_bytes: 85232
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define EPS 1e-11
 
using namespace std;
typedef long long int ll;
 
double add(double a, double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
	return a+b;
}
 
struct P{
	double x, y;
	P() {}
	P(double x, double y): x(x), y(y){
	}
	P operator+ (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator- (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator* (double d){
		return P(x*d, y*d);
	}
	double dot(P p){
		return add(x*p.x, y*p.y);
	}
	double det(P p){
		return add(x*p.y, -y*p.x);
	}
	bool operator< (const P& p) const{
		if(abs(x-p.x)>EPS){
			return x<p.x;
		}else{
			return y<p.y-EPS;
		}
	}
};
 
bool on_seg(P p1, P p2, P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}
 
P intersection(P p1, P p2, P q1, P q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1) / (q2-q1).det(p2-p1));
}

int main()
{
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) return 0;
		P p1[100], p2[100];
		set<P> st;
		for(int i=0; i<n; i++){
			double x1, y1, x2, y2;
			scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
			p1[i]=P(x1, y1), p2[i]=P(x2, y2);
			st.insert(p1[i]);
			st.insert(p2[i]);
		}
      if(n==1){
        printf("%d\n", 2);
        continue;
      }
		int v, e=st.size();
		for(int i=0; i<n; i++){
			set<P> st1;
			for(int j=0; j<n; j++){
				if(i==j) continue;
				if((p1[i]-p2[i]).det(p1[j]-p2[j])==0) continue;
				P q=intersection(p1[i], p2[i], p1[j], p2[j]);
				if(-100+EPS<q.x && q.x<100-EPS && -100+EPS<q.y && q.y<100-EPS){
					st1.insert(q);
					st.insert(q);
				}
			}
			e+=(st1.size()+1);
		}
		v=st.size();
		printf("%d\n", e-v+1);
	}
	return 0;
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll d=a-b;
	cout << (c-d>=0? c-d:0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    bool flag = false;
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        if(c == 'Y'){
            flag = true;
        }
    }
    if(flag){
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

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

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e15;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> vs(3 * n);
    rep(i, 3 * n) {
        cin >> vs[i];
        vs[i]--;
    }
    vector<vector<ll>> dp(n, vector<ll>(n, -INF));
    vector<ll> dpMax(n, -INF);
    ll cMax = 0;
    ll threes = 0;
    dp[vs[0]][vs[1]] = 0;
    dp[vs[1]][vs[0]] = 0;
    dpMax[vs[0]] = 0;
    dpMax[vs[1]] = 0;
    vector<t3> updates;
    updates.reserve(n* n);
    for (int i = 0; i < n - 1; i++) {
        updates.clear();
        const ll* buffer = &vs[3*i+2];
        //3枚同じ
        if (buffer[0] == buffer[1] and buffer[1] == buffer[2]) {
            threes++;
            continue;
        }
        //2枚同じ
        if (buffer[0] == buffer[1]) {
            ll p = buffer[0];
            ll k = buffer[2];
            for (int j = 0; j < n; j++) {
                updates.emplace_back(j, k, dp[p][j] + 1);
                updates.emplace_back(j, k, dp[j][p] + 1);
            }
        }
        else if (buffer[1] == buffer[2]) {
            ll k = buffer[0];
            ll p = buffer[2];
            for (int j = 0; j < n; j++) {
                updates.emplace_back(j, k, dp[p][j] + 1);
                updates.emplace_back(j, k, dp[j][p] + 1);
            }
        }
        else if (buffer[0] == buffer[2]) {
            ll k = buffer[1];
            ll p = buffer[2];
            for (int j = 0; j < n; j++) {
                updates.emplace_back(j, k, dp[p][j] + 1);
                updates.emplace_back(j, k, dp[j][p] + 1);
            }
        }
        //3枚ばらばらでカウント
        ll p = buffer[0];
        ll k = buffer[1];
        ll l = buffer[2];
        updates.emplace_back(k, l, dp[p][p] + 1);
        updates.emplace_back(p, l, dp[k][k] + 1);
        updates.emplace_back(p, k, dp[l][l] + 1);
        rep(j, 3) {
            rep(a, j) {
                ll p = buffer[a];
                ll k = buffer[j];
                updates.emplace_back(p, k, cMax);
            }
        }
        rep(j, 3) {
            ll p = buffer[j];
            rep(k, n) {
                updates.emplace_back(k, p, dpMax[k]);
            }
        }
        for (auto t : updates) {
            ll j, k, v;
            tie(j, k, v) = t;
            chmax(dp[j][k], v);
            chmax(dp[k][j], v);
            chmax(dpMax[j], v);
            chmax(dpMax[k], v);
            chmax(cMax, v);
        }
    }
    ll u = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == vs[3 * n - 1] && i == j) {
                chmax(u, dp[i][i] + 1);
            }
            else {
                chmax(u, dp[i][j]);
            }
        }
    }
    cout << u + threes << endl;
    return 0;
}


Measured memory_bytes: 35004
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,m;
    cin>>n>>m;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll s=0;
    for(int i=0;i<n-m;i++)
    {
        s+=a[i];
    }
    cout<<s<<endl;
}


Measured memory_bytes: 1792