akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long

#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define fill(a,b) memset(a,b,sizeof(a))

#define f first
#define s second
#define pb push_back

#define inf 1e17
#define ninf -1*1e17
#define mod 1000000007
#define N 500005
#define Ns 5005

// string s;
ll n,m,o,z,d,k,l,r;

ll dp[N];
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--){
	    
	    ll ans=0;
	    cin>>n;
	    int x[n],y[n];
	    set<pair<ll,ll>>s;
	    for(int i=0;i<n;i++){
	        int x1,y1;
	        cin>>x1>>y1;
	        s.insert({x1,y1});
	    }
	    ll mi=inf,mi2=inf;
	    for(auto it=s.begin();it!=s.end();it++){
	        
	        if(it==s.begin()){
	            mi=(*it).f+(*it).s;
	            mi2=(*it).f-(*it).s;
	            continue;
	        }
	       // cout<<*it<<" %\n";
	        ll cur=(*it).f+(*it).s;
	        ll cur2=(*it).f-(*it).s;
	        ans=max(ans,cur-mi);
	        ans=max(ans,cur2-mi2);
	        
	        mi=min(mi,cur);
	        mi2=min(mi2,cur2);
	        
	    }
	    cout<<ans;
	}
	    
	return 0;
}


Measured memory_bytes: 16148
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a-lin bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int D,T,S;cin >> D >> T >> S;
    if(T*S >= D){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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


 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
  
  int n,h;
  int mx=0;
  int count=0;
  //scanf("%d %d",&n,&h);
  cin >> n >> h;
  for(int i=1;i<n;i++){
    int hh;
    //scanf("%d",&hh);
    cin >> hh;
  	if(hh<=h){
    	count++;
    }else{
    	//mx=max(count,mx);
    	if(count>mx){mx=count;}
    	count=0;
    }
    h=hh;
  }
  //mx=max(count,mx);
  if(count>mx){mx=count;}
  //printf("%d\n",&mx);
  cout << mx;
  
  

}


Measured memory_bytes: 256
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	vi a(3);
	fo0(i,3){
		cin>>a[i];
	}
	sort(all(a));
	int flag=0;
	if(a[0]==a[1] and a[0]!=a[2]){
		flag=1;
	}
	else if(a[1]==a[2] and a[0]!=a[1]){
		flag=1;
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,sum=0,i;
	int a[3001];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i]-1;
	}
	printf("%d",sum);
	return 0;
}


Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" pred
let c = ref 0
let _ = Array.iteri (fun i a -> if a_s.(a) = i then incr c) a_s; Printf.printf "%d\n" @@ !c / 2

Measured memory_bytes: 5376
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
mod=10**9+7
L = input()
n = len(L)
dp1 = [0]*n#i桁目までがLより小さい
dp2=[0]*n#i桁目までがLと一致
dp1[0]=1 #00
dp2[0]=2 #01 or 10
for i in range(1,n):
    if L[i]=="1":
        dp1[i] = (2+1)*dp1[i-1]+1*dp2[i-1]
        dp2[i]= 2*dp2[i-1]
    elif L[i]=="0":
        dp1[i]=(2+1)*dp1[i-1]
        dp2[i]=dp2[i-1]
    dp1[i]%=mod
    dp2[i]%=mod
print((dp1[n-1]+dp2[n-1])%mod)


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

#define MAXN 200001

int p[MAXN],x[MAXN],y[MAXN],f[MAXN],pos[MAXN],n,m;


int find(int x)
{
    return f[x]==x?x:f[x]=find(f[x]);
}

int main()
{
    cin >> n >> m;
    for(int i=1;i<=n;++i)
    {
        cin >> p[i];
        pos[p[i]]=i;
        f[i]=i;
    }
    for(int i=1;i<=m;++i)
    {
        cin >> x[i] >> y[i];
        x[i]=find(x[i]);
        y[i]=find(y[i]);
        f[x[i]]=y[i];
    }
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        if(find(i)==find(pos[i]))++ans;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 2176
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Reader;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {

        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Distinct().Count() == 2 ? "Yes" : "No");
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = BUF_SIZE - 1;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }

    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; int sign = 1; while (Buffer[ptr] < 45) Move();
            if (Buffer[ptr] == 45) { Move(); sign = -1; }
            do { res = res * 10 + (Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res * sign;
        }
    }
}


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

int main() {
	vector<string> words;
	string stock;

	while (cin >> stock) {
		words.push_back(stock);
	}

	vector<int> times(words.size(), 0);
	
	for (unsigned int i = 0;i < words.size();i++) {  //times??????????????°????¨????
		for (unsigned int j = i;j < words.size();j++) {
			if (words.at(i) == words.at(j)) times.at(i)++;
		}
	}

	int mode_times = 0;//?????§???????????°
	int mode_num;  //?????§??????????????????

	for (unsigned int i = 0;i < times.size();i++) {
		if (times.at(i) > mode_times) {
			mode_times = times.at(i);
			mode_num = i;
		}
	}//??????

	int max_length = 0;
	int max_num;

	for (unsigned int i = 0;i < words.size();i++) {
		if (words.at(i).length() > max_length) {
			max_length = words.at(i).length();
			max_num = i;
		}
	} //??????

	cout << words.at(mode_num) << " " << words.at(max_num) << endl;
	
	return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;


int main()
{
	bool isPrime[10000 + 1];
	fill(isPrime, isPrime+10000+1, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i <= 10000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = i*2; j <= 10000; j += i)
				isPrime[j] = false;
		}
	}

	int N;
	while (scanf("%d", &N) != EOF)
	{
		int ans = 0;
		for (int i = 0; i <= N; ++i)
			if (isPrime[i] && isPrime[N+1-i])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  ll n,T;cin>>n;cin>>T;
  std::vector<ll> t(n);
  for(int i=0;i<n;i++) cin>>t[i];
  sort(t.begin(),t.end());
  ll res=0;
  for(int i=1;i<n;i++){
      if(t[i]<=t[i-1]+T){
          res+=t[i]-t[i-1];
      }
      else res+=T;
  }
    res+=T;
  cout<<res<<endl;
}


Measured memory_bytes: 1792
s=list(input())
n=len(s)

if n==1:
    print(0)
    exit(0)
from collections import deque

d=deque(s)
i=0
j=1
cnt=0
while d:
    f=d[0]
    l=d[-1]
    if f==l:
        d.popleft()
        if len(d)==0:
            break
        d.pop()
    else:
        if f=='x' and l!='x':
            cnt+=1
            d.popleft()
        elif f!='x' and l=='x':
            cnt+=1
            d.pop()
        else:
            print(-1)
            exit(0)

print(cnt)



Measured memory_bytes: 10652
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        string s1,s2;
        cin>>s1>>s2;
        int mini = INT_MAX;
        int m = s1.size(),n = s2.size();
        for(int i=0;i<=m-n;i++)
        {
            int count = 0;
            for(int j=i,k=0;k<n;j++,k++)
            {
                if(s1[j]==s2[k])
                {
                    count++;
                }
            }
            mini = min(mini,n-count);
        }
        cout<<mini;
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    int N,K,C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    auto getPositions = [&](){
        vector<int> res;
        for(int i=0; i<N and res.size()<K; i++){
            if(S[i] == 'o'){
                res.push_back(i);
                 i += C;
            }
        }
        return res;
    };
    vector<int> l,r;
    l = getPositions();
    reverse(S.begin(),S.end());
    r = getPositions();
    reverse(S.begin(),S.end());
    for(int i=0; i<K; i++){
        r[i] = N-1-r[i];
    }
    vector<int> lastL(N+1,-1);
    for(int i=0; i<K; i++){
        lastL[l[i]+1] = i;
    }
    for(int i=0; i<N; i++){
        if(lastL[i+1] == -1) lastL[i+1] = lastL[i];
    }
    vector<int> lastR(N+1,-1);
    for(int i=0; i<K; i++){
        lastR[r[i]] = i;
    }
    for(int i=N-1; i>=0; i--){
        if(lastR[i] == -1) lastR[i] = lastR[i+1];
    }
    // for(int i=0; i<=N; i++){
    //     cout << lastL[i] << " " << lastR[i] << endl;
    // }
    for(int i=0; i<N; i++){
        if(S[i] == 'x') continue;
        int cnt = 0;
        if(lastL[i] != -1) cnt += lastL[i] + 1;
        if(lastR[i+1] != -1) cnt += lastR[i+1] + 1;
        if(lastL[i] != -1 and lastR[i+1] != -1 and r[lastR[i+1]]-l[lastL[i]]<=C) cnt--;
        if(cnt >= K) continue;
        cout << i+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4984
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  while(cin >> a >> b >> c){
    TSTART();
    
    string ans;
    if(b-a == c-b)ans = "YES";
    else ans = "NO";
    
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
li=[0]*(n+1)
a=set([int(input()) for i in range(m)])
li[0]=1
for i in range(1,n+1):
  li[i]=(li[i-1]+li[i-2])%(10**9+7)
  if i in a:li[i]=0
print(li[n])

Measured memory_bytes: 56664
#include <cstdio>
int S[1000];
int main() {
	int N,M;
	while(scanf("%d %d",&N,&M),N|M) {
		for(int i=0;i<N;i++) scanf("%d",&S[i]);
		int x=0;
		int ans=1<<30;
		for(int i=0;i<M;i++) {
			int y;
			scanf("%d",&y);
			if(x>=(N-1)) continue;
			x+=y;
			if((N-1)>=x) x+=S[x];
			if(x>=(N-1)) ans=i+1;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1032
#include <iostream>
#include <vector>

using namespace std;

class Edge {
public:
    int to, weight;
    Edge(int t, int w) : to(t), weight(w) {}
};

int memo[100001] = {0};

inline int height(vector< vector<Edge> > &Graph, const int parent) {
    if (memo[parent]) return memo[parent];
    int ret = 0;
    for (int i=0; i<(int)Graph[parent].size(); ++i) {
        ret = max(ret, Graph[parent][i].weight + height(Graph, Graph[parent][i].to));
    }
    return memo[parent] = ret;
}

inline int diameter(vector< vector<Edge> > &Graph, const int parent) {
    int ret = 0;
    int h1 = 0, h2 = 0;
    for (int i=0; i<(int)Graph[parent].size(); ++i) {
        int h = Graph[parent][i].weight + height(Graph, Graph[parent][i].to);
        if (h1 < h) {
            h2 = h1;
            h1 = h;
        } else if (h2 < h) {
            h2 = h;
        }
        ret = max(ret, diameter(Graph, Graph[parent][i].to));
    }
    ret = max(ret, h1 + h2);
    return ret;
}

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

    int n, s, t, w;
    cin >> n;
    vector< vector<Edge> > Graph(n + 1);
    for (int i=1; i<=n-1; ++i) {
        cin >> s >> t >> w;
        Graph[s].push_back(Edge(t, w));
    }
    cout << diameter(Graph, 0) << endl;

    return 0;
}

Measured memory_bytes: 11968
N,P=map(int,input().split())
A=list(map(int,input().split()))

odd=0
even=0
for i in range(0,N):
    if A[i]%2==1:
        odd=odd+1
    else:
        even=even+1
if odd==0:
    if P==0:
        print(2**(even))
    else:
        print(0)
else:
    print((2**(odd-1))*(2**(even)))

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
from operator import itemgetter
import heapq
n, k = map(int, input().split())
TD = sorted([list(map(int, input().split())) for _ in range(n)], reverse=True, key=itemgetter(1))
L = [[] for _ in range(n+1)]
P = []
a = 0
cnt = 0
F = [-float("inf")]*(n+1)
for t, d in TD[:k]:
  L[t].append(d)
  if len(L[t]) == 1:
    a += 1
  cnt += d
F[a] = cnt
for i in range(1, n+1):
  while len(L[i]) > 1:
    heapq.heappush(P, L[i].pop())
now = k
for i in range(a, n):
  if len(P) == 0:
    break
  while now < n and L[TD[now][0]]:
    now += 1
  if now == n:
    break
  t, d = TD[now]
  L[t].append(d)
  F[i+1] = F[i] - heapq.heappop(P) + d
ans = 0
for i in range(a, n+1):
  ans = max(ans, F[i] + i*i)
print(ans)

Measured memory_bytes: 36592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

int main()
{
    ll n,k;cin>>n>>k;
    ll cnt=0;
    while(n>0)
    {
        n/=k;
        cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
  int N,n,t=0;
  long L;
  scanf("%d\n",&N);
  for(n=0;n<N;n++) {
    scanf("%ld\n",&L);
    if (L==2) t++;
    else if (L>2) {
      if (L%2){
        long Ls = (long)sqrt(L);
        long i=3; int a=1;
        while (i<=Ls) {
          if(!(L%i)) {a--;break;}
          i+=2;
        }
        t+=a;
      }
    }
  }
  printf("%d\n",t);
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>

using namespace std;

int main() {
	long long int n;

	cin >> n;

	long long int total = 0;

	long long int lim;
	// cout << "total" << endl;

	for (lim = 1; total < n; lim++) {
		total += lim;
		// cout << "total" << total << endl;
	}

	long long int diff = total - n;

	for (long long int i = 1; i < lim; i++) {
		if (i == diff) {

		}
		else {
			cout << i << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 888
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
def f(x,y):
    c=1
    d=1
    for i in range(x):
        c*=(i+1)
        d*=(y-i)
    return d//c
p=v[n-a:]
g=sum(p)/a
print(sum(p)/a)
w=0
for i in range(a,b+1):
    p=v[n-i:]
    h=sum(p)/i
    if h<g:
        break
    else:
        q=p[0]
        d=v.count(q)
        e=p.count(q)
        w+=f(e,d)
print(w)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void) {
	int n, m, i;
	int a[1000000];

	scanf("%d%d", &n, &m);

	for (i = 0; i < m; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < m; i++) {
		n -= a[i];
		if (n < 0) {
			printf("-1\n");
			return 0;
		}
	}

	printf("%d\n", n);

	return 0;
}

Measured memory_bytes: 1776
from math import gcd
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N = int(input())
cnt = {}
zz = 0
az = 0
bz = 0
for _ in range(N):
    A, B = map(int, input().split())
    if A == B == 0:
        zz += 1
        continue
    if A == 0:
        az += 1
        continue
    if B == 0:
        bz += 1
        continue
    neg = False
    if A < 0:
        neg ^= True
        A *= -1
    if B < 0:
        neg ^= True
        B *= -1
    g = gcd(A, B)
    sign = -1 if neg else 1
    A //= g
    B //= g
    frac = (-sign * A, B)
    if frac not in cnt:
        cnt[frac] = 0
    cnt[frac] += 1
ans = 1
used = set()
for frac, c in cnt.items():
    if frac in used:
        continue
    A, B = frac
    sign = 1
    if A < 0:
        A *= -1
        sign = -1
    bad = (B * -sign, A)
    if bad in cnt:
        b = cnt[bad]
        ans = ans * (pow(2, c, mod) + pow(2, b, mod) - 1) % mod
        used.add(bad)
    else:
        ans = ans * pow(2, c) % mod
ans = ans * (pow(2, az, mod) + pow(2, bz, mod) - 1) % mod
print((ans + zz - 1) % mod)


Measured memory_bytes: 112644
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N;
lint arr[200000];
int main() {
	cin >> N;
	lint ans = 0;
	REP(i, N) {
		cin >> arr[i];
	}
	sort(arr, arr + N, greater<lint>());
	ans += arr[0];
	lint idx = 1;
	bool flag = false;
	REP(i, N - 2) {
		ans += arr[idx];
		if (flag) idx++;
		flag ^= 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5232
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()

def main():
    H, W = map(int, input().split())
    S = [['#'] * (W+2)] + [['#'] + list(input()) + ['#'] for _ in range(H)] + [['#'] * (W+2)]
    direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    ans = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if S[i][j] == '#':
                continue
            init = (i, j)
            que = deque()
            que.append(init)
            dist = [[-1 for _ in range(W+2)] for _ in range(H+2)]
            dist[i][j] = 0

            while que:
                qh, qw = que.popleft()
                for dh, dw in direction:
                    h = qh + dh
                    w = qw + dw
                    if S[h][w] == '#' or dist[h][w] >= 0:
                        continue
                    dist[h][w] = dist[qh][qw] + 1
                    que.append((h, w))
            ans = max(ans, max([max(i) for i in dist]))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll n;
    cin>>n;
    ll MAX = -INF,MIN = INF,SUM = 0;
    
    for(ll i = 0; i<n; i++){
        ll x;
        cin>>x;
        MAX = max(MAX,x);
        MIN = min(MIN,x);
        SUM += x;
    }
    cout<<MIN<<" "<<MAX<<" "<<SUM<<endl;
    return 0;
}



Measured memory_bytes: 3112
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	real T = read.to!real;
	real t = read.to!real;
	format("%3.4f", T / t).writeln;
}


Measured memory_bytes: 256
//専用ライブラリ
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e12
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
ll n,k;
vector<ll> a;
vector<ll> f;
ll s=0;
bool check(ll x)
{
    //if(<xs?)
    ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        cnt+=min(x/f[i],a[i]);
    }
    if(s-cnt<=k)
        return true;
    else
        return false;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n>>k;
    a.resize(n);
    f.resize(n);
    
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    for(ll i=0;i<n;i++)
        cin>>f[i];
  //  if(s<=k){cout<<0<<endl;return 0;}
    sort(a.begin(),a.end());
    sort(f.begin(),f.end());
    reverse(f.begin(),f.end());
    ll l=-1;
    ll r=INF;
    while(abs(r-l)>1)
    {
        ll mid=(r+l)/2;
        if(check(mid))
            r=mid;
        else
            l=mid;
    }
        cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
using namespace std;
 
int main() {
  int a, b, count, i, ans;
  cin >> a;
  b = a;
  ans = 0;
  count = 1;
  while(b>=10){
    b= b / 10;
    count++;
  }
  i = 1;
  while(i<count){
    int tenpow= 1;
    for(int j=1;j<i;j++){
    tenpow =tenpow * 10;
    }
    tenpow *= 9;
    ans += tenpow;
    i = (i + 2);
  }
  
  if(i==count){
    ans += a + 1;
    int tenpow2 = 1;
    for(int k=1;k<count;k++){
    tenpow2 =tenpow2 * 10;
    }
    ans -= tenpow2;
  }  
  
  cout <<ans <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define rep(i,n) for(i = 0;i < n;i++)

int N;
int main(){
	int i;
	char *str[1001];
	cin >> N;
	rep(i,N){
		int l[3];
		cin >> l[0] >> l[1] >> l[2];
		sort(l,l+3,greater<int>());
		if(l[0]*l[0] == l[1]*l[1]+l[2]*l[2])
			str[i] = "YES";
		else
			str[i] = "NO";
	}
	rep(i,N){
		cout << str[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#player1:1
#player2:2
#blank:0
k, m =map(int, input().split())
n = k - 1
answer = [m]
for i in range(1, n + 1):
    answer.append(m - i)
    answer.append(m + i)
answer.sort()
if k == 1:
    answer = [m]
print(*answer)


Measured memory_bytes: 3060
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map[T](converter)
  }

  implicit val idConverter: String => String = s => s
  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def primes(n: Long): ArrayBuffer[Long] = {
    val buf = ArrayBuffer.empty[Long]
    val s = Math.sqrt(n).toInt

    var v = n
    for (i <- 2 to s) {
      if (v == 1 || v == 0) {
        return buf
      } else {
        while (v % i == 0) {
          buf.append(i)
          v /= i
        }
      }
    }
    if (v > s) {
      buf.append(v)
    }
    buf
  }

  def divisors(n: Int): ArrayBuffer[Int] = {
    val buf = ArrayBuffer.empty[Int]
    val s = Math.sqrt(n).toInt

    for (i <- 1 to s) {
      if (n % i == 0) {
        buf.append(i)
        if (i != n / i) {
          buf.append(n / i)
        }
      }
    }
    buf
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = get[Int]
    val as = getArray[Int]

    val map = Array.ofDim[Int](1000001)
    for (a <- as) {
      map(a) += 1
    }

    var count = 0
    for (a <- as) {
      if (divisors(a).forall(d =>
        if (a == d) {
          map(d) == 1
        } else {
          map(d) == 0
        }
      )) {
        count += 1
      }
    }

    out.println(count)
    out.flush()
  }

}

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    

    int h,w,k;
    cin>>h>>w>>k;
    string s[h];
    for(int i=0;i<h;i++) cin>>s[i];
    int cnt[h][w];
    int INF = 1e9;
    queue<array<int,2>> q;
    queue<array<int,2>> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cnt[i][j] = INF;
            if(s[i][j]=='S'){
                cnt[i][j]=0;
                q.push({i,j});
                que.push({i,j});
            }
        }
    }
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    while(q.size()){
        array<int,2> a = q.front(); q.pop();
        if(cnt[a[0]][a[1]]==k) break;
        for(int i=0;i<4;i++){
            int nx=dx[i]+a[0], ny=dy[i]+a[1];
            if(cnt[nx][ny]==INF && nx>=0 && nx<h && ny>=0 && ny<w && s[nx][ny]=='.'){
                cnt[nx][ny] = cnt[a[0]][a[1]]+1;
                q.push({nx,ny});
                que.push({nx,ny});
            }
        }
    }   
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cnt[i][j] = max(cnt[i][j],k);
        }
    } 
    while(que.size()){
        array<int,2> a = que.front(); que.pop();
        int x = a[0], y = a[1];
        for(int i=0;i<4;i++){
            int nx=dx[i]+a[0], ny=dy[i]+a[1];
            if(cnt[nx][ny]==INF && nx>=0 && nx<h && ny>=0 && ny<w){
                cnt[nx][ny] = cnt[a[0]][a[1]]+1;
                que.push({nx,ny});
            }
        }
    }
    int ans = INF;
    for(int i=0;i<w;i++){
        ans = min(ans,min(cnt[0][i],cnt[h-1][i]));
    }
    for(int i=0;i<h;i++){
        ans = min(ans,min(cnt[i][0],cnt[i][w-1]));
    }
    ans = (ans+k-1)/k;
    cout << ans << endl;
}

Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>

int main()
{
	long long n, m, k;

	std::cin >> n >> m >> k;

	for (size_t i = 0; i <= n; i++)
	{
		for (size_t j = 0; j <= m; j++)
		{
			if (i * m + j * n - i * j * 2 == k) {
				std::cout << "Yes" << std::endl;
				return 0;
			}
		}
	}

	std::cout << "No" << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,l;
  cin>>n>>l;
  vector<string> a;
  for(int i=0;i<n;i++)
  {
    string s;
	cin>>s;a.push_back(s);
  }
  sort(a.begin(),a.end());
  string s;
  for(auto x:a)
  {
    s+=x;
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 3696
def solve(n,a):
    
    a.sort()
    ans = abs(a[0]-a[1])
    for i in range(n-1):
        ans = min(ans,abs(a[i] - a[i+1]))
    return ans

while True:
    n = int(input())
    if n == 0:
        break
    a = list(map(int,input().split()))
    print(solve(n,a))



Measured memory_bytes: 5628
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] H = new int[N];
            for (int i = 0; i < N; i++) {
                H[i] = in.nextInt();
            }

            int count = 0;
            for (int i = 0; i < N; i++) {
                if (canSee(i, H)) {
                    count++;
                }
            }
            System.out.println(count);
        }
    }

    private static boolean canSee(int i, int[] H) {
        for (int j = 0; j < i; j++) {
            if (H[j] > H[i]) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstring>

using namespace std;

const int MAX = 51;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
	long long N, K;
	cin >> N >> K;
	long long G[MAX][MAX];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> G[i][j];
		}
	}
	long long ans[MAX][MAX];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans[i][j] = 0;
		}
		ans[i][i] = 1;
	}
	long long exp = K;
	while (exp > 0) {
		if (exp % 2 == 1) {
			// ans *= G;
			// <=>
			// prod = ans * G;
			// ans = prod;
			long long prod[MAX][MAX];
			for (int begin = 0; begin < N; begin++) {
				for (int end = 0; end < N; end++) {
					prod[begin][end] = 0;
					for (int j = 0; j < N; j++) {
						prod[begin][end] += ans[begin][j] * G[j][end] % MOD;
					}
					prod[begin][end] %= MOD;
				}
			}
			memcpy(ans, prod, sizeof(prod));
		}
		// G *= G;
		// <=>
		// prod = G * G;
		// G = prod;
		long long prod[MAX][MAX];
		for (int begin = 0; begin < N; begin++) {
			for (int end = 0; end < N; end++) {
				prod[begin][end] = 0;
				for (int j = 0; j < N; j++) {
					prod[begin][end] += G[begin][j] * G[j][end] % MOD;
				}
				prod[begin][end] %= MOD;
			}
		}
		memcpy(G, prod, sizeof(prod));
		exp /= 2;
	}
	long long answer = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			answer += ans[i][j];
		}
	}
	answer %= MOD;
	cout << answer << '\n';
	return 0;
}


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

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		vector<pair<int,int> > a(n);
		for(int i=0;i<n;i++){
			int p,d1,d2; cin>>p>>d1>>d2;
			a[i]=make_pair(d1+d2,p);
		}
		sort(a.begin(),a.end(),greater<pair<int,int> >());
		cout<<a[0].second<<' '<<a[0].first<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 988
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <numeric>
#include <utility>

using namespace std;

int main() {
	long long n;

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

	long long sum_n = n * (n + 1) / 2;
	long long sum_a = accumulate(a.begin(), a.end(), 0LL);

	if (sum_a % sum_n != 0) {
		cout << "NO" << endl;
		return 0;
	}
	long long cycle = sum_a / sum_n;

	long long cnt = 0;

	a.push_back(a[0]);
	for (int i = 1; i <= n; i++) {
		long long diff = a[i] - a[i - 1];
		// printf("i %2d, %2lld %2lld, diff %2lld, tmp %2lld\n", i, a[i-1], a[i], diff, -diff + cycle);
		if (diff == cycle) {
			continue;
		}

		long long tmp = -diff + cycle;
		if (tmp < 0 || tmp % n != 0) {
			cout << "NO" << endl;
			return 0;
		}
		cnt += tmp / n;
	}

	cout << (cnt == cycle ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    d = collections.defaultdict(list)
    s = S()
    for i, c in enumerate(s):
        d[c].append(i)
    for key, li in d.items():
        for i in range(len(li)-1):
            if li[i+1] - li[i] + 1 < 2 * 2:
                print(li[i]+1, li[i+1]+1)
                return
    print(-1, -1)
    return
main()



Measured memory_bytes: 9912
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n, c = 0, i, j;
    cin >> n;
    string s1;
    set<string>s;
    for (i = 0; i < n; i++)
    {
        cin >> s1;
        s.insert(s1);
    }
    cout<<s.size()<<endl;

    return 0;
}

Measured memory_bytes: 19216
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

typedef long long ll;

struct mint
{
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n + 1),ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) {
            ifact[i - 1] = ifact[i] * i;
        }
    }
    mint operator()(int n, int k){
        if(k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};


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

    if((X + Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    int n = (X + Y) / 3;
    X -= n; Y -= n;
    if(X < 0 || Y < 0){
        cout << 0 << endl;
        return 0;
    }
    combination c(X + Y);
    mint ans = c(X + Y, X);
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 10624
function Main(input) {
	input = input.split("\n");
  	var n = parseInt(input[0], 10);
  	l2=input[1].split(" ");
  	var q = parseInt(input[2], 10);
    l4=input[3].split(" ");
  	var s= new Array(n);
  	for (var i=0; i<n; i++){
     	s[i]= parseInt(l2[i].split(" "), 10);
    }
  	var t= new Array(q);
  	for (var i=0; i<q; i++){
     	t[i]= parseInt(l4[i].split(" "), 10);
    }
  	var c=0;
  	for (var i=0; i<q; i++){
    	var l=0;
  		var u=n-1;
    	while (u-l>1){
          if (s[Math.floor((l+u)/2)]>t[i]){
            u=Math.floor((l+u)/2);
          }
          else{
            l=Math.floor((l+u)/2);
          }
        }
      if (s[u]==t[i] || s[l]==t[i]){
        c++;
      }
    }
  	console.log('%d',c);
  }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 35208
import java.io.*;
class Main{
	public static void main(String args[])throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String array[] = str.split(" ");
		
		 int x = Integer.parseInt(array[0]);
		int y = Integer.parseInt(array[1]);
		
		if(x > y){
			System.out.println("a" + " > "+ "b");
		}
			else if(x == y){
				System.out.println("a" + " == " +"b");
				}
				else if(x < y){
					System.out.println("a" + " < " +"b");
					}
					}
					}
					

Measured memory_bytes: 24212
MOD = 10**9 + 7
m = 2005
fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


def COMB(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


COMBinitialize(m)


def main():
    N, K = (int(i) for i in input().split())
    ans = 0
    for i in range(1, K+1):
        ans = COMB(N-K+1, i)*COMB(K-1, i-1)
        ans %= MOD
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long N){
    std::ios::fmtflags curret_flag = std::cout.flags();
    if(N <1000){
        cout <<"ABC"<< "\n";
    } else{
        N -= 999;
        cout << "ABD" << "\n";
    }
    std::cout.flags(curret_flag);
}

int main(){

    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}



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

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M && N>0 && M>0){
        vector<int> h(N);
        vector<int> w(M);
        for(int i = 0; i < N; i++){
            cin >> h[i];
        }
        for(int i = 0; i < M; i++){
            cin >> w[i];
        }
        vector<int> h_len(1500010, 0);
        for(int i = 0; i < N; i++){
            int tmp = 0;
            for (int j = 0; j < N - i; j++){
                tmp += h[i + j];
                h_len[tmp]++;
            }
        }
        vector<int> w_len(1500010, 0);
        for(int i = 0; i < M; i++){
            int tmp = 0;
            for (int j = 0; j < M - i; j++){
                tmp += w[i + j];
                w_len[tmp]++;
            }
        }
        int count = 0;
        for(int i = 1; i < 1500010; ++i){
            if(h_len[i] != 0){
                if(w_len[i] != 0){
                    count += (h_len[i] * w_len[i]);
                }
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 14436
from itertools import product

N = int(input())

adict = {}

for i in range(1,N+1):
    a = int(input())
    adict[i] = [list(map(int, input().split())) for _ in range(a)]

ans = 0

for lst in product((0, 1), repeat=N):
    jdg = True
    for n, l in enumerate(lst):
        if l==0:continue
        for i, j in adict[n+1]:
            if lst[i-1]!=j:
                jdg = False
                break
        if not jdg:break
    if jdg:ans=max(ans, sum(lst))
      
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int f(int n){
  if(n % 2 == 0){
    return n/2;
  }else{
    return 3*n + 1;
  }
}

int main(){
  int s;
  cin >> s;
  vector<bool> flag(1000005, false);
  int count = 1;
  flag[s] = true;
  while(true){
    int a = f(s);
    if(flag[a]){
      break;
    }
    flag[a] = true;
    s = a;
    count++;
  }
  cout << count+1 << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
  		int m=sc.nextInt();
  	if(n==m){
    System.out.println("Yes");
    }else{
     System.out.println("No");
    }
    
   
    }
}

Measured memory_bytes: 22736