akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.Array

data Dir = L | R deriving (Eq, Read)

-- ### IO ###

main = do
    [fldLen,speLen] <- (map read . words) <$> getLine :: IO [Int]
    field <- listArray (1,fldLen) <$> getLine
    spells <- replicateM speLen readSpell
    let left = binSearch field (1,fldLen) (findLeftmostNonZero spells fldLen)
    let right = binSearch field (1,fldLen) (findRightmostNonLim spells fldLen)
    print $ right - left

readSpell :: IO (Char, Dir)
readSpell = do
    [t:_,d] <- words <$> getLine :: IO [String]
    return (t, read d)

-- ## Algos ###

-- Binary search over {arr}, ranging from {l} to {r},
-- with the targeting logic {f}
binSearch :: Array Int a -> (Int, Int) -> (Array Int a -> Int -> Dir) -> Int
binSearch arr (l,r) f
    | l+1 >= r  = case (f arr l, f arr r) of
        (R,R) -> r+1
        (R,L) -> r
        (L,L) -> l
        (L,R) -> error "Erroneous targeting logic"
    | otherwise = let curPos = (l+r) `div` 2 in
        case f arr curPos of
            L -> binSearch arr (l, curPos) f
            R -> binSearch arr (curPos, r) f

---- # targeting logic

findLeftmostNonZero :: [(Char,Dir)] -> Int -> Array Int Char -> Int -> Dir
findLeftmostNonZero spells lim field curPos =
        if performSpell spells field lim curPos == 0
            then R else L

findRightmostNonLim :: [(Char,Dir)] -> Int -> Array Int Char -> Int -> Dir
findRightmostNonLim spells lim field curPos =
        if performSpell spells field lim curPos == lim+1
            then L else R

---- # wizardry

performSpell :: [(Char,Dir)] -> Array Int Char -> Int -> Int -> Int
performSpell spells field lim iniPos =
    foldl (spellStep field lim) iniPos spells    

spellStep :: Array Int Char -> Int -> Int -> (Char,Dir) -> Int
spellStep field lim cur_pos (target,dir)
    | cur_pos<1 || lim<cur_pos = cur_pos
    | field!cur_pos == target = case dir of
            L -> cur_pos - 1
            R -> cur_pos + 1
    | otherwise  = cur_pos


Measured memory_bytes: 54396
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
vector<int> g[N];
vector<bool> mark(N,false);
int cnt;
void dfs(int u)
{
    mark[u]=true;
    cnt++;
    for(auto v:g[u])
    {
        if(mark[v]==false)dfs(v);
    }
}
void Digvijay()
{
    int n,m;
    cin>>n>>m;
    map<pair<int,int>,int> mp;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(mp.count({x,y})||mp.count({y,x}))continue;
        g[x].push_back(y);
        g[y].push_back(x);
        mp[{x,y}]++;
        mp[{y,x}]++;
    }
    int ans=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        if(mark[i]==false)
        {
            cnt=0;
            dfs(i);
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=1;__<=_;__++)
    {
        Digvijay();
    }
}



Measured memory_bytes: 45772
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var stack = new Stack<char>();

        stack.Push(input[0]);
        var total = 0;
        for (var i =1; i < input.Length; i++)
        {
            if (stack.Peek() == input[i])
            {
                var value = stack.Pop() == '0' ? '1' : '0';
                stack.Push(value);
                total++;
            }
            else
            {
                stack.Push(input[i]);
            }
        }

        Console.WriteLine(total);
    }
}

Measured memory_bytes: 13228
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>

#define MAXN 50

using namespace std;

int A[MAXN];
int N;
vector< pair<int,int> > V;

int func ( void )
{
  int maxpos, minpos;
  int cnt = 0;

  maxpos = minpos = 0;

  for ( int i = 0; i < N; ++i ) {
    if ( A[maxpos] < A[i] ) maxpos = i;
    if ( A[minpos] > A[i] ) minpos = i;
  }

  if ( maxpos == minpos ) return cnt;

  if ( A[minpos] >= 0 ) {
    for ( int i = 1; i < N; ++i ) {
      A[i] += A[maxpos];
      V.push_back({maxpos, i});
      maxpos = i;
      ++cnt;
    }
  } else if ( A[maxpos] <= 0 ) {
    for ( int i = N-1; i >= 0; --i ) {
      A[i] -= A[minpos];
      V.push_back({minpos, i});
      minpos = i;
      ++cnt;
    }
  }

  return cnt;
}

int solve ( void ) {
  int maxpos, minpos;
  int cnt = 0;

  maxpos = minpos = 0;

  for ( int i = 0; i < N; ++i ) {
    if ( A[maxpos] < A[i] ) maxpos = i;
    if ( A[minpos] > A[i] ) minpos = i;
  }

  if ( maxpos == minpos ) return cnt;

  if ( A[maxpos] > 0 && A[minpos] < 0 ) {
    int pos = ( abs(A[maxpos]) > abs(A[minpos]) ) ? maxpos:minpos;
    for ( int i = 0; i < N; ++i ) {
      if ( i != pos ) {
        A[i] += A[pos];
        V.push_back({pos, i});
        ++cnt;
      }
    }
  }

  cnt += func();

  return cnt;
}

int main()
{
  cin >> N;

  for ( int i = 0; i < N; ++i ) scanf("%d", &A[i]);

  cout << solve() << "\n";
  for ( int i = 0; i < V.size(); ++i ) {
    cout << V[i].first+1 << " " <<  V[i].second+1 << endl;
  }

  //for ( int i = 0; i < N; ++i ) cout << A[i] << " "; cout << endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D,N;
    ll ans=0;
    ll X[4];
    string S[4];
int main(){
    cin>>N>>A;
    if(N%2==0)cout<<(N/2>=A?"YES":"NO")<<endl;
    else cout<<(N/2+1>=A?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 256
// 5/10 リアルタイム参加
// 6/13 解き直し
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

bool check(vector<P> s) {
    int h = 0;
    for (P p : s) {
        int b = h + p.first;
        if (b < 0) return false;
        h += p.second;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    // vector<int> S(N);
    // rep(i, N) cin >> S[i];
    vector<P> ls, rs;  // 増減が正のものはls、負のものはrs。
    int total = 0;
    rep(i, n) {
        string s;
        cin >> s;
        int h = 0, b = 0;
        for (char c : s) {
            if (c == '(') ++h; else --h;
            b = min(b, h);
        }
        if (h > 0) ls.emplace_back(P(b, h));
        else rs.emplace_back(P(b-h, -h));
        total += h;
    }

    sort(ls.rbegin(), ls.rend());
    sort(rs.rbegin(), rs.rend());

    if (check(ls) && check(rs) && total == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 18920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
    	int N = ni();
    	ni();
    	String[] arr = nsa(N);
    	Arrays.sort(arr);
    	out.println(String.join("", arr));
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


Measured memory_bytes: 8276
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 1e9+9;
const int mod = 1e9+7;
int n,m,sum;
int a[1009];
int main(){
    fast,cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i],sum+=a[i];
    }
    int k = 0;
    double x = (double)1/(4*m);
    for(int i=0;i<n;i++){
        if(a[i] >= x*sum) k++;
    }
    if(k >= m){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n = int(input())
def make_divisors(n):
    for  i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
cnt = 0
for i in range(1,n+1):
    divisors = []
    if i%2 == 1:
        make_divisors(i)
        if len(divisors) == 8:
            cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, x;
    cin >> N >> x;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    int ans = 0;
    for(int i = 0; i < N; i++){
        x -= A.at(i);
        if(x < 0){
            break;
        }
        ans++;
    }
    if(x > 0){
        ans--;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 3576
import java.util.BitSet;
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		BitSet[] table = new BitSet[H];
		for (int i = 0; i < H; i++) {
			BitSet bits = table[i] = new BitSet(W);
			String S = sc.next();
			char[] chars = S.toCharArray();
			for (int j = 0; j < chars.length; j++) {
				bits.set(j, chars[j] == '.');
			}
		}

		int[][] cost = new int[H][W];
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				boolean to = table[i].get(j);
				if (j == 0 && i == 0) {
					cost[i][j] = !to ? 1 : 0;
				} else if (j == 0) {
					cost[i][j] = cost[i - 1][j] + (!to && table[i - 1].get(j) ? 1 : 0);
				} else if (i == 0) {
					cost[i][j] = cost[i][j - 1] + (!to && table[i].get(j - 1) ? 1 : 0);
				} else {
					cost[i][j] = Math.min(cost[i - 1][j] + (!to && table[i - 1].get(j) ? 1 : 0),
							cost[i][j - 1] + (!to && table[i].get(j - 1) ? 1 : 0));
				}
			}
		}
		System.out.println(cost[H - 1][W - 1]);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 25940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9 + 7;

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> a(26, vector<int>());
    rep (i, s.size()) {
        int p = s[i] - 'a';
        a[p].push_back(i);
    }
    int now = 0;
    rep (i, t.size()) {
        int spos = -1;
        while (true) {
            int alp = t[now] - 'a';
            if (a[alp].empty()) {
                cout << -1 << endl;
                exit(0);
            }
            if (upper_bound(all(a[alp]), spos) == a[alp].end()) {
                break;
            }
            int spos_new = *upper_bound(all(a[alp]), spos);
            if (spos_new < spos) {
                break;
            }
            spos = spos_new;
            now++;
            if (now == t.size()) {
                cout << 1ll * i * s.size() + spos + 1 << endl;
                exit(0);
            }
        }
    }
}




Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef long double ld;
int n, a[100001], ans = 0;
signed  main() {
	cin >> n;
	rep(i, 0, n) cin >> a[i];
	int sum = 0;
	rep(i, 0, n+1) {
		if (a[i] == 0) {
			ans += floor(sum / 2.0);
			sum = 0;
		}
		else
			sum += a[i];
	}
	cout << ans << endl;
	getchar(); getchar();
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int main()
{
	int n_num;
	int k_num;

	std::cin >> n_num >> k_num;

	std::vector<int> p_price(n_num);
	for (int i = 0; i < n_num; ++i)
		std::cin >> p_price[i];

	// 最小金額
	std::sort(p_price.begin(), p_price.end());
	
	std::cout << std::accumulate(p_price.begin(), p_price.begin() + k_num, 0) << std::endl;

}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

vector<long long int> insu;

class Calc
{
    // 宣言
    long long int a;

public:
    // 素因数分解
    void decompositPrime(long long int a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long int n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            insu.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    insu.push_back(n);
}

/*
 * メイン処理
 */
int main()
{
    long long int  iNum;

    // 計算クラスインスタンス化
    Calc objCalc;


    // 自然数入力
    cin >> iNum;


    if (iNum == 1) {
        cout << 0;
        return 0;
    }

    // 素因数分解
    objCalc.decompositPrime(iNum);


    sort(insu.begin(), insu.end());

    /*for (long long int i = 0; i < insu.size(); i++) {
        cout << insu[i] << " ";
    }
    cout << "\n";*/
    //素因数分解成功


    vector<long long int> kazu;
    for (long long int i = 0; i < insu.size(); i++) {
        if (i == 0) {
            kazu.push_back(1);
        } else {
            if (insu[i] != insu[i - 1]) {
                kazu.push_back(1);
            } else {
                kazu[kazu.size() - 1]++;
            }


        }

    }

    /*for (long long int i = 0; i < kazu.size(); i++) {
        cout << kazu[i] << " ";
    }*/

    long long int ans = 0;

    long long int temp;
    long long int k;

    for (long long int i = 0; i < kazu.size(); i++) {
        temp = kazu[i];
        k = 1;
        while (true)
        {
            temp -= k;
            if (temp < 0)break;
            ans++;
            k++;
        }
        
    }

    cout << ans;




    return 0;
}


Measured memory_bytes: 3636
N = gets.to_i
as = gets.split.map(&:to_i)

s4 = 0
s2 = 0
s1 = 0
as.each do |a|
    if a % 4 == 0
        s4 += 1
    elsif a % 2 == 0
        s2 += 1
    else
        s1 += 1
    end
end

if s1 > 0 && s4 == 0
    puts 'No'
elsif s1 == 0
    puts 'Yes'
elsif s2 > 0
    if s1 > s4
        puts 'No'
    else
        puts 'Yes'
    end
else
    if s1 > s4 + 1
        puts 'No'
    else
        puts 'Yes'
    end
end

Measured memory_bytes: 8460
w,a,b = map(int,input().split())

ans = 0

if a + w < b:
    ans = b - (a + w)
elif a < b < a + w:
    ans = 0
elif a < b + w < a + w:
    ans = 0
elif b + w < a:
    ans = a - (b + w)

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define LETSGO     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;



void solve(){
    int n;
    cin >> n;
    map<string ,int>res;
    while(n--) {
        string s;
        cin >> s;
        res[s]++;
    }
    cout << "AC x " << res["AC"] << "\n";
    cout << "WA x " << res["WA"] << "\n";
    cout << "TLE x " << res["TLE"]<< "\n";
    cout << "RE x " << res["RE"] << "\n";
}





int main(){
    LETSGO
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
LL fact[MAXN], inv[MAXN], dp[MAXN];
LL power(LL base, int p) {
    LL ret = 1;
    while (p) {
        if (p & 1) ret = ret * base % mod;
        base = base * base % mod;
        p >>= 1;
    }
    return ret;
}
void make_table(int n) {
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    inv[n] = power(fact[n], mod-2);
    for (int i = n-1; i >= 0; i--) {
        inv[i] = inv[i+1] * (i+1) % mod;
    }
}
LL combine(int n, int k) {
    LL ret = fact[n] * inv[k] % mod;
    ret = ret * inv[n-k] % mod;
    return ret;
}
LL solve(int n, int k) {
    if (2*k-n < 0 || 2*k-n > k-1) return 0;
    LL ret = combine(k-1, 2*k-n) * fact[k] % mod;
    ret = ret * fact[n-1-k] % mod;
    return ret;
}
int main() {
//    freopen("test.txt", "r", stdin);
    int n; cin >> n;
    make_table(n);
    for (int i = 0; i <= n-1; i++) {
        dp[i] = solve(n, i);
    }
    LL ret = 0;
    for (int i = 0; i+1 <= n-1; i++) {
        LL tmp = (dp[i+1] - dp[i] + mod) % mod;
        tmp = tmp * (i+1) % mod;
        ret = (ret + tmp) % mod;
    }
    cout << ret << endl;
}


Measured memory_bytes: 23680
n, m = map(int, input().split())
h = 1
for i in range(n):
	h *= 2
t = [[] for i in range(m)]
for i in range(m):
	a = [int(x) for x in input().split()]
	k = a[0]
	for j in range(1, k + 1):
		t[i].append(a[j])
p = [int(x) for x in input().split()]
ans = 0
for i in range(h):
	g = []
	for j in range(n):
		x = (i&(1<<j))
		if x == 0:
			g.append(0)
		else:
			g.append(1)
	f = True
	for j in range(m):
		cnt = 0
		for x in t[j]:
			if g[x - 1] == 1:
				cnt += 1
		if cnt % 2 != p[j]:
			f = False
	if f:
		ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;

int main(){
    string s;
    cin >> s;
    map<string,bool> mp;
    vector<string> jisyo;
    int K;
    cin >> K;
    string ans;
    int cnt=0;
    bool flag=true;
    for(int j=1;j<=K && flag;j++){
        for(int i=0;i<s.size()-j+1;i++){
            string ss={};
            for(int l=0;l<j;l++){
                ss.push_back(s[i+l]);
            }
            if(mp[ss]==false){
                cnt++;
                jisyo.push_back(ss);
                mp[ss]=true;
            }
        }
    }
    sort(jisyo.begin(),jisyo.end());
    cout << jisyo.at(K-1) <<endl;
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string S;
	cin >> S;
	for (int i = 0; i<S.size(); i++)
	{
		if (i == 5 || i == 13)
			S[i] = '  ';
	}
	cout << S << endl;
}

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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}
 
template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

long long a, b, c;

int main()
{
	ios_base::sync_with_stdio(false);

	cin>>a>>b>>c;
	if (c - a - b < 0)
		return cout<<"No\n", 0;
	if (4*a*b < (c-a-b)*(c-a-b))
		cout<<"Yes";
	else
		cout<<"No";
	cout<<'\n';
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var W = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var l = W.Sum();
            var r = 0;
            var temp = l - r;
            for (int i = N - 1; i >= 0; i--)
            {
                l -= W[i];
                r += W[i];
                if (temp < Math.Abs(l - r))
                {
                    break;
                }
                else
                {
                    temp = Math.Abs(l - r);
                }
            }
            Console.WriteLine(temp);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    long N;cin>>N;
    vector<int> sequence(N);
    for(int i=0;i<N;i++)cin>>sequence.at(i);
    int count=0;
    for(int i=0;i<N;i++){
        if(sequence.at(i)%2==0){
            int j = sequence.at(i);
            while(j%2==0){
                count++;
                j /= 2;
            }
        }
    }
    cout<<count<<endl;
}

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

template<typename Monoid, typename OperatorMonoid>
struct LazySegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    using G = function<Monoid(Monoid, OperatorMonoid)>;
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
    const F f;
    const G g;
    const H h;
    const Monoid M1;
    const OperatorMonoid OM0;
    int sz, height;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    LazySegmentTree(int n, const F f, const G g, const H h,
                    const Monoid &M1, const OperatorMonoid &OM0)
        : f(f), g(g), h(h), M1(M1), OM0(OM0), sz(1), height(0)
    {
        while (sz < n) sz <<= 1, height++;
        data.assign(sz * 2, M1);
        lazy.assign(sz * 2, OM0);
    }
    void set(int k, const Monoid &x) { data[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            data[k] = f(data[k << 1 | 0], data[k << 1 | 1]);
        }
    }
    inline Monoid reflect(int k) {
        return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
    }
    inline void propagate(int k) {
        if (lazy[k] == OM0) return ;
        lazy[k << 1 | 0] = h(lazy[k << 1 | 0], lazy[k]);
        lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
        data[k] = reflect(k);
        lazy[k] = OM0;
    }
    inline void thrust(int k) {
        for (int i = height; i > 0; i--) propagate(k >> i);
    }
    inline void recalc(int k) {
        while (k >>= 1) data[k] = f(reflect(k << 1 | 0), reflect(k << 1 | 1));
    }
    void update(int a, int b, const OperatorMonoid &x) {
        thrust(a += sz);
        thrust(b += sz - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lazy[l] = h(lazy[l], x), ++l;
            if (r & 1) --r, lazy[r] = h(lazy[r], x);
        }
        recalc(a);
        recalc(b);
    }
    Monoid get(int a, int b) {
        thrust(a += sz);
        thrust(b += sz - 1);
        Monoid L = M1, R = M1;
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) L = f(L, reflect(l++));
            if (r & 1) R = f(reflect(--r), R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) { return get(k, k + 1); }
};

const int INF = (int)1e9 + 7;
int main() {
    int n, q; cin >> n >> q;
    struct T {
        long long sum; int num;
        T(long long sum, int num) : sum(sum), num(num) { }
    };
    using E = int;
    auto f = [](T a, T b) { return T(a.sum + b.sum, a.num + b.num); };
    auto g = [](T a, E b) { return T(a.num * b, a.num); };
    auto h = [](E a, E b) { (void)a; return E(b); };
    LazySegmentTree<T, E> seg(n, f, g, h, T(0, 1), E(INF));
    seg.build();
    while (q--) {
        int op; cin >> op;
        int s, t; cin >> s >> t; t++;
        if (op == 0) {
            int x; cin >> x;
            seg.update(s, t, x);
        }
        if (op == 1) {
            cout << seg.get(s, t).sum << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7852
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==b && a!=c)
{
cout<<"Yes";
}
else if(b==c && c!=a)
{
 cout<<"Yes";
}
else if(a==c && a!=b)
{
 cout<<"Yes";
}
else
{
 cout<<"No";
}
return 0;
}

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

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

    int ans=0;
    for(int i=0; i<N-2; i++){
        if(S.substr(i,3) == "ABC"){
            ans++;
        } 
    }
    cout<<ans;
    
    return 0;
}

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

const int INF = 1000000;
const int town_max = 10;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int T[town_max][town_max];
		for(int i=0;i<town_max;i++){
			for(int j=0;j<town_max;j++){
				if(i==j)
					T[i][j] = 0;
				else
					T[i][j] = INF;
			}
		}

		int m = 0;	//頂点の数
		for(int i=0;i<n;i++){
			int a, b, c;	//町の番号は0から
			cin >> a >> b >> c;
			T[a][b] = T[b][a] = c;
			if(a+1>m)
				m = a+1;
			if(b+1>m)
				m = b+1;
		}

		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					if(T[j][k]>T[j][i]+T[i][k])
						T[j][k] = T[j][i]+T[i][k];
				}
			}
		}


		int T_min = INF;    //時間の総和の最小値
		int town_min = -1;  //最小になる町の番号
		for(int i=0;i<m;i++){
			int T_sum = 0;
			for(int j=0;j<m;j++){
				T_sum += T[i][j];   //総和を計算
			}
			if(T_sum<T_min){    //最小なら
				T_min = T_sum;  //それを最小値に
				town_min = i;   //そのときの町の番号
			}
		}

		cout << town_min << " " << T_min << endl;
	}
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll Q;
typedef pair<ll,ll> P;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>Q;
	set<P> st;
	ll typ,a,b;
	cin>>typ>>a>>b;
	ll ans;
	st.insert(P(a,0));
	auto ite=st.begin();
	ans=b;
	FOR(i,1,Q){
		cin>>typ;
		if(typ==1){
			cin>>a>>b;
			st.insert(P(a,i));
			ans+=b;
			if(st.size()%2==0 && ite->first>a){
				auto ite2=ite;
				ite2--;
				ans+=llabs(a-ite->first);
				ite=ite2;
			}else if(st.size()%2==1 && ite->first<=a){
				auto ite2=ite;
				ite2++;
				ans+=llabs(a-ite->first);
				ans-=(ite2->first-ite->first);
				ite=ite2;
			}else{
				ans+=llabs(a-ite->first);
			}
		}else{
			cout<<ite->first<<' '<<ans<<endl;
		}
	}
				
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <memory>
#include <string>
#include <cstdio>
#include <ctime>
#include <complex>
#include <cassert>
#include <list>
#include <numeric>
#include <bitset>
#include <cstring>
#include <set>
#include<map>
#include<forward_list>

int main()
{
    std::string s;
    std::cin >> s;
    if((std::adjacent_find(s.begin(), s.end(), [](auto a, auto b){return a != b;}) != s.end()))
        std::cout << "Yes";
    else std::cout << "No";
}


Measured memory_bytes: 256
s = input()
numA = 0
for i in range(len(s)):
    if s[i] == 'A':
        numA = i + 1
        break

numZ = 0
for i in range(len(s)-1,-1,-1):
    if s[i] == 'Z':
        numZ = i + 1
        break
print(numZ - numA + 1)

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5,mod=1e9+7;
ll power(ll n,ll p){
    ll ans=1;
    while(p){
        if(p&1)ans*=n,ans%=mod;
        p>>=1;
        n*=n;
        n%=mod;
    }
    return ans;
}
ll n,ans,sz[N],p2[N],inv_p2[N];
vector<ll> adj[N];
void dfs(ll node,ll pr){
    sz[node]=1;
    vector<ll> a;
    for(auto &v:adj[node]){
        if(v==pr)continue;
        dfs(v,node);
        sz[node]+=sz[v];
        a.push_back(sz[v]);
    }
    if(node!=1)a.push_back(n-sz[node]);
    ll ways=1;
    for(auto &ele:a)ways+=(p2[ele]-1+mod)%mod,ways%=mod;
    ways = p2[n-1]-ways + mod;
    ways%=mod;
    ans+=ways;
    ans%=mod;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    p2[0]=1;
    for(ll i=1;i<N;i++)p2[i]=p2[i-1]*2%mod;
    for(ll i=0;i<N;i++)inv_p2[i]=power(p2[i],mod-2);
    cin>>n;
    for(ll i=1,u,v;i<n;i++)cin>>u>>v,adj[v].push_back(u),adj[u].push_back(v);
    dfs(1,-1);
    ans*=inv_p2[n];
    cout<<ans%mod;
}


Measured memory_bytes: 29824
n = int(input())
c0,c1,c2,c3 = 0,0,0,0
for i in range(n):
    S = input()
    if S=='AC':
        c0+=1
    elif S=='WA':
        c1+=1
    elif S=='TLE':
        c2+=1
    else:
        c3+=1
print(f'AC x {c0}')
print(f'WA x {c1}')
print(f'TLE x {c2}')
print(f'RE x {c3}')


Measured memory_bytes: 9132
def main():
  from collections import deque
  import sys
  input = sys.stdin.readline
  s=input().rstrip()
  q=int(input().rstrip())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input().rstrip()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()


Measured memory_bytes: 10328
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>

constexpr long long Mod = 1000000007;

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

  std::vector<int> C;
  C.reserve(N);
  int max = 0;
  int prev = -1;
  while(N--)
  {
    int x;
    std::cin >> x;
    --x;
    max = std::max(max, x);
    if (prev != x)
      C.push_back(x);
    prev = x;
  }

  N = C.size();
  std::vector<long long> dp(N, 0);
  dp[0] = 1;
  std::vector<long long> acc(max + 1, 0);
  acc[C[0]] = 1;

  for (int i = 1; i < N; ++i)
  {
    dp[i] = (dp[i - 1] + acc[C[i]]) % Mod;
    acc[C[i]] = dp[i];
  }

  std::cout << dp.back() << std::endl;

  return 0;
}



Measured memory_bytes: 4224
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();
    long n;
    n = scanner.nextLong();
   //System.out.println(n);
    while(n > 26) {
      int rem = (int) (n % 26);
      //System.out.println(rem);
      if(rem == 0)
        sb.append('z');
      else
        sb.append((char)('a' + rem - 1));
      //System.out.println(n%26);
      n = n / 26;
      if(rem == 0)
        n--;
    }
    sb.append((char)('a' + n -1));
    System.out.println(sb.reverse().toString());
  }
}

Measured memory_bytes: 35776
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,T;
	cin>>N>>T;
	vector<ll> c(N);
	vector<ll> t(N);
	REP(i,N) cin>>c[i]>>t[i];
	ll ans=INF*INF;
	REP(i,N) {
		if(t[i]<=T) ans=min(ans,c[i]);
	}
	if(ans!=INF*INF)cout<<ans<<endl;
	else cout<<"TLE"<<endl;
	return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  int N;
  cin >> N;
  vector<ll> L(N);
  rep0(i, N) cin >> L[i];
  sort(L.begin(), L.end());

  ll ans = 0;
  rep(i, 0, N) {
    rep(j, i + 1, N) {
      ll a = L[i], b = L[j];
      ll temp;
      temp = lower_bound(L.begin(), L.end(), a + b) - L.begin();
      temp = temp - j - 1;
      ans += temp;
    }
  }

  cout << ans << BR;
  return 0;
}

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

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

    string s;
    cin >> s;

    array<int, 4> a;
    for(int i = 0; i < 4; ++i){
        a[i] = int(s[i] - '0');
    }

    for(int i = 0; i < 8; ++i){
        int sum = a[0];
        sum += (i & 1) ? a[1] : -a[1];
        sum += (i & 2) ? a[2] : -a[2];
        sum += (i & 4) ? a[3] : -a[3];
        if(sum == 7){
            cout << a[0];
            cout << ((i & 1) ? '+' : '-') << a[1];
            cout << ((i & 2) ? '+' : '-') << a[2];
            cout << ((i & 4) ? '+' : '-') << a[3];
            cout << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
//abc154_e.cpp
//Sat Mar 28 18:09:59 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	ll dp[105][2][4];
	for (int i=0;i<105;i++){
		for (int j=0;j<2;j++){
			for (int k=0;k<4;k++){
				dp[i][j][k]=0;
			}
		}
	}

//Operate for 0-digit.
	dp[0][0][0] = 0;
	dp[0][0][1] = 1;
	dp[0][0][2] = 0;
	dp[0][0][3] = 0;
	dp[0][1][0] = 0;
	dp[0][1][1] = int(n[0]-'0')-1;
	dp[0][1][2] = 0;
	dp[0][1][3] = 0;

	for (int i=1;i<n.length();i++){
		int x = int(n[i]-'0');
		if (x!=0){
			dp[i][0][1] = 0;
			dp[i][0][2] = dp[i-1][0][1];
			dp[i][0][3] = dp[i-1][0][2];

			dp[i][1][1] = dp[i-1][0][1]+dp[i-1][1][1]+9;
			dp[i][1][2] = dp[i-1][0][2]+dp[i-1][1][2]+dp[i-1][0][1]*(x-1)+dp[i-1][1][1]*9;
			dp[i][1][3] = dp[i-1][0][3]+dp[i-1][1][3]+dp[i-1][0][2]*(x-1)+dp[i-1][1][2]*9;
		}else {
			dp[i][0][1] = dp[i-1][0][1];
			dp[i][0][2] = dp[i-1][0][2];
			dp[i][0][3] = dp[i-1][0][3];
			dp[i][1][1] = dp[i-1][1][1]+9;
			dp[i][1][2] = dp[i-1][1][2]+dp[i-1][1][1]*9;
			dp[i][1][3] = dp[i-1][1][3]+dp[i-1][1][2]*9;
		}
//		cout << dp[i][0][3] << " " << dp[i][1][3] << endl;
	}


	cout << dp[n.length()-1][0][k]+dp[n.length()-1][1][k]<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair

int q[100002];
int r[100002];
int s[100002];
int main(){

int n;
cin>>n;
int i,j;
int a[n+2];
a[n+1]=0;
for(i=1;i<=n;i++){
    cin>>a[i];


}
int co=0;
for(i=1;i<=n;i++){

    if(a[i]==i){

        int t=a[i];
        a[i]=a[i+1];
        a[i+1]=t;
        co++;
    }

}
cout<<co<<endl;


return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    int origin;
    cin >> origin;
    if (origin != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    map<int, int> mp;
    mp[0] = 1;
    ll ans = 1;
    for (int i = 1; i < n; i++)
    {
        int d;
        cin >> d;
        ++mp[d];
    }
    int cnt = 1;
    for (int i = 1;; i++)
    {
        if (!mp.count(i))
        {
            if (cnt == n)
            {
                cout << ans << endl;
                return 0;
            }
            else
            {
                cout << 0 << endl;
                return 0;
            }
        }
        for (int j = 0; j < mp[i]; j++)
        {
            ans = (ans * mp[i - 1]) % 998244353;
            ++cnt;
        }
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 8212
import sys

def main():
    sys.setrecursionlimit(1000000) # recursion limit hack
    buf = input()
    N = int(buf)
    edge = dict()
    ab = []
    for i in range(N):
        edge[i] = [] # zero index
    for i in range(N-1):
        buf = input()
        buflist = list(buf.split())
        a = int(buflist[0])-1 # zero index
        b = int(buflist[1])-1 # zero index
        edge[a].append(b)
        edge[b].append(a)
        ab.append((a, b))
    buf = input()
    buflist = buf.split()
    c = list(map(int, buflist))
    c = list(sorted(c, reverse=True))
    point = 0
    assigned = []
    weight = []
    for i in range(N):
        assigned.append(False)
        weight.append(0)
    start = None
    for k, v in edge.items():
        if len(v) == 1:
            start = k
            break
    recursion_graph(point, start, edge, c, weight, assigned)
    total = 0
    for x in ab:
        total += min(weight[x[0]], weight[x[1]])
    print(total)
    print(' '.join(list(map(str, weight))))

def recursion_graph(point, k, edge, c, weight, assigned):
    weight[k] = c[point]
    assigned[k] = True
    point += 1
    for node in edge[k]:
        if not assigned[node]:
            point = recursion_graph(point, node, edge, c, weight, assigned)
    return point

if __name__ == '__main__':
    main()


Measured memory_bytes: 16752
#include <iostream>
#include <numeric>
#include <cstdio>
#include <map>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int dp[1001][8] = {};
int must[1001];
int f[256];

int main(){
    int n; cin >> n;
    f['J'] = 0;
    f['O'] = 1;
    f['I'] = 2;
    getchar();
    rep(i, n) must[i] = f[getchar()];
    rep(c, 8) if(c >> 0 & 1 && c >> must[0] & 1) dp[0][c] = 1;
    rep(i, n - 1){
        rep(tdy, 8)rep(tmr, 8){
            if(tmr >> must[i + 1] & 1 && tmr & tdy){
                dp[i + 1][tmr] += dp[i][tdy];
            }
            dp[i + 1][tmr] %= 10007;
        }
    }
    cout << accumulate(dp[n - 1], dp[n - 1] + 8, 0) % 10007 << endl;
}

Measured memory_bytes: 1196
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

string s;

int dp[100010][4];

signed main(){
    io();

    in(s);

    REPEAT(i,0,s.size()+1,false){
        REPEAT(j,0,4,false){
            if(i==s.size()){
                dp[i][j]=(j==3)?1:0;
            }else{
                dp[i][j]=dp[i+1][j]*((s[i]=='?')?3:1);
                if(j<3&&(s[i]=='?'||s[i]=="ABC"[j])){
                    dp[i][j]+=dp[i+1][j+1];
                }
                dp[i][j]%=MOD;
            }
        }
    }
    out(dp[0][0]);

    return 0;
}


Measured memory_bytes: 3648
s = input()
q = int(input())

query = [[x for x in input().split()] for i in range(q)]

T2query = []
begin = []
end = []
cnt=0
for i in range(q-1,-1,-1):
    if(query[i][0]=='1'):
        cnt+=1
        continue
    if(cnt%2==1):
        if(query[i][1]=='1'):
            end.append(query[i][2])
        else:
            begin.append(query[i][2])
    else:
        if(query[i][1]=='1'):
            begin.append(query[i][2])
        else:
            end.append(query[i][2])
wb = ''.join(begin)
we = ''.join(end)
we = we[::-1] 

if(cnt%2!=0):
    s = s[::-1]

s = wb + s + we

print(s)

Measured memory_bytes: 29448
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()

x = []
y = []
h = []
for i in range(n):
    xx,yy,hh = MAP()
    x.append(xx)
    y.append(yy)
    h.append(hh)

kk = h.index(max(h))
k = 0

for i in range(101):
    for j in range(101):
        ass = h[kk] + abs(x[kk]-i) + abs(y[kk]-j)
        for r in range(n):
            if h[r]==0:
                if ass-abs(x[r]-i)-abs(y[r]-j)>0:
                    ass = -1
                    break
            else:
                if ass != abs(x[r]-i)+abs(y[r]-j)+h[r]:
                    ass = -1
                    break
        if ass!=-1:
            print(i,j,ass)
            break


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


int main() 
{
    int N;  cin >> N;
    int temp = 0;
    int top  = 0;
    int ans  = 0;

    for( int i=0 ; i<N ; i++ )
    {
        int mount;
        cin >> mount;

        // 以前の山と同等以上なら
        if( temp <= mount && top <= mount ) ans++;
        // １番高い山
        if( top < mount ) top = mount;

        temp = mount;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let mut ans = HashSet::new();
    ans.insert(2);
    ans.insert(3);
    let mut i = 4;
    while ans.len() < N-1{
        if i%2==0 || i%3==0{ans.insert(i);}
        i+=1;
    }
    let S:usize = ans.iter().sum();
    let mut ans2 = ans.iter().map(|&a| a).collect::<Vec<_>>();
    for i in 1..30001{
        if ans.contains(&i) { continue;}
        let mut check = gcd(i,S) > 1;
        for j in 0..N-1{
            if !check { break;}
            check = gcd(ans2[j],S + i - ans2[j]) > 1;
        }
        if check {
            ans2.push(i);
            break;
        }
    }
    
    let mut out = String::new();
    for tmp in ans2{
        out += &(tmp.to_string());
        out += " ";
    }
    let l = out.len();
    println!("{}",&out[..l-1]);
    
}

fn gcd(x:usize,y:usize) -> usize{
    if y==0{return x;}
    gcd(y,x%y)
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

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

	vector<vector<int>> K(26);

	fx(S.size()) {
		K[S[x] - 'a'].push_back(x+1);
	}

	ll ans = 0;
	ll s = S.size();
	int place = 1;
	fx(T.size()) {
		int k = T[x] - 'a';
		int t = K[k].size();
		if (t==0) {
			ce(-1);
			return 0;
		}
		int i=lower_bound(K[k].begin(),K[k].end(),place) - K[k].begin();
		if (i==t) {
			place = 1;
			ans += s;
			i = lower_bound(K[k].begin(), K[k].end(), place) - K[k].begin();
		}
		place = K[k][i]+1;
	}
	ce(ans+place-1)

    return 0;
}



Measured memory_bytes: 1216