akhauriyash/Code-Regression huggingface dataset:
require 'pp'

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end

N, x_list = gets_n_and_i_list

sorted_x_list = x_list.sort
l_mid = sorted_x_list[N/2 -1]
r_mid = sorted_x_list[N/2]

N.times do |i|
  if x_list[i] <= l_mid
    puts r_mid
  else
    puts l_mid
  end
end


Measured memory_bytes: 25676
n = int(input())
l_ = [["M", 0], ["A", 0], ["R", 0], ["C", 0], ["H", 0]]
l = []

for i in range(n):
    s = input()

    for j in l_:
        if s[0] == j[0]:
            j[1] += 1
            break

for i in l_:
    if i[1] != 0:
        l.append(i[1])

k = len(l)
r = 0

if k < 3:
    r = 0
elif k == 3:
    r = l[0] * l[1] * l[2]
elif k == 4:
    for i in range(1,5):
        r += l[i%4] * l[i%3] * l[i%2]
elif k == 5:
    p = 1
    for i in range(5):
        p *= l[i]
    for i in range(4, -1, -1):
        for j in range(5):
            if i == j:
                break
            r += p / (l[i] * l[j])

print(int(r))

Measured memory_bytes: 3188
A, B = [int(_) for _ in input().split()]
aa = [int(i * 0.08) for i in range(1, 10000)]
bb = [int(i * 0.1) for i in range(1, 10000)]
for i, a, b in zip(range(1, 10000), aa, bb):
    if (a, b) == (A, B):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 9448
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

int main() {
    long long A,B,C,D;

    cin>>A>>B>>C>>D;

    long long LCM = lcm(C,D);

    long long num_factor =(B/C - (A-1)/C) + (B/D - (A-1)/D) - (B/LCM - (A-1)/LCM);

    cout << B-A+1-num_factor<<endl;
    return 0;
}

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

int main() {
	vector<int> vec(5);
	for (int i = 0; i < 5; i++) cin >> vec[i];
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (int i = 0; i < 5; i++) {
		if (i == 0) cout << vec[i] << flush;
		else cout << " " << vec[i] << flush;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <functional>

using ll = long long;

using namespace std;

struct section{long l, r;};

using pq = priority_queue<int, vector<int>, function<bool(int, int)>> ;

section s[100010];
int n;

long journey(bool di, pq ql, pq qr) {
    long res = 0, prev = 0;
    for (int i=0; i<n; i++) {
        if (di && !ql.empty()) {
            int j = ql.top(); ql.pop();
            if (s[j].l > prev) {
                res += s[j].l - prev;
                prev = s[j].l;
                di = !di;
            } else 
                break;
        } else if (!qr.empty()) {
            int j = qr.top(); qr.pop();
            if (s[j].r < prev) {
                res -= s[j].r - prev;
                prev = s[j].r;
                di = !di;
            } else 
                break;
        }
    }
    return res + abs(prev);
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) cin >> s[i].l >> s[i].r;
    pq ql(
        [&](int a, int b) {
            return s[a].l < s[b].l;
        }
    );
    pq qr(
        [&](int a, int b) {
            return s[a].r > s[b].r;
        }
    );
    for (int i=0; i<n; i++) (ql.push(i), qr.push(i));
    cout << max(journey(true, ql, qr), journey(false, ql, qr)) << '\n';
    return 0;
}

Measured memory_bytes: 4340
import Data.Char

main = interact $ unlines.map (show.(\[a,b,n] -> sumNthDecimal n $ div' a b).map read.words).lines

sumNthDecimal :: Int -> String -> Int
sumNthDecimal n str = sum.map digitToInt.take n.tail.dropWhile (/= '.') $ str

div' :: Int -> Int -> String
div' a b = show q ++ "." ++ div'' (10*r) b
  where (q,r) = quotRem a b

div'' :: Int -> Int -> String
div'' a b = show q ++ rest
  where (q,r) = quotRem a b
        rest = if r == 0 then []
                         else div'' (10*r) b

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}

int main() {
    int x; cin >> x;
    int ans = 0;
    while(true){
        if(ans >= x){
            cout << ans-x;
            return 0;
        }else{
            ans+=1000;
        }
    }
}




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

int main(){
    int N; cin >> N;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    
    int ans=0;
    int cnt=0;
    for (int i=N-1; i>0; i--){
        for(int j=i-1; j>=0; j--){
            if(A[i]<A[j]){
                cnt++;
                break;
            }
        }
    }
    ans=(N-1)-cnt+1;
    cout << ans;
}

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




int main(){
    int N;
    cin >> N;
    vector<int> px;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        px.push_back(tmp);
    }
    int result =0;
    int finalResult =0;
    for(int j=1;j<=100;j++){
    for(int i=0;i<N;i++){
        result +=((px[i]-j)*(px[i]-j));
        
    }
    if(j==1){ 
        finalResult = result;
        result =0;
    }else{
        if(result <=finalResult){
            
            finalResult = result;
            result =0;
        }
    }
    }
    
    cout << finalResult << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		int[][] C = new int[H][W];
		for (int i = 0; i < H; i++) {
			char[] c = sc.next().toCharArray();
			for (int j = 0; j < W; j++) {
				if (c[j] == '.') {
					C[i][j] = 0; // white
				} else {
					C[i][j] = 1; // black
				}
			}
		}
		sc.close();

		// bit全探索を2重に行う
		int ans = 0;
		// H loop
		for (int h = 0; h < (Math.pow(2, H)); h++) {
			for (int w = 0; w < (Math.pow(2, W)); w++) {
				int cnt = 0;
				for (int j = 0; j < H; j++) {
					for (int k = 0; k < W; k++) {
						if ((1 & h >> j) == 0 && (1 & w >> k) == 0 && C[j][k] == 1) {
							cnt++;
						}
					}
				}
				if (cnt == K) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35672
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <ctime>
#include <set>
using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair 
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;

const int N = 1e5 + 10;
const int mo = 1e9 + 7;

int qpow(int a, int b) {
	int ans = 1;
	for(; b >= 1; b >>= 1, a = (ll) a * a % mo)
		if(b & 1) ans = (ll) ans * a % mo;
	return ans;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && b == c) cout << "No";
	else if(a == b || a == c || b == c) cout << "Yes";
	else cout << "No";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
using namespace std;

/*
 * dp[i][j] = i日目にjをした場合の最大の幸福度
 *
 * dp[0][j] = abc[0][j]
 *
 * dp[i][j] = max(dp[i - 1][k] + abc[i][j] | k != j)
 */

int main() {
    int n; cin >> n;
    vector<array<int, 3>> abc(n);
    for (auto &e1 : abc) for (auto &e2 : e1) cin >> e2;

    vector<array<int, 3>> dp(n);
    dp[0][0] = abc[0][0];
    dp[0][1] = abc[0][1];
    dp[0][2] = abc[0][2];

    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < 3; ++i) {
        ans = max(ans, dp[n - 1][i]);
    }

    cout << ans << endl;
}

#if false

// メモ化再帰による解法

int solve(vector<array<int, 3>> &memo, const vector<array<int, 3>> &abc, int i, int j) {
    if (i == 0) return abc[0][j];
    if (memo[i][j] != -1) return memo[i][j];

    for (int k = 0; k < 3; ++k) {
        if (k == j) continue;
        memo[i][j] = max(memo[i][j], solve(memo, abc, i - 1, k) + abc[i][j]);
    }

    return memo[i][j];
}

int main() {
    int n; cin >> n;
    vector<array<int, 3>> abc(n);
    for (auto &e1 : abc) for (auto &e2 : e1) cin >> e2;

    int ans = 0;
    vector<array<int, 3>> memo(n, { -1, -1, -1 });
    for (int i = 0; i < 3; ++i) {
        ans = max(ans, solve(memo, abc, n - 1, i));
    }

    cout << ans << endl;
}

#endif



Measured memory_bytes: 5628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=1e5+9;

unsigned int bit[N];
int n,f[N],ans;
int to[N<<1],nxt[N<<1],beg[N],tot;

inline void add(int u,int v)
{
	to[++tot]=v;
	nxt[tot]=beg[u];
	beg[u]=tot;
}

inline void dfs(int u,int fa)
{
	bit[u]=f[u]=0;
	int las=0;
	for(int i=beg[u],v;i;i=nxt[i])
		if((v=to[i])!=fa)
		{
			dfs(v,u);
			las|=bit[v]&bit[u];
			bit[u]|=bit[v];
		}
	if(bit[u]==0)
		bit[u]=1;
	else
	{
		while((1<<f[u])<las || bit[u]&(1<<f[u]))f[u]++;
		bit[u]=(bit[u]>>f[u]<<f[u])|(1<<f[u]);
	}
	if(ans<f[u])ans=f[u];
}

int main()
{
	n=read();
	for(int i=1,u,v;i<n;i++)
	{
		u=read();v=read();
		add(u,v);add(v,u);
	}

	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4992
n,m = map(int,input().split())
ac = [0 for _ in range(n)]
wa = [0 for _ in range(n)]
for _ in range(m):
  a,b = input().split()
  a = int(a) - 1
  if b == 'AC':
    ac[a] = 1
  elif ac[a] == 0:
    wa[a] += 1
w = 0
for i in range(n):
  w += ac[i] * wa[i]
print(sum(ac),w)

Measured memory_bytes: 4772
# input
x, y = map(int, input().split())

if y >= x:
    if x >= 0:
        ans = y - x
    else:
        if y > 0:
            ans = 1 + abs(x + y)
        else:
            ans = y - x
else:
    if x < 0:
        ans = 2 + x - y
    else:
        if y > 0:
            ans = 2 + x - y
        elif y > -x:
            ans = 1 + x + y
        else:
            ans = 1 - x - y    

print(ans)

Measured memory_bytes: 3064
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long[] pre = new long[1112];
		
		for(int i = 0; i < 1112; i++){
			long l = i;
			l = l * l * l;
			pre[i] = l;
		}
		
		while(true){
			final int z = sc.nextInt();
			
			if(z == 0){
				break;
			}
			
			long max = 0;
			
			for(int x = 1; ; x++){
				if(pre[z] < pre[x]){
					break;
				}
				
				for(int y = 1; y <= x; y++){
					if(pre[z] >= (pre[x] + pre[y])){
						max = Math.max(max, pre[x] + pre[y]);
					}
				}
			}
			System.out.println(pre[z] - max);
		}
		
	}

}

Measured memory_bytes: 12000
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

} // namespace null_null

namespace null_null {

void main_() {
  usize N;
  std::cin >> N;
  std::vector<i32> H(N);
  for (usize i = 0; i < N; i++) {
    std::cin >> H[i];
  }

  std::reverse(H.begin(), H.end());

  i32 mini = 1e9;
  for (usize i = 0; i < N; i++) {

    if (H[i] - mini > 1) {
      std::cout << "No" << std::endl;
      return;
    }

    if (mini > H[i]) {
      mini = H[i];
    }
  }

  std::cout << "Yes" << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}

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

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

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

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

int main(){
	map<int,int> mp;
	FOR(i,0,4){
		int a;
		cin>>a;
		mp[a]=1;
	}
	if(mp[1]==1&&mp[4]==1&&mp[7]==1&&mp[9]==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
    return 0;
}


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

// #define ANS  //for answer
#define CMP  //for compe
#ifdef CMP
using namespace std;
#else
#endif

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x, (x)
#define ncv(x) #x, ":", (x)
#define ncvc(x) #x, ":", (x), ","
#define GETIN2MACRO(_1, _2, NAME, ...) NAME
#define GETIN3MACRO(_1, _2, _3, NAME, ...) NAME
#define GETIN4MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define GETIN5MACRO(_1, _2, _3, _4, _5, NAME, ...) NAME
#define GETIN6MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define GETIN7MACRO(_1, _2, _3, _4, _5, _6, _7, NAME, ...) NAME
#define INPUT1(n) \
  ll n;           \
  cin >> n
#define INPUT2(a, b) \
  ll a, b;           \
  cin >> a >> b
#define INPUT3(n, a, b) \
  ll n, a, b;           \
  cin >> n >> a >> b
#define INPUT4(n, m, a, b) \
  ll n, m, a, b;           \
  cin >> n >> m >> a >> b
#define INPUT(...)                                         \
  GETIN4MACRO(__VA_ARGS__, INPUT4, INPUT3, INPUT2, INPUT1) \
  (__VA_ARGS__)
#define INPUTARR(n, a) \
  ll a[n];             \
  REP(i, n) { cin >> a[i]; }
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) { pPRINT(std::cout, t...); }
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  REP(i, size)
  PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  REP(i, size)
  PRINTl(i, ":", t[i]);
}
#ifndef DBG
#define DEBUG(...)
void init() {}
#else
#define DEBUG(...)                                                     \
  {                                                                    \
    PRINT("##DEBUG##", "file :", __FILE__, ", line :", __LINE__, "["); \
    PRINT(__VA_ARGS__);                                                \
    PRINTl("]");                                                       \
  }
void init() {
  DEBUG("INIT");
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

// search max depth
ll dfs(vector<vector<ll>>& tree, ll parent, ll now, ll depth) {
  ll d = depth;
  for (auto i : tree[now]) {
    if (i == parent) continue;
    d = max(d, dfs(tree, now, i, depth + 1));
  }
  return d;
}

void solve();

int main(int argc, char* argv[]) {
  DEBUG("MAIN");
  init();
  solve();

  return 0;
}

void solve() {
  DEBUG("SOLVE START");

  //solve
  INPUT(k,x);
  PRINT(k*500>=x?"Yes":"No");

  return;
}

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

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

    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> cnt(N, 0);
    for (int i = 0; i < Q; ++i) {
        int A;
        cin >> A;
        cnt.at(A - 1)++;
    }
    for (auto &x : cnt) {
        cout << ((K + x - Q > 0) ? "Yes" : "No") << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int , input().split()))

minus = 0
abs_sum = 0
is_zero = False
abs_min = 10**9+1
for i in range(n):
    if a[i] < 0:
        minus += 1
    abs_sum += abs(a[i])
    abs_min = min(abs_min, abs(a[i]))
    if a[i] == 0:
        is_zero = True
if is_zero or minus%2==0:
    print(abs_sum)
elif minus%2 == 1:
    print(abs_sum-abs_min*2)


Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=(1<<30);
ll dp[160][160][20];
ll k[160];
ll x[160][20],d[160][20];

int main(){
	while(true){
		int n,m;	cin>>n>>m;
		if(n==0)	return 0;
		for(int i=0;i<160;i++)	for(int j=0;j<160;j++)	for(int l=0;l<20;l++)	dp[i][j][l]=INF;
		memset(k,0,sizeof(k));
		memset(x,0,sizeof(x));
		memset(d,0,sizeof(d));
		for(int i=0;i<n;i++){
			cin>>k[i];
			for(int j=0;j<k[i];j++)	cin>>x[i][j]>>d[i][j];
		}
		for(int i=0;i<k[0];i++)	dp[0][m][i]=0;
		if(m>=1)	for(int i=0;i<k[1];i++)	dp[1][m-1][i]=0;
		for(int a=0;a+1<n;a++){
			for(int b=m;b>=0;b--){
				for(int c=0;c<k[a];c++){
					if(dp[a][b][c]==INF)	continue;
					//１歩前進
					for(int i=0;i<k[a+1];i++){
						dp[a+1][b][i]=min(dp[a+1][b][i],dp[a][b][c]+(d[a][c]+d[a+1][i])*abs(x[a][c]-x[a+1][i]));
					}
					//２歩前進
					if(b>0&&a+2<n)	for(int i=0;i<k[a+2];i++){
						dp[a+2][b-1][i]=min(dp[a+2][b-1][i],dp[a][b][c]+(d[a][c]+d[a+2][i])*abs(x[a][c]-x[a+2][i]));
					}
				}
			}
		}
		ll ans=INF;
		for(int i=m;i>=0;i--){
			for(int j=0;j<k[n-1];j++)	ans=min(ans,dp[n-1][i][j]);
		}
		for(int i=1;i<=m;i++){
			for(int j=0;j<k[n-2];j++)	ans=min(ans,dp[n-2][i][j]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 5224
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<long long> a(N);
  map<long long, int> m;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    if (m.find(a[i]) == m.end())
      m[a[i]] = 0;
    ++m[a[i]];
  }

  vector<long long> t;
  for (map<long long, int>::iterator i = m.begin(); i != m.end(); ++i) {
    if (i->second >= 2)
      t.push_back(i->first);
  }

  if (t.size() < 2) {
    cout << 0 << endl;
    return 0;
  }

  sort(t.begin(), t.end(), greater<long long>());

  if (m[t[0]] >= 4)
    cout << t[0] * t[0] << endl;
  else
    cout << t[0] * t[1] << endl;

  return 0;
}

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

using namespace std;

char field[51][51];
int black[51][51],white[51][51];//0:non-rinsetu 1::rinsetu
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int w,h;

void recB(int x,int y){
  if(field[x][y]=='B' || black[x][y]==1){
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(0<=nx && nx<h && 0<=ny && ny<w){
        if(field[nx][ny]!='W' && black[nx][ny]==0){
          black[nx][ny]=1;
          recB(nx,ny);
        }
      }
    }
  }
}

void recW(int x,int y){
  if(field[x][y]=='W' || white[x][y]==1){
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(0<=nx && nx<h && 0<=ny && ny<w){
        if(field[nx][ny]!='B' && white[nx][ny]==0){
          white[nx][ny]=1;
          recW(nx,ny);
        }
      }
    }
  }
}

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

  while(cin>>w>>h,w|h){
    for(int i=0;i<h;i++){
      string s;cin >>s;
      for(int j=0;j<w;j++){
        field[i][j]=s[j];
      }
    }
    for(int i=0;i<h;i++) for(int j=0;j<w;j++){
      black[i][j]=0,white[i][j]=0;
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(field[i][j]=='W') recW(i,j);
        if(field[i][j]=='B') recB(i,j);
      }
    }
    int resB=0,resW=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(field[i][j]!='B' && black[i][j]==1 && white[i][j]==0)resB++;
        if(field[i][j]!='W' && black[i][j]==0 && white[i][j]==1)resW++;
      }
    }
   /* for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<black[i][j];
        }
        cout << endl;
    }
    cout << endl;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<white[i][j];
        }
        cout << endl;
    }*/
    cout << resB << " "<< resW<<endl;
  }
}

Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n, m; cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for(int i = 0; i < m; i++) cin >> s[i] >> c[i];

  int ans = 10101010;

  for(int num = 0; num <= 1000; num++) {
    int di = to_string(num).size();
    if(di != n) continue;
    
    vector<int> b(n);
    int x = num;
    for(int i = 0; i < n; i++) {
      b[n - i - 1] = x % 10;
      x /= 10;
    }
    
    bool ok = true;
    for(int i = 0; i < m; i++) {
      if(b[s[i] - 1] != c[i]) ok = false;
    }

    if(!ok) continue;

    ans = min(ans, num);
  }

  if(ans == 10101010) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())

a = [num for num in map(int, input().split(' '))]
b = [num for num in map(int, input().split(' '))]

ans = 0
pre = 0 # 

for i in range(n):
  # 勇者の攻撃力取得
  p = b[i]
  
  if p >= a[i]:
    # 全部倒せる + 余力あり or 余力なし
    ans += a[i]
    p -= a[i]
    # print('余力: ', p)
    # 隣町も倒しにかかる
    if p >= a[i+1]:
      # 隣町も全部倒す
      ans += a[i+1]
      a[i+1] = 0
    else:
      # 隣町の一部を倒す
      a[i+1] -= p
      ans += p
  else:
    # 一部を倒せる
    ans += p
  # print(a, ans)


print(ans)

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

int main(int argc, char const *argv[]) {

    int N,L;
    std::cin >> N >> L;

    std::vector<std::string> sentences;
    for(int sentence_index = 0 ; sentence_index < N ; sentence_index++)
    {
        std::string S;
        std::cin >> S;
        sentences.push_back(S);
    }

    std::sort(sentences.begin(),sentences.end(),[](std::string a,std::string b){
    return a < b;
    });

    for(const auto& sentence : sentences)
    {
        std::cout << sentence;
    }
    putchar('\n');

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int K;
   string S;
   cin >> K >> S;
   int size = S.size();
   if(size<=K) cout << S << endl;
   else{
      cout << S.substr(0,K) << "..." << endl;
   }
   return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

const ll mod = 1e9 + 7;

int main() {
    int n = 0;
    ll k = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    ll ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (a.at(i) > a.at(j)) {
                if (i < j) {
                    ans += (k*(k+1)/2) % mod;
                    ans %= mod;
                }
                else {
                    ans += ((k-1)*k/2) % mod;
                    ans %= mod;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  double r;cin>>r;
  cout<<fixed<<setprecision(10);
  cout<<r*2*M_PI<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll n;

vector<ll> p, a;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  p.resize(n);
  a.resize(n+1);
 
 for (int i = 0; i < n; i++) {
   cin >> p[i];
 }
 
 for (int i = 0; i < n; i++) {
  ll v = p[i];
  a[v] = max(a[v], a[v-1]+1);
 }
 ll mmax = 0;
 for (int i = 1; i <= n; i++) {
  mmax = max(a[i], mmax); 
 }
 cout << n - mmax << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
 
using namespace std;
 
typedef long long int lli;
 
template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
 
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
 
int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    REP(i, 0, N) {
        cin >> x[i] >> y[i] >> h[i];
    }
    REP(CX, 0, 101) {
        REP(CY, 0, 101) {
            int lft = 0, rght = 1000010000;
            while (lft <= rght) {
                int height = (lft + rght) / 2;
                int sme = 0, bg = 0, smll = 0;
                REP(i, 0, N) {
                    int th = max(height - abs(x[i] - CX) - abs(y[i] - CY), 0);
                    if (th < h[i]) {
                        smll++;
                    } else if (th > h[i]) {
                        bg++;
                    } else {
                        sme++;
                    }
                }
                if (sme == N) {
                    cout << CX << " " << CY << " " << height << endl;
                    return 0;
                } else if (bg + sme == N) {
                    rght = height - 1;
                } else if (smll + sme == N) {
                    lft = height + 1;
                } else {
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
n=int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
ans=num2alpha(n).lower()
print(ans)

Measured memory_bytes: 8968
#include<bits/stdc++.h>
#define   ll   long long int
#define   sz   200010

using namespace std;


int main()
{

    ll h,l,a,c=0;

    string s;

    cin>>s;

    h=s.length()-1;
    l=0;

    while(h>=l)
    {
        if(s[h--]!=s[l++])c++;
    }

    cout<<c<<endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int maxProfit(int[]a){
		int ans=Integer.MIN_VALUE;
		int minnum=0;
		int min= a[0];
		for (int i = minnum + 1; i < a.length; i++) {
            ans = Math.max (ans, a[i] - min);
			if (min > a[i]){
			    min = a[i];
			    minnum = i;
			}
        }
		return ans;
	}

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int nx = stdIn.nextInt();
        int [] x = new int[nx];

        for(int i = 0; i < nx; i++){
        	x[i] = stdIn.nextInt();
        }

        System.out.println(maxProfit(x));
	}
}




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

using namespace std;

#define ll long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005

int main()
{
	
	int n,a[55],ans=0;
	cin >> n;
	for(int i = 1; i <= n;i++) cin >> a[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = i+1; j <= n; j++)
		{
			ans += (a[i]*a[j]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll X,K,D,ans;
    cin>>X>>K>>D;
    ll n = abs(X)/D,r=abs(X)%D;
    if(K<=n)
    {
        ans = abs(abs(X) - K*D);
    }
    else
    {
        ll amari = K-n;
        if(amari%2 == 0)
        ans =abs(r);
        else
        ans = min(abs(r+D),abs(r-D));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3628
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	//input
	ll N; cin>>N;
	string S; cin>>S;

	ll L=0;
	char tmp=S[0];
	ll ans=1;
	rep(i,N){
		if(tmp==S[i]) continue;
		else{
			tmp=S[i];
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 512
def knight(x, y):
    mod = 10 ** 9 + 7
    x, y = min(x, y), max(x, y)

    if (x + y) % 3 != 0:
        return 0
    if y > 2 * x:
        return 0

    move = (x + y) // 3
    right = 2 * move - y
    up = move-right

    ans = 1
    for i in range(up):
        ans *= (move - i)
        ans *= pow(i + 1, mod - 2, mod)
        ans %= mod

    return ans


if __name__ == "__main__":
    x, y = map(int, input().split())
    ans = knight(x, y)
    print(ans)


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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = max(a - b * 2, 0);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  ll n, d;
  cin >> n >> d;

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d) ++cnt;
  }

  cout << cnt << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

const int MaxN = 42; 
const int MaxS = 1 << 17 | 1; 
const int mod = 1e9 + 7; 

int n, x, y, z, f[MaxN][MaxS], g[MaxS][11]; 

inline void add(int &x, const int &y)
{
	x += y; 
	x >= mod ? x -= mod : 0; 
}

int main()
{
	std::cin >> n >> x >> y >> z; 
	
	y += x, z += y; 
	int maxs = 1 << z; 
	
	for (int s = 1; s <= maxs; ++s)
		for (int i = 1; i <= 10; ++i)
		{
			g[s][i] = 1; 
			if (s == maxs)
				g[s][i] = maxs; 
			else
			{
				for (int k = 0; k < z; ++k)	
					if ((s >> k & 1) && k + i <= z && !(k < x && k + i > x) && !(k < y && k + i > y))
						g[s][i] |= 1 << k + i; 
				if (g[s][i] >= maxs)
					g[s][i] = maxs; 
			}
		}
	
	f[0][1] = 1; 
	for (int i = 0; i < n; ++i)
		for (int s = 1; s <= maxs; ++s)
			if (f[i][s])
			{
				for (int j = 1; j <= 10; ++j)
					add(f[i + 1][g[s][j]], f[i][s]); 
			}
	
	std::cout << f[n][maxs] << std::endl; 
	
	return 0; 
}

Measured memory_bytes: 26880
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    S = [input(), input()]

    if S[0][0] == S[1][0]:
        ans = 3
        i = 1
        pre = 0
    else:
        ans = 6
        i = 2
        pre = 1

    while i < N:
        if S[0][i] == S[1][i]:
            if pre == 0:
                ans *= 2
            else:
                ans *= 1

            i += 1
            pre = 0
        else:
            if pre == 0:
                ans *= 2
            else:
                ans *= 3
            i += 2
            pre = 1

        ans %= 1000000007
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint X, N, p;
lint exist[130];


int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> X >> N;
	REP(i, 130) {
		exist[i] = false;
	}
	REP(i, N) {
		cin >> p;
		exist[p] = true;
	}
	REP(i, 130) {
		if (!exist[X - i]) {
			cout << X - i << endl;
			return 0;
		}
		if (!exist[X + i]) {
			cout << X + i << endl;
			return 0;
		}
	}
}

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


signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  int A[H][W];
  rep(i, H){
    rep(j, W){
      cin >> A[i][j];
    }
  }
  int ans = 0, M = 0;
  pair<int, int> P[300000];
  for(int i=0;i<H;i++){
    for(int j=0;j<W-1;j++){
      if(A[i][j] % 2 == 1){
        P[M].first = i+1, P[M].second = j+1;
        M++;
        P[M].first = i+1, P[M].second = j+2;
        M++;
        A[i][j+1] += A[i][j]; 
        ans++;
      }
    }
  }
  for(int i=0;i<H-1;i++){
    if(A[i][W-1] % 2 == 1){
      ans++;
      P[M].first = i+1, P[M].second = W;
      M++;
      P[M].first = i+2, P[M].second = W;
      M++;
      A[i+1][W-1] += A[i][W-1]; 
    }
  }

  cout << ans << endl;
  for(int i=0;i<ans;i++){
    cout << P[i*2].first << ' ' << P[i*2].second << ' ';
    cout << P[i*2+1].first << ' ' << P[i*2+1].second << endl;
  }

}

Measured memory_bytes: 8704
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	set<char> s;
	for (int i = 0; i < n; i++) {
		char v; cin >> v;
		s.insert(v);
	}

	int l = s.size();

	if (l == 4) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    string s;
    cin >> s;
    int a = s.size();
    int num = a / 2;
    int p = 0;
    for(int i = 0; i < a; i++){
        if(s[i] == 'p'){
            p++;
        }
    }
    cout << num - p << endl;
}

Measured memory_bytes: 512
import sys
N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()

al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans =''
for s in S:
    for i in range(len(al)):
        if s == al[i]:
            ans +=al[i+N]
            break
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int a, b,c,d,e,f;
    scanf("%d", &a);

    if(100<=a && a<=999)
    {
        b= a%10;
        c= a/10;
        d= c%10;
        e= c/10;
        f= e%10;

        if(a==777)
        {
            printf("Yes\n");
        }

        else if(b==7)
        {
            printf("Yes\n");
        }

        else if(d==7)
        {
            printf("Yes\n");
        }
        else if(f==7)
        {
            printf("Yes\n");
        }

        else
        printf("No\n");
    }

    return 0;
}


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

#define ll long long int

ll dp[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, W;
    cin >> N >> W;
    for (int i = 0; i <= W; i++) dp[i] = 0;
    for (int i = 0; i < N; i++)
    {
        int w, v;
        cin >> w >> v;
        for (int j = W; j >= 0; j--) if (j >= w)
        {
            ll tmp = dp[j - w] + v;
            if (tmp > dp[j]) dp[j] = tmp;
        }
    }
    cout << dp[W] << '\n';
    return(0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;
vector<pair<ll, ll>> r;

int main () {
    cin >> n;
    REP(i, n) {
        ll x,l;
        cin >> x >> l;
        r.push_back(pair<ll,ll>(x-l, x+l));

    }

    sort(r.begin(), r.end(), [](pair<ll,ll>  a, pair<ll,ll> b) -> bool {
        if(a.second != b.second) {
            return a.second < b.second;
        } else {
            return a.first > b.first;
        }
    });

    // REP(i,n) {
    //     cout << i << ":" << r[i].first << "," << r[i].second << endl;
    // }

    ll cur = -1000000000;
    ll res = 0;
    REP(i, n) {
        // cout << cur << ":" << r[i].first << "," << r[i].second << endl;
        if(cur <= r[i].first) {
            // cout << "pick" << endl;
            res++;
            cur = r[i].second;
        }
    }

    cout << res << endl;

}

 

Measured memory_bytes: 2420
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = in.nextIntArray(n);

            int g = Euclid.gcd(a);
            for (int i = 0; i < n; i++) {
                if (a[i] >= k && (a[i] - k) % g == 0) {
                    out.println("POSSIBLE");
                    return;
                }
            }

            out.println("IMPOSSIBLE");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }

    static class Euclid {
        public static int gcd(int a, int b) {
            return a == 0 ? b : gcd(b % a, a);
        }

        public static int gcd(int[] array) {
            int ret = array[0];
            for (int i = 1; i < array.length; i++) {
                ret = gcd(ret, array[i]);
            }

            return ret;
        }

    }
}



Measured memory_bytes: 35808
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int dp[100001];
int main()
{
int n,k;cin>>n>>k;
int a[n];
memset(dp,INT_MAX,sizeof(dp));

for(int i=0;i<n;i++)
{
	cin>>a[i];
}
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<n;i++)
{
	int ans=INT_MAX;
	for(int j=1;j<=k;j++)
	{
		if(i-j<0)
		{
			break;
		}
		//cout<<ans<<" ";
		ans=min(ans,dp[i-j]+abs(a[i]-a[i-j]));
	}
	//cout<<endl;
	dp[i]=ans;
}
cout<<dp[n-1];
}
 
 




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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  
  if (a1 + a2 + a3 >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
        int n,r,flag;
        scanf("%d",&n);
        flag=0;
        while(n>0)
        {
            r=n%10;
            if(r==7)
            {
                printf("Yes\n");
                flag=1;
                break;
            }
            n/=10;
        }
        if(flag!=1)
        {
                printf("No\n");
        }


}


Measured memory_bytes: 1616
x,y = map(int,input().split())

a = [1,3,5,7,8,10,12]
b = [4,6,9,11]

if x == 2 or y == 2:
  print('No')
elif x in a and y in a:
  print('Yes')
elif x in b and y in b:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9064
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import Counter

def main():
    N = int(input())
    D = list(map(int, input().split()))
    Dc = Counter(D)

    if D[0]!=0 or Dc[0]!=1:
        print(0)
    else:
        mx = max(D)
        mod = 998244353
        ret = 1
        for i in range(1, mx+1):
            ret *= pow(Dc.get(i-1,0), Dc.get(i,0), mod)
            ret %= mod
        print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    ll n;
    cin >> n;
    ll a[n+1],b[n+1];
    for(ll i=1;i<=n;i++){
         b[i] = 0;
    }
    for(ll i=2;i<=n;i++){
        cin >> a[i];
        b[a[i]]++;
    }
    for(ll i=1;i<=n;i++)cout << b[i] << endl;
}


Measured memory_bytes: 6748