akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int a, b;
	int c=0;
	int i;
	cin >> a >> b;
	vector<int> d(a);
	vector<bool> x(a,true);
	vector<bool> y(a,true);
	vector<vector<int>> e(b, vector<int>(2));
	for ( i = 0;i < a;i++) {
		cin >> d[i];
	}
	for (i = 0;i < b;i++) {
		cin >> e[i][0] >> e[i][1];
		y[e[i][0] - 1] = false;
		y[e[i][1] - 1] = false;
		if (d[e[i][0] - 1] > d[e[i][1] - 1]) x[e[i][1] - 1] = false;
		else if (d[e[i][0] - 1] < d[e[i][1] - 1]) x[e[i][0] - 1] = false;
		else {
			x[e[i][1] - 1] = false;
			x[e[i][0] - 1] = false;
		}
	}
	for (i = 0;i < a;i++) {
		if (y[i] == true) x[i] = false;
		c += x[i] + y[i];
	}
	cout << c;
}


Measured memory_bytes: 9068
import java.util.*;
 
public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int K = sc.nextInt();
	int[] a = new int[N+1];
	for (int i=1; i<=N; i++) {
	    a[i] = sc.nextInt();
	}
	for (int i=K+1; i<=N; i++) {
	    if (a[i] > a[i-K]) System.out.println("Yes");
	    else { System.out.println("No"); }
	}
    }
}


Measured memory_bytes: 60068
import java.util.Arrays;
import java.util.Scanner;
class Main{

    static void solve(boolean[][] map, boolean trueiswhite){
        System.out.println("96 96");
        for(int i=0;i<96;++i){
            for(int j=0;j<96;++j){
                if(map[i][j]){
                    if(trueiswhite)System.out.print('.');
                    else System.out.print('#');
                }else{
                    if(trueiswhite)System.out.print('#');
                    else System.out.print('.');
                }
            }
            System.out.println();
        }
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        boolean[][] map = new boolean[96][96];
        for(boolean[] m : map)Arrays.fill(m,true);
        boolean trueiswhite = true;
        if(a<b){
            int tmp = a;
            a=b;
            b=tmp;
            trueiswhite=false;
        }

        if(b<16){
            for(int i=0;i<b;++i){
                for(int j=i*6;j<i*6+3;++j){
                    for(int k=0;k<96;++k)map[j][k]=false;
                }
            }
            for(int i=(b-1)*6;i<96;++i)for(int k=0;k<96;++k)map[i][k]=false;
            a-=(b-1);
            for(int i=1;i<96;i+=6){
                for(int j=1;j<96;j+=2){
                    map[i][j]=true;
                    --a;
                    if(a==0){
                        solve(map, trueiswhite);
                        return;
                    }
                }
            }
        }else{
            for(int i=0;i<16;++i){
                for(int j=i*6;j<i*6+3;++j){
                    for(int k=0;k<96;++k)map[j][k]=false;
                }
            }
            b-=16;
            a-=16;
            for(int i=1;i<96;i+=6){
                for(int j=1;j<96;j+=2){
                    map[i][j]=true;
                    --a;
                    if(a==0)break;
                }
                if(a==0)break;
            }

            for(int i=4;i<96;i+=6){
                for(int j=1;j<96;j+=2){
                    map[i][j]=false;
                    --b;
                    if(b==0){
                        solve(map, trueiswhite);
                        return;
                    }
                }
            }

        }


    }
}

Measured memory_bytes: 26324
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] X = new int[N];
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < N; i++) {
      X[i] = sc.nextInt();
      min = Math.min(min, X[i]);
      max = Math.max(max, X[i]);
    }
    int ans = Integer.MAX_VALUE;
    for (int p = min; p <= max; p++) {
      int sum = 0;
      for (int x : X) {
        sum += (x - p) * (x - p);
      }
      ans = Math.min(ans, sum);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
import sys
from collections import deque

input = sys.stdin.readline


def calc_group(N, G, group_id, group_cnt):
    g_id = 0
    for i in range(N):
        if group_id[i] != -1:
            continue
        cnt = 1
        group_id[i] = g_id
        stack = deque([i])
        while stack:
            v = stack.pop()
            for u in G[v]:
                if group_id[u] != -1:
                    continue
                cnt += 1
                group_id[u] = g_id
                stack.append(u)
        g_id += 1
        group_cnt.append(cnt)


def main():
    N, M, K = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        G[A].append(B)
        G[B].append(A)
    B = [[] for _ in range(N)]
    for i in range(K):
        C, D = map(int, input().split())
        C -= 1
        D -= 1
        B[C].append(D)
        B[D].append(C)

    group_id = [-1] * N
    group_cnt = []
    calc_group(N, G, group_id, group_cnt)

    ans = [0] * N
    for i in range(N):
        n_neighbor = len(G[i])
        n_block = sum(1 for j in B[i] if group_id[i] == group_id[j])
        ans[i] = (group_cnt[group_id[i]] - 1) - n_neighbor - n_block

    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


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

#define INF 0x3F3F3F3F
#define DINF 1e+12
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define debug(x) if(1) cout << #x << " = " << x << endl;
#define debug2(x,y) if(1) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define all(S) (S).begin(), (S).end()
#define F first
#define S second
#define EPS 1e-9
#define mp make_pair

// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);

using namespace std;

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

int main(){

	int N;
	int v[123];
	cin >> N;
	rep(i, 0, N) cin >> v[i];
	sort(v, v+N);
	int ans = 0;
	bool a = 1;
	for(int i=N-1; i>=0; i--){
		if(a) ans += v[i]; else ans -= v[i];
		a^=1;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl



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

	ll H,W;
	cin >> H >> W;
	string a[H];
	FOR(i,0,H)cin >> a[i];

	ll dp[H][W]={};
	dp[0][0] = 1;
	FOR(j,0,W){
		FOR(i,0,H){
			if(i+1<H)if(a[i+1][j]!='#')(dp[i+1][j] += dp[i][j])%=MOD;
			if(j+1<W)if(a[i][j+1]!='#')(dp[i][j+1] += dp[i][j])%=MOD;
		}
	}
	cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 9088
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools,queue

sys.setrecursionlimit(10**7)
INF = 20000
EPS = 1.0 / 10**10
MOD = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]

n, e = LI()
dist = [[INF for _ in range(n)] for _ in range(n)]
for _ in range(e):
    a,b,c = LI()
    dist[a][b] = c

dp = [[INF for _ in range(n)] for _ in range(1<<n)]

q = queue.Queue()

for i in range(1,n):
    if dist[0][i] < INF:
        dp[1 | (1<<i)][i] = dist[0][i]
        q.put((1 | (1<<i),i))

while not q.empty():
    bit, v = q.get()
    for u in range(1,n):
        if dist[v][u] < INF and not(bit & (1<<u)):
            next_bit = bit | (1<<u)
            if dp[next_bit][u]  == INF:
                q.put((next_bit, u))
            dp[next_bit][u] = min(dp[next_bit][u], dp[bit][v] + dist[v][u])

ans = INF
for i in range(1,n):
    ans = min(ans, dp[(1<<n)-1][i] + dist[i][0])
if ans < INF:
    print (ans)
else:
    print (-1)


Measured memory_bytes: 21628
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

long N;
vector<vector<long>> F;
vector<vector<long>> P;

vector<long> aaa(10, 0);

long foo(long num) {
  if (num == 10) {
    bool flag = true;
    rep (i, 10) if (aaa[i]) flag = false;
    if (flag) return -10000000000000000l;
    long ret = 0;
    rep (i, N) {
      long a = 0;
      rep (j, 10) if (aaa[j] and F[i][j]) a++;
      ret += P[i][a];
    }
    return ret;
  }
  aaa[num] = 0;
  long a = foo(num + 1);
  aaa[num] = 1;
  long b = foo(num + 1);
  return max(a, b);
}

void solve() {
  cin >> N;
  F = vector<vector<long>>(N, vector<long>(10, 0));
  P = vector<vector<long>>(N, vector<long>(11, 0));
  rep (i, N) rep (j, 10) cin >> F[i][j];
  rep (i, N) rep (j, 11) cin >> P[i][j];
  cout << foo(0) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<int> G[5010];
int ans;

//true : ?????¢???????????????, false : ?????¢????????????
bool dfs(int now){
    bool f = false;
    rep(i, 0, G[now].size()){
        f |= dfs(G[now][i]);
    }
    if(f){
        ans++; return false;
    }
    return true;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n){
        int a; cin >> a;
        G[a].push_back(i + 1);
        ans = 0;
        dfs(0);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3336
n = gets.to_i
p = gets.split.map(&:to_i)
arr = p.map.with_index{|pi,i| [i, pi] }.sort{|a,b| a[1] <=> b[1]}.map{|a|a[0]}
tmp = arr[0]
ans = 1
i = 1
until tmp==0
  if tmp>arr[i]
    ans += 1
    tmp = arr[i]
  end
  i += 1
end
p ans


Measured memory_bytes: 29208
#include<stdio.h>
#define N 50

int sum[N];


int num(int a)
{
  if(sum[a] !=0)
    return sum[a];
  if(a<=1)
    return 1;
  return sum[a]=num(a-1)+num(a-2);
}

int main(void)
{
  int b;
  scanf("%d",&b);
  printf("%d\n",num(b));

  return 0;
}
  



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

int main(){
int books=1;
int book=0;
int i=0;
while(books!=0){
cin>>books;
if(books==0){
break;
}
while(i<=8){
cin>>book;
books-=book;
i++;
}
if(i==9){
cout<<books<<'\n';
i=0;
}

}


return 0;
}

Measured memory_bytes: 1160
// Problem : D - Small Multiple
// Contest : AtCoder - AtCoder Beginner Contest 077
// URL : https://atcoder.jp/contests/abc077/tasks/arc084_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int k;cin>>k;
	int dis[k];
	inima(dis);
	deque<int> q;
	q.push_back(1);
	dis[1]=1;
	while(!q.empty())
	{
		int x=q.front();
		q.pop_front();
		if(dis[(x+1)%k]>dis[x%k]+1)
		{
			q.push_back((x+1)%k);
			dis[(x+1)%k]=dis[x%k]+1;
		}
		if(dis[(x*10)%k]>dis[x%k])
		{
			q.push_front(x*10%k);
			dis[x*10%k]=dis[x];
		}
	}
	cout<<dis[0];
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 4620
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
// Set - Disjoint Set: Union Find Tree
// TODO: REVIEW

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

class disjoint_set {
public:
    disjoint_set() = default;

    explicit disjoint_set(size_t size) : rank_(size), parent_(size) {
        for (int i = 0; i < size; ++i) make_set(i);
    }

    bool same(int x, int y) {
        return find_set(x) == find_set(y);
    }

    void unite(int x, int y) {
        link(find_set(x), find_set(y));
    }

private:
    void make_set(int x) {
        parent_[x] = x;
        rank_[x] = 0;
    }

    void link(int x, int y) {
        if (rank_[y] < rank_[x]) parent_[y] = x;
        else {
            parent_[x] = y;
            if (rank_[x] == rank_[y]) rank_[y]++;
        }
    }

    int find_set(int x) {
        if (x != parent_[x]) parent_[x] = find_set(parent_[x]);
        return parent_[x];
    }

private:
    // tree height
    vector<int> rank_;
    // x is root when x == parent_[x]
    vector<int> parent_;
};

size_t n, q;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
)";
    stringstream stream(program_input_str);
#endif
    stream >> n >> q;
    disjoint_set ds(n);

    int c, x, y;
    for (int i = 0; i < q; ++i) {
        stream >> c >> x >> y;
        if (c == 0) ds.unite(x, y);
        else if (c == 1) {
            if (ds.same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int n;
	cin>>n;
	int a[n],i;
	int mark[1000005]={0};
	set<int> st;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		st.in(a[i]);
		mark[a[i]]++;
	}
	int cnt[1000005]={0};
	sort(a,a+n);
	
	for(auto it:st)
	{
		int x=it;
		for(int j=2*x;j<1000005;j+=x)
		cnt[j]++;
	}
	int ans=0;
	for(i=0;i<1000005;i++)
	{
		if(mark[i]==1&&cnt[i]==0)
		ans++;	
	}
	cout<<ans;
}

Measured memory_bytes: 21572
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >>n;
  set<string> a;
  string b[n];
  bool c=false;
  for (int i=0;i<n;i++){
  	cin >> b[i];
    a.insert(b[i]);
  }
  if (a.size()==n){
  	c=true;
    for (int i=0;i<n-1;i++){
    	if (b[i].back()!=b[i+1].front()) c=false;
    }
  }
  if (c) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long count = 0;

		if((a==b&&b==c)&&(a%2==0&&b%2==0&&c%2==0)) {
			System.out.println(-1);
			return;
		}

		while(true) {
			if(a%2	==1||b%2==1||c	%2==1) {
				break;
			}
			long a_temp = a/2;
			long b_temp = b/2;
			long c_temp = c/2;
			a = b_temp+c_temp;
			b = a_temp+c_temp;
			c = a_temp+b_temp;
			count++;

		}
		System.out.println(count);
	}
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for(int i = 1; i <= n; i++) {
			if(i % 2 == 1) {
				int divcount = 0;
				for(int k = 1; k <= n; k++) {
					if(i % k == 0) divcount++;
				}
				if(divcount == 8) {
					ans++;
					//System.out.println(i);//該当値確認用
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}

}


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

void print(int* a, int* op){
  for (int i = 0; i < 3; i++){
    printf("%d", a[i]);
    if (op[i] == 1) printf("+");
    else printf("-");
  }
  printf("%d=7", a[3]);
}

int main(){
  int a[4];
  int n;
  cin >> n;
  for (int i = 0; i < 4; i++){
    a[3-i] = n % 10;
    n /= 10;
  }
  int diff = (a[0] + a[1] + a[2] + a[3] - 7) / 2;
  int op[3];
  for (int i = 0; i < 3; i++){
    op[i] = 1;
  }

  if (diff == 0){
    print(a, op);
    return 0;
  }
  for (int i = 1; i <= 3; i++){
    if (diff == a[i]){
      op[i-1] = 0;
      print(a, op);
      return 0;
    }
  }
  for (int i = 1; i <= 2; i++){
    if (diff == a[i] + a[(i+1)]){
      op[i-1] = 0;
      op[i] = 0;
      print(a, op);
      return 0;
    }
  }
  if (diff == a[1] + a[3]){
    op[0] = 0;
    op[2] = 0;
    print(a, op);
    return 0;
  }
  if (diff == a[1] + a[2] + a[3]){
    op[0] = 0;
    op[1] = 0;
    op[2] = 0;
    print(a, op);
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
int main() {
    ll n;
    cin >> n;
    ll ans=n;
    for(ll i=1;i<=sqrt(n);++i) {
        if(n%i==0) {
            ans=min(ans,abs(i-1)+abs((n/i)-1));
        }
    }
    cout << ans << endl;
}



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

#define rep(i, a) for (int i = 0; i < (int) a; i++)
 
signed main()
{
	int x[3];
	rep(i, 3) cin >> x[i];
	sort(x, x+3);
	int a[3] = {5, 5, 7};
	rep(i, 3) {
		if (x[i] != a[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    int n;
    cin >> n;
    cout << n / 3 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    
    double a,b,c,S,L,h;
    
    cin >> a >> b >> c;
    
    double rad;
    double PI = acos(-1);
    
    rad = c * PI / 180;
    
    S = a * b * sin(rad) / 2;
    
    L = a + b + sqrt(pow(a,2) + pow(b,2) - 2 * a * b * cos(rad));
    
    h = b * sin(rad);
    
    printf("%.8f\n", S);
    
    printf("%.8f\n", L);
    
    printf("%.8f\n", h);
    
    return 0;
    
}



Measured memory_bytes: 3520
N = int(input())
a = list(map(int, input().split()))
jousi={}
for i in range(N+1):
    jousi[str(i)]=0

for i in range(N-1):
    jousi[str(a[i])]+=1
    
for i in range(1,N+1):
    print(jousi[str(i)])


Measured memory_bytes: 44204
from math import gcd

N = int(input())
num_lis = list(map(int, input().split()))

def osa_k(max_num):
  lis = [i for i in range(max_num+1)]
  p = 2
  while p**2 <= max_num:
    if lis[p] == p:
      for q in range(2*p, max_num+1, p):
        if lis[q] == q:
          lis[q] = p
    p += 1
  return lis

hoge = 0
for i in num_lis:
  hoge = gcd(hoge, i)
if hoge > 1:
  print("not coprime")
  exit()

d_lis = osa_k(max(num_lis))
tmp = set()
for i in num_lis:
  num = i
  new_tmp = set()
  while num > 1:
    d = d_lis[num]
    new_tmp.add(d)
    num //= d
  for j in new_tmp:
    if j in tmp:
      print("setwise coprime")
      exit()
    else:
      tmp.add(j)
print("pairwise coprime")

Measured memory_bytes: 134400
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T ll
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}


vector<int> rabin_karp(string const& s, string const& t) {
	//pattern s in string t
    const int p = 31; 
    const int m = 1e9 + 9;
    int S = s.size(), T = t.size();

    vector<long long> p_pow(max(S, T)); 
    p_pow[0] = 1; 
    for (int i = 1; i < (int)p_pow.size(); i++) 
        p_pow[i] = (p_pow[i-1] * p) % m;

    vector<long long> h(T + 1, 0); 
    for (int i = 0; i < T; i++)
        h[i+1] = (h[i] + (t[i] - 'a' + 1) * p_pow[i]) % m; 
    long long h_s = 0; 
    for (int i = 0; i < S; i++) 
        h_s = (h_s + (s[i] - 'a' + 1) * p_pow[i]) % m; 

    vector<int> occurences;
    for (int i = 0; i + S - 1 < T; i++) { 
        long long cur_h = (h[i+S] + m - h[i]) % m; 
        if (cur_h == h_s * p_pow[i] % m)
            occurences.push_back(i);
    }
    return occurences;
}

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

    int n=sz(s),m=sz(t);
    while(sz(s)<m){
    	s+=s;
    }
    s+=s;
    vector<int>v=rabin_karp(t,s);
    int nxt[n],st[n];
    FOR(i,0,n-1){
    	st[i]=0;
    	nxt[i]=-1;
    }
    for(int i:v){
    	if(i>=n){
    		break;
    	}
    	nxt[i]=(i+m)%n;
    	st[(i+m)%n]++;
    }
    queue<int>q;
    int d[n];
    FOR(i,0,n-1){
    	d[i]=-1;
    }
    FOR(i,0,n-1){
    	if(st[i]==0){
    		q.push(i);
    		d[i]=0;
    	}
    }
    while(!q.empty()){
    	int u=q.front();
    	q.pop();
    	int v=nxt[u];
    	if(v==-1){
    		continue;
    	}
    	st[v]--;
    	d[v]=max(d[v],d[u]+1);
    	if(st[v]==0){
    		q.push(v);
    	}
    }
    int mx=0;
    FOR(i,0,n-1){
    	if(d[i]==-1){
    		cout<<-1;
    		return 0;
    	}
    	mx=max(d[i],mx);
    }
    cout<<mx;

    return 0;
}

Measured memory_bytes: 46040
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;

using namespace std;

int main(){
    cs
    ld t;
    int k,it=1;
    cin>>k;
    vector<int> v(k);
    rep(i,k) cin>>v[i];
    sort(v.begin(),v.end());
    t=v[0];
    while(it!=k){
        t=(t+v[it])/2;
        it++;
    }
    cout<<fixed<<setprecision(12)<<t;
}

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

int main(){
    int s;
    cin >> s;
    map<int, int> memo;
    
    int cur = s;
    do{
        if(memo.count(cur)) break;
        
        memo[cur] = 1;
        if(cur % 2 == 0) cur /= 2;
        else cur = cur*3+1;
    }while(1);

    cout << memo.size()+1 << endl;
    return 0;
}

Measured memory_bytes: 3600
N = int(input())
S = list(input())

# Sの値を+-1にする
for i in range(N) :
    if S[i] == 'o' :
        S[i] = 1
    else :
        S[i] = -1

S.append(S[0])

def check() :
    for first in [1, -1] :
        for second in [1, -1] :
            animal = [1] * (N + 2)
            animal[0] = first
            animal[1] = second
            for i in range(1,N+1) :
                if animal[i] == 1 :  # 動物が羊の場合
                    animal[i+1] = animal[i-1] *  S[i]
                else :  # 動物が狼の場合
                    animal[i+1] = animal[i-1] * S[i] * (-1)
            if animal[-2] == first and animal[-1] == second :
                return animal
    return -1

ans = check()

if ans == -1 :
    print(-1)
else :
    for i in range(N) :
        if ans[i] == 1 :
            print('S', end='')
        else :
            print('W', end='')
    print('')


Measured memory_bytes: 6788
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
 long long lcm(int x,int y)
{
     long long mul = x*y;
     long long gd = __gcd(x,y);
    return mul/gd;
}
int lm;
int n,m;
bool chk(int x)
{
   // test1(x);
     long long h = 2*x-1;
     long long g = h*lm;
    if(g<=m)
    return true;

    return false;
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	
    cin>>n>>m;
    int A[n];

    
    bool gret=false;
    int f1=0,f2=0;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        int temp = A[i]/2;
        if(temp%2)
        f1++;
        else
        {
            f2++;
        }
       
    }
    if(f1&&f2)
    {
        cout<<0;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        if(i==0)
        lm=A[i]/2;
        else
        {
            lm = lcm(lm,A[i]/2);
            
        }
    }
  
    bool ano=true;
    for(int i=0;i<n;i++)
    {
        int div = A[i]/2;
        div = lm/div;
        if(div%2==0)
        ano=false;
    }
    if(!ano)
    {
        cout<<0;
        return 0;
    }
    int cnt=0;
    for(int z=m+1;z>0;z=z/2)
    {
        while(chk(cnt+z))
        cnt+=z;
    }
    
    cout<<cnt;

    

return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#define ll long long
#define int ll
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define gcd(A,B) (__gcd(A,B))
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define mod 1000000007LL
#define all(x) x.begin(), x.end()
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

typedef pair<int,int> pii;

const int V = 101010;

vector <pii> edge_list;
vector <ll> answer_list;
ll ans;
struct Disjoint_Set_Union
{
    int connected;
    int parent[V], size[V];

    void init(int n)
    {
        for(int i=1;i<=n;i++)
        {
            parent[i]=i;
            size[i]=1;
        }
        connected=n;
    }
    int Find(int k)
    {
        while(k!=parent[k])
        {
            parent[k]=parent[parent[k]];
            k=parent[k];
        }
        return k;
    }
    int getSize(int k)
    {
        return size[Find(k)];
    }
    void merge(int x, int y)
    {
        int u=Find(x), v=Find(y);
        connected--;
        if(u==v)
            return;
        if(size[u]>size[v])
            swap(u, v);
        ans -= (size[u]*size[v]);
        size[v]+=size[u];
        size[u] = 0;
        parent[u] = parent[v];
    }
} dsu;

int32_t main()
{
    int n, m;
    scanf("%lld %lld",&n,&m);
    dsu.init(101010);
    for (int i = 0; i<m; i++)
    {
        int a, b;
        scanf("%lld %lld",&a,&b);
        edge_list.push_back({a,b});
    }
    ans = n*(n-1)/2;
    answer_list.push_back(ans);
    for (int i = m-1; i>0; i--)
    {
        int a, b;
        tie(a, b) = edge_list[i];
        dsu.merge(a,b);
        answer_list.push_back(ans);
    }
    reverse(all(answer_list));
    for (auto it:answer_list)
        printf("%lld\n",it);
}

Measured memory_bytes: 6640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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


	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int cnt = 0;

		int num = i;
		while (num > 0) {
			cnt++;
			num /= 10;
		}

		if (cnt % 2 == 1) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

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 * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string a, b, c;
  cin >> a >> b >> c;
  char t = 'a';
  while(1) {
    if(t == 'a') {
      if(a.size() == 0)
        break;
      t = a[0];
      a.erase(0, 1);
    }
    else if(t == 'b') {
      if(b.size() == 0)
        break;
      t = b[0];
      b.erase(0, 1);

    }
    else if(t == 'c') {
      if(c.size() == 0)
        break;
      t = c[0];
      c.erase(0, 1);

    }
  }
  cout << (char)(t - 'a' + 'A') << endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
	ll n,a,b,c,d,e,ans=5;
	cin>>n>>a>>b>>c>>d>>e;
	ans+=max({(n-1)/a,(n-1)/b,(n-1)/c,(n-1)/d,(n-1)/e});
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
count = currentnum = 0

if a==(list(i+1 for i in range(N))):
       print(0)
       exit()

for i in a:
  if i!=currentnum+1: count+=1
  else: currentnum+=1
print(-1 if currentnum==0 else count)

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int> xs(n);
  vector<int> ys(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    cin >> ys[i];
  }

  vector<int> ps(n);
  for (int i = 0; i < n; i++) {
    ps[i] = i;
  }

  double sum = 0;
  int count = 0;
  do {
    double d = 0;
    for (int i = 0; i < n - 1; i++) {
      int dx = xs[ps[i + 1]] - xs[ps[i]];
      int dy = ys[ps[i + 1]] - ys[ps[i]];
      d += sqrt(dx * dx + dy * dy);
    }
    sum += d;
    count++;
  } while (next_permutation(ps.begin(), ps.end()));
  if (DEBUG) cout << "count: " << count << endl;
  cout << sum / count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
int main(){
  std::array<int, 5> times;
  for(int i = 0; i < 5; ++i)
    std::cin >> times[i];

  int sum = 0;
  int maxIncl = 0;
  for(int i = 0; i < 5; ++i){
    if(times[i]%10 == 0)
      sum += times[i];
    else{
      int incl = 10 - times[i]%10;
      sum += times[i] + incl;
      if(incl > maxIncl)
        maxIncl = incl;
    }
  }

  std::cout << sum - maxIncl << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a, b, s, n;
	while (scanf("%d%d\n", &a, &b)==2) {
		s = a + b;
		for (n = 1; s >= 10; n ++)
			s /= 10;
		printf ("%d\n", n);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
const ll mod = 998244353;
int n,a[N];
int mp[N];
int main() 
{
	cin>>n;
	int ma=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
		ma=max(ma,a[i]);
	}
	if(a[1]!=0||mp[0]>=2)
	{
		cout<<0<<endl;
		return 0;
	}
	ll ans=1;
	for(int i=1;i<=ma;i++)
	{
		for(int j=1;j<=mp[i];j++)
		ans=ans*mp[i-1]%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
N, W = map(int, input().split())
w, v = [0] * N, [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

memo = {i:{} for i in range(N)}

def r(i, g):
    global memo
    if i == N:
        return 0
    elif g in memo[i]:
        return memo[i][g]
    elif g < w[i]:
        a = r(i + 1, g)
    else:
        a = max(r(i + 1, g - w[i]) + v[i], r(i + 1, g))
    
    memo[i][g] = a
    return a

print(r(0, W))


Measured memory_bytes: 10600
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n) cin>>s[i];
    bool ok = 1;
    rep(i,n-1){
        //cout<<s[i][s[i].size()-1]<<" "<<s[i+1][0]<<endl;
        if(s[i][s[i].size()-1]!=s[i+1][0]){
            //cout<<s[i][s[i].size()-1]<<" "<<s[i+1][0]<<endl;
            ok = 0;
        }
    }
    set<string> ss;
    rep(i,n) ss.insert(s[i]);
    if(ok && ss.size()==n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		
		int[] b = new int[m];
		int ans = 0;
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			int temp = 0;
			for (int j = 0; j < m; j++) {
				temp += sc.nextInt() * b[j];
			}
			temp += c;
			if (temp > 0) {
				ans++;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 24148
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigDecimal a = BigDecimal.valueOf(sc.nextLong());
        BigDecimal b = BigDecimal.valueOf(sc.nextDouble());
        System.out.println(a.multiply(b).longValue());
        sc.close();

    }

}


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

using namespace std;

class Dice{
    public:
        Dice(vector<int> num_array)
            : aspect(num_array){
            }
        void roll_Dice(char c){
            if(c == 'S'){
                int temp = aspect[0]; 
                aspect[0] = aspect[4];
                aspect[4] = aspect[5];
                aspect[5] = aspect[1];
                aspect[1] = temp;
            }else if(c == 'E'){
                int temp = aspect[0];
                aspect[0] = aspect[3];
                aspect[3] = aspect[5];
                aspect[5] = aspect[2];
                aspect[2] = temp;
            }else if(c == 'W'){
                int temp = aspect[0];
                aspect[0] = aspect[2];
                aspect[2] = aspect[5];
                aspect[5] = aspect[3];
                aspect[3] = temp;
            }else if(c == 'N'){
                int temp = aspect[0];
                aspect[0] = aspect[1];
                aspect[1] = aspect[5];
                aspect[5] = aspect[4];
                aspect[4] = temp;
            }
        }
        void yow_dice(){
            int temp = aspect[1];
            aspect[1] = aspect[2];
            aspect[2] = aspect[4];
            aspect[4] = aspect[3];
            aspect[3] = temp;
        }
        int print_eyes(int a){
            return aspect[a];
        }
        int serch_eyes(int objective_eyes){
            for (int i = 0; i < aspect.size(); i++){
                if(aspect[i] == objective_eyes) return i;
            }
        }
    private:
        vector<int> aspect; // 0:upper 1:front 2:right side 3:left side 4: rear side 5: bottom 
};

int main(){

    // --- Dice --- //    
    vector<int> num_array(6);
    for(int i=0;i < 6;i++){
        cin >> num_array[i];
    }
    Dice dice1(num_array);

    // --- 
    int n_question;
    cin >> n_question;
    int upper_side,front_side;
    for(int i = 0;i < n_question;i++){
        cin >> upper_side >> front_side;
        int upper_eye = dice1.serch_eyes(upper_side);
        if(upper_eye == 5){
            dice1.roll_Dice('N');
            dice1.roll_Dice('N');
        }else if(upper_eye == 1){
            dice1.roll_Dice('N');
        }else if(upper_eye == 2){
            dice1.roll_Dice('W');
        }else if(upper_eye == 3){
            dice1.roll_Dice('E');
        }else if(upper_eye == 4){
            dice1.roll_Dice('S');
        }
        for(int j = 0;j < 4;j++){
            dice1.yow_dice();
            if(dice1.print_eyes(1) == front_side){
                cout << dice1.print_eyes(2) << "\n";
                break;
            }
        }
    }
    
    return 0;
}
 



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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)

int main()
{
    ull a,b,c,d;
    cin>>a>>b>>c>>d;
    ull e = b-a+1;

    ull ta = min(c,d); ull tb = max(c,d);
    ull tab = c*d;
    ull r = ta%tb;
    while(r!=0){
        ta=tb; tb=r; r=ta%tb;
    }
    ull lcm = tab/tb;

    ull ans = b-a+1 - (b/c-a/c + b/d-a/d) + b/lcm-a/lcm - (a%c==0) - (a%d==0) + (a%lcm==0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main() {
      int n, k;
      cin>>n>>k;
      vector<int>vec(n+1);
      vector<int>dp(n+1, INT_MAX);
      
      for(int i=1;i<=n;i++)
        cin>>vec[i];
      
      dp[0]=0;
      dp[1]=0;
      dp[2]=abs(vec[2]-vec[1]);  
     
      for(int i=3;i<=n;i++) 
      	for(int j=1;j<=k && i>j;j++) 
        	dp[i]=min(dp[i-j]+abs(vec[i-j]-vec[i]), dp[i]);
      
      cout<<dp[n]<<endl;
      
    }  


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <vector>
#include <iomanip>
using namespace std;


int main(){
    // input
    int N, D; cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < D; ++j){
            cin >> X.at(i).at(j);
        }    
    }

    // compute
    int ans = 0;
    for (int i = 0; i < N-1; ++i){
        for (int j = i+1; j < N; ++j){
            double dist = 0;
            for (int d = 0; d < D; ++d){
                dist = dist + pow(X.at(i).at(d) - X.at(j).at(d), 2.0);
            }
            double distance = sqrt(dist);
            if (ceil(distance) == floor(distance)) ++ans;
        }    
    }

    // output
    cout << ans << endl;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    vector<ll> S(N+1, 0), O(N+1, 0), E(N+1, 0);
    REP(i, N){
    	S[i+1] = S[i] + A[i];
    	if(i%2 == 0){
    		E[i+1] = E[i] + A[i];
    		O[i+1] = O[i]; 
    	}else{
    		E[i+1] = E[i];
    		O[i+1] = O[i] + A[i];
    	}
    }
    //cout << endl;
    //cout << A << endl;
    //cout << S << endl;
    //cout << E << endl;
    //cout << O << endl;
    REP(i, Q){
    	ll X;
    	cin >> X;
    	ll res = 0;
    	if(N%2 == 0){
    		ll l = 0;
    		ll u = N/2;
    		while(u-l > 1){
    			ll m = (u+l)/2;
    			if(abs(A[N-2*m-1] - X) > abs(A[N-m-1] - X)){
    				u = m;
    			}else{
    				l = m;
    			}
    		}
    		res += (S[N] - S[N-u]);
    		res += (O[N-2*u] - O[0]);
    	}else{
    		ll l = 0;
    		ll u = N/2 + 1;
    		while(u-l > 1){
    			ll m = (u+l)/2;
    			if(abs(A[N-2*m-1] - X) > abs(A[N-m-1] - X)){
    				u = m;
    			}else{
    				l = m;
    			}
    		}
    		if(u == N/2+1){
    			res += (S[N] - S[N/2]);
    		}else{
    			res += (S[N] - S[N-u]);
    			res += (E[N-2*u] - E[0]);
    		}
    	}
    	cout << res << endl;
    }
    return 0;
}

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

int main() {
	long n,m,i,j,k,ans=0,cur,res,hi,lo;
	cin >> n;
	vector<double> l(n);
	double mid;
	for(i=0; i<n; i++){
		cin >> l[i];
	}
	l.push_back(10000); l.push_back(0);
	sort(l.begin(),l.end());
	
	for(i=1; i<n-1; i++){
		for(j=i+1; j<n; j++){
			//cout << i << j << ' ';
			hi=n+1; lo=0; mid=l[j]-l[i]+0.5;
			while(hi-lo>1){
				cur=(hi+lo)/2;
				if(l[cur]>mid){
					hi=cur;
				}else{
					lo=cur;
				}
			}
			res=max(lo,j);
			//cout << res << ' ';

			hi=n+1; lo=0; mid=l[j]+l[i]-0.5;
			while(hi-lo>1){
				cur=(hi+lo)/2;
				if(l[cur]>mid){
					hi=cur;
				}else{
					lo=cur;
				}
			}
			//cout << lo << ' ' << endl;
			ans+=lo-res;
			
		}
	}
	cout << ans;
}

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

using namespace std;

int main () {

    std::string s;

    getline(cin, s);

    for (int i = 0; i < 1200; i++) {
        if (65 <= s[i] && s[i] <= 90) {
            s[i] += 32;
        } else if (97 <= s[i] && s[i] <= 122) {
            s[i] -= 32;
        }
    }

    cout << s << endl;

    return 0;
}


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

using namespace std;

int main() {
    int n, k, s;
    cin >> n >> k >> s;

    vector<int> ret(n, s);
    for (int i = k; i < n; i++) ret[i] = s == 1e9 ? s - 1 : s + 1;

    for (int i = 0; i < n; i++) {
        if (i > 0)cout << " ";
        cout << ret[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = [0] * (N + 2)
	for i in range(1, N + 2):
		A[i] = i * (N - (i - 1)) + 1

	# print(A)
	ans = 0
	for i in range(K, N + 2):
		ans += A[i]

	ans %= con
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 69428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,s,g,l,h;
  cin >> n >> s >> g >> l >> h;
  for(ll i=0;i<n;i++) {
    if(l*(n-1-i)-h*i<=g-s&&g-s<=-l*i+h*(n-1-i)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
// AOJ 0146: Lupin The 4th
// 2017.9.28 bal4u@uu
// 2017.11.21

#include <stdio.h>
#include <string.h>

#define INF 0x7fffffff
#define MAX 32768

int s[16], d[16], v[16];	// ????????±?????????????????¢???????????±?????°
int dd[16][16];
int dp[16][MAX];			// DP????????¨?????????
int w[16][MAX];				// ????????±????????°
short prev[16][MAX][2];		// ???????????????????????????
int ord[16];				// ???????????????????????????????????????????????´???

int main()
{
	int n, i, j, k, t, ii, lim;
	int x, y;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d%d%d", s+i, d+i, v+i);
	for (i = 0; i < n; i++) for (j = i+1; j < n; j++) {
		t = d[i] - d[j]; if (t < 0) t = -t;
		dd[i][j] = dd[j][i] = t;
	}

	memset(prev, -1, sizeof(prev));
	for (ii = 1, i = 0; i < n; i++, ii <<= 1) w[i][ii] = v[i];

	lim = 1 << n;
	for (k = 0; k < lim; k++) {
		for (ii = 1, i = 0; i < n; i++, ii <<= 1) {		// ??´????????????
			if (k & ii) continue;
			t = k | ii;
			for (j = 0; j < n; j++) {	// ??´?????????
				if (i == j || w[j][k] == 0) continue;
				x = dp[j][k] + dd[i][j]*(7+2*w[j][k]);
				if (!dp[i][t] || x < dp[i][t]) {
					dp[i][t] = x, w[i][t] = w[j][k] + v[i];
					prev[i][t][0] = j;
					prev[i][t][1] = k;
				}
			}
		}
	}

	// ???????§???????????????????
	for (x = INF, ii = 0, i = 0; i < n; i++) {
		if ((y = dp[i][lim-1]) > 0 && y < x) x = y, ii = i;
	}

	// ?????£???????????????
	for (ord[0] = ii, i = ii, j = lim-1, k = 1; k < n; k++) {
		ord[k] = prev[i][j][0];
		     j = prev[i][j][1];
		     i = ord[k];
	}

	// ??????
	printf("%d", s[ord[n-1]]);
	for (i = 1; i < n; i++) printf(" %d", s[ord[n-i-1]]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 7276