akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M;
int G[710][710];
bool F = true;
int dir[710];
int tmpnums[2];

void dfs(int v, int tdir) {
	dir[v] = tdir;
	tmpnums[tdir]++;
	REP(e, N) {
		if (e == v || !G[v][e])continue;
		if (dir[e] == -1)dfs(e, 1 - tdir);
		else if (dir[e] != 1 - tdir)F = false;
	}
}

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

	cin >> N >> M;
	REP(i, N) {
		REP(j, N)G[i][j] = 1;
	}
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a][b] = 0;
		G[b][a] = 0;
	}

	vector<pii> nums;
	REP(i, N) dir[i] = -1;
	REP(v, N) {
		if (dir[v] != -1)continue;
		tmpnums[0] = tmpnums[1] = 0;
		dfs(v, 0);
		nums.push_back(pii(tmpnums[0], tmpnums[1]));
	}
	if (!F) {
		cout << -1 << endl;
		return 0;
	}

	bool dp[710] = { 0 };
	dp[0] = 1;
	REP(i, nums.size()) {
		for (int j = N; j >= 0; j--) {
			if (!dp[j])continue;
			dp[j] = 0;
			dp[j + nums[i].first] = 1;
			dp[j + nums[i].second] = 1;
		}
	}

	int a = -1;
	int mind = N;
	eREP(i, N) {
		if (!dp[i])continue;
		if (mind > abs(i - N / 2))mind = abs(i - N / 2), a = i;
	}
	int b = N - a;
	cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
	return 0;
}



Measured memory_bytes: 4224
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    H,W,K = map(int, readline().split())
    S = [list(map(int, readline().strip())) for j in range(H)]

    white = 0
    for line in S:
        white += sum(line)

    if white <= K:
        print(0)
        exit()

    # 横線の決め方を全探索
    ans = 10**5
    for pattern in range(2**(H-1)):
        # 初期化
        impossible = False
        x = 0
        ly = bin(pattern).count("1")
        y = [S[0]]
        line = 0
        for i in range(1,H):
            if (pattern >> i-1) & 1:
                line += 1
                y.append(S[i])
            else:
                y[line] = [y[line][j] + S[i][j] for j in range(W)]

        # 各列の値を加算していく
        count = [0]*(ly + 1) 
        for j in range(W):
            for i in range(line+1):
                if y[i][j] > K :
                    impossible = True
                    break

                count[i] += y[i][j]
                if count[i] > K:
                    x += 1
                    for i in range(line+1):
                        count[i] = y[i][j] 
                    break
            if x + ly > ans or impossible:
                impossible = True
                break
        if impossible:
            x = 10**6

        ans = min(ans, x + ly)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
N=int(input())
edges=[list(map(int,input().split())) for i in range(N-1)]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
root=[[] for _ in range(N)]
for a,b,c in edges:
        root[a-1].append((b-1,c))
        root[b-1].append((a-1,c))
d=[-1]*N
s=[K-1]
d[K-1]=0
while s:
        l=s.pop()

        for i,c in root[l]:
                if d[i]==-1:
                        d[i]=d[l]+c
                        s.append(i)
for i in range(Q):
        print(d[xy[i][0]-1]+d[xy[i][1]-1])

Measured memory_bytes: 87476
#include <bits/stdc++.h>
#define INF64 1LL << 60;
#define INF32 1 << 29;
using namespace std;

void execute()
{
	int N;
	int tmp;
	int min = INF32;

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> tmp;
		for (int j = 0; j <= min; j++)
		{
			if (tmp % 2 != 0)
			{
				min = j;
			}
			tmp /= 2;
		}
	}
	cout << min << endl;
	return;
}

int main()
{
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
ll direction2[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
bool valid(int a,int b)
{
    if(a>=1&&a<=h&&b>=1&&b<=w)return true;
    else return false;
}

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

    cin>>h>>w;
    char l1[h+1][w+1];
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>l1[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(l1[i][j]=='#'){
                ll x=0;
                for(int k=0;k<4;k++){
                    ll a=i+direction2[k][0];
                    ll b=j+direction2[k][1];
                    //cout<<a<<" "<<b<<endl;
                    if(valid(a,b)&&l1[a][b]=='#')x++;
                }
                //cout<<"<"<<x<<">"<<endl;
                if(x==0){
                    cout<<"No";return 0;
                }
            }
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long t,a,b,v,w,x,y,z;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    if (w>v)
    {
    	cout<<"NO"<<endl;
    	return 0;
	}
    x=abs(a-b);
    y=abs(v-w);
    z=y*t;
    if (z>=x)
    {
    	cout<<"YES"<<endl;
    	return 0;
	}
	cout<<"NO"<<endl;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 INF = inf<i64>;
signed main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N), F(N);
  cin >> A >> F;
  sort(RALL(A));
  sort(ALL(F));
  i64 ng = -1;
  i64 ok = INF;
  while (abs(ok - ng) > 1) {
    i64 mid = ok + ng >> 1;
    i64 de = 0;
    REP(i, N) {
      i64 over = A[i] * F[i] - mid;
      if (over > 0) {
        de += (over / F[i]) + (over % F[i] > 0);
      }
    }
    if (de > K) {
      ng = mid;
    } else {
      ok = mid;
    }
  }
  cout << ok << endl;
}


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


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


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


def main():
    C = Counter(list(map(int, input().split())))
    if C[5] == 2 and C[7] == 1:
        print(YES)
    else:
        print(NO)


if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long
#define M 1000000007

vector<int> graph[200010];
int vis[200010];

int dfs(int i){
	vis[i]=1;
	int ans=1;
	for(int j=0;j<graph[i].size();j++){
		if(vis[graph[i][j]]==0){
			ans+=dfs(graph[i][j]);
		}
	}
	return(ans);
}

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n,m;
	cin >> n >> m;
	while(m--){
		int a,b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			ans=max(ans,dfs(i));
		}
	}
	cout << ans << endl;
} 

Measured memory_bytes: 25484
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    double d, z = 0;
    string s;
    cin >> n;
    while (n--) {
        cin >> d >> s;
        if (s[0] == 'J') z += d;
        else z += d * 380000;
    }
    cout << z;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char a,b;
    scanf("%c %c",&a,&b);
    if(a=='D'|a=='H',b=='H'|b=='D')
    {
         if(a=='H'&&b=='H')
    {
        printf("H");
    }
    else  if(a=='D'&&b=='H')
    {
        printf("D");
    }
     else if(a=='H'&&b=='D')
    {
        printf("D");
    }
      else if(a=='D'&&b=='D')
    {
        printf("H");
    }
    }

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef LOCAL
  freopen ("input.txt", "r", stdin);
  freopen ("output.txt", "w", stdout);
#endif 
  int n, w_max;
  cin >> n >> w_max;
  vector<long long> V(w_max + 1, 0);
  for (int i = 0; i < n; ++i) {
    long long wi, vi;
    cin >> wi >> vi;
    for (long long j = w_max - wi; j >= 0; --j) {
      V[j + wi] = max(V[j + wi], V[j] + vi);
    }
  }
  cout << *max_element(V.begin(), V.end()) << '\n';  
}

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

L = [[] for i in range(42)]
for i in range(N):
    tmp = [0] * (N+1)
    for j in range(i, N):
        tmp[j+1] += A[j] + tmp[j]
        k = 0
        while tmp[j+1] >= 2 ** k:
            k += 1
        L[k-1].append(format(tmp[j+1], str(k) + 'b'))

for nums in reversed(L):
    if len(nums) >= K:
        L2 = copy(nums)
        break

def rec(cur):
    global L2
    if cur == len(L2[0]):
        return
    cnt = 0
    flag = False
    L3 = []
    for i in range(len(L2)):
        if L2[i][cur] == '1':
            cnt += 1
            L3.append(L2[i])
            if cnt == K:
                flag = True
    if flag:
        L2 = copy(L3)
        rec(cur+1)
    else:
        rec(cur+1)
    return

rec(1)

ans = int(L2[0], 2)
for i in range(1, K):
    ans &= int(L2[i], 2)

print(ans)


Measured memory_bytes: 134132
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
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, b, c;
	cin >> a >> b >> c;
	cout << b * (c / a) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    
    int N,M,X;
    int A[100];
    cin>>N>>M>>X;
    int count=0;
    for(int i=0;i<M;i++){
        cin>>A[i];
        if(A[i]<X) count++;
    }
    int cost=0;
    if(X<A[0] or A[M-1]<X){
        cout<<cost<<endl;
        return 0;
    }else if(count<M/2){
        cost=count;
        cout<<cost<<endl;
        return 0;
    }else{
        cost=M-count;
        cout<<cost<<endl;
        return 0;
    }



}

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
    os << "[";
    for (auto x : V) os << x << ", ";
    return os << "]";
}
//--------------------------------------------------//
int n;
ll a[200010];
ll dp1[200010][3];
ll dp2[200010][3];
ll ans;
int main() {
    use_cio();
    cin >> n;
    rep(i, n) cin >> a[i];
    if (n == 1) {
        cout << 0;
        return 0;
    }
    if (a[0] == 0) {
        dp1[0][0] = 0;
        dp1[0][1] = 1;
        dp1[0][2] = 2;
    } else if (a[0] % 2 == 0) {
        dp1[0][0] = a[0];
        dp1[0][1] = 1;
        dp1[0][2] = 0;
    } else {
        dp1[0][0] = a[0];
        dp1[0][1] = 0;
        dp1[0][2] = 1;
    }
    repp(i, 1, n) {
        if (a[i] == 0) {
            dp1[i][0] = dp1[i - 1][0];
            dp1[i][1] = min({dp1[i - 1][0], dp1[i - 1][1], dp1[i - 1][2]}) + 1;
            dp1[i][2] = min({dp1[i - 1][0], dp1[i - 1][2]}) + 2;
        } else if (a[i] % 2 == 0) {
            dp1[i][0] = dp1[i - 1][0] + a[i];
            dp1[i][1] = min({dp1[i - 1][0], dp1[i - 1][1], dp1[i - 1][2]}) + 1;
            dp1[i][2] = min({dp1[i - 1][0], dp1[i - 1][2]});
        } else {
            dp1[i][0] = dp1[i - 1][0] + a[i];
            dp1[i][1] = min({dp1[i - 1][0], dp1[i - 1][1], dp1[i - 1][2]});
            dp1[i][2] = min({dp1[i - 1][0], dp1[i - 1][2]}) + 1;
        }
    }
    reverse(a, a + n);
    if (a[0] == 0) {
        dp2[0][0] = 0;
        dp2[0][1] = 1;
        dp2[0][2] = 2;
    } else if (a[0] % 2 == 0) {
        dp2[0][0] = a[0];
        dp2[0][1] = 1;
        dp2[0][2] = 0;
    } else {
        dp2[0][0] = a[0];
        dp2[0][1] = 0;
        dp2[0][2] = 1;
    }
    repp(i, 1, n) {
        if (a[i] == 0) {
            dp2[i][0] = dp2[i - 1][0];
            dp2[i][1] = min({dp2[i - 1][0], dp2[i - 1][1], dp2[i - 1][2]}) + 1;
            dp2[i][2] = min({dp2[i - 1][0], dp2[i - 1][2]}) + 2;
        } else if (a[i] % 2 == 0) {
            dp2[i][0] = dp2[i - 1][0] + a[i];
            dp2[i][1] = min({dp2[i - 1][0], dp2[i - 1][1], dp2[i - 1][2]}) + 1;
            dp2[i][2] = min({dp2[i - 1][0], dp2[i - 1][2]});
        } else {
            dp2[i][0] = dp2[i - 1][0] + a[i];
            dp2[i][1] = min({dp2[i - 1][0], dp2[i - 1][1], dp2[i - 1][2]});
            dp2[i][2] = min({dp2[i - 1][0], dp2[i - 1][2]}) + 1;
        }
    }
    ans = 1e18;
    rep(i, n - 1) {
        rep(j, 3) {
            rep(k, 3) {
                ans = min(ans, dp1[i][j] + dp2[n - 2 - i][k]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 11264
#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, M, Q;
	cin >> N >> M >> Q;
	vector<ll> L(M), R(M);
	REP(i,M) cin >> L[i] >> R[i];
	vector<ll> p(Q), q(Q);
	REP(i,Q) cin >> p[i] >> q[i];

	vector<vector < ll > > LR(N+1, vector<ll>(N+1, 0));
	vector<vector < ll > > cumsum(N+2, vector<ll>(N+2, 0));

	for(int i=0; i<M; i++){
		LR[L[i]][R[i]] ++;
	}
	for(int i=1; i<N+1; i++){
		for(int j=1; j<N+1; j++){
			cumsum[i][j] = -cumsum[i-1][j-1] + cumsum[i][j-1] + cumsum[i-1][j] + LR[i][j];
		}
	}

	for(int i=0; i<Q; i++){
		cout << cumsum[q[i]][q[i]] - cumsum[p[i]-1][q[i]] - cumsum[q[i]][p[i]-1] + cumsum[p[i]-1][p[i]-1] << endl;
	}
	
	return 0;

abnormal:
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 11960
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const llint INF = 999999999999999;

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

    if (n == 1) cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxN = 100000 + 10;

int main() {
    int a , b , c;
    cin >> a >> b >> c;
    int sum = c - (a - b);
    if (sum <= 0) {
        cout << "0";
    }
    else {
        cout << sum;
    }
}


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

int main()
{
    int n;
    cin>>n;
    string s;
    int cnt=0,score=0,base=0;
    
    for(int i=0; i<n;){
        cin>>s;
        if(s=="HIT"){
            base++;
            if(base==4){
                base--;
                score++;
            }
        }
        else if(s=="HOMERUN"){
            score += base + 1;
            base = 0;
        }
        else if(s=="OUT"){
            cnt++;
        
            if(cnt==3){
                cout<<score<<endl;
                i++;
                cnt=0;
                score=0;
                base=0;
            }
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


ll N,M;
vector<ll> A;
vector<ll> S;

pair<ll,ll> f(ll x) {
	ll ans = 0, tot = 0;
	for (ll a : A) {
		auto itr = lower_bound(A.begin(), A.end(), x - a);
		ll d = distance(A.begin(), itr);
		ll c = A.size() - d;
		tot += S[A.size()] - S[d];
		tot += a * c;
		ans += c;
	}
	return pair<ll, ll>(tot, ans);
}

ll bins(ll m) {
	ll l = 0;
	ll r = 10000000;
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		ll tmp = f(mid).second;
		if (tmp >= m) l = mid;
		else r = mid;
	}
	return l;
}

ll solve(ll L) {
	auto p = f(L);
	ll ans = p.first;
	ans -= (p.second - M) * L;
	return ans;
}

int main() {
	cin >> N >> M;
	A.resize(N);
	REP(i, 0, N)cin >> A[i];
	sort(A.begin(), A.end());
	S.resize(N + 1);
	S[0] = 0;
	REP(i, 0, N) S[i + 1] = S[i] + A[i];

	auto calc = [&](int x) {
		ll tot = 0, num = 0;
		REP(i, 0, N) {
			auto itr = lower_bound(A.begin(), A.end(), x - A[i]);
			int d = distance(A.begin(), itr);
			num += N - d;
			tot += S[N] - S[d];
			tot += A[i] * (ll)(N - d);
		}
		return pair<ll, ll>(tot, num);
	};
	int l = 0, r = 10000000;
	while (l + 1 < r) {
		int c = (l + r) / 2;
		if (f(c).second >= M) l = c; else r = c;
	}
	auto p = f(l);
	ll ans = p.first;
	ans -= (p.second - M) * l;
	PRI(ans);
	return 0;
}




Measured memory_bytes: 4840
N = int(input())

iSP = []
for i in range(N):
    S, P = input().split()
    iSP.append([i + 1, S, int(P)])

iSP.sort(key = lambda x: x[2], reverse = True)    
iSP.sort(key = lambda x: x[1])

for x in iSP:
    print(x[0])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long

int N;
double p[2999];
double dp[3000][3000];

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) cin >> p[i];

  dp[0][0] = 1;
  for(int i=1; i<=N; i++) {
    dp[i][0] = dp[i-1][0] * (1-p[i-1]);
    for(int j=1; j<=N; j++) 
      dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1-p[i-1]);
  }

  double ans = 0;
  for(int i=N/2+1; i<=N; i++) ans += dp[N][i];
  printf("%.9lf\n", ans);
}


Measured memory_bytes: 70528
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 800010

char s[SIZE], t[SIZE];

/* SuffixArray (Source: 蟻本) */

//O(N log^2 N)
//pos[i] := 接頭辞の開始位置
//lcp[i] := lcp(s[pos[i]:n-1], s[pos[i-1]:n-1])
struct SuffixArray{
  vector<int> pos, lcp;
  
  SuffixArray(){}

  void build(const char *S){
    int n = strlen(S), k;
    vector<int> rank(S, S+n), tmp(n);
    auto comp = [&](const int &i, const int &j){
      if (rank[i] != rank[j]) return rank[i] < rank[j];
      return (i+k < n ? rank[i+k] : -1) < (j+k < n ? rank[j+k] : -1);
    };
    
    pos.resize(n);
    iota(pos.begin(), pos.end(), 0);
    
    for(k=1;k<n;k*=2){
      sort(pos.begin(), pos.end(), comp);
      tmp[pos[0]] = 0;
      for(int i=1;i<n;i++)
        tmp[pos[i]] = tmp[pos[i-1]] + comp(pos[i-1], pos[i]);
      for(int i=0;i<n;i++)
        rank[i] = tmp[i];
    }
    
    //LongestCommonPrefixArray
    lcp.resize(n);
    for(int i=0;i<n;i++) rank[pos[i]] = i;
    
    for(int i=0, h=0; i<n; i++) {
      if(rank[i] + 1 < n) {
        for(int j = pos[rank[i] + 1]; max(i, j) + h < n && S[i + h] == S[j + h]; h++);
        lcp[rank[i] + 1] = h;
        if(h > 0) h--;
      }
    }
  }
  
  int operator[](int k) const {
    return pos[k];
  }
};

bool nextStr(int n, char *prev, char *cur){
  for(int i=0;i<n;i++) prev[i] = cur[i];
  cur[n-1]++;
  for(int i=0;i<n-1;i++){
    if(cur[n-i-1] == 'z' + 1){
      cur[n-i-1] = 'a';
      cur[n-i-2]++;
    }
  }

  return cur[0] != 'z' + 1;
}

SuffixArray sa;


int main(){
  int n;
  int m = 0;

  scanf("%d", &n);
  
  for(int i=0;i<n;i++){
    scanf("%s", s);

    for(int j=0;s[j];j++) t[m++] = s[j];
    t[m++] = ' ';
  }

  sa.build(t);
  
  char prev[5], cur[5];
  for(int i=1;i<=4;i++){
    bool f = false;
    for(int j=0;j<i;j++) prev[j] = 'a';
    for(int j=0;j<i;j++) cur[j] = 'a';
    cur[i] = '\0';

    for(int j=0;j<m;j++){
      if(t[sa[j]] == ' ') continue;
      bool f1 = false, f2 = false, f3 = false;
      for(int k=0;k<i;k++) f1 |= t[sa[j]+k] == '\0' || t[sa[j]+k] == ' ';
      for(int k=0;k<i;k++) f2 |= t[sa[j]+k] != prev[k];
      for(int k=0;k<i;k++) f3 |= t[sa[j]+k] != cur[k];

      if(!f1 && f2 && f3){
        printf("%s\n", cur);
        return 0;
      }

      if(!f1 && !f3 && !nextStr(i, prev, cur)){
        f = true;
        break;
      }
    }

    if(!f){
      printf("%s\n", cur);
      return 0; 
    }
  }

  assert(false);
  
  return 0;
}



Measured memory_bytes: 10956
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10;

int main() {
	fast_cin();
	int n; cin >> n;
	if (__builtin_popcount(n) == 1) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	vector<pii> edges;
	edges.pb({n + 1, 3});
	for (int i = 2; i + 1 <= n; i += 2) {
		edges.pb({1, i});
		edges.pb({i, i + 1});
		edges.pb({1, n + i + 1});
		edges.pb({n + i + 1, n + i});
	}
	if (n % 2 == 0) {
		bool done = false;
		for (int i = 2; i < n; ++i) {
			if ((n ^ i ^ 1) < n) {
				int u = i, v = (n ^ i ^ 1);
				if (u % 2 == 1) {
					u += n;
				} else {
					v += n;
				}
				edges.pb({n, u});
				edges.pb({2 * n, v});
				done = true;
				break;
			}
		}
		assert(done);
	}
	for (auto &e : edges) {
		cout << e.first << ' ' << e.second << '\n';
	}
}

Measured memory_bytes: 4080
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

routes = [[] for _ in range(n)]
for i in range(m):
    routes[ab[i][0]-1].append(ab[i][1]-1)
    routes[ab[i][1]-1].append(ab[i][0]-1)

options = [i for i in range(n)]

combinations = ["0"]
for k in range(n-1):
    combinations = [i+str(j) for j in options for i in combinations if str(j) not in i]

allcount = 0
for i in range(len(combinations)):
    for j in range(n-1):
        if int(combinations[i][j+1]) not in routes[int(combinations[i][j])]:
            break
    else:
        allcount+=1

print(allcount)

Measured memory_bytes: 68776
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b;
	for(int i=0;;i++){
		if(a.size()==i)break;
		c+=a[i];
		if(b.size()==i)break;
		c+=b[i];
	}
	cout<<c<<endl;
	return 0;
}

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

using namespace std;

const int MAX_N = 1000, MAX_M = 2000, INDEX = 1;
const int MAX_C = 1000000000;
const long long INF = (long long)(MAX_N) * (long long)(MAX_C) + 1;

int n, m, a[MAX_M + INDEX], b[MAX_M + INDEX], c[MAX_M + INDEX];
long long d[2][MAX_N + INDEX];

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

    cin >> n >> m;

    for (int j = 1; j <= m; j++) {
        cin >> a[j] >> b[j] >> c[j];
    }

    for (int i = 1; i <= n; i++) {
        d[0][i] = -INF;
    }

    d[0][1] = 0;

    for (int k = 1; k <= 2 * n; k++) {
        for (int i = 1; i <= n; i++) {
            d[1][i] = d[0][i];
        }

        for (int j = 1; j <= m; j++) {
            d[1][b[j]] = min(INF, max(d[1][b[j]], d[0][a[j]] + c[j]));
        }

        for (int i = 1; i <= n; i++) {
            if (k >= n && d[1][i] > d[0][i]) {
                d[1][i] = INF;
            }

            d[0][i] = d[1][i];
        }
    }

    if (d[0][n] < INF) {
        cout << d[0][n] << endl;
    } else {
        cout << "inf" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
void debug(set<int>& s){
    cerr<<"set: ";
    for(auto x:s){
        cerr<<x<<" ";
    }
    cerr<<endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N,Q;
    cin>>N>>Q;
    vector<pair<int, pair<int, int>>> stx(N);
    rep(i,N){
        cin>>stx[i].second.first>>stx[i].second.second>>stx[i].first;
    }
    //xでソート
    sort(all(stx));
    vector<int> S(N), T(N), X(N);
    rep(i,N){
        S[i] = stx[i].second.first;
        T[i] = stx[i].second.second;
        X[i] = stx[i].first;
    }
    vector<int> D(Q), ans(Q, -1);
    set<int> set;
    map<int, int> idx;
    rep(i,Q){
        cin>>D[i];
        idx[D[i]] = i;
        set.insert(D[i]);
    }

    rep(i,N){

        auto l_itr = set.lower_bound(S[i] - X[i]);
        auto r_itr = set.lower_bound(T[i] - X[i]);
        
        while(l_itr != r_itr){
            ans[idx[*l_itr]] = X[i];
            l_itr = set.erase(l_itr);
        }/*
        while(l_itr != set.end()){
            if(*l_itr >= T[i] - X[i])break;
            ans[idx[*l_itr]] = X[i];
            set.erase(l_itr++);
        }*/
    }
    rep(i,Q){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 26880
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define pb push_back
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 60; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------
int n, m;
int a[200000];
int b[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = n - 1; i >= 0; i--) {
		b[i] = b[i + 1] + a[i];
	}
	int ok = 0, ng = 2 * 1e10, mid;
	while (ng - ok > 1) {
		mid = (ok + ng) / 2;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int k = lower_bound(a, a + n, mid - a[i]) - a;
			res += n - k;
		}
		if (res >= m) ok = mid;
		else ng = mid;
	}
	int ans = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		int k = lower_bound(a, a + n, ok - a[i]) - a;
		ans += b[k] + (n - k) * a[i];
		sum += n - k;
	}
	if (sum > m) ans -= ok * (sum - m);
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
#include<list>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int n;
int d[101], t[101];
vector<int> q[101];
int ans_prime(int p) {
    int ret = 0;
    int c = 0;
    while (c++ < p) {
        int tmp = 0;
        rep(i, n) {
            if (d[i] == p) {
                tmp += q[i][t[i]];
                t[i] = (t[i] + 1 == q[i].size() ? 0 : t[i] + 1);
            }
        }
        chmax(ret, tmp);
    }
    return ret;
}
int main() {
    while (cin >> n && n) {
        rep(i, n) { //input phase
            q[i].resize(0);
            cin >> d[i] >> t[i];
            rep(j, d[i]) {
                int q_; cin >> q_; q[i].push_back(q_);
            }
        }
        int c = 0;
        int ans = 0;
        while (c++ < 55440) {
            int tmp = 0;
            rep(i, n) {
                if (d[i] == 13 || d[i] == 17 || d[i] == 23 || d[i] == 19) continue;
                tmp += q[i][t[i]];
                t[i] = (t[i] + 1 == q[i].size() ? 0 : t[i] + 1);
            }
            chmax(ans, tmp);
        }
        ans += ans_prime(13);
        ans += ans_prime(17);
        ans += ans_prime(19);
        ans += ans_prime(23);
        cout << ans << endl;
    }
    
}



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

#define MOD (1000000000+7)

long long power( long long x, long long n )
{
	long long res = 1;
	while( n > 0 ) {
		if( n % 2 ) res = res * x % MOD;
		x = x * x % MOD;
		n /= 2;
	}
	return res;
}

int main()
{
	int N;
	cin >> N;
	vector<long long> x( N );
	for( int i = 0; i < N; i++ ) {
		cin >> x[i];
	}

	long long fac = 1;
	for( int i = 2; i < N; i++ ) {
		fac *= i;
		fac %= MOD;
	}
	vector<long long> p( N );
	p[0] = fac;
	for( int i = 1; i < N; i++ ) {
		p[i] = p[i - 1] + fac * power( i + 1, MOD - 2 ) % MOD;
		p[i] %= MOD;
	}
	long long ans = 0;
	for( int i = 0; i < N - 1; i++ ) {
		ans += (x[i + 1] - x[i]) * p[i] % MOD;
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string>
#include<iostream>
#define max 100000+5
#define nan -1
using namespace std;
struct node{int p,l,r;};
node tree[max];
int depth[max];
int n;
void print(int i);
void cal_deep(int u,int d);
int main(){
	int zi;
	scanf("%d",&n);
	for(int i=0;i<n;i++){tree[i].l=tree[i].r=tree[i].p=nan;}
	for(int i=0;i<n;i++){
		int v,d;
		scanf("%d %d",&v,&d);
		for(int j=0;j<d;j++){
		scanf("%d",&zi);
		int ne;
			if(j==0){
				tree[v].l=zi;tree[zi].p=v;
			}else{
				tree[ne].r=zi;tree[zi].p=v;
			}
			ne=zi;
		}
	}
	for(int i=0;i<n;i++){
		if(tree[i].p==nan) cal_deep(i,0);
	}
	for(int i=0;i<n;i++){
		print(i);
	}
}
void print(int i){
	string kind;
	if (tree[i].p==nan) kind="root";
	else if(tree[i].l==nan) kind="leaf";
	else kind="internal node";
	cout<<"node "<<i<<": parent = "<<tree[i].p<<", depth = "<<depth[i]<<", "
	<<kind<<", [";
	if (tree[i].l==nan) cout<<"]"<<endl;
	else{
		cout<<tree[i].l;
		int a=tree[i].l;
	while(tree[a].r!=nan){
		cout<<", "<<tree[a].r;
		a=tree[a].r;
	}
	cout<<"]"<<endl;
	}

}
void cal_deep(int u,int d){
	depth[u]=d;
	if(tree[u].l!=nan) cal_deep(tree[u].l,d+1);
	if(tree[u].r!=nan) cal_deep(tree[u].r,d);
	return;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++){
		if (s[i] == s[i + 1]){
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
}

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

int main() {
  int a, b, c, d;
  int l, r;
  
  cin >> a >> b >> c >> d;
  
  l = a + b;
  r = c + d;
  
  if (l > r) {
    cout << "Left" << endl;
  }
  else if (r == l) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using namespace std;



int main()
{


    ll n,i;

    string a,b;

    cin>>n;
    cin>>a>>b;

    for(i=0;i<n;i++)
    {
        cout<<a[i]<<b[i];
    }


    cout<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int>vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  
  int count = 0;
  
  bool exist_odd = false;
  while(true){
     for(int i = 0;i < N;i++) {
     if(vec.at(i)%2 != 0) exist_odd = true; 
    }
    
    if(exist_odd) break;
    
     for(int i = 0;i < N;i++) {
       vec.at(i) = vec.at(i)/2; 
     }
    
     count++;
  }
  
   cout << count << endl;
}
    
  

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var n, l int
  fmt.Scanf("%d %d", &n, &l)
  
  strList := make([]string, n)
  for i := 0; i < n; i++ {
    fmt.Scanf("%s", &strList[i])
  }
  
  for i := l; i > 0; i-- {
    for j := 1; j < n; j++ {
      for k := 0; k < n-j; k++ {
        if strList[k][i-1] > strList[k+1][i-1] {
          tmp := strList[k]
          strList[k] = strList[k+1]
          strList[k+1] = tmp
        }
      }
    }
  }
  
  for _, v := range strList {
    fmt.Printf("%s", v)
  }
}

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

int main() {
  string S;
  cin >> S;
  string ans = "No";
  if((S.at(2)==S.at(3)) && (S.at(4)==S.at(5))){
    ans = "Yes";
  }  
  cout << ans << endl;
}

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

int main() {
	ll a, b, c; cin >> a >> b >> c;
	ll ans = max({ a,b,c });
	ll ans2 = ans / 2;
	ll ans3 = ans - ans2;
	if (ans == a) {
		cout << ans3 * b * c - ans2 * b * c << endl;
		return 0;
	}
	else if (ans == b) {
		cout << ans3 * a * c - ans2 * a * c << endl;
		return 0;
	}
	else if (ans == c) {
		cout << ans3 * b * a - ans2 * b * a << endl;
		return 0;
	}	
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second


int ans = 10000;

bool check(vector<int>v) {
	bool fl = 0;
	for (int i = 1;i <= 8;i++) {
		if (v[i] != v[i + 1])fl = 1;
	}
	for (int i = 10;i <= 11;i++) {
		if (v[i] != v[i + 1])fl = 1;
	}
	for (int i = 13;i <= 14;i++) {
		if (v[i] != v[i + 1])fl = 1;
	}
	for (int i = 16;i <= 17;i++) {
		if (v[i] != v[i + 1])fl = 1;
	}
	for (int i = 19;i <= 20;i++) {
		if (v[i] != v[i + 1])fl = 1;
	}
	for (int i = 22;i <= 29;i++) {
		if (v[i] != v[i + 1])fl = 1;
	}
	if (!fl)return true;
	return false;
}

void bfs(vector<int>v, int cnt) {
	if (cnt > 8)return;
	vector<int>c;

	c = v;
	c[1] = v[24], c[4] = v[27], c[7] = v[30], c[24] = v[1], c[27] = v[4], c[30] = v[7], c[10] = v[21], c[21] = v[10], c[16] = v[18], c[18] = v[16];
	if (check(c)) {
		ans = min(ans, cnt);
		return;
	}
	bfs(c, cnt + 1);

	c = v;
	c[3] = v[22], c[6] = v[25], c[9] = v[28], c[22] = v[3], c[25] = v[6], c[28] = v[9], c[12] = v[19], c[19] = v[12], c[13] = v[15], c[15] = v[13];
	if (check(c)) {
		ans = min(ans, cnt);
		return;
	}
	bfs(c, cnt + 1);

	c = v;
	c[7] = v[22], c[8] = v[23], c[9] = v[24], c[22] = v[7], c[23] = v[8], c[24] = v[9], c[13] = v[18], c[18] = v[13], c[10] = v[12], c[12] = v[10];
	if (check(c)) {
		ans = min(ans, cnt);
		return;
	}
	bfs(c, cnt + 1);

	c = v;
	c[1] = v[28], c[2] = v[29], c[3] = v[30], c[28] = v[1], c[29] = v[2], c[30] = v[3], c[15] = v[16], c[16] = v[15], c[19] = v[21], c[21] = v[19];
	if (check(c)) {
		ans = min(ans, cnt);
		return;
	}
	bfs(c, cnt + 1);
}

int n, a;


int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		vector<int>v;
		v.clear();
		v.eb(0);
		for (int j = 0;j < 30;j++) {
			cin >> a;
			v.eb(a);
		}
		if (check(v)) {
			cout << 0 << endl;
			continue;
		}
		bfs(v, 1);
		cout << ans << endl;
		ans = 10000;
		v.clear();
	}
	return 0;
}


Measured memory_bytes: 3156
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

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

	int high = S / 100;
	int low = S % 100;

	if (high < 1)
	{
		if (low < 1)
			cout << "NA" << endl;
		else if (low <13)
			cout << "YYMM" << endl;
		else
			cout << "NA" << endl;
	}
	else if (high < 13)
	{
		if (low < 1)
			cout << "MMYY" << endl;
		else if (low <13)
			cout << "AMBIGUOUS" << endl;
		else
			cout << "MMYY" << endl;
	}
	else
	{
		if (low < 1)
			cout << "NA" << endl;
		else if (low <13)
			cout << "YYMM" << endl;
		else
			cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
k=int(input())
n=3
mod=10**9+7
lst=[0]*(k+1)
ans=0

for i in range(k,0,-1):
  lst[i]+=pow(k//i,n,mod)
  if k//i==1:
    continue
  else:
    for j in range(2,k//i+1):
      lst[i]-=lst[i*j]
      
for i in range(1,k+1):
  ans+=(i*lst[i])%mod
  ans%=mod
  
print(ans)

Measured memory_bytes: 62136
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;

const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {-1, 0, 1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}

ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 3e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
/*************************************************************************/

ll n;
ll k;
ll val[maxn];
map<ll,ll>hax;
void solve() {
    SLLA(n);
    SLLA(k);
    hax[0]=1;
    ll ans=0;
    REPP(i,1,n) {
        SLLA(val[i]);
        val[i] += val[i-1];
        // DE(val[i])
        if(i>=k) {
           hax[((val[i-k] - (i-k)) % k + k)%k]--;
        }
        ans += hax[((val[i] - i) % k + k)%k];
        hax[((val[i] - i) % k + k)%k]++;
        // DE(ans)
    }
    cout<<ans<<endl;
}

int main()
{
#ifndef ONLINE_JUDGE
  //freopen("i.txt", "r", stdin);
  //freopen("o.txt", "w", stdout);
#endif
  solve();
  return 0;
}





Measured memory_bytes: 14336