akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 100010;
const int INF = 2147483600;

int N,M;
int E[21][21]; LL g[(1<<16)];
int sta[21],top;
LL f[21][(1<<16)];
LL ret,ans;
pair<int,int> Tns[21][(1<<16)];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(),M=read();
	memset(E,-1,sizeof(E));
	for(int i=1;i<=M;i++){
		int u=read(),v=read(),w=read();
		E[u][v]=E[v][u]=w; ret+=w;
	}
	for(int i=1;i<(1<<N);i++){
		top=0; for(int j=1;j<=N;j++) if((1<<(j-1))&i) sta[++top]=j;
		for(int j=1;j<=top;j++){
			for(int k=j+1;k<=top;k++){
				if(E[sta[j]][sta[k]]!=-1)
					g[i]+=E[sta[j]][sta[k]];
			}
		}
	}
	memset(f,-127,sizeof(f)); f[0][0]=0;
	for(int j=1;j<(1<<N);j++){
		for(int i=1;i<=N;i++){
			if(!(j&(1<<(i-1)))) continue;
			if(!((j&1)&&(j&(1<<(N-1))))) {
				if((j&(1<<(N-1)))) {if(i==N) f[i][j]=g[j];}
				else if((j&1)) {if(i==1) f[i][j]=g[j];}
				else f[i][j]=g[j];
			}
			for(int k=1;k<=N;k++){
				if(E[k][i]==-1) continue;
				if(!(j&(1<<(k-1)))) continue;
				for(int p=j;p>0;p=(p-1)&j){
					if(!((j^p)&(1<<(i-1)))) continue;//cout<<j<<" "<<p<<" "<<i<<" "<<k<<endl;
					if(!(p&(1<<(k-1)))) continue;
					if(i!=1&&((j^p)&1)) continue;
					if(i!=N&&((j^p)&(1<<(N-1)))) continue;
					if(f[k][p]<0) continue;
					f[i][j]=max(f[i][j],f[k][p]+g[j^p]+E[k][i]);
					//if(f[i][j]==f[k][p]+g[j^p]+E[k][i]) Tns[i][j]=make_pair(k,p);
				}
			}
			if((j&(1<<(N-1)))&&(j&1)) {
				ans=max(ans,f[i][j]);
			}
		}
	} printf("%lld\n",ret-ans);
	return 0;
}


Measured memory_bytes: 12028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mmax=1e2+5;
struct node{
    string str;
    int so;
    int id;
}a[mmax];
int cmp(node a,node b)
{
    if(a.str==b.str)
        return a.so>b.so;
    return a.str<b.str;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].str>>a[i].so;
        a[i].id=i+1;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)
    cout<<a[i].id<<endl;
}


Measured memory_bytes: 256
def p_b():
    s = input()
    s = s.replace("A", ".").replace("T", ".").replace("C", ".").replace("G", ".")
    ans = 0
    tmp = 0
    for e in s:
        if e != ".":
            ans = max(ans, tmp)
            tmp = 0
        else:
            tmp += 1
    ans = max(ans, tmp)
    print(ans)
    
p_b()

Measured memory_bytes: 38256
#include<iostream>
#include<map>
#include<cassert>
int64_t n,a,b,c,d;
std::map<int64_t,int64_t> memo;

int64_t dfs(int64_t n){
  if(memo.count(n)){
    return memo[n];
  }
  int64_t tmp = (1LL<<58);
  if(n<tmp/d)tmp=n*d;
  if(n%2==0)tmp = std::min(tmp,dfs(n/2)+a);
  else{
    tmp = std::min(tmp,dfs((n+1)/2)+a+d);
    tmp = std::min(tmp,dfs((n-1)/2)+a+d);
  }
  if(n%3==0)tmp = std::min(tmp,dfs(n/3)+b);
  else{
    int64_t low3 = n/3*3;
    int64_t high3 = (n/3+1)*3;
    assert(low3<n&&n<high3);
    tmp = std::min(tmp,dfs(low3/3)+b+d*(n-low3));
    tmp = std::min(tmp,dfs(high3/3)+b+d*(high3-n));
  }
  if(n%5==0)tmp = std::min(tmp,dfs(n/5)+c);
  else{
    int64_t low5 = n/5*5;
    int64_t high5 = (n/5+1)*5;
    assert(low5<n && n<high5);
    tmp = std::min(tmp,dfs(low5/5)+c+d*(n-low5));
    tmp = std::min(tmp,dfs(high5/5)+c+d*(high5-n));
  }
  return memo[n] = tmp;
}

void solve(){
  std::cin>>n>>a>>b>>c>>d;
  memo.clear();
  memo[0] = 0;
  memo[1] = d;
  dfs(n);
  std::cout<< memo[n] <<std::endl;
}

int main(){
  int t;
  std::cin>>t;
  while(t--)solve();
}


Measured memory_bytes: 4400
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] lArr = new long[n+1];

        lArr[0] = 2;
        lArr[1] = 1;
        for (int i = 2; i <= n; i++) {
            lArr[i] = lArr[i-1] + lArr[i-2];
        }

        System.out.println(lArr[n]);
    }
}


Measured memory_bytes: 21844
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;

int main() {
	int64 N;
	cin >> N;
	string ans;
	while (N) {
		N--;
		char tmp = N % 26  + 'a';
		ans = tmp + ans;
		N /= 26;
	}
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
int main()
{
    char c;
    int arr[26]={0};
    while(1)
    {
        c=getchar();
        if(c=='\n')
            break;
        arr[c-'a']++;
    }
    for(int i=0;i<26;i++)
    {
        if(arr[i]%2==1)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *


S = list(input())
K = INT()

if len(Counter(S).values()) == 1:
	print(len(S)*K//2)
	exit()

S_one = S.copy()
S_two = S*2

inner = 0
outer = 0

tmp = ""
for i, s in enumerate(S_one):
	if tmp == s:
		S_one[i] ="_"
		inner += 1
		tmp = ""
	else:
		tmp = s

tmp = ""
for i, s in enumerate(S_two):
	if tmp == s:
		S_two[i] = "_"
		outer += 1
		tmp = ""
	else:
		tmp = s

outer -= inner
print(inner+outer*(K-1))

Measured memory_bytes: 5396
///created: 13/Jun/2019 10:27:22

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define db(x) cerr << "debug: " << #x << " = " << x << '\n';
template<class __Ty> bool minimize(__Ty& a, __Ty b) {
	if (a > b) { a = b; return true; }
	return false;
}
template<class __Ty> bool maximize(__Ty& a, __Ty b) {
	if (a < b) { a = b; return true; }
	return false;
}

const int modulo = 1e9 + 7;
int n, w, k, dp[101][9] = {0};

int main() {
	///ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> w >> k;
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < w; ++j)
			for (int k = 0; k < (1 << (w - 1)); ++k) {
				bool ts = true;
				for (int z = 0; z < w - 2; ++z)
					if ((k & (1 << z)) && (k & (1 << (z + 1))))
						ts = false;
				if (!ts) continue;
				int next = j;
				if ((k >> j) & 1)
					next++;
				if (j > 0 && ((k >> (j - 1)) & 1))
					next--;
				dp[i + 1][next] = (dp[i + 1][next] + dp[i][j]) % modulo;
			}
	cout << dp[n][k - 1];
	return 0;
}


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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  cout << m * 1900 * pow(2, m) + (n - m) * 100 * pow(2, m) << "\n";
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 < i; i--)
#define FOR(i, from, to)                                                       \
  for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to)                                               \
  for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

#define MOD (ll)1000000007

int main() {
  llv bingo(3 * 3);
  rep(i, 9) cin >> bingo[i];
  ll n;
  cin >> n;
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    rep(i, 9) if (bingo[i] == tmp) bingo[i] = 0;
  }

  if ((bingo[0] + bingo[1] + bingo[2]) * (bingo[3] + bingo[4] + bingo[5]) *
      (bingo[6] + bingo[7] + bingo[8]) * (bingo[0] + bingo[3] + bingo[6]) *
      (bingo[1] + bingo[4] + bingo[7]) * (bingo[2] + bingo[5] + bingo[8]) *
      (bingo[0] + bingo[4] + bingo[8]) * (bingo[2] + bingo[4] + bingo[6]))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<vector<int> > road;
int sum;
int count(int np, int lu, int nc){
    int a=0, b=0;
    for(int i=0;i<road[np].size();++i){
        if(road[np][i]==lu)continue;
        int c = count(road[np][i], np, nc+1);
        if(c>a){
            b=a;
            a=c;
        }else if(c>b){
            b=c;
        }
    }
    sum = max(sum, max(a+b, max(a+nc, b+nc))+1);
    return a+1;
}

int main(){
    int N;
    cin>>N;
    road.resize(N+1);
    for(int i=1;i<N;++i){
        int a, b;
        cin>>a>>b;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    count(1, -1, 0);
    sum %= 3;
    if(sum==0){
        cout << "First" << endl;
    }else if(sum == 1){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    return 0;
}


Measured memory_bytes: 26112
import sys

def gcd(a, b):
    "?????§??¬?´???°????±???????"
    if a < b:
        c = a
        a = b
        b = c
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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

for line in sys.stdin:
    a, b = map(int, line.split())
    print("%d %d" % (gcd(a, b), lcm(a, b)))

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

using namespace std;

#define re register
#define gc getchar()
#define ll long long
int read() {
	re int x(0),f(1);re char ch(gc);
	while(ch>'9'||ch<'0') f=ch=='-'?-1:1,ch=gc;
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc;
	return x*f;
}

const int N=101;
int n,m,x[N][N],f[N][N],g[N][N];
char s[N];

#define FOR(a,n,m) for(int a=n;a<=m;++a)  

signed main() {
	n=read(),m=read();
	FOR(i,1,n) {scanf("%s",s+1);FOR(j,1,m)x[i][j]=(s[j]=='#');}
	FOR(i,2,n) f[i][0]=g[i][0]=1111;
	FOR(i,2,m) f[0][i]=g[0][i]=1111;
	FOR(i,1,n) FOR(j,1,m) {
		if(!x[i][j]) {
			int a=min(f[i-1][j],f[i][j-1]);
			int b=min(g[i-1][j],g[i][j-1]); 
			f[i][j]=min(a,b+1);
			g[i][j]=min(a,b)+1; 
		} 
		else {
			int a=min(f[i-1][j],f[i][j-1]);
			int b=min(g[i-1][j],g[i][j-1]);
			f[i][j]=min(a,b+1)+1;
			g[i][j]=min(a,b); 
		}
	}
	cout<<min(f[n][m],g[n][m]+1)<<'\n';
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
#define Re register
#define fo(i, a, b) for (Re int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (Re int i = (a); i >= (b); --i)
#define edge(i, u) for (Re int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define pb push_back
#define F first
#define S second
#define ll long long
#define inf 1000000007
#define mp std::make_pair
#define lowbit(x) (x & -x)
#define eps 1e-4
#define itset std::set<node>::iterator
#define lb lower_bound
#define N 605
#define M 4000005
#define mod 1000000007
int n, k, pi[N], x, y, sum[N];
ll g[N], dp[N][N], ans;
inline int f (int x, int y) {return y - x + 1 - (sum[y] - sum[x - 1]);}
int main ()
{
    scanf("%d %d", &n, &k);
    fo (i, 1, k)
    {
        scanf("%d %d", &x, &y);
        pi[x] = y; pi[y] = x;
        sum[x] = 1; sum[y] = 1;
    }
    n <<= 1;
    fo (i, 2, n) sum[i] += sum[i - 1];
    g[0] = 1;
    for (int i = 2; i <= n; i += 2) g[i] = (i - 1) * g[i - 2] % mod;
    fo (i, 1, n)
    {
        fo (j, i, n)
            if ((j - i) & 1)
            {
                bool flag = 0;
                fo (k, i, j)
                    if (pi[k] && pi[k] < i || pi[k] > j)
                    {
                        flag = 1;
                        break;
                    }
                if (flag) continue;
                dp[i][j] = g[f(i, j)];
                fo (k, i + 1, j - 1)
                    dp[i][j] = (dp[i][j] - dp[i][k] * g[f(k + 1, j)]) % mod;
            }
    }
    k <<= 1;
    fo (i, 1, n)
        fo (j, i, n)
            if (dp[i][j])
                ans = (ans + dp[i][j] * g[n - (j - i + 1) - (k - sum[j] + sum[i - 1])]) % mod;
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;

int main () {
    string s;
    cin >> s;
    long long int a, b;
    a=b=0;
    for(int i = 0 ; i < s.size() ; i++ ) {
        if(s[i]=='0')
            a++;
        else
            b++;
    }
    cout << 2*min(a,b);
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
// struct OnionFind
// {
// 	vector<int> root;
// 	vector<int> sz;
// 	OnionFind(int n)
// 	{
// 		root = vector<int>(n);
// 		iota(root.begin(),root.end(),0);
// 		sz = vector<int>(n,1);
// 	}
// 	int climb(int u)
// 	{
// 		if(root[u]==u)
// 			return u;
// 		else
// 			return root[u] = climb(root[u]);
// 	}
// 	bool merge(int u, int v)
// 	{
// 		u = climb(u);
// 		v = climb(v);
// 		if(u==v)
// 			return false;
// 		if(!(sz[u] <= sz[v]))
// 			swap(u,v);

// 		root[u] = v;
// 		sz[v] += sz[u];
// 		return true;
// 	}
// };
struct edge
{
	int v, w;
	edge(int v, int w):v(v),w(w){}
};
// struct query
// {
// 	int L, R, D;
// 	query(int L, int R, int D):L(L),R(R),D(D);
// };
const int N = 1e5;
vector<edge> adj[N+1];
bool vis[N+1];
int dist[N+1];
bool stay_the_path(int u, int d)
{
	if(vis[u])
		return dist[u]==d;
	vis[u] = true;
	dist[u] = d;
	for(const edge& e : adj[u])
		if(!stay_the_path(e.v,d+e.w))
			return false;
	return true;
}
bool solve()
{
	//vector<query> to_assert;
	int n, m; cin >> n >> m;
	//OnionFind onion(n);
	for(int i = 0; i < m; i++)
	{
		int L, R, D; cin >> L >> R >> D;
		L--, R--;
		// if(onion.merge(L,R))
		// {
		adj[L].push_back({R,D});
		adj[R].push_back({L,-D});
		// }
		// else
		// 	to_assert.push_back(query(L,R,D));
	}
	memset(vis,false,sizeof vis);
	for(int u = 0; u < n; u++)
		if(!vis[u])
		{
			if(!stay_the_path(u,0))
				return false;
		}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cout<<(solve() ? "Yes" : "No")<<endl;

	cout<<flush;
	return 0;
}

Measured memory_bytes: 14444
from functools import reduce


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


N = int(input())
T = [int(input()) for _ in range(N)]
print(reduce(lcm, T))


Measured memory_bytes: 3700
#include<stdio.h>

int main(){
    int n;
    int x;
    int f = 0;
    scanf("%d", &n);
    for(int i=0; i<50000; i++){
        x = i;
        int buf = i;
        buf = buf*108;
        buf = buf/100;
        if(buf == n){
            f=1;
            break;
        }
    }
    if(f){
        printf("%d", x);
    }else{
        printf(":(");
    }

    return 0;
}

Measured memory_bytes: 128
n=int(input())
L=[]
for i in range(n):
    L.append(int(input()))
    
L_sort=sorted(L)
L_sort.reverse()
m_1=L_sort[0]
m_2=L_sort[1]

if m_1==m_2:
    for i in range(n):
        print(m_1)
else:
    for i in range(n):
        if L[i]==m_1:
            print(m_2)
        else:
            print(m_1)
    


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

struct edge{
    int to;
    int fee;
    int cost;
};
struct state{
    int cost;
    int pos;
    int cash;
    bool operator < (const state &s)const{
        return cost > s.cost;
    }
};
 
const int  MAX_V = 100;
const int  INF = 1e9;
vector<edge> G[MAX_V];
int V,E,L;
 
void init();
int dijkstra(int, int);
 
int main(){
  int a,b,c,d;
  while(1){
    cin >> V >> E >> L;
    if(V == 0 && E == 0 && L == 0)break;
    init();
    for(int i = 0; i < E; i++){
        cin >> a >> b >> c >> d;
        a--;
        b--;
        G[a].push_back( (edge){b,c,d} );
        G[b].push_back( (edge){a,c,d} );
    }
    cout << dijkstra(0,V-1) << endl;
  }
  return 0;
}
 
int dijkstra(int si, int ti){
    int d[MAX_V][200];
    fill(d[0], d[0] + MAX_V*200, INF);
    d[si][L] = 0;
    priority_queue<state> Q;
    Q.push( (state){0, si, L} );
    
    while(!Q.empty()){
        state now = Q.top();
        Q.pop();
        if(now.cost > d[now.pos][now.cash]) continue;

        for(int i = 0; i < G[now.pos].size(); i++){
            edge e = G[now.pos][i];
            // 護衛を雇わない場合
            if(now.cost + e.cost < d[e.to][now.cash]){
                d[e.to][now.cash] = now.cost + e.cost;
                Q.push( (state){now.cost + e.cost, e.to, now.cash} );
            }
            // この道で護衛を雇えない場合
            if(now.cash - e.fee < 0) continue;
            // 護衛を雇う場合
            int ncash = now.cash - e.fee;
            if(now.cost < d[e.to][ncash]){
                d[e.to][ncash] = now.cost;
                Q.push( (state){now.cost, e.to, ncash} );
            }
        }
    }
 
    int res = INF;
        // 刺客の最小値をとる
        for(int i = 0; i < 200; i++)
            res = min(res,d[ti][i]);
    return res;
}
 
void init(){
    for(int i = 0; i < MAX_V; i++) G[i].clear();
}


Measured memory_bytes: 3552
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int H,W,N,A,B,C,a[200200],res=0;
string S[200200];
vector<char>vec;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i = 0; i < N; i++){
        cin>>a[i];
        a[i]--;
    }
    for(long long int i = 0; i < N; i++){
        if(a[a[i]]==i){res++;}
    }
    cout<<res/2<<endl;
}


Measured memory_bytes: 2560
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n,w=pM(split(readline()))
  dp=[Int[0 for i=1:w+1] for j=1:n+1]
  for i=1:n
    wi,vi=pM(split(readline()))
    for j=1:w+1
      if j-wi>0
        dp[i+1][j]=max(dp[i][j],dp[i][j-wi]+vi)
      end
      dp[i+1][j]=max(dp[i+1][j],dp[i][j])
    end
  end
  println(dp[n+1][w+1])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 249340
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

t=int(input())
for sdghsoewrgoijof in range(t):
    s=input().split()
    a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
    if a<b or d<b:
        print("No")
        continue
    if a==b:
        if d<b:
            print("No")
            continue
        elif d==b:
            print("Yes")
            continue
        else:
            a=d
    if a%b>c:
        print("No")
        continue
    if d%b==0:
        print("Yes")
    else:
        g=gcd(b,d)
        if b+(a%g)-g>c:
            print("No")
        else:
            print("Yes")

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int n;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    map<ll,int> mp;

    //auto tmp = mp;
    FOR(i,1,n+1){
        auto d = prime_factor(i);
        for(auto e:d){
            mp[e.first] += e.second;
        }
    }

    ll ans=1;
    for(auto e:mp){
        ans *= (e.second+1);
        ans %= MOD;
    }

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

Measured memory_bytes: 256
n=int(input())
H=list(map(int,input().split()))

co=0
su=sum(H)
hana=0
while su>0 :
    #print(hana)
    if H[hana]>0 :
        H[hana]-=1
        su-=1
        if hana==n-1 or H[hana+1]==0 :
            co+=1
    hana+=1
    if hana==n :
        hana=0

print(co)


Measured memory_bytes: 3060
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
#define NIL -2100000000
int heap[700];
int n;

int parent(int i){
	return i/2;
}
int rightchild(int i){
	return 2*i+1;
}
int leftchild(int i){
	return 2*i;
}

int main(){
	cin>>n;
	for(int i =0;i <=699;i++){
		heap[i]=NIL;
	}
	for(int i =1;i <= n;i++){
		int x;
		cin>>x;
		heap[i]=x;
	}
	for(int i =1;i <=n;i++){
		printf("node %d: key = %d, ",i,heap[i]);
		if(heap[parent(i)]!=NIL) printf("parent key = %d, ",heap[parent(i)]);
		if(heap[leftchild(i)]!=NIL) printf("left key = %d, ",heap[leftchild(i)]);
		if(heap[rightchild(i)]!=NIL) printf("right key = %d, ",heap[rightchild(i)]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std ;
int a[9] , b[9] , c[9];
int main() {
        int n ;
        cin >> n ;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        int cnta = 0 , cntb = 0 ;
        for(int i = 1 ; i <= n ; i++) cin >> a[i] ;
        for(int i = 1 ; i <= n ; i++) cin >> b[i] ;
        for(int i = 1 ; i <= n ; i++) c[i] = i ;
        bool flaga = false , flagb = false ;
        do{
            if(flaga == false) {
                for(int i = 1 ; i <= n ; i++) {
                if(a[i] == c[i]) flaga = true ;
                else {
                    cnta++ ; flaga = false ; break ;
                }
            }
            }
          if(flagb == false) {
                  for(int i = 1 ; i <= n ; i++) {
                if(b[i] == c[i]) flagb = true ;
                else {
                    cntb++ ; flagb = false ; break ;
                }
            }
          }
        }while(next_permutation(c+1,c+n+1));
        //cout << cnta << " "<<cntb << endl ;
        cout << abs(cnta - cntb) << endl ;
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include<cstdio>
#include<vector>
#include<iomanip>
using namespace std;


int main(){
    int max_v = 100100;
    int q;
    cin >> q;
    int l[q],r[q];
    for (int i = 0; i < q; i++){
        cin >> l[i] >> r[i];
    }

    vector<int> is_prime(max_v,1);
    is_prime[0] = 0;
    is_prime[1] = 0;
    for (int i = 2; i < max_v; i++){
        if (!is_prime[i]) continue;
        for (int j = i*2; j < max_v; j += i){
            is_prime[j] = 0;
        }
    }

    int d[max_v+1];
    d[0] = 0;
    for (int i =1; i < max_v+1; i++){
        if (is_prime[i] && is_prime[(i+1)/2]) d[i] = d[i-1]+1;
        else d[i] = d[i-1];
    }

    for (int i = 0; i < q; i++){
        cout << d[r[i]] - d[l[i]-1] << endl;
    }



    return 0;
}

Measured memory_bytes: 2176
import math
S = input()
N = len(S)

count = 0
flug = 0
kiten={}
chukan={}
syuten={}

kiten[count] = 0
for i in range(N-1):
  if S[i] != S[i+1]:
    if flug == 0:
      chukan[count] = i
      flug = 1
    elif flug == 1:
      syuten[count] = i
      flug = 0
      count = count + 1
      kiten[count] = i+1

syuten[count] = N-1

H={}
for j in range(N):
  H[j]=0
for j in range(count+1):
  if (chukan[j]-kiten[j])%2==0:
    H[chukan[j]]=int(((syuten[j]-kiten[j]+1)+2-1)/2)
    H[chukan[j]+1]=math.floor(((syuten[j]-kiten[j]+1)/2))
  if (chukan[j]-kiten[j])%2==1:
    H[chukan[j]]=math.floor(((syuten[j]-kiten[j]+1)/2))
    H[chukan[j]+1]=int(((syuten[j]-kiten[j]+1)+2-1)/2)
for k in range(N):
  print(H[k],"",end="")

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(long &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   double f(double x, double y) {
      return sqrt(x*x+y*y);
   }
   void solve() {
      long x, a, b;
      scan(x, a, b);
      long da = std::abs(x - a);
      long db = std::abs(x - b);
      puts(da < db ? "A" : "B");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define NUM_MAX 100000

enum type {
    TYPE_WOLF,
    TYPE_SHEEP
};

enum reply {
    REPLY_X,
    REPLY_O,
};

static char type_table[2] = {
    [TYPE_WOLF] = 'W',
    [TYPE_SHEEP] = 'S'
};

static char reply_table[256] = {
    ['o'] = REPLY_O,
    ['x'] = REPLY_X
};

// right = [cur][reply][left]
static char next[2][2][2] = {
    // I'm wolf
    {
        // says 'x'
        {
            // When left is TYPE_WOLF
            TYPE_WOLF,
            // left is TYPE_SHEEP
            TYPE_SHEEP
        },
        // says 'o'
        {
            // When left is TYPE_WOLF
            TYPE_SHEEP,
            TYPE_WOLF,
        },
    },
    // I'm sheep
    {
        // says 'x'
        {
            TYPE_SHEEP,
            TYPE_WOLF,
        },
        // says 'o'
        {
            TYPE_WOLF,
            TYPE_SHEEP,
        },
    },
};

int main(void) {
    int num = get_int();
    static char str[NUM_MAX];
    get_str(str, num);

    int t, i;
    int ok = 0;
    static char types[NUM_MAX];
    for(t = 0; t < 4; t++) {
        memset(types, 0, NUM_MAX);
        // 0: wolf 1: sheep
        types[0] = !!(t&1);
        types[1] = !!(t&2);
        int flag = 1;
        for(i = 1; i <= num; i++) {
            int cur = i%num;
            int left = (i+num-1)%num;
            int right = (i+num+1)%num;
            int cur_type = types[cur];
            int reply = reply_table[str[cur]];
            int next_type = next[cur_type][reply][types[left]];
            if(i >= num-1) {
                if(next_type != types[right]) {
                    flag = 0;
                    break;
                }
            }
            types[right] = next_type;
        }
        if(flag) { ok=1; break; }
    }

    if(ok) {
        for(i = 0; i < num; i++) {
            putchar(type_table[types[i]]);
        }
    } else {
        printf("%d", -1);
    }
    putchar('\n');
    return 0;
}

Measured memory_bytes: 384
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, k := io.NextInt(), io.NextInt()
	a := io.NextInts(n)
	ans := solve(n, k, a)
	io.Println(ans)
}

func solve(n, k int, a []int) int {
	divConut := func(x float64) int {
		cnt := 0
		for i := range a {
			if float64(a[i]) <= x {
				continue
			}
			cnt += int(math.Ceil(float64(a[i])/x)) - 1
		}
		return cnt
	}
	x := sort.Search(maxIter, func(x int) bool { return divConut(float64(x+1)/10) <= k })
	if x == maxIter {
		panic("error")
	}
	return int(math.Ceil(float64(x+1) / 10))
}

const maxIter = 1e12

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 13092
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int h,w,black=0,d[5]={0,1,0,-1,0};
    cin>>h>>w;
    char s[h][w];
    int n[h][w]={};
    for(int i=0;i<h*w;i++){cin>>s[i/w][i%w];if(s[i/w][i%w]=='#')black++;}
    queue<pair<int,int>>bfs;
    n[0][0]=1;
    s[0][0]='O';
    bfs.push(make_pair(0,0));
    while(!bfs.empty()){
        pair<int,int>p=bfs.front();bfs.pop();
        for(int i=0;i<4;i++){
            if(p.first+d[i]>=0&&p.first+d[i]<h&&p.second+d[i+1]>=0&&p.second+d[i+1]<w&&s[p.first+d[i]][p.second+d[i+1]]=='.'){
                n[p.first+d[i]][p.second+d[i+1]]=n[p.first][p.second]+1;
                s[p.first+d[i]][p.second+d[i+1]]='O';
                bfs.push(make_pair(p.first+d[i],p.second+d[i+1]));
            }
        }
    }
    cout<<(n[h-1][w-1]?h*w-n[h-1][w-1]-black:-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

a, b, c = map(int, input().split())
k = int(input())

t = 0 
while a>=b:
    b *= 2
    t += 1
while b>=c:
    c *= 2
    t += 1

if t<=k:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9156
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<mint> dp(13, 0);
    dp[0] = 1;
    rep(i,n){
        vector<mint> dp2(13, 0);
        if(s[i] == '?'){
            rep(j,13){
                rep(k,10){
                    dp2[(j*10 + k)%13] += dp[j];
                }
            }
        }
        else{
            rep(j,13){
                dp2[(j*10 + (s[i] - '0'))%13] += dp[j];
            }
        }
        dp = move(dp2);
    }
    cout << dp[5].x << endl;
    return 0;
}

Measured memory_bytes: 512
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()

l = [pow(2,i) for i in range(1,30)]
cnt = [0]*(N+1)
data = [0]*(N+1)

for i in range(1,N+1):
    if i >= K:
        break
    for j in range(len(l)):
        if l[j]*i >= K:
            cnt[i] = j+1
            break
ans = 0
for i in range(1,N+1):
    data[i] = (1/N)*((1/2)**cnt[i])
    ans += data[i]

print(ans)

Measured memory_bytes: 17876
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		String[] line = str.replace(" ", ",").replace(".", ",").split(",");
		boolean flag = false;
		for (int i = 0; i < line.length; i++) {
			if (3 <= line[i].length() && line[i].length() <= 6) {
				if (flag) {
					System.out.print(" " + line[i]);
				} else {
					System.out.print(line[i]);
					flag = true;
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 17176
// B - Uneven Numbers
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int c = 0;
		for (int x = i; x > 0; x /= 10) c++;
		if (c % 2 == 1) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
   ll W;
  ll H;
   ll x;
 ll y;
   cin >>W>>H>>x>>y;
 double z=(double)(W*H)/(double)2;
  ll ans=0;
  if((x*2==W)&&(y*2==H)) {
    ans++;
  }
  CST(8);
cout<<z<<" "<<ans<<endl;
}
 

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

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

using namespace std;
int main(int argc, char const* argv[]) {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  long long n_divc, n_divd;

  n_divc = b / c - a / c;
  if (a % c == 0) {
    n_divc += 1;
  }
  n_divd = b / d - a / d;
  if (a % d == 0) {
    n_divd += 1;
  }

  long long n_divcd;
  long long cd = c * d / gcd(c, d);

  n_divcd = b / cd - a / cd;
  if (a % cd == 0) {
    n_divcd += 1;
  }

  // cout << n_divc << " " << n_divd << " " << n_divcd << endl;
  cout << b - a + 1 - (n_divc + n_divd - n_divcd) << endl;
}


Measured memory_bytes: 256
#初見じゃ無理だった。DPを使う
#標準入力
import math
H, N = map(int, input().split())
AB = []
max_A = 0
for i in range(N):
    ab = list(map(int, input().split()))
    if max_A < ab[0] :
        max_A = ab[0]
    AB.append(ab)

 #DP
DP = [0] * (H + max_A)
for i in range(1, H + max_A ): #DP[i] の最小値を求めていく
    tmp_mini = 10 ** 8
    for j in range(N):
        if i - AB[j][0] >= 0:
            tmp = DP[i - AB[j][0]] + AB[j][1]
            if tmp_mini > tmp:
                tmp_mini = tmp
    DP[i] = tmp_mini
print(min(DP[H: H + max_A]))


Measured memory_bytes: 42588
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[15], t[15];
int main() {
    scanf("%s%s", s, t);
    bool flag = true;
    for(int i = 0 ; s[i]; i++) {
        if(s[i] != t[i]) flag = false;
    }
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3688
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  bool flag = false;
  int num = 0;

  int n; cin >> n;
  cout << "ABC" << n << endl;
  
  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6 + 17;
ll a[N], b[N], cnt = 1, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m >> x;
    x += 0.5;
    r1 = n;
    while(r1 <= x)
    {
        r1 += n;
        ans += m;
    }
    cout << ans;
}


Measured memory_bytes: 6400
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
  ll n;
  cin>>n;
  vector<ll>Numbers;
  ll Zero=0;
  for(int i=1;i<=n;i++)
  {
    ll a;
    cin>>a;
    Numbers.push_back(a);
    if(a==0)Zero++;
  }
  ll MX=1e18+1;
  long double Result=1.0;
  if(Zero>=1)
  {
    cout<<0<<endl;
    return;
  }
  for(auto it:Numbers)
  {
    if(Result*it>MX)
    {
      cout<<-1<<endl;
      return;
    }
    Result=Result*it;
  }
  cout<<(long long int)Result<<endl;
}
int  main()
{
    IOS
        solve();
    return 0;
}



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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

int main() {
	int n, c, k;
	scanf("%d %d %d", &n, &c, &k);
	vector<int> v;
	fori(i, 0, n) {
		int cur;
		scanf("%d", &cur);
		v.push_back(cur);
	}
	sort(v.begin(), v.end());

	int ans = 0;
	int on = 1;
	int first = v[0];
	fori(i, 1, v.size()) {
		if(on == c || v[i] - first > k) {		
			on = 1;
			first = v[i];
			ans++;
		}
		else {
			on++;
		}
	}
	
	ans += on != 0;

	printf("%d\n", ans);

	return 0;
}



Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std ;

int dp[100005][3] ;

int main(){
	int N  , a , b , c ;
	cin >> N ;
	cin >> dp[1][0] >> dp[1][1] >> dp[1][2] ; 
	for( int i = 2 ; i <= N ; i++ ){
		cin >> a >> b >> c ;
		dp[i][0] = a + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = b + max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = c + max(dp[i-1][1],dp[i-1][0]);
	}
	int ans = max(dp[N][0],dp[N][1]) ;
	ans = max(ans,dp[N][2]);
	cout << ans << endl ;
	return 0 ;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdio.h>
int main()
{
    int n, i;
    scanf("%d", &n);
    int p[n],count[n+1];
    for(i=1; i<n+1; i++){
        count[i]=0;
    }
    for(i=1; i<n; i++){
        scanf("%d", &p[i]);
    }
    for(i=1; i<n; i++){
        count[p[i]]++;
    }
    for(i=1; i<n+1; i++){
        printf("%d\n", count[i]);
    }
    return 0;

}


Measured memory_bytes: 3248
import java.io.*;
import java.util.*;
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int[] data=new int[3];
        data[0]=Integer.parseInt(st.nextToken());
        data[1]=Integer.parseInt(st.nextToken());
        data[2]=Integer.parseInt(st.nextToken());
        Arrays.sort(data);
        System.out.println(data[0]+" "+data[1]+" "+data[2]);
    }
}

Measured memory_bytes: 24268
#include <bits/stdc++.h>
#define int long long
using namespace std;

int f[10000010];

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

signed main(){
    int n=read();
    
    int i,j;    
    int ans=0;
    
    for(i=1;i<=n;i++){
        for(j=1;i*j<=n;j++)
            f[i*j]++;
    }
    
    for(i=1;i<=n;i++)
        ans+=i*f[i];
    
    writeln(ans);
    return 0;
}

Measured memory_bytes: 81684