akhauriyash/Code-Regression huggingface dataset:
D,G=map(int,input().split())
G//=100
p=[0]*D
c=[0]*D

for i in range(D):
    p[i],c[i]=map(int,input().split())
    c[i]//=100

ans=10**10
for bit in range(2**D):
    score=G
    problems=0
    SET=set([i for i in range(D)])

    for g in range(D):
        if (bit>>g)&1:
            score-=(g+1)*p[g]+c[g]
            problems+=p[g]
            SET.remove(g)
    
    if score<=0:
        ans=min(ans,problems)
    else:
        #SETが空集合になる時は全ての問題を解いた時であり、全ての問題を解けば必ずscoreは負になるので
        #「ValueError: max() arg is an empty sequence」は防げる。
        MAX=max(SET)
        for _ in range(p[MAX]):
            score-=(MAX+1)
            problems+=1
            if score<=0:
                ans=min(ans,problems)    
                break
print(ans)

Measured memory_bytes: 44124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    vector<int> A = a;
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());

    int res = numeric_limits<int>::max();
    for(int i = 0; i < A.size(); ++i){
        vector<int> tmp = a;
        vector<int> pos;    // 区間を区切る位置
        pos.push_back(0);
        bool flag = true;
        for(int j = 0; j < n; ++j){
            if(flag){
                if(tmp[j] < A[i]){
                    pos.push_back(j);
                    flag = false;
                }
            }
            else{
                if(tmp[j] >= A[i]){
                    pos.push_back(j);
                    flag = true;
                }
            }
        }
        if(flag)    pos.push_back(n);

        int sz = pos.size();
        vector<int> candidates;
        for(int j = 0; j < sz-1; j += 2){
            int len = pos[j+1] - pos[j];
            if(len < k) continue;
            sort(tmp.begin()+pos[j], tmp.begin()+pos[j+1]);
            for(int p = 0; p < len - k + 1; ++p){
                candidates.push_back(tmp[pos[j] + p]);
            }
        }
        if(candidates.size() < q)  continue;
        sort(candidates.begin(), candidates.end());
        chmin(res, candidates[q-1] - A[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def solve():
    for x in range(101):
        for y in range(101):
            for h in range(h_min, h_min + 201):
                for i in range(N):
                    if D[i][0] != max(h - abs(D[i][1] - x) - abs(D[i][2] - y), 0):
                        break
                else:
                    return x, y, h


if __name__ == '__main__':
    N = int(input())
    D = []
    for i in range(N):
        x, y, h = inpl()
        D.append([h, x, y])

    h_min = max(D)[0]
    ans = solve()
    print(' '.join(map(str, ans)))


Measured memory_bytes: 3064
#include<iostream>
#include<string>

int main()
{

	while (true) {
		std::string x;
		std::cin >> x;
		if (x == "0") break;

		int sum = 0;
		for (int i = 0; i < x.size()
			; i++) {
			sum += x[i] - '0';
		}
		std::cout << sum << std::endl;
	}
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int x, a, b;
  cin >> x >> a >> b;

  int ans = x - a;
  while (ans >= b) {
    ans -= b;
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
import java.net.SocketPermission;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), A = in.nextInt(), B = in.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }

        int lo = 0, hi = (int)(1e9 + 10);
        while (hi - lo > 1) {
            int mid = (lo + hi) / 2;
            if (can(h, A, B, mid))
                hi = mid;
            else
                lo = mid;
        }
        System.out.println(hi);
    }

    private static boolean can(int[] hs, long A, long B, long times) {
        long rest = times;
        for (int h : hs) {
            long x = Math.max(0, h - B * times);
            rest -= (x + A - B - 1) / (A - B);
        }
        return rest >= 0;        
    }
}


Measured memory_bytes: 53016
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

fi1 = min(A[0], B[0])
fi2 = min(A[1], B[0] - fi1)
ans = fi1 + fi2
for i in range(1, N):
    fi1 = min(A[i] - fi2, B[i])
    fi2 = min(A[i+1], B[i] - fi1)
    ans += fi1 + fi2
    
print(ans)

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

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){
	int N;
	cin >> N;

	for(int i=1; i<=9; i++){
		int q = N / i;
		int r = N % i;
		if(r == 0 && q >= 1 && q <= 9){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;


int cost[110][110];
int mincost[110];
bool used[110];
int V;

int prim(){
	rep(i,V){
		mincost[i]=INF;
		used[i]=false;
	}
	mincost[0]=0;
	int res = 0;
	
	while(1){
		int v=-1;
		rep(u,V){
			if(!used[u]&&(v==-1||mincost[u]<mincost[v])) v=u;
		}
		
		if(v==-1){
			break;
		}
		used[v]=true;
		res+=mincost[v];
		rep(u,V){
			mincost[u]=min(mincost[u],cost[v][u]);
		}
	}
	return res;
}
					

int main(){
	
	while(cin>>V,V!=0){
		rep(i,V){
			rep(j,V){
				cost[i][j]=INF;
			}
		}
		int m;
		cin>>m;
		rep(i,m){
			int a,b;
			char t;
			cin>>a>>t>>b>>t;
			int c;
			cin>>c;
			c/=100;
			c--;
			cost[a][b]=cost[b][a]=c;
			//cout<<cost[a][b]<<" "<<cost[b][a]<<endl;
		}
		
		cout<<prim()<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long N, long long M, std::vector<long long> u, std::vector<long long> v, long long S, long long T){
  vector<vector<ll>> m(N,vector<ll>());
  REP(M){
    m[u[i]].push_back(v[i]);
  }
  deque<pll> q;
  q.push_back({S,0});
  vector<vector<ll>> used(3,vector<ll>(N,-1));
  used[0][S]=0;
  while(!q.empty()){
    auto tmp=q.back();q.pop_back();
    ll nex=tmp.second+1;
    for (auto &&j : m[tmp.first])
    {
      if(used[nex%3][j]==-1){
        used[nex%3][j]=nex;
        q.push_front({j,nex});
      }
    }
  }
  if(used[0][T]==-1){
    cout<<-1<<endl;
  }else{
    cout<<used[0][T]/3<<endl;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> u(M);
    std::vector<long long> v(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
        --u[i];
        --v[i];
    }
    long long S;
    scanf("%lld",&S);
    long long T;
    scanf("%lld",&T);
    --S;--T;
    solve(N, M, std::move(u), std::move(v), S, T);
    return 0;
}


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

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

int mod=998244353;
int power(int a,int b){
    if(b==0)return 1;
    ll hi=power(a,b/2);
    hi=(hi*hi)%mod;
    if(b%2==0)return hi;
    return (hi*a)%mod;
}
int inverse(int x){
    return power(x,mod-2);
}
ll fact[300010];
int choose(int a,int b){
    if(b>a)return 0;
    ll hi=fact[a];
    hi=(hi*inverse(fact[b]))%mod;
    hi=(hi*inverse(fact[a-b]))%mod;
    //printf("%d %d: %lld\n",a,b,hi);
    return hi;
}

int main() {
    fact[0]=1;
    for(int i=1;i<=300000;i++){
        fact[i]=(fact[i-1]*i)%mod;
    }
    ll n,a,b,k;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    ll ans=0;
    for(int i=0;i<=n;i++){
        if(k-a*i<0)break;
        if((k-a*i)%b!=0)continue;
        ans+=(ll)choose(n,i)*choose(n,(k-a*i)/b);
        ans%=mod;
        //printf("%d: %lld\n",i,ans);
    }
    printf("%lld",ans);
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
N = int(input())
t = [0]
x = [0]
y = [0]
for i in range(N):
  a,b,c = map(int, input().split())
  t.append(a)
  x.append(b)
  y.append(c)
dt = t[i+1]-t[i]
dist = abs(x[i+1]-x[i])+abs(y[i+1]-y[i])
ans = ""
for i in range(N):
  if dt < dist:
    ans = "No"
    break
  if (dt%2 == 0 and dist%2 == 0) or (dt%2 == 1 and dist%2 == 1):
    ans = "Yes"
  else:
    ans = "No"
    break
print(ans)

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   int n;
   cin >> n;
   int a[5] = {0};
   string march = "MARCH";
   rep (i, n) {
      string s;
      cin >> s;
      auto p = march.find(s[0]);
      if (p == string::npos) continue;
      a[p]++;
   }

   ll sum = 0;
   rep (i, 5) {
      repp (j, i+1, 5) {
         repp (k, j+1, 5) {
            sum += 1LL * a[i] * a[j] * a[k];
         }
      }
   }
   cout << sum << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <algorthm>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
const int MAX  = 1<<28;
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int> > map1(n,vector<int>(n,MAX));
  //vector<vector<int> > map2(n,vector<int>(n,MAX));
  for(int i = 0;i < m;i++){
    int a,b,c,d;
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    // cout << a << " "<<  b << " "<< c << " "<<  d << " " << endl;
    map1[a-1][b-1] = c;
    map1[b-1][a-1] = d;
  }
  //  cout << "bababa" << endl;
  int x1,x2,y1,y2;
  //  cin >> x1 >> x2 >> y1 >> y2;  
  scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
  for(int l = 0;l < n;l++){
    for(int i = 0;i < n;i++){
      for(int j = 0;j < n;j++){
	
	if(map1[i][j] > map1[i][l] + map1[l][j]){
	  map1[i][j] = map1[i][l] + map1[l][j];
	}
      }
    }
  }
  cout << y1 - (y2 + map1[x1-1][x2-1] + map1[x2-1][x1-1])  << endl;
  
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  string a;
  cin >> a;
  for(size_t i=0;i<a.size();i++){
    if(a[i]=='1'){
      a[i] = '9';
    }else{
      a[i] = '1';
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int cost[n+1];
    for(int i=0;i<n;i++)cost[i]=1000000000;
    //memset(cost,INT_MAX,sizeof(cost));
    cost[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j==n)break;
            int diff=abs(arr[j]-arr[i]);
            cost[j]=min(cost[j],cost[i]+diff);
        }
    }
    cout<<cost[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B != C || A == C && A != B || B == C && A != B) write("Yes");
    else write("No");
}

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

int main(){
  string s; cin >> s;
  int n = s.length();

  bool dp[n+1];
  for(int i=0; i<=n; i++) dp[i] = false;
  dp[0] = true;
  s = " "+s;

  for(int i=1; i<=n; i++){
    if(i>=5){
      if(s.substr(i-5+1, 5) == "dream") dp[i] = dp[i-5];
      if(s.substr(i-5+1, 5) == "erase") dp[i] = dp[i-5];
    }
    if(i>=6){
      if(s.substr(i-6+1, 6) == "eraser") dp[i] = dp[i-6];
    }
    if(i>=7){
      if(s.substr(i-7+1, 7) == "dreamer") dp[i] = dp[i-7];
    }
  }

  cout << (dp[n]? "YES": "NO") << endl;

  return 0;
}


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

int n, k, x, arr[10];

int f(int n)
{
	while(n){
		if(arr[n%10]){
			return true;
		}
		n /= 10;
	}
	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	cin >> n >> k;
	for(int i=0; i<k; i++){
		cin >> x;
		arr[x] = true;
	}
	
	while(f(n)) n++;
	cout << n << endl;
	
	return 0;
}
	 


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
typedef string::const_iterator Cursol;
int num(Cursol&);
string calc(Cursol&);
string expr(Cursol&);

int pos ;

int num(Cursol& p){
  int ret = 0;
  while(isdigit(*p)){
    ret = ret * 10 + *p - '0';
    p++;
  }
  return ret;
}

string calc(Cursol& p){
  string ret;
  if(isdigit(*p)){
    int number = num(p);
    if( *p == '(') {
      string res = expr(++p);
      p++;
      while(number--){
        ret += res;
        if(pos < ret.size()) break;
      }
    } else {
      ret.insert(ret.end(), min( pos + 1, number), *p++);
    }
  }else{
    while(isalpha(*p)){
      ret += *p++;
      if(pos < ret.size()) break;
    }
  }
  return ret;
}


string expr(Cursol& p){
  string ret;
  while( isalpha(*p) || isdigit(*p)){
    ret += calc(p);
    if(pos < ret.size()) break;
  }
  return ret;
}
int main(){
  string str;
  while(cin >> str >> pos, str!="0"||pos){
    Cursol idx = str.begin();
    string ret = expr(idx);
    if(pos < ret.size()) cout << ret[pos] << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 6096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1){
  for(int u:to[v]){
	if(u==p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}
int main() {
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  //cout << to[3][0] << endl;
  ans.resize(n);
  rep(i,q){
    int p,x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n){
    
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 23424
#include <iostream>

using namespace std;

const int A_MAX = 100000;
long long array[100000];

int main() {
    int N;
    long long K;
    cin >> N >> K;

    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        array[a - 1] += b;
    }

    for (int k = 0; k < A_MAX; ++k) {
        if (K <= array[k]) {
            cout << k + 1 << endl;
            break;
        }
        K -= array[k];
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int x;
    cin>>x;
    ll ans=0;
    for(int i=1;i<=x;++i){
        for(int j=1;j<=x;++j){
            ll t=gcd(i,j);
            for(int k=1;k<=x;++k){
                ans+=gcd(t,k);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3616
t1 = [0]*1001
t2 = [0]*1001

while 1:
    try:
        a, b = map(int, input().split(','))
        t1[a] += 1
    except:
        break

while 1:
    try:
        a, b = map(int, input().split(','))
        t2[a] += 1
    except:
        break

for i in range(1001):
    if t1[i] > 0 and t2[i] > 0:
        print(i, t1[i]+t2[i])



Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int A[100000];
int dp[100000];

int f(int i) {
  if(dp[i] != -1) return dp[i];
  return dp[i] = min( f(i - 1) + abs(A[i] - A[i - 1]),
                     i > 1 ? abs(A[i] - A[i - 2]) + f(i - 2) : (int) 2e9);
}

int main() {
  int n; cin >> n;
  for(int i = 0; i < n; ++i)
    cin >> A[i];
  memset(dp, -1, sizeof dp);
  dp[0] = 0;
  cout << f(n - 1);
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool p[101];
vector<int> prime; 
int main()
{
	fill (p, p + 101, true);
	p[0] = false;
	p[1] = false;
	for (int i = 2; i < 101; ++i){
		if (p[i]){
			for (int j = 2 * i; j < 101; j += i){
				p[j] = false;
			} // end for
		} // end if
	} // end for

	prime.clear();
	for (int i = 2; i < 101; ++i){
		if (p[i]){
			prime.push_back(i);
		} // end if
	} // end for
	int m = (int)prime.size();
	vector<int> e(m, 0);

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int N; cin >> N;
	for (int i = 2; i <= N; ++i){
		int n = i;
		rep (j, m){
			while (n % prime[j] == 0 && n > 0){
				++e[j];
			 	n /= prime[j];
			} // end while
		} // end rep
	} // end for
/*
	rep (j, m){
		cerr << e[j] << ' ';
	} // end rep
	cerr << endl;
*/
	int res = 0;
	// e[j] + 1 >= 75 のものを見つける
	rep (j, m){
		if (e[j] + 1 >= 75){
			++res;
		} // end if
	} // end rep
//	cerr << "res: " << res << endl;

	// e[j] + 1 >= 3, e[j'] + 1 >= 25 のものを見つける
	int curr3 = 0, curr25 = 0;
	rep (j, m){
		if (e[j] + 1 >= 3){
			++curr3;
		} // end if
		if (e[j] + 1 >= 25){
			++curr25;
		} // end if
	} // end rep
	res += curr25 * (curr3 - 1);
//	cerr << "res: " << res << endl;

	// e[j] + 1 >= 3 を一つ e[j] + 1 >= 5 のものを二つ見つける
	int curr5 = 0;
	rep (j, m){
		if (e[j] + 1 >= 5){
			++curr5;
		} // end if
	} // end rep
	res += curr5 * (curr5 - 1) / 2 * (curr3 - 2) ;
//	cerr << "res: " << res << endl;

	// e[j] + 1 >= 15 を一つ、e[j] + 1 >= 5 のものを見つける	
	int curr15 = 0;
	rep (j, m){
		if (e[j] + 1 >= 15){
			++curr15;
		} // end if
	} // end rep

	res += curr15 * (curr5 - 1);
//	cerr << "res: " << res << endl;

	cout << res << endl; 

	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int cnt=0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i]=='-')cnt--;
        else cnt++;
    }
    cout << cnt;
}



Measured memory_bytes: 3568
import numpy as np
import copy

h, w = map(int, input().split())
a = [input() for _ in range(h)]

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))


Measured memory_bytes: 30088
import sys

def solve():
    input = sys.stdin.readline
    N, P = map(int, input().split())
    S = list(input().strip("\n"))

    if P == 2 or P == 5:
        count = 0
        for i in range(N):
            s = int(S[N - 1 - i])
            if s % P == 0: count += N - i
        print(count)
    else:
        modDict = dict()
        modDict[0] = 1
        sSum = 0
        for i in range(N):
            s = int(S[N - 1 - i])
            sSum += s * pow(10, i, P)
            sSum %= P
            if sSum in modDict: modDict[sSum] += 1
            else: modDict[sSum] = 1
        count = 0
        for key in modDict:
            count += modDict[key] * (modDict[key] - 1) // 2
        print(count)
            

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 5412
<?php

$days = explode(',', '0,31,60,91,121,152,182,213,244,274,305,335');
$format = explode(',', 'Wednesday,Thursday,Friday,Saturday,Sunday,Monday,Tuesday');
while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%d %d', $m, $d);
    if ($m === 0) {
        break;
    }

    $n = $days[$m - 1] + $d;
    $today = $format[$n % 7];
    echo $today, PHP_EOL;
}

Measured memory_bytes: 6580
S=input()
s0=int(S[:2])
s1=int(S[2:])
if s0 in range(1, 13) and s1 in range(1, 13):
  print('AMBIGUOUS')
elif s0 in range(1, 13):
  print('MMYY')
elif s1 in range(1,13):
  print('YYMM')
else:
  print('NA')

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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;

  long long n;
  cin >> n;
  n--;
  string res = "";
  do {
    int reminder = n % 26;
    n /= 26;
    n--;
    res += ('a' + reminder);
  } while (n >= 0);
  reverse(res.begin(), res.end());
  cout << res << "\n";

  return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int k, s, ans = 0;
	cin >> k >> s;
	for(int i = 0;i <= k;i++){
		for(int j = 0;j <= k;j++){
			if(s - (i + j) <= k && s - (i + j) >= 0) ans++;
		}
	}

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

Measured memory_bytes: 256
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    s = list(input())
    result = [s.count("a"), s.count("b"), s.count("c")]
    tmp = min(result)
    for i in result:
        if i - tmp > 1:
            print("NO")
            exit(0)

    print("YES")


if __name__ == '__main__':
    main()


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 3e3 + 5;
ll mod = 998244353;
ll a[N], dp[N][N], pre[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        ll n, k;
        cin >> n >> k;
        for (int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for (int i = 1; i <= n; i++){
                for (int j = k; j >= 1; j--){
                        if (j >= a[i]) {
                                (dp[i][j] = pre[j - a[i]]) %= mod;
                                (pre[j] += dp[i][j]) %= mod;
                        }
                }
                (pre[a[i]] += i) %= mod;
                (dp[i][a[i]] += i) %= mod;
        }
        ll ans = 0;
        for (int i = 1; i <= n; i++){
                ans = (ans + dp[i][k] * (n - i + 1)) % mod;
        }
        cout << ans;
}


Measured memory_bytes: 70656
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N = readint()[1]
  keta = length(string(N))
  
  S = Array{int,2}(undef,9,9)
  S .= 0
  
  a = parse(int,string(N)[1])
  b = parse(int,string(N)[end])
  for i in 1:9
    for j in 1:9
      for k in 1:keta
        if k == 1
          i == j && i <= N && (S[i,j] += 1)
        elseif k == 2
          if i*10+j <= N
            S[i,j]+=1
          end
        elseif k == keta
          c = parse(int,string(N)[2:end-1])

            
          if i == a
              
            if j <= b
              S[i,j] += c+1
            else
              S[i,j] += max(c,0)
            end
          elseif i < a         
            S[i,j] += 10^(k-2)
          end
        else
          S[i,j] += 10^(k-2)
        end
          
      end
    end
  end
  
  s = 0
  for i in 1:9, j in 1:9
    s += S[i,j]*S[j,i]
  end
  println(s)
end



main()

Measured memory_bytes: 196696
n = int(input())
l = list(map(int,list(str(n))))
#print(l)
x = int(str(l[0])+str(l[0])+str(l[0]))
y = int(str(l[0]+1)+str(l[0]+1)+str(l[0]+1))

if n <= x:
    print(x)
else:
    print(y)




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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll N;
ll D[2];
vector<P> ds[2];
ll col[2][606][606];
vector<P> cnt[4];

void dfs(int d,int i,int j,int crtcol){
  col[d][i][j]=crtcol;
  for(P dlt : ds[d]){
    rep(dir,4){
      int di=dlt.fi,dj=dlt.se;
      if(dir%2)di=-di;
      if(dir/2)dj=-dj;
      int ni=i+di,nj=j+dj;
      if(ni<0||ni>=2*N||nj<0||nj>=2*N||col[d][ni][nj]!=-1)continue;
      dfs(d,ni,nj,1-crtcol);
    }
  }
}

int main(){
  cin>>N;
  rep(i,2)cin>>D[i];
  rep(i,2){
    for(ll x=0;x*x<=D[i];x++){
      for(ll y=0;x*x+y*y<=D[i];y++){
        if(x*x+y*y==D[i]){
          ds[i].push_back(P(y,x));
        }
      }
    }
  }
  memset(col,-1,sizeof(col));
  rep(d,2){
    rep(i,N*2)rep(j,N*2){
      if(col[d][i][j]==-1){
        dfs(d,i,j,0);
      }
    }
  }

  rep(i,N*2)rep(j,N*2){
    cnt[((col[0][i][j]==1)<<1)|(col[1][i][j]==1)].push_back(P(i,j));
  }
  rep(i,4){
    if(cnt[i].size()>=N*N){
      rep(j,N*N){
        cout<<cnt[i][j].se<<" "<<cnt[i][j].fi<<endl;
      }
      return 0;
    }
  }

  return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 1e8;
    for(int i = 1; i <= 100;++i){
        int sum = 0;
        rep(j,n) sum += (x[j]-i)*(x[j]-i);
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main(){
     string S;
     int A,B,s;
     cin >> S;
     s = stoi(S);
     A = s / 100;
     B = s % 100;
     if((A > 0) && (A <= 12)){
          if((B > 0) && (B <= 12)){
               cout << "AMBIGUOUS" << endl;
          }else{
               cout << "MMYY" << endl;
          }
     }else{
          if((B > 0) && (B <= 12)){
               cout << "YYMM" << endl;
          }else{
               cout << "NA" << endl;
          }
     }
     return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr64()
	L := list[0]
	R := list[1]

	var min int64 = int64(math.MaxInt32)
	var i int64 = 0
	var j int64 = 0
	for i = L; i <= R-1 && i < L+2018; i++ {
		for j = L + 1; j <= R && j < L+2019; j++ {
			if i == j {
				continue
			}
			var n int64 = (i * j) % 2019
			if min > n {
				min = n
			}
		}
	}
	fmt.Printf("%d\n", min)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1796
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int q=sc.nextInt();
		long[] a1=new long[a+2];
		long[] b1=new long[b+2];
		a1[0]=b1[0]=Long.MIN_VALUE;
		a1[a+1]=b1[b+1]=Long.MAX_VALUE/2;
		long[] ans1=new long[q];
		for(int i = 1; i<=a; i++){
			a1[i]=sc.nextLong();
		}
		for(int i = 1; i<=b; i++){
			b1[i]=sc.nextLong();
		}
		for(int k = 0; k<q; k++){
			long x=sc.nextLong();
			long ans=Long.MAX_VALUE;
			int idxa=-Arrays.binarySearch(a1,x)-1;
			int[] a2={idxa,(idxa==1)? a+1:idxa-1};
			int idxb=-Arrays.binarySearch(b1,x)-1;
			int[] b2={idxb,(idxb==1)? b+1:idxb-1};
			for(int i:a2){
				for(int j:b2){
					ans=Math.min(ans,Math.abs(a1[i]-x)+Math.abs(a1[i]-b1[j]));
					ans=Math.min(ans,Math.abs(b1[j]-x)+Math.abs(a1[i]-b1[j]));
				}
			}
			ans1[k]=ans;
		}
		for(int i = 0; i<q; i++){
			System.out.println(ans1[i]);
		}
	}
}

Measured memory_bytes: 99156
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10,9)+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
 //cout << setprecision(15) << std::fixed;



int main() {
    int n;
    cin >> n;
    vec x(n);
    for (int i = 0;i < n;i++) {
        cin >> x[i];
    }
    ll ans = INF;
    for (int i = 1;i <= 100;i++) {
        ll cut = 0;
        for (int j = 0;j < n;j++) {
            cut += (x[j] - i) * (x[j] - i);
        }
        ans = min(cut, ans);
    }
    print(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

int n;
cin>>n;

int m =0;

int n1=n;

while(n1!=0){
m = m+(n1%10);
n1=n1/10;

}
if(!(n%m)){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;

}

return 0;
}


Measured memory_bytes: 3544
hmk = input('')

h1 = int(hmk.split(' ')[0])
m1 = int(hmk.split(' ')[1])
h2 = int(hmk.split(' ')[2])
m2 = int(hmk.split(' ')[3])
k = int(hmk.split(' ')[4])

min1 = h1*60 + m1
min2 = h2*60 + m2

if min1 > min2:
    min2+=60*24

a = min2 - min1 - k
print(a)

Measured memory_bytes: 9140
#include<iostream>

int main(){
    int cnt5 = 0, cnt7 = 0;
    for(int i = 0; i < 3; i++){
        int tmp;
        std::cin >> tmp;
        if(tmp == 5) cnt5++;
        else if(tmp == 7) cnt7++;
    }

    if(cnt5 == 2 && cnt7 == 1){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
    return 0;
}


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

int main() {
    ll N, K, S;
    cin >> N >> K >> S;

    if (K == 0) {
        rep(i, N) {
            if (i) cout << " ";
            cout << S-1;
        }
        cout << endl;
        return 0;
    }

    if (N >= K) {
        rep(i, K) {
            if (i) cout << " ";
            cout << S;
        }
        rep(i, N-K) {
            cout << " ";
            if (S == 1) {
                cout << 1000000;
            }else {
                cout << S-1;
            }
        }
        cout << endl;
    }
    else {

        rep(i, N) {
            if (i) cout << " ";
            cout << 1000000000000;
        }
        cout << endl;


        // int tmp = 2;
        // cout << S << " ";
        // rep(i, (K-2)/2) {
        //     cout << 0 << " ";
        //     tmp++;
        // }
        // cout << S << " ";
        //
        // if (K%2) {
        //     cout << 0 << " ";
        //     tmp++;
        // }
        // rep(i, N-tmp) {
        //     if (i) cout << " ";
        //     if (S == 1) {
        //         cout << 1000000;
        //     }else {
        //         cout << S-1;
        //     }
        // }
        // cout << endl;
        //
        //

    }
}


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

int main(){
    int h, w, m;
    cin >> h >> w >> m;

    int cou_h[h], cou_w[w];
    for(int i = 0; i < h; i++){
        cou_h[i] = 0;
    }
    for(int i = 0; i < w; i++){
        cou_w[i] = 0;
    }
    map<pair<int, int> , int> ma;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        auto itr = ma.find(make_pair(a, b));
        if(itr == ma.end()){
            pair<int, int> c = make_pair(a, b);
            ma[c] = 1;
        }

        cou_h[a]++;
        cou_w[b]++;
    }

    int ans = -1;
    vector<int> v_h;
    for(int i = 0; i < h; i++){
        if(ans < cou_h[i]){
            ans = cou_h[i];
            v_h.clear();
            v_h.push_back(i);
        }else if(ans == cou_h[i]){
            v_h.push_back(i);
        }
    }

    int k = -1;
    vector<int> v_w;
    for(int i = 0; i < w; i++){
        if(k < cou_w[i]){
            k = cou_w[i];
            v_w.clear();
            v_w.push_back(i);
        }else if(k == cou_w[i]){
            v_w.push_back(i);
        }
    }

    int che = 0;
    int size_h = v_h.size();
    int size_w = v_w.size();
    for(int i = 0; i < size_h; i++){
        for(int j = 0; j < size_w; j++){
            auto itr = ma.find(make_pair(v_h[i], v_w[j]));
            if(itr == ma.end()){
                che = 1;
                break;
            }
        }

        if(che == 1){
            break;
        }
    }

    if(che == 1){
        cout << ans + k << endl;
    }else{
        cout << ans + k - 1 << endl;
    }
}

Measured memory_bytes: 28492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
  string n;
  cin >> n;
  int total=0;
  REP(i,0,n.length()){
    total += n[i]-'0';
  }
  if(total%9 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
#include<set>
#define int long long
#define mod 1000000007
using namespace std;

int a[1000], b[1000];
signed main() {
	set<int>p, q;
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) { cin >> a[i]; p.insert(a[i]); }
	for (int i = 0; i < m; i++) { cin >> b[i]; q.insert(b[i]); }
	if (p.size() != n || q.size() != m) {
		puts("0");
		return 0;
	}
	sort(a, a + n, greater<int>());
	sort(b, b + m, greater<int>());
	int x = 0, y = 0;
	int ans = 1;
	for (int i = n*m; i >= 1; i--) {
		while (x <= n - 1) {
			if (a[x] <= i)break;
			x++;
		}
		while (y <= m - 1) {
			if (b[y] <= i)break;
			y++;
		}
		if (a[x] == i) {
			if (b[y] != i) {
				ans *= y;
				ans %= mod;
			}
		}
		else  {
			if (b[y] == i) {
				ans *= x;
				ans %= mod;
			}
			else {
				ans *= (x*y - (n*m - i));
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == '1') ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
package main

import (
	"fmt"
)

func main() {
	var N, Q, l, r int
	var S string
	fmt.Scan(&N, &Q)
	fmt.Scan(&S)
	t := make([]int, N)

	for i := 0; i < N-1; i++ {
		w := 0
		if S[i:i+2] == "AC" {
			w = 1
		}
		t[i+1] = t[i] + w
	}

	for i := 0; i < Q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(t[r-1] - t[l-1])
	}

}

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

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int y, m, d;
  char a, b;
  cin >> y >> a >> m >> b >> d;
  int date = m * 100 + d;
  if(date <= 430) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a!=b && b!=c && c!=a){
    cout << 3 << endl;
  }
  else if(a==b && b==c){
    cout << 1 << endl;
  }
  else{
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll longINF=3e18;
const double eps=1e-8;
const double dinf=190.0;
const double pi=acos(-1);
const int INF=2e9+1;

int n;
        
int main() 
{        
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        cin>>n;
        int x=1;
        while ((x<<1)<=n)
                x<<=1;
        cout<<x;
        return 0;
}

Measured memory_bytes: 256
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y, x%y)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        # nを合う数字で割り切れたら、その割った数と商をリストに追加する。
        # nが平方数のとき、同じ数字が2回追加されてしまうので3行したのif文がある
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N,K = map(int,input().split())
a_list = list(map(int,input().split()))

sums = sum(a_list)
divisors = make_divisors(sums)
divisors.reverse()

def func():
    for d in divisors:
        amaris = [a%d for a in a_list]
        amaris.sort()
        amaris.reverse()
        amari_sum = sum(amaris)
        hanten_cnt = int(amari_sum / d)
        sousa_cnt = 0
        for i in range(hanten_cnt):
            sousa_cnt += d - amaris[i]
        if sousa_cnt <= K:
            return d

result = func()

print(result)

Measured memory_bytes: 42220
///created: 4/Jul/2019 21:24:00

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int modulo = 1e9 + 7;

#ifdef LOCAL_DEBUG_NTV1612
template<class __Ty>
string to_string(__Ty a) {
	string res = "[ ";
	bool f = true;
	for (auto &p : a) { res += (f ? string("") : string(", ")) + to_string(p); f = false;	}
	return res + " ]";
}
void _debug() { fprintf(stderr, "\n"); }
template<typename __Ty_head, typename... __Ty_tail>
void _debug(__Ty_head head, __Ty_tail... tail) { fprintf(stderr, "%s ", to_string(head).c_str()); _debug(tail...); }
#define debug(...) fprintf(stderr, "DEBUG [%s]: ", #__VA_ARGS__), _debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

template<class __Ty> bool mini(__Ty& a, __Ty b) { return a > b ? ((a = b) | 1) : (0); }
template<class __Ty> bool maxi(__Ty& a, __Ty b) { return a < b ? ((a = b) | 1) : (0); }
template<class __Ty> __Ty add(__Ty a, __Ty b) { return (a + b) % (__Ty(modulo)); }
template<class __Ty> __Ty sub(__Ty a, __Ty b) { __Ty m(modulo); return ((a - b) % m + m) % m; }

const int N = 2e5 + 5;
int n, k, cnt[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	memset(cnt, 0, sizeof cnt);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cnt[i % k]++;
	ll ans = 0;
	for (int i = 0; i < k; ++i) {
		if ((i + i) % k == 0)
			ans += 1LL * cnt[i] * cnt[i] * cnt[i];
	}
	cout << ans;
	return 0;
}


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

int main(void) {
    string s, ans;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') ans += '0';
        if (s[i] == '1') ans += '1';
        if (s[i] == 'B' && !ans.empty()) ans.erase(ans.size() - 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 764
#include <iostream>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main(){
	long long int n, a, b, x[100005], ans;
	cin >> n >> a >> b;
	ans = 0;
	REP(i,n) cin >> x[i];
	for (int i=0; i<n-1; i++){
		ans += min(b, a*(x[i+1]-x[i]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
<?php
	fscanf(STDIN, "%d", $N);
	$H = explode(' ',trim(fgets(STDIN)));

	$max = 0;
	$count = 0;
	for ($i = 0; $i < $N-1; $i++) {
      
      if ($H[$i] >= $H[$i+1]) {
        $count++;
      } else {
        $max = max($max, $count);
        $count = 0;
      }
    }

	if ($count !== 0) {
		$max = max($max, $count);
    }
	echo ($max);
?>

Measured memory_bytes: 22076
n = int(input())
d = dict()

for _ in range(n):
    s = "".join(sorted([x for x in input()]))
    d[s] = d.get(s, 0) + 1

ans = 0

for v in d.values():
    if v >= 2:
        ans += (v * (v-1)) // 2

print(ans)


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  
  for(int i=0; i<N; i++){
    cout << vec.at(i) << endl;
  }
  
  
  
  
}

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

int main(){

  int n, a[100000], x, ans=0, b[100002]={0};
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
    b[a[i]]++;
    b[a[i]+1]++;
    b[a[i]+2]++;
  }

  for(int i=0; i<100002; i++){
    if(ans<b[i]){
      ans=b[i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024