akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int MOD = 2019;

int min_search(int a, int b){
    int m = MOD;
    for(int i = a; i <= b - 1; i++){
        for(int j = a + 1; j <= b; j++){
            int tmp = (i * j) % MOD;
            m = min(m, tmp);
        }
    }
    return m;
}

int main(){
    int L, R; cin >> L >> R;
    int ans;
    int modL = L % MOD;
    int modR = R % MOD;
    if(modL > modR || R - L >= 2019) ans = 0;
    else ans = min_search(modL, modR);
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

data=[]
for i in range(N):
    S,P = input().split()
    li = [i+1,S,int(P)]
    data.append(li)
    
data.sort(reverse=True, key=lambda x: x[2])
data.sort(key=lambda x: x[1])
for i in range(N):
    print(str(data[i][0]))

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

const i32 mod = 998244353;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  i32 sum = 0;
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
    sum += a[i];
  }
  i32 *dp = (i32 *) calloc (sum + 1, sizeof (i32));
  dp[0] = 1;
  for (i32 i = 0; i < n; ++i) {
    for (i32 j = sum; j >= a[i]; --j) {
      dp[j] = ((i64) 2 * dp[j] + dp[j - a[i]]) % mod;
    }
    for (i32 j = a[i] - 1; j >= 0; --j) {
      dp[j] = 2 * dp[j] % mod;
    }
  }
  i32 ans = mod_pow (3, n);
  for (i32 i = (sum + 1)/ 2; i <= sum; ++i) {
    ans = (ans + mod - (i64) 3 * dp[i] % mod) % mod;
  }
  if (sum % 2 == 0) {
    memset (dp, 0, sizeof (i32) * (sum + 1));
    dp[0] = 1;
    for (i32 i = 0; i < n; ++i) {
      for (i32 j = sum / 2; j >= a[i]; --j) {
	dp[j] = (dp[j] + dp[j - a[i]]) % mod;
      }
    }
    ans = (ans + mod + (i64) 3 * dp[sum / 2] % mod) % mod;
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 512
def solve():
    t_hp, t_at, a_hp, a_at = map(int,input().split())
    turn = 0
    while t_hp > 0 and a_hp > 0:
        if turn % 2 == 0:
            a_hp -= t_at
        else:
            t_hp -= a_at
        turn += 1
    
    if t_hp > 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 61848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    map<int, int> m;
    int n; cin >> n;
    int ans = 0;
    rep(i,n){
        int a; cin >> a;
        m[a] += 1;
        m[a-1] += 1;
        m[a+1] += 1;
        ans = max(ans,max(m[a],max(m[a-1],m[a+1])));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4736
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    w = input()
    d = defaultdict(int)
    for c in w: d[c] += 1
    cond = True
    for key in d:
        if d[key] % 2 != 0:
            cond = False
            break
    if cond:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 64496
# AOJ 0141 Spiral Pattern
# Python3 2018.6.23 bal4u

for ci in range(int(input())):
	if ci > 0: print()
	n = int(input())
	a = [[' ' for c in range(n+5)] for c in range(n+5)]
	for r in range(0, n+4, n+3):
		for c in range(n+4): a[r][c] = '#'
	for c in range(0, n+4, n+3):
		for r in range(n+4): a[r][c] = '#'
	r, c = n+1, 2
	a[r][c] = '#'
	d = 'U'
	stop = 0
	while 1:
		if stop >= 4: break
		if d == 'U':
			if a[r-2][c] == '#' or a[r-1][c] == '#' or a[r-1][c+1] == '#':
				d = 'R'
				stop += 1
			else:
				r -= 1
				a[r][c] = '#'
				stop = 0
		if d == 'R':
			if a[r][c+2] == '#' or a[r][c+1] == '#' or a[r+1][c+1] == '#':
				d = 'D'
				stop += 1
			else:
				c += 1
				a[r][c] = '#'
				stop = 0
		if d == 'D':
			if a[r+2][c] == '#' or a[r+1][c] == '#' or a[r+1][c-1] == '#':
				d = 'L'
				stop += 1
			else:
				r += 1
				a[r][c] = '#'
				stop = 0
		if d == 'L':
			if a[r][c-2] == '#' or a[r][c-1] == '#' or a[r-1][c-1] == '#':
				d = 'U'
				stop += 1
			else:
				c -= 1
				a[r][c] = '#'
				stop = 0
	for r in range(2, n+2):	print(*a[r][2:n+2], sep='')



Measured memory_bytes: 7192
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
	string s;
	cin >> s;
	string ans = s[0] + to_string(s.length() - 2) + s[s.length() - 1];
	cout << ans;

	return 0;
}





Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int max = 1;
        
        for(int i = 2; i < x; i++){
            int exp = i * i;
            
            while(exp <= x){
                max = Math.max(exp,max);
                exp = exp * i;
            }
        }
        System.out.println(max);
    }
}


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

int main(void){
  long now=-100000010;
  int n;
  cin>>n;
  long a;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a==now){
      ;
    }
    else{
      if(i==0){
        cout<<a;
      }
      else{
        cout<<" "<<a;
      }
      now=a;
    }
  }
  cout<<endl;
  return 0;
}



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

signed main() {
	int n; cin >> n;
	vector<tuple<string, int, int>> a;
	for(int i = 1; i <= n; i++) {
		int p;
		string c;
		cin >> c >> p;
		p= -p;
		a.push_back(tie(c, p, i));
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < n; i++){
		cout << get<2>(a[i]) << endl;
	}
}


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

using namespace std;

int main()
{
    int a,b,d;
    cin>>a>>b>>d;
    if(a==5&&b==5&&d==7)
        cout<<"YES"<<endl;
    else if(a==5&&b==7&&d==5)
        cout<<"YES"<<endl;
    else if(a==7&&b==5&&d==5)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;

const long long INF = 2e18 + 18;

vector<vector<int> > open, close;
vector<int> l, r;
vector<long long> a;

struct T {
	vector<long long> t;
	vector<long long> add;

	void init(int n) {
		t.resize(4 * n);
		add.resize(4 * n);
	}

	void pull(int v) {
		t[v] = max(t[2 * v + 1], t[2 * v + 2]);
	}

	void push(int v) {
		t[2 * v + 1] += add[v];
		t[2 * v + 2] += add[v];
		add[2 * v + 1] += add[v];
		add[2 * v + 2] += add[v];
		add[v] = 0;
 	}

	void apply(int v, long long val) {
		t[v] += val;
		add[v] += val;
	}

	void build(int v, int tl, int tr) {
		if (tl == tr) {
			t[v] = 0;
			add[v] = 0;
		} else {
			int mid = tl + tr >> 1;
			build(2 * v + 1, tl, mid);
			build(2 * v + 2, mid + 1, tr);
			pull(v);
		}
	}

	void update(int v, int tl, int tr, int l, int r, long long val) {
		if (tl > r or l > tr) return;
		else if (tl >= l and tr <= r) {
			apply(v, val);
		} else {
			push(v);
			int mid = tl + tr >> 1;
			update(2 * v + 1, tl, mid, l, r, val);
			update(2 * v + 2, mid + 1, tr, l, r, val);
			pull(v);
		}
	}

	long long get(int v, int tl, int tr, int l, int r) {
		if (tl > r or l > tr) return -INF;
		else if (tl >= l and tr <= r) return t[v];
		else {
			push(v);
			int mid = tl + tr >> 1;
			long long left = get(2 * v + 1, tl, mid, l, r);
			long long right = get(2 * v + 2, mid + 1, tr, l, r);
			pull(v);
			return max(left, right);
		}
	}
};

void solve() {
	int n, m; cin >> n >> m;
	open.resize(n + 1);
	close.resize(n + 1);
	l.resize(m + 1);
	r.resize(m + 1);
	a.resize(m + 1);
	for (int i = 1; i <= m; i++) {
		cin >> l[i] >> r[i] >> a[i];
		open[l[i]].pb(i);
		close[r[i]].pb(i);
	}
	T t;
	t.init(n);
	t.build(0, 0, n);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < int(open[i].size()); j++) {
			int v = open[i][j];
			t.update(0, 0, n, 0, l[v] - 1, a[v]);
		}
		long long res = t.get(0, 0, n, 0, i - 1);
		t.update(0, 0, n, i, i, res);
		for (int j = 0; j < int(close[i].size()); j++) {
			int v = close[i][j];
			t.update(0, 0, n, 0, l[v] - 1, -a[v]);
		}
	}
	cout << t.get(0, 0, n, 0, n) << endl;
}

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

Measured memory_bytes: 37760
#include<stdio.h>


int main() {
	int a, b, c;
	int check=0;
	scanf("%d %d %d", &a, &b, &c);
	if (a == 5 && b == 5 && c == 7) 
		check = 1;
	else if (a == 5 && b == 7 && c == 5)
		check = 1;
	else if (a == 7 && b == 5 && c == 5)
		check = 1;
	if (check == 1)
		puts("YES");
	else
		puts("NO");
	return 0;
}

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

int inf = 1e9;
vector<vector<int>> calcNext(string x){
    vector< vector<int> > res(2, vector<int>(x.size()+1));
    res[0][x.size()] = res[1][x.size()] = inf;
    
    for(int i = x.size()-1 ; i >= 0 ; i--){
        for(int j = 0 ; j < 2 ; j++){
            res[j][i] = res[j][i+1];
        }
        if( x[i] != '|' ) res[x[i]-'0'][i] = i;
    }
    return res;
}

vector<vector<int>> nexts[2];

string s,t;
int dp[4040][4040];

int dfs(int s1, int s2){
    s1 = min<int>(s.size(), s1);
    s2 = min<int>(t.size(), s2);

    if( s1 >= s.size() && s2 >= t.size()) return 0;
    if( dp[s1][s2] != -1 ) return dp[s1][s2];
    
    int mn = 1e9;
    for(int i = 0 ; i < 2 ; i++){
        int p1 = s1 == s.size() ? s1 : nexts[0][i][s1+1];
        int p2 = s2 == t.size() ? s2 : nexts[1][i][s2+1];
        mn = min(mn, dfs(p1, p2) + 1);
    }
    return dp[s1][s2] = mn;
}

void rec(int s1,int s2, char prev){
    s1 = min<int>(s.size(), s1);
    s2 = min<int>(t.size(), s2);
    if( s1 >= s.size() && s2 >= t.size()) return;
    for(int i = 0 ; i < 2 ; i++){
        int p1 = s1 == s.size() ? s1 : nexts[0][i][s1+1];
        int p2 = s2 == t.size() ? s2 : nexts[1][i][s2+1];
        if( dfs(p1, p2) + 1 == dfs(s1, s2) ){
            cout << i;
            rec(p1, p2, i);
            return;
        }
    }

}

int main(){
    memset(dp, -1, sizeof(dp));
    cin >> s >> t;
    s = "|" + s;
    t = "|" + t;

    nexts[0] = calcNext(s);
    nexts[1] = calcNext(t);   
    rec(0, 0, 0);
    cout << endl;
    //cout << dfs(0,0) << endl;
}


Measured memory_bytes: 67208
import sys
def input():
    return sys.stdin.readline().rstrip('\n')

def calc(K, A, B):
    for i in range(A, B + 1):
        if i % K == 0:
            return 'OK'
    return 'NG'


K = int(input())
(A, B) = tuple([int(s) for s in input().split()])
print(calc(K, A, B))

Measured memory_bytes: 61704
import Data.List
main = do
 n <- readLn::IO Int
 print $ g [n]

maxpower::Int->Int->Int
maxpower n x = n^(floor(((logBase (fromIntegral n). fromIntegral) x )+0.0000001))
f [] = []
f (x:xs) = nub((x - maxpower 6 x ):(x - maxpower 9 x):(f xs))
g::[Int]->Int
g xs
    |0 `elem` xs =0
    |otherwise =(g (f xs)) + 1

Measured memory_bytes: 1020
n,k = map(int, input().split())

ret = {}

for i in range(n):
    a,b = map(int, input().split())
    ret[a] = ret.get(a, 0) + b

for i in sorted(ret.keys()):
    k -= ret[i]
    if k <= 0:
        print(i)
        break

Measured memory_bytes: 10596
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n,m;
    cin >> n >> m;
    multiset<pair<LL, LL>> s;
    rep(i, n){
        LL a, b;
        cin >> a >> b;

        s.insert(make_pair(a, b));
    }
    LL ans = 0;
    repe(i, s){
        LL a, b;
        tie(a, b) = i;
        if(m <= b){
            ans += a*m;
            break;
        }else{
            ans += a*b;
            m -= b;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	// とりあえず、直感だけでやってみる。
	ll N,M;
	std::cin >> N>>M;
	vll cnt(N,0);
	rep(i, 0, M*2) {
		ll a;
		std::cin >> a;
		cnt[a - 1]++;
	}

	rep(i, 0, N) {
		if (cnt[i] & 1) {
			std::cout << "NO" << endl;
			return 0;
		}
	}
	std::cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] l = new int[n];
		
		for(int i = 0; i < n; i++) l[i] =sc.nextInt();
		
		Arrays.sort(l);
		
		int max = l[n-1];
		
		int sum = 0;
		
		for(int i = 0; i < n-1; i++) {
			sum+=l[i];
		}
		
		System.out.println(max < sum ? "Yes" : "No");
		
	}
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

// 縦横の5個つながりを確認する
// グリッドを作成して斜めを確認する

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for(int i = 0; i < 2; i++) {
        if(A > B) {
            ans += A;
            A--;
        } else {
            ans += B;
            B--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n_people, n_relationship = list(map(int, input().split()))
adj_list = [[] for _ in range(n_people)]
for i in range(n_relationship):
  p, target = list(map(int, input().split()))
  adj_list[p].append(target)
  adj_list[target].append(p)


group = [-1] * n_people
cnt = 0
for i in range(n_people):
  if group[i] == -1:
    group[i] = cnt
    stack = [i]
    while stack:
      at = stack.pop()
      for to in adj_list[at]:
        if group[to] == -1:
          group[to] = cnt
          stack.append(to)

    cnt += 1

for _ in range(int(input())):
    s, t = map(int, input().split())
    print('yes' if group[s] == group[t] else 'no')




Measured memory_bytes: 23392
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = b * (n - 1) + a - (a * (n - 1) + b) + 1;
    cout << (ans > 0 ? ans : 0) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};

vector<int> table(1000010);

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	int a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	rep(i, n) {
		for(int j = 1; j * a[i] <= a[n-1]; j++) {
			table[j * a[i]]++;
		}
	}

	int ans = 0;
	rep(i, n) {
		if(table[a[i]] == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12624
<?php
define('MOD', 1000000007);
define('MAX', 666666);


function power($a, $b){
	$res = 1;
	while($b > 0){
		if($b & 1) $res = $res * $a % MOD;
		$a = $a * $a % MOD;
		$b >>= 1;
	}
	return $res;
}

function comb($n, $r){
	global $fact, $f_inv;
	return ($fact[$n] * $f_inv[$r]) % MOD * $f_inv[$n-$r] % MOD;
}

$n = MAX;
$fact[0] = 1;

for ($i = 0; $i < $n; $i++) {
	$fact[$i+1] = $fact[$i] * ($i+1) % MOD;
}

$f_inv[$n] = power($fact[$n], MOD-2);

for($i = $n-1; $i >= 0; --$i) {
	$f_inv[$i] = $f_inv[$i+1] * ($i+1) % MOD;
}

fscanf(STDIN, "%d %d", $X, $Y);

if (($X + $Y) % 3 === 0) {
	$Z = $X + $Y;
	$W = $Z / 3;
	$X -= $W;
	$Y -= $W;
	if ($X < 0 || $Y < 0) {
		echo "0";
	} else {
		echo comb($X + $Y, $X);
	}
} else {
	echo "0";
}


Measured memory_bytes: 64108
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
int count_change(int x, int* a, int n, int* c, int d)
{
	if(n < 0) return 0;
	if(x == 0) return 1;
	else if(x < 0 || d == 3) return 0;
	else return count_change(x, a, a[d+1], c, d+1) + count_change(x - c[d], a, n-1, c, d);
}
int main()
{
	int c[3] = {500, 100, 50};
	int a[3], x;
	cin>>a[0]>>a[1]>>a[2]>>x;
	cout<< count_change(x, a, a[0], c, 0) <<endl;
	return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
bool judge(ll k,V vec,ll &a,ll &b){
   // cout<<k<<endl;
    rep(i,vec.size()){
        vec[i] -= b*k;
    }
    sort(all(vec), greater<ll>());
    ll cnt = 0;
    rep(i,vec.size()){
        if(vec[i]<=0){
            break;
        }
        if(vec[i]%(a-b)==0){
            cnt += vec[i] / (a-b);
        }else{
            cnt += vec[i] / (a-b) + 1;
        }
    }
    return cnt <= k;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    V vec(n);
    rep(i,n)cin>>vec[i];
    ll MAX=1e9;
    ll Min = 0;
    rep(i,50){
        ll Half = (MAX + Min) / 2;
        if(judge(Half,vec,a,b)){
            MAX = Half;
        }else{
            Min = Half;
        }
    }
    cout << Min+1 << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
map <int,int> m;
int a[200001],n,i;
long long mx;
main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		m[a[i]+i]++;
	}
	for(i=1;i<=n;i++)
	{
		if(i-a[i]>0)
		mx+=m[i-a[i]];
	}
	cout<<mx;
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

ll cnt[15];
ll h,w,n;
map < pii , bool > flag;
int dy[] = {-2,-2,-2,-1,-1,-1,0,0,0};
int dx[] = {-2,-1,0,-2,-1,0,-2,-1,0};

bool inRange(int y, int x){
	return y > 0 && y <= h && x > 0 && x <= w;
}

int getCnt(int ty, int tx, int ny, int nx){
	int ret = 0;
	REP(i,ty,ny){
		REP(j,tx,nx){
			if(flag[MP(i,j)]) ret++;
		}
	}
	return ret;
}

void update(int y, int x){
	FOR(i,9){
		int ty = y + dy[i];
		int tx = x + dx[i];
		int ny = ty + 2;
		int nx = tx + 2;
		if(inRange(ty,tx) && inRange(ny,nx)){
			int bef = getCnt(ty,tx,ny,nx);
			cnt[bef]--;
			cnt[bef+1]++;
		}
	}
	flag[MP(y,x)] = true;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w >> n;
	cnt[0] = (h-2) * (w - 2);
	int y,x;
	FOR(i,n){
		cin >> y >> x;
		update(y,x);
	}
	FOR(i,10) cout << cnt[i] << endl;
	return 0;
}

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

using namespace std;

int a[4][4];
bitset<1000> mark;

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


	
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> a[i][j];

	int tt, b;
	cin >> b;
	for (int i = 0; i < b; ++i)
		cin >> tt, mark[tt] = 1;

	for (int i = 0; i < 3; ++i) {
		bool is = true;
		for (int j = 0; j < 3; ++j)
			if (!mark[a[i][j]])
				is = false;
		if (is) {
			cout << "Yes\n";
			return 0;
		}
	}

	for (int j = 0; j < 3; ++j) {
		bool is = true;
		for (int i = 0; i < 3; ++i)
			if (!mark[a[i][j]])
				is = false;
		if (is) {
			cout << "Yes\n";
			return 0;
		}
	}

	if (mark[a[0][0]] && mark[a[1][1]] && mark[a[2][2]])
		cout << "Yes\n";
	else if (mark[a[0][2]] && mark[a[1][1]] && mark[a[2][0]])
		cout << "Yes\n";
	else
		cout << "No\n";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 320;
int g[maxn][maxn];
bool good[maxn];

pair < long long , long long > solve(long long len, int d){
    if(len == 1) return {0, d};
    auto ans = solve(len >> 1, d);
    ans.first *= 2LL;
    ans.second = ans.second * 10 + ans.second;
    ans.first++;
    ans.second = ans.second / 10 + ans.second % 10;
    if(ans.second >= 10){
        ans.first++;
        ans.second = ans.second / 10 + ans.second % 10;
    }
    if(len & 1){
        ans.second = ans.second * 10 + d;
        ans.first++;
        ans.second = ans.second / 10 + ans.second % 10;   
    }
    if(ans.second >= 10){
        ans.first++;
        ans.second = ans.second / 10 + ans.second % 10;
    }
    return ans;
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    long long ans = 0;
    cin >> n;
    vector < int > v;
    for(int i = 0 ; i < n ; ++i){
        long long d, c;
        cin >> d >> c;
        auto u = solve(c, d);
        ans += u.first;
        //cout << u.first << ' ' << u.second << '\n';
        v.push_back(u.second);
    }
    int sum = v[0];
    for(int i = 1 ; i < n ; ++i){
        sum = sum * 10 + v[i];
        ans++;
        sum = sum / 10 + sum % 10;
        if(sum >= 10){
            ans ++;
            sum = sum / 10 + sum % 10;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=a+b;
	if(c<24){
		printf("%d",c);
	}else{
	c-=24;
	printf("%d",c);
}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
ll N;

//全通り試すとO(N^3)で無駄すぎる
//真ん中を固定して，それより上，それより下の値がどれだけあるかを調べてかけると組み合わせがわかる

int main(){

    cin >> N;
    vector<ll > a(N, 0);
    vector<ll > b(N, 0);
    vector<ll > c(N, 0);

    for(ll i = 0; i < N; i++){
        cin >> a[i];
    }

    for(ll i = 0; i < N; i++){
        cin >> b[i];
    }

    for(ll i = 0; i < N; i++){
        cin >> c[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    

    ll ans = 0;

    for(ll i = 0; i < N; i++){
        //b[i]より小さい（＞）値の数をaからみつける
        auto it1 = lower_bound(a.begin(), a.end(), b[i]);
        ll lessThan = it1 - a.begin();
         //b[i]より大きい（＞）値の数をaからみつける
        auto it2 = upper_bound(c.begin(), c.end(), b[i]);
        ll GreaterThan = c.end() - it2;
        //総数は？
        ans += lessThan * GreaterThan;
    }   

    cout << ans << endl;
    

} 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int N=2103;
int n,a[N],S;
bitset < N*N > bt;
int main() {
	ios::sync_with_stdio(false);
	
	cin>>n;
	
	for (int i=1; i<=n; i++) {
		cin>>a[i];
		S+=a[i];
	}
	
	sort(a+1,a+n+1);
	
	bt[0]=1;	
	for (int i=1; i<=n; i++) {
		bt|=(bt << (a[i]));
	}
	
	for (int i=(S+1)/2; i<=S; i++) 
		if (bt[i])  {
			cout<<i<<" \n";
			return 0;
		}
}

Measured memory_bytes: 1920
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, T;
    cin >> N >> T;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<ll> max_value(N);
    max_value[N - 1] = A[N - 1];
    for (ll i = N - 2; i >= 0; i--) {
        max_value[i] = max(max_value[i + 1], A[i]);
    }

    ll max_diff = 0, ans = 0;
    for (ll i = 0; i < N; i++) {
        ll diff = max_value[i] - A[i];
        if (diff == max_diff) {
            ans++;
        } else if (diff > max_diff) {
            max_diff = diff;
            ans = 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
	int n, i, j;
	int a[10000];
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	j=n;
	for(i=0;i<n;i++){
		j-=1;
		printf("%d",a[j]);
		if(j==0){
			printf("\n");
		}
		else{
			printf(" ");
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007

using namespace std;

int main()
{
	IOS;
	int n;
	cin>>n;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	a--;b--;c--;d--;
	string s;
	cin>>s;

	for(int y=a;y<c;y++)
	{
		if(s[y]=='#' && s[y+1]=='#')
			{
				cout<<"No\n";
				return 0;
			}
	}
	for(int y=b;y<d;y++)
	{
		if(s[y]=='#' && s[y+1]=='#')
			{
				cout<<"No\n";
				return 0;
			}
	}
	if(c>d)
	{
		for(int y=b;y<=d;y++)
		{
			if(s[y-1]=='.' && s[y+1]=='.' && s[y]=='.')
			{
				cout<<"Yes\n";
				return 0;
			}
		}
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;

struct node {
	bool done;
	vi to, dist;
	int id, from;
	ll d;
	bool operator<(const node & another) const {
		return !(d != another.d ? d < another.d : id < another.id);
	}
};

void bellman_ford(vector<node> nodes, int n, int start, int limit) {
	nodes[start].d = 0;
	queue<node> que;
	que.push(nodes[start]);
	int cnt = 0;
	while (que.size()&&cnt<limit) {
		node focus = que.front(); que.pop();
		Loop(i, focus.to.size()) {
			if (nodes[focus.to[i]].d > focus.d + focus.dist[i]) {
				nodes[focus.to[i]].d = focus.d + focus.dist[i];
				nodes[focus.to[i]].from = focus.id;
				que.push(nodes[focus.to[i]]);
			}
		}
		cnt++;
	}
	if (cnt == limit) cout << "NEGATIVE CYCLE" << endl;
	else {
		Loop(i, n) {
			if (nodes[i].d == INFLL) cout << "INF" << endl;
			else cout << nodes[i].d << endl;
		}
	}
}

int main() {
	int v, e, r; cin >> v >> e >> r;
	vector<node> nodes(v + 5);
	Loop(i, v) nodes[i] = { false,{},{}, i, -1, INFLL };
	Loop(i, e) {
		int s, t, d; cin >> s >> t >> d;
		nodes[s].to.push_back(t);
		nodes[s].dist.push_back(d);
		/*
		nodes[t].to.push_back(s);
		nodes[t].dist.push_back(d);
		*/
	}
	bellman_ford(nodes, v, r, (v + 1)*(e + 1));
}

Measured memory_bytes: 3360
package main

import (
        "fmt"
)

func solution(a, b, c int) int {
        count := 0
        for a&1 == 0 && b&1 == 0 && c&1 == 0 {
                a, b, c = (b+c)/2, (a+c)/2, (a+b)/2
                count++
                if a == b && b == c && c == a {
                        return -1
                }
        }
        return count
}

func main() {
        var a, b, c int
        fmt.Scan(&a, &b, &c)
        fmt.Println(solution(a, b, c))
}

Measured memory_bytes: 512
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim S As String = NextString()
        Dim x, y As New HashSet(Of Char)

        For Each c As Char In S
            Select Case c & ""
                Case "N", "S"
                    y.Add(c)
                Case "W", "E"
                    x.Add(c)
            End Select
        Next

        If x.Count Mod 2 = 0 AndAlso y.Count Mod 2 = 0 Then
            WriteLine("Yes")
        Else
            WriteLine("No")
        End If
    End Sub

    Function B2I(ok As Boolean) As Integer
        If ok Then Return 1
        Return 0
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
ll dp[3005][3005][5];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r,c,k;cin >> r >> c >> k;
    vector<vector<ll>> a(r+1,vector<ll>(c+1,-1));
    REP(i,k){
        int x,y,v;cin >> x >> y >> v;
        x--,y--;
        a[x][y]=v;
    }
    REP(i,r+1) REP(j,c+1) REP(l,5) dp[i][j][l]=-1;
    dp[0][0][0]=0;
    if(a[0][0]>0) dp[0][0][1]=a[0][0];
    REP(i,r){
        REP(j,c){
            REP(l,4){
                if(dp[i][j][l]==-1) continue;
                chmax(dp[i+1][j][0],dp[i][j][l]);
                chmax(dp[i][j+1][l],dp[i][j][l]);
                if(a[i+1][j]>0){
                    chmax(dp[i+1][j][1],dp[i][j][l]+a[i+1][j]);
                }
                if(a[i][j+1]>0){
                    chmax(dp[i][j+1][l+1],dp[i][j][l]+a[i][j+1]);
                }
            }
        }
    }
    ll ans=0;
    REP(i,4){
        chmax(ans,dp[r-1][c-1][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 425740
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 99999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , ans = INF , sum;
int main(){
fcin;
	cin>>n;
	for(int i = 0 ; i < n ; i++){
		cin>>a[i];
	}
	int i = 1;
	while(i <= 1000){
		sum = 0;
		for(int j = 0 ; j < n ; j++){
			sum+=pow(a[j]-i,2);
		}
		// cout<<sum<<endl;
		ans = min(ans,sum);
		i++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-Ofast")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (long long)a.size()
#define all(a) a.begin(), a.end()
#define reset(a, n) a.clear(), a.resize(n)
#ifndef ONLINE_JUDGE
#define cin ___in
#endif
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
typedef pair<ll, ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > vvec;
typedef vector<pair<ll, ll> > vecpi;
typedef vector<vector<pair<ll, ll> > > vvecpi;
typedef set<ll> seti;
typedef set<pair<ll, ll> > setpi;
typedef multiset<ll> mseti;
typedef multiset<pair<ll, ll> > msetpi;
typedef map<ll, ll> mpi;

static const bool tc = 0;
static const ll mod = LLONG_MAX - 24;

void solve() {
        ll n, k, ans = 1e9;
        cin >> n >> k;
        vec a(n);
        for(auto &it : a) cin >> it;
        ll l = 1, r = 1e9;
        while(l <= r) {
                ll m = (l + r) >> 1;
                ll cnt = 0;
                for(auto &it : a)
                        if(it > m)
                                cnt += it / m;
                if(cnt <= k) {
                        r = m - 1;
                        ans = min(ans, m);
                }
                else {
                        l = m + 1;
                }

        }
        cout << ans;
}

int main() {
        srand(time(0));
        int T = 1;
        if(tc) cin >> T;
        for(int i = 1; i <= T; ++i) {
                #ifndef ONLINE_JUDGE
                cout << "----- " << i << " -----\n";
                #endif
                solve();
        }
        return 0;
}


Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    int a[7];
    for(int i = 0;i<7;i++)
    scanf("%d",&a[i]);
    LL ans=0;
    ans+=a[0]/2*2;
    ans+=a[1];
    ans+=a[3]/2*2;
    ans+=a[4]/2*2;
    if((a[0]&1)&&(a[3]&1)&&(a[4]&1))ans+=3;
    if((a[0]&1)+(a[3]&1)+(a[4]&1)==2&&a[0]&&a[1]&&a[2])ans++;
    printf("%lld\n",ans);
}
/*
1441152
*/

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

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

	map<ll, ll> p;
	rep(i, 3) {
		p[a[i]]++;
		p[b[i]]++;
	}

	ll f= 0, s = 0;
	auto begin = p.begin(), end = p.end();
	for (auto it = begin; it != end; it++) {
		if (it->second == 1) f++;
		if (it->second == 2) s++;
	}

	if (f == 2 && s == 2)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,k;
    cin >> n >> k;
    int r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    vector<int> ctoi(256);
    ctoi['r'] = 2;
    ctoi['s'] = 0;
    ctoi['p'] = 1;

    int a[3] = { r, s, p };

    int ans = 0;

    rep(i,k){
        vector<int> x;
        for(int j=i;j<n;j+=k){
            x.push_back(ctoi[t[j]]);
        }
        vector<int> dp(2);
        int pre=-1;
        for(int nx : x){
            vector<int> p(2);
            swap(dp,p);
            dp[0] = max(p[0],p[1]);
            if(pre == nx){
                dp[1] = p[0]+a[nx];
            }else{
                dp[1] = max(p[0],p[1])+a[nx];
            }
            pre=nx;
        }
        ans += max(dp[0],dp[1]);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1020
//AtCoder ABC111 B - AtCoder Beginner Contest 111
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll N; cin>>N;
    vector<ll> tbl={
        111,222,333,444,555,666,777,888,999,
    };
    ll ans=111;
    for(ll i=1;i<tbl.size();++i){
        if(tbl[i-1]<N&&N<=tbl[i]) {
            ans= tbl[i];
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a;
  cin>>b>>c;
  for(int i=b;i<=c;i++){
    if(i%a==0){
      cout<<"OK";
      return 0;
    }
  }
  cout<<"NG";
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ls(n), rs(n);
    for(int i=0; i<n; i++) cin >> ls.at(i) >> rs.at(i);

    sort(ls.begin(), ls.end());
    sort(rs.begin(), rs.end());
    
    if(n%2)
    {
        cout << rs.at((n-1)/2) - ls.at((n-1)/2) + 1 << endl;
    }
    else
    {
        int lsum = ls.at(n/2-1) + ls.at(n/2);
        int rsum = rs.at(n/2-1) + rs.at(n/2);
        cout << rsum - lsum + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 4788
#include <iostream>

int main(void) {
  int N, K, h[100000];
  std::cin >> N >> K;
  for (int i = 0; i < N; i++) {
    std::cin >> h[i];
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (h[i] >= K) count++;
  }
  std::cout << count << std::endl;
  return 0;
}

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

string a, b;

bool is_integer(double x) {
    return x == floor(x);
}

int main() {
    cin >> a >> b;
    double ab = stoi(a + b);
    double ab_sqrt = sqrt(ab);

    if (is_integer(ab_sqrt)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

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

	int ans = 1, cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		int tmp = 0;
		for (int j = i; j % 2 == 0; j /= 2)
		{
			tmp++;
		}

		if (cnt < tmp)
		{
			ans = i;
			cnt = tmp;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char C;
    cin >> C;
    if ('a' <= C && C <= 'z')
        cout << "a" << endl;
    else
        cout << "A" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  int a=0,k;
  cin>>k;
  bool ok=0;
  for(int i=1;i<=1000000;i++) {
  a=(a*10+7)%k;
  if(a==0) { a=i; ok=1; break; }
  }
  if(ok) { cout<<a; }
  else { cout<<-1; }
  //} 
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x,a,b;
    cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;

    return 0;
}

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




int main() {
  ll h,w;
  cin >> h>>w;
  vector<string> s(h);
  rep(i,h)cin>>s[i];
  vector<vector<ll>> l(h+5, vector<ll> (w+5,0));
  vector<vector<ll>> r(h+5, vector<ll> (w+5,0));
  vector<vector<ll>> u(h+5, vector<ll> (w+5,0));
  vector<vector<ll>> d(h+5, vector<ll> (w+5,0));


  rep(i,h){
    rep(j,w){
      if (s[i][j]=='.'){
        u[i+1][j+1]=u[i][j+1]+1;
        l[i+1][j+1]=l[i+1][j]+1;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if (s[h-1-i][w-1-j]=='.'){
        d[h-i][w-j]=d[h-i+1][w-j]+1;
        r[h-i][w-j]=r[h-i][w-j+1]+1;
      }
    }
  }
  ll ans=0;
  rep(i,h)rep(j,w){
  //  cout<<"i"<<i<<"j"<<j<<endl;
    ll temp=l[i+1][j+1]+r[i+1][j+1]+u[i+1][j+1]+d[i+1][j+1];
  //  cout<<temp<<endl;
    ans=max(ans,l[i+1][j+1]+r[i+1][j+1]+u[i+1][j+1]+d[i+1][j+1]-3);
  }

cout<<ans;
}


Measured memory_bytes: 136768
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

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

	while(true){
		int N=in(),M=in();
		if(!N && !M) break;
		vll C=vecin(M);
		vll X=vecin(N);
		
		vvll dp(N+1,vll(256,1ll<<60));
		dp[0][128]=0;
		REP(i,N){
			REP(j,256){
				REP(k,M){
					int next = max<int>(min<int>(j+C[k],255),0);
					chmin(dp[i+1][next],dp[i][j]+(next-X[i])*(next-X[i]));
				}
			}
		}

		out(*min_element(ALL(dp[N])));
	}
	return 0;
}



Measured memory_bytes: 43824
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(0, min(B, D) - max(A, C)) << endl;
    return 0;
}

Measured memory_bytes: 256