akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define INF 100000001
#define MAX_H 20001

using namespace std;

int main() {
    int H, N;
    cin >> H >> N;

    int dp[MAX_H];
    fill(dp, dp + MAX_H, INF);
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        for (int j = 0; j <= MAX_H - 1 - A; j++) {
            if (dp[j] != INF) {
                dp[j + A] = min(dp[j + A], dp[j] + B);
            }
        }
    }

    int ans = INF;

    for (int i = H; i < MAX_H; i++) {
        ans = min(ans, dp[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
# Some Sums


def calcSumOfDigits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        # print(sum)
        n = n // 10
    return sum

a = list(map(int, input().split()))
N = a[0]
A = a[1]
B = a[2]

total = 0
for i in range(N):
    sumOfDigits = calcSumOfDigits(i+1)
    # print("sumOfDigits: ", sumOfDigits)
    if sumOfDigits >= A and sumOfDigits <= B:
        # print("N: ", i+1)
        total += i+1
# print("total: ", total)
print(total)

Measured memory_bytes: 3064
#import math
w = input()
n = int(w)

w = input().split()
dat =[]
for num in w:
    dat.append(int(num))
    
min1 = min(dat)
max1 = max(dat)

sum1 = 0
for num in dat:
    sum1 = sum1+num

print(min1,end=" ")
print(max1,end=" ")
print(sum1)


Measured memory_bytes: 6596
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

//X = a * (p + 1/2)
//2X = a * (2p + 1)
//X = b * (2p + 1), b = a / 2




const Int INF = 2e9;
Int lcm(vector<Int> A){
  Int res = 1;
  for(auto a:A){
    Int gcd = __gcd(res, a);
    res = res / gcd * a;
    Min(res, INF);
    if(res == INF) return INF;
  }
  return res;
}

Int log2(Int a){
  Int res = 0;
  while(a % 2 == 0) a /= 2, res++;
  return res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;
  vector<Int> A(N);
  cin>>A;
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());

  for(Int i=0;i<N;i++){
    if(A[i] % 2 == 0) continue;
    cout<<0<<endl;
    return 0;
  }

  for(Int &a:A) a /= 2;

  for(Int a:A){
    pr(log2(A[0]), log2(a));
    if(log2(A[0]) != log2(a)){
      cout<<0<<endl;
      return 0;
    }
  }

  Int ans = (M / lcm(A) + 1) / 2;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	
	// テァツ板ィテヲツ??
	Scanner sc = new Scanner(System.in);
	char[] alpha = {'A','B','C','D','E','F','G','H',
			'I','J','K','L','M','N','O','P',
			'Q','R','S','T','U','V','W','X',
			'Y','Z'};
	
	// テ・ツ?・テ・ツ環?
	String in = sc.next();
	char[] inChar = in.toCharArray();

	// テ・ツ、ツ嘉ヲツ崢エ
	for(int i = 0;i<inChar.length;i++){
	    for(int j = 0;j<26;j++){
		if(inChar[i]==alpha[j]){
		    inChar[i] = alpha[j<3?(26-(3-j)):(j-3)%26];
		    break;
		}
	    }
	}

	String ans = "";
	for(int i = 0;i<inChar.length;i++){
	    ans += inChar[i];
	}

	System.out.println(ans);

    }
}

Measured memory_bytes: 22176
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>

std::vector<std::array<int64_t, 64>> dp;
int next_idx(int cur, int nxt){
	return (cur % 16) * 4 + nxt;
}
int main(void){
	int n;
	std::cin >> n;
	//state 直前3文字による 4^3 = 64
	dp.resize(n);
	for(int i=0;i<n;i++){
		for(int j=0;j<64;j++)dp[i][j] = 0;
	}
	//1文字目
	for(int i=0;i<4;i++){
		dp[0][3*16 + 3 * 4 + i] = 1;
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<64;j++){
			for(int k=0;k<4;k++){
				if(k == 1){
					//AGCでない判定
					int c = j % 4;
					int b = ((j - c) / 4) % 4;
					int a = (j - b * 4 - c) / 16;
					if(a == 0 && c == 2)continue;
					if(b == 0 && c == 2)continue;
					if(a == 0 && b == 2)continue;
					if(b == 2 && c == 0)continue;
				}
				if(k == 2){
					int c = j % 4;
					int b = ((j - c) / 4) % 4;
					int a = (j - b * 4 - c) / 16;
					if(b == 0 && c == 1)continue;
				}
				int idx = next_idx(j, k);

				dp[i][idx] += dp[i-1][j];
				dp[i][idx] %= 1000 * 1000 * 1000 + 7;
			}
		}
	}
	int64_t ans = 0;
	for(int i=0;i<64;i++){
		ans += dp[n-1][i];
		ans %= 1000 * 1000 * 1000 + 7;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int a[10];
	for (int i = 0; i < 10;i++) {
		a[i] = 0;
	}
	for(int i = 0; i < 4; i++) {
		int x;
		cin >> x;
		a[x]++;
	}
	if (a[1] == 1 && a[4] == 1 && a[7] == 1 && a[9] == 1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# ABC141c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

t = []

for i in range(n):
    t.append([a[i], i])
t.sort()

for i in t:
    print(i[1]+1, end=' ')

Measured memory_bytes: 21572
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#pragma warning (disable: 4996)
using namespace std;

int dat[10] = { 0,2,5,5,4,5,6,3,7,6 };

int N, M, A[1 << 18];
int dp[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) cin >> A[i];

	for (int i = 0; i <= N; i++) dp[i] = -(1 << 30);
	dp[0] = 0;
	for (int i = 0; i <= N; i++) {
		for (int k = 1; k <= M; k++) dp[i + dat[A[k]]] = max(dp[i + dat[A[k]]], dp[i] + 1);
	}

	int val = N; string S = "";
	while (val > 0) {
		int r = 0;
		for (int i = 1; i <= M; i++) {
			if (val >= dat[A[i]] && dp[val] - 1 == dp[val - dat[A[i]]]) r = max(r, A[i]);
		}
		val -= dat[r]; S += ('0' + r);
	}
	//reverse(S.begin(), S.end());
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int cnt=0;

void Divisors(int n)
{
    vector<int>v;
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if (n/i == i)
                v.push_back(i);
            else
            {
                v.push_back(i);
                v.push_back(n/i);
            }
        }
    }
    sort(v.begin(),v.end());
    //for(int i=0; i<v.size(); i++)
    //cout<<v[i]<<" ";
    for(int i=0; i<v.size(); i++)
    {
        if(mp[v[i]])
        {
            if(v[i]==n)
            {
                if(mp[n]>1)
                {
                    cnt++;
                    break;
                }
            }
            else
            {
                cnt++;
                break;
            }
        }
    }

}

int main()
{
    int n, x, i;
    cin >> n;
    int a[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    for (int i=0; i<n; i++)
    {
        Divisors(a[i]);

    }
    cout<<n-cnt<<endl;
}


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

using namespace std;

int main(){
int k, a, b;
  cin>>k>>a>>b;
  string ans = "NG";
  for(int i = a; i<b+1; i++)
  {
  if(i%k==0){
  	ans = "OK";
    break;
  }
  }
  cout<<ans;

return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()

void solve(int n, int m) {
    vector<int> c1(n), c2(m);
    rep(i,n) cin >> c1[i];
    rep(i,m) cin >> c2[i];

    rep(i,n) rep(j,m) {
        swap(c1[i], c2[j]);
        int sum1 = accumulate(ALL(c1), 0);
        int sum2 = accumulate(ALL(c2), 0);
        swap(c1[i], c2[j]);
        if(sum1 == sum2) {
            printf("%d %d\n", c1[i], c2[j]);
            return ;
        }
    }

    puts("-1");
    return ;
}

int main() {
    int n, m;
    while(cin>>n>>m && n) solve(n,m);

    return 0;
}

Measured memory_bytes: 3224
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int count = 0;
		int flagNum = 0;
		Boolean flag = false;

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

			int m = sc.nextInt();

			// System.out.println("i: " + i + ", m=" + m);

			if (m == i) {
				if (flagNum == m - 1 && flag) {
					flag = false;
					continue;
				}
				count++;
				flagNum = i;
				flag = true;
				continue;
			}
			flag = false;

		}

		System.out.println(count);

		sc.close();

	}

}


Measured memory_bytes: 49112
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int s, w;
	cin >> s >> w;
	if(w>=s)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  
  rep(i,N){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
    
    int ans=0;
  
  rep(i,K){
    ans+=p.at(i);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    if(H == 1 || W == 1) cout << 1 << endl;
    else if(H % 2 == 0 || W % 2 == 0) cout << (H * W) / 2;
    else cout << (H * W) / 2 + 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int i, n, m, sum, index;
	while(1) {
		scanf("%d %d", &n, &m);
		if(n == 0 && m == 0) break;
		sum = n + m;
		index = 0;
		for(i = 1; i < 5; ++ i) {
			scanf("%d %d", &n, &m);
			if(sum < n + m) {
				sum = n + m;
				index = i;
			}
		}
		printf("%c %d\n", 'A' + index, sum);
	}
	return 0;
}

Measured memory_bytes: 600
! 2020.1.19
!
      program answer
      implicit none
      integer :: N
      integer,allocatable,dimension(:) :: P
      integer :: i
      integer :: j
      integer :: ans
!
      read(*,*) N
      allocate(P(N))
      read(*,*) (P(i),i=1,N)
      j=1
      ans = 1
      do i=2,N
        if(P(j) > P(i)) then
          j = i
          ans = ans+1
        end if
      end do
      write(*,*) ans
      end program answer

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

using namespace std;

using ll = long long;

#define STR_LEN 10

//組み合わせの数nCrを計算
ll calcNumOfCombination(int n, int r){
  ll num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

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

  string tmp_s;
  char tmp_c[STR_LEN] = {0};
  vector <string> s;

  for (int i = 0; i < n; i++){
    cin >> tmp_c;
    sort(tmp_c, tmp_c + STR_LEN);
    tmp_s = tmp_c;
    //cout << tmp_s << endl;
    s.push_back(tmp_s);
    cin.ignore();
  }

  sort(s.begin(), s.end());
  ll cnt = 1;

  ll ans = 0;
  for(int i = 0; i < n - 1; i++){
    //cout << s[i] << endl;
    if(s[i] == s[i + 1]){
      ++cnt;
    } else if(cnt > 1){
      // これまでの数で組み合わせ数を計算
      ans += calcNumOfCombination(cnt, 2);
      cnt = 1; // 初期化
    } else {
      cnt = 1; // 初期o化
    }
  }

  // 最後はどう？
  if(cnt > 1){
    ans += calcNumOfCombination(cnt, 2);
  }

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


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

int sum=0;

void digit(int n)
{
  if(n >= 1){
    sum += n%10;
    digit(n/10);
  }
  return;
}

int main(){
  int n;

  cin >> n;

  digit(n);

  if(n%sum == 0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

  return 0;
}

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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  REP(i, N) cin >> a.at(i);
  sort(a.begin(), a.end());
  int cnt = 0;
  REP(i, N) {
    if (i == N-1 && a.at(i) != x) break;
    x -= a.at(i);
    if (x < 0) break;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

const char *weeks[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int days[]={0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true){
        int month, day;
        cin>>month>>day;
        if(month==0) break;
        int week=3;
        for(int i=1; i<month; i++) week=(week+days[i])%7;
        week=(week+day)%7;
        cout<<weeks[week]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3096
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private int countAB(String s) {
		int idx = 0;
		int result = 0;
		for (;;) {
			int t = s.indexOf("AB", idx);
			if (t >= 0) {
				result++;
				idx = t + 1;
			} else {
				break;
			}
		}
		return result;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		int countAB = 0;
		int A = 0;
		int B = 0;
		int BA = 0;

		for (int i = 0; i < N; i++) {
			String s = sc.next();

			countAB += countAB(s);

			if (s.startsWith("B") && s.endsWith("A")) {
				BA++;
			} else if (s.startsWith("B")) {
				B++;
			} else if (s.endsWith("A")) {
				A++;
			}
		}

		int ans = 0;

		int state = 0;
		for (;;) {
			switch (state) {
			case 0: //start
				if (A > 0) {
					A--;
					state = 1; //A
				} else if (BA > 0) {
					BA--;
					state = 1; //A
				} else {
					state = 3; //end
				}
				break;
			case 1: //A
				if (BA > 0) {
					BA--;
					state = 1;
					ans++;
				} else if (B > 0) {
					B--;
					state = 2; //x
					ans++;
				} else {
					state = 3;
				}
				break;
			case 2: //B
				if (A > 0) {
					A--;
					state = 1;
				} else {
					state = 3;
				}
				break;
			}
			if (state == 3) {
				break;
			}
		}

		out.println(ans + countAB);

		sc.close();

	}

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

}


Measured memory_bytes: 31616
H, W = map(int, input().split())
def change(x):   # 黒なら1, 白なら0   ※しなくてもよい
    if x == '#':
        return 1
    else:
        return 0
field = list()
for i in range(H):
    field.append(list(map(change,[i for i in input()])))

# 右と横に移動するベクトル
vector = [[1, 0], [0, 1]]

# 座標(i, j)に到達したか確認するリスト　未到達: 0 到達: 1 
check_list = [[0 for _ in range(W)] for _ in range(H)]
check_list[0][0] = 1

# 座標(i, j)に到達するために操作が何回か必要か記録するリスト
count_list = [[0 for _ in range(W)] for _ in range(H)]
count_list[0][0] = field[0][0]

# 座標(i, j)に到達する際、どのマスから来るのが最善か記録するリスト
zahyo_front = [[0] * W] * H
zahyo_front[0][0] = [0, 0]

# 探索候補の座標を記録するリスト   ※Queueモジュールなど使うと簡易になるらしい
# １つ目のfor文 i番目のk個目の候補の座標はzahyo_search[k][i]
zahyo_search = [[(0, 0)]]


for i in range(H+W-2):
    zahyo = zahyo_search[i]   # i番目の探索候補の座標を取り出す
    zahyo_kari = list()       # (i+1)回目の探索候補の座標を記録する仮リスト
    for (y, x) in zahyo:
        for (dy, dx) in vector:
            count = count_list[y][x]  
            y_k = y + dy
            x_k = x + dx
            try:               # if y_k < H and x_k < W: でもよい 
                
                if field[y_k][x_k] == 1 and field[y][x] == 0: 
                    
                    count += 1
                    # (y_k, x_k)が黒かつ(y, x)が白ならば連続でないので、countを+1する
                
                if check_list[y_k][x_k] == 0:        # (y_k, x_k)に未到達なら、そのまま記録する 
                    count_list[y_k][x_k] = count
                    zahyo_front[y_k][x_k] = [y, x]
                    check_list[y_k][x_k] = 1
                    zahyo_kari.append((y_k, x_k))    # (i+1)回目の探索候補の仮リストに入れる
                    
                else:                                # (y_k, x_k)に到達済
                    if count < count_list[y_k][x_k]:  # countが記録されていたものより小さければ採用
                        count_list[y_k][x_k] = count
                        zahyo_front[y_k][x_k] = [y, x]
                        
            except:
                pass
            
    zahyo_search.append(zahyo_kari) # 仮リストを探索リストに入れる

print(count_list[H-1][W-1])

Measured memory_bytes: 3956
//
// Created by 永徳泰明 on 2019-01-13.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

int main() {
    vector<int> v;

    rep(i, 4) {
        int t;
        cin >> t;
        v.push_back(t);
    }
    sort(v.begin(), v.end());
    cout << ((v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) ? "YES" : "NO") << endl;

    return 0;
}

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

const int maxn=1e5+10;
int n,x,ans[maxn<<1];
stack<int> s,l;

int main(){
	cin>>n>>x;
	if(x==1||x==2*n-1){
		puts("No");
		return 0;
	}
	puts("Yes");
	for(int i=1;i<x;++i)
		s.push(i);
	for(int i=x+1;i<2*n;++i)
		l.push(i);
	ans[n]=x;
	for(int i=n-1;i;--i)
		if(s.empty()){
			ans[i]=l.top();
			l.pop();
		}
		else{
			ans[i]=s.top();
			s.pop();
		}
	for(int i=n+1;i<2*n;++i)
		if(l.empty()){
			ans[i]=s.top();
			s.pop();
		}
		else{
			ans[i]=l.top();
			l.pop();
		}
	for(int i=1;i<2*n;++i)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3072
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000000

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

struct edge{
	int to, cost;
};

int main()
{
	while(1){
		int w, h;
		cin>>w>>h;
		if(w==0 && h==0) return 0;
		char s[61][31];
		vector<edge> v[4000];
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cin>>s[i][j];
				if(s[i][j]=='S'){
					edge e;
					e.to=2*(i*w+j+1), e.cost=0;
					v[0].push_back(e);
					e.to=2*(i*w+j)+1;
					v[0].push_back(e);
				}else if(s[i][j]=='T'){
					edge e;
					e.to=2*h*w+1, e.cost=0;
					v[2*(i*w+j+1)].push_back(e);
					v[2*(i*w+j)+1].push_back(e);
				}
			}
		}
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				for(int k=1; k<=3; k++){
					if(j+k>=w) continue;
					for(int l=-(3-k); l<=3-k; l++){
						if(i+l<0 || i+l>=h) continue;
						if(s[i+l][j+k]=='X') continue;
						if(s[i+l][j+k]=='S' || s[i+l][j+k]=='T'){
							edge e;
							e.to=2*((i+l)*w+j+k)+1, e.cost=0;
							v[2*(i*w+j+1)].push_back(e);
						}else{
							edge e;
							e.cost=s[i+l][j+k]-'0', e.to=2*((i+l)*w+j+k)+1;
							v[2*(i*w+j+1)].push_back(e);
						}
					}
				}
				for(int k=1; k<=3; k++){
					if(j-k<0) continue;
					for(int l=-(3-k); l<=3-k; l++){
						if(i+l<0 || i+l>=h) continue;
						if(s[i+l][j-k]=='X') continue;
						if(s[i+l][j-k]=='S' || s[i+l][j-k]=='T'){
							edge e;
							e.to=2*((i+l)*w+j-k+1), e.cost=0;
							v[2*(i*w+j)+1].push_back(e);
						}else{
							edge e;
							e.cost=s[i+l][j-k]-'0', e.to=2*((i+l)*w+j-k+1);
							v[2*(i*w+j)+1].push_back(e);
						}
					}
				}
			}
		}
		priority_queue<P, vector<P>, greater<P> > que;
		int d[4000];
		fill(d, d+2*h*w+2, INF);
		d[0]=0;
		que.push(P(0, 0));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int x=p.second;
			if(p.first>d[x]) continue;
			for(auto e:v[x]){
				if(d[e.to]>d[x]+e.cost){
					d[e.to]=d[x]+e.cost;
					que.push(P(d[e.to], e.to));
				}
			}
		}
		if(d[2*h*w+1]==INF){
			cout<<-1<<endl;
		}else{
			cout<<d[2*h*w+1]<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef string str;
const long long INF = INT64_MAX / 2;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll N;
    cin >> N;
    for (int h = 1; h <= 3500; h++)
    {
        for(int n = 1; n <= 3500; n++) {
            double w = (N * h * n) / (double)(4 * h * n - N * n - N * h);
            if(ceil(w)==floor(w) && w >= 0 && w <= 3500) {
                cout << h << " ";
                cout << n << " ";
                cout << w << endl;
                return;
            }
        }
    }
    
}

int main() {
    FIO;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>

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


using namespace std;

const long long MOD  = 1000000007;

long long fact(long long x)
{
  if (x==0) return 1;

  return x * fact(x-1) % MOD;
}

int main(int argc, char* argv[])
{
  long long N,M,ans;

  cin >> N >> M;

  if(abs(N-M)>=2){
    ans=0;
  }else if(abs(N-M)==1){
    ans = fact(N) * fact(M); 
  }else{
    ans = 2 * fact(N) * fact(M);
  }

  cout << ans % MOD << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,k;
double ans;
void saiki(int kai,int sum){
  if(kai >= n) ans += max(1,sum-k);
  else
    for(int i=1;i<=m;i++)saiki(kai+1,sum+i);
}

int main() {
  while(1) {
    cin >> n >> m >> k;
    if(n==0 && m==0 && k==0) break;
    ans = 0;
    saiki(0,0);
    int t = 1;
    for(int i=0;i<n;i++) t*=m;
    printf("%.8f\n",ans/t);
  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define N 3000 + 5
#define Mod 998244353
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, s, inv, a[N], dp[N][N];
int read(){
	char c; int x = 0, f = 1;
	c = getchar();
	while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int Inc(int a, int b){ return (a += b) >= Mod ? a - Mod : a;}
int Mul(int a, int b){ return 1ll * a * b % Mod;}
int Qpow(int a, int b){
	int ans = 1;
	while(b){
		if(b & 1) ans = Mul(ans, a);
		a = Mul(a, a), b >>= 1;
	}
	return ans;
}
int main(){
	n = read(), s = read();
    rep(i, 1, n) a[i] = read();
    inv = Qpow(2, Mod - 2), dp[0][0] = Qpow(2, n);
	rep(i, 1, n) rep(j, 0, s){
		dp[i][j] = Inc(dp[i][j], dp[i - 1][j]);
		if(j >= a[i]) dp[i][j] = Inc(dp[i][j], Mul(dp[i - 1][j - a[i]], inv));
	}
	printf("%d", dp[n][s]);
	return 0;
}

Measured memory_bytes: 38992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> pair;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    string S;
    cin >> S;
    ll cnt = 0;
    rep (i,S.size()) {
        cnt += S.at(i) - '0';
    }
    cout << (cnt % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) cout << 'x';
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
  FAST();

  double l;
  cin >> l;
  l = l/3;
  printf("%.12lf\n", l*l*l);
  //cout << l*l*l << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    ll d,n;
    cin>>d>>n;
    ll ans = 0;
    if(d==0){
        ans = 1;
        for(int i=0;i<n-1;i++){
            ans++;
            if(ans%100==0) i--;
        }
        cout<<ans<<endl;
        return 0;
    }
    else if(d==1){
        ans = 100;
        ll copy = 100; 
        for(int i=0;i<n-1;i++){
            ans+=copy;
            if((ans/100)%100==0) i--;
        }
        cout<<ans<<endl;
        return 0;
    }
    else {
        ans = 10000;
        ll copy = 10000;
        for(int i = 0; i<n-1;i++){
            ans += copy;
            if((ans/100/100)%100==0) i--;
        }
        cout<<ans<<endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string x,y;
    cin>>x>>y;
    if(x<y){
      cout<<"<"<<endl;
    }else if(x>y){
      cout<<">"<<endl;
    }else{
      cout<<"="<<endl;
    }
}

Measured memory_bytes: 256
import numpy as np
import math
nm = list(map(int,input().split()))
x = list(map(int,input().split()))
xs = sorted(x)
n=nm[0]
m=nm[1]

def dis(a):
    amax = np.argmax(a)
    amin = np.argmin(a)
    if len(a) == 1:
        return(0)
    else:
        return a[amax]-a[amin]

if n == 1:
    print(dis(xs))
elif m ==1:
    print(0)
else:
    sk = [0 for i in range(m-1)]
    for i in range(m-1):
        sk[i]=xs[i+1]-xs[i]
    sks = sorted(sk)
    sksr = list(reversed(sks))
    print(dis(xs)-sum(sksr[:(n-1)]))
    

Measured memory_bytes: 23064
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

li a[10];

int main(){
	li t;
	cin>>t;
	rep(case_num, t){
		rep(i,10)cin>>a[i];
		li l=0, r=0;
		bool res=true;
		rep(i,10){
			if(a[i]<min(l,r)){
				res=false;
				break;
			}
			else if(a[i]>max(l,r)){
				if(l>=r)l=a[i];
				else r=a[i];
			}
			else if(a[i]>l)l=a[i];
			else if(a[i]>r)r=a[i];
			else{
				res=false;
				break;
			}
		}
		cout<<(res ? "YES" : "NO")<<endl;
	}
	
	return 0;
}

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

int main(){
    int a;
    cin >> a;
    if(a/100 <=12 && a/100 >0){
        if(a%100 <= 12 && a%100) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else{
        if(a%100 <= 12 && a%100) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int ll
using pii = pair<int, int>;
vector <int> coef;
vector <int> diff;

int n, k;
bool fail(int x)
{
    int u = 0;
    for (int i = 0; i<n; i++)
    {
        //printf("%lld %lld -> under %lld chal\n",coef[i], diff[i], x);
        int v = x/diff[i];
        int tmp = max(coef[i] - v, 0LL);
        //printf("%lld train\n",tmp);
        u += tmp; 
    }
    //printf("Under %lld : %lld\n",x,u);
    return (u > k);
}
int32_t main()
{
    usecppio
    int sumn = 0;
    cin >> n >> k;
    for (int i = 0; i<n; i++)
    {
        int x;
        cin >> x;
        coef.push_back(x);
        sumn += x;
    }
    for (int i = 0; i<n; i++)
    {
        int x;
        cin >> x;
        diff.push_back(x);
    }
    if (sumn <= k)
    {
        cout << 0 << '\n'; return 0;
    }
    sort(all(coef));
    sort(all(diff),greater<int>());
    int lo = 0, hi = 1e18;
    while(lo + 1 < hi)
    {
        int mid = (lo+hi)/2;
        //printf("%lld %s\n",mid,(fail(mid)?"NO":"OK"));
        if (fail(mid))
            lo = mid;
        else 
            hi = mid;
    }
    cout << hi << '\n';
}

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

using namespace std;

int h, n, sum;

int main(){
	cin >> h >> n;
	for(int i = 1; i <= n; i++){
		int a;
		cin >> a;
		sum += a;
	}
	if(sum >= h) cout << "Yes", exit(0);
	cout << "No";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        while(true){
            String data[] = reader.readLine().split(" ");
            int a= Integer.parseInt(data[0]);
            int b= Integer.parseInt(data[1]);
             
            if(a==0 && b==0)
                break;
             
            for(int y=0; y<a; y++){
                for(int x=0; x<b; x++){
                    builder.append("#");
                }
                builder.append("\n");
            }
            builder.append("\n");
         
        }
        System.out.print(builder);
    }
}

Measured memory_bytes: 25144
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back

const ll MAX=2097151;
ll a[21][21],dp[22][MAX+1],pt[21];
const ll MOD=1000000007;

ll solve(ll n,ll seq)
{
    if(n==0) {
        if(seq==0)
            return dp[n][seq]=1;
        return dp[n][seq]=0;
    }
    if(dp[n][seq]!=-1)
        return dp[n][seq];

    ll sm=0;
    for(ll j=0;j<22;j++) {
        ll num=(1LL<<j);
        if((seq&num) && (pt[n-1]&num))
            sm=(sm+solve(n-1,seq^num))%MOD;
    }
    return dp[n][seq]=sm;
}


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

    ll n;
    cin>>n;
    for(ll i=0;i<n;i++) {
        for(ll j=0;j<n;j++) {
            ll num=(1LL<<j);
            cin>>a[i][j];
            pt[i]+=a[i][j]*num;
        }
    }
    memset(dp,-1,sizeof dp);

    ll num=0;
    for(ll i=0;i<n;i++) {
        num+=(1LL<<i);
    }

    // ll num2=0;
    // for(ll i=0;i<21;i++) {
    //     num2+=(1LL<<i);
    // }
    // cout << num2;

    cout << solve(n,num);
    
    return 0;
}


Measured memory_bytes: 360704
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pi pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
string check[]={"AA","AB","AX","AY","BA","BB","BX","BY","XA","XB","XX","XY","YA","YB","YX","YY"};
int dp[1001];

signed main(){
  int k;
  cin>>k;
  int ans=0;
  FOR(a,1,k){
    FOR(b,1,k){
      FOR(c,1,k){
        ans+=gcd(gcd(a,b),c);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;
void swap(ll &a,ll &b){
    ll temp=a;
    a=b;
    b=temp;
}
ll gcd(ll a,ll b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}

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

void solve(){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    ll lc=lcm(C,D);
    if(B<A){
        swap(B,A);
    }
    ll tc=(B/C)-(A-1)/C;
    ll td=(B/D)-(A-1)/D;
    ll tcd=(B/lc)-(A-1)/lc;
    out((B-A+1)-(tc+td-tcd));
    return ;

}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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


	ll x, y;
	cin>>x>>y;
	if(y<=4*x&&y>=2*x&&y%2==0) cout<<"Yes";
	else cout<<"No";

    return 0;
}


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

int main()
{
    int a,n;
    int nrdiv2=0,nrdiv4=0,nrnot=0;
    cin>>n;
    int i,j;

    for(i=1;i<=n;i++)
    {
        cin>>a;
        if(a%4==0) nrdiv4++;
        else
        {
            if(a%2==0) nrdiv2++;
            else nrnot++;
        }
    }
    if(nrdiv4>=nrnot)
    {
        cout<<"Yes\n";
        return 0;
    }
    if(nrdiv4==nrnot-1 && nrdiv2==0)
    {
            cout<<"Yes\n";
            return 0;
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int cnt[100010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll X, Y,A;
	cin >> X >> Y;
	int cnt = 1;
	A = X * 2;
	while (A <= Y) {
		cnt++;
		A *= 2;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second);
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto i : a)
const int mod = (int)(1e9) + 7;
//endregion

ll n;

int main() {
    io();
    in(n);
    out(n*(n-1)/2);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 300010

int ct[MAXN], ans[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, i, j, k, ans;
	string s;
	map<string, long long> ct;
	cin >> n;
	while (n--) {
		cin >> s;
		sort(s.begin(), s.end());
		ct[s]++;
	}
	ans = 0;
	for (auto p : ct) ans += p.second * (p.second - 1) / 2;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

ll plusMod(ll a, ll b, const int mod = MOD) {
  ll ans = (a + b) % mod;
  if (ans < 0) {
    ans += mod;
  }
  return ans;
}
ll prodMod(ll a, ll b, const int mod = MOD) {
  ll t = a * b % mod;
  if (t < 0) t += mod;
  return t;
}

/**
 * 繰り返し自乗法
 * http://satanic0258.hatenablog.com/entry/2016/04/29/004730
 */
ll powMod(ll n, ll p, const int mod = MOD) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    ll t = powMod(n, p / 2);
    return prodMod(t, t);
  } else {
    return prodMod(n, powMod(n, p - 1));
  }
}
/**
 * 余剰階乗 (Factorial)
 */
ll factMod(ll n) {
  ll n_fact = 1;
  rep(i, n) { n_fact = prodMod(n_fact, n - i); }
  return n_fact;
}
/**
 * 余剰Combination
 * nCk≡n! * (k!)^M−2 * ((n−k)!)^M−2 (modM)
 */
ll combMod(ll n, ll k, const int mod = MOD) {
  ll nCk = 1;
  k = min(k, n - k);

  repi(i, 1, k + 1) {
    nCk = prodMod(nCk, (n - i + 1));
    nCk = prodMod(nCk, powMod(i, mod - 2));
  }
  return nCk;
}

int main() {

  int N, a, b;
  cin >> N >> a >> b;

  ll tot_cnt = powMod(2, N) - 1;
  ll nCa = combMod(N, a);
  ll nCb = combMod(N, b);

  // printf("%lld, %lld, %lld\n", tot_cnt, nCa, nCb);

  cout << plusMod(plusMod(tot_cnt, -nCa), -nCb) << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
def dfs(i, j):
    global cnt, vis
    if len(set(vis)) == 1:
        cnt += 1
        return None
    for k in l[j]:
        if not vis[k] == 1:
            vis[k] = 1
            dfs(i + 1, k)
            vis[k] = 0
n, m = map(int, input().split())
l = [[] for i in range(n)]
vis = [0] * n
vis[0] = 1
cnt = 0
for i in range(m):
    a, b = map(int, input().split())
    l[a - 1].append(b - 1)
    l[b - 1].append(a - 1)
dfs(0, 0)
print(cnt)

Measured memory_bytes: 3064
N, K = map(int, input().split())
ans = 0
MOD = 10 ** 9 + 7
for i in range(K, N + 2):
    min = (i - 1) * i // 2
    max = (2 * N - i + 1) * i // 2
    ans = (ans + max - min + 1) % MOD
print(ans)

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

const int Max = 1000000;

void update(vector<int> &v,int x){
  for(int i=x; i<Max; ++i){
    v[i] =min(v[i-x]+1,v[i]);
  }
}
 
int main(){
  vector<int> a(Max,Max);
  vector<int> o(Max,Max);

  a[0]=0;
  o[0]=0;
  for(int i=0;;++i){
    int tmp = i*(i+1)*(i+2)/6;
    if(tmp>Max)break;
    update(a,tmp);
    if(tmp&1)update(o,tmp);
  }
  int n;
  while(cin >> n,n){
    cout << a[n] << " " << o[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 10500
#include <bits/stdc++.h>
#include <cstdlib> // abs() for integer
#include <cmath>   // abs() for float, and fabs()
using namespace std;

int main(){
    int N;
    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;
    string txt;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> txt;
        if (txt == "AC")
        {
            AC++;
        }else if (txt == "WA")
        {
            WA++;
        }else if (txt == "TLE")
        {
            TLE++;
        }else
        {
            RE++;
        }
    }
    cout << "AC" " " "x" " "<< AC<< endl;
    cout << "WA" " " "x" " "<< WA<< endl;
    cout << "TLE" " " "x" " "<< TLE<< endl;
    cout << "RE" " " "x" " "<< RE;
    // << endl;
    // "WA x " WA;
    // << endl;
    // "TLE x " TLE;
    // << endl;
    // "RE x " RE;
    // << endl;
}

Measured memory_bytes: 3632