akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e15
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	string L;
	cin >> L;

	ll lLen = L.size();
	vector<vector<ll>> dp(lLen + 1, vector<ll>(2, 0));
	dp[0][0] = 1;
	REP(i, lLen) {
		if (L[i] == '1') {
			dp[i + 1][0] += dp[i][0] * 2;
			dp[i + 1][1] += dp[i][0];
		} else {
			dp[i + 1][0] += dp[i][0];
		}
		dp[i + 1][1] += dp[i][1] * 3;
		dp[i + 1][0] %= MOD;
		dp[i + 1][1] %= MOD;
	}

	ll ans = 0;
	ans += dp[lLen][0];
	ans += dp[lLen][1];
	ans %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
//#define TEST 
using namespace std;

#ifdef TEST
long long stack[200005];
#endif

struct Operation {
  bool kind;
  int a, b, c;
  Operation(){}
  Operation(bool k, int a_, int b_, int c_) : kind(k), a(a_) , b(b_), c(c_) {}
  
  #ifdef TEST
  void Process() {
    if (!kind) {
      stack[c] = stack[a] + stack[b];
    } else {
      stack[c] = (stack[a] < stack[b]);
    }
  }
  #endif

}op[200005];
int opnum;
void Add(int x, int y, int to) {
  op[++opnum] = Operation(0, x, y, to);
  #ifdef TEST 
    op[opnum].Process();
  #endif
}
void Comp(int x,int y, int to) {
  op[++opnum] = Operation(1, x, y, to);
  #ifdef TEST 
    op[opnum].Process();
  #endif
}

//a <= b = a < (b+1)
//OR(a,b) = (0<a) + (a<b)
//NOT(a) = a < 1

int New_Temporary_Pos() {
  static int x = 10000;
  x += 35; //each time no more than 30 position is used
  return x;
}

int Power2(int x) { return x + 2; }

int Not(int t) {
  int temp = New_Temporary_Pos();
  Comp(t, 2, temp);
  return temp;
}

int Or(int a, int b) {
  int temp = New_Temporary_Pos();
  Comp(50, a, temp); //[50] = 0
  Comp(a, b, temp + 1);
  Add(temp, temp + 1, temp);
  return temp;
}

int And(int a, int b) {
  return Not(Or(Not(a), Not(b)));
}

void AddPower(int x, int c, int k) {
  int temp = New_Temporary_Pos();
  Add(c, temp, temp);
  for (int i = 1; i <= k; ++i) {
    Add(temp, temp, temp);
  }
  Add(x, temp, x);
}

//decompose a number into 2-base representation
void Decompose(int x, int store_pos) {
  int temp_pos = New_Temporary_Pos();
  int nx = temp_pos + 1;
  Add(x, 2, nx); // [nx] = x + 1
  int pos = temp_pos + 1;
  for (int i = 29; ~i; --i) {
    Add(temp_pos, Power2(i), ++pos);
    Comp(pos, nx, ++store_pos);
    AddPower(temp_pos, store_pos, i);  // if result is 1 , temp += 2^..
  }
}

int main() {

#ifdef TEST 
  stack[0] = 105;
  stack[1] = 100;  
#endif

  Comp(0, 1, 2);
  Comp(1, 0, 3);
  Add(2, 3, 2); // = (a>b)+(b>a).  
  Add(2, 0, 2); // a=b=0 is ignored, a=0 will result in 1, a=b!=0 will result in a.  we ensure that 2^30 * this > b
  for (int i = 1; i <= 30; ++i) Add(2, 2, 2);   
  Comp(1, 2, 2);  // we have a '1' at pos 2
  for (int i = 1; i < 30; ++i) {
    Add(1 + i, 1 + i, 2 + i);   // [2+x]=2^x, x=0-29
  }
  Decompose(0, 100); // first number at [101, 130]
  Decompose(1, 200); // scond number at [201, 230]
  for (int i = 0; i < 30; ++i) {
    for (int j = 0; j < 30; ++j) {
      int t = And(130 - i, 230 - j);
      AddPower(60, t, i + j); // 60 is the sum
    }
  }

  Comp(2, 2, 2); // [2] = 0
  Add(2, 60, 2); // [2] = sum

  printf("%d\n", opnum);
  for (int i = 1; i <= opnum; ++i) {
    printf("%c %d %d %d\n", op[i].kind?'<':'+', op[i].a, op[i].b, op[i].c);
  }
  return 0;
}

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,l;cin >> n >> l;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	int k=0;
	bool flg=true;
	rep(i,n-1){
		if(a.at(i)+a.at(i+1)>=l){
			k=i;
			flg=false;
			break;
		}
	}
	if(flg) cout << "Impossible" << endl;
	else{
		cout << "Possible" << endl;
		rep(i,n-1){
			if(i!=k) cout << i+1 << endl;
			else break;
		}
		for(int i=n-2;i>=0;--i){
			if(i!=k) cout << i+1 << endl;
			else break;
		}
		cout << k+1 << endl;
	}
}


Measured memory_bytes: 1280
#include <stdio.h>
int main(void)
{
  int a, b, c, r;
  scanf("%d %d %d", &a, &b, &c);
  if(a > b){
    r = a;
    a = b;
    b = r;
  }
  if(a > c){
    r = a;
    a = c;
    c = r;
  }
  if(b > c){
    r = b;
    b = c;
    c = r;
  }
  printf("%d %d %d\n", a, b, c);
  return(0);
}

Measured memory_bytes: 596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }

    println!("{}", a*b)
}


Measured memory_bytes: 2112
D, G = map(int, input().split())
PC = [[int(pc) for pc in input().split()] for _ in range(D)]


def f(d, g):
    if 0 > d:
        return 100 ** 10
    n = min(g // (100 * (d + 1)), PC[d][0])
    s = n * 100 * (d + 1)
    if n == PC[d][0]:
        s += PC[d][1]
    if g > s:
        n += f(d - 1, g - s)
    return min(n, f(d - 1, g))


def main():
    print(f(D - 1, G))


main()


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

int main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;

  double ans = W / 2.0 * H;
  cout << ans << endl;

  if (x == W / 2.0 && y == H / 2.0) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 3015.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_L = 30;

/* typedef */

typedef vector<int> vi;

/* global variables */

string ss[MAX_N];
bool pls[MAX_N], used[MAX_N];
vi v0, v1;

/* subroutines */

bool revmatch(string &a, string &b) {
  int l = a.size();
  for (int i = 0, j = l - 1; j >= 0; i++, j--)
    if (a[i] != b[j]) return false;
  return true;
}

bool palindrome(string &a) {
  int l = a.size();
  for (int i = 0, j = l - 1; i < j; i++, j--)
    if (a[i] != a[j]) return false;
  return true;
}

/* main */

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

  for (int i = 0; i < n; i++) {
    char s[MAX_L + 4];
    scanf("%s", s);
    ss[i] = string(s);
  }
  sort(ss, ss + n);

  int c = -1;
  for (int i = 0; i < n; i++)
    if (! used[i]) {
      for (int j = i + 1; j < n; j++)
	if (! used[j] && revmatch(ss[i], ss[j])) {
	  v0.push_back(i), v1.push_back(j);
	  used[i] = used[j] = true;
	  break;
	}

      if (! used[i] && c < 0 && palindrome(ss[i]))
	c = i;
    }

  for (int i = 0; i < v0.size(); i++) printf("%s", ss[v0[i]].c_str());
  if (c >= 0) printf("%s", ss[c].c_str());
  for (int i = v1.size() - 1; i >= 0; i--) printf("%s", ss[v1[i]].c_str());
  putchar('\n');
  return 0;
}



Measured memory_bytes: 3392
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int a[n], A[n], ans = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		A[i] = a[i];
	}
	sort(a, a + n);
	sort(A, A + n);
	for (int i = 1; i < n; i++) {
		A[i] += A[i - 1];
	}
	// s
	for (int i = n - 2; i >= 0; i--) {
		if (A[i] * 2 >= a[i + 1]) {
			ans++;
		} else {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

const int MAXN=205;
vector<int> G[MAXN];
int d[MAXN][MAXN];

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

  int n;
  cin >> n;

  vector<long> a(n);
  fillLong(a, n);

  vector<long> axor(n+1);
  vector<long> aplus(n+1);

  axor[0] = 0;
  aplus[0] = 0;
  for(int i = 1; i < n+1; i++) {
    axor[i] = a[i-1]^axor[i-1];
    aplus[i] = a[i-1]+aplus[i-1];
  }

  long res = 0;
  rep(i, n) {
    int lb = i+1;
    int ub = n;
    int next;
    while(ub - lb > 1) {
      next = (lb+ub)/2;
      if((axor[next]^axor[i]) == (aplus[next]-aplus[i])) {
        lb = next;
      } else {
        ub = next;
      }
    }
    next = ub;
    while((axor[next]^axor[i]) != (aplus[next]-aplus[i])) {
      next--;
    }
    res += (next-i);
  }

  cout << res << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string sa,sb,sc;
    cin>>sa>>sb>>sc;
    int acnt=sa.size(),bcnt=sb.size(),ccnt=sc.size();
    int i=0,j=0,k=0;
    char s='a';
    while(i<=acnt&&j<=bcnt&&k<=ccnt){
        if(s=='a'){
            s=sa[i];
            i++;
        }
        else if(s=='b'){
            s=sb[j];
            j++;
        }
        else if(s=='c'){
            s=sc[k];
            k++;
        }
    }
    if(i==acnt+1) cout<<'A';
    else if(j==bcnt+1) cout<<'B';
    else if(k==ccnt+1) cout<<'C';
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int A, B;
    cin >> A >> B;
    if (A != 1 && B != 1) cout << 1 << endl;
    if (A != 2 && B != 2) cout << 2 << endl;
    if (A != 3 && B != 3) cout << 3 << endl;
    
    return 0;
}

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


using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    ll n;
    cin >> n;

    vector<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    ll sum = accumulate(all(v), 0ll );
    ll mini = sum;

    ll tmp = 0;
    for(int i = 0; i < n; i++){
        tmp += v[i];
        mini = min(  abs(sum - tmp - tmp), mini );
    }
    cout << mini << endl;

}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; cin >> n;
    vector<int> P(n);
    int mx = -1, sum = 0;
    rep(i,n){
        cin >> P[i];
        chmax(mx, P[i]);
        sum += P[i];
    }
    cout << sum - mx / 2 << ln;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int n;
inline int read()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + c - '0'; c = getchar();}
	return f * x;
}
const int MAXN = 201000;
int a[MAXN], b[MAXN], c[MAXN], l, r, x;
int main()
{
    n = read();
    for (int i = 1; i <= n; ++i) a[i] = read();
    for (int i = 1; i <= n; ++i) c[i] = read();
    for (int i = n; i >= 1; --i) b[i] = c[n - i + 1];
    x = -1;
    bool flag = false;
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] == b[i] && x == -1)
        {
            l = i;
            x = a[i];
            r = i;
            flag = true;
        }
        else if (x != -1 && a[i] == b[i])
            r = i;
    }
    if (flag)
    {
    for (int i = 1; i <= n; ++i)
    {
        if (x != a[i] && x != b[i] && l <= r)
        {
            l ++;
            swap(b[i], b[l - 1]);
        }
    }
    }
    if (l <= r && flag) cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
        for (int i = 1; i <= n; ++i) cout << b[i] << " ";
    }
    system("pause");
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

  ll N;

  cin >> N;
  ll ans_h, ans_n, ans_w;
  ans_h = 0;
  ans_n = 0;
  ans_w = 0;
  for(int h = 1; h <= 3500; h++){
    for(int n = 1; n <= 3500; n++){
      if((((4*h*n) - N *(n+h)) > 0) && (((N*h*n) % ((4*h*n) - N *(n+h))) == 0) && ((N*h*n) / ((4*h*n) - N *(n+h)) <= 3500)){
        ans_h = h;
        ans_n = n;
        // cout << (N*h*n) << " " << ((4*h*n) - N *(n+h)) << endl;
        ans_w = (N*h*n) / ((4*h*n) - N *(n+h));
        break;
      }
    }
  }

  cout << ans_h << " " << ans_n << " " << ans_w << endl;

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

r=0

if(N<K):
  if(abs(N-K)<N):
    r=abs(N-K)
  else:
    r=N

elif(K==1):
   r=0

elif(K<N):
  a=N//K
  N=N-K*a
  while(0<N):
    r=abs(N-K)
    N=N-K

print(r)

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

int main(void){
    long n;
    cin >> n;
    vector<long> v(n);
    long sum = 0;
    long vmin = 0;
    long vmax = 0;
    for(long i=0; i<n; i++){
        cin >> v[i];
        v[i] -= i+1;
        sum += v[i];
        vmax = max(vmax, v[i]);
        vmin = min(vmin, v[i]);
    }
    sort(v.begin(), v.end());
    long ans = 0;
    for(long i=0; i<n; i++){
        ans += labs(v[i]-v[n/2]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def f(n):
    if n == 0:
        return 0, False
    a = n // 3
    b = n % 3
    if b == 0:
        return a * 2, 0
    if b == 1:
        return a * 2 + 1, 1

    return a * 2 + 1, 2


def solve(s):
    last = s[0]
    c = 1
    res = 0
    last_flag = False
    for cc in s[1:]:
        if last == cc:
            c += 1
            continue

        k, k_flag = f(c)
        if k_flag == 0:
            res += k
        elif k_flag == 1:
            res += k
            last_flag = False
        else:
            if last_flag:
                res += k + 1
                last_flag = False
            else:
                res += k
                last_flag = True
        c = 1
        last = cc
    k, k_flag = f(c)
    if k_flag == 0:
        res += k
    elif k_flag == 1:
        res += k
    else:
        if last_flag:
            res += k + 1
        else:
            res += k
    return res


def main():
    s = input()
    # N = int(input())
    print(solve(s))
    # N, A, B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]


if __name__ == '__main__':
    main()


Measured memory_bytes: 43328
from itertools import product
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    *B, = map(int, readline().split())
    N = 10
    for p in product([0, 1], repeat = N):
        p1 = p2 = 0
        ok = 1
        for b, e in zip(B, p):
            if e:
                if not p1 < b:
                    break
                p1 = b
            else:
                if not p2 < b:
                    break
                p2 = b
        else:
            write("YES\n")
            break
    else:
        write("NO\n")
T = int(readline())
for i in range(T):
    solve()



Measured memory_bytes: 5632
N,M = map(int,input().split())
A = list(map(int,input().split()))
c=0
for i in range(len(A)):
 c+=A[i]
d=c/4/M
e=0
for i in range(len(A)):
 if A[i]>=d:
  e+=1
if e>=M:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 3064
n,m = (int(i) for i in input().split())

a = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]

for i in range(n):
    a[i] = [int(j) for j in input().split()]

for i in range(m):
    b[i] = int(input())

c = [0 for i in range(n)]

for i in range(n):
    for j in range(m):
        c[i] += a[i][j] * b[j]

for i in c:
    print(i)


Measured memory_bytes: 6016
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>

#define testin freopen("1.txt","r",stdin);
#define testout freopen("out.txt","w",stdout);

using namespace std;

int a[10];

int main(){
    for(int i=0;i<3;i++) cin>>a[i];
    sort(a,a+3);
    cout<<a[0]+a[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
 
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
 
typedef double ld;
typedef long long ll;
const ll N = 100500;
const ll mod = 1100000007;
const ll INF = 1e+9;
using namespace std;
//using namespace __gnu_pbds;
 
//typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

int arr[N];
int xd[N][2];
vector <pair<int, int>> xd1, xd2;

void solve(){
	int n; cin >> n;

	for(int i = 0; i < n; i++){

		cin >> arr[i];
		xd[arr[i]][i % 2]++;
	}
	int maxa = 0, maxb = 0;
	for(int i = 0; i < N; i++){
		xd1.push_back({xd[i][0], i});
		xd2.push_back({xd[i][1], i});
	}

	sort(xd1.begin(), xd1.end());
	sort(xd2.begin(), xd2.end());

	if(xd1[xd1.size() - 1].ss != xd2[xd2.size() - 1].ss){
		cout << n - xd1[xd1.size() - 1].ff - xd2[xd2.size() - 1].ff << endl;
	}
	else{
		int mini = max(xd1[xd1.size() - 2].ff + xd2[xd2.size() - 1].ff, xd1[xd1.size() - 1].ff + xd2[xd2.size() - 2].ff);
		cout << n - mini << endl;
	}
	
}
 
int main(){
	fastio;
	int tc = 1;
	//cin >> tc;

	while(tc--) solve();

	return 0;
}

Measured memory_bytes: 6288
N, M = gets.split.map(&:to_i)
ss = M.times.map { gets.split.map(&:to_i) }

a = Array.new(N) { |i| '0' }

ss.each do |s, c|
  if N != 1 && s == 1 && c == 0
    puts '-1'
    exit
  end
  if a[s - 1] != '0' && a[s - 1] != c.to_s
    puts '-1'
    exit
  end
  a[s - 1] = c.to_s 
end

a[0] = 1 if a[0] == '0' && N != 1

puts a.join.to_i


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

int N, M, A[51][51], V[51];
vector<pair<int, int>> E;

void dfs(int n, pair<int, int> inv){
	V[n] = 1;
	for(int i = 1; i <= N; i++)
		if(A[n][i] && !V[i] && !(n == inv.first && i == inv.second || n == inv.second && i == inv.first)) dfs(i, inv);
}

int main(){
	int sum = 0;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		E.push_back(make_pair(a, b));
		A[a][b] = 1, A[b][a] = 1;
	}
	for(int i = 0; i < M; i++){
		memset(V, 0, sizeof(V));
		dfs(1, E[i]);
		int cnt = 0;
		for(int j = 1; j <= N; j++)
			if(V[j]) cnt++;
		if(cnt < N) sum++;
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()
#define INPUT1(var) FOR(i,countof(var)) var[i] = ri() - 1

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

/* ********************** */
int main() {
    int n = ri();
    int res = INF;
    FOR(i,n+1) {
        int ress = 0;
        int t = i;
        while(t>0) ress+= t%6, t/=6;
        int r = n-i;
        while(r>0) ress+= r%9, r/=9;
        res = min(res,ress);
    }
    cout << res;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <algorithm> 
#include <vector> 
using namespace std;
 int main() 
{
 int n; 
cin >> n; 
vector<int> a(n);
 for (int i = 0; i < n; i++) 
{ 
cin >> a[i]; 
a[i] -= i + 1; 
} 
sort(a.begin(), a.end());
 long long ans = 0; 
for (int i = 0; i < n; i++) 
{
ans += abs(a[i] - a[n / 2]);
 } 
cout << ans << endl; 
} 


Measured memory_bytes: 1152
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
using namespace std;
ll a,b;
int main()
{
	cin>>a>>b;
	if((a<0&&b>0)||(a>0&&b<0||(a==0)||(b==0)))
	{
		cout<<"Zero"<<'\n';
		return 0;
	}
	if(a>0&&b>0)
	{
		cout<<"Positive"<<'\n';
		return 0;
	}
	if(a<0&&b<0)
	{
		if(!(((-a)+(-b))%2))
		{
			cout<<"Negative"<<'\n';
			return 0;
		}
		else
		{
			cout<<"Positive"<<'\n';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;

void solve() {
	cin >> N >> M;
	vi vec;
	for(int i = 1; i * i <= M; i++) {
		if(M % i) continue;
		if(i == M / i) vec.pb(i);
		else vec.pb(i), vec.pb(M / i);
	}
	int res = 0;
	rep(i, 0, sz(vec)) {
		if(1ll * vec[i] * N <= M) MAX(res, vec[i]);
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

ll x[100010];

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

	ll num = 0, m = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] % 4 == 0)num++;
		else if (x[i] % 2 == 0)m++;
	}
	
	num += m / 2;
	if (num >= n / 2)cout << "Yes" << endl;
	else cout << "No" << endl;
	return	0; 
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

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

  int H, W;
  cin >> H >> W;
  char S, T;
  cin >> S >> T;
  S -= 'A';
  T -= 'A';
  VS vs(H);
  cin >> vs;

  VVI G(26);
  REP(y,H) REP(x,W){
	if('A' <= vs[y][x] && vs[y][x] <= 'Z'){
	  int s = vs[y][x] - 'A';
	  REP(d,4){
		int tx = x + dx[d]*2;
		int ty = y + dy[d]*2;
		while(0 <= tx && tx < W && 0 <= ty && ty < H){
		  if((d%2==0&&vs[ty][tx] == '-') || (d%2==1&&vs[ty][tx] == '|')){
			tx += dx[d];
			ty += dy[d];
		  }
		  else if(vs[ty][tx] == 'o'){
			tx += dx[d];
			ty += dy[d];
			int t = vs[ty][tx] - 'A';
			G[s].PB(t);
			break;
		  }
		  else
			break;
		}
	  }
	}
  }

  queue<int> q;
  q.push(S);
  VI dist(26, -1);
  dist[S] = 0;
  while(!q.empty()){
	int u = q.front();
	q.pop();
	for(int to: G[u]){
	  if(dist[to] != -1) continue;
	  dist[to] = dist[u]+1;
	  q.push(to);
	}
  }
  cout << dist[T] << endl;

  return 0;
}



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

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

    vector<vector<int>> combi(n,vector<int>(26,0));
    for(int i=0;i<n;i++) {
        cin >> S;
        for(int j=0;j<S.size();j++) {
            combi[i][S[j]-'a']++;
        }
    }

    // アルファベット順に
    for(int i=0;i<26;i++) {
        minchar = 50;
        for(int j=0;j<n;j++) {
            if(minchar > combi[j][i]){
                minchar = combi[j][i];
            }
        }

        for(int k=0;k<minchar;k++) {
            printf("%c",'a' + i);
        }
    }

    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		String s = next();
		String[] output = new String[s.length()];
		Arrays.fill(output, "x");
		myout(myconv(output, 0));
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32844
import java.util.Scanner;

// C - Sentou
// https://atcoder.jp/contests/arc073/tasks/arc073_a
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int T = Integer.parseInt(scanner.next());
        int[] t = new int[N];
        for (int i = 0; i < N; i++) {
            t[i] = Integer.parseInt(scanner.next());
        }
        scanner.close();

        int seconds = 0;
        int oldTime = t[0];
        for (int i = 1; i < N; i++) {
            seconds += Math.min(t[i] - oldTime, T);
            oldTime = t[i];
        }

        seconds += T;

        System.out.println(seconds);
    }
}


Measured memory_bytes: 50048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] st2 = line2.split(" ");
		double[] x = new double[n];
		for (int i = 0; i < n; i++) {
			x[i] = Double.parseDouble(st2[i]);
		}

		String line3 = sc.nextLine();
		String[] st3 = line3.split(" ");
		double[] y = new double[n];
		for (int i = 0; i < n; i++) {
			y[i] = Double.parseDouble(st3[i]);
		}

		double D1 = 0;
		for (int i = 0; i < n; i++) {
			D1 += Math.abs(x[i] - y[i]);
		}
		System.out.println(D1);

		double D2 = 0;
		for (int i = 0; i < n; i++) {
			D2 += (x[i] - y[i]) * (x[i] - y[i]);
		}
		D2 = Math.sqrt(D2);
		System.out.println(D2);

		double D3 = 0;
		for (int i = 0; i < n; i++) {
			D3 += Math.abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
		}
		D3 = Math.cbrt(D3);
		System.out.println(D3);

		double Di = 0;
		double[] doub = new double[n];
		for (int i = 0; i < n; i++) {
			doub[i] = Math.abs(x[i] - y[i]);
		}
		double max = 0;
		for (int i = 0; i < n; i++) {
			if (doub[i] > max) {
				max = doub[i];
			}
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 26352
X = int(input())
if X % 500 == 0:
    print(int(X / 500 * 1000))
else:
    w = X % 500
    f = (X - w) / 500 * 1000
    n = w % 5
    l = (w - n) / 5 * 5
    print(int(f + l))

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    cout << N * (N + 1) / 2 - 3 * (N / 3) * (N / 3 + 1) / 2 - 5 * (N / 5) * (N / 5 + 1) / 2 + 15 * (N / 15) * (N / 15 + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 3676
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  print . showAnswer $ solve n

type Input  = (Int)
type Output = String

solve :: Input -> Output
solve = map f . show
  where
    f '1' = '9'
    f '9' = '1'

showAnswer :: Output -> Answer
showAnswer = String

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

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

using namespace std;

static const long long MOD = 1e9 + 7;

static long long calc_exp_mod (
    long long base,
    long long exponent)
{
    if ( exponent == 1 )
        return base;
    if ( exponent % 2 != 0 )
        return base * calc_exp_mod(base, exponent-1) % MOD;
    long long sqrt = calc_exp_mod(base, exponent/2);
    return (sqrt * sqrt) % MOD;
}

static long long calc_comb_mod (
    long long n,
    long long k)
{
    long long x = 1;
    long long y = 1;

    for ( int i=0; i<k; i++ ) {
        x *= n - i;
        y *= i + 1;
        x %= MOD;
        y %= MOD;
    }
    y = calc_exp_mod(y, MOD-2);
    return (x * y) % MOD;
}

int main (void) {
    int X, Y;
    cin >> X >> Y;

    long long ans = 0;
    /* (i+2, j+1)にa回、(i+1,j+2)にb回移動する */
    int a, b;
    for ( a = 0; 2 * a <= X; a++ ) {
        b = X - 2 * a;
        if ( a + 2 * b == Y ) {
            ans += calc_comb_mod(a+b, a);
        }
    }

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


Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N, M;

    cin >> N >> M;

    vector<bitset<400>> seen(N);
    vector<bool> alive(N, true);

    for (int i = 0; i < N; i++) 
        seen[i][i] = 1;

    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;

        if ((seen[x] & seen[y]).count()) {
            alive[x] = false;
            alive[y] = false;   
        }

        if (!alive[y])
            alive[x] = false;
        if (!alive[x])
            alive[y] = false;

        seen[x] |= seen[y];
        seen[y] |= seen[x];  
    }

    int res = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (alive[i] && alive[j] && !(seen[i] & seen[j]).count()) {
                res++;
            }
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    int i = A / K; int d = A % K;
    int j = B / K; int e = B % K;

	bool b=false;
    cout << (i != j || (i == j && d == 0)? "OK" : "NG") << endl; 
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){


		List<String> stlst = new ArrayList<>();
		stlst.add("AC");
		stlst.add("WA");
		stlst.add("TLE");
		stlst.add("RE");

		Map<String, Integer> list = new HashMap<>();

		for(String a : stlst) {
			list.put(a, 0);

		}

		Scanner sc = new Scanner(System.in);

		int loop = sc.nextInt();

		for(int i = 0; i < loop; i++) {
			String str = sc.next();
			int a = list.get(str) + 1;
			list.put(str, a);
		}



		for(String a : stlst) {
			System.out.println(
				a + " x " + list.get(a)
					);
		}
	}

}

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

typedef long l;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int DX[] = {1, 0, -1, 0, 1, 1, -1, -1}, DY[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  int n, d;

  cin >> n >> d;

  int x[n][d];
  int ct = 0;

  REP(i, n) {
    REP(j, d) {
      cin >> x[i][j];
    }
  }

  REP(i, n) {
    FOR(j, i + 1, n) {
      double c = 0;
      REP(k, d) {
        c += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      c = sqrt(c);
      int e = c;
      if (c - (int)e == 0.0L) ct++;
    }
  }

  cout << ct << endl;

}



Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()

def check_happiness(people):
    num_happiness = 0
    for i in range(0, len(people)-1):
        if people[i] == 'R' and people[i+1] == 'R':
            num_happiness += 1
        if people[i] == 'L' and people[i+1] == 'L':
            num_happiness += 1
    return num_happiness

print(min(check_happiness(S)+2*K, N-1))


Measured memory_bytes: 3316
a, b, k = map(int, input().split())

n=0
while n < k:
    if n%2==0:
        if a%2==0:
            halfA = a/2
            a=halfA
            b+=halfA
        else:
            halfA = (a-1)/2
            a=halfA
            b+=halfA
    else:
        if b % 2 == 0:
            halfB = b/2
            b = halfB
            a += halfB
        else:
            halfB = (b-1)/2
            b = halfB
            a+= halfB
    n+=1

print(str(int(a))+" "+str(int(b)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    cout << B * (T / A) << endl;
    return 0;
}


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

int a[3];

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

  sort(a, a+3);

  cout << a[0] << " " << a[1] << " " << a[2] <<endl;
}

Measured memory_bytes: 3152
n = (int)(input())

r = []
b = []

for _ in range(n):
    x, y = map(int, input().split())
    r.append([x, y])

for _ in range(n):
    x, y = map(int, input().split())
    b.append([x, y])

r.sort(key=lambda x: (x[1], x[0]))
b.sort(key=lambda x: (x[0], x[1]))

# print(r)
# print(b)
ans = 0
used_r = []
for i in range(n):
    #print("b", b[i])
    cnd = [v for v in r if v[0] < b[i][0]]
    cnd.sort(key=lambda x: x[1])
    pair = -1
    for j in range(len(cnd)):
        if cnd[j][1] < b[i][1]:
            pair = cnd[j]

    #print("cnd", cnd)
    #print("pair", pair)
    if pair != -1:
        r.remove(pair)
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i,n) {
        int l,r; cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = long.Parse(ReadLine());
        if (N<10)
        {
            WriteLine(N);
            return;
        }
        long max = CalcDigitSum(N);
        long tmp = 10;
        while (tmp <= N)
        {
            var val = CalcDigitSum(N - (N % tmp + 1));
            if (val > max) max = val;
            tmp *= 10;
        }
        WriteLine(max);
    }
    static long CalcDigitSum(long num)
    {
        long res = 0;
        foreach (var item in num.ToString())
        {
            res += long.Parse(item.ToString());
        }
        return res;
    }
}

Measured memory_bytes: 11092
import heapq
NM,a=open(0).read().rstrip().split('\n')
N,M=map(int,NM.split())
A=list(map(int,a.split()))
A=[-1*i for i in A]
heapq.heapify(A)
for i in range(M):
    sample=heapq.heappop(A)
    sample=-1*sample//2
    heapq.heappush(A,-1*sample)
print(-sum(A))

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

using namespace std;

int main() {
    int a, b, ans = 0;
    cin >> a >> b;
    for (int i = a; i <= b; ++i) {
        string s = to_string(i), r;
        r = s;
        reverse(r.begin(), r.end());
        if (s == r) {
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256