akhauriyash/Code-Regression huggingface dataset:
N, P = map(int,input().split())
A = list(map(int,input().split()))
odd = len(list(filter(lambda x:x%2==1 ,A)))
even = N-odd
if odd == 0:
    if P == 0:print(2**(N))
    else:print(0)
else:
    print(2**(N-1))


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

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

    int ans=0;
    
    for(int i=1;i<=N;i++){
        int x;
        cin>>x;
        if(i!=x) ans++;
    }
    if(ans<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l.append(0)
adjustment = [0] * n
base_money = 0
position = 0
for i in range(n):
    if position > l[i] and l[i] < l[i+1]:
        if position < l[i+1]:
            adjustment[i] = (abs(l[i + 1] - l[i]) -
                             abs(l[i + 1] - position)) * 2
        else:
            adjustment[i] = (abs(l[i] - position) -
                             abs(l[i + 1] - position)) * 2
    elif position < l[i] and l[i] > l[i + 1]:
        if position < l[i+1]:
            adjustment[i] = (abs(l[i] - position) -
                             abs(l[i + 1] - position)) * 2
        else:
            adjustment[i] = (abs(l[i + 1] - l[i]) -
                             abs(l[i + 1] - position)) * 2
    base_money += abs(l[i] - position)
    position = l[i]
base_money += abs(position)
for i in range(n):
    print(base_money - adjustment[i])

Measured memory_bytes: 14036
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/* define*/
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( i = a, i < b ; i++)
#define REP(i, n) for ( i = 0; i < n ; i++)
#define DER(i, n) for ( i = 0; n ; i--)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1e9 + 7;

/* alias */
typedef long long ll;

/* function */
int cmp(const int *a, const int *b) {
	return *a - *b;
}
int cmp2(const int *a, const int *b) {
	return *b - *a;
}

//* main */
int i, j, k;

int main() {
	int n, a, b, c = 0, d = 1, f;
	char s;
	scanf("%d%d%d%*c", &n, &a, &b);
	REP(i, n) {
		f = 0;
		scanf("%c", &s);
		if (s == 'a' && c < a + b) {
			c++;
			f++;
		}
		if (s == 'b' && c < a + b && d <= b) {
			c++;
			d++;
			f++;
		}
		Yes(f);
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main(){
  int n;cin>>n;
  int a[3*n];rep(i,3*n)cin>>a[i];
  sort(a,a+3*n,greater<int>());
  ll ans=0;
  rep(i,n){
    ans+=a[2*i+1];
  }
  cout<<ans<<endl;
}





Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
const int MAXN=10;
int h,w,k;
bool mp[MAXN][MAXN];
int ans=0;
bool check(int x)
{
    int tmp[MAXN][MAXN];
    for(int i=1;i<=h;++i)
    for(int j=1;j<=w;++j) tmp[i][j]=mp[i][j];
    for(int i=0;i<=(h-1);++i)
    if(x&(1<<i))
    for(int j=1;j<=w;++j) tmp[i+1][j]=0;
    for(int i=h;i<=h+w-1;++i)
    if(x&(1<<i))
    for(int j=1;j<=h;++j) tmp[j][i-h+1]=0;
    int sum=0;
    for(int i=1;i<=h;++i)
    for(int j=1;j<=w;++j) sum+=tmp[i][j];
    return sum==k;
}
int main()
{
    cin>>h>>w>>k;
    for(int i=1;i<=h;++i)
    {
        string s;
        cin>>s;
        for(int j=0;j<w;++j)
        if(s[j]=='.') mp[i][j+1]=0;
        else mp[i][j+1]=1;
    }
    for(int i=0;i<=(1<<(h+w))-1;++i)
    if(check(i)) ++ans;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

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

using namespace std;

inline int max(int a, int b) {
	if (b > a) swap(a, b);
	return a;
}

inline int min(int a, int b) {
	if (a > b) swap(a, b);
	return a;
}




int main() {
	int n;
	long long int sum = 0;
	cin >> n;
	vector<long long int> a(n);
	vector<long long int> ans(n, 0);
	rep(i, n) {
		cin >> a[i];
		a[i] *= 2;
		sum += a[i];
		if ((i % 2 == 0) && (i != n - 1)) sum -= 2 * a[i];
	}
	ans[n - 1] = sum / 2;
	for (int i = n - 2; i >= 0; i--) {
		ans[i] = a[i] - ans[i + 1];
	}

	rep(i, n) {
		cout << ans[i] << " ";
	}
	
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    long long maxWeight;
    cin >> n >> maxWeight;
    vector <long long> w(n);
    vector <long long> v(n);
    long long maxValue = 0;
    for(long long i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        maxValue+=v[i];
    }
    vector <vector<long long>> dpvv(n);
    long long ans = 0;
    for(int i = 0; i < n; i++){
        //cout << "i:"<<i<<endl;
        if(i==0){
            dpvv[i]=vector<long long>(maxValue+1,0);
            dpvv[i][v[i]]=w[i];
            if(w[i]<=maxWeight){
                ans=max(ans,(long long)v[i]);
            }
        }else{
            dpvv[i]=dpvv[i-1];
            for(long long j = 0; j <=maxValue; j++){
                if(dpvv[i-1][j]==0){
                    if(j==v[i]){
                        dpvv[i][j]=w[i];
                        if(w[i]<=maxWeight){
                            ans=max(ans,(long long)v[i]);
                        }
                    }
                }else{
                    if(j==v[i]){
                        dpvv[i][j]=min(w[i],dpvv[i-1][j]);
                        if(w[i]<=maxWeight){
                            ans=max(ans,(long long)v[i]);
                        }
                    }
                    //cout << j << endl;
                    long long sumV = j+v[i];
                    //cout << "sumV:" << sumV<<endl;
                    long long sumW = dpvv[i-1][j]+w[i];
                    //cout << "sumW:" << sumW << endl;
                    if(dpvv[i-1][sumV]==0){
                        dpvv[i][sumV]=sumW;
                        if(sumW<=maxWeight){
                            ans=max(ans,sumV);
                        }
                    }else{
                        dpvv[i][sumV]=min(dpvv[i-1][sumV],sumW);
                        if(dpvv[i][sumV]<=maxWeight){
                            ans=max(ans,sumV);
                        }
                    }
                }
            }
        }
        //cout << "ans:"<<ans << endl;
    }
    cout << ans << endl;
}

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

int vsum(vector<int> v){
  int a=0;
  for(int i=0;i<v.size();i++)a+=v[i];
  return a;
}

int check(vector<int> a,vector<int> b,int k){
  int i,c=0;
  for(i=0;i<k;i++)if(a[i]!=b[i]&&a[i]!=0)c=1;
  return c;
}

void kansu(vector<int> &p,vector<int> &c,int &D,int &G,vector<int> N,int n,int sum,int &K){
  if(N[n]==p[n])sum+=c[n];
  if(sum>=G){if(vsum(N)<K)K=vsum(N);return;}
  if(n!=D-1&&!(check(N,p,n)&&N[n]!=p[n]))kansu(p,c,D,G,N,n+1,sum,K);
  if(n==D-1&&N[n]==p[n])return;
  if(N[n]!=p[n]){sum+=(n+1)*100;N[n]++;kansu(p,c,D,G,N,n,sum,K);}
  return;
}
int main(){
  int i,D,G,n=0,sum=0;
  cin>>D>>G;
  vector<int> p(D),c(D),N(D);
  for(i=0;i<D;i++)cin>>p[i]>>c[i];
  int K=vsum(p);
  kansu(p,c,D,G,N,n,sum,K);
  cout<<K<<endl;
}

/*
N[i]!=P[i]の組が二つ現れないようにする！
*/


Measured memory_bytes: 512
#include <stdio.h>

int main (void){
    int A, B, C;
    scanf("%d %d %d", &A,&B,&C);
    if(A==7){
        if(B==5&&C==5){
            printf("YES\n");
        }
        else
            printf("NO\n");
    }
    else if(A==5){
        if(B==7 && C==5){
            printf("YES\n");
        }
        else if(C==7&& B==5){
            printf("YES\n");
        }
        else
            printf("NO\n");
    }
    else
        printf("NO\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
vector<ll> num;
int main() {
  ll a,b,k;
  cin>>a>>b>>k;
  for(int i=a;i<a+k;i++){
    num.push_back(i);
    if(i==b)break;
  }
  for(int i=b-k+1;i<=b;i++){
    if(i<a)continue;
    num.push_back(i);
  }
  sort(num.begin(),num.end());
  num.erase(unique(num.begin(),num.end()),num.end());
  for(int i=0;i<num.size();i++)cout<<num[i]<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    k,s = map(int, stdin.readline().rstrip().split())
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            z = s-i-j
            if 0<=z <= k:
                ans += 1
    print(ans)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 9152
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int i,a,b,s=0;
	cin>>a>>b;
	if(a<=b)
	{
		for(i=1;i<=a;i++)
			s++;
	}
	else
	{
		for(i=1;i<=a-1;i++)
			s++;
	}
	cout<<s;
	
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int main()
{
        for( int i = 1; i <= 9; i++ )
        {
                for( int j = 1; j <= 9; j++ )
                {
                        cout << i << "x" << j << "=" << i*j << endl;
                }
        }
        return 0;
}

Measured memory_bytes: 1116
while True:
    x, op, y = input().split()
    a, b = int(x), int(y)
    if op == '?':
        break
    elif op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(a//b)


Measured memory_bytes: 5600
#include <stdio.h>
#include <ctype.h>
int main(){
    char ch;
    
    while(1){
        scanf("%c",&ch);
        
        if(isupper(ch)!=0){
            ch=tolower(ch);
            printf("%c",ch);
        }
        
        else if(islower(ch)!=0){
            ch=toupper(ch);
            printf("%c",ch);
        }
        
        else printf("%c",ch);  
        
        if(ch =='\n') break;    
    }
    return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,z;
	if(0<=a&&a<=23){
		if(0<=b&&b<=23)
		{
			cin>>a>>b;
			z=a+b;
			int f=z%24;
		    cout<<f;
		}
		else
		{
			cout<<"Error";
		}	
	}
	else
	{
			cout<<"Error";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }
    // 同じ集合に属しているか判定
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    // 集合のサイズを取得
    int size(int x)
    {
        return cnt[find(x)];
    }
};
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    int cnt = 0;
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    rep(i,m){
        UnionFindTree utree(100);
        rep(j,m){
            if(j==i){
                continue;
            }
            utree.unite(a[j],b[j]);
        }
        if(utree.size(1)<n){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	ll N, A, B;
	cin >> N >> A >> B;
	if (A > B) {
		cout << 0 << endl;
		return 0;
	}
	if (N == 1 && A != B) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = B*(N - 1) + A - (A*(N - 1) + B) + 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

typedef vector<pii> vp;
int main(){
	int n,m;
	cin>>n>>m;
	vp yx(n);
	vi y(n),x(n);
	REP(i,n){
		cin>>yx[i].second>>yx[i].first;
		y[i]=yx[i].first;
		x[i]=yx[i].second;
	}
	sort(ALL(y));
	sort(ALL(x));
	vvi sum(n+1,vi(n+1));

	vp y_index,x_index;
	REP(i,n){
		y_index.push_back(make_pair(yx[i].first,i));
		x_index.push_back(make_pair(yx[i].second,i));
	}
	sort(ALL(y_index));
	sort(ALL(x_index));
	vi oldindex_to_newindex(n);
	REP(i,n){
		REP(j,n){
			if(x_index[j].second==y_index[i].second){
				oldindex_to_newindex[x_index[j].second]=j;
			}
		}
	}
	REP(i,n){
		int newindex=oldindex_to_newindex[y_index[i].second];
		sum[i+1][newindex+1]=1;
	}
	FOR(i,1,n+1){
		FOR(j,1,n+1){
			sum[i][j]+=sum[i-1][j];
		}
	}
	FOR(j,1,n+1){
		FOR(i,1,n+1){
			sum[i][j]+=sum[i][j-1];
		}
	}
	
	REP(i,m){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		int xt=upper_bound(ALL(x),x2)-x.begin();
		int yt=upper_bound(ALL(y),y2)-y.begin();
		int xb=lower_bound(ALL(x),x1)-x.begin();
		int yb=lower_bound(ALL(y),y1)-y.begin();
		cout<<sum[yt][xt]-sum[yt][xb]-sum[yb][xt]+sum[yb][xb]<<endl;
	}
	
}

Measured memory_bytes: 99308
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (ll i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
//typedef std::pair<int,int> P;

    ll N,X,A[100010];
    ll ans;
    ll dp[51][51][2501];
    //x枚目まででy枚使ってzの和を作れるか。
    ll DP(int x,int y,int z){
        if(z<0||y<0||x+1<y)return 0;
        if(y==0&&z==0)return 1;
        if(x==0)return dp[x][y][z]=(A[x]==z&&y==1);
        if(dp[x][y][z]!=-1)return dp[x][y][z];
        return dp[x][y][z]=DP(x-1,y,z)+DP(x-1,y-1,z-A[x]);
    }
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>X;
    REP(i,N)cin>>A[i];
    REP(i,N){
        REP(a,51)REP(b,51)REP(c,2501)dp[a][b][c]=-1;
        DEB(DP(N-1,i+1,(i+1)*X))END
        ans+=DP(N-1,i+1,(i+1)*X);
        DEB(DP(N-1,i+1,(i+1)*X))END
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 51456
#include <cstdio>

using namespace std;

char mp[60][60] = {0};
int dx[9] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[9] = {1, -1, 0, 0, 1, -1,-1,  1};

void def(int y, int x){
	mp[y][x] = 0;
	for (int i = 0; i < 8; i++){
		int ty = y + dy[i];
		int tx = x + dx[i];
		if (mp[ty][tx] == '1') def(ty, tx);
	}
}

int main()
{
	int w, h;
	int pi, pj;
	int cnt;
	while (scanf("%d %d", &w, &h), !(w == 0 && h == 0)){
		cnt = 0;
		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				scanf("%s", &mp[i][j]);
			}
		}
		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (mp[i][j] == '1'){
					def(i, j);
					cnt++;
				}
			}
		}
		
		printf("%d\n", cnt);
	}
}

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

int main() {
  int A,B;
  cin >> A >> B;
  string s;
  cin >> s;
  for (int i=0;i<A;i++){
    if ('0' <= s[i] && s[i] <= '9')continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if (s[A] != '-'){
    cout << "No" << endl;
    return 0;
  }
  for (int i=A+1;i<A+B;i++){
    if ('0' <= s[i] && s[i] <= '9')continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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


void solve()
{
    ll t,i,j,n,k;
    vector<ll> a,dp;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>t;
        a.pb(t);
        dp.pb(0);
    }
    //dp.pb(0);
    for(i=1;i<n;i++)
    {
        t=INT_MAX;
        ll lim=0;
        if(i-k>=0)
            lim = (i-k);
        for(j=i-1;j>=lim;j--)
        {
            t=min(t,dp[j]+abs(a[i]-a[j]));
        }
        dp[i]=t;
    }
    cout<<dp[n-1];
    return;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    //cin>>t;
    t=1;

    while(t--)
    {
        solve();
    }
    return 0;
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll modpow(ll X){
  // X ^ (MOD-2)
  ll bit = MOD-2;
  ll res = 1;

  while(bit > 0){
    if(bit & 1) res = res * X % MOD;
    X = X * X % MOD;
    bit >>= 1;
  }
  return res;
}


ll nCr(ll n,ll r){
  ll res = 1;
  forep(i,2,n+1) res =  res * i % MOD;
  forep(i,2,r+1) res = res * modpow(i) % MOD;
  forep(i,2,n-r+1) res = res * modpow(i) % MOD;

  return res;
}

int main(){
  ll X,Y;
  cin >> X >> Y;
  if((X+Y)%3){
    cout << 0<<endl;
    return 0;
  }

  ll n = (X+Y)/3;
  X -= n; Y -= n;

  if(X < 0 || Y < 0){
    cout << 0 << endl;
    return 0;
  }

  cout << nCr(X+Y, X) << endl;

}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll ans = 1;
    map<char, ll> chars;
    string S;
    cin >> N >> S;
    iter(c, S) chars[c]++;
    iter(i, chars) {
        ans *= i.second + 1;
        ans %= MOD;
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


S = input()
if S == 'RSR':
    print(1)
else:
    print(S.count('R'))

Measured memory_bytes: 62004
#include <bits/stdc++.h>
    using namespace std;
    int a[500][500], num[500];
    bool vis[500];
    int m, n;
    bool judge(int x) {
        memset(vis, 0, sizeof(vis));
        int cnt = m;
        while (cnt > 0) {
            bool flag = false;
            memset(num, 0, sizeof(num));
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (vis[a[i][j]]) continue;
                    num[a[i][j]]++;
                    break;
                }
            }
            for (int j = 1; j <= m; j++) {
                if (num[j] > x) {
                    vis[j] = true;
                    flag = true;
                    cnt--;
                }
            }
            if (!flag) return true;
        }
        return false;
    }
    int erfen() {
        int l = 1, r = n, ans = n;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (judge(mid)) {
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        return ans;
    }
    int main() {
        memset(a, 0, sizeof(a));
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                scanf("%d", &a[i][j]);
            }
        }
        printf("%d\n", erfen());
        return 0;
    }

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int x,a,b; cin >> x >> a >> b;
    if(b <= a) cout << "delicious" << endl;
    else if(b <= a+x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;


int main()
{
	int n,m;
	cin>>n>>m;
	double x,y;
	x = 1900*m + (n-m)*100;
	double p = pow(0.5,(double)m);
	y = x / p;
	cout<<y<<endl;
	return 0;
}



Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            if (N % 1000 == 0) { return 0; }
            return 1000 - (N % 1000);
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int[] num = sc.nextIntArray(3);
		Arrays.sort(num);
		String canDevide = "No";
		if (num[2] == num[1] + num[0]) {
			canDevide = "Yes";
		}
		System.out.println(canDevide);
	}

}

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

Measured memory_bytes: 21332
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		var S = GetString();
		int N = S.Length;
		WriteLine(isOK(S) && isOK(S.Substring(0, N / 2)) && isOK(S.Substring((N + 1) / 2)) ? "Yes" : "No");
	}

	private bool isOK(string S)
	{
		int N = S.Length;
		for(int i = 0; i < N; i++)
		{
			if(S[i] != S[N - 1 - i])
				return false;
		}
		return true;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13140
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int a,b;
int main()
{
	cin>>a>>b;
	if(a<=0&&b>=0)puts("Zero");
	else if(a>0)puts("Positive");
	else if((b-a)%2==0)puts("Negative");
	else puts("Positive");
	return 0;
}


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

using namespace std;

long long coeff[10] = {
	1,
	1,
	2,
	4,
	8,
	16,
	32,
	64,
	128,
	256,
};

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

	long long ans = 0;
	for (int i = 0; i < S.size(); i++){
		for (int j = S.size() - i - 1, p = 1; j >= 0; j--, p *= 10){
			ans += (long long)(S[i] - '0') * p * pow(2, i) * coeff[j];
		}
	}

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


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long

int mod = 1e9+7;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> ans(K);
  int R = N - K;
  if (R == 0) {
    rep(i, 0, K) {
      if (i == 0) cout << 1 << endl;
      else cout << 0 << endl;
    }
    return 0;
  } else {
    rep(i, 0, K) {
      // if (i == 0) {
      //   cout << (R + 1) % mod << endl;
      //   continue;
      // }
      int I = i + 1;
      if (R < I - 1) {
        cout << 0 << endl;
        continue;
      }
      ll ans = 1;
      rep(j, K - I + 1, K) {
        ans *= j;
        ans = (ans % mod);
      }
      rep(j, 1, I) {
        ans = ans * modinv(j, mod) % mod;
      }
      rep(j, I + 1, R + 2) {
        ans *= j;
        ans = (ans % mod);
      }
      rep(j, 1, R - I + 2) {
        ans = ans * modinv(j, mod) % mod;
      }
      cout << ans << endl;
    }
  }
};


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

int main() {
	ios_base::sync_with_stdio( false );
	cout << fixed << setprecision( 5 );

	int N;
	cin >> N;

	double result = 0;
	for( int i = 0; i < N; ++i ) {
		double x;
		string u;
		cin >> x >> u;

		if( u == "BTC" ) {
			result += 380000.0 * x;
		}
		else {
			result += x;
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
	int n;
	cin >> n;
	int ret = 1;
	for (int i = 0; i * i <= n; i++) {
		ret = i * i;
	}
	cout << ret << endl;
	return 0;
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

vector<string> c;
int n;

bool check(int a, int b) {
    inc(i, 0, n){
        inc(j, 0, n){
            if(c[(i+a)%n][(j+b)%n] != c[(j+a)%n][(i+b)%n]){
                return false;
            }
        }
    }
    return true;
}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    cin >> n;
    c.resize(n);
    inc(i, 0, n) cin >> c[i];

    int a = 0;
    inc(i, 1, n){
        if(check(i, 0)){
            a++;
        }
    }

    int b = 0;
    inc(i, 1, n){
        if(check(0, i)){
            b++;
        }
    }

    cout << (check(0, 0) ? 1 : 0)*n + a*n << endl;
    //cout << a*(n-1) << endl;

    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        c(N);
    }
    public void c(long N) {
        StringBuilder sb = new StringBuilder();
        while(0 < N) {
            N -= 1;
            int mod = (int) (N % 26);
            sb.append((char)(mod + (int)'a'));
            N /= 26;
        }
        System.out.println(sb.reverse().toString());
    }
}


Measured memory_bytes: 35624
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder
import kotlin.math.max
import kotlin.math.pow

object AMain{
    fun solve(){
        var n = nextLong()
        var ans = ""
        while(n > 0){
            if(n % 26 == 0L){
                ans = "z$ans"
                n -= 26L
            }else{
                ans = ((n % 26 - 1).toByte() + 'a'.toByte()).toChar().toString() + ans
                n -= n % 26
            }
            n /= 26
        }
        println(ans)
    }





    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun NextDouble() = next().toDouble()
}

fun main(){
    AMain.solve()
}



Measured memory_bytes: 33772
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

#include<deque>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N;
int C[9];

int main() {
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) {
        C[min(8,a[i]/400)]++;
    }
    int resmin = 0, resmax = 0;
    for (int i = 0; i < 8; i++) {
        if (C[i]) {
            resmin++;
            resmax++;
        }
    }
    resmin = max(1,resmin);
    resmax = resmax+C[8];
    cout << resmin << " " << resmax << endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU

signed main(){
	int n,m,r;
	while(cin>>n>>m>>r,n|m|r){
		vvd S(n,vd(4));
		rep(i,n)rep(j,4)cin>>S[i][j];
		vvd T(m,vd(4));
		rep(i,m)rep(j,4)cin>>T[i][j];
		double E[3];
		rep(i,3)cin>>E[i];
		
		vector<bitset<2020> >dp(m);
		rep(i,m)rep(j,n){
			double dis1=hypot(T[i][0]-S[j][0],hypot(T[i][1]-S[j][1],T[i][2]-S[j][2]));
			double dis2=hypot(S[j][0]-E[0],hypot(S[j][1]-E[1],S[j][2]-E[2]));
			double dis=S[j][3];
			if(dis1<dis&&dis2<dis);
			else if(dis1<dis&&dis2>dis||dis1>dis&&dis2<dis)dp[i][j]=1;
			else{
				double dis3=hypot(T[i][0]-E[0],hypot(T[i][1]-E[1],T[i][2]-E[2]));
				if(abs(dis1+dis2-dis3)<EPS){
					dp[i][j]=1;
					continue;
				}
				if(abs(dis1+dis3-dis2)<EPS)continue;
				if(abs(dis3+dis2-dis1)<EPS)continue;
				double ang=acos((dis1*dis1+dis3*dis3-dis2*dis2)/(2.*dis1*dis3));
				if(ang>PI/2)continue;
				ang=acos((dis2*dis2+dis3*dis3-dis1*dis1)/(2.*dis2*dis3));
				if(ang>PI/2)continue;
				double dis4=dis2*cos(ang);
				dis4=dis2*sin(ang);
				if(dis4<dis)dp[i][j]=1;
			}
		}
		// rep(i,m){show1d(dp[i]);cout<<endl;}
		double out=0;
		loop(i,1,1<<m){
			vi h(n);
			bitset<2020>bs;
			rep(j,m)if(i&1<<j)bs|=dp[j];
			int co=bs.count();
			if(co>r)continue;
			double sum=0;
			rep(j,m)if(i&1<<j)sum+=T[j][3]/(pow(T[j][0]-E[0],2)+pow(T[j][1]-E[1],2)+pow(T[j][2]-E[2],2));
			cmax(out,sum);
		}
		
		cout<<shosu(9)<<out<<endl;
	}
}











Measured memory_bytes: 3732
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s = sc.next();
    int n=s.length();
    while(n>4){
//      System.out.println(n);
      if(s.substring(n-5,n).equals("dream")){
        n-=5;
      }else if(n>6&&s.substring(n-7,n).equals("dreamer")){
        n-=7;
      }else if(s.substring(n-5,n).equals("erase")){
        n-=5;
      }else if(n>5&&s.substring(n-6,n).equals("eraser")){
        n-=6;
      }else{
        System.out.println("NO");
        return;
      }
    }
    System.out.println("YES");
  }
}

Measured memory_bytes: 28256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var N = cin.nextInt();
            var A = cin.nextInt() - 1;
            var B = cin.nextInt() - 1;
            var C = cin.nextInt() - 1;
            var D = cin.nextInt() - 1;
            var S = cin.next();

            int from = Math.Min(A, B);
            int to = Math.Max(C, D);
            for (int i = from; i < Math.Min(to, N - 1); i++)
            {
                if (S[i] == '#' && S[i + 1] == '#')
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            if (C < D)
            {
                Console.WriteLine("Yes");
                return;
            }
            bool f = false;
            for (int i = Math.Max(A + 1, B); i <= Math.Min(C - 1, D); i++)
            {
                if (S[i] == '#') continue;
                f = f || (S[i - 1] != '#' && S[i + 1] != '#');
            }
            Console.WriteLine(f ? "Yes" : "No");

        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    
}


Measured memory_bytes: 13124
import java.util.ArrayDeque;
import java.util.Scanner;


public class Main {

	static class MyProcess {

		String qName;
		int needTime;
		int finTime = 0;

		public int getFinTime() {
			return finTime;
		}

		public String getqName() {
			return qName;
		}

		public int getNeedTime() {
			return needTime;
		}

		public void setNeedTime(int needTime) {
			this.needTime = needTime;
		}

		public void setFinTime(int finTime) {
			this.finTime = finTime;
		}

		MyProcess(String qName, int needTime, int finTime) {
			this.qName = qName;
			this.needTime = needTime;
			this.finTime = finTime;

		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), qTime = sc.nextInt();
		int totalTime = 0;

		MyProcess[] mps = new MyProcess[n];

		for (int i = 0; i < n; i++) {
			mps[i] = new MyProcess(sc.next(), sc.nextInt(), 0);
		}

		java.util.Queue<MyProcess> q = new ArrayDeque<MyProcess>();
		for (int i = 0; i < n; i++) {
			q.add(mps[i]);
		}

		while (q.peek() != null) {
			MyProcess mp = q.poll();
			int needTime = mp.getNeedTime();
			String pName = mp.getqName();
			if (needTime <= qTime) {
				totalTime += needTime;
				mp.setFinTime(totalTime);
				System.out.println(mp.getqName() +" "+ mp.getFinTime());
			} else {
				q.add(new MyProcess(pName, needTime - qTime, 0));
				totalTime += qTime;
			}
		}
	}


}



Measured memory_bytes: 76860