akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int an[SIZE];
int C[SIZE],s[SIZE],f[SIZE];
int main(){
    int N;R(N);
    REP(i,N-1)R(C[i],s[i],f[i]);
    REP(i,N-1){
        int v=0;
        REPP(j,i,N-1){
            if(v<=s[j])v=s[j];
            if(v%f[j])v=(v/f[j]+1)*f[j];
            v+=C[j];
        }
        an[i]=v;
    }
    REP(i,N)W(an[i]);
    return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; i--)
#define REP(i, k, n) for(int i=(int)(k); i<(int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const int INF = INT_MAX;
const ll inf = 1e18;
const ll mod = 998244353;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

int main(){
	ll N, A[3]; cin >> N >> A[0] >> A[1] >> A[2];
	if(A[0]+A[1]+A[2] == 0){
		cout << "No" << endl;
		return 0;
	}
	string s[N];
	int ans[N];
	rep(i, N) cin >> s[i];
	ll sum = A[0]+A[1]+A[2];
	int f = 1;
	if(sum==1){
		rep(i, N){
			int p = s[i][0] - 'A';
			int q = s[i][1] - 'A';
			if(A[p] == 0 && A[q] == 0){
				f = 0;
			}else if(A[p]==0){
				ans[i] = p;
				A[p]=1, A[q]=0;
			}else if(A[q] == 0){
				ans[i] =q;
				A[p]=0, A[q]=1;
			}
		}
		if(f){
			cout << "Yes" << endl;
			rep(i, N){
				char cc = 'A' + ans[i];
				cout << cc << endl;
			}
		}else cout << "No" << endl;
	}else{
		int di[N];
		di[N-1] = -1;
		for(int i=N-2; i>=0; i--){
			if(s[i] == s[i+1]) di[i] = di[i+1];
			else di[i] = i+1;
		}
		rep(i, N){
			int p = s[i][0] - 'A';
			int q = s[i][1] - 'A';
			if(A[p] == 0 && A[q] == 0){
				f = 0;
			}else if(A[p]==0){
				ans[i] = p;
				A[p]++, A[q]--;
			}else if(A[q] == 0){
				ans[i] = q;
				A[p]--, A[q]++;
			}else{
				if(di[i] == -1){
					ans[i] = p;
					A[p]++;
					A[q]--;
				}else{
					int y = s[di[i]][0]-'A';
					int z = s[di[i]][1] - 'A';
					if(y != p && y != q){
						ans[i] = z;
						A[z]++; A[p+q-z]--;
					}else{
						ans[i] = y;
						A[y]++; A[p+q-y]--;
					}
				}
			}
		}
		if(f){
			cout << "Yes" << endl;
			rep(i, N){
				char cc = 'A' + ans[i];
				cout << cc << endl;
			}
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7424
s = input()
k = int(input())
l = sorted(list(set(list(s))))
x = set(list())
for i in l:
    x |= set([s[ii:iii+1] for ii in range(len(s)) for iii in range(ii,min(len(s),ii+5)) if s[ii] == i])
    if len(x) > 5:
        break
x = sorted(x)

print(x[k-1])

Measured memory_bytes: 4324
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main(void) {
	int n;
	long long ans=0;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	for(int i=0; i<n; i++){
		if(n%2==0){
			if(i+1==n-1-i){
				ans+=a[n-1-i]-a[i];
				break;
			}else {
				ans+=2*(a[n-1-i]-a[i]);
			}
		}else {
			if(i+2==n-1-i){
				ans+=max(2*a[i+2]-a[i+1]-a[i],a[i+2]+a[i+1]-a[i]*2);
				break;
			}else {
				ans+=2*(a[n-1-i]-a[i]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int dp[105][10];
int h,w,k;
vector<vector<int> >V;
int main(){
	cin>>h>>w>>k;
	dp[0][1] = 1;
	for(int i=0;i<(1<<(w-1));i++){
		vector<int>vec;
		for(int j=0;j<w-1;j++){
			if(((i>>j)&1)){
				vec.pb(j);
			}
		}
		int fail = 0;
		for(int j=1;j<vec.size();j++){
			if(vec[j]-vec[j-1] == 1) fail = 1;
		}
		if(fail) continue;
		vector<int>vi;
		repn(j,w) vi.pb(j);
		rep(j,vec.size()){
			swap(vi[vec[j]],vi[vec[j]+1]);
		}
		V.pb(vi);
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(dp[i-1][j] == 0) continue;
			rep(k,V.size()){
				int nxt = -1;
				rep(l,V[k].size()) if(V[k][l] == j) nxt = l+1;
				dp[i][nxt] += dp[i-1][j];
				if(dp[i][nxt] >= mod) dp[i][nxt] -= mod;
			}
		}
	}
	cout << dp[h][k] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	string n;
	cin >> n;
	if (n.size() == 1) {
		cout << n << endl;
		return 0;
	}
	rep(i, n.size()-1) {
		if (n[i + 1] != '9') {
			goto skip;
		}
	}
	cout << (n.size() - 1) * 9 + n[0] - '0' << endl;
	return 0;
	skip:
	cout << (n.size() - 1) * 9 + n[0]-'0' - 1 << endl;
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s, t;
    getline(cin,s);
  	getline(cin, t);
    int n = s.length();
    int flag = 1;
    for (int i = 0; i< n; i++){
        if (s[i] != t[i]){
            flag = 0;
            break;
        }
    }
    if ((t.length()-1 == n) && (flag)) puts("Yes");
    else puts("No");
    return 0;
}




Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


void f () {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> dp(s.size(), vector<int>(t.size()));
  tuple<int, int, int> tup(0, 0, 0);

  rep (i, t.size()) if(s[0] == t[i]) dp[0][i] = 1;
  rep (i, s.size()) if(t[0] == s[i]) dp[i][0] = 1;
  for (int i=1; i<s.size(); ++i) for (int j=1; j<t.size(); ++j) {
    if (s[i] == t[j]) dp[i][j] = 1;
    if (get<0>(tup) < dp[i][j]) tup = tie(dp[i][j], i, j);
  }

  for (int i=1; i<dp[0].size(); ++i) if (dp[0][i-1] == 1) dp[0][i] = 1;
  for (int i=1; i<dp.size(); ++i) if (dp[i-1][0] == 1) dp[i][0] = 1;
  for (int i=1; i<dp.size(); ++i) for (int j=1; j<dp[i].size(); ++j) {
    if (dp[i][j] == 0) dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    else dp[i][j] = dp[i-1][j-1] + 1;
  }

  cout << dp[s.size() - 1][t.size() - 1] << endl;
}


int main() {
  int q;  cin >> q;
  
  rep (i, q) f();
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int c[m];
    for (int i = 0; i < m; i++)
    {
        cin >> c[i];
    }
    int dp[m + 1][n + 1];
    for (int i = 0; i <= n; i++)
    {
        dp[0][i] = i;
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (j - c[i] >= 0)
            {
                dp[i + 1][j] = min({dp[i][j - c[i]] + 1, dp[i + 1][j - c[i]] + 1, dp[i][j]});
            }
            else
            {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[m][n] << endl;
}



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

int main(){

    double w,a,b,ans;

    cin >> w >> a >> b;

    if(a+w>=b && b+w >= a){
        ans = 0;
    }else{
        ans = min(fabs(b-a-w),fabs(b+w-a));
    }
    
    cout << int(ans) << endl;

    return 0;
}

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

using namespace std;

int main()
{
	string s;
	int count = 0;
	cin >> s;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == '1')
		{
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    std::string S;
	std::cin >> S;
	int64_t ans;
	if (S == "RRR") ans = 3;
	if (S == "RRS") ans = 2;
	if (S == "SRR") ans = 2;
	if (S == "RSR") ans = 1;
	if (S == "RSS") ans = 1;
	if (S == "SRS") ans = 1;
	if (S == "SSR") ans = 1;
	if (S == "SSS") ans = 0;
	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define F first
#define S second
#define fori(l, n) for(int i = l; i < n; i++)
#define forj(k, m) for(int j = k; j < m; j++)
#define revi(h) for(int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout<<"DEBUGGING --- "<<x<<endl;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);
signed main(){
    fastio;
	// input_from_file; 
	// output_to_file;
    int n;
    cin>>n;
    vector<int>A(n + 1); vector<int>B(n + 1); vector<int>C(n + 1);
    fori(1, n + 1) cin>>A[i]>>B[i]>>C[i];
    vector<vector<int>>DP(n + 1, vector<int>(4));
    DP[1][1] = A[1];
    DP[1][2] = B[1];
    DP[1][3] = C[1];
    fori(2, n + 1){
        DP[i][1] = A[i] + max(DP[i - 1][2], DP[i - 1][3]);
        DP[i][2] = B[i] + max(DP[i - 1][1], DP[i - 1][3]);
        DP[i][3] = C[i] + max(DP[i - 1][1], DP[i - 1][2]);
    }
    cout<<max(DP[n][1], max(DP[n][2], DP[n][3]))<<endl;
} 

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

int n, k, a[200200], minVal[200200][20], maxVal[200200][20], lg2[500500];

void init()
{
  for (int i = 0; i < n; i++)
    minVal[i][0] = maxVal[i][0] = a[i];

  for (int j = 0; j < 18; j++)
    for (int i = 0; i + (1 << j + 1) <= n; i++)
    {
      minVal[i][j + 1] = min(minVal[i][j], minVal[i + (1 << j)][j]);
      maxVal[i][j + 1] = max(maxVal[i][j], maxVal[i + (1 << j)][j]);
    }

  for (int j = 0; j < 18; j++)
     for (int i = 1 << j; i < 1 << j + 1; i++)
       lg2[i] = j;
}

pair<int, int> get(int l, int r)
{
  int curLg2 = lg2[r - l + 1];
  int resMin = min(minVal[l][curLg2], minVal[r - (1 << curLg2) + 1][curLg2]);
  int resMax = max(maxVal[l][curLg2], maxVal[r - (1 << curLg2) + 1][curLg2]);
  return {resMin, resMax};
}

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

  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  a[n] = n + 1;

  init();

  int ans = 0, hasSorted = 0;
  for (int i = 1, len = 1; i < n; i++)
  {
    if (a[i] > a[i - 1]) len++;
    else len = 1;

    if (i == k - 1) ans++;
    else if (i >= k)
    {
      auto u = get(i - k + 1, i - 1);
      if (len < k || !hasSorted)
        if (u.first < a[i - k] || u.second > a[i])
          ans++;
    }

    if (len >= k)
      hasSorted = 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 33408
#include<stdio.h>
int main(void)
{
	int i,j,p,a,b,h,m,cnt=0,hun[200],temp;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d %d",&h,&m); 
		hun[i]=h*60+m;
	}
	scanf("%d",&b);
	for(i=a;i<a+b;i++){
		scanf("%d %d",&h,&m);
		hun[i]=h*60+m;
	}
	for(i=0;i<a+b-1;i++){
		for(j=i+1;j<a+b;j++){
			if(hun[i]>hun[j]){
				temp=hun[i];
				hun[i]=hun[j];
				hun[j]=temp;
			}
		}
	}
	p=hun[0];
	for(i=1;i<a+b;i++){
		if(p==hun[i]){
			cnt++;
		}
		else{
			hun[i-cnt]=hun[i];
			p=hun[i];
		}
	}
	for(i=0;i<a+b-1-cnt;i++){
		printf("%d:%02d ",hun[i]/60,hun[i]%60);
	}
	printf("%d:%02d\n",hun[i]/60,hun[i]%60);
	return 0;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
int f[200005];
int pw(int x,int b)
{
	int res=1,nw=x;
	while(b)
	{
		if(b&1)res=1ll*res*nw%md;
		nw=1ll*nw*nw%md;
		b/=2;
	}
	return res;
}
int main()
{
	int n,m,a,b,ans=0;
	scanf("%d%d%d%d",&n,&m,&a,&b);
	f[0]=1;
	for(int i=1;i<=n+m;i++)f[i]=(1ll*f[i-1]*i)%md;
	for(int i=1;i<=n-a;i++)
	{
		int x=f[i+b-2],y=f[n+m-i-b-1];
		int dx=1ll*f[i-1]*f[b-1]%md,dy=1ll*f[n-i]*f[m-b-1]%md;
		ans=(ans+1ll*(1ll*x*pw(dx,md-2)%md)*(1ll*y*pw(dy,md-2)%md)%md)%md;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def check(m, k, vs):
    s = 0
    for x, y, v in vs:
        if v >= m:
            s += (v - m + y - 1) // y
    return s <= k


n, k = read_i()
ls0 = sorted(read_i())
ls1 = sorted(read_i(), reverse=True)
if sum(ls0) <= k:
    print(0)
    exit()

vs = [(x, y, x * y) for x, y in zip(ls0, ls1)]

lo = 0
hi = sum(v for _, _, v in vs)
while hi - lo > 1:
    mid = (lo + hi) // 2
    if check(mid, k, vs):
        hi = mid
    else:
        lo = mid
print(hi)

Measured memory_bytes: 127052
import time
import random


class TreapNode:
    def __init__(self, key, pri):
        self.left = None
        self.right = None
        self.key = key
        self.pri = pri


class Treap:
    def __init__(self):
        self.root = None

    def search_lower(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk < key:
                ret = pk
                ptr = ptr.right
            else:
                ptr = ptr.left
        return ret

    def search_higher(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk > key:
                ret = pk
                ptr = ptr.left
            else:
                ptr = ptr.right
        return ret

    def insert(self, key):
        pri = random.randrange(0, 2**64)
        ptr = self.root
        elem = TreapNode(key, pri)
        if ptr is None or ptr.pri < pri:
            self.root = elem
        else:
            while True:
                if key < ptr.key:
                    left = ptr.left
                    if left is None or left.pri < pri:
                        ptr.left = elem
                        ptr = left
                        break
                    ptr = left
                else:
                    right = ptr.right
                    if right is None or right.pri < pri:
                        ptr.right = elem
                        ptr = right
                        break
                    ptr = right
        left = elem
        right = elem
        while ptr is not None:
            if key < ptr.key:
                right.left = ptr
                right = ptr
                ptr = ptr.left
            else:
                left.right = ptr
                left = ptr
                ptr = ptr.right
        left.right = None
        right.left = None
        elem.left, elem.right = elem.right, elem.left

# デバッグ用
    def dump(self):
        self.__dump(self.root, 0)

    def __dump(self, idx, dep):
        if idx is not None:
            self.__dump(idx.right, dep + 1)
            for _ in range(0, dep):
                print("   ", end="")
            print([idx.key, idx.pri])
            self.__dump(idx.left, dep + 1)

def main():
    n = int(input())
    p = list(map(int, input().split()))
    idx = [0] * n
    for i in range(0, n):
        idx[i] = i
    idx.sort(key=lambda i: - p[i])
    t = Treap()
    t.insert(-1)
    t.insert(n)
    ans = 0
    for i in idx:
        nex = t.search_higher(i)
        nexnex = t.search_higher(nex)
        pre = t.search_lower(i)
        prepre = t.search_lower(pre)
        if prepre != None:
            ans += p[i] * (pre - prepre) * (nex - i)
        if nexnex != None:
            ans += p[i] * (i - pre) * (nexnex - nex)
        t.insert(i)
    print(ans)


main()


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

Measured memory_bytes: 596
def C(n,m):return 0 if n<m else fact[n]*inv[m]%MOD*inv[n-m]%MOD
MOD=1000000007
n=int(raw_input())
fact=[1]*(n+1)
inv=[1]*(n+1)
for i in range(1,n+1):fact[i]=fact[i-1]*i%MOD
inv[n]=pow(fact[n],MOD-2,MOD)
for i in range(n,0,-1):inv[i-1]=inv[i]*i%MOD
ans=0
for i in range(1,n):ans+=C(i-1,n-i-1)*fact[i]%MOD*fact[n-i-1]%MOD
print(fact[n-1]*n-ans%MOD+MOD)%MOD

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B, C;
    cin >> A >> B >> C;
    if(A == B) cout << C;
    else if(B == C) cout << A;
    else cout << B;
    cout << endl;
    return 0;
}


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

using namespace std;

const int N = 1e5+5;

#define x first
#define y second

int n;
pair< int, int > a[2*N];
pair< pair<int, int>, int > c[N];
long long l, r;

signed main() {
	l = r = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i*2].x, &a[i*2+1].x);
		c[i].x.x = a[i*2+1].x + a[i*2].x;
		c[i].x.y = min(a[i*2+1].x, a[i*2].x);
		a[i*2+1].y = a[i*2].y = c[i].y = i;
		l += a[i*2].x;
		r += a[i*2+1].x;
	}
	long long res = 0;
	sort(a, a+n+n);
	sort(c, c+n);
	set< int > lul;
	for (int i = 0; i < n; i++) {
		lul.insert(a[i].y);
		res += a[i].x;
	}
	if (lul.size() != n) {
		cout << min(res, min(r, l));
	}
	else {
		long long cur = res;
		if (a[n-1].y == c[0].y) {
			res = cur - a[n-2].x + c[0].x.x - a[n-1].x;
		}
		else {
			res = cur - a[n-1].x + c[0].x.x - c[0].x.y;
		}
		for (int i = 1; i < n; i++) {	
			if (a[n-1].y == c[i].y) {
				res = min(res, cur - a[n-2].x + c[i].x.x - a[n-1].x);
			}
			else {
				res = min(res, cur - a[n-1].x + c[i].x.x - c[i].x.y);
			}
		}
		cout << min(res, min(l, r));
	}
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
string str;
int c[7][7],d[7][7];
int main()
{
    int n,w,r,ans=0;
    scanf("%d%d%d",&n,&w,&r);
    for(int i=1;i<=n;i++)
    {
        cin>>str;
        for(int j=1;j<=w;j++)
            if(str[j-1]=='.')c[i][j]=0;
            else c[i][j]=1;
    }
    for(int i=0;i<(1<<(n+w));i++)
    {
        int sum=0;
        for(int j=1;j<=n;j++)
            for(int k=1;k<=w;k++)
                d[j][k]=c[j][k];
        for(int j=1;j<=n;j++)
            if(i&(1<<(j-1)))
                for(int k=1;k<=w;k++)
                    d[j][k]=2;
        for(int j=1;j<=w;j++)
            if(i&(1<<(j-1+n)))
                for(int k=1;k<=n;k++)
                    d[k][j]=2;
        for(int j=1;j<=n;j++)
            for(int k=1;k<=w;k++)
                if(d[j][k]==1)
                    sum++;
        //cout<<sum<<endl;
        if(sum==r)ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3828
N, K = map(int, input().split())
num = list(map(int, input().split()))

now = 0
ans = 0
X = 0

list_10 = []

keta = 0
while(True):
  if 2**keta > K:
    
    break
  keta+=1

while(num != [0]*N):
  count_1 = 0
  count_0 = 0
  for i in range(N):
    if num[i] % 2 == 1:
      count_1 += 1
    else:
      count_0 += 1
    num[i] = num[i] // 2

  list_10.append([count_1, count_0])

  now += 1

if keta > len(list_10):
  for _ in range(keta-len(list_10)):
    list_10.append([0, N])

now = len(list_10)-1
for i in list_10[::-1]:
  if i[0] >= i[1]:
    ans += (2**now) * i[0]
  else:
    if X + 2**now > K:
      ans += (2**now) * i[0]
    else:
      ans += (2**now) * i[1]
      X += 2**now
  now-=1
  
print(ans)


Measured memory_bytes: 14620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k;
    cin >> n >> k;
    vector<int> negative, positive;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        if(x < 0)   negative.push_back(-x);
        else if(x == 0) --k;
        else    positive.push_back(x);
    }
    sort(negative.begin(), negative.end());
    int n1 = negative.size();
    int n2 = positive.size();
    if(n1 == 0 && n2 == 0){
        cout << 0 << "\n";
        return 0;
    }
    if(n1 == 0){
        cout << positive[k-1] << "\n";
        return 0;
    }
    if(n2 == 0){
        cout << negative[k-1] << "\n";
        return 0;
    }
    int res = INF;
    for(int i = 0; i < min(k, n1); ++i){
        if(k - i - 1 > n2 || k - i - 1 <= 0)    continue;
        chmin(res, negative[i] + 2 * positive[k - i - 2]);
    }
    for(int i = 0; i < min(k, n2); ++i){
        if(k - i - 1 > n1 || k - i - 1 <= 0)    continue;
        chmin(res, positive[i] + 2 * negative[k - i - 2]);
    }
    cout << res << "\n";
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,x,ans;
string s;
int main(void){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x++;
            ans=max(ans,x);
        }else{
            x--;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (S.at(i) == '1') cnt++;
	}

	cout << cnt << endl;
}

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

int main() {

  int sum,N,i;
  int l,r;
  sum = 0;
  
  cin >> N;
  
  for(i=0;i<N;i++){
	cin >> l >> r;
    sum +=  r - l +1;
  }
  cout << sum <<endl;
}
  
  
  

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

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

    long long power=1;
    for(int i=1;i<=n;i++){
        power = (power*i)%int(pow(10,9)+7);
    }

    cout << power << endl;

}

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

int main()
{
    int N;cin >> N;
    vector<int> A(N),B(N);
    for (int i=0;i<N;i++)
    {
        cin >> A[i] >> B[i];
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    if (N%2==1)
    {
        cout << B[N/2]-A[N/2]+1 << endl;
    }
    else
    {
        cout << B[N/2]+B[N/2-1]-A[N/2]-A[N/2-1]+1 << endl;
    }
    
}

Measured memory_bytes: 4788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int max = 0;
        int second = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();

            if (A[i] >= max) {
                second = max;
                max = A[i];
            } else if (A[i] >= second) {
                second = A[i];
            }
        }

        for (int i = 0 ; i < N ; i++) {
            if (A[i] == max) {
                System.out.println(second);
            } else {
                System.out.println(max);
            }
        }
    }
}


Measured memory_bytes: 72944
#include <stdio.h>

int main(void){
	int a, b;
	int quo, rem;
	double quof;
	
	scanf("%d %d", &a, &b);
	quo = a / b;
	rem = a % b;
	quof = (double)(a) / (double)(b);
	
	printf("%d %d %.5f", quo, rem, quof);
	
	return 0;
}

Measured memory_bytes: 640
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	string s;
	cin>>s;
	bool a=false,b=false;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='A')
		{
			a=true;
		}
		else if(s[i]=='B')
		{
			b=true;
		}
	}
	if(a&&b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def manhattan(p0, p1):
    return abs(p0[0]-p1[0])+abs(p0[1]-p1[1])


def solve():
    """
    """
    H, W, D = read_ints()
    arr = [None for _ in range(H*W)]
    for i in range(H):
        for j, a in enumerate(read_ints()):
            arr[a-1] = (i, j)
    prefix = [0]*(H*W)
    for i in range(D):
        for j in range(i+D, H*W, D):
            prefix[j] = prefix[j-D]+manhattan(arr[j], arr[j-D])
    Q = read_int()
    for _ in range(Q):
        l, r = read_ints()
        print(prefix[r-1]-prefix[l-1])




if __name__ == '__main__':
    solve()


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

int main()
{
  string str;

  while (cin >> str){
    bool o = false, x = false;
    for (int i = 0; i < 3; i++){
      if (str[i] == str[i + 3] && str[i + 3] == str[i + 6]){
        if (str[i] == 'o')  o = true;
        else if (str[i] == 'x')  x = true;
  
      }
      if (str[i * 3] == str[i * 3 + 1] && str[i * 3 + 1] == str[i * 3 + 2]){
        if (str[i * 3] == 'o')  o = true;
        else if (str[i * 3] == 'x') x = true;
        
      }
    }
    if (str[0] == str[4] && str[4] == str[8]){
      if (str[0] == 'o')  o = true;
      else if (str[0] == 'x') x = true;
    }
    else if (str[2] == str[4] && str[4] == str[6]){
      if (str[2] == 'o')  o = true;
      else if (str[2] == 'x') x = true;
    }
    if (o)  cout << 'o';
    else if (x) cout << 'x';
    else  cout << 'd';
    cout << endl;
  }
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<long double> p(n);
    rep(i, n) cin >> p[i];
    vector<long double> dp(n+1);
    dp[0] = 1;
    rep(i, n) {
        vector<long double> pre(n+1);
        swap(dp, pre);
        rep(j, n) {
            dp[j+1] += pre[j] * p[i];
            dp[j] += pre[j] * (1.0L - p[i]);
        }
    }
    long double ans = 0;
    for (int i = n/2 + 1; i <= n; ++i) ans += dp[i];
    cout << fixed << setprecision(15) << ans << endl;
}

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

int main() {
  int n,num;
  int cnt = 0;
  vector<int> vec(9);
  vector<int> bingo(9,0);
  
  for(int i = 0; i < 9; i++) cin >> vec.at(i);
  cin >> n;
  
  // チェック
  for(int i = 0; i < n; i++){
    cin >> num;
    for(int j = 0; j < 9; j++){
      if(vec.at(j) == num) bingo.at(j) = 1;
    }
  }
  
  // ビンゴ確認
  // 縦
  for(int i = 0; i < 3; i++){
    if(bingo.at(i) + bingo.at(i+3) + bingo.at(i+6) == 3) cnt++;
  }
  // 横
  for(int i = 0; i <= 6; i+=3){
    if(bingo.at(i) + bingo.at(i+1) + bingo.at(i+2) == 3) cnt++;
  }
  // 斜め
  if(bingo.at(0) + bingo.at(4) + bingo.at(8) == 3) cnt++;
  if(bingo.at(2) + bingo.at(4) + bingo.at(6) == 3) cnt++;
  
  if(cnt > 0) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#define ll unsigned long long
using namespace std;
const int maxn=1e5+7;
ll x[maxn],p[maxn];
int n;ll s;
struct node
{
	ll time;int dir;
};
node find(int l,int r)
{
	node res;
	if(l==r) 
	{
		if(x[l]>s) {res.time=x[l]-s;res.dir=1;}
		if(x[l]<s) {res.time=s-x[l];res.dir=-1;}
	}
	else if(s<x[l])
	{
		res.dir=1;
		res.time=x[r]-s;
	}
	else if(s>x[r])
	{
		res.dir=-1;
		res.time=s-x[l];
	}
	else if(p[l]<p[r])
	{
		p[r]+=p[l];
//		node k=find(l+1,r);
		res = find(l+1, r);
		if(res.dir==1) res.time+=(x[r]-x[l]);
		else res.time+=x[l+1]-x[l];
		res.dir=-1;
	}
	else if(p[l]>=p[r])
	{
		p[l]+=p[r];
		res=find(l,r-1);
		if(res.dir==-1) res.time+=(x[r]-x[l]);
		else res.time+=x[r]-x[r-1];
		res.dir=1;
	}
	return res;
}
int main()
{
	cin>>n>>s;
	for(int i=1;i<=n;i++) cin>>x[i]>>p[i];
	cout<<find(1,n).time<<endl;
	return 0;
}

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

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int M = 107;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, k, c;

main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        int a;
        scanf("%d", &a);
        if (a >= k)
            c++;
    }
    cout << c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> fac;
  n *= 2ll;
  ll m = n;
  for(ll i = 2; i*i <= m; ++i){
    if(m%i == 0){
      ll fi = 1;
      while(m%i == 0){
        m /= i;
        fi *= i;
      }
      fac.push_back(fi);
    }
  }
  if(m > 1) fac.push_back(m);
  ll d = fac.size();
  ll ans = n-1;
  for(ll di = (1<<d)-2; di > 0; --di){
    ll t1 = 1;
    for(ll i = 0; i < d; ++i){
      if(di&(1ll<<i)) t1 *= fac[i];
    }
    ll t2 = n/t1;
    if(t2 > t1) continue;
    for(ll i = t1; i <= ans+1; i += t1){
      if((i-1)%t2 == 0){
        ans = min(ans,i-1);
        break;
      }
      if((i+1)%t2 == 0){
        ans = min(ans,i);
        break;
      }
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3660
a=list(map(int,list(input())))
s=[]
for i in range(2**3):
    calc=a[0]
    s=[str(a[0])]
    for j in range(3):
        if i>>j&1:
            calc+=a[j+1]
            s.append('+')
        else:
            calc-=a[j+1]
            s.append('-')
        s.append(str(a[j+1]))
    if calc==7:
        break
print(''.join(s)+'=7')

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

int main(void){
  char buf[64] = { 0 };
  int A,B,C;
  
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d %d %d", &A, &B, &C);
  
  int flag = 0;
  for(int i = 0; i < A; i++){
    int ans = (i * B + C) % A;
    if(ans == 0){
      flag = 1;
      break;
    }
  }
  
  if(flag) printf("YES\n");
  else printf("NO\n");
  return 0;
}


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

int main() {
    string s, t, s_cp;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    s_cp = s;
    replace(s_cp.begin(), s_cp.end(), '?', 'a');

    vector<string> matches;
    rep(i, n - m + 1) {
        string a = s.substr(i, m);
        bool matched = true;
        rep(j, m) if (a[j] != '?' && a[j] != t[j]) matched = false;

        if (matched)
            matches.push_back(s_cp.substr(0, i) + t + s_cp.substr(i + m));
    }

    if (matches.size() == 0)
        cout << "UNRESTORABLE" << endl;
    else {
        sort(matches.begin(), matches.end());
        cout << matches[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

int a[N], cnt[N], ans = 0;

void add(int pos) {
	ans += cnt[pos];
	cnt[pos]++;
}

void del(int pos) {
	cnt[pos]--;
	ans -= cnt[pos];
}

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i];
		add(a[i]);
	}
	for(int i=0;i<n;i++) {
		del(a[i]);
		cout << ans << endl;
		add(a[i]);
	}
	
}





Measured memory_bytes: 4736
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const ll INF = LLONG_MAX;
// const int MOD = (int)1e9 + 7;
// const double EPS = 1e-10;
#define PI acosl(-1)
#define MAX_N 100 + 2

void exec(){
  int n, m;
  int a[MAX_N], b[MAX_N];
  cin >> n >> m;
  for (int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  for (int i = 0; i < n; i++){
    int ans = 0;
    for (int j = 0; j < m; j++){
      if (a[j] == i || b[j] == i){
        ans++;
      }
    }
    cout << ans << endl;
  }
}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='+' or op=='-' or op=='*' or op=='/':
        if op=='+':
            print(a+b)
        if op=='-':
            print(a-b)
        if op=='*':
            print(int(a*b))
        if op=='/':
            print(int(a/b))
    else:
        break


Measured memory_bytes: 5596
#include <stdio.h>
#include <string.h>
int t[1001][1001];

int main(){
  char X[1000],Y[1000];
  int i, j, n, x, y, k;

  scanf("%d",&n);

  for(k=0; k<n; k++){
    scanf("%s%s",X+1,Y+1);
    x=strlen(X+1);
    y=strlen(Y+1);

    for(i=1; i<=x; i++)
      for(j=0; j<=y;j++)
	t[i][j]=0;

    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){
	if(X[i] == Y[j])  t[i][j]=t[i-1][j-1]+1;
	else if(t[i-1][j]>=t[i][j-1]) t[i][j]=t[i-1][j];
	else t[i][j]=t[i][j-1];
      }
    }
    printf("%d\n", t[i-1][j-1]);
  }
  return 0;
}

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

int main(){
  int k,s;
  cin >> k >> s;
  
  int ans = 0;
  rep(x,k){
    rep(y,k){
      int z = s - (x + y);
      if(0 <= z && z <= k) ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int m = in.nextInt();
        int[] obs = new int[n];
        in.nextLine();
        for (int i = 0; i < n; i++) {
            obs[i] = in.nextInt();
        }
        in.nextLine();
        Map<Integer, List<Integer>> roads = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            roads.computeIfAbsent(a, v -> new ArrayList<>()).add(b);
            roads.computeIfAbsent(b, v -> new ArrayList<>()).add(a);
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            int currH = obs[i];
            boolean good = true;
            for (int next : roads.getOrDefault(i + 1, Collections.emptyList())) {
                if (currH <= obs[next-1]) {
                    good = false;
                    break;
                }
            }
            if (good) { res++; }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 76516
'use strict'

const main = (input) => {
    input = input.split('\n').map(v => v.split(''))
    const a = input[0]
    const b = input[1]
    const c = input[2]

    let i = 'a'
    let item = []
    while(true){
        if(i === 'a'){
            item = a
        }else if(i === 'b'){
            item = b
        }else{
            item = c
        }
        if(item.length === 0){
            console.log(i.toUpperCase())
            break
        }
        i = item.shift()
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
#include <iostream>

using namespace std;

int main()
{
	long long x;
	cin >> x;

	long long t;
	for (long long i = 200; i >= -200; i--) {
		for (long long j = 200; j >= -200; j--) {
			t = i * i * i * i * i;
			t -= j * j * j * j * j;
			if (t == x) {
				printf("%d %d\n", i, j);
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3696
// 2020-09-20 13:10:15
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
void answer() {
  ll n, X, m;
  cin >> n >> X >> m;
  int cnt = 0;
  ll tot = 0;
  vector<int> mp(m + 10, -1);
  vector<ll> a;
  ll x = X;
  while (mp[x] == -1) {
    a.push_back(x);
    tot += x;
    mp[x] = cnt++;
    x = x * x % m;
  }
  if (n <= cnt) {
    ll ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << '\n';
    return;
  }
  ll c = tot;
  rep(i, mp[x]) c -= a[i];
  ll ans = tot;
  n -= cnt;
  ans += n / (cnt - mp[x]) * c;
  n %= cnt - mp[x];
  rep(i, n) ans += a[i + mp[x]];
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repm(i, a, b) for (int i = (a); i > (b); i--)

using namespace std;
using ll = long long;




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

  if (s[2]==s[3] && s[4]==s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
k = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(k[1] - k[0])

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

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

int fac(int k){
  int sum = 1;
  for (int i = 1; i <= k; ++i){
        sum *= i;
  }
  return sum;
}

  

int main() {
  int N;
  cin>>N;
  
  vector<int> x(N+1);
  vector<int> y(N+1);
  for(int i=1;i<=N;i++){
    cin>>x.at(i);
    cin>>y.at(i);
  }
  
  long double sum=0;
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      sum+=sqrt((x.at(i)-x.at(j))*(x.at(i)-x.at(j))+
                ((y.at(i)-y.at(j))*(y.at(i)-y.at(j))));
    } 
  } 

  cout << fixed << setprecision(15) << sum*2/N<< endl;
                                                     
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string word,ans;
    int i=0;
    while(cin>>word)
    {   i++;
         ans+=(word[0]-32);
        if(i==3)
        {
            cout<<ans<<endl;
            i=0;
            ans="";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

const int MAX_N = 1e5 + 1;
int N;
int play[5][MAX_N];
int dp[MAX_N][5]; //dp[i][j] : i日目において，jを選んだ場合の幸福度の最大値

int solve() {
    rep(i, N) {
        for(int j = 1; j <= (1 << 2); j <<= 1) {
            for(int k = 0; k < 3; ++k) {
                if((1 << k) & j) continue;
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][1 << k] + play[j][i]);
            }
        }
    }
    return max(dp[N][1 << 0], max(dp[N][1 << 1], dp[N][1 << 2]));
}

int main() {
    cin >> N;
    rep(i, N)
        cin >> play[1][i] >> play[2][i] >> play[4][i];
    cout << solve() << endl;
}


Measured memory_bytes: 3328