akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
}

struct node {
	int id;
	string name;
	int s;
}res[100+5];

bool cmp(node a, node b)
{
	if (a.name == b.name)
		return a.s > b.s;
	return a.name < b.name;
}

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> res[i].name;
		cin >> res[i].s;
		res[i].id = i;
	}
	sort(res + 1, res + 1 + n, cmp);
	for (int i = 1; i <= n; i++)
		cout << res[i].id << endl;
	return 0;
}

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

int main()
{
    int A, B;
    cin >> A >> B;

    if (A <= 9 and B <= 9)
    {
        cout << A*B << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void PRINT(T container, bool withSize) { if(withSize) cout<<container.size()<<endl; for(auto it : container) cout<<it<<" "; cout<<endl; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

const int MOD = 1e9+7;

/**
 * Calculate inverse of a mod b.
 * https://codeforces.com/blog/entry/23365
 */
ll inverseModulo(ll a, ll b){
    return 1<a ? b - inverseModulo(b % a, a) * b / a : 1;
}
ll binomial(int n, int k) {
    if(k>n)
        return 0;
    ll x=1;
    RNG(i,1,k) {
        x = x * (n + 1 - i) % MOD;
        x = x * inverseModulo(i, MOD) % MOD;
    }
    return x;
}


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

    int n,k; cin>>n>>k;
    vi a = readVector<int>(n);

    ll nck = binomial(n-1, k-1);

    ll ans=0;
    sort(ALL(a));

    FOR(i,n) {
        int cf = n-1-i;
        ll ways = nck;
        if(cf<k-1) break;

        nck = nck * (n-k-i) % MOD;
        nck = nck * inverseModulo(n-1-i, MOD) % MOD;

        ans -= ways * a[i];
        ans %= MOD;

        ans += ways * a[n-1-i];
        ans %= MOD;
    }

    cout<<(ans+MOD)%MOD<<endl;

    return 0;
}



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

int main(){
    int a, b;
    
    cin >> a >> b;
    
    if(a < -1000 || a > 1000 || b < -1000 || b > 1000){
        return 1;
    }
    
    if(a > b){
        cout << "a > b" << endl;
    }else if(a < b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N=200005;

ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}

int count = 0;
 
int CountTriangles(vector <int> A){  
  
    int n=A.size(); 
  
    sort(A.begin(), A.end());  
  
     int co=0;
      
    for( int i = n-1; i >= 1; i--){ 
        int l = 0, r = i-1; 
        while( l < r){ 
            if( A[l] + A[r] > A[i]){ 
  
                // If it is possible with a[l], a[r] 
                // and a[i] then it is also possible 
                // with a[l+1]..a[r-1],a[r] and a[i] 
                co += r - l ;  
  
                //checking for more possible solutions 
                r--;   
            } 
            else 
  
                // if not possible check for  
                // higher values of arr[l] 
                l++;   
        } 
    } 
    return co;
} 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif*/
    cout<<fixed<<setprecision(15);
    
    ll n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    int ans=CountTriangles(a);

    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,k[20],s[20][20],p[20],sum=0;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>k[i];
		for(int j=1;j<=k[i];j++)
		{
			cin>>s[i][j];
		}
	}
	for(int i=1;i<=m;i++)
	{
		cin>>p[i];
	}
	for(int i=0;i<(1<<n);i++)
	{
		int t=0;
		for(int j=1;j<=m;j++)
		{
			int count=0;
			for(int k=1;k<=m;k++)
			{
				if(i&(1<<(s[j][k]-1)))count++;
			}
			if(count%2==p[j])t++;
			else break;
		}
		if(t==m)sum++;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;


int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  string s; cin >> s;
  for (char &c : s) if (c == '?') c = 'D';
  kek(s);
}


Measured memory_bytes: 4120
import collections,sys
d=collections.deque()
input()
for e in sys.stdin:
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.pop()
  else:d.popleft()
print(*d)


Measured memory_bytes: 69728
#include <stdio.h>
#define N 100000
 
typedef struct{
  int left,right,p;
}Node;

Node tree[N];

int n;
 
void in(int);
void post(int);
void pre(int);

 
 
main(void){
  int i, id;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    tree[i].left = -1;
    tree[i].p = -1;
    tree[i].right = -1;
  }
  
  for(i = 0; i < n; i++){

    scanf("%d", &id);

    scanf("%d %d", &tree[id].left, &tree[id].right);

      tree[tree[id].left].p = id;
      tree[tree[id].right].p = id;

    }   
 
  printf("Preorder\n");
  for(i = 0; i < n; i++){
    if(tree[i].p == -1){
      pre(i);
    }
  }

  printf("\nInorder\n");
  for(i = 0; i < n; i++){
    if(tree[i].p == -1){
      in(i);
    }
  }

  printf("\nPostorder\n");
  for(i = 0; i < n; i++){
    if(tree[i].p == -1){
      post(i);
    }
  }
  printf("\n");
  return 0;
}



void in(int p){
  if(p != -1) {
    in(tree[p].left);
    printf(" %d", p);
    in(tree[p].right);
  }
}
 
void post(int p){
if(p != -1) {
    post(tree[p].left);
    post(tree[p].right);
    printf(" %d", p);
  }
}
 
void pre(int p){
if(p != -1) {
  printf(" %d", p);
  pre(tree[p].left);
  pre(tree[p].right);
  }
}
 

Measured memory_bytes: 616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

template<class T> class segtree {
	int n;
	vector<T> data;
	T id = P(INF, -1);
	T operation(T a, T b) {
		if (a.first < b.first) return P(a.first, a.second);
		return P(b.first, b.second);
	}
public:
	segtree(int _n) {
		n = 1;
		while (n < _n + 2) n <<= 1;
		data = vector<T>(2 * n, id);
		rep(i, 2 * n) data[i].second = i;
	}
	void change(int i, T x) {
		i += n;
		data[i] = x;
		while (i > 1) {
			i >>= 1;
			data[i] = operation(data[i << 1], data[i << 1 | 1]);
		}
	}
	void add(int i, T x) { change(i, data[i + n] + x); }
	T get(int a, int b) {
		T left = id; T right = id;
		a += n; b += n;
		while (a < b) {
			if (a & 1) left = operation(left, data[a++]);
			if (b & 1) right = operation(data[--b], right);
			a >>= 1; b >>= 1;
		}
		return operation(left, right);
	}
	T get_all() { return data[1]; }
	T operator[](int i) { return data[i + n]; }
};

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

	int n, q;
	cin >> n >> q;
	vector<ll> a(q);
	rep(i, q) cin >> a[i];
	segtree<P> seg(q + 1);
	seg.change(0, P(n, 0));
	rep(i, q) seg.change(i + 1, P(a[i], i + 1));
	vector<ll> use; int idx = 0;
	while (idx <= q) {
		P p = seg.get(idx, q + 2);
		use.pb(p.first);
		idx = p.second + 1;
	}
	reverse(all(use));
	priority_queue<P> que;
	que.push(P(use[0], 1));
	for (int i = 1; i < use.size(); i++) {
		map<ll, ll> mp;
		while (!que.empty()) {
			P p = que.top();
			if (p.first < use[i]) break;
			que.pop();
			mp[use[i]] += p.first / use[i] * p.second;
			if (p.first%use[i]) mp[p.first%use[i]] += p.second;
		}
		for (auto j : mp) que.push(P(j.first, j.second));
	}
	vector<ll> ans(n + 2);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ans[1] += p.second;
		ans[p.first + 1] -= p.second;
	}
	for (int i = 1; i <= n; i++) ans[i] += ans[i - 1];
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int n; cin >> n;
    V<ll> a(n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }

    ll tmp = 0;
    for(int i = 1; i < n; i+=2){
        tmp += 2 * a[i];
    }

    V<ll> ans(n);
    ans[0] = sum - tmp;
    for(int i = 1; i < n; i++){
        ans[i] = 2 * a[i - 1] - ans[i - 1];
    }

    for(int i = 0; i < n; i++){
        if(i != n - 1) cout << ans[i] << " ";
        else cout << ans[i] << endl;
    }
}


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

int main(){

  long long a, b, r, x, tmp;
  
  cin >> a >> b;
 
  x = a * b;
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  
  cout << x/b << endl;
 
  return 0;
  
}




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

int main(){
    int n;
    int a,b,c,d;
    cin >> n;
    a = n / 1000;
    b = n / 100 % 10;
    c = n / 10 % 100 % 10;
    d = n % 1000 % 100 % 10;
    if (a == b && b == c && c == a) {
        cout << "Yes";
    }else if (b == c &&  c == d && d == b) {
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
//
// Created by prana on 2020-05-13.
// Facebook Hacker Cup
//

#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>

using  namespace std;

int main() {

    int n;
    cin >> n;

    int p = ceil((double) n/1000);

    cout << (p*1000) - n << endl;


    return 0;
}

Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second
const int N = 5566;
ll gao(vector<pll>&v,int k,ll n)
{
    int i = k;
    if (k < 0)
        return n;
    if (k == 0)
        return n/v[0].F*v[0].S+n%v[0].F;
    ll ret = n;
    for (ll x = 0; x * v[i].F <= n; ++x)
        ret = max(ret, x * v[i].S + gao(v,k-1,n-x*v[i].F));
    return ret;
}
ll gao(ll a[],ll b[],ll n)
{
    vector<pll> v;
    for (int i = 0; i < 3; ++i)
        if (a[i] < b[i])
            v.emplace_back(a[i],b[i]);
    int k = v.size();
    return gao(v,k-1,n);
}
ll a[3],b[3];
int main()
{
    ll n;
    cin >> n;
    for (int i = 0; i < 3; ++i)
        cin >> a[i];
    for (int i = 0; i < 3; ++i)
        cin >> b[i];
    n = gao(a,b,n);
    cout << gao(b,a,n) << endl;
}


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

int main(){
    int N, A, B;
    int result = 0;
    cin >> N >> A >> B;
    for (int i = 1; i <= N;i++){
        int sum = 0;
        int num = i;
        while (1)
        {
            sum += num % 10;
            num = num / 10;
            if(num==0)
                break;
        }
        if((A<=sum)&&(sum<=B)){
            result += i;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iterator>
//#include<chrono>
//#include<mt19937>
using namespace std;
typedef long long int llint;
const int big=1e9+100000;
const llint mod=1e9+7;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define res resize
#define ins insert
#define era erase
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
//N^2+NM
//一回ごとにいもす
int main(void){
	llint i,j,n,m;cin>>n>>m;
	llint q,ans=0;
	vector<llint>dis(n+1);
	vector<llint>happy(n+1);//その店からスタートした時の食べる焼き肉のおいしさの総和
	vector<vector<llint>> yaki(m);//yaki[チケット名][店名] 美味しさ
	vector<vector<llint>> mae(m);//前のおいしい店
	vector<llint>imo(n+2);//いもす法
	dis[0]=-1e15;//番兵
	for(i=2;i<=n;i++){cin>>q;dis[i]=dis[i-1]+q;}
	for(i=0;i<m;i++){yaki[i].res(n+1);mae[i].res(n+1);}
	for(i=1;i<=n;i++){
		for(j=0;j<m;j++){
			cin>>yaki[j][i];
		}
	}
	for(j=0;j<m;j++){yaki[j][0]=big;}//番兵　海外の焼き肉店？
	for(i=1;i<=n;i++){
		llint gen=0;
		for(j=0;j<m;j++){
			llint bef=i-1;
			llint ois=0;
			while(yaki[j][bef]<yaki[j][i]){
				imo[bef]-=yaki[j][bef]-ois;
				ois=yaki[j][bef];
				bef=mae[j][bef];
			}
			imo[i]+=yaki[j][i];
			imo[bef]-=yaki[j][i]-ois;
			mae[j][i]=bef;
		}
		for(j=i;j>0;j--){
			imo[j]+=imo[j+1];
			happy[j]+=imo[j];
			maxeq(ans,happy[j]+dis[j]-dis[i]);
		}
		for(j=0;j<=n;j++){imo[j]=0;}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 18048
import sys
import numpy as np
import scipy.sparse
f=scipy.sparse.csgraph.floyd_warshall
def main():
  t=np.fromstring(sys.stdin.buffer.read(),int,sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  d=f(f(scipy.sparse.csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]]
  d[d>n]=0
  print('\n'.join((d.astype(int)-1).astype(str).tolist()))
main()

Measured memory_bytes: 30856
/*@shutoshsuman99*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define rem1 998244353
#define inf 1e18+1e17
#define F first
#define S second
#define pii pair<long long,long long>
#define p_q priority_queue <ll, vector<ll>, greater<ll> >
#define m_sp multiset <pair <ll,ll> > 
#define el "\n"
#define sp " "
typedef long long ll;
ll Pow(ll x,ll y,ll m) 
{ if (y == 0) return 1; ll p = Pow(x, y/2, m) % m; 
p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m; } 
main()
{ 
	// fast io
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);ll i,j; 
	ll n,m;
	cin>>n>>m;
	vector <ll> v[m],a(m);
	for(i=0;i<m;i++)
	{
		ll k;
		cin>>k;
		for(j=0;j<k;j++)
		{
			ll z;
			cin>>z;
			v[i].push_back(z-1);
		}
	}
	for(i=0;i<m;i++)
	cin>>a[i];
	ll cnt1=0;
	for(i=0;i<(1<<n);i++)
	{
		ll f=1;
		for(j=0;j<m;j++)
		{
			ll cnt=0;
			for(auto x:v[j])
			{
				if(i&(1<<x))
				cnt++;
			}
			if(cnt%2!=a[j])
			f=0;
		}
		if(f)
		cnt1++;
	}
	cout<<cnt1<<el;
}

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

int main(void){
  int n, m;
  vector<int> x, y;
  cin >> n >> m;
  x.resize(n + 1);
  y.resize(m + 1);
  cin >> x[0] >> y[0];
  for (int i = 1; i <= n; i++)
    cin >> x[i];
  for (int i = 1; i <= m; i++)
    cin >> y[i];
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  cout << (x[n] >= y[0] ? "War" : "No War") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && a != c)
    cout << "Yes" << endl;
  else if (a == c && b != a)
    cout << "Yes" << endl;
  else if (b == c && a != b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

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

int main() {
  //
  ll x;
  cin >> x;
  ll cnt = 2 * (x / 11);
  ll remain = x % 11;
  if (remain == 0) {
    // do nothing
  } else if (remain <= 6) {
    cnt += 1;
  } else {
    cnt += 2;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
K,A,B=map(int,input().split())
b_count=1
b_chenge_count=0

if B-A<=2:
    b_count+=K
else:
    b_chenge_count=max(0,int((K-(A-1))/2))
    b_count=b_chenge_count*(B-A)+(A)+(K-(A-1)-b_chenge_count*2)

print(b_count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> sum(n + 1);
	rep(i, n) {
		if (s.substr(i, 2) == "AC") sum[i + 1]++;
		sum[i + 1] += sum[i];
	}
	while (q--) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << sum[r] - sum[l] << endl;
	}
	return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<60;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int n,int m){
    ll dl[256][256],ds[256][256];
    fill_n((ll*)dl,256*256,infll);
    fill_n((ll*)ds,256*256,infll);
    rep(i,0,256) dl[i][i]=ds[i][i]=0;
    rep(i,0,m){
        int x,y;
        ll t;
        char sl;
        cin >> x >> y >> t >> sl;
        --x;
        --y;
        if(sl=='L'){
            dl[x][y]=min(dl[x][y],t);
            dl[y][x]=min(dl[y][x],t);
        }else{
            ds[x][y]=min(ds[x][y],t);
            ds[y][x]=min(ds[y][x],t);
        }
    }
    int r,z[1000];
    cin >> r;
    rep(i,0,r){
        cin >> z[i];
        --z[i];
    }

    rep(k,0,n) rep(i,0,n) rep(j,0,n) dl[i][j]=min(dl[i][j],dl[i][k]+dl[k][j]);
    rep(k,0,n) rep(i,0,n) rep(j,0,n) ds[i][j]=min(ds[i][j],ds[i][k]+ds[k][j]);

    ll dp[1000][256];
    fill_n((ll*)dp,1000*256,infll);
    rep(i,0,n) dp[0][i]=ds[z[0]][i]+dl[i][z[0]];
    rep(i,1,r) rep(j,0,n) rep(k,0,n){
        if(k!=j) dp[i][j]=min(dp[i][j],dp[i-1][k]+dl[z[i-1]][k]+ds[k][j]+dl[j][z[i]]);
        else dp[i][j]=min(dp[i][j],dp[i-1][k]+dl[z[i-1]][z[i]]);
    }

    ll ans=infll;
    rep(i,0,n) ans=min(ans,dp[r-1][i]);
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    while(true){
        int n,m;
        cin >> n >> m;
        if(n==0 and m==0) break;
        solve(n,m);
    }
    return 0;
}

Measured memory_bytes: 6172
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {

   int N,M,X;
   cin >> N >> M>> X;
   int C[N];
   int A[N][M];
   for(int i=0;i<N;i++){
      cin >> C[i];
         for(int j=0;j<M;j++){
            cin >> A[i][j];
         }
   }

   int a=0;
   int b=pow(2,N);
  
   int P[N],Q[b];
   int R[M];
   long long int mm=1000000000;
   int flag=0;
   for(long long int i=0;i<pow(2,N);i++){
      a=i;
      Q[i]=0;
      flag=0;
      for(int j=0;j<M;j++){
      R[j]=0;
   		}
      for(int j=0;j<N;j++){
        P[j]=a%2;
        a=a/2;
      }
     
      for(int k=0;k<N;k++){
         for(int l=0;l<M;l++){
            R[l]+=P[k]*A[k][l];
         }
        Q[i]+=P[k]*C[k];
      }
      
      for(int l=0;l<M;l++){
            if(R[l]<X){
            flag=1;
            }
      }
      if(flag==0){
      	mm=(mm>Q[i]?Q[i]:mm);
      }
   }
  if(mm!=1000000000){
  cout << mm << endl;
  }else{
    cout << -1 << endl;
  }     

}

Measured memory_bytes: 4108
#!/usr/bin/env python3
import sys

def solve(A: int, B: float):
    # b_i = int((B - int(B))*100)
    # print(b_i)
    # b = int((A*b_i)//100)
    # a = A*int(B) + b
    # # print(b)
    # print(a)

    print(A*int(B*1000)//1000)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = float(next(tokens))  # type: float
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include<stdio.h>
int main(void)
{
 int a,b,d,r;
 
 double f;
 
scanf("%d %d",&a,&b);

 d=0;
 r=0;
 f=0;

 d=a/b;

 r=a%b;

 f=1.0*a/b;


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

 return 0;

}


Measured memory_bytes: 2704
s = gets.chomp
key = "keyence"

if s[0] != "k" || s[-1] != "e"
    puts s =~ /.*#{key}.*/ ? "YES" : "NO"
else
    i = 0
    i += 1 while i < 8 && s[i] == key[i]
    j = 0
    j += 1 while j < 8 && s[-j] == key[-j]

    puts i + j >= 8 ? "YES" : "NO"
end

Measured memory_bytes: 3836
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,A,B;
ll h[100010];
ll binarySearch(function<bool(ll)> check, ll ok, ll ng) {
  while ((ok - ng > 1) || (ng - ok > 1)) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  return ok;
}
bool Check(ll n){
    ll cnt=0;
    for(ll i=0;i<N;i++){
        if(h[i]-n*B > 0){
            cnt+=(h[i]-n*B-1)/(A-B)+1;
        }
    }
    return cnt<=n;
}
int main(){
    cin>>N>>A>>B;
    for(ll i=0;i<N;i++){
        cin>>h[i];
    }
    cout<<binarySearch(Check,1'000'000'000,0)<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    if(max(x,y)%min(x,y)==0)return min(x,y);
    return gcd(max(x,y)%min(x,y),min(x,y));
}
int main(){
    int x,y;
    cin>>x>>y;
    cout<<gcd(x,y)<<endl;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for(int i = 0; i < m; ++i){
        cin >> l[i] >> r[i];
    }
    sort(begin(l), end(l), greater<int>());
    sort(begin(r), end(r));
    cout << max(r[0] - l[0] + 1, 0) << "\n";
    return 0;
}

Measured memory_bytes: 1024
num_input=input().split()   
x=int(num_input[0])
y=int(num_input[1])
ans="No"
n=-1
for i in range(x+1):
    n=n+1
    ans_num=n*2+(x-n)*4
    if ans_num==y:
        ans="Yes"
print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = pow(a, n / 2);
	if(n % 2 == 0) return res * res;
	else return a * res * res;
}

ll root(ll a, ll n) {
	if(n == 1) return a;
	else if(n == 2) {
		ll lv = -1, rv = 10000000;
		while(rv - lv > 1) {
			ll m = (lv + rv) / 2;
			if(pow(m, n) <= a) lv = m;
			else rv = m;
		}
		return lv;
	}
	else {
		ll m = 1;
		while(pow(m + 1, n) <= a) m++;
		return m;
	}
}

ll N, A;

ll func(ll x, ll T) {
	ll l = x / T;
	ll a = (l + 1) * T - x, b = x - l * T;
	ll div = pow(l, a) * pow(l + 1, b);
	return A * T + x + (N + div - 1) / div;
}

void solve() {
	cin >> N >> A;
	ll ans = N;
	rep(T, 1, 40 + 1) {
		ll s = root(N, T + 1);
		ll sum = s * (T + 1);
		ll mul = pow(s, T + 1);
		// debug(T, sum, mul);
		rep(i, 0, T + 2) {
			if(mul >= N) {
				MIN(ans, A * T + sum);
				break;
			}
			mul /= s;
			mul *= (s + 1);
			sum++;
		}
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
//cout << fixed << setprecision(10);


int main(){
    ll n,m; cin>>n>>m;
    cout<<n*(n-1)/2 + m*(m-1)/2;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
#define ri register int
typedef long long ll;
#define rll register ll
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: putc;
using io :: print;
const int N=(1<<17)+5;
int tot,lc[N],rc[N],val[N];
ll mid;
inline void addedge(ri x,ri y){
	if(!lc[x])
		lc[x]=y;
	else
		rc[x]=y;
}
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
vector<pa> v[N];
inline vector<pa> modify(vector<pa> &v1,vector<pa> &v2){
	vector<pa> ans;
	ri p=-1;
	for(auto o:v1){
		while(p+1<v2.size()&&o.second+v2[p+1].first<=mid) ++p;
		if(p>=0&&(ans.empty()||ans.back().second>v2[p].second))
			ans.pb(mp(o.first,v2[p].second));
	}
	return ans;
}
inline void merge(vector<pa> &ans,vector<pa> v1,vector<pa> v2){
	ri i,j;
	i=j=0;
	while(i<v1.size()&&j<v2.size())
		if(v1[i]<v2[j]){
			if(ans.empty()||ans.back().second>v1[i].second)
				ans.pb(v1[i]);
			++i;
		}
		else{
			if(ans.empty()||ans.back().second>v2[j].second)
				ans.pb(v2[j]);
			++j;
		}
	while(i<v1.size()){
		if(ans.empty()||ans.back().second>v1[i].second)
			ans.pb(v1[i]);
		++i;
	}
	while(j<v2.size()){
		if(ans.empty()||ans.back().second>v2[j].second)
			ans.pb(v2[j]);
		++j;
	}
}
inline void dfs(ri x){
//	printf("dfs %d %d %d\n",x,lc[x],rc[x]);
	v[x].clear();
	if(!lc[x]){
		if(val[x]<=mid) v[x].pb(mp(val[x],val[x]));
		return;
	}
	dfs(lc[x]);dfs(rc[x]);
	merge(v[x],modify(v[lc[x]],v[rc[x]]),modify(v[rc[x]],v[lc[x]]));
	for(auto &o:v[x])
		o.first+=val[x],
		o.second+=val[x];
//	puts("-------");
//	printf("x = %d\n",x);
//	for(auto o:v[x]) printf("%lld %lld\n",o.first,o.second);
//	puts("-------");
}
int main(){
	ri n,i,x;
	rll l,r;
	l=r=0;
	gi(n);
	for(i=2;i<=n;++i) gi(x),gi(val[i]),addedge(x,i),r+=val[i];
	while(l<=r){
		mid=l+r>>1;
	//	printf("mid = %lld\n",mid);
		dfs(1);
		if(!v[1].empty())
			r=mid-1;
		else
			l=mid+1;
	}
	printf("%lld\n",r+1);
	return 0;
}

Measured memory_bytes: 32672
n,k = list(map(int, input().split()))
b =[0]*n

for i in range(k):
    d = int(input())
    dk = list(map(int, input().split()))
    #print(dk)
    for j in range(d):
        #print(dk[j])
        b[dk[j] - 1] += 1
#print(b)
ans = 0
for i in range(len(b)):
    if b[i] == 0:
        ans +=1
print(ans)

Measured memory_bytes: 9108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var sides = Console.ReadLine()
                .Split(' ')
                .Select(int.Parse);

            var sortedSides = sides.OrderBy(side => side);

            // 実装1（愚直に）
            //if (sortedSides.Last() < sortedSides.Sum() - sortedSides.Last())
            //{
            //    Console.WriteLine("Yes");
            //}
            //else
            //{
            //    Console.WriteLine("No");
            //}

            // 実装2（こっちのほうが効率がいいかも？）
            if (sortedSides.Last() < sortedSides.Take(sortedSides.Count() - 1).Sum())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000
int main(){
    ll n;cin>>n;
    cout<<"0 0 1000000000 1 ";
    ll y=(n+inf-1)/inf;
    ll x=y*inf-n;
    cout<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t,ans="";//ans为最后的答案，赋为空
int i,j,r;
int main(){
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE";
        return 0;
    }//大坑，必须判断s的长度会不会比t小(我被坑了3次QAQ)
    for(i=0;i<=s.size()-t.size();i++){//枚举t从哪个地方开始
        int k=i;//将i替换为k
        string ss=s;//将s替换为ss
        j=0;//初始化为0
        while(j<t.size()){
            if(ss[k]=='?')//如果为'?'，替换
                ss[k]=t[j];
            else if(s[k]!=t[j])//否则，如果不匹配，退出
                break;
            k++;//匹配则继续匹配
            j++;
        }
        if(j==t.size()){//如果完美匹配
            for(r=0;r<ss.size();r++){
                if(ss[r]=='?')//把'?'替换为'a'
                    ss[r]='a';
            }
            if(ans=="")//如果ans为空，将ans变为ss
                ans=ss;
            else ans=min(ans,ss);//否则,取字典序最小的
        }
    }
    if(ans=="")//若ans为空
        cout<<"UNRESTORABLE";
    else cout<<ans;//输出ans
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;

void ARC080C()
{
	int N;
	cin >> N;
	vector<int> an(3);
	for (int i = 0; i < N; ++i)
	{
		long long y;
		cin >> y;
		if (y % 4 == 0)
			++an[0];
		else if (y % 2 == 0)
			++an[1];
		else
			++an[2];
	}
	bool isOk = false;
	if (an[2] <= an[0] && an[0] > 0)
		isOk = true;
	if (an[2] == an[0] + 1 && an[1] == 0 && an[0] > 0)
		isOk = true;
	if (an[2] == 0)
		isOk = true;
	string ret = isOk ? "Yes" : "No";
	cout << ret << endl;

}
int main()
{
	ARC080C();
	return 0;
}


Measured memory_bytes: 256
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();
        int ans = 0;
        int[] lights = new int[m];
        int[] p = new int[m];

        for (int i = 0; i < m; i++) {
            int k = sc.nextInt();

            int state = 0;

            for (int j = 0; j < k; j++) {
                int s = sc.nextInt();

                state += (1 << (s - 1));
            }

            lights[i] = state;
        }

        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
        }

        for (int i = 0; i < (1 << n); i++) {
            boolean check = true;

            for (int j = 0; j < m; j++) {
                int cond = Integer.bitCount(i & lights[j]);

                if (cond % 2 != p[j]) {
                    check = false;
                    break;
                }
            }

            if (check) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

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

typedef long long ll;

int N,K;
ll mod = 924844033;
ll dp[4010][4010][2];
ll F[100010] = {1};
bool mem[4010];
ll ans;

int main()
{
    scanf("%d%d",&N,&K);

    int now = 0;
    for(int i = 0; i < N % K * 2; i++)
    {
        now += N / K;
        mem[now] = true;
        now++;
    }
    for(int i = 0; i < (K - N % K) * 2; i++)
    {
        now += N / K - 1;
        mem[now] = true;
        now++;
    }

    for(int i = 1; i < 100010; i++)F[i] = F[i - 1] * i % mod;

    dp[0][0][0] = 1;
    for(int i = 0; i < N * 2; i++)
    {
        for(int j = 0; j <= N * 2; j++)
        {
            if(mem[i])
            {
                dp[i + 1][j][0] += dp[i][j][1] + dp[i][j][0];
            }
            else
            {
                dp[i + 1][j][0] += dp[i][j][0] + dp[i][j][1];
                dp[i + 1][j + 1][1] += dp[i][j][0];
            }
            dp[i + 1][j][0] %= mod;
            dp[i + 1][j + 1][1] %= mod;
        }
    }

    for(int i = 0; i <= N; i++)
    {
        ll tmp = dp[N * 2][i][0] + dp[N * 2][i][1];
        tmp = tmp * F[N - i] % mod;
        if(i % 2)ans -= tmp;
        else ans += tmp;
        ans = (ans + mod) % mod;
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 252032
#include <bits/stdc++.h>
using namespace std;
const int M = 2*1e6 + 10;

int main() {
    int n; cin >> n;
    vector<int> unique;
    vector<int> ok(M, 0);
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        if (ok[a] == 0) {
            unique.push_back(a);
            ok[a] = 1;
        }
        else if (ok[a] == 1) {
            ok[a] = -1;
        }
    }
    for (int i: unique) {
        for (int j=i*2; j<M; j+=i) {
            ok[j] = 0;
        }
    }
    int cnt = 0;
    for (int i=1; i<M; ++i) {
        if (ok[i] == 1) cnt++; 
    }
    cout << cnt << endl;
}

Measured memory_bytes: 12112
n = int(input())
a = list(map(int, input().split(" ")))


a2 = [x for x in a if x % 2 == 0]
if len(a2) == 0: # 偶数ない
    print("APPROVED")
    exit()

a3 = [x for x in a2 if x % 3 == 0 or x % 5 == 0]
if len(a3) == len(a2): # 偶数の数と3,5の倍数の数が一致
    print("APPROVED")
    exit()

print("DENIED")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i = 0 ;i < n; i++)
        cin>>a[i];
    int b[n] = {0};
    b[1] = abs(a[1] - a[0]);
    for(int i = 2; i < n; i++)
    {
        b[i] = min(b[i-2] + abs(a[i] - a[i-2]),b[i-1] + abs(a[i] - a[i-1]));
    }    

    cout<<b[n-1];
}

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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	int S = s.size();
	int t[10];
	int k[10];
	rep(i, S) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') t[i] = 1;
		else t[i] = 0;
		if (t[i] == 0) k[i] = 0;
		else if (i > 0 && t[i - 1] == 1) k[i] = k[i - 1] + 1;
		else k[i] = 1;
		ans = max(ans, k[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()) {
      int N = in.nextInt();
      int X = in.nextInt();
      int count = 1;
      int pos = 0;
      
      for (int i = 0; i < N; ++i) {
        pos += in.nextInt();

        if (pos <= X) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using vll = vector<long long>;

long long calc_score(int idx, int N, long long K, const vll & As, const vll & Bs){
    // 二進数表記での各桁の上から下 idx + 1桁目までが K に含まれ、
    // 下 idx 桁目がゼロである整数（As[i])の価値の和を求める。
    long long head = K >> (idx + 1);
    long long p = ((idx == -1) ? 0 : (1 << idx));
    long long score = 0;
    for (int i = 0; i < N; ++i){
        if (not(As[i] & p) and ((As[i] >> (idx + 1)) | head) == head){
            score += Bs[i];
        }
    }
    return score;
}


long long solve(int N, long long K, const vll & As, const vll & Bs){
    long long ans = 0;
    for (int idx = -1; (1 << idx) <= K; ++idx){
        if ((idx == -1) or K & (1 << idx)) ans = max(ans, calc_score(idx, N, K, As, Bs));
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    long long K;
    cin >> N >> K;
    vll As(N);
    vll Bs(N);
    for (int i = 0; i < N; ++i){
        cin >> As[i] >> Bs[i];
    }
    cout << solve(N, K, As, Bs) << endl;
    return 0;
}

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

using namespace std;

int main(void){
    vector<int> mountains(10);
    for(int i=0;i < 10;i ++)
    {
        cin >> mountains[i];
    }
    sort(mountains.begin(),mountains.end(),greater<int>());
    cout << mountains [0] << endl;
    cout << mountains [1] << endl;
    cout << mountains [2] << endl;

    return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>

int main() {
    int n;
    int a[105], b[105],minlist[105];
    scanf("%d",&n);
    for (int i = 0; i < 105; ++i) {
        a[i] = -1;
        b[i] = -1;
        minlist[i] = 100010;
    }
    for (int i = 0; i < n-1; ++i) {
        scanf("%d",&b[i]);
        minlist[i] = b[i];
    }

    //MINLIST TIMEEE
    int z,j;
    for (int i = 0; i < n-1; ++i) {
        for (j = i + 1; j < n; ++j) {
            if (minlist[i] > minlist[j])  {
                z = minlist[i];
                minlist[i] = minlist[j];
                minlist[j] = z;
            }
        }
    }

    //for (int i = 0; i < n-1; ++i) {
         //printf("%d\n", minlist[i]);
    //}
    for (int i = 0; i < n-1; ++i) {
        for (int j = 0; j < n-1; ++j) {
            if (minlist[i] == b[j]) {
                if ((a[j] > b[j])||(a[j] == -1)) {
                    a[j] = b[j];
                    //printf("a[%d]: %d\n",j,a[j]);
                }
                //printf("a[%d+1]: %d\n",j,a[j+1]);
                if ((a[j+1] > b[j])||(a[j+1] == -1)) {
                    a[j+1] = b[j];
                    //printf("a[%d+1]: %d\n",j,a[j+1]);
                }
            }
        }
    }
    int summ = 0;
    for (int i = 0; i < n; ++i) {
        summ = summ + a[i];
        //printf("%d\n", a[i]);
    }
    printf("%d\n",summ);


    return 0;
}


Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        a: f32,
        b: f32,
        x: f32
    }

    let ans = if 2.0*x>a*a*b {
        (180.0/std::f32::consts::PI)*(2.0*(a*a*b-x)/(a*a*a)).atan()
    } else {
        (180.0/std::f32::consts::PI)*((a*b*b)/(2.0*x)).atan()
    };

    println!("{}",ans)
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

inline int power(int a,int b,const int mod)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%mod;
		b>>=1;
		a=(ll)a*a%mod;
	}
	return ans;
}

const int maxn=2.5e5+20;

#define pii pair<int,int>

int n;
int seed[3],inv[3],mod[3];
pii f[3][maxn],g[3][maxn];
char str[maxn];

inline void init()
{
	n=read();
	seed[1]=141937; mod[1]=1e9+7; inv[1]=power(seed[1],mod[1]-2,mod[1]);
	seed[2]=181; mod[2]=998244353; inv[2]=power(seed[2],mod[2]-2,mod[2]);
	scanf("%s",str+1); 
}

unordered_map<ll,int>mp;

inline void doing()
{
	ll ans=0;
	REP(op,1,2)
	{
		function < pii (pii ,pii )> mult =[&](pii a,pii b) {
			return mkr((a.fi+(ll)a.se*b.fi)%mod[op],(ll)a.se*b.se%mod[op]);
		};
		f[op][0]=mkr(0,1); g[op][0]=mkr(0,1);
		REP(i,1,n)
		{
			if(str[i]=='+')f[op][i]=mult(f[op][i-1],mkr(1,1)), g[op][i]=mult(mkr(mod[op]-1,1),g[op][i-1]);
			else if(str[i]=='-')f[op][i]=mult(f[op][i-1],mkr(mod[op]-1,1)),g[op][i]=mult(mkr(1,1),g[op][i-1]);
			else if(str[i]=='>')f[op][i]=mult(f[op][i-1],mkr(0,seed[op])),g[op][i]=mult(mkr(0,inv[op]),g[op][i-1]);
			else f[op][i]=mult(f[op][i-1],mkr(0,inv[op])),g[op][i]=mult(mkr(0,seed[op]),g[op][i-1]);
		}
	}
	ll A=f[1][n].fi,B=f[2][n].fi;
	DREP(i,n,1)
	{
		ll x=(ll)f[1][i].fi*mod[1]+f[2][i].fi;
		mp[x]++;
		ll y=0;
		ll a=(ll)(A-g[1][i-1].fi+mod[1])*power(g[1][i-1].se,mod[1]-2,mod[1])%mod[1];
		ll b=(ll)(B-g[2][i-1].fi+mod[2])*power(g[2][i-1].se,mod[2]-2,mod[2])%mod[2];
		y=(ll)a*mod[1]+b;
		if(mp.count(y))ans+=mp[y];
	}
	printf("%lld\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

mat c;
lli h,w;
mat a;
lli ans = 0;

int main(){
	cin >> h >> w;
	c = mat(10,vll(10));
	for(lli i = 0;i < 10;i++){
		for(lli j = 0;j < 10;j++){
			cin >> c[i][j];
		}
	}
	a = mat(h,vll(w));
	for(lli i = 0;i < h;i++){
		for(lli j = 0;j < w;j++){
			cin >> a[i][j];
		}
	}
	for(lli i = 0;i < 10;i++){
		for(lli j = 0;j < 10;j++){
			for(lli k = 0;k < 10;k++){
				c[j][k] = min(c[j][k],c[j][i]+c[i][k]);
			}
		}
	}
	for(lli i = 0;i < h;i++){
		for(lli j = 0;j < w;j++){
			if(a[i][j] >= 0)
			ans += c[a[i][j]][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

int main(void){
    int N,K;
  	scanf("%d%d", &N,&K);
  	long long int ans =0;
	for(int i=K;i<N+2;i++){
      long long int max=0;
      long long int min=0;
      max = N+N-i+1;
        max = max*i/2;
      min = i-1;
      min = min*i/2;
		ans = ans + max-min+1;
      }
  	ans = ans % 1000000007;
      printf("%lld",ans);
	}

Measured memory_bytes: 3256
D = int(input())
C = list(map(int ,input().split()))
S = [list(map(int, input().split())) for i in range(D)]
sumc = sum(C)
last = [0 for i in range(26)]

ans = 0
for i in range(D):
    t = int(input())
    last[t-1] = i+1
    ans += S[i][t-1]
    for j in range(26):
        ans -= C[j]*(i+1 - last[j])
    print(ans)

Measured memory_bytes: 9396