akhauriyash/Code-Regression huggingface dataset:
w, h, n = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(n)]

field = [[1 for _ in range(w)] for _ in range(h)]

for x, y, a in xya:
        for i in range(h):
             for j in range(w):
                    if a == 1 and j < x:
                        field[i][j] = 0
                    if a == 2 and j >= x:
                        field[i][j] = 0
                    if a == 3 and i < y:
                        field[i][j] = 0
                    if a == 4 and i >= y:
                        field[i][j] = 0

ans = 0
for i in field:
    ans += sum(i)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  long long int h,n;
  cin>>h>>n;
  long long int inp;
  long long int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>inp;
    sum=sum+inp;
  }
  if(sum>=h)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
  return 0;
}

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

const ll INF=1e18;

int n,a,b;
ll ans=0;
ii arr[100005];

ll pref[100005];
ll suf[100005];

priority_queue<ll> pq;

int main(){
	cin>>n>>a>>b;
	
	ll A,B,C;
	for (int x=0;x<n+a+b;x++){
		cin>>A>>B>>C;
		ans+=A;
		arr[x]=ii(B-A,C-A);
	}
	
	sort(&arr[0],&arr[n+a+b],[](ii i,ii j){
		if (i.first!=j.first) return i.first>j.first;
		else return i.second<j.second;
	});
			
	//for (int x=0;x<n+a+b;x++) cout<<arr[x].first<<" "<<arr[x].second<<endl;
	
	for (int x=0;x<a;x++){
		pref[x]=arr[x].first+(x?pref[x-1]:0);
		pq.push(arr[x].second-arr[x].first);
	}
	for (int x=a;x<a+b;x++){
		pref[x]=pref[x-1]+arr[x].first;
		pq.push(arr[x].second-arr[x].first);
		pref[x]+=pq.top();
		pq.pop();
	}
	
	while (!pq.empty()) pq.pop();
	for (int x=n+a+b-1;x>=a+b;x--) pq.push(arr[x].second);
	for (int x=a+b-1;x>=a;x--){
		suf[x]=suf[x+1];
		pq.push(arr[x].second);
		suf[x]+=pq.top();
		pq.pop();
	}
	
	ll best=-INF;
	
	for (int x=a-1;x<a+b;x++){
		best=max(best,pref[x]+suf[x+1]);
	}	
	
	//cout<<endl;
	//for (int x=0;x<n+a+b;x++) cout<<pref[x]<<" "<<suf[x]<<endl;

	cout<<ans+best<<endl;
}

Measured memory_bytes: 3448
import java.util.*

fun main(args: Array<String>){
	val sc = Scanner(System.`in`)
  	val today = sc.next()
  	print(when(today){
      "Sunny" -> "Cloudy"
      "Cloudy" -> "Rainy"
	  "Rainy" -> "Sunny"
      else -> "unreachable"
    })
}


Measured memory_bytes: 29480
function Main(input){
  var n = input.split("\n");
  var N = n[0].split(" ")[0];
  var X = n[0].split(" ")[1];
  var L = n[1].split(" ");
  var D = 0;
  var count = 1;
  for(i=0;i<=(N-1);i++){
    L[i] = parseInt(L[i],10);
  }
  for(j=0;D<=X;j++){
    D += L[j];
    count += 1;
  }
  count -= 1;
  console.log(count);
}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	ll ans = 0;
	for (int D = 1; D <= N; ++D) {
		ll X = N / D;
		ans += D * X * (X+1) / 2;
	}
	print(ans);
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n;
    cin >> n;
    int v[n];
    bool vis[n] = {};
    fore(i,0,n) cin >> v[i];
    int cnt = 0, i = 0;
    while (i != 1) {
        if (vis[i]) {
            cnt = -1;
            break;
        }
        vis[i] = true;
        i = v[i]-1;
        cnt++;
    }
    cout << cnt << endl;
}


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

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long> a(n+1);
  
  for(int i=0;i<=n;i++){
   cin >> a[i];
  }
  a[n]=0;
  
  sort(a.begin(),a.end());
 
  long h=0,w=0;
  long cnt=1;
  for(int i=n-1;i>=0;i--){
   if(a[i]==a[i+1]){ cnt++;
   }
   else{ if(!h&&cnt>=4){ 
            h=w=a[i+1];
            break;
         }
         else if(h&&cnt>=2) {
            w=a[i+1];
            break;
         }
         else if(!h&&cnt>=2){
            h=a[i+1];
         }     
      cnt=1;
       }
                        
  }
  cout << h*w << endl;
  
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		long total = 0;

		for(int i = 1; i <= k; i++) {
			for(int j = 1; j <= k; j++) {
				for(int l = 1; l <= k; l++) {
					total += gcd(gcd(i,j),l);
				}
			}
		}

		System.out.println(total);
	}

	static int gcd(int a, int b){
		int tmp;

		while (a % b != 0)
		{
			tmp = b;
			b = a % b;
			a = tmp;
		}
		return b;
	}

}


Measured memory_bytes: 27204
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int c = n - 10*(n/10);
	if (n / 10 == 9)cout << "Yes";
	else if (c == 9)cout << "Yes";
	else cout << "No";
	cout << endl;

	return 0;
}

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

using Graph = vector<vector<int>>; //グラフ型

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        ll a1;
        cin >> a1;
        a1--;
        a[i] = a1;
    }
    vector<ll> b;
    b.push_back(0);
    map<ll,int> m;
    m[0]++;
    ll last = -1;
    for(ll i=0;i<n;i++){
        b.push_back(a[b.back()]);
        m[b.back()]++;
        if(m[b.back()]==2){
            last = b.back();
            break;           
        }
    }
    /*
    cout << "last " << last << endl;
    
    for(auto x:b){
        cout << x+1 << " ";
    }
    cout << endl;
    */
    ll start = 2;
    ll end = 2;
    ll cnt = 0;
    for(ll i=0;i<n;i++){
        if(cnt==0){
            if(b[i] == last){start = i;cnt++;}
        }else{
            if(b[i] == last){end = i;break;}
        }
    }
    //cout << start << " " << end << endl;
    b.pop_back();
    ll period = end - start;
    /*
    vector<ll> peice(period);
    ll j = 0;
    for(int i=start;i<end;i++){
        peice[j] = b[i];
        j++;
    }
    */
    /*
    for(auto x:peice){
        cout << x+1 << " ";
    }
    cout << endl;
    */
    
    //cout << period << endl;

    k;
    ll firstturn = start;
    if(firstturn>=k){
        cout << b[k] + 1 << endl;
        return 0;
    }else{
        k -= firstturn;
        ll d = k%period;
        cout << b[firstturn+d] + 1 << endl;
        return 0;
    }
    

}

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

int main(){
    int K, S;
    cin >> K >> S;
    int counter = 0;
    for(int x =0; x <=K ; x++){
        for(int y =0; y <=K; y++){
            int z = S - x - y;
            if(z >= 0 && z <= K){
                counter ++;
            } 
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
const ll MOD=1000000007;
ll N;
ll ga, sa, ba, gb, sb, bb;
ll dp[4][25000010];
ll solve(ll x, vector<P> v){
    rep(i,0,3){
        rep(j,0,x+1){
            dp[i][j]=j;
        }
    }
    rep(i,0,3){
        rep(j,0,x+1){
            if(j<v[i].fr) dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j], dp[i+1][j-v[i].fr]+v[i].sc);
        }
    }
    return dp[3][x];
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    cin>>ga>>sa>>ba>> gb>> sb>> bb;
    vector<P> x(3);
    x[0]=P(ga, gb);
    x[1]=P(sa,sb);
    x[2]=P(ba, bb);
    N=solve(N,x);
    x[0]=P(gb, ga);
    x[1]=P(sb,sa);
    x[2]=P(bb, ba);
    N=solve(N,x);
    cout <<N<<"\n";
}

Measured memory_bytes: 781568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int r[18][100010];

int pow2(int n) {
    int ret = 1;
    rep(i, n) ret *= 2;
    return ret;
}

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

    vector<int> x;
    inputVector(x, n);
    
    int L, Q;
    cin >> L >> Q;

    set<int> s;
    map<int, int> m;
    rep(i, n) {
	s.insert(-x[i]);
	m[x[i]] = i;
    }
    rep(i, n) {
	int border = -x[i] - L;
	auto it = s.lower_bound(border);
	int index = m[-*it];
	r[0][i] = index;
    }

    for (int i = 1; i < 18; i++) {
	rep(j, n) {
	    r[i][j] = r[i - 1][r[i - 1][j]];
	}
    }

    rep(i, Q) {
	int a, b;
	cin >> a >> b;
	a--; b--;

	if (a > b) swap(a, b);

	int ret = 0;
	while (true) {
	    int plus = 0;
	    rep(i, 18) {
		if (r[i][a] >= b) {
		    plus = i;
		    break;
		}
	    }
	    if (plus <= 1) {
		ret += pow2(plus);
		break;
	    }

	    ret += pow2(plus - 1);

	    a = r[plus - 1][a];
	}
	cout << ret << endl;
    }

    return 0;
}


Measured memory_bytes: 26612
#include<iostream>
using namespace std;
int main(){
int a;
cin>>a;
for(int i=1;i<=a;i++){
  int j=i;  
    if(i%3==0){
      cout<<' '<<i;
    }
    else{
  while(true){
  if(j%10==3){
    cout<<' '<<i;
    break;
  }
    j/=10;
    if(j==0)
    break;
  }
  
}


}
cout<<'\n';
return 0;
}

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

ue = 1
for i in A:
    ue *= i

shita = 0
for i in range(N):
    tmp = 1
    for j in range(N):
        if i == j: continue
        tmp *= A[j]
    shita += tmp

print(ue/shita)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int main() {
    string L; cin >> L;

    vector<vector<mint>> dp(L.size() + 1, vector<mint>(2, 0));
    dp[0][0] = 1;
    REP(i, 0, L.size()) {
        dp[i + 1][0] += dp[i][0] * ((L[i] == '1') ? 2 : 1);
        dp[i + 1][1] += dp[i][1] * 3;
        dp[i + 1][1] += ((L[i] == '1') ? dp[i][0] : 0);
    }

    cout << dp[L.size()][0] + dp[L.size()][1] << endl;

    return 0;
}

Measured memory_bytes: 8784
import copy
INFTY=1000000000
MAX = 1000
VMAX = 100000

def solve(W,N,VMAX):
    T = [-1 for _ in range(VMAX)]
    for i in range(N):
        ans = 0
        V = [False for _ in range(N)]
        WW=copy.deepcopy(W)
        WW.sort()
        for i in range(N):
            T[WW[i]] = i
        for i in range(N):
            if V[i]:
                continue
            cur = i
            S = 0
            m = VMAX
            an = 0
            while True:
                V[cur] = True
                an += 1
                v = W[cur]
                m = min(m,v)
                S += v
                cur = T[v]
                if V[cur]:
                   break
            ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
    return ans

N = int(input())
W = list(map(int,input().split()))
s = min(W)
ans = solve(W,N,VMAX)
print(ans)


Measured memory_bytes: 7172
#include <stdio.h>

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

Measured memory_bytes: 580
# A, B, C からなる長さ N の文字列 S と、1 以上 N 以下の整数 K が与えられます。
# 文字列 S の K 文字目を小文字に書き換え、新しくできた S を出力してください。

nk = gets.chomp.split
n = nk[0].to_i
k = nk[1].to_i

s = gets.chomp
s[k-1] = s[k-1].downcase

puts s

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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 600001;
const int MOD = 1e9 + 7;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int a[301][301];

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    mt19937 mt(234793824);
    auto solve = [&mt](int _) {
        int x;
        cin >> x;
        for (int n = 1; n <= 360; ++n) {
            if (x * n % 360 == 0) {
                cout << n;
                return;
            }
        }
    };


    fast_io();

    cout.precision(9);
    cout <<
         fixed;
    for (int i = 1; i <= 1; ++i)
        solve(1);


}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;bool b[10];
int main(){
  int n,m;
  cin>>n>>m;
  string s[n];
  r(i,n)cin>>s[i];
  sort(s,s+n);
  r(i,n)cout<<s[i];cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S,T;
    cin >> S >> T;
    T.pop_back();
    if(S == T){
        cout <<"Yes" << endl;
    }else{
        cout <<"No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
#! /usr/bin/env python3

n, k = map(int, input().split())
n = max(0, n-2)
ans = 0
h = [sum((63*i+9*j+81) % 11 == k for j in range(5))for i in range(min(n, 11))]
ans = sum(h) * (n // 11) + sum(h[i] for i in range(n % 11))
print(ans)

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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
ll n;
ll p;
string str;
ll s[maxn];

//check T
void solve()
{
	cin >> n >> p;
	cin >> str;
	rep(i, 0, n) s[i] = str[i]-'0';
	if(p == 2)
	{
		ll ans = 0;
		rep(i, 0, n) if(s[i]%2 == 0) ans += (i+1);
		cout << ans << endl;
		return;
	}
	if(p == 5)
	{
		ll ans = 0;
		rep(i, 0, n) if(s[i]%5 == 0) ans += (i+1);
		cout << ans << endl;
		return;
	}
	//suf[i] === suf[j] mod p
	map<ll, ll> cnt;
	++cnt[0];
	ll ans = 0;
	int suf = 0, p10 = 1;
	repinv(i, 0, n)
	{
		suf = (suf + s[i]*p10)%p;
		ans += cnt[suf]++;
		p10 = p10 *10%p;
	}
	cout << ans << endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 2580
s = input()

a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for c in s:
    if c in a:
        a.remove(c)
if len(a) > 0:
    print(a[0])
else:
    print("None")

Measured memory_bytes: 3188
N , M = map(int, input().split())
roads = []
for i in range(M):
    a , b = map(int, input().split())
    roads.append(a)
    roads.append(b)

for i in range(1,N+1):
    cnt = 0
    for j in roads:
        if j == i:
            cnt+=1
    print(cnt)     

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(2, vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t h = 0, mk = 0;
    dp[h][0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        auto&& prev = dp[h];
        auto&& next = dp[!h];
        h = !h;

        for (auto j : irange(mk, -1L, -1L)) {
            int64_t ss = 0;
            for (auto c : irange(a[i + 1], a.back() + 1)) {
                ss += prev[j][a[i] + (c - a[i + 1])];
                if (ss >= M) {
                    ss -= M;
                }
                next[j][c] = ss;
            }

            for (auto c : irange(a[i + 1], a.back() + 1)) {
                for (auto b : irange(a[i] + (c - a[i + 1]) + 1, c + 1)) {
                    auto w = j + b - (a[i] + (c - a[i + 1]));
                    if (w > k) {
                        break;
                    }
                    mk = max(mk, w);
                    next[w][c] += prev[j][b];
                    if (next[w][c] >= M) {
                        next[w][c] -= M;
                    }
                }
            }
        }
    }

    int64_t ans = 0;
    for (auto i : irange(0L, k + 1)) {
        ans += dp[h][i][a.back()];
        if (ans >= M) {
            ans -= M;
        }
    }

    cout << ans << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    string S;
    cin >> S;

    int N = S.length();

    for(int i=0; i<N; i++){
        if(S[i] != S[N-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=0; i<(N-1)/2; i++){
        // cout << S[i] << endl;
        if(S[i] != S[(N-1)/2 - 1 - i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=0; i<(N-1)/2; i++){
        if(S[(N+3)/2 - 1 + i] != S[N - 1 - i]){
            // cout << S[i] << endl;
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll H, W, K;
    cin >> H >> W >> K;
    int cell[7][7];
    for (ll i = 0; i < H; i++) {
        string s;
        cin >> s;
        for (ll j = 0; j < W; j++) {
            cell[i][j] = s[j] == '#' ? 1 : 0;
        }
    }

    ll ans = 0;
    for (ll mask1 = 0; mask1 < (1ll << H); mask1++) {
        for (ll mask2 = 0; mask2 < (1ll << W); mask2++) {
            ll cnt = 0;
            for (ll i = 0; i < H; i++) {
                if (!((mask1 >> i) & 1)) continue;
                for (ll j = 0; j < W; j++) {
                    if (!((mask2 >> j) & 1)) continue;
                    if (cell[i][j] == 1) {
                        ++cnt;
                    }
                }
            }
            if (cnt == K) {
                ++ans;
            }
        }
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(){
	int m,f,r,wa=0,z=0;
	while(1){
		scanf("%d%d%d",&m,&f,&r);
		if(m==-1 && f==-1 && r==-1)break;
		if(r==-1)r=z;
		wa=m+f;
		if(m==-1||f==-1)wa=0;
		if(wa>=80)printf("A\n");
		else if(wa>=65 && wa<80)printf("B\n");
		else if(wa>=50 && wa<65||r>=50)printf("C\n");
		else if(wa>=30 && wa<50)printf("D\n");
		else if(wa<30)printf("F\n");
	}
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<int> s, w;
    double con = -1;
    double n = (double)e * 100 / (100 + e);

    int mass, sIn;
    rep (i, f / c + 2) {
      rep (j, f / d + 2) {
        int sugar = c * i + d * j;
        if (sugar <= f) s.push_back(sugar);
      }
    }
    rep (i, 31) {
      rep (j, 31) {
        int water = 100 * a * i + 100 * b * j;
        if (water <= f) w.push_back(water);
      }
    }

    sort(w.begin(), w.end());
    sort(s.begin(), s.end());

    rep (i, w.size()) {
      rep (j, s.size()) {
        if (w[i] + s[j] <= f && w[i] != 0) {
          double tmp = (double)s[j] * 100 / (s[j] + w[i]) ;
          if (tmp <= n) {
            if (tmp >= con) {
              mass = w[i] + s[j];
              sIn = s[j];
              con = tmp;
            }
          } else {
            break;
          }
        }
      }
    }
    cout << mass << " " << sIn << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << W * H / 2.0 << endl;
  if (x * 2 == W && y * 2 == H) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


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

int main() {
	string S, x="";
	cin >> S;
	int n = S.size();

	for (int i = 0;i < n;i++) { //1010…の作成
		if (i % 2 == 0) {
			x += "1";
		}
		else {
			x += "0";
		}
	}

	int countx=0;
	for (int i = 0;i < n;i++) {
		if (S.at(i) == x.at(i)) {
			countx++;
		}
	}
	if (countx < S.size()-countx) {
		cout << countx;
	}
	else {
		cout << S.size() - countx;
	}



	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(S: str):
    ret = 0
    for c in S:
        if c == '+':
            ret += 1
        else:
            ret -= 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
ans = [[0 for i in range(1001)] for j in range(11)]
ans[0][0] = 1

for i in range(101):
     for n in range(9, -1, -1):
         for s in range(1001 - i):
             ans[n + 1][s + i] += ans[n][s]

while True:
    n, s = map(int, input().split())
    if n == 0:
        break
    print(ans[n][s])



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

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

template<typename T>void chmin(T &a,T b){a=min(a,b);}
template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<LL> V;
const LL INF=1e17;
int main(){
    int C,R;
    cin>>C>>R;
    V c(C),r(R);
    cin>>c;
    cin>>r;
    c.push_back(INF);
    r.push_back(INF);
    sort(c.begin(),c.end());
    sort(r.begin(),r.end());
    LL res=0;
    int rid=0,cid=0;
    R++,C++;
    while(1){
        if(r[rid]<c[cid]){
            res+=r[rid++]*C;
            R--;
        }
        else{
            if(c[cid]==INF)break;
            res+=c[cid++]*R;
            C--;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d %d %d",&a, &b, &c);
	d=a+b+c;
	if(d>=22)
	{
		printf("bust\n");
	}
	else
	{
		printf("win\n");
	}
	return 0;
	
	
}

Measured memory_bytes: 128
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int solve(void){
	int n,i,wa=0,ans=0;cin>>n;
	if(n==0){return 0;}
	vector<int>a(n);
	for(i=0;i<n;i++){cin>>a[i];wa+=a[i];}
	for(i=0;i<n;i++){if(a[i]*n<=wa){ans++;}}
	cout<<ans<<endl;
	return 1;
}
int main(void){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 3144
d,g = map(int,input().split())
pc = []
m = 0
for i in range(d):
  pc.append(list(map(int,input().split())))
  m += pc[-1][0]
for i in range(2**d-1):
  cur = bin(i)[2:]
  cur = '0'*(d-len(cur)) + cur
  csum = 0
  cc = 0
  for j in range(d):
    if cur[j] == '0':
      ci = j
    else:
      csum += (j+1)*100*pc[j][0] + pc[j][1]
      cc += pc[j][0]
  if csum >= g:
    m = min(m,cc)
  elif csum + (ci+1) * 100 * pc[ci][0] >= g:
      m = min(m,cc+(g-csum-1)//(100*(ci+1))+1)
print(m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;



signed main(){
    int p,q,r;
    cin>>p>>q>>r;
    cout << min({p+q,q+r,p+r}) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,max,j;
  max=0;
  scanf("%d %d",&b,&a);
int c[a],d[a];
  scanf("%d",&c[0]);
    for(j=0;j<a-1;++j)
    {scanf("%d",&c[j+1]);
     d[j]=c[j+1]-c[j];
     if(d[j]>max) max=d[j];
    }
  d[a-1]=b+c[0]-c[a-1];
  if(d[a-1]>max) max=d[a-1];
  
  
 printf("%d",b-max); 
return 0;
}


Measured memory_bytes: 1664
n, lim_w = map(int, input().split())
w, v = [], []

for _ in range(n):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

# dp[i][j] := i番目までの品物を見たとき, 重さの総和がj以下となるように選んだときの価値の総和の最大値
dp = [ [0]*(lim_w+1) for _ in range(n+1) ]

for i in range(n):
    for j in range(lim_w+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i])

print(dp[n][lim_w])


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

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if(a * b <= c) cout << a * b << '\n';
    else cout << c << '\n';
    
}









Measured memory_bytes: 3656
#pragma GCC target("avx")
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;i++)
#define FORR(i,a,n) for(i=n-1;i>=a;i--)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
//#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL LBn(VL &v,LL a){LL mx=v.size(),mn=-1,md;while(mx-mn>1){md=(mx+mn)/2;if(v[md]<a)mn=md;else mx=md;}return mx;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a%m<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}
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(){
  FAST;
  LL i,ans=0,N,M;
  cin>>N>>M;
  LL A[M];
  rep(i,M)cin>>A[i];
  rep(i,M)N-=A[i];
  cout<<max(-1LL,N)<<endl;
}


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

int f(int n) {
	int ans = 0;
	while (n != 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	cout << (n % f(n) ? "No" : "Yes") << endl;
	return 0;
}

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

int main() {
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  char a = toupper(s1.at(0));
  char b = toupper(s2.at(0));
  char c = toupper(s3.at(0));
  string ans;
  ans.push_back(a);
  ans.push_back(b);
  ans.push_back(c);
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  
  for (int i = 0; i < 10; i++) {
  S += "1";
  }
  
  for (int i = 0; ;) {
    if (S.at(0) == '1') {
      cout << "YES" << endl;
      break;
    }
    else {
      if (S.at(0) == 'd') {
        if (S.at(7) != 'a' && S.substr(0, 7) == "dreamer") {
          S.erase(0, 7);
        }
        else if (S.substr(0, 5) == "dream") {
          S.erase(0, 5);
        }
        else {
          cout << "NO" << endl;
          break;
        }
      }
      
      if (S.at(0) == 'e') {
        if (S.substr(0, 6) == "eraser") {
          S.erase(0, 6);
        }
        else if (S.substr(0, 5) == "erase") {
          S.erase(0, 5);
        }
        else { 
          cout << "NO" << endl;  
          break;
        }
      }
      
      if (S.at(0) != 'd' && S.at(0) != 'e' && S.at(0) != '1') {
        cout << "NO" << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3732
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define llINF (1e18)

#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
 
int main()
{
    ll N;
    cin >> N;
    ll mi = llINF;
    rep(i,5) {
        ll tmp;
        cin >> tmp;
        mi = min(mi, tmp);
    }
    
    print((N+mi-1) / mi + 4);
    return 0;
}

Measured memory_bytes: 256
from math import cos, sqrt, radians


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

Measured memory_bytes: 9496
N=int(input())
t=[0]*100003
x=[0]*100003
y=[0]*100003

for i in range(1,N+1):
    t[i],x[i],y[i]=map(int, input().split())
count=0

for i in range(1,N+1):
    dt=t[i]-t[i-1]
    dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    if dist>dt:
        break
    else:
        pass
    if dist%2==dt%2:
        pass
    else:
        break
    count+=1
if count==N:
    print('Yes')
else:
    print('No')

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

vector<vector<int>> G(2e6);
int N, M, Q;
vector<int> a(2e5), b(2e5);
vector<int> p(2e5), x(2e5);
map<int, int> mp;
vector<int> ans(2e5, -1);

void dfs(int v, int cost) {
    while(!G[v].empty()) {
        int tmp = G[v].back();
        G[v].pop_back();
	ans[tmp] = mp[tmp]+cost;
        
        dfs(tmp, ans[tmp]);
    }
    return ;
}

int main(){
    cin >> N >> Q;

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

    for(int i=0; i<Q; i++){
	cin >> p[i] >> x[i];
	p[i]--;
	mp[p[i]] += x[i];
    }
    ans[0] = mp[0];
    dfs(0, mp[0]);
    
    for(int i=0; i<N; i++){
	cout << ans[i] << " ";	    
    }
    cout << endl;

}



Measured memory_bytes: 84480
#include<iostream>
#include<cstdio>
#include<algorithm>
const int N=1e5+5;
typedef std::pair<int,int> P;
int n;P a[N];
P suf[N];
int main() {
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&a[i].first,&a[i].second);
        ans=std::max(ans,a[i].second-a[i].first+1);
    }
    std::sort(a+1,a+1+n,[&](const P &x,const P &y){return x.second!=y.second?x.second<y.second:x.first<x.first;});
    suf[n+1].first=1e9+7,suf[n+1].second=0;
    for(int i=n;i;i--) {
        suf[i].first=std::min(suf[i+1].first,a[i].first);
        suf[i].second=std::max(suf[i+1].second,a[i].first);
    }
    int mx=0;
    for(int i=1;i<n;i++) {
        mx=std::max(mx,a[i].first);
        if(mx>a[1].second) break;
        ans=std::max(ans,a[1].second-mx+1+a[i+1].second-suf[i+1].second+1);
        ans=std::max(ans,a[1].second-std::max(mx,suf[i+1].second)+1+a[i+1].second-suf[i+1].first+1);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		int num = Integer.parseInt(s[6]);
		if(s[5].equals("1")){
			System.out.println("TBD");
		} else if(num <= 4){
			System.out.println("Heisei");
		} else {
			System.out.println("TBD");
		}
		
		
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

template <typename T> map<T, int> coordinate_compression(vector<T> x) {
    int n = x.size();
    vector<int> y(n);
    iota(y.begin(), y.end(), 0);
    sort(y.begin(), y.end(), [&](int i, int j) { return x[i] < x[j]; });
    map<T, int> res;
    for (int i : y) if (!res.count(x[i])) {
        int j = res.size();
        res[x[i]] = j;
    }
    return res;
}

// Dual Segment Tree
template <class OM = int> struct DST {
    int n, lev;
    vector<OM> lz;
    virtual OM h(OM, OM) = 0;
    const OM e0;

    DST(int n_, const OM& e0) : e0(e0) {
        for (n = 1, lev = 0; n < n_; n <<= 1, ++lev);
        lz.assign(n << 1, e0);
    }

    inline void push(int k) {
        for (int i = lev; i > 0; --i) {
            int j = k >> i;
            if (lz[j] == e0) continue;
            lz[(j << 1) | 0] = h(lz[(j << 1) | 0], lz[j]);
            lz[(j << 1) | 1] = h(lz[(j << 1) | 1], lz[j]);
            lz[j] = e0;
        }
    }

    // [l, r)
    // l, r: 0-indexed
    void update(int l, int r, const OM& x) {
        push(l += n);
        push(r += n - 1);
        for (++r; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lz[l] = h(lz[l], x), l++;
            if (r & 1) --r, lz[r] = h(lz[r], x);
        }
    }

    // k: 0-indexed
    OM query(int k) {
        push(k += n);
        return lz[k];
    }

    void dump(int);
};

// Range Update Query (RUQ)
template <class OM> struct RUQ : DST<OM> {
    RUQ(int n, OM e0 = numeric_limits<OM>::max()) : DST<OM>(n, e0) {}
    OM h(OM a, OM b) override { return b; }
};

// Range Add Query (RAQ)
template <class OM> struct RAQ : DST<OM> {
    RAQ(int n, OM e0 = 0) : DST<OM>(n, e0) {}
    OM h(OM a, OM b) override { return a + b; }
};

// print for debug
template <class M> void DST<M>::dump(int time) {
    if (~time) cerr << "time = " << time << endl;
    for (int i = 1; i <= (1LL << lev); i <<= 1) {
        for (int j = 0; j < i; ++j) {
            cerr << "  " << lz[j + i];
        }
        cerr << endl;
    }
    cerr << endl;
}

int N, Q;
int S[200010], T[200010], X[200010], D[200010];

void _main() {
    cin >> N >> Q;
    vector<int> v;
    REP (i, N) {
        cin >> S[i] >> T[i] >> X[i];
        v.push_back(max(0LL, S[i] - X[i]));
        v.push_back(max(0LL, T[i] - X[i]));
    }
    REP (i, Q) {
        cin >> D[i];
        v.push_back(D[i]);
    }
    auto cc = coordinate_compression(v);
    vector<int> ord(N);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return X[i] > X[j];
    });
    RUQ<int> ruq(cc.size(), -1);
    REP (i, N) {
        int j = ord[i];
        ruq.update(cc[S[j] - X[j]], cc[T[j] - X[j]], j);
    }
    REP (i, Q) {
        int j = ruq.query(cc[D[i]]);
        if (j == -1) cout << -1 << endl;
        else cout << X[j] << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 68296