akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const double INF = 1e10;
int n;
int b[110], x[110], y[110];

void solve() {
  for (int i = 0; i < n; i++) {
    cin >> b[i] >> x[i] >> y[i];
    b[i]--;
  }
  double G[110][110], dis[110][110];
  fill_n((double*)G, 110 * 110, INF);  
  fill_n((double*)dis, 110 * 110, INF);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      double d = hypot(x[i] - x[j], y[i] - y[j]);
      if (d > 50) continue;
      G[b[i]][b[j]] = dis[b[i]][b[j]] = d;
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dis[i][k] >= INF || dis[k][j] >= INF) continue;
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int s, g;
    cin >> s >> g;
    s--, g--;
    if (dis[s][g] >= INF) {
      cout << "NA" << endl;
    } else {
      while (s != g) {
        cout << s + 1 << " ";
        for (int j = 0; j < n; j++) {
          if (j != s && G[s][j] + dis[j][g] == dis[s][g]) {
            s = j;
            break;
          }
        }
      }
      cout << g + 1 << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> n, n) {
    solve();
  }  

  return 0;
}


Measured memory_bytes: 3436
x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return len(divisors)
  
ans = 0
while  True:
  ans = make_divisors(x)
  if ans == 2:
    break
  else:
#    continue
    x +=1

print(x)    

Measured memory_bytes: 38768
#include<iostream>
#include<map>
using namespace std;
static const int MAX_N = 200000;
typedef long long int ll;

int N, A;
map<ll, ll> mpa;

int main(){
	cin >> N;
	ll sum = 0;
	mpa[sum]++;
	for(int i = 0; i < N; i++){
		cin >> A;
		sum += A;
		mpa[sum]++;
	}
	ll ans = 0;
	for(auto e : mpa){
		ans += e.second * (e.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12800
################ DANGER ################
test = ""
#test = \
"""
atc oder
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
        
s, t = input2().split()
print(t + s)

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

int main() {
    int n;
    while (cin >> n, n) {
        vector<long long> v(n);
        for (int i=0; i<n; ++i) cin >> v[i];
        sort(v.begin(), v.end());
        vector<long long> t(n);
        t[0] = 0;
        for (int i=1; i<(int)v.size(); ++i) {
            t[i] += t[i-1] + v[i-1];
        }
        long long sum = 0;
        for (int i=0; i<(int)t.size(); ++i) {
            sum += t[i];
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1360
#include <stdio.h>

int main(void)
{
	int b[3];
	int i;
	
	for( i = 0; i < 3; i++ )
	{
		scanf( "%d", &b[i] );
	}
	
	if( (b[0] == 1 && b[1] == 1) || (b[2] == 1) )
	{
		printf( "Open\n" );
	}
	else
	{
		printf( "Close\n" );
	}
	
	return (0);
}

Measured memory_bytes: 584
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        List<Integer> s = Stream.of(sc.nextLine().split(" "))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        sc.nextLine();
        int c = (int)Stream.of(sc.nextLine().split(" "))
                .map(Integer::parseInt)
                .filter(q -> s.contains(q))
                .count();
        System.out.println(c);
    }
}




Measured memory_bytes: 35548
cho = 0
hishi = 0
while True:
    try:
        a, b, c = map(int, input().split(','))
    except:
        break
    if a**2 + b**2 == c**2 and a!=b:
        cho += 1
    elif a**2 + b**2 != c**2 and a==b:
        hishi += 1
print(cho)
print(hishi)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,c[220000],d=0;
signed main()
{
	cin>>a>>b;
	rep(i,a){
		cin>>c[i];
	}
	rep(i,a-1){
		if(c[i+1]-c[i]>=b){
			d+=b;
		}else{
			d+=c[i+1]-c[i];
		}
	}
	d+=b;
	cout<<d;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		// どちらも9以下ならA*B、どちらかが9より大きければ-1
		System.out.println(((A<=9)&&(B<=9)) ? A*B : -1);

		sc.close();
	}


}

Measured memory_bytes: 22868
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
n,m,d = map(int,input().split())
if n == 1:
    print(m-1)
elif n == 2:
    ans = (m-1) / 2
    print(ans)
else:
    if d == 0:
        print((m-1)/n)
    else:
        print(2*(n-d)*(m-1)/n/n)

Measured memory_bytes: 10476
#include <stdio.h>
int main(void){
   int a,b;
   
   scanf("%d %d",&a,&b);
   
   if(a<b) printf("a < b\n");
   else if(a>b) printf("a > b\n");
   else printf("a == b\n");
    
    return 0;
    
}


Measured memory_bytes: 2120
N,K= map(int,input().split())
ans = []
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    ans.extend(A)

ans = set(ans)

cnt = 0
for i in range(1,N+1):
    if not i in ans:
        cnt += 1
print(cnt)



Measured memory_bytes: 9264
N = tuple([int(j) for  j in input().split(' ')])

#0が含まれたら０
if N[0] <= 0 and N[1] >= 0:
    print("Zero")
elif N[0] < 0 and N[1] < 0:
    if (N[0] * - 1 - N[1] * - 1) % 2  == 0:
        print("Negative")
    else:
        print("Positive")
elif N[0] > 0 and N[1] > 0:
    print("Positive")


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		StringBuilder sb = new StringBuilder("");
		int h = s.nextInt();
		int w = s.nextInt();
		int i = 0;
		String a = "";
		String b = "";

		String ary[] = new String[h];
		for (i = 0; i < h; i++) {
			ary[i] = "#" + s.next() + "#";

		}
		String ary1[] = new String[w + 2];

		for (i = 0; i < w + 2; i++) {
			ary1[i] = "#";

			a = a + ary1[i];

		}
		System.out.println(a);
		for (i = 0; i < h; i++) {
			System.out.println(ary[i]);
		}
		System.out.println(a);

	}

}

Measured memory_bytes: 24596
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <iostream>
#include <vector>    
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n;i++)
        if(i%3==0||i%5==0)
            continue;
        else
            sum += i;
    cout << sum;

    return 0;
}

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

#define int long long

const int N = 1e5 + 10;
int dp[N];
string s, ar[4] = {"eraser", "dreamer", "erase", "dream"};

bool check(int i, int indx) {
	if (i + ar[indx].size() - 1 >= (int)s.size())
		return 0;
		
	for (int j = 0; j < ar[indx].size(); j++)
		if (s[i + j] != ar[indx][j])
			return 0;
	return 1;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	dp[(int)s.size()] = 1;
	for (int i = (int)s.size() - 1; i >= 0; i--)
		for (int j = 0; j < 4; j++)
			if (check(i, j))
				dp[i] |= dp[i + ar[j].size()];
	cout << (dp[0]? "YES\n": "NO\n");
}

Measured memory_bytes: 1232
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int F[32];
char S[128];

void ng() {
  puts("No");
  exit(0);
}

int main() {
  int H = in();
  int W = in();

  int O = (H % 2) * (W % 2);
  int E = (H % 2) * (W / 2) + (H / 2) * (W % 2);
  int Q = (H / 2) * (W / 2);

  for (int i = 0; i < H; ++i) {
    scanf("%s", S);
    for (int j = 0; j < W; ++j) {
      ++F[S[j] - 'a'];
    }
  }

  if (O > 0) {
    bool ok = false;
    for (int i = 0; i < 26; ++i) {
      if (F[i] % 2 == 1) {
        ok = true;
        --F[i];
        break;
      }
    }
    if (!ok) {
      ng();
    }
  }
  for (int i = 0; i < 26; ++i) {
    if (F[i] % 2 != 0) {
      ng();
    }
  }

  if (E > 0) {
    int rem = E;
    for (int i = 0; rem > 0 && i < 26; ++i) {
      if (F[i] % 4 == 2) {
        F[i] -= 2;
        --rem;
      }
    }
    if (rem % 2 == 1) {
      ng();
    }
    for (int i = 0; rem > 0 && i < 26; ++i) {
      while (rem > 0 && F[i] > 0) {
        F[i] -= 4;
        rem -= 2;
      }
    }
    if (rem != 0) {
      ng();
    }
  }
  for (int i = 0; i < 26; ++i) {
    if (F[i] % 4 != 0) {
      ng();
    }
  }

  puts("Yes");
  return 0;
}


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

n=int(input())

pt=0
pxy=0
for i in range(n):
    t,x,y=map(int,input().split())
    dt=t-pt
    dxy=abs(x+y-pxy)
    if dxy>dt or dt%2!=dxy%2:
        print('No')
        exit()
else:
    print('Yes')

Measured memory_bytes: 3060
#include<iostream>


using namespace std;

int main(){
  int n;
  cin >> n;
  int max = 0;
  int ans = 0;
  for(int i = 0 ; i< n; i++){
    int j;
    cin >> j;
    if(max < j) max = j;
    ans += j;
  }
  ans -= max/2;
  cout << ans << endl;
}


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

ca = [0]
cb = [0]

for ai in a:
    ca.append(ca[-1]+ai)

for bi in b:
    cb.append(cb[-1]+bi)

ans = 0
j = m

for i, cai in enumerate(ca):
    if cai > k:
        continue
    while True:
        if cai + cb[j] <= k:
            ans = max(ans, i + j)
            break
        if j == 0:
            break
        j -= 1

print(ans)


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

int main(){
  int N;
  cin>>N;
  int c[N+1];

  int h[N];
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  
  c[0]=0;
  c[1]=abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<c[N-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main() {
	ll N, D; cin >> N >>  D;
	ll cnt = 0;

	for (int i = 0; i < N; i++) {
		ll x, y; cin >> x >> y;
		if ( (x * x + y * y) > D * D) {
			continue;
		}
		else {
			cnt++;
		}
	}

	cout << cnt << endl;
}

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

map< long long, int > prime_factor(long long n) {
  map< long long, int > ret;
  for(long long i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
int main(){
  long long n,ans=0;
  cin >> n;
  for(auto p : prime_factor(n)){
    int x=p.second;
    int b=1;
    while(x>=b){
      x-=b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */

namespace Enumeration{
    //長さNのn進数表記を全列挙する
    vector<vector<long long>> base(long long n,long long N){
        long long SIZE = 1;
        for(long long i = 0;i < N;i++)SIZE *= n;
        vector<vector<long long>> ans(SIZE,vector<long long>());
        for(long long rep = 0;rep < N;rep++){
            SIZE /= n;
            for(long long i = 0;i < ans.size();i++){
                ans[i].push_back((i/SIZE)%n);
            }
        }
        return ans;
    }
    //
}

/* main */

signed main(){
	ll N;
	cin >> N;
	ll A,B,C;
	cin >> A >> B >> C;
	vl l(N);
	FOR(i,0,N){
		cin >> l[i];
	}
	vector<vl> enu = Enumeration::base(4,N);
	ll ans = LINF;
	for(auto v:enu){
		vl a,b,c;
		FOR(i,0,N){
			if(v[i] == 1)a.pb(l[i]);
			if(v[i] == 2)b.pb(l[i]);
			if(v[i] == 3)c.pb(l[i]);
		}
		if(!(a.size()&&b.size()&&c.size()))continue;
		ll tmp = 10*(a.size()+b.size()+c.size()-3);
		tmp += abs( accumulate(ALL(a),0) - A );
		tmp += abs( accumulate(ALL(b),0) - B );
		tmp += abs( accumulate(ALL(c),0) - C );
		chmin(ans,tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j;
	long long n,t;
	long long c=1;
	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t;
		if(t>c)  
        {  long long temp;
            temp=c;  
            c=t;  
            t=temp;  
        }  
        long long int k,l;  
        k=t;  
        l=c;  
        while(t!=0)  
        {  long long temp;
            temp=c%t;  
            c=t;  
            t=temp;  
        }  
        c=k/c*l;
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
# Aizu Problem 0177: Distance Between Two Cities
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


R = 6378.1
while True:
    inp = input().split()
    if inp == ['-1'] * 4:
        break
    lat1, long1, lat2, long2 = [float(_) * math.pi / 180. for _ in inp]
    dist = round(R * math.acos(math.sin(lat1)*math.sin(lat2) + \
                               math.cos(lat1)*math.cos(lat2)*math.cos(long2-long1)), 0)
    print(int(dist))

Measured memory_bytes: 7768
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

int main(){
  int n;
  string a,b,c;
  cin>>n>>a>>b>>c;
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&a[i]==c[i])continue;
    if(a[i]==b[i]||a[i]==c[i]||b[i]==c[i]){
	 ans++;
	 continue;
    }
    ans+=2;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    ll h,w,k;
    cin>>h>>w>>k;
    vector<string>s(h);
    rep(i,h)cin>>s[i];
    int ans=0;
    rep(is,1<<h)rep(js,1<<w){
        int cnt=0;
        rep(i,h)rep(j,w){
            if(is>>i&1)continue;
            if(js>>j&1)continue;
            if(s[i][j]=='#')cnt++;
        }
        if(cnt==k)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
char c[]={'R','B','G'};
int main(){
     int n;
     string s;
     cin >> n >> s;
     ll ans=0;
     for (int i=0;i < n;i++){
          map<char,int> l;
          map<char,int> r;
          l['R']=0;l['B']=0,l['G']=0;
          r['R']=0;r['B']=0,r['G']=0;
          for(int j=0;j < i;j++){
              if (s[i] != s[j]) {
                   l[s[j]]++;
              }     
          }
          for (int h=i+1;h < n;h++){
               if (s[i] != s[h]){
                    r[s[h]]++;
               }
          }
          //vector<char> c = {'R','B','G'};
          for (int x=0;x <3;x++){
               for (int y=0;y < 3;y++){
                    if (c[x] != c[y] && c[x] != s[i] && c[y] != s[i]) ans+=r[c[x]]*l[c[y]];
                    //cout << r[c[x]]*l[c[y]] << endl;
               }
          }
          //printf("left i = %d, R = %d, G = %d,B = %d\n",i,l['R'],l['G'],l['B']);
          //printf("right i = %d, R = %d, G = %d,B = %d\n",i,r['R'],r['G'],r['B']);
          int d=1;
          while(i-d >= 0 && i+d < n){
               if (s[i-d] != s[i] && s[i+d] != s[i] && s[i-d] != s[i+d]) ans--;
               d++;
          }
     }
     cout << ans << endl;
     
     return 0;
}


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

const int mod = 1e9+7;

int main(){
	int h,w,k;
	cin >> h >> w >> k;
	
	vector<vector<int>> dp(h+1, vector<int>(w,0));
	dp[0][0] = 1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			for(int k=0; k<1<<(w-1); k++){
				bool ok = true;
				for(int l=0; l<w-2; l++){
					if(((k>>l)&1) && ((k>>(l+1))&1)){
						ok = false;
					}
				}

				if(ok){
					if(j>=1 && ((k>>(j-1))&1)){
						dp[i+1][j-1] += dp[i][j];
						dp[i+1][j-1] %= mod;
					}

					else if(j<=w-2 && ((k>>j)&1)){
						dp[i+1][j+1] += dp[i][j];
						dp[i+1][j+1] %= mod;
					}

					else{
						dp[i+1][j] += dp[i][j];
						dp[i+1][j] %= mod;
					}
				}
			}
		}
	}

	cout << dp[h][k-1] << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;
static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int ac = 0, wa = 0, tle = 0, re = 0;
	for(int i=0; i<N; i++){
		string S;
		cin >> S;
		if(S == "AC"){ ac++; }
		else if(S == "WA"){ wa++; }
		else if(S == "TLE"){ tle++; }
		else if(S == "RE"){ re++; }
	}

	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);

	return 0;

}

Measured memory_bytes: 3748
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = scanner.nextInt();
		}
		Arrays.parallelSort(l);

		int count = 0;
		for (int i = 2, left, right; i < n; i++) {
			left = 0;
			right = i - 1;
			while (left < right) {
				if (l[left] + l[right] > l[i]) {
					count += right - left;
					right--;
				} else {
					left++;
				}
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 28592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main(){
	string s;
	cin >> s;
	int n = s.length();
	vector<ll> memo(n, 0), memo2(n, 0);
	memo[0] = 1; memo2[0] = 2;
	for(int i = 1; i < n; i++){
		if(s[i] == '0'){
			memo[i] = memo[i - 1] * 3;
			memo2[i] = memo2[i - 1];
		}else{
			memo[i] = memo[i - 1] * 3 + memo2[i - 1];
			memo2[i] = memo2[i - 1] * 2;
		}
		memo[i] %= 1000000007;
		while(memo[i] < 0) memo[i] += 1000000007;
		memo2[i] %= 1000000007;
		while(memo2[i] < 0) memo2[i] += 1000000007;
	}
	cout << (memo[n - 1] + memo2[n - 1]) % 1000000007 << endl;
	return 0;
}


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

string y = "POSSIBLE", n = "IMPOSSIBLE";

int e(int a, int b) {
    if (!b) return a;
    return e(b, a%b);
}

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());

    int M = a[a.size()-1];
    int G = e(a[0], a[1]);
    for (int i=2; i<N; ++i) {
        G = e(G, a[i]);
    }

    bool t = (K%G == 0 and K <= M);
    cout << ((t) ? y : n) << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int n, a;
	int sum, max;
	while (1) {
		scanf("%d", &n);
		if( n == 0)
			break;
		sum = 0;
		max = -999999;
		while (n--) {
			scanf("%d", &a);
			sum += a;
			if( sum > max)
				max = sum;
			if( sum < 0)
				sum = 0;
		}
		printf("%d\n", max);
	}
	return 0;
}

Measured memory_bytes: 600
A,B,C = map(int,input().split())
K = int(input())
for i in range(K+1):
    for j in range(K-i+1):
        for k in range(K-i-j+1):
            if A*(2**i)<B*(2**j) and B*(2**j)<C*(2**k):
                print('Yes')
                exit()

print('No')



Measured memory_bytes: 9180
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt(); //モンスターの数
    int[] H = new int[N+1];
    String result = "YES";

    for(int i=1; i<=N; i++) {
    	H[i] = scan.nextInt();
    }

    Arrays.sort(H);

    for(int i =1; i<N; i++) {
    	if(H[i]==H[i+1]) {
    		result = "NO";
    	}
    }
    System.out.println(result);
  }
}


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

int main() {
	int a,b,c,i;
	cin >> a >> b >> c;
	for(i=0; i<b; i++){
		if((a*i)%b==c){
			cout << "YES"; return 0;
		}
	}
	cout << "NO";
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void) {

	long long N, fIndex, bIndex, ftmp, btmp, ans = 0;
	bool isEnd = false;
	string c;

	cin >> N;
	cin >> c;

	fIndex = 0;
	bIndex = N - 1;
	while (!isEnd) {
		ftmp = -1;
		btmp = -1;
		for (int fi = fIndex; fi < N; fi++) {
			if (c[fi] == 'W') {
				ftmp = fi;
				break;
			}
		}
		for (int bi = bIndex; bi >= 0; bi--) {
			if (c[bi] == 'R') {
				btmp = bi;
				break;
			}
		}

		if (ftmp < 0 || btmp < 0) {
			break;
		}

		if (ftmp >= btmp) {
			isEnd = true;
			break;
		}
		else {
			c[ftmp] = 'R';
			c[btmp] = 'W';

			fIndex = ftmp;
			bIndex = btmp;

			ans++;
		}
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 3740
#include <atcoder/math>
#include <iostream>

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

int main(void) {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  rep(i, T) {
    ll N, M, A, B;
    cin >> N >> M >> A >> B;
    ll answer = atcoder::floor_sum(N, M, A, B);
    cout << answer << endl;
  }
  return 0;
}


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

inline int read()
{
	int x=0; bool f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	if(f) return x;
	return -x;
}

const int N = 5e5;
char b[N+3];
int s1[N+3],s2[N+3];
int a[N+3];
int n;

int main()
{
	scanf("%s",b+1); n = strlen(b+1)+1;
	for(int i=2; i<=n; i++) s1[i] = b[i-1]=='<'?s1[i-1]+1:0;
	for(int i=n-1; i>=1; i--) s2[i] = b[i]=='>'?s2[i+1]+1:0;
	llong ans = 0ll;
	for(int i=1; i<=n; i++)
	{
//		printf("%d %d %d\n",i,s1[i],s2[i]);
		a[i] = max(s1[i],s2[i]);
		ans += a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6528
#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<int, int>;

int main() {
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

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

  vector<int> c(n, 1);
  for (int i = 1; i < n; i += 2) c[i] *= -1;
  for (int i = 1; i < n - 1; i++) c[i] *= 2;
  sort(c.begin(), c.end());
  ll ans1 = 0;
  rep(i, n) ans1 += a[i] * c[i];

  vector<int> d(n, -1);
  for (int i = 1; i < n; i += 2) d[i] *= -1;
  for (int i = 1; i < n - 1; i++) d[i] *= 2;
  sort(d.begin(), d.end());
  ll ans2 = 0;
  rep(i, n) ans2 += a[i] * d[i];

  cout << max(ans1, ans2) << endl;
  return 0;
}


Measured memory_bytes: 4564
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
table = [[0 for w in range(W)] for h in range(H)]

table[0][0] = int(S[0][0]=='#')
for i in range(1, H):
    table[i][0] = table[i-1][0] + int(S[i-1][0]=='.' and S[i][0]=='#')
for j in range(1, W):
    table[0][j] = table[0][j-1] + int(S[0][j-1]=='.' and S[0][j]=='#')
for i in range(1, H):
    for j in range(1, W):
        table[i][j] = min(table[i-1][j] + int(S[i-1][j]=='.' and S[i][j]=='#'),
         table[i][j-1] + int(S[i][j-1]=='.' and S[i][j]=='#'))

print(table[-1][-1])

Measured memory_bytes: 42992
j = 1
a = 0
i = 0
N = 0


#N = int(input()) for _ in range(1)
A = [int(input()) for _ in range(1)]
#N=int(input())
mylist = [0]*A[0]

h = [int(x) for x in input().split()]

for i in range(A[0]):
    mylist[h[i]-1]=i+1
print(*mylist)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt[26] = {};
    for(int i = 0; i < s.size(); ++i) cnt[s[i] - 'a']++;

    for(int i = 1; i < n; ++i) {
        cin >> s;
        int tcnt[26] = {};
        for(int j = 0; j < s.size(); ++j) tcnt[s[j] - 'a']++;

        for(int j = 0; j < 26; ++j) {
            cnt[j] = min(cnt[j], tcnt[j]);
        }
    }

    for(int i = 0; i < 26; ++i) {
        for(int j = 0; j < cnt[i]; ++j) {
            cout << char('a' + i);
        }
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,t;
	cin>>a>>b>>c;
	if(a+c-1>=b-c+1) for(int i=a;i<=b;i++) cout<<i<<endl;
	else {
	for(int i=a;i<=a+c-1;i++)
	cout<<i<<endl;
	for(int i=b-c+1;i<=b;i++)
	cout<<i<<endl;
	}return 0;
}

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

using namespace std;

int dp[1001][1001];

int main()
{
	int h, w; cin >> h >> w;

	vector<string> grid(h + 1);
	for (auto i = 1; i <= h; i++) cin >> grid[i];

	dp[0][1] = 1;
	for (auto i = 1; i <= h; i++)
	{
		for (auto j = 1; j <= w; j++)
		{
			if (grid[i][j-1] == '.')
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
		}
	}

	cout << dp[h][w] << endl;
}

Measured memory_bytes: 5248
# coding: utf-8
import sys
from math import radians,cos

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    a,b,h,m = na()
    now = h*60+m
    wlong = now/2
    wshort = now*6
    c = pow(a*a+b*b-2*a*b*cos(radians(abs(wlong-wshort))),0.5)
    print(c)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 62596
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
int main(){
  int n,l; 
  cin >> n >> l;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s.at(i);
  sort(s.begin(), s.end());
  string connect ;
  for(int i=0;i<n;i++) connect += s.at(i);
  cout << connect << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a = 0;
		int b = 0;

		while(true){
			String str = br.readLine();
			String[] s = str.split(" ");

			a = Integer.parseInt(s[0]);
			b = Integer.parseInt(s[1]);
			if((a == 0)&&(b == 0)){
				break;
			}
			if((3 <= a) &&(b <= 300)){

				for(int i = 0; i < a; i++){
					for(int j = 0; j < b; j++){
						if((i == 0) || (i ==(a - 1))){
							System.out.print("#");
						}else if((j == 0) || (j == (b - 1))){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}

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


#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,m,a,r,c,h,ans;
char s[10];
vector<int> v;

main() {
    cin >> n;
    rep(i,n) {
        cin >> s;
        if (s[0] == 'M') m++;
        else if (s[0] == 'A') a++;
        else if (s[0] == 'R') r++;
        else if (s[0] == 'C') c++;
        else if (s[0] == 'H') h++;
    }
    if (m) v.pb(m)
    if (a) v.pb(a)
    if (r) v.pb(r)
    if (c) v.pb(c)
    if (h) v.pb(h)

    int vs = v.size();

    if (vs >= 3) rep(i,vs-2) repo(j,i+1,vs-1) repo(k,j+1,vs) ans += v[i] * v[j] * v[k];

    ct(ans)

}



Measured memory_bytes: 384
#include<iostream>

using namespace std;

int memo[100][100];

int main()
{
	int n;	cin>>n;
	int card[100][2];
	for(int i=0;i<n;i++){
		cin>>card[i][0]>>card[i][1];
		for(int j=0;j<n-i;j++)	memo[i][j]=(1U<<31)-1;
	}

	for(int j=0;j<n;j++)	memo[0][j]=0;
	for(int i=1;i<n;i++){
		for(int j=0;j<n-i;j++){
			for(int k=0;k<i;k++){
				int cost=card[j][0]*card[j+k][1]*card[j+k+1][0]*card[j+i][1];
				memo[i][j]=min(memo[i][j],memo[k][j]+memo[i-k-1][j+k+1]+cost);
			}
		}
	}

	cout<<memo[n-1][0]<<endl;

	return 0;
}

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

int main() {
	int n;
	int cnt{};
	string s;
	cin >> n >> s;
	vector<vector<int>> v(10);
	int a,b;
	for(int i=0; i<n; i++){
		v.at(s.at(i)-'0').push_back(i);
	}
	for(int i=0; i<=9; i++){
		if(v.at(i).empty()) continue;
		a = v.at(i).at(0);
		for(int j=0; j<=9; j++){
			if(v.at(j).empty()) continue;
			auto it1 = upper_bound(v.at(j).begin(),v.at(j).end(),a);
			if(it1==v.at(j).end()) continue;
			b = *it1;
			for(int k=0; k<=9; k++){
				if(v.at(k).empty()) continue;
				auto it2 = upper_bound(v.at(k).begin(),v.at(k).end(),b);
				if(it2==v.at(k).end()) continue;
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 512
n = int(input())
S = input()

ans = 0
for i in range(1000):
    nows = S
    istr = str(i).zfill(3)
    idx = nows.find(istr[0])
    if idx == -1:  continue
    nows = nows[idx+1:]
    idx = nows.find(istr[1])
    if idx == -1:  continue
    nows = nows[idx+1:]
    idx = nows.find(istr[2])
    if idx == -1:  continue
    ans += 1
print(ans)


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

using namespace std;

const int N = 1e5 + 5;

char str[N];

int main() {
	scanf("%s", str);
	int n = strlen(str);
	for (int i = 0; i < n - 1; ++i) {
		if (str[i] == str[i + 1]) {
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
	}
	for (int i = 0; i < n - 2; ++i) {
		if (str[i] == str[i + 2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	puts("-1 -1");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string> 
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;

	if (n * a>b)
	{
	cout << b << endl;
	}
	else
	{
	cout << n * a << endl;
	}
	return 0;
}



Measured memory_bytes: 256
def main():
    n = int(input())
    table = [list(map(int, input().split())) for _ in range(n - 1)]
    for i in range(n - 1):
        t = 0
        for j in range(i, n - 1):
            c, s, f = table[j]
            if t <= s:
                t = s + c
            else:
                if t % f != 0:
                    t += f - (t % f)
                t += c
        print(t)
    print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
from collections import Counter
S = input()
A = Counter(list(S)).most_common()

ans = float('inf')
for a in A:
    posi = -1
    interval = 0
    for i in range(len(S)):
        if S[i] == a[0]:
            interval = max(interval, i - posi - 1)
            posi = i
        if i == len(S) - 1:
            interval = max(interval, i - posi)
            posi = i
    #print(a[0], interval)
    ans = min(ans, interval)
        
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int main() {
  int Q;cin >> Q;
  repeat(q,Q){
    ll A,B;cin >> A >> B;
    if(A>B) swap(A,B);
    ll root = sqrt(A*B);
    ll ans = root*(root+1)<A*B? 2*root-1:2*root-2;
    if(A!=B&&root*root==A*B) ans--;
    cout << ans << endl;
  }
  return 0;
}


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

template <typename T>
class avl_tree {
	struct node {
		T val;
		node *ch[2];
		int dep, size;
		node(T v, node* l = nullptr, node* r = nullptr) : val(v), dep(1), size(1) {
			ch[0] = l; ch[1] = r;
		}
	};
	int depth(node *t) { return !t ? 0 : t->dep; }
	int count(node *t) { return !t ? 0 : t->size; }
	node *update(node *t) {
		t->dep = max(depth(t->ch[0]), depth(t->ch[1])) + 1;
		t->size = count(t->ch[0]) + count(t->ch[1]) + 1;
		return t;
	}
	node *rotate(node *t, int b) {
		node *s = t->ch[!b];
		t->ch[!b] = s->ch[b];
		s->ch[b] = t;
		update(t);
		return update(s);
	}
	node *fix(node *t) {
		if (!t) return t;
		int dd = depth(t->ch[0]) - depth(t->ch[1]);
		if (abs(dd) < 2) return t;
		int b = dd < 0;
		if (depth(t->ch[b]->ch[!b]) > depth(t->ch[b]->ch[b])) {
			t->ch[b] = rotate(t->ch[b], b);
		}
		return rotate(t, !b);
	}
	node *insert(node *t, T val) {
		if (!t) return new node(val);
		if (val == t->val) return t;
		int b = val > t->val;
		t->ch[b] = insert(t->ch[b], val);
		return fix(update(t));
	}
	T minimum(node *t) {
		while (t->ch[0]) t = t->ch[0];
		return t->val;
	}
	node *erase(node *t) {
		if (!t) return t;
		if (!t->ch[0] && !t->ch[1]) return nullptr;
		if (!t->ch[0]) return t->ch[1];
		if (!t->ch[1]) return t->ch[0];
		T mini = minimum(t->ch[1]);
		return fix(update(new node(mini, t->ch[0], erase(t->ch[1], mini))));
	}
	node *erase(node *t, T val) {
		if (!t) return t;
		if (val == t->val) return fix(erase(t));
		int b = val > t->val;
		t->ch[b] = erase(t->ch[b], val);
		return fix(update(t));
	}
	node *root;
public:
	avl_tree() : root(nullptr) {}
	int size() {
		return count(root);
	}
	void insert(T val) {
		root = insert(root, val);
	}
	void erase(T val) {
		root = erase(root, val);
	}
	bool count(T val) {
		node *t = root;
		while (t) {
			if (t->val == val) return true;
			t = t->ch[val > t->val];
		}
		return false;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int q;
	cin >> q;
	avl_tree<int> rbt;
	while (q--) {
		int com, x;
		cin >> com >> x;
		if (com == 0) {
			rbt.insert(x);
			printf("%d\n", rbt.size());
		}
		else if (com == 1) {
			puts(rbt.count(x) ? "1" : "0");
		}
		else {
			rbt.erase(x);
		}
	}
	return 0;
}



Measured memory_bytes: 12528
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val list = sc.asSequence().take(n).map(String::toInt).toList()
    var p = 1
    var r = 0
    (0..n).forEach {
        p = list[p - 1]
        r++
        if (p == 2) {
            println(r)
            return
        }
    }
    println(-1)
}


Measured memory_bytes: 50008
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <iomanip>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <time.h>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define X first
#define Y second

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200047;
const LD EPS = 1e-6;
const LD PI = acos(-1.0);

string S, T;
set <char> Se;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	cin >> S;
	if (SZ(S) < 26)
	{
		REP(i, 26)
			Se.insert('a' + i);
		REP(i, SZ(S))
			Se.erase(S[i]);
		cout << S << *Se.begin();
		return 0;
	}
	if (S == "zyxwvutsrqponmlkjihgfedcba")
	{
		cout << -1;
		return 0;
	}
	T = S;
	next_permutation(T.begin(), T.end());
	REP(i, SZ(S))
	{
		cout << T[i];
		if (T[i] != S[i])
			return 0;
	}
	return 0;
}

Measured memory_bytes: 768
n,d,a = map(int,input().split())
XH = []
for _ in range(n):
    x,h = map(int,input().split())
    h = (h+a-1)//a
    XH.append([x,h])
ans = 0
XH.sort()

p = 0
j = 0
data = []
for i in range(n):
    while XH[i][0] > XH[j][0] + 2*d:
        p -= data[j]
        j += 1
    if XH[i][1] > p:
        data.append(XH[i][1]-p)
        ans += XH[i][1]-p
        p = XH[i][1]
    else:
        data.append(0)

print(ans)

Measured memory_bytes: 89176
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
vector<pair<long long,long long> > v[100008];
long long dis[100008];
void out()
{
	cout<<"No";exit(0);
}
void bfs(int x)
{
	dis[x]=1e12;queue<long long> q;q.push(x);
	while(!q.empty())
	{
		long long t=q.front();
		q.pop();
		for(long long i=0;i<v[t].size();i++)
		{
			long long u=v[t][i].first;
			if(dis[u]<0)
			{
				q.push(u);dis[u]=dis[t]+v[t][i].second;
			}
			else
			{
				if(dis[u]!=dis[t]+v[t][i].second) out();
			}
		}
	}
}
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	long long n,m;cin>>n>>m;
	while(m--)
	{
		long long a,b,c;cin>>a>>b>>c;v[a].push_back(make_pair(b,c));swap(a,b);c=-c;v[a].push_back(make_pair(b,c));
	}for(long long i=0;i<100008;i++) dis[i]=-1;
	for(int i=0;i<n;i++)if(dis[i]==-1)bfs(i);cout<<"Yes";return 0;
	return 0;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
constexpr int MAXN = 2000005;

int fact[MAXN];
int ifact[MAXN];

int Add(int x, int y) {
    x += y;
    return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
    x -= y;
    return x >= 0 ? x : x + MOD;
}

int Mul(int x, int y) {
    return int(1LL * x * y % MOD);
}

int FastPow(int x, int p) {
    int res = 1;
    while (p > 0) {
        if (p & 1) {
            res = Mul(res, x);
        }
        p >>= 1;
        x = Mul(x, x);
    }
    return res;
}

int Inv(int x) {
    return FastPow(x, MOD - 2);
}

int C(int k, int n) {
    return Mul(fact[n], Mul(ifact[k], ifact[n - k]));
}

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    fact[0] = fact[1] = 1;
    for (int i = 2; i < MAXN; ++i) {
        fact[i] = Mul(i, fact[i - 1]);
    }
    ifact[MAXN - 1] = Inv(fact[MAXN - 1]);
    for (int i = MAXN - 2; i >= 0; --i) {
        ifact[i] = Mul(ifact[i + 1], i + 1);
    }
    int k;
    string s;
    cin >> k >> s;
    int n = k + sz(s);
    int ans = 0;
    for (int i = sz(s); i <= n; ++i) {
        ans = Add(ans, Mul(Mul(C(sz(s) - 1, i - 1), FastPow(25, i - sz(s))), FastPow(26, n - i)));
    }
    cout << ans << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 19884
#include <bits/stdc++.h>
#define ll long long int


using namespace std;

int main()
{
    ll t,n,item,temp,a,b,c,x,y,z,sum,flag,k;
    string s,s1,s2;
    vector<ll>v;
    vector<string>vs;
    map<ll,ll>mp;
    map<ll,ll>check;

    cin>>a>>b;
    if(b==0)
    {
        cout<<a<<endl;
        return 0;
    }
   for(ll i=0;i<b;i++)
   {
       cin>>item;
       mp[item]++;
   }
   if(mp[a]==0)
   {
       cout<<a<<endl;
       return 0;
   }
   temp=100000000000;
   x=a+1;
   y=a-1;
   ll flag1=0;
   flag=0;
   ll temp1=100000000;
   ll temp2=1000000000;
   while(1)
   {
       if(mp[x]==0 && flag==0)
       {
           temp1=min(temp1,x);
           flag=1;
       }
       if(mp[y]==0 && flag1==0)
       {
           flag1=1;
           temp2=min(temp2,y);
       }
       if(flag1 && flag)
        break;
       y--;
       x++;



   }
   if(abs(temp1-a)>=abs(temp2-a))
    cout<<temp2<<endl;
    else
    cout<<temp1<<endl;



    return 0;
}


Measured memory_bytes: 3632
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(tuple(map(int,input().split())))
a.sort()
count=0
for i in range(n):
  m-=a[i][1]
  count+=a[i][0]*a[i][1]
  if m<=0:
    count+=a[i][0]*m
    print(count)
    break

Measured memory_bytes: 16988