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

using namespace std;

string s;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> s;
    while (s.length() < 15) {
        s += 'o';
    }
    int cnt = 0;
    for (char c : s) {
        cnt += c == 'o';
    }
    if (cnt >= 8) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayList<Integer> x = new ArrayList<>();
		while (true) {
			int a = Integer.parseInt(in.next());
			String op = in.next();
			int b = Integer.parseInt(in.next());
			if (op.equals("?")) {
				break;
			}
			switch (op) {
			case "+":
				x.add(a + b);
				break;
			case "-":
				x.add(a - b);
				break;
			case "*":
				x.add(a * b);
				break;
			case "/":
				x.add(a / b);
				break;
			}
		}
		
		for (Integer ans : x) {
			System.out.println(ans);
		}
	}
}	


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

using namespace std;

int main() {
    int A,B;
    string op;
    cin>>A>>op>>B;
    if(op=="+"){
        cout<<A+B<<endl;
    }else{
        cout<<A-B<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())

a = list(map(int,input().split()))

b = 0
ans = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        continue
    elif a[i] > a[i+1]:
        if b <= 0:
            b = -1
        else:
            b = 0
            ans += 1
    else:
        if b >= 0:
            b = 1
        else:
            b = 0
            ans += 1
print(ans)

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()

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

    ll n,t[100001],x[100001],y[100001];
    Cin(n);
    rep(i,n) Cin3(t[i],x[i],y[i]);
    if(n==1){
        if((x[0]==1 && y[0]==0) || (x[0]==0 && y[0]==1) || (x[0]==-1 && y[0]==0) || (x[0]==0 && y[0]==-1)){
            Cout("Yes");
            return 0;
        }else{
            Cout("No");
            return 0;
        }
    }
    rep(i,n-1){
        if((t[i+1]-t[i]) < abs(x[i+1]-x[i])+abs(y[i+1]-y[i])){
            Cout("No");
            return 0;
        }
        if((t[i+1]-t[i])%2 != (abs(x[i+1]-x[i])+abs(y[i+1]-y[i]))%2){
            Cout("No");
            return 0;
        }
    }
    Cout("Yes");
    return 0;
}

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

int a[22], b[22], c[22];

int main() {
	int n;
    int i;
    cin >> n;
    for(i=1;i<=n;i++)
    cin >>a[i];
    
    int sum = 0;
    for(i=1;i<=n;i++)
        cin >> b[i], sum+=b[i];
    for(i=1;i<=n-1;i++)
        cin >> c[i];
    
    for(i=2;i<=n;i++){
        if(a[i-1]+1==a[i])
            sum+=c[a[i-1]];
    }
    cout<<sum;
	
	return 0;
}

Measured memory_bytes: 256
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { x = (x > y ? y: x);}
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { x = (x < y ? y: x);}
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
using ll = long long;
const string FILENAME = "input";
const int MAXN = 200228;


int n;
int a[MAXN], b[MAXN];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME); 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    set<pair<int, int> > s;
    for (int i = 0; i < n; i++) {
        s.insert({b[i], i});
    }
    long long res = 0;
    while (!s.empty()) {
        auto x = *s.rbegin();
        if (x.first == a[x.second]) {
            s.erase(x);
            continue;
        }
        if (x.first < a[x.second]) {
            cout << -1 << endl;
            return 0;
        }
        int f = b[(x.second + n - 1) % n];
        int f1 = b[(x.second + 1) % n];
        if (f + f1 > x.first) {
            cout << -1 << endl;
            return 0;
        }
        s.erase(x);
        int g = a[x.second];
        if (b[x.second] % (f + f1) >= g) {
            res += b[x.second] / (f + f1);
            b[x.second] %= (f + f1);
            s.insert({b[x.second], x.second});
            continue;
        }
        int t = (b[x.second] - g) / (f + f1);
        if (t == 0) {
            cout << -1 << endl;
            return 0;
        }
        res += t;
        b[x.second] -= (f + f1) * (t);
        s.insert({b[x.second], x.second});
    }
    cout << res << endl;
    return 0; 
}



Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
 
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; }
 
#define rep(i,cc,n) for(long long i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
 struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int>p(n);
  rep(i, 0, n){
      cin >> p[i];
      p[i]--;
  }
  UnionFind tree(n);
  rep(i, 0, m){
      int x, y;
      cin >> x >> y;
      x--,y--;
      tree.merge(x,y);
  }
  int ans = 0;
  rep(i, 0, n){
      if(tree.issame(i,p[i]))ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
 
int main()
{
    int N, M, T;
    scanf("%d%d%d", &N, &M,&T);
    int t{-M}, sum{};
    for (int i{}; i < N; i++)
    {
        int a;
        scanf("%d", &a);
        sum += std::max(0, a - t - 2 * M);
        t = a;
    }
    sum += std::max(T - t - M, 0);
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 3208
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<u32> = read_col(n);

    for i in 0..n {
        if a[i] % 2 == 1 {
            println!("first");
            return;
        }
    }
    println!("second");
    return;
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string x,y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        int c[x.size()+1][y.size()+1];
        for(int j=0;j<x.size()+1;j++){
            for(int k=0;k<y.size()+1;k++){
                if(j==0||k==0)c[j][k]=0;
                else if(j>0&&k>0&&x[j-1]==y[k-1]) c[j][k]=c[j-1][k-1]+1;
                else if(j>0&&k>0&&x[j-1]!=y[k-1])c[j][k]=max(c[j][k-1],c[j-1][k]);
            }
        }
        int maxi=0;
        for(int j=0;j<x.size()+1;j++){
            for(int k=0;k<y.size()+1;k++){
               maxi=max(maxi,c[j][k]);
               c[j][k]=0;
            }
        }
        cout<<maxi<<endl;
    }
    
}



Measured memory_bytes: 6916
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import ceil, floor

def main():
  k = int(input())
  la = list(map(int, input().split()))[::-1]
  l = 2
  r = 2
  for a in la:
    if ceil(l/a) > floor(r/a):
      print(-1)
      return
    l = ceil(l/a) * a
    r = floor(r/a) * a + a - 1
  print(l, r)
      

if __name__=='__main__':
  main()



Measured memory_bytes: 15020
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//最大公約数を求める
fn gcd(x: usize, y: usize) -> usize {
    if x == 0 {
        return y;
    } else {
        return gcd(y % x, x);
    }
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();

    //最小公倍数を求める
    let l = n * (m / gcd(n, m));

    //文字列Xの候補に必要な要素のインデックスを得る
    let mut x_s: Vec<usize> = [1; 1].to_vec();
    let mut x_t: Vec<usize> = [1; 1].to_vec();
    for i in 1..n {
        x_s.push(x_s[i - 1] + (l / n));
    }
    for i in 1..m {
        x_t.push(x_t[i - 1] + (l / m));
    }

    //println!("x_s{:?}", x_s);
    //println!("x_t{:?}", x_t);

    let mut s_i = 0;
    let mut t_i = 0;
    let mut chk_s = vec![];
    let mut chk_t = vec![];

    //x_sとx_tで同じところを参照する箇所を抽出する
    while s_i != x_s.len() && t_i != x_t.len() {
        if x_s[s_i] == x_t[t_i] {
            chk_s.push(s_i);
            chk_t.push(t_i);
            s_i += 1;
            t_i += 1;
        } else {
            if x_s[s_i] < x_t[t_i] {
                s_i += 1;
            } else {
                t_i += 1;
            }
        }
    }

    //println!("chk_s{:?}", chk_s);
    //println!("chk_t{:?}", chk_t);

    let mut ans_flag = true;
    //同じところを参照して、一致しているか判定する
    for (x, y) in chk_s.into_iter().zip(chk_t.into_iter()) {
        if s[x] != t[y] {
            ans_flag = false;
        }
    }

    if ans_flag {
        println!("{}", l);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4392
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, N; 
  cin >> H >> N;

  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];

  vector<int> dp(H+1, INF);
  dp[0] = 0;

  REP(i, N) REP(now, H+1){
    if(dp[now] == INF) continue;
    int next = min(H, now+A[i]);
    chmin(dp[next], dp[now]+B[i]);
  }

  cout << dp[H] << "\n";

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define  rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> vi;
typedef long int li;
typedef unsigned long long ull;

int main(int argc,char* argv[])
{
    int N, ans=0;
    cin >> N;
    vi a(N);
    rep(i,N) cin >> a[i];
    rep(i,N) if(a[a[i]-1]==i+1) ans++;
    cout<< ans/2 <<endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        
        StringBuilder ans = new StringBuilder(br.readLine());
        
        ans.setCharAt(3, '8');
        
        writer.println(ans.toString());
        
        br.close();
        writer.close();
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
 

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll k = 5*(n/105);
	ll s = n%105;
	if (s+k >= 100 || s == 0){
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
}

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

int main() {
  int h, w;
  cin >> h >> w;

  map<int, int> s;
  multiset<int> vals;
  rep(i, w) {
    s[i] = i;
    vals.insert(0);
  }

  rep(i, h) {
    int l, r;
    cin >> l >> r;
    --l;
    auto itr = s.lower_bound(l);
    int mr = -1;
    while (itr != s.end() && itr->first <= r) {
      mr = max(mr, itr->second);
      int x = itr->first - itr->second;
      vals.erase(vals.find(x));
      s.erase(itr++);
    }
    if (mr != -1 && r < w) {
      s[r] = mr;
      vals.insert(r - mr);
    }
    int ans = -1;
    if (vals.size()) ans = *(vals.begin());
    if (ans != -1) ans += i + 1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 22332
N = int(input())
h = list(map(int, input().split()))[::-1]
f = [0] * N
ans = 'Yes'
last = 10 ** 10
for hi in h:
    if last >= hi:
        last = hi
    elif last >= hi - 1:
        last = hi - 1
    else:
        ans = 'No'
print(ans)


Measured memory_bytes: 63984
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 301000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
int n, Rt;
int cnt[N];
int fa1[N], fa2[N];
struct edge{
	int nxt, to;
}e[N << 1];
int head[N], ecnt = 1;
inline void addedge(int from, int to) {
	e[++ecnt] = (edge){head[from], to};
	head[from] = ecnt;
}

int blong[N];
bool evis[N << 1], etype[N << 1];
void dfs(int cur) {
	for (int &i = head[cur]; i; i = e[i].nxt) {
		if (evis[i])	continue;
		evis[i] = evis[i ^ 1] = true;
		etype[i] = true;
		int to = e[i].to; dfs(to);
	}
}

int main() {
	read(n); Rt = n + n + 1;
	for (int i = 1; i <= n; ++i) {
		read(fa1[i]);
		if (fa1[i] == -1)	fa1[i] = Rt;
		addedge(fa1[i], i); addedge(i, fa1[i]);
		++cnt[fa1[i]];
	}
	for (int i = 1; i <= n; ++i) {
		read(fa2[i]);
		if (fa2[i] == -1)	fa2[i] = Rt;
		else	fa2[i] += n;
		addedge(fa2[i], i + n); addedge(i + n, fa2[i]);
		++cnt[fa2[i]];
	}
	for (int i = 1; i <= n; ++i) {
		if ((cnt[i] & 1) != (cnt[i + n] & 1)) {
			puts("IMPOSSIBLE");
			return 0;
		}
		if (!(cnt[i] & 1))
			addedge(i, i + n), blong[i] = ecnt, addedge(i + n, i);
	}
	puts("POSSIBLE");
	dfs(1);
	for (int i = 1; i <= n; ++i) {
		if (cnt[i] & 1)	printf("0 ");
		else	printf("%d ", etype[blong[i]] ? 1 : -1);
	}
	return 0;
}


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

using namespace std;

const int INF = 1 << 29;

int main()
{
  int N, Ma, Mb, A[40], B[40], C[40];
  int dp[401][401];
  fill_n(*dp, 401 * 401, INF);

  cin >> N >> Ma >> Mb;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i];
  }

  dp[0][0] = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 400; j >= A[i]; j--) {
      for(int k = 400; k >= B[i]; k--) {
        dp[j][k] = min(dp[j][k], dp[j - A[i]][k - B[i]] + C[i]);
      }
    }
  }

  int ret = INF;
  for(int i = 1; i < 400; i++) {
    for(int j = 1; j < 400; j++) {
      if(i * Mb == j * Ma) ret = min(ret, dp[i][j]);
    }
  }

  if(ret >= INF) cout << -1 << endl;
  else cout << ret << endl;
}

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

int main(){
  using namespace std;
  int n, m, t;
  int sum = 0;
  cin >> n >> m;
  for(int i=0; i<m; i++){
    cin >> t;
    sum += t;
  }
  if(sum > n){
    cout << "-1" << endl;
    return 0;
  }
  cout << n-sum << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(){
	int a , b , c ;
	cin >> a >> b >> c ;
	if ( a > b )
		swap ( a , b );
	if ( a > c )
		swap ( a , c );
	if ( b > c )
		swap ( b , c );
	cout << a << " " << b << " " << c << endl;
}

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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(a<b){
		cout<<"Bob"<<endl;
	}else if(b<a){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Draw"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import bisect
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
cum = list(itertools.accumulate(A))
ans = 10**10
for i2 in range(1, N - 2):
    i1 = i = bisect.bisect_left(cum, cum[i2] // 2)
    c = abs(cum[i2] - 2 * cum[i1])
    for j in range(i - 1, i + 2):
        if 0 <= j < i2 and abs(cum[i2] - 2 * cum[j]) < c:
            i1 = j
            c = abs(cum[i2] - 2 * cum[j])
    i3 = i = bisect.bisect_left(cum, (cum[i2] + cum[N - 1]) // 2)
    c = abs(cum[N - 1] + cum[i2] - 2 * cum[i3])
    for j in range(i - 1, i + 2):
        if i2 < j < N - 1 and abs(cum[N - 1] + cum[i2] - 2 * cum[j]) < c:
            i3 = j
            c = abs(cum[N - 1] + cum[i2] - 2 * cum[j])
    B = [cum[i1], cum[i2] - cum[i1], cum[i3] - cum[i2], cum[N - 1] - cum[i3]]
    ans = min(ans, max(B) - min(B))
print(ans)


Measured memory_bytes: 98752
C = []
max_c = 0
for i in range(3):
  c = list(map(int,input().split()))
  C.append(c)
  max_c = max(max(c),max_c)

judge = 0 #0:不可,1:可
for i in range(max_c+1):
  a1 = i #a1のみ決めて後は全探索
  b1,b2,b3 = C[0][0]-a1,C[0][1]-a1,C[0][2]-a1
  if( ((C[1][0]-b1)==(C[1][1]-b2))and((C[1][0]-b1)==(C[1][2]-b3)) ):#a2
    if( ((C[2][0]-b1)==(C[2][1]-b2))and((C[2][0]-b1)==(C[2][2]-b3)) ):#a3
       judge = 1
       break

if(judge == 0): print('No')
else: print('Yes')

Measured memory_bytes: 3064
tmp = [int(i) for i in input().split()]
M, D = tmp[0], tmp[1]
if D < 22 or M < 4:
  print(0)
else:
  days = [(str(i)[0], str(i)[1]) for i in range(22,  D+1) if int(str(i)[0])>1 and int(str(i)[1])>1]

  n = 0
  for m in range(4, M+1):
      for d in days:
          if m == int(d[0])*int(d[1]):
              n +=1
  print(n)

Measured memory_bytes: 3064
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        sc.close();

        System.out.println(Math.min(N*A, B));
    }
}

Measured memory_bytes: 23764
O = str(input())
E = str(input())

flg = 0
N = max(len(O), len(E))
if len(O) > len(E):
  flg = 1

ans = ''
if flg:
  for i in range(N):
    if i == N-1:
      ans += O[i]
    else:
      ans += O[i] + E[i]
else:
  for i in range(N):
    ans += O[i] +E[i]
print(ans)

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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    string str;
    cin>>str;
    int len = str.length();
    if(len%2!=0 || n%2!=0){
        cout<<"No\n";
        return 0;
    }
    int i = 0, j = n/2;
    while(i<n/2 && j<len){
        if(str[i]!=str[j]){
            cout<<"No\n";
            return 0;
        }
        i++;
        j++;
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

void liner_search(int *S, int *T, int n, int q);

int main(void)
{
    int n,q;
    int *S,*T;
    int i;

    scanf("%d", &n);
    S = calloc(n, sizeof(int));
    
    for (i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    T = calloc(q, sizeof(int));

    for (i = 0; i < q; i++){
        scanf("%d", &T[i]);
    }

    liner_search(S, T, n, q);

    return (0);
}

void liner_search(int *S, int *T,int n, int q)
{
    int i,j;
    int count;

    count = 0;
    for (i = 0; i < q; i++){
        j = 0;
        while (j < n){
            if (S[j] == T[i]){
                count++;
                break;
            }
            j++;
        }
    }
    printf("%d\n", count);


}


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int main(){
	int a, b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

map<ll, bool> mp;
int main() {
  ll hoge = 1;
  while(hoge < 1e9*3) {
    mp[hoge] = 1;
    hoge *= 3;
  }
  ll a;
  while(cin >> a) {
    int ans = 0;
    if (mp[a]) ans = -1;
    while(a) {
      a /= 3;
      ans++;
    }
    
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 23:
    print(0)
    exit()
for i in range(13):
    if D.count(i) >= 3:
        print(0)
        exit()
    elif D.count(i) == 2 and D.count(i+1) == 2:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)


Measured memory_bytes: 18720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> s = a;
	sort(s.rbegin(), s.rend());
	rep(i, n) {
		int ans = s[0];
		if (s[0] == a[i]) ans = s[1];
		cout << ans << endl;
	}
	

	return 0; 
}









Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int x,n;
  cin>>x>>n;
  if(n==0) cout<<x<<endl;
  else{
    int a[n];
    rep(i,0,n){
      cin>>a[i];
    }
    sort(a,a+n);
    int i=0;
    while(true){
      if(upper_bound(a,a+n,x-i)-lower_bound(a,a+n,x-i)==0){
        cout<<x-i<<endl;
        break;
      }
      if(upper_bound(a,a+n,x+i)-lower_bound(a,a+n,x+i)==0){
        cout<<x+i<<endl;
        break;
      }
      i++;
    }
  }
}

Measured memory_bytes: 3580
def C():
    import math
    n= int(input())

    counter = 0
    for i in range(1,13):
        if int(26*(pow(26,i-1))/(26-1)) <= n < int(26*(pow(26,i))/(26-1)):
            counter = i
            break
    kekka = n - int(26*(pow(26,counter-1))/(26-1))

    alplist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

    kekkalist = []
    i = counter-1
    while i>= 0 :
        sho = int(kekka / pow(26,i))
        kekka = kekka - pow(26,i)*sho

        i -=1
        if i >= 0:
            kekkalist.append(alplist[sho])
        else:
            kekkalist.append(alplist[sho])


    print("".join(kekkalist))


C()


Measured memory_bytes: 9240
#include <cstdio>
int main() {
    long long n;
    scanf("%lld",&n);
    for (long long i = 1;i <= 3500;i++)
        for (long long j = 1;j <= 3500;j++)
            if (4*i*j-n*i-n*j > 0 && !(n*i*j%(4*i*j-n*i-n*j))) {
                printf("%lld %lld %lld",i,j,(n*i*j)/(4*i*j-n*i-n*j));
                return 0;
            }
    return 0;
}

Measured memory_bytes: 128
c = []
3.times{c << gets.split().map(&:to_i)}
d = Array.new(3).map{Array.new(3,0)}
(0..2).each do |i|
  (0..2).each do |j|
    d[i][j] = c[i][0] + c[0][j] - c[0][0]
  end
end
puts c==d ? :Yes : :No

Measured memory_bytes: 3836
Input = list(map(int, input().split()))
a = Input[0]
b = Input[1]


ra= 0
rb =0

for i in range(a):
  rb += b*(10**i)

for i in range(b):
  ra += a*(10**i)

if ra>=rb:
  print(ra)
else:
  print(rb)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int main()
{
    int n,x,mid;
    cin>>n;
    vector<pair<int,int> >v;
    int ans[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.pb(mp(x,i));
    }
    sort(v.begin(),v.end());
    mid=n/2-1;
    for(int i=mid+1;i<n;i++)
    {
        ans[v[i].second]=v[mid].first;
    }
    for(int i=0;i<=mid;i++)
    {
        ans[v[i].second]=v[mid+1].first;
    }
    for(int i=0;i<n;i++)
        cout<<ans[i]<<endl;
}


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

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

    if(400<=N && N<=599){
        cout<<"8";
    }
    else if(600<=N && N<=799){
        cout<<"7";
    }
    else if(800<=N && N<=999){
        cout<<"6";
    }
    else if(1000<=N && N<=1199){
        cout<<"5";
    }
    else if(1200<=N && N<=1399){
        cout<<"4";
    }
    else if(1400<=N && N<=1599){
        cout<<"3";
    }
    else if(1600<=N && N<=1799){
        cout<<"2";
    }
    else if(1800<=N && N<=1999){
        cout<<"1";
    }
    return 0;
}

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

int main()
{
    int k, a, b; cin >> k >> a >> b;
    int c = 0;
    bool f = false;
    rep(i, 1000) {
        c += k;
        if (c >= a && c <= b) {
            f = true;
            break;
        }
    };

    cout << (f?"OK":"NG") << endl;


    return 0;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int ans[20010];

int main(void) {
	int N;
	cin >> N;
	if (N == 3) {
		cout << "2 5 63" << endl;
	}
	else if (N == 4) {
		cout << "2 5 20 63" << endl;
	}
	else if (N == 5) {
		cout << "2 3 603 602 6002 " << endl;
	}
	else {
		int sum = 0;
		int num = 2;
		for (int i = 0; i < N; i++) {
			while (!(num % 2 == 0 || num % 3 == 0)) {
				num++;
			}
			ans[i] = num;
			sum += num % 6;
			sum %= 6;
			num++;
		}
		switch (sum % 6) {
		case 2:
			ans[4] = 30000;
			break;
		case 3:
			ans[5] = 30000;
			break;
		case 5:
			ans[5] = 30000 - 2;
			break;
		}
		for (int i = 0; i < N - 1; i++) {
			cout << ans[i] << " ";
		}
		cout << ans[N - 1] << endl;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner
fun main(args: Array<String>) {
   val scanner = Scanner(System.`in`)
    val N = scanner.nextInt()
    val M = scanner.nextInt()
    val list = mutableListOf<Int>()
    for(i in 0 until (M*2)){
        list.add(scanner.nextInt())
    }
    for(i in 1..N){
        var count = 0
        list.forEach { 
            if(it == i) count++
         }
         println(count)
    }
}

Measured memory_bytes: 29720
# coding: utf-8
import itertools
n, k = map(int, raw_input().split())
ls = map(int, raw_input().split())
kls = []
for i in range(10):
    if i not in ls:
        kls.append(i)
#print ls,kls
ans_list = []
repeat_len = len(str(n))
while not ans_list:
    for element in itertools.product(kls, repeat=repeat_len):
        a = int("".join(map(str,element)))
        if a >= n:
            ans_list.append(a)
    repeat_len += 1
print ans_list[0]




Measured memory_bytes: 2820
def seigi(s):
  lens = len(s)
  if lens%2==1:
    return "No"
  lensp2 = int(lens/2)
  for si in range(lensp2):
    if s[si] != s[si + lensp2]:
      return "No"
  return "Yes"
  
r = input()
s = input()
print(seigi(s))

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

int main(){
    long long n;
    long long ans=1;
    cin >> n;
    vector<long long> a(n);
    bool flag = false;
    rep(i,n){
        cin >> a.at(i);
        if(a.at(i) == 0)flag = true;
    }
    if(flag){
        cout << 0 << endl;
        return 0;
    }
    rep(i,n){
        long long b;
        b = ans;
        ans *= a.at(i);
        if(ans > 1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
        
        if(ans <= 0){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    }

Measured memory_bytes: 4020
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}











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

using namespace std;

typedef long long ll;

signed main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(auto& x : a){
        cin >> x;
    }
    ll acc = accumulate(a.begin(), a.end(), 0LL);
    ll ans = 0;
    vector<int> b(m);
    for(auto& x : b){
        cin >> x;
        ans += acc * x;
    }
    cout << ans << endl;
}




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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(ll, n);
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> m;
  ll ans = 0;
  rep(i, n) {
    ans += m[i - a[i]];
    m[i + a[i]]++;
  }
  out(ans);
}


Measured memory_bytes: 27544
#include<bits/stdc++.h>
#define re register
int f[6010][9030],mod;
int main()
{
	re int n;
	scanf("%d%d",&n,&mod);
	f[0][6010]=1;
	for(re int i=0;i<3*n;i++)
	{
		for(re int j=-i;j<=i/2;j++)
		if(f[i][j+6010]){
			f[i+1][j-1+6010]=(f[i+1][j-1+6010]+f[i][j+6010])%mod;
			f[i+2][j+1+6010]=(f[i+2][j+1+6010]+1ll*f[i][j+6010]*(i+1))%mod;
			f[i+3][j+6010]=(f[i+3][j+6010]+1ll*(i+2)*(i+1)*f[i][j+6010])%mod;
		}
	}
	re int ans=0;
	for(re int i=-3*n;i<=0;i++)ans=(ans+f[3*n][i+6010])%mod;
	printf("%d\n",ans);
}

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

int gcd(int m,int n){
  if(n==0)
    return m;

  return gcd(n,m%n);
}
int main(){
  int W,H,C;
  cin >> W >> H >> C;
  int a = gcd(W,H);
  cout << (W/a)*(H/a)*C << endl;
  return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;       
main(){
    int X,A;
    cin >> X >> A;
    if(X < A)cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
//a问题 
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,ans;
	cin>>n;
	ans=n%1000;
	if (0==ans) {
		cout<<0<<endl; 
	}else {
		cout<<1000-ans<<endl;
	}
	return 0;
} 

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;

	ll max = (n - 1) * b + a;
	ll min = (n - 1) * a + b;
	if (max >= min) {
		cout << (max - min + 1) << endl;
	}
	else {
		cout << 0 << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    cout << min(n % k, abs((n % k) - k)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 80
//#include<string.h>

void reset(int *p){
    int i;
    for(i=0;i<102;i++)p[i]=0;
}

int main(){
    int n,i,j,len1,len2,len;
    int n1[102],n2[102],ans[102];
    char s1[101]={0},s2[101]={0},a[102]={0};
    scanf("%d",&n);
    while(n){
        n--;
        reset(ans);
        reset(n1);
        reset(n2);
        scanf("%s%s",s1,s2);
        for(i=0;s1[i]!='\0';i++);len1=i;
//len1=strlen(s1);
        for(i=0;s2[i]!='\0';i++);len2=i;
//len2=strlen(s2);
        if(len1>MAX||len2>MAX){
            puts("overflow");
            continue;
        }
        for(j=0,i=len1-1;i>=0;i--,j++)n1[i]=s1[j]-'0';
        for(i=len2-1,j=0;i>=0;i--,j++)n2[i]=s2[j]-'0';
if(len1==1&&len2==1&&n1[0]==0&&n2[0]==0){
printf("0\n");
continue;
}
        for(i=0;i<102;i++){
            ans[i]+=(n1[i]+n2[i]);
            ans[i+1]+=ans[i]/10;
            ans[i]%=10;
        }
        for(i=101;ans[i]==0;i--);
        len=i+1;
        if(len>MAX){
            puts("overflow");
            continue;
        }
        for(i=len-1,j=0;i>=0;j++,i--){
            a[j]=ans[i]+'0';
        }
        a[j]='\0';
        printf("%s\n",a);
    }
    return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  for (int i = 0; i < 3; i++){
    if (S.at(i) == T.at(i)) {
      cnt++;
    }
  }
  
  cout << cnt;
}

Measured memory_bytes: 256
let () =
  let rec doit l =
    let n = read_int () in
    if n <> 0 then doit (n :: l)
    else
      match l with
      | [] -> assert false
      | hd :: tl ->
        Printf.printf "%d\n" hd;
        doit tl in
  try doit [] with _->()

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

int N, M, arr[100005];
long long m[100005], c[100005];

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%d", &arr[i]);
		arr[i]--;
	}
	long long ans = 0;
	for (int i = 1; i < N; i++) {
		if (arr[i-1] < arr[i]) ans += arr[i] - arr[i - 1];
		else ans += arr[i] + M - arr[i - 1];
	}
	for (int i = 1; i < N; i++) {
		if (arr[i-1] < arr[i]) {
			m[arr[i-1] + 1]++;
			c[arr[i-1] + 1] -= arr[i - 1] + 1;
			m[arr[i] + 1]--;
			c[arr[i] + 1] += arr[i - 1] + 1;
		} else {
			m[arr[i-1] + 1]++;
			c[arr[i-1] + 1] -= arr[i - 1] + 1;
			m[0]++;
			c[0] -= arr[i - 1] - M + 1;
			m[arr[i] + 1]--;
			c[arr[i] + 1] += arr[i - 1] - M + 1;
		}
	}
	long long ms = 0, cs = 0, ans1 = 1000000000000000000ll;
	for (int i = 0; i < M; i++) {
		ms += m[i];
		cs += c[i];
		ans1 = min(ans1, ans - (ms * i + cs));
		//printf("%d: %lld\n", i, ans - (ms * i + cs));
	}
	printf("%lld\n", ans1);
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int i,q;
	int c,a,n;
	int cnt;
	cin>>q;
	for(i=0;i<q;i++){
		cin>>c>>a>>n;
		cnt=0;
		if(c>=1&&a>=1&&n>=1){
			while(1){
				//cout<<"check"<<endl;
				if(c<=0||a<=0||n<=0)	break;
				c--;
				a--;
				n--;
				cnt++;
			}
		}
		if(c>=2&&a>=1){
			while(1){
				//cout<<"check1"<<endl;
				if(c<2||a<=0)			break;
				c-=2;
				a--;
				cnt++;
			}
		}
		cnt+=c/3;
		cout<<cnt<<endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll d, t, s;
    cin >> d >> t >> s;

    if (t >= (d + s - 1) / s)
    {
        cout << "Yes" << endl;
    }
    else
    {

        cout << "No" << endl;
    }
}


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

using namespace std;
const int N = 1e5+10;
vector<pair<int,int> >edge[N];
int vis[N],dis[N];
void spfa(int st)
{
    queue<int>q;
    q.push(st);
    vis[st] = 1;
    dis[st] = 1;
    while(!q.empty())
    {
        int top = q.front();q.pop();
        vis[top] = 0;
        for(int i = 0;i < edge[top].size();i++)
        {
            int to = edge[top][i].first,w = edge[top][i].second;
            if(dis[to] > dis[top] + w)
            {
                dis[to] = dis[top] + w;
                if(!vis[to])
                {
                    vis[to] = 1;
                    q.push(to);
                }
            }
        }
    }
}
int main()
{
    int k;
    scanf("%d",&k);
    for(int i = 1;i < k;i++)
    {
        edge[i].push_back(make_pair((i+1)%k,1));
        edge[i].push_back(make_pair(i*10%k,0));
    }
    memset(vis,0,sizeof(vis));
    memset(dis,0x3f,sizeof(dis));
    spfa(1);
    printf("%d\n",dis[0]);
    return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl '\n'
int main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "rt", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    fast
    string s;cin>>s;
    vector<string> v(2, "");
    int flag=1;
    int q;cin>>q;
    while(q--){
    	int x;cin>>x;
    	if(x==1){
    		flag=1-flag;
    		//cout<<"f:"<<flag<<endl;
    	}
    	if(x==2){
    		int p;cin>>p;p--;
    		char t;cin>>t;
    		v[abs(1-flag-p)]+=t;
    		//cout<<abs(1-flag-p)<<" "<<v[p]<<endl;
    	}
    }
   // cout<<"st:"<<v[0]<<" end:"<<v[1]<<endl<<flag<<endl;
    string ans;
    if(!flag) reverse(s.begin(), s.end());
    reverse(v[1-flag].begin(), v[1-flag].end());
    ans=v[1-flag] + s+ v[flag];
    cout<<ans;

#ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Measured memory_bytes: 1300
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M;
string week[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string S;
int main() {
    cin >> S;

    int ans;
    for (int i = 0; i < 7; i++) {
        if (S == week[i])
            ans = 7 - i;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

set<int> se;
int ar[100005];

int32_t main(){
	int n,m,from,to;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		ar[i]=1;
	}
	se.insert(1);
	for(int i=1;i<=m;i++){
		cin>>from>>to;
		ar[from]--;
		ar[to]++;
		if(se.count(from)){
			se.insert(to);
		}
		if(!ar[from]){
			se.erase(from);
		}
	}
	cout<<se.size();
}


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

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int H,W,vis[1000][1000],K;
int mps[1000][1000],lds;
char sd[1000];
int sx,sy,dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
inline void deal(int xx,int yy)
{
	lds=min(lds,xx-1);
	lds=min(lds,H-xx);
	lds=min(lds,yy-1);
	lds=min(lds,W-yy);
	
}
int main()
{
	H=read(); W=read(); K=read();
	lds=1000;
	for(int i=1;i<=H;i++)
	{
		scanf("%s",sd);
		for(int j=0;j<W;j++)
		{
			mps[i][j+1]=sd[j]=='#';
			if(sd[j]=='S') sx=i,sy=j+1;
		}
	}
	queue <int> q; while(!q.empty()) q.pop();
	//cerr << sx << " " << sy << endl;
	q.push(sx); q.push(sy); vis[sx][sy]=0;
	deal(sx,sy);
	while(!q.empty())
	{
		int lx=q.front(); q.pop();
		int ly=q.front(); q.pop();
		for(int i=0;i<4;i++)
		{
			int vx=lx+dir[i][0];
			int vy=ly+dir[i][1];
			if(vx<1||vy<1||vx>H||vy>W) continue;
			if(mps[vx][vy]) continue;
			if(!vis[vx][vy]&&vis[lx][ly]<K)
			{
				vis[vx][vy]=vis[lx][ly]+1;
				deal(vx,vy);
				q.push(vx); q.push(vy);
			}
		}
	}
	cout << 1+lds/K+(lds%K!=0) << endl;
	return 0;
}


Measured memory_bytes: 7296