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

int main(){

  int a,b;
  cin>>a>>b;

  string A,B;
  A=to_string(a);
  B=to_string(b);

  string ans[2]={""};
  for(int i=0;i<b;i++){
      ans[0]+=A;
  }
  for(int j=0;j<a;j++){
      ans[1]+=B;
  }

  sort(ans,ans+2);

  cout<<ans[0]<<endl;




return 0;
}

Measured memory_bytes: 256
c=[p]*gets.to_i
l=$<.map{|t|n,*a=t.split.map &:to_i;[n,a.select{|i|i>=0&&c[i]=[i,n]+(a-[i])}]}.sort
f=->n,d{c[n][3,0]=[l[n][1].size,d,h=(l[n][1].map{|i|f[i,d+1]}.max||-1)+1,d<1?:root:h<1?:leaf:"internal node"];h}
c[n=c.index(p)]=[n,-1,-1]
f[n,0]
puts c.map{|i|%w(node\ %d:\ parent sibling degree depth height %s)*" = %d, "%i}

Measured memory_bytes: 6132
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
int a[20][20]; 

int main(void){
    int n,m,ans=0,num=100;
    cin>>n;
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
            a[i][j]=-1;
        }
    }
    for(int i=1;i<=n;i++){
        cin>>m;
        for(int j=0;j<m;j++){
            int x,y;
            cin>>x>>y;
            a[i][x]=y;
        }
    }
    vector<int>b(n+1);
    for(int i=0;i<(1<<n);i++){
        num=0;
        for(int j=1;j<=n;j++){
            int digit=(i>>(j-1))&1;
            b[j]=digit;
            if(digit)num++;
        }
        bool flag=true;
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                if(a[j][k]!=-1){
                    if(b[j]){
                        if(b[k]!=a[j][k]){
                            flag=false;
                        }
                    }
                }
            }
        }
        if(flag)ans=max(ans,num);
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long int ll;


int main(){
    ll N,M;
    cin >> N>>M;
    vector<pair<ll,ll>> L(N);
    for(ll i = 0;i < N;i++){
        ll a,b;
        cin >> a >> b;
        L[i] = make_pair(a,b);
    }
    sort(L.begin(),L.end());
    ll ans = 0;
    ll memo = 0;
    ll cnt = 0;
    ll cnt1 = 0;
    for(ll i = 0; i < M;i++){
        if(L[memo].second > i - cnt1){
            ans += L[memo].first;
            cnt++;
        }else{
            memo++;
            cnt1 = cnt;
            i--;
        }
        
    }
    cout << ans << endl;
}



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

int main() {
    int n,len;
    cin>>n;
    string w,tail,head;
    set<string> st;
    rep(i,n) {
        cin>>w;
        st.insert(w);
        len=st.size();
        head=w[0];
        if (i==0) {
            tail=w.back();
            continue;
        }
        if (i+1!=len||head!=tail) {
            cout<<"No"<<endl;
            return 0;
        }
        tail=w.back();
    }
    cout<<"Yes"<<endl;
}   


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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int64_t a){if(a<=1)return false;for(int64_t i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }


int main()
{
	int n, ans = 0;

	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++)
		cin >> p[i];
	for (int i = 0; i < n; i++)
	{
		// cout << i << " ";
		if (p[i] == i + 1)
		{
			ans++;
			i++;
		}
	}
	// cout << endl;
	cout << ans << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;

VI dp(101010);
VVI adj(101010);

int f(int i) {
  if (dp[i]) return dp[i];
  VI t;
  for (auto&& j : adj[i]) {
    t.push_back(f(j));
  }
  sort(t.rbegin(), t.rend());
  for (int j = 0; j < t.size(); j++) {
    t[j] += j + 1;
  }
  return *max_element(t.begin(), t.end());
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  for (int i = 1; i < n; i++) {
    int a; cin >> a; a--;
    adj[a].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (adj[i].empty()) dp[i]++;
  }
  cout << f(0) - 1 << '\n';
  return 0;
}

Measured memory_bytes: 15488
fn dfs(s: String, maxc: u8, n: usize) {
    if s.len() == n {
        println!("{}", s);
    } else {
        for i in b'a'..maxc + 1 {
            let mut cs = s.clone();
            cs.push(i as char);
            if i == maxc {
                dfs(cs, maxc + 1, n);
            } else {
                dfs(cs, maxc, n);
            }
        }
    }
}

fn main() {
    let n: usize = read();
    dfs(String::new(), b'a', n);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 5500
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, r;
    cin >> n >> m >> r;
    Matrix<int> mat(n, vector<int>(n, INT32_MAX));
    rep (i, n) mat[i][i] = 0;
    vector<int> perm(r);
    rep (i, r) {
        cin >> perm[i];
        perm[i]--;
    }
    rep (i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        chmin(mat[a][b], c);
        chmin(mat[b][a], c);
    }   
    warshall_floyd(mat, INT32_MAX);
    sort(all(perm));
    int ans = INT32_MAX;
    do {
        int tmp = 0;
        rep (i, r - 1) {
            tmp += mat[perm[i]][perm[i+1]];
        }
        chmin(ans, tmp);
    } while (next_permutation(all(perm)));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define FW freopen("data2.txt", "w", stdout);
//快速读入输出，只适用于整数，使用时流同步打开，C语言不准关流
// getchar()<<cin(关流)<<scanf()<<cin
template <class T>
inline bool Read(T& ret)
{
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF)
        return 0;
    while (c != '-' && (c < '0' || c > '9'))
        c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
        ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
//输出只能用于整数
template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}

void slove(int question_num)
{
    int n;
    cin >> n;
    int flage = 0;
    int num = 0;
    int a[103] = { 0 }, b[103] = { 0 };
    for (int i = 1; i <= n; ++i)
        cin >> a[i] >> b[i];
    for (int i = 1; i <= n; ++i) {
        if (a[i] == b[i])
            num++;
        else
            num = 0;
        if (num == 3)
            flage = 1;
    }
    if (flage)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main()
{
    int num = 1;
    // cin >> num;
    for (int i = 1; i <= num; ++i) {
        slove(i);
    }
    // system("pause");
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    map<string,int> s;
    for(int i = 0; i < N; i++)
    {
        string stmp;
        cin >> stmp;
        s[stmp]++;
    }

    int M;
    cin >> M;
    
    for(int i = 0; i < M; i++)
    {
        string stmp;
        cin >> stmp;
        s[stmp]--;
    }

    int smax = 0;

    for(auto e:s)
    {
        if(e.second > smax)
        {
            smax = e.second;
        }
    }

    cout << smax << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            if (num.Equals(1))
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                Method();
            }
        }
        static void Method()
        {
            int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());

            Console.WriteLine(num1 + num2);
        }
    }
}


Measured memory_bytes: 11092
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();
        int d = sc.nextInt();
        int e = a + b;
        int f = c + d;
        String ans;
        if (e > f) {
            ans = "Left";
        } else if (e == f) {
            ans = "Balanced";
        } else {
            ans = "Right";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
import itertools
n,m=map(int,input().split())
path=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)

res = 0
for case in itertools.permutations(range(n)):
  if case[0] != 0:
    continue
  for i in range(n-1):
    if case[i+1] not in path[case[i]]:
      break
  else:
    res+=1
print(res)

Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;



				
int main() {
 	ios::sync_with_stdio(false);
  			cout.tie(nullptr);
  			cin.tie(nullptr);
        int a[200005];
        int b[200005];
        a[0]=0;
        b[0]=0;
  		int n,c;
      cin >> n;
      for(int i=1;i<n+1;i++){
        b[i]=0;
        cin >> a[i];
        c =a[i];
        b[c]++;
      }
      for(int i=1;i<n+1;i++){
        cout << b[i] << endl;
      }

}

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD2 1000000007
#define MOD 1000000009
#define endl "\n"
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vvi vector <vector<int>>
#define F first
#define S second




int main()
{   
    IOS;
        #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
        #endif
    
    int n;
    cin >> n;
    if(n == 0)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    
        

    
    
return 0;
}

Measured memory_bytes: 3604
'use strict'

const Main = (input) => {
  const N = parseInt(input.trim())

  let result = ':('

  for (let i = 1; i <= N; i++) {
    const tmp = Math.floor(i * 1.08)
    if (tmp === N) result = i
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
// DPL_5_C: Count the number of ways to put
// n distinguishable balls in
// k distinguishable boxes, s.t.
// each box receives at least one ball

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll S[1002][1002];
ll M = 1e9 + 7;

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

  S[0][0] = 1;
  // S(n,k)= S(n-1,k-1) + kS(n-1,k)
  for (int k = 1; k <= K; ++k)
    for (int n = 1; n <= N; ++n)
      S[n][k] = (S[n - 1][k - 1] + k * S[n - 1][k]) % M;

  ll F = 1;
  for (int i = 2; i <= K; ++i)
    F = (F * i) % M;

  cout << ((F * S[N][K]) % M) << endl;
}


Measured memory_bytes: 10920
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <malloc.h>

#define MAX 9999

int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);

void Move(int* x, int* y, int d, int n);
void Upper(int* x, int* y, int d);
void Lower(int* x, int* y, int d);
void Right(int* x, int* y, int d);
void Left(int* x, int* y, int d);




int main()
{
	
	int N = 0, T = 0;
	int c[100] = { MAX };
	int t[100] = { MAX };
	
	scanf("%d%d", &N, &T);
	
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &c[i], &t[i]);
	}

	for (int i = 0; i < N; i++) {
		if (t[i] > T) {
			c[i] = MAX;
		}
	}

	int ans = Min(c, N);

	if (ans == MAX) {
		printf("TLE");
		return 0;
	}

	printf("%d", ans);

	



	return 0;
}

void Move(int* x, int* y, int d, int n) {

}

void Upper(int* x, int* y, int d) {
	*y += d;
}
void Lower(int* x, int* y, int d) {
	*y -= d;
}
void Right(int* x, int* y, int d) {
	*x += d;
}
void Left(int* x, int* y, int d) {
	*x -= d;
}

int Pow(int n, int m) {
	int ret = 1;

	for (int i = 0; i < m; i++) {
		ret *= n;
	}

	return ret;
}

int Max(int N[], int n) {
	int max = N[0];

	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}

	return max;
}

int Min(int N[], int n) {
	int min = N[0];

	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}

	return min;
}

int Sum(int N[], int n) {
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += N[i];
	}

	return sum;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll H,W;
  cin>>H>>W;
  vector<char> vec(H*W);//vecは各頂点の白か黒かを保持
  vector<ll> answer(H*W+1,H+W);//各黒点からの距離のうち小さいものを保持(随時更新)
  for(ll i=0;i<H*W;i++){
    cin>>vec.at(i);
  }
  using Graph=vector<vector<ll>>;
  Graph G(H*W+1);//グラフのサイズはマス目のサイズ+最初の仮想の点分の1
  for (ll i=0;i<H*W;++i){//グラフの作成
    if(vec.at(i)=='#'){//仮想の点からの辺を定義
      G[H*W].push_back(i);
    }
    if(i%W!=W-1){//左右方向の辺の定義
      G[i].push_back(i+1);
      G[i+1].push_back(i);
    }
    if(i<W*(H-1)){//上下方向の辺の定義
      G[i].push_back(i+W);
      G[i+W].push_back(i);
    }
  }
  vector<ll> dist(H*W+1,-2);//全頂点を「未訪問」に初期化(-2だったら未訪問と判断)
  queue<ll> que;
  dist[H*W]=-1;//仮想の点をスタートにする
  que.push(H*W);
  while(!que.empty()){
    ll v=que.front();//キューから先頭頂点を取り出す
    que.pop();
    for(ll nv:G[v]){//vから辿れる頂点をすべて調べる
      if(dist[nv]!=-2){continue;}//すでに発見済みの頂点は探索しない
      dist[nv]=dist[v]+1;//新たな白色頂点nv について距離情報distを更新してキューに追加する
      answer.at(nv)=min(answer.at(nv),dist[nv]);//各黒点からの距離の最小値を必要に応じて更新
      que.push(nv);
    }
  }
  ll rock=0;//rockは各白点の(各黒点からの距離の最小値の)最大値を保持(随時更新)
  for(ll i=0;i<H*W;i++){
    if(vec.at(i)=='.'){rock=max(answer.at(i),rock);}
  }
  cout<<rock<<endl;
}

Measured memory_bytes: 103400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int num[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  --k;
  cout << num[k] << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for a, b in AB:
    graph[a - 1].append(b)
    graph[b - 1].append(a)
    
queue = deque()
visited = [0] * N
sign_list = [0] * N 

queue.append(1)
visited[0] = 1

while queue:
    room = queue.popleft()
    next_rooms = graph[room - 1]
    for r in next_rooms:
        if visited[r - 1] == 0:
            queue.append(r)
            sign_list[r - 1] = room
            visited[r - 1] = 1

yes = True
for s in sign_list[1:]:
    if s == 0:
        yes = False

if yes:
    print("Yes")
    for s in sign_list[1:]:
        print(s)
else:
    print("No")

Measured memory_bytes: 59576
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main(){
	int N, M, Q;
	while(cin >> N >> M >> Q){
		vector<string> board(N);
		for(auto& s : board) cin >> s;
		vector<vector<int>> grid(N+1, vector<int>(M+1, 0));
		vector<vector<int>> hori(N+1, vector<int>(M+1, 0));
		vector<vector<int>> vert(N+1, vector<int>(M+1, 0));

		auto makeSum = [&](vector<vector<int>>& v, auto f){
			for(int i=1;i<=N;i++){
				for(int j=1;j<=M;j++){
					if(f(i-1, j-1)) v[i][j] = 1;
					v[i][j] += v[i-1][j];
					v[i][j] += v[i][j-1];
					v[i][j] -= v[i-1][j-1];
				}
			}
		};
		auto getSum = [&](const vector<vector<int>>& v, int x1, int y1, int x2, int y2){
			return v[x2][y2] - v[x1-1][y2] - v[x2][y1-1] + v[x1-1][y1-1];
		};
		makeSum(grid, [&](int x, int y){ return board[x][y] == '1'; });
		makeSum(hori, [&](int x, int y){ return x > 0 && board[x-1][y] == '1' && board[x][y] == '1'; });
		makeSum(vert, [&](int x, int y){ return y > 0 && board[x][y-1] == '1' && board[x][y] == '1'; });

		for(int i=0;i<Q;i++){
			int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
			cout << getSum(grid, x1, y1, x2, y2) - getSum(hori, x1+1, y1, x2, y2) - getSum(vert, x1, y1+1, x2, y2) << endl;
		}
	}
}


Measured memory_bytes: 54272
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
int a[N];

int main() {
  int n;
  scanf("%d", &n);
  int64 sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  int64 x = a[0];
  int64 ret = abs(sum - x - x);
  for (int i = 1; i < n - 1; ++i) {
    x += a[i];
    ret = min(ret, abs(sum - x - x));
  }
  printf("%lld\n", ret);

  return 0;
}


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

int main (){
    vector<int> Vec(3);
    for (int i; i<3;i++){
        cin>>Vec.at(i);
    }
    sort(Vec.begin(), Vec.end());
    if(Vec.at(0)==5&&Vec.at(1)==5&&Vec.at(2)==7){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
cmin = lambda a,b : a if a<b else b
cmax = lambda a,b : a if a>b else b
iin = lambda : int(input())
lin = lambda : list(map(int,input().split()))
rin = lambda n : [int(input()) for _ in range(n)]

s = set(input())

print("No" if len(s)==1 else "Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdint>
#include <string>
#include <cstdlib>

int main() {
  std::string s;
  std::cin >> s;
  for (std::int_fast64_t n = s.size() / 2 - 1; n > 0; --n) {
    if (s.substr(0, n) == s.substr(n, n)) {
      std::cout << 2 * n << std::endl;
      return 0;
    }
  }
  return EXIT_FAILURE;
}

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

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

    int sum = 0;
    int number = N;
    while (true) {
        sum += number % 10;
        number /= 10;
        if (number == 0) break;
    }

    string ans = (N % sum == 0) ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC148D()
{
	int N;
	cin >> N;
	vi ai(N);
	for (auto& x : ai)
	{
		cin >> x;
	}

	int j = 1;
	int b = 0;
	for (int i = 0; i < N; ++i)
	{
		if (ai[i] == j)
		{
			++j;
		}
		else
		{
			++b;
		}
	}
	if (b < N)
	{
		cout << b << endl;
	}
	else
	{
		cout << "-1" << endl;
	}
}
int main()
{
	ABC148D();
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[200010],finv[200010],inv[200010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,200010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll n;cin>>n;
    if(n<3){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    ll k=n;
    ll x=2;
    while(k){
        if(k&1)ans=ans*x%inf;
        k>>=1;
        x=x*x%inf;
    }
    //cout<<ans<<endl;
    ans--;
    ans%=inf;
    combinit();
    ll a,b;cin>>a>>b;
    ll ma=1,mb=1;
    rep(i,a){
        ma=ma*(n-i)%inf;
    }
    //cout<<ma<<endl;
    rep(i,b){
        mb=mb*(n-i)%inf;
    }
    //cout<<mb<<endl;
    ma=ma*finv[a]%inf;
    mb=mb*finv[b]%inf;
    ans=(ans-(ma+mb)%inf)%inf;
    if(ans<0)ans+=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
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;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int> v(N);
  rep(i,N){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  int ans=0;
  rep(i,N-2){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(abs(v[i]-v[j])<v[k]&&v[k]<v[i]+v[j]){
          ans++;
        }
        else
          break;
      }
    }
  }
  cout << ans << endl;        
}

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

int main() {
    int N;
    cin >> N;
    vector<char> S(N);
    for (int i = 0; i < N; i++){
        cin >> S[i];
    }
    int count = 0;
    for (int i = 0; i < N; i++){
        if (S[i] == 'Y') count++;
    }

    if (count > 0) cout << "Four" << endl;
    if (count == 0) cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>

using namespace std;

int main() {
    char buf[131072];
    scanf("%s", buf);
    string s(buf);
    size_t ub=s.length();
    s += '$';

    for (size_t i=0; i<ub; ++i)
        for (size_t j=1; j<=2; ++j)
            if (s[i] == s[i+j]) {
                printf("%llu %llu\n", i+1, i+j+1);
                return 0;
            }

    printf("-1 -1\n");
    return 0;
}


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

int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	if(a + b < c) puts("No");
	else puts("Yes");
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main()
{
	// freopen("CF17-QA-D.in", "r", stdin); 
	int n, m, d; 
	scanf("%d%d%d", &n, &m, &d); 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			putchar("RYGB"[((i + j) / d & 1) << 1 | ((i + m - j) / d & 1)]); 
		puts(""); 
	}
	return 0; 
}


Measured memory_bytes: 384
N = int(input())
C0, C1, C2, C3 = 0, 0, 0, 0
for i in range(N):
    Si = input()
    if Si == 'AC':
        C0 += 1

    elif Si == 'WA':
        C1  += 1

    elif Si == 'TLE':
        C2 += 1

    else:
        C3 += 1

print('AC x ' + str(C0))
print('WA x ' + str(C1))
print('TLE x ' + str(C2))
print('RE x ' + str(C3))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 998244353
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;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}



int main() {
    ll n;
    cin >> n;
    ll c[4];
    fill(c,c+4,0);
    for (ll i=0;i<n;i++){
        string s;
        cin >> s;
        if (s=="AC")c[0]=c[0]+1;
        else if (s=="WA")c[1]=c[1]+1;
        else if (s=="TLE")c[2]=c[2]+1;
        else if (s=="RE")c[3]=c[3]+1;
    }
    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;
    return 0;
}

Measured memory_bytes: 3596
input_line=input().rstrip().split(" ")
num=int(input_line[0])
limt=int(input_line[1])

hight_line=input().rstrip().split(" ")
s=0
for i in range(num):
    hight = int(hight_line[i])
    if(hight>=limt):
        s+=1
print(s)

Measured memory_bytes: 9988
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    
    String o=sc.next();
    String e=sc.next();
    char oo[]=new char[o.length()];
    char ee[]=new char[e.length()];
    for(int i=0;i<o.length();i++){
      oo[i]=o.charAt(i);
    }
    for(int i=0;i<e.length();i++){
      ee[i]=e.charAt(i);
    }
    for(int i=0;i<e.length();i++){
      System.out.print(oo[i]+""+ee[i]);
    }
    if(o.length()!=e.length()){
      System.out.print(oo[o.length()-1]);
    }
    System.out.println("");
    sc.close();
  }
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
int main()
{
  string s;
  cin >> s;
  if (s == "ABC")
  {
    cout << "ARC" << endl;
  }
  else
  {
    cout << "ABC" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int x = Math.max(a,b);
int y = Math.min(a,b);
int out = helper(x,y);
System.out.println(out);
}

public static int helper(int x, int y){
if(y == 0){
return x;
} else if(x >= y){
return helper(y, x%y);
} else {
return 1;
}
}

}


Measured memory_bytes: 26212
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
	
		int[] arr = new int[n+1];
		
		for(int i=0; i<m; i++){
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			
			arr[c1]++;
			arr[c2]++;
		}
		
		for(int i=1; i<n+1; i++){
			System.out.println(arr[i]);
		}
	}
}

Measured memory_bytes: 23764
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
void call(int n) {
	int i = 1;
CHECK_NUM:
	int x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
INCLUDE3:
	if (x % 10 == 3) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
	x /= 10;
	if (x) goto INCLUDE3;
END_CHECK_NUM:
	if (++i <= n) goto CHECK_NUM;

	cout << endl;
}
void solv() {

	int n;
	cin >> n;
	int ta[5][4][11];
	memset(ta, 0, sizeof(ta));
	for (size_t i = 0; i < n; i++)
	{
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		ta[b][f][r] += v;
	}

	for (size_t i = 1; i <= 4; i++)
	{
		for (size_t j = 1; j <= 3; j++)
		{
			for (size_t kj = 1; kj <= 10; kj++)
			{
				cout << " ";
				cout << ta[i][j][kj];
			}
			cout << endl;
		}
		if(i < 4)
			cout << "####################" << endl;
	}
}

int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 3108
import sys

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

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

inf=10**18

import bisect

def main():
	a,b,q=map(int,input().split())
	s=[-inf]+[int(input()) for _ in range(a)]+[inf]
	t=[-inf]+[int(input()) for _ in range(b)]+[inf]
	x=[int(input()) for _ in range(q)]
	
	
	for i in x:
		si=bisect.bisect_left(s,i)
		ti=bisect.bisect_left(t,i)
		
		ans=inf
		for S in [s[si-1],s[si]]:
			for T in [t[ti-1],t[ti]]:
				ans=min(ans,abs(S-i)+abs(S-T),abs(T-i)+abs(S-T))
		print(ans)
		
		
		
	

if __name__ == "__main__":
	main()


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

    vector<int> A(N);

    rep(i, N)
    {
        A[i] = 0;
    }

    rep(i, N)
    {
        int a;
        cin >> a;
        A[a - 1]++;
    }

    sort(A.begin(), A.end());

    int ans = 0;
    rep(i, N - K)
    {
        ans += A[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var C = Read().ToCharArray();

            WriteLine((char)(C[0]+1));
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    cout << a[n - 1] - a[0] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n, m;
int cc;
int a[12000];

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> a[i];
		if (a[i] % 2 == 1)
			++cc;
	}
	if (cc >= 3) {
		cout << "Impossible\n";
		return 0;
	}
	cc = 0;
	for (int i = 0; i < m; ++i) {
		if (a[i] % 2 == 1) {
			++cc;
			if (cc == 1)
				swap(a[0], a[i]);
			else if (cc == 2)
				swap(a[i], a[m - 1]);
		}
	}
	for (int i = 0; i < m; ++i)
		cout << a[i] << " ";
	cout << "\n";
	vector<int> vv;
	if (a[0] != 1)
		vv.push_back(a[0] - 1);
	for (int i = 1; i < m - 1; ++i) {
		vv.push_back(a[i]);
	}
	if (m == 1) {
		vv.push_back(1);
	}
	else if (a[m - 1] % 2 == 1) {
		vv.push_back(a[m - 1] + 1);
	}
	else {
		vv.push_back(a[m - 1]);
		vv.push_back(1);
	}
	cout << vv.size() << "\n";
	for (int i: vv)
		cout << i << " ";
	cout << "\n";
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define v vector<ll>
#define st stack<ll>
#define pq  priority_queue <int>
#define q queue<ll>
#define mod 1000000005
using namespace std;
 char ch[1000000];
int main(){
    int n;
    cin>>n;
    int ans=n+(n*n)+(n*n*n);
    cout<<ans<<endl;
   }

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll ans=1000;
    for(int i=1;i<n;i++){
        if(a[i-1]<a[i]){
            ll tmp=ans/a[i-1];
            ans+=tmp*(a[i]-a[i-1]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
#define MAX 51
#define INF 1000000

typedef pair<int, int> P;

int h, w;
string s[MAX];
int d[MAX][MAX];

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

void bfs() {
  queue<P> que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d[i][j] = INF;
    }
  }
  que.push(P(0, 0));
  d[0][0] = 0;

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' && d[nx][ny] == INF) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
}

int count_black() {
  int count = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') count++;
    }
  }
  return count;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  bfs();
  if (d[h - 1][w - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  int keiro = d[h - 1][w - 1];
  int count[h * w + 1];
  fill(count, count + h * w + 1, 0);
  int count_inf = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (d[i][j] == INF) {
        count_inf++;
      } else {
        count[d[i][j]]++;
      }
    }
  }
  int black = count_black();
  int ans = 0;
  ans += count_inf - black;
  for (int i = 1; i <= h * w; i++) {
    if (i > d[h - 1][w - 1]) {
      ans += count[i];
    } else {
      ans += count[i] - 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

constexpr int MAX_A = 1e9;

ll f(int N, const vi &A)
{
    vector<ll> node_count_min(N+1), node_count_max(N+1);
    node_count_min[N] = node_count_max[N] = A[N];

    for (int d = N - 1; d >= 0; --d)
    {
        node_count_min[d] = max<ll>(1, node_count_min[d+1] / 2) + A[d];
        node_count_max[d] = node_count_max[d+1] + A[d];
    }

    ll node_count = 1, node_count_sum = 0;
    for (int d = 0; d <= N; ++d)
    {
        if (d > 0) node_count *= 2;
        
        if (node_count < node_count_min[d]) return -1;

        node_count = min(node_count, node_count_max[d]);
        node_count_sum += node_count;
        node_count -= A[d];
    }
    return node_count_sum;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 0; i <= N; i++)
        cin >> A[i];

    ll ans = f(N, A);
    cout << ans << endl;
}

Measured memory_bytes: 5108
N, X = map(int, input().split())
X_list = list(map(int, input().split()))
X_list.append(X)
X_list.sort()
kyori_list = []
for i, x in enumerate(X_list):
    if i == len(X_list) - 1:
        break
    kyori_list.append(X_list[i + 1] - x)

import fractions
from functools import reduce


def gcd_list(*numbers):
    return reduce(fractions.gcd, numbers)


print(gcd_list(*kyori_list))

Measured memory_bytes: 15376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int n, q;
    cin >> n;
    vector<int> S(n);
    rep(i, n) cin >> S[i];
    cin >> q;
    vector<int> T(q);
    rep(i, q) cin >> T[i];
    sort(ALL(S));
    sort(ALL(T));
    S.push_back(1e9 + 1);
    int idx = 0;
    int ans = 0;
    for (int i : T) {
        while (i >= S[idx + 1]) idx += 1;
        if (i == S[idx]) ans += 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define PII pair<int,int>
#define Tcase int t;cin>>t;while(t--)   
int main(){
  int h,w,n;
  cin>>h>>w>>n;
  int use=max(h,w);
  if(n%use!=0)
    cout<<(n/use)+1<<endl;
  else
    cout<<n/use<<endl;
return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	char buf[101];
	int length,count = 0;
	bool FLG;

	while(scanf("%s",buf)!=EOF){
		length = 0;
		for(int i=0; buf[i] != '\0';i++)length++;
		if(length == 1){
			count++;
			continue;
		}

		FLG = true;
		for(int i = 0; i < length/2; i++){
			if(buf[i] != buf[length-1-i]){
				FLG = false;
				break;
			}
		}
		if(FLG)count++;
	}

	printf("%d\n",count);

    return 0;
}



Measured memory_bytes: 2544