akhauriyash/Code-Regression huggingface dataset:
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[5][5], b, c, d, tmp, m, h, w, x, y, sum, k, q;
U_MAP mp;

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

  rep(i, 3) rep(j, 3) cin >> a[i][j];
  cin >> n;
  rep(i, n) {
    cin >> b;
    mp[b]++;
  }
  rep(i, 3) {
    rep(j, 3) {
      if (mp[a[i][j]]) a[i][j] = -1;
    }
  }
  rep(i, 3) {
    int ok = 0;
    rep(j, 3) {
      if (a[i][j] != -1) ok = 1;
    }
    if (ok) continue;
    Cout("Yes");
    return 0;
  }

  rep(j, 3) {
    int ok = 0;
    rep(i, 3) {
      if (a[i][j] != -1) ok = 1;
    }
    if (ok) continue;
    Cout("Yes");
    return 0;
  }

  if (a[0][0] == -1 && a[0][0] == a[1][1] && a[0][0] == a[2][2])
    Cout("Yes");
  else if (a[0][2] == -1 && a[0][2] == a[1][1] && a[0][2] == a[2][0])
    Cout("Yes");
  else
    Cout("No");
  return 0;
}

Measured memory_bytes: 384
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        var num = Int32.Parse(System.Console.ReadLine());
        var raw = System.Console.ReadLine().Split().Select(int.Parse).ToArray();
        var r = true;
        var i = 0;
        while(r && i < num){
            if(raw[i]%2==0){
                r = raw[i]%3 == 0 || raw[i]%5 == 0;
            }
            i++;
        }
        System.Console.WriteLine(r ? "APPROVED" : "DENIED");
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int n;

	double sum = 0;

	double x[101], y[101];

	double max = 0;

	cin >> n;

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

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

	for (double p = 1.000000; p <= 4.000000; p+=1.000000){
		if (p != 4){

			sum = 0;

			for (int i = 0; i < n; i++)
			{
				sum += pow(fabs(x[i] - y[i]), p);
			}

			printf("%lf\n",pow(sum,1.000000/p));

		}
		else
		{

			for (int i = 0; i < n; i++)
			{
				sum = fabs(x[i] - y[i]);

				if (sum > max)
				{
					max = sum;
				}
			}

			printf("%lf\n",max);

		}

	}
	

	return 0;
}

Measured memory_bytes: 3404
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        long ans = Math.Max(0, inpt[0] - inpt[1]);
        Console.WriteLine(ans);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"

100 17


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        long A, B;

        void solve(InputReader in, PrintWriter out) {
            A = in.nextLong();
            B = in.nextLong();

            out.println((A + B) % 2 == 0 ? (A + B)/2 : "IMPOSSIBLE");
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<numeric>

using namespace std;

int main(){
  int n;
  cin >> n;
  long long a[n];
  long long ret=0;
  for(auto& x:a){
    cin >>x;
    ret+=x;
  }
  long long out=10000000000000000;
  long long sum=0;
  for(int i=0;i<n-1;i++){
    sum+=a[i];
    out =min(out,abs(ret-2*sum));
  }
  cout << out << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 4010
#define Maxm 4010

using namespace std;

int read() {
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while('0' <= c && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

int N,M,Q;
int mp[Maxn][Maxm],sum1[Maxn][Maxm],sum2[Maxn][Maxm];

int main() {
	N = read(); M = read(); Q = read();
	char ch;
	for(int i = 1;i <= N; i++)
		for(int j = 1;j <= M; j++) {
			int x = i * 2 - 1,y = j * 2 - 1;
			ch = getchar();
			while(ch != '0' && ch != '1') ch = getchar();
			if(ch == '1') mp[x][y] = 1;
		}
	for(int i = 1;i <= N; i++)
		for(int j = 1;j <= M; j++) {
			int x = i * 2 - 1,y = j * 2 - 1;
			if(mp[x][y]) {
				if(mp[x - 2][y]) mp[x - 1][y] = 2;
				if(mp[x + 2][y]) mp[x + 1][y] = 2;
				if(mp[x][y + 2]) mp[x][y + 1] = 2;
				if(mp[x][y - 2]) mp[x][y - 1] = 2;
			}
		}
	for(int i = 1;i < N * 2; i++)
		for(int j = 1;j < M * 2; j++) {
			if(mp[i][j] == 1) sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1] + 1;
			else sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1];
			if(mp[i][j] == 2) sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1] + 1;
			else sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1];
		}
	int i_1,j_1,i_2,j_2,x_1,y_1,x_2,y_2;
	for(int k = 1;k <= Q; k++) {
		i_1 = read(); j_1 = read(); i_2 = read(); j_2 = read();
		x_1 = i_1 * 2 - 1; y_1 = j_1 * 2 - 1;
		x_2 = i_2 * 2 - 1; y_2 = j_2 * 2 - 1;
		int ans1 = sum1[x_2][y_2] + sum1[x_1 - 1][y_1 - 1] - sum1[x_2][y_1 - 1] - sum1[x_1 - 1][y_2];
		int ans2 = sum2[x_2][y_2] + sum2[x_1 - 1][y_1 - 1] - sum2[x_2][y_1 - 1] - sum2[x_1 - 1][y_2];
		printf("%d\n",ans1 - ans2);
	}
	return 0;
}

Measured memory_bytes: 190208
from collections import deque
N, M = map(int, input().split())
E = [list() for _ in range(N+1)]
for _ in range(M):
    u, v = map(int, input().split())
    E[u].append(v)
S, T = map(int, input().split())

Visited = [[False]*(N+1) for _ in range(3)]
Visited[0][S] = True
queue = deque()
queue.append((S,0))

while queue:
    cur, path = queue.popleft()
    for neighbor in E[cur]:
        if Visited[(path+1)%3][neighbor]==False:
            queue.append((neighbor, path+1))
            Visited[(path+1)%3][neighbor] = path + 1
            
ans = Visited[0][T]

if ans==False:
    print(-1)
elif ans > 2:
    ans //= 3
    print(ans)
else:
    print(ans)

Measured memory_bytes: 30172
use std::cmp::max;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}

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

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

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn accumulate_sum(v: &Vec<usize>) -> Vec<usize> {
    let mut res = vec![0; v.len() + 1];
    for i in 1..res.len() {
        res[i] += v[i - 1] + res[i - 1];
    }
    res
}

fn main() {
    input! {
        n: usize,
        w: usize,
        wv: [(usize, usize);n]
    }
    let mut v0: Vec<usize> = vec![];
    let mut v1: Vec<usize> = vec![];
    let mut v2: Vec<usize> = vec![];
    let mut v3: Vec<usize> = vec![];
    for i in 0..n {
        match wv[i].0 - wv[0].0 {
            0 => v0.push(wv[i].1),
            1 => v1.push(wv[i].1),
            2 => v2.push(wv[i].1),
            3 => v3.push(wv[i].1),
            _ => (),
        }
    }
    v0.sort_by(|a, b| b.cmp(&a));
    let ac0 = accumulate_sum(&v0);
    v1.sort_by(|a, b| b.cmp(&a));
    let ac1 = accumulate_sum(&v1);
    v2.sort_by(|a, b| b.cmp(&a));
    let ac2 = accumulate_sum(&v2);
    v3.sort_by(|a, b| b.cmp(&a));
    let ac3 = accumulate_sum(&v3);
    let mut ans = 0;
    for i in 0..(v0.len() + 1) {
        for j in 0..(v1.len() + 1) {
            for k in 0..(v2.len() + 1) {
                for l in 0..(v3.len() + 1) {
                    let mut tmpans = 0;
                    tmpans += ac0[i] + ac1[j] + ac2[k] + ac3[l];
                    if w >= i * wv[0].0 + j * (wv[0].0 + 1) + k * (wv[0].0 + 2) + l * (wv[0].0 + 3)
                    {
                        ans = max(ans, tmpans);
                    }
                }
            }
        }
    }
    println!("{}", ans);
}


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

const int INF = 100100100;

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);

  int mi = INF;
  rep(i, 0, N) {
    cin >> m[i];
    mi = min(mi, m[i]);
    X -= m[i];
  }

  int ans = X / mi + N;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#C - Ubiquity
import math
N = int(input())
a = 10**9+7

ans = (10**N)-(2*9**N - 8**N)

# def combinations_count(n, r):
#     return math.factorial(n)%a // (math.factorial(n - r)%a * math.factorial(r))%a
#
# ans =(10**(N-2))%a*(combinations_count(N, 2)*2)%a-combinations_count(N, 2)%a
print(ans%a)

Measured memory_bytes: 11128
N = int(input())
A = []
B = []
for i in range(N) :
    in_a,in_b = map(int,input().split())
    A.append(in_a)
    B.append(in_b)
    
for i in range(1,N) :
    if A[i-1] > A[i] :
        if A[i-1] % A[i] == 0 :
            a = A[i-1]//A[i]
        else :
            a = A[i-1]//A[i] + 1
    else :
        a = 1
    
    if B[i-1] > B[i] :
        if B[i-1] % B[i] == 0 :
            b = B[i-1]//B[i]
        else :
            b = B[i-1]//B[i] + 1
    else :
        b = 1
    
    p = max(a,b)
    
    A[i] *= p
    B[i] *= p

ans = A[-1] + B[-1]

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int F(int a){
    if(a % 2 == 0){
        return a / 2;
    }
    else return 3*a+1;
}
int main(){
    int s;
    cin >>s;
    int A[1000000];
    A[0] = s;
    int ans = 0;
    for(int i = 1;i < 9999999;i++){
        A[i] = F(A[i - 1]);
        bool frag = 0;
        for(int j = 0;j < i;j++){
            if(A[i] == A[j]){
                frag = 1;
                break;
            }
        }
        if(frag){
            ans = i;
            break;
        }
    }
    cout << ans + 1<< endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A,B,C,D;
  scanf("%d %d %d %d", &A,&B,&C,&D);
  
  //↓ここから繰り返し(高橋君と青木君のどちらの体力も 0 より大きい)
  //turn == 1 : 高橋君のターン  turn == -1 : 青木君のターン
  int turn = 1; //最初は高橋君のターン
  while(A > 0 && C > 0){
  	//攻撃
    if(turn == 1){
      //高橋君のモンスターの攻撃
      C = C - B;
    }else if(turn == -1){
  	  //青木君のモンスターの攻撃
  	  A = A - D;
    }
    //ターンの切替
    turn = -turn;
  }
  //↑ここまで繰り返し
  
  if( A > 0 ){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;

    int ans = 0;
    int tmp;
    REP(i, N)
    {
        tmp = i + 1;
        if (tmp % 5 == 0)
            continue;
        if (tmp % 3 == 0)
            continue;
        ans += tmp;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;cin>>a>>b>>c;
    int k;cin>>k;
    int t = max(max(a,b),c);
    int ans = a+b+c-t;
    rep(i, k){
        t*=2;
    }
    cout<<ans+t<<endl;
}

Measured memory_bytes: 256
N = input()
n = [ int(x) for x in list(N)]

K = int(input())
nl = len(N)
cnt = 0

if K == 1:
    cnt += n[0]   + (nl-1) * 9
elif K == 2 and nl >= 2:
    if nl == 2:
        cnt += (n[0]-1) * 9 + n[1]
    if nl > 2:
        cnt += (nl-1) * (nl-2) * 9 * 9 // 2
        cnt += (n[0]-1) * 9 * (nl-1)
        for i in range(1,nl):
            if n[i] > 0:
                cnt += n[i] + (nl - i -1) * 9
                break
elif K == 3 and  nl >= 3:
    if nl == 3:
        cnt += (n[0]-1) * 9 * 9
        cnt += (n[1]-1) * 9 + n[2]
    elif nl > 3:
        cnt += (nl-1) * (nl-2) * (nl-3) // 6 * 9 * 9 * 9
        cnt += (n[0]-1) * (nl-1) * (nl-2) //2 * 9 * 9
        for i in range(1,nl):
            if n[i] > 0:
                cnt += (nl-i-1) * (nl-i-2) // 2 * 9 * 9
                cnt += (n[i]-1) * (nl-i-1) * 9
                for j in range(i+1,nl):
                    if n[j] > 0:
                        cnt += (nl-j-1) * 9
                        cnt += n[j]
                        break
                break
print (cnt)


Measured memory_bytes: 38384
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   string str;
   map<char,int> mm;
   for(int i=0;i<26;i++) mm[('a'+i)]=0;
   map<char,int>::iterator iter;
 while(getline(cin,str))
 {
   for(int i=0;i<str.length();i++)
   {
     if(str[i]>='A'&&str[i]<='Z') str[i]=((str[i]-'A')+'a');
     if(str[i]>='a'&&str[i]<='z') mm[str[i]]++;        
   }
 }
   for(iter=mm.begin();iter!=mm.end();iter++)
   {
     char temp=iter->first;
     int kk=iter->second;
     cout<<temp<<" "<<":"<<" "<<kk<<endl;                                          
   }
   //while(1);
   return 0;
 }

 
 

Measured memory_bytes: 3156
n,k=map(int,input().split())
p=list(map(int,input().split()))
ep=[(x+1)/2 for x in p]
s=[0]*n
s[0]=sum(ep[:k])
if k<n:
  for i in range(0,n-k):
    s[i+1]=s[i]+ep[k+i]-ep[i]
print(max(s))

Measured memory_bytes: 32028
object Main extends App {

  val Array(a,b,k) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def solve(): Int = {
    (Math.min(a, b) to 1 by -1).filter { i =>
      a % i == 0 && b % i == 0
    }(k-1)
  }



  println(solve)

}


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

using namespace std;

#define fread freopen("in.txt", "r", stdin)
#define fwrite freopen("out.txt", "w", stdout)
#define ll long long

int main ()
{
    int n;

    scanf("%d", &n);
    int i = 1, cnt = 0;
    while (n--) {
        int in;
        scanf("%d", &in);
        if (i % 2 != 0) {
            if (in % 2 != 0) cnt++;
        }
        i++;
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<algorithm> 
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
ll dp[N],ans=0;
ll n,k;
ll quickpow(int a,int b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(){
	ios::sync_with_stdio(false);
	cin.tie(0);
}
int main()
{
	init();
	cin>>n>>k;
	for(int i=k;i>=1;i--)
	{
		dp[i]=quickpow(k/i,n);
		for(int j=i*2;j<=k;j+=i)
		dp[i]-=dp[j];
		ans=(ans+1LL*i*dp[i]%mod)%mod;
	}
	cout<<(ans+mod)%mod;
	return 0;
}

Measured memory_bytes: 4372
#include <iostream>

using namespace std;

int main() {
    int n,x;
    while(cin>>n>>x && n) {
        int ans = 0;
        for(int a=1; a<=n; a++)
            for(int b=a+1; b<=n; b++)
                for(int c=b+1; c<=n; c++)
                    if(a+b+c == x) ans++;

        cout << ans << endl;
    }

    return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int t[n];
	ll sum = 0;
	FOR(i,0,n){
		cin >> t[i];
		sum += t[i];
	}
	int m;
	cin >> m;
	FOR(i,0,m){
		int p,x;
		cin >> p >> x;
		ANS(sum - t[p-1] + x);
	}
	return 0;
}


Measured memory_bytes: 256
# -*- coding:utf8 -*-

l, r = map(int, input().split())
ans = 0
if (l - r) < 2019:
    ans = 2018
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            m = (i * j) % 2019
            if m == 0:
                print(0)
                exit()
            elif m < ans:
                ans = m
print(ans)

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

int n,k;
string s;

// outputkan karakter pertama, panjang-2, karakter terakhir

int main(){
    cin>>s;
    n=s.length();
    k=n-2;
    cout<<s[0]<<k<<s[n-1]<<endl;
}

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

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

struct Node *root,*NIL;

void inorder(struct Node *);
void preorder(struct Node *);
struct Node *find(struct Node *,int );
void insert(int );

int main(){
  int i,n,x;
  char retu[10];
  struct Node *ori;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",retu);
    if(strcmp(retu,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(retu,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else{
      scanf("%d",&x);
      ori=find(root,x);
      if(ori!=NIL)
	printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

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

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

struct Node *find(struct Node *u,int k){
  
  while(u!=NIL && k!= u->key){
    if(k < u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=k;
  z->right=NIL;
  z->left=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else x=x->right;
  }
  
  z->parent=y;
  if(y==NIL) root=z;
  else{
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}



Measured memory_bytes: 20480
import collections

R, C = map(int, input().split())
sy, sx = map(lambda n: int(n) - 1, input().split())
gy, gx = map(lambda n: int(n) - 1, input().split())
c = [input() for _ in range(R)]

dist = [[-1 for _ in range(C)] for _ in range(R)]

q = collections.deque([(sy, sx, -1)])


G =     [(-2, -2),
 (-2, -1),
 (-2, 0),
 (-2, 1),
 (-2, 2),
 (-1, -2),
 (-1, -1),
 (-1, 1),
 (-1, 2),
 (0, -2),
 (0, 2),
 (1, -2),
 (1, -1),
 (1, 1),
 (1, 2),
 (2, -2),
 (2, -1),
 (2, 0),
 (2, 1),
 (2, 2)] 

while q:
    y, x, d = q.popleft()

    if y < 0 or R <= y or x < 0 or C <= x:  # out of range
        continue

    if c[y][x] == '#':  # unable to visit
        continue

    if dist[y][x] != -1:  # not the first time to visit
        continue

    dist[y][x] = d + 1
    
    for i,j in [(-1,0),(1,0),(0,1),(0,-1)]:
        q.appendleft((y + i, x + j, d ))
    for i,j in G:
        q.append((y+i,x+j,d+1))
print(dist[gy][gx])

Measured memory_bytes: 238756
def solve(string):
    n, c = string.split()
    n, c = int(n), list(c)
    wi, ri = 0, n - 1
    while wi < n and c[wi] == "R":
        wi += 1
    while ri >= 0 and c[ri] == "W":
        ri -= 1
    ans = 0
    while wi < n and ri >= 0 and wi < ri:
        c[wi], c[ri], ans = c[ri], c[wi], ans + 1
        wi, ri = wi + 1, ri - 1
        while wi < n and c[wi] == "R":
            wi += 1
        while ri >= 0 and c[ri] == "W":
            ri -= 1
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 10812
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
string s;
int main()
{
	cin>>s; string s_=s; 
	if(s.size()==26)
	{
		if(next_permutation(s.begin(),s.end()))
		{
			for(int i=0;i<26;++i)
			{
				putchar(s[i]);
				if(s_[i]!=s[i])
					break;
			}
		}
		else cout<<-1<<"\n";
	}
	else
	{
		set<char> ss;
		for(int i='a';i<='z';++i) ss.insert(i);
		for(auto c:s) ss.erase(c);
		cout<<s<<*ss.begin()<<"\n";
	}
}


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

using namespace std; 
typedef long double ld; 

int main() 
{
	ld n, d; cin >> n >> d; 
	int points = 0; 
	for(int i = 0; i < n; i++) 
	{
		ld x, y, distance; 
		cin >> x >> y; 
		distance = sqrt(pow(abs(x), 2) + pow(abs(y), 2)); 
		if(distance <= d) 
			points++; 
	}

	cout << points << "\n";

	return 0; 
}


Measured memory_bytes: 3768
#include<stdio.h>
 
int main(void){
   int a,b,c,i;
   scanf("%d%d%d",&a,&b,&c);
     if(a>b){
       i=a; a=b; b=i;
     }
     if(b>c){
       i=b; b=c; c=i;
     }
     if(a>b){
       i=a; a=b; b=i;
     }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int x, y, z, k;
	cin >>x >>y >>z >>k;
	VL a(x), b(y), c(z);
	rep(i, x) cin >>a[i];
	rep(i, y) cin >>b[i];
	rep(i, z) cin >>c[i];
	
	VL ab; ab.reserve(x*y+100);
	rep(i, x) rep(j, y) ab.push_back(a[i] + b[j]);
	sort(all(ab), greater<ll>());
	if(sz(ab) > k) ab.resize(k);
	VL abc; ab.reserve(sz(ab)* k);
	sort(all(c), greater<ll>());
	rep(i, sz(ab)) rep(j, z) {
		abc.push_back(ab[i] + c[j]);
	}
	sort(all(abc), greater<ll>());
	rep(i, k) cout << abc[i] <<"\n";

	return 0;
}


Measured memory_bytes: 43380
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

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

  vll as(n);
  rep(i, n) cin >> as[i];

  repLRE(i, k, n-1){
    if(as[i] > as[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;;
  }

  return 0;
}


Measured memory_bytes: 4836
#include<iostream>
#include<map>

int main(){
  std::map<long long,long long> counter;
  std::string line;
  int tmp = 0;
  getline(std::cin,line);
  for(int i=0;i<(int)line.size();i++){
    tmp += ((line[i]=='(')?+1:-1);
    if(tmp)counter[tmp]++;
  }
  long long ans = 0;
  for(std::pair<long long,long long> iter : counter)ans += (iter.second*(iter.second-1))/2;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 4408
N,K = map(int, input().split())

A_input = input()
A = A_input.split()
A_sort = sorted(A)

B=[]
B.append(1)
j=0

for i in range(1,N):
    if(A_sort[i]==A_sort[i-1]):
        B[j]+=1
    else:
        B.append(1)
        j+=1

B_sort = sorted(B)
R=0

if(j+1<=K):
    R = 0
else:
    for i in range(0, j+1-K):
        R += B_sort[i]

print(R)


Measured memory_bytes: 23828
#include <cstdio>

using namespace std;

int main()
{
	int a,b;
	scanf("%d %d", &a, &b);
	
	if (a<b)
		printf("a < b\n");
	else if (a>b)
		printf("a > b\n");
	else if (a==b)
		printf("a == b\n");
	
	return 0;
}

Measured memory_bytes: 1008
def main():
    n, *a = map(int, open(0).read().split())

    o = sum([i % 2 == 1 for i in a])
    p = sum([i % 4 == 0 for i in a])
    q = sum([i % 2 == 0 for i in a]) - p

    if p + 1 >= o and not q:
        print("Yes")
    elif p >= o and q:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14052
#include <iostream>
#include <algorithm>

using namespace std;

int A[110];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	cout << A[N - 1] - A[0] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define INFTY 2147483647


typedef struct{
  char mozi;
  int suzi;
}tramp;

void mergeSort(tramp *,int,int);
void merge(tramp *,int,int,int);
int judge(tramp *,tramp *,int);

void quicksort(tramp *,int,int);
int partition(tramp *,int,int);
void swapping(tramp *,tramp *,tramp *);
  
int main(){
  int n,i,ju;
  tramp *A,*S;

  scanf("%d",&n);
  A = (tramp *)malloc(n * sizeof(tramp));
  S = (tramp *)malloc(n * sizeof(tramp));

  for(i = 1;i < n + 1;i++){
    scanf(" %c %d",&A[i].mozi,&A[i].suzi);
      S[i - 1].mozi = A[i].mozi;
      S[i - 1].suzi = A[i].suzi;
  }

  //   S = A;//kokookasisou

     quicksort(A,0,n);

     mergeSort(S,0,n);

  ju = judge(A,S,n);
  
  if(ju == 1) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 1;i < n + 1;i++)  printf("%c %d\n",A[i].mozi,A[i].suzi);

  free(A);
  free(S);
  return 0;
}

void quicksort(tramp *A,int p,int r){
  int q;
  if(r > p){
    q = partition(A,p,r);
    quicksort(A,p,q - 1);
    quicksort(A,q + 1,r);
  }
}

int partition(tramp *A,int p,int n){
  int i,j;
  tramp x,hako;
  x = A[n];
  i = p - 1;
  for(j = p;j < n;j++){
    if(A[j].suzi <= x.suzi){
      i += 1;
      swapping(&A[i],&A[j],&hako);
    }
  }
  swapping(&A[i + 1],&A[n],&hako);
  
  return i + 1;
}

void swapping(tramp *A,tramp *AA,tramp *dust){
  *dust = *A;
  *A = *AA;
  *AA = *dust;
}






int judge(tramp *A,tramp *B,int n){
  int i,num = 1;
  for(i = 1;i < n + 1;i++){
    // printf("%c %d vs %c %d\n",A[i].mozi,A[i].suzi,B[i - 1].mozi,B[i - 1].suzi);
    if(
(A[i].mozi != B[i - 1].mozi) || (A[i].suzi != B[i - 1].suzi)) num = 0;
  }
  return num;
}











void merge(tramp *A,int left,int mid,int right){
  int i,j,k,n1,n2;
  tramp *L,*R;
  n1 = mid - left;
  n2 = right - mid;
  // L[0...n1], R[0...n2] を生成
  L = (tramp *)malloc((n1 + 1) * sizeof(tramp));
  R = (tramp *)malloc((n2 + 1)* sizeof(tramp));
  for(i = 0;i < n1;i++){
    L[i].suzi = A[left + i].suzi;
    L[i].mozi = A[left + i].mozi;
  }
  for(i = 0;i < n2;i++){
    R[i].suzi = A[mid + i].suzi;
    R[i].mozi = A[mid + i].mozi;
  }
  L[n1].suzi = INFTY;
  R[n2].suzi = INFTY;
  i = 0;
  j = 0;
  for(k = left;k < right;k++){
    if(L[i].suzi <= R[j].suzi){
      A[k].suzi = L[i].suzi;
      A[k].mozi = L[i].mozi;
      i = i + 1;
    }
    else{
      A[k].suzi = R[j].suzi;
      A[k].mozi = R[j].mozi;
      
      j = j + 1;
    }
  }
}

void mergeSort(tramp *A,int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}



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

int main(){
  int a,b,m,n;
  cin >> a >> b;
  if(b==100)n=a*1000+100;
  else if(b>=10)n=a*100+b;
  else n=a*10+b;
  m=sqrt(n);
  if(n==m*m)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}

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

int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> b(n, 100001);
  for(int i = 0; i < n - 1; i++) cin >> b.at(i);
  sum = b.at(0);
  for(int i = 0; i < n - 1; i++) {
    sum += min(b.at(i), b.at(i + 1));
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
int main() {
  int n, m;
  cin >> n >> m;
  ivec a(m);
  REP(i, m) cin >> a[i];
  int ans = n;
  REP(i, m) { ans -= a[i]; }
  ans = ans < 0 ? -1 : ans;
  print(ans);
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int64_t> lucas(N+1);

	lucas.at(0) = 2;
	lucas.at(1) = 1;

	for (int i = 2; i < N + 1; i++) {
		lucas.at(i) = lucas.at(i-1) + lucas.at(i-2);
	}

	cout << lucas.at(N) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(double& x, double y) {
	x = min(x, y);
}

void chmax(double& x, double y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll N;
ll A[100010];
multiset<ll> S;

void solve() {
	cin >> N;
	rep(i, N) {
		cin >> A[i];
		auto itr = S.lower_bound(A[i]);
		if (itr != S.begin()) {
			itr--;
			S.erase(itr);
		}
		S.insert(A[i]);
	}
	cout << S.size() << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


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

template <typename T>
T gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll all = b - a + 1;

  a--;
  ll div_c = b / c - a / c;
  ll div_d = b / d - a / d;
  ll cd = lcm(c, d);
  ll div_cd = b / cd - a / cd;

  ll ans = all - div_c - div_d + div_cd;
  cout << ans << endl;
}


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

int ans[31];

int main(){


  int N,M;

  cin>>N>>M;

  int k[31];
  
  int a[31][31];

  for(int i=0;i<N;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>a[i][j];
      ans[a[i][j]]++;
    }
  }

  int cnt=0;
  
  for(int i=1;i<=M;i++){
    if(ans[i]==N){
      cnt++;
    }
  }
	   
  cout<<cnt<<endl;
	
  
  return 0;
}


Measured memory_bytes: 256
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc.read::<String>();
    let t = sc.read::<String>();
    let a: usize = sc.read();
    let b: usize = sc.read();
    let u = sc.read::<String>();
    let result = if u == s { (a - 1, b) } else { (a, b - 1) };
    println!("{} {}", result.0, result.1);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

int main()
{
    int N, M, C, B, A, Sum = 0, count = 0;
    cin >> N >> M >> C;
    vector<vector<int>> a(N, vector<int>(M));
    vector<int> b;

    for (int i = 0; i < M; i++)
    {
        cin >> B;
        b.push_back(B);
    }

    for (int b = 0; b < N; b++)
    {

        for (int c = 0; c < M; c++)
        {
            cin >> A;
            a[b][c] = A;
        }
    }

    for (int d = 0; d < N; d++)
    {
        for (int e = 0; e < M; e++)
        {
            Sum = a[d][e] * b[e] + Sum;
        }

        if (Sum + C > 0)
        {
            count++;
            Sum = 0;
        }

        else
        {
            Sum = 0;
        }
    }

    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,cnta = 0,cntc = 0,ans = 0;
    cin >> n;
    vector<ll> a(n + 1),b(n),c(n + 1);
    rep0(i, n)cin >> a[i];
    a[n] = 1e9 + 1;
    sort(all(a));
    rep0(i, n)cin >> b[i];
    sort(all(b));
    rep0(i, n)cin >> c[i];
    c[n] = 1e9 + 1;
    sort(all(c));
    rep0(i, n){
        nfor(j, cnta, n + 1){
            if(a[j] >= b[i]){
                cnta = j;
                break;
            }
        }
        nfor(j, cntc, n + 1){
            if(c[j] > b[i]){
                cntc = j;
                break;
            }
        }
        if(cntc == n)break;
        ans += cnta * (n - cntc);
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 2688
n=int(input())
a=list(map(int, input().split())) 
count=0
a.sort()

if a.count(0)==n:
    print('Yes')
elif n%3==0:
    if a.count(0)==n//3 and a.count(a[n//3])==n//3*2:
        print('Yes')
    elif a.count(a[0])==n//3 and a.count(a[n//3])==n//3 and a.count(a[n//3*2])==n//3 and a[0]^a[n//3]^a[n//3*2]==0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 14708
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=1e5+5;
int n;
int main(){
	scanf("%d",&n);
	if(n%10==3)puts("bon");
	else if(n%10==0||n%10==1||n%10==6||n%10==8)puts("pon");
	else puts("hon");
	return 0;
}

Measured memory_bytes: 3688
#include <stdio.h>
#include <stdlib.h>

void insert(int _value);
void delete(int _value);
void deleteFirst(void);
void deleteLast(void);

struct Node{
  struct Node* next;
  struct Node* prev;
  int value;
};

struct Node * head;
struct Node * tail;
main(){

  int i;
  int n;
  int tmpValue;
  char str[20];
  struct Node* node;

  head = (struct Node*)malloc(sizeof(struct Node));
  tail = (struct Node*)malloc(sizeof(struct Node));
  head->next = tail;
  head->prev = NULL;
  tail->next=NULL;
  tail->prev=head;
  head->value = 0;
  tail->value=0;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s",str);
    if(!strcmp(str,"insert")){
      scanf("%d",&tmpValue);
      insert(tmpValue);
    }else if(!strcmp(str,"deleteFirst")){
      deleteFirst();
    }else if(!strcmp(str,"deleteLast")){
      deleteLast();
    }else if(!strcmp(str,"delete")){
      scanf("%d",&tmpValue);
      delete(tmpValue);
    }
  }

  for(node=head->next; node != tail; node=node->next){
    printf("%d",node->value);
    if(node->next!=tail){
      printf(" ");
    }
  }
  printf("\n");

  return 0;

}

void insert(int _value){

  struct Node* newNode;
  struct Node* tmpNode;

  newNode = (struct Node*)malloc(sizeof(struct Node));

  tmpNode = head->next;
  if(tmpNode != NULL){
    tmpNode->prev = newNode;
  }
  head->next = newNode;
  newNode->next = tmpNode;
  newNode->prev = head;

  newNode->value = _value;

}

void delete(int _value){

  struct Node* node;
  struct Node* tmpNode;
  for(node=head->next; node != NULL; node=node->next){
    if(node->value == _value){
      tmpNode = node->prev;
      if(tmpNode != NULL){
    tmpNode->next = node->next;
      }
      if(node->next != NULL){
    node->next->prev = tmpNode;
      }
      
      break;
    }
  }

}

void deleteFirst(){

  struct Node* node;
  node=head->next;

  if(head != NULL){
    head->next= node->next;
  }
  if(node->next != NULL){
    node->next->prev = head;
  }

}

void deleteLast(){

  struct Node* tmpNode;

  tmpNode=tail->prev;
  tail->prev=tmpNode->prev;
  tmpNode->prev->next=tail;


}



Measured memory_bytes: 36092
n = int(input())
a =  list(map(int, input().split()))

seen = {}

for ai in a:
    if ai in seen:
        seen[ai] += 1
    else:
        seen[ai] = 1

ans = True
cur = 0
if n%2 == 1:
    if not (0 in seen and seen[0] == 1):
        ans = False
    else:
        cur = 2
else:
    cur = 1

if ans:
    for i in range(cur, n, 2):
        if not (i in seen and seen[i] == 2):
            ans = False
            break

print((2**(n//2) % 1000000007) if ans else 0)

Measured memory_bytes: 20448
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int n;
ll ans;
vector<int> g[200000];

void dfs(int x, int p)
{
    for(int i = 0; i<g[x].size(); i++)
        if(g[x][i]!=p)
            dfs(g[x][i],x);
    if(x<p)
        ans+=ll(x+1)*ll(p-x);
    else if(x>p)
        ans+=ll(x-p)*ll(n-x);
    else
        ans+=ll(x+1)*ll(n-x);
}

int main()
{
    cin >> n;
    for(int i = 0, u, v; i<n-1; i++)
    {
        cin >> u >> v;
        g[u-1].push_back(v-1);
        g[v-1].push_back(u-1);
    }
    dfs(0,0);
    cout << ans << endl;
}


Measured memory_bytes: 23952