akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=2e5+7;
int st[maxn],num[maxn];
int main()
{
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=0,L=1,R=n;
	auto check=[&](int x){
		int top=0;
		num[0]=0;
		int pre=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]>pre)
			{
				pre=a[i];
				continue;
			}
			if(!top)
			{
				st[++top]=a[i];
				num[top]=1;
			}
			else{
				if(x==1) return false;
				while(top&&st[top]>a[i]) top--;
				if(top&&st[top]==a[i])
				{
					++num[top];
					while(top&&num[top]==x)
					{
						int nxt=st[top]-1;
						top--;
						if(st[top]==nxt) ++num[top];
						else st[++top]=nxt,num[top]=1;
					}
				}
				else{
					st[++top]=a[i],num[top]=1;
				}
			}
			//dbg(x,i,top,st[top],num[top]);
			pre=a[i];
		}
		return num[0]==0;
	};
	while(L<=R)
	{
		int mid=L+R>>1;
		if(check(mid))
		{
			R=mid-1;
			ans=mid;
		}
		else L=mid+1;
	}
	print(ans);
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=200005;
int n,k;
int p[maxn],nxt[maxn],prv[maxn];
bool same;
set<int>s;
set<pii>ans;

int main(){
	scanf("%d%d",&n,&k);
	int pt=0;
	REP(i,n){
		scanf("%d",&p[i]);
		s.insert(p[i]);
		if(i-k>=1&&s.count(p[i-k]))s.erase(s.find(p[i-k]));
		int b=max(i-k+1,1);
		pt=max(pt,b-1);
		while(pt>=b&&p[i]<p[pt]){
			s.insert(p[pt]);
			pt--;
		}
		while(pt+1<=i&&p[pt+1]==*s.begin()){
			s.erase(s.begin());
			pt++;
		}
		nxt[b]=pt-b+1;
	}
	s.clear();
	pt=n+1;
	for(int i=n;i>=1;i--){
		s.insert(p[i]);
		if(i+k<=n&&s.count(p[i+k]))s.erase(s.find(p[i+k]));
		int e=min(i+k-1,n);
		pt=min(pt,e+1);
		while(pt<=e&&p[pt]<p[i]){
			s.insert(p[pt]);
			pt++;
		}
		while(pt-1>=i&&p[pt-1]==*s.rbegin()){
			s.erase(s.find(p[pt-1]));
			pt--;
		}
		prv[e]=e-pt+1;
	}
	pt=n;
	REP(i,n-k+1){
		if(nxt[i]==k)same=true;
		else ans.insert(mp(i+nxt[i],i+k-1-prv[i+k-1]));
	}
	printf("%d\n",int(ans.size())+same);
	return 0;
}

Measured memory_bytes: 11904
row, col = list(map(int, input().split()))
rc = []

for i in range(row):
    tmp_r = list(map(int, input().split()))
    tmp_sum = sum(tmp_r)
    rc.append(tmp_r)
    rc[i].append(tmp_sum)

new_row = []
for c in range(col+1):
    tmp = 0
    for r in range(row):
        tmp += rc[r][c]
    new_row.append(tmp)

rc.append(new_row)

for row_list in rc:
    for i, e in enumerate(row_list):
        if i == len(row_list)-1:
            print(e)
        else:
            print(e, end=" ")



Measured memory_bytes: 6196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

ll mod=1000000007;
int main() {
	ll x,y;
	cin >> x >> y;
	if((x+y)%3!=0){
		cout << 0 << endl;
		return 0;
	}
	ll a,b;
	a=(2*x-y)/3;
	b=(2*y-x)/3;
	if(a<0||b<0){
		cout << 0 << endl;
		return 0;
	}
	ll res=1;
	for(ll i=a+b;i>=b+1;i--){
		res=res*i%mod;
	}
	for(ll i=a;i>=1;i--){
		res=res*modinv(i,mod)%mod;
	}
	cout << res%mod << endl;
}


Measured memory_bytes: 3624
from fractions import gcd


def lcm(a, b):
    return a * b // gcd(a, b)


MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))


_lcm = 1
for a in A:
    _lcm = lcm(_lcm, a)

ans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD

print(int(ans % MOD))


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

//---------------------------------------------------------------

int main(){
  int N,Muki;
  Muki = 1;
  cin>>N;

    vector<ll> A(N);
  int strt = (N%2==0 ? N/2 : N/2);

  rep(i,N){
    ll B;
    cin>>B;
    if(Muki == 1){
      A.at(strt+i/2)=B;
    }else{
      A.at(strt-i/2-1)=B;
    }
    Muki = abs(Muki-1);
  }

  rep(i,N){
    if(Muki==1)cout<<A.at(i)<<" ";
    else cout<<A.at(N-i-1)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;


int main() {

	ll N, C, K;

	cin >> N >> C >> K;

	vector<ll>T(N);

	rep(i, N) {
		cin >> T[i];
	}

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


	ll D, P = 0, count = 0;

	rep(i, N) {
		P++;
		if (i == 0) {
			D = T[i] + K;
		}

		if (P >= C || T[i] > D) {
			count++;
			P = 0;
			D = T[i] + K;
		}
		if (i == N - 1) {
			count++;
		}

	}
	count = min(N, count);

	cout << count;

	return 0;
}


Measured memory_bytes: 4056
n = io.read("*n")
m = io.read("*n")
x = io.read("*n")
y = io.read("*n")
local a = nil
for i = 1, n do
	xx = io.read("*n")
	if not a or xx > a then
		a = xx
	end
end
local b = nil
for i = 1, m do
	xx = io.read("*n")
	if not b or xx < b then
		b = xx
	end
end
local war = "War"
for i = x+1, y do
	if i > a and i <= b then
		war = "No War"
	end
end
print(war)


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    ll a, b, n;
	cin >> a >> b >> n;
	ll mx = 0;
	
	ll up = min(b-1, n);
    ll ans = (up*a)/b - a*(up/b);
    
    cout << ans << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int A[100000];
int dp[100000];

int k;

int f(int i) {
  if(dp[i] != -1) return dp[i];
  int mx = 2e9;
  for(int j = 1; j <= k && i - j >= 0; ++j)
    mx = min(mx, abs(A[i] - A[i - j]) + f(i - j));
  return dp[i] = mx;
}

int main() {
  int n; cin >> n >> k;
  for(int i = 0; i < n; ++i)
    cin >> A[i];
  memset(dp, -1, sizeof dp);
  dp[0] = 0;
  cout << f(n - 1);
  return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,minn=1000000,res,k=0;
	cin>>n>>res;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		res-=x;
		k++;
		if(x<minn) minn=x;
	}
	k=k+res/minn;
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if ((b + c) == a) {
		puts("Yes");
		return 0;
	}
	if ((a + c) == b) {
		puts("Yes");
		return 0;
	}
	if ((a + b) == c) {
		puts("Yes");
		return 0;
	}
	else puts("No");
}

Measured memory_bytes: 128
n = int(input())
s = input()

ans = 0

for i in range(100):
    num = str(i).zfill(2)
    k = 0
    for j in range(len(s)):
        if num[k] == s[j]:
            k += 1
        if k == 2:
            ans += len(set(s[j+1:]))
            break

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,tmp,s2,ans;
vector<ll>s1;
set<ll>s;
inline bool isPrime(ll n)
{
    if(n<=1) return 0;
    if(n==2||n==3) return 1;
    if(n%6!=5&&n%6!=1) return 0;
    tmp=sqrt(n);
    for(int i=5;i<=tmp;i++) if(n%i==0||n%(i+2)==0) return 0;
    return 1;
}
int main()
{
    cin>>a>>b;
    tmp=sqrt(a);
    for(int i=1;i<=tmp;i++)
    {
        if(a%i==0)
        {
            s.insert(i);
            s.insert(a/i);
        }
    }
    tmp=sqrt(b);
    for(int i=1;i<=tmp;i++){
        if(!(b%i)){
            if(s.find(i)!=s.end()) s1.push_back(i);
            if(s.find(b/i)!=s.end()) s1.push_back(b/i);
        }
    }
    s2=s1.size();
    for(int i=0;i<s2;i++) if(isPrime(s1[i])) ++ans;
    cout<<ans+1;
}


Measured memory_bytes: 640
'''ika tako
bit桁ごとに考える。「XORを取り、その後足し算」という計算過程では
他の桁が影響することはないので、桁毎に独立に考えて問題ない。
N = 5
A = {   1   2   3   4   5 }   ↓
    { 001 010 011 100 101 }
たとえば2桁目を取り出すと
       0   1   1   0   0
各ペアでXORを取ると、(0,1)は'1'となり、(0,0)(1,1)は'0'となる。 
0はいくら足しても0なので、(0,1)の数だけわかれば良い。
それは、(0の個数)×(1の個数)で計算できる。
    0が3個、1が2個
→  XORを取ったとき、2桁目について'1'が立っているペア
　　　　　　　　　　　=合計に足される回数は 3x2=6
→  2進数の2桁目は2を表すので、合計に足される値は6x2=12
これを各桁について足し合わせる。
'''
n = int(input())
aaa = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
ans = 0
m = 1
for i in range(60):#上限は2＾60なので、60が上限
    bit = sum(a & m for a in aaa)#ｍは何番目のビットが立っているか
    #bit //= m こっちが原文、下の行は、下のプルグラムに合わせたみた
    bit >>= i
    non_bit = n - bit
    ans = (ans + bit * non_bit * m) % MOD
    #ｍは上記、2桁目を表す2と同様
    m <<= 1#ビットを１つずつ左シフト
print(ans)

'''
結局この計算は Ai のすべての組み合わせ(Ai 自身同士は含まない)の 
XOR の合計なので、Ai のあるビットの立っている数の合計を c とすると、
Ai のあるビットが0であった場合により計算結果に立つビットの数は 
c、Ai のあるビットが1であった場合により計算結果に立つビットの数は 
N - c になるので、あるビットに関する計算結果は c * (N -c) の
ビットシフトした値になる. 結果として以下の計算で解ける.

N = int(input())
A = list(map(int, input().split()))
 
result = 0
for bit in range(60):
    m = 1 << bit　すべてのビットを調べる
    c = sum(a & m for a in A) >> bit　
    ビット分、戻して、その桁に立っているビット数を算出
    result += (c * (N - c)) << bit　
    ビット分（上記の2桁目の2）調整、イメージとしては2のべき乗倍
    result %= 1000000007
print(result)
'''

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

int
main
(
  int argc,
  char ** argv
)
{
  std::size_t n;
  std::cin >> n;

  std::size_t maxCakes { n / 4 };
  std::size_t maxDonuts { n / 7 };

  for
  (
    std::size_t numCakes { 0 };
    numCakes <= maxCakes;
    ++numCakes
  )
  {
    const std::size_t nRest { n - 4 * numCakes };
    if (nRest == 0) {
      goto yes;
    }

    for
    (
      std::size_t costDonuts { 0 };
      costDonuts <= nRest;
      costDonuts += 7
    )
    {
      if (costDonuts == nRest) {
        goto yes;
      }
    }
  }

no:
  std::cout << "No" << std::endl;
  return 0;

yes:
  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define modulo 1000000007
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

ll fact(ll n){
	if(n==0) return 1;
	return n * fact(n-1);
}

ll Comb(ll n, ll k){
	ll a = fact(n);
	ll b = fact(n-k) * fact(k);
	return a / b;
}

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,0,n) cin >> s[i];

	for(int i=0; i<n; i++){
		sort(s[i].begin(), s[i].end());
	}

	set<string> se;
	multiset<string> ms;
	for(int i=0; i<n; i++){
		se.insert(s[i]);
		ms.insert(s[i]);
	}

	ll ans(0);
	auto itr = se.begin();
	for(int i=0; i<se.size(); i++){
		ll num = ms.count(*itr);
		if(num > 1) ans += num*(num-1)/2;
		itr ++;
	}

	cout << ans << endl;
	return 0;
}


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

int main(){
    int x;
    cin >> x;
    if(400 <= x && x <= 599 ) cout << 8 << endl;
    else if(600 <= x && x <= 799 ) cout << 7 << endl;
    else if(800 <= x && x <= 999 ) cout << 6 << endl;
    else if(1000 <= x && x <= 1199 ) cout << 5 << endl;
    else if(1200 <= x && x <= 1399 ) cout << 4 << endl;
    else if(1400 <= x && x <= 1599 ) cout << 3 << endl;
    else if(1600 <= x && x <= 1799 ) cout << 2 << endl;
    else if(1800 <= x && x <= 1999 ) cout << 1 << endl;
}

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

using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7;
int dp[N];

int mul(int a, int b) {return 1ll * a * b % MOD;}
int sum(int a, int b) {return (a + b) % MOD;}
int Pow(int a, int b) {
    int res = 1;
    for (; b; b>>=1, a = mul(a, a)) if (b&1) res = mul(res, a);
    return res;
}
void calc(int n) {
    for (int i = 2; i <= n;) {
        int j = n / (n / i) + 1;
        dp[n] = sum(dp[n], MOD - mul(dp[n/i], j - i));
        i = j;
    }
    return ;
}
int main() {
    int n, k; cin >> n >> k;
    for (int i = 1; i <= k; i++) {
        dp[i] = Pow(i, n);
        calc(i);
    }
    int ans = 0;
    for (int i = 1; i <= k; i++) ans = sum(ans, mul(i, dp[k/i]));
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 4024
n = int(input())
num_list = list(map(int,input().split()))
min_diff = 10 ** 18
sum_list = sum(num_list)
count = 0
for i in range(n):
    count += num_list[i]
    diffs = abs(count*2 - sum_list)
    if min_diff < diffs:
        print(min_diff)
        exit()
    else:
        min_diff = diffs


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

using namespace std;

int main()
{
//    freopen("TEST.INP", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    string n;
    cin >> n;
    if (n[2] == n[3] && n[4] == n[5]) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17

x, y, a, b, c = map(int, input().split())
array_a = list(map(int, input().split()))
array_b = list(map(int, input().split()))
array_c = list(map(int, input().split()))
array_a = sorted(array_a, reverse=True)[:x]
array_b = sorted(array_b, reverse=True)[:y]
ans = sum(sorted(array_a + array_b + array_c, reverse=True)[:x + y])
print(ans)


Measured memory_bytes: 103020
n,k,q =map(int, input().split())
a = [int(input()) for _ in range(q)]
score = [k-q]*n
for i in range(q):
    temp = a[i]-1
    score[temp] =  score[temp] + 1
for i in range(n):
    if score[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 10448
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// 入力値
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i=0;i<n;i++){
			p[i] = sc.nextInt();
		}
		sc.close();
		int r = n;
		int max = p[0];
		for(int i=0;i<n;i++){
			if(max<p[i]){
				r--;
			}else{
				max = p[i];
			}
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 65164
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = 0;
  	int M = 0;
	N = sc.nextInt();
	M = sc.nextInt();
	
  
  	if(M == N){
		System.out.println("Yes");
    }else{
	 	System.out.println("No");
    }
  
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            return 0;
        }
        vector<string> s(n);
        vector<int> m(n);
        vector<vector<int>> d(n);
        for (int i = 0; i < n; i++)
        {
            cin >> s[i] >> m[i];
            for (int j = 0; j < m[i]; j++)
            {
                int tmp;
                cin >> tmp;
                d[i].push_back(tmp);
            }
        }
        vector<int> p(n, 0);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m[i]; j++)
            {
                int num = d[i][j];
                int pt = n;
                for (int k = 0; k < n; k++)
                {
                    if (k == i)
                    {
                        continue;
                    }
                    for (int dd : d[k])
                    {
                        if (dd == num)
                        {
                            pt--;
                        }
                    }
                }
                if (pt == 0)
                {
                    pt++;
                }
                p[i] += pt;
            }
        }
        vector<pair<int, string>> ans(n);
        for (int i = 0; i < n; i++)
        {
            ans[i] = make_pair(p[i], s[i]);
        }
        sort(ALL(ans));
        cout << ans[0].first << ' ' << ans[0].second << endl;
    }
}


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

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, K;
  cin >> N >> K;

  vector<int> Knum(60, 0);
  int j = 0;
  int64_t K0 = K;
  while (K0) {
    if (K0 % 2) Knum[j]++;
    K0 /= 2;
    ++j;
  }

  vector<int64_t> A(N);
  vector<int64_t> Anum(60, 0);
  rep(i, N) {
    int64_t a;
    cin >> a;
    A[i] = a;
    int j = 0;
    while (a) {
      if (a % 2) Anum[j]++;
      a /= 2;
      ++j;
    }
  }

  int64_t answer = 0;
  rep(i, N) { answer += (K ^ A[i]); }
  for (int d = 60; d >= 0; --d) {
    if (Knum[d] == 0) continue;
    int64_t X = 0;
    for (int i = 60; i >= 0; --i) {
      if (d < i) {
        if (Knum[i] == 1) X |= (1LL << i);
      } else if (i < d) {
        if (Anum[i] <= (N - Anum[i])) X |= (1LL << i);
      }  // in case of i == d, forcing set to 0 to make carry.
    }
    int64_t tmp_ans = 0;
    rep(i, N) { tmp_ans += (X ^ A[i]); }
    answer = max(answer, tmp_ans);
  }
  cout << answer << endl;
  return 0;
}


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

int main(){
	char board[3][4];
	int i;
	char w;
	while(true){
		w='0';
		for(i=0;i<3;i++){
			cin>>board[i];
			if(board[i][0] == '0' && board[i][1] == '\0'){
				break;
			}
		}
		if(i<3) break;
		for(i=0;i<3;i++){
			if(board[i][0]==board[i][1] && board[i][0]==board[i][2] && board[i][0] != '+'){
				w=board[i][0];
				break;
			}
		}
		for(i=0;i<3;i++){
			if(board[0][i]==board[1][i] && board[0][i]==board[2][i] && board[0][i] != '+'){
				w=board[0][i];
				break;
			}
		}
		if(board[0][0] == board[1][1] && board[0][0] == board[2][2] && board[0][0] != '+'){
			w=board[0][0];
		}
		if(board[0][2] == board[1][1] && board[0][2] == board[2][0] && board[0][2] != '+'){
			w=board[0][2];
		}
		switch(w){
			case '0': cout << "NA\n"; break;
			case 'b': cout << "b\n"; break;
			case 'w': cout << "w\n"; break;
		}
	}
	return 0;
}

Measured memory_bytes: 1100
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args){
     Scanner scanner = new Scanner(System.in);
     int n = scanner.nextInt();
     int m = scanner.nextInt();

     int[][] A = new int[n][m];
     int[] B = new int[m];

     for(int i=0;i<n;i++){
       for(int j=0;j<m;j++){
         A[i][j] = scanner.nextInt();
       }
     }

     for(int i=0;i<m;i++){
       B[i] = scanner.nextInt();
     }


     for(int i=0;i<n;i++){
       int sum = 0;
       for(int j=0;j<m;j++){
         sum = sum + (A[i][j]*B[j]);
       }
       System.out.println(sum);
     }
  }
}



Measured memory_bytes: 40776
import java.util.Scanner;

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

        int[] a = new int[n];
        double total = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            total += 1.0 / a[i];
        }

        System.out.println(1 / total);
    }
}


Measured memory_bytes: 23764
#include<cstdio>
const int mod=998244353;
char str[2][100010];
int fac[100010],ifac[100010],S[100010];
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
int main(){
	scanf("%s%s",str[0],str[1]);
	int A=0,B=0;
	for(int i=0;str[0][i];i++)if(str[0][i]=='1'){
		if(str[1][i]=='1')A++;
		else B++;
	}
	for(int i=*fac=1;i<=A+B;i++)fac[i]=fac[i-1]*1ll*i%mod;
	ifac[A+B]=inv(fac[A+B]);
	for(int i=A+B;i;i--)ifac[i-1]=ifac[i]*1ll*i%mod;
	int s=0;
	for(int i=0;i<=A+B;i++){
		for(int j=i<B?i:B;j;j--)S[j]=(S[j-1]+1ll*S[j]*j)%mod;
		S[0]=!i;
		if(i>=B)s=(s+1ll*S[B]*ifac[i])%mod;
	}
	s=1ll*s*fac[A]%mod*fac[A+B]%mod*fac[B]%mod*fac[B]%mod;
	printf("%d\n",s);
}

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

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

Measured memory_bytes: 256
// バイナリハックイージー
#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    vector<char> v;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='B' && v.size()!=0){
            v.pop_back();
        }
        else if(s[i]!='B'){
            v.push_back(s[i]);
        }
    }
    for(int i=0;i<v.size(); i++){
        cout << v[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3552
// D - Menagerie
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; string S; cin>>N>>S;
	S += S[0];
	vector<bool> a(N+2);
	for(int j=0; j<4; j++){
		a[0] = j/2; a[1] = j%2;
		for(int k=2; k<N+2; k++)
			a[k] = a[k-1] && S[k-1]=='o' || !a[k-1] && S[k-1]=='x'? a[k-2]: !a[k-2];
		if(a[0]==a[N] && a[1]==a[N+1]) break;
	}
	if(a[0]!=a[N] || a[1]!=a[N+1]) cout<<"-1";
	else for(int i=0; i<N; i++) cout<<(a[i]?'S':'W');
	cout<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef pair<double,double> pdd;

void make(pdd s,pdd t,int k)
{
	if(k==0) 
	{
		printf("%.8f %.8f\n",s.x,s.y);
		return ;
	}
	pdd a,b,c;
	a.x=(s.x*2+t.x)/3;a.y=(s.y*2+t.y)/3;
	c.x=(t.x*2+s.x)/3;c.y=(t.y*2+s.y)/3;
	b.x=(s.x+t.x)/2-(t.y-s.y)/(2*sqrt(3));b.y=(s.y+t.y)/2+(t.x-s.x)/(2*sqrt(3));
	make(s,a,k-1);
	make(a,b,k-1);
	make(b,c,k-1);
	make(c,t,k-1);
}

int main()
{
	int n;
	scanf("%d",&n);
	pdd s(0,0),t(100,0);
	make(s,t,n);
	printf("%.8f %.8f\n",100.0,0.0);
}

Measured memory_bytes: 3172
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int h,m,s,a,b;
		String ans[]=new String[3];
		String ans2[]=new String[3];
		while(true){
			h=sc.nextInt();
			m=sc.nextInt();
			s=sc.nextInt();
			if(h==-1 && m==-1 && s==-1) break;
			a=h*3600+m*60+s;
			a=120*60-a;
			b=a*3;

			if(a/3600==0)
				ans[0]="00";
			else if(a/3600<10)
				ans[0]="0"+Integer.toString(a/3600);
			else
				ans[0]=Integer.toString(a/3600);
			a=a%3600;

			if(b/3600==0)
				ans2[0]="00";
			else if(b/3600<10)
				ans2[0]="0"+Integer.toString(b/3600);
			else
				ans2[0]=Integer.toString(b/3600);
			b=b%3600;

			if(a/60==0)
				ans[1]="00";
			else if(a/60<10)
				ans[1]="0"+Integer.toString(a/60);
			else
				ans[1]=Integer.toString(a/60);
			a=a%60;

			if(b/60==0)
				ans2[1]="00";
			else if(b/60<10)
				ans2[1]="0"+Integer.toString(b/60);
			else
				ans2[1]=Integer.toString(b/60);
			b=b%60;

			if(a==0)
				ans[2]="00";
			else if(a<10)
				ans[2]="0"+Integer.toString(a);
			else
				ans[2]=Integer.toString(a);

			if(b==0)
				ans2[2]="00";
			else if(b<10)
				ans2[2]="0"+Integer.toString(b);
			else
				ans2[2]=Integer.toString(b);

			System.out.printf("%s:%s:%s\n",ans[0],ans[1],ans[2]);
			System.out.printf("%s:%s:%s\n",ans2[0],ans2[1],ans2[2]);
		}
	}
}

Measured memory_bytes: 12000
# -*- coding: utf-8 -*-
# C - Scc Puzzle
# 標準入力の取得
N,M = list(map(int, input().split()))

# 求解
if N >= M//2:
    # cc⇒Sを行わず、"Scc"を作成した際に、Sがちょうどまたは余る
    print(M//2)
else:
    # cc⇒Sを行わず、"Scc"を作成した際に、cが余る
    print(N + (M-2*N)//4)

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        int ret = n;
        for(int i=1; i<n-1; ++i){
            int m = min(i, n-1-i);
            int x = 1;
            for(int i=0; i<m; ++i){
                ret += 2 * x;
                x *= 3;
            }
        }

        cout << ret << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  regex re("A?KIHA?BA?RA?");

  if (regex_match(s, re))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

}


Measured memory_bytes: 256
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,w,x,y,z,a[200040];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(12);
	cin>>w>>x>>y>>z>>k;
	w=w*60+x;
	y=y*60+z;
	cout<<y-w-k;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef std::numeric_limits<double> dbl;
double x,res;
//double d = 3.14159265358979;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>x;
    //cout.precision(dbl::max_digits10);
    cout<<(double)x*3.14*2;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char s[110];
int cnt[110];
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%s", s);
        for (int j = 0; j < m; ++j) ++cnt[s[j]-'a'];
    }
    int t2=0, t4=0;
    for (int i = 0; i < 26; ++i) {
        t4 += cnt[i]/4, t2 += cnt[i]%4/2;
    }
//    printf("%d %d\n", t2, t4);
    if (!(n&1) && !(m&1)) {
        if (t4 >= n*m/4) printf("Yes\n");
        else printf("No\n");
    }
    else if (n&1 && m&1) {
        if (t4 >= (n-1)*(m-1)/4) {
            t2 += (t4-(n-1)*(m-1)/4)*2;
            if (t2 >= (n+m-2)/2) printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");
    }
    else {
        if (n&1) swap(n, m);
        if (t4 >= n*(m-1)/4) {
            t2 += (t4-n*(m-1)/4)*2;
            if (t2 >= n/2) printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");
    }
    return 0;
}


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

int main(){
    ll H,W,M;
    cin >> H >> W >> M;
    vector<ll> h(M), w(M);
    rep(i,M){
        cin >> h[i] >> w[i];
    }
    map<ll,ll> mph;
    map<ll,ll> mpw;
    map<pair<ll,ll>, ll> mphw;
    rep(i,M){
        mph[h[i]]++;
        mpw[w[i]]++;
        mphw[pair<ll,ll>(h[i], w[i])]++;
    }
    ll h_max = 0;
    ll w_max = 0;
    for (map<ll,ll>::iterator itr = mph.begin(); itr != mph.end(); itr++){
        if (itr->second > h_max) h_max = itr->second;
    }
    for (map<ll,ll>::iterator itr = mpw.begin(); itr != mpw.end(); itr++){
        if (itr->second > w_max) w_max = itr->second;
    }
    map<ll,ll> maxmph;
    map<ll,ll> maxmpw;
    ll h_num = 0;
    for (map<ll,ll>::iterator itr = mph.begin(); itr != mph.end(); itr++){
        if (itr->second == h_max){
            maxmph[itr->first]++;
            h_num++;
        }
    }
    ll w_num = 0;
    for (map<ll,ll>::iterator itr = mpw.begin(); itr != mpw.end(); itr++){
        if (itr->second == w_max){
            maxmpw[itr->first]++;
            w_num++;
        }
    }
    ll ans_num = 0;
    rep(i,M){
        if (maxmph[h[i]] >= 1 && maxmpw[w[i]] >= 1) ans_num++;
    }
    if (ans_num == h_num * w_num) cout << h_max + w_max - 1 << endl;
    else cout << h_max + w_max << endl;
}


Measured memory_bytes: 101708
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            byte N = Byte.parseByte(in.next());
            Set<Byte> d = new HashSet<>();
            for (byte i = 0; i < N; i++) {
                d.add(Byte.parseByte(in.next()));
            }
            out.println(d.size());
        }

    }
}



Measured memory_bytes: 35840
#include<stdio.h>
int dp[50];

int fib(int n){
  if(n==0||n==1){
    return dp[n]=1;
  }
  if(dp[n]!=-1){
    return dp[n];
  }
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++){
    dp[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int a;
	cin >> a;

	cout << a * a << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 054
 * 2017/02/11
 * C - One-stroke Path
 *
 * https://beta.atcoder.jp/contests/abc054/tasks/abc054_c
 * */
public class Main {

	static int[] a, b;
	static int N, M, ans;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		a = new int[M];
		b = new int[M];
		boolean[] flg = new boolean[N];

		for (int i = 0; i < M; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
		}

		int now = 0;
		flg[now] = true;
		dfs(now, flg);

		System.out.println(ans);
	}

	public static void dfs(int now, boolean[] flg) {
		for (int i = 0; i < M; i++) {
			if (a[i] == now && !flg[b[i]]) {
				flg[b[i]] = true;
				dfs(b[i], flg);
				flg[b[i]] = false;
			}
			if (b[i] == now && !flg[a[i]]) {
				flg[a[i]] = true;
				dfs(a[i], flg);
				flg[a[i]] = false;
			}
		}

		for ( int i = 0; i < N; i++) {
			if ( flg[i] == false) {
				return;
			}
		}
		ans++;
		return;
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Mplus(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  string s;
  cin>>s;
  bool flag=true;
  flag&=(s[0]=='A');
  int c=0;
  FOR(i,2,s.size()-1){
    if(s[i]=='C') c++;
  }
  flag&=(c==1);

  FOR(i,1,s.size()){
    if(s[i]=='C') continue;
    flag&=('a'<=s[i]&&s[i]<='z');
  }

  if(flag) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, M;
  cin >> N >> M;

  vvi AB(M, vi(2));
  rep(i, M){
    cin >> AB[i][0] >> AB[i][1];
    AB[i][0]--;
    AB[i][1]--;
  }
  sort(rng(AB));
  sort(rng(AB),[](const vi &a, const vi &b){return a[1] < b[1];});

  i64 ans = 0;
  i64 cur = -1;
  rep(i,M){
    if(cur <= AB[i][0]){
      ans++;
      cur = AB[i][1];
    }
  }

  cout << ans << "\n";

  

}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#define debug(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#define debug(...) __VA_ARGS__
#endif
const int N = 100005;

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

    int n; string s;
    cin >> n >> s;

    for (char& c : s) {
        c -= 'A';
        c += n;
        c %= 26;
        c += 'A';
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  double T;
  T=0;
  for (int i=0;i<N;i++) {
    double A;
	string S;
	cin >> A >> S;
	if (S=="JPY") {T+=A;} else {T+=A*380000;}
	
  }
  cout << fixed << setprecision(10) << T << endl;
  
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	
	cout << count(ALL(s), '2') << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
  int N,K,num;
  scanf("%d %d",&N,&K);
  N = N-K;
  num = 1;
  num += N / (K-1);
  if(N%(K-1)!=0) num++;
  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

s = list(input())

AGCT = ["A","G","C","T"]

s.append("X")

c = 0
c_max = 0
for i in range(len(s)):
    if s[i] in AGCT:
        c += 1
    else:
        c_max = max(c_max, c)
        c = 0

print(c_max)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	cin >> N;
	vector<int> A(N),v(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
		v[i] = A[i];
	}
	sort(v.rbegin(),v.rend());
	for(int i=0;i<N;i++){
		if(A[i]!=v[0]){
			cout << v[0] << endl;
		}else{
			cout << v[1] << endl;
		}
	}
}

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


const int MAX = 42;




int main() {
  random_device rnd, rnd2, rnd3;
  mt19937 mt(rnd()), mt2(rnd2()), mt3(rnd3());
  uniform_int_distribution<> randN(2,80), randA(100, 200);
  
  
  ll N;
  cin >> N;

  vector<ll> A, sell(N+1, 0), buy(N+1, 0);
  A.push_back(0);
  ll A1;
  cin >> A1;
  A.push_back(A1);

  for(int i = 2; i <= N; i++){
    ll Ai;
    cin >> Ai;
    if(Ai != A.back()){
      A.push_back(Ai);
    }
  }
  N = A.size() - 1;


  if(A[1] < A[2]) buy[1] = 1;
  
  if(A[N] > A[N-1]) sell[N] = 1;
  for(int i = 2; i <= N-1; i++){
    if(A[i-1] < A[i] && A[i] > A[i+1]){
      sell[i] = 1;
    }
    if(A[i-1] > A[i] && A[i] < A[i+1]){
      buy[i] = 1;
    }
  }


  ll money = 1000, stock = 0;
  for(int i = 1; i <= N; i++){
    if(sell[i] == 1){
      money += stock * A[i];
      stock = 0;
    }
    if(buy[i] == 1){
      stock = money / A[i];
      money -= stock * A[i];
    }
  }

  cout << money << endl;
  





  // cout << setprecision(8) << ans << endl;  // For double
}



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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

const int MOD = 1000000007;

void diviser(long n, map<long, long> &mp)
{
    for (long i = 2; i * i <= n; ++i)
    {
        while (n % i == 0)
            n /= i, ++mp[i];
        mp[i] %= MOD;
    }
    if (n != 1)
        ++mp[n];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long N;
    cin >> N;

    map<long, long> mp;
    for (long i = 2; i <= N; ++i)
        diviser(i, mp);

    long ans = 1;
    for (auto p : mp)
        ans *= (1 + p.second), ans %= MOD;

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(int i = z; i < n; i++)
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, 0, N) cin >> A.at(i);
    
    rep(i, 0, N - K){
        if (A.at(i) < A.at(i + K)){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4048
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e6;


ll gcd(ll a,ll b)
{
    if(a!=0 && b==0)
    {
        return a;
    }
    if(a%b==0)
    {
        return b;
    }
    else
    {
        return(gcd(b,a%b));
    }
    
}

int main()
{
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll ini=a[0];
    rep(i,n-1)
    {
        ini=gcd(ini,a[i+1]);
    }
    cout<<ini;

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#include <iterator>

using namespace std;

namespace {

}

int main()
{
	int N = 0, M = 0;

	cin >> N >> M;
	
	if (abs(N - M) >= 2) {
		cout << 0 << endl;
		return 0;
	}
	long long bigN = 1000000000LL + 7;
	long long num = 1;
	if (N == M) {

		for (long long i = 1; i <= N; ++i) {
			num = (num * i) % bigN;
		}
		num = 2 * ((num * num) % bigN) % bigN;

	}	
	else {
		long long minN = min(N, M);
		for (long long i = 1; i <= minN; ++i) {
			num = (num * i) % bigN;
		}
		num = (((num * num) % bigN) * max(N, M)) % bigN;
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
import math
import copy
import sys

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
inputList=[]
inputNumList = []
for i in range(a):
    inputNum = input().split()
    inputNumList = [int(n) for n in inputNum]
    inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

for i in range(a-1, -1, -1):
    if b < inputList[i][1]:
        del inputList[i]

if len(inputList) == 0:
    print("TLE")
else:
    sortedInputList = sorted(inputList, key=lambda n:n[0])
    print(sortedInputList[0][0])








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

const int MAX = 100005;
const int WHITE = 0;
const int BLACK = 1;
vector<pair<int, int>> V[MAX];
int color[MAX], d[MAX], N;

void dfs_visit(int u, bool& flg) {
    color[u] = BLACK;
    for (int i = 0; i < V[u].size(); i++) {
        int v, w;
        v = V[u][i].first;
        w = V[u][i].second;
        if (color[v] == BLACK && d[v] != d[u] + w) flg =  false;
        if (color[v] == WHITE) {
            d[v] = d[u] + w;
            dfs_visit(v, flg);
        }
    }
}

bool dfs() {
    for (int i = 0; i < N; i++) color[i] = WHITE;
    bool flg = true;
    for (int i = 0; i < N; i++) {
        if (color[i] == WHITE) {
            d[i] = 0;
            dfs_visit(i, flg);
        } 
    }
    return flg;
}

int main() {
    int M, L, R, D;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        scanf("%d %d %d", &L, &R, &D);
        V[L].push_back(make_pair(R, D));
        V[R].push_back(make_pair(L, -D));
    }
    bool flg = dfs();
    if (flg) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 12416