akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
typedef long long ll;
typedef pair<ll, ll> P;
typedef unsigned long long ull;
const int INF = 2e9;
const int mod = 1e9 + 7;
const int N = 1010;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int h, w, ch, cw, dh, dw;
char s[N][N];
bool mark[N][N];
int warp[N][N];
void dfs(int x, int y)
{
    //cout << x << " " << y << " " << warp[x][y] << '\n';

    if (x == dh && y == dw)
        return;

    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    bool flag = false;
    rep(i, 0, 4)
    {
        int xx = x + dx[i], yy = y + dy[i];
        if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && s[xx][yy] == '.')
        {
            if (!mark[xx][yy])
            {
                flag = true;
                mark[xx][yy] = true;
                warp[xx][yy] = warp[x][y];
                dfs(xx, yy);
            }
            else
            {
                if (warp[x][y] < warp[xx][yy])
                {
                    warp[xx][yy] = warp[x][y];
                    dfs(xx, yy);
                }
            }
        }
    }

    int wx[] = {1, -1, 1, -1}, wy[] = {-1, 1, 1, -1};
    rep(i, 0, 3)
    {
        rep(j, 0, 3)
        {
            rep(k, 0, 4)
            {
                int xx = x + wx[i] * i, yy = y + wy[i] * j;
                if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && s[xx][yy] == '.')
                {
                    if (!mark[xx][yy])
                    {
                        flag = true;
                        mark[xx][yy] = true;
                        warp[xx][yy] = warp[x][y] + 1;
                        dfs(xx, yy);
                    }
                    else
                    {
                        if (warp[x][y] + 1 < warp[xx][yy])
                        {
                            warp[xx][yy] = warp[x][y] + 1;
                            dfs(xx, yy);
                        }
                    }
                }
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin >> h >> w;
    // cin >> ch >> cw;
    // cin >> dh >> dw;
    // rep(i, 1, h + 1)
    // {
    //     string in;
    //     cin >> in;
    //     rep(j, 1, w + 1)
    //     {
    //         s[i][j] = in[j - 1];
    //     }
    // }
    // mark[ch][cw] = true;
    // dfs(ch, cw);
    // if (mark[dh][dw])
    //     cout << warp[dh][dw] << endl;
    // else
    //     cout << -1 << endl;

    int n;
    cin >> n;
    int a[n];
    rep(i,0,n)
    {
        cin >> a[i];
    }
    ll ans = 0;
    rep(i,1,n)
    {
        if(a[i] < a[i-1])
        {
            int t = a[i-1] - a[i];
            a[i] += t;
            ans += t;
        }

    }

    cout << ans << endl;



    

    return 0;
}

Measured memory_bytes: 4392
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		selectionSort(a, n);
	}

	static void selectionSort(int[] a, int n) {
		int cnt = 0;
		for(int i = 0 ; i < n ; i++) {
			int minj = i;
			for(int j = i ; j < n ; j++) {
				if(a[minj] > a[j]) {
					minj = j;
				}
			}
			if(a[minj] < a[i]) {
				int v = a[i];
				a[i] = a[minj];
				a[minj] = v;
				cnt++;
			}
		}
		for(int i = 0 ; i < n ; i++) {
			if(i != n - 1) {
				System.out.print(a[i] + " ");
			} else {
				System.out.println(a[i]);
			}
		}
		System.out.println(cnt);
	}

}

Measured memory_bytes: 26428
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]): Unit ={
    B.answer()
  }
}
object B {
  def input[A](change: String => A) = readLine.split(" ").map(change(_))
  def answer(): Unit ={
    val a = input((a=>a.toInt))
    val x = a(2)
    val y = a(3)
    val maxX = (input((a=>a.toInt)) :+ x).sortBy(a=>a).last
    val minY = (input((a=>a.toInt)) :+ y).sortBy(a=>a).head
    if(maxX >= minY) {
      println("War")
    } else {
      println("No War")
    }
  }
}

Measured memory_bytes: 25648
S=input()
T=input()


num_same_all = 0
for i in range(len(S)-len(T)+1):
    num_same = 0
    for j in range(len(T)):
        if S[j+i] == T[j]:
            num_same += 1
    
    if num_same_all < num_same:
        num_same_all = num_same

print(len(T)-num_same_all)

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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    ll n;
    cin >> n;
    ll a[n];
    map<ll, ll> mp;
    ll sum = 0;
    for(ll i = 0; i<n; i++) {
        cin >> a[i];
        mp[a[i]] ++;
        sum += a[i];
    }
    ll q;
    cin >> q;
    while(q--) {
        ll x, y;
        cin >> x >> y;
        sum -= (mp[x] * x);
        sum += (mp[x] * y);
        mp[y] += mp[x];
        mp[x] = 0;
        cout << sum << '\n';
    }
}

int main() {
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}

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

int main() {
    map<int,int> mp;
    int a;

    for (int i = 0; i < 6; i++)
    {
        cin >> a;
        mp[a]++;
        if (mp[a] >= 3)
        {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}

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

using namespace std;
typedef long long ll;

const int N=200005;
vector<ll> tree(4*N,0);
vector<int> lazy(4*N,0);
const ll mod=998244353;
vector<ll> pw(N,1);
vector<ll> sum(N,1);

void push(int idx,int l,int r,int m)
{
    if(lazy[idx]!=0)
    {
        tree[2*idx]=(sum[m-l]*lazy[idx])%mod;
        tree[2*idx+1]=(sum[r-(m+1)]*lazy[idx])%mod;
        lazy[2*idx]=lazy[2*idx+1]=lazy[idx];
        lazy[idx]=0;
    }
}

void update(int idx,int l,int r,int ql,int qr,int val)
{
    if(ql>qr) return;
    if(l==ql&&r==qr)
    {
        tree[idx]=(val*sum[r-l])%mod;
        lazy[idx]=val;
    }
    else
    {
        int m=(l+r)/2;
        push(idx,l,r,m);
        update(2*idx,l,m,ql,min(qr,m),val);
        update(2*idx+1,m+1,r,max(ql,m+1),qr,val);
        tree[idx]=(pw[r-(m+1)+1]*tree[2*idx]+tree[2*idx+1])%mod;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    for(int i=1;i<=n;i++)
    {
        pw[i]=(10*pw[i-1])%mod;
        sum[i]=(sum[i-1]+pw[i])%mod;
    }
    update(1,1,n,1,n,1);
    while(q--)
    {
        int l,r,d;
        cin >> l >> r >> d;
        update(1,1,n,l,r,d);
        cout << tree[1] << "\n";
    }
    return 0;
}


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

using namespace std;

int dig(int a) {
    int ret = 0;
    while (a) {
        ret += a%10;
        a /= 10;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    int best = 1e9;
    for (int a = 1; a < n; a++) {
        int b = n - a;
        int sum = dig(a) + dig(b);
        best = min(best, sum);
    }
    cout << best << endl;
}

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

int main() {
    int x,a,b;
    int da,db;
    cin>>x>>a>>b;
    da=abs(x-a);
    db=abs(x-b);
    if(da<db)cout <<"A"<<endl;
    else cout <<"B"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    string x,y;
    cin>>x>>y;
    int n=x.length(),m=y.length();
    int dp[n+1][m+1];
    for(int i=0;i<n+1;i++)
        dp[i][0]=0;
    for(int j=0;j<m+1;j++)
        dp[0][j]=0;
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<m+1;j++)
        {
            if(x[i-1]==y[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans="";
    int i=n,j=m;
    while(i>0&&j>0)
    {
        if(x[i-1]==y[j-1])
        {
            ans+=x[i-1];
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
	return 0;
}

Measured memory_bytes: 38732
import sys
input=sys.stdin.readline
#s=input()
#l=list(map(int,input().split()))
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
A.sort(reverse=True)
for i in range(N):
    if A[0]==B[i]:
        print(A[1])
    else:
        print(A[0])


Measured memory_bytes: 64996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    cin>>x>>y;
    if(x==y){
        cout<<1<<endl;
        return 0;
    }
    ll ans=0;
    ll now=2*x;
    if(2*x<=y){
        ans=2;
        now*=2;
        //cout<<now<<'\n';
    }
    while(now<=y){
        ans++;
        now*=2;
        //cout<<now<<'\n';
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>
#include<math.h>

using namespace std;
#define rep(i, n) for ( int i = 0; i < ( int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < ( int)(n); i++)

int main() {

	long long int x, k, d, t, ans;
	cin >> x >> k >> d;
	x = abs(x);
	t = x / d;
	if (t >= k) {
		ans = x - k * d;
		
	}
	else {
		ans = abs(x - t * d - d * ((k - t) % 2));

	}
	cout << ans << endl;
	return 0;
}
//解説みた

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

int main(){
    int a,b;
    char s[2];
    while(true){
        cin>>a>>s[0]>>b;
        if(s[0]=='?')break;
        else{
            if(s[0]=='+')cout<<a+b<<endl;
            else if(s[0]=='-')cout<<a-b<<endl;
            else if(s[0]=='*')cout<<a*b<<endl;
            else cout<<a/b<<endl;
        }
    }
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  } else if (A + B < C + D) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    s=readline().strip()

    ans=[]
    flag=False
    i=n
    while True:
        max_i=i
        for sa in range(1,m+1):
            if i-sa==0:
                ans.append(sa)
                flag=True
                break
            else:
                if s[i-sa]=="0":
                    max_i=i-sa
        if flag: break
        else:
            if max_i!=i:
                ans.append(i-max_i)
                i=max_i
            else:
                break

    if flag:
        ans.reverse()
        print(*ans)
    else:
        print(-1)

if __name__=="__main__":
    main()

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


def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = float('inf')

    # KeyInsight:
    # xの座標の最小値から最大値までを探索すればよい
    # See: https://img.atcoder.jp/abc156/editorial.pdf
    left = min(x)
    right = max(x)

    for p in range(left, right + 1):
        summed = 0

        for xi in x:
            summed += (xi - p) ** 2

        ans = min(ans, summed)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100, MAX_K = 100;

int n, u, k, v[MAX_K];

vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
int t = 0;

void dfs(int);

int main() {
    // input
    cin >> n;
    REP(i, n) {
        cin >> u >> k;
        u--;
        REP(j, k) {
            cin >> v[j];
            v[j]--;
            G[u].PB(v[j]);
        }
    }

    // init d
    REP(i, n) d[i] = -1;

    // dfs
    REP(i, n) {
        if (d[i] == -1) dfs(i);
    }

    // output
    REP(i, n) {
        int id = i + 1;
        printf("%d %d %d\n", id, d[i], f[i]);
    }

    return 0;
}

void dfs(int pos) {
    d[pos] = ++t;
    REP(i, G[pos].size()) {
        int to = G[pos][i];
        if (d[to] != -1) continue;
        dfs(to);
    }
    f[pos] = ++t;
    return;
}


Measured memory_bytes: 3276
from itertools import product
import numpy as np

N, M, X = map(int, input().split())

C = [None] * N
A = [None] * N
for i in range(N):
    inp = list(map(int, input().split()))
    C[i] = inp[0]
    A[i] = inp[1:]

C = np.array(C)
A = np.array(A)
ans = C.sum() + 1

for choices in product((True, False), repeat=N):
    choices = np.array(list(choices), dtype=bool)
    if np.all(A[choices, :].sum(axis=0) >= X):
        ans = min(ans, C[choices].sum())

if ans == C.sum() + 1:
    print(-1)
else:
    print(ans)


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

#define y1 as214
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back
#define t top()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , n) for(int i = 0 ; i < n ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define ll long long
#define oo 1e17
#define int long long

const int maxn = 3e3 + 5;
int n;
int dp[maxn][maxn];
char f1[maxn] , f2[maxn];

void tr(int x , int y)
{
    if(x != 0 && y != 0)
    {
        if(dp[x][y] == dp[x - 1][y])
            tr(x - 1 , y);
        else if(dp[x][y] == dp[x][y - 1])
            tr(x , y - 1);
        else
        {
            tr(x - 1 , y - 1);
            cout << f1[x];
        }
    }
}

main()
{
    //freopen("F.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> f1;
    cin >> f2;
    int x = strlen(f1);
    int y = strlen(f2);
    FORD(i , x , 1)
        f1[i] = f1[i - 1];
    FORD(i , y , 1)
        f2[i]= f2[i - 1];
    FOR(i , 1 , x)
        FOR(j , 1 , y)
            {
                if(f1[i] == f2[j])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
            }
    tr(x , y);
}


Measured memory_bytes: 70784
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int a, b, c, x, y, t = 0, ab;
    cin >> a >> b >> c >> x >> y;

    if( a + b >= 2 * c ){
        if (y < x)ab = y, x -= ab, y -= ab;
        else ab = x, x -= ab, y -= ab;
        t += 2 * c * ab;

        if(y > x)swap(a,b),swap(x,y);

        if( a <= 2 * c) t += a * x;
        else t += 2 * c * x;
    }else{
        t += a * x + b * y;
    }
    cout << t;

}


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

int main()
{
    int n;
    int ans = 0;
    cin >> n;
    map<int, long long> s;
    for (int i = 0; i < n; i++)
    {
        long long l;
        cin >> l;
        s[i] = l;
    }
    for (auto x1 : s)
    {
        for (auto x2 : s)
        {
            if (x1.second != x2.second)
            {
                for (auto x3 : s)
                {
                    if (x1.second != x3.second && x2.second != x3.second && x1.second + x2.second > x3.second && x2.second + x3.second > x1.second && x1.second + x3.second > x2.second)
                    {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans / 6 << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define pb push_back
#define pob pop_back
#define __bp __builtin_popcount
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pdd = pair<ld,ld>;
using vint = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
#define F first
#define S second
const int N = 1e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const ll INF = 1e18+7;
const int Mod = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(7) << fixed;
}

int n, m;

void solve()
{
	string s;
	cin >> s;
	int sm = 0;
	for (char c: s)
	{
		sm += c - '0';
	}
	cout << (sm % 9 ? "No": "Yes");
}

signed main()
{
	io();
	int tt = 1;
//	cin >> tt;
	while (tt--)
		solve();
}
//overflows!!!

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int root = 0;
vector<vector<int> > g, parent;
vector<int> depth, deg, rev, leaf;
vector<bool> used;
vector<P> es;

void dfs(int v, int p, int d){
    parent[0][v] = p;
    depth[v] = d;
    used[v] = true;
    for(auto u : g[v]){
        if(used[u]) continue;
        dfs(u, v, d+1);
    }
}

void init(){
    int n = g.size();
    parent.resize(31, vector<int>(n));
    depth.resize(n);
    used.resize(n);
    dfs(root, -1, 0);
    for(int k=0;k<30;k++){
        for(int i=0;i<n;i++){
            if(parent[k][i] < 0) parent[k+1][i] = -1;
            else parent[k+1][i] = parent[k][parent[k][i]];
        }
    }
}

int lca(int u, int v){
    if(depth[u] > depth[v]) swap(u, v);
    for(int k=0;k<30;k++){
        if(((depth[v] - depth[u]) >> k) & 1){
            v = parent[k][v];
        }
        if(u == v) return u;
    }
    for(int k=29; k>=0; k--){
        if(parent[k][u] != parent[k][v]){
            u = parent[k][u];
            v = parent[k][v];
        }
    }
    return parent[0][u];
}

void dfs2(int v){
    for(auto u : g[v]){
        if(parent[0][u] == v){
            dfs2(u);
            rev[v] += rev[u];
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    g.resize(n);
    deg.resize(n);
    rev.resize(n);
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        es.push_back(P(a,b));
        deg[a]++;
    }
    if(m%2){
        cout << -1 << endl;
        return 0;
    }
    init();
    vector<int> odd;
    for(int i=0;i<n;i++){
        if(deg[i]%2) odd.push_back(i);
    };
    for(int i=0;i<int(odd.size());i+=2){
        int u = odd[i], v = odd[i+1], w;
        w = lca(u, v);
        rev[u]++;
        rev[v]++;
        rev[w]-=2;
    }
    dfs2(root);
    for(int i=0;i<m;i++){
        int a, b, u, v;
        a = es[i].first;
        b = es[i].second;
        if(depth[a] < depth[b]){
            u = a; v = b;
        }
        else{
            u = b; v = a;
        }
        if(rev[v]%2 && u == parent[0][v]) swap(a, b);
        cout << a+1 << " " << b+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 26864
#include <iostream>
#include <stdio.h>
#include <string>
#include <memory.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <time.h>
#include <assert.h>
#include <cmath>
#include <stack>
#include <string.h>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long ll;
int v[2][100];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < n; ++j) {
			scanf("%d", &v[i][j]);
			if (!i && j)
				v[i][j] += v[i][j - 1];
		}
	for (int i = n - 2; i >= 0; --i)
		v[1][i] += v[1][i + 1];
	int res = 0;
	for (int c = 0; c < n; ++c)
		res = max(res, v[0][c] + v[1][c]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    vector<int> dp(n, 0);
    for (int i = 1; i < n; ++i) {
        if (s[i] == 'C' && s[i - 1] == 'A')
            dp[i] = dp[i - 1] + 1;
        else
            dp[i] = dp[i - 1];
    }

    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        cout << dp[r - 1] - dp[l - 1] << '\n';
    }
}


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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

#define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF = 1e9 +5;
const int nax = 1e5 +5;
const long M = 1000000007;
long dp[1005][1005];
int visited[nax];
int in_degree[nax];
vector<int> edges[nax];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n,m;
		int ans = 0;
		cin>>n>>m;
		string arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		dp[0][0] = arr[0][0]=='#' ? 0 : 1;
		// cout<<dp[0][0]<<endl;
		for(int i=1;i<n;i++){
			if(arr[i][0]=='#'){
				dp[i][0] = 0;
			}
			else{
				dp[i][0] = dp[i-1][0];
			}
		}
		for(int i=1;i<m;i++){
			if(arr[0][i]=='#'){
				dp[0][i] = 0;
			}
			else{
				dp[0][i] = dp[0][i-1];
			}
		}

		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++){
		// 		cout<<dp[i][j]<<" ";
		// 	}
		// 	cout<<endl;
		// }

		for(int i=1;i<n;i++){
			for(int j=1;j<m;j++){
				if(arr[i][j]=='#'){
					dp[i][j]==0;
				}
				else{
					if(arr[i-1][j]!='#'){
						dp[i][j] = (dp[i-1][j])%M;
					}
					if(arr[i][j-1]!='#'){
						dp[i][j] += (dp[i][j-1])%M;
					}
					dp[i][j] %=M;
				}
			}
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++){
		// 		cout<<dp[i][j]<<" ";
		// 	}
		// 	cout<<endl;
		// }
		cout<<dp[n-1][m-1]%M<<endl;
	}
}

Measured memory_bytes: 12288
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int rp;
	rp = 0;
	int ans[111][333];
	int f[1111], aa, bb, cc;
	int n,a,b,c,d, time[111][111],m, cost[111][111];
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0) {
			goto a;
		}
		rp = rp + 1;
		for (int i = 1; i <= m; i++) {
			for (int z = 1; z <= m; z++) {
				if (z == i) {
					time[z][i] = 0;
					time[i][z] = 0;
					cost[i][z] = 0;
					cost[z][i] = 0;
				}
				else {
					time[z][i] = 9999;
					time[i][z] =9999;
					cost[i][z] = 9999;
					cost[z][i] = 9999;
				}
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> a >> b >> c >> d;
			cost[a][b] = c;
			cost[b][a] = c;
			time[a][b] = d;
			time[b][a] = d;
		}
		for (int i = 1; i <= m; i++) {
			for (int z = 1; z <= m; z++) {
				for (int s = 1; s <= m; s++) {
					cost[z][s] = min(cost[z][s], cost[z][i] + cost[i][s]);
					time[z][s] = min(time[z][s], time[z][i] + time[i][s]);
				}
			}
		}
		cin >> f[rp];
		for (int i = 1; i <= f[rp]; i++) {
			cin >> aa >> bb >> cc;
			if (cc == 1) {
				ans[rp][i] = time[aa][bb];
			}
			else {
				ans[rp][i] = cost[aa][bb];
			}
		}
	}
a:;
	for (int z = 1; z <= rp; z++) {
		for (int i = 1; i <= f[z]; i++) {
			cout << ans[z][i] << endl;
		}
	}
}


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

int bubbleSort(int A[], int n) {
  bool flag = true;
  int count = 0;
  while (flag) {
    flag = false;
    for (int i = n - 1; 0 < i; i--) {
      if (A[i] < A[i - 1]) {
        swap(A[i], A[i - 1]);
        count++;
        flag = true;
      }
    }
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int count;
  count = bubbleSort(A, n);
  for (int i = 0; i < n; i++) {
    if (i) {
      cout << ' ';
    }
    cout << A[i];
  }
  cout << endl;
  cout << count << endl;
}



Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d; cin >> a >> b >> c >> d;
    if(abs(a-b) <= d && abs(b-c) <= d || abs(a-c) <= d) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}





Measured memory_bytes: 256
#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>;

const ll mod = 998244353;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

class mint {
  public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    ll get() const { return x; }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        return (t & 1) ? a * a * (*this) : a * a;
    }
    operator ll() const { return x; }
    operator string() const { return to_string(x); }
    friend istream& operator>>(istream& is, mint& a) {
        is >> a.x;
        return is;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

class Combination {
  public:
    int n;
    vector<mint> fc, fci;
    Combination(int n) : n(n), fc(n + 1, 1), fci(n + 1, 1) {
        for (int i = 2; i <= n; ++i) {
            fc[i] = fc[i - 1] * mint(i);
            fci[i] = fci[i - 1] / mint(i);
        }
    }
    mint operator()(ll n, ll k) {
        if (k == 0 || n == k) return 1;
        return fc[n] * fci[k] * fci[n - k];
    }
};

int main() {
    int N, M, K;
    cin >> N >> M >> K;

    Combination C(N - 1);
    K = min(K, N - 1);

    mint ans(0);
    for (int i = K; i >= 0; --i) {
        mint t(1);
        t *= C(N - 1, i);
        t *= mint(M) * mint(M - 1).pow(N - i - 1);
        ans += t;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;


int main()
{
    IOS
    ll r,c;
    cin>>r>>c;
    ll a[r][c];
    for(ll i=0;i<r;i++)
    {
        string s;cin>>s;
        for(ll j=0;j<c;j++)
        {
            a[i][j]=1;
            if(s[j]=='#')
            a[i][j]=0;
        }
    }
    ll mr[r][c],mc[r][c];
    memset(mr,0,sizeof(mr));
    memset(mc,0,sizeof(mc));
    for(ll i=0;i<r;i++)
    {
        mr[i][0]=a[i][0];
        for(ll j=1;j<c;j++)
        {
            mr[i][j]=a[i][j]?(1+mr[i][j-1]):0;
        }
    }
    for(ll i=0;i<r;i++)
    {
        for(ll j=c-2;j>=0;j--)
        {
            if(a[i][j])
            {
                mr[i][j]=max(mr[i][j],mr[i][j+1]);
            }
        }
    }
    for(ll i=0;i<c;i++)
    {
        mc[0][i]=a[0][i];
        for(ll j=1;j<r;j++)
        {
            mc[j][i]=a[j][i]?(1+mc[j-1][i]):0;
        }
    }
    for(ll i=0;i<c;i++)
    {
        for(ll j=r-2;j>=0;j--)
        {
            if(a[j][i])
            {
                mc[j][i]=max(mc[j][i],mc[j+1][i]);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<r;i++)
    {
        for(ll j=0;j<c;j++)
        {
            if(a[i][j])
            {
                ans=max(ans,mr[i][j]+mc[i][j]-1);   
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 94080
# coding: utf-8
# Your code here!

S = input()
T = input()

ans = 10000000
for i in range(len(T), len(S)+1):
    sub_S = S[i-len(T):i]
    
    count = 0
    for j in range(len(sub_S)):
        if T[j] != sub_S[j]:
            count += 1
    ans = min(ans, count)

print(ans)

Measured memory_bytes: 9016
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int arr[100001];
int main() {
	cin >> N;
	int cnt = 0;
	rep(i, N + 1) {
		arr[i] = 0;
	}
	rep(i, N) {
		cin >> A;
		arr[i + 1] = A;
		if (arr[arr[i + 1]] == i + 1) {
			cnt++;
		}
	}
	cout << cnt;
}


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

int main() {
	
	int H, W;

	for (int k = 0;; k++) {

		cin >> H >> W;

		if (H == 0 || W == 0)break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}

	return 0;

}

Measured memory_bytes: 1120
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;

vector<ll> d;
map<pair<int,int>,ll> cost;
vector<vector<int>> e;

void dfs(int now,int parent,ll sum){
  d[now] = sum + cost[make_pair(now,parent)];
  for(int v:e[now]){
    if(v != parent){
      dfs(v,now,d[now]);
    }
  }
  return;
}

int main(){
  int n;
  cin >> n;
  d.resize(n,0);
  e.resize(n);
  
 
  for(int i = 0;i < n - 1;i++){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--,b--;
    e[a].push_back(b);
    e[b].push_back(a);
    cost[make_pair(a,b)] = c;
    cost[make_pair(b,a)] = c;
  }

  int q,k;
  cin >> q >> k;
  k--;
  dfs(k,-1,0);

  vector<ll> ans(q);
  for(int i = 0;i < q;i++){
    int x,y;
    cin >> x >> y;
    x--,y--;
    ans[i] = d[x] + d[y];
  }

  for(int i = 0;i < q;i++)cout << ans[i] << endl;
}

Measured memory_bytes: 32256
import sys
def input():
    return sys.stdin.readline()[:-1]

n,m=map(int,input().split())
s=input()
if m>n:
    m=n
tmp=-1
for i in range(m):
    if s[-i-2]=="0":
        tmp=-i-2
# print(tmp)
li=[]
for i in range(n):
    li.append(tmp)
    a=-i-2-m
    if a<-1-n:
        a=-1-n
    if s[a]=="0":
        tmp=a
ans=[]
i=-1
li.reverse()

while(i!=-n-1):

    if li[i]==i:
        print(-1)
        quit()
    ans.append(i-li[i])
    i=li[i]

ans.reverse()


for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 49580
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int t;
  while (cin >> t, t) {
    int n;
    cin >> n;
    int c = 0;
    while (n--) {
      int s, f;
      cin >> s >> f;
      c += f - s;
    }
    if (t <= c) {
      cout << "OK" << endl;
      continue;
    }
    cout << t - c << endl;
  }
}

Measured memory_bytes: 3116
import java.util.*;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int s = sc.nextInt();
	int w = sc.nextInt();
	if(w  >= s)
	System.out.println("unsafe");
	else
	System.out.println("safe");
	sc.close();
	}
}

Measured memory_bytes: 35748
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <complex>

using namespace std;

// #define mod 1000000007

const int MAX = 500000, MS = 2;
const long long int mod[] = {999999937, 1000000007}, base = 9937;

struct rolling_hash
{
	int n;
	vector<long long int> hs[MS], pw[MS];

	rolling_hash(){}

	rolling_hash(const string &s){
		n = s.size();
		for(int i = 0; i < MS; i++){
			hs[i].assign(n + 1, 0);
			pw[i].assign(n + 1, 0);
			hs[i][0] = 0;
			pw[i][0] = 1;
			for(int j = 0; j < n; j++){
				pw[i][j + 1] = pw[i][j] * base % mod[i];
				hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i];
			}
		}
	}

	long long hash(int l, int r, int i){
		return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) % mod[i];
	}

	bool match(int l1, int r1, int l2, int r2){
		bool ret = 1;
		for(int i = 0; i < MS; i++){
			ret &= hash(l1, r1, i) == hash(l2, r2, i);
		}
		return ret;
	}
};

int main()
{
	int n, m;
	string s;
	cin >> n >> m >> s;
	int l = 0, r = 1;
	set<pair<long long int, long long int> > result;
	struct rolling_hash rh = rolling_hash(s);
	for(int i = 0; i < m; i++){
		string q;
		cin >> q;
		if(q == "R--") r--;
		else if(q == "R++") r++;
		else if(q == "L--") l--;
		else l++;
		// cout << l <</ " " << r << endl;
		result.insert(make_pair(rh.hash(l, r, 0), rh.hash(l, r, 1)));
	}
	cout << result.size() << endl;
	return 0;
}


Measured memory_bytes: 31324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  while(cin >> s && s!="0") {
    int dp[2][11];
    memset(dp,0,sizeof(dp));
    dp[0][s[0]-'0']=1;
    int ans=0;
    for(int i=1; i<s.size(); i++) {
      for(int j=0; j<11; j++) dp[1][(j*10+s[i]-'0')%11]=dp[0][j];
      for(int j=0; j<11; j++) dp[0][j]=dp[1][j];
      if(s[i]!='0') dp[0][s[i]-'0']++;
      ans+=dp[0][0];
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1316
N,D = [int(x) for x in input().split()]
dots = [[int(x) for x in input().split()]for _ in range(N)]
cnt = 0
for ind,x in enumerate(dots):
    for i in range(ind+1,N):
        ans = 0
        for j in range(D):
            ans+=(x[j]-dots[i][j])**2
        ans **= 0.5
        if(int(ans)==ans):
            cnt+=1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int>A(3);
  for (int i = 0; i <3; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(2)-A.at(0) << endl;
}

Measured memory_bytes: 3608
a, b, c = [ int(v) for v in input().split() ]
d, e, f = [ int(v) for v in input().split() ]
g, h, i = [ int(v) for v in input().split() ]

if a+e+i == d+h+c and a+e+i == b+f+g:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
k = gets.strip.to_i
a, b = gets.strip.split.map(&:to_i)

if a % k == 0 then
  puts 'OK'
  exit
end

if b % k == 0 then
  puts 'OK'
  exit
end

if b / k - a / k > 0 then
  puts 'OK'
  exit
end

puts 'NG'


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

void solve(long long N){
    int max = sqrt(N);

    map<int, int> primes;

    for (int i=2;i<=max; ++i) {
        while (N > 0 && N % i == 0) {
            N /= i;
            primes[i]++;
            max = sqrt(N);
        }
    }
    if (N >1) {
        primes[N] = 1;
    }

    int count = 0;
    for (auto p : primes) {
        int n = p.second;
        for (int i=1; i<=n; ++i) {
            n -= i;
            //cout << p.first << ' ' << i << endl;
            count++;
        }
    }

    cout << count << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 3672
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

modh = 24
modm = 60

h1,m1,h2,m2,k = map(int,readline().split())
ans = 0
m1 += k
while True:
    if h1+(m1//modm) < h2:
        ans += 1
    elif h1+(m1//modm) == h2 and m1%modm < m2:
        ans += 1
    else:
        break
    m1 += 1
print(ans)

Measured memory_bytes: 62940
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1,mod=1e18;
const int inf=(1ull<<31)-1;
int a,b;

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(15);
	cin>>a>>b;
	cout<<6-a-b;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <set>
#include <cstdio>
#include <cstring>

using namespace std;

int ans[100005];
int res[100005];
int kun[100005];

int a[200005][2]={0};

int main(){
    int n;
    cin>>n;
    long long a[200005];
    long long res=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        res+=a[i];
        a[i]=res;
    }
    long long mi=0;
    for(int i=0;i<n-1;i++){
        long long ans=res;
        long long x,y;
        x=a[i];
        y=ans-a[i];
        if(i==0){
            mi=abs(x-y);
        }
        else{
            long long zz=abs(x-y);
            if(zz<mi){
                mi=zz;
            }
        }
    }
    cout<<mi;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    ll n; cin >> n;
    vector < pair<ll,ll> > edge;
    f(_,1,n-1) {
    	ll u, v; cin >> u >> v;
    	if(u > v) swap(u,v);
    	edge.pb(mp(u,v));
    }
    ll sv = 0, se = 0;
    f(i,1,n) sv += i * (n-i+1);
    fa(x,edge) se += x.ff * (n-x.ss+1);
    cout << sv - se << endl;
    return 0;
}

Measured memory_bytes: 7440
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string S;
LL K;

int main()
{
	in >> S >> K;
	rep(i, S.length())
	{
		auto num = S[i] - '0';
		if (num != 1)
		{
			out << num << std::endl;
			return 0;
		}
		if (i + 1 == K)
		{
			out << 1 << std::endl;
			return 0;
		}
	}
	out << 1 << std::endl;
	return 0;
}


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

int memo[10];
int n;
int keta;
int ans;

bool check(int d)
{
	int t=0,f=0,s=0;
	int tt=0;
	
	for(int i=d;i>=0;i--)
	{
		tt*=10;
		tt+=memo[i];
		if(memo[i]==3)t=1;
		if(memo[i]==5)f=1;
		if(memo[i]==7)s=1;
	}
	if(t==1 && f==1 && s==1 && tt<=n)return true;
	return false;
}

void dfs(int d)
{
	if(d==keta)return;
	
	memo[d]=3;
	if(check(d))ans++;
	dfs(d+1);
	memo[d]=5;
	if(check(d))ans++;
	dfs(d+1);
	memo[d]=7;
	if(check(d))ans++;
	dfs(d+1);
}

int main()
{
	int tmp;
	cin >> n;
	
	tmp=n;
	while(tmp>0)
	{
		tmp/=10;
		keta++;
	}
	dfs(0);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define inv2 500000004
const int N=200010;const int M=8000;
/*inline int ask(int x)
{
    int ans=0;
    for(;x;x-=x&-x)
        ans+=c[x];
    return ans;
}*/
inline int read()
{
    int x=0,o=1;char ch=getchar();
    while(!isdigit(ch)&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int fac[M+10],ifac[M+10],m,f[M/2+10][M/2+10],base=M/4+2,n,A[N],B[N];
inline int Pow(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,a=1ll*a*a%mod)
        if(b&1) ans=1ll*ans*a%mod;
    return ans;
}
inline int C(int n,int m)
{
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
    n=read();
    fac[0]=1;
    for(register int i=1;i<=M;i++)
        fac[i]=1ll*fac[i-1]*i%mod;
    ifac[M]=Pow(fac[M],mod-2);
    for(register int i=M-1;i>=0;i--)
        ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
    for(register int i=1;i<=n;i++)
    {
        A[i]=read();
        B[i]=read();
        f[base-A[i]][base-B[i]]++;
    }
    for(register int i=1;i<=M/2+2;i++)
        for(register int j=1;j<=M/2+2;j++)
            f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%mod)%mod;
    long long ans=0;
    for(register int i=1;i<=n;i++)
    {
        ans=(ans+f[A[i]+base][B[i]+base])%mod;
        ans=(ans-C(2*A[i]+2*B[i],2*A[i]))%mod;
    }
    ans=(ans+mod)%mod;
    ans=1ll*inv2*ans%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 64640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder177
{
    class Program
    {
        static void Main(string[] args)
        {
            QC();
        }

        static void QA()
        {
            string[] splited = Console.ReadLine().Split(' ');

            int D = int.Parse(splited[0]);
            int T = int.Parse(splited[1]);
            int S = int.Parse(splited[2]);

            Console.WriteLine((((double)D / S) <= T) ? "Yes" : "No");
        }

        static void QB()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int cntNotMatchMin = 1001;

            for (int i = 0; i < S.Length - T.Length + 1; i++)
            {
                int cntNotMatch = 0;
                for (int j = 0; j < T.Length; j++)
                {
                    if (!S[i + j].Equals(T[j])) cntNotMatch++;
                }

                if (cntNotMatch < cntNotMatchMin) cntNotMatchMin = cntNotMatch;
            }

            Console.WriteLine(cntNotMatchMin);
        }

        static void QC()
        {
            Console.ReadLine(); // 読み捨て
            string[] splited = Console.ReadLine().Split(' ');

            long sum = 0;
            long befSum = 0;
            for (int i = 1; i < splited.Length; i++)
            {
                befSum = (befSum + long.Parse(splited[i])) % 1000000007;
            }

            for (int i = 0; i < splited.Length - 1; i++)
            {
                if (i != 0) befSum -= long.Parse(splited[i]);
                if (befSum < 0) befSum += 1000000007;
                sum = (sum + (long.Parse(splited[i]) * befSum)) % 1000000007;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 43316