akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
vector<int> es[114514];
signed main(){
    int n;cin>>n;
    rep(i,0,n-1){
        int a,b;cin>>a>>b;
        a--;b--;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    int d[114514];
    priority_queue<P,vector<P>,greater<P> >que;
    fill(d,d+n,inf);
    d[0]=0;
    que.push(P(0,0));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<es[v].size(); i++){
            int e=es[v][i];
            if(d[e]>d[v]+1){
                d[e]=d[v]+1;
                que.push(P(d[e],e));
            }
        }
    }
    int ds[114514];
    fill(ds,ds+n,inf);
    ds[n-1]=0;
    que.push(P(0,n-1));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(ds[v]<p.first)continue;
        for(int i=0;i<es[v].size(); i++){
            int e=es[v][i];
            if(ds[e]>ds[v]+1){
                ds[e]=ds[v]+1;
                que.push(P(ds[e],e));
            }
        }
    }
    int count=0;int h=0;
    rep(i,1,n-1){
        if(d[i]<=ds[i])count++;
        else h++;
    }
    if(count<=h)cout<<"Snuke"<<endl;
    else cout<<"Fennec"<<endl;
    return 0;
}


Measured memory_bytes: 8572
#include <iostream>

using namespace std;

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

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

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long



int main(){
  LL x,y;
  cin>>x;
  cin>>y;
  //cerr<<x<<endl;
  //cerr<<y<<endl;
  int ret=1;
  while(2*x<=y){
    ret++;
    x*=2;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=1000000007;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
   // cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       vector<pair<int,int> >v(n);
       for(int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
       int f=0;
       for(int i=0;i<=n-3;i++)
       {
           if(v[i].first==v[i].second&&v[i+1].first==v[i+1].second&&v[i+2].first==v[i+2].second){f=1;break;}
       }
       

      if(f)cout<<"Yes"<<endl;
       else cout<<"No"<<endl;


    }
    return 0;
}


Measured memory_bytes: 3640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        A: usize,
        B: usize,
        Q: usize,
        s: [i64; A],
        t: [i64; B],
        x: [i64; Q],
    }

    let mut st;
    let mut ts;

    for x_q in x.into_iter() {
        st = mindd(&s, &t, x_q);
        ts = mindd(&t, &s, x_q);

        println!("{}", min(st, ts));
    }
}

fn min_d(array: &[i64], key: i64) -> i64 {
    match array.binary_search(&key) {
        Ok(_ind) => 0,
        Err(ind) => {
            if ind == array.len() {
                (key - array[ind-1]).abs()
            } else if ind > 0 {
                min((key - array[ind-1]).abs(), (key - array[ind]).abs())
            } else {
                (key - array[ind]).abs()
            }
        }
    }
}

fn mindd(array1: &[i64], array2: &[i64], key: i64) -> i64 {
    match array1.binary_search(&key) {
        Ok(_ind) => min_d(array2, key),
        Err(ind) => {
            if ind == array1.len() {
                (key - array1[ind-1]).abs() + min_d(array2, array1[ind-1])
            } else if ind > 0 {
                min((key - array1[ind]).abs() + min_d(array2, array1[ind]), 
                (key - array1[ind-1]).abs() + min_d(array2, array1[ind-1]))
            } else {
                (key - array1[ind]).abs() + min_d(array2, array1[ind])
            }
        },
    }
}

fn min(a: i64, b: i64) -> i64 {
    if a > b {
        b
    } else {
        a
    }
}


Measured memory_bytes: 7420
N, M = [int(_) for _ in input().split()]
bridge = [[int(_) for _ in input().split()] for _ in range(M)]


class UnionFind:
    def __init__(self, N):
        self.par = [i for i in range(N + 1)]
        self.rank = [0] * (N + 1)
        self._number = [1] * (N + 1)

    def root(self, i):
        if self.par[i] == i:
            return i
        self.par[i] = self.root(self.par[i])
        return self.par[i]

    def same(self, i, j):
        return self.root(i) == self.root(j)

    def tree_rank(self, i):
        return self.rank[self.root(i)]

    def number(self, i):
        return self._number[self.root(i)]

    def union(self, i, j):
        _root_i = self.root(i)
        _root_j = self.root(j)
        if _root_i == _root_j:
            return
        else:
            if self.tree_rank(i) < self.tree_rank(j):
                self.par[_root_i] = _root_j
                self._number[_root_j] += self._number[_root_i]
            else:
                self.par[_root_j] = _root_i
                self._number[_root_i] += self._number[_root_j]
                if self.tree_rank(i) == self.tree_rank(j):
                    self.rank[_root_i] += 1


def whether_graph_connected(n, link):
    _islands = UnionFind(n)
    for l in link:
        _islands.union(l[0], l[1])
    return _islands.number(_islands.root(1)) == n

  
count = 0

for bridge_broken in bridge:
    bridge_remain = [_ for _ in bridge if _ != bridge_broken]
    if not whether_graph_connected(N, bridge_remain):
        count += 1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
	long long n;
	long long x;
	long long y;
	long long z;
	long long m;
	long long c;
	
	cin>>n;

	for(x=1;x<=3500;x++)
	{
		for(y=1;y<=3500;y++)
		{
			m = 4*x*y - n*y - n*x;
			c = n*x*y;
			if(m>0 && c%m==0)
			{
				z=c/m;
				cout<<x<<" "<<y<<" "<<z<<endl;
				return 0;
			}
		}
	}
	return 0;
}

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

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a+b >= c+d){
    if(a+b == c+d) cout << "Balanced" << endl;
    else cout << "Left" << endl;
  }
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

f([], S, S).
f([X|Xs], S, Z) :- S2 is S + X * X, f(Xs, S2, Z).

main :-
    get_number(N),
    get_numbers(N, Xs),
    sum_list(Xs, S),
    f(Xs, 0, T),
    X is (S * S - T) div 2,
    writeln(X).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8180
def c_biscuit(K, A, B):
    # B <= A+2 の場合、ビスケットと日本円を交換する意味がない(2手に対して利益がない)。
    # A >= K の場合、ビスケットと日本円を交換できるほどビスケットが貯まらない。
    if B <= A + 2 or A >= K:
        return K + 1

    # ビスケットがA枚以上あり、かつ、残りの操作回数が2回以上あるなら、操作を2回行い、
    # ビスケットA枚をB枚に変換できる。この変換が可能な回数はmax(0, (K-(A-1))//2)回。
    # もし、上の変換を行ったあと、操作回数が余っていたら(最大1回)、それでビスケットを増やす。
    # この処理を行う場合、 A < K すなわち K+1 >= A ゆえに K-(A-1)>=0 なので、
    # 負数を割ったりmodを取ったりするおそれはない。
    exchange_time, final_remain = divmod(K - (A - 1), 2)
    ans = A + (B - A) * exchange_time + final_remain
    return ans

K, A, B = [int(i) for i in input().split()]
print(c_biscuit(K, A, B))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int mod=998244353,inv2=499122177;
int n,m,ans;
int fac[1000005],ifac[1000005];

int qm(int x) {return x>=mod?x-mod:x;}
int qpow(int x,int y) {
	int re=1;
	for(;y;y>>=1,x=1LL*x*x%mod) if(y&1) re=1LL*re*x%mod;
	return re;
}
int C(int d,int u) {return 1LL*fac[d]*ifac[u]%mod*ifac[d-u]%mod;}

int main()
{
	scanf("%d%d",&n,&m);
	fac[0]=1;for(RI i=1;i<=n+m;++i) fac[i]=1LL*fac[i-1]*i%mod;
	ifac[n+m]=qpow(fac[n+m],mod-2);
	for(RI i=n+m-1;i>=0;--i) ifac[i]=1LL*ifac[i+1]*(i+1)%mod;
	for(RI i=1;i<=n&&i<=m;++i)
		ans=qm(ans+1LL*C(n+m-2*i,n-i)*C(2*i,i)%mod);
	ans=qm(1LL*ans*inv2%mod*qpow(C(n+m,n),mod-2)%mod+max(n,m));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>

long abs(long v) {
  return (v < 0) ? -v : v;
}

int main() {
  long N;

  std::cin >> N;

  std::vector<long> A(N+2);
  std::vector<long> memo(N+2);

  A[0] = 0;
  memo[0] = 0;
  for (long i=1; i<N+1; i++) {
    std::cin >> A[i];
    memo[i] = memo[i-1] + abs(A[i-1] - A[i]);
  }
  A[N+1] = 0;
  memo[N+1] = memo[N] + abs(A[N]);

  for (long i=1; i<N+1; i++) {
    long ans =
      abs(memo[i-1]-memo[0]) + abs(A[i+1]-A[i-1]) + abs(memo[N+1]-memo[i+1]);
    std::cout << ans << std::endl;
  }

  return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int tt;
int n,ans=N;
int ch[N],v[N],head[N],to[N*2],nxt[N*2];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') ch=getchar(),o=-1;
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void dfs1(int x,int fa) {
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(y!=fa) {
	    dfs1(y,x);
	    if(v[y]) v[x]+=v[y];
	    else ++ch[x];
	}
    }
    if(ch[x]) v[x]+=ch[x]-1;
}
inline void dfs2(int x,int fa) {
    ans=min(ans,v[x]+1);
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(y!=fa) {
	    if(v[y]) {
		if(v[x]==v[y]) ++v[y];
		else v[y]+=v[x]-v[y];
	    }
	    else v[y]+=v[x]-(ch[x]>1);
	    dfs2(y,x);
	}
    }
}
int main() {
    cin>>n;
    if(n==1) {puts("0");return 0;}
    for(int i=1;i<n;i++) {
	int x=gi()+1,y=gi()+1;
	to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
    }
    dfs1(1,0),dfs2(1,0);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(1){
		int ans=0;
		cin>>n;
		if(n==0)break;
		for(int i=1;i<=n;i++){
			if(i%5==0){
				int tmp=i;
				while(1){
					if(tmp%5==0){
						ans++;
						tmp/=5;
					}else break;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
  int N, K;
  int sum = 0;
  cin >> N >> K;
  vector<int> x(N);
  for(int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  for(int i = 0; i < N; i++) {
    sum += 2 * min(x.at(i),K-x.at(i));
  }
  cout << sum;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  long long int d,i,ans=0;

  while(scanf("%lld",&d)!=EOF){
    ans=0;
    for(i=d;i<=600-d;i+=d){
      ans+=d*i*i;
    }
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 596
#include <set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int n;
char ans[1010][1010];
string a4[4] = {"aaef","bbef","cdgg","cdhh"};
string a5[5] = {"aabbi","ccf.i","ddfee","..ghj","..ghj"};
string a6[6] = {"aabbcc","ddeeff","ghi...","ghi...","...jkl","...jkl"};
string a7[7] = {"aabbcc.", "ddee..l", "ffgg..l", "....hjm", "....hjm", "....ikn", "....ikn"};
int main() {
	read(n);
	if(n == 2){
		cout<<-1<<endl;
		return 0;
	}
	if(n == 3){
		cout<<"aa.\n..b\n..b"<<endl;
		return 0;
	}
	if(n%4 == 0){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				ans[i][j] = a4[i%4][j%4];
			}
		}
	}
	if(n%4 == 1){
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				ans[i][j] = a5[i][j];
			}
		}
		for(int k=5;k<n;k+=4){
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					ans[k+i][k+j] = a4[i][j];
				}
			}
		}
	}
	if(n%4 == 2){
		for(int i=0;i<6;i++){
			for(int j=0;j<6;j++){
				ans[i][j] = a6[i][j];
			}
		}
		for(int k=6;k<n;k+=4){
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					ans[k+i][k+j] = a4[i][j];
				}
			}
		}
	}
	if(n%4 == 3){
		for(int i=0;i<7;i++){
			for(int j=0;j<7;j++){
				ans[i][j] = a7[i][j];
			}
		}
		for(int k=7;k<n;k+=4){
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					ans[k+i][k+j] = a4[i][j];
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(!ans[i][j])ans[i][j] = '.';
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define MAX 3001
#define mod 1000000007
int ans[MAX][MAX];
int main(){
	int n,m,i,j;
	cin>>n>>m;
    char grid[n][m];
    for(i=0;i<n;i++)
    for(j=0;j<m;j++) cin>>grid[i][j];
    for(i=0;i<n;i++){
    	for(j=0;j<m;j++){
    		if(i==0 && j==0) ans[i][j]=1;
    		else if(grid[i][j]=='#') ans[i][j]=INT_MIN;
    		else if(i==0) ans[i][j]=ans[i][j-1];
    		else if(j==0) ans[i][j]=ans[i-1][j];
    		else ans[i][j]=(max(ans[i-1][j],0)%mod+max(ans[i][j-1],0)%mod )%mod;
    		
    	}
    }
    cout<<ans[n-1][m-1];
	
}

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
string sub[4] = {"A", "C", "G", "T"};
ll dp[101][64];

int main(){	
	long long N;
	scanf("%lld",&N);
	rep(i, 4) {
		rep(j, 4) {
			rep(k, 4) {
				if ((i == 0 && j == 1 && k == 2) || (i == 0 && j == 2 && k == 1) || (i == 2 && j == 0 && k == 1)) dp[3][4*4*i+4*j+k] = 0; else dp[3][4*4*i+4*j+k] = 1;
			}
		}
	}
	
	for (ll i = 3; i < N; i++) {
		rep(j, 4) {
			rep(k, 4) {
				rep(l, 4) {
					rep(m, 4) {
						if (!(
							(k == 0 && l == 2 && m == 1) 
							|| (k == 0 && l == 1 && m == 2) 
							|| (k == 2 && l == 0 && m == 1) 
							|| (j == 0 && k == 2 && m == 1) 
							|| (j == 0 && l == 2 && m == 1) 
						)) dp[i+1][4*4*k+4*l+m] = (dp[i+1][4*4*k+4*l+m]+dp[i][4*4*j+4*k+l])%mod;
					}
				}
			}
		}
	}
	ll res = 0;
	rep(i, 4) {
		rep(j, 4) {
			rep(k, 4) {
				// if (dp[N][4*4*i+4*j+k] == 0) cout << i << " " << j << " " << k << endl;
				res = (res+dp[N][4*4*i+4*j+k])%mod;
			}
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256
<?php 

fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
$dis_li = array();
$sum_tmp = 0;
$min = 10**6*4;

for($i=-100;$i<=100;$i++){
	foreach($a_li as $a){
      $sum_tmp+=($a-$i)**2;
    }
  	$min = min($sum_tmp,$min);
  	$sum_tmp = 0;
}

echo $min;

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int H, W;
    std::cin>>H>>W;
    std::vector<std::string> s(H);
    for(int i = 0;i < s.size();i++){
        std::cin>>s[i];
    }

    std::vector<std::vector<int>>
        v(H, std::vector<int>(W, 0));
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

    for(int i = 0;i < H;i++){
        for(int j = 0; j < W;j++){
            if(s[i][j] == '#'){
                continue;
            }
            int n = 0;
            for(int d = 0;d < 8;d++){
                int ni = i + dy[d];
                int nj = j + dx[d];

                if(ni < 0 || H <= ni){
                    continue;
                }
                if(nj < 0 || W <= nj){
                    continue;
                }
                if(s[ni][nj] == '#'){
                    ++n;
                }
            }
            s[i][j] = char(n + '0');
        }
    }
    for(const auto& x : s){
        std::cout<<x<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
for i in range(m):
    if n % 2 == 0 and n // 2 <= (m - i) * 2 - 1:
        x = 1
    else:
        x = 0
    print(i + 1, (m - i) * 2 + i + x)

Measured memory_bytes: 9148
#include<iostream>
using namespace std;
int main(){
	int a[45];
	a[0]=1;
	a[1]=1;
	int n,i;
	cin>>n;
	if(n>=2){
		for(i=2;i<=n;i++){
			a[i]=a[i-1]+a[i-2];
		}
	}
	cout<<a[n]<<endl;
	return 0;
}

Measured memory_bytes: 3084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int f = sc.nextInt();

        Dice dice = new Dice(a, b, c, d, e, f);

        String cmd = sc.next();

        for (int i = 0; i < cmd.length(); i++) {
            switch (cmd.charAt(i)) {
            case 'N': dice = dice.rollToN(); break;
            case 'S': dice = dice.rollToS(); break;
            case 'W': dice = dice.rollToW(); break;
            case 'E': dice = dice.rollToE(); break;
            }
        }

        System.out.println(dice.getTop());
    }

    private static class Dice {
        private int t;
        private int s;
        private int e;
        private int w;
        private int n;
        private int b;

        public Dice() {
            this(1, 2, 3, 4, 5, 6);
        }
        public Dice(int t, int s, int e, int w, int n, int b) {
            this.t = t;
            this.s = s;
            this.e = e;
            this.w = w;
            this.n = n;
            this.b = b;
        }
        public Dice rollToN() {
            return new Dice(s, b, e, w, t, n);
        }
        public Dice rollToS() {
            return new Dice(n, t, e, w, b, s);
        }
        public Dice rollToW() {
            return new Dice(e, s, b, t, n, w);
        }
        public Dice rollToE() {
            return new Dice(w, s, t, b, n, e);
        }
        public int getTop() {
            return t;
        }
    }
}



Measured memory_bytes: 26376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;

int main(){
    int n;
    cin >> n;
    int x = pow(n,0.5);
    cout << x*x << endl;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**5+10)
input=sys.stdin.readline

N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)

Measured memory_bytes: 78784
/////////////////////////////////////////
////////// ^\/^ *_* :) :-D '~' \\\\\\\\\\
/////////////////////////////////////////
#include <bits/stdc++.h>
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int n,k;
	cin>>n>>k;
	vector <int> a(n);
	rep(i,n) cin>>a[i];
	int ans=1;
	n-=k;
	ans+=(n+k-2)/(k-1);
	cout<<ans<<endl;
	rt0;
}

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

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    int acc = n * 2;

    for (int i = n; i >= 0; i--) {
        string si = s.substr(s.length() - i, i);
        if (t.find(si) == 0) {
            cout << acc - i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(c) c.begin(),c.end()
#define INF int(1e9+7)

using namespace std;

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

bool ok[100006];

int main()
{
	IO_OP;

	int k, n;
	cin >> n >> k;
	vector<pi> v(n);
	for(int i=0;i<n;i++)
		cin >> v[i].S >> v[i].F;
	sort(v.begin(), v.end(), greater<pi>());
	priority_queue<int, vi, greater<int>> pq;
	long long cnt = 0, x = 0, ans = 0;
	for(int i=0;i<k;i++) {
		if(ok[v[i].S] == 0)
			ok[v[i].S] = 1, x++;
		else
			pq.push(v[i].F);
		cnt += v[i].F;
	}
	ans = cnt + x*x;
	for (int i = k; i < n && x < k; i++) {
		cnt -= pq.top();
		pq.pop();
		if(ok[v[i].S] == 0)
			ok[v[i].S] = 1, x++;
		else
			pq.push(v[i].F);
		cnt += v[i].F;
		ans = max(ans,  cnt + x*x);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1536
N, Y = map(int, input().split())
ans = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            ans = (x, y, z)
            break
    else:
        continue
    break

print(*ans)


Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}


int func(string s) {
	string bs = s.substr(0, 1);
	int cnt = 1;
	int i = 1;
	while (i < s.length()) {
		int size = 1;
		bool isEqual = false;
		do {
			if (bs == s.substr(i, size)) {
				isEqual = true;
				size++;
              	if (i + size - 1 >= s.length()) {
					i = s.length();
					break;
				}
			}
			else {
				isEqual = false;
				bs = s.substr(i, size);
				i += size;
				cnt++;
				
			}
		} while (isEqual);
	}
	return cnt;
}


int main()
{
	int max = 0, cnt1, cnt2;
	string s;
	string bs;

	cin >> s;

	cnt1 = func(s);

	reverse(s.begin(), s.end());

	cnt2 = func(s);

	cout << std::max(cnt1, cnt2) << endl;

	return 0;

}

Measured memory_bytes: 772
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	string A, B, C;
	cin >> A >> B >> C ;
	
	cout << A.at(0)<<B.at(1)<<C.at(2) << endl;
}


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

using namespace std;

void solve(void)
{
	int n, q;
	string s;
	cin >> n >> q >> s;
	vector<int> ans(n+1);
	for (int i = 1; i < n; i++)
	{
		ans[i+1] = ans[i];
		if (s[i] == 'C' && s[i-1] == 'A')
		{
			ans[i+1]++;
		}
	}

	while (q--)
	{
		int l, r;
		cin >> l >> r;
		int res = ans[r] - ans[l - 1];
		if (res && l > 1 && s[l-1] == 'C' && s[l-2] == 'A') res--;
		cout << res << endl;
	}
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod2;
        }
        now*=now;
        now%=mod2;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    ll d[n];
    ll cnt[n+1];
    fill(cnt,cnt+n+1,0);
    ll ma=0;
    rep(i,0,n){
        cin>>d[i];
        cnt[d[i]]++;
        ma=max(ma,d[i]);
    }
    if(d[0]!=0||cnt[0]>=2){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    rep(i,1,ma+1){
        ll y=cnt[i-1];
        ll t=cnt[i];
        ll r=beki(y,t);
       // cout<<y<<" "<<t<<endl;
        ans*=r;
        ans%=mod2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
n= int(input())
dp =[0]*3
for i in range(n):
    ndp=[0]*3
    c =list(map(int,input().split()))
    for j in range(3):
        for k in range(3):
            #print(j,k)
            if j !=k:
                ndp[k] = max(ndp[k],dp[j]+c[k])
                
    dp = ndp
    
print(max(dp))
        

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


LL n;
LL dp[100][2][2];

LL rec(int k,bool f,bool t){
    if(k==-1) return !t;
    if(~dp[k][f][t]) return dp[k][f][t];
    LL ret = 0;
    int x = f?((n>>k)&1):1;
    for (int i = 0; i <= x; i++) {
        if(i==0){
            ret = (ret + rec(k-1,f&(x==i),false))%mod; //(v,u)=(0,0)
            if(t){
                ret = (ret + rec(k-1,f&(x==i),true))%mod; //(v,u)=(0,1)
            }
        }
        else{
            if(!t){
                ret = (ret + rec(k-1,f&(x==i),false))%mod; //(v,u)=(1,1)
            }
            ret = (ret + rec(k-1,f&(x==i),true))%mod; //(v,u)=(1,0)
        }
    }
    return dp[k][f][t] = ret;
}


int main(){
    cin >> n;
    LL t = n;
    int k = 0;
    while(t){
        t >>= 1;
        k++;
    }
    memset(dp,-1,sizeof(dp));
    cout << rec(k-1,true,false) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	int n, ans;
	cin >> n;
	for(int i = 1;i <= n;i++){
		ans += i;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define Mod 1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
ll ckck(ll N)
{
    ll lo=1,hi=1e10;
    ll  mid,ind;
    ll cnt;
    while(lo<=hi)
    {
        mid=lo+(hi-lo)/2;
        cnt=mid*(mid+1);
        cnt/=2;
        cnt-=1;
        if(N>cnt)
        {
            ind=mid;
            lo=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return ind;
}

int main()
{
   string s;
   cin>>s;
   int n=s.length();
   int cnt[2][2019];
   memset(cnt,0,sizeof(cnt));
   int d;
   d=s[0]-'0';
   int i,j;
   cnt[0][d]++;
   cnt[1][d]++;
   ll ans=0;
   for(i=2;i<=n;i++)
   {
       for(j=0;j<2019;j++)
       {
           cnt[1][j]=0;
       }
       d=s[i-1]-'0';
       for(j=0;j<2019;j++)
       {

           cnt[1][(j*10+d)%2019]+=cnt[0][j];

       }

       cnt[1][d]++;
       ans+=cnt[1][0];
       for(j=0;j<2019;j++)
       {
           cnt[0][j]=cnt[1][j];
       }

   }
   cout<<ans;
}


Measured memory_bytes: 3740
#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
//#pragma GCC target ("tune=native")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128_t;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

bool checkIfRightMask(ll m, const vector<vector<pll>> &a) {
	for (ll i = 0; i < a.size(); i++) {
		forEach(a[i]) {
			if (bit(m, i) && (it.S && !bit(m, it.F))) return false;
			if (bit(m, i) && (!it.S && bit(m, it.F))) return false;
		}
	}
	return true;
}

void solve() {
	ll n;
	cin >> n;
	vector<vector<pll>> a(n);
	forEach(a) {
		ll k;
		cin >> k;
		it.resize(k);
		for (auto &el : it) {
			cin >> el.F >> el.S;
			el.F--;
		}
	}
	ll cnt = 0;
	for (ll m = 0; m < (1LL << n); m++) {
		if (!checkIfRightMask(m, a)) continue;
		chMax(cnt, (ll)__builtin_popcountll(m));
	}
	cout << cnt << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


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


int main()
{
	int64_t N, A, B,aCount=0,bCount=0;
	char M;

	cin >> N >> A >> B;
	
	vector<int64_t> S(100000);
	rep(i, N) {
		cin >> M;
		if (M=='a'&& A+B>0)
		{
			A--;
			cout << "Yes" << endl;

		}
		else if (M == 'b' && B>0 && A+B>0) {
			B--;
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		
	}
}

Measured memory_bytes: 3972
# -*- coding: utf-8 -*-
from collections import defaultdict
from heapq import merge
import sys
sys.setrecursionlimit(10**7)
def inpl(): return tuple(map(int, input().split()))
 
N, M = inpl()
A = inpl()
tree = [[-1, 1]  for _ in range(N)] # [next, rank]
 
def find(i):
    if tree[i][0] == -1:
        group = i
    else:
        group = find(tree[i][0]) 
        tree[i][0] = group
    return group
  
def unite(x, y):
    px = find(x)
    py = find(y)
      
    if tree[px][1] == tree[py][1]: # rank is same
        tree[py][0] = px
        tree[px][1] += 1
    else:
        if tree[px][1] < tree[py][1]:
            px, py = py, px
        tree[py][0] = px
  
for _ in range(M):
    x, y = tuple(map(int, input().split()))
    if not int(find(x) == find(y)):
        unite(x, y)
 
D = defaultdict(list)
for n in range(N):
    D[find(n)].append(A[n])
 
H = []
res = 0 

for k, v in D.items():
    v = sorted(v)
    res += v[0]
    H.append(v[1:])
 
if N < 2*(N-M-1):
    print("Impossible")
elif M == N-1:
    print(0)
else:
    res += sum(list(merge(*H))[:2*(N-M-1) - len(D.keys())])
    print(res)

Measured memory_bytes: 45092
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		Console.ReadLine();
		var s = Console.ReadLine().ToCharArray();

		var max = 0;
		for (var i = 1; i < s.Length; ++i) {
			var left = new HashSet<char>(s.Take(i));
			var right = new HashSet<char>();
			var count = 0;
			for (var j = i; j < s.Length; ++j) {
				if (left.Contains(s[j]) && !right.Contains(s[j])) {
					++count;
					right.Add(s[j]);
				}
			}

			max = Math.Max(count, max);
		}

		Console.WriteLine(max);
	}
}


Measured memory_bytes: 13280
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int a,b,k;
    cin>>a>>b>>k;
    if(a!=0)
    {
        if(a<=k)
        {
            k=k-a;

            a=0;
        }
        else
        {
            a=a-k;
            k=0;
        }
    }
    if(b!=0)
    {
        if(b<=k)
            b=0;
        else
        {
            b=b-k;
        }
    }
    cout<<a<<" "<<b; 
}
int32_t main()
{
    // clock_t tStart = clock();
    // #ifndef ONLINE_JUDGE
    // _READ
    // #endif
    
    int t;
    t=1;
    while(t--)
        solve();
    
    // #ifndef ONLINE_JUDGE
    // cout<<fixed<<setprecision(5)<<"\nTime taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC;
    // #endif
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)


using namespace std;
typedef long long ll;
// typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007



void solve() {
	int a, b;
	cin >> a >> b;
	int c = b - a;
	int length = 0;
	for (int i = 1; i < c; i++) length += i;
	cout << length - a << endl;
}

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

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
ab = b-a
ac = c-a
ad = d-a
ae = e-a
bc = c-b
bd = d-b
be = e-b
cd = d-c
ce = e-c
de = e-d
if ab <= k and ac <= k and ad <= k and ae <= k and bc <= k and bd <= k and be <= k and cd <= k and ce <= k and de <= k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int dayOfWinterVacation;
	int japanesePage;
	int mathPage;
	int c;
	int d;
	int finishDay;
	
	scanf( "%d%d%d%d%d", &dayOfWinterVacation, &japanesePage, &mathPage, &c, &d );
	
	if( japanesePage / c > mathPage / d )
	{
		finishDay = japanesePage % c == 0 ? japanesePage / c : japanesePage / c + 1;
	}
	else
	{
		finishDay = mathPage % d == 0 ? mathPage / d : mathPage / d + 1;
	}
	
	printf( "%d\n", dayOfWinterVacation - finishDay );
	
	return (0);
}

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

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define array(N, t) (t*)calloc(N, sizeof(t))
#define ll long long
#define INF ((1LL << 62) - (1LL << 31))
#define max(p, q)((p) > (q) ? (p) : (q))
#define min(p, q)((p) < (q) ? (p) : (q))
#define swap(type, a, b) { type temp = a; a = b; b = temp; }


int N;
int ans = 0;

int baisu_cnt(int x) {
  int cnt = 0;
  for (int i = 1; i <= x; i += 1) {
    if (x % i == 0) {
      cnt += 1;
    }
  }
  return cnt;
}

void solve1() {
  int cnt_C = N - 1;

  for (int i = cnt_C; i > 0; i -= 1) {
    int mult_A_B = N - i;
    int cnt_baisu = baisu_cnt(mult_A_B);
    ans += cnt_baisu;
  }
}

int baisu[1000005] = {0};

void solve2() {
  for (int i = 1; i < N; i += 1) {
    for (int j = 1; j <= i; j += 1) {
      if (i % j == 0) {
        baisu[j] += 1;
      }
    }
  }
  for (int i = 1; i < N; i += 1) {
    ans += baisu[i];
  }
}

void solve3() {
  for (int A = 1; A < N; A += 1) {
    ans += (N - 1) / A;
  }
}

int main() {
  scanf("%d", &N);
  // solve1();
  // solve2();
  solve3();
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
const double PI=3.14159265358979323846;
const long long INF = 1LL << 60;

int main() {
	string S;
	cin >> S;
	int a=0, b=0, c=0, x, y, z;
	std::cout << S.substr(0,3) << '\n';
}


Measured memory_bytes: 3584
unittest
{
	assert( [ "4 5", "##...", ".##..", "..##.", "...##" ].parse.expand.solve == "Possible" );
	assert( [ "5 3", "###", "..#", "###", "#..", "###" ].parse.expand.solve == "Impossible" );
	assert( [ "4 5", "##...", ".###.", ".###.", "...##" ].parse.expand.solve == "Impossible" );
	
	assert( [ "3 3", "###", "..#", "###" ].parse.expand.solve == "Impossible" );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto ass = new dchar[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.to!( dchar[] );
	}
	return tuple( ass );
}

auto solve( dchar[][] ass )
{
	auto y = 0L;
	auto x = 0L;
	while( !( y + 1 == ass.length && x + 1 == ass[ y ].length ) )
	{
		auto nd = ( y + 1 < ass.length      && ass[ y + 1 ][ x ] == '#' );
		auto nr = ( x + 1 < ass[ y ].length && ass[ y ][ x + 1 ] == '#' );
		if( nd && nr ) return "Impossible";		// ルートが分岐してたらダメ
		
		if( nd )
		{
			y++;
			if( 0 < x && ass[ y ][ x - 1 ] == '#' ) return "Impossible";		// ルートの先が左に曲がっていたらダメ
		}
		if( nr )
		{
			x++;
			if( 0 < y && ass[ y - 1 ][ x ] == '#' ) return "Impossible";		// ルートの先が上に曲がっていたらダメ
		}
	}
	return ( y + 1 == ass.length && x + 1 == ass[ y ].length ) ? "Possible" : "Impossible";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int main() {
	int a=read(),b=read(),c=read();
	printf("%d\n",c-min(a-b,c));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,k=0;
  vector<int> v[1000];
  cin>>n;
  fr(i,1000){
    if((i*(i-1))/2==n){
      k=i;
      break;
    }
  }
  if(k==0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl<<k<<endl;
  Fr(i,k-1){
    ifr(j,i) v[k-i].pb(n-j-(i*(i-1))/2);
  }
  fr(i,k){
    cout<<k-1<<" ";
    Fr(j,i) cout<<v[j][i-j]<<" ";
    fr(j,v[i+1].size()) cout<<v[i+1][j]<<" ";
    cout<<endl;
  }
}

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

int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> a(N);
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        a[i] = make_pair(x, i + 1);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < N; i++)
    {
        if (i == N - 1)
            cout << a[i].second << endl;
        else
            cout << a[i].second << " ";
    }
    return 0;
}

Measured memory_bytes: 1664
n=int(input())
a=list(map(int,input().split()))
gk=[0]
kgk=0
for i in range(n):
    kgk+=a[i]
    gk.append(kgk)
gk.sort()
a=gk[0]
db=0
ans=0
for i in range(1,n+1):
    b=gk[i]
    if(a==b):
        db+=1
    else:
        a=b
        p=0
        for i in range(db+1):
           p+=i
        ans+=p
        db=0
p=0
for i in range(db+1):
    p+=i
ans+=p
print(ans)

Measured memory_bytes: 25976
from itertools import permutations
from math import factorial


# メインプログラム
def func(N, lst):

    # N! を求める
    N_fact = factorial(N)

    # lst から座標のすべての組合せを求める。
    perm_grid_xy = permutations(lst)

    # すべての組合せを全探索して、総合距離を計算する
    total_dist = total_distance(N, perm_grid_xy)

    # 平均距離 = 総合距離 / N!
    average_dist = total_dist / N_fact

    return average_dist


def total_distance(N, perm_grid_xy):

    ret = 0
    
    for grid_xy in perm_grid_xy:
        for i in range(N-1):
            x0, y0 = grid_xy[i][0], grid_xy[i][1]
            x1, y1 = grid_xy[i+1][0], grid_xy[i+1][1]
            dist = ((x0 - x1)**2 + (y0 - y1)**2) ** 0.5
            ret += dist

    return ret


if __name__ == "__main__":
    N = int(input())
    lst = [tuple(map(int, input().split())) for _ in range(N)]
    print(func(N, lst))

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

def greedy(J,L,I):
    ans = 0
    ans += (J // 2) * 2
    ans += (L // 2) * 2
    J -= (J // 2) * 2
    L -= (L // 2) * 2
    if J * L * I > 0:
        ans += 3
        I -= 1
    ans += (I // 2) * 2
    return ans

def solve(I,O,T,J,L,S,Z):
    ans = O
    tmp1 = greedy(J,L,I)
    if J * L * I > 0:
        tmp1 = max(tmp1, 3 + greedy(J-1,L-1,I-1))
    ans += tmp1
    return ans
    
I,O,T,J,L,S,Z = map(int,input().split())
print(solve(I,O,T,J,L,S,Z))

# assert(solve(0,0,0,0,0,0,0) == 0)
# assert(solve(2,0,0,0,0,0,0) == 2)
# assert(solve(3,0,0,0,0,0,0) == 2)
# assert(solve(4,0,0,1,1,0,0) == 5)
# assert(solve(4,0,0,2,1,0,0) == 6)





Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;

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

  int sum_p;
  sum_p = 0;

   for (int i = 0; i < K; i++) {
      sum_p += p[i];
  }
  cout << sum_p <<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
int n,m,a,sum;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a;
    n-=a;
  }
  if(n>=0) cout<<n<<"\n";
  else cout<<"-1\n";
}

Measured memory_bytes: 3640