akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
//#include <mikasa>
using namespace std;
char s[10],t[10];
int main()
{
    scanf("%s %s",s,t);
    if(s[0]==t[2] && s[1]==t[1] && s[2]==t[0])
        puts("YES");
    else 
        puts("NO");
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	c := make([]int, n)
	s := make([]int, n)
	f := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i], &s[i], &f[i])
	}

	for i := 0; i < n; i++ {
		t := 0
		for j := i; j < n-1; j++ {
			if t < s[j] {
				t = s[j]
			} else if t%f[j] != 0 {
				t += f[j] - t%f[j]
			}
			t += c[j]
		}
		fmt.Println(t)
	}
}


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

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                int n = Integer.parseInt(line);
                call(n);
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
    
    private static void call(int n) {
        int x;
        for(int i = 1; i <= n; i++) {
            x = i;
            if(x % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while(x != 0) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    
                    break;
                }
                x /= 10;
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 26532
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	string s;
	cin >> s;
	if(s == "ABC") puts("ARC");
	else puts("ABC");

	return 0;
}


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

import sys
sys.setrecursionlimit(10 ** 6)

class Impossible(ValueError):
    pass

def main():
    n, m = map(int, input().split())
    lrds = []
    for i in range(m):
        l, r, d = map(int, input().split())
        lrds.append((l - 1, r - 1, d))

    adj = [[] for i in range(n)]
    parents = [i for i in range(n)]
    for i in range(m):
        l, r, d = lrds[i]
        union(parents, l, r)
        adj[l].append((r, d))
        adj[r].append((l, -d))

    ds = set()
    for i in range(n):
        ds.add(find(parents, i))

    pos = [None for i in range(n)]
    try:
        for i in ds:
            pos[i] = 0
            dfs(adj, pos, i)
        print("Yes")
    except Impossible:
        print("No")

def dfs(adj, pos, x):
    for y, d in adj[x]:
        if pos[y] is None:
            pos[y] = pos[x] + d
            dfs(adj, pos, y)
        elif pos[y] != pos[x] + d:
            raise Impossible

def find(p, x):
    if p[x] != x:
        p[x] = find(p, p[x])
    return p[x]

def union(p, x, y):
    p[find(p, y)] = find(p, x)


main()


Measured memory_bytes: 141220
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#define ll long long
const int MOD= 1e9 + 7;
using namespace std;

int main()
{
	int n, m, l, a[50], b[50], c[50], d[50], ans[50];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}
	for (int i = 0; i < n; i++) {
		l = MOD;
		for (int j = 0; j < m; j++) {
			if (l > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				l = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans[i] = j;
			}
		}
		cout << ans[i] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;
ll dp[2][2020];

int main(void){
	cin >> s;
	int n=s.size();
	int cur=0,nxt=1;
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=dp[cur][0];
		for(int j=0;j<2020;j++){
			int nj=(j*10+(s[i]-'0'))%2019;
			dp[nxt][nj]+=dp[cur][j];
		}
		dp[nxt][(s[i]-'0')]++;
		swap(cur,nxt);
		for(int j=0;j<2020;j++){
			dp[nxt][j]=0;
		}
	}
	ans+=dp[cur][0];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3908
import java.util.*;
 
public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < N-1; i++) {
            int a = sc.nextInt(); a--;
            int b = sc.nextInt(); b--;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }

        long ans = K*dfs(K, graph, 0, -1);
        ans %= MOD;

        System.out.println(ans);
    }

    private static long dfs(int K, List<List<Integer>> graph, int now, int from) {

        int colorNum = from == -1 ? K-1 : K-2;

        long ret = 1;
        for (int next : graph.get(now)) {
            if (next != from) {
                ret *= colorNum;
                ret %= MOD;
                colorNum--;

                ret *= dfs(K, graph, next, now);
                ret %= MOD;
            }
        }

        return ret;
    }
}


Measured memory_bytes: 110564
l, r = map(int, input().split())

result = None
for i in range(l, min(l + 2019 - l % 2019, r - 1) + 1):
    for j in range(i + 1, min(i + 2019, r) + 1):
        mod = i * j % 2019
        if result is None or result > mod:
            result = mod
print(result)


Measured memory_bytes: 40684
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<ll, int> P;


int main(){
	ll x;
	cin >> x;
	ll y = x / 11, z = x % 11;
	ll ans;
	if (z == 0) {
		ans = y * 2;
	}
	else if (z <= 6) {
		ans = y * 2 + 1;
	}
	else {
		ans = y * 2 + 2;
	}
	cout << ans << endl;
	return 0;
}


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

//  n を素因数分解した場合の素数の数
vector<pair<ll,ll>> factorize(ll n) {
  ll p = 2;
  vector<pair<ll, ll>> res;
  while (p * p < n) {
    if (n % p == 0) {
      ll cnt = 0;
      while (n % p == 0) {
        n /= p;
        cnt++;
      }
      res.push_back(make_pair(p, cnt));
    }
    p++;
  }

  if(n != 1) res.push_back(make_pair(n, 1));

  return res;
}

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

    if (n==1){
      cout << 0 << endl;
      return 0;
    }

    vector<pair<ll,ll>> f = factorize(n);

    vector<ll> a;
    a.push_back(1);
    ll i = 2;
    while(true){
      ll tmp = a[i-2] + i;
      if (tmp > 100) break;
      a.push_back(tmp);
      i++;
    }

    ll ans = 0;
    for(pair<ll,ll> p : f){
      ll k = p.second;
      auto iter = lower_bound(a.begin(),a.end(), k);
      int ind = iter - a.begin();
      if(k < a[ind]){
        ind--;
      }

      ans += ind + 1;
    }
     

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

Measured memory_bytes: 3632
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
c.sort()
ans = 0
for i in range(n):
    anum = bisect.bisect_left(a, b[i])
    cnum = n - bisect.bisect_right(c, b[i])
    ans += anum * cnum

print(ans)


Measured memory_bytes: 23360
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  string s="NO";
  if(v>w && abs(a-b)<=t*(v-w))s="YES";
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int M=0;
  int L=0;
  cin>>N;
  vector<long long>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
    if(X>0 && vec.at(X)<=vec.at(X-1)){
      M++;
    }
    else if(X>0 && vec.at(X)>vec.at(X-1)){
      if(M>=L){
        L=M;
        M=0;
      }
      else{
        M=0;
      }
    }
  }
  cout<<max(L,M)<<endl;
}

Measured memory_bytes: 4056
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;


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

	long int tot = 0;
	int totfirst = 0;
	rep(i, 0, k)tot += a[i];
	long int max = tot;
	rep(i, k, n) {
		tot = tot + a[i] - a[i - k];
		if (max < tot) {
			max = tot;
			totfirst = i - k + 1;
		}
	}
	double ans = 0;
	rep(i, totfirst, totfirst + k) {
		ans+=static_cast<double>((a[i]+ 1) / 2.0);
	}
	cout << fixed << setprecision(7) << ans << endl;
}




Measured memory_bytes: 4060
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int A,B,C,D,count = 0;
    cin >> A >> B >> C >> D;

    while(A > 0 && C > 0){
        if(count % 2 == 0){
            C -= B;
        }else{
            A -= D;
        }
        count++;
    }

    if(A <= 0){
        cout << "No" << endl;
    }else if(C <= 0){
        cout << "Yes" << endl;
    }
}

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

int main()
{
  int N, K, Q;
  int a[110000];
  int win[110000];
  cin >> N >> K >> Q;

  for(int i=0;i<Q;i++) cin >> a[i];
  rep(i,Q) a[i]--;

  rep(i,N) win[i] = 0;

  rep(i,Q) {
    int winner=a[i];
    win[winner]++;
  }

  rep(i,N) {
    if(K-Q+win[i]>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
}



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

// for 1 ... N O(N)
// MAX_N = 2^(2e5)
//   f(MAX_N) < 2e5
//   f(2e5) < 31
//   f(31) < 8

int popcount(int x) {
    return __builtin_popcount(x);
}

int f(int x) {
    if (x == 0) return 0;
    return f(x % popcount(x)) + 1;
}

int main() {
    int N; cin >> N;
    string s; cin >> s;
    vector<int> X(N);
    for (int i = 0; i < N; ++i) X[i] = s[i] - '0';
    int pc0 = accumulate(X.begin(), X.end(), 0);
    vector<int> ans(N);
    for(int b = 0; b < 2; ++b) {
        int pc = pc0;
        if (b == 0) ++pc; else --pc;
        if (pc <= 0) continue;
        int r0 = 0;
        for (int i = 0; i < N; ++i) {
            r0 = (r0 * 2) % pc;
            r0 = (r0 + X[i]) % pc;
        }
        int p = 1;
        for (int i = 0; i < N; ++i) {
            int ix = N - i - 1;
            if (X[ix] == b) {
                int r = r0;
                if (b == 0) {
                    r += p;
                    r %= pc;
                } else {
                    r -= p;
                    r = (r + pc) % pc;
                }
                ans[ix] = f(r) + 1;
            }
           p = (p * 2) % pc;
        }
    }
    for (int i = 0; i < N; ++i) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 5212
D = 10**9+7
N,K,*A = $<.read.split.map &:to_i
A.sort!
i = A.bsearch_index {0 <= _1} || N
M = A[0...i]
j = A[i...N].bsearch_index {0 < _1} || N-i
Z = A[i,j]
P = A[i+j...N]
A.sort_by! {|a| a<0 ? -1-a-a : a+a }
A.shift j
m = (K > P.size + M.size/2*2) ? 1 : (K.odd? && !P[0])
exit p(0)  if m && j>0
if m
  s = 1
  A[0,K].each{s *= _1; s %= D if s > D }
  p (s+D) % D
  exit
end  
k,s = K,1
a,b = P.pop 2
c,d = M.shift 2
while k > 1 && b && d
  k -= 2
  if (x=a*b) > (y=c*d)
    s = s*x % D
    a,b = P.pop 2
  else
    s = s*y % D
    c,d = M.shift 2
  end
end
(s = c*d*s % D; c,d = M.shift 2; k-=2)  while d && k > 1
(s *= b; k-=1)  if b && k > 0
(s = s*a % D; a = P.pop; k-=1)  while k > 0
p s % D

Measured memory_bytes: 37296
N,K=map(int, input().split())
#aをbで割った余りがK以上
#b>a bがK+1以上　bーK
#a=b K=0 Nこ
#a>b bがK+1以上 bをずらしてく　a: N-bこ　（N-b）//b*(b-K)+
ans=0
if K==0:
    ans+=N
for b in range(K+1,N+1):
    if b<=N-1:
        ans+=( (N-b)//b )*(b-K)
        if (N-b)%b!=0:
            if K==0:
                X=1
            else:
                X=K
            ans+=max((N-b)%b-X+1,0)
    if b>=2:
        if K==0:
            X=1
        else:
            X=K
        ans+=b-X
    
print(ans)
#3  6   2

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


struct Point { double x, y;};

void koch(int n, Point a, Point b){
    if (n == 0) return;

    Point s, t, u;
    double th = M_PI / 3;

    s.x = (2 * a.x + b.x) / 3;
    s.y = (2 * a.y + b.y) / 3;
    t.x = (a.x + 2 * b.x) / 3;
    t.y = (a.y + 2 * b.y) / 3;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

int main() 
{
    int n;
    Point a, b;
    cin >> n;

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f", b.x, b.y);

    return 0;
}


Measured memory_bytes: 3160
#include <stdio.h>

int main(void)
{
	int a, b;
	char op;

	while (1)
	{
		scanf("%d%s%d", &a, &op, &b);

		switch (op)
		{
			case '+': printf("%d\n", a + b); break;
			case '-': printf("%d\n", a - b); break;
			case '*': printf("%d\n", a*b); break;
			case '/': printf("%d\n", a / b); break;
		}

		if (op == '?')
			break;

	}

	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	string s; cin>>s;
	if(s.back()=='s') s+="es";
	else s+="s";
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3624
// https://atcoder.jp/contests/abc174/tasks/abc174_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll K;
  cin >> K;

  ll cur = 7 % K;
  ll res = 1;

  set<ll> s;

  while (s.count(cur) == 0) {
    if (cur == 0) drop(res);

    s.insert(cur);
    cur = (10 * cur + 7) % K;
    ++res;
  }

  drop(-1);
}


Measured memory_bytes: 50448
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 123456789;

struct Edge{
  int to, cost;

  Edge(int t, int c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
};

typedef vector< vector<Edge> > Graph;
void Dijkstra(const Graph& edges, vector<int>& d, int s){
  const int V = edges.size();
  priority_queue<PII, vector<PII>, greater<PII> > pq;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  pq.push(MP(0,s));

  while(!pq.empty()){
	PII pii = pq.top(); pq.pop();
	int v = pii.second;
	if(d[v] < pii.first) continue;
	for(auto& e:edges[v]){
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		pq.push(MP(d[e.to], e.to));
	  }
	}
  }
}

int W, H;
int idx(int x, int y){
  return y*W+x;
}

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

  for(;;){
	cin >> W >> H; if(!W) break;
	Graph G(W*H);
	bool fl = true;
	REP(y,2*H-1){
	  if(fl){
		REP(x,W-1){
		  int t; cin >> t;
		  if(!t){
			G[idx(x,y/2)].PB(Edge(idx(x+1,y/2), 1));
			G[idx(x+1,y/2)].PB(Edge(idx(x,y/2), 1));
		  }
		}
		fl = false;
	  }
	  else{
		REP(x,W){
		  int t; cin >> t;
		  if(!t){
			G[idx(x,y/2)].PB(Edge(idx(x,y/2+1), 1));
			G[idx(x,y/2+1)].PB(Edge(idx(x,y/2), 1));
		  }
		}
		fl = true;
	  }
	}
	VI d(W*H+1);
	Dijkstra(G, d, 0);
	if(d[W*H-1] == INF)
	  cout << 0 << endl;
	else
	  cout << 1+d[W*H-1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
int main(){
    string b;
    cin >> b;
    if (b == "A"){
        cout << "T";
    } else if (b == "T"){
        cout << "A";
    } else if (b == "C"){
        cout << "G";
    } else if (b == "G"){
        cout << "C";
    }
}


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

const int MOD = 1e+9 + 7;

typedef long long ll;

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

  bool finish=false;
  int array[N]={0};
  ll ans=1;
  for (int i=0; i<N; i++) {
    array[A[i]]++;
  }
  if ((N & 1) == 0) {
    for (int i=0; i<N; i++) {
      if ((i & 1) == 1 && array[i] != 2) {
        finish = true;
        break;
      }
    }

    for (int i=0; i<N/2; i++) {
      ans *= 2;
      ans %= MOD;
    }
  } else {
    if (array[0] != 1) finish = true;
    for (int i=1; i<N; i++) {
      if ((i & 1) == 0 && array[i] != 2) {
        finish = true;
        break;
      }
    }

    for (int i=0; i<(N-1)/2; i++) {
      ans *= 2;
      ans %= MOD;
    }
  }

  if (finish) cout << 0 << endl;
  else cout << ans << endl;

  return 0;
}









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

int main() {
 UL N; scanf("%u",&N);
 UL A[200001]; rep(i,N) scanf("%u",&A[i]); A[N]=~0u;
 UL M; scanf("%u",&M);
 UL B[200001]; rep(i,M) scanf("%u",&B[i]); B[M]=~0u;
 UL p=0,q=0;
 while(p+q<N+M){
  if(A[p]<B[q]){ p++; }
  else if (A[p]>B[q]){ q++; }
  else { printf("%u\n",B[q]); p++; q++; }
 }
 return 0;
}



Measured memory_bytes: 4736
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll h,a,cnt=0;
  cin >> h >> a;
  while(h>0){
    h-=a;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    char A = a.at(0);
    char B = b.at(0);
    char C = c.at(0);
    char w = 'A'-'a';
    A += w;
    B += w;
    C += w;
    cout<<A<<B<<C<<endl;
    return 0;
}


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

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] list = new int[3];

		for (int i = 0; i < list.length; i++)
			list[i] = scanner.nextInt();

		Arrays.sort(list);
		System.out.println(list[0] + " " + list[1] + " " + list[2]);
	}
}

Measured memory_bytes: 26152
#include<iostream>
using namespace std;
int main(){
    int n,fib[45];
    cin>>n;
    fib[0]=fib[1]=1;
    for(int i=2;i<=n;i++)fib[i]=fib[i-1]+fib[i-2];
    cout<<fib[n]<<endl;
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */
const int MOD = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N, K; cin >> N >> K;
  vector<int> a(N); REP(i, N) cin >> a[i];

  vector<vector<ll>> dp(N+1, vector<ll>(K+1, 0));
  dp[0][0] = 1;

  FOR(i, 1, N+1) {
    //dp[i-1]の累積和
    vector<ll> sum(K+1, 0);
    sum[0] = dp[i-1][0];
    REP(j, K){
      sum[j+1] = sum[j] + dp[i-1][j+1] % MOD;
    }

    REP(j, K+1) {
      int kmin = max(j - a[i-1], 0);
      dp[i][j] =  (MOD + sum[j] - (kmin ? sum[kmin-1] : 0)) %MOD;
    }
  }
  cout << dp[N][K] << endl;
}


Measured memory_bytes: 80256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
	int n;
	cin>>n;
	int cnt=0;
	bool ok=true;
	for(int i=0;i<n;i++){
		string s={};
		cin>>s;
		if(s=="A")cnt++;
		else cnt--;
		if(cnt<0)ok=false;
	}
	if(cnt==0&&ok)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}



Measured memory_bytes: 3228
from functools import reduce
import sys

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


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

def gcd(a, b):
    import fractions
    return fractions.gcd(a, b)


def temp(a):
    return int(a * 0.5)

max_a = max(A)

i = 0
while True:
    num = int((i+0.5) * max_a)
    if num > M:
        print(0)
        sys.exit()

    found = True
    for a in A:
        if int(num - 0.5 * a) % a != 0:
            found = False
            break
    if found:
        ans = 1
        break
    i += 1

aa = reduce(lcm, A)

ans += (M - num) // aa

print(int(ans))


Measured memory_bytes: 83936
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
xt = 0
for i in range(1, N):
	xt += x
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = xt + sum(BC)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)


Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>
#include <iostream>

using namespace std;

int makedigit(int num){
	int dig=0;
	for(int i=0;i<5; i++){
		dig += num % 10;
		num = num / 10;
	}
	return dig;
}

int main(){

	int n, a, b, sum=0, dig;

	cin >> n >> a >> b;

	for(int i=1; i<=n; i++){
		dig = makedigit(i);
		if(a<=dig && dig<=b){
			sum += i;
		}
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
b = input()

count = 0
max_count = 0
for s in b:
  if s == "A" or s == "C" or s == "G" or s == "T":
    count += 1
  else:
    if max_count < count:
      max_count = count
    count = 0
if max_count == 0 or max_count < count:
  	max_count = count
print(max_count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll D=1e18;

ll spr(ll a,ll b);

 int main()
 {
	ll h,w;
	scanf("%lld%lld",&h,&w);

	ll wn;
	wn=min(spr(w,h),spr(h,w));

	printf("%lld\n",wn);
 }
/////
 ll spr(ll a,ll b)
 {
	ll wn,mx,mn;
	wn=D;

	for(ll i=1;i<=a;i++)
	{
		mx=max(b*i,max((a-i)*((b)/2),(a-i)*((b+1)/2)));
		mn=min(b*i,min((a-i)*((b)/2),(a-i)*((b+1)/2)));

		wn=min(wn,mx-mn);	
	}

	if(a%3==0) wn=0;
	else wn=min(wn,b);

	return wn;
 }


Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    X = int(input())
    if X >= 30:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 65236
import java.util.*;
import java.awt.geom.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x==0 && y==0) break;
			
			ArrayList<Point2D.Double> list = new ArrayList<Point2D.Double>();
			ArrayList<Point2D.Double> temp = new ArrayList<Point2D.Double>();
			list.add(new Point2D.Double(x, y));
			
			int n = sc.nextInt();
			int q, r;
			Point2D.Double p;
			boolean flag = false;
			for(int i=0;i<n;i++){
				x = sc.nextInt();
				y = sc.nextInt();
				if(flag==false){
					for(int j=-1;j<=1;j++){
						for(int k=-1;k<=1;k++){
							if(0<=x+j && x+j<=9 && 0<=y+k && y+k<=9){
								for(int a=-1;a<=1;a++){
									for(int b=0;b<2;b++){
										q = x+j + 2*b + a*(1-b);
										r = y+k + 2*(1-b) + a*b;
										p = new Point2D.Double(q, r);
										if(list.contains(p)==true){
											temp.add(new Point2D.Double(x+j, y+k));
											a = 2;
											break;
										}
										q = x+j - 2*b + a*(1-b);
										r = y+k - 2*(1-b) + a*b;
										p = new Point2D.Double(q, r);
										if(list.contains(p)==true){
											temp.add(new Point2D.Double(x+j, y+k));
											a = 2;
											break;
										}
									}
								}
							}
						}
					}
					if(temp.size()==0) flag = true;
					list.clear();
					for(int j=0;j<temp.size();j++) list.add(temp.get(j));
					temp.clear();
				}
			}
			if(flag==true) System.out.println("NA");
			else System.out.println("OK");
		}
	}	
}

Measured memory_bytes: 17312
n,m,d=map(int,input().split())
lst=[input()+"#"*d for i in range(n)]
for i in range(d):
    lst.append("#"*m)
ans=0
for i in range(n):
    for j in range(m):
        if not "#" in lst[i][j:j+d]:ans+=1
        if not "#" in [lst[i+x][j] for x in range(d)]:ans+=1
print(ans)


Measured memory_bytes: 5612
def nCr(n,r):
  dividend = 1
  divisor = 1
  MOD = 10**9+7
  d1 = n
  for i in range(1,r+1):
    dividend *= d1
    divisor *= i
    d1 -= 1
    dividend %= MOD
    divisor %= MOD

  return (dividend * pow(divisor, MOD-2, MOD)) % MOD

X,Y = map(int,input().split())

if (X+Y) % 3 != 0:
  print(0)
  exit()

n = (-X+2*Y) // 3
m = (2*X-Y) // 3

if n<0 or m<0:
  print(0)
else:
  print(nCr(n+m, n))

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector< vector<char> > a(H, vector<char> (W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<=W+1;i++) cout << "#";
    cout << endl;
    for(int i=0;i<H;i++){
        cout << "#" ;
        for(int j=0;j<W;j++){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }
    for(int i=0;i<=W+1;i++) cout <<"#";
    cout << endl;
    return 0;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 2000010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-9
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, cnt, k, ans;
const ll mod = 1e9 + 7;

ll pre[SIZE], inv[SIZE];
ll qpow(ll a, ll b, ll mod) { //快速幂 a ^ b % mod
	ll ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}

void init(int n) { // 预处理阶乘和阶乘逆元
	pre[0] = pre[1] = 1;
	rep(i, 2, n) pre[i] = 1ll * i * pre[i - 1] % mod;
	inv[n] = qpow(pre[n], mod - 2ll, mod) % mod; inv[0] = 1;
	for (ll i = n; i; --i) inv[i - 1] = inv[i] * i % mod;
}

ll C(ll n, ll m) { // 求组合数 nCm
	return pre[n] * inv[n - m] % mod * inv[m] % mod;
}
int main() {
	init(1000000);
	//cout << C(10, 5) << ' ' << C(8, 4) << ' ' << C(12, 6) << ' ';
	io(); cin >> n >> k;
	if (k == 0) { cout << 1; return 0; }
	if (k == 1) { cout << n * (n - 1) % mod; return 0; }
	ll ans = 0;
	if (k >= n) k = n;
	rep(i, 0, k) {
		ans += C(n, n - i) * C(n - 1, n - i - 1) % mod;
		ans %= mod;
	}
	cout << ans;
	/*ll xx[100] = { 0,0,1,4,4 };
	do {
		cnt++;
	} while (next_permutation(xx, xx + 5));
	cout << cnt;*/
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, a2, a3, sum;
  cin >> a;
  a2 = a * a;
  a3 = a * a * a;
  sum = a + a2 + a3;
  cout << sum << endl;
  
  return 0;
}

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

int get_sum(char* str){
  int sum = 0,i;
  for(i = 0; str[i] != '\0'; i++){
    sum += str[i] - '0';
  }
  return sum;
}

int main(){
  int sum;
  char c[1000];
  while(1){
      sum = 0;
      scanf("%s",c);
      if(!strcmp(c,"0"))break;
      printf("%d\n",get_sum(c));
  }
  return 0;
}

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

int main(){
	int n ; cin >> n ;
	vector<long long> fac(n+1,1) ;
	long long mod = 1000000007 ;
	for(int i=1;i<=n;i++){
		fac.at(i) = fac.at(i-1)*i%mod ;
	}
	cout << fac.at(n) << endl ;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
A = list(map(int, input().split()))
A = [a - 1 for a in A]
visited = [0] * n

i = 0
lp = 0
step = []
while visited[i] == 0:
  visited[i] = 1
  step.append(i)
  next_visit = A[i] 
  lp += 1
  if lp == k:
    print(next_visit + 1)
    exit()
  i = next_visit

lp_start = step.index(i)
syuki = lp - lp_start

if lp_start > k:
  ans = step[k]
else:
  cnt = (k - lp_start) % syuki
  ans = step[lp_start:][cnt] + 1

print(ans)


Measured memory_bytes: 32372
import bisect
N, M = map(int, input().split())
A = [0]*M
for i in range(M):
  A[i] = int(input())

def index(a, x):
  i = bisect.bisect_left(a, x)
  if i != len(a) and a[i] == x:
    return i
  else:
    return -1

def dp(a,n):
  if n==N:
    return 1
  if n>N:
    return 0
  if index(a,n)!=-1:
    return 0
  else:
    return (DP[n+1]+DP[n+2])%(10**9+7)
    
DP=[0]*(N+3)

for i in range(N+2,-1,-1):
  DP[i]=dp(A,i)

ans=DP[0]
print(ans)

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

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

	int ints[8] = { 0,1,1,1,1,1,1,1 };
	for (int i = 1; i < 8; i++) {
		for (int j = 1; j <= i; j++) {
			ints[i] *= j;
			
		}
	}

	int ps[8];
	int qs[8];
	for (int i = 0; i < n; i++) {
		cin >> ps[i];
		
	}
	for (int i = 0; i < n; i++) {
		cin >> qs[i];
		
	}
	
	int used[9] = {};
	int used_cnt = 0;
	int p = 1, q = 1;

	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j < ps[i]; j++) {
			used_cnt += used[j];
		}
		p += (ps[i] - 1 - used_cnt) * ints[n - i - 1];
		used[ps[i]] = 1;
		used_cnt = 0;
	}
	
	for (int i = 0; i < 9; i++) {
		used[i] = 0;
	}

	

	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j < qs[i]; j++) {
			used_cnt += used[j];
		}
		q += (qs[i] - 1 - used_cnt) * ints[n - i - 1];
		used[qs[i]] = 1;
		used_cnt = 0;
	}

	int result = p - q;
	if (result < 0) {
		result = -result;
	}


	cout << result << "\n";

	return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
divisors_m = list(reversed(sorted(make_divisors(m))))
D = list(filter(lambda x:x <= m/n, divisors_m))
print(max(D))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

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

int main() {
	string s, str[4] = {"dream", "dreamer", "erase", "eraser"};
	
	cin >> s;
	
	REP(i, 4) reverse(str[i].begin(), str[i].end());
	reverse(s.begin(), s.end());
	
	int pos = 0;
	while (true) {
		bool flag = true;
		
		REP(i, 4) {
			if (s.substr(pos, str[i].size()) == str[i]) {
				pos += str[i].size();
				flag = false;
			}
		}
		
		if (flag) break;
	}
	
	if (pos == s.size()) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  char now = s[0];
  for(int i = 1; i < s.size(); ++i){
    if (now != s[i]){
      cnt++;
    }
    now = s[i];
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 512
import heapq

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

nums = list(map(lambda x: -1*x, nums))

heapq.heapify(nums)

for _ in range(M):
    tmp = heapq.heappop(nums)
    heapq.heappush(nums, (-1)*(-tmp//2))

print(sum(list(map(lambda x: -1*x, nums))))

Measured memory_bytes: 79596
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=200005;
int f[N+1],inf[N+1];
int C(int n,int r)
{
    if(n<0)
        return 0;
    if(n==r)
        return 1;
    if(r==0)
        return 1;
    if(n<r)
        return 0;
    int ans=f[n];
    ans=(ans*inf[r])%hell;
    ans=(ans*inf[n-r])%hell;
    return ans;
}
void solve()
{
    
    f[0]=1;
    for(int i=1;i<=N;i++)
        f[i]=(i*(f[i-1]))%hell;
    inf[N]=power(f[N],hell-2,hell);
    for(int i=N-1;i>=0;i--)
        inf[i]=((i+1)*inf[i+1])%hell;
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=0;i<=min(n-1,k);i++)
    {
        int x=C(n,i);
        x=(x*C(n-1,n-i-1))%hell;
        ans=(ans+x)%hell;
    }
    cout<<ans<<endl;
    
}

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


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

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

    int a,b,c;
    // 引数の受け取り
    //
    cin >> a >> b >> c;
    

    cout << (a+b+c-max(max(a,b),c)) << endl;

    // 出力
    return 0;
}



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

using namespace std;

int n;
double v[3010];
double dp[3010][3010];

int main() {
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> v[i];
    
    
    for (int i = n / 2 + 1; i <= n; ++i)
        dp[n][i] = 1.0;

    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j <= n; ++j) {
            dp[i][j] += dp[i + 1][j + 1] * v[i];
            dp[i][j] += dp[i + 1][j] * (1 - v[i]);
        }
    }
    
    printf("%.15lf\n", dp[0][0]);
    return 0;
}


Measured memory_bytes: 70784
# D - Wide Flip
# coding: utf-8

N = raw_input()

if len(N)%2 == 0:
  result = len(N)/2
  center_pos = len(N)/2  
  center = N[center_pos]
  for i in range(len(N)/2):
    if N[center_pos+i] != center or N[center_pos-(i+1)] != center : break
    result += 1
else:
  result = (len(N)+1)/2
  center_pos = (len(N)-1)/2
  center = N[center_pos]
  for i in range((len(N)-1)/2):
    if N[center_pos+(i+1)] != center or N[center_pos-(i+1)] != center : break
    result += 1

print result

Measured memory_bytes: 4228
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
  int a,b;
  cin>>a>>b;
  b*=2;

  if(a>b){
    cout<<a-b<<endl;
  }
  else{
    cout<<0<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int INF = 1e9 + 5;

int main()
{
    int n, overall;
    vector <int> costs;
    overall = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int step;
        cin >> step;
        costs.push_back(step);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
        for (int j : {i + 1, i + 2})
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(costs[i] - costs[j]));
    printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 1144
#include <iostream>
#include <stack>

int main()
{

    std::stack<int> hoge;
    std::string word;
    
    while(std::cin >> word)
    {
        
        if (word == "+") {
            //std::cout << word << std::endl;
            int number_1, number_2;
            number_1 = hoge.top();
            hoge.pop();
            number_2 = hoge.top();
            hoge.pop();
            hoge.push(number_1 + number_2);
        } else if (word == "-") {
            //std::cout << word << std::endl;
            int number_1, number_2;
            number_1 = hoge.top();
            hoge.pop();
            number_2 = hoge.top();
            hoge.pop();
            hoge.push(number_2 - number_1);
            
        } else if (word == "*") {
            //std::cout << word << std::endl;
            int number_1, number_2;
            number_1 = hoge.top();
            hoge.pop();
            number_2 = hoge.top();
            hoge.pop();
            hoge.push(number_1 * number_2);

        } else {

            //std::cout << word << std::endl;
            hoge.push(std::stoi(word));
        }
    
    }
    
    std::cout << hoge.top() << std::endl;
    return 0;
    
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Graph g;
vector<bool> visited;
vector<int> v;
int solve(int now, int sum) {
  int res = 0;
  visited[now] = 1;
  // cout << string(nest,' ');
  // printf("%d %d\n", now,modoru);
  REP(i,g[now].size()) {
    int d = g[now][i].dst;
    if (!visited[d] && g[d].size() > 1) {
      res += g[now][i].weight + solve(d, sum + g[now][i].weight);
    } else if (!visited[d] && g[d].size() == 1) {
      v.push_back(sum);
    }
  }
  // cout << res << endl;
  return res;
}

int main() {
  int n;
  while(cin >> n,n) {
    g = Graph(n);
    visited.assign(n,0);
    REP(i,n-1) {
      int a,b,c;
      cin >> a>>b>>c;
      a--;b--;
      g[a].push_back(Edge(a,b,c));
      g[b].push_back(Edge(b,a,c));
    }
    v.clear();
    int res = solve(0,0)*2;
    sort(ALL(v),greater<int>());
    // FOR(it,v)
    //   cout <<*it << " ";

    cout << res - v[0] << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int sum1,sum2;
    sum1=sum2=0;
    int a,b,c;
    while(cin>>a>>b>>c)
    {
        if(a==5)
            ++sum1;
        else if(a==7)
            ++sum2;
        if(b==5)
            ++sum1;
        else if(b==7)
            ++sum2;
        if(c==5)
            ++sum1;
        else if(c==7)
            ++sum2;
        if(sum1==2&&sum2==1)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256