akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int ll
int n,w;
vector<pair<int,int>> v(105);
vector<vector<int>> dp(105,vector<int>(100005,-1));

int max_val(int ind,int w){
    if(ind<0)return 0;
    if(dp[ind][w]!=-1)return dp[ind][w];
    dp[ind][w]=max_val(ind-1,w);
    if(w-v[ind].first>=0)dp[ind][w]=max(dp[ind][w],v[ind].second+max_val(ind-1,w-v[ind].first));
    return dp[ind][w];
}

void solve()
{
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    // cout<<max_val(n-1,w)<<"\n";
    //Iterative
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0){
                dp[i][j]=0;continue;
            }
            dp[i][j]=dp[i-1][j];
            if(j-v[i-1].first>=0)dp[i][j]=max(dp[i][j],v[i-1].second+dp[i-1][j-v[i-1].first]);
        }
    }
    cout<<dp[n][w]<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 86176
import itertools
from math import factorial

n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]
d = list()
for pp in itertools.combinations(p, 2):
    d.append(((pp[0][0] - pp[1][0])**2 + (pp[0][1] - pp[1][1])**2)**0.5)
f = factorial(n)
i = f * (n-1) / len(d)
print(sum(d) * i / f)

Measured memory_bytes: 38384
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int a[MAXN];

bool solve(ll &mn,ll &mx) {
	mn=mx=2;
	for(int i=n-1;i>=0;--i) {
		ll l=(mn+a[i]-1)/a[i];
		if(l*a[i]>mx) return false;
		ll r=mx/a[i];
		mn=l*a[i],mx=(r+1)*a[i]-1;
	}
	return true;
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]);
	ll mn,mx; if(!solve(mn,mx)) printf("-1\n"); else printf("%lld %lld\n",mn,mx);

}

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
int n;
char s[max_n];
int cnt[max_n];
int main()
{
    scanf("%d",&n);
    scanf(" %s",s+1);
    for(int i=1;i<=n;i++)
    {
        cnt[i]=cnt[i-1]+(s[i]=='.');
    }
    int ans=n;
    for(int i=0;i<=n;i++)
    {
        ans=min(ans,i-cnt[i]+cnt[n]-cnt[i]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin() , v.end());
    int m;
    cin >> m;
    vector<int> v2(m);
    for(int i = 0; i < m; i++){
        cin >> v2[i];
    }
    sort(v2.begin(), v2.end());

    for(int i = 0; i< m; i++){
        int p;
        p = v2[i];
        if(std::binary_search(v.begin(), v.end(), p)){
            //cout << 1 << endl;
        }
        else {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}


Measured memory_bytes: 4464
H,W,D = map(int,raw_input().split())
P = [None]*(H*W+1)
for y in range(H):
  A = map(int,raw_input().split())
  for x in range(W):
    P[A[x]] = (y,x)
B = [0]*(H*W+1)
for i in range(D+1,H*W+1):
  B[i] = B[i-D] + abs(P[i][0]-P[i-D][0])+abs(P[i][1]-P[i-D][1])
Q = input()
ans = 0
for _ in range(Q):
  L,R = map(int,raw_input().split())
  print B[R]-B[L]


Measured memory_bytes: 16952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int main() {
    int a,b,c,x,y; cin >> a >> b >> c >> x >> y;
    long long res = 0;
    long long allc = LONG_MAX;
    if ((a + b) / 2 >= c) {
        if (x > y) {
            res += c * y * 2;
            res += (x - y) * a;
            allc = c * x * 2;
        } else {
            res += c * x * 2;
            res += (y - x) * b;
            allc = c * y * 2;
        }
    } else {
        res += a * x;
        res += b * y;
    }
    cout << min(res, allc) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace test{
	class program{
	
	static void Main() {
	string[] tmp = Console.ReadLine().Split(' ');;
	rectangle rect = new rectangle(int.Parse(tmp[0]), int.Parse(tmp[1]));
	Console.WriteLine("{0} {1}",rect.area(),rect.perm());
	}
}
class rectangle{
	int height;
	int width;
	public rectangle(int h, int w){
		height = h;
		width = w;
	}
	public int area(){
		return height*width;
	}
	public int perm(){
		return (height+width)*2;
	}
}
}

Measured memory_bytes: 5616
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	string S; cin >> S;
	int x = 0;
	rep (i, S.size()) {
		if (S[i] == '+')x++;
		else if (S[i] == '-')x--;
	}

	cout << x << endl;
}

Measured memory_bytes: 256
N = int(input())
A,B = map(int,input().split())
L = list(map(int,input().split()))
one = []
two = []
three = []
for i in range(N):
  if L[i] <= A:
    one.append(L[i])
  elif A+1 <= L[i] <= B:
    two.append(L[i])
  else:
    three.append(L[i])
print(min(len(one),len(two),len(three)))


Measured memory_bytes: 3064
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    var a: Seq[(Int, Int)] = Seq()
    for (i <- 0 until n) {
      a +:= (sc.nextInt(), i + 1)
    }
    a = a.sortBy(_._1)
    val b = new StringBuilder
    for (ans <- a) {
      b.append(ans._2)
      b.append(" ")
    }
    println(b)
  }
}

Measured memory_bytes: 76792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

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

    if(s == t){
        cout << "No" << endl;
        return 0;
    }

    ll N = s.size();
    ll M = t.size();
    vector<char> S(N), T(M);

    rep(i, 0, N) S[i] = s[i];
    rep(i, 0, M) T[i] = t[i];

    sort(S.begin(), S.end());
    sort(T.begin(), T.end(), greater<char>());

    string ss, tt;
    rep(i, 0, N) ss.push_back(S[i]);
    rep(i, 0, M) tt.push_back(T[i]);

    vector<string> a;
    a.push_back(ss);
    a.push_back(tt);
    sort(a.begin(), a.end());

    if(a[0] == ss){
        cout << "Yes" << endl;
    }else{ 
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

char str[128][128];
int area_id[128][128];

void DFS(int i, int j, int H, int W){
	if (i + 1 < H){
		if (str[i][j] == str[i+1][j] && area_id[i+1][j] == (i + 1) * W + j){
			area_id[i+1][j] = area_id[i][j];
			DFS(i + 1, j, H, W);
		}
	}
	
	if (i - 1 >= 0){
		if (str[i][j] == str[i-1][j] && area_id[i-1][j] == (i - 1) * W + j){
			area_id[i-1][j] = area_id[i][j];
			DFS(i - 1, j, H, W);
		}
	}
	
	if (j + 1 < W){
		if (str[i][j] == str[i][j+1] && area_id[i][j+1] == i * W + (j + 1)){
			area_id[i][j+1] = area_id[i][j];
			DFS(i, j + 1, H, W);
		}
	}
	
	if (j - 1 >= 0){
		if (str[i][j] == str[i][j-1] && area_id[i][j-1] == i * W + (j - 1)){
			area_id[i][j-1] = area_id[i][j];
			DFS(i, j - 1, H, W);
		}
	}
}
	

int main(void)
{
	int H, W, i, j, cnt;
	char area_num[128 * 128];
	
	while (1){
		scanf("%d %d", &H, &W);
		
		if (H == 0 && W == 0){
			break;
		}
		
		//
		
		for (i = 0; i < H; i++){
			for (j = 0; j < W; j++){
				area_id[i][j] = i * W + j;
			}
		}
				
		for (i = 0; i < 128 * 128; i++){
			area_num[i] = 0;
		}
		
		cnt = 0;
		
		//
		
		for (i = 0; i < H; i++){
			scanf("%s", str[i]);
		}
		
		for (i = 0; i < H; i++){
			for (j = 0; j < W; j++){
				DFS(i, j, H, W);
			}
		}
		
		for (i = 0; i < H; i++){
			for (j = 0; j < W; j++){
				area_num[area_id[i][j]] = 1;
			}
		}
		
		for (i = 0; i < H; i++){
			for (j = 0; j < W; j++){
				if (area_num[i * W + j] == 1){
					cnt++;
				}
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return (0);
}

Measured memory_bytes: 1780
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

func setBit(d, n int) int {
	t := 1 << uint(n)
	return d | t
}

func intAbs(n int) int {
	return int(math.Abs(float64(n)))
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	line := nextLine()

	spl := intSprit(line)

	t := spl[1] / spl[0]

	if t >= spl[2] {
		fmt.Println(spl[2])
	} else {
		fmt.Println(t)
	}
}


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

int main() {
	int n,m;
	cin>>n>>m;
	int ar[n];
	for(int i=0;i<n;i++)
	 cin>>ar[i];
    sort(ar, ar+n, greater<int>()); 
    int sum=0;
    for(int i=0;i<n;i++)
     sum+=ar[i];
    int mini=-1;
    if(sum%(4*m)==0)
     mini=sum/(4*m);
    else mini=(sum/(4*m))+1; 
    if(ar[m-1]<mini)
     cout<<"No"<<endl;
     else cout<<"Yes"<<endl;
	 return 0;
}

Measured memory_bytes: 256
N,L = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
if c = (1...N).to_a.find{ |i| A[i-1]+A[i] >= L }
  puts "Possible"
  (c-1).times{ |a| p a+1 }
  (N-c-1).times{ |a| p N-a-1 }
  p c
else
  puts "Impossible"
end


Measured memory_bytes: 17156
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt

  val z = (1 to N).maxBy(x => {
    var i = 0
    var a = x
    while (a % 2 == 0) {
      i += 1
      a /= 2
    }

    i
  })
  println(z)
}


Measured memory_bytes: 27448
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long n, k;
    readlnTo(n, k);
    auto a = readLongs();
    long[long] c;
    foreach(ai; a) {
        if(ai in c) {
            ++c[ai];
        } else {
            c[ai] = 1;
        }
    }
    long[] b;
    foreach(k, v; c) {
        b ~= v;
    }
    b.sort();
    if(b.length <= k) {
        writeln(0);
        return;
    }
    long ans;
    foreach(i; iota(b.length - k)) { 
        ans += b[i];
    }
    writeln(ans);
}



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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n); 0<=i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());                   //昇順
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());    //降順
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper); 
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define SetPre(x) setprecision(x)

int main(void){
    //標準入力
    ll N;
    cin >> N;
    VL A(N),B(N),C(N);
    REP(i,N)
    {
        cin >> A.at(i);
    }
    REP(i,N)
    {
        cin >> B.at(i);
    }
    REP(i,N)
    {
        cin >> C.at(i);
    }
    //昇順ソートしておく
    V_SORT_U(A)
    V_SORT_U(B)
    V_SORT_U(C)
    //中パーツを固定⇒上下パーツで使える数をカウントする
    ll count = 0;
    REP(i,N)
    {
        auto itr_A = lower_bound( A.begin(), A.end(), B.at(i) ); //lowerで以上となる数を数えて全ての数から引く
        auto itr_C = lower_bound( C.begin(), C.end(), B.at(i)+1 ); //lowerは以上なので+1して判定する（真に大きくするため）
        ll increment = 0;
        //cout << "*itr_A:" << *itr_A << endl;
        //cout << "*itr_C:" << *itr_C << endl;
        increment = (itr_A-A.begin())*(C.end()-itr_C); //上パーツ候補数×下パーツ数の組み合わせ
        
        //cout << "debug increment:" << increment << endl;
        count += increment; //上パーツ候補数×下パーツ数の組み合わせ
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2560
n = int(input())
s = input()

def addleave(p):
    for i in range(1,n):
        if s[i]=="o":
            if p[i]=="S":
                p += "S" if p[i-1]=="S" else "W"
            else:
                p += "W" if p[i-1]=="S" else "S"
        else:
            if p[i]=="S":
                p += "W" if p[i-1]=="S" else "S"
            else:
                p += "S" if p[i-1]=="S" else "W"
    return p
def solve():
    result = addleave("SS")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]
    result = addleave("SW")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]
    result = addleave("WS")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]

    result = addleave("WW")
    if result[-1] == result[0]:
        if check(result):
            return result[:-1]
    return -1

def check(res):
    res = res[:-1] + res[:-1] + res[:-1]
    flag = True
    for i in range(n):
        if res[n + i - 1] == res[n + i + 1] and res[n + i]=="S" and s[i]=="o":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="S" and s[i]=="x":
            pass
        elif res[n + i - 1] == res[n + i + 1] and res[n + i]=="W" and s[i]=="x":
            pass
        elif res[n + i - 1] != res[n + i + 1] and res[n + i]=="W" and s[i]=="o":
            pass
        else:
            flag = False
    return flag
print(solve())

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

int main(int argc, char const *argv[]) {
  int sum = 0;
  string w, s, end;
  cin >> w >> s;

  while (s != "END_OF_TEXT") {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    if (s == w) sum++;
    cin >> s;
  }

  cout << sum << endl;

  return 0;
}



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

#define ll long long
#define N 100010
int n;
ll s[N];
int used[N];

int main() {
	while (scanf("%d", &n) != EOF) {
		for (int i = 0; i < n; ++i) {
			scanf("%lld", s + i);
		}
		memset(used, 0, sizeof used); 
		ll res = 0;
		for (int C = 1; C <= n; ++C) {
			ll tmp = 0; 
			for (int k = 1; 1ll * k * C < n; ++k) {  
				int a = k * C;
				int b = n - 1 - k * C;
				if (b <= 0 || b - C <= 0) break;
				if (a < 0 || a >= n || b < 0 || b >= n || a == b) break;
				if (used[a] == C || used[b] == C) {
					break;
				}
				used[a] = C;
				used[b] = C;
				tmp += s[a];
				tmp += s[b];
				res = max(res, tmp);
			}
		}
		printf("%lld\n", res);
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (true) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if (a <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
int main(){
  int n;
  std::cin>>n;
  std::vector<int> a(n);
  for(auto& ai:a)std::cin>>ai;
  int64_t answer = 0;
  for(int i=1;i<n;++i){
    if(a[i-1]>a[i]){
      answer += a[i-1]-a[i];
      a[i] = a[i-1];
    }
  }
  std::cout<<answer<<std::endl;
}

Measured memory_bytes: 3968
from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    # graph[node] = [(cost, to)]
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist
    # dist = [costs to nodes]



from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, From, To, cost=1):
        self.graph[From].append((To,cost))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):

    def __init__(self, graph, start):
        self.g = graph.graph
        self.dist = defaultdict(lambda:float('inf'))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        self.Q = []
        heappush(self.Q,(self.dist[start], start))

        while  self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, cost in self.g[u]:
                alt = dist_u + cost
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q,(alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]

        return path[::-1]

g = Graph()
N = int(input())
for i in range(N-1):
    u,v,w = map(int,input().split())
    g.add_edge(u-1,v-1,w)
    g.add_edge(v-1,u-1,w)

dijkstra = Dijkstra(g,0)
for i in range(N):
    print(dijkstra.shortest_distance(i)%2)

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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll; 
typedef long double ld; 
typedef pair<int,int> p32;   
typedef pair<ll,ll> p64;  
typedef pair<double,double> pd; 
typedef pair<ld,ld> pld; 
typedef vector<int> v32;  
typedef vector<ll> v64;  
typedef vector<pd> vpd;   
typedef vector<p32> vp32;  
typedef vector<p64> vp64;  
typedef vector<v32> vv32;  
typedef vector<v64> vv64;  

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }


const int inf=1000*1000*1000+9; 
const ll infl=1ll*inf*inf; 
int mod=1000*1000*1000+7;  
// ---------------------------------------------------------------------------- -------------- 

v64 nums; 

void dfs(ll num , int last_dig, int req_digs){
	if(req_digs==0){
		nums.push_back(num); 
	}
	else {
		dfs(num*10+last_dig,last_dig,req_digs-1); 
		if(last_dig>0){
			dfs(num*10+last_dig-1,last_dig-1,req_digs-1); 
		}
		if(last_dig<9){
			dfs(num*10+last_dig+1,last_dig+1,req_digs-1); 
		}
	}
}

void solve(){	
	int k; 
	cin>>k; 
	int digs=1; 
	while(sz(nums)<k){
		for(int i=1;i<=9;i++){
			dfs(i,i,digs-1); 
		}
		digs++; 
	}
	sort(all(nums)); 
	// for(int i=0;i<1000;i++) cout<<nums[i]<<endl; 
	cout<<nums[k-1]<<endl; 
}



int main(){
	// clock_t beg=clock(); 
  fast_io; 
  int testcases=1; 
  // freopen("student.in","r",stdin); 
  // freopen("student.out","w",stdout); 
  // cin>>testcases; 
  cout << fixed << setprecision(13); 
  while(testcases--){
    solve(); 	
  }
	// clock_t end=clock(); 
	// fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}



Measured memory_bytes: 2420
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;



public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	   	String s = sc.next();
	   	char[] s_c = s.toCharArray();
	   	int dp[] = new int[2019];
	   	dp[0] = 1;
	   	int rem = 0;
	   	int pow = 1;
	   	long ans = 0;
	   	for(int i = s_c.length-1; i >= 0; i--) {
	   		int x = Integer.parseInt(String.valueOf(s_c[i]));
	   		x = (x*pow)%2019;
	   		rem = (rem+x)%2019;
	   		ans += dp[rem];
	   		dp[rem]++;
	   		pow *= 10;
	   		pow%=2019;
	   	}
	   	System.out.println(ans);
	}
}

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

vector<int> arr(100001);
vector<int>  dp(100001,-1) ;

int func(int id){
    if(id == 0)return 0 ;
    
    if(dp[id] != -1)return dp[id] ;
    
    return dp[id] = min(abs(arr[id] - arr[max(0, id - 1)]) + func(max(0, id - 1))
                    ,abs(arr[id] - arr[max(0, id - 2)]) + func(max(0, id - 2))) ;
}

main(){
    
    int n ; 
    cin>>n ; 
    for(int i = 0; i < n; ++i)cin>>arr[i] ;
    cout<<func(n-1) ;
}

Measured memory_bytes: 4224
from collections import Counter

n, k = map(int, input().split())
A = list(map(int, input().split()))

cnt_A = sorted(Counter(A).values())

ans = 0
if len(cnt_A) <= k:
    print(ans)
else:
    for i in range(len(cnt_A) - k):
        ans += cnt_A[i]
    print(ans)

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++){
        if(s[i] == '2'){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
 
#define pb 					push_back
 
template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}
 
template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<"\n";
 
	return os;
}
 
 
template<typename T>
ostream& operator <<(ostream& os, set<T> input) {
	for(auto t: input)
		os << t <<"\n";
 
	return os;
}

int main() {

	string s;
	cin >> s;

	for(int i =1; i<(int)s.size(); i++) {
		if(s[i]!=s[i-1]) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

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

int x[60];
int sum[60];
long long f[60][2510];

int main(){
	int n, A;
	scanf("%d%d", &n, &A);
	for (int i = 0; i < n; i++){
		scanf("%d", &x[i]);
		sum[i] = x[i];
		if (i) sum[i] += sum[i - 1];
	}
	f[0][0] = 1;
	for (int i = 0; i < n; i++){
		for (int j = n; j >= 1; j--){
			for (int k = sum[i]; k >= x[i]; k--){
				f[j][k] += f[j - 1][k - x[i]];
			}
		}
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++){
		ans += f[i][i * A];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
int mod=1e9+7;
const int N=1e4+100;

vector<pa>ve;
int vis[N];
int main()
{
   int n,k;cin>>n>>k;
   int num=(n-2)*(n-1)/2;
   if(k>num) puts("-1");
   else{
    for(int i=1;i<=n;i++)
        vis[i]=n-2;
   num-=k;
   for(int i=2;i<=n;i++)
     ve.push_back(make_pair(1,i));
   int kz=2;
   while(num){
        int kk=kz+1;
       while(vis[kz]) {
             ve.push_back(make_pair(kz,kk));
             vis[kz]--,vis[kk]--;
             kk++;
             //cout<<kk<<endl;
             num--;
             if(!num) break;
        }
        kz++;

   }
   cout<<ve.size()<<endl;
  for(auto v:ve){
    cout<<v.first<<" "<<v.second<<endl;
  }
   }
    return 0;
}


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

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL
#define maxN 2000007

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
// structure
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vll>

// get value
#define FF first
#define SS second

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const int& a, const int& b) {return a > b;}

int main() {
//    #ifndef ONLINE_JUDGE
//        freopen("tmp.inp", "r", stdin);
//        freopen("tmp.out", "w", stdout);
//    #endif // ONLINE_JUDGE

    int a, b;
    scanf("%d%d", &a, &b);

    printf("%d", ((a+b-1+24)%24+1)%24);

    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(raw_input())

    num = map(int,raw_input().split())
    cnt = 0
    for i in range(n - 2):
        if num[i] < num[i+1] and num[i+1] < num[i+2]:
            cnt += 1
        if num[i] > num[i+1] and num[i+1] > num[i+2]:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::HashSet;

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1); m]
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in &es {
        g[a].push(b);
    }
    let mut reach = vec![vec![false; n]; n];
    let mut reach2 = vec![vec![false; n]; n];
    for i in 0..n {
        let mut done = vec![false; n];
        done[i] = true;
        for &j in &g[i] {
            if done[j] {
                reach2[i][j] = true;
                continue;
            }
            done[j] = true;
            dfs(j, &g, &mut done);
        }
        for j in 0..n {
            reach[i][j] |= done[j];
        }
    }
    for i in 0..n {
        g[i].reverse();
    }
    for i in 0..n {
        let mut done = vec![false; n];
        done[i] = true;
        for &j in &g[i] {
            if done[j] {
                reach2[i][j] = true;
                continue;
            }
            done[j] = true;
            dfs(j, &g, &mut done);
        }
    }
    for &(a, b) in &es {
        if reach[b][a] ^ reach2[a][b] {
            println!("diff");
        } else {
            println!("same");
        }
    }
}

fn dfs(v: usize, g: &Vec<Vec<usize>>, done: &mut Vec<bool>) {
    for &c in &g[v] {
        if done[c] {
            continue;
        }
        done[c] = true;
        dfs(c, g, done);
    }
}


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


int n,m,deg[100005],a,b,uno,due,cont;

vector<int> grafo[100005];

int dfs(int nodo,int last){
	
	if(last!=-1 && nodo==uno)return 0;
	
	if(nodo==due)return 1;
	
	int ans=0;
	
	for(int i=0;i<grafo[nodo].size();i++){
		
		if(grafo[nodo][i]!=last){
			ans+=dfs(grafo[nodo][i],nodo);
		}
		
	}
	
	return ans;
}

int main(){

	cin>>n>>m;
	
	
	for(int i=0;i<m;i++){
	
		cin>>a>>b;
		
		grafo[a].push_back(b);
		grafo[b].push_back(a);
		
		deg[a]++;
		deg[b]++;
	
	}
	
	if(m<n+2){
		cout<<"No"<<endl;
		return 0;
	}
	
	uno=due=-1;
	
	int maxdeg=0;
	
	for(int i=1;i<=n;i++){
		if(deg[i]%2==1){
			cout<<"No"<<endl;
			return 0;
		}
		
		if(deg[i]==4){
			cont++;
			if(uno==-1){
				uno=i;
			}
			else due=i;
		}
		
		maxdeg=max(maxdeg,deg[i]);
	}
	
	
	if(cont==2 && maxdeg==4){
		
		//cout<<"ok"<<dfs(uno,-1)<<" "<<uno<<" "<<due<<endl;
		
		if(dfs(uno,-1)==4)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
		
		return 0;
		
	}
	
	cout<<"Yes"<<endl;
	
	
	return 0;


}


Measured memory_bytes: 7680
N = int(input())
S = input()

num_r = S.count('R')
num_g = S.count('G')
num_b = S.count('B')

ans = num_r * num_g * num_b

for i in range(N):
  for j in range(i+1, N):
    k = j + (j - i)
    if k<N and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      ans -= 1

print(ans)

Measured memory_bytes: 9200
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define fi first
#define fs first
#define se second
#define sc second
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;
#define ll long long

bool solve()
{
	int a, L; cin >> a >> L;
	if (a == 0 && L == 0)return false;
	map<int, int> mp;
	mp[a] = 0;

	int j = 0;
	while (++j)
	{
		vec digit(L);
		REP(i, L)
		{
			digit[i] = a % 10;
			a /= 10;
		}
		sort(digit.begin(), digit.end());
		int n1 = 0, n2 = 0;
		REP(i, L)
		{
			n1 *= 10;
			n1 += digit[i];
			n2 *= 10;
			n2 += digit[L - i - 1];
		}
		a = n2 - n1;
		if (mp.count(a))
		{
			cout << mp[a] << " " << a << " " << j - mp[a] << endl;
			return true;
		}
		mp[a] = j;
	}


	return true;
}

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


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdint>
using namespace std;

const int MAX_SIZE = 100;

int main(){
    int h, w;
    char c[MAX_SIZE][MAX_SIZE];
    vector<int> valid_w;
    vector<int> valid_h;

    cin >> h >> w;

    for(int i = 0; i < h; i++) {
        bool w_blank_flag = true;
        for(int j = 0; j < w; j++) {
            char c_in;
            cin >> c_in;
            c[i][j] = c_in;
            if(c_in == '#') {
                w_blank_flag = false;
            }
        }
        if(!w_blank_flag) {
            valid_h.push_back(i);
        }
    }
    
    for(int j = 0; j < w; j++) {
        bool h_blank_flag = true;
        for(int i = 0; i < h; i++) {
            if(c[i][j] == '#') {
                h_blank_flag = false;
            }
        }
        if(!h_blank_flag) {
            valid_w.push_back(j);
        }
    }

    int h_valid_index = 0;
    int w_valid_index = 0;
    for(int i = 0; i < h; i++) {
        if(i == valid_h[h_valid_index]) {
            h_valid_index++;
            for(int j = 0; j < w; j++) {
                if(j == valid_w[w_valid_index]) {
                    w_valid_index++;
                    cout << c[i][j];
                }
            }
            w_valid_index = 0;
            cout << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char o[51],e[51];
	int i;
	scanf("%s%s",o,e);
	for(i=0;i<strlen(o);i++){
		printf("%c",o[i]);
		if(e[i]!='\0')printf("%c",e[i]);
	}
	return 0;
}

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

def main():
    s = S
    length = len(s)
    ans = "No"
    for _ in range(length):
        if s == T:
            ans = "Yes"
            break
        temp = s[-1] + s
        s = temp[0:length]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue
#define PI 3.141592653589793238462643383279502
#define debug(n1) cout<<"debug... "<<n1<<"\n"
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        ll dp[2001]={};
        dp[3]=1; // 3
        dp[4]=1; // 4 
        dp[5]=1; // 5
        dp[6]=2; // 6 , 3+3
        //dp[7]=3 ; // 7 , 3 4 , 4 3
        rep(i,7,2001)
        {
            dp[i]=1;
            rep(j,3,i+1 )
            {
                dp[i]+=dp[i-j];
                dp[i]=dp[i]%rem;
            }
        }
        cout<<dp[n]%rem;
    }
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder_170A
{
    class Program
    {
        static void Main(string[] args)
        {
            var countline = Console.ReadLine();
            var count = countline.Split(' ').Select(s => int.Parse(s)).ToArray();

            int sum = 0;

            for( int i = 0;i < count.Length; ++i)
            {
                sum = sum + count[i];
            }

            int ans = 15 - sum;

            Console.WriteLine(ans);
            //Console.ReadKey();

        }
    }
}


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

from collections import Counter
import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

L = []
for i in range(1, N+1):
    prime = prime_factorize(i)
#    print(i, prime)
    L += prime
C = Counter(L)
#print(C)


def count_n(C, n):
    return [v >= n for v in C.values()].count(True)

count_4 = count_n(C, 4)
count_2 = count_n(C, 2)
count_14 = count_n(C, 14)
count_24 = count_n(C, 24)
count_74 = count_n(C, 74)


c4_442 = count_4
c2_442 = count_2 - 2

if c4_442 < 2 or c2_442 < 1:
    ans442 = 0
else:
    ans442 = combinations_count(c4_442, 2)*combinations_count(c2_442, 1)

c14_144 = count_14
c4_144 = count_4 - 1
if c14_144 < 1 or c4_144 < 1:
    ans144 = 0
else:
    ans144 = combinations_count(c14_144, 1)*combinations_count(c4_144, 1)

c24_242 = count_24
c2_242 = count_2 - 1
if c24_242 < 1 or c2_242 < 1:
    ans242 = 0
else:
    ans242 = combinations_count(c24_242, 1)*combinations_count(c2_242, 1)
    
c74_74 = count_74
if c74_74 < 1:
    ans74 = 0
else:
    ans74 = combinations_count(c74_74, 1)
    
print(ans442+ans144+ans242+ans74)


Measured memory_bytes: 38384
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;
 
int main() {
    int n; cin >> n;
    for (int i = 0; i <= n; i++) {
        if (int(i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
// #include<math.h>
// #include<ctime>
// #include<cmath>
// #include<utility>
// #include<cstdlib>
// #include<bitset>
#include<map>
// #include<set>
// #include<queue>
// #include<stack>
// #include<iomanip>
using namespace std;                       

#define ll long long
#define pb push_back
#define mp make_pair

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll fastpo(ll a, ll x){
    if(x == 0) return 1ll;
    if(x == 1) return a;
    ll y = fastpo(a, x/2);
    if(x%2 == 0){
        return y*y;
    }
    return y*y*a;
}

ll inv(ll a, ll M){
    return fastpo(a, M-2);
}

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        return -1; 
    else
    { 
        ll res = (x%m + m) % m; 
        return res;
    } 
}


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

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

void print(vector<int> &a){
    int n = a.size();
    for(int i=0; i<n; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main(){
//    clock_t time_req;
//     time_req = clock();
    fastio;
    int n;
    cin>>n;
    int r = n%1000;
    if(r == 0){
        cout<<r<<endl;
    }
    else{
        cout<<1000-r<<endl;
    }
    // time_req = clock()-time_req;
    // cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int n;

int main()
{
	scanf("%d", &n);
	if(n < 3) printf("0\n");
	else
	{
		printf("%d\n", n/3);
	}
	return 0;
}

Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline())

def isPrime(n):
    if n < 2:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

def divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def calc(n):
    used = set()
    a = 0
    c = True
    c1 = []
    ds = divisors(n)
    m = max(ds)
    for d in ds:
        if not isPrime(d):
            continue
        v = d
        i = 1
        while v <= m:
            c1.append(v)
            i += 1
            v = d ** i
    c1.sort()
    while c:
        c = False
        for d in c1:
            if d in used:
                continue
            if n % d != 0:
                continue
            #print(n, d)
            n //= d
            a += 1
            c = True
            used.add(d)
            break
    return a

print(calc(n))

Measured memory_bytes: 9564
#include<iostream>
#include<map>
#include<vector>
#include<string>
using namespace std;

void rec(string s);
int cnt;
map< string, vector<string> >m;
map<string,int>selected;

int main()
{
  int n,i;
  string s,ans;
  string words=":,.",key;
  while(cin>>n,n){
    m.clear();
    ans="";
    while(n-->0){
      cin>>s;
      for(int i=0,start=0;i<s.size();i++){
	if(words.find(s[i])!=string::npos){
	  if(s[i]==':'){
	    key=s.substr(start,i-start);
	  }else{
	    m[key].push_back(s.substr(start,i-start));
	  }
	  if(s[i]=='.')break;
	  start=i+1;
	  if(ans=="")ans=key;
	}
      }
    }
    cnt=0;
    selected.clear();
    rec(ans);
    cout<<cnt<<endl;
  }
}


void rec(string s){
  map< string, vector<string> >::iterator mit;
  vector<string>::iterator vit;
  for(vit=m[s].begin();vit!=m[s].end();vit++){
    if(selected[*vit])continue;
    selected[*vit]=true;
    cnt++;
    if(m.count(*vit)){
      cnt--;
      rec(*vit);
    }
  }
  return;
}

Measured memory_bytes: 1048
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	cin>>s;
	int a=0,b=0;
	int ans = 0;
	for(char x: s){
		if(a==b){
			b++;
			if(x=='p'){
				ans--;
			}
		}
		else{
			a++;
			if(x=='g') ans++;
		}
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 512