akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    string str;
    cin>>str;
    ll res = 0, prev = -1, cnt;
    for(int i = 0; i < str.size(); i++)
    {
        if(str[i] == '<')
        {
            cnt = 0;
            while(str[i] == '<')
            {
                cnt++;
                i++;
            }
            prev = cnt;
            res += (((cnt*(cnt+1)))/2);
            i--;
        }
        else if(str[i] == '>')
        {
            cnt = 0;
            while(str[i] == '>')
            {
                i++;
                cnt++;
            }
            if(prev == -1)res += (((cnt*(cnt+1)))/2);
            else if(prev > cnt)
            {
                cnt--;
                res += (((cnt*(cnt+1)))/2);
            }
            else
            {
                res -= prev;
                res += (((cnt*(cnt+1)))/2);
            }
            i--;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 4268
n,x,y = map(int,input().split())
left = x-1
mid = y-x+1
right = n-y

x_to_mid = [0] * n
x_to_mid[0] = 1
for i in range(1, mid//2):
    x_to_mid[i] = 2
x_to_mid[mid//2] = 1 + mid%2

ans = [0] * n
#LL,RR
for i in [left,right]:
    for j in range(1,i):
        ans[j] += i-j

#mid-mid
for i in range(1, 1 + mid//2):
    ans[i] += mid * x_to_mid[i] // 2

#LR
for i in range(left):
    for j in range(right):
        ans[i+j+3] += 1

#L-mid,R-mid
for i in [left,right]:
    for j in range(n):
        tmp = x_to_mid[j]
        if(tmp==0):
            break
        for k in range(1,i+1):
            ans[ j+k ] += tmp

for i in ans[1:]:
    print(i)

Measured memory_bytes: 43204
from math import gcd

MOD = 1000000007

def inv(a, b):
    if a < 0:
        a, b = -a, -b
    return (-b, a)

def solve(n, a, b):
    zero_zero = 0
    zero = 0
    inf = 0
    D = {}
    for i in range(n):
        p, q = a[i], b[i]
        if (p == 0) and (q == 0):
            zero_zero += 1
        elif p == 0:
            zero += 1
        elif q == 0:
            inf += 1
        else:
            r = gcd(p, q)
            p, q = (p // r, q // r)
            if q < 0:
                p, q = -p, -q
            k = (p, q)
            if not k in D:
                D[k] = 0
            D[k] += 1
    group = set()
    for (p, q), v in D.items():
        if not inv(p,q) in group:
            group.add((p,q))
    pow2 = [0] * (n+1)
    pow2[0] = 1
    for i in range(n):
        pow2[i+1] = (pow2[i] * 2) % MOD
    ans = 1
    for p, q in group:
        t = pow2[D[p,q]]
        if inv(p, q) in D:
            t += pow2[D[inv(p, q)]] - 1
        ans = (ans * t) % MOD
    ans *= pow2[zero] + pow2[inf] - 1
    return (ans + zero_zero - 1) % MOD

n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

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

int main(){
  vi time(5);
  rep(i,5) cin >> time[i];
  sort(time.begin(),time.end());
  int ans = 100000000;
  do{
    int t=0;
    rep(i,5){
      t += time[i];
      if(i!=4) t = (t+9)/10*10;
    }
    ans = min(ans, t);
  }while(next_permutation(time.begin(),time.end()));
  cout << ans << endl;
}


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


int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(){

  int n,m,i;
  scanf("%d %d",&n,&m);
  int x[m],h[m-1],s;
  
  for(i=0;i<m;i++){
    scanf("%d",&x[i]);
  }
  
   qsort(x, m, sizeof(int), compare_int);
  s=0;
  
  for(i=0;i<m-1;i++){
    h[i]=x[i]-x[i+1];
  }
  
  qsort(h, m-1, sizeof(int), compare_int);
  
  for(i=n-1;i<m-1;i++){
    s=s+h[i];
  }
  printf("%d",s);
  
}

Measured memory_bytes: 1268
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,x,n) for(int i = (int)(x);i < (int)(n);++i)    
#define seg_size 524288
using P=pair<int,int>;
#define mod 1000000007
ll gg(ll a,ll b){
    ll r=1;
    while(b){
        if(b%2==1)r=r*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return r;
}
ll f(int x,int y){
    ll a=1,b=1;
    rep(i,1,x+1)a=a*i%mod;
    rep(i,1,y+1)a=a*i%mod;
    rep(i,1,x+y+1)b=b*i%mod;
    return b*gg(a,mod-2)%mod;
    
}

int main(){
    
    int x,y;
    cin>>x>>y;
    if((x+y)%3){
        cout<<0<<endl;
        return 0;
    }
    int n=(x+y)/3;
    if(x<n||y<n){
        cout<<0<<endl;
        return 0;
    }
    x-=n,y-=n;
    ll ans=f(x,y);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

LL n,cnt = 0;
void solve(LL v,LL x){
	while(v % x == 0) v = v / x;
	if(v % x == 1) cnt ++;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n; cnt ++;
	for(LL i = 2;i * i <= n;i ++){
		if(n % i == 0){
			solve(n,i);
			if(i * i != n) solve(n,n / i);
		}
	}
	n --;
	for(LL i = 2;i * i <= n;i ++){
		if(n % i == 0){
			if(i * i == n) cnt ++;
			else cnt += 2;
		}
	}
	if(n != 1) cnt ++;
	cout << cnt << endl;
	return 0;
}
//

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

using namespace std;

#define ll long long

int main()
{
    ll N, W;
    cin >> N >> W;

    vector<int> v;
    vector<ll> w;

    int sum = 0;
    for(int i = 0; i < N; i++)
    {
        ll val, weight;
        cin >> weight >> val;
        v.push_back(val);
        w.push_back(weight);

        sum += val;
    }

    //dp[i][v] - min weight using i items get value v
    //dp[i][v] = min(dp[i-1][v], dp[i-1][v-v[i]] + w[i])
    vector<vector<ll>> dp(N+1, vector<ll>(sum+1, INT_MAX));
    dp[0][0] = 0;

    for(int i = 1; i <= N; i++)
    {
        for(int j = 0; j <= sum; j++)
        {
            if(j - v[i-1] >= 0)
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

//    for(auto& v: dp)
//    {
//        for(auto e: v)
//            cout << e << " ";
//        cout << endl;
//    }

    for(int i = N; i >= 1; i--)
    {
        for(int j = sum; j >= 0; j--)
        {
            if(dp[i][j] <= W)
            {
                cout << j << endl;
                return 0;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 80256
import java.util.*;
import java.io.*;
 
public class Main {
     
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
     
    private void solv() {
        Scanner input = new Scanner(System.in);
         
        int n = input.nextInt();
        int[] S = new int[n];
        for (int i = 0; i < n; i++) S[i] = input.nextInt();
         
        int q = input.nextInt();
        int[] T = new int[q];
        for (int i = 0; i < q; i++) T[i] = input.nextInt();
         
        Arrays.sort(S);
        Arrays.sort(T);
         
        int i = 0, j = 0, count = 0;
        while (j < q && i < n) {
            if (S[i] < T[j]) {
                i++;
            } else if (S[i] == T[j]) {
                count++;
                while (i < n && S[i] == T[j]) i++;
            } else {
                j++;
            }
        }
         
        System.out.println(count);
    }
     
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
     
    private static class Scanner {
        BufferedReader r;
        StreamTokenizer st;
         
        public Scanner(InputStream in) {
            r = new BufferedReader(new InputStreamReader(in));
            st = new StreamTokenizer(r);
        }
         
        public String next() {
            nextToken();
            return st.sval;
        }
         
        public Integer nextInt() {
            nextToken();
            return (int)st.nval;
        }
         
        private int nextToken() {
            int token = st.TT_EOF;
            try {
                token = st.nextToken();
            } catch (IOException e) {
            }
            return token;
        }
    }
}

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

int main() {
    double a, b;
    cin >> a >> b;
    cout << a / b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int num;
  int n, m;
  cin >> n >> m;

  priority_queue<int> q;
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    q.push(a);
  }

  while (m > 0)
  {
    int a = q.top();
    q.pop();
    a /= 2;
    q.push(a);
    --m;
  }

  // while (!q.empty())
  // {
  //   cout << q.top() << endl;
  //   q.pop();
  // }
  num = 0;
  while (!q.empty())
  {
    num += q.top();
    q.pop();
  }
  cout << num << endl;
}


Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

string s, t, ts;
int longest[540000];
bool ok[540000];

vector<int> z_algo(string s){
    int n = s.size();
    vector<int> res(n);
    res[0] = 0;
    int now = 0, l = 0;
    for(int i = 1;i < n;i++){
        res[i] = now-i;
        if(now-i >= 0 && res[i-l] != res[i])res[i] = min(res[i-l], res[i]);
        else{
            res[i] = max(res[i], 0);
            while(res[i] < n && s[i + res[i]] == s[res[i]])res[i]++;
            now = i + res[i];
            l = i;
        }
    }
    return res;
}

int calc_longest(int x, int dep = 0){
    if(dep > s.size())return -1;
    if(longest[x] != -1)return longest[x];
    if(!ok[x])return longest[x] = 0;
    longest[x] = calc_longest((x + t.size()) % s.size(), dep + 1);
    if(longest[x] == -1)return -1;
    return longest[x] += 1;
}

int main(){
    fill(longest, longest + 540000, -1);
    cin >> s >> t;
    ts = t + s + t; 
    for(int i = 0;i < t.size();i++){
        ts[t.size() + s.size() + i] = s[i % s.size()];
    }
    auto z = z_algo(ts);
    for(int i = 0;i < s.size();i++){
        if(z[t.size() + i] >= t.size()){
            ok[i] = true;
        }
    }
    int ans = 0;
    for(int i = 0;i < s.size();i++){
        longest[i] = calc_longest(i);
        if(longest[i] == -1){
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, longest[i]);
    }
    cout << ans << endl;
    return 0;
}

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

string S;

const string s1 = "dream";
const string s2 = "erase";
const string s3 = "eraser";
const string s4 = "dreamer";

int main(void) {
	cin >> S;
	string ans = "NO";
	string sub;

	while (S.length() >= s1.length()) {
		if ((S == s1) || (S == s2) || (S == s3) || (S == s4)) {
			ans = "YES";
			break;
		}
		sub = S.substr(S.length() - s1.length());
		if (sub == s1) {
			S.erase(S.length() - s1.length());
			continue;
		}
		sub = S.substr(S.length() - s2.length());
		if (sub == s2) {
			S.erase(S.length() - s2.length());
			continue;
		}
		sub = S.substr(S.length() - s3.length());
		if (sub == s3) {
			S.erase(S.length() - s3.length());
			continue;
		}
		sub = S.substr(S.length() - s4.length());
		if (sub == s4) {
			S.erase(S.length() - s4.length());
			continue;
		}
		break;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ARC067D();

#if 1
int main()
{
	ARC067D();
	fflush(stdout);
	return 0;
}
#endif

static void ARC067D()
{
	int N;
	LLONG A, B;
	getint(N);
	getint(A, B);

	std::vector<LLONG> xn(N, 0);
	for (int i = 0; i < N; i++) {
		getint(xn[i]);
	}

	LLONG distMax = B / A;
	if (B % A) distMax++;
	
	LLONG dist = 0;
	LLONG nowCost = 0;
	for (int i = 1; i < N; i++) {
		if (xn[i] - xn[i - 1] < distMax) {
			nowCost += A * (xn[i] - xn[i - 1]);
		}
		else {
			nowCost += B;
		}
	}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  vector<int> v(n);
  for(int i; i < n; i++)
    cin >> v.at(i);
  
  int s = 0;
  for(int i; i < n; i++)
    s += v.at(i);
  s -= n;
  
  cout << s << endl; 
}



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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	FAST
	
	string s; cin >> s;
	int n = s.length();
	if(s[0] == '?')
	{
		if(n==1) s[0]='D';
		else if(s[1] == 'D' || s[1] == '?') s[0] = 'P';
		else if(s[1] == 'P') s[0] = 'D';
	}

	for(int i = 1; i < n-1; i++)
	{
		if(s[i] == '?')
		{
		if(s[i-1] == 'P') s[i] = 'D';
		else if( s[i+1] == 'D' || s[i+1] == '?') s[i] = 'P';
		else s[i] = 'D';
		}
	}

	if(n>1 && s[n-1] == '?') s[n-1] = 'D';

	cout << s << '\n';

	return 0;
}


Measured memory_bytes: 3740
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100000									// 最大配列数

// 内部変数
static int si1Array[D_ARRAY_MAX + 5];							// 配列
static int siACnt;												// 配列数
static int siSum;												// 取りやめない時の合計値

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 観光スポット数取得
	int liCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liCnt);

	// 配列取得
	si1Array[0] = 0;
	si1Array[liCnt + 1] = 0;
	for (i = 1; i <= liCnt; i++) {
#ifdef D_TEST
		fscanf(szpFpT, "%d", &si1Array[i]);
#else
		fscanf(stdin, "%d", &si1Array[i]);
#endif
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// 配列数
	siACnt = liCnt + 2;

	// 取りやめない時の合計値
	siSum = 0;
	for (i = 0; i < siACnt - 1; i++) {
		siSum += abs(si1Array[i] - si1Array[i + 1]);
	}

	// 取りやめる場合を出力
	for (i = 1; i < siACnt - 1; i++) {

		// 前後の金額減額
		int liSum = siSum;
		liSum -= abs(si1Array[i] - si1Array[i - 1]);
		liSum -= abs(si1Array[i] - si1Array[i + 1]);

		// ２マス移動額
		liSum += abs(si1Array[i - 1] - si1Array[i + 1]);

		// 結果セット
		sprintf(lc1Out, "%d\n", liSum);

		// 結果表示
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
		if (strcmp(lc1Buf, lc1Out)) {
			siRes = -1;
		}
#else
		printf("%s", lc1Out);
#endif
	}

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 1536
N,M=gets.chomp.split(" ").map(&:to_i)
keys = [] # [cost, key(bit), keys]
M.times do
    a,b=gets.chomp.split(" ").map(&:to_i)
    array=gets.chomp.split(" ").map(&:to_i)
    key = 0
    array.each do |i|
        key += 2**(i-1)
    end
    keys.push([a, key, array])
end
keys = keys.sort_by { |e| e[0] }

all_key = 0
keys.each do |e|
    all_key = all_key | e[1]
end
if all_key != (2**N)-1
    puts "-1"
    exit
end

INF = 10**6
dp = [INF]* 2**N
dp[0] = 0

keys.each do |a, key, array|
    dp.each_with_index do |price, index|
        new_key = key | index
        new_price = a + price
        if new_price < dp[new_key] 
            dp[new_key] = new_price
        end
    end
end
puts dp[-1]

Measured memory_bytes: 2300
#include<cstdio>
#define Rest 100005
#define INF 2100000000
int n;
int w[Rest],next[Rest][21];
int ex[21];
int L;
int path(int s, int f) {
	if (s >= f) return 0;
	int i;
	for (i = 0; i <= 20; i++) {
		if (next[s][i + 1] == 0 || next[s][i + 1] > f) return ex[i] + path(next[s][i], f);
	}
}
int main() {
	scanf("%d", &n);
	int i,j;
	for (i = 1; i <= n; i++) scanf("%d", &w[i]);
	scanf("%d", &L);
	int nxt=2;
	for (i = 1; i <= n; i++) {
		while (w[nxt] - w[i] <= L && nxt<=n) nxt++;
		next[i][0] = nxt - 1;
	}
	next[n][0] = 0;
	ex[0] = 1;
	for (i = 1; ; i++) {
		ex[i] = ex[i - 1] * 2;
		bool end = true;
		for (j = 1; j < n; j++) {
			if (next[j][i - 1] && next[next[j][i - 1]][i - 1]) {
				next[j][i] = next[next[j][i - 1]][i - 1];
				end = false;
			}
			else break;
		}
		if (end) break;
	}
	int Q;
	scanf("%d", &Q);
	while (Q-- > 0) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a > b) {
			int t = a; a = b; b = t;
		}
		printf("%d\n",path(a, b));
	}
	return 0;
}

Measured memory_bytes: 9344
#!/usr/bin/env python3
import sys

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def solve(N: int):
#    print(factorization(N))
    arr = factorization(N)
    ans = 0
    for i in range(len(arr)):
        [a, b] = arr[i]
        if a == 1:
            continue

        tmp = b

        for j in range(1, b+1):
            tmp -= j
            if tmp >= 0:
                ans += 1
            else:
                break
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9540
fun main(args: Array<String>){
    val N = nextInt()
    val P = listOfInt()
    val Q = P.sorted()
    var count = 0
    for (n in 0 until N) {
        if (P[n] != Q[n]) count++
    }
    println(if (count <= 2) "YES" else "NO")
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toLong() }


Measured memory_bytes: 37832
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

ll N,M,x,y,wt; 
vector<pair<ll,ll>> *graph = new vector<pair<ll,ll>>[20000];
ll d[20000];

ll bford()
{
	for(ll i = 0; i < N-1; i++)
	{
		for(ll j = 1; j <= N; j++)
		{
			for(ll t = 0; t < graph[j].size(); t++)
			{
				if(graph[j][t].second + d[j] < d[graph[j][t].first])
				{
					d[graph[j][t].first] = graph[j][t].second+d[j];
				}
			}
		}
	}
	return d[N];
}
int main() 
{
	for(ll i = 0; i < 1005; i++)
	{
		d[i] = 10000000000000;
	}
	fast;
	cin>>N>>M;
	for(ll i = 0; i < M; i++)
	{
		cin>>x>>y>>wt;
		graph[x].push_back(make_pair(y,-wt));
	}
	d[1] = 0;
	ll a = bford();
	ll b = bford();
	if(a == b) cout << -a << endl;
	else cout << "inf" << endl;
 	return 0;
}

Measured memory_bytes: 768
var
	N,sum,i,min,s:Longint;
begin
	read(N);
	min:=114514;
	for i:=1 to N do begin
		read(s);
		inc(sum,s);
		if(s mod 10<>0)and(min>s)then min:=s;
	end;
	if sum mod 10<>0 then writeln(sum)else if min<114514 then writeln(sum-min)else writeln(0);
end.


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//using ll = long long;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int n,t,a;
    cin >> n >> t >> a;
    t *= 1000;
    a *= 1000;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    const int c = 6;
    int ans,dif = 100000000;
    rep(i,n){
        int temp = abs(a-(t - h[i]*c));
        if (temp < dif){
            ans = i+1;
            dif = temp;
        }
    }
    cout << ans;
}

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

int n,q;string s;
const int MAX=200000;
char d[MAX],t[MAX];
int judge(int k){
    int p=k;char m=s[k];
    for(int i=0;i<q;i++)
    {
        if(t[i]==m)
        {
            if(d[i]=='L')   
            p--;
            else    
            p++;
        }
        m=s[p];
        if(p<0)
        return -1;//left
        if(p>=n)
        return 1;//right

    }
    return 0;//otinai
}

int main(){
    cin>>n>>q;
    cin>>s;
    for(int i=0;i<q;i++)
    cin>>t[i]>>d[i];
    
    int l=0,r=s.size()-1,mid;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(judge(mid)<=0)
        l=mid+1;
        else if(judge(mid)>0)
        r=mid-1;
    }
    int ans1;
    if(l>=n)
    ans1=n;
    else if(judge(l)==1)
    ans1=l;
    else if(judge(r)==1)
    ans1=r;
    l=0;r=s.size()-1;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(judge(mid)>=0)
        r=mid-1;
        else if(judge(mid)<0)
        l=mid+1;
    }
    int ans2;
    if(r<0)
    ans2=-1;
    else if(judge(r)==-1)
    ans2=r;
    else if(judge(l)==-1)
    ans2=l;
    
    cout<<ans1-ans2-1<<endl;
    return 0;
}

Measured memory_bytes: 900
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi a(n), b(n), da(m), db(m);
	REP(i, n)cin >> a[i] >> b[i];
	REP(i, m)cin >> da[i] >> db[i];

	REP(i, n) {
		int dist = INF, p = 0;;
		REP(j, m) {
			int c = abs(a[i] - da[j]) + abs(b[i] - db[j]);
			if (c < dist) {
				dist = c; p = j;
			}
		}
		cout << p+1 << endl;

	}

	return 0;
}


Measured memory_bytes: 256
X, Y = [int(_) for _ in input().split()]

cache = {}

def calc(X, Y):
    if X < Y:
        X, Y = Y, X
    def cal(X, Y):
        if X <= 1:
            return False
        for n in range(1, X // 2 + 1):
            if calc(X - n * 2, Y + n) == False:
                return True
        for n in range(1, Y // 2 + 1):
            if calc(X + n, Y - n * 2) == False:
                return True
        return False
    k = (X, Y)
    if k in cache:
        return cache[k]
    r = cal(X, Y)
    cache[k] = r
    return r

def calc1(X, Y):
    if abs(X - Y) < 2:
        return False
    return True

if calc1(X, Y):
    print("Alice")
else:
    print("Brown")
    

Measured memory_bytes: 3192
def f(n):
    if n == 0: return ""
    n -= 1
    return (f(n // 26) + chr(ord("a") + n % 26))

def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    n = input_number()
    ans = f(n)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#!/usr/bin/env python3

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    Asum, Bsum = [0], [0]

    for i in range(N):
        Asum.append(Asum[i] + A[i])
    for i in range(M):
        Bsum.append(Bsum[i] + B[i])

    ans, j = 0, M

    for i in range(N + 1):
        if K < Asum[i]:
            break
        while Bsum[j] > K - Asum[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 47280
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=2e5+5;
const int mod=998244353;
const double pi=acos(-1.0);
ll n,m,s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(m);
    n=100;
    while(n<m){
        n=n+n/100;
        s++;
    }
    printf("%lld\n",s);
    return 0;
}

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

string a[100],b[100];

int main(){
	int n,m,flag=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<=n-m;i++){
		for(int j=0;j<=n-m;j++){
			flag=0;
			for(int st=i;st<(m+i);st++){
				for(int r=j;r<(m+j);r++){
					if(a[st][r]!=b[st-i][r-j])
						flag=1;
				}
			}
			if(flag==0){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
require 'set'
n = gets.chomp.to_i
s = gets.chomp
max = 0
for i in 0..n-1
    k = s.slice(0..i)
    l = s.slice(i+1..n)
    k = Set.new(k.chars)
    l = Set.new(l.chars)
    if (k & l).length > max
        max = (k & l).length
    end
end  
print(max)

Measured memory_bytes: 2428
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

ll d[3];
int main(){
   ll k, a, b;
   cin >> k >> a >> b;
   k++;
   ll res = a + max(ZER, (k - a) / 2) * (b - a) + (k - a) % 2;
   if(b - a <= 2 || k < a)res = k;
   cout << res << endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll A,B;
  cin>>A>>B;
  ll ans=max(2*A-1,2*B-1);
  ans=max(ans,A+B);
  cout<<ans<<endl;
}


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

int main()
{
  long long n, x, a;
  scanf("%lld%lld%lld", &n, &x, &a);
  long long ans = std::max(a - x, 0LL);
  a -= std::max(a - x, 0LL);
  for (long long i = 1; i < n; ++i)
  {
    long long last = a;
    scanf("%lld", &a);
    long long ex = std::max(a + last - x, 0LL);
    ans += ex;
    a -= std::min(a, ex);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#ifdef loc
    #include "../codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
const int N = 100005;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    int prev = 0;
    ll res = 0;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(x == 0) {
            prev = 0;
            continue;
        }
        if(prev) {
            x++;
            prev = 0;
        }
        res += x / 2;
        if(x & 1) {
            prev = 1;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int p[100010];
vector<int> v[100010];

int search(int s) {
  queue<int> q;
  int count = 0;
  q.push(s);
  while(!q.empty()) {
    count++;
    int c = q.front(); q.pop();
    for (int i = 0; i < v[c].size(); i++) {
      //printf("%d\t%d\n", c, p[v[c][i]]);
      if (p[v[c][i]] <= p[s]) continue;
      p[v[c][i]] = -1;
      q.push(v[c][i]);
    }
  }
  p[s] = -1;
  return count;
}

int main(){


  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  queue<int> q;
  int count = 0;
  q.push(1);
  p[1] = 1;
  while(!q.empty()) {
    count++;
    int c = q.front(); q.pop();
    if (c == n) continue;
    for (int i = 0; i < v[c].size(); i++) {
      if (p[v[c][i]] > 0) continue;
      p[v[c][i]] = p[c] + 1;
      q.push(v[c][i]);
    }
  }
  int u = p[n];
  int black = count;

  int t = n;
  for (int i = p[n]; i > 0; i--) {
    if (i > (u + 1) / 2) black += -search(t);
    else break;
    for (int j = 0; j < v[t].size(); j++) {
      if (p[v[t][j]] == i - 1) {
        t = v[t][j];

        break;
      }
    }
  }

  int white = n - black;
  //printf("black: %d\n", black);
  //printf("white: %d\n", white);
  if (black > white) printf("Fennec\n");
  else printf("Snuke\n");

  return 0;
}

Measured memory_bytes: 6272
//OPTIMIZATIONS
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
//#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//OPTIMIZATIONS
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long uu;
typedef long long int lll;
typedef unsigned long long int uuu;
using namespace std;

#define watch(x) cerr << "\n" \
					  << (#x) << " is " << (x) << endl
#define cel(x, y) 1 + ((x - 1) / y)
const double PI = 3.141592653589793238463;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;

/*
$alil03

URL: url

Solution Begins here
*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int curr = 0;
	for (int i = 0; i < n; i++)
	{
		if (arr[i] == curr + 1)
		{
			curr++;
		}
	}
	if (curr == 0)
	{
		cout << -1;
	}
	else
	{
		cout << n - curr;
	}
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,VI(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
    
template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}    

template<typename T>
T lcm(T a, T b){
    return a/gcd(a,b)*b;
}    


int main() {
  ll n,k,m,x=0, y=0 , z = 0, h,w, ans=0,sum = 1, Max = -1, Min = 3e9+1;
  string u;
  bool ok=true;
  cin >> n;
  VL a(n); rep(i,n) cin >> a[i];
  sort(ALL(a));
  if(n==1){
    pri(a[0]);
    return 0;
  }
  else{
    x = lcm(a[0],a[1]);
    for(int i=2; i<n; i++){
      x = lcm(a[i],x);
    }
    pri(x);
    return 0;
  }
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

arr = [set() for _ in range(W)]
arr[0].add(A[0][0] - B[0][0])
for x in range(1, W):
    s = arr[x]
    d = A[0][x] - B[0][x]
    for n in arr[x-1]:
        s.add(abs(n+d))
        s.add(abs(n-d))

for y in range(1, H):
    nextarr = [set() for _ in range(W)]
    Ay = A[y]
    By = B[y]
    dh = H - y - 1
    for x in range(W):
        nextset = nextarr[x]
        d = Ay[x] - By[x]
        dw = W - x - 1
        lim = (dh + dw + 1) * 160
        #lim = 1280
        if x >= 1:
            arr[x] |= nextarr[x-1]
        for n in arr[x]:
            if abs(n+d) <= lim:
                nextset.add(abs(n+d))
            if abs(n-d) <= lim:
                nextset.add(abs(n-d))
    arr = nextarr
print(min([abs(d) for d in arr[-1]]))

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

int x,y;
signed main(){
	cin>>x>>y;
	int ans=0;
	while(x<=y){
		y/=2;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
using namespace std;

int main() {
  ill n, s = 0, z = 1, mi = 0;
  cin >> n;
  vector<ill> v(n);
  rep(i, 0, n) {
    cin >> v[i];
    if(v[i] < 0) {
      s -= v[i];
      mi++;
    } else {
      s += v[i];
    } if(v[i] == 0) {
      z = 0;
    }
  }
  if(z == 0) {
    cout << s;
  } else {
    if(mi % 2 == 0) {
      cout << s;
    } else {
      ill m = 10000000000;
      rep(i, 0, n) {
        if(v[i] > 0 && m > v[i]) {
          m = v[i];
        } if(v[i] < 0 && m > -v[i]) {
          m = -v[i];
        }
      }
      cout << s - m * 2;
    }
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans=0,tmp;
  int k;
  k = n/7;
  for(int i=0;i<=k;i++){
    tmp=n;
    tmp=n-i*7;
    if(tmp%4==0){
      ans=1;
      break;
    }
  }
  if(ans==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;

  }
}


Measured memory_bytes: 256
S = list(input())
N = len(S) + 1

from_left = [0] * N
from_right = [0] * N

for i in range(N-1):
  s = S[i]
  if s == '<':
    from_left[i+1] = from_left[i] + 1

for i in range(N-2,-1,-1):
  s = S[i]
  if s == '>':
    from_right[i] = from_right[i+1] + 1
    
ans = 0
for i in range(N):
  ans += max(from_left[i],from_right[i])
  
print(ans)

Measured memory_bytes: 31036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    int n;
    cin >> n;
    double ans;
    for(int i=0;i<n;i++){
        float a;
        cin >> a;
        ans += 1/a;
    }
    cout << fixed << setprecision(8) << 1/ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
double n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  ll x = 0,y = 0;
  cin >> n >> m >> l;
  ll ans = 0;
  rep(i,0,l){
    ll a,b,c;
    cin >> a >> b >> c;
    if(c == 2){
      if(n >= a)n = a;
    }else if(c == 1){
      if(x <= a)x = a;
    }else if(c == 4){
      if(m >= b)m = b;
    }else if(c == 3){
      if(y <= b)y = b;
    }
  }
  if(ans == -1 || (n-x) <= 0 || (m-y) <= 0)puts("0");
  else print((n-x)*(m-y));
  return 0;
}

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


int main() {
  int N;
  cin >> N;
  bool flg = false;
  for (int i = 0; i < N; ++i) {
    char S;
    cin >> S;
    if (S == 'Y') {
      flg = true;
      break;
    }
  }
  if (flg) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < K; i++){
    ans += p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
//#define ll __int64
#define ll long long

int n;
ll d[500][500];
ll t[500][500];
int main(){
cin>>n;
rep(i,n)rep(j,n)cin>>d[i][j];
rep(i,n)rep(j,n)t[i][j]=d[i][j];

rep(k,n){
	rep(i,n){

		rep(j,n){//(d[i][j],d[i][k]+d[k][j])
			if((d[i][j]>0&&d[i][k]>0&&d[k][j]>0)&&d[i][j]==d[i][k]+d[k][j])d[i][j]=0;

		}
	}
}

rep(i,n){
	rep(j,n){
		rep(k,n){
			if(t[i][j]>t[i][k]+t[k][j]){cout<<-1<<endl;return 0;}
		}
	}
}

ll ans=0;
rep(i,n)for(int j=i+1;j<n;j++)ans+=d[i][j];
cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc()) 
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 55;
int n;
struct edge {
  int la,b;
};
struct graph {
  edge con[N << 1];
  int tot, fir[N];
  void add_edge(int from,int to) {
    con[++tot] = (edge) {fir[from], to};
    fir[from] = tot;
  }
  void dfs(int pos,int *fa) {
    for (int i = fir[pos]; i; i = con[i].la) {
      if (con[i].b == fa[pos]) continue;
      fa[con[i].b] = pos;
      dfs(con[i].b, fa);
    }
  }
  void init() {
    memset(fir, 0, sizeof fir);
    tot = 0;
  }
  int deg[N];
  bool bfs() {
    rep (i, 1, n) deg[i] = 0;
    rep (pos, 1, n)
      for (int i = fir[pos]; i; i = con[i].la)
	++ deg[con[i].b];
    queue<int> q;
    rep (i, 1, n) if (!deg[i])
      q.push(i);
    int cnt = 0;
    for (int pos; !q.empty(); q.pop()) {
      pos = q.front();
      ++ cnt;
      for (int i = fir[pos]; i; i = con[i].la) {
	if (-- deg[con[i].b] == 0)
	  q.push(con[i].b);
      }
    }
    return cnt == n;
  }
} t1, t2, g;
int ans;
int fa[2][N], vis[N];
void doit0(int rt) {
  memset(fa, 0, sizeof fa);
  t1.dfs(rt, fa[0]);
  t2.dfs(rt, fa[1]);
  rep (i, 1, n) vis[i] = 0;
  rep (i, 1, n) {
    if (fa[0][i] == fa[1][i]) {
      vis[i] = 1;
      for (int j = fa[0][i]; j; j = fa[0][j]) {
	if (fa[0][j] != fa[1][j]) return;
	vis[j] = 1;
      }
    }
  }
  g.init();
  rep (i, 1, n) if (!vis[i]) {
    if (!vis[fa[0][i]]) g.add_edge(fa[0][i], i);
    if (!vis[fa[1][i]]) g.add_edge(i, fa[1][i]);
  }
  if (!g.bfs()) return;
  int num = n;
  rep (i, 1, n) if (vis[i]) num --;
  ans = min(ans, num);
}
void doit1(int rt1,int rt2) {
  memset(fa, 0, sizeof fa);
  t1.dfs(rt1, fa[0]);
  t2.dfs(rt2, fa[1]);
  g.init();
  rep (i, 1, n) {
    if (fa[0][i]) g.add_edge(fa[0][i], i);
    if (fa[1][i]) g.add_edge(i, fa[1][i]);
  }
  if (!g.bfs()) return;
  ans = min(ans, n);
}
void solve() {
  int x,y;
  read(n);
  t1.init(), t2.init();
  rep (i, 1, n-1) {
    read(x), read(y);
    t1.add_edge(x, y);
    t1.add_edge(y, x);
  }
  rep (i, 1, n-1) {
    read(x), read(y);
    t2.add_edge(x, y);
    t2.add_edge(y, x);    
  }
  ans = n+1;
  rep (i, 1, n)
    doit0(i);
  rep (i, 1, n) rep (j, 1, n)
    doit1(i, j);
  if (ans > n) puts("-1");
  else printf("%d\n", ans);
}
int main() {
  int T;
  read(T);
  while (T --)
    solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int N;
  int i,x,y,z;
  if(scanf("%d",&N)==1);
  int a[100000];
  for(x=1;x<=100;x++){
    for(y=1;y<=100;y++){
     for(z=1;z<=100;z++){
       int s;
       s=x*x+y*y+z*z+x*y+y*z+z*x;
       if(s>N){
         break;
       }
       a[s-1]++;
     }
    }
  }
  for(i=0;i<N;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}

  

Measured memory_bytes: 1668
#include<stdio.h>

 int partion(int A[],int p,int r){
      int i,j,tmp,x;
      x=A[r];
      i=p-1;
      for(j=p;j<r;j++){
                if(A[j]<=x){
                        i=i+1;
                        tmp=A[i];A[i]=A[j];A[j]=tmp;
                        }
                }
      tmp=A[i+1];A[i+1]=A[r];A[r]=tmp;
      return i+1;
      }

 int main(){
      int n,A[100000],i,x;
      scanf("%d",&n);
      for(i=0;i<n;i++){
             scanf("%d",&A[i]);
             }

      x=partion(A,0,n-1);

      for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
      printf("\n");
      return 0;
      }


      


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
vector<ll> to[100001];
ll d[100001];
int main(void){
    int n,m;
    cin>>n>>m;
    fill(d,d+100001,INF);
    d[1]=0;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<ll> que;
    que.push(1);
    while(!que.empty()){
        ll a=que.front();
        que.pop();
        for(auto x:to[a]){
            if(d[x]==INF){
                d[x]=a;
                que.push(x);
            }
        }
    }
    bool ok=true;
    for(int i=1;i<=n;i++){
        if(d[i]==INF) ok=false;
    }
    if(ok){
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++){
            cout<<d[i]<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 12912
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "ok" <<endl;

using namespace std;

int main()
{
    int a,b;
	cin >> a >> b;
	int n= ceil((b-a)/double(a-1));
	cout << n+1 << endl;

}


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

int main(void) {
	string w; cin >> w;
	map<char, int> mp;
	int i;
	for (i = 0; i < w.size(); i++) {
		mp[w[i]] += 1;
	}

	for (pair<char, int> x : mp) {
		if (x.second % 2 != 0) {
			cout << "No" << endl; return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 256