akhauriyash/Code-Regression huggingface dataset:
import itertools
import numpy as np
N, M, X = [int(_) for _ in input().split()]
CA = np.array([[int(_) for _ in input().split()] for _ in range(N)], dtype=int)
ans = 10**10
for bs in itertools.product(range(2), repeat=N):
    s = np.zeros(M + 1, dtype=int)
    for i, b in enumerate(bs):
        if b:
            s += CA[i]
    if np.all(s[1:] >= X):
        ans = min(ans, s[0])
if ans == 10**10:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 27284
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    n %= 10;
    if(n == 3) puts("bon");
    else if(n == 0 || n == 1 || n == 6 || n == 8) puts("pon");
    else puts("hon");
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void) {
	// your code goes here
	int z, a,b,c,d,ans=0;
	while(scanf("%d",&z)!=EOF) {
		for(a = 0;a < 10; a++) {
			for(b=0;b < 10; b++) {
				for(c=0;c < 10; c++) {
					for (d=0;d < 10; d++) {
						if((a+b+c+d) == z) {
							ans += 1;
						}
					}
				}
			}
		}
				
		printf("%d\n",ans);
		ans = 0;
	}
	return 0;
}

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

int main(){
  int N;
  while((cin>>N)&&(N!=0)){
    int locx=10;
    int locy=10;
    vector<int> x;
    vector<int> y;
    //cout << N << endl;
    for(int i=0;i<N;i++){
      //      cout << "whei" << endl;
      int varx;
      int vary;
      cin >> varx >> vary;
      x.push_back(varx);
      y.push_back(vary);
      //     cout << "x = " << var << " ";
    }

    int M;
    cin >> M;
    int cnt=0;
    for(int i=0;i<M;i++){
      char direction;
      cin >> direction;
      if(direction == 'W'){
        int a;
        cin >> a;
        for(int j=0;j<a;j++){
          locx -= 1;
          for(int k=0;k<N;k++){
            if(locx==x[k]&&locy==y[k]){
              x[k]=-1;
              y[k]=-1;
              cnt++;
            }
          }
        }
      }else if(direction == 'E'){
        int a;
        cin >> a;
        for(int j=0;j<a;j++){
          locx += 1;
          for(int k=0;k<N;k++){
            if(locx==x[k]&&locy==y[k]){
              x[k]=-1;
              y[k]=-1;
              cnt++;
            }
          }
        }
      }else if(direction == 'N'){
        int a;
        cin >> a;
        for(int j=0;j<a;j++){
          locy += 1;
          for(int k=0;k<N;k++){
            if(locx==x[k]&&locy==y[k]){
              x[k]=-1;
              y[k]=-1;
              cnt++;
            }
          }
        }
      }else if(direction == 'S'){
        int a;
        cin >> a;
        for(int j=0;j<a;j++){
          locy -= 1;
          for(int k=0;k<N;k++){
            if(locx==x[k]&&locy==y[k]){
              x[k]=-1;
              y[k]=-1;
              cnt++;
            }
          }
        }
      }
    }
    if(cnt==N)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1212
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    int N; cin>>N;
    vector<string>S(N);
    ll m=0,a=0,r=0,c=0,h=0;
    rep(i,N){
        cin>>S[i];
        if(S[i][0]=='M')m++;
        else if(S[i][0]=='A')a++;
        else if(S[i][0]=='R')r++;
        else if(S[i][0]=='C')c++;
        else if(S[i][0]=='H')h++;
    }
    ll ans =m*(a*r+a*c+a*h+r*c+r*h+c*h);
    ans+=r*(a*c+a*h+c*h);
    ans+=a*c*h;
    cout<<ans<<endl;

}


Measured memory_bytes: 6144
#include <iostream>
#include <stdio.h>
#include <unordered_map>
#include <vector>

#define MAX_N 200'000

using namespace std;

int A[MAX_N]{};

int main() {
  int N, K;
  cin >> N >> K;
  int res = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    ++A[a - 1];
    ++res;
  }
  if (N == K) {
    printf("0\n");
    return 0;
  }
  sort(A, A + N);
  for (int i = N - 1; i >= N - K; --i) {
    res -= A[i];
  }
  printf("%d\n", res);
}

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

int main(int argc, char const *argv[]) {
    string s;
    cin >> s;

    string output = "Yes";
    if (s[0] == s[1] && s[1] == s[2]) {
        output = "No";
    }

    cout << output << endl;
    return 0;
}


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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    ll a, b, c, d;
    ll ans = -LINF;
    cin >> a >> b >> c >> d;

    ans = max(a * c, ans);
    ans = max(a * d, ans);
    ans = max(b * c, ans);
    ans = max(b * d, ans);

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

Measured memory_bytes: 3628
n = int(input())
li = []
import itertools
for j in range(3,10):
    for i in itertools.product([3,5,7],repeat=j):
        if i.count(3)<1 or i.count(5)<1 or i.count(7)<1:
            pass
        else:
            li += [int(''.join(map(str,i)))]

import bisect
print(bisect.bisect(li,n))

Measured memory_bytes: 10148
// 0266
#include <iostream>
#include <string>
using namespace std;

void reconfigurate(char &s, char c){
	if(s == 'A'){
		if(c == '0')
			s = 'X';
		else if(c == '1')
			s = 'Y';
	}else if(s == 'X'){
		if(c == '0')
			s = 'S';
		else if(c == '1')
			s = 'Z';
	}else if(s == 'Y'){
		if(c == '0')
			s = 'X';
		else if(c == '1')
			s = 'S';
	}else if(s == 'Z'){
		if(c == '0')
			s = 'W';
		else if(c == '1')
			s = 'B';
	}else if(s == 'W'){
		if(c == '0')
			s = 'B';
		else if(c == '1')
			s = 'Y';
	}else if(s == 'B'){
		if(c == '0')
			s = 'Y';
		else if(c == '1')
			s = 'X';
	}
}

int main(){
	while(1){
		char state = 'A';
		string str;

		cin>>str;
		if(str == "#")
			break;

		for(int i=0;i<str.length();i++)
			reconfigurate(state, str[i]);

		if(state == 'B')
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
N, M = map(int, input().split())
ABs = [tuple(map(int, input().split())) for i in range(M)]

ABs.sort()

ans = 0
minB = N+1
for A, B in ABs + [(N+1, N+1)]:
    if minB <= A:
        ans += 1
        minB = B
    minB = min(minB, B)

print(ans)


Measured memory_bytes: 17456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> arr(n+1,0);
    for(int i=1;i<n;i++)
    {
	int x ;
	cin>>x;
	arr[x]++;
    }

    for(int i=1;i<=n;i++)
	cout<<arr[i]<<endl;

    return 0;
}


Measured memory_bytes: 3992
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;




namespace contest
{

    class contest
    {


        static void Main(string[] args)
        {


            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();



            //int n = int.Parse(Console.ReadLine());

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = num[0];
            int x = num[1];

            long amount = 0;
            for(int i=1; i< n; i++)
            {
                int sum = Math.Abs(arr[i]+arr[i-1]);
                int diff = sum - x;
                if (diff <= 0) continue;

                if(arr[i]>=diff)
                {
                    arr[i] -= diff;
                    amount += diff;
                }
                else
                {
                    arr[i - 1] -= diff - arr[i];
                    arr[i] = 0;
                    amount += diff;
                }
            }



            Console.WriteLine(amount);






        }

       
       

    }

 
    
}


Measured memory_bytes: 18008
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    s += "XXX";
    int count = 0;
    for(int i=0; i<n; i++){
        if(s.substr(i, 3) == "ABC"){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

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

using namespace std;

int main() {
  char b;
  cin >> b;
  if(isupper(b)) {
    cout << "A" << endl;
    return 0;
  } else {
    cout << "a" << endl;
    return 0;
  }
}



Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n;
int dp[101010];

int main(){
	cin >> n;
	
	for(int i = 0; i < 101010; i++) dp[i] = INF;
	deque<P> q;
	q.push_front(P(1,1));
	while(!q.empty()){
		P p = q.front();
		q.pop_front();
		i64 sc = p.first, now = p.second;
		if(dp[now] <= sc) continue;
		dp[now] = sc;
		if(now == 0) break;
		int nx = (now+1)%n;
		q.push_back(P(sc+1, nx));
		nx = (now*10)%n;
		q.push_front(P(sc, nx));
	}
	
	cout << dp[0] << endl;
	
	return 0;
}

Measured memory_bytes: 2304
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $k);
if ($b - $a + 1 <= $k * 2) {
	$x = range($a, $b);
} else {
	$x = array_merge(range($a, $a + $k - 1), range($b - $k + 1, $b));
}
echo implode("\n", $x);

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

using namespace std;

stack<int> num;

void add(){
    int a = num.top();
    num.pop();
    int b = num.top();
    num.pop();
    num.push(a+b);
}

void sub(){
    int a = num.top();
    num.pop();
    int b = num.top();
    num.pop();
    num.push(b-a);
}

void mul(){
    int a = num.top();
    num.pop();
    int b = num.top();
    num.pop();
    num.push(a * b);
}

int main(void){
    string s;
    while(cin >> s){
        if(s == "+"){
            add();
        }else if(s == "-"){
            sub();
        }else if(s == "*"){
            mul();
        }else{
            num.push(stoi(s));
        }
    }
    cout << num.top() << endl;
}


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

int main() {
    int N;
    cin >> N;
    cout << (N + 1) / 2;
    return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int t;cin>>t;while(t--)
#define N 100003
#define M 103
#define inf LLONG_MAX
//int mod=1e9+7;
//int mod=998244353;

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int a,b,c;
    cin>>a>>b>>c;
    int ans=b;
    ans+=min(c,b);
    c-=b;
    if(c>0)
    {
        ans+=min(a,c);
        c-=a;
        if(c>0)
            ++ans;
    }
    cout<<ans;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int N;

    cin >> N;

    int sum = 0;
    int n = N;

    while(n != 0){
        sum += n%10;
        n /= 10; 
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

#define ll long long

int main(void){
    ll n, t, t2, ans, min_;
    cin >> n >> t >> t2;
    
    ans = t2 - t;
    min_ = min(t2, t);
    
    for (ll i = 2; i < n; i++) {
        cin >> t2;
        ans = max(t2 - min_, ans);
        min_ = min(min_, t2);
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 3120
#include<iostream>
using namespace std;
int main()
{
  int n, a, b, c, d;
  cin >> n;
  a = n / 1000;
  b = (n / 100) % 10;
  c = (n / 10) % 10;
  d = n % 10;
  if((a == b && c == d && a == c) || (a == b && b == c) || (b == c && c == d))
    cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,k;
    cin>>n>>k;
    vector<long long>a(n),f(n);
    for(int i=0;i<n;i++)
	{
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
	{
        cin>>f[i];
    }
    sort(a.begin(),a.end());
    sort(f.begin(),f.end());
	reverse(f.begin(),f.end());
    long long  cnt = -1;
    long long  ans = 1e13+10;
    while (abs(ans - cnt)>1)
	{
        long long  mid = (ans + cnt) / 2;
        long long  ss = 0;
        for(int i=0;i<n;i++){
            if(a[i]*f[i]>mid)
			{
                ss+=a[i]-(mid/f[i]);
            }
        }
        if (ss<=k)
		{
			ans=mid;
		}
        else
		{
			cnt=mid;
		}
    }
    cout<<ans<<endl;
    return 0;
}

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

int gcd(int p,int q){
    return q==0 ? p : gcd(q,p%q);
}
int main(){
    int p,q;
    while(cin>>p>>q,p){
        int g=gcd(p,q);
        p/=g;
        q/=g;
        long long int res=1;
        for(int i=2;i<1e5;i++){
            if(q%i==0){
                res*=i;
                while(q%i==0) q/=i;
            }

        }
        res*=q;
        cout<<res<<endl;
        return 0;
    }

}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;

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

int64_t nCk(int64_t n, int64_t k)
{
  int64_t res = 1;
  for (int64_t i = 1; i <= k; i++)
  {
    res = (((res * (n - i + 1)) % MOD) * modinv(i, MOD)) % MOD;
  }
  return res;
}

int main()
{
  int64_t N, K;
  cin >> N >> K;
  for (int64_t i = 1; i <= K; i++)
  {
    if (N - K - i + 1 < 0)
    {
      cout << 0 << endl;
      continue;
    }
    int64_t a = nCk(K - 1, i - 1) % MOD;
    a = (a * nCk(N - K + 1, N - K - i + 1)) % MOD;
    cout << a % MOD << endl;
  }
}

Measured memory_bytes: 256
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static int[][] cArray;
    public static int[][] dArray;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        cArray = new int[n][n];
        dArray = new int[c][c];
        for(int y = 0;y < c;++y){
            for (int x = 0;x < c;++x){
                dArray[x][y] = sc.nextInt();
            }
        }
        for(int y = 0;y < n;++y){
            for (int x = 0;x < n;++x){
                cArray[x][y] = sc.nextInt();
            }
        }
       // genre(n,c);
        search(n,c);
    }

    public static void genre(int n,int c){
        Random random = new Random();
        for(int y = 0;y < c;++y){
            for (int x = 0;x < c;++x){
                if(x == y)continue;
                dArray[x][y] = random.nextInt(1000);
            }
        }
        for(int y = 0;y < n;++y){
            for (int x = 0;x < n;++x){
                cArray[x][y] = random.nextInt(c) + 1;
            }
        }
    }

    public static void search(int n,int c){
        int cc[][] = new int[3][c];
        int s = 2;
        for (int x = 0;x < n;++x){
            s = (x + 2) % 3;
            for (int y = 0;y < n;++y){
                ++cc[s][cArray[x][y] - 1];
                ++s;
                if(s == 3)s = 0;
            }
        }

        long min = Long.MAX_VALUE;
        for (int c1 = 1;c1 <= c;++c1) {
            for (int c2 = 1; c2 <= c; ++c2) {
                if (c2 == c1) continue;
                for (int c3 = 1; c3 <= c; ++c3) {
                    if (c1 == c3 || c2 == c3) continue;
                    long k = 0;
                    for (int nn = 0;nn < c;++nn){
                        k += dArray[c3 - 1][nn] * cc[0][nn];
                        k += dArray[c1 - 1][nn] * cc[1][nn];
                        k += dArray[c2 - 1][nn] * cc[2][nn];
                    }
                    if(min > k)min = k;
                }
            }
        }


        System.out.println(min);
    }

}


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

int main() {
  int m, d, s = 0;
  cin >> m >> d;
  rep(i, m){
    if(i < 3) continue;
    rep(j, d){
      if(j < 20) continue;
      else{
        int a = (j+1) / 10, b = (j+1) % 10;
        if(a * b == i+1 && a > 1 && b > 1) ++s;
      }
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-8;
int m,n;
char fld[1000][1000];
char flag[2][2];
bool ok(int x,int y){
	if(x<0||y<0||x+1>=m||y+1>=n)return false;
	REP(i,4)if(fld[x+i%2][y+i/2]!=flag[i%2][i/2])return false;
	return true;
}
string JOI="JOI";
int main(){
	cin>>n>>m;
	REP(i,n)REP(j,m)cin>>fld[j][i];
	REP(i,2)REP(j,2)cin>>flag[j][i];
	int ans=0;
	REP(i,n-1)REP(j,m-1)if(ok(j,i))ans++;
	int res=ans;
	REP(i,n)REP(j,m){
		int c1=0;
		char tmp=fld[j][i];
		REP(k,4)if(ok(j-k%2,i-k/2))c1++;
		REP(k,3){
			int c2=0;
			fld[j][i]=JOI[k];
			REP(l,4)if(ok(j-l%2,i-l/2))c2++;
			ans=max(ans,res-c1+c2);
		}
		fld[j][i]=tmp;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2180
#include <iostream>
#include <iomanip>

using namespace std;
int main() {
    int a,b;

    cin>>a>>b;
    cout << a/b << " "<< a%b << " ";

    cout<<fixed;
    cout << setprecision(10) << (double)a/b << endl;
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    int N;
    vector<int> A;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    int sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += A[i];
    }
    ld avg = (ld) sum /  (ld) N;

    int result = -1;
    ld diff = 1000;
    for (int i = 0; i < N; ++i) {
        ld d = abs(avg - (ld) A[i]);
        if(diff > d){
            result = i;
            diff = d;
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[[c for c in input()] for _ in range(h)]
b=[]
flag=0
for s in a:
  if "#" in s:
    b.append(s)
for i in range(w):
  flag=0
  for j in range(len(b)):
    if b[j][i]=="#":
      flag=1
      break
  if flag==0:
    for j in range(len(b)):
      b[j][i]=""
for s in b:
  print("".join(s))

Measured memory_bytes: 3064
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)

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

int main() {
  int n, a[3][3], b[10];
  bool appear[3][3];
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) cin >> a[i][j];
  }
  cin >> n;
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      appear[i][j] = false;
      for(int k = 0; k < n; k++) {
        if(a[i][j] == b[k]) appear[i][j] = true;
      }
    }
  }
  string ans = "No";
  for (int i = 0; i < 3; i++) {
    if (appear[i][0] and appear[i][1] and appear[i][2]) ans = "Yes";
  }
  for (int i = 0; i < 3; i++) {
    if (appear[0][i] and appear[1][i] and appear[2][i]) ans = "Yes";
  }
  if(appear[0][0] and appear[1][1] and appear[2][2]) ans = "Yes";
  if(appear[0][2] and appear[1][1] and appear[2][0]) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self,n):
        fact=[1]*(n+1); invfact=[1]*(n+1)
        for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1): invfact[i]=invfact[i+1]*(i+1)%MOD
        self.__fact=fact; self.__invfact=invfact

    def inv(self,n):
        assert(n>0)
        return self.__fact[n-1]*self.__invfact[n]%MOD

    def fact(self,n):
        return self.__fact[n]

    def invfact(self,n):
        return self.__invfact[n]

    def comb(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[k]*self.__invfact[n-k]%MOD

    def perm(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[n-k]%MOD

def resolve():
    h,w,n=map(int,input().split())
    RC=[None]*n
    for i in range(n):
        r,c=map(int,input().split())
        r-=1; c-=1
        RC[i]=(r,c)
    RC.append((h-1,w-1))
    n+=1
    RC.sort(lambda p:sum(p))

    mf=modfact(h+w)
    f=lambda x,y:mf.comb(x+y,x)
    dp=[None]*n
    for i in range(n):
        r,c=RC[i]
        res=f(r,c)
        for j in range(i):
            r0,c0=RC[j]
            res-=dp[j]*f(r-r0,c-c0)
        dp[i]=res%MOD

    print(dp[-1])
resolve()

Measured memory_bytes: 47852
from collections import deque

def dfs(field, s):
    MOVE = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    q = deque([(0, s)])
    dist = [[-1] * w for _ in range(h)]

    d, i, j = -1, -1, -1
    while q:
        d, (i, j) = q.popleft()
        if dist[i][j] != -1:
            continue
        dist[i][j] = d
        for di, dj in MOVE:
            ni, nj = i + di, j + dj
            if not 0 <= ni < h or not 0 <= nj < w:
                continue
            if field[ni][nj] == '#':
                continue
            if dist[ni][nj] != -1:
                continue
            q.append((d + 1, (ni, nj)))
    return d, i, j

h,w=map(int,input().split())
S=[]
for i in range(h):
    S.append(input())

ans=0
for i in range(h):
    for j in range(w):
        if S[i][j]==".":
            d,i,j=dfs(S,(i,j))
            ans=max(ans,d)

print(ans)

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

#define MAX 200001
#define INFTY -2000000000

long R[MAX];

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

  for ( int i = 0; i < n; i++ ) {
    cin >> R[i];
  }

  long maxp = INFTY;
  long maxr = INFTY;
  for ( int i = n - 1; i >= 0; i-- ) {
    maxp = max(maxp, maxr - R[i]);
    maxr = max(maxr, R[i]);
    // cout << "maxr: " << maxr << endl                                         
    //      << "maxp: " << maxp << endl;                                        
  }

  cout << maxp << endl;

  return 0;
}

Measured memory_bytes: 4636
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, d, a;
  cin >> n >> d >> a;

  vP lst(n);
  rep(i, n){
    ll x, h;
    cin >> x >> h;
    h = (h + a - 1)/a;
    lst[i] = P(x, h);
  }
  Sort(lst);

  vll dm(n+1, 0);

  ll ans = 0;
  rep(i, n){
    ll cnt = lst[i].second;
    if(i > 0) dm[i] += dm[i-1];
    cnt = max(cnt - dm[i], 0LL);
    dm[i] += cnt;
    ans += cnt;
    ll iend = Upper_bound(lst, P(lst[i].first + 2*d, INF));
    dm[iend] -= cnt;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7956
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll R,C,N;
  cin>>R>>C>>N;
  using P=pair<pll,pll>;
  auto cul=
    [&](pll a){
      ll x=a.F,y=a.S;
      ll ret=0;
      if(y==0){return ret+x;}
      ret+=R;
      if(x==R){return ret+y;}
      ret+=C;
      if(y==C){return ret+R-x;}
      ret+=R;
      return ret+C-y;
    };
  auto good2=
    [&](pll a){
      ll x=a.F,y=a.S;
      return x==0 || x==R || y==0 || y==C;
    };
  auto good1=
    [&](P a){
      return good2(a.F) && good2(a.S);
    };
  ll dif=R*2+C*2;
  vector<pll> A;
  for(int i=0;i<N;i++){
    P a;
    cin>>a;
    if(!good1(a)){continue;}
    ll s=cul(a.F),g=cul(a.S);
    if(s>g){swap(s,g);}
    A.push_back({s,g});
    s+=dif;
    //A.push_back({g,s});
    g+=dif;
    /*
    A.push_back({s,g});
    s+=dif;
    A.push_back({g,s});
    g+=dif;
    
    A.push_back({s,g});
    s+=dif;
    A.push_back({g,s});
    g+=dif;
    */
  }
  priority_queue<ll,vector<ll>,greater<ll>> Q;
  sort(A.begin(),A.end());
  //cout<<A<<endl;
  for(auto &I:A){
    while(!Q.empty() && Q.top()<=I.F){Q.pop();}
    //cout<<I<<" ";
    //if(!Q.empty()){cout<<Q.top()<<endl;}
    //else{cout<<endl;}
    if(!Q.empty() && Q.top()<I.S){cout<<"NO"<<endl; return 0;}
    Q.push(I.S);
  }
  cout<<"YES"<<endl;
  


  return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
using namespace std;
vector<int> Data;

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

	if (n.find("7") == string::npos)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}

	return 0;
}

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

int main()
{
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    long long num[5] = {A, B, C, D, E};
    sort(num, num + 5);

    cout << N / num[0] + (N % num[0] != 0) + 4 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ld PI = 3.14159265358979323846;
const ll MOD = 998244353;
 
 
int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 2; i * i <= n; i++) {
		ll cnt = 0;
		if (n % i == 0) {
			while (n % i == 0) {
				n /= i;
				cnt++;
			}
		    int step = 1;
		    while(cnt - step >= 0){
		        ans++;
		        cnt -= step;
		        step++;
		    }
		}
	}
    if(n > 1)ans++;
    cout << ans;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#define H_MAX 10001
using namespace std;

void breakLine(int data[H_MAX][5], int y) {
  for(int i = y; i+1 < H_MAX; i++) {
    for(int j = 0; j < 5; j++) {
      data[i][j] = data[i+1][j];
    }
  }
}

void search(int data[H_MAX][5], int sy, int ey) {
  for(int i = sy; i <= ey; i++) {
    bool flag = true;
    for(int j = 0; j < 5; j++) {
      if(data[i][j] != 1) {
	flag = false;
	break;
      }
    }
    if(flag) {
      breakLine(data, i);
      i--;
    }
  }
}

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    int data[H_MAX][5];

    for(int i = 0; i < H_MAX; i++) {
      for(int j = 0; j < 5; j++) {
	if(i == 0) data[i][j] = 1;
	else      data[i][j] = 0;
      }
    }

    for(int i = 0; i < n; i++) {
      int d, p, q, qy;
      cin >> d >> p >> q;
      q--;
      for(int y = H_MAX-1; y >= 0; y--) {
	bool put = false;
	switch(d) {
	case 1:
	  for(int j = 0; j < p; j++) {
	    if(data[y][q+j] == 1) {
	      put = true;
	      y++;
	      qy = y;
	      for(int k = 0; k < p; k++) {
		data[y][q+k] = 1;
	      }
	      break;
	    }
	  }
	  break;
	case 2:
	  if(data[y][q] == 1) {
	    put = true;
	    y++;
	    qy = y;
	    for(int j = 0; j < p; j++) {
	      data[y+j][q] = 1;
	    }
	  }
	  break;
	}
	if(put) {
	  break;
	}
      }

      switch(d) {
      case 1: search(data, qy, qy); break;
      case 2: search(data, qy, qy+p-1); break;
      }
    }

    int count = 0;
    for(int i = 1; i < H_MAX; i++) {
      for(int j = 0; j < 5; j++) {
	count += data[i][j];
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b-a==c-b)  cout << "YES" << endl;
  else  cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = a+b;
      	if (b+c<=d){
          d = b+c;
        }
      	if (c+a<=d){
          d = c+a;
        }
		System.out.println(d);
	}
}

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

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int sum = Z, cnt = 0;

  for (int i = 0; ; i++) {
    sum += Y + Z;
    if (X < sum) {
      cnt = i;
      break;
    }
  }

  cout << cnt << endl;

  return 0;
}


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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if ( a + b == c || b + c == a || c + a == b ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

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

int main() {
	int N, Q, l, r;
	string S;
	cin >> N >> Q >> S;
	static int sum[100001];
	sum[0] = sum[1] = 0;
	for (int i = 1;i < N;++ i) sum[i + 1] = sum[i] + (S[i - 1] == 'A' && S[i] == 'C' ? 1 : 0);
	while (Q--) {
		cin >> l >> r;
		cout << sum[r] - sum[l] << endl;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

累積和
*/

Measured memory_bytes: 1408
#include <stdio.h>
int main(){
int a,b,c,d[8]={0};
scanf("%d%d%d",&a,&b,&c);
d[a]++;
d[b]++;
d[c]++;
if (d[5]==2 && d[7]==1){
printf("YES\n");
}
else printf("NO\n");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <algorithm>
#include <utility>

int main(void){
	using namespace std;
	
	// index
	array<int, 26> a;
	for(int i = 0; i < 26; ++i){
		a[i] = 51;
	}
	
	int n;
	cin >> n;

	vector<string> s;
	s.resize(n);
	for(int i = 0; i < n; ++i){
		cin >> s[i];
		
		for(int j = 0; j < 26; ++j){
			int tmp = count(s[i].begin(), s[i].end(), 'a' + j);
			a[j] = min(tmp, a[j]);
		}
	}
	
	// DEBUG
	/*
	for(int i = 0; i < 26; ++i){
		char test = 'a' + i;
		cout << test << " : " << a[i] << endl;
	}
	*/
	
	string ans;
	for(int i = 0; i < 26; ++i)
		for(int j = 0; j < a[i]; ++j)
			ans += 'a' + i;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int flag = 0;
int a[100001];
char c[100001][2];
int ma[100001];
char mc[100001];

void quickSort(int, int);
int partition(int, int);
void swap(int ,int);

void mergeSort(int, int);
void merge(int, int, int);

int main()
{
  int n, i;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    {
      scanf("%s %d", &c[i][0], &a[i]);
      mc[i] = c[i][0];
      ma[i] = a[i];
    }

  quickSort(0, n-1);
  mergeSort(0, n);

  for(i = 0; i < n; i++)
    {
      if(c[i][0] != mc[i])flag = 1;
    }

  if(flag)printf("Not stable\n");
  else printf("Stable\n");
  
  for(i = 0; i < n; i++)
    {
      printf("%c %d\n", c[i][0], a[i]);
    }
  return 0;
}

int partition(int l, int r)
{
  int temp, i, j;

  temp = a[r];
  i = l;
  
  for(j = l; j <= r; j++)
    {
      if(a[j] <= temp)
	{
	  swap(i, j);
	  i++;
	}
    }

  return i-1;
}

void swap(int i, int j)
{
  int t;
  char temp;

  if(i == j)return;

  t = a[i];
  a[i] = a[j];
  a[j] = t;
  
  temp = c[i][0];
  c[i][0] = c[j][0];
  c[j][0] = temp;
}

void quickSort(int l, int r)
{
  int p;
  
  if(l < r)
    {
      p = partition(l, r);
      quickSort(l, p-1);
      quickSort(p+1, r);
    }

  return;
}

void merge(int left,int mid, int right)
{
  int *l, *r;
  char *lc, *rc;
  int n1, n2, i, j, k;
  int inf=1000000000;
  n1 = mid-left;
  n2 = right-mid;

  l = malloc(sizeof(int)*(n1+1));
  lc = malloc(sizeof(char)*(n1+1));
  r = malloc(sizeof(int)*(n2+1));
  rc = malloc(sizeof(char)*(n2+1));

  for(i = 0; i < n1; i++)
    {
      l[i] = ma[left+i];
      lc[i] = mc[left+i];
    }
  l[n1] = inf;
  for( i = 0; i < n2; i++)
    {
      r[i] = ma[mid+i];
      rc[i] = mc[mid+i];
    }
  r[n2] = inf;

  i = 0;
  j = 0;
  
  for(k = left; k < right;k++)
    {
      if(l[i] <= r[j])
	{
	  ma[k] = l[i];
	  mc[k] = lc[i];
	  i++;
	}
      else
	{
	  ma[k] = r[j];
	  mc[k] = rc[j];
	  j++;
	}
    }
  return;
}

void mergeSort(int left, int right)
{
  int mid;

   if(left+1 < right)
    {
      mid = (right+left) / 2;
      mergeSort(left, mid);
      mergeSort(mid, right);
      merge(left,mid,right);
    }
   return;
}





Measured memory_bytes: 21412
#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 n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;

  int ans = 0;
  rep(i, k) {
    char c = 'a';
    for (int j = i; j < n; j += k) {
      if (c == t[j]) c = 'a';
      else {
        c = t[j];
        if (c == 'r') ans += p;
        else if (c == 's') ans += r;
        else if (c == 'p') ans += s;
      }
    }
  }
  cout << ans << endl;


  
  return 0;
}

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

int main(){
	int n,k;
  	cin >> n >> k;
  	vector<int> a(n);
  	for(int i = 0; i< n;i++)
      	cin >> a[i];
  	sort(a.begin(),a.end());
  	int count =0;
  	for(int i = n-1; i>= n-k;i--)
      	count += a[i];
  	cout << count << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
#define MAX_N 100000
int main(void){

	int N, K; 	scanf("%d %d", &N , &K);
	long long x[MAX_N + 1];
	for(int i = 0 ; i < N ; i++)	scanf("%lld", x + i);

	long long ans = 900000000;
	for(int i = 0 ; i + K - 1 < N ; i++)
	 	ans = min(ans , x[i + K - 1] - x[i] + min(abs(x[i]) , abs(x[i + K - 1])) );
	
  
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1024
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
import java.util.*;

public class Main
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String cubeStr = sc.nextLine();
	    int length = cubeStr.length();
	    List<Character> list = new ArrayList<Character>();
	    for(int i=0; i<length; i++){
	        list.add(cubeStr.charAt(i));
	    }
	    
	    int sequence = 0;
	    int numOfCubesCleared = 0;
	    
	    while(sequence < list.size()-1){
	        if (list.get(sequence) != list.get(sequence+1)){
	            list.remove(sequence);
	            list.remove(sequence);
	            numOfCubesCleared += 2;
	            sequence = Math.max(0, sequence-1);
	        }else{
	            sequence++;
	        }
	    }
	    System.out.println(numOfCubesCleared);
		
	}
}


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

int calc(int n) {
	string s = to_string(n);
	int result = 0;

	for (int i = 0; i < s.size(); i++) {
		result += stoi(s[i] + ""s);
	}
	return result;
}

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

	if (N % calc(N)) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}


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


def operation(n):
    count = 0
    for a, b, c, d in itertools.product(range(10), repeat=4):
        if a + b + c + d == n:
            count += 1
    print(count)


def main():
    for l in sys.stdin:
        n = int(l.strip())
        operation(n)


if __name__ == '__main__':
    main()

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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<char>>;

int main()
{
    int h,w;
    cin >> h >> w;
    Graf g(h+1,vector<char>(w+1));
    rep(i,h){
        rep(j,w){
            cin >> g[i][j];
        }
    }
    int count;
    rep(i,h){
        count=0;
        rep(j,w){
            if(g[i][j]=='#'){
                break;
            }
            count++;
        }
        if(count==w){
            g[i][w]='1';
        }else{
            g[i][w]='0';
        }
    }
    rep(j,w){
        count=0;
        rep(i,h){
            if(g[i][j]=='#'){
                break;
            }
            count++;
        }
        if(count==h){
            g[h][j]='1';
        }else{
            g[h][j]='0';
        }
    }

    rep(i,h){
        if(g[i][w]=='0'){
            rep(j,w){
                if(g[h][j]=='0'){
                    cout << g[i][j];
                }
            }
            cout << endl;
        }
        

    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b-a<0&&c-b<0&&c-a<0){cout<<"No";}
    else if(b-a<=d&&c-b<=d||c-a<=d)cout<<"Yes";
    else{cout<<"No";}














return 0;}


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

typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    ll A;
    ll total = 0;
    for (int i = 0; i < M; i++) {
        cin >> A;
        total += A;
    }
    if (total > N) {
        cout << -1 << endl;
    } else {
        cout << N - total << endl;
    }
}



Measured memory_bytes: 3584
def main():
    buf = input()
    buflist = buf.split()
    H = int(buflist[0])
    W = int(buflist[1])
    D = int(buflist[2])
    board = []
    for i in range(H):
        buf = input()
        buflist = buf.split()
        board.append(list(map(int, buflist)))
    buf = input()
    Q = int(buf)
    query = []
    for i in range(Q):
        buf = input()
        buflist = buf.split()
        L = int(buflist[0])
        R = int(buflist[1])
        query.append((L, R))
    moddivxy = []
    for i in range(H):
        for j in range(W):
            moddivxy.append((board[i][j] % D, board[i][j] // D, i, j))
    moddivxy = list(sorted(moddivxy))
    mp_table = [[0]]
    mod = 0
    last_xy = (-1, -1)
    for x in moddivxy:
        if x[0] == 0 and x[1] == 1: # first element
            mp_table[mod].append(0)
        elif x[0] > mod:
            mod = x[0]
            mp_table.append([0])
        else:
            mp_table[mod].append(mp_table[mod][-1] + abs(last_xy[0] - x[2]) + abs(last_xy[1] - x[3]))
        last_xy = (x[2], x[3])
    for q in query:
        m = q[0] % D
        d_start = q[0] // D
        d_end = q[1] // D
        print(mp_table[m][d_end] - mp_table[m][d_start])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38568
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	def negative():
		for i in reversed(range(1,N)):
			print(i+1, i)

	def positive():
		for i in range(N-1):
			print(i+1, i+2)

	N = I()
	A = LI()
	max_A = max(A)
	maxidx = A.index(max(A)) +1
	min_A = min(A)
	minidx = A.index(min_A) +1
	
	p=[]

	## all negative
	if max_A < 0:
		print(N-1)
		negative()

	# both positive and negative
	elif min_A < 0:
		print(2*N-1)

		# 最大値を全ての要素に足し、全ての要素を非負整数にする
		if abs(max_A) >= abs(min_A):
			for i in range(N):
				if i+1 != maxidx:
					print(maxidx, i+1)
			print(maxidx, maxidx)
			positive()

		# 最小値を全ての要素に足し、全ての要素を0以下にする
		else:
			for i in range(N):
				if i+1 != minidx:
					print(minidx, i+1)
			print(minidx,minidx)
			negative()


	## all positive
	else:
		print(N-1)
		positive()


if __name__ == '__main__':
	main()

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

inline void print(){return;} 
template <typename T, typename... Types> 
inline void print(T var1,Types... var2){cout<<var1<<" ";print(var2...);} 

inline void println(){cout<<"\n";} 
template <typename T, typename... Types> 
inline void println(T var1,Types... var2){cout<<var1<<" ";println(var2...);}

int mod=1e9+7;

main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int g=(c*d)/__gcd(c,d);
    int ans=((b/c)-((a-1)/c))+((b/d)-((a-1)/d))-((b/g)-((a-1)/g));
    print(b-(a-1)-ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[50],n,a;
ll dp[55][55][2600];
ll recur(int pos,int sum,int cnt)
{
    if(pos==n)
    {

        if(cnt==0)
            return 0;
        int cur=sum/cnt;
        if(cur*cnt!=sum)
        return 0;
        if(cur==a)
            return 1;
        return 0;
    }
    ll &ret=dp[pos][cnt][sum];
    if(~ret)
        return ret;
    ret=0;
    ret+=recur(pos+1,sum,cnt);
    ret+=recur(pos+1,sum+arr[pos],cnt+1);

    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>a;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<recur(0,0,0)<<endl;




    return 0;
}


Measured memory_bytes: 65016
program sample
    implicit none
    character(100000)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
   
    read(*,*)n
    allocate(x(n),y(n))
    read(*,*)x
    m=0
    y(:)=0
    do i=1,n
        if(x(i)>n)then
            m=m+1
        else
            a=x(i)
            y(a)=y(a)+1
        endif
    end do
    do i=1,n
        if(y(i)>i)then
            m=m+y(i)-i
        elseif(y(i)<i)then
            m=m+y(i)
        end if
    end do
 
    write(*,*)m
    stop
end program sample
  



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

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("Error.txt", "w", stderr);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

void solve()
{
	string s;
	cin>>s;
	if(s[s.length()-1]=='s')
		s+="es";
	else
		s+="s";
	cout<<s;
}

int main()
{	
	checkpoint1();
/********************************************************/	
	auto startrrr = high_resolution_clock::now();
	cout << setprecision(20);
/*******************************************************/	
	
	solve();


/*******************************************************/	
	auto stoprrr = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stoprrr - startrrr);
	#ifndef ONLINE_JUDGE
		cerr << "Time: " << duration.count()/1000.0<<"\n";
	#endif
/*******************************************************/		
	return 0;
}

Measured memory_bytes: 3644