akhauriyash/Code-Regression huggingface dataset:
from collections import deque

s = deque(list(input()))

q = int(input())

reverse = 0

for i in range(q):
  query = list(input().split())
  if query[0] == '1':
    reverse ^= 1
    continue
  else:
    if query[1] == '1':
      if reverse:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse:
        s.appendleft(query[2])
      else:
        s.append(query[2])
if reverse:
  print(''.join(s)[::-1])
else:
  print(''.join(s))



Measured memory_bytes: 103932
import sys
H,W=map(int,input().split())
a = [[c for c in l.strip()] for l in sys.stdin]
#print(a)
dic={}
for i in range(H):
  for j in range(W):
    if(a[i][j] not in dic):
      dic[a[i][j]]=1
    else:
      dic[a[i][j]]+=1
#print(dic)
flag=True
if(H%2==0 and W%2==0):
  for i in dic.keys():
    if(dic[i]%4!=0):
      flag=False
elif((H%2==1 and W%2==0)):
  count=0
  for i in dic.keys():
    if(dic[i]%2!=0):
      flag=False
    if(dic[i]%4==2):
      count+=1
  if(count>W//2):
    flag=False
elif((H%2==0 and W%2==1)): 
  count=0
  for i in dic.keys():
    if(dic[i]%2!=0):
      flag=False
    if(dic[i]%4==2):
      count+=1
  if(count>H//2):
    flag=False
else:
  count2=0
  count1=0
  for i in dic.keys():
    if(dic[i]%4==1):
      count1+=1
    elif(dic[i]%4==2):
      count2+=1
    elif(dic[i]%4==3):
      count1+=1
      count2+=1
  if(count1>2 or count2>(W+H)//2-1):
    flag=False
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
	
	int N;
	scanf("%d",&N);
	
	switch(N){
		case 25:
			printf("Christmas");
			break;
		case 24:
			printf("Christmas Eve");
			break;
			
		case 23:
			printf("Christmas Eve Eve");
			break;
		case 22:
			printf("Christmas Eve Eve Eve");
			break;
	}
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
XYH.sort(key=lambda x:x[2], reverse=True)
isOk = False
cx = 0
while cx <= 100:
  cy = 0
  while cy <= 100:
    x, y, h = XYH[0]
    H = h+abs(x-cx)+abs(y-cy)
    i = 1
    isOk = True
    while i < N and isOk:
      x, y, h = XYH[i]
      if max(H-abs(x-cx)-abs(y-cy),0) != h:
        isOk = False
      i += 1
    if isOk:
      break
    cy += 1
  if isOk:
    break
  cx += 1
print(cx, cy, H)

Measured memory_bytes: 40560
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
const int N=200000+10;
char s[N];
vector<int> g[N];
void prt(int u,int p){
    for(auto v:g[u]){
        if(v==p)continue;
        printf("%d %d\n", u,v);
        prt(v,u);
    }
}
int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    for(int i=1;i<n;i++) if(s[i]!=s[n-i]) return !printf("-1\n");
    if(s[1]=='0'||s[n]=='1') return !printf("-1\n");
    int now=1, top=1;
    for(int i=1,j=i;i<=n;i=j){
        if(s[i]=='1'){
            if (i!=1){ 
                while(now+1<=i) {
                    //printf("add %d %d\n", now+1, top);
                    g[now+1].push_back(top); 
                    g[top].push_back(now+1);
                    ++now;
                }
            }
            while(j<=n&&s[i]==s[j]) {
                ++j; 
                //printf("addd %d %d\n", now+1, top);
                g[now+1].push_back(top), g[top].push_back(now+1); ++now; top=now;
            }
        } else {
            ++j;
        }
    }
    prt(top,top);
}






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

using namespace std;
typedef long long ll;

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

    int S = 0;
    for(int i=0; i<N; i++) S += A[i];
    int hS = S/2;
    bitset<2000*2000> knapsack;
    
    knapsack[0] = 1;
    for(int i=0; i<N; i++){
        knapsack = knapsack | (knapsack << A[i]);
    }

    int highest_true = 0;
    for(int i=1; i<=hS; i++){
        if(knapsack[i]) highest_true = i;
    }

    cout << S - highest_true << endl;
}


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

int D[6];
void spin(char c)
{
    if(c=='E'){
        swap(D[0],D[3]);swap(D[3],D[5]);swap(D[5],D[2]);
    }
    else if(c=='W'){
        swap(D[0],D[2]);swap(D[2],D[5]);swap(D[5],D[3]);
    }
    else if(c=='S'){
        swap(D[0],D[1]);swap(D[0],D[4]);swap(D[4],D[5]);
    }
    else if(c=='N'){
        swap(D[0],D[1]);swap(D[1],D[5]);swap(D[5],D[4]);
    }
}


int main() {
    //?????¢???????????????
    for (int i = 0; i < 6 ; ++i) {
        cin >> D[i];
    }
    int Dice[6];

    //?????????????????????
    for (int i = 0; i < 6 ; ++i) {
        cin >> Dice[i];
    }

    bool ans = 0;

    //?????¢???????????????
    char SWS[10]={"SSSSWSSSS"};
    for(int i=0;i<10;i++){
        if(D[1]==Dice[1])break;
        spin(SWS[i]);
    }
    //?????¢???????????????
    for(int j=0;j<4; ++j){
        if(D[0] == Dice[0]){
            if(D[2]==Dice[2] && D[3]==Dice[3] &&D[4]==Dice[4] && D[5]==Dice[5])
                ans = 1;
        }
        spin('W');
        }

    //??????
    if (ans == 1){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<climits>
#include<map>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
int n;
char s[100010];
vector<ll> v;
ll res=0;
ll dfs(int i,ll pro){
  if(i==v.size()){
    res=(res+pro)%MOD;
    return 0;
  }
  dfs(i+1,(pro*v[i])%MOD);
  dfs(i+1,pro);
  return 0;
}
int main(){
  scan(n);
  rep(i,n){
    scan(s[i]);
  }
  map<char,ll> mc;
  rep(i,n){
    mc[s[i]]++;
  }
  for(auto ite=mc.begin();ite!=mc.end();ite++){
    v.push_back(ite->second);
  }
  dfs(0,1);
  prin(res-1);
  




  
    

  

  return 0;
}


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

typedef unsigned long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;
    unordered_map<string,ll> S;
    REP(i,N){
       string s;
       cin >> s;
       sort(s.begin(), s.end());
       S[s]++;
    }

    ll count = 0;
    for(auto i : S ){
       if(i.second > 1 ){
          if( i.second%2 == 0){
             count += (i.second/2)*(i.second-1);
          }else{
             count += (i.second * ((i.second-1)/2));
          }
       }
    }
    cout << count << endl;
}


Measured memory_bytes: 10660
s = str(input())
a = s[0:4]
b = s[5:7]
c = s[8:10]
ans = 0
if int(a) <= 2019:
    if int(b) <= 4:
        if int(c) <= 30:
            ans += 1
if ans == 1:
    print("Heisei")
else :
    print("TBD")

Measured memory_bytes: 3060
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=5e2+4;

int main()
{
	int n;

	scn(n);

	string s;

	cin>>s;

	vector<int> v[3];

	vector<int> fa(n+1,0);

	int r=0,b=0,g=0;

	rep(i,0,n)
	{
		if(s[i]=='R')
		v[0].pb(i),r++;
		else if(s[i]=='G')
		v[1].pb(i),b++;
		else
		v[2].pb(i),g++,fa[i]=1;
	}

	ll ans=0;

	for(int x:v[0])
	{
		for(int y:v[1])
		{
			int x1=x,y1=y;

			if(x1>y1)
			swap(x1,y1);

			ans+=(int)v[2].size();

			int dif=y1-x1;

			// cout<<dif<<endl;

			if(x1-dif>=0 and fa[x1-dif])
			ans--;

			if(y1+dif<n and fa[y1+dif])
			ans--;

			if(dif%2==0 and fa[(x1+y1)/2])
			ans--;
		}
	}

	lpri(ans);

    return 0;
}

Measured memory_bytes: 3796
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
typedef long long LL;
using namespace std;

static LL MAX = 1000000;
static LL MOD = 1000000007;

vector<LL> fac(MAX), finv(MAX), inv(MAX);
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
 
LL COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    int x;
    int y;
    int n;
    int r;
    LL ans=0;
    cin >> x >> y;
    n = (x+y)/3;
    r = x-n;
    COMinit();
    if((x+y)%3!=0 || r<0){
      ans = 0;
    }else{
      ans = COM(n, r);
    }
    cout << ans << endl;
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> points(N,K-Q);
  
  int a;
  for(int i=0; i<Q; i++){
    cin >> a;
    points[a-1]++;
  }
  
  for(int i=0; i<N; i++){
    if(points[i]>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#pragma region Macros
// ===========
// include
// ===========
#include <bits/stdc++.h>

using namespace std;

// ===========
// typedef
// ===========
typedef int64_t int64;
typedef vector<int64> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

// ===========
// conversion
// ===========
inline int toInt(string s) {int 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; }
inline int64 Factorial( int64 n ){ return n == 0 ? 0 : ( n == 1 ? 1 : Factorial( n - 1) * n  ); }

// ===========
// repetition
// ===========
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), __length = int(b); i < __length; ++i)

void input(vector<int64> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }
void input(vector<string> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }

#pragma endregion //Macros

int main()
{
    int64 N, D;
    VI X, Y;
    cin >> N >> D;

    X.resize(N);
    Y.resize(N);

    rep(i, N)
    {
        cin >> X.at(i) >> Y.at(i);
    }

    int64 sqrD = D * D;
    int count = 0;

    rep(i, N)
    {
        const int64& x = X.at(i);
        const int64& y = Y.at(i);
        if( (x * x + y * y)  <= sqrD )
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 6420
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
   string s;
   cin>>s;
   int cnt=0;
   for(int i=0;i<s.length();i++)
   {

       if(cnt<3)
       {  cnt++;
          cout<<s[i];
   }
   }

 return 0;
}



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

class UF {
private:
	vector<int> par;
	vector<int> sz;
public:
	UF(int n) { 
		par = vector<int>(n+10);
		sz = vector<int>(n+10);
		for(int i = 0; i < n+10; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x,int y) {
		x = find(x);
		y = find(y);
		if(x == y) return;
		if (sz[x] < sz[y]) swap(x,y);
		par[y] = x;
		sz[x] += sz[y];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int main() {
    int n,m;
    cin >> n >> m;
    UF uf(n+10);
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        uf.unite(a,b);
    }
    int ma = 0;
    for(int i = 0; i < n; i++){
        ma = max(ma,uf.size(i));
    }
    cout << ma << endl;
	return 0;
}

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

def dfs(s):
    if int(s) > N:
        return 0
    ok = True
    ret = 0
    for c in "753":
        if s.count(c) < 1:
            ok = False
            break
    if ok:
        ret = 1
    for c in "753":
        ret += dfs(s+c)
    return ret

print(dfs("0"))


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

int main (void){
    int N;
    cin >> N;
    vector<P> coord(N);
    rep(i, N) cin >> coord.at(i).first >> coord.at(i).second;
    
    vector<int> order(N);
    rep(i, N) order.at(i) = i;
    double sum = 0;
    int count = 0;
    do {
        count++;
        double tmp_dist=0;
        rep(i, N-1) {
            double tmp_dist_x = coord.at(order.at(i)).first - coord.at(order.at(i+1)).first;
            double tmp_dist_y = coord.at(order.at(i)).second - coord.at(order.at(i+1)).second;
            tmp_dist += sqrt(pow(tmp_dist_x, 2.0) + pow(tmp_dist_y, 2.0));
        }
        sum += tmp_dist;
    } while (next_permutation(order.begin(), order.end()));
    
    printf("%.10f\n", sum / count);
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int S = 0;
  
  for(int i=0; i < N; i++){
    int x;
    cin >> x;
    if(x <= K-x){
      S += 2*x;
    }  
    else{
      S += 2*(K-x);
    }
  }
  cout << S << endl;
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>//157B
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll i,j,n,k;
    char key;
    string s;
    cin>>n>>s>>k;
    key=s[k-1];
    for(i=0;s[i];i++)
    {
        if(key!=s[i])
        cout<<"*";
        else cout<<s[i];

    }

    cout<<endl;



    return 0;
}





Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

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

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

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

int main() {
    string s;
    cin >> s;

    ll s_count = 0;
    ll ans = 0;
    for(auto c : s) {
        if (c == 'S') {
            ++s_count;
            ++ans;
        } else {
            if (s_count) {
                --s_count;
                --ans;
            } else {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
/***********************************************************************************
*           Falling down is an accident, Staying down is a choice.                 *
***********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) //Fast IO
#define _USE_MATH_DEFINES
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;
void solve();int main(){ios;solve();return 0;}
/***********************************************************************************/
void solve()
{
	int n; cin >> n;
	vector<ll> a(n),oa(n);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]=a[i]*2;
		oa[i]=a[i];
		if(i&1) a[i]=-a[i];
		sum+=a[i];
	}
	vector<ll> x(n);
	x[0]=sum/2;
	for(int i=1;i<n;i++)
	{
		x[i]=oa[i-1]-x[i-1];
	}
	for(int i=0;i<n;i++)
	{
		cout<<x[i]<<" ";
	}
	cout<<endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-6)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

int n,m,K[201],S[201][21],H[201][21];
double cost[210][210];
double dp[210];

void compute() {
  rep(i,n) {
    rep(j,m+1) {
      int remain = j;
      rep(k,K[i]) {
        if( remain == 0 ) break;
        if( 0 < S[i][k] * H[i][k] && S[i][k] * H[i][k] <= remain ) {
          cost[i][j] += H[i][k];
          remain -= S[i][k] * H[i][k];
        } else {
          cost[i][j] += (double)remain/(double)S[i][k];
          remain = 0;
        }
      }
    }
  }
  rep(i,n) {
    for(int j=m;j>=0;--j) {
      rep(k,m+1) {
        if( j+k <= m && LT(dp[j+k],dp[j] + cost[i][k]) ) {
          dp[j+k] = dp[j] + cost[i][k];
        }
      }
    }
  }
  printf("%.10f\n",dp[m]);
}

int main() {
  cin >> n >> m;
  rep(i,n) {
    cin >> K[i];
    rep(j,K[i]) cin >> S[i][j] >> H[i][j];
  }
  compute();
  return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long
#define PI 2 * acos(0.0)
#define MAX 1000000000
#define INF 1000000 
#define M 1000000007
using namespace std;
int main(){
   ll n;
   cin>>n;
   string s;
   cin>>s;
   if(n == 0){
      cout<<s<<endl;
      return 0;
   }
   map<ll,ll> mp;
   char a = 'A';
   for(ll i = 0;i<26;i++){
        mp[a] = i;
        a++;
   }
   string d;
   char b = 'A';
   for(ll i = 0;i<s.length();i++){
      ll y = (mp[s[i]] + n)%26;
      char f = b+y;
      d.push_back(f);
   }
   cout<<d<<endl;
   return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=t.at(i)){
            count++;
        }
    }
    cout<<count<<endl;


}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

int main(){
    ll N; cin>>N;
    vec d(N);
    rep(i,N) cin>>d[i];
    vec x;
    x.pb(d[0]);
    REP(i,1,N-1) if((d[i]-d[i-1])*(d[i]-d[i+1])>=0) x.pb(d[i]);
    x.pb(d[N-1]);
    ll ans=1000;
    ll kabu=0;
    ll K=x.size();
    //cout<<K<<endl;
    rep(i,K-1){
        if(x[i]>x[i+1]) {
            ans+=x[i]*kabu;
            kabu=0;
        }
        else{
            ll F=ans/x[i];
            kabu+=F;
            ans-=F*x[i];
        }
        //cout<<x[i]<<':'<<ans<<' '<<kabu<<endl;
    }
    cout<<ans+kabu*x[K-1]<<endl;

}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[15], x[15][15], y[15][15];
bool bl[15];
int ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 0; j < a[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		int cnt = 0;
		bool d = true;
		for (int j = 0; j < n; j++) {
			if (i&(1 << j)) {
				bl[j] = true;
				cnt++;
			}
			else bl[j] = false;
		}
		for (int j = 0; j < n; j++) {
			if (!bl[j])continue;
			for (int k = 0; k < a[j]; k++) {
				if ((y[j][k] && (!bl[x[j][k] - 1])) || (!y[j][k] && bl[x[j][k] - 1])) {
					d = false;
				}
			}
		}
		if (d)ans = max(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}



int main(){
    lint n,d,cnt=0;
    cin>>n>>d;
    repi(i,1,n+1)repi(j,1,d+1){

        if((j/10)>1&&(j%10)>1&&i==(j/10)*(j%10))cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 256
ans = 0

def mizuyari( l ):
    if len( l ) == 0: return # return のみで関数から抜ける
    
    minimum = min( l )
    min_i = l.index( minimum )
    l = list( map(lambda x: x - minimum, l) )
    global ans  # global宣言すると、関数外で宣言した値に代入できる
    ans += minimum
    
    mizuyari( l[:min_i] )
    mizuyari( l[min_i+1:] )


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

mizuyari( h )
print( ans )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 10000000;

int N;
vector<vector<int> > edge;
int K;
vector<int> P;

vector<int> low, high;

bool flg;

vector<int> ans;

void calclh(int now, int prev)
{
    int min_tmp = -inf, max_tmp = inf;
    
    if (P[now] >= 0) min_tmp = max_tmp = P[now];

    for (auto v : edge[now])
    {
        if (v == prev) continue;
        calclh(v, now);
        if (max_tmp < inf && high[v] < inf && (abs(high[v] - max_tmp) % 2 == 0))
        {
            flg = true;
        }
        max_tmp = min(max_tmp, high[v]+1);
        min_tmp = max(min_tmp, low[v]-1);
        if (max_tmp < min_tmp) flg = true;
    }
    low[now] = min_tmp;
    high[now] = max_tmp;
}

void calcans(int now, int prev)
{
    if (prev < 0) ans[now] = low[now];
    else
    {
        ans[now] = ans[prev] - 1;
        if (ans[now] < low[now]) ans[now] += 2;
    }
    for (auto v : edge[now])
    {
        if (v == prev) continue;
        calcans(v, now);
    }
}

int main()
{
    cin >> N;
    edge = vector<vector<int> >(N, vector<int>());
    for (int i=0; i<N-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    cin >> K;
    P = vector<int>(N, -inf);

    int vi, pi;
    for (int i=0; i<K; i++)
    {
        cin >> vi >> pi;
        vi--;
        P[vi] = pi;
    }

    flg = false;
    low = high = vector<int>(N, -inf);
    calclh(vi, -1);
    if (flg)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
        ans.resize(N);
        calcans(vi, -1);
        for (auto v : ans) cout << v << endl;
    }
}


Measured memory_bytes: 15744
#include <stdio.h>

int main(void)
{
	int a[1000000];
	int n;
	int count;
	int i, j;

	while (scanf("%d", &n) != EOF){
		for (i = 2; i <= n; i++){
			a[i] = 1;
		}
		count = 0;

	for (i = 2; i <= n; i++){
		if (1 == a[i]){
			for (j = i * 2; j <= n; j += i){
				a[j] = 0;
			}
		}
	}

	for (i = 2; i <= n; i++){
		if (a[i] == 1){
			count++;
		}
	}

	printf("%d\n", count);
	}
	return (0);
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  int ans=1;
  while(ans<=n){ ans*=2; }
  ans/=2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>

using namespace std;
#define ll long long
// <最短距離, 頂点の番号>
typedef pair<ll, ll> P;
const int INF = 1e9;
const int MAX_N = 3*1000000; 

struct edge{
    int to;
    int cost;
};
// ノード数
int V;
// ある頂点から出るエッジを保持
vector<edge> G[MAX_N];
// コストを保持
int d[MAX_N];

void dijkstra(int s) {
    // cout << V;
    // Pのコスト昇順の優先度付きキュー
    priority_queue <P, vector<P>, greater<P> > que;
    // INFで初期化
    fill(d, d + V + 10, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i = 0; i < G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int E,S,T,V_r;
    cin >> V >> E;
    V_r = V;
    V = 3*V;
    // cout << V_r << endl;
    for (int i = 0; i < E; ++i) {
        int a, b;
        int c = 1;
        cin >> a >> b;
        edge e1 = {b + V_r, c};
        edge e2 = {b + 2*V_r, c};
        edge e3 = {b, c};
        G[a].push_back(e1);
        G[a + V_r].push_back(e2);
        G[a + 2*V_r].push_back(e3);
    }
    cin >> S >> T;
    dijkstra(S);
    for (int i = 1; i <= V; ++i) {
        // cout << "始点：" << i << endl;
        // for(int j = 0; j < G[i].size(); j++){
        //     cout << "行き先：" << G[i][j].to << endl;
        // }
        // cout << S <<"から" << i << "までのコスト: " << d[i] << endl;
    }
    if(d[T] != INF) cout << d[T]/3 << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 81912
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=100010;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}

int main(){
	int r, b, g, n;
//	long long int  a[N];
//	int b[N]=0;
	cin>>r>>b>>g>>n;
	int ans, jouyo;
	ans=0;
	rep(i, n/r+1){
		rep(j, n/b+1){
			jouyo=(n-r*i-b*j);
			if(jouyo>=0&&jouyo%g==0){
				ans++;
			}
		}
	}
	cout<<ans<<endl;









//	qsort(b, 5, sizeof(long long int), compare_int);
/*	rep(i, 5){
		if((b[i]-1)%10<k){
			k=b[i]%10;
		}
		ans=ans+(b[i]+9)/10;
	}
	anss=ans*10+k-10;
	if(k==0){
		anss=anss+10;
	}
	cout<<anss<<endl;




/*	qsort(b, 5, sizeof(int), compare_int);
	if(b[4]-b[0]>k){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
		rep(i, n){
		ans=c;
		rep(j, m){
			cin>>imp;
			ans=ans+imp*b[j];
		}
		if(ans>0){
			anss++;
		}
	}
	cout<<anss<<endl;
}*/
}


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

using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int t1 = 10 * a + b + c;
  int t2 = 10 * b + a + c;
  int t3 = 10 * c + a + b;
  cout << max(t1, max(t2, t3)) << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define repf(i,s,e)  for(int i=s;i<e;i++)
#define repb(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve(){
	int n;
	cin>>n;

	vector<int> arr(n);
	vector<int> boss(n+1,0);
	repf(i,1,n){
		cin>>arr[i];
		boss[arr[i]]++;
	}

	repf(i,1,n+1){
		cout<<boss[i]<<endl;
	}

}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	if(fopen("input.txt", "r")){
	    freopen("input.txt", "r", stdin),
	    freopen("output.txt", "w", stdout);
	}
	
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 6352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String X = sc.next();
		String Y = sc.next();
		sc.close();
		if(X.charAt(0) > Y.charAt(0)) {
			System.out.println(">");
		}else if(X.charAt(0) == Y.charAt(0)) {
			System.out.println("=");
		}else {
			System.out.println("<");
		}
	}
}

Measured memory_bytes: 23252
//*-- ILSH --*//
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
const ll inf=1e18+1e17;
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll arr[1000+5][1000+5];
void solve(){
	int n,m;
	cin>>n>>m;
	memset( arr,0,sizeof ( arr));
	arr[0][1]=1;
	for ( int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		for (int j=1;j<=m;j++)
			if ( s[j-1]=='#')
				arr[i][j]=0;
			else
				arr[i][j]=(arr[i-1][j]+arr[i][j-1])%mod;
	}
	cout<<arr[n][m]%mod<<'\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while ( t-- )
    	solve();    
}

Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;
int A[100002];
int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;++i){
    cin >> A[i+1];
  }
  int dist = 0;
  for(int i=0;i<N+1;++i){
    dist += abs(A[i+1] - A[i]);
  }
  
  for(int i=1;i<N+1;++i){
    if(( A[i-1] <= A[i] && A[i] <= A[i+1] )||( A[i-1] >= A[i] && A[i] >= A[i+1] )){
      cout << dist << endl;
    }else{
      cout << dist - min(abs(A[i+1]-A[i]),abs(A[i]-A[i-1]))*2 << endl;
    }
  }
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i += 1)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX_N 100000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    ll N,K,R,S,P;
    cin >> N >> K >> R >> S >> P;
    string t;
    cin >> t;
    vector<vector<ll>> point(3,vector<ll>(3,0));
    point[0][1] = R;
    point[1][2] = S;
    point[2][0] = P;
    /*Rep(i,3){
        Rep(j,3){
            cout << point[i][j];
        }
        cout << endl;
    }*/
    //ll dp[K][(N+K-1)/K + 1][3]; //dp[i][j][k] i*K+j kth
    vector<vector<vector<ll>>> dp(K,vector<vector<ll>>((N+K-1)/K + 1,vector<ll>(3,0)));
    Rep(i,K){
        Rep(j,(N+K-1)/K){
            Rep(k,3){
                if(j*K + i >= N)break;
                int e;
                if(t[j*K+i] == 'r')e = 0;
                if(t[j*K+i] == 's')e = 1;
                if(t[j*K+i] == 'p')e = 2;
                dp[i][j+1][k] = max(dp[i][j][(k+1)%3],dp[i][j][(k+2)%3]);
                dp[i][j+1][k] += point[k][e];
                //cout << i << sp << j << sp << k << sp << dp[i][j+1][k] << endl; 
            }
        }
    }
    ll ans = 0;
    Rep(i,K){
        int j = (N+K-1)/K;
        
        if((j-1)*K + i >= N){
            j--;
        }
        ll p = 0;
        Rep(k,3)p = max(p,dp[i][j][k]);
        ans += p;
    }
    cout << ans << endl;
    //cin >> N;
}

Measured memory_bytes: 17536
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100010;
int t,l[15],r[15],a[10];
bool dfs(int i,int x,int y){
	if(i==11)return true;
	if(a[i]>l[x]){
		l[x+1]=a[i];
		if(dfs(i+1,x+1,y))return true;
		else return false;
	}
	if(a[i]>r[y]){
		r[y+1]=a[i];
		if(dfs(i+1,x,y+1))return true;
		else return false;
	}
	return false;
}
int main()
{
	cin>>t;
	while(t--){
		memset(l,0,sizeof(l));
		memset(r,0,sizeof(r));
		for(int i=1;i<=10;i++)cin>>a[i];
		if(dfs(1,0,0))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<cstring>
int main(){
    char str1[101],str2[101],str3[201];
    scanf("%s %s",str1,str2);
    strcpy(str3,str1);
    strcat(str3,str1);
    if(strstr(str3,str2)==NULL) printf("No\n");
    else printf("Yes\n");
}


Measured memory_bytes: 3152
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c;
  std::cin >> a>>b>>c;
  if(a+b+c>=22)std::cout << "bust" << '\n';
  else std::cout << "win" << '\n';

  return 0;
}


Measured memory_bytes: 888
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C, D = input()

    for a in ["+", "-"]:
        for b in ["+", "-"]:
            for c in ["+", "-"]:
                if eval(A + a + B + b + C + c + D) == 7:
                    print(A + a + B + b + C + c + D + "=7")
                    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
PX = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)
  
cost = [0] * (N + 1)
for p, x in PX:
  cost[p] += x
  
check = [0] * (N + 1)
stack = [1]
check[1] = 1

while stack:
  s = stack.pop()
  for g in graph[s]:
    if check[g] == 0:
      check[g] = 1
      cost[g] += cost[s]
      stack.append(g)
      
print(*cost[1:])

Measured memory_bytes: 130216
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))

z = float('inf')
zi = -1
for i, hi in enumerate(h):
    ti = t - hi*0.006
    if abs(a-ti) < z:
        z = abs(a-ti)
        zi = i+1
print(zi)

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

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

	cin >> a >> b >> c >> d;
	ans = a + b - c - d;

	if( ans > 0 ) {
		cout << "Left" << endl;
	}
	else if( ans < 0 ) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int n;
	int a,b;
	int i;
	int now;
	int buff;
	int result = 0;

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

	for(i=1;i<=n;i++){
		buff = i;
		now = buff %10;
			buff /= 10;
		while(buff != 0){
			now += buff % 10;
			buff /= 10;
		}
		if(now >= a){
			if(now <= b){
				result += i;
			}
		}
	}

	printf("%d\n",result);

	getchar();
	getchar();
	getchar();
	getchar();

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

ll f(ll x) {
  ll y = 1;
  for (ll i = 1; i <= x; i++) {
    y *= i;
    y %= MOD;
  }
  return y;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  ll N,K; cin >> N >> K;
  vector<ll> ans(K+1);
  for (int i = 1; i <= K; i++) {
    if (N-K-i+1 >= 0) {
      ll child = f(K-1) * f(N-K+1);
      child %= MOD;
      ll mom = f(K-i) * f(i-1);
      mom %= MOD;
      mom *= f(N-K-i+1);
      mom %= MOD;
      mom *= f(i);
      mom %= MOD;
      mom = modinv(mom,MOD);
      ans[i] = child * mom;
      ans[i] %= MOD;
    } else ans[i] = 0;
  }
  
  for (int i = 1; i <= K; i++) cout << ans[i] << endl; 
}

Measured memory_bytes: 256
//ドワンゴからの挑戦状5-予選C
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;

ll n,q,k;
string s;

int main(){
    cin>>n>>s>>q;

    while(q--){
        cin>>k;
        ll d=0,m=0,dm=0,ans=0;
        rep(i,n){
            if(s[i]=='D')d++;
            if(s[i]=='M')m++,dm+=d;
            if(s[i]=='C')ans+=dm;
            if(i>=k-1&&s[i-k+1]=='D')d--,dm-=m;
            if(i>=k-1&&s[i-k+1]=='M')m--;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
const int MAX_N=300000;
bool isPrime[MAX_N];
void eratos(){
  for(int i=0;i<MAX_N;i++)isPrime[i]=true;
  isPrime[0]=isPrime[1]=false;
  for(int i=0;i<MAX_N;i++){
    if(isPrime[i]){
      for(int j=i+i;j<MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
}
int main()
{
  eratos();
  while(true)
  {
    int n;
    cin>>n;
    if(n==0)
    {
      break;
    }
    int count=0;
    int s=n+1;
    int e=2*n;
    for(int i=s;i<=e;i++)
    {
      if(isPrime[i])
      {
        count++;
      }
    }
    cout<<count<<endl;
  }
  return 0;
}



Measured memory_bytes: 3376
def acinput():
    return list(map(int, input().split(" ")))


N=int(input())

a=acinput()

cnt=0
now=1
for i in range(N):
   # print(i)
    if now==a[i]:
        #print(now,a[i])
        now+=1
        

if now==1:
    print(-1)
else:
    print(N-now+1)


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

int main() {
    int n,a,b,ans;
    cin>>n>>a>>b;
    ans=min(n*a,b);
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int n, a;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    cin >> a;
    if (i % 2 == 1) continue;
    if (a % 2 == 1) ans++;
  }
  COUT(ans);

  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin>>c;
    c++;
    cout<<c<<endl;
  

    return 0;   
}


 
 


Measured memory_bytes: 256
n = input()
summ = 0
lst = list(map(int, input().split()))
for i in range(len(lst) - 1):
    if lst[i] > lst[i + 1]:
        k = lst[i] - lst[i + 1]
        lst[i + 1] = lst[i + 1] + k
        summ += k
print(summ)

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

int intcmp(const void *a,const void *b)
{
  return *(int*)a - *(int*)b;
}

int main(void)
{
  while (1){
    int nitems,money_limit,price,max_sum,*items;
    scanf("%d %d",&nitems,&money_limit);
    if (nitems == 0 && money_limit == 0){
      return 0;
    }
    items = (int*)malloc(sizeof(int) * nitems);

    for (int i=0;i < nitems;i++){
      scanf("%d",&price);
      items[i] = price;
    }

    qsort(items,nitems,sizeof(int),intcmp);
  
    if (items[0]+items[1] > money_limit){
      
      printf("%s\n","NONE");
      continue;
    }
    int idx=0,max_below_limit=0;
    for (int j=nitems - 1;j > 0;--j){
      for (int k=j - 1;k >= 0;--k){
        max_sum = items[j] + items[k];
        if (max_sum <= money_limit && max_below_limit < max_sum){
          max_below_limit = max_sum;
          idx++;
        }
      }
    }
    printf("%d\n",max_below_limit);
  }
}



Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long const mod = 1000000007;

long long mod_pow(long long a, long long b){
    long long res = 1;
    a %= mod;
    while(b > 0){
        if(b%2 == 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return res;
}

long long mod_inv(long long a){
    return mod_pow(a, mod-2);
}
int n;
vector<int> a;

vector<long long> cnt((1<<20), 0);

int main(void){
    int n;
    cin >> n;
    a.assign(n, 0);
    for(int i=0;i<n;i++) cin >> a[i];

    for(int i=0;i<n;i++){
        int v = a[i];
        for(int j=2;j*j<=v;j++){
            int u = 0;
            while(v%j == 0){
                v /= j;
                u++;
            }
            if(cnt[j] < u) cnt[j] = u;
        }
        if(cnt[v] < 1) cnt[v] = 1;
    }

    long long m = 1;
    for(int i=2;i<(1<<20);i++){
        m *= mod_pow(i, cnt[i]);
        m %= mod;
    }

    long long ans = 0;
    for(int i=0;i<n;i++){
        ans += m * mod_inv(a[i]) % mod;
        ans %= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 8448
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n,m;
	cin>>n>>m;
	ll ans=0;
	ll low=1,high=n;
	for(ll i=0;i<m;i++)
	{
		ll l,r;
		cin>>l>>r;
		if(l>low)
		low=l;
		if(high>r)
		high=r;
	}
	cout<<max((ll)0,(high-low+1));
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, A[2001];
	long long K;
	scanf("%d %lld", &N, &K);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	
	int j;
	long long inv = 0;
	for (i = 0; i < N; i++) {
		for (j = 0; j < i; j++) if (A[j] < A[i]) inv = (inv + (K - 1) * K / 2) % 1000000007;
		for (j = i + 1; j < N; j++) if (A[j] < A[i]) inv = (inv + (K + 1) * K / 2) % 1000000007;
	}
	
	printf("%lld\n", inv);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128