akhauriyash/Code-Regression huggingface dataset:
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#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 __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define MP make_pair
#define fs first
#define sc second
#define F first
#define S second
#define nl "\n"
#define asche cerr<<"Ekhane asche\n";
#define pf printf
#define sf scanf
#define mem(a,x) memset(a,x,sizeof(a))
#define SZ(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define one(x) __builtin_popcount(x)
#define fout(x) fixed<<setprecision(x)
#define BeatMeScanf ios_base::sync_with_stdio(false)
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace IO
{
    #define in() ( { int a ; scanf("%d",&a); a; } )
    #define LL() ( { ll a ; scanf("%lld",&a); a; } )
       #define ULL() ( { ull a ; scanf("%llu",&a); a; } )
    #define DD() ({ double a; scanf("%lf", &a); a;})
    #define CC() ( { char a ; scanf("%c",&a); a; } )
    #define pf1(a) printf("%d\n",a)
    #define pf1ll(a) printf("%lld\n",a)
}
using namespace IO;

const int mod=1e9+7;
const int N=3e5+9;
const double eps=1e-9;
const double PI=acos(-1.0);
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

int a[200];
int32_t main()
{
    int n=in();
    for(int i=1;i<=n;i++) a[i]=in();
    int ans=0;
    for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) ans+=a[i]*a[j];
    pf1(ans);
    return 0;
}
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 200010
#define INF 0x7fffffff
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read(){
    int w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
ll poww(ll a,int b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1)
		{
			ans=ans*base%MOD;
		}
		base=base*base%MOD;
		b>>=1;
	}
	return ans;
}
int n,k;
ll yh[MAXN],ans;
int main(){
	n=read(),k=read();
	if(k==1)
	{
		ll tmp=n;
		printf("%lld",tmp*(tmp-1));
		return 0;
	}
	yh[1]=1;
	FUP(i,2,n)
	{
		yh[i]=yh[i-1]*poww(i-1,MOD-2)%MOD*(n-i+1)%MOD;
		//cout<<yh[i]<<endl;
	}
	FUP(i,1,min(n,k+1))
	{
		ans=(ans+(yh[i]*(yh[i]+yh[i-1])%MOD)%MOD)%MOD;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#define max 101
void depth(int);
int n,count=1,m[max][max],d[max],H[max],S[max];
int main(){
  int i,j,k,u,v;
  scanf("%d",&n);
  d[0]=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      m[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    if(d[i]==0){
      depth(i);
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,H[i],S[i]);
  }
  return 0;
}

void depth(int q){
  int p;
  H[q]=count++;
  d[q]=1;
  for(p=0;p<n;p++){
    if(m[q][p]==1 && d[p]==0){
      depth(p);
    }
  }
  S[q]=count++;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <utility>
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1e9
typedef long long int ll;
using namespace std;

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

    REP(i,s.size()-8){
        cout << s[i] ;
    }

    printf("\n");

    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,n) cin >> s[i];
	sort(s.begin(), s.end());
	int ans = 1;
	rep(i,n-1) if (s[i] != s[i+1]) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9608
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for _ in range(M)]

answer=min(a)+min(b)

for i in range(M):
    if a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]<answer:
        answer=a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]

print(answer)

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

void solve() {
    string S;
    cin >> S;
    set<string> ans;
    ans.insert(S);
    for (int i = 0; i < S.length(); i++) {
        string sub1 = S.substr(0, i + 1), sub2 = S.substr(i + 1, S.length() - i - 1);
        string r_sub1 = sub1, r_sub2 = sub2;
        reverse(r_sub1.begin(), r_sub1.end());
        reverse(r_sub2.begin(), r_sub2.end());
        string sub_str1[2] = {sub1, r_sub1};
        string sub_str2[2] = {sub2, r_sub2};
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                ans.insert(sub_str1[j] + sub_str2[k]);
                ans.insert(sub_str2[k] + sub_str1[j]);
            }
        }
    }
    cout << ans.size() << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) solve();
    return 0;
}


Measured memory_bytes: 3272
package main

import "fmt"

func main() {
 var number string
 sum := 0
 fmt.Scanf("%s", &number)
  
  for _, c := range number {
    sum += int(c - '0')
  }
  
  if sum % 9 == 0 {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}


void solve(){
    int N;
    cin >> N;

    int a;
    bool truth = false;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a & 1) {
            truth = true;
            break;
        }
    }

    if (truth) {
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
from collections import deque

class Pos:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        return 'Pos(' + str(self.x) + ', ' + str(self.y) + ')'
    
    def __add__(self, other):
        return Pos(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Pos(self.x - other.x, self.y - other.y)

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def __ne__(self, other):
        return not(self.x == other.x and self.y == other.y)

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

# もともとの黒マスの数を調べる
count = 0
for y in range(H):
    for x in range(W):
        count += 1 if s[y][x] == '#' else 0

# 訪問済みリスト
visited = [[-1 for _ in range(W)] for _ in range(H)]

# 訪問予定リスト
d = deque()

visited[0][0] = 0
d.appendleft(Pos(0, 0))

while d:
    now = d.pop()
    nexts = [now+Pos(0, 1), now+Pos(0, -1), now+Pos(1, 0), now+Pos(-1, 0)]
    for next in nexts:
        x, y = next.x, next.y
        if 0 <= x < W and 0 <= y < H:
            if s[y][x] == '.' and visited[y][x] == -1:
                visited[y][x] = visited[now.y][now.x] + 1
                d.appendleft(next)

if visited[H-1][W-1] == -1:
    print(-1)
else:
    print(H*W-(visited[H-1][W-1]+1)-count)

Measured memory_bytes: 41836
p=lambda x:print(x,end=' ')
n=input();p(n+':')
n=int(n);s=n**.5;d=3
while n%2==0 and n>3:p(2);n//=2
while s>d and n>d:
 if n%d>0:d+=2
 else:p(d);n//=d
print(n)


Measured memory_bytes: 5632
from functools import lru_cache, reduce


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    # if N == 2:
    # memG = gcd(As[0], As[1])
    if N < 10:
        for i in range(N):
            tmp = As[:i] + As[i + 1 :]
            g = reduce(gcd, tmp)
            if g > memG:
                memG = g
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))


sub()


Measured memory_bytes: 32404
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int n;
ll t[400005];

void inc(int l, int r, ll v) {
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if (l & 1) t[l++] += v;
        if (r & 1) t[--r] += v;
    }
}

ll que(int x) {
    ll z = 0;
    for (x += n; x; x >>= 1) z += t[x];
    return z;
}

int main() {
    ios::sync_with_stdio(false);
    ll d, a, z = 0;
    pair<ll, ll> b[200005] = {};
    cin >> n >> d >> a;
    for (int i = 0; i < n; i++) cin >> b[i].first >> b[i].second, b[i].second = (b[i].second - 1) / a + 1;
    sort(b, b + n);
    for (int i = 0; i < n; i++) inc(i, i + 1, b[i].second);
    for (int i = 0; i < n; i++) {
        int c = (int)(lower_bound(b, b + n, make_pair(b[i].first + d + d, 1ll * mod)) - b);
        ll q = max(0ll, que(i));
        z += q;
        inc(i, c, -q);
    }
    cout << z;
}


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

int main() {
    long long N;
    cin >> N;
    N--;
    int num = 1;
    while (N >= pow(26, num)) {
        N -= pow(26, num);
        num++;
    }
    stack<int>st;
    for (int i = 0; i < num; i++) {
        st.push(N % 26);
        N /= 26;
    }
    while (!st.empty()) {
        cout << (char)(st.top()+97);
        st.pop();
    }
}

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

int main()
{
	int A, B;
	long long max = 0;
	long long ans = 1;


	map<int, int> m_a, m_b;

	cin >> A >> B;

	while (A != 1)
	{
		for (int i = 2; i <= A; i++)
		{
			if (A%i == 0)
			{
				//cout << "A=" << A << endl;
				m_a[i] += 1;
				if (max < i)max = i;
				A = A / i;
				break;
			}
		}
	}

	while (B != 1)
	{
		for (int i = 2; i <= B; i++)
		{
			if (B%i == 0)
			{
				//cout << "B=" << B << endl;
				m_b[i] += 1;
				if (max < i)max = i;
				B = B / i;
				break;
			}
		}
	}

	for (int i = 2; i <= max; i++)
	{
		/*cout << "因数" << i << "の数は" << endl;
		cout << "A" << m_a[i] << endl;
		cout << "B" << m_b[i] << endl;*/
		if (m_a[i] > 0 || m_b[i] > 0)
		{
			if (m_a[i] >= m_b[i])
			{
				ans *= pow(i, m_a[i]);
			}
			else
			{
				ans *= pow(i, m_b[i]);
			}
		}
	}

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

Measured memory_bytes: 8832
import numpy as np
n, k = list(map(int, input().split()))

def get_bound(x):
    if x < k-1:
        return [(0, x+1), (x+k+1, 2*k)]
    else:
        return [(x-k+1, x+1)]

blacks = [[0]*(2*k+1) for _ in range(2*k+1)]
for _ in range(n):
    x, y, c = input().split()
    x = int(x)%(2*k)
    y = int(y)%(2*k) if c == 'B' else (int(y)+k)%(2*k)

    for shift in [0, k]:
        for b, t in get_bound((y+shift)%(2*k)):
            for l, r in get_bound((x+shift)%(2*k)):
                blacks[b][l] += 1
                blacks[t][l] -= 1
                blacks[b][r] -= 1
                blacks[t][r] += 1
        
ans = np.max(np.cumsum(np.cumsum(blacks, axis = 1), axis = 0))
print(int(ans))


Measured memory_bytes: 106344
K = int(input())
A,B = map(int,input().split())
flag = 0
#flagはフラグ関数(Kの倍数が存在したかどうか)
for i in range(A,B+1):
#(A,B)だとA以上B-1以下までを調べてしまうので注意！！
  if i%K == 0:
    flag += 1
    print("OK")
    break
if flag == 0:
  print("NG")

Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return ans;
}

ll memop[2000000];
ll mkai(ll i){
    if(i==0){
        return 1;
    }
    if(memop[i]!=0){
        return memop[i];
    }else{
        ll ans=(mkai(i-1)*hpow(i,i_7-2))%i_7;
        memop[i]=ans;
        return ans;
    }
}

ll memok[2000000];
ll kai(ll i){
    if(i==0){
        return 1;
    }
    if(memok[i]!=0){
        return memok[i];
    }else{
        ll ans=(kai(i-1)*i)%i_7;
        memok[i]=ans;
        return ans;
    }
}

ll comb(ll n,ll k){
    ll ans=(kai(n)*mkai(k))%i_7;
    ans=(ans*mkai(n-k))%i_7;
    return ans;
}

int main(){
    ll h,w,a,b;cin>>h>>w>>a>>b;
    ll ans=0;
    rep(i,b,w-1){
        ans=(ans+(comb(h-a-1+i,h-a-1)*comb(a-1+w-1-i,a-1))%i_7)%i_7;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8192
def dfs(i,f,sum):
    if i==3:
        if sum==7:
            print(f+"=7")
            exit()
    
    else:
        dfs(i+1, f+"-"+s[i+1], sum-int(s[i+1]))
        dfs(i+1, f+"+"+s[i+1], sum+int(s[i+1]))
    
    return False
s=input()

dfs(0,s[0],int(s[0]))



Measured memory_bytes: 3060
#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, T;
    ll ans = 0;
    cin >> n >> T;
    vector<int>t(n);
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
    }
    
    for (int i = 0; i < n - 1; i++)
    {
        if (t[i+1] - t[i] > T) ans += T;
        else ans += t[i+1] - t[i];
    }
    ans += T;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//Name: Best Pizza
//Level: 2
//Category: 貪欲,Greedy
//Note:

/*
 * どのトッピングを載せても値段の増分は同じなので，最もカロリーが高いものから載せていくと最高のコストパフォーマンスになる．
 * (k個のトッピングを載せていて i(i≦k) 番目に高いものが選ばれておらず代わりに j(j>k) 番目が選ばれているとき，
 *  j番目をi番目に置換することでコストが変化しないままカロリーだけが高くなる．)
 */
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int toppings[100];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; ++i) {
        cin >> toppings[i];
    }
    sort(toppings, toppings+N, greater<int>());

    int total_cal = C, total_cost = A;
    int best = total_cal / total_cost;
    for(int i = 0; i < N; ++i) {
        total_cal += toppings[i];
        total_cost += B;
        best = max(best, total_cal / total_cost);
    }
    cout << best << endl;
    return 0;
}

Measured memory_bytes: 0
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

alias K = Tuple!(long, "t", long, "x", char, "d");

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];
    K[] ks;
    foreach (_; 0..N) {
        auto stx = readln.split.to!(long[]);
        auto S = stx[0];
        auto T = stx[1];
        auto X = stx[2];
        ks ~= K(S-X, X, 's');
        ks ~= K(T-X, X, 't');
    }
    sort!"a.t < b.t"(ks);
    auto rbt = redBlackTree!true(long.max);
    foreach (_; 0..Q) {
        auto D = readln.chomp.to!int;
        while (!ks.empty && ks[0].t <= D) {
            if (ks[0].d == 's') {
                rbt.insert(ks[0].x);
            } else {
                rbt.removeKey(ks[0].x);
            }
            ks = ks[1..$];
        }
        auto d = rbt.front;
        writeln(d == long.max ? -1 : d);
    }
}

Measured memory_bytes: 38048
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 R, G, B, N;
  std::cin >> R >> G >> B >> N;

  i64 answer = 0;
  for (i64 r = 0; r <= 3000; ++r) {
    for (i64 g = 0; g <= 3000; ++g) {
      const i64 Bb = N - R * r - G * g;
      if (Bb >= 0 && Bb % B == 0) ++answer;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int main() {
	int N; cin >> N;
	vector<vll> dp(N, vll(3, -LLINF));

	cin >> dp[0][0];
	for (int i = 1; i < N; i++) {
		char op; ll val;
		cin >> op >> val;
		if (op == '-') val = -val;
		chmax(dp[i][0], dp[i-1][0] + val);
		chmax(dp[i][1], dp[i-1][1] - val);
		chmax(dp[i][2], dp[i-1][2] + val);
		if (op == '-') {
			chmax(dp[i][1], dp[i-1][0] + val);
			chmax(dp[i][2], max(dp[i-1][1], dp[i-1][2]) - val);
		}
		chmax(dp[i][0], dp[i-1][1] + val);
	}
	cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
	return (0);
}


Measured memory_bytes: 5760
import math
K = int(input())
ans1=0
ans2=0
ans3=0
ans = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            tmp = math.gcd(a,b)
            ans1 += math.gcd(c,tmp)

for a in range(1,K):
    for b in range(a+1,K+1):
        ans2 += math.gcd(a,b)

ans3 = sum(range(1,K+1))
ans = ans1*6+ans2*3*2+ans3
print(ans)

Measured memory_bytes: 68660
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    X = II()

    while 1:
        for i in range(2, int(pow(X, 0.5))+1):
            if X % i == 0:
                break
        else:
            print(X)
            return

        X += 1



if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define drep(i,cc,n) for(int i=cc;i>n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    string s;
    int q;
    cin>>s>>q;
    int rev = 0;

    rep(i,0,q){
        int t;
        cin>>t;
        if(t == 2){
            int f;
            string c;
            cin>>f>>c;
            f--;
            if(rev == 1) f = f - 1;
            if(f == 0){
                s.insert(0,c);
            }
            else{
                s += c;
            }
        }

        else rev = 1 - rev;
    }

    if(rev == 1) reverse(s.begin(),s.end());
    
    cout<<s<<endl;

    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

LL GCD(LL x, LL y){
    LL r=0;
	if( x<y ) swap(x, y);
    r = x % y;
    while(r!=0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}

LL LCM(LL x, LL y){
	if( x<y ) swap(x, y);
    return (x/GCD(x, y))*y;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M;
	string S, T;
	cin >> N >> M;
	cin >> S;
	cin >> T;

	LL ans = -1;
	if(S[0] != T[0]){
		printf("-1\n");
	}
	else{
		LL lcm = LCM(N, M);
		LL a = lcm / N;
		LL b = lcm / M;
		LL c = LCM(a, b);
		a = c/a;
		b = c/b;
		int no = 0;
		for(int i=0, j=0; i<S.size() && j < T.size(); i+=a, j+=b){
			if(S[i] != T[j]){
				no = 1;
				break;
			}
		}
		if(no == 1){
			printf("-1\n");
		}
		else{
			ans = lcm;
			printf("%lld\n", ans);
		}
	}
	return 0;
}



Measured memory_bytes: 3916
def operate(S,A,B,C,N):
    OP = []
    for i in range(N):
        if S[i] == "AB":
            if A == 0 and B == 0:
                return -1
            else:
                if A == 1 and B == 1 and i < N-1:
                    if S[i+1] == "BC":
                        OP.append("B")
                        A,B = A-1,B+1
                    else:
                        OP.append("A")
                        A,B = A+1,B-1
                elif A >= B:
                    OP.append("B")
                    A,B = A-1,B+1
                else:
                    OP.append("A")
                    A,B = A+1,B-1
        if S[i] == "BC":
            if B == 0 and C == 0:
                return -1
            else:
                if B == 1 and C == 1 and i < N-1:
                    if S[i+1] == "AB":
                        OP.append("B")
                        B,C = B+1,C-1
                    else:
                        OP.append("C")
                        B,C = B-1,C+1
                elif B >= C:
                    OP.append("C")
                    B,C = B-1,C+1
                else:
                    OP.append("B")
                    B,C = B+1,C-1
        if S[i] == "AC":
            if A == 0 and C == 0:
                return -1
            else:
                if A == 1 and C == 1 and i < N-1:
                    if S[i+1] == "BC":
                        OP.append("C")
                        A,C = A-1,C+1
                    else:
                        OP.append("A")
                        A,C = A+1,C-1
                elif C >= A:
                    OP.append("A")
                    C,A = C-1,A+1
                else:
                    OP.append("C")
                    C,A = C+1,A-1
    return OP

def main():
    N,A,B,C = map(int,input().split())
    S = [input() for _ in range(N)]

    ans = operate(S,A,B,C,N)
    if ans != -1:
        print("Yes")
        for i in range(N):
            print(ans[i])
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 17108
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const ll Inf = 1e18;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n + 1);
  for (int i = 0; i <= n; ++i) cin >> a[i];
  vector <ll> mx(n + 2);
  for (int i = n; i >= 0; --i) {
    mx[i] += mx[i + 1];
    mx[i] += a[i];
  }
  vector <ll> mn(n + 2);
  for (int i = n; i >= 0; --i) {
    mn[i] = (mn[i + 1] + 1) / 2;
    mn[i] += a[i];
  }
  if (mn[0] > 1) {
    cout << "-1\n";
    return 0;
  }
  ll ans = 0;
  ll free = 1;
  for (int i = 0; i <= n; ++i) {
    ans += min(mx[i], free);
    free -= a[i];
    free = min(Inf, 2 * free);
  }
  cout << ans << '\n';
}



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

typedef long long ll;

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 998244353;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int i = size; i <= n; i++) {
                factorial[i] = fact(i-1) * modint(i);
            }
        }
        return factorial[n];
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    ll n, m, k;
    cin >> n >> m >> k;
    modint res = 0;
    for (ll x = n-1-k; x <= n-1; x++) {
        res += C(n-1, x) * modint::pow(m-1,x) * modint(m);
    }
    cout << res << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%2==0) cout << 0.5 << endl;
  else{
    double n2 = n;
    cout << (n2+1)/2/n2 << endl;
  }
}


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

using namespace std;

int MapData[5001][6];
int N;


void solveHori(int len, int pos) {
	bool findFirstSquare;

	for (int row = 5000; row > -1; --row) {
		findFirstSquare = false;
		for (int j = 0; j < len; ++j) {
			if (MapData[row][pos+j] == 1) {
				findFirstSquare = true;
				break;
			}
		}
		if (!findFirstSquare) {
			continue;
		}
		for (int j = 0; j < len; ++j) {
			MapData[row+1][pos + j] = 1;
		}
		return;
	}
	for (int j = 0; j < len; ++j) {
		MapData[0][pos + j] = 1;
	}
}

void solveVert(int len, int pos) {
	bool findFirstSquare;

	for (int row = 5000; row > -1; --row) {
		findFirstSquare = false;
		if (MapData[row][pos] == 1) {
			findFirstSquare = true;
		}
		if (!findFirstSquare) {
			continue;
		}
		for (int j = 0; j < len; ++j) {
			MapData[row + 1 + j][pos] = 1;
		}
		return;
	}
	for (int j = 0; j < len; ++j) {
		MapData[j][pos] = 1;
	}
}

void modifyMapData(int row) {

	for (int i = row; i < 5000; i++) {
		for (int j = 1; j < 6; j++) {
			MapData[i][j] = MapData[i + 1][j];
		}
	}
	
}

void earseMapdata() {
	int cntZero, cntOne;
	
	for (int row = 0; row < 5001; ++row) {
		cntZero = cntOne = 0;
		for (int col = 1; col < 6; ++col) {
			if (MapData[row][col] == 1) {
				++cntOne;
			}
			else {
				++cntZero;
			}
		}
		if (cntZero == 5) {
			return;
		}
		if (cntOne == 5) {
			modifyMapData(row);
			--row;
		}
	}
}

int main() {
	int d, p, q, cnt;

	while (cin >> N, N) {
		memset(MapData, 0, sizeof(MapData));
		for (int i = 0; i < N; ++i) {
			cin >> d >> p >> q;

			if (d == 1) {
				//横向き
				solveHori(p, q);
			}
			else if (d == 2) {
				//縦向き
				solveVert(p, q);
			}
			earseMapdata();
		}
		cnt = 0;
		for (int row = 0; row < 5000; ++row) {
			for (int col = 1; col < 6; ++col) {
				if (MapData[row][col] == 1) {
					++cnt;
				}
			}
		}
		cout<<cnt<<endl;
	}

	return 0;
}




Measured memory_bytes: 3188
#include<iostream>
int plusEach(int n)
{
    int sum=0,divided=10,tmp;
    for(int i=1;i<=6;i++){
        tmp=n%divided;
        tmp/=divided/10;
        sum+=tmp;
        divided*=10;
    }
    // std::cout<<std::endl<<n<<","<<sum<<std::endl;
    return sum;
}
int main(int argc, char const *argv[])
{
    int n,sum,min=9999999,a,b;
    std::cin>>n;
    for(int i=1;i<=n/2;i++){
        sum=plusEach(i)+plusEach(n-i);
        if(sum<min) min=sum;
    }
    std::cout<<min;
    return 0;
}

Measured memory_bytes: 256
import math
def gcd(a, b):
    #aとbの最大公約数を求める
    #math.gcdもしくはnp.gcdを使えばいいのだが、AtCoder上のpythonでは使えない
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        c = a % b
        return gcd(b, c)

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

def gcd_list(l):
    #リストlに対して、lの要素の最大公約数を返す
    d = l[0]
    for i in range(len(l) - 1):
        d = gcd(d, l[i + 1])
    return d

def lcm_list(l):
    #リストlに対して、lの要素の最大公倍数を返す
    m = l[0]
    for i in range(len(l) - 1):
        m = lcm(m, l[i + 1])
    return m

N = int(input())
T = [int(input()) for i in range(N)]
print(lcm_list(T))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string a,b;
int main(){
    cin >> a >> b;
    while(sz(a) != sz(b)){
        if(sz(a) > sz(b)) b = "0" + b;
        else a = "0" + a;
    }
    
    if(a > b) cout << "GREATER" << '\n';
    else if(a == b)  cout << "EQUAL" << '\n';
    else  cout << "LESS" << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n;
  int k;
  int i = 0;
  int ans = 1;
  scanf("%d",&n);
  scanf("%d",&k);
  for(i = 0;i<n;i++){
    if(ans>k){
      ans+=k;
    }else{
      ans+=ans;
    }
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
#include <stdio.h>

int	main()
{
	int	s;
	int	nb;
	int	count;

	count = 0;
	scanf("%d\n", &s);
	nb = s;
	if (s == 3)
	{
		count++;
		nb = 10;
	}
	while (nb > 4)
	{
		if (nb % 2)//odd
			nb = 3 * nb + 1;
		else //even
			nb = nb / 2;
		count++;
	}
	printf("\n");
	count += 4;
	printf("%d\n", count);
	return (0);
}

Measured memory_bytes: 128
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;

vector<ll>bitSearch(int bit,int n){
    vector<ll>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    S.push_back(1e9);
    return S;
}


int main(){
   int n;
   cin >> n;
   if(n >= 24){
      cout << 0 << endl;
      return 0;
   }
   vector<int> a(n);
   rep(i, n)cin >> a[i];
   vector<int> d(50, 0), list;

   rep(i, n){
      d[a[i]]++;
   }

   int res = 0;
   d[0]++;
   rep(i, 13){
      if(d[i] > 0)list.push_back(i);
      if(d[i] > 2 || (i % 12 == 0 && d[i] > 1)){
         cout << 0 << endl;
         return 0;
      }
   }
   
   for(int bit = 0; bit <= (1 << list.size()); bit++){
      auto S = bitSearch(bit, (int)list.size());
      auto tmp = list;
      int sz = tmp.size();
      rep(i, sz){
         int now = tmp[i];
         if(i == *lower_bound(ALL(S), i))tmp[i] = (24 - tmp[i]) % 24;
         if(d[now] == 2)tmp.push_back((24 - tmp[i]) % 24);
      }
      int dif = INF;
      sort(ALL(tmp));
      rep(i, (int)tmp.size()){
         REP(j, i + 1, (int)tmp.size() - 1){
            int t = abs(tmp[i] - tmp[j]);
            int d = min(t, 24 - t);
            chmin(dif, d);
         }
      }
      chmax(res, dif);
   }
   cout << res << endl;
}


Measured memory_bytes: 3196
def main():
    N = int(input())
    sum_N = 0
    judge_N = N

    while True:
        sum_N += (N%10)
        N = N//10
        if N == 0:
            break

    if (judge_N % sum_N) == 0:
        print('Yes')
    else:
        print('No')

main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1e9+5
#define int long long
#define LINF 1000000000000000005

int n,m,x,y,cnt[100005];

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> x >> y;
        cnt[x]++; cnt[y]++;
    }
    for(int i=1;i<=n;i++){
        if(cnt[i]%2){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";

}


Measured memory_bytes: 1024
#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 dp[3005][3005];

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 1; i <= s.size(); ++i) {
        for (int j = 1; j <= t.size(); ++j) {
            if (s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
            dp[i][j] = max(dp[i-1][j], dp[i][j]);
            dp[i][j] = max(dp[i][j-1], dp[i][j]);
        }
    }

    string ans;
    int i = s.size(), j = t.size();
    while (i>0 && j>0) {
        if (dp[i][j] == dp[i-1][j]) i--;
        else if (dp[i][j] == dp[i][j-1]) j--;
        else {
            i--; j--;
            ans.push_back(s[i]);
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

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

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

  if (weatherToday == "Sunny")
  {
    cout << "Cloudy" << endl;
  }
  else if (weatherToday == "Cloudy")
  {
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
 
n = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
from collections import defaultdict
d = defaultdict(int)
for i in range(2, n + 1):
    a = prime_factorize(i)
    for j in a:
        d[j] += 1
cnt_74 = []
cnt_2 = []
cnt_4 = []
cnt_14 = []
cnt_24 = []
for i in d:
    if d[i] >= 74:
        cnt_74.append(i)
    if d[i] >= 2:
        cnt_2.append(i)
    if d[i] >= 4:
        cnt_4.append(i)
    if d[i] >= 14:
        cnt_14.append(i)
    if d[i] >= 24:
        cnt_24.append(i)
ans = 0
ans += len(cnt_74)

for i in cnt_2:
    for j in cnt_24:
        if i != j:
            ans += 1
for i in cnt_4:
    for j in cnt_14:
        if i != j:
            ans += 1
for i in cnt_2:
    for j in range(len(cnt_4)):
        for k in range(j + 1, len(cnt_4)):
            j_ = cnt_4[j]
            k_ = cnt_4[k]
            if i != j_ and j_ != k_ and k_ != i:
                ans += 1
print(ans)
#print(d)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
#define fst first
#define snd second
  
int n, len; 

int solve(vector<pair<int, int>> & lr){
    for(auto & e : lr) swap(e.fst, e.snd);
    sort(begin(lr), end(lr));
    for(auto & e : lr) swap(e.fst, e.snd);
    
    int ret = n;
    rep(i, n){
        int cur = 1;
        int rs = lr[i].snd, frs = rs;
  
        // cout << rs << endl;

        range(_, 1, n){
            int j = (i + _) % n;
  
            int cl = lr[j].fst, cr = lr[j].snd;
            // cout << cl << " " << cr << endl;
            if(cl >= cr){
                if(cl <= rs or rs <= cr){
                    continue;
                }
                if(cl <= frs or frs <= cr){
                    continue;
                }

            }
            else {
                if(cl <= rs and rs <= cr){
                    continue;
                }
                if(cl <= frs and frs <= cr){
                    continue;
                }
            }
  
            cur++;
            rs = cr;
        }
  
        ret = min(ret, cur);
    }


    return ret;
}
  
int main(void){
    int w, h; cin >> n >> w >> h;
  
    vector<pair<int, int>> lr(n);
    len = 2 * w + 2 * h;
    for(auto & e : lr){
        int x, y; cin >> x >> y;
        y = h - y;
        char f; cin >> f;
  
        int o, p;
        switch(f){
        case 'N': o = x;                 p = y;     break;
        case 'E': o = w + y;             p = w - x; break;
        case 'S': o = 2 * w + h - x;     p = h - y; break;
        case 'W': o = 2 * w + 2 * h - y; p = x;     break;
        }
  
        e.fst = (o - p + len) % len;
        e.snd = (o + p) % len;
    }
  
    int res = solve(lr);
  
    for(auto & e : lr){
        e.fst = (len - 1) - e.fst;
        e.snd = (len - 1) - e.snd;
    }
    for(auto & e : lr) swap(e.fst, e.snd);
    res = min(res, solve(lr));
  
    cout << res << endl;
  
    return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll get_val(vector<ll>&ft,ll index)
{
  ll res=0;
  for(;index>=0;index=(index & (index+1))-1)
    res+=ft[index];
  return res;
}

void update(vector<ll>&ft,ll index,ll val)
{
  for(;index<(ll)ft.size();index|=index+1)
    ft[index]+=val;
}

ll mex(vector<ll>&a, ll n)
{
  ll res=0;
  // set<ll>st;
  vector<ll>b(n+1,0);
  for(auto x:a) b[x]++;
    while(res<n && b[res]>0) res++;
  return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    
    // Sieve();
   ll tests=1;
 // cin>>tests;
  // ll t=1;
    while(tests--)
    {
      string s,t1,t2;
      cin>>s;
      bool flag1=true,flag2=true;
      t1=s.substr(0,2);
      t2=s.substr(2,2);
      if(t1[0]>'1') flag1=false;
      if(t2[0]>'1') flag2=false;
      if(t1[0]=='0' && t1[1]=='0') flag1=false;
      if(t2[0]=='0' && t2[1]=='0') flag2=false;
      if(t1[0]=='1' && t1[1]>'2') flag1=false;
      if(t2[0]=='1' && t2[1]>'2') flag2=false;
      if(flag1 && flag2) cout<<"AMBIGUOUS";
      else if(flag1) cout<<"MMYY";
      else if(flag2) cout<<"YYMM";
      else cout<<"NA";

    }

    return 0;
   }

Measured memory_bytes: 14044
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, T;
	cin >> N >> T;
	vector<int> c(N), t(N);
	for (int i = 0; i < N; i++) {
		cin >> c.at(i) >> t.at(i);
	}
	int cost = 10000;
	for (int j = 0; j < N; j++) {
		if (t.at(j) <= T) {
			cost = min(cost, c.at(j));
		}
	}
	if (cost == 10000)cout << "TLE" << endl;
	else cout << cost << endl;
}


Measured memory_bytes: 256
function main(input) {
  const A = parseInt(input.split(" ")[0], 10);
  const B = parseInt(input.split(" ")[1], 10);
  if(A>8||B>8){
    console.log(":(");
  }else{
    console.log("Yay!");
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
//---------- begin union_find ----------
pub struct DSU {
    parent: Vec<u32>,
    size: Vec<u32>,
    stack: Vec<Option<(u32, u32)>>,
}

impl DSU {
    pub fn new(n: usize) -> DSU {
        let mut res = DSU {
            parent: vec![0; n],
            size: vec![1; n],
            stack: vec![],
        };
        res.init();
        res
    }
    pub fn init(&mut self) {
        self.stack.clear();
        for (i, (parent, size)) in self.parent.iter_mut().zip(self.size.iter_mut()).enumerate() {
            *parent = i as u32;
            *size = 1;
        }
    }
    pub fn root(&self, mut x: usize) -> usize {
        assert!(x < self.parent.len());
        while self.parent[x] != x as u32 {
            x = self.parent[x] as usize;
        }
        x
    }
    pub fn same(&self, x: usize, y: usize) -> bool {
        assert!(x < self.parent.len());
        assert!(y < self.parent.len());
        self.root(x) == self.root(y)
    }
    pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
        assert!(x < self.parent.len());
        assert!(y < self.parent.len());
        let mut x = self.root(x);
        let mut y = self.root(y);
        if x == y {
            self.stack.push(None);
            return None;
        }
        if self.size[x] < self.size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.size[x] += self.size[y];
        self.parent[y] = x as u32;
        self.stack.push(Some((x as u32, y as u32)));
        Some((x, y))
    }
    pub fn parent(&self, x: usize) -> Option<usize> {
        assert!(x < self.parent.len());
        let p = self.parent[x];
        if p != x as u32 {
            Some(p as usize)
        } else {
            None
        }
    }
    pub fn size(&self, x: usize) -> usize {
        assert!(x < self.parent.len());
        let r = self.root(x);
        self.size[r] as usize
    }
    pub fn undo(&mut self) -> Option<(usize, usize)> {
        self.stack.pop().unwrap().map(|(x, y)| {
            let x = x as usize;
            let y = y as usize;
            self.size[x] -= self.size[y];
            self.parent[y] = y as u32;
            (x, y)
        })
    }
}
//---------- end union_find ----------

use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        q: usize,
    }
    let mut u = DSU::new(n);
    for _ in 0..q {
        input! {
            op: u8,
            a: usize,
            b: usize,
        }
        if op == 0 {
            u.unite(a, b);
        } else {
            let ans = u.same(a, b) as u8;
            println!("{}", ans);
        }
    }
}

fn main() {
    run();
}


Measured memory_bytes: 6764