akhauriyash/Code-Regression huggingface dataset:
l = list(map(int, input().split()))
W = l[0]
H = l[1]
x = l[2]
y = l[3]
r = l[4]

left_x = x - r
right_x = x + r
top_y = y + r
bottom_y = y - r

if left_x >= 0 and right_x <= W and top_y <= H and bottom_y >= 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
def main():
    inf = 10**9
    H, N = map(int, input().split())
    AB = []
    for n in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))
    AB.sort(reverse=True, key=lambda x: x[0])
    dp = [inf] * (H + 10 ** 4)
    dp[0] = 0
    for a, b in AB:
        for h in range(H):
            if dp[h] != inf:
                tmp = dp[h] + b
                if tmp < dp[h + a]:
                    dp[h + a] = tmp
    print(min(dp[H:]))


main()


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

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

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

const int Maxn = 200005;
int n, ans, maxx, maxy, minx, miny, x[Maxn], y[Maxn];
int dis(int a, int b)
{
	return max(abs(x[a] - x[b]), abs(y[a] - y[b]));
}
int main()
{
	scanf("%d", &n);
	maxx = minx = maxy = miny = 1;
	for (int i = 1; i <= n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		x[i] = a + b, y[i] = a - b;
		if (x[i] > x[maxx]) maxx = i;
		if (x[i] < x[minx]) minx = i;
		if (y[i] > y[maxy]) maxy = i;
		if (y[i] < y[miny]) miny = i;
	}
	for (int i = 1; i <= n; i++)
		ans = max(ans, max(max(dis(i, maxx), dis(i, minx)), max(dis(i, maxy), dis(i, miny))));
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 5384
#include <iostream>
using namespace std;
int main(void){
   int n;
   long long a[10001]={0};
   cin >> n;
   for(int i=0;i<n;i++){
       cin >> a[i];
   }
   long long min =1000000,max=-1000000,sum=0;
   for(int i=0;i<n;i++){
       if(a[i]<min){
           min=a[i];
       }
   }
    for(int i=0;i<n;i++){
       if(a[i]>max){
           max=a[i];
       }   
       sum=sum+a[i];
   }
   cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

int n, m, k;
vector<vector<double> > memo;

double dfs(int num = 0, int sum = 0) {
	if(num == n)
		return max(1, sum - k) * 1.0;

	if(memo[num][sum] >= 0.0)
		return memo[num][sum];

	double res = 0.0;
	for(int i = 1; i <= m; ++i)
		res += dfs(num + 1, sum + i) / m;

	return memo[num][sum] = res;
}

int main() {
	while(scanf("%d %d %d", &n, &m, &k), n) {
		memo.clear();
		memo.resize(n, vector<double>(n * m, -1.0));
		printf("%.10lf\n", dfs());
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1268
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];

    for (int i = 0; i < n; i++) {
      s[i] = sc.next();
    }

    Arrays.sort(s);

    int count = 1;

    for (int i = 0; i < n-1; i++) {
      if (! s[i].equals(s[i+1])) {
        count++;
      }
    }

    System.out.println(count);

  }

}


Measured memory_bytes: 70144
#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.at(i);
  }
  
  for (int i =0; i<(N-K) ; i++){
    if (A.at(i) < A.at(i+K)){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }

}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define pb push_back
#define all(v) (v).begin(),v.end()
int main(){
  string s;
  cin>>s;
  int n=s.size();
  cout<<s[0]<<n-2<<s[n-1]<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, X;
ll L[110];

int main() {
  std::cin >> N >> X;

  rep( i, N )
    std::cin >> L[i];

  ll x = 0, ans = 1;

  rep( i, N ) {
    x += L[i];

    if( x <= X )
      ++ans;
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)
typedef vector<int> vec;
int main(){
  int n; cin>>n;
  int dp[n+5];
  int h[n+5];
  rep(i,n) cin>>h[i];
  rep(i,n){
    if(i==1) dp[i]=0;
    else if(i-2<1) dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    else dp[i]=min( dp[i-2]+abs(h[i]-h[i-2]) , dp[i-1]+abs(h[i]-h[i-1]) );
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
A, B, C, D = list(input())
a = ['+', '-']

for op1 in a:
  fml_1 = ''
  fml_1 += (op1 + B)
  for op2 in a:
    fml_2 = fml_1
    fml_2 += (op2 + C)
    for op3 in a:
      fml_3 = fml_2
      fml_3 += (op3 + D)
      if eval(fml_3) == 7 - int(A):
        print(A + fml_3 + '=7')
        exit()



Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void)
{
	double a, b, c;
	int tyouhoukei = 0, hisigata = 0;
	char op;
	while (cin >> a >> op >> b >> op >> c)
	{
		if (a == b) hisigata++;
		else if (sqrt(a * a + b * b) == c) tyouhoukei++;
	}
	cout << tyouhoukei << endl << hisigata << endl;
	return 0;
}


Measured memory_bytes: 3164
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String L = sc.next();
        int n = L.length();
        
        // dp[i][0] ・・・ a + b == L
        // dp[i][1] ・・・ a + b < L        
        long[][] dp = new long[n+5][2];
        int MOD = (int)1e9 + 7;
        
        dp[0][0] = 1;
        for(int i = 1; i <= n; i++){
            
            // (aのi番目) + (bのi番目) == 0 とする場合
            if ( L.charAt(i-1) == '0' ){
                dp[i][0] = dp[i-1][0];
                dp[i][1] = dp[i-1][1];
            } else if( L.charAt(i-1) == '1' ){
                dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % MOD;
            }
            
            // (aのi番目) + (bのi番目) == 1 とする場合
            if ( L.charAt(i-1) == '0' ){
                dp[i][1] += dp[i-1][1] * 2 % MOD;
                dp[i][1] %= MOD;
            } else if( L.charAt(i-1) == '1' ){
                dp[i][0] += dp[i-1][0] * 2 % MOD;
                dp[i][1] += dp[i-1][1] * 2 % MOD;
                dp[i][0] %= MOD;
                dp[i][1] %= MOD;
            }
        }
        
        System.out.println( (dp[n][0] + dp[n][1]) % MOD );
    }
}


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

#define MOD (1000 * 1000 * 1000 + 7)
#define INF (1LL << 60)
#define pb push_back
#define po pop_back
#define fi first
#define se second

typedef long long ll;
typedef long double ld;

#define maxn 100005
ll dp[maxn][3];
ll A[maxn][3];

int main() {
    int N;
    scanf("%d", &N);

    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j < 3; ++j) {
            scanf("%d", &A[i][j]);
        }
    }

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

    printf("%lld\n", max({dp[N][0], dp[N][1], dp[N][2]}));

    return 0;
}

Measured memory_bytes: 4992
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        int result = 0;
        for (int i = 1; i <= N; i++) {
            int num = sc.nextInt();
            if ((i % 2) == 1 && (num % 2 == 1)) {
                result++;
            }
        }
        pw.println(result);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


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

#define pii pair<int, int>
#define ft first
#define sd second

const int N = 1e5+5;
vector<pii> vec[N];
int col[N];

void dfs(int u, int p){
    for(pii x: vec[u]){
        if(x.ft != p){
            if(x.sd%2 == 0){
                col[x.ft] = col[u];
            }
            else{
                col[x.ft] = (col[u] ^ 1);
            }
            dfs(x.ft, u);
        }
    }
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u, v, h;
        cin >> u >> v >> h;
        vec[u].push_back({v, h});
        vec[v].push_back({u, h});
    }
    dfs(1, 0);
    for(int i = 1 ; i<= n; i++)
        cout << col[i] << " ";
}


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

int main(int argc, char const *argv[]) {
    long long n, k;
    cin >> n >> k;
    long long a = n % k;

    long long b = abs(a - k);
    n = min(a, b);

    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3592
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int x = in.ni(), a = in.ni(), b = in.ni();
        out.println((Math.abs(x-a)<Math.abs(x-b))?'A':'B');
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

n, k, s = map(int, input().split())
ans = [ 0 for _ in range(n) ]

for i in range(n):
    if i < k:
        ans[i] = s
    else:
        if s == 1000000000:
            ans[i] = 999999999
        else:
            ans[i] = 1000000000


print(" ".join(map(str, ans)))



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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

int main() {
  int N;cin>>N;
  string S = to_string(N);
  int SN = accumulate(ALL(S),0,[](int a,char c){ return a+(c-'0'); });
  (N%SN==0) ? OUT("Yes") : OUT("No");

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	static int n;
	static Scanner sc = new Scanner(System.in);
	static Queue<String> events;
	
	static boolean read() {
		int cnt = 0;
		String event;
		events = new LinkedList<String>();
		do {
			event = sc.next();
			if(event.equals("OUT")) {
				cnt++;
			} else {
				events.offer(event);
			}
		} while(cnt < 3);
		
		return true;
	}
	
	static int solve() {
		int ans = 0, s = 0;
		while(!events.isEmpty()) {
			String e = events.poll();
			s = (s << 1) + 1;
			if(e.equals("HIT")) {
				//Single hit
				if((s & 8) > 1) {
					ans++;
				}
				s = (s & 7);
			} else {
				//homerun
				for(int i = 1; i < 16; i = (i << 1)) {
					if((s & i) >= 1) {
						ans++;
					}
				}
				s = 0;
			}
		}
		
		return ans;
	}
	
	public static void main(String[] args) {
		n = sc.nextInt();
		while(n -- > 0 && read()) {
			System.out.println(solve());
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int M=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long ll;
typedef pair<int,int> PII;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	int n;
	cin>>n;
	bool flag=0;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(t%2==0){
			if(t%3!=0&&t%5!=0)
				flag=1;
		}
	}
	if(flag)
		cout<<"DENIED"<<endl;
	else
		cout<<"APPROVED"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		String[] str = num.split(" ", 0);
		int k = Integer.parseInt(str[0]);
		int c = Integer.parseInt(str[1]);
		if(k%3==0) {
			System.out.println("Possible");
		}else if(c%3==0) {
			System.out.println("Possible");
		}else if((c+k)%3==0) {
			System.out.println("Possible");
		}else {
			System.out.println("Impossible");
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
int N; cin >> N;
vector<ll> A(N); rep(i, 0, N) cin >> A[i];//scanf("%ld", &A[i]);

// 累積和
vector<long long> s(N+1, 0); 
partial_sum(ALL(A), s.begin() + 1);
// s の集計
unordered_map<long long, long long> nums;
rep(i, 0, N+1) nums[s[i]]++;

ll cnt=0, num;
for (pair<long long, long long> p : nums){
    num = p.second;
    cnt += num * (num - 1) / 2;
}

cout << cnt << "\n";

return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.
// map[]は対数時間．unordered_map[]は一定時間．


Measured memory_bytes: 11592
/*
AM 02:54 -> AM 06:45
 */
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<cassert>
#include<bitset>
#include<cmath>
#include<climits>
#include<unordered_map>
#include<unordered_set>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 200
#define all(a) (a).begin(),(a).end()

using namespace std;

int N,limit,tail;
int d[MAX];
int remain[10000];
int town[30];

set<vector<int>> result;

pair<vector<int>,bool> check(int state,int pos,int value){

  if((state>>pos) & 1)return pair<vector<int>,bool>(vector<int>(),false);
  assert(value >= 0);
  int pstate = state;
  vector<int> add;
  pstate = pstate & ((1<<N)-2);
  while(pstate){
    int use = log2(pstate & -pstate);

    int diff1 = abs(town[use]-value);

    if(remain[diff1] == 0){
      break;
    }
    pstate -= (pstate & -pstate);
    add.push_back(diff1);
    remain[diff1]--;
  }

  return pair<vector<int>,bool>(add,(pstate == 0));

}

void dfs(int state,int last){
  if(state == (1<<N)-1){
    vector<int> vec;
    REP(i,1,N){
      vec.push_back(town[i]-town[i-1]);
    }
    result.insert(vec);
    return;
  }

  while(last >= 0 && remain[d[last]] == 0)last--;
  if(last < 0 || ( last >= 0 && remain[d[last]] == 0))return;

  int value = d[last];
  int rstate = ~state & ((1<<N)-1);
  int use = log2(~state & ((1<<N)-1));
  vector<int> add;
  remain[value]--;
  pair<vector<int>,bool> F = check(state,use,value);
  add = F.first;
  if(F.second){//N徳恐粒
    town[use] = value;
    dfs(state|(1<<use),last);
    town[use] = -1;
  }

  remain[value]++;

  for(int i : add){
    remain[i]++;
  }

  if(remain[tail-value] == 0)return;
  use = log2(rstate & -rstate);

  remain[tail-value]--;
  F = check(state,use,tail-value);

  add = F.first;
  if(F.second){// 0徳恐粒
    town[use] = tail - value;
    dfs(state|(1<<use),last);
    town[use] = -1; 
  }

  remain[tail-value]++;

  for(int i : add){
    remain[i]++;
  }
}

void compute(){
  town[0] = 0;
  town[N-1] = d[limit-1];
  remain[d[limit-1]]--;
  tail = d[limit-1];

  dfs(1|(1<<(N-1)),limit-1);

  for(vector<int> i : result){
    rep(j,i.size()){
      if(j)cout << ' ';
      cout << i[j];
    }
    cout << endl;
  }

}

int main()
{
  while(cin >> N,N){
    result.clear();
    
    limit = (int)(N*(N-1)*0.5);
    for(int& i : remain){
      i = 0;
    }

    vector<int> input;
    rep(i,N)town[i] = -1;
    rep(i,limit){
      cin >> d[i];
      assert(d[i]);
      input.push_back(d[i]);
      remain[d[i]]++;
    }

    sort(all(input));
    input.erase(unique(all(input)),input.end());
    limit = input.size();
    rep(i,limit)d[i] = input[i];

    compute();
    puts("-----");
  }

  return 0;
}

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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << '+' << endl;
	}
	else if (a*b == 15) {
		cout << '*' << endl;
	}
	else {
		cout << 'x' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define fi first
# define se second
# define mk make_pair
using namespace std;
const int MAX = 2e6 + 2;
const int MAXN = 2e6 + 5;
const int MAXM = 5e3 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<double, int> PDI;
int A[MAXN], invA[MAXN];


int qpow(int a, int b){
    int res = 1;
    while(b > 0){
        if(b&1)  res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}


void init(){
    A[0] = 1;
    for(int i = 1;i <= MAX; ++i){
        A[i] = 1LL * A[i-1] * i % MOD;
    }
    invA[MAX] = qpow(A[MAX], MOD - 2);
    for(int i = MAX - 1; i >= 0; --i){
        invA[i] = (1LL * invA[i + 1] * (i + 1)) % MOD;
    }
}

int C(int n, int m){
    return 1LL * A[n] * invA[m] % MOD * invA[n-m] % MOD;
}

int f(int r, int c){
    return C(r + c, c);
}

int g(int r, int c){
    int res = 0;
    for(int i = 2; i <= r + 1; ++i){
        res = (1LL * res + 1LL * f(i, c)) % MOD;
    }
    return (1LL * res - r + MOD) % MOD;
}


int calc(int r1, int c1, int r2, int c2){
    int res = 0;
    res = (1LL * res + g(r2, c2)) % MOD;
    if(c1 > 1)  res = (1LL * res - g(r2, c1 - 1) + MOD) % MOD;
    if(r1 > 1)  res = (1LL * res - g(r1 - 1, c2) + MOD) % MOD;
    if(c1 > 1 and r1 > 1)  res = (1LL * res + g(r1 - 1, c1 - 1)) % MOD;
    return res;
}


int main(){
    init();
    int r1, c1, r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    printf("%d\n", calc(r1, c1, r2, c2));
    return 0;
}
/*
2 5 9 14 20 27 35 44 54 65
5 14 28 48 75 110 154 208 273 350
9 28 62 117 200 319 483 702 987 1350
14 48 117 242 451 780 1274 1988 2988 4352
20 75 200 451 912 1703 2989 4990 7992 12359
27 110 319 780 1703 3418 6420 11424 19431 31806
35 154 483 1274 2989 6420 12854 24293 43740 75563
44 208 702 1988 4990 11424 24293 48602 92359 167940
54 273 987 2988 7992 19431 43740 92359 184736 352695
65 350 1350 4352 12359 31806 75563 167940 352695 705410
 */

Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    int buf;
    cin >> buf;
    p.push_back(buf);
  }

  int count = 0;
  for (int i = 1; i < p.size()-1; i++) {
    if ((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])) count++;
  }

  cout << count << endl;
  return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int K=sc.nextInt();
		ArrayList<Integer> d=new ArrayList<Integer>();
		for(int i=Math.max(A, B);i>=1;i--){
			if(A%i==0 && B%i==0) d.add(i);
		}
		//d.forEach(e->System.out.println(e));
		System.out.println(d.get(K-1));
	}

}

Measured memory_bytes: 23632
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long mod = 1000000007;
int N, M, K;
long long fib[10];
long long dp[200][10];

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> M >> K;
  fib[0] = 1;
  fib[1] = 1;
  for(int i = 2;i < 10;i++) {
    fib[i] = (fib[i-1] + fib[i-2]) % mod;
  }

  for(int i = 0;i < N;i++) {
    for(int j = 0;j < M;j++) {
      if(i == 0) {
        if(j == 0) dp[i][j] = fib[M-1];
        else if(j == 1) dp[i][j] = fib[M-2];
        else dp[i][j] = 0;
        continue;
      }

      dp[i][j] = (dp[i-1][j]*(fib[j]*fib[M-j-1]) % mod) % mod;
      if(j - 1 >= 0) {
          long long x = (dp[i-1][j-1]*(fib[j-1]*fib[M-j-1]) % mod) % mod;
          dp[i][j] = (dp[i][j] + x) % mod;
      }
      if(j + 1 < M) {
        long long x = (dp[i-1][j+1]*(fib[j]*fib[M-j-2]) % mod) % mod;
        dp[i][j] = (dp[i][j] + x) % mod;
      }
    }
  }

  cout << dp[N-1][K-1] << endl;

  return 0;
}


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

int fac(int x) {
  int tmp = x;
  for (int i = 1; i < x - 1; ++i) tmp *= x - i;
  return tmp;
}

int main() {
  int n;
  double total = 0;

  cin >> n;

  vector<pair<int, int>> city;
  vector<int> jun;

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    city.push_back(make_pair(x, y));
    jun.push_back(i);
  }

  do {
    for (int i = 0; i < n - 1; i++) {
      total += sqrt(
          pow(city.at(jun.at(i)).first - city.at(jun.at(i + 1)).first, 2.0) +
          pow(city.at(jun.at(i)).second - city.at(jun.at(i + 1)).second, 2.0));
    }
  } while (next_permutation(jun.begin(), jun.end()));

  cout << setprecision(100) << total / fac(n);

  return 0;
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
Ngrid = [[i for i in input()] for i in range(N)]
Mgrid = [[i for i in input()] for i in range(M)]

for h in range(N-M+1):
  for w in range(N-M+1):
    for m in range(M):
      for mm in range(M):
        #print(h+m,w+mm, Mgrid[m][mm])
        if Ngrid[h+m][w+mm] == Mgrid[m][mm]:
          continue
        else:
          break
      else:
        continue
      break
    else:
      print("Yes")
      exit()
else:
  print("No")

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

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

Measured memory_bytes: 256
H, W = map(int, input().split())
if H * W % 3 == 0:
    print(0)
else:
    ans = H * W
    Wsmall = W // 2
    for i in range(1, H + 1):
        A = i * Wsmall
        B = i * (W - Wsmall)
        C = (H - i) * W
        ans = min(ans, max(A, B, C) - min(A, B, C))
    
    Hsmall = H // 2
    for i in range(1, W + 1):
        A = Hsmall * i
        B = (H - Hsmall) * i
        C = H * (W - i)
        ans = min(ans, max(A, B, C) - min(A, B, C))

    Wsmall = W // 3
    Wbig = W // 3 + 1
    ans = min(ans, H * (Wbig - Wsmall))

    Hsmall = H // 3
    Hbig = H // 3 + 1
    ans = min(ans, (Hbig - Hsmall) * W) 
    
    print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <sstream>
#include <string>
#include <vector>

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

  size_t x;

  std::cin >> x;

  size_t d_500 = x / 500;
  size_t r_500 = x % 500;

  size_t d_5 = r_500 / 5;
  size_t r_5 = r_500 % 5;

  std::cout << d_500 * 1000 + d_5 * 5 << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
int S[100][2];
int n;
int i=0;
int cnt=0;

    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d %d", &S[i][0], &S[i][1]);

    for(i=0; i<n; i++){
        if(S[i][0]==S[i][1]) cnt++; 
        else                 cnt=0;
        if(cnt==3)          break;
    }
    if(cnt==3) printf("Yes");
    else       printf("No");    
    return 0;
}

Measured memory_bytes: 1712
mod = 10**9+7

def comb(n, r):
    if 2 * r > n: return comb(n, n-r)
    return fac[n] * inv[r] * inv[n-r] % mod

x, y = map(int, input().split())
if (x+y) % 3 != 0:
  print(0)
  exit()
     
n = (x+y)//3
x -= n
y -= n
if x<0 or y<0:
  print(0)
  exit()
  
fac = [1] * (n+2)
inv = [1] * (n+2)
for i in range(2, n+1):
    fac[i] = fac[i-1] * i % mod
inv[n] = pow(fac[n], mod - 2, mod)
for i in range(n-1, 1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod
  
print(comb(x+y, x) % mod)

Measured memory_bytes: 55796
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int main() {
    string s;
    cin >> s;
    for(int i = s.size()-1; i > 0; i--) {
        cout << s[i];
    }
    cout << s[0] << endl;
    return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>

long N(long x){
  return (x+1)*(x+2)*(x+3)/6;
}

int main(){
  long n,m;
  while(~scanf("%ld",&n)){
    if (n > 2000)
      n = 4000 - n;
    if (n < 1001)
      printf("%d\n",N(n));
    else {
      m = n - 1000;
      printf("%ld\n", N(n)-(N(2*m)-m-1)/2);
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 10000010;

bool p[N];

int main(){
    fill(p,p+N,true);
    p[0] = p[1] = false;
    for(int i=2; i<N; ++i){
        if(p[i]) for(int j=2*i; j<N; j+=i) p[j] = false;
    }

    int n;
    cin >>n;

    int ans = 0;
    for(int q=3; q<=n; ++q){
        if(p[q] && p[q+2]) ans += 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 12856
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| add(a)}
  end

  def add(element)
    @data.push(element)
    bottom_up
  end

  def peek
    @data[0]
  end

  def poll
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end

  def size
    @data.size
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  def bottom_up
    idx = size - 1
    while(has_parent?(idx))
      parent_idx = parent_idx(idx)
      if @data[parent_idx][:key] > @data[idx][:key]
        swap(parent_idx, idx)
        idx = parent_idx
      else
        return
      end
    end
  end

  def top_down
    idx = 0
    while (has_child?(idx))
      a = left_child_idx(idx)
      b = right_child_idx(idx)
      if @data[b].nil?
        c = a
      else
        c = @data[a][:key] <= @data[b][:key] ? a : b
      end
      if @data[idx][:key] > @data[c][:key]
        swap(idx, c)
        idx = c
      else
        return
      end
    end
  end

  def parent_idx(idx)
    (idx - (idx.even? ? 2 : 1)) / 2
  end

  def left_child_idx(idx)
    (idx * 2) + 1
  end

  def right_child_idx(idx)
    (idx * 2) + 2
  end

  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end

  def has_parent?(idx)
    idx > 0
  end
end

N = gets.to_i
A = gets.split.map(&:to_i)

sorted = A.sort_by{ |v| -v }
comb = PriorityQueue.new([{ key: -sorted[1], value: [sorted[0],sorted[1]]}] * 2)

ans = sorted[0]
sorted[2..-1].each do |v|
  tmp = comb.poll
  ans += -tmp[:key]
  comb.add({ key: -v, value: [v, tmp[0]] })
  comb.add({ key: -v, value: [v, tmp[1]] })
end

puts ans


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K; cin >> N >> K;
    int ans = 0;
    REP(i,N){
        int x; cin >> x;
        ans += min(2*x, 2*(K-x));
    }
    cout << ans << endl;
    return 0;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long dp[55][6000];
main()
{
	int t,p,q;
	scanf("%d%d",&t,&p);
	dp[0][3000]=1;
	for(int i = 0;i < t;i++)
	{
		scanf("%d",&q);
		for(int j = 0;j < 6000;j++)
		{
			if(dp[i][j]!=0 && j+q-p>=0 && j+q-p<6000)
			{
				dp[i+1][j+q-p]+=dp[i][j];
			}
			dp[i+1][j]+=dp[i][j];
		}
	}
	printf("%lld",dp[t][3000]-1);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define maxn 200001
using namespace std;
int main()
{
	int N;
	long long ans=0;
	cin>>N;
	for (int a=1;a<=N;a++)
		for (int b=1;b*a<N;b++)
		{
			ans++;
		}
	cout<<ans<<endl;	
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    string s;
    cin>>s;
    if(s=="Sunny") cout<<"Cloudy";
    else if(s=="Cloudy") cout<<"Rainy";
    else if(s=="Rainy") cout<<"Sunny";
    return 0;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#define ll long long
#define pii pair<ll,ll>
#define m_p  make_pair
#define ull unsigned long long
#define spd  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
ll ans[N],cum_sum[N];
int main()
{
    spd;

    ll n,k,d,neg,div,pos,mid,req;

    cin>>n>>k>>d;

    if(n<0)n = abs(n);

    pos = n/d;

    if(pos>=k)
    {
        ll des = (n%d) + (pos-k)*d;

        cout<<des<<endl;
    }

    else
    {
       req = k-pos;

       if(k%2==pos%2)
       {
           cout<<n%d<<endl;
       }

       else
        cout<<abs((n%d)-d)<<endl;
    }
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
using namespace std;
int n,ans;
char s[110];
int main(){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        int a[26]={},b[26]={},m=0;
        for(int j=0;j<n;j++){
            if(j<i) a[s[j]-'a']=1;
            else b[s[j]-'a']=1;
        }
        for(int j=0;j<26;j++){
            if(a[j]&&b[j]) m++;
        }
        ans=max(ans,m);
    }
    cout<<ans;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
s = input()
a_num = 0
b_num = 0
for i in s:
    if i == "a":
        if a_num + b_num < a + b:
            print("Yes")
            a_num += 1
        else:
            print("No")
    elif i == "b":
        if a_num + b_num < a + b and b_num < b:
            print("Yes")
            b_num += 1
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 4016
package main

import "fmt"

func main() {
    var a int
    fmt.Scan(&a)

    var b int
    fmt.Scan(&b)

    var c int
    fmt.Scan(&c)
  
  r := c - a + b
  if r < 0 {
    r = 0
  }
  
    fmt.Println(r)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define vi vector<ll>
# define vvi vector<vi>
# define rep(i, N) for (int i = 0; i < N; i++)
# define Rep(i, N) for (int i = 1; i <= N; i++)
# define deb(x) cerr << #x << ": " << x << endl;
# define deb2(x, i) cerr << #x << "[" << i << "]: " << x[i] << endl;
/*
vi v(10, 2); 
rep(i, 10) deb2(v, i); 
*/

/*
int a; cin >> a;
int a, b; cin >> a >> b;
rep(i, n){cin >> v[i];}
cout <<   << endl;
*/

signed		main()
{
	string s; cin >> s;
	cout << (s == "ARC" ? "ABC": "ARC")  << endl;
		
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,m;
string s,t;

int main() {
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  int ans=0;
  rep(i,n){
    while(i+1<n && a[i]==a[i+1]) i++;
    if(a[i+1]<a[i])
      while(i+1<n && a[i+1]<=a[i]) i++;
    else if(a[i+1]>a[i])
      while(i+1<n && a[i+1]>=a[i]) i++;
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int num[3];
  int max = 0;
  int flag;
  for(int i=0; i<3; i++){
    scanf("%d", num+i);
    if(num[i] > max){
      max = num[i];
      flag = i;
    }
  }
  int ans = (max*2-num[(flag+1)%3]-num[(flag+2)%3])/2;
  if(num[(flag+1)%3]%2!=num[(flag+2)%3]%2)
    ans += 2;

  printf("%d\n", ans);
  return 0;
}
      


Measured memory_bytes: 128
using System;
using System.Collections.Generic;


public class C{
	
	public static void Main(){
	
		int n = Int32.Parse( Console.ReadLine() );
		List<int> result = new List<int>();
		
		int rest = n;
		int i = 0;
		while(true){
			if( (rest & (1 << i)) == 0 ){
				result.Add(0);
				
			}else{
				result.Add(1);
				if( (i & 1) == 0 ){
					rest -= (1 << i);
				}else{
					rest += (1 << i);
				}
				
			}
			if( rest == 0 ) break;
			i++;
		}
		
		for( int j = 0; j < result.Count; j++ ){
			Console.Write( result[result.Count - 1 - j ] );
		}
		Console.WriteLine();
		
	}

}

Measured memory_bytes: 13140
n,m = map(int,input().split())
data = []
for i in range(m):
    k,*s = map(int,input().split())
    data.append(set(s))
p = list(map(int,input().split()))

ans = 0
for i in range(1<<n):
    on = set()
    for j in range(n):
        if i>>j&1:on.add(j+1)
    if all([len(on&data[l])%2==p[l] for l in range(m)]):ans+=1
print(ans)


Measured memory_bytes: 43484
#include<stdio.h>
#include<string.h>
#define LEN 100005
typedef struct a{
	char name[100];
	int t;
}P;


P Q[LEN];

int head,tail,n;

void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}
P dequeue(){
	P x =Q[head];
	head = (head+1)%LEN;
	return x;
}

int min(int a,int b){
	if(a<b){return a;}
	else{return b;}
}

int main(void){
	int e=0;
	int c;
	int q;
	P u;
	int i;
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1;
	tail=n+1;
	while(head!=tail){
		u =dequeue();
		c = min(q,u.t);
		u.t=u.t-c;
		e=e+c;
		if(u.t>0){
			enqueue(u);
		}
		else{
			printf("%s %d\n",u.name,e);
		}
	}
	
	
	return 0;
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e2 + 10;
const int mod = 1e9 + 7;


map<int, int> mp;

void fac(int n){
	while(n%2 == 0){
		n /= 2;
		mp[2]++;
	}
	int sq = sqrt(n);
	for(int i = 3 ; i <= sq ; i+=2){
		while(n%i == 0){
			n /= i;
			mp[i]++;
		}
	}

	if(n != 1){
		mp[n]++;
	}

}
int32_t main(){
	boost;

	string s;
	cin >> s;
	int a , z;
	for(int i = 0 ; i < s.size() ; ++i){
		if(s[i] == 'A'){
			a = i;
			break;
		}
	}


	for(int i = s.size()-1 ; i >= 0 ; --i){
		if(s[i] == 'Z'){
			z = i;
			break;
		}
	}

	
	cout << z - a + 1;
	return 0;
}

Measured memory_bytes: 720
/**
 *      
 *      
 *      SoundHound Inc. Programming Contest 2018 -Masters Tournament- B
 *      author  : kyomukyomupurin
 *      created : 2018-10-28 00:53:40
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int64 long long
#define print(x) cout << (x) << '\n'
using namespace std;

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

    string S; cin >> S;
    int w; cin >> w;

    for (int i = 0; i < (int) S.size(); i += w) {
        cout << S[i];
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,sum[101],ans,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x;
		cin>>x;
		for(int j=1;j<=x;j++)
		{
			int y;
			cin>>y;
			sum[y]++;
		}
	}
	for(int i=1;i<=n;i++)ans+=(sum[i]==0?1:0);
	cout<<ans;
	
}


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  
  sort(V.begin(),V.end());
  int count = 0;
  for (int j = 0; j < K; j++) 
    count += V.at(j);
  
  cout << count << endl;
  
}


Measured memory_bytes: 3592
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ll INF = 1e15;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}

ll pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a;
	}
	ll ans = pow(a, b / 2);
	ans *= ans;
	ans *= b % 2 == 1 ? a : 1;
	return ans;
}

namespace SOLVE {
	int n;
	double dp[305][305][305];

	double expected_depth(int ones, int twos, int threes) {
		if (dp[ones][twos][threes] != -1) {
			return dp[ones][twos][threes];
		}
		double total_depth = 0.0;
		if (ones + twos + threes == 0) {
			dp[ones][twos][threes] = 0.0;
			return 0.0;

		}
		if (ones != 0) {
			total_depth += (double)ones * (expected_depth(ones - 1, twos, threes));
		}
		if (twos != 0) {
			total_depth += (double)twos * (expected_depth(ones + 1, twos - 1, threes));
		}
		if (threes != 0) {
			total_depth += (double)threes * (expected_depth(ones, twos + 1, threes - 1));
		}
		total_depth += (double)n;
		total_depth *= 1.0 / (double)(ones + twos + threes);
		
		//cout << ones << ' ' << twos << ' ' << threes <<  ' ' << total_depth << endl;
		dp[ones][twos][threes] = total_depth;
		return total_depth;
		
	}

	void main() {
		cin >> n;
		int temp;
		VI counts(4);

		REP(i, 0, n) {
			cin >> temp;
			counts[temp]++;
		}

		REP(i, 0, n+1) {
			REP(j, 0, n+1) {
				REP(k, 0, n+1) {
					dp[i][j][k] = -1.0;
				}
			}
		}

		/*
		while (big < 1e9) {
			big *= n;
		}
		*/
	
		double ans = expected_depth(counts[1], counts[2], counts[3]);

		printf("%.10lf", ans);
	}
}


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

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}


Measured memory_bytes: 219392
def lunlun_maker(l: int) -> int:
    next_lunluns = []
    for e in l:
        nxt = e * 10
        mod = e % 10
        if 0 < mod < 9:
            next_lunluns.extend([nxt + mod - 1, nxt + mod, nxt + mod + 1])
        elif mod == 0:
            next_lunluns.extend([nxt, nxt + 1])
        elif mod == 9:
            next_lunluns.extend([nxt + 8, nxt + 9])
    return next_lunluns


def get_lunlun(num: int) -> int:
    lunluns = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    counter = len(lunluns)
    counter_tmp = counter
    while counter < num:
        lunluns = lunlun_maker(lunluns)
        counter_tmp = counter
        counter += len(lunluns)
    return lunluns[num - counter_tmp - 1]


K = int(input())
print(get_lunlun(K))

Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6, INF = 1e9;
int a[N+5];
int main(){
	int n, k; cin >> n >> k;
	vector<int> dp(n, INF);
	for(int i = 0; i < n; i++)cin >> a[i];
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j <= i+k; j++)
			if(j < n) 
				dp[j] = min(dp[j], dp[i]+abs(a[j]-a[i]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 4060
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        int k = ipar();
        ntok();
        int[] arr = iapar(n);
        int count = 0;
        for (int i = 0; i < n; i++)
        {
            if (arr[i] >= k)
            {
                count++;
            }
        }
        out.println(count);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 31444
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
                     // I'm in Love with Experience. �😎�
void solve()
{
    ll D,T,S;cin>>D>>T>>S;
    if((D/(double)S)<=T)cout<<"Yes";
    else cout<<"No";
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);solve();exit(0);
}/*Solved By:- Ritik Agarwal*/

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

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

  bool ok = true;
  if (c < d /* A B C D */) {
    for (int i = a + 1; i <= c; i++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        ok = false;
        break;
      }
    }
    for (int i = b + 1; i <= d; i++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        ok = false;
        break;
      }
    }
  } else { /* A B D C */
    for (int i = a + 1; i <= c; i++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        ok = false;
        break;
      }
    }
    for (int i = b + 1; i <= d; i++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        ok = false;
        break;
      }
    }
    bool jump = false;
    for (int i = b; i <= d; i++) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
        jump = true;
        break;
      }
    }
    if (!jump) {
      ok = false;
    }
  }

  if (ok) {
    puts("Yes");

  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 3756