akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long llint;

int main() {
  llint h1, h2, m1, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int a = (h2 - h1) * 60 + (m2 - m1);
  cout << max(0LL, a - k) << endl;
  return 0;
}

Measured memory_bytes: 3644
from fractions import gcd

N, M = map(int, input().split())
A = list(map(int, input().split()))

"""
A = [a_0, a_1, ...]として、
X = a_i * (p+0.5) = (a_i//2) * (2*p+1)
(2p+1)は奇数より、Xが2で割り切れる回数は(a_i//2)が2で割り切れる回数に等しい。
特に全てのa_iに関して2で割り切れる回数が等しくなければXは存在しない。

もし全てのa_iに関して2で割り切れる回数が等しいならば、
    T = LCM(a_0//2, a_1//2, ...)
と定めれば、XはTの奇数倍で尽くされる。
"""

def quotBy2(n):
    num = 0
    while n % 2 == 0:
        num += 1
        n //= 2
    return num

def lcm(a, b):
    d = gcd(a, b)
    return a * b // d

T = A[0] // 2
quot = quotBy2(A[0])
for i in range(N - 1):
    T = lcm(T, A[i + 1]//2)
    #print("T={}".format(T))
    if quot != quotBy2(A[i + 1]):
        print(0)
        exit()

print((M + T) // (2 * T))


Measured memory_bytes: 89812
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll n, m, k;
  cin >> n >> m >> k;
  cout << k << " " << n << " " << m << endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
const int MOD = 1000000007;
#define rev(s) (string((s).rbegin(), (s).rend()))

int main () {

    int h,w;cin>>h>>w;

    ll dp[1010][1010];

    string field[h+10];
    rep(i,h) {
        cin>>field[i];
    }
    rep(i,h) {
        dp[i][0]=0;
    }
    rep(i,w) {
        dp[0][w]=0;
    }
    rep(i,h) {
        rep(j,w) {
            if (i==0&&j==0) {
                dp[i+1][j+1]=1;
            }
            else {
                if (field[i][j]=='#') {
                    dp[i+1][j+1]=0;
                }
                else {
                    dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%MOD;
                }
            }
        }
    }

    cout << dp[h][w]%MOD << endl;

}

Measured memory_bytes: 9216
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main(){
    int n;
    while(cin>>n,n){
        vector<vi> t(n,vi(n+1));
        rep(i,n)rep(j,n+1) cin >> t[i][j];
        vi dp(1<<n,INF);
        dp[0] = 0;
        rep(i,1<<n){
            rep(v,n)if(!(i&(1<<v))){
                int mt = t[v][0];
                rep(u,n)if(i&(1<<u)){
                    mt = min(mt,t[v][u+1]);
                }
                dp[i|(1<<v)] = min(dp[i|(1<<v)], dp[i]+mt);
            }
        }
        cout << dp[(1<<n)-1] << endl;
    }
}

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

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

    int x,y;
    int param_x=Y/10000;
    int param_y=Y/5000;
    rep(x,param_x){
        rep(y,param_y){
            int z=(Y-(x*10000+y*5000))/1000;
            if(z>=0&&x+y+z==N){
                cout << x << " " << y << " " << z << endl;
                return 0;


            }
        }
    }
    cout << "-1 -1 -1" << endl;
    

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    double L;

    std::cin >> L;

    double side = L / 3.0;

    cout << std::setprecision(12) << std::fixed << side * side * side << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
   int k,a,b;
   scanf("%d%d%d",&k, &a, &b);
   for(int i = a; i <= b; i++){
      if(i % k == 0){
         printf("OK\n");
         return 0;
      }
   }
   printf("NG\n");
   return 0;
}



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

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

    vector <string> blue (N);

    for(int i=0; i < N; i++){
        cin >> blue .at(i);
    }

    int M;
    cin >> M;

    vector <string> red (M);

    for(int i=0; i < M; i++){
        cin >> red .at(i);
    }

    int answer=0;

    for (int i=0; i < N; i++){
        int count = 0;

        for(int l=0; l < N; l++){
            if (blue .at(i) == blue .at(l)){
                count += 1;
            }
        }

        for(int m=0; m < M; m++){
            if (blue .at(i) == red .at(m)){
                count -= 1;
            }
        }    

        if(answer < count){
            answer = count;
        }
    }

    cout << answer << endl;

}

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

public class Main {
	public static void main(String[] age)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		int number[] = new int[26];
		String AlHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String alha = "abcdefghijklmnopqrstuvwxyz";
		int i = 0;
		int j = 0;
		String input;
		String a;

		while(( input = br.readLine())!=null ){
			for( i=0 ; i<input.length() ; i++ ){
				for( j=0 ; j<26 ; j++ ){
					a = input.substring(i, i+1);
					if( a.equals(AlHA.substring(j, j+1)) || a.equals(alha.substring(j, j+1))){
						number[j]++;
					}
				}
			}
		}

		for( i=0 ; i<26 ; i++ ){
			sb.append(alha.substring(i, i+1)).append(" : ").append(Integer.toString(number[i])).append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 29748
#include <iostream>

int main()
{
    int k, a, b;
    std::cin >> k >> a >> b;

    if (a / k < b / k || a % k == 0)
    {
        std::cout << "OK" << std::endl;
    }
    else
    {
        std::cout << "NG" << std::endl;
    }
}


Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;cin>>s>>t;
  ll sl=s.length(),tl=t.length();
  vector<vector<ll>>dp(sl+1,vector<ll>(tl+1,0));
  vector<vector<ll>>p(sl+1,vector<ll>(tl+1,-1));
  auto q=p;
  repi(i,1,sl+1)repi(j,1,tl+1){
    if(chmax(dp[i][j],dp[i-1][j])){p[i][j]=p[i-1][j];q[i][j]=q[i-1][j];}
    if(chmax(dp[i][j],dp[i][j-1])){p[i][j]=p[i][j-1];q[i][j]=q[i][j-1];}
    if(s[i-1]==t[j-1]){
      if(chmax(dp[i][j],dp[i-1][j-1]+1)){
        p[i][j]=i-1;
        q[i][j]=j-1;
      }
    }
  }
  ll y=p[sl][tl],x=q[sl][tl];
  string res="";
  while(y>=0&&x>=0){
    res=s[y]+res;
    auto ty=p[y][x];
    x=q[y][x];
    y=ty;
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 212736
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int a[100010], b[100010];
signed main() {
    int n; cin >> n;
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) cin >> b[i];
    int ans = 1;
    rep(i,0,n) {
        bool fla = false, flb = false;
        if(i == 0 || a[i-1] < a[i]) fla = true;
        if(i == n-1 || b[i] > b[i+1]) flb = true;
        if(fla && flb) {if(a[i] != b[i]) ans *= 0;}
        else if(fla) {if(a[i] > b[i]) ans *= 0;}
        else if(flb) {if(a[i] < b[i]) ans *= 0;}
        else ans = mmul(ans, min(a[i], b[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	for(auto& e: b)
		cin >> e;
	int num=0;
	for(int i=0; i<n; i++){
		int sum=0;
		for(int j=0; j<m; j++){
			int a;
			cin >> a;
			sum+=a*b[j];
		}
		sum+=c;
		if(sum>0)
			num++;
	}
	cout << num << endl;
	return 0;
}

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  int sz = s.size();
  ll ans = 0;
  for (int i = 0; i < (1 << (sz - 1)); i++) {
    string t = string(1, s[0]);
    for (int j = 0; j < sz - 1; j++) {
      if (i >> j & 1) {
        if (t != "") ans += stoll(t);
        t = string(1, s[j + 1]);
      } else {
        t += s[j + 1];
      }
    }
    if (t != "") ans += stoll(t);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
	double x1,x2,y1,y2;
	while(cin>>x1>>y1>>x2>>y2){
		double ans=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		printf("%0.8f\n",ans);
	}
	return 0;
} 


Measured memory_bytes: 3264
al=[chr(ord('a') + i) for i in range(26)]

def f(x,c):
    if len(x) == n:
        print(x)
    else:
        for i in range(c):
            f(x+al[i],c)
        f(x+al[c],c+1)

n = int(input())

f("a",1)

Measured memory_bytes: 4340
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

typedef long long ll;
#define rep(i, n) for(int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
using namespace std;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    vector<int> vec(4);
    rep(i, 4) {
        vec[i] = s[i];
    }
    int i = 48 * 4;
    int a = s[0] - 48;
    int b = s[1] - 48;
    int c = s[2] - 48;
    int d = s[3] - 48;
    if (a + b + c + d  == 7) {
        cout << to_string(a);
        cout << '+';
        cout << to_string(b);
        cout << '+';
        cout << to_string(c);
        cout << '+';
        cout << to_string(d);
        cout << "=7";
        cout << endl;
    } else if (a + b - c + d  == 7) {
        cout << to_string(a);
        cout << '+';
        cout << to_string(b);
        cout << '-';
        cout << to_string(c);
        cout << '+';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    } else if (a + b + c - d  == 7) {
        cout << to_string(a);
        cout << '+';
        cout << to_string(b);
        cout << '+';
        cout << to_string(c);
        cout << '-';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    } else if (a + b - c - d  == 7) {
        cout << to_string(a);
        cout << '+';
        cout << to_string(b);
        cout << '-';
        cout << to_string(c);
        cout << '-';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    } else if (a - b + c + d  == 7) {
        cout << to_string(a);
        cout << '-';
        cout << to_string(b);
        cout << '+';
        cout << to_string(c);
        cout << '+';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    } else if (a - b + c - d  == 7) {
        cout << to_string(a);
        cout << '-';
        cout << to_string(b);
        cout << '+';
        cout << to_string(c);
        cout << '-';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    } else if (a - b - c + d  == 7) {
        cout << to_string(a);
        cout << '-';
        cout << to_string(b);
        cout << '-';
        cout << to_string(c);
        cout << '+';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    } else if (a - b - c - d  == 7) {
        cout << to_string(a);
        cout << '-';
        cout << to_string(b);
        cout << '-';
        cout << to_string(c);
        cout << '-';
        cout << to_string(d);
        cout << "=7";
        cout << endl;

    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    std::cout<<((x - a) % b)<<std::endl;
    return 0;
}

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

int main(){
    int x , y , z;
    cin >> x >> y >> z;
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
    tmp = x;
    x = z;
    z = tmp;
    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
for(int i=0;i<m;i++){
int temp;
cin >> temp;
n -= temp;
}
if(n < 0)cout << "-1" << endl;
else{
    cout << n << endl;
}
return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int 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 F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int MOD=1000003;
int INF=100100100100100;

int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

LL beki(LL a,LL b)
{
	if(b==0)return 1;
	LL x=beki(a,b/2);
	if(b%2==0)return (x*x)%MOD;
	else return (((a*x)%MOD)*x)%MOD;
}

LL inv(LL a)
{
	return beki(a,MOD-2);
}

LL kaijou(LL a)
{
	LL ans=1;
	for(LL i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

LL combi(LL a,LL b)
{
	LL ret=1;
	for(LL i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}
int po[1001001];
signed main(){
  rep(i,1001001){
    if(i==0)po[i]=1;
    else po[i]=prod(i,po[i-1]);
  }
  int q;cin>>q;
  rep(i,q){
    int ans=1;
    int x,d,n;cin>>x>>d>>n;
    int y=prod(x,inv(d));
    if(d==0)ans=beki(x,n);
    else if(y==0 || y+n-1>=MOD)ans=0;
    else{
      ans=beki(d,n);
      int hoge=prod(po[y+n-1],inv(po[y-1]));
      ans=prod(ans,hoge);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	string a;
	cin>>n>>m;
	cin>>a;
	if(a[n]!='-')
	{
		cout<<"No"<<'\n';
		return 0;
	}
	for(int i=0;i<n+m+1;i++)
	{
		if(i!=n&&a[i]<48||a[i]>57)
		{
			cout<<"No"<<'\n';
			return 0;
		}
	}
	cout<<"Yes"<<'\n';
	return 0;
}

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

int main()
{
    // (1)  1   1   2   2   1   2   3   2
    //     (1)  1   2   2   1   2   3   2
    //          1  (2)  2   1   2   3   2
    //          1      (2)  1   2   3   2
    //         (1)          1   2   3   2
    //                      1   2  (3)  2
    //                      1  (2)      2
    //                      1          (2)
    //                      1

    int N; cin >> N;
    vector<int> b{};
    for (int i = 1; i <= N; i++)
    {
        int x; cin >> x;
        b.push_back(x);
    }

    bool canOperate = true;
    vector<int> ans{};
    while (canOperate)
    {
        canOperate = false;
        for (int i = b.size() - 1; i >= 0; i--)
        {
            if (b[i] == i + 1)
            {
                b.erase(b.begin() + i);
                ans.insert(ans.begin(), i + 1);
                canOperate = true;
                break;
            }
        }
    }

    if (b.empty())
    {
        for (int k : ans) cout << k << endl;
    }
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
bool compare(int a, int b)
{
    return a > b;
}
int main()
{
    int x,n,i,ans,j,temp,maxi,k;
    int flag[200100]= {0};
    int mark[1001000]= {0};
    int flag2[1001000]= {0};

    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>flag[i];
        flag2[flag[i]]++;
    }
    sort(flag,flag+ n, compare);
    maxi=flag[0];
    ans=0;
    for(i=0; i<n; i++)
    {
        k=2;
        while(flag[i]*k<=maxi)
        {
            mark[flag[i]*k]=1;
            k++;
        }
    }

    for(i=0; i<n; i++)
    {
        if(flag2[flag[i]]==1)
        {
            if(mark[flag[i]]!=1)ans++;
        }

    }
    cout<<ans<<endl;
}


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

int main(){
    int N;
    cin>>N;
    string S=to_string(N);
    char a=S.back();
    switch(a){
        case '2':;
        case '4':;
        case '5':;
        case '7':;
        case '9': cout<<"hon"<<endl;break;
        case '0':;
        case '1':;
        case '6':;
        case '8': cout<<"pon"<<endl;break;
        case '3': cout<<"bon"<<endl;break;

        return 0;
    }
}

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

int m, d;

int main() {
	cin >> m >> d;
	
	int ans = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= d; j++) {
			int d10 = j / 10;
			int d1 = j % 10;
			if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_right

while True:
    n, m = map(int, input().split())
    if not n:
        break

    ps = [0] + sorted(int(input()) for _ in range(n))

    p2 = set()
    for i, pi in enumerate(ps):
        for pj in ps[i:]:
            if pi + pj > m:
                break
            p2.add(pi + pj)

    p2 = sorted(p2)

    print(max(pi + p2[bisect_right(p2, m - pi) - 1] for pi in p2))

Measured memory_bytes: 56332
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String B = scan.next();
        HashSet<Character> uppercases = new HashSet<>();
        char[] d = B.toCharArray();
        boolean answer = true;
        int count_upper = 0;
        int count_c = 0;
        int count_c_range = 0;
        for (int i = 0; i < d.length; i++) {
            if (d[i] == 'C') {
                count_c += 1;
            }
            if (i == 0) {
                if (d[i] != 'A') {
                    answer = false;
                    break;
                }
            }
            if (2 <= i && i <= d.length - 2) {
                if (d[i] == 'C') {
                    count_c_range += 1;
                }
            }
            if (0 <= d[i] - 'A' && d[i] - 'A' <= 25) {
                count_upper += 1;
            }
        }
        if (count_c_range != 1 || count_c_range != count_c) {
            answer = false;
        }
        if (count_upper != 2) {
            answer = false;
        }
        System.out.println(answer ? "AC" : "WA");
    }
}


Measured memory_bytes: 23252
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
A = list(map(int, input().split()))

cons = []
cur = 0
mn, mx = 0, 0
for i in range(N, -1, -1):
    mn = ((mn + 1) // 2) + A[i]
    mx = mx + A[i]
    if mn > 2 ** i:
        print(-1)
        exit()
    cons.append((mn, mx))
cons = list(reversed(cons))
ans = 0
cnt_node = 1
for i in range(N + 1):
    mn, mx = cons[i]
    now = min(mx, cnt_node)
    ans += now
    cnt_node = (now - A[i]) * 2
print(ans)



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

  int main() {
    int N;
    string S;
    int key=0;
    int t=0;
    
    cin >> N >> S ;
    
    string base;
    base="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int t = 0;t<S.size();t++){
    	for(int i=0; i<26; i++){
      		if( S.at(t)==base.at(i) ){
        		key=i;
        		cout << base.at(key+N);
            }
        }
    }
  }


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

class Program
{
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    HashSet<int> d = new HashSet<int>();
    for (int i = 0; i < n; i ++) d.Add(int.Parse(Console.ReadLine()));
    Console.WriteLine(d.Count);
  }
}


Measured memory_bytes: 13396
#include <stdlib.h>
#include <iostream>
#include <climits>
using namespace std;


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

	int *a = (int*)malloc(n * sizeof(int));
	int *mina = (int*)malloc(n * sizeof(int));
	int minv = INT_MAX;

	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(minv > a[i]) minv = a[i];
		mina[i] = minv;
	}

	int this_dif = 0;
	int max_dif  = 0;
	int dif_num  = 0;

	for(int i = 1; i < n; i++){
		this_dif = a[i] - mina[i];
		if(this_dif > max_dif){
			max_dif = this_dif;
			dif_num = 1;
		}else if(this_dif == max_dif){
			dif_num++;
		}
	}
	cout << dif_num << endl;
	return 0;
}



Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


def primes(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return {i for i in range(n + 1) if is_prime[i]}


prime_set = primes(10 ** 6)
n = I()
while True:
    if n in prime_set:
        break
    n += 1


print(n)


Measured memory_bytes: 16668
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions


num = int(stdin.readline().rstrip())
count = 0
arr = []
for a in range(1, num + 1):
    for b in range(1, num + 1):
        arr.append(math.gcd(a, b))
for c in range(1, num + 1):
    for d in arr:
        count += math.gcd(c, d)
print(count)


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


template<typename T>
struct LinearSystemIncidence {
  struct Edge {
    int id, to;
    bool fwd;
    Edge(int i, int t, bool f) : id(i), to(t), fwd(f) {}
  };

  int n, m;
  vector<T> x;
  vector<bool> seen;
  vector<vector<Edge>> G;
  
  LinearSystemIncidence(int n, vector<P> &E) : n(n), m(E.size()), G(n) {
    rep(i, m) {
      G[E[i].first].emplace_back(i, E[i].second, true);
      G[E[i].second].emplace_back(i, E[i].first, false);
    }
  }

  T dfs(vector<T> &b, int u) {
    seen[u] = true;
    T res = b[u];
    for (Edge e : G[u]) {
      if (seen[e.to]) continue;
      T tmp = dfs(b, e.to);
      x[e.id] = tmp * (e.fwd ? 1 : -1);
      res += tmp;

      // mod2
      x[e.id] %= 2;
      if (x[e.id] < 0) x[e.id] += 2;
      ////
    }
    res %= 2; // mod 2
    return res;
  }

  pair<bool, vector<T>> solve(vector<T> &b) {
    x.assign(m, 0);
    seen.assign(n, false);
    for (int s = 0; s < n; ++s) {
      if (seen[s]) continue;
      if (dfs(b, s)) return {false, vector<T>()};
    }
    return {true, move(x)};
  }
};


int main() {
  int n, m; cin >> n >> m;
  vector<P> E;
  V c(n+1);
  rep(i, m) {
    int u, v; cin >> u >> v;
    E.emplace_back(u, v);
    ++c[u];
  }

  LinearSystemIncidence<int> LSI(n+1, E);
  auto sol = LSI.solve(c);

  if (sol.first) {
    rep(i, m) {
      if (sol.second[i]) swap(E[i].first, E[i].second);
      cout << E[i].first << " " << E[i].second << "\n";
    }
  }
  else cout << -1 << "\n";
  return 0;
}

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

using System.Collections;

class Program
{
    static void Main()
    {
        string S = Console.ReadLine();

        int redCount = S.Count(c => c == '1');
        int blueCount = S.Count(c => c == '0');

        Console.WriteLine(Math.Min(redCount, blueCount) * 2);
    }
}

Measured memory_bytes: 11360
#include <stdio.h>
#include <stdlib.h>
 
int binsearch(int S[], int n, int key)
{
    int left = 0;
    int right = n;
    int mid;
     
    while (left < right) {
        mid = (left + right)/2;
        if (S[mid] == key) 
            return 1;
        else if (S[mid] < key)
            left = mid+1;
        else
            right = mid;
    }
    return 0;
}
 
int main()
{
    int n, q;
    int *S, T;
    int i, j = 0;
    int *A;
     
    scanf("%d", &n);
    S = (int*)malloc(sizeof(int) * n);
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
     
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &T);
        if (binsearch(S, n, T)) {
            j++;
        }
    }
     
    printf("%d\n", j);
     
    return 0;
}

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

void rec(char g[20][20], int ci, int cj){
    g[ci][cj] = '0';
    int di[] = {0,1,0,-1};
    int dj[] = {1,0,-1,0};
    rep(dir,4){
        rep(dist,4){
            int ni = ci+di[dir]*dist;
            int nj = cj+dj[dir]*dist;
            if(ni >= 8 || nj >= 8 || ni < 0 || nj < 0 || g[ni][nj] == '0') continue;
            rec(g,ni,nj);
        }
    }
}

int main(){
    int t;
    scanf("%d",&t);
    rep(tt,t){
        char g[20][20];
        rep(i,8) scanf("%s",g[i]);
        int i,j;
        scanf("%d%d",&i,&j);
        rec(g,j-1,i-1);
        printf("Data %d:\n",(int)tt+1);
        rep(i,8) puts(g[i]);
    }
}

Measured memory_bytes: 1176
#include <stdio.h>
#include <math.h>

int GCD(int x, int y){
    int temp;
    if(x <= y){
        temp = x;
        x = y;
        y = temp;
    }
    
    if(y == 0) return x;
    else{
        temp = y;
        y = x % y;
        x = temp;
        return GCD(x, y);
    }
}

int LCM(int x, int y, int gcd){
    return x / gcd * y;
}
        
int main(void){
  
    //int n, i;
    int a, b;
    
    while(scanf("%d %d", &a, &b) == 2){
        printf("%d %d\n", GCD(a, b), LCM(a, b, GCD(a,b)));
    }
    return 0;
    
}

Measured memory_bytes: 592
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n;
int a[200010];
long long sum=0,tmp_sum=0,res=0,ans;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)sum+=a[i];
    for(int i=0;i<n-1;i++)
    {
        tmp_sum+=a[i];
        res=sum-tmp_sum;
        if(i==0)ans=abs(res-tmp_sum);
        else ans=min(ans,abs(res-tmp_sum));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) { return  key % M; }
int h2(int key) { return 1+(key % (M-1)); }

int find(char str[]) {
    int h_key, next;
    long long key;
    key = getKey(str);
    h_key = h1(key);
    if((strcmp(H[h_key], str))==0) return 1;
    else {
        next = h2(key);
        h_key += next;
        if (h_key >= M) h_key = h_key - M;
        while (H[h_key][0]!='\0'){
            if ((strcmp(H[h_key], str)) == 0) return 1;
            h_key += next;
            if (h_key >= M) h_key = h_key - M;
        }
    }
    return 0;
}

int insert(char str[]) {
    int h_key,next;
    long long key;
    key = getKey(str);
    h_key = h1(key);
    if (H[h_key][0] == '\0') strcpy(H[h_key], str);
    else {
        next = h2(key);
        h_key += next;
        if (h_key >= M) h_key = h_key - M;
        while (1) {
            if (H[h_key][0] == '\0') {
                strcpy(H[h_key], str);
                break;
            }
            h_key += next;
            if (h_key >= M) h_key = h_key - M;
        }
    }
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for (i = 0; i < M; i++) H[i][0] = '\0';

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s %s", com, str);

        if (com[0] == 'i') {
            insert(str);
        }
        else {
            if (find(str)) {
                printf("yes\n");
            }
            else {
                printf("no\n");
            }
        }
    }

    return 0;
}



Measured memory_bytes: 15420
#include<iostream>
#define int long long
using namespace std;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int ans=0,n,i,j,k,l,num=0;
	string s;
	cin>>s;
	n=s.size();
	for(i=0;i<n;i++){
		if(s[i]=='B'){
			num++;
		}
		else{
			ans+=num;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
using lint = long int;
using llint = long long int;
using namespace std;

int main() {
    fastIO;

    int n;
    cin >> n;

    vector<int> costs;
    int subsum = 0;
    rep(_, n) {
        int cost;
        cin >> cost;
        subsum += cost;
        costs.push_back(cost);
    }
    int diff = round((double)subsum / n);

    int sum = 0;
    for (auto c : costs) {
        sum += (c - diff) * (c - diff);
    }
    cout << sum << endl;
}

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

int main(){
  int h, n, sum=0;
  cin >> h >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }

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

Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;

int main()
{
	char S[20];
	cin >> S;

	bool flag = true;
	int count = 0;
	int index = 0;

	if (S[0] == 'A')
	{
		//if (S[strlen(S) -1 ] == 'C')
		//{
		//	flag = false;
		//	goto END;
		//}
		for (int i = 0; i < strlen(S); i++)
		{
			if (S[i] == 'C' && 2 <= i && i <= strlen(S) - 2)
			{
				index = i;

				for (int l = 1; l < strlen(S); l++)
				{
					if (l == index) continue;

					if (S[l] >= 'A' && S[l] <= 'Z')
					{
						flag = false;
						goto END;
					}
				}

				flag = true;

				count++;
			}

			if (count >= 2)
			{
				flag = false;
				goto END;
			}
		}

		if (count == 0)
		{
			flag = false;
			goto END;
		}
	}
	else
	{
		flag = false;
	}

END:
	if (flag)
	{
		cout << "AC" << endl;
	}
	else
	{
		cout << "WA" << endl;
	}

	return 0;
}

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

typedef long long ll;
ll ab[1000000][2];
ll iab[1000000];
ll n;

bool comp(const ll& left, const ll& right) {
    return ab[left][1] < ab[right][1];
}
int main(){
    cin >> n;
    for( ll i=0; i<n; i++) {
        cin >> ab[i][0] >> ab[i][1];
        iab[i]=i;
    }
    
    sort(iab, iab+n, comp);

    ll sum=0;
    for(ll i=0; i<n; i++){
        sum += ab[iab[i]][0];
        if( sum > ab[iab[i]][1]){
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



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

namespace D2019PC2A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int N = int.Parse(input[0]);//ボールの個数
            int K = int.Parse(input[1]);//人数
            int ans = 0;
            if (K > 1)
            {
                ans = N - K;
            }
            else
            {
                ans = 0;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

const LL mod = 1e9+7;

int main(void){
    string S;
    cin>>S;
    vector<LL> num(4,0);
    num[0] = 1;
    REP(i,SZ(S)){
        vector<LL> v(4,0);
        v[0] += (S[i]=='?') ? num[0]*3 : num[0];

        if(S[i] == 'A' || S[i] == '?')
            v[1] += num[0];

        v[1] += (S[i]=='?') ? num[1]*3 : num[1];
        if(S[i] == 'B' || S[i] == '?')
            v[2] += num[1];

        v[2] += (S[i]=='?') ? num[2]*3 : num[2];
        if(S[i] == 'C' || S[i] == '?')
            v[3] += num[2];

        v[3] += (S[i]=='?') ? num[3]*3 : num[3];
        num = v;
        REP(j,4)
            num[j] %= mod;
    }
    printf("%lld\n", num[3]);
    return 0;
}

Measured memory_bytes: 512
'''
Created on 2020/09/03

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  K,S=map(int,pin().split())
  ans=0
  for x in range(K+1):
    for y in range(K+1):
      if 0<=S-x-y<=K:
        ans+=1
  print(ans)
  return 
main()

Measured memory_bytes: 9052
def aaa(i):
    return bin(int(i))[2:].zfill(20)[::-1]

N=int(input())
a=list(map(aaa,input().split()))

ans=0
x=[[-1,-1] for i in range(20)]

for i in range(N):
    for j in range(20):
        if a[i][j]=="1":
            x[j]=[x[j][1],i]
    ans+=i-max([ x[j][0] for j in range(20) ])

print(ans)

Measured memory_bytes: 32684
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    Q = int(input())

    rev = 0
    sdeq = collections.deque(list(S))

    for i in range(Q):
        A = [x for x in input().split()]
        if len(A) == 1:
            rev = (rev + 1) % 2
        else:
            f = int(A[1])
            c = A[2]
            if f == 1:
                if rev == 0:
                    sdeq.appendleft(c)
                else:
                    sdeq.append(c)
            else:
                if rev == 0:
                    sdeq.append(c)
                else:
                    sdeq.appendleft(c)

    if rev == 0:
        print("".join(list(sdeq)))
    else:
        print("".join(list(sdeq)[::-1]))
    print()



if __name__ == '__main__':
    main()


Measured memory_bytes: 10468
#include<string>
#include<iostream>
using namespace std;
 
int main(){
  string S,T;
  cin>>S>>T;
  int count=0;
  for(int i=0;i<S.length();i++){
    if(S[i]!=T[i])count++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int pre[n+5];
    int suf[n+5];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    pre[0]=a[0];
    for(int i=1;i<n;i++){
        pre[i]=__gcd(pre[i-1],a[i]);
    }
    suf[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        suf[i]=__gcd(suf[i+1],a[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(i==0){
            ans=max(ans,suf[i+1]);
        }else if(i==n-1){
            ans=max(ans,pre[n-2]);
        }else{
            ans=max(ans,__gcd(pre[i-1],suf[i+1]));
        }
    }
    cout<<ans<<endl;
    
    return 0;
    
}



Measured memory_bytes: 2560
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  ll N, K;
  cin >> N >> K;
  
  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  ll len = 0;
  for (ll i = 1; i <= K; i*=2) {
    len++;
  }
  
  ll x = 0;
  for (ll i = len - 1; i >= 0 ; i--) {
    ll zero = 0, one = 0;
    for (ll j = 0; j < N; j++) {
      if(vec[j] & (1LL << i)) {
        one++;
      } else {
        zero++;
      }
    }
    if (zero > one && (x | (1LL << i)) <= K) {
      x |= (1LL << i);
    }
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ans += vec[i] ^ x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
n=int(input())
ans=0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
    x=min(a[i],b[i])
    ans+=x
    b[i]-=x
    x=min(a[i+1],b[i])
    ans+=x
    a[i+1]-=x
print(ans)

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

#define INF 1000000

int minCost(int n, int *arr, int *dp)
{
    if(n < 1)
        return INF;
    if(n == 1)
        return 0;
    if(dp[n] != -1)
        return dp[n];
    int ans1 = abs(arr[0]-arr[1]) + minCost(n-1, arr+1, dp);
    int ans2 = INF;
    if(n >= 3)
         ans2 = abs(arr[0]-arr[2]) + minCost(n-2, arr+2, dp);
    dp[n] = min(ans1, ans2);
    return dp[n];
}

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int *dp =  new int[n+1];
    for(int i=0; i<=n; i++)
        dp[i] = -1; 
    cout<<minCost(n, arr, dp);
}

Measured memory_bytes: 7296