akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	var n, m int

	n = nextInt()
	m = nextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		if i != 0 {
			a[i] += a[i-1]
		}
		a[i] %= m
	}

	var ans int64
	mp := make(map[int]int)

	for i := 0; i < n; i++ {
		mp[a[i]]++
		if a[i] == 0 {
			ans += int64(mp[0])
		} else {
			ans += int64(mp[a[i]]) - 1
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 7296
# include <iostream>
# include <climits>
# include <algorithm>
using namespace std;

int n, W;
int weight[110], value[110];

int dp[110][10010];

int main(void) {
    cin >> n >> W;
    for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

    // DPの初期条件を設定する
    for (int w = 0; w <= W; ++w) dp[0][w] = 0;

    // 各荷物 i について処理していく
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= W; ++w) {
            // wを超えないかどうか
            if (w >= weight[i]) {
                // 入れることを選択する場合、入れなかった場合で最適な方を選択
                dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
            }
            else {
                // この荷物は入れられないので、選択できない
                dp[i + 1][w] = dp[i][w];
            }
        }
    }

    cout << dp[n][W] << endl;
}



Measured memory_bytes: 7036
#include <cstdio>
#include <queue>
using namespace std;

int main()
{
  int h,w;
  scanf("%d%d",&h,&w);
  static char M[1000][1001];
  for(int i=0;i<h;i++){
    scanf("%s",M[i]);
  }
  static int K[1000][1001]={0};
  int dx[8]={1,1,1,0,0,-1,-1,-1},dy[8]={-1,0,1,-1,1,-1,0,1};
  queue<pair<int,int> > Q[2];
  bool b=0;
  for(int i=1;i<h-1;i++){
    for(int j=1;j<w-1;j++){
      for(int v=0;v<8;v++){
	int x=i+dx[v],y=j+dy[v];
	if(M[x][y]=='.'){
	  K[i][j]++;
	}
      }
      if(M[i][j]!='.'&&K[i][j]>=M[i][j]-'0'){
	Q[b].push(make_pair(i,j));
      }
    }
  }
  int t=0;
  while(!Q[b].empty()){
    while(!Q[b].empty()){
      pair<int,int> p=Q[b].front();
      Q[b].pop();
      int i=p.first,j=p.second;
      for(int v=0;v<8;v++){
	int x=i+dx[v],y=j+dy[v];
	K[x][y]++;
	if(M[x][y]!='.'&&K[x][y]==M[x][y]-'0'){
	  Q[!b].push(make_pair(x,y));
	}
      }
    }
    t++;
    b=!b;
  }
  printf("%d\n",t);
  return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int x[550], a[330000];
signed main() {
    cin >> N;
    for (int i = 1; i <= N; i++)cin >> x[i];
    for (int i = 1; i <= N; i++) {
        if (a[x[i]] != 0) {cout << "No" << endl; return 0;}
        a[x[i]] = i;
    }
    queue<int> l, r;
    for (int i = 1; i <= N * N; i++) {
        if (a[i] != 0) {
            for (int j = 0; j < a[i] - 1; j++)l.push(a[i]);
        }
    }
    for (int i = N * N; i >= 1; i--) {
        if (a[i] != 0) {
            for (int j = 0; j < N - a[i]; j++)r.push(a[i]);
        }
    }

    for (int i = 1; i <= N * N; i++) {
        if (l.empty())break;
        if (x[l.front()] < i) {cout << "No" << endl; return 0;}
        if (a[i] != 0)continue;
        a[i] = l.front(), l.pop();
    }
    for (int i = N * N; i >= 1; i--) {
        if (r.empty())break;
        if (x[r.front()] > i) {cout << "No" << endl; return 0;}
        if (a[i] != 0)continue;
        a[i] = r.front(), r.pop();
    }
    cout << "Yes" << endl;
    for (int i = 1; i <= N * N; i++)cout << a[i] << " ";
    cout << endl;
}


Measured memory_bytes: 5248
import sys
def cross(x1,y1,x2,y2):
    return x1*y2-y1*x2
for line in sys.stdin.readlines():
    line=map(float,line.strip().split(","))
    x,y=line[0::2],line[1::2]
    xv=[x[(i+1)%4]-x[i] for i in xrange(4)]
    yv=[y[(i+1)%4]-y[i] for i in xrange(4)]
    if 0<len([i for i in xrange(4) if cross(xv[i],yv[i],xv[(i+1)%4],yv[(i+1)%4])>0])<4: print "NO"
    else:print "YES"
#temp

Measured memory_bytes: 5736
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int H,W;
    cin >> H >> W;
    string S[H];
    
    rep(i,0,H) {
        cin >> S[i];
    }

    int ans[H][W] = {0};

    rep(h,0,H) {
        rep(w,0,W) {
            ans[h][w] = 0;
        }
    }

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

    rep(h,0,H) {
        rep(w,0,W) {
            if (S[h][w] == '#') {
                continue;
            }

            rep(i,0,8) {
                if (h+dy[i]>=0 && h+dy[i]<H && w+dx[i]>=0 && w+dx[i]<W) {
                    if (S[h+dy[i]][w+dx[i]]=='#') {
                        ans[h][w]++;
                    }
                }
            }
        }
    }
    rep(h,0,H) {
        rep(w,0,W) {
            if (S[h][w]=='#') {
                cout << '#';
            }
            else {
                cout << ans[h][w];
            }
        }
        cout << endl;
    }

}


Measured memory_bytes: 256
number=list(map(int,input().split()))
n,D=number[0],number[1]
ans=0

for i in range(n):
    tmp=list(map(int,input().split()))
    L=int(tmp[0]**2+tmp[1]**2)**float(1/2)
    if L<=D:
        ans+=1

print(ans)

Measured memory_bytes: 70476
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	int s, w;
	cin >> s >> w;
	if (s <= w) cout << "unsafe" << endl;
	else cout << "safe" << endl;
} 

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

int main()
{
  int n,j=0,now=0;
  cin>>n;
  int a[n];
  for(int i=1; i<n+1; i++)cin>>a[i];
  now=a[1];
  if(now==2){
    cout<<"1"<<endl;
    j=1;
    return 0;
  }
  for(int i=1; i<n; i++){
    now=a[now];
    if(now==2){
      j=1;
      cout<<i+1<<endl;
      break;
    }
  }
  if(j==0)cout<<"-1"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is_palindrome(string s) {
  for(int i=0;i<s.size();i++){
    if(s[i]!=s[s.size()-1-i])return false;
  }
  return true;
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  string s;cin>>s;

  if(is_palindrome(s)&&is_palindrome(s.substr(0, s.size()/2))&&is_palindrome(s.substr(s.size()/2+1, s.size()/2)))
    puts("Yes");
  else
    puts("No");

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	long long a,b,n;
	scanf("%lld%lld%lld",&a,&b,&n);
	long long x=min(n,b-1);
	printf("%lld\n",a*x/b-a*(x/b));
}


Measured memory_bytes: 1704
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;

const ll mod=1e9+7;

ll zettaiti(ll a){
	return (a>0)?a:-1*a;
}

int main(){
	int n,m;
	cin>>n>>m;
	ll x[n],y[m];
	ll minx=0,miny=0;
	rep(i,n){
		cin>>x[i];
		minx=min(minx,x[i]);
	}
	if(minx<0)rep(i,n)x[i]+=zettaiti(minx);
	rep(i,m){
		cin>>y[i];
		miny=min(miny,y[i]);
	}
	if(miny<0)rep(i,m)y[i]+=zettaiti(miny);
	ll sumx=0,sumy=0;
	rep(i,n)sumx+=(i-(n-i-1))*x[i];
	rep(i,m)sumy+=(i-(m-i-1))*y[i];
	cout<<((sumx%mod)*(sumy%mod))%mod<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std ;
int main()
  { 
   string a,b,c;
   cin>>a>>b>>c;
   transform(a.begin(),a.end(),a.begin(),::toupper); 
  transform(b.begin(),b.end(),b.begin(),::toupper); 
 transform(c.begin(),c.end(),c.begin(),::toupper); 

   cout<<a[0]<<b[0]<<c[0]<<endl;
}

Measured memory_bytes: 256
import sys
MOD = 2019

l, r = map(int, sys.stdin.readline().split())
r = min(r, l + MOD - 1)

def main():
    res = MOD - 1
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            res = min(res, (i % MOD) * (j % MOD) % MOD)
    print(res)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 40176
#include<bits/stdc++.h>
#define maxn 100010
#define mod 1000000007
using namespace std;
char s[maxn];
int pre[maxn], nxt[maxn][3], able[maxn][3], f[maxn];
int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	for (int i = 1; i <= n; i++)
	{
		pre[i] = pre[i - 1];
		if (s[i] == 'a') pre[i] = (pre[i] + 1) % 3;
		else pre[i] = (pre[i] + 2) % 3;
	}
	int flag = 0;
	for (int i = 1; i <= n - 1; i++)
		if (s[i] == s[i + 1]) flag = 1;
	if (flag == 0) {puts("1"); return 0;}
	for (int i = 0; i <= 2; i++)
		nxt[n + 1][i] = able[n + 1][i] = n + 1;
	for (int i = n; i >= 0; i--)
	{
		for (int j = 0; j <= 2; j++)
		{
			nxt[i][j] = nxt[i + 1][j];
			able[i][j] = able[i + 1][j];
		}
		if (i)
		{
			nxt[i][pre[i]] = i;
			able[i][pre[i]] = i;
		}
		for (int j = 0; j <= 2; j++)
			if (i != n && i != 0 && s[i] == s[i + 1]) able[i][j] = min(able[i][j], nxt[i + 1][j]);
	}
	f[0] = 1;
	for (int i = 0; i <= n - 1; i++)
		for (int j = 1; j <= 2; j++)
		{
			int tmp = able[i][(j + pre[i]) % 3];
			f[tmp] = (f[tmp] + f[i]) % mod;
		}
	int res = 0;
	for (int i = 1; i <= n; i++)
		if (pre[n] == pre[i]) res = (res + f[i]) % mod;
	printf("%d\n", res);
	return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong K;
  cin >> K;

  queue<llong> que;
  for (int i = 1; i <= 9; ++i) {
    que.push(i);
  }
  while (--K) {
    llong n = que.front();
    que.pop();
    for (int i = 0; i <= 9; ++i) {
      if (abs(n % 10 - i) <= 1) {
        que.push(n * 10 + i);
      }
    }
  }

  cout << que.front() << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

int main(){
	while(1){	
		int n;
		long a[51]={0};
		
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i) scanf(" %ld", &a[i]);
		sort(a, a+n);
		
		int now=0;
		bool flag=false;
		while(now<n){
			bool ct=false;
			
			//printf("now=%d\n",now);
			
			if(flag) printf(" ");	
			printf("%ld", a[now]);
			
			while(a[now+1] == a[now]+1){
				ct=true;
				++now;	
			}
			if(ct) printf("-%ld", a[now]);
			++now;
			flag=true;
		}
		printf("\n");
	}
	return 0;
}

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

int main()
{
  int n;
  int g[105][105];
  
  cin >> n;

  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;

    for(int j = 0; j < n; j++) g[u-1][j] = 0;

    for(int j = 0; j < k; j++){
      int v;
      cin >> v;

      g[u-1][v-1] = 1;
      
    }

    for(int j = 0; j < n; j++){
      if(j) cout << " ";
      cout << g[i][j];
    }

    cout << endl;
    
  }

  return 0;

}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const int INF = (1<<30)-1;
const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];

  ll ans = INF;
  rep(b,1<<n) {
    if (pcnt(b) < k) continue;
    vi x = a;
    ll cost = 0;
    ll pmax = -1;
    rep(i,n) {
      if (bit(b,i)) {
        if (pmax+1 > x[i]) {
          cost += pmax+1 - x[i];
          x[i] = pmax+1;
        }
      }
      chmax<ll>(pmax,x[i]);
    }
    chmin(ans, cost);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int min(int i,int j){
	if(i<j)return i;
	return j;
}

int main(){
	int A,B,C,D,m;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	A = min(A,B);
	B = min(C,D);
	m = A+B;
	printf("%d",m);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;
    double crane, turtle;
    if (x * 4 < y) {
        cout << "No\n";
        return 0;
    }
    crane = 2.0 * (double)x - ((double)y / 2.0);
    turtle = ((double)y - (2.0 * (double)x)) / 2.0;
    //cout << crane << ", " << turtle << endl;
    if (crane < 0 || turtle < 0 || (int)crane + (int)turtle != x) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  int A, B;
  cin >> A >> B;
  print(max(0, A - 2 * B));
  return 0;
}

Measured memory_bytes: 256
def i_coins(N, P):
    """
    N枚の番号が振られたコインがある。i番目のコインを投げたときに
    表が出る確率はp_i, 裏が出る確率は1-p_iである。
    N枚のコインをすべて投げるとき、表の枚数が裏の枚数を上回る確率を求めよ。
    """
    # dp[i][j]: コインをi枚使ったとき、表がj枚である確率
    dp = [[0.0] * (N + 1) for _ in range(N + 1)]
    dp[0][0] = 1.0  # これで初期化(0枚投げて表が0枚である確率は考えられないが)
    for i in range(1, N + 1):
        # 表が出た回数が投げたコインの枚数を上回ることはありえない
        for j in range(i + 1):
            # i枚使ってj枚表が出る確率
            # = i-1枚使ってj-1枚表が出る確率 * i枚目が表である確率
            # + i-1枚使ってj枚表が出る確率 * i枚目が裏である確率
            dp[i][j] = (dp[i - 1][j - 1] * P[i - 1] * int(j >= 1)
                        + dp[i - 1][j] * (1.0 - P[i - 1]))

    ans = 0.0
    for i in range(N // 2 + 1, N + 1):
        ans += dp[N][i]  # N枚使ってN//2+1枚以上表が出る確率を足し合わせると解
    ans = round(ans, 11)  # round()は正確には偶数への丸めだが、使う
    return ans

N = int(input())
P = [float(i) for i in input().split()]
print(i_coins(N, P))

Measured memory_bytes: 115548
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int dp[110000][3];
    int a[110000];
    int b[110000];
    int c[110000];
    int n;
    cin >> n;
    rep(i, 1, n+1) {
        cin >> a[i] >> b[i] >> c[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];
    }
    int res = 0;
    res = max(res, dp[n][0]);
    res = max(res, dp[n][1]);
    res = max(res, dp[n][2]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head, const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    double r;
    in(r);
    out((double)M_PI*r*r,(double)2*M_PI*r);
}



Measured memory_bytes: 3280
import java.io.*;
import java.util.*;

public class Main {

    static PrintStream out = System.out;

    static void solve(Scanner in) {

        int A = in.nextInt();
        int B = in.nextInt();
        int k = in.nextInt();


        int res = 0;
        int cnt = 0;
        for(int i = Math.min(A, B); i >= 1; i--){
            if(A%i == 0 && B%i == 0){
                cnt++;
                if(cnt == k){
                    res = i;
                    break;
                }
            }
        }
        System.out.println(res);

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        solve(in);
    }
}

Measured memory_bytes: 21844
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<utility>
#include<vector>
#include<memory>
using namespace std;

int n,m;
int ans=0;
vector<int> gra[11];
bool used[11];

void dfs(int x,int s)
{
	if(s==n)
	{
		ans++;
		return;
	}
	for(int i=0;i<gra[x].size();i++)
	{
		if(used[gra[x][i]]==false)
		{
			used[gra[x][i]]=true;
			dfs(gra[x][i],s+1);
			used[gra[x][i]]=false;
		}
	}
}

int main()
{
	cin>>n>>m;
	int a,b;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		gra[a].push_back(b);
		gra[b].push_back(a); 
	}
	used[1]=true;
	dfs(1,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(m)]

L=[i[0] for i in LR]
R=[i[1] for i in LR]
ans=min(R)-max(L)
if ans>=0:
  print(ans+1)
else:
  print(0)


Measured memory_bytes: 29048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  rep(i, S.size()) {
    if(S[i] != T[i]) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  ll N, Q, S = 0;
  cin >> N;
  vi A(N), count(1e5 + 10);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    count[A[i]]++;
    S += A[i];
  }
  cin >> Q;
  ll b, q;
  for (ll i = 0; i < Q; i++) {
    cin >> b >> q;
    S += count[b] * (q - b);
    cout << S << endl;
    count[q] += count[b];
    count[b] = 0;
  }
}


Measured memory_bytes: 4816
N = int(input())
S = input()
R = S.count("R")
G = S.count("G")
ans = R*G*(N-R-G)

for i in range(N-2):
    for j in range(i,N-1):
        k = 2*j - i
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

            
print(ans)

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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i <= _##i poi  i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i < _##i poi  i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i >= _##i poi  i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i > _##i poi  i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

using namespace std;

#define fuwafuwa(n, c) dokidoki((n) + (c) - 1, c)
#define dokidoki(n, c) ((n) / (c) * (c))

template<class T> bool read(T& t){
    return cin >> t poi
}
template<class T, class...U> bool read(T& t, U&... u){
    unless(cin >> t) return false poi
    return read(u...) poi
}

template<class T> T lov_yet(T t){
    if(t) return t poi
    else return 0 poi
}

template<class T> T gcd(T a, T b){
    if(b) return gcd(b, a % b) poi
    else return a poi
}

pair<double, double> solve_linear(double a1, double b1, double c1, double a2, double b2, double c2){
    return make_pair(lov_yet((b1 * c2 - b2 * c1) / (b1 * a2 - b2 * a1)), lov_yet((a1 * c2 - a2 * c1) / (a1 * b2 - b1 * a2))) poi
}

double distance(const pair<double, double>& p){
    return lov_yet(sqrt(p.first * p.first + p.second * p.second)) poi
}
double distance(const pair<double, double>& a, const pair<double, double>& b){
    return distance(make_pair(a.first - b.first, a.second - b.second)) poi
}

int main(){
    int W, N poi
    cin >> W >> N poi

    vector<int> pyon(W) poi
    times(W, i) pyon[i] = i poi

    times(N, i){
        int A, B poi
        char comma poi
        cin >> A >> comma >> B poi
        A--poi B--poi
        swap(pyon[A], pyon[B]) poi
    }

    times(W, i) cout << pyon[i] + 1 poipoi poi

    return 0 poi
}

Measured memory_bytes: 1188
#include <iostream>

using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, N, A, B;
	cin >> N;
	if (N == 1)cout << "Hello World" << endl;
	else {
		cin >> A >> B;
		cout << A + B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
vector<int> et[100000];
vector<int> ec[100000];
int color[100000];

void dfs(int p, int v, int dep) {
	color[v] = dep % 2;
	int i;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		dfs(v, nv, dep + ec[v][i]);
	}
}

signed main() {
	int i;

	cin >> n;
	rep(i, n - 1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		et[u].push_back(v);
		ec[u].push_back(w);
		et[v].push_back(u);
		ec[v].push_back(w);
	}

	dfs(-1, 0, 0);

	rep(i, n) {
		cout << color[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 15488
a,b,c,x,y = list(map(int,input().split()))
for i in range(100001):
    price_new = i*2*c + max(0, x-i)*a + max(0, y-i)*b
    if i==0:
        price = price_new
    else:
        price = min(price, price_new)

print(price)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// 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();
}

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

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

  int n;
  cin >> n;

  const int m = 55556;
  vector<bool> primes(m, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i < m; i++) {
    if (primes[i]) {
      for (int j = i * i; j < m; j += i) primes[j] = false;
    }
  }

  vector<int> ans;
  int cnt = 2;
  while (n) {
    if (primes[cnt]) {
      if (cnt % 5 == 1) {
        ans.push_back(cnt);
        n--;
      }
    }
    cnt++;
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << (i != (int)ans.size() - 1 ? " " : "");
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
typedef long long ll;
using namespace std;
int ren[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(void){
    int k;cin>>k;
    cout<<ren[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int A,B;
  scanf("%d %d",&A,&B);
  if(A>=13){
    printf("%d",B);
  }
  else if(A>=6 && A<=12){
    printf("%d",B/2);
  }
  else{
    printf("0");
  }
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		long cum = 0;
		int idx = -1;
		for (int i = 0; i < N; ++i) {
			if (cum * 2 < A[i]) {
				idx = i;
			}
			cum += A[i];
		}
		System.out.println(N - idx);
	}
}


Measured memory_bytes: 50344
#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;
}
*/
ll n,m;
vl g[MAX];
ll done[MAX],dp[MAX];
ll dfs(ll u)
{
    if(done[u])
        return dp[u];
    ll ans = 0;
    for(auto v:g[u])
    {
        ans = max(ans,1+dfs(v));
    }
    done[u] = 1;
    return dp[u] = ans;
}
int main()
{
    FAST;
    cin>>n>>m;
    for(ll i=1; i<=m; ++i)
    {
        ll u,v;
        cin>>u>>v;
        g[u].pb(v);
    }
    ll ans = 0;
    for(ll i=1; i<=n; ++i)
    {
        dfs(i);
        ans = max(ans,dp[i]);
    }
    cout<<ans;
    return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 12616
//新幹線からAC

#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n,0);
        inv = vector<int>(n,0);
        fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
	int a; cin >> a;
	cout << 48-a << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    string s;

    cin >> n >> s;
    int m = s.size();

    int cnt1 = 0,cnt2 = 0;//记录（和）的个数

    for (int i = 0; i < m ; i ++ )
    {
        if(s[i] == '(') cnt1++;
        else if(s[i] != '(')
        {
            if(cnt1 > 0) cnt1--;
            else if(cnt1 == 0) cnt2++;
        }
    }

    for (int i = 0; i < cnt1; i ++ ) s=s+')';
    for (int i = 0; i < cnt2; i ++ ) s='('+s;

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

int n;
int l[200010],r[200010];
int main() {
    
    ll a,b,c;
    cin>>a>>b>>c;
  if(b>c){cout<<0;return 0;}
  if(a == 1 && b!=c)cout<<0;
  else
    cout<<(a-2)*(c-b)+1;
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define sll            set<ll int>
#define msll        multiset<ll int>
#define io    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll n,a[100005],b[100005],c[100005];
ll dp[100005][4];

ll go(ll i, ll pichla){
    if(i>n) return 0;

    if(dp[i][pichla]!=-1) return dp[i][pichla];
    ll ans=-1e17;
    if(pichla!=1) ans=max(ans,go(i+1,1)+a[i]);
    if(pichla!=2) ans=max(ans,go(i+1,2)+b[i]);
    if(pichla!=3) ans=max(ans,go(i+1,3)+c[i]);
    return dp[i][pichla]=ans;
}

int main()
{
    io
    ll i,j;
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];

    cout<<go(1,0);




    return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main ()
{

    int d;
    int t;
    int s;
    cin >> d >> t >> s;
   	int ds = s*t;
    if (ds>=d)
    {
        cout<<"Yes"<<endl;
    }
    else 
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3600
cards_available = {}
for suit in (['S ', 'H ', 'C ', 'D ']):
    for num in range(1,14):
        s = suit + str(num)
        cards_available[s] = False

n = int(input())
for i in range(n):
    s = input()
    cards_available[s] = True

nalist = [k for k, v in cards_available.items() if v == False]
for card in nalist:
    print(card)



Measured memory_bytes: 5604
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

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

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<int> C;
    vector<vector<int>> D;
    vector<int> prev;
    int max_C = 200001;

    void input() {
        cin >> N;
        C.resize(N);
        D.resize(max_C);
        rep(i, 0, N) {
            cin >> C[i];
            C[i]--;
            D[C[i]].push_back(i);
        }
        prev.resize(N, -1);
        for (int i = 0; i < max_C; ++i) {
            for (int j = 1; j < D[i].size(); ++j) {
                prev[D[i][j]] = D[i][j - 1];
            }
        }
    }

    void solve() {
        input();
        vector<ll> dp(N);
        dp[0] = 1;
        for (int i = 1; i < N; ++i) {
            if (prev[i] != -1 && prev[i] != i - 1) {
                dp[i] = (dp[i - 1] + dp[prev[i]]) % MOD;
            } else {
                dp[i] = dp[i - 1];
            }
        }
        cout << dp[N - 1] << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <string>
using namespace std;
int main(){
     int N,M;
     int c[300],v[300],d[300],l[300];
     int V[301],D[301],L[301];
     while(cin>>N>>M){
	  if(cin.eof())break;
	  for(int i=0;i<N;i++){
	       string temp;
	       getline(cin,temp);
	       //cout<<temp;
	       getline(cin,temp);
	       //cout<<temp;
	       cin>>c[i]>>v[i]>>d[i]>>l[i];
	  }
	  for(int i=0;i<M+1;i++) V[i]=D[i]=L[i]=0;
	  for(int i=0;i<N;i++){
	       for(int j=c[i];j<M+1;j++){
		    V[j]=max(V[j],V[j-c[i]]+v[i]);
		    D[j]=max(D[j],D[j-c[i]]+d[i]);
		    L[j]=max(L[j],L[j-c[i]]+l[i]);
	       }
	  }
	  cout<<max(V[M],max(D[M],L[M]))<<endl;
     }
     return 0;
}

Measured memory_bytes: 932
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N,K; cin >> N >> K;
  vector<ll> a(N), b(N);
  REP(i,N){
    cin >> a[i];
    b[i] = max(0LL, a[i]);
  }
  vector<ll> suma(N+1,0), sumb(N+1,0);
  REP(i,N){
    suma[i+1] = suma[i] + a[i];
    sumb[i+1] = sumb[i] + b[i];
  }

  ll ans = -1e18;
  //i,i+1,...,i+K-1の色を固定
  FOR(i,1,N-K+2){
    ll u = max(0LL,suma[i+K-1]-suma[i-1]);
    ll t = sumb[i-1] + u + sumb[N] - sumb[i+K-1];
    ans = max(ans,t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
priority_queue<PR> que;
vector<PR> e[MAXN];
int fu[MAXN],fv[MAXN],su[MAXN],sv[MAXN],flag[MAXN],n,m,S,T;
void getdist(int *f,int *s,int S,int T)
{
	for (int i=1;i<=n;i++) f[i]=loo,flag[i]=0;
	que.push(MP(0,S)),f[S]=0,s[S]=1;
	while (!que.empty())
	{
		int q=que.top().se,c=-que.top().fi; que.pop();
		if (flag[q]) continue; flag[q]=1;
		for (auto v:e[q])
			if (f[v.fi]>c+v.se) 
				s[v.fi]=s[q],f[v.fi]=c+v.se,que.push(MP(-f[v.fi],v.fi));
			else if (f[v.fi]==c+v.se) (s[v.fi]+=s[q])%=mods;
	}
}
signed main()
{
	n=read(),m=read(),S=read(),T=read();
	for (int i=1;i<=m;i++)
	{
		int u=read(),v=read(),c=read();
		e[u].PB(MP(v,c)),e[v].PB(MP(u,c));
	}
	getdist(fu,su,S,T);
	getdist(fv,sv,T,S);
	
	int D=fu[T],ans=0;
	for (int i=1;i<=n;i++) 
		if (fu[i]*2==D&&fv[i]*2==D)
		{
			int t=su[i]*sv[i]%mods;
			ans+=t*(t-1)%mods;
		}
	for (int i=1;i<=n;i++)
		for (auto v:e[i])
		if (i<v.fi)
		{
			int x=i,y=v.fi,c=v.se;
			if (fu[x]>fu[y]) swap(x,y);
			if (fu[x]*2<D&&fv[y]*2<D&&fu[x]+fv[y]+v.se==D) 
			{
				int t=su[x]*sv[y]%mods;
				ans+=t*(t-1)%mods;
			}
		}
	ans%=mods;
	printf("%lld\n",(su[T]*(su[T]-1)-ans+mods)%mods);
	return 0;
}

Measured memory_bytes: 32412