akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i,n,m,k,a[N],b[N],dp1[N],dp2[N];

bool check(int mid)
{
    int best=INF;
    for(i=0;i<=n;++i)
    {
        int rem=mid-i,req=dp1[i];
        if(rem<=m && rem>=0)
        {
            req+=dp2[rem];
            best=min(best,req);
        }
    }
    return best<=k;
}

void solve()
{
    cin>>n>>m>>k;
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
        dp1[i]=a[i];
        dp1[i]+=dp1[i-1];
    }
    for(i=1;i<=m;++i)
    {
        cin>>b[i];
        dp2[i]=b[i];
        dp2[i]+=dp2[i-1];
    }
    int lo=0,hi=m+n;
    while(lo<hi)
    {
        int mid=(lo+hi+1)/2;
        if(check(mid))
            lo=mid;
        else
            hi=mid-1;
    }
    cout<<lo;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

int main() {
  int H, W, a = 0, b, c, d;
  cin >> H >> W;
  string S, e;
  for (; S.size() < H * W; S += e) cin >> e;
  for (; a < H * W; a++) {
    if (a && !(a % W)) cout << endl;
    if (S.at(a) == '.') {
      for (b = 0, c = a / W; c < a / W + 3; c++) for (d = a % W; d < a % W + 3; d++) if (c * d && c < H + 1 && d < W + 1) if (S.at(W * c - W + d - 1) == '#') b++;
      cout << b;
    }
    else cout << '#';
  }
}

Measured memory_bytes: 256
integer N,M
integer(16),allocatable::a(:),b(:),c(:)
integer(16),allocatable::dist(:)
integer(16) ans

logical,allocatable::negative(:)


read*,N,M
allocate( a(M),b(M),c(M) )
do i=1,M
  read*,a(i),b(i),c(i)
  c(i)=-c(i)
end do

allocate(dist(N))
dist=huge(a(J))/2
dist(1)=0
do i=1,N-1
  do j=1,M
    if(dist(a(j))==huge(a(j))/2)cycle
    if (dist(b(j)) > dist(a(j))+c(j) )dist(b(j))= dist(a(j))+ c(j)
  end do
end do
ans=dist(N)

allocate(negative(N))
negative=.false.
do i=1,N
  do j=1,M
   if (dist(a(j)) == huge(a(j))/2)cycle
   if (dist(b(j)) > dist(a(j)) + c(j) )then
     dist(b(j)) = dist(a(j)) + c(j)
     negative(b(j)) = .true.
   endif
   if (negative(a(j)) ) negative(b(j)) =.true.
  end do
end do

if(negative(N))then
  print"(A)","inf"
else
  print"(i0)",-ans
end if
end

Measured memory_bytes: 384
let () =
  let (n, k) = Scanf.scanf "%d %d\n" (fun n k -> (n, k)) in
  let ary = Array.make n 0 in
  let rec read i =
    if i >= n then ()
    else begin
      let w = Scanf.scanf "%d\n" (fun w -> w) in
      ary.(i) <- w;
      read (i + 1)
    end
  in
  read 0;
  let check p =
    let rec doit i j s =
      if i = n then n
      else if j >= k then i
      else
        let s = s + ary.(i) in
        if s > p then doit i (j + 1) 0
        else doit (i + 1) j s
    in
    doit 0 0 0
  in
  let rec bin_search l r =
    if r < l then l
    else begin
      let m = (l + r) / 2 in
      let v = check(m) in
      if v >= n then bin_search l (m - 1)
      else bin_search (m + 1) r
    end
  in
  Printf.printf "%d\n" (bin_search 0 (100000 * 10000))

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i = 0; i < N-2; i++){
    if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C') ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;if(n<0)pcu('-'),n*=-1;
	if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

struct union_find {
	struct node {int p, r = 1;};
	vector<node> nodes;

	union_find(int n) : nodes(n) {
		int i = 0;
		for (node &n: nodes)
			n.p = i++;
	}
	int find(int x) {
		int &p = nodes[x].p;
		if (p != x)
			p = find(p);
		return p;
	}
	void unite(int a, int b) {
		int ar = find(a), br = find(b);
		node &an = nodes[ar], &bn = nodes[br];
		if (an.r > bn.r)
			bn.p = ar;
		else {
			an.p = br;
			if (an.r == bn.r)
				bn.r++;
		}
	}
	bool equal(int a, int b) {
		return find(a) == find(b);
	}
};

int main() {
	union_find u(in());
	for (int q = in(); q; q--) {
		if (in())
			outl(u.equal(in(), in()));
		else
			u.unite(in(), in());
	}
}


Measured memory_bytes: 2704
#include <iostream>
using namespace std;
int main(void){
    int r;
    cin>>r;
    if(r<1200){
        std::cout << "ABC" << std::endl;
    }else if(r<2800){
        std::cout << "ARC" << std::endl;
    }else{
        std::cout << "AGC" << std::endl;
    }
    
}


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

using namespace std;

int n, k;
string s;
int face = 0;
int happy = 0;

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

	cin >> n >> k;
    cin >> s;

    for (int i = 1; i < n - 1; i++)
    {
        if (s[i] == 'R' && s[i + 1] == 'L')
            face++;
        else if (s[i] == 'R' && s[i + 1] == 'R')
            happy++;
        else if (s[i] == 'L' && s[i - 1] == 'L')
            happy++;
    }
    if (s[0] == 'R' && s[1] == 'L')
        face++;
    else if (s[0] == 'R' && s[1] == 'R')
        happy++;

    if (s[n - 2] == 'L' && s[n - 1] == 'L')
        happy++;

    happy += min(k, face) * 2;

    k -= min(k, face);
    if (k > 0)
        happy = n - 1;

    cout << happy;

	return 0;
}


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

int main() {
	int h, w; cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s.at(i).at(j);
		}
	}
	int ans = 0;
	vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s.at(i).at(j) == '#') continue;
			vector<vector<int>> dir(h, vector<int>(w, -1));
			dir.at(i).at(j) = 0;
			queue <pair<int, int>> q;
			q.push(make_pair(i, j));
			while (q.size() > 0) {
				pair<int, int> p = q.front(); q.pop();
				int x = p.first, y = p.second;
				for (int k = 0; k < 4; k++) {
					int nx = x + dx.at(k), ny = y + dy.at(k);
					if (0 <= nx && nx < h && 0 <= ny && ny < w && s.at(nx).at(ny) == '.' && dir.at(nx).at(ny) == -1) {
						dir.at(nx).at(ny) = dir.at(x).at(y) + 1;
						q.push(make_pair(nx, ny));
					}
				}
			}
			int ma = 0;
			for (int k = 0; k < h; k++) {
				for (int l = 0; l < w; l++) {
					ma = max(ma, dir.at(k).at(l));
				}
			}
			ans = max(ans, ma);
		}
	}
	cout << ans << endl;
}

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

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

long long H,W,N,a,b;
vector<long long>v;
map<pair<int,int>,bool>mp;
long long ans[10];

int main(){
	cin>>H>>W>>N;
	for(int i=0;i<N;i++){
		cin>>a>>b;
		a--; b--;
		v.push_back(a*W+b);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		int y=v[i]/W;
		int x=v[i]%W;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				int ny=y+dy[j];
				int nx=x+dx[k];
				if(ny>0 && ny<H-1 && nx>0 && nx<W-1){
					if(!mp[make_pair(ny,nx)]){
						int cnt=0;
						for(int l=0;l<3;l++){
							for(int m=0;m<3;m++){
								if(binary_search(v.begin(),v.end(),(ny+dy[l])*W+(nx+dx[m])))cnt++;
							}
						}
						ans[cnt]++;
						mp[make_pair(ny,nx)]=true;
					}
				}
			}
		}
	}
	long long sum=0;
	for(int i=1;i<=9;i++){
		sum+=ans[i];
	}
	ans[0]=(H-2)*(W-2)-sum;
	for(int i=0;i<=9;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 57332
X = int(input())
s = 199
t = 400
if t <= X <= t + s:
    print(8) 
elif t + 200 * 1 <= X <= t + 200 * 1 + s:
    print(7)
elif t + 200 * 2 <= X <= t + 200 * 2 + s:
    print(6)
elif t + 200 * 3 <= X <= t + 200 * 3 + s:
    print(5)
elif t + 200 * 4 <= X <= t + 200 * 4 + s:
    print(4)
elif t + 200 * 5 <= X <= t + 200 * 5 + s:
    print(3)
elif t + 200 * 6 <= X <= t + 200 * 6 + s:
    print(2)
elif t + 200 * 7 <= X <= t + 200 * 7 + s:
    print(1)


Measured memory_bytes: 9196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const ll mod2=1e9+9 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   int n;
   cin>>n;
   string s;
   cin>>s;
   int m=1<<n;
   map<string,ll> mp;
   ll ans=0;
   rep(i,m){
       string ret="";
       string res="";
       rep(j,n){
           if(i&(1<<j)){ret+=s[j];}
           else res+=s[j];
       }
       reverse(res.begin(),res.end());
       ret=ret+'+'+res;
       mp[ret]++;
   }
   rep(i,m){
       string ret="";
       string res="";
       rep(j,n){
           if(i&(1<<j))ret+=s[n+j];
           else res+=s[n+j];
       }
       reverse(ret.begin(),ret.end());
       ret=ret+'+'+res;
       ans+=mp[ret];
   }
   cout<<ans<<endl;

   return 0;
}


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

using namespace std;
const int MAXN  = 1e6+100;
int a[MAXN],dp[MAXN];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	memset(dp,0x3f,sizeof(dp));
	dp[1]=0;
	for(int i=2;i<=k;i++){
		for(int j=1;j<i;j++) dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
	}
	for(int i=k+1;i<=n;i++){
		for(int j=i-k;j<=i-1;j++){
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
		}
	}
	cout<<dp[n]<<endl;
	return 0;
} 

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

int main()
{
	int N, R;
	cin >> N >> R;
	if (N >= 10) {
		cout << R << endl;
	}
	else {
		cout << R + (100 * (10 - N)) << endl;
	}
}


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    var n = Number(input[0].split(" ")[0]);
    var k = Number(input[0].split(" ")[1]);
    var r = Number(input[1].split(" ")[0]);
    var s = Number(input[1].split(" ")[1]);
    var p = Number(input[1].split(" ")[2]);
    var t = input[2].split(" ")[0].trim();
//    var isRNG = true;
//    var isSNG = true;
//    var isPNG = true;
    
    var results = [];
    
    for(var i=0; i<t.length; i++){
        if(i>=k && t.charAt(i) == t.charAt(i-k) && results[i-k] > 0){
            results.push(0);
            continue;
        }
        
        if(t.charAt(i) == "r"){
            results.push(p);
        }else if(t.charAt(i) == "s"){
            results.push(r);
        }else{
            results.push(s);
        }
    }
    
    var result = 0;
    for(var i=0; i<results.length; i++){
        result += results[i];
    }
    
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
	if not (a[i] == b[i] and b[i] == c[i] and c[i] == a[i]):
		ans += 2
		if a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
			ans -= 1
print(ans)

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

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

    std::vector<int> vec;
    vec.resize(n);
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        vec[i] = a;
    }

    int q;
    std::cin >> q;

    for (int j = 0; j < q; ++j) {
        int k;
        std::cin >> k;

        std::cout << ((binary_search(vec.begin(), vec.end(), k)) ? 1 : 0)
                  << std::endl;
    }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N,M;
cin >> N;
vector<string> blue(N);

map<string,int> moji;

for (int i = 0;i < N;i++) {
    cin >> blue.at(i);
    if (moji.count(blue.at(i))) {
        moji[blue.at(i)] += 1;
    }else  moji[blue.at(i)] = 1;
}
cin >> M;
vector<string> red(M);
for (int i = 0;i < M;i++) {
cin >> red.at(i);
if (moji.count(red.at(i))) {
    moji[red.at(i)] -= 1; 
} else moji[red.at(i)] = -1; 
}

int maxi = -100;
for (auto p : moji) {
    auto key = p.first;
    auto value = p.second;
    if (value > maxi) maxi = value; 
}

if (maxi > 0)  cout << maxi << endl;
else cout << 0 << endl;


return 0;
}


Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
G = [[] for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    G[u].append(v)
    G[v].append(u)
q = deque([1])
p = [0]*(n+1)
while q:
    v = q.popleft()
    for u in G[v]:
        if p[u] == 0:
            p[u] = v
            q.append(u)
print("Yes\n"+"\n".join(map(str, p[2:])))

Measured memory_bytes: 42000
N, K = map(int, input().split())
 
ans = 0
mod = pow(10,9)+7
 
for k in range(K, N+2): ## K個以上で総数(N+1)
  ## 全個数の計算　## k個最大 ## k個最小
  ans += k*((N+1-k)+N)//2 - k*(0+k-1)//2 + 1
  
print(ans % mod)


## sum(range(N-k+1, N+1))
## k*((N+1-k)+N)/2

## sum(range(0, k))
## k*(0+k-1)/2

Measured memory_bytes: 9164
X, K, D = map(int, input().split())

X = abs(X)

d, r = divmod(X, D)
if K >= d:
    if (K - abs(d)) % 2 == 0:
        print(min(r, abs(X - D*K)))
    else:
        print(min(abs(r - D), abs(X - D*K)))
else:
     print(abs(X - D*K))   


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

#define ll long long

const ll INF = (ll)9e17L;

void wynik(ll& a, ll b) {
    a = min(a, b);
}

#define pb push_back

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

	int n, W;	cin >> n >> W;
	vector<int> waga, koszt;
	for(int i=0; i<n; i++) {
			int x, y;	cin >> x >> y;
			waga.pb(x); koszt.pb(y);
	}

	int suma = 0;
	for(int i : koszt) {
			suma += i;
	}
	vector<ll> dp(suma+1, INF);
	dp[0] = 0;
	for(int i=0; i<n; i++)
			for(int j=suma-koszt[i]; j>=0; j--)
					wynik(dp[j+koszt[i]], dp[j] + waga[i]);
	ll R = 0;
	for(int i = 0; i <= suma; i++)
			if(dp[i] <= W)
					R = max(R, (ll) i);
	cout << R;
}


Measured memory_bytes: 1024
from collections import Counter
n,k = map(int,input().split())
td = [list(map(int,input().split())) for i in range(n)]
td.sort(key = lambda x:x[1],reverse=True)
ans = list(range(k))
ansv = sum((td[i][1] for i in range(k)))
c = Counter((td[i][0] for i in range(k)))
cnt = len(c)
ansv += len(c)**2
ptr = k
ansls = [ansv]
for i in range(k-1,-1,-1):
  t,d = td[ans[i]]
  if ptr < n and c[t] > 1:
    while ptr < n and c[td[ptr][0]] >= 1:
      ptr += 1
    if ptr >= n:
      break
    ansv = ansv-d+2*cnt+1+td[ptr][1]
    c[t] -= 1
    c[td[ptr][0]] += 1
    cnt += 1
    ptr += 1
    ansls.append(ansv)
print(max(ansls))

Measured memory_bytes: 73816
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
int main(){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(all(a));
  int res = a[0] + a[1] + a[2]*10;
  cout << res <<endl;
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	
	
	ll N;
	cin >> N;
	vector<ll> A(N,0);
	REP(i,N){
		cin >> A[i];
	}
	sort(A.begin(), A.end(), greater<ll>());
	ll ans = A[0];
	for(int i=2; i<N; i++){
		ans += A[i/2];
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eps 1e-9

const int MOD = 1e9+7;

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

ll POWER[65];
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
ll inv(ll x) {return power(x,MOD-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}
const int MAXN = 1e5+5;
int fin[MAXN];
pii ar[MAXN];
int main() {
//	freopen("TASK.in","r",stdin);freopen("TASK.out","w",stdout);
	precompute();
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		scanf("%d",&ar[i].ff);
		ar[i].ss=i;
	}
	sort(ar+1,ar+1+n);
	int cur=0;
	ar[0].ff=-1;
	for(int i=1;i<=n;i++) {
		if(ar[i].ff!=ar[i-1].ff) ++cur;
		fin[ar[i].ss]=cur;
	}
	int ans=0;
	for(int i=1;i<=n;i+=2) {
		if(!(fin[i]&1)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 998244353
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int D[100000];
void Calc(){
	int N = rei();
	int F = rei();
	D[F]++;
	for(int i=0;i<N-1;i++){
		int p = rei();
		D[p]++;
	}
	if(F != 0 || D[0] > 1){
		cout << 0 << endl;
		return;
	}
	long ans = 1;
	for(int i=1;i<N;i++){
		for(int j=0;j<D[i];j++){
			ans *= D[i-1];
			ans %= mod;
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

int MAX = pow(10, 9);

int GCD(int a, int b) {
    if(a < b) {
        swap(a, b);
    }
    if(a % b == 0) {
        return b;
    } else {
        return GCD(b, a % b);
    }
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    int line_x;
    for(int i = 0; i < N; i++) {
        cin >> line_x;
        x.at(i) = abs(line_x - X);
    }

    int gcd = x.at(0);
    for(int i = 1; i < N; i++) {
        gcd = GCD(gcd, x.at(i));
    }

    cout << gcd << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
  ll n,m;
  cin >> n >> m;
  vector<vector<ll>> a(3*n+1,vector<ll>(6*n+20,0));
  a[0][3*n+5]=1;
  for(ll i=1;i<=3*n;i++){
      for (int j=4;j<6*n+15;j++){
          (a[i][j+1]+=a[i-1][j])%=m;
          if (i>1){
              (a[i][j-1]+=(i-1)%m*a[i-2][j])%=m;
          }
          if (i>2){
              (a[i][j]+=(i-1)%m*(i-2)%m*a[i-3][j])%=m;
          }
      }
  }
  ll ans=0;
  for (int i=3*n+5;i<6*n+20;i++){
      (ans+=a[3*n][i])%=m;
  }
  cout << ans << endl;
}


Measured memory_bytes: 566144
#include <bits/stdc++.h>
#define gb(i,j) ((i>>j)&1)

using namespace std;
int n,a[(1<<18)+10];
int cs[(1<<18)+10][2];
int main()
{
    #ifdef abcxyz
    freopen("a.inp", "r", stdin);
    freopen("a.out", "w", stdout);
    #endif
    cin >> n;
    a[(1<<n)]=0;
    for(int i=0; i<(1<<n); ++i)cin >> a[i],cs[i][0]=i,cs[i][1]=(1<<n);
    int mx=0;
    for(int i=1; i<(1<<n); ++i){
        for(int j=0; j<n; ++j)
        if(gb(i,j)){
            int t=i-(1<<j);
            if(cs[t][0]!=cs[i][1] && cs[t][0]!=cs[i][0] && a[cs[t][0]]>a[cs[i][1]]){
                cs[i][1]=cs[t][0];
                if(a[cs[i][1]]>a[cs[i][0]])swap(cs[i][1],cs[i][0]);
            }
            if(cs[t][1]!=cs[i][1] && cs[t][1]!=cs[i][0] && a[cs[t][1]]>a[cs[i][1]]){
                cs[i][1]=cs[t][1];
                if(a[cs[i][1]]>a[cs[i][0]])swap(cs[i][1],cs[i][0]);
            }
        }
        mx=max(mx,a[cs[i][1]]+a[cs[i][0]]);
        cout << mx<<endl;
    }
    return 0;
}


Measured memory_bytes: 6144
from math import factorial
n, m = map(int, input().split())
mod = 10**9 + 7
dif = abs(n - m)
if dif >= 2:
    print(0)
    exit()
mi = min(n, m)
p = factorial(mi) % mod
print(p * ((mi+1) * p % mod) % mod) if dif == 1 else print((p*p%mod)*2%mod)


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 110;

int n;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%*d%d", &n);
	int Max = 0, sum = 0, x;
	REP(i, 0, n)
	{
		scanf("%d", &x), sum += x;
		chkmax(Max, x);
	}
	printf("%d\n", max(0, max(0, Max - (sum - Max) - 1)));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,i,sum,maxz;
char s;

int main()
{
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>s;
        if(s=='I')
            sum++;
        else
            sum--;
        maxz=max(maxz,sum);
    }
    cout<<maxz;
    return 0;
}

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


int main(){
    string s[4];
    s[0] = "maerd";
    s[1] = "remaerd";
    s[2] = "esare";
    s[3] = "resare";
    
    string S; cin >> S;
    reverse(S.begin(),S.end());
    
    string T;
    bool F=true;
    for(int i=0; i<S.length(); ){
        if(S[i]=='m'){
            T += s[0];
            i += 5;
        }
        else if(S[i]=='e'){
            T += s[2];
            i += 5;
        }
        else if(S[i]=='r'){
            if(i+2<=S.length()){
                if(S[i+2]=='m'){
                    T += s[1];
                    i += 7;
                }
                else if(S[i+2]=='s'){
                    T += s[3];
                    i += 6;
                }
                else
                    F = false;
            }
            else F=false;
        }
        else F=false;
        if(!F) break;
    }
    if(F){
        if(S==T){
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int INF=1e10;

int main(){
	string s;
	cin >> s;
	if (s[s.size()-1] == 's'){
		s+="es";
	}else{
		s+='s';
	}
	cout << s << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
const int N = 300000 + 10;
int n,a[N]; char s[N];
int id(char c) {
	if (c=='R') return 0;
	if (c=='G') return 1;
	return 2;
}
int c[8]; // 0,1,2,01,02,12
int main() {
	scanf("%d%s",&n,s+1);
	LL ans=1;
	for(int i=1;i<=n*3;i++){
		int x=id(s[i]);
		if(x==0){
			if(c[5]>0) {
				ans=ans*c[5]%MOD; c[5]--; 
			}else if(c[1]>0){
				ans=ans*c[1]%MOD; c[1]--; c[3]++;
			}else if(c[2]>0){
				ans=ans*c[2]%MOD; c[2]--; c[4]++;
			}else{
				c[0]++;
			}
		}
		if(x==1){
			if(c[4]>0){
				ans=ans*c[4]%MOD; c[4]--;
			}else if(c[0]>0){
				ans=ans*c[0]%MOD; c[0]--; c[3]++;
			}else if(c[2]>0){
				ans=ans*c[2]%MOD; c[2]--; c[5]++;
			}else{
				c[1]++;
			}
		}
		if(x==2){
			if(c[3]>0){
				ans=ans*c[3]%MOD; c[3]--;
			}else if(c[0]>0){
				ans=ans*c[0]%MOD; c[0]--; c[4]++; 
			}else if(c[1]>0){
				ans=ans*c[1]%MOD; c[1]--; c[5]++;
			}else{
				c[2]++;
			}
		}
	}
	for(int i=1;i<=n;i++)ans=ans*i%MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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 (a > b) { a = b; return true; } return false; }

// ?¨???°????????? O(N+K)
// ??¶?´?: 0 <= v[i] <= v.size()
void counting_sort(vector<int> &v) {
	int n = v.size(), k = *max_element(v.begin(), v.end());
	vector<int> cnt(k + 1), tmp(v);
	cnt[0]--;
	for (int x : v)cnt[x]++;
	for (int i = 0; i < k; i++)cnt[i + 1] += cnt[i];
	for (int i = n - 1; i >= 0; i--) {
		v[cnt[tmp[i]]] = tmp[i];
		cnt[tmp[i]]--;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> A(n); rep(i, 0, n) { cin >> A[i]; }
	counting_sort(A);
	cout << A[0]; rep(i, 1, A.size()) { cout << " " << A[i]; } cout << endl;
	return 0;
}

Measured memory_bytes: 18328
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define extreme   inline
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define test      cout<<"THIS_AND_THIS"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n,m;
	cin>>n>>m;
	ll arr[n],sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];sum+=arr[i];
	}
	sort(arr,arr+n);
	reverse(arr,arr+n);
	double x=(double)sum/(4*m);
	if(arr[m-1]>=x){cout<<"Yes";}
	else{cout<<"No";}
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>
#include <utility>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int64;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64 n;
  cin >> n;
  int64 res = n + 1;
  for (int64 i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res = min(res, i + (n / i));
    }
  }
  cout << res - 2 << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, m; cin >> n >> m; 
    vector<vi> graph(n);
    rep(loop, m){
        int a, b; cin >> a >> b; a--, b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    deque<int> path = { 0, graph[0][0] };
    vi used(n); for(auto v : path) used[v] = true;

    auto check = [&]{
        rep(i, 2){
            int v = i == 0 ? path.front() : path.back();
            for(auto nv : graph[v]){
                if(used[nv] == false){
                    used[nv] = true;
                    if(i == 0) path.push_front(nv);
                    else       path.push_back (nv);
                    return false;
                }
            }
        }
        return true;
    };

    while(check() == false){}
    
    cout << path.size() << endl;
    for(auto& v : path){
        cout << v + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 7168
#include <iostream>
    #include <vector>
    #include <algorithm>
     
    int main(){
    	int N, M;
      	int sum = 0;
      	int flag;
      	bool f = true;
     	std::cin>>N>>M;
      	std::vector<int> A(N);
      	for(int i=0;i<N;i++){
          std::cin>>A.at(i);
          sum += A.at(i);
        }
      
      	std::sort(A.begin(), A.end(), std::greater<int>());
      
      	if(sum%(4*M)==0){
        	flag = sum/(4*M);
        }else{
          	flag = 1 + sum/(4*M);
        }
      
      for(int i = M; i>0;i--){
        if(A.at(M-1)<flag){
          f=false;
          break;
        }
      }
      
      if(f){std::cout<<"Yes";}else{std::cout<<"No";}
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;

int main()
{
    ll t,i,n,k;
    ll a,c;
    long double b;
    cin>>n>>k;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    ll l=0,r=k-1;
    ll sum=0;
    for(i=0;i<k;i++) sum+=arr[i];
    ll mx=sum;
    for(i=1;i<n-k+1;i++)
    {
        sum-=arr[i-1];
        sum+=arr[i+k-1];
        if(mx<sum)
        {
            l=i;
            r=i+k-1;
            mx=sum;
        }
    }
    long double ans=0;
    for(i=l;i<=r;i++)
    {
        a=arr[i];
        b=(a*(a+1))/2.0;
        b/=(long double)a;
        //cout<<" "<<b<<endl;
        ans+=b;
    }
    cout<<fixed<<setprecision(8)<<ans;
}

Measured memory_bytes: 5304
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;


int _map[310][301];

int main()
{
    int h,w,k;
    scanf("%d%d%d",&h,&w,&k);
    k=1;
    for (int i=1;i<=h;++i)
    for (int j=1;j<=w;++j){
        char ch=getchar();
        while (ch!='#'&&ch!='.') ch=getchar();
        if (ch=='#') _map[i][j]=k++;else _map[i][j]=0;
    }
    for (int j=1;j<=w;++j){
        for (int i=2;i<=h;++i)
        if (!_map[i][j])
            _map[i][j]=_map[i-1][j];
        for (int i=h-1;i>=1;--i)
        if (!_map[i][j])
            _map[i][j]=_map[i+1][j];
    }
    for (int i=1;i<=h;++i){
        for (int j=2;j<=w;++j)
        if (!_map[i][j])
            _map[i][j]=_map[i][j-1];
        for (int j=w-1;j>=1;--j)
        if (!_map[i][j])
            _map[i][j]=_map[i][j+1];
    }

    for (int i=1;i<=h;++i,printf("\n"))
    for (int j=1;j<=w;++j)
        printf("%d ",_map[i][j]);

}



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

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> a(N,0);
  for( int i=1; i<N; ++i ) {
    a[i] = a[i-1];
    if ((S[i-1] == 'A') && (S[i] == 'C')) {
      a[i]++;
    }
  }
//  REP(i,N) cout << a[i] << " "; cout << endl;

  REP(i,Q) {
    int l,r;
    cin >> l >> r;
    l--; r--;
    cout << a[r]-a[l] << endl;
  }
}




Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char s[11];
  cin>>s;
  int i;
  if(strlen(s)%2!=0)
     printf("No");
     
 else
 {
  for(i=0;s[i];++i)
  {
    if(i%2==0)
    {
      if(s[i]=='h')
          continue;
      
      else
         break;
    }
    
    else
    {
      if(s[i]=='i')
          continue;
      
      else
         break;
    }
  }
  if(i<strlen(s))
      printf("No");
  
  else
     printf("Yes");
 }
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll n, k;
vi logs;

bool valid(ll len) {
    ll tot = 0;
    rep(i, 0, n) {
        tot += ceil((long double)logs[i] / len) - 1;
    }

    return tot <= k;
}   

int bsearch(int l, int r) {
    if (l == r) return l;
    if (l + 1 == r) {
        if (valid(l)) return l;
        return r;
    } else {
        int m = (l + r) / 2;
        if (valid(m)) return bsearch(l, m);
        else return bsearch(m + 1, r);
    }
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    logs.resize(n);
    for (auto& i : logs) cin >> i;
    cout << bsearch(1, 1e9);
}


Measured memory_bytes: 3960
#include <iostream>
 
using namespace std;
 
int main(){
    int N,ac=0,wa=0,tle=0,re=0;
    char S[3];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>S;
        if(S[0]=='A')ac++;
        else if(S[0]=='W')wa++;
        else if(S[0]=='T')tle++;
        else if(S[0]=='R')re++;
    }
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);
}

Measured memory_bytes: 3760
#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 gcd(int a, int b){
    int r,temp;
    if (a < b){
        temp = a;
        a = b;
        b = temp;
    }
    while ( (r = a % b) != 0){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if (C % gcd(A,B) == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
N, K = map(int,input().split())
p = [0] + [int(x) for x in input().split()]
p = [(x+1)/2 for x in p]
for i in range(N):
  p[i+1] += p[i]
ans = 0
for i in range(K, N+1):
  ans = max(ans, p[i]-p[i-K])
print(ans)


Measured memory_bytes: 77704
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = scan.nextInt();
        Long K = scan.nextLong();
        Integer Q = scan.nextInt();
        ArrayList<Integer> A = new ArrayList<Integer>();
        Integer array[] = new Integer[N];

        for(int i=0;i<Q;i++) A.add(scan.nextInt());

        for(int i=0;i<N;i++)
            array[i] = 0;

        for(int i=0;i<Q;i++){
            array[A.get(i)-1]++;
        }


        for(int i=0;i<N;i++){
            if(Q-K>=array[i])
                System.out.println("No");
            else
                System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 82600
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#define rep(n,i)  for(int i=0; i<(int)(n);i++)
#define all(v)  v.begin(),v.end()
using namespace std;

int jousu(int, int);
int jousu(int x, int y) {
	int z = 1;
	for (int i = 0; i < y; i++) {
		z *= x;
	}
	return z;
}
int kurai(int x, int y) {
	int z = (x%jousu(10,y)) / jousu(10, y-1);
	return z;
}
int keta(int x) {
	int z = x;
	int w = 0;
	while (z != 0) {
		z /= 10;
		w++;
	}
	return w;
}



int main() {
	int n,r;
	cin >> n >> r;
	cout << r+(10-min(n,10))*100 << endl;
	
}

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

int MAX = 2 * 100000;
int main() {
    long n;
    cin >> n;
    long c[n] = {0};
    long num[n] = {0};
    rep(i, n) {
        cin >> num[i];
        num[i]--;
        c[num[i]]++; 
    }
    long ans = 0;
    rep(i, n) {
        if (c[i] < 2) {
            continue;
        }
        ans += c[i] * (c[i] - 1) / 2;
    }
    rep(i, n) {
        cout << ans - (c[num[i]] - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 5760
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define inf LLONG_MAX
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6];
ll power(ll x,ll n){
    if(n==0) return 1;
    /*while(n){
        if(n%2) x=(((x*x)%M)*x)%M; 
        else x=(x*x)%M;
        n/=2;
    }*/
    if(n%2 == 0) return power((x*x),n/2);
    else return (x*power((x*x),(n-1)/2));
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=M6;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
ll n,m,vis[M6];
V g[M5];
/*ll solve(ll sor,ll des){
	if(sor==des) return 1;
	else return 0;
	if(dp[sor][des]!=-1) return dp[sor][des];
	ll i,ans=0;
	for(i=1;i<=n;i++){
		if(connect[i][des]){
			ans+=solve(n,i); ans%=M;
		}
	}
	return dp[sor][des]=ans;
}*/
int main(){
    //buf; 
    //fact();
    //sieve()
    ll i,j,k,l,test,flag,ans,x,y; string s;
    //cin>>test;
    test=1;
    while(test--){
    	cin>>n>>y;
    	y/=1000;
    	for(i=0;i<=n;i++){
    		for(j=0;i+j<=n;j++){
    			if(i*10+j*5+n-i-j==y){
    				cout<<i<<" "<<j<<" "<<n-i-j; return 0;
    			}
    		}
    	}
    	cout<<"-1 -1 -1";
	}
    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

ll func(ll sy, ll sx, ll gy, ll gx, ll H, ll W, char S[21][21])
{
    if (S[sy][sx] == '#' || S[gy][gx] == '#') return -1;

    bool T[21][21];
    rep(i, 21) rep(j, 21) T[i][j] = false;

    struct point
    {
        ll y;
        ll x;
        ll counter;
    };
    queue<point> que;
    que.push({sy, sx, 0});

    ll ans = 0;
    while (!que.empty())
    {
        point now = que.front();
        que.pop();
        if(T[now.y][now.x]) continue;
        else T[now.y][now.x] = true;
        
        if (now.y == gy && now.x == gx)
        {
            ans = now.counter;
            break;
        }

        if (now.y >= 1 && now.y <= H && now.x >= 1 && now.x <= W && S[now.y][now.x] != '#')
        {
            que.push({now.y + 1, now.x, now.counter + 1});
            que.push({now.y - 1, now.x, now.counter + 1});
            que.push({now.y, now.x + 1, now.counter + 1});
            que.push({now.y, now.x - 1, now.counter + 1});
        }
    }
    return ans;
}

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

    ll H, W;
    cin >> H >> W;
    char S[21][21];
    rep1(i, H) rep1(j, W) cin >> S[i][j];

    ll ans = 0;
    rep1(sy, H) rep1(sx, W) rep1(gy, H) rep1(gx, W)
    {
        ll mv = func(sy, sx, gy, gx, H, W, S);
        ans = max(ans, mv);
    }
    print(ans);

    return 0;
}

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

int main() {
    int n;
    while (cin >> n) {
        long long debt = 100000;
        for (int i = 0; i < n; i++) {
            debt += debt / 20;
            debt += (debt % 1000 == 0) ? 0 : 1000 - (debt % 1000);
        }
        cout << debt << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A(N+1);
    std::vector<int64_t> B(N);

    for (auto& a : A) {
        std::cin >> a;
    }

    for (auto& b : B) {
        std::cin >> b;
    }

    int64_t count = 0;
    for (int64_t i = 0; i < B.size(); ++i) {
        if (B.at(i) <= A.at(i)) {
            int64_t diff = A.at(i) - B.at(i);
            count += B.at(i);
            A.at(i) = diff;
            B.at(i) = 0;
        } else {
            int64_t diff = B.at(i) - A.at(i);
            count += A.at(i);
            A.at(i) = 0;
            B.at(i) = diff;
        }

        if (B.at(i) <= A.at(i+1)) {
            int64_t diff = A.at(i+1) - B.at(i);
            count += B.at(i);
            A.at(i+1) = diff;
            B.at(i) = 0;
        } else {
            int64_t diff = B.at(i) - A.at(i+1);
            count += A.at(i+1);
            B.at(i) = diff;
            A.at(i+1) = 0;
        }
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 1792