akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#define int long long
using namespace std;
const int N = 2555,M = 5555;


int32_t main(){
	cin.tie(0)->sync_with_stdio(0);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	#endif
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]&&(a[i]!=a[j])&&(a[j]!=a[k])&&(a[i]!=a[k]))
				{
					ans++;
				}
			}
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<long long> x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  int max=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
        break;
      }
      
      int d=x[i]-x[j];
      if(d<0){
        d=-d;
       }
      if(d>max){
        max=d;
      }
    }
  }
  cout<<max<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int how(int a)
{
	int cnt=0;
	for(int i=1;i<=a;i++)
	{
		if(a%i==0) cnt++;
	}
	if(cnt==8) return 1;
	else return 0;
}
int main()
{
	int n,x=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(how(i)==1 && i%2!=0) x++;
	 } 
	 cout<<x;
	 return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    int d=0,e=0,f=0;
    char s='a';
    for(int i=0;i<a.size()+b.size()+c.size();i++){
    	if(s=='a'){
    		s=a[d];
    		if(d==a.size()){cout<<'A'<<endl;return 0;}
    		d++;
    	}
    	if(s=='b'){
    		s=b[e];
    		if(e==b.size()){cout<<'B'<<endl;return 0;}
    		e++;
    	}
    	if(s=='c'){
    		s=c[f];
    		if(f==c.size()){cout<<'C'<<endl;return 0;}
    		f++;
    	}
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
int main() {
  int N, C, K; cin >> N >> C >> K;
  map<int, int>T;
  int t;
  for (int i{0}; i < N; ++i) {
    cin >> t; ++T[t];
  }

  int total{0};

  for (auto& kv : T) {
    int temp = kv.second; kv.second = 0;
    if (temp % C != 0) {
      decltype(T)::iterator it = T.lower_bound(kv.first + 1);
      decltype(T)::iterator last = T.upper_bound(kv.first + K);
      while (it != last) {
        int add = MIN(C - temp % C, it->second);
        temp += add; it->second -= add;
        if (temp % C == 0) break;
        ++it;
      }
    }
    total += (temp + (C - 1)) / C;
  }

  cout << total << "\n";
  return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#define N 2000
#define INF 1000000
#define White 0
#define Gray 1
#define Black 2

int n, A[N][N];
int prim();

int main(){
  int  i, j, e;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d",&e);
      if(e == -1) A[i][j] = INF;
      else A[i][j] = e;
    }
  }

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

  return 0;
}

int prim(){
  int i, u, v, minc;
  int data[N], parent[N], color[N];
  int sum = 0;

  for(i=0; i<n; i++){
    data[i]= INF;
    parent[i] = -1;
    color[i] = White;
  }
  data[0] = 0;

  while(1){
    minc = INF;
    for(i=0; i<n; i++){
      if(minc>data[i] && color[i] != Black){
	u = i;
	minc = data[i];
      }
    }

    if(minc == INF) break;
    color[u] = Black;

    for(v=0; v<n; v++){
      if(color[v] != Black && A[u][v] != INF){
	if(data[v]>A[u][v]){
	  data[v] = A[u][v];
	  parent[v] = u;
	  color[v] = Gray;
	}
      }
    }
  }

  for(i=0; i<n; i++){
    if(parent[i] != -1){
      sum += A[i][parent[i]];
      /* printf("%d",sum); */
    }
  }
  return sum;
}

Measured memory_bytes: 1040
def checker(bbit,listN,N):
    i = 0
    j = 0
    ng = False
    #print(N)
    #print(listN)
    #print(bin(bbit))
    while N > i :
        j=0
        checkFig = 3
        ibit = 1 << i
        while N > j :
            cbit = 1 << j
            if bbit & cbit == 0 :
                #print("A:{} {}".format(j,i))
                pass
            elif listN[j][i] == 3 :
                #print("B:{} {}".format(j,i))
                pass
            elif (listN[j][i] == 0) and (bbit & ibit != 0):
                ng = True
                break
            elif (listN[j][i] == 1) and (bbit & ibit == 0):
                ng = True
                break
            elif checkFig == 3 :
                #print("C:{} {}".format(j,i))
                checkFig = listN[j][i]
            elif checkFig != listN[j][i] :
                ng = True
                #print("D:{} {}".format(j,i))
                break
            j += 1
        if ng :
            #print(ng)
            break
        else :
            i +=1
    return (not ng)


def main():
    N = int(input())
    listA = [[3 for j in range(N)] for k in range(N)]
    n = 0
    while N > n :
        a = int(input())
        i = 0
        while a > i:
           x,y  = map(int,input().split())
           listA[n][x-1] = y
           i += 1
        n += 1
        
    honestBit = pow(2, N)-1
    honest = 0
    
    while honestBit > 0:
        ok = checker(honestBit,listA,N)
        if ok :
            okbit = honestBit
            oknum = 0
            while okbit > 0 :
                oknum += (okbit % 2) 
                okbit = okbit >> 1
            if oknum > honest :
                honest = oknum 
        honestBit -= 1
    print(honest)
    

main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

#define N 1000000

static int k_operafan[ N ] = { 0, 0, 1 };
static int n_operafan = 3;

static int
isPrime (
  int n
  )
{
  int i;

  if ( n < 2
    || !( n % 2 ) ) return ( 0 );

  for ( i = 3; i * i <= n; i += 2 )
  {
    if ( !( n % i ) ) return ( 0 );
  }

  return ( 1 );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int n;

    if ( scanf ( "%d", &n ) != 1 ) break;

    for ( ; n_operafan <= n; ++n_operafan )
    {
      k_operafan[ n_operafan ] = k_operafan[ n_operafan - 1 ]
                               + !!( isPrime ( n_operafan ) );
    }

    printf ( "%d\n", k_operafan[ n ] );
  }

  return ( 0 );
}

Measured memory_bytes: 4304
#include <cstdio>
#include <algorithm>
#define LL long long
#define M 3000
#define INF 1e15
//1e15由来:换钱耗时+旅行耗时=(D*A*N)+(B*N)50*=10^9*50*50+10^9*50
using namespace std;
//3010由来，旅行最多经过N个点(N-1条边)，每条边最多花费50,故总花费50*50=2500,再大些，取3010
LL dp[55][3010];//换钱耗时+旅行耗时=(D*A*N)+(B*N)50*=10^9*50*50+10^9*50很明显int不够用
int c[55],d[55],head[55],tot;
struct node{
	int to,next,a,b;
}e[105*2];//无向图
void add_edge(int u,int v,int a,int b){//邻接表
	tot++,e[tot].to=v,e[tot].a=a,e[tot].b=b,e[tot].next=head[u],head[u]=tot;
}
int main(){
	int n,m,s,u,v,a,b,i,j,flag;
	scanf("%d%d%d",&n,&m,&s);
	for(i=1;i<=m;i++){
		scanf("%d%d%d%d",&u,&v,&a,&b);
		add_edge(u,v,a,b),add_edge(v,u,a,b);//无向图
	}
	for(i=1;i<=n;i++)scanf("%d%d",&c[i],&d[i]);
	for(i=1;i<=n;i++)
		for(j=0;j<=M;j++)//注意j从0开始,因最终目标是求dp[i][0],故j从0开始
			dp[i][j]=INF;
	s=min(s,M);//银币太多，无用
	dp[1][s]=0;//初始位置情况
	while(1){
		flag=0;
		for(u=1;u<=n;u++){//u所处节点
			for(j=0;j<=M;j++)//j手上银币数量
				if(j>=c[u]&&dp[u][j]>dp[u][j-c[u]]+d[u]) dp[u][j]=dp[u][j-c[u]]+d[u];//先换钱,01背包
			for(j=0;j<=M;j++)
				for(b=head[u];b;b=e[b].next){//再旅行
					v=e[b].to;
					if(j>=e[b].a&&dp[v][j-e[b].a]>dp[u][j]+e[b].b)//j消耗掉e[b].a，才能到j-e[b].a状态 v->u->1
						flag=1,dp[v][j-e[b].a]=dp[u][j]+e[b].b;//动归dp,状态转移
				}
			for(j=M-1;j>=0;j--)dp[u][j]=min(dp[u][j],dp[u][j+1]);//清空手头的银币，但不消耗时间
		}
		if(!flag)break;//Bellman-Ford优化
	}
	for(i=2;i<=n;i++)printf("%lld\n",dp[i][0]);
	return 0;
}

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

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll n, m, s, t;
vector<vector<ll>> adj;
vector<vector<bool>> vis;
vector<ll> dist;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    adj.assign(n, vector<ll>());
    F0R(i, m)
    {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].pb(b);
    }
    cin >> s >> t;
    s--; t--;
    vis.assign(n, vector<bool>(3, false));
    dist.assign(n, -1);
    // vtx, step # 
    queue<pair<ll, ll>> q;
    q.push({s, 0});
    dist[s] = 0;
    while(!q.empty())
    {
        pair<ll, ll> cur = q.front();
        q.pop();
        F0R(i, sz(adj[cur.f]))
        {
            if(!vis[adj[cur.f][i]][(cur.s + 1 )%3])
            {
                vis[adj[cur.f][i]][(cur.s + 1 )%3] = true;
                if((cur.s + 1 )%3 == 0) dist[adj[cur.f][i]] = (cur.s + 1)/3;
                q.push({adj[cur.f][i], (cur.s + 1)});
            }
        }
    }
    cout << dist[t];
    return 0;
}

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

int main() {
	int A, B, N;
	cin >> A >> B >> N;
  
    vector<int> F(A);
    for(int i = 0; i < A; i++) cin >> F.at(i);
  
    vector<int> R(B);
    for(int i = 0; i < B; i++) cin >> R.at(i);

    vector<vector<int>> C(N, vector<int>(3));
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
          cin >> C.at(i).at(j);
        }
      }
  
    int ans = 1001001;

    for(int i = 0; i < N; i++){
      int price = 0;
		price = F.at(C.at(i).at(0)-1) + R.at(C.at(i).at(1)-1) - C.at(i).at(2);
        ans = min(ans, price);
    }

    sort(F.begin(), F.end());
    sort(R.begin(), R.end());
  
	cout << min (ans, F.at(0)+R.at(0)) << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define lint long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<lint,lint> P;
const lint inf=1e18+7;
const int MOD=1000000007;
struct Nums{
    long long n;
    vector<long long> kaijo;
    Nums(int N){
        n=N;
        kaijo.push_back(1);
        for(long long i=1;i<=n;i++){
            kaijo.push_back((kaijo[i-1]*i)%MOD);
        }
    }
    long myPow(long x, long n, long m){
        if(n == 0)
            return 1;
        if(n % 2 == 0)
            return myPow(x * x % m, n / 2, m);
        else
            return x * myPow(x, n - 1, m) % m;
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
    long long comb(long long N,long long K,long long rest){
        long long res=kaijo[N]*modinv(kaijo[K],rest)%rest;
        res*=modinv(kaijo[N-K],rest);
        res%=rest;
        return res;
    }
};

lint gcd(lint a,lint b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
}
signed main(){
  lint n;cin>>n;
  vector<lint> a(n);
  vector<lint> b(n);
  map<P,lint> memo;
  Nums lib(n+5);
  lint cnt0=0;
  lint a0=0;lint b0=0;
  rep(i,n){
      cin>>a[i]>>b[i];
      if(a[i]==0&&b[i]==0){
          cnt0++;
          continue;
      }
      if(a[i]==0){
          ++a0;
          continue;
      }
      if(b[i]==0){
          ++b0;
          continue;
      }
    lint ba=abs(a[i]);lint bb=abs(b[i]);
    lint g=gcd(ba,bb);
    if(a[i]<0){
        a[i]*=-1;b[i]*=-1;
    }
    P buf={a[i]/g,b[i]/g};
    memo[buf]+=1;
  }
  lint res=1;
  for(auto it=memo.begin();it!=memo.end();++it){
      lint buf=0;
      P mp;
      if(it->second==0){
          continue;
      }
      mp.first=(it->first).second;
      mp.second=(it->first).first;
      
      if(mp.first<0){
          mp.first*=-1;
          //mp.second*=1;
      }
      else{
          mp.second*=-1;
      }
      lint cur=0;
      auto it2=memo.find(mp);
      if(it2!=memo.end()){
          cur+=it2->second;
          it2->second=0;
      }
      /*
      mp.first*=-1;
      mp.second*=-1;
      auto it3=memo.find(mp);
      if(it3!=memo.end()){
          cur+=it3->second;
          it3->second=0;
      }*/
      buf=lib.myPow(2,it->second,MOD);
      buf+=lib.myPow(2,cur,MOD)-1+MOD;
      buf%=MOD;
      res*=buf;
      res%=MOD;
      it->second=0;
  }
  res*=lib.myPow(2,a0,MOD)+lib.myPow(2,b0,MOD)-1;
  res%=MOD;
  res+=cnt0+MOD-1;
  res%=MOD;
  cout<<res<<"\n";
  return 0;
}

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

vector<int> a;

bool rec(int i, int s){
    if(i==0){
        if(s==0) return true;
        else return false;
    }
    return rec(i-1,s) || rec(i-1,s-a[i-1]);
}

int main() {
    int n, q;
    cin >> n;
    a.resize(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cin >> q;
    for(; q>0; q--){
        int m;
        cin >> m;
        cout << (rec(n,m) ? "yes" : "no") << endl;
    }
    return 0;
}



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

namespace White_Cells
{
    public class Program
    {
        static void Main(string[] args)
        {
            //マス目作成
            string[] s = Console.ReadLine().Split(' ');
            int line = int.Parse(s[0]);
            int column = int.Parse(s[1]);
            //列・行指定
            string[] s2 = Console.ReadLine().Split(' ');
            int nline = int.Parse(s2[0]);
            int ncolumn = int.Parse(s2[1]);
            int wcells = Solve(line, column, nline, ncolumn);
            Console.WriteLine(wcells);
        }

        public static int Solve(int l, int c, int nl, int nc)
        {
            int wcells = l * c;
            int bcells = (nl * c) + (l * nc) - (nl * nc);
            wcells -= bcells;
            return wcells;
        }
    }
}


Measured memory_bytes: 11092
/**
 * Problem:	A. 
 * Author:	hkxadpall. 
 * Date:	2018-09-01. 
 * Upload:	AtCoder. 
 */
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue> 
#include <map>
#include <set>
using namespace std;

namespace AuthorName { 
    template <typename _TpInt> inline _TpInt read();
    template <typename _TpRealnumber> inline double readr();
    template <typename _TpInt> inline void write(_TpInt x);
//	template <typename _TpSwap> inline void swap(_TpSwap &x, _TpSwap &y);
	
#	define Max_N 1007
	
	int n, m, a[Max_N];
	
	int main() 
	{
		n = read<int>();
		write((n >> 1) * ((n + 1) >> 1));
	    return 0;
	}

#	define Getchar() getchar()

    template <typename _TpInt>
    inline _TpInt read()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpInt init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = (init << 3) + (init << 1) + (c & 15);
        return init * flag;
    }

    template <typename _TpRealnumber>
    inline double readr()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpRealnumber init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init * 10 + (c & 15);
        if (c != '.') return init * flag;
        register _TpRealnumber l = 0.1;
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init + (c & 15) * l, l *= 0.1;
        return init * flag;
    }

    template <typename _TpInt>
    inline void write(_TpInt x)
    {
        if (x < 0) {
            putchar('-');
            write<_TpInt>(~x + 1);
        }
        else {
            if (x > 9) write<_TpInt>(x / 10);   
            putchar(x % 10 + '0');
        }
    }

//	template <typename _TpSwap>
//	inline void swap(_TpSwap &x, _TpSwap &y)
//	{
//	    _TpSwap t = x;
//	    x = y;
//	    y = t;
//	}
}

int main()
{
    AuthorName::main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vl h(n);
  REP(i, n) { cin >> h[i]; }
  sort(h.rbegin(), h.rend());
  ll ans = 0;
  REP(i, n) {
    if (i >= k)
      ans += h[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

bool judge(int N);

int main(){
    int N;
    cin >> N;
    bool yes = judge(N);
    if(yes)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

bool judge(int N){
    if(N == 0)
        return true;
    else if(N < 0)
        return false;

    if(judge(N - 4) || judge(N - 7))
        return true;
    else false;
}


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

int main(){
    using namespace std;
    unsigned long N, Q;
    cin >> N >> Q;
    vector<unsigned long> c(N);
    for(auto&& i : c){
        cin >> i;
        --i;
    }
    vector<tuple<unsigned long, unsigned long, unsigned long>> queries(Q);
    {
        unsigned long cnt{0};
        for(auto&& [i, l, r] : queries){
            cin >> l >> r;
            --l;
            i = cnt++;
        }
    }
    constexpr unsigned long B{1000};
    sort(begin(queries), end(queries), [&B](const auto& lhs, const auto& rhs){
        const auto& [i, li, ri] = lhs;
        const auto& [j, lj, rj] = rhs;
        return li / B == lj / B ? (li / B) & 1 ? ri > rj : ri < rj : li < lj;
    });
    unsigned long nl{0}, nr{0}, now{0};
    vector<unsigned long> cnt(N), ans(Q);
    for(const auto& [i, l, r] : queries){
        while(nr < r)now += !cnt[c[nr++]]++;
        while(nr > r)now -= !--cnt[c[--nr]];
        while(nl < l)now -= !--cnt[c[nl++]];
        while(nl > l)now += !cnt[c[--nl]]++;
        ans[i] = now;
    }
    for(const auto& i : ans)cout << i << endl;
    return 0;
}

Measured memory_bytes: 27128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long P, vector<long long> A) {
  bool isOdd = false;

  REP(i, N) if (A[i] % 2 != 0) isOdd = true;

  if (!isOdd && P == 1) {
    cout << "0" << endl;
    return;
  }

  ll ans = isOdd ? 1LL << (N - 1) : 1LL << N;

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long P;
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  cin >> P;
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  solve(N, P, A);
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    INF = float('inf')

    idEle = -INF  # max
    def _binOpe(x, y):
        return x if x >= y else y  # max
    def makeSegTree(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [idEle] * (2*numPow2)
        return data, numPow2
    def setInit(As):
        for iST, A in enumerate(As, numPow2):
            data[iST] = A
        for iST in reversed(range(1, numPow2)):
            data[iST] = _binOpe(data[2*iST], data[2*iST+1])
    def _update1(iA, A):
        iST = iA + numPow2
        data[iST] = A  # set
    def update(iA, A):
        _update1(iA, A)
        iST = iA + numPow2
        while iST > 1:
            iST >>= 1
            data[iST] = _binOpe(data[2*iST], data[2*iST+1])
    def getValue(iSt, iEn):
        L = iSt + numPow2
        R = iEn + numPow2
        ans = idEle
        while L < R:
            if L & 1:
                ans = _binOpe(ans, data[L])
                L += 1
            if R & 1:
                R -= 1
                ans = _binOpe(ans, data[R])
            L >>= 1
            R >>= 1
        return ans


    N, K = map(int, input().split())
    As = [int(input()) for _ in range(N)]

    maxA = max(As)

    data, numPow2 = makeSegTree(maxA+1)
    setInit([0]*(maxA+1))

    for A in As:
        L, R = A-K, A+K
        if L < 0:
            L = 0
        if R > maxA:
            R = maxA
        v = getValue(L, R+1)
        update(A, v+1)

    ans = getValue(0, maxA+1)
    print(ans)


solve()


Measured memory_bytes: 100376
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std; 
double ans,d,x,n;
int main(){
	cin>>n>>d>>x; n*=2;
	for(int t=n/2;t;--t){
		ans+=d+(n-1)/2*x;
		auto f=d+(2*d+5*x)/n;
		auto g=x+4*x/n;
		d=f,x=g,n-=2;
	}
	cout.precision(15);
	cout<<fixed<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> ac(n), pena(n);
    for(int i = 0; i < m; i++){
        int p;
        string s;
        cin >> p >> s;
        --p;
        if(ac[p]) continue; //すでにacしてたら
        if(s == "AC"){
            ac[p] = 1;
        }else {
            pena[p]++;
        }
    }
    int AC = 0, PENA = 0;
    for(int i = 0; i < n; i++){
        AC += ac[i];
        if(ac[i]) PENA += pena[i];
    }
    cout << AC << " " << PENA;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  while(n>1000){
    n-=1000;
  }
  n=1000-n;
  cout<<n<<endl;
}

Measured memory_bytes: 3632
N = [int(i) for i in input().split()][0]
P = [int(i) for i in input().split()]

count=0
for i in range(0,N-2):
  tmp = [P[i],P[i+1],P[i+2]]
  tmp.sort()
  if P[i+1]==tmp[1]:
    count+=1
  elif tmp[0]==tmp[1] or tmp[0]==tmp[2]:
    count+=1

print(count)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := prime(n)
	var cnt int
	for _, v := range m {
		var s int
		for k := v; k > s; k -= s {
			cnt++
			s += 1
		}
	}
	fmt.Println(cnt)
}

func prime(a int) map[int]int {
	m := make(map[int]int)
	ok := true
	for ok {
		ok = false
		for i := 2; i <= sqrt(a); i++ {
			if a%i == 0 {
				a /= i
				m[i]++
				ok = true
				break
			}
		}
	}
	if a > 1 {
		m[a]++
	}
	return m
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1852
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;

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

  int n;
  cin >> n;

  set<int> se;
  rep(i,n) {
    int a;
    cin >> a;
    se.insert(a);
  }
  cout << (se.size() == n ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 9600
import heapq

N, M = map(int, input().split())
A = [-int(n) for n in input().split()]
heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    a = a // 2 if a % 2 == 0 else a // 2 + 1
    heapq.heappush(A, a)

print(-sum(A))


Measured memory_bytes: 14184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int n,q,cnt[200000];
vector<int> e[200000];

void dfs(int v,int p){
    if(p!=-1){
        cnt[v]+=cnt[p];
    }
    for(int n:e[v]){
        if(n!=p){
            dfs(n,v);
        }
    }
}

int main(){
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        --p;
        cnt[p]+=x;
    }
    dfs(0,-1);
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<cnt[i];
    }
    cout<<endl;
}


Measured memory_bytes: 23424
import sys
input = sys.stdin.readline

# B - Similar Arrays
def count_simular_arrays(arr):
	ans = 0
	
	for a in arr:
		for n in a:
			if n % 2 == 0:
				ans += 1
				break

	return ans


import copy

n = int(input())
a = list(map(int, input().split()))
arr = []

for i in range(-1, 2):
	arr.append([a[0] + i])

for i in range(1, n):
	copied = copy.deepcopy(arr)
	arr.clear()
	
	for c in copied:
		for j in range(-1, 2):
			arr.append(c + [a[i]+j])

print(count_simular_arrays(arr))

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

int main(){
  int a, b;
  cin >> a >> b;
  
  for(int i=0;i<=10000;i++){
    int za = i * 0.08;
    int zb = i* 0.1;
    
    if( za == a && zb == b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long long LL;

int N;
int A[100010];
vector<int> V[100010];
bool b = 1;

LL dfs(int p , int q){
	if((int)V[q].size() == 1) return A[q];
	LL z = 0;
	repv(int,it,V[q]){
		if(*it == p) continue;
		LL w = dfs(q,*it);
		if(w > (LL)A[q]) b = 0;
		z += w;
	}
	if(p < 0 && z != (LL)2 * A[q]) b = 0;
	if(z < (LL)A[q] || (LL)2 * A[q] < z) b = 0;
	return 2 * A[q] - z;
}

int main(){
	scanf("%d" , &N);
	repp(i,1,N+1){
		scanf("%d" , A + i);
	}
	repp(i,1,N){
		int x,y;
		scanf("%d%d" , &x , &y);
		V[x].PB(y);
		V[y].PB(x);
	}
	if(N == 2){
		printf("%s\n" , A[1] == A[2] ? "YES" : "NO");
		return 0;
	}
	int r = 1;
	while((int)V[r].size() == 1) ++r;
	dfs(-1,r);
	printf("%s\n" , b ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 11392
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

   
int main(){
int A,B,T;
cin >> A >> B >> T;
cout << (T/A)*B << endl;

}

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

int main() {
    long long n,m;
    cin>>n>>m;
    string s1, s2;
    cin>>s1;
    cin>>s2;
    long long int lcma = (n*m)/ __gcd(n, m);
    long long int n1 = lcma/n;
    long long int m1 = lcma/m;
    long long int temp;
    bool poss = true;
    for (long long int i = 0; i < n; i++) {
      if ((i * n1) % m1 == 0) {
        temp = (i * n1) / m1;
        if (s1[i] != s2[temp]) {
          poss = false;
          break;
        }
      }
    }
    for (long long int i = 0; i < m; i++) {
      if ((i * m1) % n1 == 0) {
        temp = (i * m1) / n1;
        if (s2[i] != s1[temp]) {
          poss = false;
          break;
        }
      }
    }
    if(poss == true){
        cout<<lcma<<endl;
    } else {
        cout<<-1<<endl;
    }
    return 0;
}


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

namespace ABC125A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            c = int.Parse(ss[2]);
            Console.WriteLine((c / a) * b);
            Console.ReadKey();

        }
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
#include <set>

using namespace std;
#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	vector<int>x(n);
	vector<int>y(n);
	rep(i, n) {
		int tmp;
		cin >> tmp;
		x[i] = y[i] = tmp;
	}
	sort(x.begin(), x.end());
	int min = x[n/2-1];
	int max = x[n / 2];
	rep(i, n) {
		if (y[i] <= min)println(max);
		else if (y[i] >= max)println(min);
	}
}

Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c[3];
	cin>>a>>b;
	c[0]=a+b;
	c[1]=a-b;
	c[2]=a*b;
	cout<<max(c[0],max(c[1],c[2]))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mp make_pair
#define pb push_back
#define F first
#define S second
string s,t;
int dp[3005][3005];
int fun(int x,int y)
{
    if(x==0&&y>0)
    {
        if(s[x]==t[y])
        {
            dp[x][y]=1;
        }
        else
        {
            if(dp[x][y-1]==-1)
            dp[x][y-1]=fun(x,y-1);
            dp[x][y]=dp[x][y-1];
        }
    }
    else if(x>0&&y==0)
    {
        if(s[x]==t[y])
        {
            dp[x][y]=1;
        }
        else
        {
            if(dp[x-1][y]==-1)
            dp[x-1][y]=fun(x-1,y);
            dp[x][y]=dp[x-1][y];
        }
    }
    else if(x>0&&y>0)
    {
        if(s[x]==t[y])
        {
            if(dp[x-1][y-1]==-1)
            dp[x-1][y-1]=fun(x-1,y-1);
            dp[x][y]=1+dp[x-1][y-1];
        }
        else
        {
            if(dp[x-1][y]==-1)
            dp[x-1][y]=fun(x-1,y);
            if(dp[x][y-1]==-1)
            dp[x][y-1]=fun(x,y-1);
            dp[x][y]=max(dp[x-1][y],dp[x][y-1]);
        }
    }
    else
    {
        if(s[x]==t[y])
        {
            dp[x][y]=1;
        }
        else
        dp[x][y]=0;
    }
    return dp[x][y];
}
int main()
{
    string ans;
    int i,j,l,m,p,x;
    cin>>s;
    cin>>t;
    l=s.length();
    m=t.length();
    for(i=0;i<l+5;i++)
    {
        for(j=0;j<m+5;j++)
        dp[i][j]=-1;
    }
    dp[l-1][m-1]=fun(l-1,m-1);
    vector<int> v;
    i=l-1;
    j=m-1;
    while(1)
    {
        if(i!=0&&j!=0)
        {
            if(dp[i][j]==dp[i-1][j-1])
            {
                i-=1;
                j-=1;
            }
            else if(dp[i][j]==dp[i-1][j])
            {
                i-=1;
            }
            else if(dp[i][j]==dp[i][j-1])
            {
                j-=1;
            }
            else if(dp[i][j]==(dp[i-1][j-1]+1))
            {
                v.pb(j);
                i-=1;
                j-=1;
            }
        }
        else
        {
            if(i==0&&j>0)
            {
                if(dp[i][j]==1&&dp[i][j-1]!=1)
                {    
                    v.pb(j);
                    break;
                }
                j-=1;
            }
            else if(i>0&&j==0)
            {
                if(dp[i][j]==1&&dp[i-1][j]!=1)
                {
                    v.pb(0);
                    break;
                }
                i-=1;
            }
            else if(i==0&&j==0)
            {
                if(dp[0][0]==1)
                v.pb(0);
                break;
            }
        }
    }
    ans="";
    for(i=v.size()-1;i>=0;i--)
    {
        ans+=string(1,t[v[i]]);
    }
    cout<<ans<<endl;
    return 0;
}
   

Measured memory_bytes: 35968
x1, y1, x2, y2 = map(int, input().split())
x = x2 - x1
y = y2 - y1
x3 = x2 - y
y3 = y2 + x
x4 = x1 - y
y4 = y1 + x
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<sstream>
#include<stack>
#include<map>
#include<vector>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 3; ++i) if (a * i * b & 1) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;

int main(){
    int N;
    cin >> N;
    int a = N / 100;
    int b = N%100 / 10;
    int c = N%10;
    if (a == 7 || b == 7 || c == 7) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#define INF 1e+9
using namespace std;

int main(){
	int n,t[16][17];
	int dp[1 << 16][16];
	while(cin >> n,n){
		for(int i = 0;i < n;i++){
			for(int j = 0;j <= n;j++) cin >> t[i][j];
		}
		for(int i = 0;i < 1 << n;i++){
			for(int j = 0;j < n;j++) dp[i][j] = INF;
		}
		for(int i = 0;i < n;i++) dp[1 << i][i] = t[i][0];
		for(int i = 0;i < 1 << n;i++){
			for(int j = 0;j < n;j++){
				if(i >> j & 1){
					int tt = t[j][0];
					for(int k = 0;k < n;k++){
						if(j != k && i >> k & 1) tt = min(tt,t[j][k + 1]);
					}
					for(int k = 0;k < n;k++){
						dp[i][j] = min(dp[i][j],dp[i & ~(1 << j)][k] + tt);
					}
				}
			}
		}
		int mi = INF;
		for(int i = 0;i < n;i++) mi = min(mi,dp[(1 << n) - 1][i]);
		cout << mi << endl;
	}
	return 0;
}

Measured memory_bytes: 7148
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int d[310];
long long inv[110000];
long long fact[110000];
long long finv[110000];
long long dp[2][310][610];
int main(){
	inv[1]=fact[0]=finv[0]=1;
	for(int i=2;i<110000;i++)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	for(int i=1;i<110000;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",d+i);
	std::sort(d,d+a);
	long long ret=0;
	dp[0][0][0]=1;
	for(int i=0;i<a;i++){
	//	printf("%d\n",d[i]);
		int t=i%2;
		for(int j=0;j<=a;j++)for(int k=0;k<=2*a;k++)dp[!t][j][k]=0;
		for(int j=0;j<a;j++){
			for(int k=0;k<=2*a;k++){
				if(!dp[t][j][k])continue;
		//		printf("%d %d %d: %lld\n",i,j,k,dp[t][j][k]);
				dp[!t][j][k]=(dp[!t][j][k]+dp[t][j][k]*finv[d[i]-1])%mod;
				if(d[i]>=2)dp[!t][j+1][k+d[i]-2]=(dp[!t][j+1][k+d[i]-2]+dp[t][j][k]*finv[d[i]-2])%mod;
			}
		}
	}
 
	int t=a%2;
	for(int i=3;i<=a;i++){
		for(int j=0;j<=a*2;j++){
	
	//		if(dp[t][i][j])printf("%d %d: %lld\n",i,j,dp[t][i][j]);
			if((a-i&&j==0))continue;
			if(j==0){
				ret=(ret+dp[t][i][j]*fact[i]%mod*inv[i]%mod*inv[2])%mod;
				continue;
			}
			//if(dp[t][i][j])printf("%d %d: %lld\n",i,j,fact[a-i+1-2]*dp[t][i][j]%mod*finv[j-1]%mod*fact[i]%mod*inv[i]%mod*inv[2]%mod);
			if(dp[t][i][j])ret=(ret+fact[a-i+1-2]*dp[t][i][j]%mod*fact[j]%mod*finv[j-1]%mod*fact[i]%mod*inv[i]%mod*inv[2])%mod;
		}}
	
	printf("%lld\n",ret);
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<long long, int>> p;
    for (int i = 0; i < a; i++) {
        long long w; cin >> w; p.emplace_back(w, 0);
    }
    for (int i = 0; i < b; i++) {
        long long w; cin >> w; p.emplace_back(w, 1);
    }
    for (int i = 0; i < c; i++) {
        long long w; cin >> w; p.emplace_back(w, 2);
    }
    sort(p.rbegin(), p.rend());
    vector<int> q(3, 0);
    long long ans = 0;
    auto ok = [&](auto &q) {
        return (q[0] + q[1] + q[2] <= x + y) && (q[0] <= x) && (q[1] <= y);
    };
    for (int i = 0; i < a+b+c; i++) {
        q[p[i].second]++;
        if (ok(q)) {
            ans += p[i].first;
        } else {
            q[p[i].second]--;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 10604
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, A, B = gets_i_list
size = B - A + 1

if A > B
  puts 0
elsif N == 1
  puts 0 if A != B
  puts 1 if A == B
else
  min = A * (N - 1) + B
  max = A + B * (N - 1)
  puts max - min + 1
end


Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

int main(){
    
    int n;

    std::cin >> n;

    std::vector<std::string> w(n);

    for(auto &&e : w){
        std::cin >> e;
    }

    for(auto i = w.begin(); i < w.end(); i++){
        if(std::find(i + 1, w.end(), *i) != w.end()){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    for(int i = 0; i < n - 1; i++){
        if(*(w[i].end() - 1) != *(w[i + 1].begin())){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
import static java.lang.Integer.*;
import static java.lang.Integer.max;
import static java.lang.Integer.min;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int k = scanInt(), n = scanInt();
        int load[] = new int[n];
        int mi = Integer.MAX_VALUE, ma = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            load[i] = scanInt();
            mi = min(mi, load[i]);
            ma = max(ma, load[i]);
        }
        int answer = ma - mi;
        Arrays.sort(load);
        for (int i = 0; i < n - 1; i++) {
            answer = min(answer, load[i] + k - load[i + 1]);
        }
        out.print(answer);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 47936
#include<stdio.h>
#include<algorithm>
using namespace std;
int dat[20000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<2*a;i++){
			int j,h,b;
			scanf("%d:%d:%d",&j,&h,&b);
			dat[i]=j*7200+h*120+b*2+(i+1)%2;
		}
		std::sort(dat,dat+2*a);
		int ret=0;
		int c=0;
		for(int i=0;i<2*a;i++){
			if(dat[i]&1)c++;
			else c--;
			ret=max(ret,c);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a,b;
	cin >> a >> b;
	b >= a ? cout <<"unsafe":cout<<"safe";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    //UnionFindのデータはparで構成されていて、[name].parでアクセスできる
    vector<int> rank; 
    vector<int> unsize;

    UnionFind(ll N) : par(N), rank(N), unsize(N){ //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i, rank[i] = 0, unsize[i] = 1;
    }

    int root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    ll unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        ll ret = 0;
        if(rx!=ry){
            ret = unsize[rx]*unsize[ry];
        }
        if(rank[rx] < rank[ry]){ //木の長さが低い方を高い方に繋げる
            par[rx] = ry;
            unsize[ry] += unsize[rx];
        }else if(rank[rx] > rank[ry]){
            par[ry] = rx;
            unsize[rx] += unsize[ry];
        }else if(rx != ry){
            par[ry] = rx;
            if(rank[rx] == rank[ry]) rank[rx]++;
            unsize[rx] += unsize[ry];
        }
        return ret;
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll n , m ; cin >> n >> m;
    vector<ll> a(m),b(m);
    rep(i,m){
        ll ai,bi;
        cin >> ai >> bi ;
        ai--; bi--;
        a.at(i) = ai;
        b.at(i) = bi;
    }

    UnionFind tree(n);
    vector<ll> noct(m+1,0); //The number of Connected Towns
    ll dif;

    for(int i=m-1;i>=0;i--){
        ll aa=a.at(i), bb = b.at(i);
        dif = tree.unite(aa,bb);
        if(i==m-1){
            noct.at(i) = dif;
        }else{
            noct.at(i) = noct.at(i+1) + dif;
        }
    }

    //prvec(noct);

    ll all = n*(n-1)/2;

    for(int i=1;i<=m;i++){
        noct.at(i) = all - noct.at(i);
        cout << noct.at(i) << "\n";
    }
    return 0;
}



Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, n)mp[s[i]]++;
    int m = mp.size();
    vector<vector<ll>> dp(m+1, vector<ll>(2, 0));
    dp[0][0] = 1;
    ll mod = 1000000007;
    int cnt = 0;
    for(auto p : mp){
        ll c = p.second;
        dp[cnt+1][0] = (dp[cnt][0] + dp[cnt][1]) % mod;
        dp[cnt+1][1] = (dp[cnt][0] + dp[cnt][1]) % mod * c % mod;
        cnt++;
    }
    ll ans = (dp[m][0] + dp[m][1] - 1 + mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3740