akhauriyash/Code-Regression huggingface dataset:
using System.Linq;
using System.Collections.Generic;
using System;


public class hello
{
    public static void Main()
    {
        var maxlength = 0;
        var maxlengthword = "";
        var dict = new Dictionary<string,int>();
        string[] s = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i].Length > maxlength)
            {
                maxlength = s[i].Length;
                maxlengthword = s[i];
            }
            if (dict.ContainsKey(s[i])) dict[s[i]] += 1;
            else dict[s[i]] = 1;
        }
        var ans = dict.OrderByDescending(x => x.Value).First().Key;
        Console.WriteLine("{0} {1}", ans, maxlengthword);


    }
}

Measured memory_bytes: 9856
#include <cstdio>
using namespace std;
int main(void){
  int i=0,a,b,c,d;
  int day;

  scanf("%d %d %d %d %d",&day,&a,&b,&c,&d);
  while(a>0||b>0){
    a-=c;
    b-=d;
    i++;
  }
  printf("%d\n",day-i);
  return 0;
}

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

const int N = 1e5 + 5;

int n, m;
int a[N];
int par[N];
vector<int> vec[N];
vector<int> vals;
long long ans = 0;

int anc(int u) {
	return par[u] == u ? u : par[u] = anc(par[u]);
}

void join(int u,int v) {
	par[anc(v)] = anc(u);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) par[i] = i;
	for (int i = 0; i < m; ++i) {
		int u, v; cin >> u >> v;
		join(u, v);
	}
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		cnt += anc(i) == i;
		vec[anc(i)].push_back(a[i]);
	}
	if (cnt == 1) return cout << 0 << '\n',0;
	int choose = 2 * cnt - 2;
	for (int i = 0; i < n; ++i) if (anc(i) == i) {
		sort(vec[i].begin(), vec[i].end());
		ans += vec[i][0];
		choose--;
		for (int j = 1; j < vec[i].size(); ++j) {
			vals.push_back(vec[i][j]);
		}
	}
	if (choose > vals.size()) return cout << "Impossible\n",0;
	sort(vals.begin(), vals.end());
	for (int i = 0; i < choose; ++i) ans += vals[i];
	cout << ans << '\n';
}

Measured memory_bytes: 6528
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()

print(((N+N%2)/2)/N)


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

typedef long long LL;

int main()
{   ios::sync_with_stdio(false);
    LL a, b, n, x;

    cin>>a>>b>>n;

    x = (n<b)? n:(b-1);

    cout<<a*x/b-a*(x/b);

	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int sum;
    int count = 0;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                sum = 500 * i + 100 * j + 50 * k;
                if (sum == X)
                {
                    count++;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;
//using namespace atcoder;

int main(){
    int a,b;
    cin>>a>>b;
    if(a>=13) b=b;
    else if(a>=6) b/=2;
    else b=0;
    cout<<b<<endl;
}


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

int main()
{
    int c=0,a=0,b=0,i;
    char s[3]= {'\0'};
    scanf("%c%c%c",&s[0],&s[1],&s[2]);
    for(i=0; i<3; i++)
    {
        if(s[i]=='a')
            a++;
        if(s[i]=='b')
            b++;
        if(s[i]=='c')
            c++;
    }
    if(a==1&&b==1&&c==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
ll get_ans(ll x)
{
    if(x<0)
        return 0;
    if(x%4==1)
        return 1;
    else    if(x%4==2)
        return x+1;
    else    if(x%4==3||x==0)
        return 0;
    else    return x;
}
int main()
{
    cin>>a>>b;
    ll aa=get_ans(a-1);
    ll bb=get_ans(b);
    aa=aa^bb;
    cout<<aa;
    return 0;
}

Measured memory_bytes: 256
import java.util.*; 
import java.math.*;
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal a = new BigDecimal(sc.next());
		BigDecimal b = new BigDecimal(sc.next());
		BigDecimal c = a.multiply(b);
		BigDecimal d = c.setScale(0,RoundingMode.FLOOR);
		System.out.println(d);
		sc.close();
	}
 
}

Measured memory_bytes: 35796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int k;
	int a,b;
	cin>>k;
	cin>>a>>b;
	bool flag=true;
	for(int i=a;i<=b;i++){
		if(i%k==0){
		cout<<"OK";flag=false;break;}
	}
	if(flag)
	cout<<"NG";
	return 0;
}


Measured memory_bytes: 3548
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<998244353>;
// template<> const Mint Mint::G = Mint(3);

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

    int n;
    cin >> n;
    V<int> freq(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i == 0 && x) {
            cout << 0 << endl;
            return 0;
        }
        if (i && x == 0) {
            cout << 0 << endl;
            return 0;
        }
        freq[x]++;
    }
    Mint sm = Mint(1);
    for (int i = 1; i < n; i++) {
        sm *= Mint(freq[i - 1]).pow(freq[i]);
    }
    cout << sm << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i, n) cin >> w[i];
  int ans = 1e9;
  
  for(int i = 0; i < n; ++i) {
    int lsum = 0;
    int rsum = 0;
    for(int j = 0; j <= i; ++j) {
      lsum += w[j]; 
    }
    for(int j = i + 1; j <= w.size() - 1; ++j) {
      rsum += w[j];
    }
    int delt = abs(lsum - rsum); 

    ans = min(ans, delt);
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> vec(n, vector<int>(10));
  rep(i, n){
    rep(j, 10){
      cin >> vec[i][j];
    }
  }
  vector<vector<int>> point(n, vector<int>(11));
  rep(i, n){
    rep(j, 11){
      cin >> point[i][j];
    }
  }
  int biggest = mod;
  for (int bit = 0; bit < (1<<10); ++bit) {
    vector<int> S;
    for (int i = 0; i < 10; ++i) {
      if (bit & (1<<i)) {
        S.push_back(i);
      }
    }
    if(S.empty()) continue;
    int sum = 0;
    rep(i, n){
      int cnt = 0;
      for(auto p : S){
        if(vec[i][p] == 1) cnt++; 
      }
      sum += point[i][cnt];
    }
    if(biggest == mod) biggest = sum;
    else biggest = max(biggest, sum);
  }
  cout << biggest << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int i,j,n,m,temp;
    vector< vector <int> > a;
    vector<int> b;
    cin>> n>> m;
    a.resize(n);
    b.resize(m);
    for(i=0;i<n;i++){
        a[i].resize(m);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            a[i][j]=0;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>> a[i][j];
        }
    }
    for(j=0;j<m;j++){
        cin>> b[j];
    }
    for(i=0;i<n;i++){
        temp=0;
        for(j=0;j<m;j++){
            temp+=a[i][j]*b[j];
        }
        cout<< temp<< endl;
    }
    
    return 0;
}

Measured memory_bytes: 1244
DT = input()
data = DT.split()

N = int(data[0])
x = int(data[1])

DT = input()
a = DT.split()
for lop in range(len(a)):
    a[lop] = int(a[lop])
a = sorted(a)

cnt = 0
for lop in range(len(a)):
    if x < 0:
        break
    x -= a[lop]
    cnt += 1

if not(x == 0):
    cnt -= 1

print(cnt)

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

MOD = 1000000007  # type: int

def get_factors(n):
    fact = 2
    tmp = n
    ret = []
    while fact * fact <= n:
        count = 0
        while tmp % fact == 0:
            tmp //= fact
            count += 1
        if count > 0:
            ret.append(count)
            #print(fact)
        fact += 1
    if tmp > 1:
        ret.append(1)
    return ret

def comb(n, k):
    if k > n:
        return 0
    ret = 1
    k = min(k, n - k)
    for i in range(k):
        ret *= n - i
        ret //= i + 1
    return ret

def solve(N: int, M: int):
    facts = get_factors(M)
    #print(facts)
    ret = 1
    for c in facts:
        ret *= comb(c + N - 1, N - 1)
    print(ret % MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        int[] A = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        int[] dT = new int[n];
        List<int> iT = new List<int>();
        int[] dA = new int[n];
        List<int> iA = new List<int>();
        for (int i = 0; i < n; i++)
        {
            if(i == 0){
                dT[i] = T[i];
                iT.Add(i);
            }
            else if(i == n - 1){
                dA[i] = A[i];
                iA.Add(i);
            }
            else{
                if(T[i - 1] != T[i]){
                    dT[i] = T[i];
                    iT.Add(i);
                }
                if(A[i] != A[i + 1]){
                    dA[i] = A[i];
                    iA.Add(i);
                }
            }
        }
        Console.Error.WriteLine("iT: {0}", string.Join(" ", iT));
        Console.Error.WriteLine("iA: {0}", string.Join(" ", iA));
        bool contra = false;
        foreach (int idx in iT)
        {
            Console.Error.WriteLine("T idx: {0}", idx);
            if(dT[idx] > A[idx] || (dA[idx] != 0 && dT[idx] != dA[idx])) contra = true;
            if(contra) break;
        }
        foreach (int idx in iA)
        {
            Console.Error.WriteLine("A idx: {0}", idx);
            if(dT[idx] != 0){
                if(dA[idx] > T[idx] || dT[idx] != dA[idx]) contra = true;
            }
            else {
                iT.Add(idx);
                dT[idx] = 1;
            }
            if(contra) break;
            
        }
        Console.Error.WriteLine("iT + iA: {0}", string.Join(" ", iT));
        long pat = 1;
        if(!contra){
            for(int i = 0; i < n; i++){
                if(dT[i] != 0) continue;
                else pat *= T[i] <= A[i] ? T[i] : A[i];
                pat %= (long)Math.Pow(10, 9) + 7;
                Console.Error.WriteLine("i:{0} pat:{1}", i, pat);
            }
        }
        else pat = 0;
        Console.WriteLine(pat);

    }
}


Measured memory_bytes: 33204
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


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

  int dist[N][N];
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      if (i == j) dist[i][j] = 0;
      else dist[i][j] = nmax;
    }
  }

  vector < vector < pair<int, int> > > graph(N); 
  for (int i = 0; i < M; i++){
    int A, B, C; cin >> A >> B >> C;
    A--; B--;
    dist[A][B] = C; dist[B][A] = C;
    graph[A].push_back(make_pair(B, C));
    graph[B].push_back(make_pair(A, C));
  }
  

  for (int k = 0; k < N; k++){
    for (int i = 0; i < N; i++){
      for (int j = 0; j < N; j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = M;
  for (int i = 0; i < N; i++){
    int now = i;
    for (int j = 0; j < graph[i].size(); j++){
      int next = graph[i][j].first;

      if (now < next){
        if (dist[now][next] == graph[i][j].second){
          ans--;
        }
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
s = input()

cou = []
enc = 0
enc1 = 0
for i in s:
    if i not in cou:
        cou.append(i)

if len(cou) != 2:
    print('No')
    exit()

for i in s:
    if i in cou[0]:
        enc += 1
    if i in cou[1]:
        enc1 += 1

if enc == 2 and enc1 == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9124
#include <stdio.h>
#include<string.h>
int main()
{
  long  int n,b,sum=0,i,test,count=0,flag=1,min=0;
  char a[1000000];
  
     gets(a);
     for(i=0;i<strlen(a);i++)
     {
          
         if(a[i]=='B')
         {
            count++;
             
            
         }else{
             if(a[i]=='W')
             {
                 sum+=count;
             }
         }
         
     }
     printf("%ld",sum);
       
     
    return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline

N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

if a[0]+a[1]>x:
    if a[0]<=x:
        ans += a[0]+a[1]-x
        a[1] = x-a[0]
    else:
        ans += a[1]
        a[1] = 0
        ans += a[0]-x
        a[0] = x

for i in range(2, N):
    if a[i-1]+a[i]<=x:
        continue
    
    ans += a[i-1]+a[i]-x
    a[i] = x-a[i-1]

print(ans)

Measured memory_bytes: 59632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<int> d(n);

	for(int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	int first = d[n / 2 - 1];
	int second = d[n / 2];

	cout << second - first << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f3f;
const ll maxn = 1e7+5;
const ll mod = 1e9+7;
ll qmi(ll a,ll k,ll mod){//快速幂 算a的k次方 
	ll res=1;
	while(k){
		if(k&1/*判断是否为奇数 */) res=(ll)res*a%mod;
		a=(ll)a*a%mod;
		k>>=1/*实际上将K除以2*/;
	}
	return res;
}
int main(){
	int n;
	cin >> n;
	cout << (qmi(10,n,mod)%mod+qmi(8,n,mod)%mod-2*(qmi(9,n,mod)%mod)%mod+mod)%mod << '\n';
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<int> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    int64_t ans = 0;
    for (int j = 0; j < N; j++) {
        int one = arr[j];
        while (one % 2 == 0) {
            ans++;
            one /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N >> M;
  ;
}
void solve() {
  if (N + M >= 10) {
    cout << "error" << endl;
  } else
    cout << N + M << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val numbers: Array[Int] = Array.fill(n)(sc.nextInt())

    val ans = numbers.forall(
      input =>
        if (input % 2 == 0) {
          input % 3 == 0 || input % 5 == 0
        } else {
          true
      }
    )

    println(if (ans) "APPROVED" else "DENIED")
  }
}


Measured memory_bytes: 27468
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

bool isMonth(int n)
{
	return 1<=n&&n<=12;
}

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

	int f=stoi(S.substr(0,2));
	int e=stoi(S.substr(2,2));

	if(isMonth(f)&&isMonth(e))
	{
		cout<<"AMBIGUOUS"<<endl;
	}
	else if(isMonth(f))
	{
		cout<<"MMYY"<<endl;
	}
	else if(isMonth(e))
	{
		cout<<"YYMM"<<endl;
	}
	else
	{
		cout<<"NA"<<endl;
	}
	return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>>board(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)cin >> board.at(i).at(j);
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (board.at(i).at(j) == '.')continue;
			bool up = false, left = false, right = false, down = false;
			if (i != 0)if (board.at(i - 1).at(j) == '#')up = true;
			if (j != 0)if (board.at(i).at(j - 1) == '#')left = true;
			if (j != w - 1)if (board.at(i).at(j + 1) == '#')right = true;
			if (i != h - 1)if (board.at(i + 1).at(j) == '#')down = true;
			if (!(up || left || right || down)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

}

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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;
const ll inf = 9e18;

template <class T>
struct BIT
{
    ///1-indexed
	int sz;
	vector<T> t;

	void init(int n) ///max size of array
	{
		sz = n;
		t.assign(sz,0);
	}

	T query(int idx)
	{
		T ans = 0;
		for(; idx >= 1; idx -= (idx & -idx)) ans += t[idx];
		return ans;
	}

	void upd(int idx, T val)
	{
		if(idx <= 0) return;
		for(; idx <sz; idx += (idx & -idx)) t[idx] += val;
	}

	void upd(int l, int r, T val)
	{
	    upd(l,val);
	    upd(r+1,-val);
	}

	T query(int l, int r) { return query(r) - query(l - 1); }
};
int32_t main()
{
    BIT<ll> t;
    t.init(N);
    int n = in(), d = in(), p = in();
    vector<pll> v(n);
    for(auto &x: v) x.first = in(), x.second = in();
    sort(v.begin(), v.end());
    ll ans = 0;
    for(int i =0 ; i<n; i++){
        ll nw = v[i].second + t.query(i+1);
        if(nw > 0){
            int k = upper_bound(v.begin() + i, v.end(), make_pair(1LL*v[i].first + 2LL*d, inf)) - v.begin();
            t.upd(i+1, k, max(-1000000100LL, -(nw + p -1) / p * p));
            ans += (nw + p -1)/p;
        }
    }
    cout << ans << nl;
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		cout << "Left";
	}
	else {
		if (a + b < c + d) {
			cout << "Right";
		}
		else {
			cout << "Balanced";
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 105

int map[MAX][MAX];
int xs, ys, xg, yg;
int n;
int w, h;
int c, d, x, y;
int count = 0;
int color;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void jadge(int x, int y){
	if(count == 0){
		if(0 <= x && x <= w && 0 <= y && y <= h && map[x][y] == color){
			map[x][y] = 9;
			if(x == xg && y == yg){
				count = 1;
				return;
			}
			for(int i=0; i < 4; i++){
				jadge(x+dx[i], y+dy[i]);
			}
		}
	}
}
int main(){
	while(1){
		count = 0;

		for(int i=0; i < MAX; i++){
			for(int j=0; j< MAX; j++){
				map[i][j] = 0;
			}
		}

		cin >> h >> w;
		if(w == 0 && h == 0) break;

		cin >> ys >> xs;
		cin >> yg >> xg;
		xs--; ys--; xg--; yg--;
		cin >> n;
		for(int i=0; i < n; i++){
			cin >> c >> d >> y >> x;

			for(int i=0;  i < 4; i++){
				for(int j=0; j < 2; j++){
					if(d == 1){
						map[x-1+i][y-1+j] = c;
					}
					else{
						map[x-1+j][y-1+i] = c;
					}
				}
			}
		}
		/*
		for(int i=0; i < w; i++){
			for(int j=0; j < h; j++){
				cout << map[i][j];
			}
			cout << endl;
		}
		*/
		if(map[xs][ys] != map[xg][yg]){
			cout << "NG" << endl;
			continue;
		}
		else if(map[xs][ys] == 0 || map[xg][yg] == 0){
			cout << "NG" << endl;
			continue;
		}
		color = map[xs][ys];

		jadge(xs, ys);

		if(count == 1) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int a,b;
  cin>>a>>b;
 vector<int> vec(a);
  rep(i,a){
    cin>>vec[i];
  }
  for(int j=b;j<a;j++){
    if(vec[j]>vec[j-b]){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}   

Measured memory_bytes: 4840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0027
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str;
            while(!((str=Console.ReadLine().Split(' ')).Contains("0")))
            {
                int[] input = str.Select(int.Parse).ToArray();
                int month = input[0];
                int date = input[1];
                var output = new DateTime(2004, month, date).DayOfWeek;
                Console.WriteLine(output);
            }
        }
    }
}



Measured memory_bytes: 16428
#include <iostream>
using namespace std;
int f[101];
int main(){
  int n, k, d, x;
  cin>>n>>k;
  while(k--){
    cin>>d;
    while(d--){
      cin>>x;
      f[x]=1;
    }
  }
  int ans=0;
  for(int i=1; i<=n; i++)
    if(f[i]==0)
      ans++;
  cout<<ans;
}

Measured memory_bytes: 3624
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n  ; cin >> n ; 

	vector<vector<ll>> dp(10 ,vector<ll>(10)) ; 
	for(ll i = 1 ; i<10 ; i++){
		dp[i][i] = 1;
	}
	ll ans = min(n  , 9LL) ;
	for(ll i = 10 ; i<= n ;i++){

		if(i%10==0){
			continue ; 
		}
		ll x = i ;  
		ll rev = i%10;
		while(x/10>0){
			x/=10;
		}
		rev = rev*10 + x%10;

		dp[rev%10][rev/10]++;
		if(rev/10 != rev%10)ans += 2*dp[rev/10][rev%10];
		else ans += 2*dp[rev/10][rev%10] - 1;
		// cout << i << " " <<ans << endl;


	}

	cout << ans;

	
}

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

int main()
{
    int t,last;
    cin>>t;
    last=t%10;
    if((last==2) || (last==4) || (last==5) || (last==7) || (last==9))
    {
        cout<<"hon";
    }
    else{
        if((last==0) || (last==1) || (last==6) || (last==8))
        {
            cout<<"pon";
        }
        else{
            cout<<"bon";
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,co=0;
    string a,b,c;
    cin >> n >> a >> b >> c;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]&& a[i]==c[i]){
            continue;
        }else if(a[i]==b[i] || b[i]==c[i] || a[i]==c[i]){
            //cout << 1 << endl;
            co+=1;
        }else{
            //cout << 2 << endl;
            co+=2;
        }
    }
    cout << co << endl;
    return 0; 
}

Measured memory_bytes: 256
X,N=map(int,input().split())
P=list(map(int,input().split()))

if N==0:
    print(X)
else:
    if X<min(P):
        ans=X
        print(ans)
    
    elif X in range(min(P),max(P)+1):
        #大した大きい数じゃないので全探索すればいい
        ans_len=200 #ひとまずの仮定
        for i in range(250):
            if i in P:
                continue
            else:
                l=abs(X-i)
                if l < ans_len:
                    ans_len=l
                    ans=i
        print(ans)
                
    else:
        ans=X
        print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
  char s; cin>>s;
  ll t=(ll)(s+1);
  cout<<(char)(t)<<endl;
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<int>>;
Graph G(10);

int N,M;
ll ans = 0;

void dfs(int n,int x,bitset<10> s){
  s.set(x);
  if(n == N){
    for(int i = 0;i < N;i++){
      if(!s.test(i)){
        return ;
      }
    }
    ans++;
    return ;
  }
  int m = G[x].size();
  for(int i = 0;i < m;i++){
    if(!s.test(G[x][i])){
      dfs(n+1,G[x][i],s);
    }
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0;i < M;i++){
    int a,b;cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1,0,0);
  cout << ans << endl;
}

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

int main()
{
	int a,sum=0;
    
	string s;
    cin>>a;
    vector<int> b(a),c(a),d(a);

    for(int i=0;i<a;i++)
    {
        cin>>b[i];
    }
	for(int i=0;i<a;i++)
    {
        cin>>c[i];
        d[i]=b[i]-c[i];
    }
    for(int i=0;i<a;i++)
    {
        if(d[i]>0)
            sum+=d[i];
    }
	cout<<sum;
	return 0;
}
	

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int t,n,i;
	for(i=0;i<4;i++){
		scanf("%d%d",&t,&n);
		switch(t){
			case 1:t=6000;break;
			case 2:t=4000;break;
			case 3:t=3000;break;
			case 4:t=2000;break;
		}
		printf("%d\n",t*n);
	}
	
	return 0;
}

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

int main()
{
    map<int,int> mp,mp1;
    int n,c=1;
    cin>>n;
    mp[n]++;
    while(1)
    {
        if(n%2==0){
            n/=2;
            mp[n]++;
            if(mp[n]==2)break;
        }
        else{
            n=n*3 + 1;
            mp[n]++;
            if(mp[n]==2)break;
        }
        c++;
    }
    cout<<c+1<<endl;

    return 0;
}


Measured memory_bytes: 256
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	multiset<int> s;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		s.insert(a[i]);
	}
	for(int i=0;i<n;i++){
		auto it=s.find(a[i]);
		int x=*it;
		s.erase(it);
		auto it1=s.end();
		it1--;
		cout<<*it1<<endl;
		s.insert(x);
	}
}

Measured memory_bytes: 11776
N,X,M = list(map(int,input().split()))
L = []
D = {}
L.append(X)
D[X] = D.get(X,0)+1
A = X
flag = 1
for i in range(N-1):
    A = A**2%M
    D[A] = D.get(A,0)+1
    if D[A]==2:
        flag=-1
        break
    else:
        L.append(A)
        if A==0:
            flag=0
            break
if flag==0:
    print(sum(L))
elif flag==1:
    print(sum(L))
else:
    LN = len(L)
    for i in range(LN):
        if L[i]==A:
            break
    Lu = L[i:]
    LuN = len(Lu)
    LuS = sum(Lu)
    out = 0
    if i!=0:
        out += sum(L[:i])
        N = N-i
    if N%LuN==0:
        out += LuS*(N//LuN)
        print(out)
    else:
        out += LuS*(N//LuN)
        amari = N%LuN
        out += sum(Lu[0:amari])
        print(out)

Measured memory_bytes: 78136
#include <iostream> // cin, cout
#include <algorithm> // sort
#include <vector> // vector
#include <cstdio> // printf
#include <cmath> // M_PI
#include <numeric> // accumulate
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long

class matrix {
	public:
		matrix();
		void get(void);
		void put(void);
	private:
		int c[100];
		int data[100][100];
		int n, m;
};

matrix::matrix() {
	rep(y, 100)
		rep(x, 100)
			data[x][y] = 0;
}

void matrix::put() {
	int t;
	rep(i, n) {
		t = 0;
		rep(k, m) {
			t += data[i][k] * c[k];
			//cout << "data" << i << "," << k << ":" << data[i][k] << endl;
			//cout << "c" << i << ":" << c[i] << endl;
			//cout << "t:" << t << endl;
		}
		cout << t << endl;
	}
}

void matrix::get() {
	cin >> n >> m;
	rep(i, n)
		rep(k, m) {
			cin >> data[i][k];
		}
	rep(i, m) {
		cin >> c[i];
	}
}

int		main(void)
{
	matrix mtx;
	mtx.get();
	mtx.put();
	return (0);
}



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

int main () {
    char str [222];
    scanf ("%s", str ) ;
    int n= strlen (str ) ;
    for (int i=n -2; i; i -=2) {
        if( strncmp (str , str +i/2 , i/2) ==0) {
            printf ("%d\n" ,i) ;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using ll = long long;
using namespace std;
int main() {
	int n, l;
	cin >> n >> l;
	vector<int> v(n);
	int minabs = abs(l), mindex = 0;
	int sum = 0;
	REP(i, n) {
		v[i] = i + l;
		sum += v[i];
		if (minabs > abs(v[i])) {
			minabs=abs(v[i]);
			mindex = i;
		}
	}
	cout << sum - v[mindex] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

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

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

    cout << lcm(n, 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define start() int t;cin>>t;while(t--) 
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0), cin.tie(0); } }_;
 
int32_t main()
{
    
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 3648
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N, M;
  cin >> N >> M;
  map<int, vector<int>> e;
  for(int i=1; i<N+1; i++){
    int k; cin >> k;
    for(int j=0; j<k; j++){
      int v; cin >> v;
      e[i].push_back(-v);
      e[-v].push_back(i);
    }
  }

  queue<int> q;
  q.push(1);
  set<int> s; s.insert(1);
  set<int> visited; visited.insert(1);
  while(q.size() > 0){
    int i; i = q.front(); q.pop();
    if(e.find(i) != e.end()){
      for(int j=0; j<e[i].size(); j++){
        if(visited.find(e[i][j]) == visited.end()){
          visited.insert(e[i][j]);
          if(e[i][j] > 0) s.insert(e[i][j]);
          q.push(e[i][j]);
        }
      }
    }
  }

  // for(auto x: s) cout << x << endl;

  if(s.size() == N) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 21368
X,Y = map(int,input().split())
mod = 10**9+7

m = 3*10**6 +1 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

if (X+Y)%3!=0:
    ans = 0
else:
    N = (X+Y)//3
    a = X-N
    b = Y-N
    if a<0 or b<0:
        ans = 0
    else:
        ans = comb(a+b,a)
print(ans)

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K, S;
  cin >> N >> K >> S;

  for ( int i = 0; i < K; i++ ) cout << S << " ";
  for ( int i = 0; i < N-K; i++ ) {
    if ( S == (int)1e9 ) cout << S-1 << " ";
    else cout << S+1 << " ";    
  }

  cout << endl;
  
  return 0;
}


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

int main(){
    int s,t,m;
    cin >> s >> t >> m;
    vector<int> a(s);
    rep(i,s) cin >> a[i];
    vector<int> b(t);
    rep(i,t) cin >> b[i];
    vector<pil> q(m);
    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        q[i].first.first = x;
        q[i].first.second = y;
        q[i].second = z;
    }
    int r = 2e9;
    rep(i,m){
        int s = a[q[i].first.first-1] + b[q[i].first.second-1] - q[i].second;
        r = min(r,s);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    r = min(r,(a[0]+b[0]));
    cout << r << endl;
}


Measured memory_bytes: 2176
function Main(input){
 
input = input.split(" ");

const num  = parseInt(input[0], 10);
	const total= parseInt(input[1], 10);
 

console.log(num * 500 >= total == true ? "Yes" :"No");
 
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b; cin >> a >> b;
	int arr[a + 50], mi[a + 50];
	fill(mi, mi + a, 2147483647);
	for(int i=0; i<a; i++)
	{
		cin >> arr[i];
		if(i) mi[i] = mi[i - 1];
		mi[i] = min(mi[i], arr[i]);
	}
	int cnt = 1, now = 0;
	for(int i=1; i<a; i++)
	{
//		cout << arr[i] << ' ' << mi[i] << '\n';
		if(arr[i] - mi[i - 1] > now)
		{
			cnt = 1;
			now = arr[i] - mi[i - 1];
		}
		else if(arr[i] - mi[i - 1] == now) cnt ++;
	}
	cout << cnt << '\n';
}

Measured memory_bytes: 1152
// -*- coding: utf-8 -*-
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskC solver = new TaskC();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskC {    
    int n, a, xi;
    int[] cards;
    long[][][] state;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      n = in.nextInt();
      a = in.nextInt();
      cards = new int[n];
      for (int i = 0; i < n; ++i) {
        xi = in.nextInt();
        cards[i] = xi;
      }
      state = new long[n][n * 50 + 1][n + 1];
      for (long[][] i : state) {
        for (long[] j : i) {
          Arrays.fill(j, -1L);
        }
      }
      out.println(go(n - 1, 0, 0));
    }
    
    long go(int pos, int s, int t) {
      if (pos < 0) {
        if (t > 0 && s % t == 0 && s / t == a) {
          return 1L;
        }
        return 0L;
      }
      if (state[pos][s][t] != -1L) {
        return state[pos][s][t];
      }
      long ans = go(pos - 1, s + cards[pos], t + 1) + go(pos - 1, s, t);
      state[pos][s][t] = ans;
      return ans;
    }
    
  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}


int main(){

    ll k, s; cin >> k >> s;

    ll ans = 0;
    rep(x, k+1){
        rep(y, k+1){
            if(s-x-y>=0 && s-x-y<=k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int dp[100010];
	dp[0]=0;
	for(int n=1;n<=100000;n++){
		dp[n]=100000;
		int power=1;
		while(power<=n){
			dp[n]=min(dp[n],dp[n-power]+1);
			power*=6;
		}
		int power2=1;
		while(power2<=n){
				dp[n]=min(dp[n],dp[n-power2]+1);
				power2*=9;
			}
	}
	int N;
	cin>>N;
	cout<<dp[N]<<endl;
}


Measured memory_bytes: 640
N = int(input())
evidence = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x,y = map(int,input().split())
    evidence[i].append((x-1,y))
result = 0
for j in range(1,2**N):
  consistent = True
  for k in range(N):
    if (j >> k) & 1 == 0:
      continue
    for x,y in evidence[k]:
      if (j >> x) & 1 != y:
        consistent = False
        break
    if not consistent:
      break
  if consistent:
    result = max(result, bin(j)[2:].count("1"))
print(result)


Measured memory_bytes: 68476
//BY: YASH JAIN, CF: yashjain0333
#include <bits/stdc++.h>
using namespace std;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
// #define N 100

void solve(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int res = 0;
    int cur = a[0];
    for(int i=1;i<n;i++){
        if(cur>a[i]) res += cur-a[i];
        cur = max(cur,a[i]);
    }
    cout<<res;
}

int32_t main(){
    May_the_fork_be_with_you
    int t = 1; 
    // cin>>t;
    while (t--)
        solve();
}


Measured memory_bytes: 4784
from itertools import combinations
 
n, k = [int(item) for item in input().split()]
xy = [[int(item) for item in input().split()] for _ in range(n)]
 
xsort = sorted(xy, key=lambda x: x[0])
ysort = sorted(xy, key=lambda x: x[1])
l = [i for i in range(n)]
 
cum = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        cum[i+1][j+1] = cum[i+1][j] + cum[i][j+1] - cum[i][j] + ([xsort[i][0], ysort[j][1]] in xy)

def count_points_in_rec(x0, x1, y0, y1):
    point = cum[x1+1][y1+1] - cum[x0][y1+1] - cum[x1+1][y0] + cum[x0][y0]
    return point

ans = 5 * 10**18
comb = []
for a, b in combinations(l, 2):
    if b - a >= k-1:
        comb.append([a, b])
for a, b in comb:
    for c, d in comb:
        if count_points_in_rec(a, b, c, d) == k:
            ans = min(ans, (xsort[b][0]-xsort[a][0]) * (ysort[d][1]-ysort[c][1]))
print(ans)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input1 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var N = input1[0];
        var M = input1[1];


        var results = new Dictionary<int, Result>();
        for (int i = 0; i < M; i++)
        {
            var input2 = Console.ReadLine().Split(' ').ToArray();
            var mondai = int.Parse(input2[0]);
            var success = input2[1] == "AC";

            if (!results.ContainsKey(mondai))
            {
                results.Add(mondai, new Result(mondai));
            }

            results[mondai].Add(success);
        }

        var count1 = results.Values.Count(i => i.Clear);
        var count2 = results.Values
            .Where(i => i.Clear)
            .Sum(i => i.Penarty);
        Console.WriteLine($"{count1} {count2}");
    }

    private class Result
    {
        public int No { get; private set; }
        public bool Clear { get; private set; }
        public int Penarty { get; private set; }

        public Result(int no)
        {
            No = no;
        }

        public void Add(bool clear)
        {
            if (Clear) return;
            if (!clear) Penarty++;
            if (clear) Clear = true;
        }
    }
}

Measured memory_bytes: 25028