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

using namespace std;

const int N = 100010;

int n;
long long X;

struct TExam{
  long long b, l, u;
  TExam(){};
  TExam(int b, int l, int u) : b(b), l(l), u(u){}
};

TExam a[N];

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

  cin >> n >> X;
  for(int i = 1; i <= n; ++i) {
    int b, l, u; cin >> b >> l >> u;
    a[i] = TExam(b, l, u);
  }

  long long low = 0, high = 1e11, ret = high;

  while(low <= high) {
    long long hour = (low + high) >> 1;
    long long tmw = hour % X, k = hour / X;
    

    long long startingTot = 0;

    vector < pair < long long, int > > arr;
    for(int i = 1; i <= n; ++i) {
      startingTot -= a[i].l * a[i].b;
      arr.emplace_back((X - a[i].b) * a[i].u + a[i].l * a[i].b, i);
    }

    sort(arr.rbegin(), arr.rend());

    k = min(k, 1LL * n);
    for(int i = 0; i < k; ++i) {
      startingTot += arr[i].first;  
    }

    if(k >= n) {
      if(startingTot >= 0) {
        ret = hour;
        high = hour - 1;
      }
      else {
        low = hour + 1;
      }
      //return 0;
      continue;
    }


    long long ans = -1;
    for(int i = 0; i < k; ++i) {
      int id = arr[i].second;
      if(tmw > a[id].b) {
        ans = max(ans, startingTot - (X - tmw) * a[id].u + arr[k].first);
      }
      else {
        ans = max(ans, startingTot - (X - a[id].b) * a[id].u - (a[id].b - tmw) * a[id].l + arr[k].first);
      }

    }


    for(int i = k; i < n; ++i) {
      int id = arr[i].second;
      if(tmw > a[id].b) {
        ans = max(ans, startingTot + a[id].l * a[id].b + (tmw - a[id].b) * a[id].u);
      }
      else {
        ans = max(ans, startingTot + tmw * a[id].l);
      }
    }


    if(ans >= 0) {
      ret = hour;
      high = hour - 1;
    }
    else {
      low = hour + 1;
    }
    //return 0;
  }

  cout << ret;

  return 0;
}

Measured memory_bytes: 6260
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const ll MOD = 1e18+7;
ll a[int(1e6+10)]; 
int main() {
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];
	sort(a,a+n);
	ll g = a[0];
	rep(i,n) g = __gcd(g, a[i]);

	if (g > 1) {
		cout << "not coprime" << endl;
		return 0;
	}
	
	map<int, int> p;
	rep(i,n) {
		int x = a[i];
		for (int j = 2; j*j <= a[i]; j++)
		{
			if (x % j != 0) continue;
			if (p[j] > 0) {
				cout << "setwise coprime" << endl;
				return 0;
			}
			p[j] = 1;
			while(x % j == 0) x /= j; 
		}
		if (x > 1) {
			if (p[x] > 0) {
				cout << "setwise coprime" << endl;
				return 0;
			} else p[x] = 1;
		}
	}
	cout << "pairwise coprime" << endl;
	return 0;
}

Measured memory_bytes: 11392
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MAXN 200005

typedef long long lint;

int N, A[MAXN];

lint solve() {
	lint ans = 0ll;
	int s = 0;
	for(int i = 0; i < N; i++) {
		s += A[i];
		if(i % 2) {
			int d = max(0, 1 - s);
			ans += d;
			s += d;
		}
		else {
			int d = max(0, s + 1);
			ans += d;
			s -= d;
		}
		//printf("i = %d, s = %d, ans = %d\n", i, s, ans);
	}
	return ans;
}

int main() {
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", A + i);

	lint ans = solve();
	for(int i = 0; i < N; i++) A[i] *= -1;
	printf("%lld", min(ans, solve()));
	return 0;
}


Measured memory_bytes: 512
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int Prime_factorize(ll n) {
    int cnt=0;
    for (ll i=2; i*i<=n; i++) {
        int th = 1;
        int now = 0;
        while (n%i == 0) {
            now++;
            if (th == now) {
                cnt++;
                now = 0;
                th++;
            }
            n /= i;
        }
        if (i != 2) i++;
    }
    if(n != 1) cnt++;
    return cnt;
}

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

    int cnt = Prime_factorize(n);

    cout << cnt << endl;

    return 0;
}

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

int main() {
    while (1) {
        string s;
        cin >> s;
        if (s == "0") break;
    
        int sum = 0;
        for (int i = 0; i < s.size(); i++) {
            sum += s.at(i) - '0';
        }
        
        cout << sum << endl;
    }
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

struct UnionFind {
    vector<int> par, size;
    UnionFind(int n) : par(n), size(n,1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }
    void Union(int x, int y) {
        x = Find(x), y = Find(y);
        if(x == y) return;
        if(size[x] < size[y]) swap(x,y);
        size[x] += size[y];
        par[y] = x;
    }
    int Find(int x) {
        if(par[x]==x) return x;
        else return par[x] = Find(par[x]);
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int Size(int x) {
        return size[Find(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    UnionFind uf(n);
    REP(i,q) {
        bool query; cin >> query;
        int x,y; cin >> x >> y;
        if(query) {
            cout << (uf.Same(x,y) ? 1 : 0) << endl;
        }
        else uf.Union(x,y);
    }
    return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;


struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};


void solve() {
    ll N, M, K; cin >> N >> M >> K;
    UnionFind uf(N);
    vector<ll> vec(N);
    for(int i = 0; i < M; ++i){
        ll a, b; cin >> a >> b;
        --a;--b;
        uf.merge(a,b);
        --vec[a];
        --vec[b];
    }
    for(int i = 0; i < K; ++i){
        ll a, b; cin >> a >> b;
        --a;--b;
        if(uf.issame(a,b)){
            --vec[a];
            --vec[b];
        }
    }
    for (int i = 0; i < N; ++i) {
        vec[i] += uf.size(i)-1;
    }
    for (int i = 0; i < N; ++i) {
        cout << vec[i];
        if(i == N-1) cout << endl;
        else cout << ' ';
    }
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 2048
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N, &S)
	ans := make([]byte, len(S))
	for i := 0; i < len(S); i++ {
		ans[i] = (S[i]-'A'+byte(N))%26 + 'A'
	}
	fmt.Println(string(ans))
}


Measured memory_bytes: 768
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
   int x1, x2, x3, x4, y1, y2, y3, y4;
   cin>> x1 >> y1 >> x2 >> y2;
   x3=(y1-y2)+x2;
   y3=-(x1-x2)+y2;
   x4=x3+(x1-x2);
   y4=y3+(y1-y2);
   cout << x3 << ' ' <<  y3 << ' ' <<  x4 << ' ' << y4 << endl;
   
   
   
}

Measured memory_bytes: 256
n = int(input())
D = list(map(int,input().split()))
D.sort()

ans = 0
for s in range(0,13):
    Q = [-s,-s]
    ok = 1
    for d in D:
        if Q[0]+s <= d <= 24 - Q[1]-s:
            Q[0] = d
        elif Q[1]+s <= d <= 24 - Q[0] - s:
            Q[1] = d
        else:
            ok = 0
    if ok:
        ans = s

print(min(ans,min(D)))

Measured memory_bytes: 3188
using System;
using System.Linq;

namespace abc126
{
    class A
    {
        static void Main(string[] args)
        {
            var intArray = Input.IntArray();
            var S = Input.Str().ToCharArray();

            var N = intArray[0];
            var K = intArray[1];

            S[K - 1] = S[K - 1].ToString().ToLower().ToCharArray()[0];






            Console.WriteLine(new String(S));


        }
    }

    internal static class Input
    {
        public static int Int() => int.Parse(Console.ReadLine());

        public static string Str() => Console.ReadLine();

        public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

    }

}


Measured memory_bytes: 13268
def main():
    n = int(input())
    x = []
    for _ in range(n):
        a, b, c = map(int, input().split())
        x.append([a, b, c])
    dp = [[0] * 3 for _ in range(n)]
    # i日目の幸福度dp[i-1]
    # まず1日目の幸福度を設定
    dp[0] = [x[0][l] for l in range(3)]
    for i in range(1,n):
        for j in range(3):
            dp[i][j] = max([dp[i-1][k]+x[i][j] for k in range(3) if k != j]+[dp[i][j]])
    print(max(dp[n-1]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 75096
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    S = readline().rstrip().decode()
    #csw[i]:='W'のi番目までの登場回数
    #cse[i]:='E'のi番目までの登場回数
    csw = [0]
    cse = [0]
    for i in range(N):
        if S[i] == 'W':
            csw.append(csw[i]+1)
            cse.append(cse[i])
        else:
            csw.append(csw[i])
            cse.append(cse[i]+1)
    ans = int(1e6)
    for i in range(N):
        #Sのi番目の文字を見たときSの区間[0,i）にある'W'の数と区間(i, N)にある'E'の数の合計が「向く方向を変える人数」である
        #i番目はリーダーなので数えないことに注意
        ans = min(cse[N]-cse[i+1] + csw[i] - csw[0], ans)
    print(ans)
if __name__ == '__main__':
    main()


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

int main(){
    int N;
    int a[110];
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    int count=0;
    for(int i=0;i<N;i+=2){
        if(a[i]%2==1) count++;
    }
    cout << count << endl;
    return 0;

    
}

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

int main(){
long long n,k,b;
  cin>>n>>k;
  b=0;
  vector<long long> d(k);
  vector<long long> sum(n,0);
  for(int i=0;i<k;i++){
cin>>d.at(i);
    for(int j=0;j<d.at(i);j++){
vector<long long> vec(d.at(i));
cin>>vec.at(j);
        for(int m=1;m<=n;m++){
if(vec.at(j)==m){
sum.at(m-1)=1;
}
        }
      }
    }
    for(int i=0;i<n;i++){
if(sum.at(i)==0){
  b++;
}
    }
      cout<<b<<endl;
    }


Measured memory_bytes: 3632
def main():
    N = int(input())
    c = str(input())
    c = list(c)
    
    i = -1
    j = N
    up = True
    ans = 0
    
    for n in range(N):
        if i == j:
            break
        if up:
            i += 1
            if c[i] == 'W':
                up = False
        else:
            j -= 1
            if c[j] == 'R':
                up = True
                ans += 1
            
    print(ans)
                
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 10784
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 100000;
const int MAXK = 1000;
int x[MAXN + 5], y[MAXN + 5], c[MAXN + 5];
int y1[10 * MAXK + 5];
int main() 
{
	int N,K,Max=0,cnt = 0;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++) 
	{
		char ch;
		scanf("%d%d %c",&x[i],&y[i],&ch);
		x[i]%=(2*K);
		y[i]%=(2*K);
		if(ch=='W' ) c[i] = 1;
		else c[i]=0;
	}
	for(int i=0;i<=K;i++) {
		cnt = 0;
		fill(y1,y1+2*K+1,0);
		for(int j=1;j<=N;j++) {
			bool p = ( i <= x[j] && x[j] < i+K );
			bool q = ( 0 <= y[j] && y[j] < K );
			if( p ^ q == c[j] )
			{
				cnt++;
				y1[y[j]] ++;
			}
			else 
			{
				y1[y[j]] --;
			}
		}
		for(int j=0;j<=K;j++) 
		{
			Max=std::max(Max,std::max(cnt,N-cnt));
			if( j != K )
				cnt = cnt - y1[j] - y1[K+j];
		}
	}
	printf("%d\n",Max);
}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

int main() {
    fast;
    cin.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w" , stdout);
#endif*/
    lld n;
    cin >> n;
    set<string> s;
    for (lld i = 0; i < n; i++) {
        string x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 19244
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>

using namespace std;

int main()
{



     flash;
     ///////////////////////////////////////////////////////////////////////////////////////

ll n;
cin>>n;
ll dir[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};
ll maxi[4]={INT_MIN,INT_MIN,INT_MIN,INT_MIN};
ll mini[4]={INT_MAX,INT_MAX,INT_MAX,INT_MAX};
for(ll i=0;i<n;i++)
{
    ll x,y;
    cin>>x>>y;
    for(ll j=0;j<4;j++)
    {
    maxi[j]=max(maxi[j],x*dir[j][0]+y*dir[j][1]);
    mini[j]=min(mini[j],x*dir[j][0]+y*dir[j][1]);
}

}
ll ans=INT_MIN;
for(ll i=0;i<4;i++)
{
    ans = max(ans,maxi[i]-mini[i]);

}
cout<<ans<<endl;









    ///////////////////////////////////////////////////////////////////////////////////////

     return 0;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 20;


int main(){
  int N, L, pie, x, y = 10000;
  cin >> N >> L;
  
  rep2(i, 1, N+1){
    x = L+i-1;
    pie += x;
    if(abs(x) < abs(y)) y = x;
  }

  cout << pie - y << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using ll = long long;
using namespace std;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '+') {
			ans += 1;
		}
		else {
			ans -= 1;
		}
	}
	cout << ans;
}


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


int main() {
	int N; cin >> N;
	int a[200100];
	REP(i, N)cin >> a[i];
	REP(i, N)a[i]--;
	vector<int>idx(N);
	REP(i, N)idx[a[i]] = i;
	set<int>s;
	ll ans = 0;
	for (int x = 0; x <=N-1; ++x) {
		int i = idx[x];
		int l = -1;
		int r = N;
		s.insert(i);
		auto itr1 = s.find(i);
		if (itr1 != s.begin()) {
			--itr1;
			l = *itr1;
		}
		auto itr2 = s.find(i);
		++itr2;
		if (itr2 != s.end()) {
			r = *itr2;
		}
		ans += (ll)(x + 1)*(i - l)*(r - i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  string str;
  cin >> str;

  int s = -1, t;
  for(int i = 0; i < str.size(); i++) {
    if(str[i] == 'A' && s == -1) {
      s = i;
    }
    if(str[i] == 'Z') {
      t = i;
    }
  }

  cout << t - s + 1 << endl;

  return 0;
}


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

int n, m;
int a, b;

int main(){
  cin >> n >> m;
  vector<int> h(n+1);
  vector<int> bad(n+1);
  for(int i=0; i<n; i++){
    cin >> h[i+1];
  }
 
 for(int i=0; i<m; i++){
   cin >> a >> b;
   if(h[a] < h[b]){
     bad[a] = 1;
   }
   if(h[a] > h[b]){
     bad[b] = 1;
   }
   if(h[a] == h[b]){
     bad[a] = 1;
     bad[b] = 1;
   }
  }
  
  int count = 0;
  for(int i=1; i<n+1; i++){
    if(bad[i] != 1){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4024
n, a, b = map(int, input().split())
MOD = 10**9+7


def COM(n, r):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
    Y = pow(Y, MOD-2, MOD)
    while 0 < r:
        X = X*n % MOD
        n -= 1
        r -= 1
    return X*Y


ans = pow(2, n, MOD)-1 - COM(n, a)-COM(n, b)
ans %= MOD

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}
template<typename T> 
void showmatrix(T a){
  for(auto j: a){for(auto i : j){ cout << i; }cout << endl;}
  cout << endl;
}


int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  
  
  int a, b;
  cin >> a >> b;
  if(b % a == 0){
    cout << a+b << endl;
  }
  else cout << b-a << endl;
  

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var A = ReadLong();
            var B = ReadLong();
            var C = ReadLong();
            var X = ReadLong();
            var count = 0;
            for (var 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++;
                        }
                    }
                }
            }
            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

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

  string s[N];
  for(int i=0; i<N; i++){
    cin >> s[i];
    s[i] = s[i][0];
  }

  int a[5]={};
  long long count=0;

  for(int i=0; i<N; i++){
    if(s[i]=="M"){
      a[0]++;
    }else if(s[i]=="A"){
      a[1]++;
    }else if(s[i]=="R"){
      a[2]++;
    }else if(s[i]=="C"){
      a[3]++;
    }else if(s[i]=="H"){
      a[4]++;
    }
  }
  for(int i=0; i<5; i++){
    for(int j=i+1; j<5; j++){
      for(int k=j+1; k<5; k++){
        count += (long long)a[i]*a[j]*a[k];
      }
    }
  }
  cout << count << endl;
}

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

typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define precise(x) cout<<fixed<<setprecision(12)<<x
#define test cout<<"#";

const ll INF = 1e18L + 5;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin>>n>>k;
	vector<ll> v(n+1);
	for(ll x = 1; x <=n; x++)
		cin>>v[x];
	ll ans[n+1][k+1];
	for(ll x = 0; x<=k; x++)
	{
		if(x<=v[1])
			ans[1][x] = 1;
		else
		{
			ans[1][x] = 0;
		}		
	}
	for(ll x = 2; x <= n; x++)
	{
		for(ll y = 0; y <=k; y++)
		{
			if(y==0)
				ans[x][y] = ans[x-1][y];
			else 
				ans[x][y] = (mod+ans[x][y-1] + ans[x-1][y] - ((y-v[x]-1)>=0?ans[x-1][y-v[x]-1]:0));
			ans[x][y]%=mod;
		}
	}
	cout<<ans[n][k];
}

Measured memory_bytes: 78336
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    string snuke = "snuke";
    int ansc,ansd;
    REP(i,h){
        bool f = true;
        REP(j,w){
            string s;
            cin >> s;
            f=true;
            REP(k,5){
                if(s[k]!=snuke[k]){
                    f = false;
                    break;
                }
            }
            if(f){
                ansc = j;
                ansd = i;
            }
        }
    }
    printf("%c%d\n",(char)('A'+ansc), ansd+1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
array<int, 101> factoring(int x) {
    array<int, 101> ret{};
    for (int i = 2; x >= i * i; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

signed main() {
    int n;
    cin >> n;
    vector<int> as(n);
    REP(i, n) { cin >> as[i]; }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int b, m, e;
        cin >> b >> m >> e;
        rotate(as.begin() + b, as.begin() + m, as.begin() + e);
    }
    int k = 0;
    for (int x : as) {
        k++;
        cout << x;
        if (k != n) {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3180
n=int(input())
dlist=[int(i) for i in input().split()]
if dlist[0]!=0:
    print(0)
else:
    dlist=sorted(dlist)
    before=0
    kyolist=[0]
    dame=0
    for i in range(n):
        if dlist[i]==before:
            kyolist[-1]+=1
        elif dlist[i]==before+1:
            kyolist.append(1)
        else:
            dame=1
        before=dlist[i]
    #print(kyolist)
    if dame==1 or kyolist[0]!=1:
        print(0)
    else:
        if len(kyolist)<=2:
            print(1)
        else:
            answer=1
            for i in range(len(kyolist)-1):
                answer*=(kyolist[i]**kyolist[i+1])
            print(answer%998244353)

Measured memory_bytes: 57516
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

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

	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	int n;
	ll k;
	cin >> n >> k;
	vector<int> v(n);
	rep(i,n) cin >> v[i];

	mint ans = 0;
	rep(i,n) {
		int cntb = 0;
		int cnts = 0;
		for (int j = 0; j < i; j++) {
			if (v[i] < v[j]) cnts++;
		}
		for (int j = i+1; j < n; j++) {
			if (v[i] < v[j]) {
				cntb++;
				cnts++;
			}
		}
		mint t = k + 1;
		t *= k;
		t /= 2;
		t *= cnts;
		ans += t;
		t = k * cntb;
		ans -= t;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007

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

	cout << n * n - a << endl;
	return 0;
}

Measured memory_bytes: 256
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

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

public class Main {

	static void solve() throws Exception {
		long s = scanLong();
		out.print("0 0 1 1000000000 " + ((s + 999999999) / 1000000000) + " " + ((-s % 1000000000 + 1000000000) % 1000000000));
	}

	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: 21204
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	vi A(3);
	int Asum = 0;
	rep(i, 3) {
		cin >> A[i];
		Asum += A[i];
	}
	if (Asum >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

int main(){

	int n; cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];

	int dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];

	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
	}

	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
	return 0;
} 

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

int main() {
    int n, m;

    int sum = 0;

    cin >> n;
    int t[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        sum += t[i];
    }

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

    for (int i = 0; i < m; i++) {
        cout << sum - (t[p[i] - 1] - x[i]) << endl;
    }

    return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 998244353;
constexpr ll INF = 1e18;

long long factrial[5000000]; //再帰が深くなるとスタックオーバーフローになるので最初に使うものは初期化しておく

long long init() {
    factrial[0] = 1;
    for(int i = 1; i < 5000000; i++)
        factrial[i] = (factrial[i - 1] * i) % MOD;
}

long long Repeat(long long a, long long cnt) {
    if(cnt == 0) return 1LL;
    if(cnt % 2 == 1) {
        long long x = Repeat(a, cnt / 2);
        return (((a * x) % MOD) * x) % MOD;
    } else {
        long long x = Repeat(a, cnt / 2);
        return (x * x) % MOD;
    }
}

long long fact(long long a) {
    if(a == 0)
        return 1LL;
    else if(factrial[a] != 0)
        return factrial[a];
    else
        return factrial[a] = (a * fact(a - 1)) % MOD;
}

long long comb(long long a, long long b) {
    long long fa, fb, fab;
    fa = fact(a);
    fb = fact(b);
    fab = fact(a - b);
    fb = Repeat(fb, MOD - 2);
    fab = Repeat(fab, MOD - 2);
    return (((fa * fb) % MOD) * fab) % MOD;
}

int main() {
    ll n, m, i, j, k;
    cin >> n >> m >> k;
    ll ret = 0;
    for(i = 0; i <= k; i++) {
        ll t = comb(n - 1, i);
        t *= m;
        t %= MOD;
        t *= Repeat(m - 1, n - i - 1);
        t %= MOD;
        ret+=t;
        ret%=MOD;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 8224
import sys

input = sys.stdin.readline
mod = 10 ** 9 + 7
n, m = map(int, input().split())
dp = [0] * (n + 1)
dp[0] = 1
ng = set(int(input()) for _ in range(m))

for i in range(n):
    next1 = i + 1
    if next1 not in ng:
        dp[next1] += dp[i]
        dp[next1] %= mod
    next2 = i + 2
    if next2 not in ng and next2 <= n:
        dp[next2] += dp[i]
        dp[next2] %= mod
print(dp[-1])

Measured memory_bytes: 18152
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int n,sum = 0;
  string s;
  cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  VSORT(v);
  for (int i = 0; i < n-1; i++){
    sum += v[i];
  }
  if (v[n-1] < sum) {
    s = "Yes";
  } else {
    s = "No";
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll k;
	cin>>k;
	ll ans=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int p=1;p<=k;p++)
			{
				ans+=__gcd(i,__gcd(j,p));
			}
		}
	}
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 3640
n, a, b, c, d = map(int, raw_input().split())
MOD = 10**9+7
fact = [1]*(n+1)
frev = [1]*(n+1)

rcd = range(c, d+1)

dp = [0]*(n+1)
dp[0] = 1

for i in xrange(1, n+1):
    v = fact[i] = (fact[i-1] * i) % MOD
    frev[i] = pow(v, MOD-2, MOD)
Y = [None]*(n+1)
for g in xrange(a, min(n/c, b)+1):
    p = c*g; q = d*g
    y = frev[g]
    Y[p:min(q,n)+1:g] = (pow(y, j, MOD)*frev[j] for j in xrange(c, min(d, n/g)+1))
    dp[p:] = (dp[i] + frev[n-i]*sum(dp[i-j] * fact[n-i+j] * Y[j] for j in xrange(p, min(q, i)+1, g)) % MOD for i in xrange(p, n+1))
print dp[n]%MOD

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

int main()
{

    ll N;

    cin >> N;
    int ans = ceil(N/2.0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
using namespace std;
using ll =long long;

int main (void) {
  int A,B,K;
  cin >> A >> B >> K;
  for (int i=A; i<=min(A+K-1,B); i++) {
    cout << i<< endl;
  }
  for (int i=max(B-K+1,A+K); i<=B; i++) {
    cout << i << endl;
  }
}


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

int main(){
	string S,T;
	cin >> S >> T;
	int ans = 0;
	for(int i=0;i<3;++i)
		if(S[i]==T[i])++ans;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,l[10],i,max=0,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
    sum+=l[i];
  }
  for(i=0;i<n;i++){
    if(max<l[i]) max=l[i];
  }
  if(max<sum-max) printf("Yes");
  else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int n, k;
int v[N];
int dp[N];
int f(int i){
    if(i == n - 1)
        return 0;
    if(dp[i] != -1)return dp[i];
    int &ans = dp[i];
    ans = 1e9;
    for(int j = 1; j <= k; j++)
        if(i + j <= n - 1)
            ans = min(ans,f(i + j) + abs(v[i] - v[i + j]));
    return ans;
}

int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    cls(dp, -1);
    cin >> n >> k;
    fore(i, 0, n)cin >> v[i];
    /*dp[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--){
        if(i + 1 <= n - 1)
            dp[i] = min(dp[i],dp[i + 1] + abs(v[i] - v[i + 1]));
        if(i + 2 <= n - 1)
            dp[i] = min(dp[i],dp[i + 2] + abs(v[i] - v[i + 2]));
    }
*/
    cout << f(0) << '\n';
    return 0;   
}

Measured memory_bytes: 5760
#include <cstdio>
 
using namespace std;
 
int main()
{
    long K, S;
 
    scanf("%ld %ld", &K, &S);
 
    long i, j, k, n;
    long long counter = 0;
    long offset = 0;

    if (K + K < S) offset = S - (K + K);
 
    for (i = offset; i <= K; i++) {
        for (j = offset; j <= K; j++) {
            n = S - (i + j);

            if (offset <= n && n <= K) counter++;
        }
    }
 
    printf("%lld\n", counter);
 
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var h, n int
	fmt.Scan(&h, &n)

	sum := 0
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		sum += a
	}

	if h <= sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

ll dfs(ll depth, bool gu, vl a){
	if (depth == a.size()) return 0;
	ll ret = 0;
	if (a[depth] % 2){
		return 2 * (ll)pow(3, a.size() - depth - 1) + dfs(depth+1, gu, a);
	}
	else{
		return (ll)pow(3, a.size() - depth - 1) + 2 * dfs(depth+1, gu, a);
	}
	return ret;
}

int main(){
	ll n; cin >> n;
	vl a(n); rep(i, n) cin >> a[i];
	cout << dfs(0, false, a) << endl;
	return 0;
}

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

int fact(int n)
{}
int main()
{
    
    int n,m;
    cin>>n>>m;
    //total n+m balls
    //n have even number on it
    //m have odd number on it
    //choose 2 such that sum is even
    // even + even = even
    // odd + odd = even
    // even + odd = odd
    long long ans = (n*(n-1)/2) + (m*(m-1)/2);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  double l;
  cin >> l;
  double x = l / 3;
  cout << x * x * x << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s[100];
    for(int i=0;i<n;i++) cin>>s[i];
    int x=1;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]){
                x=0;
                break;
            }
        }
    if(x==0) break;
    }
    for(int i=0;i<n-1;i++){
        if(s[i][s[i].size()-1]!=s[i+1][0]){
            x=0;
            break;
        }
    }
    if(x==1) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const int N = 1e5 + 5;

int n;
int a[N];

bool dp[N][2];

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

    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];

    dp[0][0] = true;
    for(int i = 1; i <= n; i++)
    {
        if(a[i] >= a[i - 1])
            dp[i][0] |= dp[i - 1][0];
        if(a[i] >= a[i - 1] - 1)
            dp[i][0] |= dp[i - 1][1];
        if(a[i] - 1 >= a[i - 1])
            dp[i][1] |= dp[i - 1][0];
        if(a[i] - 1 >= a[i - 1] - 1)
            dp[i][1] |= dp[i - 1][1];
    }

    if(dp[n][0] || dp[n][1])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int cnt;
void insertionSort(int A[], int n,  int g)
{
    
    for( int i = g; i < n; ++i ){
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ){
           
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n)
{
     cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] = n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i]);

    //出力
    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

int main()
{
    //入力
    int n;
    scanf("%d", &n);
    int A[n];
    for( int i = 0; i < n; ++i )
        scanf("%d", &A[i]);

    //シェルソート
    shellSort(A, n);

    return 0;
}



Measured memory_bytes: 5668
score, s, t = 0, [], []
n = int(input())
for i in range(n):
    s.append(input())
m = int(input())
for i in range(m):
    t.append(input())
for c in list(set(s)):
    if(s.count(c) - t.count(c) > score):
        score = s.count(c) - t.count(c)
print(score)

Measured memory_bytes: 3064
def a_zero(a):
	if len(a)%2==0:
		return -1
	else:
		tmp=0
		for i in range(len(a)):
			if i%2==0:
				tmp+=a[i]
			else:
				tmp-=a[i]
		return tmp

n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n)]
ans[0]=a_zero(a)
for i in range(1,n):
	ans[i]=2*(a[i-1]-ans[i-1]//2)
for i in range(len(ans)):
	if i!=len(ans)-1:
		print(ans[i],end=" ")
	else:
		print(ans[i])

Measured memory_bytes: 14400
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, W;
  cin >> N >> W;
  vpll wv(N);
  rep(i, N) cin >> wv[i].first >> wv[i].second;

  ll w1 = wv[0].first;
  vector<vvl> dp(N + 1, vvl(N + 1, vl(400, -1)));
  rep(i, N + 1) dp[i][0][0] = 0;

  rep(i, N){
    ll wrem = wv[i].first - w1;
    ll v = wv[i].second;

    rep(j, i + 2){
      rep(k, 3 * (i + 1) + 1){
	if(dp[i][j][k] == -1) continue;
	
	dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
	dp[i + 1][j + 1][k + wrem] = max(dp[i + 1][j + 1][k + wrem], dp[i][j][k] + v);
      }      
    }
  }

  ll ans = 0;

  rep(j, N + 1){
    rep(k, 400){
      if(dp[N][j][k] == -1) continue;
      if((j * w1 + k <= W)){
	ans = max(ans, dp[N][j][k]);
      }
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 32896
N, K = [int(_) for _ in input().split()]

s = 0
e = 0
ans = 0

MOD = 10 ** 9 + 7

for i in range(N+1):
    s += i 
    e += N - i 
    if i + 1 >= K:
        ans += e - s + 1
        ans %= MOD
print(ans)


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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define ZERO(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int k,t;

void solve() {
    vector<int> a(t,0);
    rep(i,t) scanf("%d",&a[i]);
    sort(ALL(a));

    int mm = a[t-1];
    rep(i,t-1) mm -= a[i];

    cout << max(0, mm-1) << "\n";
}

int main() {
    while(cin>>k>>t) solve();

    return 0;
}


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

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

typedef long long ll;

const int INF = 1e8;

int main() {
  string s; cin >> s;
  
  int p = 0;
  string t;
  rep(i, s.length()){
    if(s[i] == '0' || s[i] == '1') t += s[i];
    else if(t.length() != 0) t.pop_back();
  }
  
  cout << t << endl;
}


Measured memory_bytes: 256