akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# input
n, tc = map(int, input().split())
data = []
for i in range(n):
    c, t = map(int, input().split())
    data.append([c, t])

# process
cost = 1001
getroad = 0
for j in range(n):
    if data[j][1] <= tc:
        if cost > data[j][0]:
            cost = data[j][0]
            getroad += 1

# output
if getroad == 0:
    print("TLE")
else:
    print(cost)


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 3020
#define MOD 998244353
using namespace std;

int a[N];
int f[N][N];

int main(void)
{
    int n, m;
    int i, j;

    cin >> n >> m;
    f[0][0] = 1;
    for(i = 1; i <= n; i ++)
    {
        cin >> a[i];
        for(j = 0; j <= m; j ++)
        {
            f[i][j] = (long long)f[i - 1][j] * 2 % MOD;
            if(j >= a[i])
                f[i][j] = (f[i][j] + f[i - 1][j - a[i]]) % MOD;
            // printf("prev %d, sum %d : %d\n", i, j, f[i][j]);
        }
    }
    cout << f[n][m] << endl;

    return 0;
}


Measured memory_bytes: 38984
#include <stdio.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)

int dp[105][10101] = {0};
int main(){
    int N, W;
    scanf("%d%d", &N, &W);
    int v[105], w[105];
    rep(i, N) scanf("%d%d", v+i, w+i);

    rep(i, N){
        rep(j, W+1){
            if(j - w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    printf("%d\n", dp[N][W]);
}


Measured memory_bytes: 5800
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a,b;
    cin >> a >> b;
    if(a > b) cout << "a > b" << endl;
    else if(a < b) cout << "a < b" << endl;
    else cout << "a == b" << endl;
}


Measured memory_bytes: 3100
class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N = gets.to_i

def f(a, b)
  l = a.to_s.size
  m = b.to_s.size

  [l, m].max
end

puts N.divisor_list.map { |n| f(n, N / n) }.min


Measured memory_bytes: 2300
/*
ID: Barry Wang
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
#define X first
#define Y second
#define Chtolly return 0
/*---define types---*/
typedef long long ll;
typedef list<int> li;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef unsigned int uint;
/*---define variables---*/
const int inf=(1<<29);
int n,lim;
ll h[100005],dp[100005];
/*---define function---*/

/*---main code---*/
int main(){
	cin>>n>>lim;
	for(int i=1;i<=n;++i){
		dp[i]=0x7fffffff;
		cin>>h[i];
	}
	dp[1]=0;
	for(int i=1;i<=n;++i){
		for(int k=1;k<=lim;++k){
			dp[i+k]=min(dp[i+k],dp[i]+abs(h[i+k]-h[i]));
		}
	}
	cout<<dp[n]<<'\n';
	return 0;
}


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

int sosa(int x)
{

	if (x <= 1)
		return 0;
	else if (x == 2)
		return 1;
	if (x % 2 == 0)
	
		return 0;
	
	for (int i = 3; i <= x/i; i+=2)
	
		if (x % i == 0)
		return 0;
		
		return 1;
	
}

int main()
{
	int l[10000];
	int k, n;
	int tmp,flug,cnt;
	cnt = 0;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> n;
		l[i] = n;
	}
	//入力終わり

	for (int i = 0; i < k; i++)
	{
		tmp = l[i];
		flug = sosa(tmp);
		if (flug == 1)
		{
			cnt++;
		}
		
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3140
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

lli i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
bool func(pll p1 , pll p2)
{
  return p1.fi>p2.se;
}
map< lli , lli> ct;
void solve()
{
	lli n,m; cin>>n>>m;
	lli a[n]={0};
	sll s;
	rep(i,0,n-1) cin>>a[i],++ct[a[i]],s.ins(a[i]);
   
   rep(i,0,m-1)
   {
   	lli b,c; cin>>b>>c;
     ct[c]+=b; s.ins(c);
   }

   auto it=s.end();
   --it;
   lli cnt=n,sum=0;

   while(cnt>0)
   {
   	 lli v=min2(cnt,ct[*it]);
   	 cnt-=v;
   	 sum+=v*(*it);
   	 --it;
   }
   cout<<sum<<"\n";
}

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

int main(){
  int p[7];
  int tmp,n;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<7;i++)p[i] = 0;
    for(int i=0;i<n;i++){
      cin >> tmp;
      if(tmp<10)p[0]++;
      else if(tmp<20)p[1]++;
      else if(tmp<30)p[2]++;
      else if(tmp<40)p[3]++;
      else if(tmp<50)p[4]++;
      else if(tmp<60)p[5]++;
      else p[6]++;
    }
    for(int i=0;i<7;i++)cout << p[i] << endl;
  }
}

Measured memory_bytes: 864
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int k; cin >> k;
    rep(i,k){
        cout << "ACL" ;
    }
    cout << endl;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	ll N; cin >> N;
	int ans = 0;
	for(int i = 1; i <= N; ++i) {
		if( N-i>i && N-i>=1 && (N-i!=i)) ans++;
	}
	cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int X, Y, Z, K;

	cin >> X >> Y >> Z >> K;

	long long A[X], B[Y], C[Z];

	for(int i = 0; i < X; i++)
		cin >> A[i];
	for(int j = 0; j < Y; j++)
		cin >> B[j];
	for(int k = 0; k < Z; k++)
		cin >> C[k];

	sort(A, A+X, greater<long long>());
	sort(B, B+Y, greater<long long>());
	sort(C, C+Z, greater<long long>());

	vector<long long> ans;
	for(int i = 0; i < X; i++){
		for(int j = 0; j < Y; j++){
			if((i+1) * (j+1) > K) break;
			for(int k = 0; k < Z; k++){
				if((i+1) * (j+1) * (k+1) > K) break;
				ans.push_back(A[i]+B[j]+C[k]);
			}
		}
	}

	sort(ans.begin(), ans.end(), greater<long long>());

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


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll a[101010];
ll b[101010];
ll c[101010];
ll dp[101010][3];
bool flag[5];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	rep(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	rep(i, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (j != k) {
					if (j == 0) {
						dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i]);
					}
					else if (j == 1) {
						dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + b[i]);
					}
					else {
						dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + c[i]);
					}
				}
			}
		}
	}
	ll ans = 0;
	rep(i, 3) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for (auto& x : a) cin >> x;
  sort(a.begin(), a.end());
  
  long seki = 1;
  for (long x : a) {
    if (x > 0 && seki > long(1e18) / x) {
      return cout << -1 << endl, 0;
    }
    seki *= x;
  }
  cout << seki << endl;
}

Measured memory_bytes: 3972
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
abs_A = [abs(i) for i in A]
ans = 0
if (0 in A) or (np.count_nonzero(A<0) % 2 == 0):
    ans = sum(abs_A)
else:
    ans = sum(abs_A) - 2*min(abs_A)
print(ans)

Measured memory_bytes: 23360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
int N, W;
vvi dp;
vi w, v;

ll solve(int cur=0, ll rest=W){

    ll &ret=dp[cur][rest];
    if(ret != -1) return ret;

    ret=0;
    if(rest >= w[cur]) ret=v[cur]+solve(cur+1, rest-w[cur]);
    ret=max(ret, solve(cur+1, rest));

    return ret;

}

int main(){
    scanf("%d %d",&N, &W);
    dp=vvi(N+2, vi(W+2));
//    for(int i=0;i<=N;i++) for(int j=0;j<=W;j++) dp[i][j]=-1;
    w=vi(N), v=vi(N);
    for(int i=0;i<N;i++) scanf("%lld %lld",&w[i], &v[i]);


    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= W; j++) {
            int weight = w[i - 1];
            if(weight<=j){
                dp[i][j] = max(v[i - 1] + dp[i - 1][j - weight],dp[i - 1][j]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }

    printf("%lld", dp[N][W]);
//    printf("%lld", solve());

    return 0;
}


Measured memory_bytes: 81024
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int score = 0;
			int t = 0;
			for(int i = 0;i < 5;i++){
				score += ((t = scan.nextInt()) < 40)?40:t;
			}
			System.out.println(score/5);
		}
	}
}

Measured memory_bytes: 17328
import           Text.Printf
import           Control.Monad         (replicateM)
import qualified Data.ByteString.Char8 as BSC8

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- replicateM n (BSC8.unpack <$> BSC8.getLine)
    let (c0, c1, c2, c3) = solve xs (0, 0, 0, 0)
    printf "AC x %d\nWA x %d\nTLE x %d\nRE x %d\n" c0 c1 c2 c3
solve :: [String] -> (Int, Int, Int, Int) -> (Int, Int, Int, Int)
solve [] t = t
solve (x:xs) (a, b, c, d)
    | x == "AC"  = solve xs (a + 1, b, c, d)
    | x == "WA"  = solve xs (a, b + 1, c, d)
    | x == "TLE" = solve xs (a, b, c + 1, d)
    | x == "RE"  = solve xs (a, b, c, d + 1)
    | otherwise  = solve xs (a, b, c, d)

Measured memory_bytes: 26692
#include<iostream>
#include<vector>

int main(){
	int A,ans(0);
  	std::cin >> A;
  	std::vector<int> d(A);
  	for(int i = 0 ; i < A ; i ++){
    	std::cin >> d[i];
    }
  	for(int i = 0 ; i < A ; i ++){
    	for(int I = i + 1 ; I < A ; I ++){
        ans += d[i] * d[I];
        }
    }
  	std::cout << ans;
}

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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    vector<long long> sum(n+1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    long long ans = 1e18;
    for (int i = 1; i < n; i++) {
        long long l = sum[i];
        long long r = sum[n]-sum[i];
        long long res = abs(l-r);
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
# abc164B
# https://atcoder.jp/contests/abc164/tasks/abc164_b

# 高橋君モンスターの体力はA、攻撃力はB
# 青木君モンスターの体力はC、攻撃力はD

# 高橋君が勝ったら"Yes"、負けたら"No"

# 入力
a, b, c, d = map(int, input().split())

# 処理
# 必殺技を受けた残りの体力
while a > 0 and c > 0:
    a -= d
    c -= b

if c <= 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9016
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }

    int ans = INT_MAX;
    for(int bit=0; bit<(1<<n); bit++){ 
        vector<int> inte(m);
        int cost = 0;
        rep(i, n){
            if(bit & (1 << i)){
                cost += c[i];
                rep(j, m){
                    inte[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        rep(k, m){
            if(inte[k] < x){
                ok = false;
                break;
            }
        }
        if(ok){
            ans = min(ans, cost);
        }
    }
    if(ans == INT_MAX){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
#define ll long long
#define trace(x) cerr << #x << " = " << x << endl
using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
int main()
{
   /*
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("ouput.txt","w",stdout);
    #endif 
   */

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while(t--){
         string s;
	 cin>>s;
	 int x = 0;
	 for(char c : s){
		 x += c - '0';
	 }
		 
	 if(x%9 == 0)
		 cout<<"Yes"<<endl;
	 else
		 cout<<"No"<<endl;
    }
    return 0;
} 


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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    int ans = 0;

    rep(i,N) if(a[i] % 2 == 1 and (i + 1) % 2 == 1) ans++;

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

Measured memory_bytes: 3628
# https://atcoder.jp/contests/abc089/tasks/abc089_c

from itertools import combinations

n=int(input())
s=[input() for _ in range(n)]

S=dict()
w=['M','A','R','C','H']

for e in s:
    fst=e[0]
    if fst in w:
        S[fst]=S.get(fst,0)+1

C=list(combinations(S,3))

ans=0
for c in C:
    tmp=1
    for e in c:
        tmp*=S[e]
    ans+=tmp
print(ans)

Measured memory_bytes: 9776
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 2000005
typedef long long ll;
typedef long double ld;
using namespace std;
#define int long long
// stores smallest prime factor for every number 
int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret;
}
bool solve(ll a[],ll n){
	set<ll> st;
	vll v1;
	for (int i = 0; i < n; ++i)
	{
		v1=getFactorization(a[i]);
		set<ll>st1;
		for(auto e:v1){
			st1.insert(e);
		}
		for(auto e:st1){
			if(st.find(e)!=st.end())return false;
			//debug(e);
			st.insert(e);
		}
	}
	return true;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    sieve();
    int cnt=0;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];if(a[i]==1)++cnt;
    }
    if(cnt>=n-1){
    	cout<<"pairwise coprime";
    	return 0;
	}
	int m=n-cnt;
	int b[m];
	int pos=0;
	for(int i=0;i<n;i++){
		if(a[i]!=1){
			b[pos++]=a[i];
		}
	}
    if(solve(b,m)){
    	cout<<"pairwise coprime";
    }else{
    	int g=a[0];
    	for (int i = 0; i < n; ++i)
    	{
    		g=__gcd(a[i],g);
    	}
    	if(g==1){
    		cout<<"setwise coprime";
    	}else{
    		cout<<"not coprime";
    	}
    }

    return 0;
}

Measured memory_bytes: 34852
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,x,y = readline() |> split |> parseMap
	d = zeros(Int,n)
	for i in 1:n-1
		for j in i+1:n
			if j<=x||i>=y
				d[j-i] += 1
			elseif i<=x&&j>=y
				d[j-i-y+x+1] += 1
			elseif i<=x
				d[min(j-i,y-j+x-i+1)] += 1
			elseif j>=y
				d[min(j-i,i-x+j-y+1)] += 1
			else
				d[min(j-i,y-j+i-x+1)] += 1
			end
		end
	end
	for i in 1:n-1
		println(d[i])
	end
end

main()

Measured memory_bytes: 112176
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    cout << (A*min(N, B-1))/B << endl;
}


Measured memory_bytes: 3176
#include <iostream>

const int N = 100010;

int64_t a[ N ], l;
int n;

int main() {

	std::cin >> n >> l;

	for ( int i = 1 ; i <= n ; ++i ) {
		std::cin >> a[i];
	}

	int mx = 1;
	for ( int i = 2 ; i+1 <= n ; ++i ) {
		if ( a[i] + a[i+1] > a[mx] + a[mx+1] ) {
			mx = i;
		}
	}

	if ( a[mx] + a[mx+1] < l ) {
		std::cout << "Impossible" << std::endl;
		return 0;
	}

	std::cout << "Possible\n";
	for ( int i = 1 ; i < mx ; ++i ) {
		std::cout << i << "\n";
	}
	for ( int i = n-1 ; i > mx ; --i ) {
		std::cout << i << "\n";
	}

	std::cout << mx << "\n";

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, t;
    cin >> n >> t;
    vl a(n);
    rep(i, n) cin >> a[i];
    ll dif = 0LL, cnt = 0LL, m = 1e18;
    rep(i, n) {
        if(dif < a[i] - m) {
            dif = a[i] - m;
            cnt = 1;
        }
        else if(dif == a[i] - m) {
            ++cnt;
        }
        m = min(m, a[i]);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    string s;
    cin >> s;
    int num[4];
    rep(i, 4) num[i] = s[i] - '0';
    int x = 10 * num[0] + num[1];
    int y = 10 * num[2] + num[3];
    bool f1 = 1 <= x && x <= 12, f2 = 1 <= y && y <= 12;
    if (f1 && f2)
        cout << "AMBIGUOUS" << endl;
    else if (f1)
        cout << "MMYY" << endl;
    else if (f2)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  i64 fact[100100];
  int N; cin >> N;

  fact[0] = 1;
  for (i64 i = 1; i <= N; ++i) {
    fact[i] = fact[i-1] * i % 1'000'000'007;
  }

  cout << fact[N] << endl;

  return 0;
}



Measured memory_bytes: 1024
ABCD = [int(x) for x in list(input())]

calc_seq = [ABCD[0]]
op_seq = []

for i in range(1,4):
    for h in calc_seq[(2**(i-1))-1:(2**(i))-1]:
        calc_seq.append(h - ABCD[i])
        calc_seq.append(h + ABCD[i])

for i in range(7,16):
    if calc_seq[i] == 7:
        while i != 0:
            if i % 2 == 0:
                op_seq.append("+")
            else:
                op_seq.append("-")
            i = (i - 1) // 2
        break

op_seq = op_seq[::-1]
print(str(ABCD[0]) + op_seq[0] + str(ABCD[1]) + op_seq[1] + str(ABCD[2]) + op_seq[2] + str(ABCD[3]) + "=7")


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

pair<ll, ll> solve(vector<int> a) {
    int n = a.size();
    if (a[n - 1] != 2) return {-1, -1};

    ll mn = 2, mx = 2;
    for (int i = n - 1; i >= 0; i--) {
        // x%a[i]=0
        // x-x%a[i+1]=old
        mn = (mn + a[i] - 1) / a[i] * a[i];
        mx = (mx + a[i]) / a[i] * a[i] - 1;
        if (mn > mx) return {-1, -1};
    }

    return {mn, mx};
};

int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    int n;
    while (cin >> n) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        auto o = solve(a);
        if (o.first == -1) cout << -1 << endl;
        else cout << o.first << " " << o.second << endl;
    }

    return 0;
}

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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<size;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define FLL(a,n,i) for(long long int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()

const int mod=1000000007;
const int modpro=988244353;

const int di[8]={-1,0,1,0,-1,1,1,-1},dj[8]={0,1,0,-1,1,1,-1,-1};

vector<bool> visi;
vector<vector<int>> adj;

int dfs(int i){
	stack<int> s;
	s.push(i);
	int nodes = 0;
	visi[i]=true;
	while(!(s.empty())){
		int temp;
		temp = s.top();
		nodes++;
		s.pop();
		for(int adjNode : adj[temp]){
			if(visi[adjNode]==false){
				s.push(adjNode);
				visi[adjNode]=true;
			}
		}
	}
	return nodes;
}

void solve(){
	int n,m;
	cin>>n>>m;
	visi.resize(n);
	adj.resize(n);
	F(0,m,i){
		int u,v;
		cin>>u>>v;
		adj[u-1].pb(v-1);
		adj[v-1].pb(u-1);
	}
	int ma=0;
	F(0,n,i){
		if(visi[i]==false) ma=max(ma,dfs(i));
	}
	cout<<ma;
}

int main()
{

  //freopen("out", "w", stdout);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
  
  cerr<<endl << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << " ms\n";
}



Measured memory_bytes: 15084
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll n,k;
  cin >> n >> k;
  n++;
  vector<ll> a(n + 1);
  rep(i, n){
    a[i + 1] = i;
  }
  rep(i, n - 1) a[i + 2] += a[i + 1];
  ll ans = 0;
  for(int i = k - 1; i < n; i++){
    ans += (a[n] - a[n - 1 - i]) - a[i + 1] + 1;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main()
{
    ll X;
    cin >> X;
    for (int i = -1000; i <= 1000; i++)
    {
        for (int j = -1000; j <= 1000; j++)
        {
            if (pow(i, 5) - pow(j, 5) == X)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	int N;
	cin >> N;

	ll sum = 0;
	vector<int> V(N);

	for(auto &i : V) cin >> i, sum += i;

	int Q;
	cin >> Q;

	while(Q--){
		int p,x;
		cin >> p >> x;
		p--;

		cout << sum + (x - V[p]) << endl;
	}

	return 0;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

class mint {
  private: 
    ll x;

  public:
    constexpr mint(const ll x = 0) noexcept : x((x % mod + mod) % mod) {}
    constexpr ll value() noexcept { return x; }
    constexpr mint operator += (const mint right) noexcept {
      if ((x += right.x) >= mod) x -= mod;
      return *this;
    }
    constexpr mint operator -= (const mint right) noexcept {
      if ((x += mod - right.x) >= mod) x -= mod;
      return *this;
    }
    constexpr mint operator *= (const mint right) noexcept {
      x = x * right.x % mod;
      return *this;
    }
    constexpr mint operator /= (const mint right) noexcept {
      return *this *= right.inv();
    }
    constexpr mint operator + (const mint right) const noexcept {
      return mint(*this) += right;
    }
    constexpr mint operator - (const mint right) const noexcept {
      return mint(*this) -= right;
    }
    constexpr mint operator / (const mint right) const noexcept {
      return mint(*this) /= right;
    }
    constexpr mint operator * (const mint right) const noexcept {
      return mint(*this) *= right;
    }
    constexpr mint inv() const {
      return pow(mod-2);
    }
    constexpr mint pow(ll n) const {
      if (n == 0) return 1;
      mint a = pow(n>>1);
      a *= a;
      if (n & 1) a *= *this;
      return a;
    }
};

mint dp[100005];

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n, m; cin >> n >> m;
  set<int> broke;

  rep(i, m) {
    int a; cin >> a;
    broke.em(a);
  }

  dp[0] = 1;
  rep(i, n) {
    if (broke.count(i)) continue;
    dp[i+1] += dp[i];
    dp[i+2] += dp[i];
  }

  cout << dp[n].value() << endl;
}


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

long d;
long c[26];
long s[365][26];
long t[365];
long last[27];

long calcMinus(int day);

int main(){
    cin >> d;
    for(int i=0;i<26;i++)cin >> c[i];
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    long t[d];
    for(int i=0;i<d;i++)cin >> t[i];
    
    for(int i=1;i<=26;i++)last[i] = -1;

    long ans = 0;

    for(int i=0;i<d;i++){
        last[t[i]] = i;
        ans += s[i][t[i]-1];
        ans += calcMinus(i);
        cout << ans << endl;

    }
}


long calcMinus(int day){

    long ans = 0;
    for(int i=0;i<26;i++){
        ans -= c[i] * (day - last[i+1]);
    }

    return ans;
}

Measured memory_bytes: 3664
N = int(input())
v_list = [int(v) for v in input().split()]

v_list.sort(reverse=True)

while len(v_list) > 1:
  v_1 = v_list.pop()
  v_2 = v_list.pop()
  new = (v_1 + v_2) /2
  v_list.append(new)
  v_list.sort(reverse=True)
print(v_list[0])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
int main(){
	using namespace std;
	unsigned long Q,a,b,c,d,M{205891132094649UL};
	cin>>Q;
	const auto& calc=[&M](auto a,auto b,auto c,auto d){
		auto u{b},l{b},p{M};
		while(p/=3)if((a/p+(4-a/p%3)%3)*p<=c){if(u/p%3==1)u=u/(3*p)*3*p+2*p;if(l/p%3==1)l=l/(3*p)*3*p+p-1;}
		return c-a+min(u-b+max(u,d)-min(u,d),b+d-2*l);
	};
	while(Q--){
		cin>>a>>b>>c>>d;
		if(--a>--c)swap(a,c),swap(b,d);
		if(--b>--d){b=M-b-1;d=M-d-1;}
		cout<<max(calc(a,b,c,d),calc(b,a,d,c))<<endl;
	}
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
  int x,y,z,k,s,count=0;
  
  cin >> k;

  cin >> s;

    for(x=0;x<=k;++x){
      for(y=0;y<=k;++y){
	z = s-x-y;
	if(0<=z && z<=k){
	  count++;
	}
      }
    }
    
    
    
    cout << count;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;


void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n,m,a,b;
    const int mxN=2e5;
    vvi adj(mxN);
	vi vis(mxN),ans;
    cin >> n >> m;
    REP(i,m){
    	cin >> a >> b;
    	--a,--b;
    	adj[a].pb(b);
    	adj[b].pb(a);
	}
	function<void(int)> dfs = [&](int u){
	  vis[u]=1;
	  EACH(v, adj[u]) if(!vis[v]) dfs(v);
	};
	REP(i,n){
		if(!vis[i]){
			ans.pb(i+1);
			dfs(i);
		}
	}
	int sz = ans.size();
	OUT(sz-1);
    return 0;
}

Measured memory_bytes: 13480
INF = 10 ** 20
H, W = map(int, input().split())
power = 0
graph = []
for i in range(10):
  graph.append(list(map(int, input().split())))

for k in range(10):
  for i in range(10):
    for j in range(10):
      graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
  
for h in range(H):
  A = list(map(int, input().split()))
  for w in range(W):
    if A[w] == -1:
      continue
    else:
      power += graph[A[w]][1]

print(power)

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    LL a, b, x;
    cin >> a >> b >> x;

    if( a == 0 || a % x == 0){
        cout << (b / x ) - (a / x) + 1 << endl;
    }
    else{
        cout << (b / x ) - (a / x) << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; ll k;
  cin >> n >> k;
  vector<int> ar(n);
  for(int &i: ar) {
    cin >> i;
    i--;
  }
  int st = ar[0];
  vector<int> lp;
  vector<bool> vis(n);
  vis[0] = 1;
  lp.push_back(0);
  while(1) {
    if(vis[st]) {
      break;
    }
    vis[st] = 1;
    lp.push_back(st);
    st = ar[st];
  }
  vector<int> rec;
  bool ok = false;
  for(int i = 0; i < (int) lp.size(); ++i) {
    if(st == lp[i]) {
      ok = true;
    }
    if(ok) {
      rec.push_back(lp[i]);
      continue;
    }
    if(k-- == 0) {
      cout << lp[i] + 1 << '\n';
      return 0;
    }
  }
  cout << rec[k % (int) rec.size()] + 1 << '\n';
  return 0;
}


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

int main(){
    int n, R, maxv = -1 * pow(10, 9), minv;
    cin >> n;
    cin >> minv;
    for (int i = 1; i < n; i++){
        cin >> R;
        if(maxv < R - minv) maxv = R - minv;
        if(minv > R) minv = R;
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 1005


int main(){

    ll n;
    cin >> n;
    ll cnt = 0;
    for(ll i = 1;i < n;i*=3){
        cnt++;
    }
    cout << cnt << endl;


    return 0;
}


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

int main(){
	
	int A,B,C,D,P;
	int X,Y;
	cin>>A>>B>>C>>D>>P;
	
	X = A*P;
	
	if(P<=C)
		Y=B;
	else
	Y=B+(P-C)*D;
	
	cout<<min(X,Y)<<endl;
	
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int long long h;
  int long long n;
  cin>>h>>n;
  int long long a[n];
  int long long at=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    at+=a[i];
  }
  if(at>=h)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

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

    if(A != B && B != C && A != C)cout << "No";
    else if(A == B && B == C && C == A)cout << "No";
    else cout << "Yes";
    cout << endl;
}

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

#define NIL -1

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

void insert(Node **, Node *);
void print(Node *);
void inorderTreeWalk(Node *);
void preorderTreeWalk(Node *);

main(){
  int m, key, i;
  char string[10];
  Node *T, *node;

  T = NULL;

  scanf("%d", &m);
  for(i=0; i<m; i++){
    scanf("%s", string);
    if(strcmp(string, "insert")==0){
      scanf("%d", &key);
      node = malloc(sizeof(Node));
      node->key = key;
      node->left = NULL;
      node->right = NULL;

      insert(&T, node);
    }
    else print(T);
  }
   return 0;
}

void insert(Node **T, Node *z){
  Node *x, *y;
  
  y = NULL;  //xの親
  x = *T;
  
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  
  if(y==NULL) *T = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void print(Node *T){
  inorderTreeWalk(T);
  printf("\n");

  preorderTreeWalk(T);
  printf("\n");
}

void inorderTreeWalk(Node *T){
  if(T == NULL) return;

  inorderTreeWalk(T->left);
  printf(" %d", T->key);
  inorderTreeWalk(T->right);
}

void preorderTreeWalk(Node *T){
  if(T == NULL) return;
  printf(" %d", T->key);
  preorderTreeWalk(T->left);
  preorderTreeWalk(T->right);
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >>s;
  int free=0;
  string prev ={"-1"};
  int ans=0;
  rep(i,s.size()){
    if(free==0){
      prev[0] = s[i];
      free++;
    }
    else{
      if(prev[0]==s[i]){
	free++;	
      }
      else{
	free--;
	ans+=2;	
      }
    }
  }
  cout << ans << endl;


  
  return 0;
    

}


Measured memory_bytes: 512
import sys
# input = sys.stdin.readline
# inf = 10 ** 18
# P = 10 ** 9 + 7

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

if N % 3 > 0:
    if a.count(0) == N:
        print('Yes')
    else:
        print('No')
    sys.exit()

items = []
for ai in a:
    if ai not in items: items.append(ai)
    if len(items) >= 3: break
items.sort()

if len(items) == 1:
    if a.count(0) == N:
        print('Yes')
    else:
        print('No')
elif len(items) == 2:
    cnt = [a.count(item) for item in items]
    if sum(cnt) < N:
        print('No')
    if items[0] > 0:
        print('No')
    elif a.count(items[1]) == a.count(0) * 2:
        print('Yes')
    else:
        print('No')
else:
    cnt = [a.count(item) for item in items]
    if sum(cnt) < N:
        print('No')
    elif items[2] != items[0] ^ items[1]:
        print('No')
    elif cnt[0] == cnt[1] == cnt[2]:
        print('Yes')
    else:
        print('No')

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

#define endl '\n'

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define BUFF ios::sync_with_stdio(0);

typedef long long int ll;
typedef long double ld;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > ii;
typedef vector < ii > vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1e9+7;
const ld pi = acos(-1);

ll dp[5000][51] = {0ll};
int main() { BUFF
  ll n, a; cin >> n >> a;
  vi x(n); for(auto &it : x) cin >> it;
  for(int i=0; i<n; i++) {
    for(int j=n; j>=2; j--) {
      for(int k=1; k<=2500; k++) {
        int prev = k - x[i];
        if(prev < 0) continue;
        dp[k][j] += dp[prev][j-1];
      }
    }
    dp[x[i]][1]++;
  }

  ll ans = 0;
  for(int i=1; i<=n; i++){
    ans += dp[a*i][i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define R(a) a=sqrt(a)
#define POW(a,b) a=pow(a,b)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
bool is_integer(long double x){
    return floor(x)==x;
}
 
int main(){
    FAST;
    string a;
    ll ans=0;
    cin>>a;
    if(a[0]=='R'){
        ans++;
        if(a[1]=='R'){
            ans++;
            if(a[2]=='R'){
                ans++;
            }
        }
    }
    else if(a[1]=='R'){
        ans++;
        if(a[2]=='R'){
            ans++;
        }
    }
    else if(a[2]=='R'){
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3636