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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S;
signed main() {
    cin >> S;
    cout << count(all(S), '+') - count(all(S), '-') << endl;
}

Measured memory_bytes: 256
void main() {
  auto k = ri;
  auto s = rs;
  if (s.length <= k) writeln(s);
  else writeln(s[0..k] ~ "...");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
  return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
  return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
  auto res = new T[][](height, width);
  foreach(i; 0..height) {
    res[i] = readAs!(T[]);
  }
  return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
  auto res = new T[][](height, width);
  foreach(i; 0..height) {
    auto s = rs;
    foreach(j; 0..width) res[i][j] = s[j].to!T;
  }
  return res;
}

int ri() {
  return readAs!int;
}

long rl() {
  return readAs!long;
}

double rd() {
  return readAs!double;
}

string rs() {
  return readln.chomp;
}

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

using namespace std;

using seika = string;
template <class kizuna>
using akari = vector<kizuna>;

template <class T>
akari<pair<T, int>> RunLengthEncoding(akari<T> v)
{
    akari<pair<T, int>> res;
    int len = 0, n = v.size();
    T cur = v.front();
    for (int i = 0; i < n; i++)
    {
        if (cur == v[i])
        {
            len++;
        }
        else
        {
            res.push_back(make_pair(cur, len));
            cur = v[i];
            len = 1;
        }
    }
    res.push_back(make_pair(cur, len));
    return res;
}

int main(void)
{
    int n;
    cin >> n;
    akari<char> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    auto v = RunLengthEncoding(s);
    // for (auto &p : v)
    // {
    //     cout << p.first << ' ' << p.second << endl;
    // }
    cout << v.size() << endl;
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

#define lli long long
#define li long
#define vi vector<int>
#define vli vector<li>
#define vlli vector<lli>
#define pi pair<int,int>
#define pli pair<li, li>
#define vpi vector<pi>

#define mod 1000000007

using namespace std;
    
set<lli> brokens;

lli sum(lli a, lli b) {
    return ((a % mod) + (b % mod)) % mod;
}

lli multi(lli a, lli b) {
    return ((a % mod) * (b % mod)) % mod;
}

lli solve(lli DP[], lli n) {
    if(brokens.count(n)) return 0;
    if(n < 0) return 0;
    if(n == 0) return 1;

    if(DP[n] != -1) return DP[n];

    return DP[n] = sum(solve(DP, n-1), solve(DP, n-2));
}   

int main() {


    lli n, m;

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

    for(int i = 0; i < m; i++) {
        lli b;
        scanf("%lld", &b);
        brokens.insert(b);
    }

    lli DP[n+1];

    memset(DP, -1, sizeof(DP));
    lli ans = solve(DP, n);

    printf("%lld\n", ans);

}


Measured memory_bytes: 5760
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
typedef long long ll;
ll longinf=1ll<<60;
 
int N;
ll A[200003];
ll S[200003];
int i,k;
ll ans=0;
 
int main(){
    cin>>N;
    rep1(i,N) cin>>A[i];
    S[0]=0;
    rep1(i,N){
        S[i]=A[i]+S[i-1];
    }
    ans=longinf;
 
    REP(j,2,N-1){
        i=(lower_bound(S+1, S+j, S[j]/2)-S);
        if(abs(S[i]-S[j]/2)>abs(S[i-1]-S[j]/2)&&i>1){
            i=i-1;
        }
        k=(lower_bound(S+j+1, S+N, (S[N]-S[j])/2+S[j])-S);
        if(abs(S[k]-S[j]-(S[N]-S[j])/2)>abs(S[k-1]-S[j]-(S[N]-S[j])/2)&&k>j+1){
            k=k-1;
        }
        ll dif=longinf;
        dif=max({S[i],S[j]-S[i],S[k]-S[j],S[N]-S[k]})-min({S[i],S[j]-S[i],S[k]-S[j],S[N]-S[k]});
        ans=min(ans,dif);
    }
    cout<<ans<<endl;
 
 
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    string s;cin>>s;

    if(s=="ABC")cout<<"ARC\n";
    else cout<<"ABC\n";

    return 0;

}

Measured memory_bytes: 3628
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

i = 1
c = 0
lines[0][0].times {
  po = lines[i][0] ** 2 + lines[i][1] ** 2
  h = Math.sqrt(po)
  if h <= lines[0][1]
  	c += 1
  end
  i += 1
}
puts c


Measured memory_bytes: 28924
#include <stdio.h>

int main(void)
{
	int r,g,b,num;
	scanf("%d%d%d",&r,&g,&b);
	num = 100*r+10*g+b;
	if(num%4 == 0)
		{printf("YES");}
	else
		{printf("NO");}
	return 0;
}
		


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

int N,X;
int ans[200010] = {0};
bool used[200010] = {0};

int main()
{
    scanf("%d%d",&N,&X);
    if(N == 2)
    {
        if(X == 2)
        {
            printf("Yes\n");
            printf("1\n2\n3\n");
        }
        else printf("No\n");
        return 0;
    }
    N = N * 2 - 1;
    if(X == 1 || X == N)
    {
        printf("No\n");
        return 0;
    }
    if(X == 2)
    {
        ans[N / 2] = X;
        ans[N / 2 - 1] = X + 1;
        ans[N / 2 + 1] = X - 1;
        ans[N / 2 + 2] = X + 2;
        used[X] = used[X - 1] = used[X + 1] = used[X + 2] = true;
    }
    else
    {
        ans[N / 2] = X;
        ans[N / 2 + 1] = X - 1;
        ans[N / 2 - 1] = X + 1;
        ans[N / 2 - 2] = X - 2;
        used[X] = used[X + 1] = used[X - 1] = used[X - 2] = true;
    }
    int cnt = 1;
    for(int i = 0; i < N; i++)
    {
        if(ans[i] == 0)
        {
            while(used[cnt])cnt++;
            ans[i] = cnt;
            used[cnt] = true;
        }
    }
    printf("Yes\n");
    for(int i = 0; i < N; i++)printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 2432
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    
    int a1 = input.nextInt();
    int a2 = input.nextInt();
    int a3 = input.nextInt();
    
    int sum = a1 + a2 + a3;
    if (sum >= 22)
      System.out.println("bust");
    else
      System.out.println("win");
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-48;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    ll n;
    cin>>n;
    ll a[200005];
    ll sum=0,sum1=0,mod=1e9+7;
    ll s[200005];
    s[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s[i]=s[i-1]+a[i];
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+(((s[n]-s[i])%mod)*a[i])%mod)%mod;
    }
    if(ans<0)
    {
        cout<<ans+mod;
    }
    else
    {
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 6708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 10;
int a[maxn];

vector<int> bit[64]; //idx
inline void divide(ll x,int idx){
    bitset<64> bb(x); //
    for(unsigned int i=0;i<64;i++){
   // cout<<bb[i];
        if(bb[i]) bit[i].push_back(idx);
    }
  //  cout<<endl;
}
vector<int> st;
bitset<64> ans;
inline void Union(vector<int> a,vector<int> b,vector<int>& c){
    set<int> ms;
    for(auto& it:a) ms.insert(it);
    for(auto& it:b) if(ms.count(it)) c.push_back(it);
}
int main(){
  //  divide(12,0);divide(14,0);
    int n,k;scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    int idx=0;
    for(int i=1;i<=n;i++){
        ll sum=0;
        for(int j=i;j<=n;j++){
            sum+=a[j];
           // cout<<sum<<" ";
            divide(sum,++idx);
        }
    }

    int i;
    for(i=60;i>=0;i--){
        if(bit[i].size()>=k){
            for(auto& it:bit[i]){
                st.push_back(it);
            }
            ans[i]=1;
            break;
        }
    }
   // cout<<i<<endl;
    --i;
    for(;i>=0;i--){
   //     if(bit[i].size()<k) continue;
        vector<int> tmp;
        Union(st,bit[i],tmp);
        if(tmp.size()>=k){
            st=tmp;
            ans[i]=1;
        }
    }
    cout<<ans.to_ullong()<<endl;
}


Measured memory_bytes: 44624
#include<stdio.h>

int main(){
   int A,B,C,K;
   int count = 0;
   scanf("%d %d %d %d",&A,&B,&C,&K);
   while((A > 0) && (K > 0)){
      A--;
      K--;
      count++;
   }
    while((B > 0) && (K > 0)){
      B--;
      K--;
   }
     while((C > 0) && (K > 0)){
      C--;
      K--;
      count--;
   }
     printf("%d\n",count);
     return 0;
}


Measured memory_bytes: 1736
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll N, vector<ll> a) {
  vector<int> c(8);
  int cnt = 0;
  for (ll i: a) {
    if (i < 3200) c[i / 400] = 1;
    else ++cnt;
  }
  int sum = accumulate(ALL(c), 0);
  cout << max(1, sum) << " " << cnt + sum << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005];
int c[100005];
int d[100005];
int main(){
  int n; cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  for(int i=1;i<=n;++i){
    c[a[i-1]]++;
  }
  for(int i=1;i<=100000;++i){
    d[i] = d[i-1] + c[i-1];
  }
  int ans=0;
  for(int i=0;i<=100000;i++){
    ans = max(ans, d[i+3]-d[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
n,a,b = map(int,input().split())
d = 0
for i in range(1,n+1):
    k = (i//10000)%10+(i//1000)%10+(i//100)%10+(i//10)%10+i%10
    if a <= k and k <= b:
        d = d + i
print(d)

Measured memory_bytes: 2940
/*
[agc031] A - Colorful Subsequence
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
const int Z = 'z' - 'a' + 1;

int N;
string S;
ll cnt[Z];

ll solve() {
    for (int i = 0; i < N; i++) {
        cnt[S[i] - 'a']++;
    }

    ll ans = 1;
    for (int i = 0; i < Z; i++) {
        (ans *= cnt[i] + 1) %= MOD;
    }
    (ans += MOD - 1) %= MOD;

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 512
x,y=map(int,input().split())
cnt=0
cnt+=y-x
cnt1=1
cnt1+=y+x
cnt2=1
cnt2+=-y-x
cnt3=2
cnt3+=-y+x
a=[cnt,cnt1,cnt2,cnt3]
for i in range(4):
    if a[i]<0:
      a[i]=10000000000000000
print(min(a))

Measured memory_bytes: 3064
N = int(input())
ABC = []
for _ in range(N):
        a,b,c = map(int,input().split())
        ABC.append((a,b,c))

dpA = [ABC[0][0]]*N
dpB = [ABC[0][1]]*N
dpC = [ABC[0][2]]*N

for i in range(1, N):
        dpA[i] = max(dpB[i-1] + ABC[i][0], dpC[i-1] + ABC[i][0])
        dpB[i] = max(dpA[i-1] + ABC[i][1], dpC[i-1] + ABC[i][1])
        dpC[i] = max(dpA[i-1] + ABC[i][2], dpB[i-1] + ABC[i][2])
print(max(dpA[N-1], dpB[N-1], dpC[N-1]))

Measured memory_bytes: 66136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, a, b, ans = 0;
  cin >> n >> a >> b;
  for (int i = 1; i <= n;i++){
    int temp = i, sum = 0;
    while(temp>0){
      sum += temp % 10;
      temp /= 10;
    }
    if(sum>=a&&sum<=b){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>s(N);
	vector<int>t(N);
	vector<unsigned long long int>u(N);
	vector<unsigned long long int>v(N);
	for (auto &i : s)cin >> i;
	for (auto &i : t)cin >> i;
	for (auto &i : u)cin >> i;
	for (auto &i : v)cin >> i;
	vector<vector<unsigned long long int>>ans(N, vector<unsigned long long int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (s[i] && t[j]) {
				ans[i][j] = u[i] & v[j];
			}
			else if (!s[i] && !t[j]) {
				ans[i][j] = u[i] | v[j];
			}
			else if (!s[i]) {
				ans[i][j] = u[i];
			}
			else {
				ans[i][j] = v[j];
			}
		}
	}
	vector<vector<int>>h(N, vector<int>(64));
	vector<vector<int>>w(N, vector<int>(64));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < 64; k++) {
				if ((ans[i][j] >> k) & 1) {
					h[i][k]++;
					w[j][k]++;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (s[i] == 0)continue;
		for (int k = 0; k < 64; k++) {
			if (((u[i] >> k) & 1) && !h[i][k]) {
				for (int j = 0; j < N; j++) {
					if (t[j]) continue;
					if (w[j][k] + 1 < N) {
						w[j][k]++;
						ans[i][j] |= 1ULL << k;
						break;
					}
				}
			}
		}
	}
	for (int j = 0; j < N; j++) {
		if (t[j] == 0)continue;
		for (int k = 0; k < 64; k++) {
			if (((v[j] >> k) & 1) && !w[j][k]) {
				for (int i = 0; i < N; i++) {
					if (s[i])continue;
					if (h[i][k] + 1 < N) {
						h[i][k]++;
						ans[i][j] |= 1ULL << k;
						break;
					}
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (s[i]) {
			unsigned long long int box = 0;
			for (int j = 0; j < N; j++) {
				box |= ans[i][j];
			}
			if (box != u[i]) {
				cout << -1 << endl;
				return 0;
			}
		}
		else {
			unsigned long long int box = ULLONG_MAX;
			for (int j = 0; j < N; j++) {
				box &= ans[i][j];
			}
			if (box != u[i]) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	for (int j = 0; j < N; j++) {
		if (t[j]) {
			unsigned long long int box = 0;
			for (int i = 0; i < N; i++) {
				box |= ans[i][j];
			}
			if (box != v[j]) {
				cout << -1 << endl;
				return 0;
			}
		}
		else {
			unsigned long long int box = ULLONG_MAX;
			for (int i = 0; i < N; i++) {
				box &= ans[i][j];
			}
			if (box != v[j]) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	for (auto i : ans) {
		for (auto j : i)cout << j << " ";
		cout << endl;
	}
}


Measured memory_bytes: 7872
#include <iostream>

using namespace std;

long long int comb(long long int x, long long int y) {
    if(x==y || y==0) {
        return 1;
    }
    
    if(x-y<y) {
        return comb(x, x-y);
    }
    
    long long int res=1;
    for(int i=1; i<=y; i++) {
        res *= (x-i+1);
        res /= i;
    }
    return res;
}

int main() {
    int N, P;
    cin >> N >> P;
    long long int e_num=0, o_num=0;
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        if(A%2==0) {
            e_num++;
        } else {
            o_num++;
        }
    }

    long long int ans=0;
    for(long long int i=0; i<=o_num/2; i++) {
        if(o_num/2==0) break;
        ans += comb(o_num, i*2);
    }

    if(o_num/2==0 && P%2==0) {
        ans++;
    }
    for(int i=0; i<e_num; i++) {
        ans *= 2;
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>

signed main(){
long long n;
long long i;
long long sum=1;
long long a[100010]={};
scanf("%lld",&n);

for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
}
int zero=0;
for(i=0;i<n;i++)if(a[i]==0)zero++;


if(zero>0){
printf("0\n");
return(0);

}
for(i=0;i<n;i++){
    if(a[i]<=1000000000000000000/sum){
        sum*=a[i];
    }else{
        printf("-1\n");
        return (0);
    }

}

if(sum>1000000000000000000){
    printf("-1\n");
    return (0);
}
printf("%lld\n",sum);
return (0);
}

Measured memory_bytes: 2512
n,m = map(int,input().split())
a = list(int(input()) for i in range(m))

mod = 1000000007
b = [0]*(m + 1)
if m != 0:
    b[0] = a[0] - 1
    b[m] = n - a[m - 1] - 1
else:
    b[0] = n

for i in range(1,m):
    b[i] = a[i] - a[i-1] - 2

b.sort()
ans = 1
if b[0] == -1:
    ans = 0
else:
    pattern = [0]*(max(b[m]+1,2))
    pattern[0] = 1
    pattern[1] = 1
    for i in range(2,b[m]+1):
        pattern[i] = pattern[i-1] + pattern[i-2]
    for i in range(m + 1):
        ans *= pattern[b[i]]

print(ans % mod)


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

#define P(s) cout<<(s)<<"\n"
#define R(v) v.begin(),v.end()

int main() {
    int32_t a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    vector<int32_t> v{
        a * x + b * y,
        (x > y)
            ? (c * y * 2 + (x - y) * a)
            : (c * x * 2 + (y - x) * b),
        max(x, y) * 2 * c
    };

    P(*min_element(R(v)));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x[200];
int main()
{
    int n,sum=0,sum1=0,minn=2147483647;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
        sum+=x[i];
    }
    for(int i=1;i<=n;i++)
    {
        sum1+=x[i];
        sum-=x[i];
        minn=min(minn,abs(sum1-sum));
    }
    cout<<minn;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  rep(i, n) {
    int val;
    cin >> val;
    v.push_back(val);
  }
  sort(v.begin(), v.end());
  int result = 0;

  rep(i, k) result += v[i];
  cout << result << endl;
  return 0;
}

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

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

const double PI = 3.14159265358979323846;
const int mod = 1e9+7;
// int 1e9+7 double 1e-12 long long 1e18

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll R;
  cin >> R;
  if (R < 1200)
  {
    cout << "ABC" << endl;
  }else if (R < 2800) {
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
  
  return 0;
}


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

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

    vector<int> c(m);
    vector<int> dp(n+1, 10000);

    for(int i = 0; i < m; i++) {
        cin >> c[i];
    }    

    dp[0] = 0;

    for(int i = 0; i <= n; i++) {
        for(int j = 0; j < m; j++) {
            if(i+c[j] <= n) {
                dp[i+c[j]] = min(dp[i+c[j]], dp[i]+1);
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}


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

using namespace std;

#define fin(ans) cout << ans << endl

int main(void) {
  int num;
  int ans = 0;
  cin >> num;
  vector<int> vec(num);
  for (int i = 0; i < num; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < num-1; i++) {
    for (int j = i+1; j < num; j++) {
      ans += vec.at(i) * vec.at(j);
    }
  }
  fin(ans);
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

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

using namespace std;

typedef long long ll;

const int inf = 2e9;

int n, m;
int d[100][100];

int main(){
	scanf("%d%d", &n, &m);

	rep(i, n){
		fill_n(d[i], n, inf);
		d[i][i] = 0;
	}

	rep(i, m){
		int f, t, c;
		scanf("%d%d%d", &f, &t, &c);
		d[f][t] = c;
	}

	rep(k, n){
		rep(i, n){
			rep(j, n){
				if(d[i][k] != inf && d[k][j] != inf){
					d[i][j] = (int)min((ll)d[i][k] + d[k][j], (ll)d[i][j]);
				}
			}
		}
	}

	rep(i, n){
		if(d[i][i] < 0){
			puts("NEGATIVE CYCLE");
			return 0;
		}
	}
	
	rep(i, n){
		rep(j, n){
			if(j != 0){
				putchar(' ');
			}
			if(d[i][j] == inf){
				printf("INF");
			}
			else{
				printf("%d", d[i][j]);
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1068
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
 
let num=readInts()
let a=num[0]
let b=num[1]
let ans=a-2*b
if ans<0{
  print(0)
}else{
  print(ans)
}

Measured memory_bytes: 8252
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int x,n;
    cin >> x >> n;
    vector<bool> a(200, true);
    rep(i,n){
        int p; cin >> p;
        a[p] = false;
    }
    for(int d = 0; d < 110; ++d){
        if(a[x-d] == true){
            cout << x-d << endl;
            return 0;
        }
        else if(a[x+d] == true){
            cout << x+d << endl;
            return 0;
        }
    }




    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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


int main(){
	int n, m;
	cin >> n >> m;
	int a[m];
	int sum = 0;
	for(int i=0; i<m; ++i){
		cin >> a[i];
		sum += a[i];
	}
	if((n - sum)<0){
		cout << "-1" << endl;
	}else{
		cout << n-sum << endl;
	}
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <stdlib.h>
#define maxSize (int)(1e5 + 1)

int main(){
	int i;
	char *s, first, last;
	s = (char *)malloc(sizeof(char) * maxSize);
	scanf("%s", s);
	first = s[0];
	for(i = 1; ; i++){
		if(s[i] == '\0'){
			last = s[i - 1];
			break;
		}
	}
	if((first == last && i % 2 == 1) || (first != last && i % 2 == 0)){
		printf("Second\n");
	}
	else{
		printf("First\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
  
int puz[3][3];
int tmp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void empty(int *x,int *y) {
  int i,j;
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      if(!puz[i][j]) {
	*x = j;
	*y = i;
	return;
      }
    }
  }
}
   
void swap(int *a,int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}
  
int cal(){
  int i,a,sum=0; 
  for(i=0; i<9; i++){
    a = puz[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3) + abs(i%3 - a%3);
    }
  }    
  return sum;
}
  
int dfs(int x,int y,int p,int dep,const int lim){
    int i,h,nx,ny,res;   
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1; 
    for(i=0; i<4; i++){
        nx = x+dx[i];
        ny = y+dy[i];      
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;    
        swap(&puz[y][x],&puz[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;       
        swap(&puz[y][x],&puz[ny][nx]);
    }   
    return -1;
}  
  
int main() {
    int i,j,ans,x,y,l;
      
    for(i=0; i<3; i++){
        for(j=0; j<3; j++) scanf("%d",&puz[i][j]);
    }
       
    empty(&x,&y);
    for(l=0; l<100; l++){
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) tmp[i][j] = puz[i][j];
        }
          
        ans = dfs(x,y,-1,0,l);
        if(ans!=-1){
            printf("%d\n",ans);
            break;
        }
          
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) puz[i][j] = tmp[i][j];
        }
          
        ans = -1;
        if(l==99) printf("%d\n",ans);
    }
      
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int count = 0;
		for (int a = 0; a <= A; a++) {
			for (int b = 0; b <= B; b++) {
				for (int c = 0; c <= C; c++) {
					if (a * 500 + b * 100 + c * 50 == X) {
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}

}


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

using ll = long long;
const int maxn = 52, maxm = 103, maxa = 52;

int n, m;
ll starts, c[maxn], d[maxn], dp[maxn][maxa * maxm];
std::vector<std::tuple<int, ll, ll>> E[maxn];

std::priority_queue<std::tuple<ll, int, int>> q;

void update(int i, int c, ll w) {
    if(c < 0 || c >= maxa * maxm || dp[i][c] <= w)
        return;
    dp[i][c] = w;
    q.emplace(-w, i, c);
}

void solve() {
    update(1, std::min(starts, maxa * (ll)maxm - 1), 0);
    while(!q.empty()) {
        ll w; int i, mc;
        std::tie(w, i, mc) = q.top();
        q.pop();
        w = -w;
        if(w != dp[i][mc])
            continue;
        // fprintf(stderr, "%d %d %lld\n", i, mc, w);
        update(i, mc + c[i], w + d[i]);
        for(auto &&[v, cost, minute] : E[i])
            update(v, mc - cost, w + minute);
    }
}

int main() {
    scanf("%d%d%lld", &n, &m, &starts);
    for(int i = 0; i < m; ++i) {
        int u, v;
        ll a, b;
        scanf("%d%d%lld%lld", &u, &v, &a, &b);
        E[u].emplace_back(v, a, b);
        E[v].emplace_back(u, a, b);
    }
    for(int i = 1; i <= n; ++i) {
        scanf("%lld%lld", c + i, d + i);
    }
    memset(dp, 0x7f, sizeof(dp));
    solve();
    for(int i = 2; i <= n; ++i)
        printf("%lld\n", *std::min_element(dp[i], dp[i] + maxa * maxm));
    return 0;
}

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

int main(){
    int M,D,cou=0;
    cin>>M>>D;
    for(int i=2;i<M+1;i++){
        for(int j=22;j<D+1;j++){
            if(j/10>=2&&j%10>=2){
                if((j/10)*(j%10)==i){
                    cou++;
                }
            }
        }
    }
    cout<<cou<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	q := getNextInt(scanner)
	hp1 := &R64{}
	hp2 := &I64{}
	heap.Init(hp1)
	heap.Init(hp2)

	var p, bb, sum1, sum2 int64
	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		if t == 1 {
			a := getNextInt64(scanner)
			bb += getNextInt64(scanner)
			if hp1.Len() == 0 {
				heap.Push(hp1, a)
				sum1 += a
				continue
			}
			if hp2.Len() < hp1.Len() {
				p = heap.Pop(hp1).(int64)
				sum1 -= p
			} else {
				p = heap.Pop(hp2).(int64)
				sum2 -= p
			}
			if a < p {
				heap.Push(hp1, a)
				sum1 += a
				heap.Push(hp2, p)
				sum2 += p
			} else {
				heap.Push(hp1, p)
				sum1 += p
				heap.Push(hp2, a)
				sum2 += a
			}
			continue
		}
		p = heap.Pop(hp1).(int64)
		sum1 -= p
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", p, p*int64(hp1.Len())-sum1+sum2-p*int64(hp2.Len())+bb))
		heap.Push(hp1, p)
		sum1 += p
	}

	writer.Flush()
}

type I64 []int64

func (h I64) Len() int           { return len(h) }
func (h I64) Less(i, j int) bool { return h[i] < h[j] }
func (h I64) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *I64) Push(x interface{}) {
	*h = append(*h, x.(int64))
}
func (h *I64) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

type R64 []int64

func (h R64) Len() int           { return len(h) }
func (h R64) Less(i, j int) bool { return h[i] > h[j] }
func (h R64) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *R64) Push(x interface{}) {
	*h = append(*h, x.(int64))
}
func (h *R64) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  vector<char> a;
  if(s[0]==s[1] && s[1]==s[2] && s[2]==s[3]){
    cout<<"No"<<endl;
  }
  else if((s[0]==s[1] && s[2]==s[3]) || (s[0]==s[2] && s[1]==s[3]) || (s[0]==s[3] && s[1]==s[2])){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[10^^5] CS;

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];

    auto S = readln.chomp.to!(char[]);

    auto pre = 'T';
    foreach (i, c; S) {
        if (i) CS[i] = CS[i-1];
        if (pre == 'A' && c == 'C') ++CS[i];
        pre = c;
    }

    foreach (_; 0..Q) {
        auto lr = readln.split.to!(int[]);
        auto l = lr[0]-1;
        auto r = lr[1]-1;

        writeln(CS[r] - CS[l]);
    }
}

Measured memory_bytes: 4476
n,m=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(1,max(m,n)+1):f.append(f[i-1]*i%mod)
def comb(n,r):return f[n]*pow(f[r],mod-2,mod)*pow(f[n-r],mod-2,mod)%mod
def pern(n,r):return f[n]*pow(f[n-r],mod-2,mod)%mod
a=[0]*(n+1)
a[n]=1
for i in range(n-1,-1,-1):
    a[i]=(comb(n,n-i)*pern(m-i,n-i)-a[i+1])%mod
print(a[0]*pern(m,n)%mod)


Measured memory_bytes: 127176
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+1):
        k = n - i -j
        if k < 0:
            continue
        else:
            x = 10000*i+5000*j+1000*k
            if x == y:
                print(i, j, k)
                exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define pb emplace_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

int main(){
    fastio;
  
	lli n, w; cin >> n >> w;
	vector<lli> weight(n), value(n);
	for(int i=0; i<n; i++) cin >> weight[i] >> value[i];
	
	lli sum_value = 0;
	for(lli x: value) sum_value += x;
	
	vector<lli> dp(sum_value+1, INT_MAX);
	dp[0] = 0;
	
	for(int i=0; i<n; i++){
		for(int val = sum_value; val >= value[i]; val--){
			dp[val] = min(dp[val], dp[val-value[i]]+weight[i]);
		}
	}
	
	lli ans = 0;
	for(int i=0; i<sum_value+1; i++){
		if(dp[i] <= w) ans = max(ans, (lli)i);
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define rep(i,n) REP(i,n);
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep(i,n) RREP(i,n)
#define mp make_pair
#define fi first
#define sc second
ll a,b,c;

int main(){
	cin >> a >> b >> c;

	if(a == b && b == c) {
		cout << 1 << endl;
	}else if(a == b || b == c || c == a)
		cout << 2 << endl;
	else {
		cout << 3 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x,y,flag=0,i;
  cin >> x >>y;
  if(y%2==0){
  for(i=1;i<=x;i++)
  {
    if(y==(i*4)+(x-i)*2 || y==(x-i)*4+(i*2))
    {
      flag=1;
      break;
    }
  }
  }else
    flag=0;
  
  if(flag==1)
    cout<<"Yes";
  else
    cout <<"No";
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> d(n);
    rep(i, n) cin >> d[i].first >> d[i].second;
    int Max = 0;
    int ans = 0;
    rep(i, n) {
        if (d[i].first == d[i].second) {
            Max++;
        } else {
            if (d[i-1].first == d[i-1].second) {
                ans = max(Max, ans);
            }
            Max = 0;
        }
    }
    ans = max(Max, ans);
    if (ans >= 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n), dp(n, 1);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    ll ans = 0;
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    rep(i, n) {
        int idx = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        dp[i] *= idx;
    }
    
    rep(i, n) {
        int idx = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        dp[i] *= (n - idx);
    }
    
    rep(i, n) {
        ans += dp[i];
    }
    
    cout << ans << endl;
    return 0;
}

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

int power(int p,int n){
     int back=p;
    for(int i=0;i<n-1;i++){
         back *=p;
    }
    return back;
}
int main(){
     int A;
     cin >>A;
     cout << A+power(A,2)+power(A,3)<<endl;
}


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

int n;
int arr[100005];
int dp[100005];
long long int cost(int x)
{
	if(dp[x] != -1)return dp[x];
	if(x==n)return 0;
	if(x == n-1)return abs(arr[x+1]-arr[x]);
	dp[x+1] = cost(x+1);
	dp[x+2] = cost(x+2);
	dp[x] = min(abs(arr[x+1]-arr[x])+dp[x+1], abs(arr[x+2]-arr[x])+dp[x+2]);
	return dp[x];
} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>arr[i];
	for(int i=0;i<100005;i++)dp[i] = -1;
	cout<<cost(1)<<endl;
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int H[20];
int N;
int A[20];
int x[20][20],y[20][20];

int dfs(int count,int H[]){
  if(count==N+1) return 0;
  if(count==N){
    int out=0;
    for(int i=0;i<N;i++){
      if(H[i]==1){
        for(int j=0;j<A[i];j++){
          if(y[i][j]!=H[x[i][j]-1]){
            out=1;
          }
        }
      }
    }
    if(out==0){
      int C=0;
      for(int i=0;i<N;i++){
        C+=H[i];
      }
      if(ans<C) ans = C;
    }
  }
  H[count]=1;
  dfs(count+1,H);
  H[count]=0;
  dfs(count+1,H);
}

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i];
    for(int j=0;j<A[i];j++){
      cin >> x[i][j] >> y[i][j];
    }
  }
  dfs(0,H);
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        int a=0;
        for(int i=0;i<=x;i++) {
        	int j=x-i;
        	if(2*i+4*j==y) {
        		System.out.println("Yes");
        		a=1;
        	}
        }
        if(a==0)	System.out.println("No");
    }
}

Measured memory_bytes: 35748
import sys

if __name__ == "__main__":
    n,w = map(int,input().split())
    W = []
    V = []
    for i in range(n):
        a,b = map(int,input().split())
        W.append(a)
        V.append(b)
    dp = [[0]*(w+1) for i in range(n+1)]
    for i in range(n+1):
        for j in range(w+1):
            if i == 0 or j == 0:
                dp[i][j] = 0
            elif W[i-1] <= j:
                dp[i][j] = max(dp[i-1][j-W[i-1]]+V[i-1],dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[-1][-1])

Measured memory_bytes: 120300
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  vector<int> a(3);
  for(int i=0; i<3; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0; i<3; i++){
    if(i){
      cout << " ";
    }
    cout << a[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3116
/************************************************************
	> File Name: d.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Mon 27 Apr 2020 07:24:27 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <ext/rope>
#define lowbit(x) (x&-x)
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int INF = 0x3f3f3f3f;
const LL INF_ll = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int mod = 2019;
signed main(void){
	string s;
	cin >> s;
	vll d(SZ(s)+1);
	int ten = 1;
	for(int i = SZ(s)-1;i >= 0;i--){
		int a = (s[i]-'0') * ten % mod;
		d[i] = (d[i+1]+a)%mod;
		ten *= 10;
		ten %= mod;
	}
	vll cnt(SZ(s)+1);
	LL ans = 0;
	for(int i = SZ(s);i >= 0;i--){
		ans += cnt[d[i]];
		cnt[d[i]]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6652
S = list(map(int, input()))
N = len(S)
count1 = 0
count2 = 0
if N == 1:
    print(0)
    exit()
for a in range(N):
    if a % 2 == 0:
        if S[a] != 0:
            count1 += 1
    else:
        if S[a] != 1:
            count1 += 1

for a in range(N):
    if a % 2 == 0:
        if S[a] != 1:
            count2 += 1
    else:
        if S[a] != 0:
            count2 += 1

print(min(count1, count2))

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n, T;

int t[105], c[105];

int main() {

	FAST;

	cin >> n >> T;
	for (int i = 1; i <= n; i ++) {
		cin >> c[i] >> t[i];
	}	
	int ans = 1005;
	for (int i = 1; i <= n; i ++) {
		if (t[i] <= T) {
			ans = min(ans, c[i]);
		}
	}
	if (ans == 1005) {
		cout << "TLE\n";
	}
	else {
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  ll n, a, b;
  cin >> n >> a >> b;
  ll res1 = 0, res2 = 0, res3 = 0;
  if(abs(a - b) % 2 == 1){
    ll a2 = 1;
    ll b2 = b - a;
    res1 += a;
    res1 += (b2 - a2) / 2;
    ll b3 = n;
    ll a3 = a + (n - b + 1);
    res2 += n - b + 1;
    res2 += (b3 - a3) / 2;
    cout << min(res1, res2);
  }
  else{
    cout << (b - a) / 2;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0){
      break;
    }
    int p,d,d2;
    int mxl=0,mxd=0;
    for(int i=0;i<n;i++){
      cin>>p>>d>>d2;
      if(mxl<d+d2){
	mxl=d+d2;
	mxd=p;
      }
    }
    cout<<mxd<<' '<<mxl<<endl;
  }
  return(0);
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull B=1e9+7;
ull Hash(vector<int> &v){
  ull h=0;
  for(int i=0;i<26;i++)h=h*B+v[i];
  return h;
}

int main(){
  string a,b;
  cin>>a>>b;
  int ans=0,n=a.size(),m=b.size();
  
  for(int i=1;i<=n;i++){
    unordered_set<ull> S;
    vector<int> v(26,0);
    for(int j=0;j<n;j++){
      if(i==j)S.insert(Hash(v));
      v[a[j]-'a']++;
      if(j>=i) {
	v[a[j-i]-'a']--;
	S.insert(Hash(v));
      }
    }
    S.insert(Hash(v));
    v=vector<int>(26,0);
    for(int j=0;j<m;j++){
      if(i==j&&S.count(Hash(v)))ans=i;
      v[b[j]-'a']++;
      if(j>=i){
	v[b[j-i]-'a']--;
	if(S.count(Hash(v)))ans=i;
      }    
    }
    if(S.count(Hash(v)))ans=i;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
const int INF = 2147483647;

#define MAX_E 2001
#define MAX_V 2001
map<int,int> mp;

//隣接リスト表現。
struct edge{
  int to;
};
typedef pair<int, int> P;//firstは最短距離、secondは頂点の番号

int V,E;                //頂点数、辺数
vector<edge> G[MAX_V];  //隣接リスト。各頂点にedgeがある分をつなげる。
int d[MAX_V];           //頂点sからの最短距離

//隣接リストデータinput。
void input_graph(int x,int y){
  REP(i,E-1){
    G[i].push_back({i+1});
    G[i+1].push_back({i});
  }
  G[x].push_back({y});
  G[y].push_back({x});  
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d+V, INF);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p=que.top(); que.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    REP(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+1){
        d[e.to]=d[v]+1;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  REP(i,V) mp[d[i]]++;
}

int main(){
  int x,y;
  cin>>V>>x>>y;E=V;x--;y--;
  input_graph(x,y);
  REP(i,V) dijkstra(i);
  REP(i,V) if(i) cout<<mp[i]/2<<endl;
}

Measured memory_bytes: 512