akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> v;
	int flag = 1;
	int cnt = 0;
	rep(i,n) {
		if (flag == s[i] - '0') {
			cnt++;
		} else {
			v.push_back(cnt);
			cnt = 1;
			flag = 1 - flag;
		}
	}
	if (cnt) v.push_back(cnt);
	if (v.size() % 2 == 1) v.push_back(0);
	vector<int> sum(v.size() + 1);
	rep(i,v.size()) sum[i+1] = sum[i] + v[i];

	int ans = 0;
	for (int i = 0; i < (int) sum.size(); i += 2) {
		int t = sum[min(i + 2 * k + 1, (int) sum.size() - 1)] - sum[i];
		ans = max(ans, t);
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

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

bool isPrime (int n) {
    if (n <= 1) return false;
    for (int i=2, l=(int)sqrt(n); i<=l; ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}
int main() {
    int n; cin >> n;
    int num = 0;
    for (int i=0; i<n; ++i) {
        int x; cin >> x;
        num += isPrime(x);
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

dist = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        dist.append([dx, dy])

res = N
for p, q in dist:
    cnt = 0
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            if p == x[i] - x[j] and q == y[i] - y[j]:
                cnt += 1
    res = min(res, N - cnt)

print(res)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx, dy = ty - sy;
	rep(i, 0, abs(dx)) {
		if (dx < 0) cout << 'L';
		else cout << 'R';
	}
	rep(i, 0, abs(dy)) {
		if (dy < 0)cout << 'D';
		else cout << 'U';
	}
	rep(i, 0, abs(dx)) {
		if (dx < 0) cout << 'R';
		else cout << 'L';
	}
	rep(i, 0, abs(dy)) {
		if (dy < 0)cout << 'U';
		else cout << 'D';
	}

	if (dy < 0)cout << 'U';
	else cout << 'D';
	rep(i, 0, abs(dx) + 1) {
		if (dx < 0) cout << 'L';
		else cout << 'R';
	}
	rep(i, 0, abs(dy) + 1) {
		if (dy < 0)cout << 'D';
		else cout << 'U';
	}
	if (dx < 0) cout << 'R';
	else cout << 'L';

	if (dy < 0)cout << 'D';
	else cout << 'U';
	rep(i, 0, abs(dx) + 1) {
		if (dx < 0) cout << 'R';
		else cout << 'L';
	}
	rep(i, 0, abs(dy) + 1) {
		if (dy < 0)cout << 'U';
		else cout << 'D';
	}
	if (dx < 0) cout << 'L';
	else cout << 'R';

	return 0;
}

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

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,s,t;
    cin>>n>>s>>t;
    s--,t--;
    ll cnt[n]={};
    Dijkstra dij(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        cnt[a]++;
        cnt[b]++;
        dij.add_undirected_edge(a,b,1);
    }    
    vector<ll> ds=dij.shortest_path(s);
    vector<ll> dt=dij.shortest_path(t);
    ll ans = 0;
    if(cnt[s]==1){
        if(ds[t]==2){
            cout << 1 << endl;
            return 0;
        }
        else if(ds[t]==1){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(cnt[i]==1){
            if(ds[i] == dt[i]){
                ans = max(ans,dt[i]);
            }
            else if(ds[i] < dt[i]){
                ans = max(ans,dt[i]-1);
            }
        }
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 10908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> Graph;
typedef vector<ll> vll;

template <class type> void printVector(vector<type> vec){
    stringstream ss;
    ll n = vec.size();
    for(ll i=0;i<n;i++)
    {
        ss<<vec[i];
        if(i!=n-1)ss<<" ";
    }
    cout<<ss.str()<<endl;
}


void dfs(Graph& tree,vll& cnt,ll parent,ll i)
{
    for(auto child:tree[i])//子全てに対して行う
    {
        if(child==parent)continue;//親に対しては足し算しない
        cnt[child]+=cnt[i];
        dfs(tree,cnt,i,child);
    }
}

int main(){
    ll N,Q;
    cin>>N>>Q;
    Graph tree(N);
    vll cnt(N,0);
    for(ll i=0;i<N-1;i++)
    {
        ll a,b;cin>>a>>b;--a;--b;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }

    for(ll i=0;i<Q;i++)
    {
        ll p,x;cin>>p>>x;--p;
        cnt[p]+=x;
    }

    dfs(tree,cnt,-1,0);
    printVector(cnt);
}

Measured memory_bytes: 37400
// unihernandez22
// https://atcoder.jp/contests/abc061/tasks/abc061_a
// implementation

import std.stdio: readf, writeln;

void main() {
	int a, b, c;
	"%s %s %s\n".readf(&a, &b, &c);

	if (c >= a && c <= b)
		writeln("Yes");
	else
		writeln("No");
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        String S = scan.next();

        HashSet<Integer> set = new HashSet<>();

        for(int i = 0; i <= 999; i++) {
            if(i < 10) {
                int zeroTimes = 0;
                for(int j = 0; j < S.length(); j++) {
                    if(zeroTimes < 2) {
                        if (S.charAt(j) == '0')
                            zeroTimes++;
                    } else {
                        if(S.charAt(j) == String.valueOf(i).charAt(0)) {
                            set.add(i);
                            break;
                        }
                    }
                }
            } else if(i < 100) {
                int times = 0;
                for(int j = 0; j < S.length(); j++) {
                    if(times == 0) {
                        if (S.charAt(j) == '0')
                            times++;
                    } else if(times == 1){
                        if(S.charAt(j) == String.valueOf((int)Math.floor(i/10.0)).charAt(0)) {
                            times++;
                        }
                    } else if(times == 2) {
                        if (S.charAt(j) == String.valueOf(i % 10).charAt(0)) {
                            set.add(i);
                            break;
                        }
                    }
                }
            } else {
                int times = 0;
                int a = (int)Math.floor(i/100.0);
                int b = (int)Math.floor((i - 100*a)/10.0);
                int c = (int)i%10;
                for(int j = 0; j < S.length(); j++) {
                    if(times == 0) {
                        if (S.charAt(j) == String.valueOf(a).charAt(0))
                            times++;
                    } else if(times == 1){
                        if(S.charAt(j) == String.valueOf(b).charAt(0)) {
                            times++;
                        }
                    } else if(times == 2) {
                        if (S.charAt(j) == String.valueOf(c).charAt(0)) {
                            set.add(i);
                            break;
                        }
                    }
                }
            }
        }
        os.println(set.size());
    }


}

Measured memory_bytes: 323244
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
a = int(input())
while True:
  if is_prime(a) == True:
    print(a)
    break
  a += 1

Measured memory_bytes: 2940
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=1e5+5;
int i,root,num,j,n,m,k[maxn],ne[maxn<<1],g[maxn<<1],size[maxn];
ll ans,c[maxn<<1],an,d[maxn];
void add(int x,int y,int z){
	ne[++num]=k[x],k[x]=num,g[num]=y,c[num]=z;
}
void dfs(int x,int y){
	int i,s=0;
	size[x]=1;
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (go!=y){
			dfs(go,x);
			s=max(s,size[go]);
			size[x]+=size[go];
			if (size[go]==m) an=c[i];
		}
	}
	s=max(s,n-size[x]);
	if (s<=n/2) root=x;
}
void df(int x,int y){
	int i;
	ans+=d[x];
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (go!=y) d[go]=d[x]+c[i],df(go,x);
	}
}
int main(){
	n=read();
	fo(i,1,n-1){
		int x=read(),y=read(),z=read();
		add(x,y,z),add(y,x,z);
	}
	m=(n&1)?-1:n/2,an=-1;
	dfs(1,0);
	df(root,0);
	ans<<=1;
	if (an==-1) {
		an=1e15;
		fo(i,1,n) if (i!=root) an=min(an,d[i]);
	}ans-=an;
	printf("%lld\n",ans);
}

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

using namespace std;
#define ll long long int 

const int MOD=2019;

ll arr[200010];

ll mod[2050];

int main(){
	string s;
	cin>>s;
	ll n=s.size();
	for(ll i=0;i<s.size();i++){
		arr[i]=s[i]-'0';
	}
	memset(mod,0,sizeof(mod));
	// map<ll,ll> mod;
	ll sum=0,ten=1;
	for(ll i=n-1;i>=0;i--){
		sum+=(ten*arr[i]);
		ten=(ten*10)%MOD;
		sum%=MOD;
		mod[sum]++;
	}
	// for(auto x:mod){
	// 	cout<<x.first<<" "<<x.second<<endl;
	// }
	ll ans=mod[0]*(mod[0]+1)/2;
	for(ll i=1;i<2019;i++){
		ans+=mod[i]*(mod[i]-1)/2;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5180
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{ int parent, left, right; };

Node T[MAX];
int n, D[MAX];

void print(int u)
{
  int c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].parent == NIL) cout << "root, ";
  else if(T[u].left == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";
  for(int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right)
  {
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p)
{
  D[u] = p;
  if(T[u].right != NIL) rec(T[u].right, p);
  if(T[u].left != NIL) rec(T[u].left, p+1);
}

int main(){
  cin >> n;

  for(int i = 0; i < n; i++)T[i].parent = T[i].left = T[i].right = NIL;

  int id, degree, child, left, right;
  for(int i = 0; i < n; i++)
  {
    cin >> id >> degree;
    for(int j = 0; j < degree; j++)
    {
      cin >> child;
      if(j == 0) T[id].left = child;
      else T[left].right = child;
      left = child;
      T[child].parent = id;
    }
  }
  for(int i = 0; i < n; i++)
  {
    if(T[i].parent == NIL) right = i;
  }

  rec(right, 0);

  for(int i = 0; i < n; i++)print(i);

  return 0;
}



Measured memory_bytes: 7760
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)
#define P pair<long int, long int>

struct edge{long int from, to, cost;};

// long int z = 0;
bool func(const edge& x, const edge& y){
    // cout << z << endl;
    // z++;
    return x.cost < y.cost;
}

long int const MAX_N = 200000;
long int par[MAX_N]; // 親
long int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(long int n){
    for(long int i = 0; i < n; i++){
        par[i] = i;
        depth[i] = 0;
    }
}

// 木の根を求める
int find(long int x){
    if (par[x] == x) {
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を合併
void unite(long int x, long int y){
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (depth[x] < depth[y]) {
        par[x] = y;
    }else{
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(long int x, long int y){
    return find(x) == find(y);
}


int main(){
    long int n;
    cin >> n;
    // n = 100000;
    P x[n], y[n];
    edge G[2*(n-1)];
    rep(i, n){
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }
    // rep(i, n){
    //     x[i].first = i + 1;
    //     y[i].first = i + 1;
    //     x[i].second = i;
    //     y[i].second = i;
    // }

    sort(x, x + n);
    sort(y, y + n);
    
    rep(i, n - 1){
        G[2*i].from = x[i].second;
        G[2*i].to = x[i+1].second;
        G[2*i].cost = x[i+1].first - x[i].first;
        G[2*i+1].from = y[i].second;
        G[2*i+1].to = y[i+1].second;
        G[2*i+1].cost = y[i+1].first - y[i].first;
    }
    
    sort(G, G + 2 * (n - 1), func);
    // rep(i, 2 * (n - 1)) cout << G[i].cost << " ";
    // cout << endl;

    init(n);
    long int count = 0;
    long int ans = 0;
    for (long int i = 0; count < n - 1; i++){
        long int e1 = G[i].from;
        long int e2 = G[i].to;
        if (same(e1, e2)){
            continue;
        }
        unite(e1, e2);
        ans += G[i].cost;
        count++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include<cstdio>
using namespace std;
int a,b,c,x;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&x);
	int cnt=0;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
n=int(input())
a=[int(i) for i in input().split()]
b=[0]*n
b[n-2]=abs(a[n-1]-a[n-2])
for i in range(n-3,-1,-1):
    b[i]=min(abs(a[i]-a[i+1])+b[i+1],abs(a[i]-a[i+2])+b[i+2])
print(b[0])

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

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  vector<char> ans;
  while ( N >= 0 ) {
    N--;    
    ans.push_back((char)('a' + (N)%26));
    N /= 26;
    if ( N <= 0 ) break;
  }

  for ( int i = (int)ans.size()-1; i >= 0; i-- ) {
    cout << ans[i];
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, a, ans, m;

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		cin >> a;
		m = max(m, a);
		ans += m - a;
	}
	cout << ans;
}


Measured memory_bytes: 3636
#include <map>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
vector<long long> A004394 = {
	1, 2, 4, 6, 12,
	24, 36, 48, 60, 120,
	180, 240, 360, 720, 840,
	1260, 1680, 2520, 5040, 10080,
	15120, 25200, 27720, 55440, 110880,
	166320, 277200, 332640, 554400, 665280,
	720720, 1441440, 2162160, 3603600, 4324320,
	7207200, 8648640, 10810800, 21621600, 36756720,
	61261200, 73513440, 122522400, 147026880, 183783600,
	367567200, 698377680, 735134400, 1102701600, 1163962800,
	1396755360, 2327925600, 2793510720, 3491888400, 6983776800,
	13967553600, 20951330400, 27935107200, 41902660800, 48886437600,
	80313433200, 160626866400, 321253732800, 481880599200, 642507465600,
	963761198400, 1124388064800, 1927522396800, 2248776129600, 3373164194400,
	4497552259200, 4658179125600, 6746328388800, 9316358251200, 13974537376800,
	18632716502400, 27949074753600, 32607253879200, 55898149507200, 65214507758400,
	97821761637600, 130429015516800, 144403552893600, 195643523275200, 288807105787200,
	433210658680800, 577614211574400, 866421317361600
};
std::map<unsigned long long, unsigned> prime_factorize(unsigned long long x) {
	std::map<unsigned long long, unsigned> ret;
	for (unsigned i = 2; 1ULL * i * i <= x; i++) {
		while (x % i == 0) x /= i, ret[i]++;
	}
	if (x != 1) ret[x]++;
	return ret;
}
unsigned long long divisor_function(unsigned long long x, int r = 1) {
	std::map<unsigned long long, unsigned> res = prime_factorize(x);
	unsigned long long ret = 1;
	for (std::pair<unsigned long long, unsigned> w : res) {
		unsigned long long mulexp = 1, mul = 1, sum = 1;
		for (int i = 0; i < r; i++) mulexp *= w.first;
		for (int i = 0; i < w.second; i++) mul *= mulexp, sum += mul;
		ret *= sum;
	}
	return ret;
}
long long n;
int main() {
	while (cin >> n, n) {
		int ptr = lower_bound(A004394.begin(), A004394.end(), n + 1) - A004394.begin() - 1;
		cout << fixed << setprecision(15) << 1.0 * divisor_function(A004394[ptr], 1) / A004394[ptr] << endl;
	}
	return 0;
}

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

int main() {

	string n; cin >> n;


	if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef  long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

int main()
{
    char a;
    cin>>a;
    if(a<='z'&&a>='a') cout<<'a'<<endl;
    else cout<<'A'<<endl;

}


Measured memory_bytes: 3044
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, B, Bb = 10000000;
    cin >> N;

    ll ans = 0;
    REP(i, N - 1) {
        cin >> B;
        ans += min(B, Bb);
        Bb = B;
    }
    ans += B;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    ll N,K;
    cin>>N>>K;
    N%=K;
    ll mini=abs(N-K);
    for(int i=0;i<100;i++){
        N=abs(N-K);
        mini=min(N,mini);
    }
    cout<<mini<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define BIG 2000000007
 
#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;
 
typedef struct {
	int a;
	int b;
} hw;
 
#define N_MAX 100000
#define M_MAX 100000
 
ull n, m, k;
ull h, w;
ull va, vb, vc, vd;
ull a[N_MAX];
// sll a[N_MAX];
ull b[N_MAX];
// ull dp[N_MAX][M_MAX + 1];
char s[N_MAX + 1];
// char t[N_MAX + 1];
// hw arr[N_MAX];
 
void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}
 
int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}
 
int min(ull x, ull y){
	return (x < y) ? x : y;
}
 
ull gcd(ull x, ull y){
	if (x < y) {
		return gcd(y, x);
	} else if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}
 
ull bitpow(ull a, ull x){
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= MOD;
		}
		x /= 2;
		a = (a * a) % MOD;
	}
	return result;
}

int comp(const void *left, const void *right){
	if ((*(int*)left) < (*(int*)right)) {
		return -1;
	} else if ((*(int*)left) > (*(int*)right)) {
		return +1;
	} else {
		return 0;
	}
}

// int nextroute(int arr[]){
// 	int i = n - 1;
// 	int j, x;
// 	while (arr[i - 1] > arr[i]) i--;

// 	x = n;
// 	for (j = i; j < n; j++) {
// 		if (arr[j] < arr[i - 1]) continue;
// 		if (x == n || arr[x] > arr[j]) x = j;
// 	}
// 	arr[i - 1] ^= arr[x];
// 	arr[x] ^= arr[i - 1];
// 	arr[i - 1] ^= arr[x];

// 	qsort(&arr[i], n - i, sizeof(int), comp);
// 	return 0;
// }

ull solve(){
	int i, j;
	int x[256] = {0};

	for (i = 0; s[i]; i++) {
		if (x[s[i]]) {
			puts("no");
			return 0;
		}
		x[s[i]] = 1;
	}
	puts("yes");

	return 0;
}
 
int main(void){
	int i, j;
	int x;

	scanf("%s", s);

	solve();

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>

using namespace std;


int main() {
	int N, max[2] = { 1,0 }, a,c;
	cin >> N;
	
	for (int i = 1; i <= N;i++) {
		a = i;
		c = 0;
		while (a % 2 == 0 && a != 0) {
			a /= 2;
			c++;
		}
		if (max[1] < c) {
			max[0] = i;
			max[1] = c;
		}
	}
	
	cout << max[0] << endl;
	return 0;
}

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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            int b;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = 0;
            for (int i = 0; i <= a; i ++)
            {
                b = b + i;
            } 
            Console.WriteLine(b);
            Console.ReadKey();


        }
    }
}


Measured memory_bytes: 13140
fn main() {
    proconio::input! {
        n: usize,
        city: [(i64, i64, i64); n]
    };
    let mut dist_v = vec![vec![0; 1<<n]; n];
    let mut dist_h = vec![vec![0; 1<<n]; n];
    for i in 0..1<<n {
        for j in 0..n {
            dist_v[j][i] = city[j].0.abs().min(city[j].1.abs());
            dist_h[j][i] = city[j].0.abs().min(city[j].1.abs());
            for k in 0..n {
                if i&(1<<k) == 0 { continue }
                dist_v[j][i] = dist_v[j][i].min((city[k].0-city[j].0).abs());
                dist_h[j][i] = dist_h[j][i].min((city[k].1-city[j].1).abs());
            }
            dist_v[j][i] *= city[j].2;
            dist_h[j][i] *= city[j].2;
        }
    }
    let mut res = vec![1000000000000000000; n+1];
    for i in 0..1<<n {
        let idx = (i as u64).count_ones() as usize;
        let mut j = i;
        loop {
            let mut cur = 0;
            for k in 0..n {
                cur += dist_v[k][j].min(dist_h[k][i^j]);
            }
            res[idx] = res[idx].min(cur);
            if j == 0 { break; }
            j = i&(j-1);
        }
    }
    for &v in &res { println!("{}", v) }
}


Measured memory_bytes: 9736
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, S: str):
    return [NO, YES][S[:N//2] == S[N//2:]]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(f'{solve(N, S)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75096
# abc134_a.py
# https://atcoder.jp/contests/abc134/tasks/abc134_a

# A - Dodecagon /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 半径 aの円に内接する正十二角形の面積は 3a2であることが知られています。
# 整数 rが与えられるので、半径 rの円に内接する正十二角形の面積を求めて下さい。

# 制約
#     1≦r≦100
#     rは整数である。

# 入力
# 入力は以下の形式で標準入力から与えられます。
# r

# 出力
# 正十二角形の面積を表す整数を出力してください。

# 入力例 1
# 4

# 出力例 1
# 48

# 正十二角形の面積は 3×42=48です。

# 入力例 2
# 15

# 出力例 2
# 675

# 入力例 3
# 80

# 出力例 3
# 19200


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    r = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 3 * r**2

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4']
        lines_export = [48]
    if pattern == 2:
        lines_input = ['15']
        lines_export = [675]
    if pattern == 3:
        lines_input = ['80']
        lines_export = [19200]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9236
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
 
namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            
            //int N = int.Parse(Console.ReadLine());
            int[] K = ReadLine().Split(' ').Select(int.Parse).ToArray();
    
            //水の総量
            int sum = K[1] + K[2];
            //残った水
            int ans = 0;
            if(K[0] < sum){
                ans = sum - K[0];
            }
            
            
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

int prime(ll m){
    if(m==3 or m==5 or m==7) return 1;
    for(int i=2;i<=sqrt(m);i++){
        if(m%i==0){
            return 0;
        }
    }
    return 1;
}

int main(){
    int n; cin>>n;
    int ans = 0;
    
    while(n--){
        ll m; cin>>m;
        ans += prime(m);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

int nums[300010];
vector<int> prime;

void make_nums()
{
    for (int i = 8; i <= 300000; i += 7)
        nums[i] = 1;
    for (int i = 6; i <= 300000; i += 7)
        nums[i] = 1;
}
void make_prime()
{
    for (int i = 0; i <= 300000; i++)
    {
        if (!nums[i])
            continue;
        prime.push_back(i);
        for (int j = i; j <= 300000; j += i)
            nums[j] = 0;
    }
}

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

    make_nums();
    make_prime();
    while (1)
    {
        int n;
        cin >> n;
        if (n == 1)
            break;
        cout << n << ":";
        for (int i = 0; i < prime.size(); i++)
            if (n % prime[i] == 0)
            {
                cout << " " << prime[i];
            }
        cout << endl;
    }
}



Measured memory_bytes: 5796
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] a = { 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 };
        
        System.out.println(a[n-1]);
    }
}


Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if (a<1200){
    cout << "ABC" << endl;
  }
  else if (a<2800){
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
char in[4];
int b[110];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	std::sort(b,b+a);
	printf("%d\n",b[a-1]-b[0]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n;
    while (cin >> n, n) {
        V p(n + 1), t(n + 1);   // 1-index!!
        p[0] = t[0] = 0;
        rep(i, n) cin >> p[i + 1] >> t[i + 1];

        const int inf = 1e9;
        VV dp(n + 1, V(4, inf));    // ?§?????????¢????????????????°????
        dp[0][0] = 0;
        rep(i, n) {
            rep(j, 4) {
                if (j + 1 <= 3 && t[i] + (j + 1) * abs(p[i] - p[i + 1]) <= t[i + 1]) {
                    dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + abs(p[i] - p[i + 1]));
                }
                if (j >= 1 && t[i] + (j + 1) * p[i] + 1 * p[i + 1] <= t[i + 1]) {
                    dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + p[i] + p[i + 1]);
                }
            }
        }

        // ???????????¶????????£???????????????????????????
        int d = inf;
        rep(j, 4) d = min(d, dp[n][j] + p[n]);
        if (d < inf) {
            cout << "OK " << d << endl;
        } else {
            rep(i, n + 1) {
                if (*min_element(all(dp[i])) == inf) {
                    cout << "NG " << i << endl;
                    break;
                }
            }
        }

        // rep(i, n) {
        //     rep(j, 4) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << endl;
        // }
    }
}

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

   int n;
   cin>>n;

   int arr[n];

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

   int cnt =0;
   int a=1;

   for(int i=0;i<n;i++){
        if(arr[i]==a){
            cnt++;
            a++;
        }
   }

   if(cnt!=0)cout<<n-cnt<<endl;
   else cout<<-1<<endl;
}






Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, T;
vi A;

int main() {
    cin >> N >> T;
    A.resize(N);
    rep(i, N) cin >> A[i];

    vector<pair<int, int>> Amax(N);
    Amax[N - 1] = mp(A[N - 1], 1);
    for (int i = N - 2; i >= 0; --i) {
        if (A[i] > Amax[i + 1].first) {
            Amax[i] = mp(A[i], 1);
        }
        else if (A[i] == Amax[i + 1].first) {
            Amax[i] = mp(Amax[i + 1].first, Amax[i + 1].second + 1);
        }
        else {
            Amax[i] = mp(Amax[i + 1].first, Amax[i + 1].second);
        }
    }

    int maxProfit = 0;
    rep(i, N) {
        maxProfit = max(maxProfit, Amax[i].first - A[i]);
    }

    map<int, int> m;
    rep(i, N) {
        if (Amax[i].first - A[i] == maxProfit) {
            m[A[i]]++;
        }
    }

    int ans = 0;
    set<int> s_s, s_b;
    rep(i, N) {
        if (Amax[i].first - A[i] == maxProfit && s_s.find(Amax[i].first) == s_s.end() && s_b.find(A[i]) == s_b.end()) {
            ans += min(m[A[i]], Amax[i].second);
            s_s.insert(Amax[i].first);
            s_b.insert(A[i]);
        }
    }
    write(ans);
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M, D;
  cin >> N >> M >> D;
  int d = D*2;

  char color[2][2] = {{'R', 'Y'}, {'G', 'B'}};

  vector<string> mas(N, "");


  rep(i, N) rep(j, M) {
    int x = ((i-j)%d+d)%d;
    int y = (i+j)%d;
    //cout<<i<<" "<<j<<" "<<x<<" "<<y<<" "<<color[x<D][y<D]<<endl;
    mas[i] += color[x<D][y<D];
  }

  rep(i, N) cout << mas[i] << endl;

  return 0;
}


Measured memory_bytes: 768
import sys
from collections import deque

readline = sys.stdin.readline

n = int(readline())
p = list(map(int, readline().split()))

a = len([1 for i in range(1, n - 1) if 
    (p[i] < p[i + 1] or p[i] < p[i - 1]) and
    (p[i] > p[i + 1] or p[i] > p[i - 1])
])

print(a)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
    int n; scanf("%d", &n);
    vector<int> v(n + 1, 1e9); 
    for(int i = 0; i < n; ++i) {
        int a; scanf("%d", &a);
        *upper_bound(v.begin(), v.end(), -a) = -a; 
    }
    printf("%d\n", lower_bound(v.begin(), v.end(), 1e9) - v.begin());
}

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

int a, b, c;

int main()
{
    cin >> a >> b >> c;
	for (size_t i = 0; i < b; i++)
	{
		if (i*a%b == c)
		{
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
n = gets.to_i
arr = []
n.times{arr << gets.chomp.split.map(&:to_i)}
uniq = [[],[],[]]
arr.transpose.each_with_index{|ar, i|
    h = Hash.new(0)
    ar.each{|x| h[x]+=1}
    h.each{|k, v| uniq[i] << k if v == 1}
}
score = Array.new(n, 0)
arr.each_with_index{|ar, player|
    ar.each_with_index{|x, i|
    score[player] += x if uniq[i].include?(x)}
}
puts score


Measured memory_bytes: 6884
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

void pr(ll ans){
    cout1(ans)
    exit(0);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,a,b;
    cin>>n>>a>>b;
    
    if(a>b) pr(0);
    if(n==1){
        if(a==b) pr(1);
        else pr(0);
    }
    
    ll ans=(b-a)*(n-2)+1;
    pr(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long

int main()
{

	ll n, W;
	cin >> n >> W;

	ll wt[n];
	ll val[n];
	for (int i = 0; i < n; i++)
	{
		cin >> wt[i] >> val[i];
	}

	ll dp[n + 1][W + 1];

	for (ll i = 0; i <= W; i++)
		dp[0][i] = 0;

	for (ll i = 0; i <= n; i++)
		dp[i][0] = 0;
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= W; j++)
		{
			ll x = 0;
			if (j - wt[i - 1] >= 0)
				x = dp[i - 1][j - wt[i - 1]] + val[i - 1];
			ll y = dp[i - 1][j];

			dp[i][j] = max(x, y);
		}
	}

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

}













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

int main(){
    long a,b,c,d;
    cin >> a >> b >> c >> d;

    long aBound = a+b;

    if(d <= a){
        cout << d;
    }else{
        if(d<=aBound){
            cout << a;
        }else{
            cout << a-(d-aBound);
        }
    }
}

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1000000;
char s[maxn];

int main()
{
    scanf("%s", s);
    int len = strlen(s);
    for(int i = 0; i < len; i++)
    {
        if((i+1) % 2 == 1) printf("%c", s[i]);
    }
    cout << "\n";
    return 0;
}


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

const long long INF = 1LL << 60;
const ll MOD = ll(1e9)+7;

bool has_key(unordered_map<string, ll> &m, string s){
    if (m.find(s) == m.end()){
        return false;
    }
    else{
        return true;
    }
}


bool vector_find(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) {
    return true;
  }
  else {
    return false;
  }
}


void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}


void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll count_black(vector<vector<string>> C) {

  ll num = 0;
  for (ll i = 0; i < C.size(); i++) {
    for (ll j = 0; j < C.at(i).size(); j++) {
      if (C.at(i).at(j) == "#") num++;
    }
    
  }

  return num;
  
}

vector<vector<string>> paint(vector<vector<string>> C, vector<ll> x, vector<ll> y) {

  vector<vector<string>> C_painted = C;

  for (ll i = 0; i < x.size(); i++) {
    if(x.at(i) == 1) {
      for (ll j = 0; j < C_painted.size(); j++) {
        C_painted.at(j).at(i) = "r";
      }
    }
  }

  for (ll i = 0; i < y.size(); i++) {
    if(y.at(i) == 1) {
      for (ll j = 0; j < C_painted.at(0).size(); j++) {
        C_painted.at(i).at(j) = "r";
      }
    }
  }

  return C_painted;
  
}

vector<vector<ll>> vec_x;

void sublistx(vector<ll> tmp, ll n) {
    if (n == 0) {
      vec_x.push_back(tmp);
    }
    if (n > 0) {
      vector<ll> tmp0 = tmp;
      vector<ll> tmp1 = tmp;
      tmp0.push_back(0);
      tmp1.push_back(1);
      sublistx(tmp0, n - 1);
      sublistx(tmp1, n - 1);
    }
}

vector<vector<ll>> vec_y;

void sublisty(vector<ll> tmp, ll n) {
    if (n == 0) {
      vec_y.push_back(tmp);
    }
    if (n > 0) {
      vector<ll> tmp0 = tmp;
      vector<ll> tmp1 = tmp;
      tmp0.push_back(0);
      tmp1.push_back(1);
      sublisty(tmp0, n - 1);
      sublisty(tmp1, n - 1);
    }
}


int main() {

  ll N;
  cin >> N;

  vector<ll> A(N);
  ll ans = 0;
  ll hmax = 0;

  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);

    if(hmax < A.at(i)) hmax = A.at(i);

    ans += (hmax - A.at(i));
  }
  

 
  


  cout << ans << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  int ans = 0;
  int maxh = 0;
  rep(i, n) {
    cin >> h[i];
    if (h[i] >= maxh) ans++;
    maxh = max(maxh, h[i]);
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  vector<string> v(n);
  rep(i, n) {
    cin >> v[i];
    sort(v[i].begin(), v[i].end());
  }
  map<char, int> ans;
  for(int i = 0; i < v[0].size(); i++){
    ans[v[0].at(i)]++;
  }
  for(int i = 1; i < n; i++){
    map<char, int> t;
    for(int j = 0; j < v[i].size(); j++){
      t[v[i].at(j)]++;
    }
    for(auto itr = ans.begin(); itr != ans.end(); itr++){
      if(t[itr->first] < ans[itr->first]){
        ans[itr->first] = t[itr->first];
      }
    }
  }
  for(auto  itr = ans.begin(); itr != ans.end(); itr++){
    for(int j = 0; j < itr->second; j++){
      cout << itr->first;
    }
  }
  cout << endl;
  system("pause");
}

Measured memory_bytes: 504
import sys

N = int(input())

w = []

limit = 0

for _ in range(N):

    ai, bi = map(int, input().split())
    w.append((ai, bi))

w = sorted(w, key=lambda x:x[1])

now = 0
for v in w:
    limit = v[1]
    now += v[0]
    if now > limit:
        print('No')
        sys.exit()

print('Yes')



Measured memory_bytes: 33480
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, K;
  cin >> N >> K;
  VEC<int> D(K);
  VEC<bool> kirai(10, 0);

  REP(i, 0, K) {
    cin >> D[i];
    kirai[D[i]] = true;
  }
  int lim = N * 10;
  auto isAns = [&](int n) -> bool {
    while (n > 0) {
      if (kirai[n % 10]) return false;
      n /= 10;
    }
    return true;
  };

  REP(num, N, lim) {
    if (isAns(num)) {
      cout << num << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256