akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTwoAlpinist solver = new CTwoAlpinist();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTwoAlpinist {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] t = new int[n];
            int[] a = new int[n];
            boolean[] ft = new boolean[n];
            boolean[] fa = new boolean[n];
            ModInt res = new ModInt(1);
            for (int i = 0; i < n; i++) {
                t[i] = in.nextInt();
            }
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    ft[i] = true;
                } else if (t[i] != t[i - 1]) {
                    ft[i] = true;
                } else {
                    ft[i] = false;
                }
            }

            for (int i = n - 1; i >= 0; i--) {
                if (i == n - 1) {
                    fa[i] = true;
                } else if (a[i] != a[i + 1]) {
                    fa[i] = true;
                } else {
                    fa[i] = false;
                }
            }

            for (int i = 0; i < n; i++) {
                if (ft[i] && fa[i]) {
                    if (t[i] != a[i]) {
                        res = res.mul(0);
                    }
                } else if (ft[i] && !fa[i]) {
                    if (a[i] < t[i]) {
                        res = res.mul(0);
                    }
                } else if (!ft[i] && fa[i]) {
                    if (t[i] < a[i]) {
                        res = res.mul(0);
                    }
                } else {
                    res = res.mul(Math.min(t[i], a[i]));
                }
            }
            out.println(res.getVal());


        }

    }

    static class ModInt {
        long val;
        int MOD = (int) 1e9 + 7;

        public ModInt(long i) {
            this.val = (i + MOD) % MOD;
        }

        public ModInt mul(long l) {
            return new ModInt(this.val * l);
        }

        public long getVal() {
            return val;
        }

        public String toString() {
            return Long.toString(val);
        }

    }
}



Measured memory_bytes: 90388
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
signed main(){
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	int g=gcd(n,m);
	bool h=true;
	rep(i,g){
		if(s[n/g*i]!=t[m/g*i])h=false;
	}
	if(!h)cout<<-1<<endl;
	else cout<<lcm(n,m)<<endl;
}






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

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

    int k;
    cin >> k;
    vector<ll> a(k + 1);
    rep(i, k) cin >> a[i + 1];
    a[0] = 1LL;

    ll l = 2LL, r = 2LL;
    if (a[k] != 2LL)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = k; i >= 1; i--)
    {
        ll r2 = r / a[i] * a[i];
        ll l2 = (l + a[i] - 1) / a[i] * a[i];
        if (r2 < l2)
        {
            cout << -1 << endl;
            return 0;
        }
        l = l2;
        r = r2 + a[i] - 1;
    }
    cout << l << ' ' << r << endl;

    return 0;
}


Measured memory_bytes: 1024
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    let n = it.next().unwrap();
    let mut v = Vec::with_capacity(n);
    for _ in 0..n {
        let mut buf = String::new();
        stdin.read_line(&mut buf).ok();

        let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
        let mut a = it.next().unwrap();
        v.push(a - 1);
    }

    let mut ans = 0;
    let mut next: usize = v[0];
    for _ in 0..n {
        //        println!("next => {}", next);
        if next == 1 {
            println!("{}", ans + 1);
            return;
        }
        next = v[next];
        ans += 1;
    }
    println!("{}", -1);
    return;
}


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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    ll Z,W;
    cin>>N>>Z>>W;
    vector<ll> a(N);
    REP(i,N) cin>>a[i];

    vector<vector<ll>> dp(N+1,vector<ll>(2));
    REP(i,N+1){
        dp[i][0]=-INF;
        dp[i][1]=INF;
    }

    ll X,Y;
    REPD(i,N){
        //Xについて
        if(i==0){Y=W;}
        else{Y=a[i-1];}
        dp[i][0]=max(dp[i][0],abs(Y-a[N-1]));
        REP2(j,i+1,N){
            dp[i][0]=max(dp[i][0],dp[j][1]);
        }
        //Yについて
        if(i==0) continue;
        X=a[i-1];
        dp[i][1]=min(dp[i][1],abs(X-a[N-1]));
        REP2(j,i+1,N){
            dp[i][1]=min(dp[i][1],dp[j][0]);
        }
    }
    cout<<dp[0][0]<<endl;

}

Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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 int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);

    ll ans = 0;
    for(int i=1; i<=N; i++) {
        ll d = N / i;
        ans += d * (d + 1) / 2 * i;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3768
def main():
    n = int(input())
    bs = []
    xyss = []
    ans = 0
    for _ in range(n):
        bs.append(int(input()))
        xys = [[int(i) for i in input().split()] for __ in range(bs[-1])]
        xs = set(x-1 for x, y in xys if y == 1)
        ys = set(x-1 for x, y in xys if y == 0)
        # print(list(xs), list(ys))
        xyss.append((xs, ys))
    
    for i in range(2**n):
        # print("=== {0:b} ===".format(i))
        f = True
        for j in range(n):
            if i & (1 << j) > 0:
                xs, ys = xyss[j]
                for x in xs:
                    if (~i) & (1<<x) > 0:
                        f = False
                        # print(x)
                        #break
                for y in ys:
                    if i & (1<<y) > 0:
                        f = False
                        # print(y)
                        #break
            #if not f:
            #    break
        # print("{0}".format(f))
        if f:
            ans = max(ans, sum(1 for c in "{0:b}".format(i) if c == '1'))
    print(ans)

main()


Measured memory_bytes: 47964
import sys

for s in sys.stdin:
	pos = list(map(float, s.split(',')))
	sideB = (pos[3]-pos[1])*(pos[0]-pos[4]) - (pos[2]-pos[0])*(pos[1]-pos[5])
	sideD = (pos[7]-pos[1])*(pos[0]-pos[4]) - (pos[6]-pos[0])*(pos[1]-pos[5])
	abxcd = sideB * sideD
	sideA = (pos[1]-pos[3])*(pos[2]-pos[6]) - (pos[0]-pos[2])*(pos[3]-pos[7])
	sideC = (pos[5]-pos[3])*(pos[2]-pos[6]) - (pos[4]-pos[2])*(pos[3]-pos[7])
	cdxab = sideA * sideC

	if abxcd < 0 and cdxab < 0:
		print("YES")
	else:
		print("NO")

Measured memory_bytes: 6760
H,W = map(int,input().split())
A = ["."+input() for _ in range(H)]
DP = [[0]*(W+1) for _ in range(H+1)]
DP[1][1] = 1
A = ["#"*W]+A
MOD = 10**9 + 7
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j] == ".":
            DP[i][j] += (DP[i-1][j]+DP[i][j-1])%MOD

print(DP[H][W])

Measured memory_bytes: 43640
MOD = 10 ** 9 + 7

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()

    fact = [0] * (N + 1) # fact[n] = n!
    ifact = [0] * (N + 1)

    for i in range(N+1):
        if i == 0:
            fact[i] = 1
            continue
        fact[i] = i * fact[i-1]
        fact[i] %= MOD
    ifact[N] = pow(fact[N], MOD-2, MOD)
    for i in range(N)[::-1]:
        ifact[i] = ((i+1) * ifact[i+1])%MOD

    def comb(n, r):
        if r < 0 or r > n: return 0
        return fact[n]*ifact[n-r]*ifact[r]%MOD

    for i in range(1, K+1): print(comb(K-1, i-1) * comb(N-K+1, i) % MOD)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int):
    ret = 'Draw'
    if A != B:
        if A == 1 :
            ret = 'Alice'
        elif B == 1 :
            ret = 'Bob'
        elif A > B :
            ret = 'Alice'
        else:
            ret = 'Bob'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
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; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
vector<int> E[200001];
vector<bool> seen;
typedef pair<int, int> P;
int D[101];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;
    
    return res %= MOD;;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int main() {
    string S; cin >> S;
    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int n; cin >>n;
  vector<int>a(n),b(n),c(n-1);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n-1;i++)cin>>c[i];
  int sum=0;
  for(int i=0;i<n;i++){
    //cout<<b[a[i]-1]<<" ";
    sum+=b[a[i]-1];
    if(i<n-1&&a[i+1]-a[i]==1)sum+=c[a[i]-1];
  }
  cout<<sum<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int n = 8;

char s[n + 1] = "FESTIVAL";

ll cur[n + 1];

int main()
{
    ll K;
    cin >> K;
    for (int i = 0; i < n - 1; i++) printf("%c", s[i]);
    for (int i = 0; i < n; i++) cur[i] = 1;
    for (int i = 0; (1LL << i) <= K; i++)
    {
        assert(cur[n - 1] == (1LL << i));
        if (K & (1LL << i))
        {
            printf("L");
            cur[n] += cur[n - 1];
        }
        for (int j = n - 2; j >= max(0, i / 9); j--)
        {
            ll need = 2 * cur[j + 1];
//             cout << i << ' ' << j << ' ' << need << endl;
            while (cur[j + 1] != need)
            {
                printf("%c", s[j]);
                cur[j + 1] += cur[j];
            }
        }
    }
    cout << endl;
//     cout << cur[n] << ' ' << K << endl;
    assert(cur[n] == K);
    return 0;
}

Measured memory_bytes: 384
use std::collections::HashMap;

fn read<T: std::str::FromStr>()->T{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();

    s.trim().parse().ok().unwrap()
}

fn main(){
    let s: String = read();
    
    let (n, k) = {
        let mut ws = s.split_whitespace();
        let n:i64 = ws.next().unwrap().parse().unwrap();
        let k:i64 = ws.next().unwrap().parse().unwrap();
    
        (n, k)
    };


    let mut bucket: HashMap<i64, i64> = HashMap::new();

    for i in 0..n{
        let (b, times) = {
            let s:String = read();
            let mut ws = s.split_whitespace();
            let b:i64 = ws.next().unwrap().parse().unwrap();
            let times:i64 = ws.next().unwrap().parse().unwrap();
          
            (b, times)
        };

        //挿入
        let v = bucket.entry(b).or_insert(0);
        *v += times;
    }

    // sort
    let maxim = 100001;

    let mut index = 1;

    let mut mut_k = k;

    for i in 1..maxim{
        if mut_k <= 0 {
            break;
        }

        if let Some(x) = bucket.get(&i){
            index = i;
            mut_k -= *x;
        }
    }

    println!("{}", index);

}



Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

vector<tuple<int, int, int>> calc(vector<int> a) {
    if (a.size() <= 1u) return {};
    int p = (int)a.size() / 2;
    auto left = calc(vector<int>(a.begin(), a.begin() + p));
    auto right = calc(vector<int>(a.begin() + p, a.end()));
    vector<tuple<int, int, int>> ans;
    int max_color = 0;
    for (auto tp: left) {
        ans.push_back(tp);
        max_color = max(max_color, get<2>(tp));
    }
    for (auto tp: right) {
        ans.push_back(tp);
        max_color = max(max_color, get<2>(tp));
    }
    max_color++;
    for (int i = 0; i < p; i++) {
        for (int j = p; j < int(a.size()); j++) {
            ans.emplace_back(a[i], a[j], max_color);
        }
    }
    return ans;
}

int ans[505][505];

int main() {
    int n;
    cin >> n;
    vector<int> iv;
    for (int i = 1; i <= n; i++) iv.push_back(i);
    auto res = calc(iv);
    for (auto tp: res) ans[get<0>(tp)][get<1>(tp)] = get<2>(tp);
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            printf("%d%c", ans[i][j], " \n"[j == n]);
        }
    }
}


Measured memory_bytes: 3092
#include <stdio.h>

int main(void) {

	int n,i,j;
	char symbol;
	int number;
	int snum;
	int all[52];
	int cards[52];

	for (i = 0; i < 52; i++) {

		all[i] = 1; 
	}

	scanf("%d", &n);

	for (j = 0; j < n; j++) {

		scanf("\n%c %d", &symbol, &number);

		switch (symbol) {
		
		case 'S':
			snum = 0;
			break;
		case 'H':
			snum = 1;
			break;
		case 'C':
			snum = 2;
			break;
		case 'D':
			snum = 3;
			break;

		}

		cards[j] = snum * 13 + number - 1;
	
	}

	for (j = 0; j < n; j++) {
		int card_index = cards[j];
	
			all[card_index] = 0;
		
	}

	for (i = 0; i < 52; i++) {
		if (all[i] == 1) {
			number = (i + 1) % 13;
			if (number == 0) {
				number = 13;
			}
			snum = (i - number + 1) / 13;

			switch(snum){
			case 0:
				symbol = 'S';
				break;
			case 1:
				symbol = 'H';
				break;
			case 2:
				symbol = 'C';
				break;
			case 3:
				symbol = 'D';
				break;
			}
			
			printf("%c %d\n", symbol, number);

		}
	}

	

	return(0);

}


Measured memory_bytes: 2104
import sys
from collections import deque as dq
input = sys.stdin.readline

N, X, Y = map(int, input().split())
dp = [[N] * N for _ in range(N)]
for x in range(N):
  Q = dq([x])
  dp[x][x] = 0
  while len(Q):
    p = Q.popleft()
    if p == X - 1:
      if dp[x][Y - 1] > dp[x][p] + 1:
        dp[x][Y - 1] = min(dp[x][Y - 1], dp[x][p] + 1)
        Q.append(Y - 1)
    if p == Y - 1:
      if dp[x][X - 1] > dp[x][p] + 1:
        dp[x][X - 1] = min(dp[x][X - 1], dp[x][p] + 1)
        Q.append(X - 1)
    if p + 1 < N:
      if dp[x][p + 1] > dp[x][p] + 1:
        dp[x][p + 1] = min(dp[x][p + 1], dp[x][p] + 1)
        Q.append(p + 1)
    if p - 1 >= 0:
      if dp[x][p - 1] > dp[x][p] + 1:
        dp[x][p - 1] = min(dp[x][p - 1], dp[x][p] + 1)
        Q.append(p - 1)
table = [0] * N
for i in range(N):
  for j in range(i, N): table[dp[i][j]] += 1

for k in range(1, N):
  print(table[k])

Measured memory_bytes: 89564
#include <cstdio>
#include <algorithm>
#include <utility>
#include <cstring>

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

#define pow CHANGETHENAMESTUPID

using namespace std;

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

const int MAXN = 101;

char s[2 * MAXN];
int k;

void load() {
	scanf("%s", s);
	scanf("%d", &k);
}

void solve() {
	ll x = 0;
	int n = strlen(s);
	bool isti = true;
	for (int i = 1; i < n; i++) if (s[i] != s[0]) isti = false;
	if (isti) {
		x = (ll)k * n / 2;
	} else {
		if (s[0] != s[n-1]) {
			for (int i = 1; i < n; i++) {
				if (s[i] == s[i-1]) {
					x += k; i++;
				}
			}
		} else {
			char ch = s[0];
			int ind1 = 1;
			while (s[ind1] == ch) ind1++;
			int gap = ind1;
			int ind2 = n-1;
			while (s[ind2] == ch) ind2--;
			gap += n - 1 - ind2;
			//printf("%d\n", gap);
			x += (ll)(k-1) * (gap / 2);
			for (int i = ind1 + 1; i <= ind2; i++) {
				if (s[i] == s[i-1]) {
					x += k; i++;
				}
			}
			x += (n-1-ind2) / 2 + ind1 / 2;
		}
	}

	printf("%lld\n", x);
}

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


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


int main()
{
    int n,q;
    std::cin>>n;
    std::vector<long long> a;

    for(int i = 0; i < n; i++)
    {
        int hoge;
        std::cin>>hoge;
        a.push_back(hoge);
    }

    std::cin>>q;

    for(int i = 0; i < q; i++)
    {
        int k;
        std::cin>>k;
        if (binary_search(a.begin(),a.end(), k))
        {
        std::cout <<'1'<< std::endl;
        }else
        {
        std::cout <<'0'<< std::endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3944
#include <stdio.h>

int main(void) {
	int x,y;
	int end = 0;
	
	while(end != 1){
		
		scanf("%d",&x);
		scanf(" %d\n",&y);
		
		if(x == 0 && y == 0){
			end = 1;
			
		}
		else if(x < y){
			printf("%d %d\n",x,y);	
		}
		else {
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include <cstdio>

int main(){
    int seconds, h, m, s;
    scanf("%d", &seconds);
    h = seconds / 3600;
    m = (seconds % 3600) / 60;
    s = (seconds % 3600) % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> A(N,pair<int,int>(0,0));
  for(int i=0;i<N;i++){
    cin >> A.at(i).first >> A.at(i).second;
  }
  sort(A.begin(),A.end());
  //for(int i=0;i<N;i++){
  //  cout << A.at(i).first << " " << A.at(i).second << endl;
  //}
  long long ans=0;
  int count=0;
  for(int i=0;i<N;i++){
    if(count+A.at(i).second<M){
      for(int j=0;j<A.at(i).second;j++){
        ans += A.at(i).first;
        //cout << ans << endl;
      }
      count += A.at(i).second;
    }else{
      for(int j=0;j<M-count;j++){
        ans += A.at(i).first;
        //cout << ans << endl;
      }
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            String in = scanner.nextLine();
            int sum = 0;

            if (in.equals("0")) break;
    
            for (int i=0; i<in.length(); i++) {
                char c = in.charAt(i);
                int n = Character.getNumericValue(c);
                sum += n;
            }
    
            System.out.println(sum);
        }
    }
}



Measured memory_bytes: 26840
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  int q;
  cin >> q;
  vector<int> a(100001, 0);
  a[2] = 1;
  for (int i = 3; i <= 100000; i += 2) {
    bool flag = true;
    for (int j = 2; j * j <= i; j ++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      a[i] = 1;
      if (a[(i + 1) / 2]) a[i] = 2;
    }
  }

  vector<int> sum(100001, 0);
  for (int i = 1; i <= 100000; i ++) {
    sum[i] = sum[i - 1];
    if (a[i] == 2) sum[i] ++;
  }

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

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

def main():
  l = int(input())
  dp = [[float('inf') for _ in range(l+1)] for _ in range(5)]
  dp[0][0] = 0
  for i in range(l):
    a = int(input())
    for j in range(5):
      for k in range(j, 5):
        cost = a
        if k == 1 or k == 3:
          if a % 2 == 0 and a > 0:
            cost = 0
          elif a > 0:
            cost = 1
          else:
            cost = 2
        elif k == 2:
          if a % 2 == 1:
            cost = 0
          else:
            cost = 1
        if dp[k][i+1] > dp[j][i] + cost:
          dp[k][i+1] = dp[j][i] + cost
  print(min([dpp[-1] for dpp in dp]))


if __name__ == '__main__':
  main()


Measured memory_bytes: 104524
ABC = [int(abc) for abc in input().split()]

ABC_mod = [i%2 for i in ABC]
ABC_plus_1 = []
if ABC_mod.count(1) == 1 or ABC_mod.count(1) == 3:
  for i in range(3):
    ABC_plus_1.append(1-ABC_mod[i])
else:
  ABC_plus_1 = ABC_mod
for i in range(3):
  ABC[i] = ABC[i] + ABC_plus_1[i]

ABC.sort()
ABC_plus_2 = (ABC[-1]-ABC[0])//2 + (ABC[-1]-ABC[1])//2

ans = sum(ABC_plus_1)//2 + ABC_plus_2
print(ans)

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	cout << min(a*b, c)<< "\n";	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int a=0;
    int l=0;
    for(int i=0;i<N;i++){
        if(a<=H[i]){
            l+=1;
            a=H[i];
        }
    }
    cout<<l<<endl;
    return 0;
    }


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    if (x>=n) {cout<<t;return 0;}
    if (n%x>0) {cout<<(n/x)*t+t;return 0;}
    cout<<(n/x)*t;
    return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            int N = int.Parse (Console.ReadLine ());

            int ans = 0;
            for (int i = 1; i <= N; i += 2)
            {
                int count = 0;
                for (int j = 1; j <= i; j++)
                {
                    if (i % j == 0) count++;
                }
                if (count == 8) ans++;
            }

            Console.WriteLine (ans);
        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ld = long double;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define int long long
int N;
int A;

int dp[100][100][3030];

signed main(){
    cin >> N >> A;
    vector<int> a;
    a.resize(N);
    rep(i,0,N - 1) cin >> a[i];

    dp[0][0][0] = 1;
    rep(i,1,N){
        rep(j,0,N){
            rep(k,0,2500){
                dp[i][j][k] = dp[i - 1][j][k];
                if(k - a[i - 1] >= 0 && j > 0){
                    dp[i][j][k] += dp[i - 1][j - 1][k - a[i - 1]];
                }
            }
        }
    }
    int ans = 0;
    rep(j,1,N){

        ans += dp[N][j][A * j];
    }

    cout << ans << endl;
}


Measured memory_bytes: 119040
#include<stdio.h>

int main(){
    int n,x,y;

    scanf("%d",&n);
    x=n;
    y=0;

    while(n>0){
        y=y*10+n%10;
        n/=10;
    }

    if(x==y){
        printf("Yes");
    }
    else{
        printf("No");
    }

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int p[n];
    int diff = 0;
    for(int i=0;i<n;i++){
        cin >> p[i];  
        if(p[i] != i+1) diff++;
    }
    if(diff <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
a, b, k = [ int(v) for v in input().split() ]

a_list =  [ i for i in range(a,min(a+k,b+1)) ]
b_list =  [ i for i in range(max(a,b+1-k),b+1) ]

ans_list = sorted(list(set(a_list+b_list)))
ans_list = [ str(v) for v in ans_list ]
print(" ".join(ans_list))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int a[5];
	rep(i, 5) cin >> a[i];
	cout << 15 - a[0] - a[1] - a[2] - a[3] - a[4] << endl;
	return 0;
}

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

int main(){
    
    int H,W;
    cin>>H>>W;
    vector<vector<long int>> S(H+1,vector<long int>(W+1,0));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c;cin>>c;
            if(c=='.') S[i+1][j+1]=(S[i][j+1]+S[i+1][j])%1000000007;
            if(i==0&&j==0) S[1][1]=1;
        }
    }
    cout<<S[H][W]<<endl;
}


Measured memory_bytes: 8064
def main():
    X, Y, Z, K = list(map(int, input().split()))

    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)


    data = []
    for i in range(X):
        for j in range(Y):
            if i * j > K:
                break
            for k in range(Z):
                if i * j * k > K:
                    break
                data.append(A[i] + B[j] + C[k])

    data.sort(reverse=True)

    for i in range(K):
        print(data[i])

if __name__ == '__main__':
    main()




Measured memory_bytes: 112344
#include<iostream>
#include<bitset>
using namespace std;
int n,x,sum;
bitset<2000007>f;
int main(){
	cin>>n;
	f[0]=1;
	for(int i=0;i<n;i++){
		cin>>x;
		f|=f<<x;
		sum+=x;
	}
	for(int i=(sum+1)/2;i<=sum;i++){
		if(f[i]) {cout<<i<<endl;break;}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main()
{
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200)
    cout << s;
  else
    cout << "red" << endl;
}


Measured memory_bytes: 256
def count(a, b, c, x):
    A = 10
    B = 2

    x /= 50

    count = 0
    for an in range(0, a+1):
        for bn in range(0, b+1):
            if 0 <= (x - (an * A + bn * B)) <= c:
                count += 1

    return count


a = int(input())
b = int(input())
c = int(input())
x = int(input())
print(count(a, b, c, x))


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


int main() {
	int n,k;
	long int p;
	std::cin >> n>>k;

	std::vector<long int> v(n);
	for (long int& x : v) {
		std::cin >> x;
	}

	std::sort(v.begin(), v.end());


	p = v[k-1]-v[0];

	//std::cout <<"\n"<< p <<" "<<v[3]<<" "<< v[4] << std::endl;

	for (int i = 0; i < n-(k-1); i++) {

		if (p > v[i + k-1] - v[i]) {
			p = v[i + k-1] - v[i];
			//std::cout << p << std::endl;
		}
		//std::cout << i << std::endl;
	}



	std::cout << p << std::endl;
	return 0;
}

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


// /*bool compare(pair<int,int>& a, pair<int,int>& b){
// 	if(((a.first * 1.0) / (a.second * 1.0)) < ((b.first * 1.0) / (b.second * 1.0)))
// 		return false;

// 	return true;
// }
// */

// /*bool compare1(pair<int,int>& a, pair<int,int>& b){
// 	if(a.first < b.first)
// 		return false;

// 	return true;
// }

// bool compare2(pair<int,int>& a, pair<int,int>& b){
// 	if(b.second * ceil(a.first / b.first) < a.second)
// 		return false;
// 	return true;
// }*/
// int h,n;
// int downto(int x, int y){
// 	if(h > x)
// 	return h/x * y;
// 	return y;
// }

// bool compare3(pair<int,int>& a, pair<int,int>& b){
// 	int x = downto(a.first,a.second);
// 	int y = downto(b.first, b.second);
// 	if(x > y)
// 		return false;
// 	else if(x == y)
// 	{
// 		if(a.second > b.second)
// 			return false;
// 		return true;
// 	}
// 	return true;
// }

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

// 	vector<pair<int,int> > v;
// 	int x,y;
// 	for(int i = 0;i<n;i++)
// 		{cin>>x>>y;
// 			v.push_back(make_pair(x,y));
// 		}

// 	//sort(v.begin(),v.end(),compare1);
// 	//sort(v.begin(),v.end(),compare2);
// 	//cout<<"+++++++++++++++++++++++++++++"<<endl;
// 	int cnt =0;
// 	// for(int i =0;i <n;i++)
// 	// 	cout<<v[i].first<<" "<<v[i].second<<endl;

// 	// 	int left = h % v[0].first;

// 	// 	int req = h / v[0].first;

// 	// 	h = h - req * v[0].first;

// 	// 	cnt = cnt + req * v[0].second;
	
// 	// cout<<left<<" "<<req<<" "<<cnt<<endl;
// 	while(h > 0){
// 		// cout<<h<<endl;

// 		sort(v.begin(),v.end(),compare3);
// 		int req;
// 		if(v[0].first > h)
// 			req = 1;
// 		else
// 			req = h / v[0].first;
// 		cout<<req<<" "<<v[0].first<<endl;
// 		h = h - req * v[0].first;

// 		cnt = cnt + req * v[0].second;
// 	}
// 	cout<<cnt<<endl;
// 	return 0;

// }

#include<bits/stdc++.h>
using namespace std;

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

	int a[n];
	int b[n];

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

	int dp[h+1];
	dp[0] = 0;
	for(int i = 1;i<=h;i++)
		dp[i] = INT_MAX;
	for(int i =1;i<=h;i++){
		for(int j = 0;j <n;j++){
			dp[i] = min(dp[i],b[j] + dp[max(0,i - a[j])]);
		}
	}


	cout<<dp[h];
	return 0;
}

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

int main(){
  int h,w,sx,sy,a[SIZE][SIZE],m[250000][4];cin>>h>>w;
  REP(i,h)REP(j,w) cin>>a[i][j];
  
  bool f=0;int count=0;
  REP(i,h){
    for(int j=(i%2?w-1:0);j>=0&&j<w;j+=(i%2?-1:1)){
      if(a[i][j]%2){
        if(f){
          bool ff=0;
          int lastx=sx,lasty=sy;
          for(int k=sy;k<=i;k++){
            for(int l=(k==sy?sx:(k%2?w-1:0));l>=0&&l<w;l+=(k%2?-1:1)){
              if(k!=sy||l!=sx){
                m[count][0]=lasty;
                m[count][1]=lastx;
                m[count][2]=lasty=k;
                m[count][3]=lastx=l;
                count++;
              }
              if(k==i&&l==j){
                ff=1;
                break;
              }
            }
            if(ff) break;
          }
          f=0;
        }else{
          sx=j;sy=i;f=1;
        }
      }
    }
  }
  cout<<count<<endl;
  REP(i,count){
    cout<<m[i][0]+1<<" "<<m[i][1]+1<<" "<<m[i][2]+1<<" "<<m[i][3]+1<<endl;
  }

}


Measured memory_bytes: 6912
using System;

namespace TestProject
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string s0 = "Hoshino";
			string s1 = "Hoshina";
			string[] s = new string[n];
			for (int i = 0; i < n; i++)
			{
				s[i] = Console.ReadLine();
				s[i] = s[i].Replace(s0, s1);
			}
			foreach (var x in s)
			{
				Console.WriteLine(x);
			}
		}
	}
}

Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s;
    cin >> s;
    string k = "keyence";
    bool ok = false;
    for(int i = 0; i <= (int)s.size(); i++) {
        for(int j = i; j <= (int)s.size(); j++) {
            string ss = s.substr(0, i) + s.substr(j, s.size()-j);
            if(ss == k) ok = true;
        }
    }
    printf("%s\n", ok?"YES":"NO");
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main(){
    ll n,m;cin >>n>>m;
    vector<ll>x(m);
    vector<ll>d;
    for (int i = 0; i < m; ++i) {
        cin>>x[i];
    }
    sort(all(x));
    for (int j = 1; j <m ; ++j) {
        d.push_back(x[j]-x[j-1]);
    }
    sort(all(d));
    reverse(all(d));
    ll ans=0;
    for (int k = 0; k < m-1; ++k) {
        if(k>=n-1) {
            ans += d[k];
        }
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 2168
import math

n = int(input())
#a = int(input())
#n,a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string1 = input()
#string2 = input()
#ls = [int(input()) for i in range(n)]

numst = str(n)
num = 0
for i in numst:
  num += int(i)
if n%num == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 2940
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut w = String::new();
    io::stdin().read_line(&mut w).unwrap();
    let w: usize = w.trim().parse().unwrap();
    let mut uu: Vec<u8> = Vec::new();
    for (i, c) in buf.trim().bytes().enumerate() {
        if i % w == 0 {
            uu.push(c);
        }
    }
    println!("{}", String::from_utf8_lossy(uu.as_slice()));
}


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

int main(){
    
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    
    vector<int> where;
    vector<int> order(n+1, -1);
    
    int v = 1;
    
    while(order[v] == -1){
        
        order[v] = where.size();
        where.push_back(v);
        v = a[v-1];
        
    }
    
    int c = where.size() - order[v];
    int l = order[v];
    
    if(k<l){
        cout << where[k] << endl;
    
    }else{
        k -= l;
        k %= c;
        cout << where[k+l] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 5828
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[101],n,m,i,j,x1,x2;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	for(i=1;i<=m;i++)	{
		for(j=1;j<n;j++)	{
			x1=a[j]%i;	x2=a[j+1]%i;
			if(x1>x2)	swap(a[j],a[j+1]);
		}
	}
	for(i=1;i<=n;i++)	printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	string p[4]={"dream","dreamer","erase","eraser"};
	for(int i=0;i<4;i++)
	{
		reverse(p[i].begin(),p[i].end());
	}
	for(int i=0;i<s.size();)
	{
		bool f=false;
		for(int j=0;j<4;j++)
		{
			if(s.compare(i,p[j].size(),p[j])==0)
			{
				i+=p[j].size();
				f=true;
				break;
			}
		}
		if(!f)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 512
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
for pt in itertools.product([0,1],repeat=3):
    now = int(s[0])
    for i,x in enumerate(pt):
        # print(now)
        if x:
            now += int(s[i+1])
        else:
            now -= int(s[i+1])
    if now == 7:
        res = s[0]
        for i in range(1,4):
            tmp = '+' if pt[i-1] else '-'
            res += tmp + s[i]
        print(res+'=7')
        break
    

Measured memory_bytes: 10392
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define printv(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define ld long double
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define X first
#define Y second
#define oset tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);

// AC automaton will help me get AC!
struct AC {
    vector <vector <int>> ch;
    vector <int> cnt, f;
    AC () {extend();}
    void extend() {
        ch.pb(vector <int>(26, 0));
        cnt.pb(0);
    }
    int next(int u, int v) {
        if (!ch[u][v]) {
            ch[u][v] = ch.size();
            extend();
        }
        return ch[u][v];
    }
    void insert(string &s) {
        int now = 0;
        for (char c : s) {
            now = next(now, c - 'a');
        }
        cnt[now]++;
    }
    void build_fail() {
        f.assign(ch.size(), 0);
        queue <int> q;
        for (int i = 0; i < 26; ++i) if (ch[0][i]) q.push(ch[0][i]);
        while (q.size()) {
            int v = q.front(); q.pop();
            for (int i = 0; i < 26; ++i) if (ch[v][i]) {
                    int k = f[v];
                    while (k && !ch[k][i]) k = f[k];
                    if (ch[k][i]) k = ch[k][i];
                    f[ch[v][i]] = k;
                    cnt[ch[v][i]] += cnt[k];
                    q.push(ch[v][i]);
                }
        }
    }
    int match(string &s) {
        int k = 0, ans = 0;
        for (char c : s) {
            while (k && !ch[k][c - 'a']) k = f[k];
            if (ch[k][c - 'a']) k = ch[k][c - 'a'];
            ans += cnt[k];
        }
        return ans;
    }
};

const int mod = 1e9 + 7, x = 864197532, N = 2000087, logN = 17;

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    fop (i,0,n) cin >> a[i];
    sort(a, a + n);
    lli ans = 0;
    fop (i,0,n) fop (j,i + 1,n) {
        int p = lower_bound(a, a + n, a[i] + a[j]) - a;
        ans += max(p - 1 - j, 0);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
a = int(input())
b = int(input())
c = int(input())
s = 3*c
alpha = s-(b+c)
beta = s-(c+a)
gamma = s-(a+b)
delta = s-(alpha+beta)
print(a,b,gamma)
print((s-(a+delta)),c,(s-(beta+gamma)))
print(delta,alpha,beta)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, p;
  cin >> n >> m >> p;
  vector<vector<int>> to(n), co(n);
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b, c -= p;
    to[a].push_back(b);
    co[a].push_back(-c);
  }
  vector<ll> dist(n, LINF);
  dist[0] = 0;
  rep(i, n-1) {
    rep(now, n) rep(j, to[now].size()) {
      if (dist[now] != LINF)
        chmin(dist[to[now][j]], dist[now]+co[now][j]);
    }
  }
  vector<bool> update(n);
  rep(i, n) {
    rep(now, n) rep(j, to[now].size()) {
      if (dist[now] == LINF)
        continue;
      if (update[now] || dist[now]+co[now][j] < dist[to[now][j]])
        update[to[now][j]] = true;
    }
  }
  if (update[n-1])
    cout << -1 << endl;
  else
    cout << max(-dist[n-1], 0LL) << endl;
  return 0;
}

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

int main(){
  int N;
  
  
  int cnt2=0;
  cin>>N;
  for(int i=1;i<N+1;i+=2){
    int cnt1=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)cnt1+=1;
    }
    if(cnt1==8)cnt2+=1;
  }
  cout<<cnt2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int  a=0,b=0,c=0,d=0,i=0;
    char arr[1000]={};
    for(i=0;;i++){
        cin >> a >> b >> c;
        d++;
        if(a==-1 && b==-1 && c==-1)break;
        else{
            if(a==-1 || b==-1)cout << 'F' << endl;
            else if(a+b >= 80)cout << 'A' << endl;
            else if(a+b >=65 && 80 > a+b)cout << 'B' << endl;
            else if(a+b >=50 && 65 > a+b)cout << 'C' << endl;
            else if(a+b >=30 && 50 > a+b){
                if(c >=50)cout << 'C' << endl;
                else cout << 'D' << endl;
            }
            else if(30 > a+b)cout << 'F' << endl;
        }
    }
    /* for(i=0;i<d;i++){
        cout << arr[i];
         if(i<d-1)cout << endl;
     }*/
    //cout << endl;

return 0;

}

//1793081

Measured memory_bytes: 1152