akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int apple[3][100005], need[2], siz[3];

int main() {
	int x, y, a, b, c;
	scanf("%d%d%d%d%d", &need[0], &need[1], &siz[0], &siz[1], &siz[2]);
	
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < siz[i]; j++) {
			scanf("%d", &apple[i][j]);
		}
		
		sort(apple[i], apple[i] + siz[i], greater<int>());
	}
	
	vector <int> choice;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < need[i]; j++) choice.push_back(apple[i][j]);
	}
	
	for (int i = 0; i < siz[2]; i++) choice.push_back(apple[2][i]);
	
	sort(choice.begin(), choice.end(), greater<int>());
	
	long long res = 0;
	
	for (int i = 0; i < need[0] + need[1]; i++) res += choice[i];
	
	printf("%lld\n", res);
}


Measured memory_bytes: 6500
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n, m;
	long long k;
	vector<long long> a, b;

	scanf("%d %d %lld", &n, &m, &k);

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

		scanf("%lld", &input);

		a.push_back(input);
	}

	for (int i = 0; i < m; i++)
	{
		long long input;

		scanf("%lld", &input);

		b.push_back(input);
	}

	long long cur = 0;
	int ptr1 = n;

	if (a[0] > k)
	{
		ptr1 = 0;
	}

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

			if (cur + a[i] > k)
			{
				break;
			}

			else
			{
				ptr1 = i + 1;
			}

			cur += a[i];
		}
	}

	int ptr2 = m;

	int sol = 0;

	if (b[0] > k)
	{
		ptr2 = 0;
	}

	else
	{
		for (int i = 0; i < m; i++)
		{
			ptr2 = i;

			if (cur + b[i] > k)
			{
				break;
			}

			else
			{
				ptr2 = i + 1;
			}

			cur += b[i];
		}

		sol = ptr1 + ptr2;

		for (int i = ptr1 - 1; i >= 0; i--)
		{
			cur -= a[i];

			while (ptr2 < m && cur + b[ptr2] <= k)
			{
				cur += b[ptr2];

				ptr2++;
			}

			const int cand = i + ptr2;

			if (cand > sol)
			{
				sol = cand;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 7456
def CountingSort(A, B, n, k):
    C = [0]*(k+1)
    
    # C[i] に i の出現数を記録する
    for j in range(n):
        C[A[j]]+=1
        
    #C[i] に i 以下の数の出現数を記録する
    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]
        
    for j in range(n):
        B[C[A[j]]-1] = A[j]
        C[A[j]]-=1

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    B = A[:]
    k = max(A)
    CountingSort(A, B, n, k)
    print(' '.join(map(str, B)))


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

#define t 1000000000
#define k 1000000000000
#define u 200000000000000

using namespace std;

int main(void)
{
	long int h;
	long int ans = 0;
	cin>>h;
	long int i;
	long int num = 1;
	while(h != 1){
		ans += num;
		if(h % 2 == 1){
			h--;
		}
		h = h / 2;
		num = num * 2;
	}
	ans += num;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#coding:UTF-8

import math

class Bank(object):
    #type: True complex, False simple
    def __init__(self, num, rate, type):
        self.num = num
        self.rate = rate
        self.type = type
    def calc(self, year):
        if(self.type):
            return (1 + self.rate / 100.0) ** year
        else:
            return (1 + year * self.rate / 100.0)

while True:
    n = input()
    if n == 0:
        break
    Bankarr = []
    gain = []
    y = input()
    for i in range(n):
        s = raw_input().split(" ")
        b = True if s[2] == "2" else False
        Bankarr.append(Bank(int(s[0]),float(s[1]), b))
    for i in range(n):
        gain.append(Bankarr[i].calc(y))
    bestgain = 0
    bestnum = 0
    for i in range(n):
        if bestgain < gain[i]:
            bestgain = gain[i]
            bestnum = Bankarr[i].num
    print "%d" % bestnum

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

int main() {
    int n; cin >> n;
    int k; cin >> k;
    int mask = 0;
    while (k--) { int i; cin >> i; mask |= 1 << i; }
    for (int b = mask; ; b = (b - 1) & mask) {
        int rb = b ^ mask;
        cout << rb << ":";
        for (int i = 0; i < n; i++) if (rb >> i & 1) cout << " " << i;
        cout << endl;
        if (!b) break;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

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

int main() {
	int N;
	cin >> N;
	unsigned long long ans;
	if (N % 2 == 0) {
		ans = N / 2;
		ans *= N - 1;
	}
	else {
		ans = (N - 1) / 2;
		ans *= N;
	}
	cout << ans;
	return 0;

}



Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a,b;
    scanf("%d %d", &a, &b);
    if ((a * b) % 2 == 0)
    {
        printf("Even");
    }
    
    else if ((a * b) % 2 == 1)
    {
        printf("Odd");
    }
}

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

using namespace std;
typedef long long LL;
const int LEN = 1e4 + 10;
LL arr[LEN];
LL len, cnt;

void init() {
    len = cnt = 0;
    while (1) {
        arr[cnt] = cnt * cnt * cnt * cnt * cnt;
        if (cnt && arr[cnt] - arr[cnt - 1] > (1e9)) {
            break;
        }
        cnt++;
    }
    cnt++;
    len = cnt;
    for (int i = 1; i < cnt; i++) {
        arr[len++] = arr[i] * -1;
    }
    sort(arr, arr + len);
}

int solve(long long x) {
    int l = 0, r = len;
    while (l < r) {
        int mid = l + r >> 1;
        if (arr[mid] < x) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    return arr[l] == x ? l : -1;
}

int main() {
    init();
    LL x;
    cin >> x;
    int ansa = -1, ansb = -1;
    for (int i = 0; i < len; i++) {
        ansb = solve(arr[i] - x);
        if (ansb >= 0) {
            ansa = i - 120;
            ansb -= 120;
            break;
        }
    }
    cout << ansa << " " << ansb << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int a,b,c,d;
 cin>>a>>b>>c>>d;
 long long int  maxi;
 long long int  maxi1,maxi2;
 maxi1=max(a*c,a*d);
 maxi2=max(b*c,b*d);
 maxi=max(maxi1,maxi2);
 cout<<maxi;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int g = 1;
    for (;;++g) {
        if (N <= K + (K-1)*(g-1)) break;
    }
    cout << g << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    lli n;
    lli d;
    cin>>n>>d;
    lli arr[n];
    lli brr[n];
    for(lli i=0;i<n;i++)
    {
        cin>>arr[i];
        cin>>brr[i];
    }
    lli ans=0;
    for(lli i=0;i<n;i++)
    {
       if(arr[i]*arr[i]+brr[i]*brr[i]<=d*d) 
       {
           ans++;
       }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6752
#include <cstdio>
#define FOR(i, m, n) for (int i = m; i <= n; ++i)
const int MOD = (int)1e9 + 7;
using ll = long long;

int main() {
  int N; scanf("%d", &N);
  ll ans = 1;
  FOR(i, 2, N) {
    ans *= i;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 1e5 + 5;
const ll MAX_V = 1e10 + 5;

ll ar[MAXN], other[MAXN];
map<ll, int> cnt;
bool not_prime[MAXN];
vector<ll> primes, primesq;
set<ll> visit;

int main() {
    for (int i = 2; i < MAXN; i++) {
        if (!not_prime[i]) {
            primes.pb(( ll )i);
            primesq.pb(sq(( ll )i));
        }
        for (int j = i * 2; j < MAXN; j += i)
            not_prime[j] = true;
    }
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &ar[i]);
        ll &num = ar[i];
        ll s = ar[i], b = ar[i];
        for (ll j : primes) {
            if (j * j * j > num) break;
            int cur = 0;
            while (num % j == 0) {
                num /= j;
                s /= j;
                b /= j;
                cur++;
            }
            cur %= 3;
            if (cur > 0)
                b *= j * j * j;
            while (cur--) {
                num *= j;
                b /= j;
            }
        }
        b /= s;
        if (binary_search(all(primesq), s))
            b *= ( ll )sqrt(s);
        else if (s <= ( ll )1e5)
            b *= s * s;
        else
            b = 0;
        other[i] = b;
        //printf("%d) %lld\n", i, num);
        cnt[num]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ll num = ( ll )cbrt(ar[i]);
        if (ar[i] == 1) continue;
        if (visit.count(ar[i])) continue;
        visit.insert(ar[i]);
        visit.insert(other[i]);
        ans += max(cnt[ar[i]], cnt[other[i]]);
    }
    if (cnt[1] > 0) ans++;
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 20096
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

signed main(){
  string S;
  cin >> S;

  int res = 0;
  int cnt = 0;
  for (auto c : S) {
    if (c == 'R') {
      cnt++;
      res = max(res, cnt);
    } else {
      cnt = 0;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3624
T=[[0,0] for i in range(5)]


for i in range(5):
    temp=int(input())
    if temp%10==0:
        T[i]=[10,temp]
    else:
        T[i]=[temp%10,temp]

T.sort(reverse=True)

ans=0
for i in range(4):
    ans+=((T[i][1]-1+10)//10)*10

ans+=T[4][1]

print(ans)

Measured memory_bytes: 3064
function main(input) {
  input=input.trim();
  const a = parseInt(input.split(" ")[0], 10);
  const b = parseInt(input.split(" ")[1], 10);
  const c = parseInt(input.split(" ")[2], 10);
  var ar=[a,b,c]
  var set=new Set(ar)
  console.log(set.size);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
n, k = map(int, input().split())
arr = [0] + list(map(int, input().split())) + [0] * 1000

INF = 1 << 60
dp = [INF] * (n + 1000)

dp[1] = 0

for i in range(1, n):
    for k in range(1, k + 1):
        dp[i + k] = min(dp[i + k], dp[i] + abs(arr[i + k] - arr[i]))

print(dp[n])

Measured memory_bytes: 54112
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int x, t;
    cin >> x >> t;
    cout << max(x-t, 0) << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

int digit_sum(int N){
    int ans = 0;
    int tmp = N;
    for(int i = 0; i < 6; i++){
        ans += (tmp % 10);
        tmp /= 10;
    }
    return ans;
}
int main(){
    int N;
    cin >> N;
    int ans = INT_MAX;
    for(int i = 1; i < N; i++){
        int tmp_ans = digit_sum(i) + digit_sum(N - i);
        ans = min(ans, tmp_ans);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n ; cin >> n ;
	vector<int> a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	int  ans = 100000000 ;
	for(int i=-100;i<=100;i++){
		int sub = 0 ;
		for(int j=0;j<n;j++){
			sub += (i-a.at(j))*(i-a.at(j)) ;
		}
		if(sub<ans) ans = sub ;
	}
	cout << ans << endl ;
}

Measured memory_bytes: 256
import math

def iip():
    return [int(i) for i in input().split()]

def sita_over(a, x):
    return math.atan(((2*x)/a**3)) / math.pi * 180

def sita_under(a, b, x):
    d = (2*x) / (a*b**2)
    e = math.atan(d) / math.pi * 180
    return 90 - e

def sita(a, b, x):
    if x > 1/2 * a**2 * b:
        vv = a**2 * b - x
        return sita_over(a, vv)
    else:
        return sita_under(a, b, x)


a, b, x = iip()

print(sita(a, b, x))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
void selection(int n, char data[][5],char sdata[],char sample[][5]){
  int min,flag = 0 ;
  int tmp,key,counter = 0;
  char tmp2[3];
  char cop[36][5];
  memcpy(cop,sample,sizeof(cop));
  
  /*
  for (int i = 0; i < n ; i ++){
    printf("%s ",data[i]);
  }
  */
  //i-nまでのminを探索
  //i:既ソートの右端index
  //j:未ソートの左端index
  for (int i = 0; i < n ; i ++ ){ //未ソートの右端でループ
    min = sdata[i];//既ソートの左端の値をminの初期値に
    key = i; // keyの初期化
    for (int j = i; j < n; j ++ ){
      //最小値とそのindexの探索
      if (sdata[j]< min){
        min = sdata[j];
        key = j;
      }
    }
    //既ソートのminが未ソートの右端よりも小さい場合にswap
    if (sdata[i] > min){
    //data[i]にminを、data[j]にdata[i]を代入
      tmp = sdata[i];
      sdata[i] = min;
      sdata[key] = tmp;
      counter += 1; 
      //dataのソート
      strcpy(tmp2,data[i]);
      strcpy(data[i],data[key]);
      strcpy(data[key],tmp2);   
    }
  }
  //結果の出力
  
  for (int i = 0; i < n ; i ++ ){
    if (i > 0) printf(" ");
    printf("%s",data[i]);
  }
  printf("\n");
  //printf("%d\n",counter);
  for (int i = 0; i < n; i ++){
    if (strcmp(cop[i],data[i])){
      printf("Not stable\n");
      flag = 1;
    break;
    }
  }
  if (flag == 0) printf("Stable\n");
  flag = 1;
}

void sort(int n,char data[][5],char sdata[]){
  int flag = 0;
  char cop[36][5];
  int counter = 0;
  char tmp,tmp2[2];
  char ans[n];
  //strcpy(cop,data);
  while (1==1){
    flag = 0;
    for (int i = 0; i < n-1; i ++ ){
      //sdataでソート
      if (sdata[i] > sdata[i+1]){
        counter += 1;
        tmp = sdata[i];
        sdata[i] = sdata[i+1];
        sdata[i+1] = tmp;
        //dataのソート
        strcpy(tmp2,data[i]);
        strcpy(data[i],data[i+1]);
        strcpy(data[i+1],tmp2);
        flag = 1;
      }
    }
    if (flag == 0){
      for (int i = 0; i < n ; i ++){
        if ( i > 0 ) printf(" ");
        printf("%s",data[i]);
      }
      printf("\n");
      //printf("%d\n",counter);
      break;
    }
  }
  // dataの文字を配列に格納
  printf("Stable\n");
  
}


int main(){
  //入力を文字列として配列に格納
  //文字列の配列は2次元配列
  char data[36][5];
  char sdata[36];
  int stable;
  int n;
  char mem[36][5];
  char smem[36];
  scanf("%d",&n);
  for (int i = 0; i < n; i ++){
    scanf("%s",data[i]);
  }
 //dataから数値を抽出した配列の生成
 for (int i = 0 ; i < n ;i ++){
   sdata[i] = (data[i][1]);
 }
// stableかの判定

memcpy(mem,data,sizeof(data));
memcpy(smem,sdata,sizeof(sdata));
sort(n,data,sdata);

selection(n,mem,smem,data);
}




Measured memory_bytes: 2112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    BContests solver = new BContests();
    solver.solve(1, in, out);
    out.close();
  }

  static class BContests {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int a = in.nextInt();
      int b = in.nextInt();
      int cnt1 = 0;
      int cnt2 = 0;
      int cnt3 = 0;
      for (int i = 0; i < n; i++) {
        int tmp = in.nextInt();
        if (tmp <= a) {
          cnt1++;
        } else if (tmp <= b) {
          cnt2++;
        } else {
          cnt3++;
        }
      }
      out.println(Math.min(Math.min(cnt1, cnt2), cnt3));
    }

  }
}



Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> V;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;

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


signed main(){
    ll n;
    cin >> n;
    V a(n);
    V b(n);

    queue<ll> que;
    V v(400000, 0);

    REP(i,n){
        cin >> a[i] >> b[i];
        ++v[a[i] + b[i]];
    }
    REP(i,400000){
        REP(j, 30){
            if(!j)continue;
            if(v[i] <= 1)break;
            if(v[i] & (1<<j))
                que.emplace(i + j);
        }
        v[i] %= 2;
    }

    while(!que.empty()){
        ll i = que.front();
        que.pop();

        v[i]++;

        REP(j, 30){
            if(!j)continue;
            if(v[i] <= 1)break;
            if(v[i] & (1<<j))
                que.emplace(i + j);
        }
        v[i] %= 2;
    }
    REP(i,400000){
        if(v[i])
            cout << i << " " << 0 << endl;
    }

}



Measured memory_bytes: 7896
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9*2; const long long INFLL=1e18*2;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.second >> p.first; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vector<pii> a(n);
    REP(i,n) cin>>a[i].first,a[i].second=i+1;
    sort(ALL(a));

    int ans=0;
    set<int> s;
    s.insert(0);
    s.insert(n+1);
    FORE(p,a) {
        int x=p.first;
        int i=p.second;
        auto itr=s.upper_bound(i); // 挿入位置の1つ後ろ
        int b=*itr-i;
        itr--; // 挿入位置の1つ前
        int c=i-*itr;
        ans+=b*c*x;
        s.insert(i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

using mint = ModInt<MOD>;
int main() {
	int n, k; cin >> n >> k;
	++n;
	mint sum[n + 1] = {};
	for(int i = 1; i <= n; ++i) {
		sum[i] = sum[i - 1] + i;
	}
	mint ans = 0;
	for(int i = k; i <= n; ++i) {
		mint r = sum[n] - sum[n - 1 - (i - 1)];
		mint l = sum[i];
		ans += (r - l + 1);
		// cerr << l << " " << r << '\n';
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5128
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>

int main(){
    int64_t N, K;
    std::cin >> N;
    std::cin >> K;
    int64_t H;
    std::vector<int64_t> Hi;
    for(int i=0; i<N; i++){
        std::cin >> H;
        Hi.push_back(H);
    }
    std::sort(Hi.begin(), Hi.end());
    std::reverse(Hi.begin(), Hi.end());
    int64_t res = 0;
    if (!(N<=K)){
        Hi.erase(Hi.begin(), Hi.begin() + K);
        std::cout << std::accumulate(Hi.begin(), Hi.end(),0LL);
    }
    else{
        std::cout<<res;
    }

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    string s;
    cin >> s;
    int q;
    cin >> q;
    int t;
    bool flag = true;
    int count = 0;
    string front = "", back = "";
    rep(i,q) {
        cin >> t;
        if (t == 1) {
            count++;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (flag) front.push_back(c);
                else back.push_back(c);
                
            } else {
                if (flag) back.push_back(c);
                else front.push_back(c);
            }
        }
        flag = (count%2 == 0);
    }
    reverse(front.begin(), front.end());
    s = front + s + back;
    if (!flag) reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1200
class Node:
    def __init__(self):
        self.parent=-1
        self.left=-1
        self.right=-1


nodeList=[]
preOrderList=[]
inOrderList=[]
postOrderList=[]

def readinput():
    global nodeList

    n=int(input())
    nodeList=[Node() for _ in range(n)]
    for _ in range(n):
        id,l,r=list(map(int,input().split()))
        nodeList[id].left=l
        nodeList[id].right=r
        if(l!=-1):
            nodeList[l].parent=id
        if(r!=-1):
            nodeList[r].parent=id
    
def findRoot():
    global nodeList

    for i,node in enumerate(nodeList):
        if node.parent==-1:
            return i
    return -1

def getPreOrder(id):
    global nodeList
    global preOrderList

    preOrderList.append(id)
    node=nodeList[id]
    if(node.left!=-1):
        getPreOrder(node.left)
    if(node.right!=-1):
        getPreOrder(node.right)

def getInOrder(id):
    global nodeList
    global inOrderList

    node=nodeList[id]
    if(node.left!=-1):
        getInOrder(node.left)
    inOrderList.append(id)
    if(node.right!=-1):
        getInOrder(node.right)
    
def getPostOrder(id):
    global nodeList
    global postOrderList

    node=nodeList[id]
    if(node.left!=-1):
        getPostOrder(node.left)
    if(node.right!=-1):
        getPostOrder(node.right)
    postOrderList.append(id)

def main():
    global nodeList

    root=findRoot()
    getPreOrder(root)
    getInOrder(root)
    getPostOrder(root)
    print('Preorder')
    print(' ',end='');print(' '.join(map(str,preOrderList)))
    print('Inorder')
    print(' ',end='');print(' '.join(map(str,inOrderList)))
    print('Postorder')
    print(' ',end='');print(' '.join(map(str,postOrderList)))

if __name__=='__main__':
    readinput()
    main()



Measured memory_bytes: 5620
import scala.io.StdIn._
object Main extends App {

  val Array(s, n, m) = readLine.trim.split(' ').map(_.toInt)
  val stops = readLine.trim.split(' ').map(_.toInt)
  val passengers = Array.tabulate(n){_ ⇒
    val Array(t, p) = readLine.trim.split(' ').map(_.toInt)
    t - stops(p - 1)
  }.sorted
  val waitingTimeSum = 0 +: passengers.map{_ - passengers.head}
  for (i ← waitingTimeSum.indices.tail) waitingTimeSum(i) += waitingTimeSum(i - 1)
  val memo = Array.fill(m){Array.fill(n + 1){-1}}
  for (i ← 0 to n) memo(0)(i) = waitTime(i, n - 1)
  for (i ← 1 until m) {
    memo(i)(n) = 0
    minTime(i)
  }
  println(memo.last.head)
  def minTime(busRest: Int): Long = {
    def rec(pMin: Int, pMax: Int, kMin: Int, kMax: Int): Unit = {
      if (pMin <= pMax) {
        val mid = (pMin + pMax) / 2
        val (r, k) = (math.max(mid, kMin) to math.min(n, kMax)).map{k ⇒ (memo(busRest - 1)(k + 1) + waitTime(mid, k), k)}.minBy(_._1)
        memo(busRest)(mid) = r
        rec(pMin, mid - 1, kMin, k)
        rec(mid + 1, pMax, k, kMax)
      }
    }
    rec(0, n - 1, 0, n - 1)
    memo(busRest).last
  }
  def waitTime(from: Int, to: Int): Int = {
    (passengers(to) - passengers.head) * (to - from + 1) - waitingTimeSum(to + 1) + waitingTimeSum(from)
  }
}


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

int main(){
    vector<char> s(3);
    for(int i=0;i<3;i++){
        cin >> s.at(i);
    }
    int ans=700;
    for(int i=0;i<3;i++){
        if(s.at(i)=='o'){
            ans+=100;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    int n;
    cin >> n;
    int a[n];
    int check, MAX = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        MAX = max(MAX, a[i]);
        if(MAX == a[i])
            check = i;
        if(MAX - a[i] >= 2 && i > check){
            cout << "No" << endl;
            break;
        }
        if(i == n-1)
            cout << "Yes" << endl;
    }
    return 0;
}

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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    string c;
    cin >> c;
    if(c=="a"||c=="i"||c=="u"||c=="e"||c=="o")
        P("vowel");
    else
        P("consonant");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<bool> ok(n, false);
	vector<int> box(n, 1);
	
	ok[0] = true;
	for(int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		
		if( ok[x] ) ok[y] = true;
	
		box[x]--; box[y]++;
		
		if( box[x] == 0 ) ok[x] = false;
	}
	
	int ans = 0;
	for(auto v : ok) {
		if( v ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s;
   cin >> s;
    int co=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R')co++;
    }
    int x=(n%2==0?n/2:(n-1)/2);
    if(co>x) cout<< "Yes"<< endl;
    else{
        cout << "No"<< endl;
    }
    return 0;
}


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

int main(){
  int r, c, A[105][105]={};
  cin>>r>>c;
  for (int i=0;i<r;i++){
    for (int j=0;j<c;j++){
      cin>>A[i][j];
      A[i][c] += A[i][j];
      A[r][j] += A[i][j];
      A[r][c] += A[i][j];
    }
  }
  for (int i=0;i<r+1;i++){
    for (int j=0;j<c;j++){
      cout<<A[i][j]<<" ";
    }
    cout<<A[i][c]<<endl;
  }
  return 0;
}




Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  string s, t;
  cin >> s >> t;
  s += s;
  int ans = s.find(t);
  if(ans == std::string::npos){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
void ad(ll &a,ll b)
{
	a=(a+b)%mod;
}
void mul(ll &a,ll b)
{
	a=(a*b)%mod;
}
vector<ll> fact,seq_inv,fact_inv;
void create_fact_mod(ll num)
{
	fact[0]=1;fact[1]=1;
	for(ll i=2;i<=num;i++) fact[i]=fact[i-1]*i%mod;
}
void create_seq_inv_mod(ll num)
{
	seq_inv[0]=1;seq_inv[1]=1;
	for(ll i=2;i<=num;i++) seq_inv[i]=(mod-mod/i)*seq_inv[mod%i]%mod;
}
void create_fact_inv_mod(ll num)
{
	fact_inv[0]=1;fact_inv[1]=1;
	for(ll i=2;i<=num;i++)
	fact_inv[i]=fact_inv[i-1]*seq_inv[i]%mod;
}
void create_mod_tables(ll num)
{
	fact.resize(num+1);
	seq_inv.resize(num+1);
	fact_inv.resize(num+1); 
	create_fact_mod(num);
	create_seq_inv_mod(num); 
	create_fact_inv_mod(num);
}
ll comb_mod(ll n,ll k)
{
	return fact[n]*fact_inv[n-k]%mod*fact_inv[k]%mod;
}
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll res=0;
	for(ll i=1;i<=n;i++)
	{
		ad(res,i*(n-i));
	}
	mul(res,m*m);
	//cout<<res<<endl;
	ll res1=0;
	for(ll i=1;i<=m;i++)
	{
		ad(res1,i*(m-i));
	}
	mul(res1,n*n);
	ad(res,res1);
	ll a=n*m;
	create_mod_tables(a);
	//cout<<res<<endl;
	mul(res,comb_mod(a-2,k-2));
	cout<<res<<endl;
}

Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++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 FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

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

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> hvec(h, 0);
    vector<int> wvec(w, 0);
    vector< vector<int> > checker(h, vector<int>());
    vector< vector<int> > checker2(w, vector<int>());
    for(int i = 0; i < m; ++i) {
        int ch, cw; cin >> ch >> cw;
        ch--; cw--;
        hvec[ch]++; wvec[cw]++;
        checker[ch].emplace_back(cw);
        checker2[cw].emplace_back(ch);
    }

    for(int i = 0; i < h; ++i) {
        sort(checker[i].begin(), checker[i].end());
    }
    for(int i = 0; i < w; ++i) {
        sort(checker2[i].begin(), checker2[i].end());
    }
    int hmax = 0;
    for(int i = 0; i < h; ++i) {
        if(hmax <= hvec[i]) {
            hmax = hvec[i];
        }
    }
    // hの候補
    vector<int> hc;
    for(int i = 0; i < h; ++i) {
        if(hmax == hvec[i]) hc.emplace_back(i);
    }

    int wmax = 0;
    for(int i = 0; i < w; ++i) {
        if(wmax <= wvec[i]) {
            wmax = wvec[i];
        }
    }

    // wの候補
    vector<int> wc;
    for(int i = 0; i < w; ++i) {
        if(wmax == wvec[i]) wc.emplace_back(i);
    }

    int ans = 0;
    int hlen = hc.size();
    int wlen = wc.size();
    if(hlen == h && wlen == w) {
        if(h == 1 && w == 1) cout << 1 << endl;
        else cout << 2 << endl;
        return 0;
    }
    for(int i = 0; i < hlen; ++i) {
        for(int j = 0; j < wlen; ++j) {
            int cch = hc[i], ccw = wc[j];
            int ccc = hvec[cch]+wvec[ccw];
            int cchhlen = checker[cch].size();
            int ccwwlen = checker2[ccw].size();
            int lc, uc;
            if(cchhlen < ccwwlen) {
                lc = lower_bound(checker[cch].begin(), checker[cch].end(), ccw) - checker[cch].begin();
                uc = upper_bound(checker[cch].begin(), checker[cch].end(), ccw) - checker[cch].begin();
            }else {
                lc = lower_bound(checker2[ccw].begin(), checker2[ccw].end(), cch) - checker2[ccw].begin();
                uc = upper_bound(checker2[ccw].begin(), checker2[ccw].end(), cch) - checker2[ccw].begin();
            }
            if(lc != uc) ccc--;
            chmax(ans, ccc);
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)

long long solve(const string &sorig, const string &t) {
  const string s = sorig + sorig;
  const int slen = sorig.length();
  vector<int> pos[128];
  REP(i,s.length()) {
    pos[s[i]].push_back(i);
  }
  long long ans = -1LL;
  int idx = -1;
  for(int i = 0; i < t.length(); i++) {
    char c = t[i];
    if(pos[c].empty()) return -1;
    int nxt = upper_bound(pos[c].begin(), pos[c].end(), idx) - pos[c].begin();
    //    cout << c << " " << pos[c].size() << " " << nxt << endl;
    if(nxt < pos[c].size()) {
      ans += (long long)(pos[c][nxt] - idx);
      idx = pos[c][nxt];
      idx %= slen;
    }
    //    cout << idx << "," << pos[c][nxt] << "," << ans << endl;
  }
  return ans + 1;
}

int main() {
  string s, t; cin>>s>>t;
  long long ans = solve(s, t);
  cout << ans;
  cout << endl;
  return 0;
}


Measured memory_bytes: 1980
import java.util.Scanner;

public class Main{

	public static double beki2(double x){
		return x*x;
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		int []s;
		while(true){
			n = sc.nextInt();
			if(n==0)
				break;
			s = new int[n];
			for(int i=0;i<n;i++){
				s[i]=sc.nextInt();
			}
			double ave;
			int sum=0;
			for(int i=0;i<n;i++){
				sum+=s[i];
			}
			ave = (double)sum/n;
			double vari=0;
			for(int i=0;i<n;i++){
				vari += beki2(s[i]-ave);
			}
			vari/=n;
			double dev=Math.sqrt(vari);
			System.out.println(dev);
		}
	}
}


Measured memory_bytes: 30744
/*author - Ashutosh Chitranshi*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin >> a >> b;
    char c;
    cin >> c;
    ll d;
    cin >> d;
    b = b*100+d;
    ll ans = a*b;
    ans /= 100;
    cout << ans << "\n";
    return 0;
}

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


int main(){
    int a,b;
    vector<int> A;
    cin >> a >> b;
    int e = a + b;
    int r = a - b;
    int t = a * b;
    cout << max({e,r,t}) << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{

int x,y;
    cin >> x >> y;
    if(x * 2 == y or x * 4 == y){
		cout<<"Yes";
	}
  else
  {
		for(int i = 1; i <= x; i++)
    {
			if(i * 4 + ((x - i) * 2) == y)
      {
				cout<<"Yes";
				return 0;
			}
		}
		cout<<"No";
	}
}

Measured memory_bytes: 3164
import sys
input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size(x) < self.size(y):
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.union(x, y)

s = set()
for i in range(N):
    s.add(uf.find(i))

print(len(s))


Measured memory_bytes: 12780
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

signed main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> a2(n);
    map<ll,ll> MP;
    ll MAXA=0;
    rep(i,n) {
        scanf("%lld",&a[i]);
        MP[a[i]]++;
        MAXA = max(MAXA,a[i]);
    }
    sort(a.begin(),a.end());

    rep(i,n) a2[i]=a[i];
    a2.erase(unique(a2.begin(),a2.end()),a2.end());
    ll sz2 = a2.size();
    ll sz1 = a.size();
    ll ct=0;
    bool ff[1000009];
    rep(i,MAXA+10) ff[i]=true;
    rep(i,sz2){
        //cout<<a2[i]<<" ";
        for(ll j=2;j*a2[i]<=MAXA;j++){
            ff[j*a2[i]]=false;
        }
    }
    rep(i,sz2){
        if(MP[a2[i]]<2 && (ff[a2[i]]==true)) ct++;
    }
    printf("%lld\n",ct);
}


Measured memory_bytes: 19720
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  constexpr int kMod = 998244353;
  int N, M;
  cin >> N >> M;
  vector<int> X(N);
  for (auto& e : X) cin >> e;
  long long sum = 0;
  map<int, long long> m;
  vector<set<int>> rec(M);
  for (const auto& e : X) ++m[e], rec[e % M].insert(e);
  auto op = [&](long long a, int b) {
  	//cerr << "[op] a : " << a << ", b : " << b << ", m[b] : " << m[b] << '\n';
  	return a + m[b];
  };
  for (int i = 1; i < M / 2 + M % 2; ++i) {
  	int j = i, k = M - i;
  	auto a = accumulate(cbegin(rec[j]), cend(rec[j]), 0ll, op);
  	auto b = accumulate(cbegin(rec[k]), cend(rec[k]), 0ll, op);
  	if (b < a) swap(a, b), swap(j, k);
  	sum += a;
  	for (const auto& e : rec[k]) {
  		long long c = m[e];
  		if (b - a >= 2) {
  			int t = min(c, b - a) / 2;
  			b -= t * 2;
  			sum += t;
  		}
  	}
  }
  sum += accumulate(cbegin(rec[0]), cend(rec[0]), 0ll, op) / 2;
  if (M % 2 == 0)
    sum += accumulate(cbegin(rec[M / 2]), cend(rec[M / 2]), 0ll, op) / 2;
  cout << sum << endl;
}


Measured memory_bytes: 16256
import sys
N, K = map(int, input().split())
st = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
dis = map(int, input().split())
for i in dis:
    st.remove(i)


def dfs(num, pos, target):
    if pos == target:
        if num >= N:
            print(num)
            sys.exit()
        return
    for i in st:
        dfs(num * 10 + i, pos + 1, target)


Len = len(str(N))
dfs(0, 0, Len)
dfs(0, 0, Len+1)


Measured memory_bytes: 3064
import java.util.Scanner;
import java.math.BigDecimal;

class Main {
    public static final double pi = Math.PI;

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        double r = scanner.nextDouble();
        System.out.println( new BigDecimal(pi * Math.pow(r,2))  + " " + new BigDecimal(2*r*pi) );
        scanner.close();
    }
}



Measured memory_bytes: 28176
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll K, N;cin>>K>>N;
	ll A[N];
    REP(i,N)cin>>A[i];
    
	// 解法
	ll gap[N];
	REP(i,N){
		if (i==0) gap[i] = K - A[N-1] + A[i];
		else gap[i] =A[i] - A[i-1];
	}
	ll A_max = 0;
	REP(i,N) if (A_max<gap[i]) A_max = gap[i];
	ll ans = K - A_max;

	//出力
	printf("%lld\n", ans);
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;cin>>n;
    map<string,bool> m;
    vector<string> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    char a=v[0][v[0].length()-1];
    m[v[0]]=1;
    for(int i=1;i<n;i++){
        if(m[v[i]]){cout<<"No";return 0;}
        if(a!=v[i][0]){cout<<"No";return 0;}
        a=v[i][v[i].length()-1];
        m[v[i]]=1;
    }
    cout<<"Yes";return 0;
}

Measured memory_bytes: 256