akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

case S
when 'Sunny'
  puts 'Cloudy'
when 'Cloudy'
  puts 'Rainy'
when 'Rainy'
  puts 'Sunny'
end


Measured memory_bytes: 14344
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        char[] arr = sc.next().toCharArray();
        StringBuilder sb = new StringBuilder();

        for (int i=0; i<arr.length; i++) {
            if (arr[i] != 'B') {
                sb.append(arr[i]);
            } else {
                if (sb.length() != 0) {
                    sb.setLength(sb.length() - 1);
                }
            }
        }

        System.out.println(sb.toString());
    }

}



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

const ll mod = 1e9+7;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

vector<mint> fac(300001); //n!(mod M)
vector<mint> ifac(300001); //k!^{M-2} (mod M)

mint mpow(ll x, ll n){//x^n(mod M)
    mint ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

mint comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    mint tmp = ifac[a-b]* ifac[b];
    return tmp * fac[a];
}

int main() {
    ll n, k;
    cin >> n >> k;
    mint ans = 0;
    for(ll i = k; i <= n+1; i++){
        ans += i*(n - i + 1) + 1;
    }
    cout << ans << endl;


}

Measured memory_bytes: 7868
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    string s;
    int n;

    cin >> s;
    cin >> n;

    for(int i = 0; i < s.size(); i++){
        if(i % n == 0){
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

#define Max 100001

typedef struct {
  int par, chi, bro;
} Node;

Node T[Max];
int D[Max], n;

void get_depth(int u, int p) {
  D[u] = p;
  if (T[u].bro != -1) get_depth(T[u].bro, p);
  if (T[u].chi != -1) get_depth(T[u].chi, p + 1);
}

void print(int u) {
  int i, c;
  for (i = 0; i < n; i++) {
    int count = 0;
    printf("node %d: ", i);
    printf("parent = %d, ", T[i].par);
    printf("depth = %d, ", D[i]);

    if (T[i].par == -1) {
      printf("root, ");
    } else if (T[i].chi == -1) {
      printf("leaf, ");
    } else {
      printf("internal node, ");
    }

    printf("[");
    c = T[i].chi;

    while (c != - 1) {
      if (count > 0) printf(", ");
      printf("%d", c);
      c = T[c].bro;
      count++;
    }
    printf("]\n");
  }
}

int main(int argc, char const *argv[]) {
  int i, j, m, child, parent, brother, current, root;
  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    T[i].par = -1;
    T[i].chi = -1;
    T[i].bro = -1;
  }

  for (i = 0; i < n; i++) {
    scanf("%d %d", &parent, &m);
    for (j = 0; j < m; j++) {
      scanf("%d", &current);
      if (j == 0) T[parent].chi = current;
      else T[child].bro = current;
      child = current;
      T[current].par = parent;
    }
  }

  for (i = 0; i < n; i++) {
    if (T[i].par == -1)  root = i;
  }

  get_depth(root, 0);

  print(i);

  return 0;
}



Measured memory_bytes: 6384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s1[66],s2[66];
char cc[555];
int main(){
        int a,b,c;
        while(scanf("%s%s",s1,s2) != EOF){
                int len = 0;
                int len1 = strlen(s1);
                int len2 = strlen(s2);
                int i1 = 0;
                int i2 = 0;
                for(int i = 0;i < len1+len2;++i){
                        if(i%2 == 0 && i1 < len1) cc[i] = s1[i1++];
                        else if(i2 < len2 ) cc[i] = s2[i2++];
                }
                cc[len1+len2] = '\0';
                printf("%s\n",cc);
        }
        return 0;
}


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

int main(){
  vector<int>a{0,1,3,1,2,1,2,1,1,2,1,2,1};
  int i,j;
  cin>>i>>j;
  if(a[i]==a[j]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

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

using namespace std;

int main()
{
  string s;
  int num=0;
  cin>>s;
  for(int i=0;i<4;i++){
    if(s[i]== '+') num++;
    if(s[i] == '-') num--;
  }
  cout<<num<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
const int maxn=185+5;
int n,m;
char s[maxn][maxn];
int dp[maxn][maxn][maxn];

int main() {
	scanf("%d%d", &n, &m);
	for (int i=1;i<=n;++i)
		scanf("%s",s[i]+1);
	for (int i=1;i<=n;++i)
		for (int j=m;j>=1;--j){
			dp[i][j][j]=s[i][j]==s[i-1][j]?dp[i-1][j][j]+1:1;
			for (int k=j+1;k<=m;++k) 
			dp[i][j][k]=s[i][k]==s[i][k-1]?min(dp[i][j][k-1],dp[i][j+1][k]):0;
		}
	if (dp[n][1][m]==n) return puts("0"),0;
	for (int depth=1;;++depth){
		for (int i=n;i>=1;--i){
			for (int j=1;j<=m;++j){
				vector<int>tmp(m+1);
				for (int k=j+1,p=j;k<=m;++k){
					while(p+2<k&&dp[i][j][p]>dp[i][p+1][k]&&dp[i][j][p+1]>dp[i][p+2][k]) ++p;
					tmp[k]=max(tmp[k],min(dp[i][j][p],dp[i][p+1][k]));
					if (p+2<=k) tmp[k]=max(tmp[k],min(dp[i][j][p+1],dp[i][p+2][k]));
				}
				for (int k=j;k<=m;++k)
					dp[i][j][k]=max(dp[i-dp[i][j][k]][j][k]+dp[i][j][k],tmp[k]);
			}
		}
		if (dp[n][1][m]==n){printf("%d\n",depth);break;}
	}
}

Measured memory_bytes: 26752
import java.util.ArrayList;
import java.util.Scanner;

class D {
    static class E {
        final int to;
        final int d;

        public E(int to, int d) {
            this.to = to;
            this.d = d;
        }
    }

    static class V extends ArrayList<E> {
    }

    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int M = sc.nextInt();
        final int[] L = new int[M];
        final int[] R = new int[M];
        final int[] D = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt() - 1;
            R[i] = sc.nextInt() - 1;
            D[i] = sc.nextInt();
        }
        final V[] vs = new V[N];
        for (int i = 0; i < N; i++)
            vs[i] = new V();
        for (int i = 0; i < M; i++) {
            vs[L[i]].add(new E(R[i], D[i]));
            vs[R[i]].add(new E(L[i], -D[i]));
        }
        final boolean[] visited = new boolean[N];
        final int[] ds = new int[N];
        boolean success = true;
        for (int i = 0; i < N && success; i++)
            if (!visited[i]) {
                visited[i] = true;
                success &= check(i, vs, visited, ds);
            }
        System.out.println(success ? "Yes" : "No");
    }

    static boolean check(int idx, V[] vs, boolean[] visited, int[] ds) {
        for (final E e : vs[idx])
            if (visited[e.to]) {
                if (ds[idx] + e.d != ds[e.to])
                    return false;
            } else {
                visited[e.to] = true;
                ds[e.to] = ds[idx] + e.d;
                if (!check(e.to, vs, visited, ds))
                    return false;
            }
        return true;
    }
}
public class Main {
    public static void main(String... args) {
        D.main(args);
    }
}

Measured memory_bytes: 167348
#include <stdio.h>

int main(void) 
{
	int counter=0;
	char a[10];
	scanf("%s",a);
	if (a[0]=='1') counter++;
	if (a[1]=='1') counter++;
	if (a[2]=='1') counter++;
	printf ("%d",counter);

	return 0;
	
	
}

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

#define ll long long
#define ii pair<int, int>
#define dd pair<double, double>
#define pb(i) push_back(i)
const double PI = 3.14159265359;
const int inf = 1e9+77;
const ll mod = 1e9+7;
const double eps = 1e-7;
//int dir1[8] = {0, 0, 1, -1, 1, -1, 1, -1};
//int dir2[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dir1[4] = {0, 0, 1, -1};
int dir2[4] = {1, -1, 0, 0};

ll inv_mod(ll a);

#define si pair<string, int>
#define is pair<int, string>

bool by(is a, is b)
{
	if(a.first < b.first)
		return false;
	else if(a.first > b.first)
		return true;
	else
	{
		if(a.second.compare(b.second) < 0)
			return true;
		else
			return false;
	}
}

int main()
{
	int i, j;

	vector<pair<int, string> > v;
	map<string, int> p;
	int n;
	string s;
	cin >> n;

	while(n--)
	{
		cin >> s;
		if(p.find(s) == p.end())
		{
			p.insert(si(s, (int)p.size()));
			v.pb(is(1, s));
		}
		else
		{
			int ind = p.find(s)->second;
			v[ind].first++;
		}
	}

	sort(v.begin(), v.end(), by);

	cout << v[0].second << '\n';
	for(i = 1; i < v.size(); i++)
	{
		if(v[i].first == v[i-1].first)
			cout << v[i].second << '\n';
		else
			break;
	}
}


ll inv_mod(ll a)
{
	ll b = mod-2, ans = 1;
	while(b)
	{
		if(b&1)
			ans = (ans*a)%mod;
		a = (a*a)%mod;
		b >>= 1;
	}
	return ans;
}

Measured memory_bytes: 26616
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    string a, b;
    cin >> a >> b;
    cout << b + a;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>

inline int read(void){
	int res = 0;
	char ch = std::getchar();
	while(ch < '0' || ch > '9')
		ch = std::getchar();
	while(ch >= '0' && ch <= '9')
		res = res * 10 + ch - 48, ch = std::getchar();
	return res;
}

typedef long long ll;

const int MAXN = 2e5 + 19;

namespace camel{
	struct Node{
		int val, k;
		
		bool operator<(const Node &b)const{
			return k < b.k;
		} 
	}A[MAXN], B[MAXN];
	
	int n, anum, bnum;
	ll ans;
	
	std::priority_queue<int, std::vector<int>, std::greater<int> > q;
	
	int main(){
		n = read(), ans = 0ll, anum = 0, bnum = 0;
		for(int i = 1; i <= n; ++i){
			int k = read(), l = read(), r = read();
			if(l > r)
				ans += r, A[++anum] = (Node){l - r, k};
			else
				ans += l, B[++bnum] = (Node){r - l, n - k};
		}
		std::sort(A + 1, A + 1 + anum);
		std::sort(B + 1, B + 1 + bnum);
		for(int i = 1; i <= anum; ++i){
			if(A[i].k == 0)
				continue;
			if(q.size() < A[i].k)
				q.push(A[i].val);
			else if(q.size() == A[i].k){
				if(A[i].val > q.top())
					q.pop(), q.push(A[i].val);
			}
		}
		while(!q.empty())
			ans += q.top(), q.pop();
		for(int i = 1; i <= bnum; ++i){
			if(B[i].k == 0)
				continue;
			if(q.size() < B[i].k)
				q.push(B[i].val);
			else if(q.size() == B[i].k){
				if(B[i].val > q.top())
					q.pop(), q.push(B[i].val);
			}
		}
		while(!q.empty())
			ans += q.top(), q.pop();
		std::printf("%lld\n", ans);
		return 0;
	}
}

int main(){
	for(int T = read(), i = 1; i <= T; ++i)
		camel::main();
	return 0;
}


Measured memory_bytes: 4748
#include<stdio.h>
int main(){
  int N,i,temp,j,z;
  int A[100];
  scanf("%d",&N);
  for(i=1;i<=N;i++){
    scanf("%d",&A[i]);
  }
  for (i=1;i<=N;i++){
    temp = A[i];
    j = i-1;
    while (j >= 0 && A[j] > temp){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = temp; 
    for(z=1;z<=N;z++){
      printf("%d",A[z]);
      if(z == N)printf("\n");
      else printf(" ");
    }
  }
  return 0;
}

Measured memory_bytes: 604
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(a) begin(a), end(a)
#define deb(x) cout << #x << " = " << x << endl
#define debu(x, y) cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl
#define int long long

typedef long long ll;
ll mod=1000000007;

template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0; i<n; i++) {
            cin >> a[i];
        }
        vector<int> mark(n);
        mark[n-1] = a[n-1];
        for(int i=n-2; i>=0; i--) {
            mark[i] = (mark[i+1] + a[i])%mod;
        }
        int ans = 0;
        for(int i=0; i<n-1; i++) {
            ans = (ans + (a[i]*mark[i+1])%mod)%mod;
        }
        cout << ans%mod;
    }
    return 0;
}


Measured memory_bytes: 6308
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

struct restaurant{
	string s;
	int p;
	int id;
	int num;
};
int n;
restaurant res[101];

bool cmp(restaurant x,restaurant y){
	if (x.s==y.s) return x.p>y.p;
	else return x.s<y.s;
}

int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>res[i].s>>res[i].p;
		res[i].num=i;
	}
	sort(res+1,res+n+1,cmp);
	for (int i=1;i<=n;i++){
		cout<<res[i].num<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, m, l = [int(x) for x in input().split(' ')]

A = [0] * n
for i in range(n):
    A[i] = [int(x) for x in input().split(' ')]
B = [0] * m
for i in range(m):
    B[i] = [int(x) for x in input().split(' ')]

def tranpose(matrix):
    r, c = len(matrix), len(matrix[0])
    return [[row[i] for row in matrix] for i in range(c)]

B = tranpose(B)
C = [[0 for _ in range(l)] for _ in range(n)]

for i in range(n):
    for j in range(l):
        C[i][j] =  sum(a * b for a, b in zip(A[i], B[j]))

for row in C:
    print(*row, sep=' ')

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

int main() {
    int k; cin >> k;
    vector<ll> a(k); for (int i = 0; i < k; i++) cin >> a[i];
    ll min = 2, max = 2;
    for (int i = k-1; i >= 0; i--) {
        ll n = (min + a[i] - 1) / a[i] * a[i];
        ll nn = max / a[i] * a[i] + a[i] - 1;
        if (n > max || nn < min) {
            cout << -1 << endl;
            return 0;
        }
        min = n;
        max = nn;
    }
    cout << min << " " << max << endl;
    return 0;
}

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

int main()
{
    string S;
    int N=25;
    
    S = "abcdefghijklmnopqrstuvwxyz";
    
    char s;
    cin >> s;
    
    for(int i=0; i<N; i++){
        if(S[i] == s){
            cout << S[i+1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
S = input()
n = len(S)


def is_palindrome(string):
    return True if string == string[::-1] else False


if is_palindrome(S) and is_palindrome(S[:(n - 1) // 2]) and is_palindrome(S[(n + 3) // 2 - 1:]):
    print('Yes')
else:
    print('No')

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

v.sort()

while True :
    x = v.pop(0)
    y = v.pop(0)
    z = (x + y) / 2
    v.insert(0, z)

    if len(v) == 1:
        print(z)
        exit()


Measured memory_bytes: 2940
from sys import stdin
import numpy as np


def main():
    n, m = list(map(int, stdin.readline().split()))
    hList = list(map(int, stdin.readline().split()))
    ABList = [list(map(int, stdin.readline().split())) for _ in range(m)]
    maxHeights = np.zeros(n)
    for a, b in ABList:
        if hList[a-1] >= maxHeights[b-1]:
            maxHeights[b-1] = hList[a-1]
        if hList[b-1] >= maxHeights[a-1]:
            maxHeights[a-1] = hList[b-1]
    total = 0
    i = 0
    for maxHeight in maxHeights:
        if maxHeight < hList[i]:
            total += 1
        i += 1
    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49692
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int a,b,c,d;
  int ans;
  cin>>a>>b>>c>>d;
  if(a<c) ans=min(b-c,d-c);
  else if(a>c) ans=min(d-a,b-a);
  else ans=min(b,d);
  if(ans<0) ans=0;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = input()
    count = 0

    S = len(N)
    flag = 0
    for i in range(S):
        temp = flag + int(N[-1 - i])
        if temp > 5:
            count += 10 - temp
            flag = 1
        elif temp ==5  and i !=S-1 and int(N[-1-i-1])>=5:
            count+=temp
            flag=1

        else:
            count += temp
            flag = 0

    print(count + flag)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11256
#include<stdio.h>

int main(void)
{
	int n, i, a[128];
	scanf("%d", &n);

	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);

	}

	for (i = n; i > 1; i--)
	{
		printf("%d ", a[i]);

	}

	printf("%d\n", a[1]);

	return 0;

}


Measured memory_bytes: 2056
import java.util.*;
import java.math.*;
class Main{
	static final int M=100000007;
	public static int comb(int n,int c){
		BigInteger b=BigInteger.ONE;
		for(int i=0;i<c;i++){
			b=b.multiply(new BigInteger(String.valueOf(n-i))).divide(new BigInteger(String.valueOf(i+1)));
		}
		return b.mod(new BigInteger(String.valueOf(M))).intValue();
	}
	public static void main(String[]Z){
		Scanner cin=new Scanner(System.in);
		int r=cin.nextInt(),c=cin.nextInt(),a1=cin.nextInt(),a2=cin.nextInt(),b1=cin.nextInt(),b2=cin.nextInt();
		int x=Math.abs(a1-b1),y=Math.abs(a2-b2);
		x=Math.min(x,r-x);y=Math.min(y,c-y);
		int z=1;
		if(x==r-x)z*=2;
		if(y==c-y)z*=2;
		System.out.println(z*comb(x+y,Math.min(x,y))%M);
	}
}

Measured memory_bytes: 12000
a,b,c,d = map(int,input().split())

import math
LCM=c * d //math.gcd(c, d)

tmp1=b//c + b//d - b//LCM #1~bまで調べたとき、割り切れる数の個数
tmp2=(a-1)//c + (a-1)//d - (a-1)//LCM #1~a-1まで調べたとき、割り切れる数の個数
tmp=tmp1-tmp2 #a~bまで調べたとき、割り切れる数の個数
ans=(b-a+1)-tmp

print(ans)

Measured memory_bytes: 62128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long

int main(void)
{
    int n;
    int count = 0;
    long double dist, d;
    ll x, y;
    scanf("%d %Lf", &n, &d);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld %lld", &x, &y);
        dist = sqrt((x * x) + (y * y));
        if (dist <= d)
        {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

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

#define LL long long

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

	int n;
	cin>>n;

	if(n>=1000){cout<<"ABD"<<endl;}
	else{cout<<"ABC"<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
void A()
{
    int n;
    cin>>n;
    vector<int> a(n,0);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> dp(n+1,inf);
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
        if(i>=2) dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;

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


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

const int MAXN = 2005;

int N,K;
vector<int> adj[MAXN];
int dep[MAXN], cnt; //dep[i]记录以i为根的树的深度(根节点深度为0) 

void dfs(int u, int fa, int lim)
{
    for(int i = 0; i < adj[u].size(); i++)
    {
        int v = adj[u][i];
        if(v != fa)
        {
            dep[v] = dep[u] + 1; //深度+1 
            if(dep[v] > lim) cnt++;
            dfs(v,u,lim);
        }
    }
}

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 1; i < N; i++) //N个节点的树有N-1条边 
    {
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int ans = 0x3f3f3f3f;
    
    //枚举每一个点 
    if(K % 2 == 0)
    {
        for(int i = 1; i <= N; i++)
        {
            cnt = 0;
            dep[i] = 0; dfs(i,0,K/2); //fa[父节点] = 0 
            ans = min(ans,cnt);
        }
    }
    else
    {
    	//枚举每一条边，将树分为两棵 
        for(int i = 1; i <= N; i++)
            for(int j = 0; j < adj[i].size(); j++)
            {
                cnt = 0;
                dep[i] = 0; dfs(i,adj[i][j],(K-1)/2);
                dep[adj[i][j]] = 0; dfs(adj[i][j],i,(K-1)/2);
                ans = min(ans,cnt);
            }
    }

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

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

pair<int, int> AB[100000];

int main()
{
	int N, M, A, B;
	ll amount = 0;

	cin >> N >> M;
	rep(i, N) {
		cin >> A >> B;
		AB[i] = make_pair(A, B);
	}

	sort(AB, AB + N);

	rep(i, N) {
		if (AB[i].second <= M) {
			amount += (ll)AB[i].first * (ll)AB[i].second;
			M -= AB[i].second;
		}
		else {
			amount += (ll)AB[i].first * M;
			M = 0;
		}

		if (M == 0) break;
	}

	cout << amount << endl;

	return 0;
}


Measured memory_bytes: 1024
import sys

for line in sys.stdin:
    h, w = map(int, line.strip().split())
    if h == 0 and w == 0:
        break

    print('#' * w)
    for _ in range(1, h - 1):
        print('#' + '.' * (w - 2) + '#')
    print('#' * w)

    print()



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

int modVal = 998244353;

int myPow(int a, int b) {
  int r = 1;
  while (b--) {
    r = (r * a) % modVal;
  }
  return r;
}

int32_t main() {
  int n;
  cin >> n;
  int maxDist = 0;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    maxDist = max(maxDist, d[i]);
    if ((i == 0 && d[i] != 0) || (i != 0 && d[i] == 0)) {
      cout << 0;
      return 0;
    }
  }

  vector<int> nums(maxDist+1, 0);
  for (int i = 0; i < d.size(); i++) {
    nums[d[i]]++;
  }

  int res = 1;
  for (int i = 0; i < nums.size()-1; i++) {
    res = (res * myPow(nums[i], nums[i+1])) % modVal;
  }
  cout << res;
}

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

int HelloWorld(){
	cout << "Hello World" << endl;
	return 0;
}

int XCubic(){
	int x;
	cin >> x;
	if (1 <= x && x <= 100){
		x = x*x*x;
		cout << x << endl;
		return 0;
	}
	return 1;
}

int Rectangle(){
	int a, b, area, perimeter;

	cin >> a >>b;
	if (1 <= a && b <= 100){
		area = a*b;
		perimeter = (a + b) * 2;
		cout << area << " " << perimeter << endl;
		return 0;
	}
	return 1;
}

int Watch(){
	int S;
	cin >> S;
	
	
	int D = 60;
	int s = S%D;
	int m = (S / D) % D;
	int h = (S / D) / D;
	if (0 <= S && S <= 86400){
		printf("%u:%u:%u\n", h, m, s);
		return 0;
	}
	
	return 1;
}

int SmallLargeOrEqual(){
	int a, b;
	cin >> a >> b;
	if (!(a <= a && b <= 1000)) return 1;
	if (a < b)		cout << "a < b" << endl;
	else if (a > b) cout << "a > b" << endl;
	else			cout << "a == b" << endl;
	return 0;
}

int Range(){
	int a, b,c;
	bool flag = true;

	cin >> a >> b >> c;
	if (!(0 <= a && a <= 100)) return 1;
	if (!(0 <= b && b <= 100)) return 1;
	if (!(0 <= c && c <= 100)) return 1;

	if (!(a < b)) flag=false;
	if (!(b < c)) flag = false;

	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

int SortingThreeNumbers(){
	int a, b, c,temp;
	cin >> a >> b >> c;

	if (!(1 <= a && a <= 10000)) return 1;
	if (!(1 <= b && b <= 10000)) return 1;
	if (!(1 <= c && c <= 10000)) return 1;

	if (a > b){
		temp = a;
		a = b;
		b = temp;
	}
	if (b > c){
		temp = b;
		b = c;
		c = temp;
	}
	if (a > b){
		temp = a;
		a = b;
		b = temp;
	}

	printf("%u %u %u\n", a, b, c);
	
	
	return 0;
}


int main(){
	//HelloWorld();
	//XCubic();
	//Rectangle();
	//Watch();
	//SmallLargeOrEqual();
	//Range();
	SortingThreeNumbers();

	return 0;
}

Measured memory_bytes: 3120
from functools import reduce
p = 1000000007  #ここを変える
ccache = []
inv_ccache = []
N = 1000000
def powmod(a, n):
    global p
    res = 1
    tmp=a
    while n>0:
        if n & 1 == 1:
            res = (res * tmp) % p
        n=n//2
        tmp = tmp * tmp % p
    return res
def invmod(n):
    return powmod(n, p - 2)
def cmod(n, r):
    global p
    global ccache
    global inv_ccache
    global N
    if len(ccache) == 0:
      ccache.append(1)
      inv_ccache.append(1)
      for i in range(N):
        ccache.append(ccache[i]*(i+1)%p)
        inv_ccache.append(1)
      inv_ccache[N]=invmod(ccache[N])
      for i in range(N-1):
        inv_ccache[N-1-i]=inv_ccache[N-i]*(N-i)%p
    if r > n or r < 0:
        return 0
    if r > n // 2:
        return cmod(n, n - r)
    return ccache[n]*inv_ccache[r]%p*inv_ccache[n-r]%p
 
n = int(input())
adj_of = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    adj_of[a - 1].append(b - 1)
    adj_of[b - 1].append(a - 1)
stack = [(0, -1)] # root, excludee
course = []
while len(stack) > 0:
    popped = stack.pop()
    course.append(popped)
    for adj in adj_of[popped[0]]:
        if adj != popped[1]:
            stack.append((adj, popped[0]))
sizes = [{} for _ in range(n)] #size, pattern_num
pattern_nums = [{} for _ in range(n)]
for step in reversed(course):
    size = 1
    pattern_num = 1
    for adj in adj_of[step[0]]:
        if adj != step[1]:
            size += sizes[adj][step[0]]
            pattern_num *= pattern_nums[adj][step[0]] * cmod(size - 1, sizes[adj][step[0]]) % p
            pattern_num %= p
    sizes[step[0]][step[1]] = size
    pattern_nums[step[0]][step[1]] = pattern_num
 
#print(course)
#print(sizes)
#print(pattern_nums)
 
ans = [None] * n
for step in course:
    if step[0] == 0:
        ans[0] = pattern_nums[0][-1]
        continue
    #ans[step[0]] = pattern_nums[step[0]][step[1]] * pattern_nums[step[1]][step[0]]\
    #             * cmod(sizes[step[0]][step[1]] + sizes[step[1]][step[0]], sizes[step[0]][step[1]]) % p
    pattern_nums_step1_step0 = ans[step[1]] * invmod(cmod(n - 1, sizes[step[0]][step[1]]) % p * pattern_nums[step[0]][step[1]]) % p
    ans[step[0]] = pattern_nums[step[0]][step[1]] * pattern_nums_step1_step0 % p\
                 * cmod(n - 1, sizes[step[0]][step[1]] - 1) % p
 
for a in ans:
    print(a)


Measured memory_bytes: 280268
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	
	vi c(n);
	for(int i = 0; i < n; i++) cin >> c[i];
	
	vi prev(n);
	map<int, int> u;
	for(int i = 0; i < n; i++) {
		if(!u.count(c[i])) prev[i] = -1;
		else prev[i] = u[c[i]];
		u[c[i]] = i;
	}
	
	vi dp(n, 0);
	dp[0] = 1;
	for(int i = 1; i < n; i++) {
		(dp[i] = dp[i - 1] + (prev[i] == -1 || prev[i] == i - 1 ? 0 : dp[prev[i]])) %= P;
	}
	
	cout << dp[n - 1] << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 15028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int K, T;
    cin >> K >> T;
    int a[K];
    for(int i = 0; i < T; i++) cin >> a[i];
    int maxnum = a[0];
    for(int i = 0; i < T; i++) maxnum = max(a[i], maxnum);
    if(maxnum > K - maxnum)
        cout << 2 * maxnum - K - 1;
    else
        cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int i, n, a[100];
	//数列の長さを入力
	scanf("%d", &n);
	//数列を入力
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	//数列を逆順に表示
	for(i = n - 1; i >= 0; i--){
		if(i == 0){
			printf("%d\n", a[i]);
		}else{
			printf("%d ", a[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 596
n = int(input())
a,b = map(int,input().split())
P = list(map(int,input().split()))
s = []
m = []
l = []
for p in P:
    if p <= a:
        s.append(p)
    elif p <= b:
        m.append(p)
    else:
        l.append(p)
print(min(len(s),len(m),len(l)))

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

int main(void){
    int S,h,m,s;
    cin >> S;
    h = S/3600;
    m = (S-h*3600)/60;
    s = S-h*3600-m*60;
    cout << h;
    cout << ":";
    cout << m;
    cout << ":";
    cout << s;
    cout << endl;
}



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

using namespace std;

using ll = long long;

const int MAX_N = 100;
const int MAX_W = 10000;

ll N, W;
ll v[MAX_N], w[MAX_N], m[MAX_N];

ll dp[MAX_W+1];

int main() {
  cin >> N >> W;
  for(ll i = 0; i < N; ++i) cin >> v[i] >> w[i] >> m[i];

  fill(dp, dp+MAX_W+1, -1);
  dp[0] = 0;
  for(ll i = 0; i < N; ++i) {
    ll lim = m[i];
    for(ll k = 0; lim > 0; ++k) {
      ll use = min(lim, 1LL<<k);
      for(ll j = W-use*w[i]; j >= 0; --j) {
	if(dp[j] == -1) continue;
	dp[j+use*w[i]] = max(dp[j+use*w[i]], dp[j]+use*v[i]);
      }
      lim -= use;
    }
  }
  ll ans = 0;
  for(ll i = 0; i <= W; ++i) ans = max(ans, dp[i]);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3200
def main():
	n = int(input())
	dictionary = set()

	for _ in range(n):
		order, code = input().split()
		if order == 'insert':
			dictionary.add(code)
		elif order == 'find':
			if code in dictionary:
				print('yes')
			else:
				print('no')
		else:
			raise Exception('InputError')

if __name__ == '__main__':
	main()

Measured memory_bytes: 33148
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    map<ll, ll> cnt;
    map<int, int> leftID;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
        cnt[a[i]]++;
        if(leftID.count(a[i]) == 0) {
            leftID[a[i]] = i;
        }
    }
    cnt[0]++;

    vi b;
    each(p, cnt) {
        b.push_back((int)p.first);
    }
    reverse(all(b));
    int ma = b[0];
    int cur = -1;
    rep(i, n) {
        if(ma == a[i]) {
            cur = a[i];
            break;
        }
    }

    vll ans(n);

    rep(i, sz(b) - 1) {
        int val = b[i], nextVal = b[i + 1];
        smin(cur, leftID[val]);
        ans[cur] += cnt[val] * (val-nextVal);
        cnt[nextVal] += cnt[val];
    }

    rep(i, n)cout << ans[i] << endl;
}


Measured memory_bytes: 13692
#include<bits/stdc++.h>
using namespace std;
int n,x,y,a[200010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>x)
			x=a[i];
		else if(a[i]>y)
			y=a[i];
	}
	for(int i=1;i<=n;i++)
		if(a[i]==x)
			printf("%d\n",y);
		else
			printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 2432
import java.util.*;

public class Main {

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

        int judgePoint = 0;
        int basePoint = 0;
        if (a > b) {
            basePoint = b;
            judgePoint = a;
        } else {
            basePoint = a;
            judgePoint = b;
        }

        int plusW = basePoint + width;

        int ans;
        if (plusW >= judgePoint ) {
            ans = 0;
        } else {
            ans = judgePoint - plusW;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <cmath>

using namespace std;



int   main(){
    int  N, W;
    cin >> N >> W;
    long long int dp[N][2];
    for (long long int i = 0; i < N; i++) cin >> dp[i][0] >> dp[i][1];
    long long int res[N+1][W+1];
    for (long long int i = 0; i <= W; i++)res[0][i] = 0;
    for (long long int i = 0; i <= N; i++) res[i][0] = 0;

    for (long long int i = 1; i <= N; i++){
        for (long long int j = 1; j <= W; j++){
            if (j >= dp[i-1][0]){
                res[i][j] = max(res[i-1][j], res[i-1][j-dp[i-1][0]] + dp[i-1][1]);
            }else{
                res[i][j] = res[i-1][j];
            }
        }
    }
    cout << res[N][W] << endl;
}

Measured memory_bytes: 79104
x, y ,z, k = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)

now = [0, 0, 0]
que = [[A[0] + B[0] + C[0], 0, 0, 0]]
memory = [[A[0] + B[0] + C[0], 0, 0, 0]]
ans = []
while len(ans) < k:
  maxli = max(que, key = lambda x:x[0])
  ans.append(maxli[0])
  now = maxli[1:]
  que.remove(maxli)
  a = A[min(now[0] + 1, x - 1)]
  b = B[min(now[1] + 1, y - 1)]
  c = C[min(now[2] + 1, z - 1)]
  if [a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]] not in memory:
    que.append([a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]])
    memory.append([a + B[now[1]] + C[now[2]], min(now[0] + 1, x - 1), now[1], now[2]])
  if [A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]] not in memory:
    que.append([A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]])
    memory.append([A[now[0]] + b + C[now[2]], now[0], min(now[1] + 1, y - 1), now[2]])
  if [A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)] not in memory:
    que.append([A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)])
    memory.append([A[now[0]] + B[now[1]] + c, now[0], now[1], min(now[2] + 1, z - 1)])

print(*ans, sep = "\n")

Measured memory_bytes: 5352
MAX = 510000;
MOD = 1000000007;

finv = [0] * MAX
inv = [0] * MAX

def init():
    finv[0] = finv[1] = 1;
    inv[1] = 1
    for i in xrange(2, MAX):
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;


def com(n, k):
    ans = 1
    for i in xrange(n, n - k, -1):
        ans = (ans * i) % MOD
    return ans * finv[k] % MOD


def main():
    n, a, b = map(int, raw_input().split())
    init()
    print (pow(2, n, MOD) - 1 - com(n, a) - com(n , b)) % MOD

main()


Measured memory_bytes: 37740
n = list(map(int, input().split()))
s_1 = abs(n[1]-n[0])+abs(n[2]-n[1])
s_2 = abs(n[2]-n[0])+abs(n[2]-n[1])
s_3 = abs(n[0]-n[1])+abs(n[2]-n[0])
#s_4 = abs(n[2]-n[1])+abs(n[2]-n[0])
#s_5 = abs(n[0]-n[2])+abs(n[0]-n[1])
#s_6 = abs(n[1]-n[2])+abs(n[0]-n[1])
print(min(s_1, s_2, s_3))

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

template<int MOD>
struct mod_int {
	static const int mod = MOD;
	unsigned x;
	mod_int() : x(0) { }
	mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }

	mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
	mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
	mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
	mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }

	mod_int inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		return mod_int(u);
	}
};

template<int MOD>
istream& operator >> (istream& is, mod_int<MOD>& val) {
	long long x;
	is >> x; val = x;
	return is;
}

template<int MOD>
ostream& operator << (ostream& os, const mod_int<MOD>& val) {
	os << val.get();
	return os;
}

using mint = mod_int<1000000007>;

const int MAX = 2e6;

bool inited = false;
mint fac[MAX + 1];
mint rfac[MAX + 1];

void init() {
	inited = true;
	fac[0] = 1;
	for (int i = 1; i <= MAX; i++) {
		fac[i] = fac[i - 1] * i;
	}
	rfac[MAX] = fac[MAX].inverse();
	for (int i = MAX; i >= 1; i--) {
		rfac[i - 1] = rfac[i] * i;
	}
}

mint nPr(int n, int r) {
	if (!inited) init();
	return r < 0 || n < r ? 0 : fac[n] * rfac[n - r];
}

mint nCr(int n, int r) {
	if (!inited) init();
	return r < 0 || n < r ? 0 : fac[n] * rfac[n - r] * rfac[r];
}

mint nHr(int n, int r) {
	if (!inited) init();
	return r == 0 ? 1 : nCr(n + r - 1, r);
}

int main()
{
	int X, Y;
	cin >> X >> Y;
	if ((X + Y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	int cnt = (X + Y) / 3;
	if (X < cnt || cnt * 2 < X) {
		cout << 0 << endl;
		return 0;
	}
	cout << nCr(cnt, X - cnt) << endl;
	return 0;
}


Measured memory_bytes: 15872
R, G, B, N = map(int, input().split())

ans = 0
n_iter_r = N//R + 1
n_iter_g = N//G + 1

for r in range(n_iter_r):
    for g in range(n_iter_g):
        nokori = N - R*r - G*g
        if nokori < 0:
            break
        else:
            if nokori%B==0:
                ans += 1

print(ans)

Measured memory_bytes: 2940
n, k = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
l = 0
(k).upto(n-1) do |i|
  if a[l] < a[i]
    puts "Yes"
  else
    puts "No"
  end
  l += 1
end

Measured memory_bytes: 33728
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n),p(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<n;i++) cin>>p[i];
  vector<Int> dp(1<<n,0);
  for(Int b=1;b<(1<<n);b++){
    Int t=1;
    for(Int i=0;i<n;i++){
      if((b>>i)&1){
	Int k=a[i]/__gcd(t,a[i]);
	t=(t<=m/k?t*k:m+1);
      }
      if(t>m) break;
    }
    dp[b]=m/t;
  }
      
  for(Int i=0;i<n;i++)
    for(Int b=0;b<(1<<n);b++)
      if((b>>i)&1) dp[b]-=dp[b^(1<<i)];
  
  double ans=0;
  for(Int b=0;b<(1<<n);b++){
    double po=1;
    for(Int i=0;i<n;i++)
      if((b>>i)&1) po*=p[i]/100.0;
      else po*=1.0-(p[i]/100.0);
    ans+=po*abs(dp[b]);
  }
  cout<<fixed<<setprecision(12)<<ans<<endl;
  return 0;
}



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

const int N = (1 << 18) + 5;

int n, m, a[N], l[N], r[N];
int res[N], res2[N];
vector<int> G[N], rG[N];

void add(int u, int v) {
	// cout << "add " << u << ' ' << v << '\n';
	G[u].push_back(v), rG[v].push_back(u);
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n; m = 1 << n;
	for (int i = 1; i <= m; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; j += (1 << i)) {
			for (int k = j; k <= j + (1 << (i - 1)) - 1; ++k) {
				add(k, k + (1 << (i - 1)));
			}
		}
	}
	for (int i = 1; i <= m; ++i) {
		if (a[i]) l[i] = r[i] = a[i];
		else l[i] = 1, r[i] = m;
	}
	for (int i = 1; i <= m; ++i) {
		for (auto j : G[i]) l[j] = max(l[j], l[i] + 1);
	}
	for (int i = m; i >= 1; --i) {
		for (auto j : rG[i]) r[j] = min(r[j], r[i] - 1);
	}
	for (int i = 1; i <= m; ++i) {
		// cout << l[i] << ' ' << r[i] << '\n';
		if (l[i] > r[i]) {
			cout << "NO"; return 0;
		}
	}
	set<int> s;
	for (int i = 1; i <= m; ++i) s.insert(i);
	vector<int> go;
	for (int i = 1; i <= m; ++i) go.push_back(i);
	sort(go.begin(), go.end(), [&] (int x, int y) {
		return (r[x] == r[y]) ? l[x] < l[y] : r[x] < r[y];
	}); 
	for (auto i : go) {
		set<int> :: iterator it = s.lower_bound(l[i]);
		if (it == s.end() || *it > r[i]) {
			cout << "NO"; return 0;
		}
		res[i] = *it, s.erase(it);
		// cout << i << ' ' << res[i] << '\n';
	}
	cout << "YES\n";
	res2[1] = 1;
	for (int i = 1; i <= m; ++i) {
		int cur = res2[i], pos = G[cur].size();
		for (auto j : G[i]) res2[j] = G[cur][--pos];
		cout << res[cur] << ' ';
	}
}

Measured memory_bytes: 69364
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int X;
	double b = 1;
	double p = 2;
	int max = 1;
	cin >> X;
	
	for (b = 2; pow(b, 2) <= X; b++) {
		for (p = 2; pow(b, p) <= X; p++) {
			if (pow(b, p) > max) {
				max = pow(b, p);
			}
		}
	}

	cout << max << endl;
	
	return 0;
}


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

int main() {
	string sa = "012345678954321012345678954321";
	int n;
	cin >> n;
	for (int x = 0;x < n;x++) {
		char a, b;
		cin >> a >> b;
		int aa=1e-9, ab=1e9;
		for (int i = 0;i < sa.size();i++) {
			if (sa[i] == a) {
				for (int j = i;j <= sa.size();j++) {
					if (sa[j] == b) {
						if (ab - aa > j - i) {
							aa = i;
							ab = j;
						}
					}
				}
			}
		}
		for (int i = aa; i <= ab;i++) {
			if (i != aa)cout << ' ';
			cout << sa[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main()
{
	int n;
	cin >> n;
	int A[n + 1];
	for(int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	sort(A, A + n);
	int a = 0, b = 0;
	reverse(A, A + n);
	for(int i = 0; i < n; i++)
	{
		if(i % 2 == 0)
			a += A[i];
		else
			b += A[i];
	}
	cout << abs(a - b) << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 1e6+10;

int ns, nt;

vector<int> v[N];
vector<int> vis;
//Complexity is O(n)
vector<int> z_function(string &s, int n) {
   vector<int> z(n);
   for (int i=1, l=0, r=0; i<n; ++i) {
      if (i <= r) {
         z[i] = min(r-i+1, z[i-l]);
      }
      while (i+z[i]<n && s[z[i]] == s[i+z[i]]) {
         ++z[i];
      }
      if (i+z[i]-1 > r) {
         l = i, r = i+z[i]-1;
      }
   }

   for (int i = nt+1; i < n; ++i)
   {
      if(z[i] == nt){
         vis[(i-(nt+1))%ns] = 1;
      }
   }

   return z;
}


int indeg[N];
vector<int> topo; //Stores lexicographically smallest toposort
vector<int> g[N];

bool toposort(int n, int max_lim) //Returns 1 if there exists a toposort, 0 if there is a cycle
{  
   priority_queue<int, vector<int>, greater<int> > pq;
   for(int i=0;i<n;i++){
      for(auto &it:g[i])
         indeg[it]++;
   }
   for(int i=0;i<n;i++)
   {
      if(!indeg[i])
         pq.push(i);
   }
   while(!pq.empty())
   {
      int u=pq.top();
      pq.pop();
      topo.push_back(u);
      for(auto &v:g[u])
      {
         indeg[v]--;
         if(!indeg[v])
            pq.push(v);
      }
   }
   if(topo.size() != max_lim)
      return 0;
   return 1;
}

void solve(){

   string s, t;
   cin >> s >> t;
   ns = sz(s), nt = sz(t);

   while(sz(s) <= ns + nt){
      s += s;
   }

   int n = sz(s);
   vis.resize(ns);


   string pt = t + '#' + s;
   z_function(pt, sz(pt));

   for (int i = 0; i < ns; ++i)
   {
      if(vis[i] and vis[(i+nt)%ns]){
         g[i].pb((i+nt)%ns);
         v[(i+nt)%ns].pb(i);
      }
   }

   tr(vis);

   bool bad = 1;
   for(auto i: vis)
      bad &= i == 0;

   if(bad){
      cout<<0;
      exit(0);
   }

   if(!toposort(ns, ns)){
      cout<<-1;
      exit(0);
   }

   vector<int> dp(n, 1);
   tr(topo);
   reverse(topo.begin(), topo.end());

   for(auto i: topo){
      for(auto par: v[i]){
         smax(dp[par], dp[i] + 1);
      }
   }

   tr(dp);
   int ans = 0;
   for(auto i: dp)
      smax(ans, i);

   cout<<ans;
}

int32_t main(){_

   solve();   

   return 0;
}

Measured memory_bytes: 105896
n = int(input())
N = ['']*n
for i in range(n):
    N[i] = input()
m = int(input())
M = ['']*m
for i in range(m):
    M[i] = input()
r = 0
for i in N:
    r = max(N.count(i)-M.count(i), r)
print(r)

Measured memory_bytes: 3060