akhauriyash/Code-Regression huggingface dataset:
N, M = input().split(' ')
N = int(N)
M = int(M)

AmStr = input().split(' ')
Am = []
sumA = 0
for v in AmStr:
  sumA += int(v)
  Am.append(int(v))

if (N - sumA >= 0):
  print(N - sumA)
else:
  print(-1)



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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int acc[N];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int k,n;
    scanf("%d %d",&k,&n);
    vector<ll>v;
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    ll rev_sum =0,ans=1e19;
    for(int i=n-2;i>=0;i--){
        acc[i]=acc[i+1]+(a[i+1]-a[i]);
        // cout<<acc[i]<<" "<<i<<endl;
    }
    for(int i=0;i<n;i++){
        ll dist = acc[i]+rev_sum;
        ans=min(ans,dist);
        if(!i){
            rev_sum+=(a[0]+k)-a[n-1];
        }else {
            rev_sum+=(a[i]-a[i-1]);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3072
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a<=0 && 0<=b) {
			System.out.println("Zero");
		} else if(a<=0 && (b-a+1)%2==1) {
			System.out.println("Negative");
		} else {
			System.out.println("Positive");
		}
		
		sc.close();
	}
}


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

int main() {
  char c;
  map<char, bool> m;
  while (cin >> c) {
    m[c] = true;
  }
  if (m['N'] ^ m['S'] || m['E'] ^ m['W']) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 2e5 + 10;

int n,k,cnt[N];


int main() {
    cin >> n >> k;
    while (n--) { 
        int x; cin >> x;
        cnt[x]++;
    }
    priority_queue<int,vi,greater<int>> q;
    forn(x,N) if (cnt[x]) q.push(cnt[x]);

    int ans = 0;
    while (si(q) > k) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, m, a[MAXN], b[MAXN], f[MAXN];
char s[MAXN];

inline int Find(int x)
{
	while (x ^ f[x])
		x = f[x] = f[f[x]];
	return x;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	scanf("%s", s + 1), n = strlen(s + 1), m = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = s[i] - 'a';
	for (int i = n + 1; i; i --)
		f[i] = i, a[i] = (a[i] - a[i - 1] + 26) % 26;
	for (int i = 1, l, r; i <= m; i ++)
		l = Read(), r = Read(), f[Find(l)] = Find(r + 1);
	for (int i = 1; i <= n + 1; i ++)
		f[Find(i)] = Find(n + 2 - i);
	for (int i = 1; i <= n + 1; i ++)
		b[Find(i)] = (b[Find(i)] + a[i]) % 26;
	for (int i = 1; i <= n + 1; i ++)
		if (Find(i) == i && b[i])
			return puts("NO"), 0;
	return puts("YES"), 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;

int main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int x;
  cin>>x;
  if(x>=30){
  	cout<<"Yes"<<endl;
  }
  else{
  	cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class B {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        string S;
        Input(out S);
        Print(new string('x', S.Length));
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

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

int main(){
    int d;
    cin>>d;
    vector<int>c(26),t(d);
    vector<vector<int>>s(d,vector<int>(26)),last(d+1,vector<int>(26,0));
    rep(i,26)cin>>c[i];
    rep(i,d)rep(j,26)cin>>s[i][j];
    rep(i,d){
        cin>>t[i];
        t[i]--;
    }
    ll ans=0;
    rep(i,d){
        if(i!=0){
            rep(j,26)last[i][j]=last[i-1][j];
        }
        ans+=s[i][t[i]];
        last[i][t[i]]=i+1;
        rep(j,26)ans-=c[j]*((i+1)-last[i][j]);
    }
    int m;
    cin>>m;
    while(m--){
        int dx,qx; cin>>dx>>qx;
        dx--; qx--;
        int cap=t[dx];
        t[dx]=qx;
        ll cnt=0;
        rep(i,d+1)rep(j,26)last[i][j]=0;
        rep(i,d){
            if(i!=0){
                rep(j,26)last[i][j]=last[i-1][j];
            }
            cnt+=s[i][t[i]];
            last[i][t[i]]=i+1;
            rep(j,26)cnt-=c[j]*((i+1)-last[i][j]);
        }
        cout<<cnt<<endl;
    }
}


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

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int x;
	cin>>x;
	int a = x/500;
	int b = x%500;
	int c = b/5;
	cout<<a*1000 + c*5;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n, last_digit;
    scanf("%d", &n);
    last_digit = n%10;
    if(last_digit == 2 ||last_digit ==  4 || last_digit == 5||last_digit ==  7||last_digit ==  9){
        printf("hon\n");
    }
    else if(last_digit == 0||last_digit ==  1||last_digit ==  6||last_digit ==  8){
        printf("pon\n");
    }
    else if(last_digit == 3){
        printf("bon\n");
    }
    return 0;
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")


signed main() {
    vector<int> ds(5);
    int last = 0;
    rep(i, 5) {
        cin >> ds[i];
        auto m = ds[i] % 10;
        if(m != 0 && m < ds[last] % 10)
            last = i;
    }
    int ans = 0;
    rep(i, 5) {
        if(i == last)
            ans += ds[i];
        else
            ans += ceil((double)ds[i] / 10) * 10;
    }
    cout << ans << nl;
}


Measured memory_bytes: 256
def main():
    mod = 10**9+7
    fact = [1, 1]
    for i in range(2, 5*(10**5)+1):
        fact.append(fact[-1]*i % mod)

    def nPr(n, r, mod=10**9+7):
        return pow(fact[n-r], mod-2, mod)*fact[n] % mod
    n, m = map(int, input().split())
    if m == 1:
        print(0)
        return
    ans = nPr(m, n)
    if m-n == 1:
        a0 = 1
    else:
        a0 = 0
    a1 = 1
    for i in range((m-n-1), m-1):
        a1, a0 = ((i+1)*a1+(i-(m-n-1))*a0) % mod, a1
    print(a1*ans % mod)


main()


Measured memory_bytes: 28900
#include <bits/stdc++.h>
#include <set>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam) ll nam; cin >> nam


int main()
{
  string s,t;
  cin >> s >> t;
  ll ans = t.length();
  repl(i, s.length() - t.length()+1)
  {
    ll tmp = 0;
    repl(j, t.length())
    {
      if(s[i+j] != t[j]) tmp++;
    }
    ans = min(ans, tmp);
  }

  cout << fixed << ans << endl;

  return 0;
}

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

int main(){
    string n; cin >> n;
    string ans = "No";
    rep(i, n.size()){
        if(n.at(i) == '7'){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int main(){
  int N,M;
  int sum=0;
  cin>>N;
  cin>>M;
  int input;
  for(int i = 0; i < M ; i++){
    cin>>input;
    sum+=input;
  }
  
  if((N-sum) >= 0){
    cout<<(N-sum);
  }else{
    cout<<-1;
  }
  
  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}


int main() {
    string S; cin >> S;
    sort(all(S));
    string str = "None";

    if(S[0] != 'a') {
        str = "a";
    } else {
        for(int i = 0; i < S.size() - 1; ++i) {
            if(S[i + 1] - S[i] > 1) {
                str = S[i] + 1;
                break;
            }

            if(i == S.size() - 2 && S[i + 1] != 'z') {
                str = S[i + 1] + 1;
            }
        }
    }

    cout << str << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int h = scan.nextInt();
        
        System.out.println((a + b) * h / 2);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	char odd[3] = { 'R','U','D' };
	char even[3] = { 'L','U','D' };
	string s; cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		bool ok = false;
		if (i % 2 == 0) {
			for (int j = 0; j < 3; ++j) {
				if (s[i] == odd[j]) {
					ok = true;
				}
			}
		}
		if (i % 2 == 1) {
			for (int j = 0; j < 3; ++j) {
				if (s[i] == even[j]) {
					ok = true;
				}
			}
		}
		if (!ok) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n, m  = map(int, input().split())

A = [int(input().strip()) for _ in range(m)]

a0 = 1
if len(A) == 0:
  a1 = 1
else:
  a1 = 1 if A[0] !=1 else 0
mod = 1000000007

ANS=[0]*(n+1)
ANS[0]=a0
ANS[1]=a1
Next = A if a1 !=0 else A[1:]
next = 0
for i in range(2, n+1):
    if next <= len(Next)-1:
        if i == Next[next]:
            ANS[i] = 0
            next += 1
            continue
    ANS[i] = ANS[i-2] + ANS[i-1]

print(ANS[n]%mod)



Measured memory_bytes: 460020
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int X;
  cin >> X;

  int y = X%100;

  int sum = 0;
  for (int i=5; i>=1; --i) {
    int a = y/i;
    sum += (100+i)*a;
    y = y%i;
  }

  if (sum <= X) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  double value[N];
  for(int i=0; i<N; i++){
    cin >> value[i];
  }
  sort(value, value+N);
  for(int j=1; j<N; j++){
    value[0] = (value[0]+value[j])/2;
  }
  
  cout << value[0];
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();

int main()
{
    long long H;
    cin >> H;

    long long s = 0;
    REP(i, floor(log2(H)))
    {
        s += (long long)pow(2, i + 1);
    }

    cout << s + 1 << endl;

    return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
p = list(int(i) for i in input().split())

kitai = [(x+1)/2 for x in p]

rui_kitai = [kitai[0]]

for i in range(1, n):
    ruiseki=rui_kitai[i-1]+kitai[i]
    rui_kitai.append(ruiseki)

gokei = 0

for i in range(n-k+1):
    if i==0:
        wa = rui_kitai[k-1]
    else:
        wa = rui_kitai[i+k-1]-rui_kitai[i-1]
    if gokei < wa:
        gokei = wa

print(gokei)

Measured memory_bytes: 25060
#include<stdio.h>
#include<string.h>
int main(){
	char a[22];
	while(gets(a)!=NULL){
		int n=strlen(a);
		for(int i=0;i<n;i++){
			if(a[i]==','){
				printf(" ");
			}
			else
			printf("%c",a[i]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mod 1000000007



int main()
{
	ll n;
	cin>>n;
    ll ac=0,wa=0,tle=0,re=0;
    
    for(ll i=0;i<n;i++)
    {
    	string s;
    	cin>>s;
    	if(s=="AC")
    		ac++;
    	else if(s=="TLE")
    		tle++;
    	else if(s=="WA")
    		wa++;
    	else
    		re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;

  return 0;
	
}




Measured memory_bytes: 3628
#include<stdio.h>
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
  int i,n;
  int ary[100001];
    scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&ary[i]);
  }
  for(i=0;i<n;i++){
    printf("node %d: key = %d, ",i+1,ary[i]);
    if(parent(i+1)>=1)printf("parent key = %d, ",ary[parent(i+1)-1]);
    if(left(i+1)<=n)printf("left key = %d, ",ary[left(i+1)-1]);
    if(right(i+1)<=n)printf("right key = %d, ",ary[right(i+1)-1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int main() {
	char c; cin>>c;
	if(c=='A') cout<<'T';
	else if(c=='G') cout<<'C';
	else if(c=='T') cout<<'A';
	else cout<<'G';
}	

Measured memory_bytes: 256
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
  
  
public class Main{
     
    public static long count(long s){
        long p = 1;
        long cnt = 1;
        long res = 0;
         
        while(p * 10 < s){
            long less3 =  (p * 10 - 1)/3 - (p - 1)/3;
            long less5 =  (p * 10 - 1)/5 - (p - 1)/5;
            long less15 = (p * 10 - 1)/15 - (p - 1)/15;
             
            res += ((p * 10 - 1) - (p - 1) - less3 - less5 + less15) * cnt;
            res += (less3 - less15) * 4;
            res += (less5 - less15) * 4;
            res += less15 * 8;
             
            cnt++;
            p *= 10;
        }
         
         
        long less3 =  (s - 1)/3 - (p - 1)/3;
        long less5 =  (s - 1)/5 - (p - 1)/5;
        long less15 = (s - 1)/15 - (p - 1)/15;
         
        res += ((s - 1) - (p - 1) - less3 - less5 + less15) * cnt;
        res += (less3 - less15) * 4;
        res += (less5 - less15) * 4;
        res += less15 * 8;
         
        return res;
    }
     
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
         
        final long s = sc.nextLong();
         
        long upper = s;
        long lower = 1/*(long) Math.pow(10 ,(long)Math.log10(s))*/;
         
        while(upper - lower > 1){
            long med = (upper + lower)/2;
            long dist = count(med);
            //System.out.println(upper + " " + lower + " " + med + " " + dist + " " + s);
             
            if(dist > s){
                upper = med;
            }else if(dist < s){
                lower = med;
            }else{
                upper = med;
                lower = med-1;
            }
        }
         
         
        for(long i = lower, cur = count(lower) + 1; ; i++){
            String str = null;
             
            if(i % 15 == 0){
                str = "FizzBuzz";
            }else if(i % 5 == 0){
                str = "Buzz";
            }else if(i % 3 == 0){
                str = "Fizz";
            }else{
                str = Long.toString(i);
            }
             
            char[] ch = str.toCharArray();
            for(int j = 0; j < ch.length; j++, cur++){
                 
                if(cur < s){
                    //System.out.println(cur + " " + ch[j]);
                    continue;
                }else if(cur >= (s + 20)){
                    System.out.println();
                    return;
                }else{
                    System.out.print(ch[j]);
                }
            }
        }
         
    }
      
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vi a(n+1); rep(i, n+1) std::cin >> a[i];
    vi b(n); rep(i, n) std::cin >> b[i];
    ll ans = 0;
    rep(i, n) {
        if (a[i] < b[i]) {
            b[i] -= a[i];
            ans += a[i] + min(b[i], a[i+1]);
            a[i+1] -= min(b[i], a[i+1]);
        } else {
            ans += b[i];
        }
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int ch;
  
  while(1){
	ch=fgetc(stdin);	
	if(ch==EOF)
	  break;
	if(ch=='\n')
	  break;
	if((65<=ch)&&(ch<=90))
	  printf("%c",ch+32);
	else if((97<=ch)&&(ch<=122))
	  printf("%c",ch-32);
	else
	  printf("%c",ch);
	
}
  printf("\n");
  return 0;
}



Measured memory_bytes: 2040
# C - Count Order

import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
assert len(P) == N and len(Q) == N

perm = list(itertools.permutations(P))
perm.sort()

a = perm.index(tuple(P))
b = perm.index(tuple(Q))
print(abs(a - b))

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    string s;
    cin >> s;
    if(s.find("RRR")!=string::npos){
        cout << 3 << endl;
        return 0;
    }else if(s.find("RR")!=string::npos){
        cout << 2 << endl;
        return 0;
    }else if(s.find("R")!=string::npos){
        cout << 1 << endl;
        return 0;
    }else{
        cout << 0 << endl;
        return 0;
    }
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, m, result;
  cin >> n >> m;
  result = abs((n - 2) * (m - 2));
  cout << result << endl;
}

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

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=s[i]-'0';
    int ans=0;
    for(int i=0;i<n;i++)
    ans+=a[i];
    if(ans%9)
    cout<<"No";
    else
    cout<<"Yes";
}

Measured memory_bytes: 4528
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int n, k;
    cin >> n >> k;
    vi h(n);
    fo(i, n) cin >> h[i];

    int dp[100005];

    fo(i, k) dp[0] = 0;

    for ( int i = 1; i < n; i++ ) {
        int menor = INF;
        for ( int j = i - 1; j >= max(0, i - k); j-- ) {
            menor = min(menor, dp[j] + abs(h[i] - h[j]));
        }
        dp[i] = menor;
    }

    cout << dp[n - 1] << endl;

    return 0;
}

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

bool used[10000];
vector<P>E[10000];
int main() {
	int v, e; scanf("%d%d", &v, &e);
	rep(i, e) {
		int s, t, w; scanf("%d%d%d", &s, &t, &w);
		E[s].push_back(P(w, t));
		E[t].push_back(P(w, s));
	}
	priority_queue<P, vector<P>, greater<P>>que;
	int res = 0;
	que.push(P(0, 0));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (used[p.second])continue;
		used[p.second] = true;
		res += p.first;
		for (P i : E[p.second])
			que.push(i);
	}
	printf("%d\n", res);
}

Measured memory_bytes: 7852
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

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

const int INF = INT_MAX;

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cntE[3*112345];
    cntE[0] = 0;
    repeat(i, N){
        cntE[i+1] = cntE[i];
        if(S[i] == 'E'){
            cntE[i+1]++;
        }
    }
    int ans = INF;
    repeat(i, N){
        int a = ((i)-cntE[i])+(cntE[N]-cntE[i+1]);
        ans = min(ans,a);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1796
#include<bits/stdc++.h>
#define db double
#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define fir first
#define sec second
#define pb push_back
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pii pair<int,int>
#define vii vector<int>
#define vll vector<ll>
#define sc(x) scanf("%d",&(x))
#define sz(x) (int)(x).size()
#define ms(x) memset((x),0,sizeof(x));
#define all(x) (x).begin(), (x).end()
#define er(x) cerr<<(x)<<" ";
#define err(x) cerr<<#x<<": "<<(x)<<" ";
#define errn cerr<<endl;
#define Fin freopen("in.txt","r",stdin);
using namespace std;
#define mod 1000000007
const db pi=acos(-1.0);
template <class T> void R(T &x) { cin>>x; }
void R(int &x) { scanf("%d",&x); }
void R(ll &x) { scanf("%lld",&x); }
void R(double &x) { scanf("%lf",&x); }
void R(char &x) { scanf(" %c",&x); }
void R(char *x) { scanf("%s",x); }
ll _pow(ll a,ll b) { ll res=1ll; while(b){ if(b&1)
res=res*a%mod; a=a*a%mod; b>>=1; } return res; }
///_____________________________________________

#define mxn 1000005

int n;
int aa[mxn],bb[mxn];
int amx,asec,bmx,bsec,a,b,c,d;

int main()
{
    while(~sc(n))
    {
        n/=2;
        ms(aa); ms(bb);
        for(int i=0;i<n;i++) {
            int x,y;
            R(x),R(y);
            aa[x]++;
            bb[y]++;
        }
        amx = asec = bmx = bsec = 0;
        a = b = c = d = 0;
        vector <pii> vec[2];
        for(int i=1; i<=1e5; i++) {
            vec[0].pb({aa[i],i});
            vec[1].pb({bb[i],i});
        }
        sort(all(vec[0]));
        sort(all(vec[1]));
        int res;
        if(vec[0].back().sec != vec[1].back().sec) res = vec[0].back().fir + vec[1].back().fir;
        else res = max(vec[0][sz(vec[0])-2].fir + vec[1].back().fir, vec[0].back().fir + vec[1][sz(vec[1])-2].fir);
        printf("%d\n",2*n - res);
    }
    return 0;
}


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

using PP = pair<int, int>;

int n;
map<PP, int> mp;
vector<int> G[100000];
int ans[100000];

void rec(int from, int prev, int col) {
  if (prev != -1) {
    int j = mp[PP(prev, from)];
    ans[j] = col;
  }
  
  int nc = 0;
  for (int to : G[from]) {
    if (to == prev) continue;
    if (nc == col) ++nc;
    rec(to, from, nc);
    ++nc;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    mp[PP(a, b)] = i;
    mp[PP(b, a)] = i;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rec(0, -1, -1);
  
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    mx = max<int>(mx, G[i].size());
  }
  
  cout << mx << endl;
  for (int i = 0; i < n - 1; ++i) {
    cout << ans[i] + 1 << endl;
  }
}

Measured memory_bytes: 19328
program main
 implicit none
 integer*8 N,i,ind,one
 integer*8, allocatable :: AB(:,:)
 data one /1/
 read(*,*) N
 allocate(AB(2,1:N))
 do i=1,N
  read(*,*) AB(1,i),AB(2,i)
 end do
 call quicksort(AB,one,N)
 
 ind = AB(2,N)
 do i=N,1,-1
  if(ind > AB(2,i)) then
   ind = AB(2,i)
  end if
  ind = ind - AB(1,i)
  if(ind < 0) then
   write(*,*) 'No'
   exit
  end if
  !write(*,*) ind
 end do
 if(ind >= 0)then
  write(*,*) 'Yes'
 end if
 
contains
 recursive subroutine quicksort(a, first, last)
  implicit none
  integer*8  a(2,*)
  integer*8 first, last
  integer*8 i, j
  integer*8 x
  integer*8 t(1:2)
  
  x = a(2, (first+last) / 2 )
  i = first
  j = last
  do
     do while (a(2,i) < x)
        i=i+1
     end do
     do while (x < a(2,j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(:,i);  a(:,i) = a(:,j);  a(:,j) = t
     i=i+1
     j=j-1
  end do
  if (first < i - 1) call quicksort(a, first, i - 1)
  if (j + 1 < last)  call quicksort(a, j + 1, last)
 end subroutine quicksort
end program main

Measured memory_bytes: 3328
K = int(input())
C = input()
C = list(C)
r = C.count("R")
A = C[:r].count("W")
B = C[-K+r:].count("W")
# print(A)
# print(B)
cnt = 0
for _ in range(200000):
    if A > 0:
        if B > 0:
            A -= 1
            B += 1
            cnt += 1
        else:
            A -= 1
            cnt += 1
    else:
        break
print(cnt) 

Measured memory_bytes: 11952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,s;
    cin >> n >> k >> s;
    if(s!=1000000000){
        REP(i,n){
            cout << ((i<k)?s:s+1) << ((i!=n-1)?" ":"");
        }cout << endl;
        return 0;
    }else{
        REP(i,n){
            cout << ((i<k)?s:1) << ((i!=n-1)?" ":"");
        }cout << endl;
        return 0;        
    }
    
}

Measured memory_bytes: 1280
#グローバル変数
ab = []
nTop = 0
nBtm = 0
nMid = 0
mid = []

def solve0(n):
    ok = 0
    for a in range(1,n+1):
        for b in range(1,n+1):
            if str(a)[0] == str(b)[-1] and str(a)[-1] == str(b)[0]:
                ok += 1
                ab.append([a,b])
    return ok

def solve1(n):
    ok = 0
    for a in range(1,n+1):
        for b in range(1,n+1):
            if str(a)[0] == str(b)[-1] and str(a)[-1] == str(b)[0]:
                ok += 1
    return ok

def solve2(n,ab):
    ok = 0
    ok_a = 0
    ok_b = 0
    for a,b in ab:
        ok_a = count(n,a)
        ok_b = count(n,b)
        ok = ok + ok_a * ok_b
    return ok

def count(n,z):
    strN = str(n)
    strZ = str(z)
    if z > n:       # z の方が大きい場合は 0
        return 0
    if len(strN) == 1: #　n　の桁が１桁の場合
        return 1
    if len(strZ) == 1: #　z　の桁が１桁の場合
        return 1

    #　n と z　の桁が2桁以上の場合
    ok = 0
    mlen = 0
    while mlen+2 < len(strN): # z の桁が n より小さい
        ok = ok + 10**mlen
        mlen = mlen + 1
    # n と z　の桁が同じ
    if int(strZ[0]+"9"*mlen+strZ[-1]) <= n:
        ok = ok + 10**mlen
#       print("routeA",n,int(strZ[0]+"9"*mlen+strZ[-1]))
    elif int(strZ[0]+strN[1:len(strN)-1]+strZ[-1]) <= n:
        ok = ok + int(strN[1:len(strN)-1])+1
#        print("routeB",n,int(strZ[0]+strN[1:len(strN)-1]+strZ[-1]))
    else:
        nMid = str(strN[1:len(strN)-1])
        if int(nMid) > 0:
            nMid = str(int(nMid)-1).zfill(len(strN)-2)
            if int(strZ[0]+nMid+strZ[-1]) <= n:
                ok = ok + (int(nMid))+1
#            print("routeC",n,int(strZ[0]+str(nMid-1)+strZ[-1]))
    return ok

# 配列 ab の準備
solve0(99)

# 整数の入力
n = int(input())
print(solve2(n,ab))


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//直感フィボナッチっぽい
//12211 122332 12233
//13322 133112 13322
//1-2-2-1がきたら、*2
//1-2-1-2がきたら、*2
//122122 122133
//133133 133122
//1-1がきたら*2
//1 *3
//2 *6
//2-1 *1 2-1-1 2-1-2
//2-2 *3 2-2-1 2-2-2
//1-1 *2 1-1-1 1-1-2
//1-2 *2 1-2-1 1-2-2
//
int main(){
  ll N,MOD=1e9+7; cin>>N;
  string S; cin>>S;
  S+="1";
  vector<ll> T;
  for(int i=0; i<N; i++){
    if(S[i]==S[i+1]){
      T.emplace_back(2);
      i++;
    }
    else T.emplace_back(1);
  }
  ll ans=1, Tsz=T.size();
  if(T[0]==1) ans*=3;
  else ans*=6;
  for(int i=0; i<Tsz-1; i++){
    if(T[i]==1) (ans*=2)%=MOD;
    else{
      if(T[i+1]==1) continue;
      else (ans*=3)%=MOD;
    }
  }
  cout<<ans<<endl;
}

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

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

    vector<long long> a(3*n);
    for(int i = 0; i < 3*n; i++){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());

    long long ans = 0;
    for(int i = 1; i <= n*2; i+=2){
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct mint {
    ll x; // typedef long long ll;
    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;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

const int NMAX = int(1e6 + 1);
ll fact[NMAX+1], finv[NMAX+1], inv[NMAX+1];

void comb_init(int N) {
    // init
    REP(i, 2) {
        fact[i] = 1;
        finv[i] = 1;
        inv[i] = 1;
    }

    FOR(i, 2, N+1) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

mint comb(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;

    return mint(fact[n]) * finv[k] * finv[n-k];
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int x, y;
    cin >> x >> y;

    comb_init(NMAX);

    mint ans = 0;

    REP(i, max(x, y) + 1) {
        if (i <= x && x <= 2 * i && i <= y && y <= 2 * i && x + y == 3 * i) {
            ans += comb(i, x - i);
        }
    }

    print(ans);
    
}


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

int main()
{
	int n;
	while(cin>>n,n)
	{
		int p[101][101];
		for(int i=1;i<=n;i++)
		{
			cin>>p[i][0];
			for(int j=1;j<=p[i][0];j++) cin>>p[i][j];
		}
		int num;
		int k[100];
		cin>>num;
		for(int i=0;i<num;i++) cin>>k[i];

		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(p[i][0]<num) continue;
			int cnt=0;
			for(int j=0;j<num;j++)
			{
				for(int l=1;l<=p[i][0];l++)
				{
					if(k[j]==p[i][l]) {cnt++; break;}
				}
			}
			if(cnt==num)
			{
				if(!ans) ans=i;
				else ans=-1;
			}
		}
		if(ans==0) ans=-1;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 908
import sys

def f(n):
    r = []
    for d in range(1, n+1, 2):
        if n % d == 0:
            r.append(d)
    return r

def main(N):
    count = 0
    for i in range(1, N+1, 2):
        r = f(i)
        print(i, r, len(r), file=sys.stderr)
        if len(r) == 8:
            count+=1

    return count

    
n = int(input())
count = main(n)
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
#define forn(i,n) for (int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back

vvi opp;

int f(int v) {
    vi xs;
    for (int u:opp[v]) xs.pb(f(u));
    sort(all(xs));
    reverse(all(xs));
    int ans=0;
    forn(i, xs.size()) {
        ans=max(ans, i+1+xs[i]);
    }
    return ans;
}

int main() {
    cxxio();
    int n;
    cin>>n;
    opp.resize(n);
    for (int i=1, x; i<n; i++) {
        cin>>x, x--;
        opp[x].pb(i);
    }
    cout<<f(0)<<'\n';
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a == b && b == c) {
            System.out.println(1);
        } else if (a != b && b != c && c != a) {
            System.out.println(3);
        } else {
            System.out.println(2);
        }
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;
 
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int a, b, c;
	cin >> a >> b >> c;
 
	if (a > INF || b > INF || c > INF) {
		cout << -1 << endl;
	}
 
 
	int n = 4 * a*b;
	int m = (c - a - b)*(c - a - b);
	if (n < m && c - a - b>=0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
 
	return 0;
}

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

int a[100001];

int partition(int p, int r){
  int x = a[r];
  int idx = p-1;
  for(int i = p; i < r; i++){
    if(a[i] <= x){
      idx++;
      swap(a[idx], a[i]);
    }
  }
  swap(a[idx+1], a[r]);
  return idx+1;
}

int main(){

  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  int q = partition(0, n-1);
  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    if(i == q) cout << "[";
    cout << a[i];
    if(i == q) cout << "]";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3348
#include<bits/stdc++.h>
using namespace std;
int n,k,q;
string s;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>s>>q;
	while(q--){
		cin>>k;
		long long ans=0,dm=0,m=0,d=0;
		for(int i=0;i<n;i++){
			if(s[i]=='D')
				d++;
			if(s[i]=='M')
			{
				dm+=d;
				m++;
			}
			if(s[i]=='C')
				ans+=dm;
			if(i>=k-1){
				int p=i-k+1;
				if(s[p]=='D')
					dm-=m,d--;
				if(s[p]=='M')
					m--;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 1412
from collections import deque

N, M = list(map(int, input().split()))
graph = [deque() for i in range(N*3)]
visited = [False] * (N*3)

for i in range(M):
    u, v = list(map(int, input().split()))
    u, v = (u-1)*3, (v-1)*3

    graph[u].append(v+1)
    graph[u+1].append(v+2)
    graph[u+2].append(v)

S, T = list(map(int, input().split()))
S, T = (S-1)*3, (T-1)*3

q = deque([(S, 0)])
visited[S] = True
ans = -1

while q:
    u, cost = q.popleft()
    if u == T:
        ans = cost//3
        break
    else:
        for v in graph[u]:
            if not visited[v]:
                visited[v] = True
                q.append((v, cost+1))
print(ans)

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,k;
	cin>>n>>k;
	vector<ll> h(n+1,0);
	repi(i,1,n+1)cin>>h[i];

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

	vector<vector<ll>> dp(n+1,vector<ll>(n+1,1LL<<60));

	dp[0][0]=0;

	repi(i,1,n+1){
		repi(j,1,i+1){
			repi(l,1,i+1){
				dp[i][j] = min(dp[i][j], dp[i-l][j-1]+max(0LL,h[i]-h[i-l]));
			}
		}
	}

	ll ans=1LL<<60;
	rep(i,n+1) ans=min(ans, dp[i][n-k]);

	cout<<ans<<endl;

	// rep(i,n+1){
	// 	rep(j,n+1)cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


int main(){
  string s;
  cin >> s;
  
  rep(i,3){
    if(s[i] == '9') s[i] = '1';
    else if(s[i] == '1') s[i] = '9';
  }
  
  cout << s << endl;
}



Measured memory_bytes: 256