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

int main() {
	int		c,i,j,k,h,n,m,x,y,ans = 0;
	
	cin >> h >> n;
	vector<int> a(n);
	vector<int> b(n);
	for(i=0; i<n; i++) {
		cin >> a[i] >> b[i];
	}
	vector<int>	dp(h+1,0x7fffffff); 
	dp[0] = 0;

	for(i=0; i<=h; i++) {
		if (dp[i] == 0x7fffffff) continue;
		for(j=0; j<n; j++) {
			c = min(h, i+a[j]);
			dp[c] = min(dp[c] , dp[i]+b[j]);
		}
	}
	cout << dp[h] << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    vector <int> b(n-1);
    cin >> n;
    for(int i=0;i<n-1;++i) cin >> b[i];
    vector <int> a(n);
    a[0]=b[0];
    a[n-1]=b[n-2];
    for(int i=1;i<n-1;++i) {
        a[i]=min(b[i-1],b[i]);
    }
    int sum=0;
    for(int i=0;i<n;++i) {
        sum+=a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 384
n = int(input())
lst = []#lst[0]=time,lst[1]=limitatiom
for _ in range(n):
    lst.append(list(map(int,input().split())))

lst.sort(key=lambda x: x[1])
sum_time = 0
for time,limitation in lst:
    sum_time+=time
    if sum_time<=limitation:pass
    else:
        print("No")
        exit()

print("Yes")





Measured memory_bytes: 53724
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rrep(i,a,b) for(int i = a; i >=b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using ii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pil = pair<int,ll>;
using vvi = vector<vi>;
using vpi = vector<ii>;

const int N = 100100;
ll mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n-1){
        cin>>a[i];
    }
    int tosodh = 1;
    int cnt = n;
    rep(i,0,n-1){
        if(a[i]==tosodh){
            tosodh = a[i]+1;
            cnt--;
        }
    }
    if(cnt==n){
        cout<<"-1"<<nl;
    }
    else
        cout<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 3904
#include <cstdio>
#include <algorithm>

using namespace std;

int zeikomi(int n, int r)
{
    return n * (100 + r) / 100;
}

int main()
{
    for (;;) {
        int x, y, s;
        scanf("%d %d %d", &x, &y, &s);
        if (x == 0 && y == 0 && s == 0)
            break;

        int ans = 0;
        for (int i = 1; i < s; ++i)
            for (int j = 1; j < s; ++j)
                if (zeikomi(i, x) + zeikomi(j, x) == s)
                    ans = max(ans, zeikomi(i, y) + zeikomi(j, y));

        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1012
#include <stdio.h>
#include <string.h>

int main(){
	
	char S[100];
	int k;
	scanf("%d", &k);
	scanf("%s", &S);
	for(int i = 0; i < strlen(S); i++){
		if( S[i] > 'A' && S[i] < 'Z'){
			return 1;
		}
	}
	if( k > 100 ||  k < 1){
		return 1;
	}
	if (k >= strlen(S)){
		printf("%s", S);
	}else if (k < strlen(S)){
		for( int i =0; i < k; i++){
			printf("%c", S[i]);
		}
		printf("...");
	}
	return 0;
}

Measured memory_bytes: 1728
using DataStructures
at(ft,l,r)=(prefixsum(ft,r)-prefixsum(ft,l-1))
function main()
  n,k=parse.(Int64,split(readline()))
  lr=(x->parse.(Int,split(x))).(readlines())
  ft=FenwickTree{Int}(n)
  inc!(ft,1,1)
  for to=2:n
    for i=lr
      l=to-i[2];r=to-i[1]
      l>1 && inc!(ft,to,at(ft,l,r)%998244353)
      l<2 && r>0 && inc!(ft,to,prefixsum(ft,r)%998244353)
    end
  end
  println(at(ft,n,n)%998244353)
end
main()

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

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

    int ans = 0;
    
    for(int i = 1; i <= N; i++){
        ostringstream oss; oss << i;
        int digit = oss.str().length();

        if(digit % 2 == 1){
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  ll l,r;
  cin>>l>>r;
  r=min(r,l+2019);
  ll ans=2018;
  for(ll i=l;i<=r;i++){
    for(ll j=i+1;j<=r;j++){
      ll x=(i*j)%2019;
      ans=min(ans,x);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int exam1,exam2,reexam,gokei;
	while(cin>>exam1>>exam2>>reexam){
		if(exam1==-1&&exam2==-1&&reexam==-1) break;
		while(1){
		gokei=exam1+exam2;
		if(exam1==-1||exam2==-1){
			cout<<"F"<<endl;
			break;
			}
		if(gokei>=80){
			cout<<"A"<<endl;
			break;
			}
		if(gokei>=65&&gokei<80){
			cout<<"B"<<endl;
			break;
			}
		if(gokei>=50&&gokei<65){
			cout<<"C"<<endl;
			break;
			}
		if(gokei>=30&&gokei<50&&reexam<50){
			cout<<"D"<<endl;
			break;
			}
		if(gokei>=30&&reexam>=50){
			cout<<"C"<<endl;
			break;
			}
		if(gokei<30){
			cout<<"F"<<endl;
			break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
long long n,k,r,s,p,hh[6],a[100100];
long long ans;
char t[100100];
int main()
{
	scanf("%lld%lld%lld%lld%lld\n",&n,&k,&r,&s,&p);
	hh[1]=r,hh[2]=s,hh[3]=p;
	for(int i=1;i<=n;i++)
	{
		scanf("%c",&t[i]);
		if(t[i]=='s')
			a[i]=1,ans+=hh[1];
		if(t[i]=='p')
			a[i]=2,ans+=hh[2];
		if(t[i]=='r')
			a[i]=3,ans+=hh[3];
	}
	for(int i=1;i<=k;i++)
	{
		int cnt=1,last=a[i];
		for(int j=i+k;j<=n;j+=k)
		{
			if(a[j]==last)
				cnt++;
			else
			{
				ans-=(cnt/2)*hh[last];
				last=a[j];
				cnt=1;
			}
		}
		ans-=(cnt/2)*hh[last];
	}
	printf("%lld",ans);
	
	return 0; 
} 

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s,c;
    cin>>s;
    cin>>c;
    c.erase(c.begin()+s.length(),c.end());
    if(c==s) cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}





Measured memory_bytes: 3632
N = int(input())
otoshidama = [input().split() for i in range(N)]

jpy = 0.0
btc = 0.0
rating = 380000.0
sum = 0.0

for i in range(0, N):
    if otoshidama[i][1] == "JPY":
        jpy += float(otoshidama[i][0])
    else:
        btc += float(otoshidama[i][0])

sum = jpy + btc * rating

print(sum)

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

ll dp[2100][2100];

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

    // input
    ll N, M;
    cin >> N >> M;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    vector<ll> B(M);
    FOR(i, 0, M){
        cin >> B.at(i);
    }

    FOR(i, 1, N+1){
        FOR(j, 1, M+1){
            if (A[i-1] == B[j-1]){
                dp[i][j] = 1 + dp[i][j-1] + dp[i-1][j];
                dp[i][j] %= mod;         
            }  
            else {
                dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1];
                if(dp[i][j]<0) dp[i][j]+=mod;   
                dp[i][j] %= mod;         
            }
        }
    }
    p(dp[N][M]+1);

    return 0;
}

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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;

int main ()
{
    lli h,n;
    cin >> h >> n;
    lli a[n+2];
    lli sum=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        sum+=a[i];
    }
    if(sum>=h)
    {
        cout << "Yes"<<endl;
    }
    else
        cout << "No"<<endl;
    return 0;
}



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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 200005;

int k, n;
int a[N];

int32_t main()
{

	FIO
	//cout << fixed << setprecision(10);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

  cin >> k >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];
  int res = k - a[n - 1] + a[0];
  for(int i = 1; i < n; ++i){
    res = max(res, a[i] - a[i - 1]);
  }
  cout << k - res << '\n';


	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

int main() {
  //入力
  int a,b,c;
  std::scanf("%d %d %d",&a,&b,&c);
  
  if (a <= b && b <= c) {
      printf("%d %d %d\n", a,b,c);
  }
  else if (a <= c && c <= b) {
      printf("%d %d %d\n", a,c,b);
  }
  else if (b <= a && a <= c) {
      printf("%d %d %d\n", b,a,c);
  }
  else if (b <= c && c <= a) {
      printf("%d %d %d\n", b,c,a);
  }
  else if (c <= a && a <= b) {
      printf("%d %d %d\n", c,a,b);
  }
  else if (c <= b && b <= a) {
      printf("%d %d %d\n", c,b,a);
  }
  return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string O,E;cin >> O >> E;
  for (int i=0;i<O.size();i++) {
    cout << O[i];
	if (i<E.size()) cout << E[i];
	if (i==O.size()-1 && O.size()<E.size()) cout << E[i];
  }
}

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

using namespace std;

const int mod = 100000;
int w,h,dp[102][102][4];

int main(){
	while(1){
	cin >> w >> h;
	if(w == 0 && h == 0)break;
	dp[1][1][0] = 1;dp[1][1][3] = 1;
	for(int i = 1;i <= h;i++){
		for(int j = 1;j <= w;j++){
			if(i == 1 && j == 1)continue;
			dp[i][j][0] = dp[i-1][j][0] + dp[i-1][j][2];
			dp[i][j][1] = dp[i-1][j][0];
			dp[i][j][2] = dp[i][j-1][3];
			dp[i][j][3] = dp[i][j-1][1] + dp[i][j-1][3];
			for(int k = 0;k < 4;k++)dp[i][j][k]%=mod;
		}
	}
	cout << (dp[h][w][0]+dp[h][w][3])%mod << endl;
	}
	return 0;
}


Measured memory_bytes: 1320
import math

# H, N = 9, 3
# ARR = [
#     [8, 3],
#     [4, 2],
#     [2, 1]
# ]
#
#
# H, N = 100, 6
# ARR = [
#     [1, 1],
#     [2, 3],
#     [3, 9],
#     [4, 27],
#     [5, 81],
#     [6, 243]
# ]
#

H, N = map(int, input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int, input().split())))


def calculate(h, n, arr):
    brr = [math.inf] * (h+1)
    brr[0] = 0

    for i in range(h + 1):
        for j in range(n):

            damage = arr[j][0]
            cost = arr[j][1]

            nextDamage = i + damage

            if nextDamage > h:
                nextDamage = h

            nextCost = min(brr[i] + cost, brr[nextDamage])

            brr[nextDamage] = nextCost

    print(brr[-1])


calculate(H, N, ARR)


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    //trueがひつじ、falseがおおかみ
    vector<bool> ss(n, true);
    for (int i = 0; i < n; i++){
        if (ss[i] && s[i] == 'o') ss[(i + 1) % n] = ss[(n + i - 1) % n];
        if (ss[i] && s[i] == 'x') ss[(i + 1) % n] = !ss[(n + i - 1) % n];
        if (!ss[i] && s[i] == 'o') ss[(i + 1) % n] = !ss[(n + i - 1) % n];
        if (!ss[i] && s[i] == 'x') ss[(i + 1) % n] = ss[(n + i - 1) % n];
    }
    if (ss.front() && ss.back()){
        for (int i = 0; i < n; i++){
            if (ss[i]) cout << 'S';
            else cout << 'W';
        }
        cout << endl;
        return 0;
    }
    vector<bool> ww(n, false);
    for (int i = 0; i < n; i++){
        if (ww[i] && s[i] == 'o') ww[(i + 1) % n] = ww[(n + i - 1) % n];
        if (ww[i] && s[i] == 'x') ww[(i + 1) % n] = !ww[(n + i - 1) % n];
        if (!ww[i] && s[i] == 'o') ww[(i + 1) % n] = !ww[(n + i - 1) % n];
        if (!ww[i] && s[i] == 'x') ww[(i + 1) % n] = ww[(n + i - 1) % n];
    }
    if (!ww.front() && !ww.back()){
        for (int i = 0; i < n; i++){
            if (ww[i]) cout << 'S';
            else cout << 'W';
        }
        cout << endl;
        return 0;
    }
    vector<bool> ws(n, false); ws[0] = true;
    for (int i = 0; i < n; i++){
        if (ws[i] && s[i] == 'o') ws[(i + 1) % n] = ws[(n + i - 1) % n];
        if (ws[i] && s[i] == 'x') ws[(i + 1) % n] = !ws[(n + i - 1) % n];
        if (!ws[i] && s[i] == 'o') ws[(i + 1) % n] = !ws[(n + i - 1) % n];
        if (!ws[i] && s[i] == 'x') ws[(i + 1) % n] = ws[(n + i - 1) % n];
    }
    if (ws.front() && !ws.back()){
        for (int i = 0; i < n; i++){
            if (ws[i]) cout << 'S';
            else cout << 'W';
        }
        cout << endl;
        return 0;
    }
    vector<bool> sw(n, true); sw[0] = false;
    for (int i = 0; i < n; i++){
        if (sw[i] && s[i] == 'o') sw[(i + 1) % n] = sw[(n + i - 1) % n];
        if (sw[i] && s[i] == 'x') sw[(i + 1) % n] = !sw[(n + i - 1) % n];
        if (!sw[i] && s[i] == 'o') sw[(i + 1) % n] = !sw[(n + i - 1) % n];
        if (!sw[i] && s[i] == 'x') sw[(i + 1) % n] = sw[(n + i - 1) % n];
    }
    if (!sw.front() && sw.back()){
        for (int i = 0; i < n; i++){
            if (sw[i]) cout << 'S';
            else cout << 'W';
        }
        cout << endl;
        return 0;
    }
    cout << - 1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;

const double PI = acos(-1.0);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,K;
    string S;
    cin>>N>>K>>S;
    vector<pair<char,int>> T;
    int cnt = 1;
    rep(i,N){
        if(i == N-1){
            T.push_back({S[i],cnt});
            continue;
        }
        if(S[i] == S[i+1])cnt++;
        else{
            T.push_back({S[i],cnt});
            cnt = 1;
        }
    }
    printpair(T);
    int X = T.size();
    ll ans = 0;
    rep(i,X){
        ans += T[i].second-1;
    }
    ans = min((ll)N-1,ans + 2 * K);
    cout<<ans<<endl;
}

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




int main(void) {

int N,M,L,K;
double b; 

scanf("%d",&N);
M = N/2;
L = N%2;
K = M+L;
b = (double)K/(double)N;
printf("%f\n",b);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
    cerr << "[";
    for (auto e : aux) cerr << e << ' ';
    cerr << "]";
    return cerr;
}

const int maxN = 111;

int n;
int a[maxN];
vector<int> sol;

int main()
{
    //freopen("test.in","r",stdin);

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

    for (int tms = 1; tms <= n; tms++) {
        int i;
        for (i = n - tms + 1; i > 0 && a[i] != i; i--);
        if (i == 0) {
            cout << -1;
            return 0;
        }

        sol.pb(i);
        for (int j = i; j <= n - tms; j++) 
            a[j] = a[j + 1];
    }

    reverse(sol.begin(), sol.end());
    for (auto e : sol) cout << e << '\n';


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n;
string str[N];

int trie[10 * N][26], cnt[10 * N][26];
bool term[10 * N];
int nodecnt = 1;
void add(const string &s) {
	int node = 0;
	for (int i = 0; i < s.size(); i++) {
		int idx = s[i] - 'a';

		if (i == s.size() - 1) {
			cnt[node][idx] += 1;
		}

		if (!trie[node][idx]) {
			trie[node][idx] = nodecnt++;
		}
		node = trie[node][idx];
	}
}

int query(const string &s) {
	int scnt[26];
	memset(scnt, 0, sizeof scnt);

	for (char c : s) {
		scnt[c - 'a'] += 1;
	}

	int node = 0;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		int idx = s[i] - 'a';

		for (int j = 0; j < 26; j++) {
			if (!scnt[j]) continue;
			ans += cnt[node][j];
		}

		scnt[idx] -= 1;
		if (!trie[node][idx]) {
			break;
		}
		node = trie[node][idx];
	}

	return ans;
}

bool comp(const string &a, const string &b) {
	return a.size() < b.size();
}

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

	for (int i = 0; i < n; i++) {
		cin >> str[i];
		reverse(str[i].begin(), str[i].end());
	}

	sort(str, str + n, comp);

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (long long) query(str[i]);
		add(str[i]);
	}

	cout << ans << '\n';

	return 0;
}


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

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<long long> ab, cd, abcd;
    ab.push_back(a);
    ab.push_back(b);
    if(a<=0 && b >= 0) ab.push_back(0);
    cd.push_back(c);
    cd.push_back(d);
    if(c <= 0 && d >= 0) cd.push_back(0);
    for(long long x : ab){
        for(long long y : cd){
            abcd.push_back(x * y);
        }
    }
    sort(abcd.begin(), abcd.end());
    reverse(abcd.begin(), abcd.end());
    cout << abcd.at(0) << endl;
}

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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> x(n, 0);
    vector<ll> y(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        cin >> y[i];
    }
    ll max_u = - 10e17;
    ll min_u = 10e17;
    ll max_v = - 10e17;
    ll min_v = 10e17;
    for (int i = 0; i < n; i++) {
        max_u = max(x[i] + y[i], max_u);
        max_v = max(x[i] - y[i], max_v);
        min_u = min(x[i] + y[i], min_u);
        min_v = min(x[i] - y[i], min_v);
    }
    cout << max(max_u - min_u, max_v - min_v) << endl;
    return 0;
}

Measured memory_bytes: 6444
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;

    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

::std::vector<::std::int64_t> primes(::std::int64_t upper){
	::std::vector<::std::int64_t> res;
	for (::std::int64_t i = 2; i <= upper; ++i) {
		bool isPrime = true;
		for (auto x : res) {
			if (x * x > upper) break;
			if (i % x == 0) {
				isPrime = false;
				break;
			}
		}
		if (isPrime)
			res.push_back(i);
	}
	return res;
}

int main(void) {
  int64 m, a, b;
  auto pr = primes(100000);
  while (cin >> m >> a >> b && m+a+b) {
    [&](){
      int64 rp = 2, rq = 2;
      for (auto q : pr) {
        for (auto p : pr) {
          if (p * q > m || p > q) break;
          if (a*q <= p*b) {
            if (rp*rq <= p*q) {
              rp = p; rq = q;
            }
          }
        }
      }
      cout << rp << " " << rq << endl;
    }();
  }
}


Measured memory_bytes: 3252
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll x, maybe, ans = INF;
  scanf("%lld", &x);
  if (x == 1)
  {
    printf("%d\n", 1);
    return 0;
  }
  for (int i = 2; i < 40; i++)
  {
    for (int j = 2;; j++)
    {
      maybe = pow(i, j);
      if (maybe > x)
      {
        ll diff = fabs(pow(i, j - 1) - x) - llabs(ans - x);
        if (diff <= 0 && j >= 3)
        {
          ans = pow(i, j - 1);
        }
        break;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int k;
string s;

signed main(){
    cin >> s;
    cin >> k;
    vector<char> sc(all(s));

    int n = sz(s);
    REP(i,n-1){
        if (sc[i] != 'a' && k >= 'z' + 1 - sc[i]){
            k -= 'z' + 1 - sc[i];            
            sc[i] = 'a';
        }
    }
    k %= 26;
    sc[n-1] = (sc[n-1] - 'a' + k) % 26 + 'a';
    cout << string(all(sc)) << endl;
}

Measured memory_bytes: 640
#include <stdio.h> 
 
typedef enum { 
    FALSE, 
    TRUE 
} bool_t; 
 
void sorter ( int* data, int elements ) 
{ 
    int i, j, cmp, key; 
    for ( i = 0; i < elements; i++ ) 
    { 
        key = data[i]; 
        for ( j = i; j > 0; j-- ) 
        { 
            cmp = data[j - 1]; 
            if ( key < cmp ) 
            { 
                break; 
            } 
            else 
            { 
                data[j] = cmp; 
            } 
        } 
        data[j] = key; 
    } 
} 
 
int square ( int input ) 
{ 
    return input * input; 
} 
 
// length[] should be sorted 
// assuming number of elements of length[] is 3 
bool_t alg ( int* length ) 
{ 
    if ( square(length[0]) == square(length[1]) + square(length[2]) )                  
        return TRUE;                             
    else                                         
        return FALSE; 
} 
 
int main ( void ) 
{ 
    bool_t result; 
    int linenum, i; 
    int data[3]; 
 
    scanf( "%d", &linenum ); 
 
    for ( i = 0; i < linenum; i++ ) 
    { 
        scanf( "%d %d %d", &data[0], &data[1], &data[2] ); 
        sorter( data, 3 ); 
        if ( alg(data) ) 
            puts( "YES" ); 
        else 
            puts( "NO" ); 
    } 
 
    return 0; 
} 

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t=1;
	//cin >> t;
	while (t--) {
		int n,b;
		cin >> n>>b;
		cout<<n*b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3664
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 入力文字列を取得
		Scanner sc = new Scanner(System.in);

		// 配列を作る
		ArrayList<Integer> list = new ArrayList<Integer>();
		int index_max = sc.nextInt();

		// リストにテキスト入力文字を格納
		for (int i = 0; i < index_max; i++) {
			//
			list.add(sc.nextInt());
		}

		// 逆順に表示
		for (int index = index_max - 1; index >= 0; index--) {

			String number = list.get(index).toString();

			// 最後の数以外には空白を追加
			if (index != 0) {

				number = number + " ";
				System.out.print(number);
				// 最後の数は改行出力
			} else {
				//
				System.out.println(number);
			}
		}

	}
}

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

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    int a[n][m], b[m][l];
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
            cin >> a[i][j];
    for (int i=0; i<m; i++)
        for (int j=0; j<l; j++)
            cin >> b[i][j];
    for (int i=0; i<n; i++)
        for (int j=0; j<l; j++){
            long c = 0;
            for (int k=0; k<m; k++)
                c += a[i][k]*b[k][j];
            if (j==l-1)
                cout << c << endl;
            else
                cout << c << ' ';
        }
}


Measured memory_bytes: 3144
import java.util.Scanner;

public class Main {

	public static int[] Fee = {200, 300};
	public static int Num_Classes = 9;

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

		String[] className = new String[Num_Classes];
		int[][] visitors = new int[Num_Classes][2];
		for(int i = 0; i < Num_Classes; i++){
			className[i] = sc.next();
			visitors[i][0] = sc.nextInt();
			visitors[i][1] = sc.nextInt();
		}

		sc.close();

		int[][] data = new int[Num_Classes][2];
		for(int i = 0; i < Num_Classes; i++){
			data[i][0] = visitors[i][0] + visitors[i][1];
			data[i][1] = visitors[i][0] * Fee[0] + visitors[i][1] * Fee[1];
		}

		for(int i = 0; i < Num_Classes; i++){
			System.out.printf("%s %d %d\n", className[i], data[i][0], data[i][1]);
		}


	}

}

Measured memory_bytes: 17212
from collections import deque
h, w = map(int, input().split())
s = ['#' * (w+2)] + ['#' + input() + '#' for _ in range(h)] + ['#' * (w+2)]

ans = 0
INF = 111111

for i in range(h+1):
  for j in range(w+1):
    if s[i][j] == '#':
      continue
    visited = [[0] * (w+2) for _ in range(h+2)]
    visited[i][j] = 1
    max_s = 0
    dq = deque([(i, j, 0)])

    while dq:
      ci, cj, step = dq.popleft()
      if step > max_s:
        max_s = step
      step += 1

      for di, dj in ((ci+1, cj), (ci, cj+1), (ci-1, cj), (ci, cj-1)):
        if s[di][dj] == '#' or visited[di][dj] == 1:
          continue
        visited[di][dj] = 1
        dq.append((di, dj, step))
    ans = max(max_s, ans)

print(ans)

Measured memory_bytes: 3316
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    void calc()
    {
        var x = cin.nextInt();
        var a = cin.nextInt();
        var b = cin.nextInt();
        var ret = "A";
        a = Math.Abs(x - a);
        b = Math.Abs(x - b);
        if(b < a)
        {
            ret = "B";
        }

        Console.WriteLine(ret);
    }


    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
int abs(int n){
    if(n>=0) return n;
    else return -n;
}

int main(){
    int n,l;
    scanf("%d %d",&n,&l);
    int answer=0;
    int min=1000;
    int minN;

    for(int i=0;i<n;i++){
        answer+=l;
        if(min>abs(l)){
            minN=l;
            min=abs(l);
        }
        l++;
    }
    answer-=minN;
    printf("%d\n",answer);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n;
string s, t;


int main()
{
	cin >> s;
	if (s == "Sunny")
		cout << "Cloudy" << endl;
	else if (s == "Cloudy")
		cout << "Rainy" << endl;
	else
		cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports, deprecated, dead_code)]

// Input macros
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{VecDeque,HashSet,HashMap,BinaryHeap};
// Module for v1.15.1
use std::ascii::AsciiExt; // deprecated since 1.26.0: use inherent method instead

// Functions

// Main
fn main() {

    input! {
        M: usize,
        K: usize,
    }

    if M == 0 {
        if K == 0 {
            println!("0 0");
            return;
        }
    } else if M == 1 {
        if K == 0 {
            println!("0 0 1 1");
            return;
        } else if K == 1 {
            println!("-1");
            return;
        }
    }

    let mm = 2_usize.pow(M as u32);
    if K >= mm {
        println!("-1");
        return;
    }

    let mut a1 = VecDeque::new();
    let mut a2 = VecDeque::new();
    for i in 0..mm{
        if i == K {
            continue;
        }
        a1.push_back(i);
        a2.push_front(i);
    }

    for a in a1 {
        print!("{} ", a);
    }
    print!("{} ", K);
    for a in a2 {
        print!("{} ", a);
    }
    print!("{} ", K);

}

Measured memory_bytes: 7932
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int n, k, r, s, p;
string t;
int main() {
    cin >> n >> k >> r >> s >> p >> t;
    i64 scr = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        if (t[i] == 'r') x = p;
        else if (t[i] == 's') x = r;
        else x = s;
        if (i - k >= 0 && t[i] == t[i - k]) {
            t[i] = '*';
            x = 0;
        }
        scr += x;
    }
    cerr << t << endl;
    cout << scr << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
ab = [[int(x) for x in input().split()] for _ in range(n)]
from collections import defaultdict, Counter
import math

double_zero_cnt = 0 # [0, 0]の個数
a_b = [] # a/bを、約分した形で保持(a/gcd(a, b), b/gcd(a, b), 符号)
for a, b in ab:
    if a == 0 and b == 0: 
        double_zero_cnt += 1
        continue
    g = math.gcd(a, b)
    a //= g
    b //= g
    sign = 1 if a*b > 0 else -1 if a*b < 0 else 0
    a_b.append((abs(a), abs(b), sign))

c = Counter(a_b) # ベクトルごとにグループ分け
key_list = list(c.keys())

d = defaultdict(list) # [a, b] あるngなペアのそれぞれの要素の個数
for key in key_list:
    a, b, sign = key
    if d[(b, a, -sign)]: # ダブルカウントしないように
        continue 
    if c[(b, a, -sign)] != 0:
        d[(a, b, sign)] = [c[(a, b, sign)], c[(b, a, -sign)]]

ans = 1 # 積算の単位元
used_cnt = double_zero_cnt # 組めないものがあるイワシの個数(計算で使用したらカウント)
for key in d.keys():
    if d[key] == []: # 前のループで調べると[]が生まれてしまう
        continue
    x, y = d[key]
    used_cnt += (x + y)
    mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod # このグループからは、片方ずつからしか出せない。何も選ばないがダブルカウントになる。
    ans *= mul
    ans %= mod

ans *= pow(2, n - (used_cnt), mod) # まだ使われていないイワシは好きな組み合わせ可能
ans += double_zero_cnt # 両方0のものは1つにつき自分のみの1通り
ans -= 1 # 0匹は選べない
ans %= mod
print(ans)


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

int main(){
    int n;
    cin >>n;
    long long int a[n],ans=0;
    for(int i=0;i<n;i++)cin >>a[i];
    for(int i=0;i<n-1;i++){
        int sa = a[i+1]-a[i];
        if(sa<0){
            ans-=sa;
            a[i+1]-=sa;
        }
    }
    cout <<ans<<endl;
}

Measured memory_bytes: 5148
h, w = map(int, input().split())

ans = [[0 for j in range(w)] for i in range(2 * h)]
for i in range(h):
    c = input()
    for j in range(len(c)):
        ans[i * 2][j] = c[j]
        ans[i * 2 + 1][j] = c[j]

for i in range(2 * h):
    for j in range(w):
        print(ans[i][j], end='')
    print()

Measured memory_bytes: 4600
#define mod 1000000007
int add(int x,int y){
	return (x+=y)<mod?x:x-mod;
}
int sub(int x,int y){
	return add(x,mod-y);
}
int mul(int x,int y){
	return (int)((long long int)x*y%mod);
}
int pw(int x,int y){
	int r=1;
	while(1){
		if(y&1)r=mul(r,x);
		if(y>>=1)x=mul(x,x);else
			break;
	}
	return r;
}

#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define ran 222222
int n,X,Y;
vector<int> a[ran];
int ifac[ran],fac[ran];

int main(){
	scanf("%d%d%d",&n,&X,&Y);

	fac[0] = ifac[0] = 1;
	for(int i=1; i<=n; i++){
		fac[i] = mul(fac[i-1],i);
		ifac[i] = pw(fac[i],mod-2);
	}

	for(int i=1; i<=n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
	}
	int p = -1, p2 = -1;
	for(int i=1; i<=n; i++)
		if(!a[i].empty()){
			sort(a[i].begin(),a[i].end());
			if(p==-1 || a[i][0] < a[p][0])
				p2 = p, p=i;
			else
			if(p2 == -1 || a[i][0] < a[p2][0])
				p2 = i;
		}
	int res = 1, tot = 0;
	for(int i=1; i<=n; i++)
		if(!a[i].empty() && (i == p || a[i][0] + a[p][0] <= Y)){
			int z = 0;
			for(int j=0; j<a[i].size(); j++){
				if(a[i][j] + a[i][0] <= X || (i!=p && a[i][j] + a[p][0] <= Y) || (i == p && a[i][j] == a[i][0])
					|| (i == p && p2 != -1 && a[i][j] + a[p2][0] <= Y))
					z++;
			}
			res = mul(res,ifac[z]);
			tot += z;
		}
	printf("%d\n",mul(res,fac[tot]));
	return 0;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, X, before = 0; cin >> N >> X;
    vector<int> bound, filtered; bound.push_back(0);
    rep (i, 0, N) {
        int l; cin >> l;
        before += l;
        bound.push_back(before);
    }

    copy_if(bound.begin(), bound.end(), back_inserter(filtered), [&X](int l){return l <= X;});
    cout << filtered.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[100],ans;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(int i=0;i<n;i++){
    if(i%2)ans-=a[n-i-1];
    else ans+=a[n-i-1];
    
    
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstdio>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)2e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N,K; cin >> N >> K;
	string S; cin >> S;
	vector<int> state;
	int now = 1;
	int cnt = 0;
	rep(i,N){
		if(S[i] == now + '0') cnt++;
		else{
			now = 1-now;
			state.push_back(cnt);
			cnt = 1;
		}
	}
	if(cnt != 0) state.push_back(cnt);
	if(now == 0) state.push_back(0);
	int m = state.size();
	vector<int> sum(m+1);
	rep(i,m) sum[i+1] = sum[i] + state[i];
	int ans = 0;
	for(int i = 0; i < m; i+=2){
		int now = 0;
		now += sum[min(i+2*K+1,m)] - sum[i];
		ans = max(ans,now);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
typedef pair<ll, ll> pi;
#define f first
#define s second

ll n, k, arr[100005], ans = 1e18;

int main() {
	cin >> n >> k;
	FOR(i, 1, n) cin >> arr[i];
	FOR(i, 1, n-k+1) {
		//printf("from %lld to %lld, dist %lld, to0 %lld\n", i+k-1, i, arr[i+k-1] - arr[i], min(abs(arr[i+k-1]), abs(arr[i])));
		ans = min(ans, arr[i+k-1] - arr[i] + min(abs(arr[i+k-1]), abs(arr[i])));
	}
	cout << ans;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{
	int n,i,j,k,l;
	cin>>n;
	string s;
	cin>>s;
	if(n>=s.length())
		cout<<s<<endl;
	else{
		cout<<s.substr(0,n)<<"..."<<endl;
	}
}
int  main() 
{
	fast_io;
    int t=1;
    ///cin>>t;
    while(t--)
    	solve();
	return 0; 
}

Measured memory_bytes: 3656
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    int k = (a+b)/2;
    if(abs(a-k)==abs(b-k)){
        cout << k;
    }
    else{
        cout << "IMPOSSIBLE";
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Main
{
    public static class Program
    {
        static void Main(string[] arg)
        {
            int n = int.Parse(Console.ReadLine());
            //var array = GetIntList(Console.ReadLine());
            int answer = 0;
            var list = new List<int>();
            int max = 0;
            int semimax = 0;
            bool maxes = false;

            for(int i = 0;i<n;i++){
                int num = int.Parse(Console.ReadLine());
                list.Add(num);
                if(num > max){
                    semimax = max;
                    max = num;
                }
                else if(num > semimax){
                    semimax = num;
                }
            }
            if(list.Where(x => x==max).Count() > 1)maxes = true;

            for(int i=0;i<n;i++){
                if(list[i] < max){
                    Console.WriteLine(max);
                }
                else{
                    if(maxes){
                        Console.WriteLine(max);
                    }
                    else{
                        Console.WriteLine(semimax);
                    }
            }

            // Console.WriteLine(answer);
            Console.ReadLine();
 
        }}
        
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();
 
        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();
 
        }
        private static ulong[] GetUlongList(string line)
        {
            return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
        }
        private static long[] GetLongList(string line)
        {
            return line.Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static bool IsOdd(int i)
        {
            return i % 2 == 1 ? true : false;
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}

Measured memory_bytes: 21976