akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  deque<char> deq;
  int len = S.size();
  for(int i = 0; i < len; i++) {
    deq.push_back(S.at(i));
  }

  int cntT = 0;
  int T, F;
  bool state = false;
  char C;

  for(int i = 0; i < Q; i++) {
    cin >> T;
    if(T == 1) {
      state = !state;
      cntT++;
    } else {
      cin >> F >> C;
      if(state) {
        if(F == 1) {
          // S = S+C;
          deq.push_back(C);
        } else {
          // S = C+S;
          deq.push_front(C);
        }
      } else {
        if(F == 1) {
          // S = C+S;
          deq.push_front(C);
        } else {
          // S = S+C;
          deq.push_back(C);
        }
      }
    }
  }

  int size = deq.size();
  if(cntT % 2 == 1) {
    for(int i = 0; i < size; i++) {
      char b = deq.back();
      deq.pop_back();
      cout << b;
    }
  } else {
    for(int i = 0; i < size; i++) {
      char f = deq.front();
      deq.pop_front();
      cout << f;
    }
  }
  cout << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, w; cin >> n >> w;
	vector<ll> dp(w + 1);
	rep(i, n){
		int a, b; cin >> a >> b;
		for(int j = w - a; j >= 0; j--) dp[j + a] = max(dp[j + a], dp[j] + b);
	}
	cout << dp[w] << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

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

  if(n==0) {
    cout << 0 << endl;
    return 0;
  }

  int cur = 1;
  string ans = "";
  while(n != 0){
    if(n%2==0) ans.pb('0');
    else {
      ans.pb('1');
      n -= cur;
    }
    cur *= -1;
    n /= 2;
  }
  reverse(all(ans));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int n, x, t;
	cin >> n >> x >> t;

	int ans = ((n - 1) / x + 1) * t;

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


Measured memory_bytes: 3640
#C問題
N = int(input())
S = []
for i in range(N):
    s = list(str(input()))
    s.sort()
    S.append(s)
S.sort()

count = 0
now = 0
nows = 0
for i in range(N):
    if i == 0:
        nows = S[0]
        now = 1
    else:
        if nows != S[i]:
            nows = S[i]
            count += ((now*(now-1))//2)
            now = 1
        else:
            now+=1
            
count += ((now*(now-1))//2)
print(count)


Measured memory_bytes: 24652
import numpy as np
def divisor(n):
    tank = []
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            tank.append(i)
            if i!=n//i:
                tank.append(n//i)
    tank.sort()
    return tank

n = int(input())
tank = np.array(divisor(n))
res = 0
for i in range(len(tank)):
    x = tank[i] - 1
    if x!=0 and n%x==n//x:
        res += x
print(res)

Measured memory_bytes: 12564
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int n,ans=0;
  cin >> n;
  vector<string>s(n);
  unordered_map<string,long long>mp(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
    sort(s[i].begin(),s[i].end());
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++){
    mp[s[i]]++;
    ans+=mp[s[i]]-1;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		String line[] = sc.nextLine().split(" ");

		int n = Integer.parseInt(line[0]);
		int x = Integer.parseInt(line[1]);

		int height = 0;
		int cnt = 1;

		for(int i = 0; i < n; i++) {
			int l = sc.nextInt();

			height += l;

			if(height > x) {
				break;
			}
			cnt++;
		}

		sc.close();
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21844
from collections import deque


def main():
    ans = deque()
    n = int(input())
    for i in range(n):
        c = input()
        if c == "deleteFirst":
            ans.popleft()
        elif c == "deleteLast":
            ans.pop()
        else:
            c, x = c.split()
            if c == "insert":
                ans.insert(0, x)
            else:
                try:
                    ans.remove(x)
                except ValueError:
                    pass
    print(*ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 69732
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main() {
	double n, over = 255, under[4] = {0.5, 0.25, 0.125, 0.0625};
	rep(i, 4) over += under[i];
	while(cin >> n, n != -1.0) {
		double sum = 0;
		vector<char> ans;
		if(n > over) cout << "NA" << endl;
		else {
			for(int i = 7; i > -1; --i) {
				if(sum + (1 << i) <= n) {
					sum += (1 << i);
					ans.push_back('1');
				}
				else ans.push_back('0');
			}
			ans.push_back('.');
			rep(i, 4) {
				if(sum + under[i] <= n) {
					sum += under[i];
					ans.push_back('1');
				}
				else ans.push_back('0');
			}
			if(sum == n) rep(i, ans.size()) cout << ans[i];
			else cout << "NA";
			cout << endl;
		}
	}
}

Measured memory_bytes: 1240
#D
N = int(input())
A = list(map(int, input().split()))

A.sort()
posA = 0
negcnt = 0
absmin = 10**9
for itm in A:
    if itm < 0:
        negcnt += 1
    absmin = min(absmin, abs(itm))
    posA += abs(itm)
ifNodd = N % 2
ifnegodd = negcnt % 2
#-1 N
#odd odd = N-1
#even even = N
#odd even = N-1
#even odd = N
if ifnegodd == 1:
    ans = posA - 2*absmin
else:
    ans = posA
print(ans)


Measured memory_bytes: 14284
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

lint powermod(lint a, int x, lint MOD)
{
    if (x == 0)
        return 1 % MOD;
    if (x % 2 == 1)
        return a * powermod(a, x - 1, MOD) % MOD;
    lint ret = powermod(a, x / 2, MOD);
    return ret * ret % MOD;
};

lint inversemod(lint a, lint MOD)
{
    return powermod(a, MOD - 2, MOD);
};

lint count_paths(int h, int w, VEC(lint)& factorials, lint MOD)
{
    lint ret = factorials[h + w - 2];
    ret = ret * inversemod(factorials[h - 1], MOD) % MOD;
    ret = ret * inversemod(factorials[w - 1], MOD) % MOD;
    return ret;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    const lint MOD = 1000000007;
    VEC(lint) factorials(200001);
    factorials[0] = 1;
    FOR(i, 1, 200001)
        factorials[i] = factorials[i - 1] * i % MOD;

    lint all = count_paths(H, W, factorials, MOD), sub = 0;
    FOR(h, H - A + 1, H + 1) {
        lint rem = count_paths(h, B, factorials, MOD);
        rem = rem * count_paths(H + 1 - h, W - B, factorials, MOD) % MOD;
        sub = (sub + rem) % MOD;
    }

    lint ret = (all + MOD - sub) % MOD;
    cout << ret << endl;
    return 0;
};


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

import sys


if len(sys.argv) == 2:
    sys.stdin = open(sys.argv[1])

N = int(input())
S = input()
T = ""
for ch in S:
    T += chr(ord('A') + (ord(ch) - ord('A') + N) % 26)
print(T)


Measured memory_bytes: 9184
fun main() {
    val (s, w) = readListInt()
    if (s > w) {
        println("safe")
        return
    }
    println("unsafe")

}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 36420
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string o, e;
	cin >> o >> e;
	REP(i, o.length()) {
		cout << o[i];
		if (i < e.length()) cout << e[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

def main():
    A, B, Q = map(int, input().split())
    S = [-10**12] + [int(input()) for _ in range(A)] + [10**12]
    T = [-10**12] + [int(input()) for _ in range(B)] + [10**12]
    for _ in range(Q):
        x = int(input())
        s = bisect_left(S, x)
        t = bisect_left(T, x)
        sl, sr = x - S[s - 1], S[s] - x
        tl, tr = x - T[t - 1], T[t] - x
        if sl < tl:
            m = min(tl, 2 * sl + tr)
        else:
            m = min(sl, 2 * tl + sr)
        if sr < tr:
            m = min(m, tr, 2 * sr + tl)
        else:
            m = min(m, sr, 2 * tr + sl)
        print(m)

main()


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

using namespace std;

const int P = 998244353;

long long power(long long x, long long t) {
	long long ret = 1;
	for(; t; t >>= 1, x = x * x % P) {
		if(t & 1) {
			ret = ret * x % P;
		}
	}
	return ret;
}

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

	int k = 3000001;

	vector<long long> fac(k);
	vector<long long> inv(k);

	fac[0] = 1;
	for(int i = 0; i + 1 < k; ++i) {
		fac[i + 1] = fac[i] * (i + 1) % P;
	}

	inv[k - 1] = power(fac[k - 1], P - 2);
	for(int i = k - 1; i >= 1; --i) {
		inv[i - 1] = inv[i] * i % P;
	}

	auto C = [&] (int n, int m) {
		if(n < m) {
			return 0LL;
		}
		return fac[n] * inv[m] % P * inv[n - m] % P;
	};

	long long ans = 0;
	for(int i = 0; i + i <= m; ++i) {
		if(m - 2 * i <= n) {
			int two = m + i;
			ans = (ans + C(two + n - 1, n - 1) * C(n, m - 2 * i) % P) % P;
		}
	}

	ans = (ans - C(m - 1 + n - 1, n - 1) * n % P + P) % P;

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 50240
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

int N, K;
double pro = 0;
double ans;

int main()
{
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		//iは最初にでた目
		int f = i;
		pro = (double)1 / N;
		//fがK以上とならない限りfに2をproに(1/2)をかけ続ける
		while (f <= K - 1) {
			f *= 2;
			pro *= (double)1 / 2;
		}
		ans += pro;
	}
	cout << fixed;
	cout << setprecision(11) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int ll;
ll dp[500][500];
ll n;
ll pre[500];
int main()
{
    scanf("%lld",&n);
    memset(dp,-1,sizeof(dp));
    for(int i = 1; i <= n ; i++)
    {
        ll a = 0;
        dp[i][i] = 0;
        scanf("%lld",&a);
        pre[i] = pre[i-1]+a;
    }
    //start dp
    for(int l = 1; l <n; l++)
        for(int i = 1; i+l <=n; i++)
        {
            int j = i+l;
            for(int k = i; k+1 <= j; k++)
            {
                ll temp = dp[i][k]+dp[k+1][j]+pre[j]-pre[i-1];
                if(dp[i][j] == -1)
                {
                    dp[i][j] = temp;
                }
                else dp[i][j] = min(dp[i][j],temp);
            }

        }

    printf("%lld\n",dp[1][n]);
}


Measured memory_bytes: 5768
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
vector<int> E[100050];
int n,k,ret;
ll dfs(int u,int pre,int num){
    ll ret = 1ll*num;
    num = k-1;
    if(pre != -1) num--;
    for(auto v : E[u]){
        if(pre == v) continue;
        (ret *=dfs(v,u,num))%= mod;
        num--;
    }
    return ret%mod;
}
int main(){
    cin>>n>>k;
    for(int i=0;i<n-1;++i){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    ll ans = dfs(0,-1,k);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 11520
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long countC = b / c - a / c + (a % c == 0 ? 1 : 0);
        long countD = b / d - a / d + (a % d == 0 ? 1 : 0);
        long cd = lcm(c, d);
        long countCD = b / cd - a / cd + (a % cd == 0 ? 1 : 0);
        System.out.println(b - a + 1 - countC - countD + countCD);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }


    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;

int n,x,m[100],cnt;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>x;
	cnt = n;
	for(int i=0;i<n;i++){
		cin>>m[i];
		x -= m[i];
	}
	sort(m, m+n);
	for(int i=0;i<n;i++){
		if(x < m[i])
			break;
		n += x / m[i];
		x %= m[i];
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n,m,k;
void solve()
{
    cin>>n>>m>>k;
    cout<<k/max(n,m)+(k%max(m,n)!=0);
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int test;cin>>test;while(test--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int n, x[101];
  scanf("%d", &n);
  rep(i, 0, n) scanf("%d", &x[i]);

  int ans = INF;
  rep(i, 1, 101) {
    int sum = 0;
    rep(j, 0, n) {
      sum += (i - x[j]) * (i - x[j]);
    }
    ans = min(ans, sum);
  }
  printf("%d\n", ans);
  return 0;
}


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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NM = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            int ans = 0;
            int edge = NM[0] + 1;
            Enumerable.Range(0, NM[1])
                .Select(i =>
                {
                    int[] ab = Console.ReadLine().Split().Select(j => Convert.ToInt32(j)).ToArray();
                    return new Tuple<int, int>(ab[0], ab[1]);
                })
                .OrderByDescending(i => i)
                .ToList()
                .ForEach(i => {
                    if (i.Item1 < edge && i.Item2 <= edge)
                    {
                        ans++;
                        edge = i.Item1;
                    }
                });
            Console.WriteLine(ans);
        }
    }

}


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

int main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> A(n);
  rep(i, m) cin >> A[i];
  rep(i, m-1){
    if(A[0]>x) {cout << 0 << endl; break;}
    else if(A[m-1]<x) {cout << 0 << endl; break;}
    else if(A[i]<x&&x<A[i+1]){
      if(m-i-1>i+1) cout << i+1 << endl;
      else cout << m-i-1 << endl;
      break;
    }
  }
}

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

int main() {
  int N, sum = 0;
  cin >> N;
  int N2 = N;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  if (N2 % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N, M= (int(i) for i in input().split())
lst = [[int(i) for i in input().split()] for i in range(N)]
import numpy as np
food = np.zeros((N,M))
for i in range(N):
    for j in range(lst[i][0]):
        #print(lst[i][j+1])
        food[i][lst[i][j+1]-1] = 1
#print(food)
s = np.sum(food, axis=0)
print(len(s[s==N]))

Measured memory_bytes: 12488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String p = scan.next();
		scan.close();
		int l1 = s.length();
		int l2 = p.length();
		char[] c = new char[l1];
		for(int i = 0; i < l1; i++) {
			c[i] = s.charAt(i);
		}
		for(int i = 0; i < l1; i++) {
			boolean flag = true;
			for(int j = 0; j < l2; j++) {
				int k = (i + j) % l1;
				if(c[k] != p.charAt(j)) {
					flag = false;
					break;
				}
			}
			if(flag) {
				System.out.println("Yes");
				System.exit(0);
			}
		}
		System.out.println("No");
	}
}


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" \
						  << " = " << a[i] << endl;
#define fastio                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define PI 3.141592654

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;

ll powmod(ll base, ll exp, const ll MOD){ll ans = 1;while (exp){	if (exp & 1)	ans = (ans * base) % MOD;base = (base * base) % MOD;exp >>= 1;}return ans;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
void add(ll &x, ll v)
{
	x = (x + v) % MOD;
	if (x < 0)
		x += MOD;
}
//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


const int mxN = 2e5 + 100;


void test_case() {
	

}

int main()
{
	fastio;
	int n;
	cin >> n;
	cout << ((n + 999) / 1000) * 1000 - n;
	return 0;
}

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

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

int main(){

    int n;
    cin>>n;
    vector<int> p(n),q(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        q[i]=i+1;
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            swap(p[i],p[j]);
            if(p==q){
                cout<<"YES"<<endl;
                return 0;
            }
            else swap(p[i],p[j]);
        }
    }

    cout<<"NO"<<endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  long n;
  cin >> n;
  long max_sqrt = sqrt(n);
  long a, b;
  for (int i = max_sqrt; i > 0; i--){
    
    if (n%i==0) {
      b = i;
      a = n/b;
      break;
    }
  }
  cout << std::to_string(a).length() << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in [0]*N]

A = [(0,0)]*N
B = [(0,0)]*N
for i,T in enumerate(S):
    m = 0
    M = 0
    tot = len(T) - T.count(")")*2
    if tot>=0:
        tot = 0
        for t in T:
            if t==")":
                tot -= 1
                m = min(m,tot)
            else:
                tot += 1
        A[i] = (m,tot)
    else:
        tot = 0
        for t in T[::-1]:
            if t==")":
                tot += 1
            else:
                tot -= 1
                m = min(m,tot)
        B[i] = (m,tot)

A.sort(reverse=True)
B.sort(reverse=True)

totA = 0
ans = True
for m,t in A:
    if totA + m < 0:
        ans = False
        break
    totA += t
totB = 0
if ans:
    for m,t in B:
        if totB + m < 0:
            ans = False
            break
        totB += t
    if totA != totB:
        ans = False

if ans:
    print("Yes")
else:
    print("No")

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

using namespace std;

int n;

int main()
{
    cin >> n;
    if(n == 25) puts("Christmas");
    else if(n == 24) puts("Christmas Eve");
    else if(n == 23) puts("Christmas Eve Eve");
    else if(n == 22) puts("Christmas Eve Eve Eve");
    return 0;
}


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

int main(){
  int n, k, q; cin >> n >> k >> q;
  vector<int> point(n, k-q);
  for(int i=0; i<q; i++){
    int x; cin >> x;
    point[x-1]++;
  }

  for(int i=0; i<n; i++){
    if(point[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	int L,N,x[30],w[30];
	scanf("%d",&L);
	scanf("%d",&N);
	for(int i = 0;i<N;i++){
		scanf("%d %d",&x[i],&w[i]);
		x[i] = x[i]*(-1);
	}
	printf("%d\n",N);
	for(int i = 0;i<N;i++){
		printf("%d %d\n",x[i],w[i]);
	}
	return 0;	
}

Measured memory_bytes: 2672
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String board = s.next();
        int n = board.length();
        char prev = board.charAt(0);
        int a = 0;
        for (int i = 1; i < n; i++) {
            char c = board.charAt(i);
            if (c != prev) {
                a ++;
            }
            prev = c;
        }
        System.out.println(a);

    }


}


Measured memory_bytes: 24392
#include<cstdio>
#include<cmath>

const int A = 1e9 + 7;
int n, k;
unsigned int l[100][40000];

int main() {
    scanf("%d %d", &n, &k);
    const int sqn = static_cast<int>(std::sqrt(n));
    for (int i = 1; i * i <= n; i++) {
        l[0][i] = i;
        l[1][i] = (n / i + l[1][i - 1]) % A;
    }
    for (int i = 2; i < k; i++) {
        l[i][sqn] = (l[i - 1][sqn]
                  + static_cast<long>(l[i - 2][sqn]) * (n / sqn - sqn)) % A;
        for (int j = sqn - 1; j > 0; j--) {
            l[i][j] = (l[i][j + 1]
                    + static_cast<long>(l[i - 2][j]) * (n / j - n / (j + 1))) % A;
        }
        for (int j = 2; j * j <= n; j++) {
            l[i][j] = (l[i][j] + l[i][j - 1]) % A;
        }
    }

    unsigned int sum = (l[k - 1][sqn]
                     + static_cast<long>(l[k - 2][sqn]) * (n / sqn - sqn)) % A;
    for (int j = sqn - 1; j > 0; j--) {
        sum = (sum + static_cast<long>(l[k - 2][j]) * (n / j - n / (j + 1))) % A;
    }

    printf("%u\n", sum);
    return 0;
}


Measured memory_bytes: 15232
// https://atcoder.jp/contests/dp/tasks/dp_d
// https://atcoder.jp/contests/dp/tasks/dp_e
#include <bits/stdc++.h>
#define int             long long
#define ld              long double
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(int i=1;i<=n;i++)
#define fok(i,k,n)      for(int i=k;i<=n;i++)
#define rfo(i,n)        for(int i=n;i>=0;i--)
#define rfo1(i,n)       for(int i=n-1;i>=0;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcount(x)
#define zerobits(x)     __builtin_ctz(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define endl            '\n'
#define mod             1000000007
#define M               (int)1e6+6
#define inf             1e18
using namespace std;

int n,m,k,x,y,z,a1,b,c,d,i,j,l,r;
int val[105],wt[105];


void knapsack1(int w)
{
    int dp[n+1][w+1];//max val considering wight upto i having knapsack of size j
    
    for(int i=0;i<=n;i++) 
    {
        for(int j=0;j<=w;j++)
        { if(i==0 || j==0)dp[i][j]=0; 
          else if(wt[i-1]>j)dp[i][j]=dp[i-1][j];//no way to take current weight
          else dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);//either choose or not
        }
    }
    
    cout<<dp[n][w]<<endl;


}

void knapsack2(int w)
{
    int sum=0;
    fo(i,n)sum+=val[i];
    int dp[n+1][sum+1];//minmum weight required to get value v

    fo(i,n+1)fo(j,sum+1){if(j==0)dp[i][j]=0;else dp[i][j]=inf;}


    fo1(i,n)
    {
        fo1(j,sum)
        {
            if(val[i-1]>j)dp[i][j]=dp[i-1][j];//no way to include
            else  dp[i][j]=min(wt[i-1]+dp[i-1][j-val[i-1]],dp[i-1][j]);
            
            
        }
    }
   
    int mx;
    rfo(i,sum)
    {
        if(dp[n][i]<=w){mx=i;break;}
    }
    cout<<mx<<endl;
}







void sol()
{   int w;
    cin>>n>>w;
    fo(i,n)cin>>wt[i]>>val[i];

    
    // knapsack1(w);
    knapsack2(w);
    
    // cout<<  <<endl;
}





int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // w(t)
    sol();
    return 0;
}



Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double ans=0;
    double a;
    for(int i=0;i<n;i++){
        cin>>a;
        ans+=1/a;
    }
    doublecout(1/ans);
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

const int MX=200005;
ll a[MX],b[MX];

int main()
{
    ll k;
    int n,m,x=0,y=0;
    scanf("%d %d %lld",&n,&m,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(i) a[i]+=a[i-1];
        if(a[i]<=k) x=i+1;
    }
    for(int i=0;i<m;i++){
        scanf("%lld",&b[i]);
        if(i) b[i]+=b[i-1];
        if(b[i]<=k) y=i+1;
    }
    int mx=max(x,y);
    for(int i=0;i<x;i++){
        int j=upper_bound(b,b+m,k-a[i])-b;
        mx=max(mx,i+1+j);
    }
    for(int i=0;i<y;i++){
        int j=upper_bound(a,a+n,k-b[i])-a;
        mx=max(mx,i+1+j);
    }
    printf("%d\n",mx);
    return 0;
}

Measured memory_bytes: 6944
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <string>
#include <stdlib.h>
#include <utility>
 
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i = a;i<=b;i++)
#define ll long long int
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define iii pair<ii,int >
#define ff first
#define ss second
#define vi vector<int>
#define vc vector<char>
 
using namespace std;

vi g[300000];
int dp[300000];

void solve(int node){
	if(dp[node] != -1)return ;
	int mx = 0;
	FOR(i,g[node].size()){
		int child =g[node][i];
		solve(child);
		mx = max(mx,dp[child]);
	}
	dp[node] = 1+mx;
}

int main(){
	int N,M;cin >> N >> M;
	int indeg[N];
	FOR(i,N)dp[i] = -1;
	FOR(i,M){
		int a,b;
		cin >> a >> b;
		a--;b--;
		indeg[b]++;
		g[a].pb(b);
	}
	FOR(i,N)solve(i);
	int mx = 0;FOR(i,N)mx = max(mx,dp[i]);//,cout << dp[i] << endl;;
	cout << mx-1 << endl;

	return 0;
}


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

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

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int ans[N];

int main() {
  int n, x;
  cin >> n;
  for(int i = 0; i < n - 1; i++){
    cin >> x; ans[x]++;
  }
  for(int i = 1; i <= n; i++)printf("%d\n", ans[i]);
  return 0;
}

Measured memory_bytes: 4548
import java.util.*;

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

        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] X = new int[N][D];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    }

    static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    }
}


Measured memory_bytes: 23636
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def ans(i):
    if i % 2 == 0:
        return s-sre[int((n-i-1)/2)]*2-slo[int(i/2)]*2
    return s-sro[int((n-i)/2)]*2-sle[int((i-1)/2)]*2


n = int(input())
a = list(map(int, input().split()))

s = sum(a)
sle = [0]
sre = [0]
slo = [0]
sro = [0]
for i in range(n):
    if i % 2 == 0:
        slo.append(slo[-1]+a[i])
        sro.append(sro[-1]+a[-i-1])
    else:
        sle.append(sle[-1]+a[i])
        sre.append(sre[-1]+a[-i-1])
print(' '.join(map(str, [ans(i) for i in range(n)])))


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

using namespace std;

int main()
{
  long long N;
  
  scanf("%lld", &N);
  
  int ans = 1000000;
  
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      int digit = 0;
      int tmp = N / i;
      while (tmp) {
        digit++;
        tmp /= 10;
      }
      ans = digit;
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll s[210000], ans = 0, n, m;
int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		s[a]++;
		s[b + 1]--;
	}
	REP(i, 200000)s[i + 1] += s[i];
	REP(i, 200000) {
		if (s[i] == m)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){

	int i;
	int height[10];

    for(i = 0; i < 10; i++)
    {
    	scanf("%d",&height[i]);
    }
    
	s_sort(height);

    for(i = 0; i < 3; i++)
    {
    	printf("%d\n",height[i]);
    }

    return 0;
}

int s_sort(int *height)
{
	int i;
	int temp, flag;
	 
	do{
	    flag = 0;
	    for(i = 0; i < 9; i++){
	        if(*(height+i) < *(height+i + 1)){
	            flag = 1;
	            temp = *(height+i + 1);
	            *(height +i + 1) = *(height+i);
	            *(height +i) = temp;
	        }
	    }
	}while(flag);

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int a=0,b=0;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='g'&&a)a--,b++;else if(s[i]=='g')a++;
		if(s[i]=='p'&&a)a--;else if(s[i]=='p')a++,b--;
	}
	cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	int res = 0;
	rep(i, n) {
		if (s[i] == 'I')res++;
		else res--;
		ans = max(res, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{
    for(int i = 0; i<N2;i++){
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};

bool isTarget(Puzzle p){
  for(int i = 0; i<N2;i++){
    if(p.f[i] != (i+1)) return false;
  }
    return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while(!Q.empty()){
    u = Q.front();
    Q.pop();
    if(isTarget(u)) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for(int r = 0; r<4;r++){
      int tx = sx+dx[r];
      int ty = sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N) continue;
      v = u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space = tx*N+ty;
      if(!V[v]){
	V[v] = true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;

  for(int i = 0; i<N2;i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout<<ans.size()<<endl;

  return 0;
}



Measured memory_bytes: 30556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll n;
  cin >> n;
  mat a(n,vec(3));
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<3;j++) {
      cin >> a[i][j];
    }
  }
  mat dp(n+1,vec(3));
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<3;j++) {
      for(ll k=0;k<3;k++) {
        if(j==k) continue;
        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<string>

using namespace std;

int main(){

	string s,p; //入力文字列
	getline(cin,s);
	int count = 0;
	while(true){
		getline(cin,p);
		if(p == "END_OF_TEXT")
			break;

		string box;
		int element = 0;
		for(int i =0;i <= p.length() ;i++){
			if((p[i] == ' ')||(p.length() == i)){
				//cout << box << endl;
				if(box == s)
					count++;
				element = 0;
				box = "";
			}else{
				if((p[i] >='A')&&(p[i] <= 'Z'))
					p[i] -= 'A'-'a';
				box += p[i];
				element++;
			}

		}

	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3152
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

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();
}

//change
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;
}

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

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

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

//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 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())

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

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    if (s == "Rainy")
    {
        cout << "Sunny" << endl;
    }
}


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

int main(){
  int n;
  float x;
  float suum = 0;
  string u;
  
  cin >> n;
  
  for(n; n > 0; n--){
    cin >> x >> u;
    
    if(u == "JPY"){
      suum += x;
    }
    else{
      suum += 380000.0 * x;
    }
  }
  cout << suum << endl;
}

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

int main()
{
	int  N,b, sum = 0, a = 100000000;

	cin >> N;

	b = N;
	while (a >= 1) {
		sum += b / a;
		b %= a;
		a /= 10;
	}

	if (N%sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

static class NagataKanaIsAGenius {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int L=Query(0);
        int R=L;
        int l=0,r=n;
        while(true){
            int c=((l+r)/2);
            int C=Query(c);
            if(((c-l)%2==0)^(C!=L)){l=c;L=C;}
            else {r=c;R=C;}
        }
    }
    static int Query(int x){
        Console.WriteLine(x);
        char c = Console.ReadLine()[0];
        if(c=='V')Environment.Exit(0);
        if(c=='M')return 0;
        if(c=='F')return 1;
        throw new NotImplementedException();
    }
}


Measured memory_bytes: 13512
from sys import stdin

n = stdin.readline().rstrip()
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort(reverse=True)

N=M=0

for i in range(0,len(A),2):
    N = N + A[i]

for i in range(1, len(A), 2):
    M = M + A[i]

print (N-M)







Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int A[3];
    int i,ans;
    for(i=0;i<3;i++){
    cin>>A[i];
    }
    sort(A,A+3);
    ans=A[2]-A[0];
    cout<<ans<<endl;
  return 0;  
}


Measured memory_bytes: 256
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/14
# Filename: main 
# Author: acto_mini

def main():
    N = int(input())
    A = list()
    A.append(list(map(int, input().split())))
    A.append(list(map(int, input().split())))

    ans = 0
    for i in range(N):
        p = 0
        k = 0
        for j in range(N):
            p += A[k][j]
            if i == j:
                k = 1
                p += A[k][j]
        ans = max(p, ans)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768
n, w = map(int, input().split())
lis = [[0, 0]]
for i in  range(n):
    lis.append(list(map(int, input().split())))

dp = [[0 for i in range(w+1)] for i in range(n+1)]
#print(dp)
#print(lis)

for i in range(1, n+1):
    for j in range(w+1):
        if j - lis[i][0] < 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-lis[i][0]] + lis[i][1])
print(dp[n][w])

Measured memory_bytes: 173448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n;
  cin >>n;
  vector<int>h(n);
  rep(i,n)cin>>h[i];
  int takasa=h[0];
  int kotae=1;
  for(int i=1;i<n;i++){
    if(takasa<=h[i]&&h[i]>=h[i-1])kotae++;
    takasa=max(takasa,h[i]);
  } 
  cout<<kotae<<endl;
  return 0;
}
  

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int min = a[0], max = a[0];
    for (int i = 0; i < n; i++)
    {
        if (min > a[i])
        {
            min = a[i];
        }
        if (max < a[i])
        {
            max = a[i];
        }
    }
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 3564