akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

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

    int alpha[26] = {};

    if(s.size() != 26)
    {
        REP(i,s.size())
        {
            ++alpha[s[i] - 'a'];
        }

        REP(i,26)
        {
            if(alpha[i] == 0)
            {
                char c = 'a' + i;
                cout << s + c << endl;
                return 0;
            }
        }
    }
    else
    {
        //26文字
        for(int i = s.size() - 1; i >= 0; --i)
        {
            int num = s[i] - 'a';
            ++alpha[num];
            REP(j,26)
            {
                if(alpha[j] != 0 && j > num)
                {
                    string t = s.substr(0, i);
                    char c = 'a' + j;
                    t += c;
                    cout << t << endl;
                    return 0;
                }
            }
        }
    }
    

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
(function(stdin) {
'use strict';

  var inputs = stdin.toString().trim();
  var re = /\w+\n[\w\s]*?\n/g;
  var lines = inputs.match(re).map(function(line) {
    return line.split('\n')[1]
      .split(' ')
      .slice(0, line.split('\n')[0])
      .map(Number);
  });
  var result = (function(lines) {

    return lines.map(stdev);

    function stdev(scores) {
      var avg = average(scores);
      return Math.sqrt(average(scores.map(function(score) {
        return Math.pow(score - avg, 2);
      })));
    }

    function average(scores) {
      return sum(scores) / scores.length;
    }
    function sum(scores) {
      return scores.reduce(add);
    }
    function add(a, b) {
      return a + b;
    }
  })(lines);

  console.log(result.join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 16996
n=int(input())
x=list(map(int,input().split()))
x0=[xi for xi in x]
x0.sort()
m0=x0[n//2-1]
m1=x0[n//2]
for i in range(n):
  if x[i]<=m0:
    print(m1)
  else:
    print(m0)


Measured memory_bytes: 25556
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
char s[100001];
int main(){
	ull i,j,h,w;
	cin>>h>>w;
	for(i=0;i<w+2;i++) cout<<"#";
	cout<<endl;
	for(i=0;i<h;i++){
		cin>>s;
		cout<<"#"<<s<<"#"<<endl;
    }
	for(i=0;i<w+2;i++) cout<<"#";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const ll mod=1e9+7;
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{

  int n;
  cin>>n;
  vector<pair<int,int> >v;
  for(int i=0;i<n;i++)
  {
      int a,b;
      cin>>a>>b;
      v.pb(mp(b,a));
  }
  int f=1;
  ll sum=0;
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++)
  {
      sum+=v[i].ss;
      if(sum>v[i].ff)
      {
          f=0;
          break;
      }
  }
  if(f)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;






}






















































Measured memory_bytes: 5372
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n=sc.nextInt();
int X=sc.nextInt();
int[] x=new int[n+1];
int[] y=new int[n];
x[0]=X;
for (int i = 0; i < n; i++) {
    x[i+1]=sc.nextInt();
}
for (int i = 0; i < n; i++) {
    y[i]=abs(x[i+1]-x[i]);
}
int ans=y[0];
for (int i = 0; i < n; i++) {
    ans=gcd(ans,y[i]);
}
out.println(ans);
}
static int gcd (int a, int b) {
	int temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}
}

Measured memory_bytes: 49628
#include <stdio.h>
#include <string.h>
int main(void){
    char o[51];
    char e[51];
    scanf("%s %s",o,e);
    int i,leno;
    leno=strlen(o);
    int lene;
    lene=strlen(e);
    if(leno-lene==0){
    for(i=0;i<2*leno;i++){
        if(i%2==0)printf("%c",o[i/2]);
        else printf("%c",e[i/2]);
    }
    }
    else if(leno-lene==1){
        for(i=0;i<2*leno-1;i++){
            if(i%2==0)printf("%c",o[i/2]);
            else printf("%c",e[i/2]);
    }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const ll oo = 1e15 + 7;
const int mod = 1e9 + 7, maxn = (2 * 1e3) + 10;
const long double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;

    cin >> n >> m;

    vector<ll> a(m), b(m), c(m), dist(n, oo);
    bitset<maxn> neg(0);

    for (int i=0; i<m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        c[i]*=-1;
    }

    dist[0] = 0;

    for (int loop=0; loop<n-1; loop++){
        for (int i=0; i<m; i++){
            if (dist[a[i]] == oo) continue;
            
            if (dist[b[i]] > dist[a[i]] + c[i]){
                dist[b[i]] = dist[a[i]] + c[i];
            }
        }
    }

    ll ans = dist[n-1];

    for (int loop = 0; loop < n-1; loop++){
        for (int i=0; i<m; i++){
            if (dist[a[i]] == oo) continue;
            if (dist[b[i]] > dist[a[i]] + c[i]){
                neg[b[i]] = 1;
                dist[b[i]] = dist[a[i]] + c[i];
            }
            if (neg[a[i]]) neg[b[i]] = 1;
        }
    }

    if (neg[n-1]) cout << "inf" << endl;
    else cout << -ans << endl;
    return 0;
}

Measured memory_bytes: 3648
from collections import defaultdict
import sys

def soinsuu(soinsuu_dic, num):
    for i in range(2, int(num ** 0.5) + 1):
        while num % i == 0:
            num //= i
            soinsuu_dic[i] += 1
    if num > 1:
        soinsuu_dic[num] += 1
    return soinsuu_dic

def main():
    num = int(input())
    soinsuu_dic = defaultdict(int)

    for i in range(2, num + 1):
        soinsuu_dic = soinsuu(soinsuu_dic, i)


    ans = 1
    mod = 10 ** 9 + 7
    for ele, value in soinsuu_dic.items():
        ans *= value + 1
        ans %= mod

    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

void solve(){
	int n;
	cin >> n;
	int ac = 0, tle = 0, re = 0,wa = 0;
	while(n--){
		string s;
		cin >> s;
		if(s == "AC") ++ac;
		if(s == "WA") ++wa;
		if(s == "TLE") ++tle;
		if(s == "RE") ++re;
	}
	cout << "AC" << " x " << ac << newl;
	cout << "WA" << " x " << wa << newl;
	cout << "TLE" << " x " << tle << newl;
	cout << "RE" << " x " << re << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

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

  sort(l,l+n);
  reverse(l,l+n);
  int sum = 0;
  for(int i=0;i<k;i++) sum += l[i];

  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a >> b >> c;
		if (a < b && b<c){
			cout << a <<" "<<b<<" "<<c<< endl;
	}
		else if (a < b&&c < b){
			cout << a << " " << c << " " << b << endl;
		}
		else if (b<c&&c<a){
			cout << b << " " << c << " " << a << endl;
	}
		else if (b < c&&a < c){
			cout << b << " " << a << " " << c << endl;
		}
		else if (c < a&&a < b){
			cout << c << " " << a << " " << b << endl;
	}
		else if (c < a&&b<a){
			cout << c << " " << b << " " << a << endl;
		}
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#define pie 3.141592653589793238
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s;
  cin >> t;
  
  if(s.length()>10 || s.length()<1){
    cout << "No" << endl;
    return 0;
  }
  
  if(t.length()!=s.length()+1){
    cout << "No" << endl;
    return 0;
  }
  
  if(t[t.length()-1]>='a' || t[t.length()-1]<='z'){
    for(int i=0; i<s.length(); i++){
    	if(t[i]!=s[i]){
          cout << "No" << endl;
    	  return 0;
        }
        if(t[i]<'a' || t[i]>'z'){
          cout << "No" << endl;
    	  return 0;
        }
    }
  }
  else{
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<string.h>
int aa[20];
main()
{
	int a,b,c;
	
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		memset(aa,0,sizeof(aa));
		aa[a]++;
		aa[b]++;
		aa[c]++;
		if(aa[5]==2&&aa[7]==1)
		{
			printf("YES\n");
		}
		else
		printf("NO\n");
	}
	
} ///

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    cin >>n;
    int a=0,b=0;
    string x,y;
    vector<vector<int>>dp(1010,vector<int>(1010,0));
    rep(_,n){
        rep(i,a+1){
            rep(j,b+1){
                dp[i][j]=0;
            }

        }
        cin>>x>>y;
        a=x.size();
        b=y.size();
       
        rep(i,a){
            rep(j,b){
                
                    chmax(dp[i+1][j+1],dp[i][j+1]);
                
                if(j!=0){
                    chmax(dp[i+1][j+1],dp[i+1][j]);
                }
                if(x[i]==y[j]){
                    chmax(dp[i+1][j+1],dp[i][j]+1);
                }
            }
        }
        cout<<dp[a][b]<<endl;
    }
    
}


Measured memory_bytes: 6784
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n, k = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
for i in range(k):
    ans += P[i]
print(ans)

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

using namespace std;

int main(void) {
    long n;
    vector<char> ans;
    cin >> n;
    long quo = 26;
    int rem;
    int count = 0;
    while(quo > 0){
        count += 1;
        quo = n / 26;
        rem = n % 26;
        
        if(rem == 0){
            ans.push_back(122);
            quo -= 1;
        }
        else{
            ans.push_back(rem + 96);
        }
        n = quo;
        // cout << "quo = " << quo << " rem = " << rem << endl;
    }
    // ans.push_back(quo + 96);
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < count; i++){
        cout << ans.at(i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3628
main(){
    int i,n,k,a,b,A,B,dist[101][101];
    scanf("%d%d",&n,&k);
        /*initialize*/
        memset(dist,11,sizeof(dist));
        for(i=1;i<=n;i++)dist[i][i]=0;
        for(;k>0;k--){
            scanf("%d,%d,%d,%d",&a,&b,&A,&B);
            dist[a][b]=A,dist[b][a]=B;
        }
  
        {/*warshall-floyd*/
            int k,i,j;
            for(k=1;k<=n;k++)
                for(i=1;i<=n;i++)
                    for(j=1;j<=n;j++)
                        if(dist[i][j]>dist[i][k]+dist[k][j])
                            dist[i][j]=dist[i][k]+dist[k][j];
        }
  
        {/*query*/
            scanf("%d,%d,%d,%d",&a,&b,&A,&B);
            printf("%d\n",A-B-dist[a][b]-dist[b][a]);
        }
    exit(0);
}

Measured memory_bytes: 644
#include <iostream>
#include <unordered_set>

using namespace std;

const int MAX = 200000;

int main() {

    int N, M;
    scanf("%d %d", &N, &M);

    unordered_set<int> G[MAX + 1];

    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].insert(b);
        G[b].insert(a);
    }

    bool ans = false;

    for (int i:G[1]) {
        if (G[N].find(i) != G[N].end()) {
            ans = true;
        }
    }

    printf("%s\n", ans ? "POSSIBLE" : "IMPOSSIBLE");
}

Measured memory_bytes: 28480
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	ll n,a,b; cin >> n >> a >> b;
	ll c = a+b;
	ll ans = (n/c)*a + min(a,n%c);
	cout << ans << endl;
}




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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const llint INF = 1e9;
const llint llINF = 1e18;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int t[100000],x[100000],y[100000];
int main(){
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>t[i]>>x[i]>>y[i];
	int pret=0,prex=0,prey=0;
	for(int i=0;i<n;i++){
		if(
		!(
		t[i]-pret >= abs(x[i]-prex)+abs(y[i]-prey) && 
		(abs(x[i]-prex)+abs(y[i]-prey))%2==((t[i]-pret)%2)
		)
		){
			cout << "No" << endl;
			return 0;
		}
		pret=t[i];
		prex=x[i];
		prey=y[i];
	}
	cout << "Yes" << endl;
}


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

int main() {
    int n;
    int k,score;
    cin >> n >> k;
    double ans=0;
    for(int i=1;i<=n;i++){
        score = i;
        double temp=(double)1/(double)n;
        while(true){
            if(score>=k){
                ans += temp;
                break;
            }else{
                temp *= 0.5;
                //cout << temp << endl;
                score *= 2;
            }
        }
    }
    printf("%.12f\n", ans);
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    vec a(N), b(N);
    rep(i,N) cin>>a[i];
    rep(i,N) cin>>b[i];
    mat bstd(29,vec(N));
    rep(i,29){
        rep(j,N) bstd[i][j] = b[j] % (1LL << (i+1));
        sort(bstd[i].begin(), bstd[i].end());
    }
    vec ans(29,0);
    rep(i,29){
        M = 1LL << i;
        rep(j,N){
            A = a[j] % (1LL << (i+1));
            ll temp = (lower_bound(bstd[i].begin(), bstd[i].end(), M*2 - A)- lower_bound(bstd[i].begin(), bstd[i].end(), M - A));
            ans[i] += temp;
            temp = (lower_bound(bstd[i].begin(), bstd[i].end(), M*4 - A)- lower_bound(bstd[i].begin(), bstd[i].end(), M*3 - A));
            ans[i] += temp;
        }
    }
    ll out = 0;
    rep(i,29) if((ans[i]&1) == 1) out += (1LL << i);
    cout<<out<<endl;
}

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

using namespace std;

int a, b, d[11][11], ta, tb, tc;
pair< pair< int, int >, int > p[11][11];
vector< pair< pair< int, int >, int > > v;
bool u[101][101];

int main() {
	scanf("%d%d", &a, &b);
	for (int i = 1; i <= a; i++)
		for (int j = 1; j <= b; j++)
			scanf("%d", d[i] + j), p[i][j].second = -1;
	for (int i = 0; i <= 100; i++)
		for (int j = 0; j <= 100; j++) {
			ta = INT_MIN;
			for (int ii = 1; ii <= a; ii++)
				for (int jj = 1; jj <= b; jj++)
					ta = max(ta, d[ii][jj] - ii * i - jj * j);
			if (ta >= 0 && ta <= 100)
				for (int ii = 1; ii <= a; ii++)
					for (int jj = 1; jj <= b; jj++)
						if (ta == d[ii][jj] - ii * i - jj * j)
							p[ii][jj] = make_pair(make_pair(i, j), ta);
		}
	for (int i = 1; i <= a; i++)
		for (int j = 1; j <= b; j++)
			if (p[i][j].second == -1) {
				printf("Impossible\n");
				return 0;
			}
	for (int i = 1; i <= 100; i++)
		v.push_back(make_pair(make_pair(i, i + 1), -1));
	for (int i = 1; i <= 100; i++)
		v.push_back(make_pair(make_pair(101 + i, 101 + i + 1), -2));
	for (int i = 1; i <= a; i++)
		for (int j = 1; j <= b; j++) {
			ta = p[i][j].first.first;
			tb = p[i][j].first.second;
			tc = p[i][j].second;
			if (!u[ta][tb]) {
				u[ta][tb] = 1;
				v.push_back(make_pair(make_pair(ta + 1, 101 + 100 + 1 - tb), tc));
			}
		}
	printf("Possible\n%d %d\n", 101 + 100 + 1, v.size());
	for (int i = 0; i < v.size(); i++) {
		printf("%d %d ", v[i].first.first, v[i].first.second);
		if (v[i].second == -1)
			printf("X\n");
		else if (v[i].second == -2)
			printf("Y\n");
		else
			printf("%d\n", v[i].second);
	}
	printf("%d %d\n", 1, 101 + 100 + 1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    map<string, int> cnt;
    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl;
    cout << "TLE x " << cnt["TLE"] << endl;
    cout << "RE x " << cnt["RE"] << endl;

    fflush(stdout);
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);
    if (n < sum) {
        cout << -1 << endl;
    } else {
        cout << n - sum << endl;
    }
    return 0;
}


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

int main() {
    int n, y;
    cin >> n >> y;
    y /= 1000;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            int k = n - i - j;
            if (k < 0) break;
            if (10 * i + 5 * j + k == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
number_hp = list(map(int, input().split()))
a_b = []

for i in range(number_hp[0]):
    a_b.append(list(map(int, input().split())))
attack_damage_list = []
throw_damage_list = []
for i in range(number_hp[0]):
    attack_damage_list.append(a_b[i][0])
for i in range(number_hp[0]):
    throw_damage_list.append(a_b[i][1])
attack = max(attack_damage_list)
throw_damage_list = [i for i in throw_damage_list if i >= attack]
throw_damage_list.sort(reverse=True)
damage = 0
number = 0
for i in range(len(throw_damage_list)):
    damage = damage + throw_damage_list[i]
    number = number + 1
    if damage >= number_hp[1]:
        break
if damage >= number_hp[1]:
    pass
else:
    attack_number = int((number_hp[1] - damage) // attack)
    number = number + attack_number
    if int((number_hp[1] - damage) % attack) != 0:
        number = number + 1
print(number)

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

int main() {
  int N;
  cin >> N;
  int ans = 1;
  while (true) {
    ans = ans * 2;
    if (ans <= N) {
      continue;
    }
    else {
      break;
    }
  }
  cout << ans /2 << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    const int mod = 1e9 + 7;
    int n;
    cin >> n;
    ll a;
    ll res = 1;
    ll d[3] = {};
    for (int i = 0; i < n; ++i) {
        cin >> a;
        int tmp = 0;
        for (int j = 0; j < 3; ++j) {
            if(d[j] == a) tmp++;
        }
        if(!tmp){
            cout << 0 << endl;
            return 0;
        }
        res *= tmp;
        res %= mod;
        for (int j = 0; j < 3; ++j) {
            if(d[j] == a){
                d[j]++;
                break;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
    long long int N, K, a, f, start = 1, n = 0;
    vector<long long int> A;
  
    map<long long int, long long int> mp;
  
    cin >> N >> K;
    n = K;
  
    for (int i = 0; i < N; i++) {
        cin >> a;
        A.push_back(a);
    }
  
    int next = A[0];
    int prev = 1;
    for (long long int i = 1; i <= K; i++) {
        if (next != 1 && mp[next] == 0) {
            mp[next] = i;
            prev = next;
        } else {
            f = i - mp[next];
            n = (K - mp[next]) % f;
            if (n == 0) {
                start = next;
            } else {
                start = next;
            }
            break;
        }
        next = A[next-1];
    }
    for (int i = 0; i < n; i++) {
        start = A[start-1];
    }
    cout << start << endl;
    return 0;
}

Measured memory_bytes: 14784
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i = x;i < y;i++)
using namespace std;

bool block[110][110];

int check(int x,int y,int D,int N,int M){
  int ans = 0;
  if(x+D<=N){
    bool flag = 1;
    FOR(i,0,D)if(block[x+i][y])flag=0;
    if(flag)ans++;
  }
  if(y+D<=M){
    bool flag = 1;
    FOR(i,0,D)if(block[x][y+i])flag=0;
    if(flag)ans++;
  }
  return ans;
}

int main(){
  int N,M,D,ans=0;
  char c;
  cin >> N >> M >> D;
  FOR(i,0,N)FOR(j,0,M){
    cin >> c;
    if(c=='#')block[i][j]=1;
  }
  FOR(i,0,N)FOR(j,0,M)ans+=check(i,j,D,N,M);
  cout << ans << endl;
}



Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var P = ReadArrayInt();
            var Q = ReadArrayInt();

            var PN = Factorial(N);
            var QN = Factorial(N);

            var Pst = new List<int>();
            for (int i = 1; i <= N; i++) Pst.Add(i);
            Pst.Reverse();
            var Qst = new List<int>(Pst);
            var Pm = 0L;
            var Qm = 0L;

            for (int i = 0; i < N - 1; i++)
            {
                var chk = P[i];
                var idx = 0;
                for (int j = 0; j < Pst.Count(); j++)
                {
                    if (Pst[j] == chk)
                    {
                        idx = j;
                        break;
                    }
                }
                PN /= Pst.Count();
                Pm += PN * (idx + 1);
                Pst.RemoveAt(idx);
            }
            for (int i = 0; i < N - 1; i++)
            {
                var chk = Q[i];
                var idx = 0;
                for (int j = 0; j < Qst.Count(); j++)
                {
                    if (Qst[j] == chk)
                    {
                        idx = j;
                        break;
                    }
                }
                QN /= Qst.Count();
                Qm += QN * (idx + 1);
                Qst.RemoveAt(idx);
            }

            Console.WriteLine(Math.Abs(Pm - Qm));
            Console.ReadKey();
        }

        static long Factorial(long num) { if (num == 0) return 1L; return num * Factorial(num - 1); }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

const MOD: i64 = 1_000_000_007;

fn main() {
    let l: Vec<char> = read::<String>().chars().collect();
    let mut keta_dp: Vec<Vec<i64>> = vec![vec![0; 2]; l.len() + 1];
    keta_dp[0][0] = 1;
    for i in 0..l.len() {
        if l[i] == '0' {
            keta_dp[i + 1][0] = keta_dp[i][0];
            keta_dp[i + 1][1] = keta_dp[i][1];
        } else {
            keta_dp[i + 1][1] = (keta_dp[i][0] + keta_dp[i][1]);
            keta_dp[i + 1][1] %= MOD;
        }

        if l[i] == '0' {
            keta_dp[i + 1][1] += (keta_dp[i][1] * 2 % MOD);
            keta_dp[i + 1][1] %= MOD;
        } else {
            keta_dp[i + 1][0] += keta_dp[i][0] * 2 % MOD;
            keta_dp[i + 1][0] %= MOD;
            keta_dp[i + 1][1] += (keta_dp[i][1] * 2 % MOD);
            keta_dp[i + 1][1] %= MOD;
        }
        // println!("{:?}", keta_dp);
    }
    println!("{}", (keta_dp[l.len()][0] + keta_dp[l.len()][1]) % MOD);
}


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

int main() {
  
  int N; cin >> N; int table[2][N]; int sum = 0;
  
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> table[i][j];
    }
  }
  
  for (int i = 0; i < N; i++) {
    
    int tmp = 0;
    
    for (int j = 0; j < i + 1; j++) tmp += table[0][j];
    
    for (int j = i; j < N; j++) tmp += table[1][j];
    
    sum = max(sum, tmp);
    
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace _074_Videotape
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			TimeSpan limit = new TimeSpan (2, 0, 0);

			while ((inputStr = Console.ReadLine ()) != "-1 -1 -1")
			{
				int[] inputNum = inputStr.Split (' ').Select (int.Parse).ToArray ();

				TimeSpan time = new TimeSpan (inputNum[0], inputNum[1], inputNum[2]);
				TimeSpan span = limit - time;
				TimeSpan span2 = span + span + span;

				Console.WriteLine (span);
				Console.WriteLine (span2);
			}
		}
	}
}

Measured memory_bytes: 9560
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=10**15
for i in range(1<<(N-1)):
  cnt,s,t=0,0,a[0]+1
  for j in range(N-1):
    if i>>j&1:
      x=a[j+1]
      cnt+=1
      if x>=t:
        t=x+1
      else:
        s+=(t-x)
        t+=1
    else:
      t=max(t,a[j+1]+1)
  if cnt>=K-1:
    ans=min(s,ans)
print(ans)

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

int main() {
    ll n, m;
    cin >> n >> m;
    priority_queue<P> q;
    rep(i,n) {
        ll a;
        cin >> a;
        q.push(make_pair(a,1));
    }
    rep(i,m) {
        ll b, c;
        cin >> b >> c;
        q.push(make_pair(c,b));
    }
    ll sum = 0;
    rep(i,n) {
        auto p = q.top();
        q.pop();
        sum += p.first;
        p.second -= 1;
        if (p.second != 0) q.push(p);
    }
    cout << sum << endl;
    
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector <int> a(M), b(M), num(N);
  
  for (int i=0; i<M; i++){
    cin >> a.at(i) >> b.at(i);
    num.at(a.at(i)-1)++;
    num.at(b.at(i)-1)++;
  }
  
  
  for (int i=0; i<N; i++){
    cout << num.at(i) << endl;
  }
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++ i) 
#define N 100010
using namespace std;
int n,m,v,p,a[N],ans,a1;
inline bool cmp(int i, int j)
{
	return i>j;
}
inline int read()
{
	char cc = getchar(); int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();};
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();};
	return flus * cn;
}
signed main()
{
	n = read();
	m = read();
	v = read();
	p = read();
	//scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	ans=p;
	rep(i, 1, n) a[i] = read();
	sort(a+1, a+n+1, cmp);
	rep(i, p + 1, n)
	{
		if(a[i] + m < a[p]) break;
		if(v <= p + n - i) ++ans;
		else if(((v - p - n + i) * m - a1 - 1) / (i - p) + 1 + a[p] <= a[i] + m) ++ans;
		a1 += a[p] - a[i];
	}
	printf("%lld",ans);
	return 0;
 }


Measured memory_bytes: 1024
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let r = read_as_vec::<i32>()[0];

    if r < 1200{
        println!("ABC");
    }else if r < 2800{
        println!("ARC");
    }else{
        println!("AGC");
    }
}


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

int main() {
  int Q;
  cin >> Q;
  vector<int> Like;
  set<int> s;
  for (int i = 3; i < 100000; i += 2) {
    int q = sqrt(i);
    bool b = false;
    for (int j = 2; j <= q; j++) {
      if (i%j == 0) {
        b = true;
        break;
      }
    }
    if (!b) s.insert(i);
  }
  Like.push_back(3);
  for (int i = 5; i < 1000000; i += 2) {
    if (s.count(i) && s.count((i+1)/2)) Like.push_back(i); 
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    auto itr1 = lower_bound(Like.begin(), Like.end(), l);
    auto itr2 = lower_bound(Like.begin(), Like.end(), r+1);
    cout << distance(itr1, itr2) << endl;
  }
}

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

int dp[60][60];
char a[60][60];
//1 null 2 B 3 W 4 non
void calc(int w,int h){
  queue<tuple<int,int,int>> task;
  task.push(make_tuple(1,1,1));
  while(!task.empty()){
    tuple<int,int,int>memo =task.front();
    task.pop();
    int x,y,stat;
    x=get<0>(memo);
    y=get<1>(memo);
    stat=get<2>(memo);
    if(dp[x][y]==stat||dp[x][y]==4) continue;
    if(dp[x][y]>1&&stat==1) continue;
    if(dp[x][y]==2&&stat==3||dp[x][y]==3&&stat==2) stat=4;
    if(a[x][y]!='.'&&stat==4) continue;
    if(a[x][y]=='W') stat=3;
    if(a[x][y]=='B') stat=2;
    if(a[x][y]=='!') continue;
    dp[x][y]=stat;
    task.push(make_tuple(x+1,y,stat));
    task.push(make_tuple(x-1,y,stat));
    task.push(make_tuple(x,y+1,stat));
    task.push(make_tuple(x,y-1,stat));
  }

  return;
}
int main(){
  while(1){
    int w,h;
    cin>>w>>h;
    if(w==0&&h==0) break;
    lp(i,60){
      lp(j,60){
	dp[i][j]=0;
	a[i][j]='!';
      }
    }
    lp(i,h+1){
      if(i==0) continue;
      lp(j,w+1){
	if(j==0) continue;
	cin>>a[j][i];
      }
    }
    calc(w,h);
    int countb=0,countw=0;
    lp(i,h+1){
      if(i==0) continue;
      lp(j,w+1){
	if(j==0) continue;
	if(a[j][i]=='.'){
	  if(dp[j][i]==2) countb++;
	  if(dp[j][i]==3) countw++;
	}
      }
    }
    cout<<countb<<" "<<countw<<endl;
    
  }
  return 0;
}




Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

void solve(ll N, int use, ll current, ll &count) {
  if (current > N) return;
  if (use == 0b111) count++;

  // 7
  solve(N, use | 0b001, current * 10 + 7, count);
  // 5
  solve(N, use | 0b010, current * 10 + 5, count);
  // 3
  solve(N, use | 0b100, current * 10 + 3, count);
}

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

  ll ans = 0;
  solve(N, 0, 0, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

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


Measured memory_bytes: 256
n = int(input())
creatures = list(map(int,input().split()))
creatures.sort()
ans = 0
p = creatures[0]
for i in range(1, n):
    if creatures[i] > p * 2:
        ans = 0
    else:
        ans += 1
    p += creatures[i]
ans += 1
print(ans)

Measured memory_bytes: 14320
#include<bits/stdc++.h> 
#define ll long long
using namespace std; 
int main() { ll a,b,c,d, i,j,k,l;
    l=0;
    cin>>a;
    for(i=1;i<=a;i++){
    if(i%3==0||i%5==0){}
else {l+=i;}
        }
    cout<<l<<endl;
    }


Measured memory_bytes: 3588
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line

inline void solve(void){
  int a,b;
  in(a,b);
  out(a*b);
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3652
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    D = LI()

    D = sorted(D)
    t = n // 2
    print(D[t] - D[t-1])


if __name__ == '__main__':
    solve()


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

int N;
int A[210];
 
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  
  int res = 0;
  
  while (true) {
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
    	if (A[i] % 2 != 0) exist_odd = true;
    }
    
    if (exist_odd) break;
    
    for (int i = 0; i < N; i++) {
    	A[i] /= 2;
    }
    res++;	
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author:   bebebe
# Created:  2019-10-27
#


obj = input().strip().split(' ')
A, B = list(map(int, obj))


if A > 9 or B > 9:
    print(-1)
else:
    print(A * B)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
int main()
{
  ll A, B, N, r; cin >> A >> B >> N; 
  if (N < B) r = N % B; else r = B - 1;
  cout << A * r / B << endl; 
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[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;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

vector<ll> pa, query;
set<ll> used;
UnionFindTree g;

int main() {
    ll n, q;
    while(cin >> n >> q, n){
        bool marked[MAX_N]{};
        pa.resize(n+5);
        query.clear();
        used.clear();
        g.init(n+5);
        REP(i,n-1){
            cin >> pa[i+2];
        }
        used.insert(1);
        REP(i,q){
            string s;
            ll k;
            cin >> s >> k;
            if(s=="Q")query.push_back(k);
            else{
                if(used.count(k)>0)continue; // すでにマークされた頂点はマークしない
                used.insert(k);
                query.push_back(-k);
                marked[k] = true;
            }
        }
        for(int i=2;i<=n;i++){
            if(!marked[i]) g.unite(pa[i],i);
        }
        reverse(ALL(query)); // 逆順に操作
        ll sum = 0;
        for(auto k : query){
            if(k<0){
                k=abs(k);
                g.unite(pa[k],k);
            }
            else{
                sum += ll(g.find(k));
            }
        }
        cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 7528
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double PI = 3.14159265358979323846;

int main() {
    int n, m, a[1001], b[1001];
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
    }

    int r[1001] = {};

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[j] <= b[i]) {
                r[j]++;
                break;
            }
        }
    }

    int max = 0;
    int maxI = 0;
    for (int k = 0; k < n; ++k) {
        if (max < r[k]) {
            max = r[k];
            maxI = k;
        }
    }

    cout << maxI + 1 << endl;

    return 0;
}

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

int main() {
    //
    string str;
    vector<int> vec(26, 0);

    cin >> str;

    if (str == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1;
    } else if (str.size() == 26) {
        string tmp = str;
        next_permutation(str.begin(), str.end());

        string kekka = "";
        for (int i = 0; i < str.size(); i++) {
            kekka += str.at(i);
            if (str.at(i) > tmp.at(i)) break;
        }

        cout << kekka;
    } else {
        for (int i = 0; i < str.size(); i++) vec.at(str.at(i) - 'a')++;

        for (int i = 0; i < vec.size(); i++) {
            if (vec.at(i) == 0) {
                cout << str << (char)(i + 'a');
                break;
            }
        }
    }

    //
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
 
int main(){
string s,t;
cin>>s>>t;
int i;
int c=0;
for(i=0;i<3;i++){
	if(s[i]==t[i]){
		c++;
	}
} 
cout<<c<<'\n';
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
m = n / 2 + 1
q = gets.split.map(&:to_f)

d = Array.new(m, 0)
d[0] = 1
u = Array.new(m)
ans = 0
q.each do |e|
    m.times {|i| u[i] = d[i] * (1 - e)}
    (m-1).times {|i| u[i+1] += d[i] * e}
    ans += d[m-1] * e
    d, u = u, d
end

p ans

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

def main():

    while True:
        n, x = map(int, input().split())
        if n == x == 0:
            break

        ans = 0

        for i in range(1, n - 1):
            for j in range(i + 1, n):
                for k in range(j + 1, n + 1):
                    if (i + j + k) == x:
                        ans += 1

        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

#define fst first
#define snd second

using namespace std;

using ll = long long;
using PII = pair<int, int>;

ll _sum[300010], *sum = _sum+1;
int main(void){
	_sum[0] = 0;
	int N;
	cin >> N;
	REP(i, N){
		cin >> sum[i];
		sum[i+N] = sum[i];
		sum[i+2*N] = sum[i];
	}
	FOR(i, 1, N*3){
		sum[i] += sum[i-1];
	}
	ll res = 0;
	REP(i, N){
		ll fs, sc, th;
		fs = *(lower_bound(sum+i, sum+i+N, (sum[N-1]/3)+sum[i])-1);
		sc = *(lower_bound(sum+i, sum+i+N, (sum[N-1]/3)+fs)-1);
		sc -= fs;
		fs -= sum[i-1];
		th = sum[N-1]-fs-sc;
		res = max(res, min(fs, min(sc, th)));
		sc = *lower_bound(sum+i, sum+i+N, (sum[N-1]/3)+fs+sum[i-1]);
		sc -= fs + sum[i-1];
		th = sum[N-1]-fs-sc;
		res = max(res, min(fs, min(sc, th)));
		fs = *lower_bound(sum+i, sum+i+N, (sum[N-1]/3)+sum[i]);
		sc = *(lower_bound(sum+i, sum+i+N, (sum[N-1]/3)+fs)-1);
		sc -= fs;
		fs -= sum[i-1];
		th = sum[N-1]-fs-sc;
		res = max(res, min(fs, min(sc, th)));
		sc = *lower_bound(sum+i, sum+i+N, (sum[N-1]/3)+fs+sum[i-1]);
		sc -= fs + sum[i-1];
		th = sum[N-1]-fs-sc;
		res = max(res, min(fs, min(sc, th)));
	}
	cout << res << endl;
}

Measured memory_bytes: 5388
#include <iostream>
using namespace std;
int main(){
  long long n;cin>>n;
  long long a[n];
  for(int i = 0; n > i; i++)cin>>a[i];
  long long ansmn = 2;
  long long ansmx = 2;
  for(int i = n-1; 0 <= i; i--){
    long long tmp = ansmn/a[i]*a[i];
    while(ansmn > tmp)tmp+=a[i];
    ansmn = tmp;
    ansmx = ansmx/a[i]*a[i];
    ansmx+=a[i]-1;
    if(ansmn > ansmx){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ansmn << " " << ansmx <<endl;

}

Measured memory_bytes: 1024
#include <stdio.h>

#define mod 1000000007

int main(void)
{
	int n, a[2000], all[2000], right[2000];
	long long int k, sum;
	scanf("%d %lld", &n, &k);
	int i, j, left, count;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);

	for (i = 0; i < n; i++)
	{
		count = 0;
		for (j = 0; j < i; j++)
		{
			if (a[j] < a[i])
				count++;
		}
		left = count;
		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[i])
				count++;
		}
		all[i] = count;
		right[i] = count - left;
	}

	sum = 0;
	for (i = 0; i < n; i++)
	{
		sum = (sum + (k * right[i]) % mod + (((k * (k - 1) / 2) % mod) * all[i]) % mod) % mod;
	}

	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 128
// Improved version of https://beta.atcoder.jp/contests/abc075/submissions/1685909
// using while instead of for
object Main{
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val K = sc.nextInt
 
    val x_ = Array.ofDim[BigInt](N)
    val y_ = Array.ofDim[BigInt](N)
    for(i <- 0 to N-1){
      x_(i) = sc.nextInt
      y_(i) = sc.nextInt
    }
 
    val x = x_.sorted
    val y = y_.sorted
 
    var ans : BigInt = (x(N-1)-x(0)) * (y(N-1)-y(0))
    var xi = 0
    while(xi < N) {
      var xj = xi + 1
      while(xj < N){
        var yi = 0
        while(yi < N){
          var yj = yi + 1
          while(yj < N){
            val lx = x(xi)
            val rx = x(xj)
            val by = y(yi)
            val uy = y(yj)
 
            var cnt = 0
            var i = 0
            while(i < N) {
              if(lx<=x_(i) && x_(i)<=rx && by<=y_(i) && y_(i)<=uy) cnt = cnt + 1
              i += 1
            }
 
            if(cnt >= K){
              ans = ans.min((rx-lx)*(uy-by))
            }
            yj += 1
          }
          yi += 1
        }
        xj += 1
      }
      xi += 1
    }
    assert(ans > 0)
    println(ans)
  }
}

Measured memory_bytes: 105564