akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){

    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);

    if(a>b){
        d=a;
        a=b;
        b=d;
    }
    if(a>c){
        d=a;
        a=c;
        c=d;
    }
    if(b>c){
        d=b;
        b=c;
        c=d;
    }
    printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;int n,m,f[100010],x,y,now;
inline int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
inline LL read()
{
	char c;LL d=1,f=0;
	while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
	while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
	return d*f;
}
signed main()
{
	n=read();m=read();
	for(register int i=1;i<=n;i++) f[i]=i;
	for(register int i=1;i<=m;i++) 
	{
		x=read();y=read();
		x=find(x);y=find(y);
		if(x==y) continue;
		f[y]=x;now++;
	}
	printf("%d",n-1-now);
}

Measured memory_bytes: 1980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<ll> rf;

void fctr(ll N) {
	ll n = sqrt(N);
	for (ll i = 1;i <= n;i++) {
		if (N%i == 0) {
			rf.push_back(i);
			rf.push_back(N / i);
		}
	}
	return;
}

int main(){
	ll N, S, ans, M;
	cin >> N >> S;
	if (N == S) {
		cout << N + 1 << endl;
		return 0;
	}
	if (N < S) {
		cout << -1 << endl;
		return 0;
	}
	fctr(N - S);
	sort(all(rf));
	for (ll i : rf) {
		i++;
		M = N;
		ans = 0;
		while (M) {
			ans += M % i;
			M /= i;
		}
		if (ans == S) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> s;
if(s.substr(s.length()-1,1)=="2"||s.substr(s.length()-1,1)=="4"||s.substr(s.length()-1,1)=="5"||s.substr(s.length()-1,1)=="7"||s.substr(s.length()-1,1)=="9") {
	cout<<"hon"<<endl;
} else if(s.substr(s.length()-1,1)=="0"||s.substr(s.length()-1,1)=="1"||s.substr(s.length()-1,1)=="6"||s.substr(s.length()-1,1)=="8") {
			cout<<"pon"<<endl;
		}else if(s.substr(s.length()-1,1)=="3"){
			cout<<"bon"<<endl;
		}

		return 0;
	}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll H, W;

void solve() {
	cin >> H >> W;
	if(H == 1 || W == 1) cout << 1 << "\n";
	else {
		if(W % 2) {
			cout << (H / 2) * (W / 2) + ((H + 1) / 2) * (W / 2 + 1) << "\n";
		}
		else {
			cout << H * (W / 2) << "\n";
		}
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll mod=1e9+7;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  ll m,n;
  cin >> m >> n;
  cout << mpow(m,n) << endl;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	int X = sc.nextInt();
    	int Y = sc.nextInt();
    	if (A + B < 2 * C) {
    		System.out.println(A * X + B * Y);
    	} else {
    		if (Y < X) {
    			if (A < 2 * C) {
    				System.out.println(C * 2 * Y + A * (X - Y));
    			} else {
    				System.out.println(C * X * 2);
    			}
    		} else {
    			if (B < 2 * C) {
    				System.out.println(C * 2 * X + B * (Y - X));
    			} else {
    				System.out.println(C * Y * 2);
    			}
    		}
    	}
    }
}

Measured memory_bytes: 23636
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()
arr = ["hon", "pon", "bon"]
arr2 = [1, 1, 0, 2, 0, 0, 1, 0, 1, 0]
print(arr[arr2[N % 10]])


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

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        int ans = 1;
        for(int i = 2; i <= Math.sqrt(x); i++){
            int can = i;
            while(can*i <= x){
                can *= i;
            }
            ans = Math.max(ans,can);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 19540
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H, W, K; cin >> H >> W >> K;
    vector<string> G(H);
    rep(i,H) cin >> G.at(i);
    vector<vector<int>> R(H, vector<int>(W,0));
    int num = 1;
    int empty = 0;
    rep(i,H) {
        int berry = 0;
        rep(k,W) if (G[i][k] == '#') berry++;
        if (berry == 0) {
            empty++;
            continue;
        }
        rep(k,W) {
            rep(j,empty) R[i-j-1][k] = num;
            R[i][k] = num;
            if (G[i][k] == '#') {
                berry--;
                if (berry > 0) num++;
            }
        }
        empty = 0;
        num++;
    }
    if (empty) rep(i,empty) rep(j,W) R[H-i-1][j] = R[H-empty-1][j];
    rep(i,H) {
        rep(j,W) {
            cout << R[i][j];
            if (j != W-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 4160
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;

#define what_is(x) cerr << #x << " is " << x << endl;

const int N = 1e5+1;

int n, q, a[N];
string s;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// cout.precision(1); cout << fixed;
	cin >> n >> q >> s;
	string t = "AC";
	for (int i = 0; i <= n-2; i++) {
		a[i+1] = a[i]+(s.substr(i,2)==t);
	}

	while (q--) {
		int l, r; cin >> l >> r;
		cout << a[r-2+1]-a[l-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1488
times=[int(input()) for _ in range(5)]
amari=[i%10 + 10*(i%10==0) for i in times]#余り0は10とみなす
kiriage=[j//10+(j%10!=0) for j in times]
minamari=min(amari)
if minamari==10:
    print(sum(times))
else:
    print(10*(sum(kiriage))-10+minamari)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin >>n;

  for(int i=1 ;;i++)
  if(i*i>n) {cout <<(i-1)*(i-1)<<endl; return 0;}
  }


Measured memory_bytes: 256
s = input()

res = []

for i in range(len(s)):
    for j in range(i, len(s)):
        check = s[i:j+1]
        if len(check) == check.count("A")+check.count("T")+check.count("C")+check.count("G"):
            res.append(len(check))
print(0 if res == [] else max(res))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    int x,y,i,z;
    cin >> x >> y;
    
    for(i=1;i<=10000;i++){
        if(x==0 && y==0){
            break;
        }
        if(x>y){
        cout << y <<" "<< x<<endl;
        cin >> x >> y;
       
        }
        else{
          cout << x <<" "<< y<<endl;
          cin >> x >> y;
        }
    }
    
}


Measured memory_bytes: 3052
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#define N 1000010
#define ls x << 1
#define rs x << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
#define int long long
#define XRZ 1000000007
#define debug() puts("XRZ TXDY");
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
int dx[10] = {1, -1, 0, 0};
int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar(   );
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}

double a, b, c; int n;
signed main() { n = read();
	a = b = c = 1.0 * n / 3;
	printf("%.10f\n", a * b * c);
	return 0;
}


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

using namespace std;

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

ll mod = 1e9+7;
  
int main() {
	// 入力
	ll A,B;cin>>A>>B;
    
    
	// 解法
    ll tmp = 1;
	ll ans = 0;
    while (tmp<B){
        tmp += A -1;
        ans++;
    }
    
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    def step(t, i):
        """i -> i+1 at t"""
        s = S[i] if t < S[i] else math.ceil(t / F[i]) * F[i]
        d = s + C[i]
        return d
    for i in range(N):
        t = 0
        for j in range(i, N-1):
            t = step(t, j)
        print(t)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5728
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=998244353;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;

int main(){
	cin>>s;
	if(s.size()==3) reverse(s.begin(),s.end());
	cout<<s<<endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int N, K, MAX = INT32_MIN, MIN = INT32_MAX;
	int a;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		if (a > MAX) MAX = a;
		if (a < MIN) MIN = a;
	}
	cout << MAX - MIN << endl;
}

Measured memory_bytes: 256
S = input()

cnt = [0, 0]
c_ind = 0
l_ind = 0
p = 0
res = [0]*len(S)

for i in range(len(S) - 1):
    cnt[p & 1] += 1
    if S[i] == 'L' and S[i+1] == 'R':
        j = (c_ind & 1) ^ (l_ind & 1)
        res[c_ind] += cnt[j]
        res[c_ind + 1] += cnt[j ^ 1]
        p = 0
        l_ind = i + 1
        cnt = [0, 0]
    else:
        p += 1
        if S[i] == 'R' and S[i+1] == 'L':
            c_ind = i

if p > 0:
    cnt[p & 1] += 1
    j = (c_ind & 1) ^ (l_ind & 1)
    res[c_ind] += cnt[j]
    res[c_ind + 1] += cnt[j ^ 1]

for i in range(len(S)):
    print(res[i])

Measured memory_bytes: 10060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

//オーバフローしないようにかける順番を気を付ける
ll lcm(ll x,ll y){
    return ll(x/gcd(x,y))*y;
}

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

	if (a > b)
		cout << lcm(a, b) << endl;
	else
		cout << lcm(b, a) << endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[1001][1001];
const int MOD=1e9+7;
main()
{
    int n,m;
    scanf("%lld%lld",&n,&m);
    string s[n+1];
    for(int i=1;i<=n;i++){
        cin>>s[i];
        s[i]="#"+s[i];
    }
    dp[1][1]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i][j]=='.'){
                if(s[i-1][j]=='.'){
                    dp[i][j]+=dp[i-1][j];
                    dp[i][j]%MOD;
                }
                if(s[i][j-1]=='.'){
                    dp[i][j]=(dp[i][j]%MOD+dp[i][j-1]%MOD)%MOD;
                }
            }
        }
    }
    printf("%lld",dp[n][m]);
}


Measured memory_bytes: 9088
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int n = 0, k, s;
	cin >> n >> k >> s;
	vector<int> ans(n);
	for (int i = 0; i < n; ++i) {
		if (i < k) {
			ans[i] = s;
		} else {
			ans[i] = (s < 1e8) ? 1e9 : 1;
		}
		if (i) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1664
N=int(input())
A=[]
B=[]
for i in range(N):
    AB=list(map(int,input().split()))
    A.append(AB[0])
    B.append(AB[1])

ans=0
for i in range(N-1,-1,-1):
    A[i]+=ans
    A[i]%=B[i]
    if A[i]!=0:
        ans+=B[i]-A[i]

print(ans)

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

int n,k,w;
int h[100010];
int dp[100010];

cin >> n >> k;

for(int i = 0; i < n; i++) cin >> h[i];

for(int i = 0;i < n; i++){
    if(i == 0) dp[i] = 0;
    else{
        if(i <= k) w = i;  
        int a[100010];
        for(int j = 0; j < w; j++) a[j] = abs(h[i] - h[i - j - 1]) + dp[i - j - 1];
        
        for(int l = 0; l < w; l++){
            if(a[0] > a[l]) a[0] = a[l];
            }
        dp[i] = a[0];
        }
    }
    
cout << dp[n - 1] << "\n";

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main(){
  ll n,money=1000,mn=201,kabu;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    mn=min(mn,a[i]);
    if(a[i]>mn){
      kabu=money/mn;
      money-=kabu*mn;
      money+=kabu*a[i];
      mn=a[i];
    }
  }
  cout<<money<<endl;
}


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

//ABC166D
//ABC166C
int main(void) {
  int n, m, k, i, cou=0, tmp, a, b;
  scanf("%d %d", &n, &m);
  int h[n], ox[n];
  for(i=0; i<n; i++){
    ox[i]=1;
  }
  for(i=0; i<n; i++){
    scanf(" %d", &h[i]);
  }

  for(i=0; i<m; i++){
    scanf(" %d %d", &a, &b);
    if(h[a-1]>=h[b-1]) ox[b-1]=0;
    if(h[a-1]<=h[b-1]) ox[a-1]=0;
    //printf("ox[%d]=%d ox[%d]=%d\n",a-1,ox[a-1],b-1,ox[b-1]);
  }
  for(i=0; i<n; i++){
    if(ox[i]==1) cou++;
    //printf("%d\n",ox[i]);
  }
  printf("%d", cou);
  return 0;
}

Measured memory_bytes: 2512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
using namespace std;
int dp[101][10001], w[101], v[101], n;
int main() {
	int W;
	cin >> n;
	cin >> W;
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 0; i <= n; i++) dp[i][0] = 0;
	for (int j = 0; j <= W; j++) dp[0][j] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= W; j++) {
			if (w[i + 1] > j) dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i + 1]] + v[i + 1]);
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] s1 = new String[N];
		String[] s2 = new String[N];
		
		int[] bs = new int[N];
		int[] ss = new int[N];
		for(int i = 0; i < N; i++) {
			String s = sc.next();
			s1[i] = s;
			s2[i] = s;
			int c = s.charAt(1) - '0';
			bs[i] = c;
			ss[i] = c;
		}
		BubbleSort(bs,s1, N);
		SelectionSort(ss,s2, N);

		print(s1);
		System.out.println("Stable");
		print(s2);
		System.out.println(match(s1, s2) ? "Stable" : "Not stable");
		
		sc.close();
	}
	
	void BubbleSort(int[] C, String[] s, int N) {
		for(int i = 0; i < N; i++) {
			for(int j = N-1; j > i; j--) {
				if(C[j] < C[j-1]) {
					int a = C[j];
					C[j] = C[j-1];
					C[j-1] = a;
					String tmp = s[j];
					s[j] = s[j-1];
					s[j-1] = tmp;
				}
			}
		}
	}
	
	void SelectionSort(int[] C, String[] s, int N) {
		for(int i = 0; i < N; i++) {
			int minj = i;
			for(int j = i; j < N; j++) {
				if(C[j] < C[minj]) {
					minj = j;
				}
			}
			int a = C[i];
			C[i] = C[minj];
			C[minj] = a;
			String tmp = s[i];
			s[i] = s[minj];
			s[minj] = tmp;
		}
	}
	
	 boolean match(String[] s1, String[] s2) {
	        for (int i = 0; i < s1.length; i++) {
	            if (!s1[i].equals(s2[i])) {
	                return false;
	            }
	        }
	        return true;
	    }
	
    void print(String[] s) {
        for (int i = 0; i < s.length; i++) {
            System.out.print((i == 0 ? "" : " ") + s[i]);
        }
        System.out.println();
    }

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 26280
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<char> c(N);
    REP(i, N) cin >> c[i];
    queue<int> idxwhite;
    REP(i, N)
    {
        if ('W' == c[i]) idxwhite.push(i);
    }
    queue<int> idxred;
    for (int i = N - 1; i >= 0; --i)
    {
        if ('R' == c[i]) idxred.push(i);
    }
    int ans = 0;
    while(!idxwhite.empty() && !idxred.empty())
    {
        int wid = idxwhite.front();
        idxwhite.pop();
        int rid = idxred.front();
        idxred.pop();
        if (rid < wid) break;
        else ++ans;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4440
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,m=get_i
island={}
m.times do|i|
  a,b=get_i
  a-=1
  b-=1
  if island[a]==nil
    island[a]=[]
  end
  island[a].push(b)
end
flag=false
island[0].each do|num|
  if island[num]!=nil and island[num].include?(n-1)
    flag=true
    break
  end 
end
puts yn_judge(flag,"POSSIBLE","IMPOSSIBLE")

Measured memory_bytes: 17276
A,B = map(int,input().split())
PA = 1

while PA <= 1250:
    if PA*0.08 >= A:
        break
    else:
        PA += 1

if int(PA*0.1) == B:
    print(PA)

elif PA*0.1 >= B+1:
    print(-1)

else:
    while PA <= 1000:
        if PA*0.1 >= B:
            break
        else:
            PA +=1
    if int(PA*0.08) == A:
        print(PA)
    else:
        print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int main()
{
	int n,k;
	cin>>n>>k;

	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	vector<int>dp(n+1,INT_MAX);
	dp[n]=0;
	for(int i=n-1;i>=1;i--)
	{
		for(int j=1;j<=k;j++)
		{
			if(i+j>n)break;
			dp[i]=min(dp[i],abs(a[i+j]-a[i])+dp[i+j]);
		}
		//cout<<current<<endl;
	}
	cout<<dp[1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,c;
 c=0;
 string s,t;
 cin >> s >> t;
 for(i=0;i<s.length();i++)
 c+=(s[i]!=t[i]);
 cout << c;
 return 0;
}

Measured memory_bytes: 3860
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;

bool isPrime(ll n)
{
	if(n==1||n==2||n==3||n==5||n==7)
		return 1;
	else
	{
		ll i,j,k,l,m;
		for(i=2;i<=sqrt(n);i++)
		{
			if(n%i==0)
				return 0;
		}
		return 1;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll x,a;
	cin>>x>>a;
	if(x<a)
		cout<<0;
	else
		cout<<10;
	return 0;
}
	

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a[];
		
		a = new int[10];
		while (sc.hasNext()) {
			String st = sc.next();
			for (int i = 1; i <= 9; i++) {
				a[i] = st.charAt(i - 1);
			}
			if (a[1] == a[2] && a[2] == a[3] && a[1] != 's') {
				System.out.println((char)(a[1]));
			} else if (a[4] == a[5] && a[5] == a[6] && a[4] != 's') {
				System.out.println((char)(a[4]));
			} else if (a[7] == a[8] && a[8] == a[9] && a[7] != 's') {
				System.out.println((char)(a[7]));
			} else if (a[1] == a[4] && a[4] == a[7] && a[1] != 's') {
				System.out.println((char)(a[1]));
			} else if (a[2] == a[5] && a[5] == a[8] && a[2] != 's') {
				System.out.println((char)(a[2]));
			} else if (a[3] == a[6] && a[6] == a[9] && a[3] != 's') {
				System.out.println((char)(a[3]));
			} else if (a[1] == a[5] && a[5] == a[9] && a[1] != 's') {
				System.out.println((char)(a[1]));
			} else if (a[3] == a[5] && a[5] == a[7] && a[3] != 's') {
				System.out.println((char)(a[3]));
			} else {
				System.out.println("d");
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t { as swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(auto &v : a) cin >> v;
    map<ll, ll> sumMap{{0, 1}};
    ll sum = 0;
    for (auto v : a) {
        sum += v;
        auto target = sumMap.find(sum);
        if (target != sumMap.end()) {
            target->second++;
        } else {
            sumMap.insert(make_pair(sum, 1));
        }
    }
    ll pairs = 0;
    for (auto pair : sumMap) {
//        cerr << pair.first << ' ' << pair.second << endl;
        pairs+= pair.second * (pair.second - 1) / 2;
    }
    cout << pairs << endl;
}



Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;

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/gcd(a, b))*b;
}

typedef long double ld;
const ld eps = 1.0E-14; // 許容される誤差




int main() {

    ld a,b,c; cin >> a >> b >> c;

    if(sqrt(a) + sqrt(b) + eps < sqrt(c)) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  ll L, R;
  cin >> L >> R;

  if (R - L > 2019) {
    cout << 0 << endl;
    return 0;
  }

  L = L % 2019;
  R = R % 2019;

  // cout << L << " " << R << endl;

  int result = INF;
  for (int i = L; i <= R; i++) {
    for (int j = i + 1; j <= R; j++) {
      result = min(result, i * j % 2019);
    }
  }

  cout << result << endl;

  return 0;
}


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

int main(){
  int w,h,n;
  cin >> w>> h >> n;
  int left=0,right=w,bottom=0,top=h;
  for(int i=0; i<n; i++){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1)left=max(left,x);
    if(a==2)right=min(right,x);
    if(a==3)bottom=max(bottom,y);
    if(a==4)top=min(top,y);
  }
  int ans = 0;
  cout << max(0,right-left)*max(0,top-bottom) << endl;
}

Measured memory_bytes: 256
N = input()
LISTSTR = list(N)

ans = ''
for i in range(len(LISTSTR)):
    mae = ''
    if i != 0:
        mae = ans[-1]
    str = LISTSTR[i]


    if str != '?':
        ans += str
    elif mae == '?':
        ans += 'D'
    else:
        ans += 'D'


if len(LISTSTR) == 1:
    ans = 'D'



print(ans)



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

int A, B;

int main() {
    cin >> A >> B;
    int ans = -300;

    ans = max(ans, A+B);
    ans = max(ans, A-B);
    ans = max(ans, A*B);

    cout << ans << endl;

    return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v{a, b, c};
    sort(v.begin(),v.end());
    string str;
    
    for(auto x : v)
        str += to_string(x) + " ";
        
    str.pop_back();
    cout << str << endl;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    unordered_map<string, int> UM;
    int tmp = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if (UM.count(s) == 1) {
            ++UM[s];
        } else {
            UM[s] = 1;
        }
        tmp = max(tmp, UM[s]);
    }
    vector<string> ans;
    for (auto e : UM) {
        if (e.second == tmp) {
            ans.push_back(e.first);
        }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < (int)ans.size(); ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}



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

signed main(){
    int N,M;cin>>N>>M;
    vector<int> box(N,1),red(N,0);
    red[0]=1;
    REP(i,M){
        int x,y;
        cin>>x>>y;
        x--;y--;
        if(red[x]==1){
            if(box[x]==1) red[x]=0;
            red[y]=1;
        }
        box[x]--;
        box[y]++;
    }
    int ans=0;
    REP(i,N) if(red[i]==1) ans++;
    cout<<ans<<endl;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    cout << (N == M ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;

  if ((A % 2 != 0) && (B % 2 != 0)) {
    cout << "Odd" << endl;
  } else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct SegmentTree {
  using T = int;
  static T op(const T& a, const T& b) { return min(a, b); }
  static constexpr T e() { return 2e9 + 1; }

  const int n;
  V<T> t;
  SegmentTree(int _n) : n(_n), t(2 * n, e()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  T acc(int l, int r) const {
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  void set(int i, const T& a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int _n) : n(_n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  V<> b(n); for (auto&& e : b) cin >> e;
  auto va = a, vb = b;
  sort(begin(va), end(va));
  sort(begin(vb), end(vb));
  for (int i = 0; i < n; ++i) {
    if (va[i] > vb[i]) {
      return cout << "No" << '\n', 0;
    }
  }
  SegmentTree st(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    st[i] = vb[i] - va[i + 1];
  }
  st.build();
  for (int i = 0; i < n; ++i) if (a[i] <= b[i]) {
    int ia = lower_bound(begin(va), end(va), a[i]) - begin(va);
    int ib = lower_bound(begin(vb), end(vb), b[i]) - begin(vb);
    if (ia >= ib) {
      return cout << "Yes" << '\n', 0;
    }
    if (st.acc(ia, ib) >= 0) {
      return cout << "Yes" << '\n', 0;
    }
  }
  V<> a_ord(n);
  iota(begin(a_ord), end(a_ord), 0);
  sort(begin(a_ord), end(a_ord), [&](int i, int j) { return a[i] < a[j]; });
  V<> b_ord(n);
  iota(begin(b_ord), end(b_ord), 0);
  sort(begin(b_ord), end(b_ord), [&](int i, int j) { return b[i] < b[j]; });
  V<> to(n);
  for (int t = 0; t < n; ++t) {
    to[a_ord[t]] = b_ord[t];
  }
  UnionFind uf(n);
  for (int i = 0; i < n; ++i) {
    uf.unite(i, to[i]);
  }
  if (uf.size(0) < n) {
    return cout << "Yes" << '\n', 0;
  }
  cout << "No" << '\n';
}

Measured memory_bytes: 4224
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;

 
int main(){
	int m;
	cin >> m;
	for(int i = 0; i < m; i++) {
		double a, b, money, in, sum, max;
		int y, c, d, n;
		cin >> a >> y >> n;
		double e[100];
		for(int j = 0; j < n; j++) {
			money = a;
			sum = 0;
			cin >> c >> in >> d;
			for(int k = 0; k < y; k++) {
				if(c == 0) {
					b = money * in;
					money -= d;
					sum += floor(b);
				} else {
					b = floor(money * in);
					money = money + b - d;
				}
			}
			if(c == 0) e[j] = money + sum;
			else e[j] = money;
		}
		max = e[0];
		for(int j = 1; j < n; j++) {
			if(max < e[j]) max = e[j];
		}
		cout << (int)max <<endl;
		
	}
  
	return 0;
}

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

const int MaxCardNum = 9;
const int CardSetNum = 3;
const int CardNumInSet = MaxCardNum / CardSetNum;
vector<int> cardNums;
vector<bool> cardVisited;
vector<int> newCardNums;

void DataInpt() {
	// Read all numbers on card first
	cardNums.clear();
	for (int i = 0; i < MaxCardNum; i++) {
		int cardNum;
		cin >> cardNum;
		cardNums.push_back(cardNum);
	}
	// Then add corresponding color number on each card
	for (int i = 0; i < MaxCardNum; i++) {
		string color;
		cin >> color;
		if (color == "G") {
			cardNums[i] += 10;
		} else if (color == "B") {
			cardNums[i] += 20;
		}
	}
}

bool CheckSolutionValid() {
	for (int i = 0; i < CardSetNum; i++) {
		int b = i * CardNumInSet;
		if (newCardNums[b] == newCardNums[b + 1] && newCardNums[b + 1] == newCardNums[b + 2]) {
			continue;
		}
		if (newCardNums[b] == newCardNums[b + 1] - 1 && newCardNums[b + 1] == newCardNums[b + 2] - 1) {
			continue;
		}
		return false;
	}
	return true;
}

bool Dfs(int depth) {
	if (depth >= MaxCardNum) {
		return CheckSolutionValid();
	}
	for (int i = 0; i < MaxCardNum; i++) {
		if (cardVisited[i] == false) {
			cardVisited[i] = true;
			newCardNums[depth] = cardNums[i];
			if (Dfs(depth + 1)) {
				return true;
			}
			cardVisited[i] = false;
		}
	}
	return false;
}

void Solve() {
	DataInpt();
	cardVisited.clear();
	cardVisited.resize(MaxCardNum, false);
	newCardNums.clear();
	newCardNums.resize(MaxCardNum, 0);
	if (Dfs(0)) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
}

int main() {
	int setNum = 0;

	cin >> setNum;
	for (int i = 0; i < setNum; i++) {
		Solve();
	}

	return 0;
}

Measured memory_bytes: 1232
# test
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))


Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    ll n, k, orig_k;
    cin >> n >> k;
    orig_k = k;
    int dst[n] = {};
    int hist[n] = {};
    for(int i=0;i<n;++i)
    {
        cin >> dst[i];
        dst[i]--;
        hist[i] = -1;
    }   
    int current = 0;
    int step = 0;
    while(true)
    {
        if(k == 0)
        {
            cout << (current + 1) << endl;
            break;
        }
        hist[current] = step;
        int next = dst[current];
        if(hist[next] != -1)
        {
            // loop detected
            int cycle_len = (step + 1) - hist[next];
            orig_k -= hist[next];
            orig_k = orig_k % cycle_len;
            current = next;
            while(orig_k > 0)
            {
                current = dst[current];
                orig_k--;
            }
            cout << (current + 1) << endl;
            break;
        }

        current = next;
        ++step;
        --k;
    }    
}

Measured memory_bytes: 5172
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF ((1<<30)-1+(1<<30))
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(n); ++i)
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; }


int main()
{
	const int sz = 1e7;
	vector<int> bkt(sz + 1, 2);
	bkt[0] = 0; bkt[1] = 1;
	for (int i = 2; i <= sz / 2; ++i) {
		for (int j = i * 2; j < sz + 1; j += i) {
			++bkt[j];
		}
	}
	int N; cin >> N;
	ll ans = 0;
	rep(i, N+1) {
		ans += (ll)i * bkt[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 41704
#include <iostream>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
 
 
int main() {
    int N,M;
    cin >> N >> M ;
    vector<int>V;
    int allNum= 0;
    for (int i = 0; i < N; i++){
        int num;
        cin >> num;
        V.push_back(num);
        allNum += num;
    }
    int cnt = 0;
    for (int i = 0; i < N; i++){
        if (V[i]*(4*M) >= allNum){
            cnt++;
        }
        if (M == cnt){
            cout << "Yes"<<endl;
             return 0;
        }
    }
    cout << "No"<<endl;
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/* #include <atcoder/all> */
#include <iostream>
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<vint> v(10);
    REP(i, n) {
        int now = s[i] - '0';
        v[now].push_back(i);
    }
    int ans = 0;
    REP(i, 10) {
        if (v[i].size() == 0) continue;
        REP(j, 10) {
            if (v[j].size() == 0) continue;
            REP(k, 10) {
                if (v[k].size() == 0) continue;
                int idx_i = v[i][0];
                auto ite_j = upper_bound(ALL(v[j]), idx_i);
                if (ite_j == v[j].end()) continue;
                int idx_j = *ite_j;
                auto ite_k = upper_bound(ALL(v[k]), idx_j);
                if (ite_k == v[k].end()) continue;
                ++ans;
            }
        }
    }
    cout << ans << endl;
}


int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,A;
  cin>>H>>A;
  int Ans;
  if(H<=A) Ans=1;
  else {
      if( H%A==0) Ans=H/A;
      else Ans=H/A+1;
  }
  cout<<Ans<<endl;
   return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    end = len(S)
    while end>0:
        if S[end-5:end]=='dream' or S[end-5:end]=='erase':
            end -= 5
        elif S[end-7:end]=='dreamer':
            end -= 7
        elif  S[end-6:end]=='eraser':
            end -= 6
        else:
            print('NO')
            break
    else:
        print('YES')



if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
import queue

N = int(input())

# Adjacency matrix
e = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    e[a].append(b)
    e[b].append(a)

even_v = []
odd_v = []

is_reached = [False] * (N+1)
q = queue.Queue()
# [start vertex, total distance]
q.put([1, 0])

# BFS
while not q.empty():
    v, d = q.get()
    if is_reached[v]:
        continue
    is_reached[v] = True
    
    if d%2 == 0:
        even_v.append(v)
    else:
        odd_v.append(v)

    for tv in e[v]:
        q.put([tv, d+1])

# Remainder lists [1..N] mod 3
r1 = list(range(1, N+1, 3))
r2 = list(range(2, N+1, 3))
r3 = list(range(3, N+1, 3))

p = [0] * N
if len(even_v) <= len(r3):
    # Embed r3 in even_v
    for v in even_v:
        p[v-1] = r3.pop()
elif len(odd_v) <= len(r3):
    # Embed r3 in odd_v
    for v in odd_v:
        p[v-1] = r3.pop()
else:
    # Embed r1 in even_v
    for v in even_v:
        if not r1:
            break
        p[v-1] = r1.pop()
    # Embed r2 in odd_v
    for v in odd_v:
        if not r2:
            break
        p[v-1] = r2.pop()

# Collect unused vertexes
rv = []
rv.extend(r1)
rv.extend(r2)
rv.extend(r3)
for i, _ in enumerate(p):
    if p[i] == 0:
        p[i] = rv.pop()

ans = ' '.join(list(map(str, p)))
print(ans)


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

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) {
    p[i] -= x;
  }
  int ans = x;
  rep(k, 101) {
    bool okp = true;
    bool okm = true;
    rep(i, n) {
      if (k == p[i]) {
        okp = false;
      }
      if (p[i] == (-1) * k) {
        okm = false;
      }
    }
    if (okp || okm) {
      if (okm) {
        ans = x - k;
        cout << ans << endl;
        return 0;
      }
      if (okp) {
        ans = x + k;
        cout << ans << endl;
        return 0;
      }
    }
  }
}


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


using namespace std;



int main() {
	int64_t H;
	cin >> H;

	int64_t height = 0;

	while (H != 0) {
		
		H /= 2;
		height++;

	}
	int64_t attack = 0;
	for (int64_t i = 0; i < height; i++) {
		attack += attack + 1;

	}
	cout << attack;
	return 0;

}

Measured memory_bytes: 888
use std::collections::BTreeMap;

const MOD: u64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: u64 = sc.read();

    let mut dp: BTreeMap<u64, BTreeMap<u64, u64>> = BTreeMap::new();
    println!("{}", rec(n, n, &mut dp));
}

fn rec(s: u64, x: u64, dp: &mut BTreeMap<u64, BTreeMap<u64, u64>>) -> u64 {
    if s == 0 {
        return 1;
    }

    if dp.contains_key(&s) {
        if dp[&s].contains_key(&x) {
            return dp[&s][&x];
        }
    } else {
        dp.insert(s, BTreeMap::new());
    }

    let mut ans = rec(s / 2, x / 2, dp) % MOD;
    ans = (ans + rec((s - 1) / 2, (x - 1) / 2, dp)) % MOD;
    if s >= 2 {
        ans = (ans + rec((s - 2) / 2, x / 2, dp)) % MOD;
    }
    dp.get_mut(&s).unwrap().insert(x, ans);
    return ans;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
using namespace std; 
 
const int N = 2e5 + 1000, OO = 1e9 + 100, M = 1e9 + 7, P = 6151, SQ = 120, lg = 100;
typedef pair <int, int> pii;
int a[N];

int32_t main() {
    use_fast;
    int n, m;
    cin >> n >> m;
    vector <int> v;
    for(int i = 1; i <= n; i++) {
    	cin >> a[i];
    	int x = a[i];
    	int k = 0;
    	x /= 2;
    	while(x % 2 == 0) {
    		x /= 2;
    		k++;
		}
		v.pb(k);
	}
	sort(v.begin(), v.end());
	if(v[(int)v.size() - 1] != v[0]) 
		return cout << 0, 0;
	int lc = 1;
	for(int i = 1; i <= n; i++) {
		a[i] /= 2;
		int h = __gcd(a[i], lc);
		lc = (lc * a[i]) / h;
	}
	m /= lc;
	cout << (m + 1) / 2 << endl;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 1912
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = -1
num = sum(b)
for i in a:
    if i == m+1:
        num += c[m-1]
    m = i
print(num)

Measured memory_bytes: 9188