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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, x, y;
int c[200005], w[200005];

int par[200005], ra[200005];

void dsuInit() {
    forn(i, n) par[i] = i, ra[i] = 1;
}

int dsuParent(int v) {
    if (v == par[v]) return v;
    return par[v] = dsuParent(par[v]);
}

void dsuMerge(int u, int v) {
    u = dsuParent(u);
    v = dsuParent(v);
    if (u == v) return;
    if (ra[u] < ra[v]) swap(u, v);
    par[v] = u;
    ra[u] += ra[v];
}

vector<int> cm[200005];
map<int, int> cnt;
int f[200005], rf[200005];

int binPow(LL x, int p) {
    LL res = 1;
    while (p) {
        if (p & 1) res = res * x % MOD;
        p >>= 1;
        if (p) x = x * x % MOD;
    }
    return (int)res;
}

int C(int n, int k) {
    return (LL)f[n] * rf[k] % MOD * rf[n - k] % MOD;
}

inline bool cmp(const int &lhs, const int &rhs) {
    return w[lhs] < w[rhs];
}

vector<int> pos[200005];
vector<int> upto[200005];

const int INF = int(2e9) + 123;

int main() {
    f[0] = rf[0] = 1;
    for (int i = 1; i < 200005; ++i) {
        f[i] = (LL)f[i - 1] * i % MOD;
        rf[i] = binPow(f[i], MOD - 2);
    }
    scanf("%d%d%d", &n, &x, &y);
    forn(i, n) scanf("%d%d", c + i, w + i), --c[i];
    dsuInit();

    forn(i, n) pos[c[i]].pb(i);
    forn(i, n) sort(pos[i].begin(), pos[i].end(), cmp);
    int best = -1, best2 = -1;
    int bestVal = INF, bestVal2 = INF;
    forn(i, n) if (!pos[i].empty()) {
        int val = w[pos[i][0]];
        if (val < bestVal) {
            bestVal2 = bestVal;
            best2 = best;
            best = i;
            bestVal = val;
        } else if (val < bestVal2) {
            bestVal2 = val;
            best2 = i;
        }
    }

    forn(i, n) if (!pos[i].empty()) {
        for (int j = 1; j < (int)pos[i].size() && w[pos[i][0]] + w[pos[i][j]] <= x; ++j) {
            dsuMerge(pos[i][0], pos[i][j]);
        }
        if (best != -1 && best != i) {
            for (int j = 0; j < (int)pos[i].size() && w[pos[best][0]] + w[pos[i][j]] <= y; ++j) {
                dsuMerge(pos[best][0], pos[i][j]);
            }
        }
        if (best2 != -1 && best2 != i) {
            for (int j = 0; j < (int)pos[i].size() && w[pos[best2][0]] + w[pos[i][j]] <= y; ++j) {
                dsuMerge(pos[best2][0], pos[i][j]);
            }
        }
    }

    forn(i, n) {
        cm[dsuParent(i)].pb(i);
    }
    int ans = 1;
    forn(i, n) if (!cm[i].empty()) {
        cnt.clear();
        for (int x : cm[i]) {
            ++cnt[c[x]];
        }
        int cc = 0;
        for (PII p : cnt) {
            ans = (LL)ans * C(cc + p.second, p.second) % MOD;
            cc += p.second;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  int count = 0;
  for(int i = 0; i < n-2; i++){
    if(s.substr(i,3) == "ABC")
    	++count;
  }
  cout << count;
}

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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    char dif = 'A' - 'a';
    printf("%c%c%c\n", a[0] + dif, b[0] + dif, c[0] + dif);
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


signed main(){ 
    int n; cin>>n;
    vector<int> A(20000000,0);
    int result=0;
    int a[n];
    for(int i=0;i<n;i++){
        int ai; cin>>ai;
        a[i]=ai;
        result+=ai;
        A[ai]+=1;
    }

    int q; cin>>q;
    
    vector<int> scores;

    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        result=result+(c-b)*A[b];
        A[c]+=A[b];
        A[b]=0;

        scores.push_back(result);
    }

    for(int i=0;i<q;i++){
        cout<<scores[i]<<endl;
    }
}  

Measured memory_bytes: 161236
#include<iostream>
using namespace std;
int main(){
  long long int h,n,sum=0;
  cin>>h>>n;
  int flag=1;
  for(long long int i=0;i<n;i++){
   long long int val;
    cin>>val;
    sum+=val;
    if(sum>=h){
         cout<<"Yes";
      flag=0;
      break;
    }
    
  }
  if(flag)cout<<"No";
  
  
 return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{   
    char S[101];
    int s=0,i,j=0,k=0;
  
    scanf("%s",S);
    s=strlen(S);
  
    if(s==1){
      if((S[0]=='R')||(S[0]=='U')||(S[0]=='D')){
        printf("Yes\n"); return 0;
      }
      else printf("No\n");
      return 0;
    }
  
    for(i=0;i<s/2;i++){
      if((S[2*i]=='R')||(S[2*i]=='U')||(S[2*i]=='D'))
        j++;
      if((S[2*i+1]=='L')||(S[2*i+1]=='U')||(S[2*i+1]=='D'))
        k++;
    }
 
    if((j==s/2)&&(k==s/2)) printf("Yes\n");
    else printf("No\n");
  
    return 0;
}

Measured memory_bytes: 1644
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        var inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();

        WriteLine(Math.Min(inp[0] * inp[1], inp[2]));
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

bool is_prime(const unsigned n){
    switch(n) {
        case 0: // fall-through
        case 1: return false;
        case 2: return true;
    } // n > 2 が保証された

    if(n % 2 == 0) return false;

    // 上で i=2 相当は調べたので、i=3から奇数のみ調べる
    for(unsigned i = 3; i * i <= n; i += 2) {
        if(n % i == 0) return false;
    }

    return true;
}
bool N2017(ll n){
    if(is_prime(n) == false) return false;
    if(is_prime((n+1)/2) == false) return false;
    return true;
}

int main()
{
    cout << fixed << setprecision(15);
    ll Q;
    cin >> Q;

    vector<ll> L(Q);
    vector<ll> R(Q);

    REP(i, Q){
        cin >> L[i] >> R[i];
    }
    
    ll maxN = 100003;
    vector<ll> P(maxN);
    vector<ll> C(maxN);

    REP(i, maxN){
        if(N2017(i) == true){
            P[i] = 1;
        }
        else{
            P[i] = 0;
        }
    }
    C[0] = 0;
    for(ll i=1; i<= maxN; i++){
        C[i] = C[i-1] + P[i];
    }

    REP(i, Q){
        cout << C[R[i]] - C[L[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;
ll N,M;
ll A[100000], B[100000];
P p[100000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    rep(i,0,N){
        cin>>A[i]>>B[i];
        p[i]=P(A[i],B[i]);
    }
    sort(p,p+N);
    ll i=0;
    ll ans=0;
    while(M>0){
        ans+=p[i].fr*min(p[i].sc,M);
        M-=p[i].sc;
        i++;
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define initialize(array,size,value) for(ll i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<ll>
#define vp vector< pair <ll,ll> >
#define sl set<ll>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<ll, ll>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

ll n;
ll a[305];
ld dp[302][302][302];
ld f(ll b, ll c, ll d){
	//cout<<"call "<<b<<" "<<c<<" "<<d<<endl;
	ld aa=n-b-c-d;
	if(b<0 || c<0 || d<0 || n-b-c-d<0) return 0;
	else if(aa==n){
		return 0;
	}
	else if(dp[b][c][d]!=0) {
		return dp[b][c][d];
	}
	else {
		ld ans=0;
		ld x=(ld)b/(ld)n;
		ld y=(ld)c/(ld)n;
		ld z=(ld)d/(ld)n;
		ans=1 +x*f(b-1, c, d) +y*f(b+1, c-1, d) + z*f(b, c+1, d-1);
		ans=ans/((ld)1-(aa/(ld)n));
		return dp[b][c][d]=ans;
	}
}

int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
   /* #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    //ll n;
    cin>>n;
    //ll a[n];
    ll c0=0, c1=0, c2=0, c3=0;
    loop(i,0,n){
    	cin>>a[i];
    	if(a[i]==0) c0++;
    	else if(a[i]==1) c1++;
    	else if(a[i]==2) c2++;
    	else if(a[i]==3) c3++;
    }
    memset(dp,0,sizeof dp);
    //cout<<c0<<" "<<c1<<" "<<c2<<" "<<c3<<endl;
    cout<<fixed<<setprecision(15)<<f(c1,c2,c3)<<endl;
 	
 }

Measured memory_bytes: 430720
a, b, c, d = map(int, input().split())
ans = 0
if 0 <= a and 0 <= c:
    ans = b*d
elif 0 <= a and d <= 0:
    ans = a*d
elif b <= 0 and 0 <= c:
    ans = b*c
elif b <= 0 and d <= 0:
    ans = a*c
elif a <= 0 <= b and 0 <= c:
    ans = b*d
elif a <= 0 <= b and d <= 0:
    ans = a*c
elif 0 <= a and c <= 0 <= d:
    ans = b*d
elif b <= 0 and c <= 0 <= d:
    ans = a*c
else:
    ans = max(a*c, b*d)

print(ans)


Measured memory_bytes: 9188
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e5 + 10, MOD = 1e9+7;
const ll OO = 2e18;
string val[] = { "Sunny", "Cloudy", "Rainy", "Sunny" };
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 4; ++i) {
		if (s == val[i])
			cout << val[(i + 1) % 4] << endl, exit(0);
	}
}

Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=105;

int n;
vector<int> g[N];
long long a1=1e18,a2=1e18;

int d[N][N];
void dfs(int u,int p,int tag,int dep=1){
    int cnt=0;
    for(int v:g[u])if(v!=p)dfs(v,u,tag,dep+1),cnt++;
    d[tag][dep]=max(d[tag][dep],cnt);
}
int dg[N];
int main(){
    scanf("%d",&n);
    FOR(i,2,n){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a].pb(b);
        g[b].pb(a);
        dg[a]++,dg[b]++;
    }
    FOR(u,1,n){
        for(int v:g[u]){
            //printf("u=%d,v=%d\n",u,v);
            FOR(i,1,n)d[1][i]=0;
            FOR(i,1,n)d[2][i]=0;
            dfs(u,v,1);
            dfs(v,u,2);
            long long x=1,cnt=0;
            FOR(i,1,n){
                //printf("d[%d,%d]=%d\n",1,i,d[1][i]); printf("d[%d,%d]=%d\n",2,i,d[2][i]);
                long long t=max(d[1][i],d[2][i]);
                if(t==0)break;
                cnt=i;
                if(1e18/t<x)x=1e18;
                else x*=t;
            }
            if(1e18/2<x)x=1e18;
            else x*=2;
            ++cnt;
            if(cnt<a1)a1=cnt,a2=x;
            else if(cnt==a1)a2=min(a2,x);
        }
    }
    FOR(u,1,n){
        FOR(i,1,dg[u])FOR(j,1,n)d[i][j]=0;
        int id=0;
        long long x=1,cnt=0;
        for(int v:g[u]){
            ++id;
            dfs(v,u,id);
        }
        assert(id==dg[u]);
        FOR(i,1,n){
            int t=d[1][i];
            FOR(j,1,id)t=max(t,d[j][i]);
            if(t==0)break;
            cnt=i;
            if(1e18/t<x)x=1e18;
            else x*=t;
        }
        if(1e18/dg[u]<x)x=1e18;
        else x*=dg[u];
        cnt+=2;
        if(cnt<a1)a1=cnt,a2=x;
        else if(cnt==a1)a2=min(a2,x);
    }
    printf("%lld %lld\n",a1,a2);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 31

int main() {
	int w, n, a, b;
	int i, temp;
	int arr[MAX] = {0};

	scanf("%d", &w);
	for(i = 0; i < w; i++) {
		arr[i] = i + 1;
	}

	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d,%d", &a, &b);
		temp = arr[b-1];
		arr[b-1] = arr[a-1];
		arr[a-1] = temp;
	}

	i = 0;
	while(arr[i] != 0) {
		printf("%d\n", arr[i]);
		i++;
	}

	return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int H1 = s.nextInt();
		int M1 = s.nextInt();
		int H2 = s.nextInt();
		int M2 = s.nextInt();
		int K = s.nextInt();
		
		int bw = (H2-H1)*60 + (M2-M1);
		
		System.out.println(bw-K);
    }
}

Measured memory_bytes: 35816
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int main(void) {
    int n, t, a;
    cin >> n >> t >> a;
    int x, y, j = 100000000, ans;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        int y = (t * 1000 - x * 6) - a * 1000;
        y = abs(y);
        if (j > y) {
            j = y;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#define mp make_pair
#define pb push_back

using namespace std;

int main() 
{
	string a,b;
	cin >> a >> b;
	int sum = 0;
	if (a[0] == a[4] && a[1] == a[3])
			sum++;
	while (a != b) {
		int i = 4;
		while (1) {
			if (a[i] < '9') {
				a[i]++;
				break;
			}
			else {
				a[i] = '0';
				--i;
			}
		}
		if (a[0] == a[4] && a[1] == a[3])
			sum++;
	}
	cout << sum;
	return 0;
}

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

int main(){
    long int N,M,num;
    cin >> N >> M;
    
    if(N>M){
        num = N-M;
    }
    else if(M>N){
        num = M-N;
    }
    else{
        num=0;
    }

    cout<<num<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    string T = "";
    for(int i = 0; i < N / 2; i++) {
        T += S.at(i);
    }
    if(S == T + T) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];

    rep(i,n){
       if(a[i]%2)continue;
       if(a[i]%3 && a[i]%5){
           cout<<"DENIED\n";
           return 0;
       }
    }

    cout<<"APPROVED\n";

    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, M, K = map(int, input().split())
A = np.cumsum([0] + list(map(int, input().split())))
B = np.cumsum([0] + list(map(int, input().split())))

def nibu(data, value):
  left = 0
  right = len(data) - 1
  while right - left > 1:
    mid = (left + right)//2
    if data[mid] == value:
      return mid
    elif value < data[mid]:
      right = mid
    else:
      left = mid
  if value >= data[right]:
    return right
  else:
    return left
  
ans = 0
for i in range(N+1):
  sa = K - A[i]
  if sa < 0:
    break
  j = nibu(B, sa)
  ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 53164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    ll N;
    cin>>N;
    ll a[101];
    rep(i,N)cin>>a[i];
    ll dp[110][21]={0};
    dp[0][a[0]]=1;
    for(int i=1;i<N-1;i++){
        for(int j=0;j<21;j++){
            ll o,p;
            if(j-a[i]>=0){
                o=dp[i-1][j-a[i]];
            }else{
                o=0;
            }
            if(j+a[i]<21){
                p=dp[i-1][j+a[i]];
            }else{
                p=0;
            }
            dp[i][j]=o+p;
        }
    }
    cout<<dp[N-2][a[N-1]]<<endl;
    return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<string> A(N);
  vector<int> P(N);
  for(int i=0;i<N;i++){ 
    cin>>A.at(i)>>P.at(i);
  }
  for(int i=0;i<N;i++){
    int retu=-1;
    int tokuten=0;
    string hikaku="zzzzzzzzzzz";
      for(int j=0;j<N;j++){
     if(A.at(j)<hikaku){
       retu=j;
       tokuten=P.at(j);
       hikaku=A.at(j);
     }else if(A.at(j)==hikaku){
      if(P.at(j)>tokuten){
       retu=j;
       tokuten=P.at(j);
       hikaku=A.at(j);
      }
     }
      }
    cout<<retu+1<<endl;
    A.at(retu)="zzzzzzzzzzz";
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        
        String result = "D";
        if (a.equals(b)) result = "H";
        
        System.out.println(result);
      
    }
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,k,ans=pow(10,9);
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0;i < n;i++)
    {
        cin >> v.at(i);
    }

    for(int i=0;i+k-1 < n;i++)
    {
        if(v.at(i)<0 && v.at(i+k-1)>=0){
            ans = min(ans,2*min(-v.at(i),v.at(i+k-1))+max(-v.at(i),v.at(i+k-1)));
        }else if(v.at(i+k-1)<0){
            ans = min(ans,-v.at(i));
        }else{
            ans = min(ans,v.at(i+k-1));
        }
    }
    cout << ans << endl;
}
//最適な選び方はすぐにわかる、制約も小さいので全探索すればよい
//teamでやったやつ




Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X = int(input())
    if 400 <= X <= 599:
        print(8)
    elif 600 <= X <= 799:
        print(7)
    elif 800 <= X <= 999:
        print(6)
    elif 1000 <= X <= 1199:
        print(5)
    elif 1200 <= X <= 1399:
        print(4)
    elif 1400 <= X <= 1599:
        print(3)
    elif 1600 <= X <= 1799:
        print(2)
    else:
        print(1)


    

if __name__ == '__main__':
    main()



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

int main(){
  int n,i,j,k;
  cin >> n;
  vector<int> a(n,0);
  j=0;
  for(i=0;i<n;i++){
    cin >> a.at(j);
    if(j==0||a.at(j)!=a.at(j-1)){
      j++;
    }
  }
  n=j;
  if(n==1){
    cout << 1000 << endl;
    return 0;
  }
  /*for(i=0;i<n;i++){
    cout << a.at(i) << endl;
  }*/
  vector<int> vl(n),mt(n);
  j=0;
  k=0;
  if(a.at(0)<a.at(1)){
    vl.at(0)=a.at(0);
    j=1;
  }
  for(i=1;i<n-1;i++){
    if(a.at(i)>a.at(i-1)&&a.at(i)>a.at(i+1)){
      mt.at(k)=a.at(i);
      k++;
    }else if(a.at(i)<a.at(i-1)&&a.at(i)<a.at(i+1)){
      vl.at(j)=a.at(i);
      j++;
    }
  }
  
  if(a.at(n-1)>a.at(n-2)){
    mt.at(k)=a.at(n-1);
    k++;
  }
  
  /*for(i=0;i<k;i++){
    cout << vl.at(i) << " " << mt.at(i) << endl;
  }*/
  
  ll money=1000;
  for(i=0;i<k;i++){
    money += (money/vl.at(i))*(mt.at(i)-vl.at(i));
  }
  cout << money << endl;
}

Measured memory_bytes: 3632
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int h, w, k; cin>>h>>w>>k;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    queue<P> que;
    vector<vector<int>> ans(h, vector<int>(w, -1));
    int cnt = 1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] == '#'){
                que.emplace(i, j);
                ans[i][j] = cnt++;
            }
        }
    }

    while(que.size()){
        int cy, cx;
        tie(cy, cx) = que.front(); que.pop();
        for(int i=0; i<2; i++){
            int ny = cy, nx = cx + dx[i];
            if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
            if(ans[ny][nx] != -1) continue;

            ans[ny][nx] = ans[cy][cx];
            que.emplace(ny, nx);
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(ans[i][j] != -1){
                que.emplace(i, j);
            }
        }
    }

    while(que.size()){
        int cy, cx;
        tie(cy, cx) = que.front(); que.pop();
        for(int i=2; i<4; i++){
            int ny = cy + dy[i], nx = cx;
            if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
            if(ans[ny][nx] != -1) continue;

            ans[ny][nx] = ans[cy][cx];
            que.emplace(ny, nx);
        }
    }

    cout << endl;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

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

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

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

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

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    int l,r;
    cin >> l >> r;
    ans+=r-l+1;
  }

  cout << ans << endl;
  
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int can = a - b;
	int heru = min(can,c);
	c -= heru;
	cout << c << endl;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int xx = x2 - x1;
    int yy = y2 - y1;

    int x3 = x2 - yy;
    int y3 = y2 + xx;
    int x4 = x1 - yy;
    int y4 = y1 + xx;
    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll poc(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int n;
ll a[16][16];
ll dp[1<<16];
ll dfs(int now){
    if(dp[now]>=0)return dp[now];
    ll ans=0;
    rep(i,0,n-1){
        rep(j,i+1,n){
            if(((now>>i)&1)&&((now>>j)&1))ans+=a[i][j];
        }
    }
    int u=(now-1)&now;
    while(u>0){
        Max(ans,dfs(u)+dfs(now^u));
        u=(u-1)&now;
    }
    return dp[now]=ans;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    rep(i,0,n)rep(j,0,n)cin>>a[i][j];
    fill(dp,dp+(1<<n),-1);
    dp[0]=0;
    cout<<dfs((1<<n)-1)<<endl;
    
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
int n, x, e;
long long ans = 1, MOD = 1e9+7;
int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &x);
		if(2*(i-e) >= x) (ans *= i+1-e++) %= MOD;
	}
	for(int i=n-e; i>0; i--) (ans *= i) %= MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,N,ans=0;
  cin>>N;
  pvec v(N);
  rep(i,N){
    cin>>v[i].first;
    v[i].second=i%2;
  }
  vsort(v);
  for(i=0;i<N;i+=2){
    if(v[i].second%2)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    ll n;
    cin>>n;
    string s="";
  
    while (n > 0) { 
        int rem = n % 26; 
        if (rem == 0) { 
            s+="z"; 
            n = (n / 26) - 1; 
        } 
        else 
        { 
            char c=(rem - 1) + 'a';
            s+=c ; 
            n = n / 26; 
        } 
    } 
    reverse(all(s)); 
    cout << s << endl; 
  
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

int N;
ll pw[200010];
int p[200010];
vi g[200010];
int cnt[200010];
int md;

deque<int> dp[3][200010];

void dfs(int v, int d)
{
	++cnt[d];
	md = max(md, d);

	int pos = 0;

	for (int to : g[v]) {
		dfs(to, d + 1);

		if (dp[0][v].size() < dp[0][to].size()) {
			rep(j, 3) swap(dp[j][v], dp[j][to]);	
		}

		int sz = dp[0][to].size();
		pos = max(pos, sz);

		rep(i, sz) {
			ll u[3] = {};

			rep(j, 3) {
				rep(k, 3) {
					int nj = min(2, j+k);
					u[nj] = (u[nj] + (ll)dp[j][v][i] * dp[k][to][i]) % MOD;
				}
			}
			rep(j, 3) dp[j][v][i] = u[j];	
		}

		rep(j, 3) {
			deque<int> emp;
			dp[j][to].swap(emp);
		}	
	}

	dp[1][v].push_front(1);
	dp[0][v].push_front(1);
	dp[2][v].push_front(0);

	rep(i, pos + 1) {
		dp[0][v][i] = (dp[0][v][i] + dp[2][v][i]) % MOD;
		dp[2][v][i] = 0;
	}
}

int main() {
	pw[0] = 1;
	for (int i = 1; i < 200010; ++i) {
		pw[i] = pw[i-1] * 2 % MOD;
	}

	scanf("%d", &N);

	rep(i, N) {
		scanf("%d", &p[i]);
		g[p[i]].pb(i + 1);
	}

	dfs(0, 0);
	ll ret = 0;

	for (int i = 0; i <= md; ++i) {
		ll t = dp[1][0][i];
		ret = (ret + t * pw[N + 1 - cnt[i]]) % MOD;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 466816
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}



int main(){
	string s;
	cin>>s;
	LL dp[101010][3]={};
	int l=s.length();
	int tmp=1LL;
	FOR(i,1,l+1){
		if(s[i-1]=='A'){
			dp[i][0]=add(dp[i-1][0],tmp);
			dp[i][1]=dp[i-1][1];
			dp[i][2]=dp[i-1][2];
		}else if(s[i-1]=='B'){
			dp[i][1]=add(dp[i-1][0],dp[i-1][1]);
			dp[i][0]=dp[i-1][0];
			dp[i][2]=dp[i-1][2];

		}else if(s[i-1]=='C'){
			dp[i][2]=add(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=dp[i-1][1];
			dp[i][0]=dp[i-1][0];

		}else{
			dp[i][0]=add(3LL*dp[i-1][0],tmp);
			dp[i][1]=add(dp[i-1][0],3LL*dp[i-1][1]);
			dp[i][2]=add(dp[i-1][1],3LL*dp[i-1][2]);
			tmp=mul(tmp,3LL);

		}
	}
	cout<<dp[l][2];
    return 0;
}


Measured memory_bytes: 2880
#include <iostream>
int main(void){
  int a,b,k,i;
  std::cin >> a;
    std::cin >> b;
    std::cin >> k;
  if((b-a)<k*2){
    for(i=a;i<=b;i++){
      std::cout << i << "\n" ;
    }
  }else{
    for(i=a;i<a+k;i++){
      std::cout << i << "\n";
    }
    for(i=b-k+1;i<=b;i++){
      std::cout << i << "\n";
    }
  }
}

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

using namespace std;

using ll = long long int;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanVecInt(B, N);

    vector<int> result_rev;
    result_rev.reserve(N);

    REP(i, N){
        bool ok_flag = false;
        RREP(j, N - i){
            if (B[j] == j + 1){
                B.erase(B.begin() + j);
                result_rev.emplace_back(j + 1);
                ok_flag = true;
                break;
            }
        }
        if (!ok_flag){
            cout << -1 << endl;
            return 0;
        }
    }

    RREP(i, N){
        cout << result_rev[i] << endl;
    }
}


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


void solve(long long N, std::vector<long long> H){
    int ans=0;
    int maxH=H.at(0);
    for(int i=0; i<H.size(); i++) {
        if (maxH <= H.at(i)) {
            ans++;
            maxH = H.at(i);
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vector<pair<int, int>> ans;
    int x = a[n - 1], y = a[0];
    reps(i, 1, n - 1) {
        if (a[i] < 0) {
            ans.emplace_back(x, a[i]);
            x -= a[i];
        }
        else {
            ans.emplace_back(y, a[i]);
            y -= a[i];
        }
    }
    ans.emplace_back(x, y);
    printf("%d\n", x - y);
    rep(i, sz(ans)) printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}

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

int main(){
	int n;
	char tile[21][21];
	while(cin>>n, n){
		int ans=0,xPos=10, yPos=10;

		for(int i=0;i<=20;i++){
			for(int j=0;j<=20;j++) tile[i][j]='.';
		}

		int x,y;
		for(int i=0;i<n;i++){
			cin>>x>>y;
			tile[x][y]='#';
		}


		int m;	cin>>m;
		char com;
		int s;
		for(int i=0;i<m;i++){
			cin>>com>>s;
			for(int j=0;j<s;j++){
				switch(com){
					case 'N':
						yPos++;
						break;
					case 'S':
						yPos--;
						break;
					case 'W':
						xPos--;
						break;
					case 'E':
						xPos++;
						break;
				}
				if(tile[xPos][yPos]=='#') ans++;
				tile[xPos][yPos]='@';
				//printf("(%d,%d)\n",xPos,yPos);
			}
		}
		//printf("ans=%d\n",ans);
		if(ans==n) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

	return 0;
}



Measured memory_bytes: 2996
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int64;

const int kInf = 1e9+10;
const int kMod = 1e9+7;
const int kMaxN = 1e5+10;

int pre1[kMaxN], pre2[kMaxN];

void solve() {
	int n;
	cin >> n;

	vector<int64> dp(n+1);

	dp[0] = 1;
	int64 sum = 1;

	for (int i = 1; i <= n; ++i) {
		dp[i] = sum;
		if (i >= 2) {
			dp[i] = (dp[i] - dp[i-2] + kMod) % kMod;
		}
		sum = (sum + dp[i]) % kMod;

		// cout << dp[i] << "\n";
	}
	// dp[n] = (dp[n] + 1) % kMod;

	int64 ans = 0;
	for (int i = 0; i <= n-1; ++i) {
		ans = (ans + dp[i] * (i < n-1 ? i+1 : i) % kMod) % kMod;
	}
	for (int i = 0; i <= n-2; ++i) {
		ans = (ans + dp[i] * (n-1) % kMod * (n-1) % kMod) % kMod;
	}
	ans = (ans + dp[n]) % kMod;
	cout << ans << "\n";
}

int main() {
	int tests = 1;

	for (;tests; --tests) {
		solve();
	}
}

Measured memory_bytes: 8064
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
  //happy coding

  string s;
  string t;
  cin>>s>>t;
	vector<int>m[26];
  for(int i=0;s[i];i++){
  	m[s[i]-'a'].pb(i);
  }

  for(int i=0;t[i];i++){
  	if(m[t[i]-'a'].size()==0){
  		cout<<-1<<endl;
  		return 0;
  	}
  }
  int idx = -2;
  int sum = 0;
  for(int i=0;t[i];i++){
  	auto x = lower_bound(all(m[t[i]-'a']),idx+1);
  	if(x != m[t[i]-'a'].end()){
  		idx = *x;
  	}else{
  		sum ++;
  		idx = m[t[i]-'a'][0];
  	}
  }

  cout<<sum*s.length()+idx+1<<endl;

  
  return 0;
}
int main(){
  int test = 1;
  //scanf("%d", &test);
  while (test--)solve();return 0;
} 


Measured memory_bytes: 1216
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int p;
    int q;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int asc(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;

  int tmp1 = test1.p;   /* b を基準とする */
  int tmp2 = test2.p;

  return tmp2 - tmp1;
}



int main(){
    int d;
    scanf("%d",&d);
    int dwn[26];
    for(int i=0;i<26;i++){
        scanf("%d",&dwn[i]);
    }
    data scr[d][26];
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%d",&scr[i][j].p);
            scr[i][j].q=j+1;
        }
    }
    for(int i=0;i<d;i++){
        qsort(scr[i],26,sizeof(data),comp);
        printf("%d\n",scr[i][0].q);
    }
    
}


Measured memory_bytes: 1804
#include<stdio.h>
int main(){
  int a[5],i,av=0;
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
    if(a[i]>=40)    av+=a[i];
    else av+=40;
  }
  printf("%d\n",av/5);
  return 0;
}

Measured memory_bytes: 1028