akhauriyash/Code-Regression huggingface dataset:
def solve(n, m, s, p)
  res = 0
  [ 0, 1 ].repeated_permutation(n) do |perm|
    m.times do |i|
      cnt = s[i].inject(0) { |acc, val| acc += perm[ val - 1] }
      break res -= 1 if cnt % 2 != p[i]
    end
    res += 1
  end
  return res
end

n, m = gets.chomp.split.map(&:to_i)

s = m.times.with_object([]) do |i, o|
  o << gets.chomp.split.map(&:to_i)
  o[i].shift
end

p = gets.chomp.split.map(&:to_i)

puts solve(n, m, s, p)

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

typedef long long ll;

int main(){
	string s;
	int n;
	cin>>n>>s;
	int ans=0;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H,W;
  scanf("%d%d",&H,&W);

  char a[H+2][W+2];
  char s[W];
  for(int i = 0;i < H+2;i++){
    for(int j = 0;j < W+2;j++){
      a[i][j] = '#';
    }
  }

  for(int i = 0;i < H;i++){
    scanf("%s",s);
    for(int j = 0;j < W;j++){
      a[i+1][j+1] = s[j];
    }
  }

  for(int i = 0;i < H+2;i++){
    for(int j = 0;j < W+2;j++){
      printf("%c",a[i][j]);
    }
    printf("\n");
  }

  return 0;
}

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

using namespace std;

int main() {
  
  int n;
  while(cin >> n, n) {
    vector<vector<int> > G(n, vector<int>(n, 0));
    for(int i=0; i<n; i++) {
      int m; cin >> m;
      for(int j=0; j<m; j++) {
	cin >> G[i][j];
      }
    }
    
    int k, data[100];
    cin >> k;
    for(int i=0; i<k; i++) {
      cin >> data[i];
    }
    
    int ans;
    int good = 0;
    for(int i=0; i<n; i++) {
      bool ok = true;
      for(int j=0; j<k; j++) {
	if(find(G[i].begin(), G[i].end(), data[j]) == G[i].end()) ok = false;
      }
      if(ok) { good ++; ans = i+1; }
    }
    if(good == 1) cout << ans << endl;
    else cout << -1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1260
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a[1000000];
int main(){
	int n,k;
	cin >> n>>k;
	rep(i, n) { cin >> a[i]; }
	sort(a, a + n);
	rep(i, n -(k-1)) { a[i] = (a[i+k-1] - a[i]); }
	sort(a, a + n-(k-1));
	cout << a[0] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

long long solve(deque<long long> A)
{
	long long ans = 0;
	sort(A.begin(), A.end());

	long long l = A.back();
	long long r = A.back();
	A.pop_back();

	for (;;) {
		if (A.empty()) break;
		auto a = abs(A.back() - l);
		auto b = abs(A.back() - r);
		auto c = abs(A.front() - l);
		auto d = abs(A.front() - r);

		auto m = max({ a, b, c, d });
		if (m == a) {
			ans += abs(A.back() - l);
			l = A.back();
			A.pop_back();
		}
		else if (m == b) {
			ans += abs(A.back() - r);
			r = A.back();
			A.pop_back();
		}
		else if (m == c) {
			ans += abs(A.front() - l);
			l = A.front();
			A.pop_front();
		}
		else {
			ans += abs(A.front() - r);
			r = A.front();
			A.pop_front();
		}
		
	}

	return ans;
}

int main()
{
	int N;
	cin >> N;
	deque<long long> A(N);
	for (auto &x : A) {
		cin >> x;
	}
	cout << solve(A) << endl;
}


Measured memory_bytes: 1920
N = int(input())
p = [int(i) for i in input().split()]

ret = 0
for i in range(N-1) :
    if p[i] == i + 1 :
        p[i], p[i+1] = p[i+1], p[i]
        ret += 1
if p[N-1] == N :
    ret += 1
    
print(ret)

Measured memory_bytes: 53036
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                cnt += 1
print(cnt)


Measured memory_bytes: 3060
def resolve():
    n = int(input())
    rests = []
    for i in range(1, n+1):
        o = input().split(" ")
        o[1] = (0 - int(o[1]))
        o.append(i)
        rests.append(o)

    rests = sorted(rests, key=lambda x: (x[0], x[1]))
    for i in range(n):
        print(rests[i][2])
    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3064
from itertools import combinations_with_replacement as com
n, m, q = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(q)]
x = []
for i in range(m):
    x.append(i+1)
y = list(com(x, n))
ans = 0
for i in y:
    tmp = 0
    for a, b, c, d in arr:
        if i[b-1] - i[a-1] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 21480
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  int keta=0;
  int tn=n;
  while(tn>0)
  {
    keta++;
    tn/=10;
  }
  //cout<<keta<<endl;
  ll res=0;
  repi(k,1,keta+1)
  {
    rep(i,pow(3,k))
    {
      int  tn=0,ti=i;
      int ket=0;
      int cnt=0;
      rep(j,k)
      {
        if(ti%3==0){tn+=3*pow(10,ket);cnt|=1;}
        if(ti%3==1){tn+=5*pow(10,ket);cnt|=2;}
        if(ti%3==2){tn+=7*pow(10,ket);cnt|=4;}
        ket++;
        ti/=3;
      }
      //cout<<tn<<endl;
      if(cnt!=7)continue;
      if(tn<=n){res++;}
    }
}
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int memo[10][10][10] = {0};
int d[3] = {0, -1, 1};
int m, n, p;
vector<pair<int, int>> v;

void solve();
bool ch();

int main() {
  while(1) {
    cin >> n >> m >> p;
    if(m + n + p == 0) break;
    for(int i = 0; i < 10; ++i)
      for(int j = 0; j < 10; ++j)
        for(int k = 0; k < 10; ++k) memo[i][j][k] = -1;
    for(int i = 0; i < p; ++i) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      v.push_back(make_pair(x, y));
    }
    solve();
    v.erase(v.begin(), v.end());
  }
  return 0;
}

void solve() {
  for(int t = 0; t < p; ++t) {
    int z = 0;
    pair<int, int> now = v[t];
    while(memo[now.fi][now.se][z] != -1 && z + 1 < n) ++z;
    memo[now.fi][now.se][z] = t % 2;
    if(ch()) {
      if(t % 2 == 0)
        cout << "Black ";
      else
        cout << "White ";
      cout << t + 1 << endl;
      return;
    }
  }
  cout << "Draw" << endl;
}

bool ch() {
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      for(int k = 0; k < 3; ++k)
        for(int x = 0; x < n; ++x)
          for(int y = 0; y < n; ++y)
            for(int z = 0; z < n; ++z) {
              if(x + (m - 1) * d[i] < 0 ||
                 x + (m - 1) * d[i] >= n)
                continue;
              if(y + (m - 1) * d[j] < 0 ||
                 y + (m - 1) * d[j] >= n)
                continue;
              if(z + (m - 1) * d[k] < 0 ||
                 z + (m - 1) * d[k] >= n)
                continue;
              if(i == j && j == k && i == 0) continue;
              int nx = x, ny = y, nz = z, cnt[2] = {0};
              for(int q = 0; q < m; ++q) {
                if(memo[nx][ny][nz] == -1) break;
                ++cnt[memo[nx][ny][nz]];
                nx += d[i];
                ny += d[j];
                nz += d[k];
              }
              if(cnt[0] == m || cnt[1] == m) return 1;
            }
  return 0;
}


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

using namespace std;

int main()
{
    string s,t;
    cin >> s >> t;
    int n=s.size();
    int m=t.size();
    s='?'+s;
    vector<int> v[26];
    for(int i=1;i<=n;i++) v[s[i]-'a'].push_back(i);
    long long res=0;
    for(char c:t)
    {
        if(v[c-'a'].empty())
        {
            cout << -1 << endl;
            return 0;
        }
    }
    int idx=0;
    int now=0;
    while(idx<m)
    {
        int l=-1,r=v[t[idx]-'a'].size();
        while(l<r-1)
        {
            int mid=(l+r)/2;
            if(v[t[idx]-'a'][mid]<=now) l=mid;
            else r=mid;
        }
        if(r==(int)v[t[idx]-'a'].size())
        {
            res+=n;
            now=0;
        }
        else
        {
            now=v[t[idx]-'a'][r];
            idx++;
        }
    }
    res+=now;
    cout << res << endl;
    return 0;
}


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

using namespace std;

int main()
{
  int64_t N;
  cin >> N;
  
  int64_t gA, sA, bA;
  cin >> gA >> sA >> bA;
  
  int64_t gB, sB, bB;
  cin >> gB >> sB >> bB;
  
  vector<int64_t> dp_A(N + 1, 0);
  for (int64_t n = 0; n < N; ++n) {
    if (n + gA <= N) { dp_A[n + gA] = max(dp_A[n + gA], dp_A[n] + (gB - gA)); }
    if (n + sA <= N) { dp_A[n + sA] = max(dp_A[n + sA], dp_A[n] + (sB - sA)); }
    if (n + bA <= N) { dp_A[n + bA] = max(dp_A[n + bA], dp_A[n] + (bB - bA)); }
  }
  
  int64_t M = N + *max_element(dp_A.begin(), dp_A.end());
  
  vector<int64_t> dp_B(M + 1, 0);
  for (int64_t m = 0; m < M; ++m) {
    if (m + gB <= M) { dp_B[m + gB] = max(dp_B[m + gB], dp_B[m] + (gA - gB)); }
    if (m + sB <= M) { dp_B[m + sB] = max(dp_B[m + sB], dp_B[m] + (sA - sB)); }
    if (m + bB <= M) { dp_B[m + bB] = max(dp_B[m + bB], dp_B[m] + (bA - bB)); }
  }
  
  cout << (M + *max_element(dp_B.begin(), dp_B.end())) << endl;
  
  return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

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

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 5e2 + 10, mod = 1e9 + 7;
int fact[N], invfact[N];
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (((ll) x) * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}
void pre(){
	fact[0] = invfact[0] = 1;
	for(int i = 1;i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for(int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k){
	if(n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int dp[N][N], dp2[N][N];
int powers[N][N];

int num[N];
int main(){
	pre();
	for(int i = 0; i < N; i++){
		powers[i][0] = 1;
		for(int j = 1; j < N; j++) powers[i][j] = mul(i, powers[i][j - 1]);
	}
	int n = 100, L = 500; 
	sd(n); sd(L);
	for(int i = 1; i <= n; i++){
		int r = rand() % L + 1; 
		sd(r); 
		num[r]++;
	}
	L++;
	dp[0][0] = 1;
	for(int l = L; l >= 1; l--){
		memcpy(dp2, dp, sizeof dp);
		memset(dp, 0, sizeof dp);
		for(int jx = 0; jx <= L; jx++){
			for(int x = 0; x <= L; x++){
				int ways = dp2[jx][x];
				if(!ways) continue;
				for(int now = 0; now * l + jx <= L; now++){
					int total_len = now * l + jx;
					int total_num = now + x;
					
					dp[total_len][total_num] = add(dp[total_len][total_num], mul(ways, mul(invfact[now], powers[total_len - total_num * l][ num[l]])));
				}
			}
		}
	}
	int ans = 0;
	for(int r = 1; r <= L; r++){
		int val = mul(fact[r], dp[L][r]);
		if(r & 1) ans = add(ans, val);
		else ans = sub(ans, val);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3328
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n, K;
    scanf("%d%d", &n, &K);
    vector<int> a(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.rbegin(), a.rend());
    ll sum = 0;
    for (i = 0; i < K; i++) {
        sum += a[i];
    }
    printf("%lld\n", sum);

    

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d%d", &T, &B);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    r,g,b = LI()
    t = g*10+b
    if t % 4 == 0:
        return 'YES'

    return 'NO'


print(main())


Measured memory_bytes: 7596
A,B = input().split()
n_A, n_B = input().split()
num_A = int(n_A)
num_B = int(n_B)
C = input()
if C == A:
  num_A = num_A -1
if C == B:
  num_B = num_B -1
print(num_A, num_B)

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

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

        private static object GetResult()
        {
            var (L, R, d) = Read3Longs();
            var count = 0L;
            for (var i = L; i <= R; i++)
            {
                if (i % d == 0)
                {
                    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: 28208
def resolve():
    import math
    a = [int(input()) for _ in range(5)]
    b = []
    for i in range(5):
        if a[i]%10 != 0:
            b.append(a[i]%10)
    if len(b) == 0:
        amin = 10
    else:
        amin = min(b)
    ans = 0
    for i in range(5):
        ans += math.ceil(a[i]/10)*10
    print(ans-10+amin)

resolve()

Measured memory_bytes: 38384
#include<cstdio>
#include<algorithm>
using namespace std;
int B[100 + 5];
int main() {
	int N; scanf("%d", &N);
	for(int i=1;i<N;i++)
		scanf("%d", &B[i]);
	int ans = 0;
	for(int i=1;i<N-1;i++)
		ans += min(B[i], B[i + 1]);
	printf("%d\n", ans + B[N - 1] + B[1]);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
   int a ,b, c,i;

for(int i=1;i<=3000 ;i++){
    cin >> a >> b;
if (a>b)
{
   c=a;
   a=b;
   b=c;
}
   if (a==0 && b==0)
   break ;
   else
  
   cout << a << " " << b<< endl;
}
}


Measured memory_bytes: 3056
package main
import "fmt"
func main() {
  var s,t0,t1 string
  var n,m0,m1 int
  fmt.Scan(&s)
  n = len(s)
  t0 = ""
  t1 = ""
  for i:=0;i<(n+1)/2;i++ {
    t0 += "01"
    t1 += "10"
  }
  m0 = 0
  m1 = 0
  for i:=0;i<n;i++ {
    if s[i:i+1] != t0[i:i+1] { m0++ }
    if s[i:i+1] != t1[i:i+1] { m1++ }
  }
  fmt.Println(min(m0,m1))
}
func min(n int,m int) int {
  if n < m { return n }
  return m
}

Measured memory_bytes: 7936
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

struct node {
	int u;
	int v;
	int len;
};

int L;
string s;
vector<node> ans;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> L;
	s = "";
	int cur = 1;
	while (1) {
		if (L&cur) s = "1" + s;
		else s = "0" + s;
		cur = cur << 1;
		if (cur > L) break;
	}
	int cnt = s.length();
	for (int i = 1; i < cnt; i++) {
		int tmp = cnt - 1 - i;
		int v = 1 << tmp;
		ans.pb({ i - 1, i, v });
		ans.pb({ i - 1, i, 0 });
	}
	int pre = 0;
	int acc = 0;
	for (int i = 1; i < cnt; i++) {
		if (s[i] == '0') continue;
		int tmp = cnt - 1 - pre;
		int v = 1 << tmp;
		acc += v;
		ans.pb({ 0, i, acc });
		pre = i;
	}
	cout << cnt << " " << (int)ans.size() << E;
	for (int i = 0; i < (int)ans.size(); i++) {
		cout << ans[i].u + 1 << " " << ans[i].v + 1 << " " << ans[i].len << E;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
vl A;

int main(){FAST;
for(ll i=0;i<3;i++){
	ll x;
	cin>>x;
	A.pb(x);
}
sort(all(A));
ll ans =0;
if(A[0]%2 == A[1]%2){
	ans+=A[2]-A[1];
	ans+=(A[1]-A[0])/2;
}
else{
	ans++;
	A[0]--;
	ans+=A[2]-A[1];
	ans+=(A[1]-A[0])/2;
}
cout<<ans;
return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int m = in.nextInt();
            out.println(48 - m);
        }

    }
}



Measured memory_bytes: 23252
//**************************
//*** author  :  Alex Hu **
//************************

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

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

int n,m;
vector<vi> g;
vi memo;

int dfs(int v)
{
	if (memo[v]!=-1) return memo[v];
	memo[v]=0;
	for (int u:g[v]) memo[v]=max(memo[v],dfs(u)+1);
	return memo[v];
}

int main()
{
	cin>>n>>m;
	g.resize(n);
	memo=vi(n,-1);
	rept(i,0,m)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].pb(y);
	}
	int ans=0;
	rept(i,0,n) ans=max(ans,dfs(i));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8192
A,B,C,K = map(int,input().split())
nList = [A,B,C]
pList = [1,0,-1]

ans = 0
for i in range(len(nList)):
  if nList[i] <= K:
    ans += nList[i]*pList[i]
    K -= nList[i]
  else:
    ans += K*pList[i]
    break
    
print(ans)
 

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

using namespace std;

#define ll long long




void solve() {

	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			for(int k = j + 1; k < n; k++) {
				int a = arr[i], b= arr[j], c = arr[k];
				if(a + b > c && a + c > b && b + c > a && a != b && b != c && a != c) {
					cnt++;
				}
			}
		}
	}
	cout << cnt;

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  
  int largest = (b / k) * k;
  
  if (a <= largest) {
    cout << "OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
}


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

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e5+9;
const ll INF=1e12;
const ll mod=1e9+7;

ll N,res,arr[MAX],dp[MAX],fact[MAX],ifact[MAX];

ll power(ll base,ll exp)
{
	ll res=1;
	while(exp)
	{
		if(exp%2)
			res*=base;
		base*=base;
		res%=mod;
		base%=mod;
		exp/=2;
	}
	return res;
}

ll nCr(ll N,ll K)
{
	return ((fact[N]*ifact[K])%mod*ifact[N-K])%mod;
}

signed main()
{
	ios_base::sync_with_stdio(false);

	fact[0]=1;
	ifact[0]=1;
	for(ll A=1;A<MAX;A++)
	{
		fact[A]=(A*fact[A-1])%mod;
		ifact[A]=power(fact[A],mod-2);
	}
	cin>>N;
	for(int A=1;A<=N;A++)	
		cin>>arr[A];
	for(int A=2;A<=N;A++)
	{
		dp[A]=((nCr(N,A)*fact[A-1])%mod*fact[N-A])%mod;
		dp[A]=(dp[A-1]+dp[A])%mod;
	}
	for(int A=1;A<=N;A++)
	{
		res=(res+(arr[A]*fact[N])%mod)%mod;
		res=(res+(arr[A]*dp[N-A+1])%mod)%mod;
		res=(res+(arr[A]*dp[A])%mod)%mod;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 6400
while True:
    a, b, c = map(str, input().split())
    a = int(a)
    c = int(c)
    if(b == '+'):
        print(a + c)
    elif(b == '-'):
        print(a - c)
    elif(b == '*'):
        print(a * c)
    elif(b == '/'):
        print(a // c)
    else:
        break


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

const ll INF = 1LL << 60;
const ll MOD = 998244353;
ll dp[200020];

int main() {
  int N,K;
  cin >> N >> K;
  int l[10], r[10];
  REP(i,K) cin >> l[i] >> r[i];

  dp[1] = 1;
  dp[2] = -1;
  for( int i=1; i<=N; i++ ) {
    dp[i] = (dp[i] + dp[i-1]) % MOD;
    REP(j,K) {
      if ( i+l[j] <= N )
        dp[i+l[j]] = (dp[i+l[j]] + dp[i]) % MOD;
      if ( i+r[j]+1 <= N ) {
        dp[i+r[j]+1] = dp[i+r[j]+1] - dp[i];
        if (dp[i+r[j]+1] < 0) dp[i+r[j]+1] += MOD;
      }
    }
//    REP(i,N+1) cout << dp[i] << " ";
//    cout << endl;
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 5188
/*
    NO 
        TIME 
            TO 
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <complex>
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// define x, y as real(), imag()


template<class T>
istream& operator>> (istream& is, complex<T>& p) {
  T value;
  is >> value;
  p.real(value);
  is >> value;
  p.imag(value);
  return is;
}
#define M_PI 3.14159265358979323846
typedef long long int lli;
lli mod=1e9+9ll;
#define OS //single input use oeis
lli INF=9223372036854775807;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,z,k,x,m,d,y,q,b,c;
const double pi=3.14159265358979323846;
lli me(lli a,lli b)
{
    // cout<<mod<<"\n";
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
bool cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.first.first==b.first.first&&a.first.second==b.first.second)
    {
        return a.second.second>b.second.second;
    }
    return a.first<b.first;
}
pair<ll,ll> p[55];
vector<lli> vv;
lli mx=0;
void dfs(lli i,lli m,lli start)
{
    if(i==11)
    {
        // vv.push_back(m);
        // cout<<m<<"\n";
        
        lli ans=0;
        for(int j=1;j<=q;j++)
        {
            lli a,b,c,d;
            a=p[j].first.first;
            b=p[j].first.second;
            c=p[j].second.first;
            d=p[j].second.second;
            // cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
            if(vv[b-1]-vv[a-1]==c)
            {
                ans+=d;
            }
        }
        mx=max(mx,ans);
        // vv.pop_back();
        return;
    }
    // cout<<start<<"\n";
    for(lli j=start;j<=m;j++)
    {
        vv.push_back(j);
        dfs(i+1,m,j);
        vv.pop_back();
    }
}
int main()
{
 #ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 #endif
 IO;
 OS;
 
 cin>>n>>m>>q;
 for(int i=1;i<=q;i++)
 {
    cin>>p[i].first.first>>p[i].first.second>>p[i].second.first>>p[i].second.second;
 }
 vv.push_back(1);
 dfs(2,m,1);
 cout<<mx;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> inline void chadd(T &a, const T b) { a = a + b; }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

const int MAXSIZE = 3000 + 10;
double dp[MAXSIZE][MAXSIZE];

int main() {
  int N; cin>>N;
  vector<double> p(N);
  REP(i,N) cin>>p[i];
  dp[0][0] = 1.0;
  REP(i,N) {
    for(int j = 0; j <= i; j++) {
      chadd(dp[i+1][j], dp[i][j] * (1.0 - p[i]));
      chadd(dp[i+1][j+1], dp[i][j] * p[i]);
    }
  }
  double ans = 0.0;
  for(int i = N; i > (N-i); i--) {
    ans += dp[N][i];
    //cout << i << " " << dp[N][i] << " " << ans << endl;
  }
  printf("%0.10f", ans);
  puts("");
  return 0;
}


Measured memory_bytes: 69120
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c,d = inpl()
cnt = 0
while True:
    if cnt == 0:
        c -= b
        if c <= 0:
            print('Yes')
            break
    else:
        a -= d
        if a <= 0:
            print('No')
            break
    cnt ^= 1



Measured memory_bytes: 10464
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long int;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a; i < b; i++)

int main() {

	int a, b;
	cin >> a >> b;

	if (a <= 9 && b <= 9) cout << a * b << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

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


    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v;
            que.push(nv);
        }
    }
    bool flag = true;
    for (int v = 0; v < N; ++v) {
        if (dist[v]==-1) flag = false;
    }
    if(flag){
        cout << "Yes" << endl;
        for (int i = 1; i < N; i++)
        {
            cout << dist[i]+1 << endl;
        }
        
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 13336
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll L;
	while(cin>>L) {
		ll mx = 0, co = 0, acc=0;
		VI off;
		VI bs;
//		DD(L);
		REP(i, 32) {
			ll j = 31-i;
			if(L>>j&1) {
				mx = max(mx, j);
				co++;
				off.PB(acc);
				acc += 1LL<<j;
				bs.PB(j);
			}
		}
//		DD(bs);
//		DD(off);
		cout<<mx+1<<" "<<mx*2+bs.size()-1<<endl;
		REP(i, mx) {
			cout<<i+1<<" "<<i+2<<" "<<0<<endl;
			cout<<i+1<<" "<<i+2<<" "<<(1LL<<(mx-1-i))<<endl;
		}
		RANGE(i, 1, bs.size()) {
			cout<<1<<" "<<1+bs[0]-bs[i]<<" "<<off[i]<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s; cin >> s;
    int ans;
    if (s == "SUN") ans = 7;
    else if (s == "MON") ans = 6;
    else if (s == "TUE") ans = 5;
    else if (s == "WED") ans = 4;
    else if (s == "THU") ans = 3;
    else if (s == "FRI") ans = 2;
    else if (s == "SAT") ans = 1;

    cout << ans << endl;

    return 0;
}
 

Measured memory_bytes: 256
import sys
from collections import deque
readline = sys.stdin.readline
n = int(readline())
li = list(map(int, readline().split()))
def square(P):
    G = []
    L = deque()
    for i, v in enumerate(P):
        if not L:
            L.append((i, v))
            continue
        if v > L[-1][1]:
            L.append((i, v))
        elif v < L[-1][1]:
            k = i - 1
            while L and v < L[-1][1]:
                a = L.pop()
                G.append((k - a[0] + 1) * a[1])
            L.append((a[0], v))
    while L:
        a = L.pop()
        G.append((n - a[0]) * a[1])
    return max(G)
print(square(li))

Measured memory_bytes: 22920
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void solve()
{
int n;
int k;
cin>>n>>k;
vector<int> v(n);
for(int i=0;i<n;i++)
cin>>v[i];
sort(v.begin(),v.end());
auto it=v.begin();
long long int sum=0;
int cnt=0;
while(cnt<k)
{
sum+=*it;
it++;
cnt++;
}
cout<<sum<<endl;
}
int main()
{
	
FASTIO
 long long int t;
 t=1;
 while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 3644
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int a,b; cin >> a;
  char op; cin >> op;
  cin >> b;

  if (op=='+'){cout << a+b;}
  else {cout << a-b;}



  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
 
using namespace std; 
 
int used[100001];
 
void dfs(int a, int b, const int k, int &ans) {
	if(used[a] <= b) return;
	else used[a] = b;
	if(a == 0) {
		ans = min(ans,b);
		return;
	}
	if (b + 1 < ans) dfs((a + 1) % k, b + 1, k, ans);
	dfs((a * 10) % k, b, k, ans); 
} 
 
int main() {
        int k, ans = 0;
        scanf("%d", &k);
        int kk = k;
        while (kk > 0) { 
                ans += kk % 10;
                kk /= 10;
        }
        for (int i = 0; i <= k; i ++) used[i] = 1 << 30;
	dfs(1, 1, k, ans);
        printf("%d\n", ans);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
#define PI acos(-1.0)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int main()
{
 
    int r, c, i, j, f;
    char s[150][150];
    cin>>r>>c;
    map <int,int> mpr, mpc;
    for(i=0;i<r;i++){
        for(j=0;j<c;j++)cin>>s[i][j];
    }
    for(i=0;i<r;i++){
        f=0;
        for(j=0;j<c;j++){
           if(s[i][j]=='#'){
                f=1;
                break;
           }
        }
        if(f==1)mpr[i]=-1;
    }
    for(i=0;i<c;i++){
        f=0;
        for(j=0;j<r;j++){
           if(s[j][i]=='#'){
                f=1;
                break;
           }
        }
        if(f==1)mpc[i]=-1;
    }
    for(i=0;i<r;i++){
        f=0;
        for(j=0;j<c;j++){
           if(mpr[i]==-1 && mpc[j]==-1){
                cout<<s[i][j];f=1;
            }
        }
        if(f)cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
   int64_t N,A,B;
   cin>>N>>A>>B;
   if(N==1&&A!=B){cout<<0<<endl;return 0;}
   else if(A>B){cout<<0<<endl;return 0;}
   cout<<(N-1)*B+A-((N-1)*A+B)+1<<endl;
return 0;}

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

//const int mymax = 2147483647;
const long mymax=9223372036854775807;

//int sol = mymax;

long judge(vector<long> C, int X, vector< vector<long> > A, vector<int> buff, int bR){
    int M = A[0].size();
    vector<long> sums(M,0);
    long cost = 0;
    for(int i=0;i<bR;i++){
        int cursor = buff[i];
        //cout << cursor << " "; ////////////////////////
        for(int j=0;j<M;j++){
            sums[j] += A[cursor][j];
        }
        cost += C[cursor];
    }
    int tmp_judge=1;
    for(int j=0;j<M;j++){
        if(sums[j]<X){
            tmp_judge=0;
        }
    }
    if(tmp_judge){
        //cout << ": ok : " << cost << endl; ////////////////////////
        //if(sol>cost) sol = cost;
        return cost;
    }else{
        //cout << ": no : " << cost << endl; /////////////////////
        return -1;
    }
}

// コストデータ、目標値データ
// 選択肢データ、選択肢カーソルleft, 選択肢カーソルright
// 選択済みバッファ、今何個目、全部で何個、
long dfs(vector<long> C, int X, vector< vector<long> > A, int sL,int sR, vector<int> buff, int bL, int bR){
    
    if(bL==bR){
        return judge(C,X,A,buff,bR);
    }

    // あと何個選ぶの？
    //int num = bR-bL;
    // どこまでの範囲から選ぶの？
    int tmpR = sR-(bR-bL-1);

    long cost;
    int tmp_judge=-1;
    long tmp_min = mymax;

    for(int i=sL;i<tmpR;i++){
        buff[bL] = i;
        cost = dfs(C,X, A,i+1,sR, buff,bL+1,bR);
        // i冊でできるか判定？
        if(cost==-1)    continue;
        // できるならその価格を記憶
        if(tmp_min>cost){
            //for(int j=0;j<bL;j++) cout << "  "; ////////
            //cout << tmp_min << " -> " << cost << "  "; ////////
            //for(int j=0;j<bL;j++) cout << buff[j] << "  "; cout << buff[bL] << endl; ////////
            tmp_min = cost;
            tmp_judge = 0;
        }
    }

    if(tmp_judge==-1){
        return -1;
    }else{
        //for(int j=0;j<bL;j++) cout << "  "; ////////
        //cout << "back " << tmp_min << endl;/////////////////////
        return tmp_min;
    }
}

int main(){
    int N,M,X;
    cin >> N >> M >> X;

    vector< vector<long> > A(N, vector<long>(M, 0));
    vector<long> C(N, 0);

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

    vector<int> buff(N,0);
    int tmp_judge=-1;
    long tmp_min = mymax;
    long cost;
    for(int i=1;i<=N;i++){
        cost = dfs(C,X, A,0,N, buff,0,i);
        // i冊でできるか判定？
        if(cost==-1)    continue;
        // できるならその価格を記憶
        if(tmp_min>cost){
            //cout << tmp_min << " -> " << cost << endl; ////////
            tmp_min = cost;
            tmp_judge=0;
        }
    }

    if(tmp_judge==-1){
        cout << -1 << endl;
    }else{
        cout << tmp_min << endl;
        //cout << sol << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

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

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;

//.....................
const int MAX = (int)2e5 + 5;

char s_[MAX];
int n, m;
double board[20][20];

double dfs(int reached) {
	static int used;
	static double dp[1 << 17][20];
	static bool done[1 << 18][20];
	if (done[used][reached] == true) {
		return dp[used][reached];
	}
	double res = 0.0;
	if (reached == n) {
		return 1.0;
		if (test) cerr << "!";
	}
	rep(i, m) {
		if ((used >> i) & 1) continue;
		used |= 1 << i;
		double res_i = 0.0;
		double keep_win_p = 1.0;
		REP(j, reached, n) {
			res_i += dfs(j) * keep_win_p * (1.0 - board[i][j]);
			if (test) dump(dfs(j));
			keep_win_p *= board[i][j];
		}
		res_i += keep_win_p;
		chmax(res, res_i);
		used ^= 1 << i;
	}
	done[used][reached] = true;
	return dp[used][reached] = res;
}

void solve() {
	 m = atoi(s_);
	cin >> n;
	rep(i, m) rep(j, n) cin >> board[i][j];
	cout << dfs(0) << endl;
}

signed main() {
	int T = 10;
	cout << fixed << setprecision(15);
	rep(i, T) {
		if (scanf("%s", s_) == EOF) break;
		solve();
		break;
	}
	return 0;
}

Measured memory_bytes: 14820
void main()
{
    long n, k;
    rdVals(n, k);
    Coord[] p = n.rdCol!Coord;

    long[] xlist = new long[n], ylist = new long[n];
    foreach (i; 0 .. n)
    {
        xlist[i] = p[i].x, ylist[i] = p[i].y;
    }
    xlist.sort!"a < b", ylist.sort!"a < b";

    long result = (xlist[$-1] - xlist[0]) * (ylist[$-1] - ylist[0]);
    foreach (i; 0 .. n-1)
    {
        foreach (j; i+1 .. n)
        {
            foreach (s; 0 .. n-1)
            {
                foreach (t; s+1 .. n)
                {
                    Coord u = Coord(xlist[i], ylist[s]);
                    Coord v = Coord(xlist[j], ylist[t]);
                    long cnt;
                    foreach (d; p)
                    {
                        if (d.check(u, v)) ++cnt;
                    }
                    if (cnt >= k)
                    {
                        Coord diff = v - u;
                        result = min(result, diff.area);
                    }
                }
            }
        }
    }

    result.writeln;
}


struct Coord
{
    long x, y;

    this(long x, long y)
    {
        this.x = x, this.y = y;
    }

    Coord opBinary(string op)(Coord that)
    if (op == "+")
    {
        return Coord(this.x + that.x, this.y + that.y);
    }

    Coord opBinary(string op)(Coord that)
    if (op == "-")
    {
        return Coord(this.x - that.x, this.y - that.y);
    }

    bool check(Coord l, Coord r)
    {
        return l.x <= this.x && this.x <= r.x && l.y <= this.y && this.y <= r.y;
    }

    long area()
    {
        return this.x * this.y;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256