akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
map<int,int> mp;
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
    	mp[2]++;
        //cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
        	mp[i]++;
            //cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)
		mp[n]++;  
        //cout << n << " ";  
}  
int32_t main()
{
	int n;
	cin >> n;
	primeFactors(n);
	int cnt=0;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		int x=(*it).second;
		int y=(sqrt(8*x+1)-1)/2;
		cnt+=y;
	}
	cout << cnt;
}


Measured memory_bytes: 3600
#!/usr/bin/env python3
import sys


def solve(N: int, X: int, Y: int):
    distances = [0] * (N - 1)
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            if j < X - 1 or Y - 1 < i:
                distance = j - i
            else:
                distance = min(j - i, abs(X - 1 - i) + abs(Y - 1 - j) + 1)
            distances[distance - 1] += 1

    for k in distances:
        print(k)

            
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

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

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

int N, M;
vi p(100010);
vi used(100010, 0);
vector<vi> G(100010);

vi dfs(int n) {
    vi list;
    if (used[n]) return vi({});
    used[n] = 1;
    list.push_back(n);
    for (int v : G[n]) {
        vi t = dfs(v);
        list.insert(list.end(), t.begin(), t.end());
    }
    return list;
}

ll ans = 0;

int main() {
    cin >> N >> M;
    rep(i,N) cin >> p[i];
    rep(i,M) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    rep(i,N) {
        if (!used[i]) {
            vi t = dfs(i);
            set<int> mp;
            rep(i,t.size()) {
                mp.insert(p[t[i]]);
            }
            rep(i,t.size()) {
                if (mp.count(t[i]+1)) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 19680
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define readi(x) scanf("%d", &x)
#define reads(s) scanf("%s", s)
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b, x;
  scanf("%d %d %d", &a, &b, &x);

  if (a <= x && a + b > x) printf("YES\n");
  else printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
#include <math.h>
#include <algorithm>
// #include "./Debug.h"

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

int main(void) {

	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());

	const unsigned int a = std::min(s[0],s[1]), b = std::max(s[0], s[1]);

	double ans = (a + b) / 2.0;

	bool conf = true;

	if (ceil(ans) != ans) {
		printf("IMPOSSIBLE\n");
	} else {
		printf("%1.0lf\n", ans);
	}

	return 0;
}


Measured memory_bytes: 888
a,b,c = map(int,input().split())
if max(a,b,c) % 2 == (a + b + c) % 2:
	print((3 * max(a,b,c) - (a + b + c)) // 2)
else:
	print((3 * (max(a,b,c) + 1) - (a + b + c)) // 2)

Measured memory_bytes: 3060
import numpy as np

n = int(input())
a = [int(x) for x in input().split()]

a_before = np.sum(a)
for i in range(len(a)-1):
    # print(a)
    if a[i] > a[i+1]:
        a[i+1] = a[i]

a_after = np.sum(a)

print(a_after - a_before)

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

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

  set<int> s;
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      s.insert(a);
    }
  }

  cout << N - s.size() << endl;
  return 0;
}


Measured memory_bytes: 3632
# map(int, input().split())
# list(map(int, input().split()))
# for _ in range(int(input())):

n = int(input())

def check(i, j, col, occ):
    c = occ[n-1]-occ[j];
    if (j+j-i<=n-1 and rgb[j+(j-i)]==col): 
        c-=1
    return c

rgb = list(input())

red, blue, green = [0]*n,[0]*n,[0]*n 

if (rgb[0]=='R'): 
    red[0]+=1;
elif (rgb[0]=='B'): 
    blue[0]+=1;
elif (rgb[0]=='G'): 
    green[0]+=1;
for i in range(1,n):
    red[i] = red[i-1];
    blue[i] = blue[i-1];
    green[i] = green[i-1];
    if (rgb[i]=='R'): red[i]+=1;
    elif (rgb[i]=='B'): blue[i]+=1;
    elif (rgb[i]=='G'): green[i]+=1;


ans = 0;
for i in range(0,n-2) :
    for j in range(i+1,n-1) :
        if (rgb[j]==rgb[i]): 
            continue
        if ('G' != rgb[i] and 'G' != rgb[j]): 
            ans += check(i,j,'G',green);
        elif ('B' != rgb[i] and 'B' != rgb[j]): 
            ans += check(i,j,'B',blue);
        elif ('R' != rgb[i] and 'R' != rgb[j]):
            ans += check(i,j,'R',red);

print(ans)


Measured memory_bytes: 69436
#include <stdio.h>

int main()
{
    int n;
    int i;
    scanf("%d", &n);
    for(i = 1; i <= n; i++) {
        if((i%3) == 0 || (i%10) == 3 || ((i/10)%10) == 3 || ((i/100)%10) == 3 || ((i/1000)%10) == 3) {
            printf(" %d", i);
        }
    }
    printf("\n");
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; ++i) {
    cin >> p.at(i);
  }
  int ans = accumulate(p.begin(), p.end(), 0);
  ans -= *max_element(p.begin(), p.end()) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

var R = [][]int{}

func main() {
	var N, M, Q int
	fmt.Scanf("%d %d %d\n", &N, &M, &Q)
	A := make([]int, Q)
	B := make([]int, Q)
	C := make([]int, Q)
	D := make([]int, Q)

	for i := 1; i <= M; i++ {
		rec([]int{}, i, M, N)
	}
	for i := 0; i < Q; i++ {
		var a, b, c, d int
		fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
		A[i] = a
		B[i] = b
		C[i] = c
		D[i] = d
	}

	max := 0
	for _, r := range R {
		score := 0
		for i := 0; i < Q; i++ {
			a := A[i]
			b := B[i]
			c := C[i]
			d := D[i]
			if r[b-1]-r[a-1] == c {
				score += d
			}
		}
		if score > max {
			max = score
		}
	}
	fmt.Println(max)

}

func rec(r []int, s, e int, l int) {
	if len(r) == l {
		R = append(R, r)
		return
	}
	for i := s; i <= e; i++ {
		for j := i; j <= e; j++ {
			r := append([]int{}, r...)
			r = append(r, j)
			if i == j {
				rec(r, j, e, l)
			}
		}
	}
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


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

int main()
{
  char answer[4];for(int i=0;i<4;i++)scanf("%c",&answer[i]);
  if((answer[0]==answer[1])||(answer[1] == answer[2])||(answer[2] == answer[3]))
  {cout<<"Bad"<<endl;}
  else
  {cout<<"Good"<<endl;}
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  map<string, int> m;
  int n; cin >> n;
  string s;
  
  int best = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> s;
    best = max(best, ++m[s]);
  }

  for (auto const& p : m) if (p.second == best)
    cout << p.first << endl;
  
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

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


    int main()
    {
       int n;
       cin>>n;
       vector<int> T(n,0);
       int sum=0;
       for(int i=0; i<n; i++)
       {
           cin>>T[i];
           sum+=T[i];
       }
       int m;
       cin>>m;
       for(int i=0; i<m; i++)
       {
           int p, x;
           cin >> p >> x;
           cout<<sum-T[p-1]+x<<endl;
       }
    }


Measured memory_bytes: 256
#include<stdio.h>
#include<map>
using namespace std;
typedef long long ll;
map<ll,int>p;
map<ll,int>::iterator it;
int fa[100010],siz[100010],a[100010],b[100010],h[100010],nex[200010],to[200010],M,n;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
ll wd[100010],d[100010];
void dfs(int x,int dis){
	siz[x]=1;
	d[1]+=dis;
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			fa[to[i]]=x;
			dfs(to[i],dis+1);
			siz[x]+=siz[to[i]];
		}
	}
}
void dfs(int x){
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			d[to[i]]=d[x]+n-siz[to[i]]*2;
			dfs(to[i]);
		}
	}
}
int get(int x){return fa[x]==x?x:(fa[x]=get(fa[x]));}
int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",wd+i);
		p[wd[i]]=i;
	}
	for(i=1;i<=n;i++){
		fa[i]=i;
		siz[i]=1;
	}
	it=p.end();
	for(it--;it!=p.begin();it--){
		if(n-siz[it->second]*2==0||!p.count(it->first-(n-siz[it->second]*2))){
			puts("-1");
			return 0;
		}
		M++;
		a[M]=it->second;
		b[M]=p[it->first-(n-siz[it->second]*2)];
		siz[fa[a[M]]=get(b[M])]+=siz[a[M]];
	}
	M=0;
	for(i=1;i<n;i++){
		add(a[i],b[i]);
		add(b[i],a[i]);
	}
	fa[1]=0;
	dfs(1,0);
	dfs(1);
	for(i=1;i<=n;i++){
		if(wd[i]!=d[i]){
			puts("-1");
			return 0;
		}
	}
	for(i=1;i<n;i++)printf("%d %d\n",a[i],b[i]);
}

Measured memory_bytes: 17280
K = int(input())
A = list(map(int, input().split()))

# 最後に2人以上残るような最小のNを探す
ok, ng = 10 ** 18, 0
while abs(ok - ng) > 1:
    n = (ok + ng) // 2
    x = n
    for a in A:
        x = (x // a) * a
    if x >= 2:
        ok = n
    else:
        ng = n
m = ok

# 最後に2人以下になるような最大のNを探す
ok, ng = 0, 10 ** 18
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    n = x
    for a in A:
        x = x // a * a

    if x <= 2:
        ok = n
    else:
        ng = n
M = ok


# 条件を満たすかチェック
mx, Mx = m, M
for a in A:
    mx = (mx // a) * a
    Mx = (Mx // a) * a

if mx == 2 and Mx == 2:
    print(m, M)
else:
    print(-1)


Measured memory_bytes: 63984
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int a = 0;
    string s;
    cin >> s;
    if(s == "SUN") a = 7;
    if(s == "MON") a = 6;
    if(s == "TUE") a = 5;
    if(s == "WED") a = 4;
    if(s == "THU") a = 3;
    if(s == "FRI") a = 2;
    if(s == "SAT") a = 1;
    dunk(a);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

using namespace std;

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

std::string L;
mint dp[100010][2];

int main()
{
  std::cin >> L;

  ll N = L.size();

  dp[0][0] = 1;

  rep( i, N ) rep( lim, 2 )
  {
    rep( x, 2 ) rep( y, 2 )
    {
      if( x && y )
        continue;
      if( !lim && x+y > L[i]-'0' )
        continue;

      dp[i+1][lim || x+y < L[i]-'0'] += dp[i][lim];
    }  
  }

  mint ans = dp[N][0]+dp[N][1];

  printf( "%lld\n", ans.x );

  return 0;
}

Measured memory_bytes: 2048
import queue

h,w = map(int,input().split())
si = [input() for i in range(h)]

q = queue.Queue()

check = [-1]*(h*w)

vx = [0,1,0,-1]
vy = [1,0,-1,0]

for i in range(h*w):
    y = i//w
    x = i%w
    if si[y][x] == '#':
        if check[i] != -1:
            continue
        q.put([i,'#'])
        check[i] = i
        
        while not q.empty():
            num, clr = q.get()
            y = num//w
            x = num%w
            
            for j in range(4):
                ny = y + vy[j]
                nx = x + vx[j]
                if ny >= 0 and ny < h and nx >= 0 and nx < w:
                    new_num = ny*w+nx
                    if check[new_num] != -1:
                        continue
                    #print(new_num)
                    if clr == '#':
                        if si[ny][nx] == '.':
                            q.put([new_num,'.'])
                            check[new_num] = check[num]
                    else:
                        if si[ny][nx] == '#':
                            q.put([new_num,'#'])
                            check[new_num] = check[num]
    
#print(check)

ans = 0

li = [0]*(h*w+1)

for i in range(h):
    for j in range(w):
        if si[i][j] == '.':
            li[check[i*w+j]] += 1

#print(li)

for i in range(h):
    for j in range(w):
        if si[i][j] == '#':
            ans += li[check[i*w+j]]
            
print(ans)

Measured memory_bytes: 10692
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#define DBG(...) {string dst__=#__VA_ARGS__;dreplace(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dreplace(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
constexpr LL LINF=334ll<<53; constexpr int INF=15<<26; constexpr LL MOD=1E9+7;

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

    int n;
    LL a,b;
    cin >> n >> a >> b;
    VLL x(n);
    for(int i=0; i<n; ++i){
        cin >> x[i];
    }
    LL ans =0;
    for(int i=1; i<n; ++i){
        if((x[i]-x[i-1])*a>b) ans+=b;
        else ans+=(x[i]-x[i-1])*a;
    }
    cout << ans <<"\n";

    return 0;
}



Measured memory_bytes: 1024
import sys
n=int(input())

if (n % 10)  % 2 == 1:
    print(0)
    sys.exit()

counter=0
i=1
while True:
    tmp = (n // 5**i)//2
    if tmp == 0:
        print(counter)
        sys.exit()
    else:
        counter += tmp
        i += 1





Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

#define long long long // for codeforces

template <class T>
class WeightedUnionFind {
  int n;
  vector<int> par,sz;
  vector<T> w;
  // weight[i] : iがpar[i]よりどれだけ重いか
public:
  WeightedUnionFind(){}
  WeightedUnionFind(int _n) : n(_n) {
    par.resize(n, -1);
    sz.resize(n, 1);
    w.resize(n, 0);
  }
  int find(int i){
    if(par[i] < 0) return i;
    int p = find(par[i]);
    w[i] += w[par[i]];
    return par[i] = p;
  }
  T weight(int x){ find(x); return w[x]; }
  bool same(int x, int y){ return find(x) == find(y); }
  // weight[i] +w の位置に j を配置
  void unite(int i, int j, T nw){
    nw += weight(i) - weight(j);
    int x = find(i), y = find(j);
    if(x == y) return;
    if(sz[x] < sz[y]){
      swap(x, y);
      nw = -nw;
    }
    sz[x] += sz[y];
    par[y] = x;
    w[y] = nw;
  }
  // x からみた y の相対位置
  T diff(int x, int y){ return weight(y) - weight(x); }
};

int main(){
  int n,q;
  scanf("%d %d", &n, &q);

  WeightedUnionFind<int> uf(n);
  vector<int> added(n, 0);
  rep(i,q){
    char s[20];
    scanf("%s", s);
    if(s[0] == 'I') {
      int a,b,c;
      scanf("%d %d %d", &a, &b, &c);
      a--;b--;
      uf.unite(a, b, c + added[a] - added[b]);
      added[a] += c;
      added[b] += c;
    }
    else if(s[0] == 'C') {
      int a,b;
      scanf("%d %d", &a, &b);
      a--;b--;
      if(uf.same(a,b)) { dbg(added, uf.weight(0), uf.weight(1), uf.weight(2));
        printf("%d\n", uf.diff(a,b) + added[b] - added[a]);
      } else {
        printf("WARNING\n");
      }
    }
    else assert(false);
  }

  return 0;
}



Measured memory_bytes: 4408
#!/usr/bin/env python3
s = input()
t = input()
flag = 0
left = 0
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(1+len(s)-len(t)):
    for j in range(len(t)):
        #後ろから一致or s[i]==?かをみる
        if s[-i-j-1] == "?" or s[-i-j-1] == t[-j-1]:
            if j == len(t) -1 :
                flag = 1
                break
        else: break
    if flag == 1: 
        left = i
        break
    if i == len(s)-len(t):
        print("UNRESTORABLE")
        exit()
#print(left)
for i in range(len(s)):
    if i < len(s) - left - len(t) or i >= len(s) - left:
        if s[i] == "?":
            print("a",end = "") 
        else: print(s[i],end="")
    elif i < len(s) - left:
        print(t[i-(len(s) - left-len(t))],end="")

Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;
char ch;

int cnt[26] = {};
int main()
{

	while ( cin >> ch ) {
		ch = tolower(ch);
		if (isalpha(ch)) {
			cnt[ch - 'a']++;
		}
	}
	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", i + 'a', cnt[i]);
	}
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
int n;
cin >> n;
if(n%2 == 0) cout << n/2-1 << endl;
else cout << n/2 << endl;
}


Measured memory_bytes: 3676
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b; cin >> n >> a >> b;
	vector<ll> v(n);
	rep(i, n)cin >> v[i];
	ll ans = 0;
	rep(i, n - 1) {
		ans += min(a * (v[i + 1] - v[i]), b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <limits>

int main(int argc, char *argv[])
{
    int n, m;

    std::cin >> n >> m;

    if (n % 2 == 1) { // 奇数
        for (int i = 0; i < m; i++) {
            std::cout << i + 1 << " " << 2 * m - i << std::endl;
        }
    } else { // 偶数
        for (int i = 0; i < m; i++) {
            std::cout << i + 1 << " " << 2 * m - i + ((i < m / 2)?1:0) << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3180
n,p = map(int,input().split())
a  = list(map(int,input().split()))
cnt = 0
for x in a:
    if x%2:cnt+=1
if cnt == 0:
    if p:ans = 0
    else:ans = 2**n
else:
    ans = 2**(n-1)
print(ans)

Measured memory_bytes: 3060
#include<iostream>

int A, B, C;

int main(){
    std::cin >> A >> B >> C;

    for(int x = 1; x <= 5050; x++){
        if((B*x + C) % A == 0){
            std::cout << "YES";
            return 0;
        }
    }
    std::cout << "NO";
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [10000000000]*(N)
dp[0] = 0

for i in range(N-1):
  for j in range(1,K+1):
    if i+j < N:
      dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]))
  
print(dp[-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    string S;
    cin >> S;
    if(S.at(2)==S.at(3) && S.at(4)==S.at(5)) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val n = StdIn.readInt()
    for(i <- 1 to n){
      if(check_num(i)){print(" %d".format(i))}
    }
    println()
  }

  def check_num(n:Int): Boolean = n match {
      case n if n % 3 == 0 => true
      case n if(n.toString.contains("3")) => true
      case _ => false
    }
}

Measured memory_bytes: 55356
#include<bits/stdc++.h>
using namespace std;
int n,a[210];
int main()
{
	scanf("%d",&n);
	for (int i=0;i<2*n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+2*n);
	int ans=0;
	for (int i=0;i<2*n;i+=2)
	{
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
cpw=7*a+b
w=c//cpw
r=c%cpw
if r<7*a:
    if r%a==0:
        d=r//a
    else:
        d=(r//a)+1
elif 0<=r-7*a and r-7*a<b:
    d=7
print(7*w+d)


Measured memory_bytes: 5596
n = int(input())
a = list(map(int,input().split()))
b= list(map(int,input().split()))
c = list(map(int,input().split()))
 
m=0
 
for i in range (0,n):
  m += b[a[i]-1]
  if i !=0 and a[i]==a[i-1]+1:
    m += c[a[i-1]-1]
print(m)

Measured memory_bytes: 3064
#include<stdio.h>
#define N 100

int main(void){
    int n,i,j,k,a[N],base;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        base=a[i];
        j=i-1;
        while(j>=0 && a[j]>base){
            a[j+1]=a[j];
            j=j-1;
            a[j+1]=base;
        }
	    for(k=0;k<n;k++){
		    if(k<n-1){
                printf("%d ",a[k]);
            }
            if(k==n-1){
                printf("%d\n",a[k]);
            }
        }
    }
        return 0;
}


Measured memory_bytes: 2096
import java.util.Scanner;

//Highway Toll
public class Main{

	public static void main(String[] args) {
		int[][] p = {
				{0,300,500,600,700,1350,1650},
				{300,0,350,450,600,1150,1500},
				{500,350,0,250,400,1000,1350},
				{600,450,250,0,250,850,1300},
				{700,600,400,250,0,600,1150},
				{1350,1150,1000,850,600,0,500},
				{1650,1500,1350,1300,1150,500,0}
		};
		int[][] d = {
				{0,6,13,18,23,43,58},
				{6,0,7,12,17,37,52},
				{13,7,0,5,10,30,45},
				{18,12,5,0,5,25,40},
				{23,17,10,5,0,20,35},
				{43,37,30,25,20,0,15},
				{58,52,45,40,35,15,0}
		};
		Scanner sc = new Scanner(System.in);
		while(true){
			int s = sc.nextInt();
			if(s==0)break;
			s--;
			int sh = sc.nextInt()*60+sc.nextInt();
			int t = sc.nextInt()-1;
			int th = sc.nextInt()*60+sc.nextInt();
			int x = p[s][t]/50;
			if(d[s][t]<=40&&(17*60+30<=sh&&sh<=19*60+30 || 17*60+30<=th&&th<=19*60+30)){
				if(x%2==1)x=x/2+1;
				else x/=2;
			}
			System.out.println(x*50);
		}
	}
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, M = LI()
    A = []
    for _ in range(M):
        A.append(II())
    A.append(INF)
    pre = 0
    cur = 1
    k = 0
    for i in range(1, N + 1):
        if i == A[k]:
            k += 1
            pre = cur
            cur = 0
        else:
            tmp = cur
            cur = (cur + pre) % MOD
            pre = tmp
    ans = cur
    return ans

print(main())

Measured memory_bytes: 7080
def main():
    a,b,c=map(int, input().split())
    number=1
    if a==b:
        if b==c:
            number=1
        else:
            number=2
    else:
        if b==c:
            number=2
        elif a==c:
            number=2
        else:
            number=3
    print(number)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

vector<int> path[205];
queue<int> q1;
string sta;
int used[205];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	int s=-1,sa=0;
	int num;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>sta;
		for(j=0;j<n;j++){
			if(sta[j]=='1')path[i].push_back(j);
		}
	}
	for(i=0;i<n;i++){
		memset(used,-1,sizeof(used));
		while(!q1.empty())q1.pop();
		q1.push(i);
		a=0,num=0,sa=0;
		while(!q1.empty()){
			if(num!=n)sa++;
			a++;
			int z=q1.size();
			for(j=0;j<z;j++){
				b=q1.front(),q1.pop();
				if(used[b]!=-1){
					if(used[b]==a || used[b]==a-2)continue;
					//cout<<a<<" "<<b<<endl;
					sa=-1;
					break;
				}
				used[b]=a,num++;
				for(k=0;k<path[b].size();k++){
					q1.push(path[b][k]);
				}
			}
			if(sa==-1)break;
		}
		//cout<<sa<<endl;
		s=max(s,sa);
	}
	cout<<s<<endl;
}

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

int main() {

	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	double ans;
	double prev = (double)v[0];
	for (int i = 1; i < n; i++) {
		ans = (double)(prev + v[i]) / 2;
		prev = ans;
	}
	cout << fixed << setprecision(11) << ans << endl;
	return 0;
}

Measured memory_bytes: 3700
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    preSum = [0] * (N + 1)
    dd = defaultdict(int)
    dd[0] = 1
    for i in range(N):
        preSum[i + 1] = preSum[i] + A[i]
        dd[preSum[i] + A[i]] += 1
    sumA = 0
    for key in dd.keys():
        if dd[key] > 1:
            sumA += dd[key] * (dd[key] - 1) // 2
    print(sumA)


resolve()


Measured memory_bytes: 46844
import java.util.Scanner;

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

        if(a > b){
            if(b > c){
                System.out.printf("%d %d %d\n", c, b, a);
            }else if(a > c){
                System.out.printf("%d %d %d\n", b, c, a);
            }else{
                System.out.printf("%d %d %d\n", b, a, c);
            }
        }else{
            if(a > c){
                System.out.printf("%d %d %d\n", c, a, b);
            }else if(b > c){
                System.out.printf("%d %d %d\n", a, c, b);
            }else{
                System.out.printf("%d %d %d\n", a, b, c);
            }
        }

    }
}


Measured memory_bytes: 26332
// https://atcoder.jp/contests/agc023/tasks/agc023_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize, s: i64,
        a: [(i64, u64); n]
    };

    let mut left = VecDeque::new();
    let mut right = VecDeque::new();
    for &m in &a {
        if m.0 < s {
            left.push_front(m);
        } else {
            right.push_back(m);
        }
    }
    // debug!(left, right);

    let mut ans = 0;

    let mut dir = 0;
    while true {
        if left.len() == 0 {
            let rr = right.pop_back().unwrap();
            ans += rr.0 - s;
            break;
        } else if right.len() == 0 {
            let ll = left.pop_back().unwrap();
            ans += s - ll.0;
            break;
        } else {
            let mut ll = left.pop_back().unwrap();
            let mut rr = right.pop_back().unwrap();
            if ll.1 >= rr.1 {
                if dir != 1 {
                    ans += rr.0 - ll.0;
                }
                dir = 1;
                ll.1 += rr.1;
                left.push_back(ll);
            } else {
                if dir != -1 {
                    ans += rr.0 - ll.0;
                }
                dir = -1;
                rr.1 += ll.1;
                right.push_back(rr);
            }
        }
    }
    println!("{}", ans);
}


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

#define GRAY 1
#define BLACK 2
#define WHITE 0

int time = 0;

int color[101], d[101], f[101];
int ppp[101][101];
int n = 0;

void dfs(){
    int i=0, h=0;
    for(h=0; h<n; h++){
        color[h]==WHITE;
    }
    time = 0;
    for(h=0; h<n; h++){
        if(color[h]==WHITE) visit(h);
    }
    for(i=0;i<n;i++){
        printf("%d %d %d\n",i+1,d[i],f[i]);
    }
}

void visit(int u){
    color[u] = GRAY;
    d[u] = ++time;
    int i = 0;
    for(i=0; i<n; i++){
        if(ppp[u][i]==1){
            if(color[i]==WHITE) visit(i);
        }
    }
    color[u] = BLACK;
    f[u] = ++time;
}

int main()
{
    int a1, a2, a3, a4, a5;
    scanf("%d", &n);
    for (a1=0; a1<n; a1++){
        scanf("%d %d", &a2, &a3);
        a2--;
        for(a4=0; a4<a3; a4++){
            scanf("%d", &a5);
            a5--;
            ppp[a2][a5] = 1;
        }
    }
    dfs();
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>

using namespace std;

int main()
{
   long long int n,count=0,a;
   cin>>n;
   for(int i=1;i<n;i++){
      a=n/i;
      if(a*i==n){
      	a--;
      }
      count=count+a;
   }
   cout<<count<<endl;
   return 0;
}

Measured memory_bytes: 3632
/******************************************
* AUTHOR : SARTHAK GUPTA *
* NICK : SOPHOZAAR *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int h, w;
char grid[1001][1001];
int dp[1001][1001];

int solve(int i, int j) {
	// Base cases

	if((i < 0 || j < 0) || (i >= h || j >= w))
		return 0;
	if(grid[i][j] == '#')
		return 0;
	if(dp[i][j] != -1)
		return dp[i][j];
	dp[i][j] = ((solve(i - 1, j) % MOD) + (solve(i, j - 1) % MOD)) % MOD;
	return dp[i][j];
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);

cin >> h >> w;
for(int i = 0; i < h; i++) {
	for(int j = 0; j < w; j++) {
		cin >> grid[i][j];
		dp[i][j] = -1;
	}
}

dp[0][0] = 1;
cout << solve(h - 1, w - 1) << "\n";

}

Measured memory_bytes: 5248
#include<cstdio>
using namespace std;
const int MAX = 1200;
const char alpha[] = "XYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buf[MAX];
int main(){
  scanf("%s",buf);
  for(int i{} ; buf[i] != '\0' ; i++)
    printf("%c",alpha[buf[i] - 'A']);
  putchar('\n');
}



Measured memory_bytes: 2600
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

// End of template.

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

    int a, b, c;
    cin >> a >> b >> c;
    print((a + b + c) >= 22 ? "bust" : "win");

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main(){
    while(true){
        int N;
        cin>>N;
        if(N==0)break;
        vector<int> a(N);
        for(int i =0;i<N;i++){
            cin>>a[i];
        }
        int ave = accumulate(a.begin(),a.end(),0)/a.size();
        int ans=0;
        for(int i=0;i<N;i++){
            if(a[i]<=ave)ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){


    int n,tmp,array_maxi=-1,sum=0;
    cin >> n;
    vector<int> a(MAX_A,0);
    for(int i = 0;i < n;i++){

        cin >> tmp;
        a[tmp]++;
        a[tmp+1]++;
        if(tmp>0){
            a[tmp-1]++;
        }else{
            sum++;
        }
        array_maxi=max(array_maxi,tmp);
    }

    int maxi=0;
    int ans;
    for(int i = 0;i <
        array_maxi;i++){

        if(maxi<a[i]){
            maxi=a[i];
        }
    }
    cout << max(maxi,sum) << endl;
    
}

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

int main()
{
    string str1,str2;
    cin>>str1>>str2;
    int len1=str1.length();
    int len2=str2.length();
    int dp[len1+5][len2+5];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=len1;i++){
        for(int j=1;j<=len2;j++){
            if(str1[i-1]==str2[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int index=dp[len1][len2];
    int i=len1,j=len2;
    char lcs[index+1];
    lcs[index]='\0';
    while(i>0 && j>=0){
        if(str1[i-1]==str2[j-1])
            lcs[index-1]=str1[i-1],i--,j--,index--;
        else if(dp[i-1][j]>dp[i][j-1])i--;
        else j--;
    }
    cout<<lcs<<endl;
}


Measured memory_bytes: 35584
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var params = input[0].split(' ');
    var a = parseInt(params[0], 10);
    var b = parseInt(params[1], 10);
    var c = parseInt(params[2], 10);
    var d = parseInt(params[3], 10);

    if (b <= c || d <= a) {
        console.log(0);
    }
    else if (a <= c) {
        if (b <= d) {
            console.log(b - c);
        }
        else {
            console.log(d - c);
        }
    }
    else {
        if (b <= d) {
            console.log(b - a);
        }
        else {
            console.log(d - a);
        }
    }
}


Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
vector<int> v[100010];
vector<int> vb[100010];
vector<int> vv;
bool visit[100010];
int d[100010];
int res;
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (!visit[xi]) dfs(xi);
	}
	vv.push_back(x);
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		v[x].push_back(y);
		vb[y].push_back(x);
	}
	for (int i=0;i<n;i++)
	{
		if (!visit[i])
		    dfs(i);
	}
	reverse(vv.begin(),vv.end());
	d[vv[0]]=0;
	for (int tr=1;tr<n;tr++)
	{
		int x=vv[tr];
		for (int i=0;i<vb[x].size();i++)
		    d[x]=max(d[x],d[vb[x][i]]+1);
	}
	for (int i=0;i<n;i++) res=max(res,d[i]);
	cout <<res;
	return 0;
}

Measured memory_bytes: 13564
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 21:09:45 2019

@author: iwata
"""

N, M = map(int, input().split())
anew = []         

a = list(map(int, input().split()))
for i in range(1,len(a)):
    anew.append(a[i])

if N==1:
    print(len(anew))
else:
    for j in range(1,N):
        a = list(map(int, input().split()))
        for k in range(1, len(a)):
            anew.append(a[k])
        anew_duplicate = [x for x in set(anew) if anew.count(x) > 1]
        anew = anew_duplicate 
    print(len(anew_duplicate))

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

const int Maxn = 605, dx[] = {0, -1, -1, 1, 1}, dy[] = {0, 1, -1, 1, -1};
int n, d1, d2, ct1, ct2, cnt[3][3], col1[Maxn][Maxn], col2[Maxn][Maxn];
pair <int, int> T1[Maxn], T2[Maxn];
queue <pair <int, int> > Qu;
void bfs1(pair <int, int> s)
{
	Qu.push(s);
	while (!Qu.empty())
	{
		pair <int, int> now = Qu.front();
		Qu.pop();
		for (int k = 1; k <= ct1; k++)
			for (int q = 1; q <= 4; q++)
			{
				int tmp1 = now.first + dx[q] * T1[k].first, tmp2 = now.second + dy[q] * T1[k].second;
				if (tmp1 <= 2 * n && tmp1 >= 1 && tmp2 <= 2 * n && tmp2 >= 1 && col1[tmp1][tmp2] == -1)
					col1[tmp1][tmp2] = col1[now.first][now.second] ^ 1, Qu.push(make_pair(tmp1, tmp2));
			}
	}
}
void bfs2(pair <int, int> s)
{
	Qu.push(s);
	while (!Qu.empty())
	{
		pair <int, int> now = Qu.front();
		Qu.pop();
		for (int k = 1; k <= ct2; k++)
			for (int q = 1; q <= 4; q++)
			{
				int tmp1 = now.first + dx[q] * T2[k].first, tmp2 = now.second + dy[q] * T2[k].second;
				if (tmp1 <= 2 * n && tmp1 >= 1 && tmp2 <= 2 * n && tmp2 >= 1 && col2[tmp1][tmp2] == -1)
					col2[tmp1][tmp2] = col2[now.first][now.second] ^ 1, Qu.push(make_pair(tmp1, tmp2));
			}
	}
}
int main()
{
	scanf("%d%d%d", &n, &d1, &d2);
	int maxi = sqrt(d1);
	for (int i = 1; i <= maxi; i++)
		if (sqrt(d1 - i * i) == (int)sqrt(d1 - i * i))
		{
			T1[++ct1] = make_pair(i, sqrt(d1 - i * i));
			T1[++ct1] = make_pair(sqrt(d1 - i * i), i);
		}
	maxi = sqrt(d2);
	for (int i = 1; i <= maxi; i++)
		if (sqrt(d2 - i * i) == (int)sqrt(d2 - i * i))
		{
			T2[++ct2] = make_pair(i, sqrt(d2 - i * i));
			T2[++ct2] = make_pair(sqrt(d2 - i * i), i);
		}
	memset(col1, -1, sizeof(col1));
	memset(col2, -1, sizeof(col2));
	for (int i = 1; i <= 2 * n; i++)
		for (int j = 1; j <= 2 * n; j++)
		{
			if (col1[i][j] == -1)
			{
				col1[i][j] = 0;
				bfs1(make_pair(i, j));
			}
			if (col2[i][j] == -1)
			{
				col2[i][j] = 0;
				bfs2(make_pair(i, j));
			}
			cnt[col1[i][j]][col2[i][j]]++;
		}
	for (int i = 0; i <= 1; i++)
		for (int j = 0; j <= 1; j++)
			if (cnt[i][j] >= n * n)
			{
				int Left = n * n;
				for (int k = 1; k <= 2 * n; k++)
					for (int q = 1; q <= 2 * n; q++)
						if (col1[k][q] == i && col2[k][q] == j)
						{
							printf("%d %d\n", k - 1, q - 1);
							Left--;
							if (!Left) return 0;
						}
			}
}

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

int main()
{
    int n;
    cin >> n;
    int A[n];
    int key;
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    for(int i = 0; i < n; i++){
        cout << A[i];
        if(i < n - 1){
            cout << ' ';
        }else{
            cout << endl;
        }
    }

    for(int i = 1; i < n; i++){
        key = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > key){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = key;
      
        for(int k = 0; k < n; k++){
            cout << A[k];
            if(k < n-1){
                cout << ' ';
            }else{
                cout << endl;
            }
        }
    }
}



Measured memory_bytes: 3080