akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int A, B, H, M;
	cin >> A >> B >> H >> M;
	double L = 0.5, S = 6;
	int minute = 60 * H + M;
	double angle = (L - S) * minute;
	double radian = (angle * 3.14159265358979) / 180;
	double X = A * A + B * B - 2 * A * B * cos(radian);
	double answer = sqrt(X);
	cout << fixed << setprecision(30) << answer << endl;
}

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

typedef long long ll;

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

    int cnt = 0;
    string s;
    cin >> s;
    for(int i=0;i<4;i++){
        if(s[i]=='2') cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
 
void solve()
{
  vector<int> v[10000];
	int n, x, y;
	cin >> n >> x >> y;
	
	for(int i = 1; i < n; i++){
		v[i].pb(i+1);
		v[i+1].pb(i);
	}
	v[x].pb(y);
	v[y].pb(x);
	
	map<int,int> m;
	
	for(int i = 1; i <= n; i++){
		queue<int> q;
		q.push(i);
		int dis[n+1];
		for(int j = 1; j <= n; j++)
			dis[j] = 1e9;
		dis[i] = 0;
		while(!q.empty()){
			auto p = q.front();
			q.pop();
			for(auto x : v[p]){
				if(dis[x] == 1e9){
					dis[x] = dis[p] + 1;
					q.push(x);
				}
			}
		}
		for(int j = i+1; j <= n; j++){
			if(dis[j] != 1e9){
				m[dis[j]]++;
			}
		}
	}
	for(int i = 1; i <= n-1; i++)
		cout << m[i] << endl;
  return ;
}

signed main()
{
   FAST;
	int T=1;
	// cin >> T;
	while(T--)
	{
		solve();
	}
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.util.function.*;

public class Main{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        long N = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        if(a+b==0) {
            out.println(0);
            out.flush();
            return;
        }
        long x = N / (a+b);
        long r = N % (a+b);
        long res = a * x + Math.min(a, r);




        out.println(res);
        out.flush();
    }

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define INF 100100100
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  vector<int> a(n), copy(n);
  rep(i,n){
  	cin >> a[i];
  	copy[i] = a[i];
  }

  sort(copy.begin(), copy.end(), greater<int>());
  rep(i,n){
  	if(a[i] == copy[0]) cout << copy[1] << endl;
  	else cout << copy[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

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

#define pb push_back
#define fr first
#define sc second

const int p[22] = { 2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,3,9,15,21,5,7 };
//const int q[4] = { 13,14,15,16 };

int main(){
	int N;
	ll a[102] = {};
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; i ++){
		scanf("%lld",&a[i]);
	}
	for(int i = N/2+1 ; i <= N ; i ++){
		a[i] = max( a[i] , 0LL );
	}
	
	ll ret = 0;
	for(int s = 0 ; s < (1<<20) ; s ++){
		ll A[102];
		for(int i = 1 ; i <= N ; i ++){
			A[i] = a[i];
		}
		for(int i = 0 ; i < 20 ; i ++){
			if((s>>i)&1){
				for(int j = p[i] ; j <= N ; j += p[i]){
					A[j] = 0;
				}
			}
		}
		
		for(int i = N/2 ; i >= 1 ; i --){
			ll sum = 0;
			for(int j = i ; j <= N ; j += i){
				sum += A[j];
			}
			if(i == 1){
				ret = max( ret , sum );
				break;
			}
			if(sum < 0){
				for(int j = i ; j <= N ; j += i){
					A[j] = 0;
				}
			}
			/*for(int j = 0 ; j < 2 ; j ++){
				if(i == 2*q[j]){
					sum = A[2*q[j]]+A[3*q[j]]+A[6*q[j]];
					if(sum < 0){
						A[2*q[j]] = 0;
						A[3*q[j]] = 0;
						A[6*q[j]] = 0;
					}
				}
			}*/
		}
		
		
	}
	cout << ret << endl;
}



Measured memory_bytes: 384
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()

Rc = Lc = sc
Uc = Dc = sr

for i in range(N):
  if   S[i] == "L":
    Lc -= 1
  elif S[i] == "R":
    Rc += 1
  elif S[i] == "U":
    Uc -= 1
  elif S[i] == "D":
    Dc += 1
  
  if Lc < 1 or W < Rc or Uc < 1 or H < Dc:
    print("NO")
    break

  if   T[i] == "L" and 1 < Rc:
    Rc -= 1
  elif T[i] == "R" and Lc < W:
    Lc += 1
  elif T[i] == "U" and 1 < Dc:
    Dc -= 1
  elif T[i] == "D" and Uc < H:
    Uc += 1
else:
  print("YES")

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

int GCD(int x, int y) {
    return x ? GCD(y % x, x) : y;
}
int main()
{
  int N,M;
  cin >> N;
  vector<int> vec(N);
  vector<int> head(N);
  vector<int> tail(N); 
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  head.at(0) = vec.at(0);
  tail.at(N-1) = vec.at(N-1);
  for (int i = 1; i < N; i++) {
    head.at(i) = GCD(head.at(i-1) , vec.at(i));
    tail.at(N-i-1) = GCD(tail.at(N-i) , vec.at(N-i-1));
  }  
  
  M = max(head.at(N-2),tail.at(1));
  for (int i = 1; i < N-1; i++) {
    M = max(M , GCD(head.at(i-1),tail.at(i+1)));
  }    
  cout << M << endl;
}

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

typedef long long ll;

ll n;
vector<int> g[200005];
int c[200005];
int sz[200005];
ll cnt[200005],tot;
ll ans[200005];

int dfs(int x,int p){
    sz[x]=1;
    int &col=c[x];
    ll tmp=cnt[col];
    for(int &y:g[x])if(y!=p){
        ll pre=tot-cnt[col];
        sz[x]+=dfs(y,x);
        ll cur=tot-cnt[col]-pre;
        ans[col]+=cur*(cur-1)/2;
    }
    cnt[col]=tmp+sz[x];
    tot++;
    return sz[x];
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>c[i];ans[c[i]]--;
    }
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        ans[i]+=(n-cnt[i])*(n-cnt[i]-1)/2;
        cout<<n*(n-1)/2-ans[i]<<'\n';
    }

    return 0;
}

Measured memory_bytes: 37900
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    int k = sc.nextInt();
    int turn = 0;
    while (k-- > 0) {
      if (turn == 0) {
        a /= 2;
        b += a;
      } else {
        b /= 2;
        a += b;
      }
      turn = 1 - turn;
    }
    System.out.println(String.format("%d %d", a, b));
  }
}

Measured memory_bytes: 34164
s[2],r,c,i;
main(n){
	for(;scanf("%d",&n)*n;){
		int d[4]={1,2,3},a=1;
		for(;n--;){
			scanf("%s",s);
			r=*s%8%6;
			for(i=4;i--;){
				// NNNNWWWWRRRRSSSSLLLLEEEE
				c="302131020312302103123102"[r*4+i]-'0';
				d[i]=c-r/2?d[c]:7-d[c];
			}
			a+=*d;
		}
		printf("%d\n",a);
	}
}

Measured memory_bytes: 0
#include<stdio.h>
int main() {
 
	int a;
	int b;
	int res = -1000;
 
	scanf("%d", &a);
	scanf("%d", &b);
 
	if (a + b > res) res = a + b;
	if (a - b > res) res = a - b;
	if (a * b > res) res = a * b;
 
	printf("%d", res);
 
	return 0;
}

Measured memory_bytes: 128
//include thu vien
#include  <iostream>

using namespace std;
	int  main()
{
   int a[3];
 cin >>a[0]>>a[1]>>a[2];
 for (int i = 0 ; i<2;i++)
   for(int j = 1;j<3;j++)
   {
     if(a[i] > a[j]){
      int temp = a[i]; a[i]=a[j];a[j]=temp;}
    }
 cout <<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
 return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;

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

	ll n, m;
	cin >> n >> m;
	ll even = (m + 1) / 2;
	REP(i, even) cout << i + 1 << " " << even * 2 - i << "\n";
	REP(i, m - even) cout << even * 2 + 1 + i << " " << m * 2 + 1 - i << "\n";

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

int SumOfDigits(int x){
  int sum=0;
  while(x>0){
    sum+=x%10;
    x/=10;
  }
  return sum;
}


int  main(){
  int N,ans=100000;
  cin>>N;
  for(int i=1;i<=N/2;i++){
    ans=min(ans,SumOfDigits(i)+SumOfDigits(N-i));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def II(): return int(input())
N=II()
N-=1
i=1
ans=''
while N-26**i>=0:
  N-=26**i
  i+=1
for j in range(i):
  div,mod=divmod(N,26)
  ans+=chr(mod+ord('a'))
  N=div
ans=ans[::-1]
print(ans)

Measured memory_bytes: 9196
//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
#include <set>
//#include <string.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int n=0,m=0;
    cin >> n>>m;
    vector<double> A;
    double sum=0;
    rep(i,n){
        int a;
        cin >> a;
        A.push_back(a);
        sum +=a;
    }
    
    double th = sum /(4*m);

    sort(A.begin(),A.end());
    
    if(A.at(n-m)<th)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
        
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int a, b, h, m;
	scanf("%d %d %d %d",&a,&b,&h,&m);
	double d1, d2;
	d1 = h * 1.0 / 12*360.0;
	d2 = m * 1.0 / 60*360.0;
	d1 += m*30.0 / 60;
	double d = abs(d1 - d2);
	if (d>180.0) {
		d = 360.0 - d;
	}
	//cout << cos(d / 2 /) << endl;
	double ans= sqrt(a * a + b * b - 2 * a * b * cos(d*(PI/180.0)));
	printf("%.10lf\n",ans);
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)


int main(void) {
	string s; cin >> s;
	int k; cin >> k;
	vector<string> v;
	rep(i, s.size()) {
		reps(j, 1, min((int)s.size() - i + 1, 6)) {
			v.push_back(s.substr(i, j));
			// cout << s.substr(i, j) << endl;
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	cout << v[k - 1] << endl;
	return 0;
}

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

int N, A[200];

int main()
{
  int dmin = 100;
  cin >> N;
  for(int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    int d = 0;
    while(A % 2 == 0) {
      A /= 2;
      ++d;
    }
    dmin = min(dmin, d);
  }
  cout << dmin << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
l = [0]*m
r = [0]*m
for i in range(m):
    t1,t2 = map(int,input().split())
    l[i] = t1
    r[i] = t2

if min(r)-max(l) < 0:
    print(0)
else:
    print(min(r)-max(l)+1)

Measured memory_bytes: 47636
#include<iostream>
#include<vector>
#include<cstring>

using namespace std;

int main(){
    int N;
    int sum = 0;
    vector<int> d;
    scanf("%d", &N);
    d.resize(N);
    for(int i = 0; i < N; i++){
        int a;
        scanf("%d", &a);
        d[i] = a;
    }

    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            sum+=(d[i]*d[j]);
        }
    }

    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 256
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
LL dp[3005][3005];
void solve()
{
     int n;cin>>n;
     LL a[n];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     for(int l=n-1;l>=0;l--)
     {
         for(int r=l;r<n;r++)
         {
             if(l==r)
             {
                 dp[l][r] = a[l];
             }
             else
             {
                 dp[l][r] = max(a[l] - dp[l+1][r] , a[r] - dp[l][r-1]);
             }
             
         }
     }
     cout<<dp[0][n-1]<<endl;
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

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

int64_t xy2id(int64_t x, int64_t y){
    return x*1000000 + y;
}

int group[100000];
vector<pair<int,int>> inx[100000], iny[100000];
vector<pair<int,int>> pts;
bool checked[100000];
unordered_set<int> xs[100000], ys[100000];
int g_cnt[100000];

int main(){    
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        pts.emplace_back(x,y);
        inx[x].emplace_back(y,i);
        iny[y].emplace_back(x,i);
    }

    int g = 0;

    for(int i=0;i<n;i++){
        if(group[i] == 0){
            g++;
            queue<int> q;
            for(int k=0;k<n;k++) checked[k] = false;
            q.push(i);
            checked[i] = true;
            group[i] = g;

            while(!q.empty()){
                int t = q.front();
                q.pop();
                int xx = pts[t].first;
                int yy = pts[t].second;
                for(auto p : inx[xx]){
                    int yyy = p.first;
                    int idx = p.second;
                    if(checked[idx] || yyy==yy) continue;
                    q.push(idx);
                    checked[idx] = true;
                    group[idx] = g;
                }
                for(auto p : iny[yy]){
                    int xxx = p.first;
                    int idx = p.second;
                    if(checked[idx] || xxx==xx) continue;
                    q.push(idx);
                    checked[idx] = true;
                    group[idx] = g;
                }                
            }
        }
    }

    for(int i=0;i<n;i++){
        xs[group[i]-1].insert(pts[i].first);
        ys[group[i]-1].insert(pts[i].second);
        g_cnt[group[i]-1]++;
    }

    int64_t ans = 0;
    for(int i=0;i<g;i++){
        if(xs[i].size()<=1 || ys[i].size()<=1) continue;
        ans += xs[i].size() * ys[i].size() - g_cnt[i];
    }

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

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

int main(){
    int A,B,ans;
    ans=0;
    cin>>A>>B;

    for(int i=0;i<=B-A;i++){
        if((A+i)/10000==(A+i)%10 && (A+i)/1000%10==(A+i)/10%10)ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
from heapq import *
n, m = map(int,input().split())
a = map(int,input().split())
q = []
for i in a:
  heappush(q,-i)
#print(q)
for j in range(m):
  temp = -heappop(q)
  temp //= 2
  heappush(q,-temp)
  #print(q)
print(-(sum(q)))

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
ll P = 1000000007;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll m;
  string s;
  cin >> m >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  ll base = 1;
  vector<ll> vs(10);
  for (int i = 0; i < n; i++) {
    vs[s[i] - '0'] += base;
    vs[s[i] - '0'] %= P;
    base = (base * 10) % P;
  }
  char first = s.back();
  vector<ll> per({
                     0, 1, 2, 3, 4, 5, 6, 7, 8, 9
                 });
  do {
    if (per[first - '0'] == 0 && n > 1) continue;
    ll mod = 0;
    for (int i = 0; i < 10; i++) {
      mod += (per[i] * vs[i]) % P;
      mod %= P;
    }
    if (mod == m) {
      for (int j = 0; j < n; j++) {
        cout << per[s[n - j - 1] - '0'];
      }
      cout << endl;
      return 0;
    }
  } while (next_permutation(per.begin(), per.end()));
  cout << -1 << endl;
  return 0;
}



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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (b <= 1)
    {
        cout << 0 << endl;
        exit(0);
    }
    int now = 1;
    int ans = 0;
    while (now < b)
    {
        ans += 1;
        now -= 1;
        now += a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int d[300000];
#define rd(a,b)(a>b?n-a+b:b-a)
#define ld(a,b)(rd(b,a))
int main() {
	int n, m, p; scanf("%d%d%d", &n, &m, &p);
	rep(i, m)scanf("%d", &d[i]);
	sort(d, d + m);
	int a = (upper_bound(d, d + m, p) - d + m - 1) % m;
	int b = lower_bound(d, d + m, p) - d;
	int Min = min(rd(p, d[a]), ld(p, d[b]));
	rep(i, m) {
		Min = min(Min, rd(p, d[i]) + ld(d[i], d[(i + 1) % m]));
		Min = min(Min, ld(p, d[i]) + rd(d[i], d[(i + m - 1) % m]));
	}
	printf("%d\n", Min * 100);
}

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

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

    sort(p, p+n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i != n-1)
            ans += p[i];
        else
            ans += p[i]/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll solve(ll x){
    ll ans=0;
    for(int i=1;i<=10;i++){
        ll n=x*i;
        ans+=(x%10);
    }
    return ans;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll A[n+1];
    for(int i=0;i<n;i++)cin>>A[i];
    vector<ll>v(n,INT_MAX);
    v[0]=0;
    for(int i=0;i<n;i++){
        for(int j:{i+1,i+2}){
            if(j<n){
                v[j]=min(v[j],v[i]+abs(A[j]-A[i]));
            }
        }
    }
    cout<<v[n-1];
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int r, D, x;
    cin >> r >> D >> x;
    rep(i, 0, 10) {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int c1=0, c2=0, c3=0;
	for(int i=0; i<n; i++){
		int p;
		cin >> p;
		if(p<=a) c1++;
		else if(p<=b) c2++;
		else c3++;
	}
	cout << min({c1,c2,c3}) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> pre(n+1);
    rep(i,n)pre[i+1] = max(a[i],pre[i]);
    int ret = 0;
    rep(i,n)ret += pre[i] <= a[i];
    cout << ret  << endl;

    return 0;
}

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

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

int main()
{
	int a,b;cin>>a>>b;
	if(a+b==15) cout<<'+';
	else if(a*b==15) cout<<'*';
	else cout<<'x';
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i=0, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL
    //int A[n];
    //scan(n);
    cin>>x;

    while(true)
    {
        i++;
        A.insert(x);
        if(i>A.sz)
        {
            cout<<i<<endl;
            return 0;
        }
        if(x%2==0)
        {
            x/=2;

        }
        else
        {
            x=(3*x+1);
        }

    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  n, a=0, b=0;
  cin >> n ;
  
  
  if(n%2 == 0){
    a  = n/2;
  }else{
    a = (n/2) + 1;
  }
  
  cout << a <<endl;
}


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

int main(){
    using namespace std;
    unsigned long a, b, c;
    cin >> a >> b >> c;
    unsigned long k{4 * a * b}, l{c - a - b};
    puts(a + b < c && k < l * l ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())

x = c/b
y = a/d

if x > int(x):
    x+=1
    x=int(x)
if y > int(y):
    y+=1
    y=int(y)

if x <= y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, T; cin >> A >> B >> T;
    cout << T / A * B << endl;
    return 0;
}


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


float distance(vector<int> a, vector<int> b, int d) {
    float res = 0.0;
    for (size_t i=0; i<d; i++) {
        res += (a[i] - b[i]) * (a[i] - b[i]);
    }
    // cout << "dist: " << res << endl;
    return sqrt(res);
}

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> points(n, vector<int>(d,0));
    for (int i=0; i<n; i++) {
        for (int j=0; j<d; j++) {
            cin >> points[i][j];
        }
    }
    float dist = 0.0;
    int cnt = 0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            // cout << i << j << endl;
            dist = distance(points[i], points[j], d);
            // cout << dist;
            if (floor(dist) == dist) cnt++;
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>

int main(int argc, char const *argv[]) {

  int S,a,b;

  scanf("%d\n",&S );
  a = S/100;
  b = S%100;

  if(a==0 && b == 0){
    printf("NA");
  }else if(a==00 && (b>=1 && b<=12)){
    printf("YYMM");
  }else if(a==00 && (b>=13 && b<=99)){
    printf("NA");
  }else if( (a>=1 && a<=12) && (b==0)){
    printf("MMYY");
  }else if( (a>=1 && a<=12) && (b>=1 && b<=12)){
    printf("AMBIGUOUS");
  }else if( (a>=1 && a<=12) && (b>=13 && b<=99)){
    printf("MMYY");
  }else if( (a>=13 && a<=99) && (b==0)){
    printf("NA");
  }else if( (a>=13 && a<=99) && (b>=1 && b<=12)){
    printf("YYMM");
  }else if( (a>=13 && a<=99) && (b>=13 && b<=99)){
    printf("NA");
  }

  return 0;
}


Measured memory_bytes: 128
# coding: utf-8
# Your code here!
num = []
num = input().split(" ")
#print(num)

for i in range(5):
    if i != 4:
        if int(num[i]) == 0:
            print(int(num[i+1])-1)
    elif int(num[4]) == 0:
        print(int(num[i-1])+1)

Measured memory_bytes: 9180
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    s = 0
    for i in range(N):
        s ^= a[i]

    if s != 0:
        print('No')
        return

    if N%3 == 0:
        d = {}
        for i in range(N):
            if not a[i] in d:
                d[a[i]] = 0
            d[a[i]] += 1

        if (len(d) == 1 and 0 in d) or (2 <= len(d) <= 3 and all(v%(N//3) == 0 for v in d.values())):
            print('Yes')
        else:
            print('No')

    else:
        if all(a[i] == 0 for i in range(N)):
            print('Yes')
        else:
            print('No')



if __name__ == '__main__':
    main()

Measured memory_bytes: 20972
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long ans=0;
    for ( int i=1;i<=n;i++)
	{
        if (i%3!=0&&i%5!=0) 
        { 
	        ans+=i;
        }
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main() {
	int i = 3, x = 0, y = 0;
	char ch;
	while(i--) {
		cin >> ch;
		if(ch =='A') ++x;
		else ++y;
	}
	if((x > 1 && y > 0) || (y > 1 && x > 0)) {
		cout << "Yes" << endl;
	} else cout << "No" << endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {//とりあえずbitで最小値求める
		try(Scanner sc = new Scanner(System.in)){
			int n=sc.nextInt();//蔵の数
			double[][] dist=new double[n][n];//蔵間の距離
			double[] d=new double[n];//城からの距離
			int[] v=new int[n];//千両箱の数
			int[] s=new int[n+1];
			double[][] dp=new double[1<<n][n];
			int[][] p=new int[1<<n][n];
			int[] ws=new int[1<<n];
			int INF=1<<28;
			double eps=1e-9;
		
			for(int i=0; i<n; i++) {
				s[i]=sc.nextInt();//蔵番号
				d[i]=sc.nextDouble();//城からの距離
				v[i]=sc.nextInt();//蔵にある千両箱の数
			}
			
			for(int i=0; i<(1<<n); i++) {
				for(int j=0; j<n; j++) {
					ws[i|(1<<j)]=ws[i]+20*v[j];
					if(i!=0)dp[i][j]=INF;
				}
			}
			
			for(int i=0; i<n; i++) {
				for(int j=i+1; j<n; j++) {
					dist[i][j]=Math.abs(d[i]-d[j]);
					dist[j][i]=Math.abs(d[i]-d[j]);
				}
			}
			
			for(int i=0; i<(1<<n); i++) {
				for(int j=0; j<n; j++) {//現在いる頂点j
					//System.out.println("j="+j);
					for(int k=0; k<n; k++) {//次の行き先頂点k
						//System.out.println("k="+k);
						if((1&i>>k)==1) continue;//すでに訪れてるとき
						int nexti = i| (1<<k);//bitごとのOR演算(今まで通ってきた頂点に次の頂点を足せる) 
						//System.out.println("nexti="+nexti);
						double nextd=dp[i][j]+(dist[j][k]*(70.0+ws[i])/2000.0);
						//System.out.println("nextd="+nextd);
						if(nextd+eps<dp[nexti][k]) {
							dp[nexti][k]=nextd;
							p[nexti][k]=j;
						}
					}
				}
			}
			
			int m=0;
			int all=(1<<n)-1;//最後の全部bitたっている状態
			for(int i=0; i<n; i++) {
				//System.out.println(dp[all][i]);
				if(dp[all][i]+eps<dp[all][m]) {
					m=i;//all状態でdp値が一番小さいものを探している→一番最後に訪れたところ
				}
			}
			//int sup=all;
			ArrayList<Integer> list=new ArrayList<Integer>();
			for(int k=m, sup=all; sup!=0;) {//後ろから前へ逆戻りのイメージ
				//System.out.println(i+" "+sup);
				list.add(k);
				int j=p[sup][k];//状態がsupになるkを訪れる前の頂点j
				//System.out.println(j);
				sup&=~(1<<k);//訪問状態から訪問前の状態にしてる
				k=j;
			}
			for(int i=0; i<list.size(); i++) {
				System.out.print(s[list.get(list.size()-1-i)]+(i==list.size()-1?"\n":" "));
			}

		}
	}
}


Measured memory_bytes: 35620
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO Auto-generated method stub

    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    long K = sc.nextLong();
    
    for(int i = 0; i < K; i++){
      if(S.charAt(i) != '1'){
        System.out.println(S.charAt(i));
        break;
      }
      else if(i == K-1){
        System.out.println("1"); 
      }
    }  
  }
}


Measured memory_bytes: 26892
import itertools

s = input()
n = len(s)

ans = 0
for v in itertools.product([0, 1], repeat=n-1):
    lst = list(v)
    idx = 0
    for i in range(n-1):
        if lst[i] == 1:
            ans += int(s[idx:i+1])
            idx = i + 1
    ans += int(s[idx:])
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;


const int MAX =	1000000	* 2;

ll solve(const ll N, ll P) {
  ll ans = 1LL;
  vector<int> prime(MAX,1);
  vector<ll> ps;
  prime[0] = prime[1] = 0;
  for(int i = 2; i < MAX; i++) {
    if(prime[i]) {
      ps.push_back(i);
      for(int j = i+i; j < MAX; j+=i)
        prime[j] = 0;
    }
  }
  REP(i, ps.size()) {
    if(ps[i] > P) break;
    ll cnt = 0;
    while(P % ps[i] == 0) {
      cnt++;
      P /= ps[i];
    }
    if(cnt >= N) {
      REP(j,(int)(cnt/N)) ans *= ps[i];
    }
  }
  if(N==1) ans *= P;
  return ans;
}

int main() {
  ll N, P; cin>>N>>P;
  ll ans = solve(N, P);
  cout << ans << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    int output = 0;
    for (int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    for (int i=1; i<n-1; i++){
        if(vec.at(i) < vec.at(i+1) && vec.at(i) > vec.at(i-1)){
            output += 1;
        }
        if(vec.at(i) > vec.at(i+1) && vec.at(i) < vec.at(i-1)){
            output += 1;
        }
    }
    cout << output;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    A = list(map(int,input().split()))

    ans = 0

    while True:
        
        #全列が0ならば探索終了
        if max(A) == 0:
            break
        
        i = 0
        
        #１列 横に調査
        while i < n:
        
            if A[i] == 0:
                #横にずらす
                i += 1
            else:
                #カウント++
                ans += 1

                #最後か0にぶつかるまで,列の値を１マイナスする
                while i < n and A[i] != 0:
                    #1ずつマイナスする
                    A[i] -= 1
                    #横にずらす
                    i += 1
    print(ans)

Measured memory_bytes: 9120
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
#define Array vec<ll>
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll combup(ll n,ll r){
    ll sum=1;
    rrep(i,min(r,n-r)) (sum*=(n-i+1))%=mod;
    return sum;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void solve(){
    
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x,y;
    ll left1=0,right1=0;
    cin>>x>>y;
    ll a=min(x,y),b=max(x,y);
    while(a>0 && b>0){
        if(a>b){
            b-=1;
            a-=2;
            right1++;
        }else if(a<=b){
            b-=2;
            a-=1;
            left1++;
        }
        
        if((a==0 && b!=0) || (a!=0 && b==0)) {
            cout<<0<<endl;
            return 0;
        }
    }
    ll n=(right1+left1);
    COMinit();
    cout<<COM(n,right1)<<endl;
    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n, k;
typedef long double ld;
ld a[maxn];

int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    gbtb;
    cin >> n >> k;
    repd(i, 1, n)
    {
        cin >> a[i];
        a[i] = (a[i] * (a[i] + 1.0)) * 0.5 / (a[i]);
    }
    ld ans = 0;
    repd(i, 1, k)
    {
        ans += a[i];
    }
    ld pre = ans;
    repd(i, k + 1, n)
    {
        pre -= a[i - k];
        pre += a[i];
        ans = max(ans, pre);
    }
    cout << fixed << setprecision(6) << ans << endl;

    return 0;
}




Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  int mx = 0;
  int count = 0;
  rep(i, N - 1)
  {
    if (H[i] >= H[i + 1])
      count++;
    else
      count = 0;

    mx = std::max(mx, count);
  }

  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int flag =1;
    rep(i,n){
        if (a[i] %2 ==0 ) {
            if (!(a[i]%3==0 ||a[i]%5==0))
                flag =0;
        }
    }
    if (flag) cout <<"APPROVED";
    else cout << "DENIED";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll ans;
int main(){
	cin>>s;
	if(s=="SAT") ans=1;
	if(s=="SUN") ans=7;
	if(s=="FRI") ans=2;
	if(s=="THU") ans=3;
	if(s=="WED") ans=4;
	if(s=="TUE") ans=5;
	if(s=="MON") ans=6;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */



int main(){
    ll x, y; cin >> x >> y;
    ll ans = 0;
    for(ll i=x; i <= y; i = i*2){
   
        ans++;
    }
    cout << ans << endl;
    
    
}




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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans1, ans2, ans3, ans4, an1, an2;
  ans1 = ans2 = ans3 = ans4 = an1 = an2 = 1;
  ans1 *= a;
  ans1 *= c;
  ans2 *= a;
  ans2 *= d;
  ans3 *= b;
  ans3 *= c;
  ans4 *= b;
  ans4 *= d;
  an1 = max(ans1, ans2);
  an2 = max(ans3, ans4);
  cout << max(an1, an2) << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int a[25], n, t;

int solve(int i,int sum)
{
	if(i == n)
	{
		return sum == t;
	}
	if(solve(i + 1,sum + a[i]))
	{
		return 1;
	}
	if(solve(i + 1,sum))
	{
		return 1;
	}
}

int main()
{
	int i, q;
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", a + i);
	}
	scanf("%d", &q);
	for(i = 0; i < q; i++)
	{
		scanf("%d", &t);
    	if(solve(0,0))
    	{
    		printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 2040
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    ll N, K;
    cin >> N >> K;

    ll P = K;

    rep(i, N - 1) P *= (K - 1);

    cout << P << endl;

}

Measured memory_bytes: 256