akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
using pint = pair<int,int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int H, W;
string fi[110];
int dist[110][110]; // BFS 用

int main() {
    // 入力
    cin >> H >> W;
	int wnum = 0;
	for (int i = 0; i < H; ++i) {
        cin >> fi[i];
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '.') ++wnum;
        }
	}

    // BFS
    memset(dist, -1, sizeof(dist));
	dist[0][0] = 1;
	queue<pint> que;
	que.push(pint(0, 0));
	while (!que.empty()) {
        pint cur = que.front();
        que.pop();
        int x = cur.first;
        int y = cur.second;
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x + dx[dir];
            int ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (fi[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push(pint(nx, ny));
            }
        }
	}
	if (dist[H-1][W-1] == -1) cout << -1 << endl;
	else  cout << wnum - dist[H-1][W-1] << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll n;
    cin>>n;
    vector<ll> w(n);
    vector<ll> s(n,0);
    rep(i,n){
        cin>>w[i];
        if(i!=0) s[i] = s[i-1] + w[i-1];
    }
    ll sum = accumulate(w.begin(),w.end(),0LL);
    ll k=sum;
    rep(i,n) k=min(k,abs(s[i]-(sum-s[i])));
    cout<<k<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 200001


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

    int n , t;
    cin >> n >> t;
    int a ,b;
    int ans = 100000000;
    for (int i = 0; i < n; i++) {
    	cin >> a >> b;
    	if (b <= t) {
    		ans = min(ans , a);
    	}
    }
    if (ans < 10000000) {
    	cout << ans << endl;
    }
    else {
    	cout << "TLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

void solve()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c, a*d, b*c, b*d})<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

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

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

int A,B,C,D,E,F;

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

	cin >> A >> B >> C >> D >> E >> F;

	int ansm = A*100, anss = 0;

	for (int a = 0;;a+=A){
		if(a*100 > F) break;
		for (int b = 0;;b+=B){
			if(a*100+b*100 > F) break;
			for (int c = 0;;c+=C){
				if(a*100+b*100+c > F) break;
				if(c > (a+b)*E) break;
				for (int d = 0;;d+=D){
					int m = a*100+b*100+c+d;
					if(m > F) break;
					if(c+d > (a+b)*E) break;
					if(anss*m < ansm*(c+d)){
						anss = c+d;
						ansm = m;
					}
				}
			}
		}
	}

	cout << ansm << " " << anss << endl;

	return 0;

}


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

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

int main()
{
	int n, k;
	cin >> n >> k;
	
	string s;
	cin >> s;

	s[k-1] = tolower(s[k-1]);

	cout << s << "\n";

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
  char s[11];
  
  int i;
  
  scanf("%s", s);
  
  for(i=0; i < 11 && s[i] != '\0'; i++) {
    if (i % 2 == 0) {
      if (s[i] != 'h') {
        puts("No");
        return 0;
      }
    } else {
      if (s[i] != 'i') {
        puts("No");
        return 0;
      }
    }
  }
  
  if (i%2 == 0) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  rep(i, 0, n * 2) {
    if (i % 2 == 0)
      cout << s[i / 2];
    else
      cout << t[(i - 1) / 2];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3624
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int h, n;
    cin >>h >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    ll sum = accumulate(a.begin(), a.end(), 0);
    if(h <= sum)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
ll mod=998244353;
int inf=1000000000;
ll INF=10000000000000000;
int main(){
    string s,t;
    cin >> s >> t;
    vector<vector<ll>> o(26,vector<ll>(0));
    rep(i,s.size()){
        int x=s.at(i)-'a';
        o.at(x).push_back(i);
    }
    ll ans=0,e=-1;
    rep(i,t.size()){
        int x=t.at(i)-'a';
        if (o.at(x).size()==0) {cout << -1 << endl;return 0;}
        else {
            auto itt=upper_bound(o.at(x).begin(),o.at(x).end(),e);
            if (itt==o.at(x).end()) {ans+=o.at(x).at(0)+s.size()-e;e=o.at(x).at(0);}
            else {ans+=*itt-e;e=*itt;}
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s1;
    string s2;

    cin >> s1;
    cin >> s2;

    string s = s1 + s1;
    size_t found = s.find(s2);
    if (found != string::npos)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long

const int mxN = 21;
int H,W;
char mat[mxN][mxN];
bool visited[mxN][mxN];
int dist[mxN][mxN];

pair<int,int>directions[4] = {{1,0},{0,1},{-1,0},{0,-1}};

bool isValidMove(int x,int y)
{
    return (x >= 0 && y >=0 && x < H && y <  W);
}

int bfs(int x,int y)
{
    queue<pair<int,int>>q;
    q.push({x,y});

    dist[x][y] = 0;
    visited[x][y] = true;

    int size = 0;

    while(!q.empty())
    {
        int row = q.front().first;
        int col = q.front().second;

        q.pop();

        for(auto dir : directions)
        {
            int new_row = row + dir.first;
            int new_col = col + dir.second;

            if(isValidMove(new_row,new_col) && !visited[new_row][new_col] && mat[new_row][new_col] == '.')
            {
                q.push({new_row,new_col});
                dist[new_row][new_col] = dist[row][col] + 1;
                visited[new_row][new_col] = true;
                size = max(size,dist[new_row][new_col]);
            } 
        }
    }

    return size;
}

void solve()
{
    cin>>H>>W;

    for(int i = 0 ; i < H; i++)
        for(int j = 0 ; j < W; j++)
            cin>>mat[i][j];
    
    int ans = 0;

    for(int i = 0; i < H; i++)
    {
        for(int j = 0 ; j < W; j++)
        {
            if(mat[i][j] == '.')
            {
                memset(visited,false,sizeof(visited));
                memset(dist,0,sizeof(dist));
                ans = max(ans,bfs(i,j));
            }
        }
    }
    
    cout<<ans<<endl;
}

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

    solve();

    return 0;
}

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

ll dp[101][101][500];
ll w[100];
ll v[100];
const ll INF = 1e18;

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

	ll N, W;
	cin >> N >> W;

	fill((ll*)begin(dp), (ll*)end(dp), -INF);
	dp[0][0][0] = 0;
	for(int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
		for(int j = 0; j <= 100; j++) {
			for(int k = 0; k < 500; k++) {
				if(dp[i][j][k] == -INF) continue;
				dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
				ll Wsum = j * w[0] + k + w[i];
				if(Wsum <= W) {
					dp[i + 1][j + 1][k + w[i] - w[0]] = max(dp[i + 1][j + 1][k + w[i] - w[0]], dp[i][j][k] + v[i]);
				}
			}
		}
	}

	ll ans = 0;
	for(int j = 0; j <= 100; j++) {
		for(int k = 0; k < 500; k++) {
			if(dp[N][j][k] == -INF) continue;
			ans = max(ans, dp[N][j][k]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 40192
"use strict";

const main = (arg) => {
  const array = arg.trim().split("\n");
  const array_A = array[0].trim().split(" ");
  const X = parseInt(array_A[0]);
  const N = parseInt(array_A[1]);
  if (N == 0) {
    console.log(X);
    return;
  }
  let array_B = array[1].trim().split(" ");
  array_B.sort(function (a, b) {
    return parseInt(a) < parseInt(b) ? -1 : 1;
  });

  let min = array_B[0];
  let max = array_B[N - 1];
  let maxNumber = 0;
  let minNumber = 0;

  for (let i = X; i < max; i++) {
    let maxFlag = true;
    for (let j = 0; j < array_B.length; j++) {
      // console.log(array_B[j]);
      if (array_B[j] == i) {
        maxFlag = false;
      }
    }
    if (maxFlag) {
      maxNumber = i;
      break;
    }
  }
  if (maxNumber == 0) {
    maxNumber = parseInt(max) + 1;
  }

  for (let k = X; min <= k; k--) {
    let minFlag = true;
    for (let l = 0; l < array_B.length; l++) {
      if (array_B[l] == k) {
        minFlag = false;
      }
    }
    if (minFlag) {
      minNumber = k;
      break;
    }
  }
  if (minNumber == 0) {
    minNumber = parseInt(min) - 1;
  }

  let result = 0;
  let maxResult = maxNumber - X;
  let minResult = X - minNumber;

  if (maxResult == minResult) {
    console.log(minNumber);
  } else if (maxResult < minResult) {
    console.log(maxNumber);
  } else if (minResult < maxResult) {
    console.log(minNumber);
  }
};
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main("6 5\n4 7 10 6 5");
// main("6 0\n");
// https://atcoder.jp/contests/abc170/tasks/abc170_c


Measured memory_bytes: 29516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int K,T; cin >> K >> T;
    VI A(T);
    REP(i,T){
        cin >> A[i];
    }
    sort(A.begin(),A.end(),greater<int>());

    cout << max(0, (A[0] - (K-A[0]+1))) << endl;

}


Measured memory_bytes: 256
(defun solve (s n queries)
  (declare (ignore n))
  (let ((reversed-p nil))
    (dolist (query (reverse queries))
      (destructuring-bind (x &optional y z) query
        (cond
          ((= x 1) (setf reversed-p (not reversed-p)))
          (t
           (when (or (and reversed-p
                          (= y 2))
                     (and (not reversed-p)
                          (= y 1)))
             (princ z))))))
    (if reversed-p
        (loop for i from (1- (length s)) downto 0
              do (write-char (aref s i)))
        (write-string s))
    (dolist (query queries)
      (destructuring-bind (x &optional y z) query
        (cond
          ((= x 1) (setf reversed-p (not reversed-p)))
          (t
           (unless (or (and reversed-p
                            (= y 2))
                       (and (not reversed-p)
                            (= y 1)))
             (princ z))))))
    (fresh-line)))

#-swank
(let* ((s (read-line))
       (n (read))
       (queries (loop repeat n
                      for x = (read)
                      if (= x 1)
                      collect (list x)
                      else
                      collect (list x (read) (read-char)))))
  (solve s n queries))


Measured memory_bytes: 70344
#include <stdio.h>
int main() {
    int H, W, i, j;
    
    while(1) {
        scanf("%d%d", &H, &W);
        
        if (H == 0 && W == 0) break;
        
        for (i = 0; i < H; i++) {
            
            for (j = 0; j < W; j++) {
                
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.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; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        string S;
        cin >> S;
        string ans(S.begin(), S.end()-8);
        cout << ans << endl;
}


Measured memory_bytes: 3632
#import sys
#sys.setrecursionlimit(20000)

times = int(input())
x = []
for t in range(times):
    x.append(list(map(int, input().split())))


def f(n):
    if n == 0:
        return 0
    if n == 1:
        return d
    if n in dic:
        return dic[n]

    if n%2 == 0:
        n2 = f(n // 2) + a
    elif n%2 == 1:
        n2 = min(f((n-1) // 2) + d, f((n+1) // 2) + d) + a

    if n%3 == 0:
        n3 = f(n // 3) + b
    elif n%3 == 1:
        n3 = min(f((n-1) // 3) + d, f((n+2) // 3) + 2*d) + b
    elif n%3 == 2:
        n3 = min(f((n-2) // 3) + 2*d, f((n+1) // 3) + d) + b

    if n%5 == 0:
        n5 = f(n // 5) + c
    elif n%5 == 1:
        n5 = min(f((n-1) // 5) + d, f((n+4) // 5) + 4*d) + c
    elif n%5 == 2:
        n5 = min(f((n-2) // 5) + 2*d, f((n+3) // 5) + 3*d) + c
    elif n%5 == 3:
        n5 = min(f((n-3) // 5) + 3*d, f((n+2) // 5) + 2*d) + c
    elif n%5 == 4:
        n5 = min(f((n-4) // 5) + 4*d, f((n+1) // 5) + d) + c

    Y = min(n2, n3, n5, n*d)
    dic[n] = Y
    return Y


for t in range(times):
    n, a, b, c, d = x[t][0], x[t][1], x[t][2], x[t][3], x[t][4]
    dic = {}
    print(f(n))



Measured memory_bytes: 10836
#include <iostream>
#include <queue>
using namespace std;
int main(){
  int n, q;
  cin >> n >> q;
  queue<pair<string, int> > queue;
  for(int i=0;i < n;i++){
    string name; int time;
    cin >> name >> time;
    queue.push(make_pair(name,time));
  }
  int now = 0;
  while(!queue.empty()){
    pair<string, int> que = queue.front(); queue.pop();
    if(que.second <= q){
      now += que.second;
      cout << que.first << " " << now << endl;
    }else{
      que.second -= q;
      queue.push(que);
      now += q;
    }
  }
	return 0;
}

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

#define endl "\n"
#define INF 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

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

int now() {
    return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()
    .time_since_epoch()).count();
}

vector<int> fact(5e5 + 5);

int nck(int n, int k) {
    return ((fastpow(fact[n - k], HELL - 2, HELL)) * 
            ((fact[n] * fastpow(fact[k], HELL - 2, HELL)) % HELL)) % HELL;
}

int32_t main() { fastio;
    time_t start = now();
    
    int n, k;
    cin >> n >> k;

    fact[0] = 1;
    for (int i = 1; i < fact.size(); i++) {
        fact[i] = (i * fact[i - 1]) % HELL;
    }

    int res = nck(2 * n - 1, n - 1);
    for (int i = k + 1; i < n; i++) {
        res = (res - (nck(n, i) * nck(n - 1, n - i - 1)) % HELL + HELL) % HELL;
    }
    cout << res << endl;

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// aより大きい、最小のmの倍数を返す
ll oki_baisu(ll a, ll m) { return (a % m == 0) ? a : a / m * m + m; }

// aより小さい、最大のmの倍数を返す
ll chi_baisu(ll a, ll m) { return (a % m == 0) ? a : a / m * m; }

// ====================================================================

int main() {
  ll K;
  cin >> K;
  vector<ll> A(K);
  for (int i = 0; i < K; i++) cin >> A[i];

  // ひっくり返す
  reverse(A.begin(), A.end());

  ll ans_min = A[0];
  ll ans_max = A[0];

  for (int i = 0; i < K - 1; i++) {
    ans_max = chi_baisu(ans_max + A[i] - 1, A[i + 1]);
    ans_min = oki_baisu(ans_min, A[i + 1]);
  }

  // 元に戻す
  reverse(A.begin(), A.end());

  // 実際にシミュレートする
  ll kakunin = ans_min;
  for (auto x : A) kakunin = kakunin / x * x;

  // 結果が2じゃないといけないので
  if (kakunin != 2) {
    cout << -1 << endl;
    return 0;
  }

  cout << ans_min << " " << ans_max + A[0] - 1 << endl;
}


Measured memory_bytes: 1024
def solve(T, R, S, P, K):
    N = len(T)
    Z =[None for i in range(N)]
    for i in range(N):
        if T[i] == 'r':
            Z[i] = P
        elif T[i] == 's':
            Z[i] = R
        else:
            Z[i] = S
        if i - K >= 0:
            if T[i-K] == T[i] and Z[i-K] != 0:
                Z[i] = 0
    return sum(Z)
N, K = map(int,input().split(' '))
R, S, P = map(int,input().split(' '))
T = str(input())
print(solve(T, R, S, P, K))

Measured memory_bytes: 10224
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val K = sc.nextInt

    val ke = K / 2
    val ko = if (K % 2 == 0) K / 2 else K / 2 + 1
    (ke * ko).toString
  }
}


Measured memory_bytes: 25420
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n], b[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }

    sort(b, b+n);

    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= 0; j--){
            if(a[i] != b[j]){
                cout << b[j] << endl;
                break;
            }else{
                cout << b[j-1] << endl;
                break;
            }
        }
    }


    return 0;
}

Measured memory_bytes: 3200
from bisect import bisect_right as br
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
time=0
allB=0
AA=[0]
BB=[0]
for i in range(N):
  AA.append(A[i]+AA[-1])
for i in range(M):
  BB.append(B[i]+BB[-1])

allB=br(BB,K)-1
ans=0
for i in range(allB,-1,-1):
  #print(i)
  ans=max(ans,i+br(AA,K-BB[i])-1)
print(ans)
  
  


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

const int N = 110;
const int moder = 1e9 + 7;

int dp[N][N][N], a[N];
int n;

int main(){
	scanf("%d", &n);
	for (int i = 1; i < n << 1; ++ i){
		scanf("%d", &a[i]);
	}
	std::sort(a + 1, a + (n << 1));
	dp[n][1][1] = 1;
	for (int i = n; i; -- i){
		bool flag1 = a[i - 1] == a[i], flag2 = a[2 * n - i + 1] == a[2 * n - i];
		for (int j = 0; j < N; ++ j){
			for (int k = 1; k <= j; ++ k){
				if (flag1 && flag2){
					int &x = dp[i - 1][j][k];
					x = (dp[i][j][k] + x) % moder;
					for (int kk = 1; kk < k; ++ kk){
						int &x = dp[i - 1][j - (k - kk - 1)][kk];
						x = (x + dp[i][j][k]) % moder;
					}
					for (int kk = k + 1; kk <= j; ++ kk){
						int &x = dp[i - 1][j - (kk - k - 1)][k + 1];
						x = (x + dp[i][j][k]) % moder;
					}
				}
				else if (flag1){
					int &x = dp[i - 1][j + 1][k];
					x = (dp[i][j][k] + x) % moder;
					for (int kk = 1; kk < k; ++ kk){
						int &x = dp[i - 1][j - (k - kk - 1) + 1][kk];
						x = (x + dp[i][j][k]) % moder;
					}
					for (int kk = k + 1; kk <= j + 1; ++ kk){
						int &x = dp[i - 1][j - (kk - k - 1) + 1][k + 1];
						x = (x + dp[i][j][k]) % moder;
					}
				}
				else if (flag2){
					int &x = dp[i - 1][j + 1][k + 1];
					x = (dp[i][j][k] + x) % moder;
					for (int kk = 0; kk < k; ++ kk){
						int &x = dp[i - 1][j - (k - kk - 1) + 1][kk + 1];
						x = (x + dp[i][j][k]) % moder;
					}
					for (int kk = k + 1; kk <= j; ++ kk){
						int &x = dp[i - 1][j - (kk - k - 1) + 1][k + 2];
						x = (x + dp[i][j][k]) % moder;
					}
				}
				else{
					int &x = dp[i - 1][j + 2][k + 1];
					x = (dp[i][j][k] + x) % moder;
					for (int kk = 0; kk < k; ++ kk){
						int &x = dp[i - 1][j - (k - kk - 1) + 2][kk + 1];
						x = (x + dp[i][j][k]) % moder;
					}
					for (int kk = k + 1; kk <= j + 1; ++ kk){
						int &x = dp[i - 1][j - (kk - k - 1) + 2][k + 2];
						x = (x + dp[i][j][k]) % moder;
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; ++ i){
		for (int j = 0; j < N; ++ j){
			ans = (ans + dp[1][i][j]) % moder;
		}
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(10);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll A,B;
    cin >> A >> B;
    char grid[100][100];
    bool flag = 0;
    if(A < B){
        FOR(i,0,100)FOR(j,0,100)grid[i][j] = '.';
        A--;
        FOR(i,0,25)FOR(j,0,25){
            if(A == 0)break;
            ll x = i*4+2;
            ll y = j*4+2;
            FOR(k,0,8){
                grid[x+dx8[k]][y+dy8[k]] = '#';
            }
            A--;
            B--;
        }
        REP(i,0,50)REP(j,0,50){
            if(B == 0)break;
            if(grid[i*2+1][j*2+1] == '.'){
                grid[i*2+1][j*2+1] = '#';
                B--;
            }
        }
    }
    else{
        swap(A,B);
        FOR(i,0,100)FOR(j,0,100)grid[i][j] = '#';
        A--;
        FOR(i,0,25)FOR(j,0,25){
            if(A == 0)break;
            ll x = i*4+2;
            ll y = j*4+2;
            FOR(k,0,8){
                grid[x+dx8[k]][y+dy8[k]] = '.';
            }
            A--;
            B--;
        }
        REP(i,0,50)REP(j,0,50){
            if(B == 0)break;
            if(grid[i*2+1][j*2+1] == '#'){
                grid[i*2+1][j*2+1] = '.';
                B--;
            }
        }
    }
    cout << 100 << ' ' << 100 << endl;
    FOR(i,0,100){
        FOR(j,0,100)cout << grid[i][j];cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a[300],sum,p;
main(){
cin>>n;
for(int k=1;k<=n;k++){
    cin>>a[k];
    p+=a[k];
}
int ans=INT_MAX;
for(int k=1;k<=n;k++){
        sum+=a[k];
        p-=a[k];
    ans=min(ans,abs(sum-p));
}
cout<<ans;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll f(ll b, ll n){
    if (n < b) return n;
    else return f(b, n/b) + (n%b);
}

int main() {
    ll n, s;
    cin >> n >> s;

    ll ans = -1;

    if (n == s){
        ans = n+1;
    }else{
        FOR(i,2,sqrt(n)){
            if (f(i, n) == s){
                ans = i;
                break;
            }
        }
        if (ans == -1){
            ans = 1e13;
            for (ll i = 1; i<sqrt(n); i++){
                ll x = (n-s)/i + 1;
                if (x > 1 && f(x, n) == s)
                    ans = min(ans,x);
            }
        }
        if (ans == 1e13) ans = -1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

signed
main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	int ans = 500;
	for(int i=0;i<3;i++){
			for(int j=i+1;j<3;j++){
					ans = min(ans, a[i]+a[j]);
			}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	int N, i,j;
	scanf("%d", &N);
	if (N % 111 != 0) {
		i = N / 111;
		i = i + 1;
	    j = i * 111;
	}
	else
		 j = N;

	printf("%d", j);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

char field[10][10];
bool grand[10][10] = {false};
bool reached[10][10] = {false};

int main() {
    int A, B;
    cin >> A >> B;

    int ans = 0, res = 1, pos = 0;
    while(1){
        if (res >= B){
            break;
        }
        res = res+A-1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  int mx = -1, idx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (abs(a[i]) > mx) {
      mx = abs(a[i]);
      idx = i;
    }
  }
  cout << 2 * n - 2 << '\n';
  for (int i = 1; i <= n; i++) {
    if (i == idx) continue;
    cout << idx << " " << i << '\n';
  }
  if (a[idx] >= 0) {
    for (int i = 1; i < n; i++) {
      cout << i << " " << i + 1 << '\n';
    }
  } else {
    for (int i = n; i > 1; i--) {
      cout << i << " " << i - 1 << '\n';
    }
  }
  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 ll long long

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

	if (b == "A") cout << 'T';
	if (b == "T") cout << 'A';
	if (b == "G") cout << 'C';
	if (b == "C") cout << 'G';


}



// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int v[26] = {};
    for(auto i:s){
        v[i-'a'] = 1;
    }
    f(26){
        if(!v[i]){
            cout<<char('a'+i) << '\n';
            exit(0);
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back 
#define endl '\n'
#define bug(x) cout << #x << " = " << x << '\n'
#define ll long long

int32_t main(){
	
	int balls, colors, ans = 0;
	cin >> balls >> colors;
	ans += colors;
	for(int i = 1; i < balls; i++)
		ans *= (colors - 1);
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  ll q;
  cin>>q;
  set<tuple<ll,int>> s;
  ll val = 0;
  auto itr = end(s);
  REP(i,q) {
    int t;
    cin>>t;
    if (t == 1) {
      ll a,b;
      cin>>a>>b;
      val += b;
      auto tp = make_tuple(a,i);
      s.insert(tp);
      if (itr == end(s)) { // s was empty
        --itr;
      } else {
        if (tp > *itr) {
          if (s.size() % 2 == 1) {
            ++itr;
          }
          ll nm = get<0>(*itr);
          val += abs(nm - a);
        } else {
          if (s.size() % 2 == 0) {
            ll pm = get<0>(*itr);
            --itr;
            ll nm = get<0>(*itr);
            val += abs(pm - nm);
          }
          ll nm = get<0>(*itr);
          val += abs(nm - a);
        }
      }
    } else {
      cout<<get<0>(*itr)<<' '<<val<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 12800
// AtCoder Regular Contest 075
// E - Meaningful Mean

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> PLI;

const int MAX_N = 200000;
const int MAX_BIT_IDX = MAX_N + 1;


template <typename T>
class BIT {
public:
  T b[MAX_BIT_IDX + 1];
  int n;
  void init(int num);
  T sum(int i);
  void add(int i, T x);
};

template <typename T>
void BIT<T>::init(int num) {
  n = num;
  for (int i = 0; i <= n; i++) {
    b[i] = 0;
  }
  return;
}

template <typename T>
T BIT<T>::sum(int i) {
  T s = 0;

  for (; i > 0; i -= i & -i) {
    s += b[i];
  }
  return s;
}

template <typename T>
void BIT<T>::add(int i, T x) {
  for (; i <= n; i += i & -i) {
    b[i] += x;
  }
  return;
}


int N;
ll K;
PLI b[MAX_N + 1];
BIT<int> bit;
ll ans;

int main() {

    ll a;

    scanf("%d%lld", &N, &K);
    b[0] = PLI(0, 0);
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &a);
        b[i].first = b[i - 1].first + a - K;
        b[i].second = i;
    }

    sort(b, b + N + 1);

    ans = 0;
    bit.init(N + 1);
    for (int i = 0; i <= N; i++) {
        ans += bit.sum(b[i].second + 1);
        bit.add(b[i].second + 1, 1);
    }

    printf("%lld\n", ans);

    return 0;

}





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

using namespace std;

#define int long long
#define MP make_pair

constexpr int INF = 1LL << 60;
constexpr int MOD = 998244353;
constexpr double EPS = 1.0e-11;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

constexpr int MAX_N = 15;
constexpr int MAX_Q = 55;

int arr[MAX_N], n, m, q, a[MAX_Q], b[MAX_Q], c[MAX_Q], d[MAX_Q];

int eval() {
    int res = 0;
    for (int i = 0; i < q; i++) {
        if (arr[b[i]] - arr[a[i]] == c[i]) {
            res += d[i];
        }
    }

    return res;
}

int solve(int k, int pre) {
    if (n + 1 <= k) {
        return eval();
    }

    int res = 0;
    for (int i = pre; i <= m; i++) {
        arr[k] = i;
        res = max(res, solve(k + 1, i));
    }

    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(16);

    cin >> n >> m >> q;
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    cout << solve(1, 1) << endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=4e5+100;
int main()
{
    FASTINOUT;
    int x,y;
    cin>>x>>y;
    cout<<(x-1)*(y-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
def f(W, H):
    res = float('INF')
    w = W // 2
    for h in range(1, H):
        res = min(res, max(h * W, (H - h) * w,  (H - h) * (W - w)
                           ) - min(h * W, (H - h) * w,  (H - h) * (W - w)))
    return min(H, res)


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
    else:
        print(min(f(W, H), f(H, W)))


main()


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	long long int T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
	long long int diff1 = T1 * A1 - T1 * B1;
	long long int diff2 = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2;
	if(diff1 > 0 && diff2 > 0 || diff1 < 0 && diff2 < 0){
		cout << 0 << endl;
		return 0;
	}
	if(diff2 == 0){
		cout << "infinity" << endl;
		return 0;
	}
	diff1 = abs(diff1);
	diff2 = abs(diff2);
	long long int ans = diff1 / diff2 * 2 + 1;
	if(diff1 % diff2 == 0){
		ans -= 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

ll mygcd(ll A, ll B)
{
  ll a = A, b = B;
  while (a > 0 && b > 0)
  {
    b %= a;
    swap(a, b);
  }
  return b;
}

ll mylcm(ll A, ll B)
{
  ll G = mygcd(A, B);
  return A / G * B;
}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  ll L = A.front() / 2;
  for (ll i = 1; i < N; i++)
  {
    L = mylcm(L, A.at(i) / 2);
    if (M < L)
      FINALANS(0);
  }

  vector<ll> B(N, 0);
  for (ll i = 0; i < N; i++)
  {
    ll a = A.at(i);
    while (a % 2 == 0)
    {
      a /= 2;
      B.at(i)++;
    }
    //cerr << B.at(i) << endl;
  }

  bool same = true;
  for (ll i = 0; i < N - 1; i++)
  {
    if (B.at(i) != B.at(i + 1))
    {
      same = false;
      break;
    }
  }

  if (!same)
    cout << 0 << endl;
  else
  {
    ll ans = divceil(M / L, 2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{

  int N;
  
  cin >> N; 

  string S,T;
  
  cin >> S >> T;
  
  for(int i=0;i<N;i++){
    cout << S[i];
    cout << T[i];    
  }
  
  return 0;
}

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

int main(){
    double n, d; cin >> n >> d;
    int ans = 0;

    rep(i, n){
        double x, y; cin >> x >> y;
        double distance = sqrt(x*x + y*y);
        if(distance <= d){
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3860
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
//#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern

//const int nax = 1e5 + 2;
const double eps = -1e3;
int n,k;
vector<double> v;
bool check(double val){
	//debug(val);
	int cnt = 0;
	for(int i =0 ; i < n ;i++){
		if(v[i] > val){
			int temp = 0;
			
			temp += v[i]/val;
			if(temp*v[i] < val){
				temp += 1;
			}
			cnt += temp;	
		}
		
	}
	
	if(cnt > k){
		return false;
	}
	else
		return true;
	
}

signed main() {    
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    
    cin >> n >> k;
    
    v.assign(n , 0);
    for(int i =0 ; i < n; i++){
		cin >> v[i];
	}
    
    int ma = *max_element(all(v));
    //int mi = *min_element(all(v));
    
    double ans = ma;
    
    double l = 0 , r = ma;
    while(abs(l - r) > 0.000001){
		//debug(l , r);
		
		double mid = l + (r - l)/2.00000;
		
		bool val = check(mid);
		
		if(val){
			ans = mid;
			
			r = mid;
		}
		else{
			l = mid;
		}
		
	}
    
    //debug(ans);
    double val = ceil(ans);
    double val2 = floor(ans);
    
    if(ans - l <= r - ans){
		cout<<(int)val2;
	}
	else{
		cout<<(int)val;
	}
    
    
    return 0;
}


Measured memory_bytes: 4708
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<pair<int,int>>edges;
	int sum=n;
	if(n%2==0)sum++;
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++){
			if(i+j==sum)continue;
			edges.push_back({i,j});
		}
	}
	cout<<int(edges.size())<<'\n';
	for(auto x : edges)cout << x.first << ' ' << x.second << '\n';
}


Measured memory_bytes: 384
import java.util.*;
import java.util.Arrays;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);      
      int n = sc.nextInt();
      int[] member = new int[n];
      for(int i=0;i<n;i++){
        member[i]=sc.nextInt();
      }
      Arrays.sort(member);      
      if(n%2!=0 && member[0]!=0){
        System.out.println(0);
        System.exit(0);
      }else{
        for(int i=member.length-1;i>0;i-=2){
          if(member[i] != member[i-1]){
            System.out.println(0);
            System.exit(0);
          }
        }
      }
      
     long ans=1;
     for(int i=0; i<n/2; i++){
       ans = 2*ans%1000000007;
     }
	 System.out.println(ans);
      
      //long sortComb =(long)Math.pow(2, n/2);
      //sortComb %= 1000000000 + 7;
      //System.out.println(sortComb);
	}
}

Measured memory_bytes: 49580
import numpy as np
H,N=map(int, input().split())
A=[]
B=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)

A=np.array(A)
B=np.array(B)
dp=np.ones((H+1+10**4))*np.inf
dp[H+1:]=0
dp[0]=0
for i in range(1,H+1):
    
    dp[i]=min(dp[i-A]+B)

print(int(dp[H]))
#print(dp)

Measured memory_bytes: 21920
n, m = map(int, input().split())
l = []
for i in range(n):
    x, y, z = map(int, input().split())
    l.append([x, y, z])
ans = 0
for i in range(8):
    a = bin(i)[2:].zfill(3)
    xi = 1 if a[0] == '1' else - 1
    yi = 1 if a[1] == '1' else - 1
    zi = 1 if a[2] == '1' else - 1
    l = sorted(l, key=lambda value: value[0] * xi + value[1] * yi + value[2] * zi, reverse=True)
    ans = max(ans, abs(sum(j[0] * xi for j in l[:m])) + abs(sum(j[1]*yi for j in l[:m])) +abs(sum(j[2]*zi for j in l[:m])))
print(ans)



Measured memory_bytes: 43376
N,x = map(int,input().split())
num = list(map(int,input().split()))
count = 0
for i in range(N-1):
  sum2 = num[i] + num[i+1]
  if x < sum2:
    count += (sum2 -x)
    if sum2-x <= num[i+1]:
      num[i+1] -= sum2-x
    else:
      num[i+1] = 0
print(count)

Measured memory_bytes: 14132