akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

vector<vector<char>> field(10, vector<char>(10));

//oと上下左右で隣接しているところは全てxに変える 
//全てのマスをxに変えるまで何回dfsを行ったかがoの連結数

//現在地(x,y)
void dfs(int x, int y) {
  //今いるところをxに変える

  field[x][y] = 'x';

  //移動する四方向をループ
  for (int i = 0; i < 4; i++) {

    //移動先をnx,nyとする
    int nx = x + dx[i], ny = y + dy[i];

    //nxとnyが地図の範囲内であるかどうかと移動先field[nx][ny]が陸地かどうかを判定
    if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && field[nx][ny] == 'o') dfs(nx,ny);

  }
  return;
}

int main(){
	int N,L;
	cin >> N >> L;
	vector<pair<int,int>> p(N);
	vector<int> app(N);
	rep(i,N){
		app[i] = L + i;
	}
	int sum1 = 0;
	int sum2 = 0;

	rep (i,N){
		sum1 += app[i];
	}
	sum2 = sum1;
	rep (i,N) {
		sum2 -= app[i];
		p[i].first = abs(sum1 - sum2);
		p[i].second = sum2;
		sum2 += app[i];
	}
	sort(p.begin(),p.end());
	cout << p[0].second << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool jud =false;

    rep(i,100){
        if(a*(i+1) %b == c) jud = true; 
    }

    if(jud) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n,k; cin>>n>>k;
    vector<int> x(n);
    rep(i,0,n) cin>>x[i];
    int ans=INF;
    for(int i=0; i+k-1<n; i++){
        ans=min(ans,min(abs(x[i])+abs(x[i]-x[i+k-1]),abs(x[i+k-1])+abs(x[i]-x[i+k-1])));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;

int main(){
    const int MA=100005;
    int Q;
    int lef[MA],rig[MA];
    cin>>Q;
    for(int i=1;i<=Q;i++){
        cin>>lef[i]>>rig[i];
    }
    bool prime[MA]={};
    for(int i=0;i<MA;i++){
        prime[i]=true;
    }
    prime[1]=false;
    for(int j=2;j<MA;j++){
        if(prime[j]){
            for(int i=2*j;i<MA;i+=j){
                prime[i]=false;
            }
        }
    }
    int like_2017[MA]={};
    for(int i=1;i<MA;i+=2){
        if(prime[i] && prime[(i+1)/2]){
            like_2017[i]=1;
        }
    }
    int tumoru=0;
    for(int i=1;i<MA;i+=2){
        int x=like_2017[i];
        like_2017[i]+=tumoru;
        tumoru+=x;
    }
    //the followings do queries.
    for(int i=1;i<=Q;i++){
        int ans;
        if(lef[i]==1){
            ans=like_2017[rig[i]];
        }else{
            ans=like_2017[rig[i]]-like_2017[lef[i]-2];
        }
        cout<<ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b ? a:b;}
ll min(ll a, ll b) {return a<b ? a:b;}



int main(void) {
    ll K;
    cin >> K;
    ll ans[50];
    ll i, j;
    
    for(i=0; i<50; i++) {
        ans[i]=49;
        ans[i]+=K/50;
    }
    
    for(i=0; i<K%50; i++) {
        ans[i]+=50;
        for(j=0; j<50; j++) {
            if(j==i) continue;
            ans[j]--;
        }
    }
    
    pt(50);
    for(i=0; i<50; i++) cout << ans[i] << " ";
    cout <<  endl;
    
    
}







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

int main()
{
  string buf;
  while( true ) {
    cin >> buf;
    if( buf == "0" ) {
      break;
    }

    int sum = 0;
    for( int i = 0; i < buf.size(); i++ ) {
      sum += buf[i] - 48;
    }
    cout << sum << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
	int h, w;
	string ans;
	char s[51][51];

	cin >> h >> w;

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> s[i][j];
		}
	}

	ans = "Yes";

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (s[i][j] == '#' &&
				s[i + 1][j] == '.' && s[i - 1][j] == '.' &&
				s[i][j + 1] == '.' && s[i][j - 1] == '.')
			{
				ans = "No";
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  static int MAX_NUM = 100;
  int num;
  int nums[MAX_NUM];
  
  cin >> num;
  for(int i = 0; i < num; i++) {
    cin >> nums[i];
  }
  for(int i = 0; i < num; i++) {
    cout << nums[num - i - 1];
    if(i != num - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 3088
n = int(input())
A = list(int(input()) for _ in range(n))

def insertionSort(A, g):
    global cnt
    for i in range(g, len(A)):
        temp = A[i]
        j = i - g
        
        while j >= 0 and A[j] > temp:
            A[j+g] = A[j]
            j -= g
            A[j+g] = temp
            cnt += 1

def shellSort(A):
    global cnt
    cnt = 0
    G = []
    i = 1
    
    while i <= len(A):
        G.append(i)
        i = 3 * i + 1
        
    G.reverse()
    m = len(G)
    print(m)
    print(*G)
    
    for j in range(m):
        insertionSort(A, G[j])
        
        
shellSort(A)
print(cnt)

for a in A:
    print(a)


Measured memory_bytes: 45468
def factorial_mod(n,mod):
    ret = 1
    for i in range(1,n+1):
        ret *= i
        ret %= mod
    return ret
def comb_mod(n,r,mod):
    if r > n or r < 0:
        ret = 0
    else:
        fact_n  = factorial_mod(n, mod)
        fact_r  = factorial_mod(r, mod)
        fact_nr = factorial_mod(n-r, mod)
        ret = fact_n * pow(fact_r, mod-2, mod) * pow(fact_nr, mod-2, mod) % mod
    return ret
n,m = map(int,input().split())
c = abs(n-m)
mod = 10**9+7
if c >= 2:
    ans = 0
elif c == 1:
    ans = factorial_mod(n,mod)*factorial_mod(m,mod)
else:
    ans = 2*factorial_mod(n,mod)*factorial_mod(m,mod)
print(ans%mod)

Measured memory_bytes: 9232
from collections import defaultdict


def main():
    S = input()
    ans = 0
    # 2 ^ nの組み合わせの全列挙
    n = len(S) - 1
    for b in range(2 ** n):
        p_list = [i for i in range(n) if b & 1 << i]
        x, s = [], S[:]
        for p in p_list[::-1]:
            a, s = s[p + 1:], s[:p + 1]
            x.append(a)
        if s:
            x.append(s)
        ans += eval("+".join(x))

    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

const double PI = 3.141592;
const int MAX_N = 1e5+5;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

const bool dbgEnabled = false;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef vector<pii> vpii;
typedef vector<psi> vpsi;
typedef vector<pis> vpis;
typedef vector<vi> vvi;

// Debug macros
#define dbg(x) do { \
	if (dbgEnabled) { cerr << #x << ": " << x << "\n"; } \
} while (0)

#define dbgv(x) do { \
	if (dbgEnabled) { cerr << #x << ": [ "; for (auto& _ : x) cerr << _ << " "; cerr << "]\n"; } \
} while (0)

#define dbgvv(x) do { \
	if (dbgEnabled) { cerr << #x << ":\n[\n"; for (auto& __ : x) dbgv(__); cerr << "]\n";} \
} while (0)

void solve() {
	string s, t;
	cin >> s >> t;
	ll n = s.size(), m = t.size();
	ll ans = LLONG_MAX;
	for (ll i = 0; i < n-m+1; i++) {
		ll c = 0;
		for (ll j = 0; j < m; j++) {
			if (s[i+j] == t[j]) c++;
		}
		ans = min(ans, m - c);
	}
	cout << ans << endl;
}

int main() {
	if (!dbgEnabled) {
		ios_base::sync_with_stdio(false);
		cin.tie(nullptr); cout.tie(nullptr);
	}
	
	ll t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}    
    return 0;
}



Measured memory_bytes: 3672
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define INF 100000000
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) cout << "error" << endl;
    else cout << a + b << endl;
    return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  if (N %2 != 0){
    cout << "No" << endl;
  }else {
  int n = N/2;
  
  int ans = 1;
  for (int i = 0; i< n; i++){
    ans *= (S[i] == S[i+n]);
  }
  if ( ans == 1){
  cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  }

  
}


Measured memory_bytes: 256
import math
inf = float('inf')

n, t = map(int, input().split())
c_t = [list(map(int, input().split())) for i in range(n)]

min_c = inf
for i in c_t:
    if i[1] <= t:
        min_c = min(min_c, i[0])

if min_c == inf:
    print("TLE")
else:
    print(min_c)

Measured memory_bytes: 9176
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

def precompute(N, M, data):
    data = data.reshape(-1, 3)
    A, B, C = data[:N].T
    D, E, F = data[N:].T
    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B)
    D = np.searchsorted(X, D)
    C = np.searchsorted(Y, C)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F)
    return A, B, C, D, E, F, X, Y

@njit('(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])', cache=True)
def solve(A, B, C, D, E, F, X, Y):
    H, W = len(X), len(Y)
    N = H * W
    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]

    def set_ng(A, B, C, D, E, F, H, W):
        ng = np.zeros((H * W, 4), np.bool_)

        for i in range(len(A)):
            for x in range(A[i], B[i]):
                v = x * W + C[i]
                ng[v][1] = 1
                ng[v - 1][0] = 1

        for i in range(len(D)):
            for y in range(E[i], F[i]):
                v = D[i] * W + y
                ng[v][3] = 1
                ng[v - W][2] = 1
        return ng

    ng = set_ng(A, B, C, D, E, F, H, W)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

N, M = map(int, readline().split())
data = np.int64(read().split())

x = solve(*precompute(N, M, data))
if x == 0:
    print('INF')
else:
    print(x)

Measured memory_bytes: 165176
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};

int main(){
    int n;cin>>n;
    while(n-1000>=0){
        n -= 1000;
    }
    if(n==0)cout<<0<<endl;
    else cout<<1000-n<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

 
int main() {
  int N,K;
  cin >> N >> K;
  string s;
  cin >> s;
  vi nums;
  int now = 1;
  int cnt = 0;
  rep(i,N) {
    if(s[i] == (char)(now + '0')) {
      cnt++;
    } else {
      nums.push_back(cnt);
      cnt = 1;
      now = 1 - now;
    }
  }
  if(cnt != 0) nums.push_back(cnt);
  if(sz(nums) % 2 == 0) nums.push_back(0);
  int len = sz(nums);
  vi sum(len+1);
  sum[0] = 0;
  rep(i,len) {
    sum[i+1] = sum[i] + nums[i];
  }

  int ans = 0;
  for(int i = 0;i < len;i += 2) {
    int left = i;
    int right = min(i + 2 * K +1,len);
    ans = max(ans,sum[right] - sum[left]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1272
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

def solve():
    H, W, K = map(int, input().split())
    S = [list(map(int, list(input()))) for _ in range(H)]
    ans = INF
    for i in range(2 ** (H - 1)):
        p = deque()
        for j in range(H - 1):
            if (i >> j) & 1:
                p.append(j + 1)
        num = len(p)
        if len(p) == 0:
            check = 0
            for j in range(W):
                temp_sum = sum([S[l][j] for l in range(H)])
                if temp_sum > K:
                    num = INF
                if check + temp_sum > K:
                    check = temp_sum
                    num += 1
                else:
                    check += temp_sum
        else:
            p.appendleft(0)
            p.append(H)
            check = [0] * (len(p) - 1)
            for j in range(W):
                for l in range(len(p) - 1):
                    if p[l + 1] - p[l] == 1:
                        check[l] += S[l][j]
                    else:
                        temp_sum = sum([S[t][j] for t in range(p[l], p[l + 1])])
                        if temp_sum > K:
                            num = INF
                            break
                        check[l] += temp_sum
                for l in check:
                    if l > K:
                        num += 1
                        for k in range(len(p) - 1):
                            if p[k + 1] - p[k] == 1:
                                check[k] = S[k][j]
                            else:
                                temp_sum = sum([S[t][j] for t in range(p[k], p[k + 1])])
                                if temp_sum > K:
                                    num = INF
                                check[k] = temp_sum
                        break
        if num < ans:
            ans = num
    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 83028
N, M = map(int, input().split())
for i in range(M):
    tmpL, tmpR = map(int, input().split())
    if i == 0:
        L, R = tmpL, tmpR
    else:
        L = max(tmpL, L)
        R = min(tmpR, R)
    if L > R:
        print(0)
        break
if i == M - 1 and L <= R:
    print(R - L + 1)

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

using namespace std;

using ll = long long;

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

struct node {
  int x, y, z;
  ll v;
  node(int a, int b, int c, ll d) : x(a), y(b), z(c), v(d) {}
  bool operator<(const node b) const {
    return v < b.v;
  }
  bool operator>(const node b) const {
    return b < (*this);
  }
};

vector<ll> a, b, c;

node calc(int x, int y, int z)
{
  if (x < a.size() && y < b.size() && z < c.size()) {
    node n(x, y, z, a[x] + b[y] + c[z]);
    return n;
  }
  node n(x, y, z, 0);
  return n;
}

int main()
{
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  a.resize(x);
  b.resize(y);
  c.resize(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(all(a), greater<ll>());
  sort(all(b), greater<ll>());
  sort(all(c), greater<ll>());
  priority_queue<node> q;
  q.push(calc(0, 0, 0));
  set<pair<ll, pair<ll, ll>>> s;
  s.insert(make_pair(0, make_pair(0, 0)));
  while (1) {
    if (k == 0) break;
    auto a = q.top();
    q.pop();
    cout << a.v << endl;
    node t = calc(a.x+1, a.y, a.z);
    auto p = make_pair(a.x+1, make_pair(a.y, a.z));
    if (s.count(p) == 0) {
      q.push(t);
      s.insert(p);
    }
    t = calc(a.x, a.y+1, a.z);
    p = make_pair(a.x, make_pair(a.y+1, a.z));
    if (s.count(p) == 0) {
      q.push(t);
      s.insert(p);
    }
    t = calc(a.x, a.y, a.z+1);
    p = make_pair(a.x, make_pair(a.y, a.z+1));
    if (s.count(p) == 0) {
      q.push(t);
      s.insert(p);
    }    
    k--;
  }
}



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

const int N = 300000;
int p[N + 1];

int main(){
	int n;
	fill(p, p + N + 1, 0);
	for(int i = 0;i < N / 7;++i){
		p[7 * i + 1] = p[7 * i + 6] = 1;
	}
	p[1] = 0;
	for(int i = 0;i <= sqrt(N + 1);++i){
		if(p[7 * i + 1]){
			int inc = 7 * i + 1;
			for(int j = 2 * (7 * i + 1);j <= N;j += inc){
				p[j] = 0;
			}
		}
		if(p[7 * i + 6]){
			int inc = 7 * i + 6;
			for(int j = 2 * (7 * i + 6);j <= N;j += inc){
				p[j] = 0;
			}
		}
	}
	while(cin >> n, n != 1){
		int c = 0;
		cout << n << ":";
		for(int i = 6;i <= n / 6;++i){
			if(p[i] && n % i == 0){
				cout << " " << i;
				++c;
			}
		}
		if(!c) cout << " " << n;
		cout << endl;
	}
	return 0;
}

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

int k = 1;
vector<int> colors;

void dfs(const vector<vector<int>> &G, vector<bool> &seen, int v, int color, vector<pint> &ab)
{
    seen[v] = true;

    for (int line_id : G[v])
    {
        pint line = ab[line_id];
        int to = line.first;
        if (to == v)
            to = line.second;
        if (seen[to])
            continue;
        color = color % k + 1;
        colors[line_id] = color;
        dfs(G, seen, to, color, ab);
    }
}

int main()
{
    int n;
    cin >> n;

    vector<pint> ab(n - 1);
    vector<vector<int>> G(n + 1);

    rep(i, n - 1)
    {
        cin >> ab[i].first >> ab[i].second;

        G[ab[i].first].emplace_back(i);
        G[ab[i].second].emplace_back(i);
    }

    rep(i, n + 1) k = max(k, int(G[i].size()));

    colors.resize(n - 1);

    vector<bool> seen(n, false);
    dfs(G, seen, 1, 0, ab);

    cout << k << endl;
    rep(i, n - 1) cout << colors[i] << endl;
}

Measured memory_bytes: 11624
#include <stdio.h>
#include <string.h>
int main()
{
	int N, cnt = 0;
	char S[31000]={0};
	scanf("%d", &N); getchar();
	scanf("%s", S);
	int len = strlen(S);
	for(int i=0;i<=999;i++)
	{
		int a[3]={0};
		a[0]=i/100; a[1]=(i/10)%10; a[2]=i%10;
		int flag = 0, p = 0, num = 0;
		for(p=0;p<len;p++)     //在S中找 a[flag]
		{
			if(a[flag]==(S[p]-48))
			{
				num++; p++; break;
			}
		}
		flag = 1;
		for(;p<len;p++)
		{
			if(a[flag]==(S[p]-48))
			{
				num++; p++; break;
			}
		}
		flag = 2;
		for(;p<len;p++)
		{
			if(a[flag]==(S[p]-48))
			{
				num++; break;
			}
		}
		if(num==3) cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n, m;
  while (scanf("%d %d", &n, &m) != EOF)
  {
    int a[n], votes = 0;
    for (int i = 0; i < n; i++)
    {
      scanf("%d", &a[i]);
      votes += a[i];
    }
    int minimum = votes / (4 * m) + (votes % (4 * m) != 0);

    int valid = 0;
    for (int i = 0; i < n; i++)
      if (a[i] >= minimum)
        valid++;
    printf("%s\n", valid >= m ? "Yes" : "No");
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11; 
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
ll f[10001];
void solveforthiscase(const int & test)
{
cin>>n;
for(int i=1;i<=n;i++)
{
    for(int x=1;x*x<i;x++)
    {
        for(int y=1;y*y+x*x+x*y+x+y<=i;y++)
        {
            for(int z=1;z*z+y*y+x*x+z*x+z*y+x*y<=i;z++)
            {
                int calc=z*z+x*x+y*y+y*z+z*x+x*y;
                if(calc==i)
                f[i]++;
            }
        }
    }
cout<<f[i]<<'\n';
}
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t start, end;
    start = clock(); 
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    solveforthiscase(i);
    end = clock(); 
    long double t_t = (long double)(end - start) /(long double)(CLOCKS_PER_SEC); 
    cerr << (long double)t_t*1000<< " ms ";
}


Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s;
    int K;
    cin >> K;
    cin >> s;

    string res;

    size_t size = s.length();
    int len = size-K;
    if(len <= 0){
        cout << s << endl;
    }
    else{
        res = s.substr(0, K);

        res.push_back('.');
        res.push_back('.');
        res.push_back('.');
    
        cout << res << endl;
        
    }
    
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int64_t n;
	std::cin >> n;
	int64_t res = 1000000000000000000;
	for (int i = 1; (int64_t) i * i <= n; i++) {
		if (n % i) continue;
		res = std::min(res, i + n / i);
	}
	std::cout << res - 2 << std::endl;
	return 0;
}


Measured memory_bytes: 384
/*
    Problem 97
    https://atcoder.jp/contests/abc150/tasks/abc150_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* global variables */
/* function */
ll gcd(ll x, ll y) {
    ll tmp;
    while (y) {
        tmp = x;
        x = y;
        y = tmp % y;
    }
    return x;
}
/* main */
int main(){
    ll N, a;
    ll K;
    cin >> N >> K;
    set<ll> A;
    set<int> B;
    for (int i = 0; i < N; i++) {
        cin >> a;
        a /= 2;
        A.insert(a);
    }
    ll lcm = 1;
    for(auto a : A) lcm = lcm * a / gcd(a, lcm);
    for(auto a : A) {
    if((lcm / a) % 2) continue;
    cout << 0 << '\n';
    return 0;
    }
    int ans = (K / lcm + 1) / 2;
    cout << ans << '\n';
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    map<char, long long> m;
    int q;
    cin >> q;
    rep(i,q){
        int p, n;
        char c;
        cin >> p >> c >> n;

        m[c]+=n;

        if(m['('] == m[')']){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int H[505];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	int ret=0;
	FOR(i,N) {
		cin>>x;
		if(x>=K) ret++;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		double r = s.nextDouble();
		double pi = Math.PI;
		double area, circ;
		area = r * r * pi;
		circ = 2 * pi * r;
		System.out.printf("%f %f", area, circ);
	}
	public static void main(String[] args) {
		/* 
		 * Main x;
		 * x = new Main();
		 * x.run();
		 * ??¨????????????
		 */
		new Main().run();
		
	}
}

Measured memory_bytes: 28280
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  if(N==1){
    cout << "Hello World"<<endl;
  }else{
    int A,B;cin>>A>>B;
    cout << A+B<<endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

int n;
int k;
int r;
int s;
int p;
string a;
string b;

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k >> r >> s >> p;
	cin >> a;
	b = a;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (i >= k && a[i] == b[i - k]) {
			b[i] = '#';
			continue;
		}
		if (a[i] == 'r') {
			ans += p;
		} else if (a[i] == 's') {
			ans += r;
		} else {
			ans += s;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#define mod 998244353 
#define maxn 505
using namespace std;
int n, ans, x[maxn], y[maxn], pw[maxn];

int main(){
    scanf( "%d", &n );
    pw[0] = 1;
    for( int i = 1; i <= n; i ++ ) pw[i] = ( long long ) pw[i - 1] * 2 % mod;
    for( int i = 1; i <= n; i ++ ) scanf( "%d%d", &x[i], &y[i] );
    ans = ( pw[n] - n - 1 - n * ( n - 1 ) / 2 + mod ) % mod;
    for( int i = 1; i <= n; i ++ ) {
        for( int j = i + 1; j <= n; j ++ ) {
            int tmp = 0;
            for( int k = j + 1; k <= n; k ++ ) {
                if( ( y[j] - y[i] ) * ( x[k] - x[j] ) == ( y[k] - y[j] ) * ( x[j] - x[i] ) ) tmp ++;
            }
            ans = ( ans + mod + 1 - pw[tmp] ) % mod;
        }
    }
    printf( "%d", ans );
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = k; i < n; i++) {
        cout << (a[i] > a[i-k] ? "Yes" : "No") << endl;
    }
}


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


def solve(N: int, A: int, B: int):
    C = N //(A+B)
    MOD_REMAIN = N % (A+B)
    print(C*A + min(MOD_REMAIN,A))
    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
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-28 14:15:33
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int main()
{
    int h, n, x;
    cin >> h >> n;
    while(n--){
        cin >> x;
        h -= x;
    }if(h > 0)puts("No");else puts("Yes");
    
    system("pause");
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

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

const int mod = 2019;

int main(){
  int64_t l, r; cin >> l >> r;
  if (r - l + 1 >= mod){
    cout << 0 << endl;
    return 0;
  }
  int ans = mod;
  for (int64_t i = l; i < r; i++){
    for (int64_t j = i + 1; j <= r; j++){
      int r = i * j % mod;
      ans = min(r, ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, L = list(map(int, input().split(' ')))

#print(N, L)

before_apple_pie = N * L + N * (N - 1) / 2

#print(before_apple_pie)

apple = []
for i in range(N):
    apple.append(L + i)
#print(apple)

min = 1000
for i in range(N):
    if(min > abs(apple[i])):
        min = abs(apple[i])
        min_i = i

after_apple_pie = int(before_apple_pie - apple[min_i])

print(after_apple_pie)

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

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

inline void Main() {
  // code
  string s;
  cin>>s;
  sort(all(s));
  if(s[0]==s[1] && s[2]==s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <functional>
#include <iostream>
#define SIZE 10005
 
using namespace std;
typedef long long int ll;
// typedef pair <int,int> P;
 
int pair[SIZE];
 
int main()
{
	int n;
    int sum = 0;
    int count = 0;
    std::cin >> count;
    int value_x[count],value_y[count];
    for (int i = 0; i < count; i++)
    {
        std::cin >> value_x[i];
    }
    for (int i = 0; i < count; i++){
        std::cin >> value_y[i];
        if (value_x[i] > value_y[i])
            sum += value_x[i] - value_y[i];
    }
	std::cout << sum << std::endl;
	return 0;
}

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

int main(){
    int A, B, T;
    cin >> A >> B >> T;

    int ans = 0;
    int elaps = A;
    while(elaps < T + 0.5){
        ans += B;
        elaps += A;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long combi(int x,int r);

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    if(n<=1&&m<=1){
        printf("%d\n",0);
        return 0;
    }else if(n<=1&&m>1){
        printf("%ld\n",combi(m,2));
        return 0;
    }else if(n>1&&m<=1){
        printf("%ld\n",combi(n,2));
        return 0;
    }

    printf("%ld\n",combi(n,2)+combi(m,2));
    return 0;
}

long combi(int x,int r){
    if(r==0||x==r){
        return 1L;
    }else{
        return combi(x-1,r)+combi(x-1,r-1);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define GET_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(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<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;}

#define INF 1120000000
#define long long long // for codeforces

class UnionFind {
public:
  vector<int> par, rank;
  // if par is negative, it is a root, of which tree size is the abs-value.
  // rank represents depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;
    if(rank[x] < rank[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    if(rank[x]==rank[y]) rank[x]++;
  }
  inline bool same(int x, int y){ return find(x) == find(y); }
  inline int size(int x){ return -par[find(x)]; }
};

int main(){
  int n,q;
  cin>>n>>q;

  UnionFind uf(n);

  rep(i,q){
    int t,x,y;
    cin>>t>>x>>y;
    if(t==0) uf.unite(x,y);
    else cout << (uf.same(x,y)?1:0) << "\n";
  }

  return 0;
}

Measured memory_bytes: 3180
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
import itertools #list(accumulate(A))

S = sys.stdin.readline().rstrip()
S_int = list(map(int, list(S)))
N = len(S)

if N==1:
    print(S)
    exit()

cnt = 0
for l in list(itertools.product([0, 1], repeat=N-1)):
    tmp = S_int[0]
    for i, kigo in enumerate(l):
        if kigo == 1:
            cnt += tmp
            tmp = S_int[i+1]
        else:
            tmp = tmp * 10 + S_int[i+1]
    cnt += tmp

print(cnt)
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n, k, s;
    cin >> n >> k >> s;
    vector<int> ans(n);
    for (int i = 0; i < k; ++i) {
        ans[i] = s;
    }
    for (int i = k; i < n; ++i) {
        if(s != 1000000000) ans[i] = 1000000000;
        else ans[i] = 999999999;
    }
    for (int i = 0; i < n; ++i) {
        if(i) printf(" ");
        printf("%d", ans[i]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1664
N=int(input())
A=[[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
  i=str(i)
  ii=len(i)
  A[int(i[0])][int(i[ii-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=A[i][j]*A[j][i]
print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n,0);
    rep(i,n-1){
        int x;
        cin >> x;
        x--;
        a[x]++;
    }

    for(auto x:a) cout << x << endl;
}

Measured memory_bytes: 4048
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;*/

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int N = 2e5 + 10;
vector<int> g[N];
vector<bool> used(N);

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        g[i].pb(a);
	}
	vector<int> v;
	int now = 1;
	bool x = 0;
	while(k > 0){
        k--;
        used[now] = 1;
        v.pb(now);
        now = g[now][0];
        if (used[now] && !x){
            x = 1;
            int dl = 0;
            for (int i = v.size() - 1; i > -1; i--){
                if (v[i] == now){
                    dl = v.size() - i;
                    break;
                }
            }
            k %= dl;
        }
	}
	cout << now << endl;
	return 0;
}


Measured memory_bytes: 16240
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	int min_a = 9999, max_a = 0;
	REP(i, n)
	{
		int a;
		cin >> a;
		chmin(min_a, a);
		chmax(max_a, a);
	}
	print(max_a - min_a);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = 0

if A + B <= 2 * C:
    ans = A * X + B * Y
elif A + B >= 2 * C:
    ans += min(X, Y) * (2 * C)
    if X > Y:
        ans += min((X - Y) * A, (X - Y) * 2 * C)
    else:
        ans += min((Y - X) * B, (Y - X) * 2 * C)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
    Graph g(10005);
    lint num[10005];
    lint ans=0;
    void dfs(lint to, lint from=-1){
            for(lint u:g[to]){
                if(u==from)continue;
                ans+=min(num[to],num[u]);
              
                dfs(u,to);
            }
    }
  int main(){
     string s;
     cin>>s;
     if(regex_match(s,regex("(dream|dreamer|erase|eraser)*")))cout<<"YES";
     else cout<<"NO";
  }


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    Vec v(n);
    rep(i,n){
        cin>>v[i];
    }
    ll now = 1;
    ll ans=0;

    rep(i,n){
        if(v[i]==now){
            now++;
        }else{
            ans++;
        }
    }
    if(ans==n){
        ans = -1;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
ll const MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> tmp(n, 0);
  tmp[n-1] = a[n-1];
  for(ll i = n-2; i >= 1; i--) {
    tmp[i] = (tmp[i+1] + a[i]) % MOD;
  }

  ll ans = 0;
  rep(i, n-1) {
    ans =  (ans + ((a[i] * tmp[i+1]) % MOD)) % MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6424