akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int keta(long long a){
    int ans = 0;
    while(a>0){
        a/=10;
        ans++;
    }
    return ans;
}
int main(){
    long long n;
    cin >> n;
    int ans = 11;
    for(int i = 1;i<=1e5+2;i++){
        if(n%i==0){
            ans = min(ans,max(keta(i),keta(n/i)));
        }
    }
    cout << ans << endl;
}

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

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

const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

ll f[Max], inv[Max];

ll BigMod(ll a, int e) {
        if(e == -1) {
                e = Mod - 2;
        }
        ll r = 1;
        while(e) {
                if(e & 1) {
                        r *= a, r %= Mod;
                }
                a *= a, a %= Mod, e >>= 1;
        }
        return r;
}

ll nCr(int x, int y) {
        if(x < 0 or y < 0 or x < y) {
                return 0;
        }
        return f[x] * (inv[y] * inv[x - y] % Mod) % Mod;
}

void init() {
        f[0] = 1;
        for(int i = 1; i < Max; ++i) {
                f[i] = i * 1LL * f[i - 1] % Mod;
        }
        inv[Max - 1] = BigMod(f[Max - 1], -1);
        for(int i = Max - 1; i; --i) {
                inv[i - 1] = i * 1LL * inv[i] % Mod;
        }
}

ll BigMod(ll a, ll b, ll m) {
        if(!b) {
                return 1 % m;
        }
        ll x = BigMod(a, b / 2, m);
        x = (x * x) % m;
        if(b & 1) {
                x = (x * a) % m;
        }
        return x;
}

ll cum[Max];

int main() {
#ifdef Mr_Emrul
        freopen("inputf.in", "r", stdin);
#endif /// Mr_Emrul

        ios_base::sync_with_stdio(false);
        cin.tie(0);


        init();
        ll n, m, sum = 0;
        cin >> n >> m;
        for(int i = 1; i <= n + 1; i++) {
                cum[i] = cum[i - 1] + i - 1;
        }
        for(int i = m; i <= n + 1; i++) {
                ll x = cum[i];
                ll y = cum[n + 1] - cum[n + 1 - i];
                //cout << x << " " << y << endl;
                sum += y - x + 1;
                sum %= Mod;
        }
        cout << sum << endl;
        return 0;
}

Measured memory_bytes: 36356
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = INF;
    for (int i = -100; i <= 100; i++)
    {
        int cost = 0;
        rep(j, n) cost += (i - a[j]) * (i - a[j]);
        ans = min(ans, cost);
    }
    cout << ans << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        int min = 10;
        string input = Console.ReadLine();
        int a = int.Parse(input);
        if (a % 10 != 0 && a % 10 < min) { min = a % 10; }
        if (a % 10 != 0) { a += (10 - (a % 10)); }
        input = Console.ReadLine();
        int b = int.Parse(input);
        if (b % 10 != 0 && b % 10 < min) { min = b % 10; }
        if (b % 10 != 0) { b += (10 - (b % 10)); }
        input = Console.ReadLine();
        int c = int.Parse(input);
        if (c % 10 != 0 && c % 10 < min) { min = c % 10; }
        if (c % 10 != 0) { c += (10 - (c % 10)); }
        input = Console.ReadLine();
        int d = int.Parse(input);
        if (d % 10 != 0 && d % 10 < min) { min = d % 10; }
        if (d % 10 != 0) { d += (10 - (d % 10)); }
        input = Console.ReadLine();
        int e = int.Parse(input);
        if (e % 10 != 0 && e % 10 < min) { min = e % 10; }
        if (e % 10 != 0) { e += (10 - (e % 10)); }
        Console.WriteLine(a+b+c+d+e+min-10);
    }
}


Measured memory_bytes: 11092
#include <cstdio>

int main() {
  int a[5];
  for (int i = 0; i < 5; ++i) scanf("%d", &a[i]);
  int k;
  scanf("%d", &k);
  for (int i = 0; i < 5; ++i)
    for (int j = 0; j < i; ++j)
      if (a[i] - a[j] > k)
        return puts(":("), 0;
  
  puts("Yay!");
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first    
#define se second
#define mod 1000000007
void solve()
{
    double a,b;
    cin>>a>>b;
    ll ans=ceil((b-a)/(a-1));
    cout<<ans+1;
}
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif  
    clock_t tStart = clock();
    ll t;
    // cin>>t;
    // while(t--)
       solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}       

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mergecount(vector<int> &a) {
	int count = 0;
	int n = a.size();
	if (n > 1) {
		vector<int> b(a.begin(), a.begin() + n / 2);
		vector<int> c(a.begin() + n / 2, a.end());
		count += mergecount(b);
		count += mergecount(c);
		for (int i = 0, j = 0, k = 0; i < n; ++i)
			if (k == c.size())       a[i] = b[j++];
			else if (j == b.size())  a[i] = c[k++];
			else if (b[j] < c[k])   a[i] = b[j++];
			else { a[i] = c[k++]; count += n / 2 - j; }
	}
	return count;
}
signed main() {
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	vector<int> b(N + 1);
	b[N] = 0;
	for (int i = N - 1 ; i >= 0; i--) {
		b[i] = b[i + 1] + a[i] - K;
	}
	cout << mergecount(b) << endl;
	return 0;
}

Measured memory_bytes: 6616
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
using namespace std;


#define ll long long
#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];



int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	int t = -1;
	int f = vec.size();
	while (f - t > 1) {
		int m = (t + f) / 2;

		if (vec[m] < xx) {
			t = m;
		}
		else {
			f = m;
		}
	}
	return f;
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx == 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}





signed main() {
	int n, m,a,b;
	cin >> n >> m;
	vector<pair<int, int>>vec2(m);
	vector<vector<int>>vec(n);
	rep(i, m) {
		cin >> a >> b;
		vec2[i].first = a;
		vec2[i].second = b;
		vec[a - 1].push_back(b);
	}
	rep(i, n) {
		sort(all(vec[i]));
	}
	rep(i, m) {
		printf("%06lld%06lld\n", vec2[i].first, b_s(vec[vec2[i].first - 1], vec2[i].second) + 1);
	}
}






Measured memory_bytes: 8576
#include<iostream>
#include<vector>

using namespace std;

int main(){
	short N,M,C;
	int i,j,sum,ans=0;

	cin >> N >> M >> C;
	
	vector<short> B(M);
	vector< vector<short> > A;
	A.assign(N,vector<short>(M));

	for(i=0;i<M;++i){
		cin >> B[i];
	}

	for(i=0;i<N;++i){
		sum=0;
		for(j=0;j<M;++j){
			cin >> A[i][j];
			sum+=(A[i][j]*B[j]);
		}
		sum+=C;
		if(sum>0){
			++ans;
		}
	}

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

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


int d[1000001];

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

  ++d[s];

  int a = s;
  int m = 1;
  while(true) {
    ++m;
    a = a%2==0 ? a/2 : 3*a+1;
    if(d[a] > 0) {
      break;
    }

    ++d[a];
  }

  cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

const int N = 200010;

int a[N];
int b[N];
int p[N];
int s[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k; cin >> k >> n;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	p[0] = 0;
	for(int i = 1 ; i < n ; i++) {
		b[i] = b[i] - b[i - 1];
		p[i] = a[i] - a[0];
	}
	s[n - 1] = 0;
	for(int i = n - 2 ; i >= 0 ; i--) {
		s[i] = s[i + 1] + (a[i + 1] - a[i]);
	}
	int last = k - (a[n - 1] - a[0]);
	int ret = k - last;
	for(int i = 1 ; i < n ; i++) {
		int d = s[i] + last + p[i - 1];
		ret = min(ret, d);
	}
	cout << ret;
}


Measured memory_bytes: 3328
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Array.MArray
import           Data.Array.ST
import           Data.STRef

newtype Card =
    Card String
    deriving Eq

instance Ord Card where
    compare (Card [a, b]) (Card [c, d]) = compare b d

instance Show Card where
    show (Card cs) = cs

show' :: Show a => [a] -> String
show' = unwords . fmap show

bubble :: forall a. Ord a => [a] -> [a]
bubble xs =
    runST $ do
        let n = length xs
        a <- newListArray (0, n - 1) xs :: ST s (STArray s Int a)
        forM_ [0 .. n - 1] $ \i -> do
            forM_ [n - 1,n - 2 .. i + 1] $ \j -> do
                e1 <- readArray a j
                e2 <- readArray a (j - 1)
                when (e1 < e2) $ do
                    writeArray a (j - 1) e1
                    writeArray a j e2
        getElems a

selection :: forall a. Ord a => [a] -> [a]
selection xs =
    runST $ do
        let n = length xs
        minjRef <- newSTRef 0
        a <- newListArray (0, n - 1) xs :: ST s (STArray s Int a)
        forM_ [0 .. n - 1] $ \i -> do
            writeSTRef minjRef i
            forM_ [i .. n - 1] $ \j -> do
                minj <- readSTRef minjRef
                e1 <- readArray a j
                e2 <- readArray a minj
                when (e1 < e2) $ do
                    writeSTRef minjRef j
            minj <- readSTRef minjRef
            e1 <- readArray a i
            e2 <- readArray a minj
            writeArray a minj e1
            writeArray a i e2
        getElems a

main :: IO ()
main = do
    getLine
    xs <- fmap Card . words <$> getLine :: IO [Card]
    let b = show' $ bubble xs
    let s = show' $ selection xs
    putStrLn b
    putStrLn "Stable"
    putStrLn s
    if b == s
       then putStrLn "Stable"
       else putStrLn "Not stable"



Measured memory_bytes: 4092
using System;

    class Program
    {
        static void Main(string[] args)
        {
            var O = Console.ReadLine();
            var E = Console.ReadLine();

            var pass = string.Empty;
            for(var i = 0;i<O.Length;i++)
            {
                pass += O[i];
                if(i<E.Length) pass += E[i];
            }
            Console.WriteLine(pass);
        }
    }

Measured memory_bytes: 11092
n = int(input())
nums = list(map(int, input().split()))
print(' '.join(map(str, nums)))

for i in range(1, n):
    key = nums[i]
    j = i - 1
    while j >= 0 and nums[j] > key:
        nums[j + 1] = nums[j]
        j -= 1
    nums[j + 1] = key
    print(' '.join(map(str, nums)))



Measured memory_bytes: 5596
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
    // int a,b,c;
    cin>>n;
    vi a(n);
    rep(i,0,n)
    {
        cin>>a[i];
        if(a[i]==1) pos=i;
    }
    int mn=INF;
    rep(i,0,n)
    {
        if(a[i]<mn)
        {
            count++;
            mn=a[i];
        }
    }
    cout<<count;
}
 
 
signed main()
{
   
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int n,m,k;
    cin >>  n >> m >> k;
    Graph F(n), B(n);
    UnionFind tree(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        F[a].push_back(b);
        F[b].push_back(a);
        tree.merge(a,b);
    }
    for(int i=0;i<k;i++){
        int c,d;
        cin >> c >> d;
        c--;
        d--;
        B[c].push_back(d);
        B[d].push_back(c);
    }
    for(int i=0;i<n;i++){
        int cnt = tree.size(ll(i)); 
        cnt--;
        for(auto x:F[i]){
            if(tree.issame(ll(i) ,ll(x))){
                cnt--;
            }
        }
        for(auto y:B[i]){
            if(tree.issame(ll(i),ll(y))){
                cnt--;
            }
        }
        cout << cnt << " ";

    }
    cout << endl;

}

Measured memory_bytes: 13432
from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que = deque()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if 0 <= i < h and 0 <= j < w and dist[i][j] < 0:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j))
    return dist[x][y]


h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(bfs(a))


Measured memory_bytes: 110176
#include <stdio.h>

int main(void){
  int x, y, z;
  scanf("%d%d%d", &x, &y, &z);
  int nokori = x - z;
  int ans = 0;
  int i;
  for(i = 0; nokori >= y + z; i++){
    ans++;
    nokori -= y + z;
  }
  
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
		int y = scan.nextInt();
		
		if(!(x==0&&y==0)) {
			int judge = 0;
			for(int i=0;i<=x;i++) {
				if(4*i+2*(x-i)==y) {
					judge = 1;
					break;
				}
			}
			if(judge==1) {
				System.out.print("Yes");
			}else {
				System.out.print("No");
			}
			
		}
		else {
			System.out.print("Yes");
		}
		
	}

}

Measured memory_bytes: 35616
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, q, com, x, y;

struct range_sum_query {
	// 管理したい元の配列のサイズ以上の2冪。
	int n;
	// セグメント木(完全二分木)を管理する一次元配列。
	vector<ll> segtree;
	// minの単位元としてのINF。値は2^31-1。
	const int INF = INT_MAX;

	// @param sz 管理したい元の配列のサイズ
	// nをsz以上の2冪にし、セグメント木のサイズを2*n-1、値をINFに初期化する。
	range_sum_query(int sz) {
		for (n = 1; n < sz;) n <<= 1;
		segtree.assign(2 * n - 1, 0);
	}

	int getSum(int l, int r) {
		return getSum(l, r, 0, n, 0);
	}
	int getSum(int l, int r, int a, int b, int k) {
		// [a,b)が[l,r)の外側なら、影響のない単位元INFを返す。
		if (b <= l || r <= a) return 0;

		// [a,b)が[l,r)の内側なら、その頂点は[l,r)内で最も大きい区間minを持つので、それを返す。
		else if (l <= a && b <= r) return segtree[k];

		// どちらでもなければ(解説スライドでの赤線を跨いでいる状態)、もっと細分されたものを確認する必要があるため、子を確認する。
		// 左側の子は[a,(a+b)/2)の区間minを持ち、indexは2*k+1	
		// 右側の子は[(a+b)/2,b)の区間minを持ち、indexは2*k+2
		// この２つの[l,r)内の区間minのminを返してやれば良い。
		// 現在見ている頂点が葉に該当する場合は必ず上の２つの条件のどちらかで捕捉されるため考えなくて良い。
		else return getSum(l, r, a, (a + b) / 2, 2 * k + 1) + getSum(l, r, (a + b) / 2, b, 2 * k + 2);
	}

	void add(int i, int x) {
		// 解説スライドの通り、元の配列を持つ最下段の長さをn(2冪)とすると、
		// その上のセグメント木の構造を持つ部分は n/2 + n/4 + n/8 + .. + 1 = n-1(等比級数の公式より)
		// よって、元の配列を最初に更新したいので、元の配列部分のindexに修正するため、n-1を加える。
		i += n - 1;

		// その頂点をxに更新する。
		segtree[i] += x;
		// 更新した最下段の情報の影響する範囲を更新する。
		// 具体的には更新した頂点の祖先全てが対象となる。
		while (i > 0) {
			// 親ノードへと移動
			i = (i - 1) / 2;
			// 自分の子２つを比較し、小さい方を得る。
			segtree[i] = segtree[2 * i + 1] + segtree[2 * i + 2];
		}
	}
};

int main() {
	cin >> n >> q;
	range_sum_query rsq(n);
	rep(i, q) {
		cin >> com >> x >> y;
		if (com == 0) {
			rsq.add(x - 1, y);
		}
		else {
			cout << rsq.getSum(x - 1, y) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4864
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A = ri()
B = ri()

c = set([1,2,3]) - set([A,B])
print(c.pop())


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

const int N = 4005;
typedef long long ll;

ll ans, f[N][N], res;
int n;
struct node {
	ll val;
	int pos;
} a[N];

bool cmp(node a, node b) { return a.val > b.val; }

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		cin>>a[i].val;
		a[i].pos = i;
	}
	sort(a + 1, a + n + 1, cmp);
	memset(f, -0x7f, sizeof(f));
	f[0][n + 1] = 0;
	for(int i = 1; i <= n; i++)
		for(int l = 0; l <= i; l++) {
			int r = n - i + l + 1;
			if(l >= 1)f[l][r] = max(f[l][r], f[l - 1][r] + abs(a[i].pos - l)*a[i].val);
			if(r <= n)f[l][r] = max(f[l][r], f[l][r + 1] + abs(a[i].pos - r)*a[i].val);
		}
	for(int i = 0; i <= n; i++)
		ans = max(ans, f[i][i + 1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 128972
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T>void read(T &x){
	x = 0; int f(1); char c = getchar();
	for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
	for(;isdigit(c);c = getchar()) x = x*10+c-'0';
	x *= f;
}
int main(){
	ll a,b,n;
	cin >> a >> b >> n;
	ll x = min(b-1,n);
	printf("%lld\n",a*x/b);
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = (double)w*h/2.00;
    int num =0;
    if(w==x*2&&h==y*2)num=1;
    cout << fixed<<setprecision(20);
    cout << ans<<" "<<num<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int a,b;
    int i;
    for (i=0;i<3000;i++)
    {
        scanf("%d %d",&a,&b);
        if(a==0&&b==0)
            break;
        else if (a<b)
            printf("%d %d\n",a,b);
        else
            printf("%d %d\n",b,a);
    }
    return 0;
}



Measured memory_bytes: 1900
#include <stdio.h>
int main(void){
    int a,b,c,x;
    scanf("%d%d%d%d", &a, &b, &c, &x);

    int ans = 0;
    for (int i = 0; i <= a; i++){
        for (int j = 0; j <= b; j++){
            for (int k = 0; k <= c; k++){
                if (500 * i + 100 * j + 50 * k == x){
                    ans += 1;
                } 
            }
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

void Main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    vector<int> a(n);
    rep(i, n) a[i] = i + 1;

    map<vector<int>, int> mp;
    do
    {
        mp[a] = mp.size();
    } while (next_permutation(all(a)));
    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <cmath>

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> B(N);
    for (int i=0; i<N-1; ++i) {
        std::cin >> B[i];
    }
    int sum = 0;
    if (N>2) {
        sum = B[0];
        for (int i=1; i<N-1; ++i) {
            sum += std::min(B[i-1], B[i]);
        }
        sum += B[N-2];
    } else {
        // N=2
        sum = B[0]*2;
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
import collections

n, k = map(int, input().split())
dict_ = dict()
for i in range(1, 100001):
    dict_[i] = 0
for j in range(n):
    a, b = map(int, input().split())
    dict_[a] += b

tmp = 0
for m, l in dict_.items():
    tmp += l
    if tmp >= k:
        print(m)
        break


Measured memory_bytes: 15468
#include<bits/stdc++.h>
using ll = long long;
const int INF_INT = 100000000;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second


int main()
{
    int a,b;
    std::cin >> a >> b;
    std::cout << (a == 2 || b == 2 ? "No" : "Yes") << std::endl; 
}


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

int calc(int n)
{
	int ret = 0;

	string str = to_string(n);
	for(auto c : str)
		ret += c - '0';

	return ret;
}

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

	int sum = calc(N);

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

	return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int m, d; cin >> m >> d;

  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= d; ++j) {
      int d1 = j / 10,  d2 = j % 10;
      if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) {
        //cerr << d1 << " " << d2 << '\n';
        ++cnt;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
clist = list(map(int,input().split()))

ans = 0
past = 999

for i in alist:

    if i - past == 1:
        #print(i, ans)
        ans += clist[past-1]
    #print(i, ans)
    ans += blist[i-1]
    past = i
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

void solve() {
  // main coding
  ll n; cin>>n;
  ll V=0; // num of vertex
  ll matchID[1001][1001];
  // create matchID
  rep(i,n) rep(j,n) if(i<j) {
    matchID[i][j]=V;
    V++;
  }
  // toID func
  auto toID=[&](ll i,ll j){
    if(i>j) swap(i,j);
    return matchID[i][j];
  };
  vector<vector<ll>> E(V); // V=n*(n-1)/2
  vector<ll> A(n-1);
  rep(i,n) {
    rep(j,n-1) {
      cin>>A[j];
      A[j]--; // 0-indexed
    }
    rep1(j,n-1) E[toID(i,A[j])].push_back(toID(i,A[j-1]));
  }
  // dynamic programming
  // -1: unvisited, 0: visited && uncalculated
  vector<ll> dp(V,-1);
  function<void(ll)> dfs=[&](ll v){
    if(dp[v]>0) return;
    else if(dp[v]==0) { // detection of cycle
      cout<<-1<<"\n";
      exit(0);
    }
    dp[v]=0;
    ll len=1;
    for(ll u:E[v]) { // from v to u
      if(dp[u]<=0) dfs(u);
      len=max(len,dp[u]+1);
    }
    dp[v]=len;
  };
  rep(i,V) dfs(i);
  cout<<*max_element(dp.begin(),dp.end())<<"\n";
}

int main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 39168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
ll MOD = 1e9+7;
ll MOD2 = 998244353;
int inf = 1e8;
ll INF = 1e16;
string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, A;
    cin >> N >> A;
    cout << N-A+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

const bool isPrime(const int p)
{
    if(p == 2)
    {
        return true;
    }

    if(p < 2 || p % 2 == 0)
    {
        return false;
    }

    for(int i = 3; i <= sqrt(p); i += 2)
    {
        if(p % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main(void)
{
    bool p[1000000];

    for(int i = 0; i < 1000000; ++i)
    {
        p[i] = isPrime(i);
    }

    int n;

    while(std::cin >> n)
    {
        int result = 0;

        for(int i = 0; i <= n; ++i)
        {
            result += p[i];
        }

        std::cout << result << std::endl;
    }

    return 0;
}

Measured memory_bytes: 4060
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	cin >> n;
	set<int> s;
	bool isDiff = true;
	for (int i = 0; i < n;i++) {
		int a;
		cin >> a;
		if (s.find(a) == s.end()) {
			s.insert(a);
		}
		else {
			isDiff = false;
			
		}

		
	}

	cout << (isDiff ? "YES" : "NO") << endl;
}





Measured memory_bytes: 9600
#include<cstdio>
#include<algorithm>
using namespace std;
struct f{
	long long int a,b;
}a[1000000];
bool cmp(f e,f d)
{
	return e.a<d.a;
}
int main()
{
	int i;long long int s=0,m,n;
	scanf("%lld%lld",&n,&m);
	for(i=0;i<n;i++)
	scanf("%lld%lld",&a[i].a,&a[i].b);
	sort(a,a+n,cmp);
	for(i=0;i<n;i++)
	{
		if(m>a[i].b)
		{ 
			m-=a[i].b;
			s+=a[i].b*a[i].a;
		}
		else
		{    
			s+=m*a[i].a;
			break;
		}
	}
	printf("%lld\n",s);
	
}

Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import math
import numpy as np

N = int(input())

An = np.array(input().split(" "), dtype=np.int)

out = 1

for ai in An:
    if ai % 2 == 0:
        if ai % 3 == 0 or ai % 5 == 0:
            pass
        else:
            out = 0

if out == 1:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 21388
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long

int main(){
	ll n;
	cin >> n;
	ll outa, outb;
	outa=outb= 0;
	for (int i = 0; i < n; ++i){
		ll a, b;
		cin >> a >> b;
		if (outa == 0 && outb == 0){
			outa = a;
			outb = b;
			continue;
		}
		ll tmpa=a, tmpb=b;
		ll tmp = 1;
		if (outa%tmpa==0){
			tmp = outa / tmpa;
		}
		else{
			tmp = outa / tmpa + 1;
		}
		if (outb%tmpb==0){
			tmp = max(tmp, outb / tmpb);
		}
		else{
			tmp = max(tmp, outb / tmpb + 1);
		}
		outa = tmpa*tmp;
		outb = tmpb*tmp;
		//cout <<tmp<<" "<< outa + outb << endl;
	}
	cout << outa+outb<< endl;
	return 0;
}

Measured memory_bytes: 256
dhw = [(1,0),(0,-1),(0,1),(-1,0),
( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2),
( 1,-2),( 1,-1),        ( 1, 1),( 1, 2),
( 0,-2),                        ( 0, 2),
(-1,-2),(-1,-1),        (-1, 1),(-1, 2),
(-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)]

H, W = map(int, input().split())
sh, sw = map(lambda x:int(x)-1, input().split())
eh, ew = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(H)]

dst = [[-1]*W for _ in range(H)]
dst[sh][sw] = 0

from collections import deque
dq = deque([(sh, sw)])
while dq:
    h, w = dq.popleft()

    for i in range(4):
        nh = h + dhw[i][0]; nw = w + dhw[i][1]
        if nh < 0 or H <= nh : continue
        if nw < 0 or W <= nw : continue
        if S[nh][nw] == '#': continue
        if dst[nh][nw] == -1 or dst[h][w] < dst[nh][nw]:
            dst[nh][nw] = dst[h][w]
            dq.appendleft((nh, nw))

    for i in range(4, 24):
        nh = h + dhw[i][0]; nw = w + dhw[i][1]
        if nh < 0 or H <= nh : continue
        if nw < 0 or W <= nw : continue
        if S[nh][nw] == '#': continue
        if dst[nh][nw] >= 0: continue
        if dst[nh][nw] == -1 or dst[h][w] + 1 < dst[nh][nw]:
            dq.append((nh, nw))
            dst[nh][nw] = dst[h][w] + 1

print(dst[eh][ew])


Measured memory_bytes: 89336
N = gets.to_i
S = gets.chomp.chars

r = []
g = []
b = []
S.each_with_index{|s, i|
  r << i if s == 'R'
  g << i if s == 'G'
  b << i if s == 'B'
}
ans = 0
b_s = b.size
r.product(g){|w|
  w.sort!
  ans += b_s
  wk = w[1] - w[0]
  ans -= 1 if wk.even? && S[w[0] + wk/2] == 'B'
  ans -= 1 if w[0] - wk >= 0 && S[w[0] - wk] == 'B'
  ans -= 1 if w[1] + wk < N && S[w[1] + wk] == 'B'
}

puts ans


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

using namespace std;
using ll = long long;

const ll INF = 1LL << 60;

struct edge {
    ll from, to, cost;
};

bool bellman_ford(const int v, const int s, vector<edge> es, vector<ll>& dist) {
    vector<ll> d(v, INF);
    d[s] = 0;
    bool neg_loop = false;
    for(ll cnt=0; ;cnt++) {
        bool update = false;
        for(auto& e : es) {
            if(d[e.from] == INF) continue;
            if(d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
                
                if(cnt >= v-1 && e.to == v-1) return true;
            }
        }

        if(!update) break;
        
        if(cnt >= v-1) {
            //neg_loop = true;
            neg_loop = false;
            break;
        }
    }

    dist = std::move(d);
    return neg_loop;
}

int main(void){
    ll N, M;
    cin >> N >> M;
    vector<edge> es;
    for(int i=0;i<M;i++){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        es.push_back(edge{a, b, -c});
    }

    vector<ll> dist;
    bool  loop = bellman_ford(N, 0, es, dist);

    if(loop) {
        cout << "inf" << endl;
    } else {
        cout << -dist[N-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
def f(s):
    cnt = 0
    st = set()

    cnt += 1
    st.add(s)

    while True:
        cnt += 1

        if s % 2 == 0:
            tmp = s / 2
        else:
            tmp = 3 * s + 1

        if tmp in st:
            break

        st.add(tmp)
        s = tmp
    return cnt


s = int(input())
ans = f(s)
print(ans)


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    for (auto &p : P)
        cin >> p;

    vector<int> C(N + 1);
    for (int p : P)
    {
        C[p] = C[p - 1] == 0 ? 1 : C[p - 1] + 1;
    }

    cout << N - *max_element(C.begin(), C.end())
         << endl;

    return 0;
}


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

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

Measured memory_bytes: 3632
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        n:usize,q:usize,
        a:[(Usize1,Usize1);q],
    }

    let mut table = vec![0_usize; n];
    table[0] = 1;
    table[1] = 2;

    for (i, j) in a {
        table.swap(i, j);
        let mut v = vec![i, j];
        if i != 0 {
            v.push(i - 1);
        }
        if j != 0 {
            v.push(j - 1);
        }
        if i + 1 < n {
            v.push(i + 1);
        }
        if j + 1 < n {
            v.push(j + 1);
        }
        for k in v {
            if table[k] == 1 {
                if k + 1 < n && table[k + 1] == 0 {
                    table[k + 1] = 2;
                }
                if k > 0 && table[k - 1] == 0 {
                    table[k - 1] = 2;
                }
            }
        }
    }
    println!("{}", table.iter().filter(|&&x| x != 0).count());
}


Measured memory_bytes: 5744
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    VI t = {1,3,1,2,1,2,1,1,2,1,2,1};
    int x,y;
    cin >> x >> y;
    if (t[x-1] == t[y-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void init(int *cnt) {
    for (int i=0; i<3; i++) cnt[i]=0;
}
int me(int *cnt) {
    int res=INT_MAX;
    for(int i=0; i<3; i++) res=min(res,cnt[i]);
    return res;
}
bool isok(int *cnt) {
    if (cnt[0]>=cnt[1]&&cnt[1]<=cnt[2]) return true;
    return false;
}
int cnt[3];
int main() {
    string in;
    cin>>in;
    int res=0;
    char flag='*';
    for (int i=0; i<in.length(); i++) {
        if (flag=='*'&&in[i]=='J') {  // J task start
            init(cnt);
            flag='J';
            cnt[0]++;
        } else if (flag=='I'&&in[i]=='J') {
            if (isok(cnt)) res=max(res,me(cnt));
            flag='J';
            init(cnt);
            cnt[0]++;
        } else if (flag=='J'&&in[i]=='J') {
            flag='J';
            cnt[0]++;
        } else if (flag=='O'&&in[i]=='J') { // J task end
            flag='J';
            init(cnt);
            cnt[0]++;
        } else if (flag=='J'&&in[i]=='O') { // O task start
            flag='O';
            cnt[1]++;
        } else if (flag=='O'&&in[i]=='O') {
            flag='O';
            cnt[1]++;
        } else if (flag=='I'&&in[i]=='O') { // O task end
            if (isok(cnt)) res=max(res,me(cnt));
            flag='*';
        } else if (flag=='O'&&in[i]=='I') { // I task start
            flag='I';
            cnt[2]++;
        } else if (flag=='I'&&in[i]=='I') {
            flag='I';
            cnt[2]++;
        } else if (flag=='J'&&in[i]=='I') { // I task end
            flag='*';
        }
        // for (int j=0; j<3; j++) printf("%d%c",cnt[j],j==2?'\n':' ');
   }
   if (flag=='I'&&isok(cnt)) res=max(res,me(cnt));
   printf("%d\n",res);
}

Measured memory_bytes: 1984
#include<iostream>
#include<map>
#include<set>
#define LIM 1000000
using namespace std;
map<int,long long>data;
set<int>used;
int main(){
	int n;
	while(cin>>n && n){
		used.clear();
		data.clear();
		bool update=false;
		for(int i=0;i<n;i++){
			int id;
			cin>>id;
			long long  ans;
			cin>>ans;
			int tmp;
			cin>>tmp;
			ans*=tmp;
			data[id]+=ans;
			if(data[id]>=LIM &&used.find(id)==used.end()){
				update=true;
				cout<<id<<endl;
				used.insert(id);
			}
		}
		if(!update)cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1292
from fractions import gcd

def calc(A, B, x):
    n1 = (A - 1) // x
    n2 = B // x
    return n2 - n1

A, B, C, D = map(int, input().split())
E = C * D // gcd(C, D)
ans = B - A + 1 - calc(A, B, C) - calc(A, B, D) + calc(A, B, E)
print(ans)

Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int inf=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int N;
struct segtree{
	//
	vector<pair<int,int> > dat;
	//
	segtree(int n_){
		init(n_);
	}
	//
	void init(int n_){
		N=1;
		while(N<n_){
			N*=2;
		}
		dat=vector<pair<int,int> >(N*2-1,make_pair(2147483647,-1));
	}
	//
	void update(int k,int a){
		k+=N-1;
		dat[k]=make_pair(a,k);
		while(k){
			k=(k-1)/2;
			if(dat[k*2+1].first<=dat[k*2+2].first){
				dat[k]=dat[k*2+1];
			}else{
				dat[k]=dat[k*2+2];
			}
		}
	}
	//[a,b)
	pair<int,int> query(int a,int b,int k=0,int l=0,int r=-1){
		if(r==-1){
			r=N;
		}
		if(r<=a||b<=l){
			return make_pair(2147483647,-1);
		}else if(a<=l&&r<=b){
			return dat[k];
		}else{
			pair<int,int> va=query(a,b,k*2+1,l,(l+r)/2);
			pair<int,int> vb=query(a,b,k*2+2,(l+r)/2,r);
			if(va.first<=vb.first){
				return va;
			}else{
				return vb;
			}
		}
	}
	//
};
//
struct BIT{
	//
	int n;
	vector<int> dat;
	//
	BIT(int n_){
		init(n_);
	}
	//
	void init(int n_){
		n=n_;
		dat.resize(n+1,0);
	}
	//
	void add(int k,int a){
		k++;
		while(k<=n){
			dat[k]+=a;
			k+=k&-k;
		}
	}
	//[0,k]
	int query(int k){
		k++;
		int res=0;
		while(k){
			res+=dat[k];
			k-=k&-k;
		}
		return res;
	}
	//
};
//
int main(){
	string S;int K;
	cin>>S>>K;
	K++;
	int L=S.size();
	segtree seg(L);
	BIT bit(L);
	FOR(i,0,L){
		seg.update(i,S[i]-'a');
		bit.add(i,1);
	}
	queue<char> ans;
	while(K){
		int l=0,r=L-1;
		while(r-l>1){
			int m=(l+r)/2;
			if(bit.query(m)<K){
				l=m;
			}else{
				r=m;
			}
		}
		pair<int,int> h=seg.query(0,(L<=r?L:r+1));
		ans.push('a'+h.first);
		seg.update(h.second-(N-1),2147483647);
		bit.add(h.second-(N-1),-1);
		K-=bit.query(h.second-(N-1));
		if(bit.query(L-1)==0){
			break;
		}
	}
	vector<char> ret;
	while(!ans.empty()){
		ret.push_back(ans.front());
		ans.pop();
	}
	int mm=ret.size();
	FOR(i,0,L){
		if(i==0&&bit.query(0)==1){
			ret.push_back(S[i]);
		}else if(i!=0&&bit.query(i)-bit.query(i-1)==1){
			ret.push_back(S[i]);
		}
	}
	while(K<=0){
		swap(ret[mm-1],ret[mm]);
		mm++;
		K++;
	}
	FOR(i,0,ret.size()){
		cout<<ret[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 11352
#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 main() {
  char a;
  cin >> a;
  if (isupper(a))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }

  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){

    int N,i,j,k,L[2001],s,ans=0;

    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d",&L[i]);
    }

    qsort(L,N,sizeof(int),compare_int);

    for(i = 0;i < N;i++){
        for(j = i + 1;j < N;j++){
            for(k = j + 1;k < N;k++){
                if(L[i] + L[j] > L[k]){
                    ans++;
                }else{
                    break;
                }
            }
        }
    }

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 +7;
const int N = 100100;



int main(){

int n , k ;
cin>>n>>k;

ll ans=0;
if( n >=k ){
ll y = 1 + ( n-k )/k;
ans += y*y*y;
}

if( k%2==0 && n >= k/2 ){
    ll x = 1 + ( n-k/2 )/k;
    ans += x*x*x;
}
cout<< ans <<endl;

return 0;
}


Measured memory_bytes: 256