akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) int((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl '\n'
#define ff first
#define ss second
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T add(T x, T y, T m) { return ((x % m)  + (y % m)) % m;}
template<typename T>   T mul(T x, T y, T m) { return ((x % m) * (long long)(y % m)) % m;}
template<typename T>   T sub(T x, T y, T m) { return add(x, -y + m);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}

int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

struct pair_hash{
	template<class T1, class T2>
	size_t operator() (const pair<T1, T2> &p) const {
		auto h1 = hash<T1>{}(p.first);
		auto h2 = hash<T2>{}(p.second);
		return h1 ^ h2;
	}
};




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

	int n;
	cin >> n;

	ll sum = 0;

	for(int i = 1 ; i <= n ; ++i) {
		if(i % 3 && i % 5) sum += i;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3652
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
G = [[] for _ in range(n)]
for x, y in LIR(m):
    G[x - 1] += [y - 1]

dist = [[INF] * n for _ in range(3)]
s, t = LI()
dist[0][s - 1] = 0
dq = deque([(0, s - 1)])
while dq:
    cost, u = dq.popleft()
    for v in G[u]:
        if cost + 1 < dist[(cost + 1) % 3][v]:
            dist[(cost + 1) % 3][v] = cost + 1
            dq += [(cost + 1, v)]


ans = dist[0][t - 1]
if ans == INF:
    print(-1)
else:
    print(ans // 3)





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

int main() {
    long long n, m;
    cin >> n >> m;
    for (long long i = 1; i < m + 1; i++) {
        if (i <= m - m / 2) {
            cout << i << " " << n + 1 - i << endl;
        } else {
            cout << n + 1 - i - (m - i + 1) * 2 << " " << n + 1 - i << endl;
        }
    }
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

template<class T> bool chmin(T& a, T b){
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	long long h[100010];
	long long dp[100010];
	const long long INF = 1LL << 60;
	for (int i = 0; i < N; i++){
		cin >> h[i];
	}
	for (int i = 0; i < 100010; i++){
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < N; i++){
		chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;
const int MX = 1e5+5;
int dp[MX][4];

vector<vector <int> > v;
int n;

int solve(int days,int prev){
    if(days == n+1) return 0;
    if(dp[days][prev] != -1) return dp[days][prev];
    long long ans = -1e17;
    for(int i=1; i<=3 ; i++){
        if(i != prev){
            ans = max(ans, solve(days + 1, i) + v[days][i]);
        }
    }
    return dp[days][prev] = ans;
}

int32_t main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    v.resize(n+1);
    for(int i=1 ; i<=n ; i++){
        v[i].resize(4);
        for(int j=1 ; j<=3 ; j++) cin>>v[i][j];
    }
    cout<<solve(1,0);

    return 0;
}


Measured memory_bytes: 16640
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
int main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n), sum(n + 1, 0);
	for(int i = 0; i < n; ++i) {
		cin >> l[i];
	}
	for(int i = 1; i < n + 1; ++i) {
		sum[i] += sum[i - 1] + l[i - 1];
		//cout<<sum[i]<<' ';
		if(sum[i] > x) {
			cout << i << endl;
			return 0;
		}
	}
	if(sum[n] <= x)
		cout << n+1 << endl;
	else
		cout << 0 << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include <stdio.h>
#include<string>
using namespace std;
string s[1000], t,ma,hi; int i=0,j[1000],times=0;
int main() {
	while (cin>>s[i])
	{
		for (int q=0; q < i; q++) {
			if (s[i] == s[q]) { j[q]++; }if (j[q] > times) { hi = s[q]; times = j[q]; }
	}
		if (ma.size() < s[i].size())ma = s[i];
		i++;
	}
	cout << hi << " " << ma<<endl;
	return 0;
}


Measured memory_bytes: 3060
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long A, B;
    scan(A, B);
    max(0, A - B * 2).writeln();
}


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

bool b[2][MAX];
int dp[MAX][MAX], s[2][MAX][MAX];

int main(){
  int n, d;
  char c;
  scanf("%d", &n);
  for(int i = 0; i < n*2; i++){
    cin >> c >> d;
    bool t = (c == 'B');
    int k = 0;
    b[t][--d] = true;
    for(int j = d+1; j < n; j++) k += b[t][j];
    s[t][d][n] = k;
    for(int j = n-1; j >= 0; j--) s[t][d][j] = s[t][d][j+1] + b[!t][j];
  }
  for(int i = 1; i <= n; i++){
    dp[0][i] = dp[0][i-1] + s[1][i-1][0];
    dp[i][0] = dp[i-1][0] + s[0][i-1][0]; 
  }
  for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++)
    dp[i][j] = min(dp[i-1][j] + s[0][i-1][j], dp[i][j-1] + s[1][j-1][i]);
  printf("%d\n", dp[n][n]);
}

Measured memory_bytes: 47488
n = int(input())
minab=10**20
for i in range(1,n//2+1):
    a = str(i)
    b = str(n-i)
    sumab=0
    for j in range(len(a)):
        sumab += int(a[j])
    for j in range(len(b)):
        sumab += int(b[j])
    minab = min(minab,sumab)
print(minab)

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

int main(){
  string s;
  cin >> s;
  if(s.length()%2==0){
    r(i,s.length()/2)cout << s.at(2*i);
  }
  else r(i,s.length()/2+1)cout << s.at(2*i);
  cout << endl;
}

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

using namespace std;

long long inf=1000000007;
set<char> counter;

void solve(vector<unordered_map<char,long long>> &seg,long long a,long long b,long long k,long long l,long long r){
	if(r<=a || b<=l) return;
	else if(a<=l && r<=b){
		for(char tmp='a';tmp<='z';tmp++){
			if(seg.at(k).count(tmp)){
				counter.insert(tmp);
			}
		}
	}else{
		solve(seg,a,b,k*2+1,l,(l+r)/2);
		solve(seg,a,b,k*2+2,(l+r)/2,r);
	}
}

int main(){
	long long n,q;
	string s;
	cin>>n>>s>>q;
	long long N=1;

	while(N<s.size()){
		N*=2;
	}

	vector<unordered_map<char,long long>> seg(2*N-1);

	for(long long i=0;i<s.size();i++){
		long long I=i+N-1;
		seg.at(I)[s.at(i)]=1;

		while(I>0){
			I=(I-1)/2;
			seg.at(I)[s.at(i)]++;
		}
	}

	for(long long i=0;i<q;i++){
		long long ord,x;
		cin>>ord>>x;

		if(ord==1){
			char pre;
			for(char tmp='a';tmp<='z';tmp++){
				if(seg.at(x+N-2).count(tmp)) pre=tmp;
			}

			char now;
			cin>>now;
			long long I=x+N-2;

			while(I>=0){
				seg.at(I).at(pre)--;
				seg.at(I)[now]++;
				if(seg.at(I).at(pre)<=0) seg.at(I).erase(pre);

				if(I==0) break;
				I=(I-1)/2;
			}
		}else{
			long long l,r;
			l=x;
			cin>>r;
			l--;

			counter.clear();
			solve(seg,l,r,0,0,N);
			cout<<counter.size()<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 202740
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
const int maxn = 111;
int n, m;
char mat[maxn][maxn];
int dp[maxn][maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i<= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> mat[i][j];
	memset(dp, 0x3f, sizeof dp);
	dp[1][1] = mat[1][1]=='#';
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(i < n) {
				dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (mat[i][j]=='.'&&mat[i+1][j]=='#')); 
			}
			if(j < m) {
				dp[i][j+1] = min(dp[i][j+1], dp[i][j] + (mat[i][j]=='.'&&mat[i][j+1]=='#')); 
			}
		}
	}
	cout << dp[n][m] << '\n';
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==5&&b==7&&c==5)cout << "YES";
    else if(a==5&&b==5&&c==7)cout << "YES";
    else if(a==7&b==5&&c==5)cout << "YES";
    else cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int a, int b) {
   if (b == 0)
   return a;
   return gcd(b, a % b);
}
int main()
{
    int k;
    cin >> k;
    long long sum = 0;
    for(int a = 1; a <= k; a++)
    {
        for(int b = 1; b <= k; b++)
        {
            for(int c = 1; c <= k; c++)
            {
                sum += gcd(gcd(a,b), c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

import math

n = int(input())
l = list(input().split(" "))
l = [int(element) for element in l]

end = max(l)

dist = []

for i in range(1,end+1):
  s = 0
  for e in l:
    s += (e - i)**2
  dist.append(s)

print(min(dist))




Measured memory_bytes: 3060
A,B,C,X,Y = map(int,input().split())
Z = min(X,Y)
if ((A+B)*Z <= C*2*Z):
  if (X <= Y):
    if (B <= 2*C):
      print((A+B)*Z+B*(Y-Z))
    else:
      print((A+B)*Z+2*C*(Y-Z))
  else:
    if (A <= 2*C):
      print((A+B)*Z+A*(X-Z))
    else:
      print((A+B)*Z+2*C*(X-Z))
else:
  if (X <= Y):
    if (B <= 2*C):
      print(2*C*Z+B*(Y-Z))
    else:
      print(2*C*Z+2*C*(Y-Z))
  else:
    if (A <= 2*C):
      print(2*C*Z+A*(X-Z))
    else:
      print(2*C*Z+2*C*(X-Z))

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(){
	int a,b,c=0;
	double x=0,y=0,rad;
	while(1){
		scanf("%d,%d",&a,&b);
		if(a==0&&b==0){
			printf("%d\n%d\n",(int)y,(int)x);
			return 0;
		}
		rad=4*atan(1)*(90-c)/180;
		x+=a*sin(rad);
		y+=a*cos(rad);
		c+=b;
	}
}

Measured memory_bytes: 604
#木の根を得る
def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合
def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

def size(x):
    return -par[root(x)]

def same(x, y):
    rx = root(x)
    ry = root(y)
    return rx == ry

N, M = map(int,input().split())
par = [-1]*N
K = []
for i in range(M):
    a, b = map(int, input().split())
    K.append([a-1, b-1])
K = K[::-1]

result = [0]
ans = 0
for i, j in K:
    if not same(i, j):
        a = size(i)
        b = size(j)
        unite(i, j)
        c = size(i)
        ans += c*(c-1)//2 - (a*(a-1)//2 + b*(b-1)//2)
    result.append(ans)

result = result[::-1]
for i in result[1:]:
    print(result[0] - i)

Measured memory_bytes: 97640
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
int a,b;
int main(){
    cin>>a>>b;
    if(a==b){
        rep(i,0,a){
            printf("%d",a);
        }
    }else if(a>b){
        rep(i,0,a){
            printf("%d",b);
        }
    }else{
        rep(i,0,b){
            printf("%d",a);
        }
    }
}

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

#define ll unsigned long long

using namespace std;


int main(){

	ll n,k,x;
	cin >> n >> k;

	vector<ll>vs;

	for(ll i=0;i<k;i++){
		cin >> x;
		vs.push_back(x);
	}


	for(ll i=k;i<n;i++){
		cin >> x;
		vs.push_back(x);
		if(x>vs[i-k])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
		// prev=curr;
	}



	return 0;
}

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

#define ll long long

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

	ll k,cur=100,ans=0;
	cin>>k;
	while(cur<k){
		cur+=(cur/100);
		++ans;
	}
	cout<<ans<<"\n";
	return 0;
}


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

namespace ConsoleApp43 {
    class Program {
        static void Main(string[] args) {
            int x = int.Parse(Console.ReadLine());

            if (x < 1200) {
                Console.WriteLine("ABC");
            } else {
                Console.WriteLine("ARC");
            }
        }

    }
}


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

void BubbleSort(string card[36], int N) {
	for (int i=0; i<N; i++) {
		for (int j=N-1; j>i; j--) {
			if (card[j-1][1] > card[j][1]) {
				string tmp = card[j-1];
				card[j-1] = card[j];
				card[j] = tmp;
			}
		}
	}
}

void SelectionSort(string card[36], int N) {
	for (int i=0; i<N; i++) {
		int minj = i;
		for (int j=i; j<N; j++) {
			if (card[j][1] < card[minj][1]) {
        minj = j;
			}
		}
		string tmp = card[i];
		card[i] = card[minj];
		card[minj] = tmp;
	}
}

int main(int argc, char const* argv[])
{
	int N;
	cin >> N;
	string card[36];
	string card2[36];
	for (int i=0; i<N; i++) {
		cin >> card[i];
		card2[i] = card[i];
	}

	BubbleSort(card, N);
	for (int i=0; i<N; i++) {
		cout << card[i];
		if (i==N-1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
	cout << "Stable" << endl;

	SelectionSort(card2, N);
	bool flag = false;
	for (int i=0; i<N; i++) {
		cout << card2[i];
		if (card2[i] !=  card[i]) {
			flag = true;
		}
		if (i==N-1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
	if (flag) {
		cout << "Not stable" << endl;
	} else {
		cout << "Stable" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
bool visit[1000005];
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	ll n,w1;
  	cin>>n>>w1;
  	ll a[n],w[n];
  	For(i,n)cin>>w[i]>>a[i];
  	ll ans[100005];
  	ans[0]=0;
  	for(ll i=0;i<100005;i++)ans[i]=w1+1;
  	ans[0]=0;
  	For(i,n)
  	{
  		for(int j=100000-a[i];j>=0;j--)
  		{
  			ans[j+a[i]]=min(ans[j+a[i]],ans[j]+w[i]);
  		}
  		//cout<<ans[30]<<" "<<a[50]<<" "<<a[60]<<" "<<a[80]<<" "<<a[120]<<endl;
  	}
  	int ans1=0;
  	for(int i=0;i<100005;i++)
  	{
  		if(ans[i]<=w1)ans1=max(ans1,i);
  	}
  	cout<<ans1<<endl;
	return 0;
}

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

int main(void){

  int n,m,l;

  cin>>n>>m>>l;

  vector<vector<int>> lmat(n,vector<int>(m));
  vector<vector<int>> rmat(m,vector<int>(l));
  vector<vector<int64_t>> res(n,vector<int64_t>(l,0));

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++) cin>>lmat.at(i).at(j);
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++) cin>>rmat.at(i).at(j);
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      for(int k=0;k<m;k++) res.at(i).at(j)+=lmat.at(i).at(k)*rmat.at(k).at(j);
      if(j==l-1){
        cout<<res.at(i).at(j)<<endl;
      }
      else cout<<res.at(i).at(j)<<" ";
    }
  }

}



Measured memory_bytes: 3272
#include <iostream>
using namespace std;
int main() {
  int a, b;
  int result;
  cin >> a >> b;
  if(a > b){
      result = 2 * a - 1;
  } else if(a < b){
      result = 2 * b - 1;
  } else{
      result = 2 * a;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 1010
using namespace std;
char s[maxn],t[maxn];
int main(){
	int i,j,mx=0,cnt,n,m;
	scanf("%s%s",s,t);
	n=strlen(s),m=strlen(t);
	for(i=0;i<n;i++){
		cnt=0;
		if(i+m-1>=n)break;
		for(j=0;j<m;j++)
			if(s[i+j]==t[j])cnt++;
		mx=max(mx,cnt);
	}
	printf("%d\n",m-mx);
	return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S;
    cin >> S;
    int zero = 0, one = 0;
    for (auto x : S) {
        if (x == '0') zero++; else one++;
    }
    cout << min(zero, one) * 2 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int A[4005]={0};

int main(){
 int n;
 cin>>n;
 if((n%10==7)||(n/10)%10==7||n/100==7)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	char S;
	for (int i = 0; i < 19; i++)
	{
		cin >> S;
		if (i == 5 || i == 13)cout << " ";
		else cout << S;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    while(x - b >= 0){
        x -= b;
    }
    cout << x << endl;
}

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

#ifdef LOCAL 
#include "/home/gokul/Codes/lib/prettyprint.hpp"
#else
#define debug(...) 2
#endif

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  long long n, m;
  cin >> n >> m;

  vector<long long> a(n), suf(n + 5, 0);
  for (int i = 0; i < n; ++i) 
    cin >> a[i];

  sort(a.begin(), a.end());
  for (int i = n-1; i >= 0; --i)
    suf[i] += a[i] + suf[i+1];

  auto count = [&](int mid) {
    long long ret = 0;
    for (int i = 0, j = n-1; i < n; ++i) {
      while (j >= 0 && a[i] + a[j] >= mid) --j;
      ret += (n-j-1);  
    }
    return ret;
  };

  long long l = 0, r = 1e6;
  while (l < r) {
    int mid = (l + r) / 2;
    if (count(mid) >= m)  l = mid + 1;
    else r = mid;
  }
  
  --l;
  debug(l);
  debug(count(l));
  long long ans = 0, cnt = 0;;
  for (int i = 0; i < n; ++i) {
    int req = l - a[i];
    int j = lower_bound(a.begin(), a.end(), req) - a.begin();
    ans += suf[j];
    ans += (n-j) * a[i];
    cnt += (n-j);
  } 

  debug(suf);
  debug(cnt);
  ans -= l * (count(l) - m);
  cout << ans << '\n';
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#define Max (int)1e5+10
#define MAX_INT (int)1e9+2

int dp[Max];
void init(){
	int i;
	for(i=0;i<Max;i++)
		dp[i] = 0;
}
void solve(int n,int a[],int k){
	int x,y,i,j;
	for(i=n-1;i>=0;i--){

		int minimum = MAX_INT;

		for(j=k;j>0;j--){
			x = MAX_INT;
			if(i+j < n){
				x = dp[i+j] + fabs(a[i+j] - a[i]);	
			}

			minimum = (minimum > x) ? x : minimum;

		}
		dp[i] = minimum == MAX_INT ? 0 : minimum;
		//printf("%d %d %d %d\n",i,dp[i],x,y);
	}

}
int main(){
	int n,a[Max],i,k;
	
	init();
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	solve(n,a,k);
	printf("%d\n",dp[0]);
	return 0;
}



/*
if(i+1 < n)
			x = dp[i+1]+abs(a[i+1]-a[i]);
		else
			x = MAX_INT;
		
		if(i+2 < n)
			y = dp[i+2]+abs(a[i+2]-a[i]);
		else
			y = MAX_INT;

*/

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main () {
  string N;
  cin >> N;
  string b = "No";
  for(int i = 0; i < N.size(); i++){
    if(N.at(i) == '7'){
      b = "Yes";
      break;
    }
  }
  cout << b << endl;
}

Measured memory_bytes: 3612
import itertools
import numpy as np

n, m, x = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for _ in range(n)]
costs = [i[0] for i in table]
acc = [i[1:] for i in table]

ret = 10 ** 9
for i in itertools.product([True, False], repeat=n):
  algos = np.zeros(m)
  for book, t_f in enumerate(i):
    if t_f:
      algos += acc[book]
  if np.all(algos >= x):
    ret = min(ret, (np.array(costs) * i).sum())

print(ret if ret != 10 ** 9 else -1)

Measured memory_bytes: 27304
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <tuple>
#include <unordered_map>
#include <vector>

#include <boost/range/adaptors.hpp>


int main() {
    int N;
    int K;
    std::cin >> N >> K;

    std::vector<int> having(N, 0);
    for (int i = 0; i < K; ++i) {
      int d;
      std::cin >> d;
      for (int j = 0; j < d; ++j) {
        int x;
        std::cin >> x;
        having[x - 1] = 1;
      }
    }
    int count = 0;
    for (auto x : having) {
      if (x == 0) ++count;
    }
    std::cout << count << std::endl;

    return 0;
}


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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

using pii = pair<ll, ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    ll ans = INF;
    if (n % a == 0) ans = n / a * b;
    else ans = (n / a + 1) * b;

    if (n % c == 0) chmin(ans, n / c * d);
    else chmin(ans, (n / c + 1) * d);

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



Measured memory_bytes: 3172
n = int(input())
s = list(map(int, input().split()))

m = 1000
stock = 0

for i in range(n-1):
  if s[i+1] >= s[i]:
    #buy
    stock = stock + m // s[i]
    m = m - s[i]*(m//s[i])
  else:
    #sell
    m = m + stock*s[i]
    stock = 0

an  = m + stock*s[n-1]
print(an)

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;
int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	ll n;
	cin>>n;
	vector<PII> p(n);
	REP(i,n){
		int a,b;cin>>a>>b;
		p[i]=make_pair(b,a);
	}
	VSORT(p);

	string ans="Yes";
	int now=0;
	REP(i,n){
		now+=p[i].second;
		if(p[i].first<now)ans="No";
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO 1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
map<int,set<int> > mp;
int main()
{
    IO;
    string s,k;
    cin >> s >> k;
    int n=s.size();
    for(int i=0;i<n;++i)
        mp[k[i]-'a'].insert(s[i]-'a');
    vector<bool> vis(26,false);
    for(auto i:mp){
        if(i.s.size()>1)re cout<<"No\n",0;
        for(auto j:i.s){
            if(vis[j])re cout<<"No\n",0;
            vis[j]=true;
        }
    }
    cout<<"Yes\n";
    re 0;
}

Measured memory_bytes: 916
#include<cstdio>
#include<cstdlib>
#define NIL NULL

struct node {
  struct node * right;
  struct node * left;
  struct node * parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x) {
  while (x->left != NIL) x = x->left;
  return x;
};
Node treeMaximum(Node x) {};

Node treeSearch(Node u, int k) {
  Node x = u;

  while (x != NIL) {
    if (k < x->key) x = x->left;
    else if (x->key < k) x = x->right;
    else break;
  }

  return x;
};

Node treeSuccessor(Node x) {
  return treeMinimum(x->right);
};

void treeDelete(Node z) {
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || z->right == NIL) {
    y = z;
  } else {
    y = treeSuccessor(z);
  }

  if (y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if (x != NIL) x->parent = y->parent;

  if (y->parent == NIL) {
    root = x;
  } else if (y == y->parent->left) {
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }

  if (y != z) z->key = y->key;
}

void insert(int k) {
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s", &com);
    if (com[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    } else if (com[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com[0] == 'f') {
      scanf("%d", &x);
      Node n = treeSearch(root, x);
      if (n == NIL) printf("no\n");
      else printf("yes\n");
    } else if (com[0] == 'd') {
      scanf("%d", &x);
      Node n = treeSearch(root, x);
      treeDelete(n);
    }
  }

  return 0;
}



Measured memory_bytes: 21332
#a,bの最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

#a,bの最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

#べき乗関数powを使った逆元の計算(modinvよりもPythonでは高速、PyPyだと遅い)
def modinv2(a,m):
    return pow(a,m-2,m)


N = int(input())
A = list(map(int,input().split()))
P = 10**9+7

if N == 1:
    ans = 1

else:

    A.sort()

    inv = modinv2(A[0],P)
    g = A[0]
    invlist = []
    seki = A[0]%P

    for i in range(1,N):
        inv = (inv+modinv2(A[i],P))%P
        seki = seki*A[i]%P

    g = gcd(A[0],A[1])
    l = A[0]//g*A[1]
    cc = modinv2(g,P)
    for i in range(2,N):
        g = gcd(l,A[i])
        l = l//g*A[i]
        cc = cc*modinv2(g,P)%P

    ans = (inv*seki%P)*cc%P

print(ans)


Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 2008;
char mat[MAXN][MAXN];

int up[MAXN][MAXN];
int down[MAXN][MAXN];
int le[MAXN][MAXN];
int ri[MAXN][MAXN];

int h, w; 

int main()
{
    cin >> h >> w;
    int i, j;
    for(i = 0; i < h; i++)
        cin >> mat[i];
        
    for(i = 0; i < h; i++)
    {
        for(j = 0; j < w; j ++)
        {
            if(mat[i][j] == '#')
            {
                up[i][j] = le[i][j] = 0;
            }
            else
            {
                if(i == 0)
                    up[i][j] = 1;
                else
                    up[i][j] = up[i - 1][j] + 1;
                if(j == 0)
                    le[i][j] = 1;
                else
                    le[i][j] = le[i][j-1] + 1;
            }
        }
    }
    
    for(i = h - 1; i >= 0; i--)
    {
        for(j = w - 1; j >= 0; j--)
        {
            if(mat[i][j] == '#')
            {
                down[i][j] = ri[i][j] = 0;
            }
            else
            {
                if(i == h - 1)
                    down[i][j] = 1;
                else
                    down[i][j] = down[i + 1][j] + 1;
                if(j == w - 1)
                    ri[i][j] = 1;
                else
                    ri[i][j] = ri[i][j + 1] + 1;
            }
        }
    }
    
    int ans = 0;
    for(i = 0; i < h; i++)
    {
        for(j = 0; j < w; j ++)
        {
            ans = max(ans, up[i][j] + down[i][j] + le[i][j] + ri[i][j] - 3);
        }
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 67200
#include<stdio.h>

int main(){
    int a,b,c;


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

    int max,mid,min;


    if(a >b && a > c){
        max=a;
        if(b<c){
            min=b;
            mid=c;
        }
        else{
            min=c;
            mid=b;
        }

    }
    else if(b>a&&b>c){
        max=b;
        if(a<c){
            mid=c;
            min=a;
        }
        else{
            mid=a;
            min=c;
        }
    }
    else if(c>a&&c>b){
        max=c;
        if(a<b){
            mid=b;
            min=a;
        }
        else{
            mid=a;
            min=b;
        }
    }
    printf("%d %d %d\n",min,mid,max);
    return 0;
}



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

int main() {
  int N,K; // N:回数, K：Bの位置
  cin >> N >> K; 
  
  int value = 0;
  int x; // ボールの位置
  for (int i=0; i<N; i++) {
    cin >> x;
  	if (x*2 <= abs(K-x)*2) {
    	value += x*2;
  	} else {
    	value += abs(K-x)*2;
    }
  }
  cout << value << endl;
}

Measured memory_bytes: 256
s = input()
if (len(s)%2==1):
    print("No")
    exit()
for i in range(len(s)):
    if (i%2==0):
        if (s[i]!="h"):
            print("No")
            exit()
    else:
        if (s[i]!="i"):
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long 
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
vector< vector<ll int> > dp;
ll int a[105],b[105];
ll int n,w;
ll int knapsack(int pos,ll int w)
{
	if(w<=0)
		return 0;
	if(pos>=n)
		return 0;


	if(dp[pos][w]!=-1)
		return dp[pos][w];
	if(w<a[pos])
		return dp[pos][w]=knapsack(pos+1,w);	
	if(pos==n-1)
		return dp[pos][w]=b[pos]; 
	return dp[pos][w]=max(knapsack(pos+1,w),knapsack(pos+1,w-a[pos])+b[pos]);



}

int main()
{ quick;

	
	cin>>n>>w;
	
	fab(0,n,i)
	cin>>a[i]>>b[i];
	dp=vector< vector<ll int> > (n,vector<ll int>(w+1,-1));
	knapsack(0,w);
	cout<<dp[0][w]<<endl;


	return 0;
}

Measured memory_bytes: 79488
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;

    cin >> a;

    if(a<1200) cout <<  "ABC";
    else cout << "ARC";

    return 0;
}

Measured memory_bytes: 256
x = int(input())
eps = 10**-10

B = [0]
for i in range(10**5):
    B.append(i)
    B.append(-i)

for b in B:
    if x + b**5 >= 0:
        c = (x + b**5) ** 0.2
        if abs(c - int(c)) < eps:
            print(int(c), b)
            break
        elif abs(c - (int(c)+1)) < eps:
            print(int(c)+1, b)
            break 

Measured memory_bytes: 78896
n = int(input())

count = [0] * (n + 1)

for x in range(1, 10 ** 2 + 1):
    for y in range(1, 10 ** 2 + 1):
        for z in range(1, 10 ** 2 + 1):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= n:
                count[ans] += 1

for i in range(1, n + 1):
    print(count[i])



Measured memory_bytes: 74628
N, M = map(int, input().split())
G = [[] for i in range(N)]
E = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)
    E.append((a, b))


def dfs(v, pre, s, ng):
    if used[v]:
        return
    used[v] = 1
    s.add(v)
    for u in G[v]:
        if u == pre:
            continue
        if (u, v) != ng and (v, u) != ng:
            dfs(u, v, s, ng)
    return


num = 0
for i in E:
    used = [0] * N
    s = set()
    dfs(0, -1, s, i)
    if len(s) == N:
        num += 1

print(M - num)


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

int main() {
  int a, b, i, count = 0;
  
  cin >> a >> b;
  i = a;
  while(i <= b){
    int num_up2, num_down2;
    num_up2 = i / 1000;
    num_down2 = i % 100;
    if(num_up2 / 10 == num_down2 % 10 && num_up2 % 10 == num_down2 / 10)
      count++;
    i++;
  }
 
 cout << count << endl;   
}


Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
vector<ll>to[200005];
ll ans[200005] = {};
int main() {
	ll n,q;
	cin >> n>>q;
	int a, b;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	int p,x;
	for (int i = 0; i < q; i++) {
		cin >> p >> x;
		p--;
		ans[p] += x;
	}

	vector<ll>dist(n, inf);
	queue<ll>que;
	dist[0] = 0;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int id : to[v]) {
			if (dist[id] != inf)continue;
			dist[id] = dist[v] + 1;
			ans[id] += ans[v];
			que.push(id);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;

}



Measured memory_bytes: 19440
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff

def divisor_num(n):
    a = 1
    for _, x in factorization(n):
        a *= x + 1
    return a

n = int(input())

cnt = 0
for x in range(n + 1):
    if x % 2 == 1:
        if divisor_num(x) == 8:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream> 
using namespace std;
int main() {
    string s; cin >> s;
    int a, b, c, d;
    a = s[0] - '0'; b = s[1] - '0'; c = s[2] - '0'; d = s[3] - '0';
    if (a + b + c + d == 7)
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    else if (a + b + c - d == 7)
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    else if (a + b - c - d == 7)
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    else if (a - b + c - d == 7)
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    else if (a - b - c + d == 7)
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    else if (a + b - c + d == 7)
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    else if (a - b - c - d == 7)
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
    else
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
MAX = 10 ** 6 + 10
cnt = [0] * MAX  # cntが1以上ならその数以下に約数が1個以上存在する(自分も含める)

for a in A:
    if cnt[a] != 0:
        cnt[a] += 1
        continue
    for j in range(a, MAX, a):
        cnt[j] += 1
ans = 0
for a in A:
    if cnt[a] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32392
function main(input) {
	var array = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
	var result = 0;
	while(array.every((n) => (n % 2) === 0)) {
		result += 1;
		array = array.map((n) => (n / 2));
	}
	console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7880
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int X, N; std::cin >> X >> N;
  std::vector<int> p(N); rep(i,N) std::cin >> p[i];

  std::set<int> s;
  for(int i=-200; i<=200; i++) s.insert(i);
  rep(i,N) s.erase(p[i]);

  int ans = -1;
  int value = 1e5;
  for(auto&& t : s) {
    int a = std::abs( X - t );
    if ( value > a ) {
      ans = t;
      value = a;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 3664
#include <stdio.h>
#include <memory.h>

int bubble_sort(int lst[], int n);

int main(void) {
	int i, n;
	int lst[100];
	int count;
	memset((char*)lst, 0x00, sizeof(lst));

	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &lst[i]);
	}
	
	count = bubble_sort(lst, n);
	
	for(i=0;i<n;i++) {
		printf("%d", lst[i]);
		if(i<n-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}
	printf("%d\n", count);
	
	return 0;
}

int bubble_sort(int lst[], int n) {
	int i, j, tmp, count;
	for(i=0,count=0;i<n-1;i++) {
		for(j=n-1;j>i;j--) {
			if(lst[j-1] > lst[j]) {
				tmp = lst[j];
				lst[j] = lst[j-1];
				lst[j-1] = tmp;
				count++;
			}
		}
	}
	
	return count;
}

Measured memory_bytes: 604
#include <iostream>

    using namespace std;

    typedef long long int lint;

    const int NMAX = 100000 + 5;

    int N;
    lint A[NMAX];
    lint APrim[NMAX];
    lint mars[2 * NMAX];

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

        cin >> N;
        for (int i = 1; i <= N; ++ i)
            cin >> A[i];

        lint S = 0;
        for (int i = 1; i <= N; ++ i)
            S += A[i];

        lint onePass = N * (N + 1LL) / 2;
        if (S % onePass != 0) {
            cout << "NO\n";
            return 0;
        }

        lint passes = S / onePass;
        APrim[0] = A[N];
        for (int i = 1; i <= N; ++ i)
            APrim[i] = A[i];

        lint sumAPrim = 0;
        for (int i = N; i; -- i) {
            APrim[i] -= APrim[i - 1];
            APrim[i] -= passes;
            APrim[i] *= (-1);

            if (APrim[i] < 0 || APrim[i] % N != 0) {
                cout << "NO\n";
                return 0;
            }
            APrim[i] /= N;
            sumAPrim += APrim[i];
        }

        if (sumAPrim != passes)
            cout << "NO\n";
        else {
            //Build waves generators
            for (int i = 1; i <= N; ++ i) {
                mars[i] += APrim[i];
                mars[i + N] -= APrim[i];
            }
            for (int i = 1; i <= 2 * N; ++ i)
                mars[i] += mars[i - 1];

            //Propagate one -N for every wave, so that it suddenly stops
            for (int i = 1; i <= N; ++ i)
                mars[i + N] -= APrim[i] * N;
            for (int i = 1; i <= 2 * N; ++ i)
                mars[i] += mars[i - 1];

            //Build circularity
            for (int i = 1; i <= N; ++ i)
                mars[i] += mars[i + N];

            //Final check
            for (int i = 1; i <= N; ++ i)
                if (mars[i] != A[i]) {
                    cout << "NO\n";
                    return 0;
                }
        }

        cout << "YES\n";
        return 0;
    }


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

int main(void){
  int N,A[100005],sum,charge,i,j;
  char str[600000],*p;
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  A[0]=0;
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  A[1]=atoi(p);
  for(i=2;i<=N;i++){
   p=strtok(NULL," \n");
   A[i]=atoi(p);
  }
  for(i=1;i<=N;i++){
    sum+=abs(A[i]-A[i-1]);
  }
  sum+=abs(A[N]-A[0]);
  
  for(i=1;i<=N;i++){
    charge=sum;
    if(i==N){
     charge=charge-abs(A[N]-A[N-1])-abs(A[N]-A[0])+abs(A[N-1]-A[0]);
      printf("%d\n",charge);
      break;
    }
   charge-=abs(A[i]-A[i-1]),charge-=abs(A[i+1]-A[i]);
    charge+=abs(A[i+1]-A[i-1]);
    printf("%d\n",charge);
  }
  
  return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n, m, c;
    cin>>n>>m>>c;
    vector<int> bs(m);
    cin>>bs;
    int cnt = 0;
    rep(i, n) {
        vector<int> as(m);
        cin>>as;
        ll acc = 0;
        rep(i, m) {
            acc += as[i] * bs[i];
        }
        acc += c;
        if (acc > 0) cnt++;
    }
    cout<<cnt<<endl;
}

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

namespace Toggling_Cases
{
    class Program
    {
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            char[] str = input.ToArray();
            for (int i = 0; i < str.Length; ++i)
            {
                if (char.IsUpper(str[i]))
                {
                    str[i] = char.ToLower(str[i]);
                }
                else if (char.IsLower(str[i]))
                {
                    str[i] = char.ToUpper(str[i]);
                }
            }
            String output = new String(str);
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 9496
import sys
from collections import defaultdict
input = sys.stdin.readline

n, k = map(int, input().split())
a_tuple = tuple(map(int, input().split()))
count_dict = defaultdict(int)

for i in a_tuple:
    count_dict[i] += 1

n = len(count_dict.keys())

if n <= k:
    print(0)
else:
    ans = sum(tuple(sorted(count_dict.values()))[:n-k])
    print(ans)


Measured memory_bytes: 34032