akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

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

  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  --a;

  const ll ta = a - a / c - a / d + a / lcm(c, d);
  const ll tb = b - b / c - b / d + b / lcm(c, d);
  cout << tb - ta << endl;
}

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

  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int a[n+1];
	for(i=1;i<=n;i++)  cin>>a[i];
	int minv=2147483647;
	for(i=1;i<=n;i++){
		int x=a[i],cnt=0;
		while(x%2==0){
			x/=2;
			cnt++;
		}
		if(cnt<minv)  minv=cnt;
	}
	
	cout<<minv<<endl;
	
	return 0;
}

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



int main(void) {
	long long H, W;
	cin >> H >> W;
	
	long long dif = (long long)H*W;

	for (int h = 1; h <= H-1; h++) {
		if ((H-h)>=2) {
			long long S[3] = {h*W, ((H-h)/2)*W, ((H-h)-((H-h)/2))*W};
			long long max = std::max(S[0], std::max(S[1], S[2]));
			long long min = std::min(S[0], std::min(S[1], S[2]));
			dif = std::min(dif, max-min);
			if (dif == 32704) {
				dif = dif;
			}
		}
		{
			long long S[3] = {h*W, (H-h)*(W/2), (H-h)*(W-W/2)};
			long long max = std::max(S[0], std::max(S[1], S[2]));
			long long min = std::min(S[0], std::min(S[1], S[2]));
			dif = std::min(dif, max-min);
			if (dif == 32704) {
				dif = dif;
			}
		}
	}

	swap(H, W);
	for (int h = 1; h <= H-1; h++) {
		if ((H-h)>=2) {
			long long S[3] = {h*W, ((H-h)/2)*W, ((H-h)-((H-h)/2))*W};
			long long max = std::max(S[0], std::max(S[1], S[2]));
			long long min = std::min(S[0], std::min(S[1], S[2]));
			dif = std::min(dif, max-min);
		} 
		{
			long long S[3] = {h*W, (H-h)*(W/2), (H-h)*(W-W/2)};
			long long max = std::max(S[0], std::max(S[1], S[2]));
			long long min = std::min(S[0], std::min(S[1], S[2]));
			dif = std::min(dif, max-min);
		}
	}	
	
	cout << dif << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int N;
vector<vector<int>> E;
int need[100000 + 10];

int getneed(int pos) {
	if (need[pos] != 0)return need[pos];
	vector<int> slist;
	for (int i = 0; i < E[pos].size(); i++) {
		int nxt = E[pos][i];
		slist.push_back(getneed(nxt));
	}
	sort(slist.begin(), slist.end());
	int cnt = 0;
	for (int i = 0; i < slist.size(); i++) {
		if (cnt < slist[i])cnt = slist[i];
		cnt++;
	}
	need[pos] = cnt;
	return need[pos];
}

int main() {
	cin >> N;
	E.resize(N);

	for (int i = 1; i < N; i++) {
		int a;
		cin >> a;
		a--;
		E[a].push_back(i);
	}

	getneed(0);

	cout << need[0] << endl;

	return 0;
}

Measured memory_bytes: 15488
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		for(int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}
		boolean flag = true;
		for(int i = N - 2 ; i >= 0; i--) {
			if(X[i] > X[i + 1]) {
				if(X[i] - X[i + 1] == 1)X[i]--;
				else{
					flag = false;
					break;
				}
			}
		}

		System.out.println((flag)?"Yes":"No");

	}
}

Measured memory_bytes: 49956
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

//scanf("%d",&x);
//printf("%d",x);
//for(i=0;i<N;i++){  }
//if( == ){  }else{  }
//while( ){  }

/*
int N, i;
int H[100];
scanf("%d", &N);
for (i = 0; i < N; i++) scanf("%s", &H[i]);
*/

int main()
{
	int a[4];
	int i;

	
	for (i = 0; i < 3; i++) scanf("%d", &a[i]);

	for (i = 0; i < 3; i++) {
		for (int j = i + 1; j < 3; j++) {

			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	
	

	int Ans = a[2] * 10 + a[1] + a[0];

	printf("%d", Ans);
}

Measured memory_bytes: 128
s = list(input())
k = int(input())
x = []
ans = 0
cnt = 1
for i in range(len(s)):
    if i < len(s) - 1 and s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        x.append(cnt)
        cnt = 1
cnt = 0
if s[0] == s[len(s) - 1]:
    cnt = x[0] // 2 + x[-1] // 2 - (x[0] + x[-1]) // 2

print(ans * k - cnt * (k - 1) if len(set(s)) != 1 else len(s) * k // 2)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string s;
int lens,ans,g_c=0,p_c=0;
int main(){
	cin>>s;
	lens=s.length();
	for(int i=0;i<lens;++i){
		if(s[i]=='p' && g_c>p_c){
			++p_c;
		}
		else if(s[i]=='p'){
			--ans;
			++g_c;
		}
		if(s[i]=='g' && g_c>p_c){
			++ans;
			++p_c;
		}
		else if(s[i]=='g'){
			++g_c;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std; 

int func(int a){
	if ( a%2){
		return 3*a + 1;
	}
	return a / 2;
}


int main(){
	
	int s ; 
	
	vector<int> v(100007);
	vector<int> values(100007);
	
	cin >> s ;
	
	int index = 1;
	
	values[s] = 1;
	
	while(1){
		
		s = func(s);
		
		
		index++; 
		
		if(values[s]){
			cout << index << endl; 
			return 0;
		}
		
		values[s] = 1;
		
	}
	
    return 0;
}


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

int		main()
{
	char *S, *N;

	S = (char *)malloc(sizeof(char) * 12);
	N = (char *)malloc(sizeof(char) * 12);
	scanf("%s\n%s\n", S, N);
	if (strlen(S) + 1 - strlen(N) == 0)
	{
		N[strlen(N) - 1] = '\0';
		if (strcmp(S, N) == 0)
		{
			printf("Yes\n");
			return (0);
		}
	}
	printf("No\n");
	return (0);
}

Measured memory_bytes: 1660
#include <stdio.h>

int sort(const void *a, const void *b){
  if(*(int *)a < *(int *)b) return -1;
  else if(*(int *)a == *(int *)b) return 0;
  else return 1;
}

int main(){
  int a[3], tmp, i, ans=0;
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  qsort(a,3,sizeof(int),sort);

  if((a[1]+a[2])%2 == 1){
    a[0]++;
    a[1]++;
    ans++;
    if((a[0]+a[2])%2 == 1){
      a[1]++;
      a[2]++;
      ans++;
    }
  } else if((a[0]+a[2])%2 == 1){
    a[1]++;
    a[2]++;
    ans++;
  }
  ans+=(a[2]-a[1])/2;
  ans+=(a[2]-a[0])/2;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

main = do
  [a,b,c,d]<-readInt
  print $ max (a*b) (c*d)

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  string s;
  cin >> s;
  ll res = 0;
  ll res2 = 0;
  REP(i,s.length()){
    if (i%2==0) {
      if (s[i] == '1'){
      res++;
      }
    }
    else{
      if (s[i] == '0'){
        res++;
      }
    }
  }
  REP(i,s.length()){
    if (i%2==0) {
      if (s[i] == '0'){
        res2++;
      }
    }
    else{
      if (s[i] == '1'){
        res2++;
      }
    }
  }
  cout << min(res,res2) << endl;
  return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int f(int i){
	ll l = 1, r = 1e5;
	while(l < r){
		ll mid = (l + r + 1) / 2;
		if((mid * (mid + 1) / 2) <= i) l = mid;
		else r = mid - 1;
	}
	return l;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n;
	cin >> n;
	int ans = 0;
	for(ll i = 2; (i * i) <= n; i++){
		int cur = 0;
		while(n % i == 0){
			n /= i;
			cur++;
		}
		if(cur) ans += f(cur);
	}
	if(n > 1) ans++;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3620
N, M = map(int,input().split())
A = [str(input()) for i in range(N)]
B = [str(input()) for i in range(M)]

for i in range(N - M + 1):
  for j in range(N - M + 1):
    #start = A[i][j]
    count = 0
    for k in range(M):
      for l in range(M):
        if B[k][l] != A[i + k][j + l]:
          count += 1
    if count == 0:
      print("Yes")
      quit()
  
print("No")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# 標準入力を取得
n = int(input())
G = {}
for _ in range(n):
    g = list(map(int, input().split()))
    G[g[0]] = g[2:]

# 求解処理
seen = [False for _ in range(n)]
ans = []


def dfs(v: int) -> None:
    seen[v - 1] = True
    ans.append(v)

    for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

    ans.append(v)


while sum(seen) != n:
    v = seen.index(False)
    dfs(v + 1)

d = [-1 for _ in range(n)]
f = [-1 for _ in range(n)]

for i, a in enumerate(ans):
    if d[a - 1] == -1:
        d[a - 1] = i + 1
    else:
        f[a - 1] = i + 1

for id in range(n):
    print(id + 1, d[id], f[id])



Measured memory_bytes: 5724
#include<stdio.h>

int main(void){
    int th,ta,ah,aa;
    scanf("%d %d %d %d",&th,&ta,&ah,&aa);
    int p= th/aa>=ah/ta ? th/aa : ah/ta;
    th-=aa*p;
    ah-=ta*p;
    if((th>0 && ah>0 && ah-ta<=0) || (ah<=0)){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1704
(defun solve (N K)
  (loop for i from 0
        with arr = (loop for m from 1 to N collect m)
        and sum = 0 and M = N
        if (null arr) return (/ sum N)
        do (setf arr (loop for x in arr with j = 0
                           while (< x K)
                           collect (* x 2)
                           do (incf j)
                           finally (incf sum (/ (- M j) (expt 2 i)))
                           (setf M j)))))


(format t "~F" (coerce (solve (read) (read)) 'long-float))

Measured memory_bytes: 6500
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int X, Y;
    cin >> X >> Y;
    
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            if(i + j == X && i * 4 + j * 2 == Y){
                cout << "Yes" << endl;
                return 0;
        
            }    
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3632
#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 FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
#define FS first
#define SC second
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define SQR(x) ((x) * (x))
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;
template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}

long perm(int N, int K){
	long x=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
	}
	return x%MOD;
}

long factorial(int N){
	return perm(N,N);
}

long comb(int N,int K){
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

bool isprime(int n) {
    if (n < 2) return false;
    for (int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void eratosthenes(int n){
	// エラトステネスのふるい
    bitset<1000000> is_prime(0); // 十分大きなサイズを確保します
    for (int i = 2; i <= n; ++i) is_prime.set(i); // とりあえず全部ふるいに入れます
    for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) { // 素数 i を発見したら
            for (int j = i * 2; j <= n; j += i) {
                is_prime.reset(j); // i の倍数をふるい落とす
            }
        }
    }
	for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) cout << i << endl;
    }
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (int next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v, seen); // 再帰的に探索
    }
}

void bfs(const vector<vector<int> > &G, int v, vector<int> &dist){
    REP(i,SZ(dist)) dist[i] = -1; // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[v] = 0;
    que.push(v); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int next_v : G[v]) {
            if (dist[next_v] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[next_v] = dist[v] + 1;
            que.push(next_v);
        }
    }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
let solve tak aoki k =
    let rec solve_t tak aoki k =
        if k = 0 then tak, aoki
        else solve_a (tak / 2) (aoki + tak / 2) (k - 1)
    and solve_a tak aoki k =
        if k = 0 then tak, aoki
        else solve_t (tak + aoki / 2) (aoki / 2) (k - 1)
    in solve_t tak aoki k

let () =
    let tak, aoki = Scanf.scanf "%d %d %d\n" solve in
    Printf.printf "%d %d\n" tak aoki


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

ll mod = 1e9 + 7;

int main() {
    int n, ans = 0;
    string c;
    cin >> n >> c;
    int cntw = 0, cntr = 0;
    int w[n], r[n];
    for(int i=0; i<n; i++) {
        if(c[i] == 'W') cntw++;
        else cntr++;
        w[i] = cntw;
        r[i] = cntr;
    }
    for(int i=0; i<n; i++) {
        if(w[i] == cntr - r[i]) ans = w[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5316
#include<iostream>
using namespace std;
int main()
{
    int a,b,n=1,m;
    cin>>a>>b;
    while(a>0)
    {
        n*=100;
        a--;
    }
    if(a==0)
    {
        if(b==100)
            b++;

    }
    cout<<b*n<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
import itertools

def distance(x1,y1,x2,y2):
    l = math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
    return l


N = int(input())
S = []
for _ in range(N):
  S.append(list(map(int, input().split())))
l = [i for i in range(N)]
dic=[]
for v in itertools.permutations(l):
    dic.append(v)
#print(dic)
    
sum_l=0.0
for i in range(len(dic)):
  for j in range(N-1):
    sum_l += distance(S[dic[i][j]][0],S[dic[i][j]][1],S[dic[i][j+1]][0],S[dic[i][j+1]][1])
print(sum_l/len(dic))

Measured memory_bytes: 45424
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

max_read = 0

def spend(t):
    global max_read
    if t % 10 == 0:
        return t
    else:
        ret = (t // 10 + 1) * 10
        max_read = max(max_read, ret-t)
        return ret
    


result = 0
result += spend(A)
result += spend(B)
result += spend(C)
result += spend(D)
result += spend(E)
print(result - max_read)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		int input[] = new int[n];

		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int l = 0;
		int r = 1_000_000_001;

		while(l < r - 1){
			int mid = (l + r)/2;
//			System.out.println("l "+l+" r " + r+" mid "+mid);

			int tmpCount = 0;

			for(int i = 0; i < n; i++){
				tmpCount += (input[i] - 1)/mid;
			}
//			System.out.println("cut "+tmpCount);

			if(tmpCount <= k){
				r = mid;
			}
			else {
				l = mid;
			}
		}

		System.out.println(r);
	}

}


Measured memory_bytes: 50504
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	string a;
	cin >> a;

	bool n = false , w = false, s = false, e = false;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'N') {
			n = true;
		}
		if (a[i] == 'W') {
			w = true;
		}
		if (a[i] == 'S') {
			s = true;
		}
		if (a[i] == 'E') {
			e = true;
		}
	}

	if ((n && !s) || (!n && s) || (w && !e) || (!w && e)) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	string s;
	cin >> s;
	string ans;
	if (s[0] == 'S')ans = "Cloudy";
	else if (s[0] == 'C')ans = "Rainy";
	else if (s[0] == 'R')ans = "Sunny";
		c(ans);

	return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int n,k;cin>>n>>k;
    combination c(n);
    mint res=0;
    if(k<n){
        rep(i,k+1){
            int l=n-i;
            res+=c(n-1,l-1)*c(n,i);
            //cout<<(c(n-1,l-1)*c(n,i)).x<<endl;
        }
    }else{
        rep(i,n+1){
            int l=n-i;
            res+=c(n-1,l-1)*c(n,i);
        }
    }
    cout<<res.x<<endl;
}

Measured memory_bytes: 3328
N = int(input())
S = input()



# 1,Nをヒツジと狼のどちらかと仮定して場合分け

for s1,sn in [("S","S"), ("S","W"), ("W","S"), ("W","W")]:
    ans = [""]*(N+2)
    ans[1] = s1
    ans[0] = sn
    for i in range(1,N+1):
       
        if ans[i] == "S":

            if S[i-1] == "o":
                ans[i+1] = "S" if ans[i-1] =="S" else "W"
            else:
                ans[i+1] = "W" if ans[i-1] =="S" else "S"
        else:
            if S[i-1] == "o":
                ans[i+1] = "S" if ans[i-1] =="W" else "W"
            else:
                ans[i+1] = "W" if ans[i-1] =="W" else "S"

    if ans[0] == ans[N] and ans[1] == ans[N+1]:
        print("".join(ans[1:N+1]))
        exit()

print(-1)

Measured memory_bytes: 4948
def f(a):
	s=0;q=a[:n];s=sum(q);heapify(q);r=[s]
	for e in a[n:2*n]:s+=e-heappushpop(q,e);r+=[s]
	return r
import sys;from heapq import*;n,*a=list(map(int,sys.stdin.read().split()));print(max(map(sum,zip(f(a),reversed(f([-e for e in reversed(a)]))))))

Measured memory_bytes: 127832
#ifdef debug
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    int n;

    scanf("%d", &n);

    vec< int > p(n + 1);
    vec< int > dp(n + 1);

    for(int i = 1;i <= n;i++) {
        scanf("%d", &p[i]);
        dp[p[i]] = dp[p[i] - 1] + 1;
    }

    printf("%d\n", n - *max_element(ALL(dp)));

    return 0;
}


Measured memory_bytes: 1792
ta=list(input())
sz=len(ta)
ans0=0
ans1=0
ans=0
for i in range(sz):
    if(i%2==0):
        if(ta[i]=="0"):
            ans0=ans0+1
    else:
        if(ta[i]=="1"):
            ans0=ans0+1
for i in range(sz):
    if(i%2==0):
        if(ta[i]=="1"):
            ans1=ans1+1
    else:
        if(ta[i]=="0"):
            ans1=ans1+1
ans+=min(ans0,ans1)
print(ans)

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

using namespace std;

int in(){ int a; cin >> a; return a; }
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
  int n = in();
  int ac = 0, wa = 0, tle = 0, re = 0;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    if(s == "AC") ac++;
    if(s == "WA") wa++;
    if(s == "TLE") tle++;
    if(s == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}



Measured memory_bytes: 3656
#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>;

const int N = 60;
const int M = 3;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  ll k;
  cin >> k;
  if (abs(a - b) > 1e18) {
    cout << "Unfair" << endl;
    return 0;
  }
  if (k % 2 == 0)
    cout << a - b << endl;
  else
    cout << b - a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string S;
    int ans=0;
    cin>>S;
    for(int i=0;i<3;i++){
        if(S[i]=='1'){
            ans+=1;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define db double
const int MX=3000;
db dp[MX+5][MX+5];
db a[MX+5];
int vis[MX+5][MX+5];
int n,k;
db solve(int p, int c)
{
  if(p>n)
  {
    if(c>=k)return 1.0;
    else return 0.0;
  }
  if(~vis[p][c])return dp[p][c];
  db mx;
  mx=(1.0-a[p])*solve(p+1,c)+a[p]*solve(p+1,c+1);
  vis[p][c]=1;
  return dp[p][c]=mx;
}
int main()
{
  cin>>n;
  k=n/2;
  k++;
  for(int i=1;i<=n;i++)cin>>a[i];
  memset(vis,-1,sizeof(vis));
  db res=solve(1,0);
  cout<<setprecision(10)<<fixed<<res<<endl;
  return 0;
}


Measured memory_bytes: 106112
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    while(a != 0 || b != 0) {
        cout << min(a,b) << " " << max(a,b)<<endl;
        cin >> a >> b;
    }
    return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    string S;
    cin >> S;
    string r="";
    r+=S[0];
    int cnt=1;
    for(int i=1; i<S.size(); i++){
        string tmp="";
        tmp+=S[i];
        int pp=0;
        if(tmp==r){
            for(int j=i+1; j<S.size(); j++){
                tmp+=S[j];
                pp++;
                if(tmp!=r){
                    break;
                }
            }
        }
        if(r!=tmp){
            r=tmp;
            cnt++;
        }
        i+=pp;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define INF (1 << 31) - 1

int main() {
  int N;
  cin >> N;
  int X[N];
  rep(i,N){
    cin >> X[i];
  }
  int min_sum = INF;
  rep(i,100){
    int sum = 0;
    rep(j,N){
     sum += (X[j]-i)*(X[j]-i);
    }
    min_sum = min(sum,min_sum);
  }
  cout << min_sum << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
#define MOD 1000000007
//scanf("%d", &a) '\n'
 
int main() {
	int n;
	cin >> n;
	vector<int> a(100001, 0);
	vector<int> b(100001, 0);
    int unko=0;
	rep(i, n) {
		int v;
		scanf("%d", &v); '\n';
        unko=max(unko,v);
		if (i % 2 == 0) a[v]++;
		else b[v]++;
	}
	int ma = 0;
	int na = 0;
	int mb = 0;
	int nb = 0;
	rep2(i, 1, unko+1) {
		if (a[i] > a[ma]) {
			na = ma;
			ma = i;
		}
		else if (a[i] > a[na]) {
			na = i;
		}
		if (b[i] > b[mb]) {
			nb = mb;
			mb = i;
		}
		else if (b[i] > b[nb]) {
			nb = i;
		}
	}
	if (ma != mb) {
		cout << n - a[ma] - b[mb] << endl;
	}
	else {
		cout << n - max(a[ma] + b[nb], a[na] + b[mb]) << endl;
	}
}
	

Measured memory_bytes: 1532
S = input()

YYMM = 1 <= int(S[2:]) <= 12
MMYY = 1 <= int(S[:2]) <= 12

if YYMM and MMYY:
    print('AMBIGUOUS')
elif YYMM and not MMYY:
    print('YYMM')
elif not YYMM and MMYY:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  string s;
  cin >> s;
  ll sum = 0;
  for (int i = 0, N = s.size(); i < N; i++) {
    sum += (int)s[i] - '0';
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int n;
int good[3]={3,5,7};
int cnt=0;
void dfs(ll,ll);
int main(){
    cin>>n;
    dfs(0,0);
    cout<<cnt<<endl;
}
void dfs(ll sum,ll d){
    if(sum>n)return;
    vector<int>flag(3,0);
    string now=to_string(sum);
    rep(i,(int)now.size()){
        if(now[i]=='3')flag[0]=1;
        if(now[i]=='5')flag[1]=1;
        if(now[i]=='7')flag[2]=1;
    }
    if(flag[0]&&flag[1]&&flag[2])cnt++;
    for(int i=0;i<3;i++){
        int add=good[i];
        if(sum*10+add<=n){
            dfs(sum*10+add,d+1);
        }
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

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

    ll fact=26;
    int cnt=1;
    for(int i=0; i<15; i++){
        if(N-fact<=0)break;
        else{
            N-=fact;
            fact*=26LL;
            cnt++;
        }
    }
    
    N--;
    vector<char> ans(0);
    for(int i=0; i<cnt; i++){
        ans.push_back(N%26+'a');
        N/=26;
    }
    reverse(ans.begin(),ans.end());
    for(auto &a:ans){
        cout << a;
    }
    cout << endl;
}

Measured memory_bytes: 3624
n=int(input())
x=[0 for i in range(6)]
for i in range(n):
  a=float(input())
  if a<165.0:
    x[0]+=1
  elif 165.0<=a<170.0:
    x[1]+=1
  elif 170.0<=a<175.0:
    x[2]+=1
  elif 175.0<=a<180.0:
    x[3]+=1
  elif 180.0<=a<185.0:
    x[4]+=1
  else:
    x[5]+=1
for i in range(6):
  print('{}:{}'.format(i+1,x[i]*'*'))


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    cin >>n;
    vector<int>a(n);
    deque<int>ans;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        if(i%2==0){
            ans.push_back(a[i]);
        }else{
            ans.push_front(a[i]);
        }
    }
    if(n%2==1){
        reverse(all(ans));
    }
    rep(i,n){
    cout<<ans[i];
    if(i!=n){
        cout<<" ";
    }
    }
    cout<<endl;
}

Measured memory_bytes: 3840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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





void printVector(VI &a){
    int n = SZ(a);
    REP(i, n){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << "\n";
}

int bubbleSort(VI &a){
    int n = SZ(a), ret = 0;
    bool flag = true;
    for(int i = 0; flag && (i < n); ++i){
        flag = false;
        for(int j = n-1; j >= i + 1; --j){
            if(a[j-1] > a[j]){
                swap(a[j-1], a[j]);
                flag = true; ++ret;
            }
        }
    }
    return ret;
}

int main(){
    int n; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    int cnt = bubbleSort(a);
    printVector(a);
    cout << cnt << "\n";
    return 0;
}



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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, M, X, Y;
ll i, j, k;
int main(){

    scanf("%lld%lld%lld%lld", &N, &M, &X, &Y);
    j = X;
    fornum(i,0,N){
        ll x;
        scanf("%lld", &x);
        j = max(j, x);
    }
    k = Y;
    fornum(i,0,M){
        ll y;
        scanf("%lld", &y);
        k = min(k, y);
    }
    if(j<k){
        printf("No War");
    }else{
        printf("War");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B.begin(),B.end());
    for(int i = 0; i < N; i++) {
        if(A[i] == B[N-1]) {
            cout << B[N-2] << endl;
        }
        else {
            cout << B[N-1] << endl;
        }
    }
}

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

using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 4e18;
const ll MOD = 1e9+7;

int dp[100110];
int h[100110];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;

  for (int i = 1; i <= n; i++) {
    dp[i] = inf;
    cin >> h[i];
  }

  dp[1] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    }
  }

  cout << dp[n] << endl;
  return 0;
}


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

using namespace std;

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

	int n, m, x;
	int a[100];
	cin >> n >> m >> x;
	for( int i = 0; i < m; i++ )cin >> a[i];
	for( int i = 0; i < m; i++ )
	{
		if( a[i] > x )
		{
			cout << min(i, m - i) << endl;
			break;
		}
	}

	return 0;
}


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

using namespace std;


typedef long long ll;
ll mod=1e9+0LL;
ll MOD=1e18+0LL;
double pi=acos(-1);


int main()
{
    int cs=1;
    //scanf("%d",&cs);
    while(cs--)
    {
        int n,i;cin>>n;
        ll mul=1LL;
        ll arr[n];
        for(i=0;i<n;i++) {cin>>arr[i];
        if(arr[i]==0) mul=0;}
        if(!mul)
        {
            cout<<0;
            return 0;
        }
        long double power=0;
        for(i=0;i<n;i++)
        {
            power+=log10(arr[i]);
        }
        if(power>18)
        {
            cout<<-1;
            return 0;
        }
        for(i=0;i<n;i++)
        {
            mul*=arr[i];
        }
        if(mul>1000000000000000000)
        {
            cout<<-1;
            return 0;
        }
        cout<<mul;
    }
}


Measured memory_bytes: 4596
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 a = sc.nextInt();
    int b = sc.nextInt();
    int answer=0;
    answer = (h-a)*(w-b);
    System.out.println(answer);
  }
  

  
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

int main() {

  ll N,M,ans=0; cin >> N >> M ;
  
  if(2*N<=M){//ここの条件ミスった、アホすぎる
    ans+=N;
    ll x=M-2*N;
    ans+=(x/4);
  }

  else{
    ans+=(M/2);
  }
  
  cout << ans << endl;

  return 0;
}

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<ll,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;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  vi vec;
  cin >> n;
  rep(i,0,n*2){
    cin >> m;
    vec.pb(m);
  }
  sort(all(vec));
  l = 0;
  rep(i,0,n*2){
    l += min(vec[i],vec[i+1]);
    i++;
  }
  print(l);
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll dr[4] = { 1, -1, 0, 0 };
ll dc[4] = { 0, 0, 1, -1 };

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<vector<ll>> dp(n,vector<ll>(n));
  rep(r,n)rep(c,n) {
    ll minR = min(r,n-1-r);
    ll minC = min(c,n-1-c);
    dp[r][c] = min(minR,minC);
  }

  vector<vector<bool>> isBlank(n,vector<bool>(n));

  // printtree(dp);

  ll ans = 0;
  rep(iter,n*n) {
    ll p;
    cin >> p;
    --p;
    ll r = p/n;
    ll c = p%n;
    ans += dp[r][c];

    // Update (r,c)
    isBlank[r][c] = true;

    // Update by BFS
    P s = P(r,c);
    queue<P> q;
    q.push(s);
    while (!q.empty()) {
      P p = q.front(); q.pop();
      ll r = p.first;
      ll c = p.second;
      ll newCost; // candidate cost for surroundings
      if (isBlank[r][c]) {
        newCost = dp[r][c];
      } else { // is not blank
        newCost = dp[r][c] + 1; // 1 by (r,c)
      }
      // Update surroundings
      rep(i,4) {
        ll nr = r+dr[i];
        ll nc = c+dc[i];
        if (nr < 0 || nr >= n || nc < 0 || nc >= n) { continue; }
        if (dp[nr][nc] > newCost) {
          dp[nr][nc] = newCost;
          q.emplace(nr,nc);
        }
      }
    }

    // cout << "(r,c):" << r << "," << c << endl;
    // printtree(dp);
  }
  cout << ans << endl;
}


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

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

    int res = S.size();
    for(int i=0; i+1<S.size(); ++i) {
        if(S[i] == S[i + 1]) --res, i += 2;
    }
    cout << res << endl;
}

Measured memory_bytes: 640
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
ans = min(a)+min(b)
 
for i in range(M):
    x,y,z = map(int,input().split())
    s = a[x-1]+b[y-1]-z
    ans = (s if s < ans else ans)
 
print(ans)

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

using namespace std;
typedef long long ll;

vector<ll> vec;
ll N, A, B;

bool isOK(ll x) {
  ll num = 0;
  for (int i = 0; i < N; i++) {
    ll hp = vec[i] - (x * B);
    if (hp > 0) {
      ll cnt = hp / (A - B);
      if (hp % (A - B)) {
        cnt++;
      }
      num += cnt;
    }
  }
  return (x >= num);
}

ll binary_search() {
  ll ng = 0;
  ll ok = 1e9;

  while (abs(ng - ok) > 1) {
    ll mid = (ng + ok) / 2;
    if (isOK(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

int main() {
  cin >> N >> A >> B;
  vec.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  cout << binary_search() << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int D[31][31];
int c[510][510];
int cnt[31][3];
int main()
{
	int N, C;
	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> c[i][j];
			c[i][j]--;
			cnt[c[i][j]][(i + j + 2) % 3]++;
		}
	}
	int ans = mod;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			for (int k = 0; k < C; k++) {
				if (i == j || j == k || k == i) continue;
				int cost = 0;
				for (int l = 0; l < C; l++) {
					cost += D[l][i] * cnt[l][0];
					cost += D[l][j] * cnt[l][1];
					cost += D[l][k] * cnt[l][2];
				}
				ans = min(ans, cost);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  char now = 'a';
  while (true) {
    if (now == 'a') {
      if (sa.size() == 0) {
        cout << 'A' << endl;
        return 0;
      }
      now = sa[0];
      sa.erase(sa.begin());
    } else if (now == 'b') {
      if (sb.size() == 0) {
        cout << 'B' << endl;
        return 0;
      }
      now = sb[0];
      sb.erase(sb.begin());
    } else {
      if (sc.size() == 0) {
        cout << 'C' << endl;
        return 0;
      }
      now = sc[0];
      sc.erase(sc.begin());
    }
  }
}


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

vector<int>to[100010];
int dp[100010];

int rec(int v){
  vector<int>num;
  for(int u:to[v]){
    num.push_back(rec(u));
  }
  sort(num.begin(),num.end());
  int cnt=0;
  rep(i,num.size()){
    cnt=max(cnt,num[i]);
    cnt++;
  }
  dp[v]=cnt;
  return dp[v];
}

int main(){
  int n;
  cin>>n;
  for(int i=2; i<=n; ++i){
    int a; cin>>a;
    to[a].push_back(i);
  }
  rec(1);
  cout<<dp[1]<<endl;
}

Measured memory_bytes: 18704