akhauriyash/Code-Regression huggingface dataset:
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;

typedef complex<int> P;

int b[19][19];

int main(){
	
	string s;
	cin>>s;
	int sum=0;
	int sakujo=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='S')
			sum++;
		else if(s[i]=='T'&&sum>0){
			sum--;
			sakujo+=2;
		}
	}
	
	cout<<s.size()-sakujo<<endl;
	
}

Measured memory_bytes: 640
#include"iostream"
#include"cmath"
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int st=max(a,c),en=min(b,d);
if(st<=en)
{
	cout<<en-st<<'\n';
}
else cout<<"0\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
long sort(long *a,long *b);
int main(void){
int n;
  scanf("%d",&n);
  long x[n][2];
  for(int i=0;i<n;i++){
    scanf("%ld %ld",&x[i][0],&x[i][1]);
  }
  
  long xl[n][2];
  for(int i=0;i<n;i++){
    xl[i][1]=x[i][0]-x[i][1];		//左腕の座標
    xl[i][0]=x[i][0]+x[i][1];     //右腕の座標
  }
  
  qsort(xl,n,sizeof(long)*2,sort);
 /* for(int i=0;i<n;i++){
    printf("%ld %ld\n",xl[i][0],xl[i][1]);
  }
/*  

  
  for(int i=0;i<n-1;i++){
	if(xl[i+1][0]<xl[i][1]&&!flag[i+1]){ans--;
    flag[i]=1;
  }*/
  //printf("%d",ans);
  int ans=1;
  int point=xl[0][0];
  for(int i=1;i<n;i++){
	if(xl[i][1]>=point){
	ans++;
      point=xl[i][0];
    }
  }
  printf("%d",ans);
  return 0;
}
  	/*int flag[n];						//1:排除,0:残留
  for(int i=0;i<n;i++){					//flagの初期化
	flag[i]=0;
  }
  int ans=n;
  
  for(int i=1;i<n;i++){//printf("%d個目のロボット------",i+1);		//注目ロボット
    for(int j=0;j<n;j++){		//11							//比較ロボット
      if(flag[i])break;
if(i==j)continue;						//自分と自分以外のロボットを比較
      if(i<j){  //33
      if(xl[i][0]>xl[j][1]&&!flag[j]){		//22
		ans--;
        //printf("腕がぶつかります\n");
        flag[i]=1;
      }//22
      }//33
      else{
        if(xl[i][1]<xl[j][0]&&!flag[j]){
          ans--;
         // printf("腕がぶつかります\n");
        flag[i]=1;
        }
      }
    }//111
  }//000
  printf("%d",ans);
  return 0;
}*/
  
  
  long sort(long *a,long *b){
return *a-*b;
  }

Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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 Graph = vector<vector<int>>;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  int d=(a-b+1)*(a-c+1);
  cout<<d<<endl;
}

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

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long dp[60005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, t; cin >> n >> t;
    long long a, b;
    vector<pair<int, int>> items;
    for(int i = 0; i < n; ++i){
        cin >> b >> a;
        items.push_back(make_pair(b, a));
    }

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

    for(auto i : items){
        a = i.second;
        b = i.first;
        for(int ti = t + b - 1; ti >= b; --ti)
            dp[ti] = max(dp[ti], dp[ti - b] + a);
    }

    b = 0;
    for(int i = 0; i <= 60004; ++i)
        b = max(b, dp[i]);

    cout << b;

    return 0;

}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main(void){
    int n, l;
    string s[105];
    cin >> n >> l;
    for (int i = 0; i < n; i++) cin >> s[i];
    
    sort(s, s + n);
    
    for (int i = 0; i < n; i++) cout << s[i];
  cout << endl;
}

Measured memory_bytes: 256
from logging import getLogger, basicConfig, DEBUG
basicConfig(level=DEBUG)
LOG = getLogger(__name__)

N = int(input())

def get_count_logical_and(base_int, list):
    result = []
    for item in list:
        logical_and = format(base_int & item, 'b').zfill(10)
        count = logical_and.count("1")
        result.append(count)
        # LOG.debug("{0} and {1} -> {2}".format(
        #     format(base_int, 'b').zfill(10), 
        #     format(item, 'b').zfill(10), 
        #     count))
    return result

def get_profits(pattern_array, lists):
    profits = 0
    for i in range(N):
        index = pattern_array[i]
        profit_list = lists[i]
        profits += profit_list[index]
        # LOG.debug("{0} : profits -> {1}".format(index, profits))
    return profits

def main():
    business_list = [int(input().replace(' ', ''), 2) for _ in range(N)]
    profits = [list(map(int, input().split())) for _ in range(N)]
    result = -float('inf')
    for i in range(1, 2 ** 10):
        open_pattern = get_count_logical_and(i, business_list)
        result = max(result, get_profits(open_pattern, profits))
        # LOG.debug("result -> {0}".format(result))
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4964
import std.stdio;
import std.string;
import std.array;

string card, next, tmp, s;
string[] queue;
int pos;
int[string] memo;
int[4] d = [-1, 1, 4, -4];


void main(){
	card = "01234567";
	queue ~= card;
	memo[card] = 0;
	solve();
	while (s = chomp(readln()), s) {
		s = replace(s, " ", "");
		writeln(memo[s]);
	}
}

void solve(){
	while (queue.length) {
		card = queue.front;
		queue.popFront();
		for (int i = 0; i < d.length; i++) {
			pos = position() + d[i];
			if (pos < 8 && pos >= 0 && !(pos == 4 && d[i] == 1) && !(pos == 3 && d[i] == -1)){
				tmp = card[pos..pos+1];
				next = replace(replace(replace(card, "0", "z"), tmp, "0") , "z", tmp);
				if(!(next in memo)){
					queue ~= next;
					memo[next] =  memo[card] + 1;
				}
			}
		}
	}
}

int position(){
	foreach (i;0..8) if (card[i] == '0') return i;
	return -1;
}

Measured memory_bytes: 4468
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            int iN = int.Parse(sS);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            List<int> lstMlt2 = new List<int>() { 64, 32, 16, 8, 4, 2, 1};
            // 1 は 2で割ると0で余り1で割り切れない。
            // なのに1の解答が1なのは問題の意図に反する
      		for (int i = 0; i < lstMlt2.Count; i++)
            {
                if (lstMlt2[i] <= iN) { iOut = lstMlt2[i]; break; }
            }

            //出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
/*
 *  Author  : StelaYuri
 * Language : GNU G++ 14
 */

//#pragma comment(linker,"/STACK:1024000000,1024000000")
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
//#include<unordered_map>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define perr(i,a,b) for(int i=a;i>b;i--)
#define pb push_back
#define eb emplace_back
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-12;
const double PI=acos(-1.0);
const double angcst=PI/180.0;
const ll mod=998244353;
ll max_3(ll a,ll b,ll c){if(a>b&&a>c)return a;if(b>c)return b;return c;}
ll min_3(ll a,ll b,ll c){if(a<b&&a<c)return a;if(b<c)return b;return c;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qmul(ll a,ll b){ll r=0;while(b){if(b&1)r=(r+a)%mod;b>>=1;a=(a+a)%mod;}return r;}
ll qpow(ll a,ll n){ll r=1;while(n){if(n&1)r=(r*a)%mod;n>>=1;a=(a*a)%mod;}return r;}
ll qpow(ll a,ll n,ll p){ll r=1;while(n){if(n&1)r=(r*a)%p;n>>=1;a=(a*a)%p;}return r;}



void solve()
{
    int n,m,c=0;
    cin>>n>>m;
    rep(i,1,n)
    {
        int a,b;
        cin>>a>>b;
        a=abs(a);
        b=abs(b);
        if(hypot(a,b)<=m)
            c++;
    }
    cout<<c<<'\n';
}
int main()
{
    closeSync;
    //multiCase
    {
        solve();
    }
    return 0;
}


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

struct edge {
  edge () {}
  edge (int to, int cost) : to(to), cost(cost) {}

  int to, cost;
};

bool bellman_ford(int s, const vector<vector<edge>> &G, vector<long long> &d) {
  const long long linf = 1001001001001001001ll;
  d = vector<long long>(G.size(), linf);
  d[s] = 0;
  bool f = false;

  for (int i = 0; i < G.size(); ++i) {
    for (int v = 0; v < G.size(); ++v) {
      for (auto &e : G[v]) {
        if (d[v] != linf && d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          if (i == G.size() - 1) f = true;
        }
      }
    }
  }

  return f;
}

int main() {
  int v, e, r;
  cin >> v >> e >> r;

  vector<vector<edge>> G(v);
  for (int i = 0; i < e; ++i) {
    int a, b, c;
    cin >> a >> b >> c;

    G[a].push_back(edge(b, c));
  }

  vector<long long> d;
  if (bellman_ford(r, G, d)) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < v; ++i) {
      if (d[i] == 1001001001001001001ll) cout << "INF" << endl;
      else cout << d[i] << endl;
    }
  }
}

Measured memory_bytes: 3144
s = list( map( int, input() ) )

n1 = s[0]*10 + s[1]
n2 = s[2]*10 + s[3]

if n1 > 0 and n1 <=12:
    if n2 > 0 and n2 <= 12:
        ans = 'AMBIGUOUS'
    else:
        ans = 'MMYY'
else:
    if n2 > 0 and n2 <= 12:
        ans = 'YYMM'
    else:
        ans = 'NA'

print(ans)

Measured memory_bytes: 38256
//Carden Lantern
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef int Weight;
struct Edge{
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight){}
};
bool operator<(const Edge &e, const Edge &f){
  return e.weight!=f.weight ? e.weight>f.weight : e.src!=f.src ? e.src<f.src : e.dst<f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

pair<Weight, Edges> minimumSpanningTree(const Graph &g, int r=0){
  int n=g.size();
  Edges T;
  Weight total=0;

  vector<bool>visited(n);
  priority_queue<Edge> Q;
  Q.push(Edge(-1, r, 0));
  while(!Q.empty()){
    Edge e=Q.top(); Q.pop();
    if(visited[e.dst])continue;
    T.push_back(e);
    total+=e.weight;
    visited[e.dst]=true;
    FOR(f, g[e.dst]) if(!visited[f->dst])Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}

int main(){
  int n, m;
  while(true){
    cin>>n;
    if(n==0)break;
    cin>>m;
    Graph g(n);
    REP(i,m){
      int src, dst, weight;
      scanf("%d,%d,%d", &src, &dst, &weight);
      g[src].push_back(Edge(src, dst, weight/100-1));
      g[dst].push_back(Edge(dst, src, weight/100-1));
    }
    cout<<minimumSpanningTree(g).first<<endl;
  }
  return 0;
}

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

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

using namespace std;

int main(){
  int n,h,w;cin>>n>>h>>w;

  cout<<(n-h+1)*(n-w+1);
  return 0;
}

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

long long n;
vector<long long> a, s;
map<long long, long long> mp;

bool solve();

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  for(int i = 0; i < n; ++i) ++mp[a[i]];
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  if(mp.size() == 1 && a[0] == 0) return 1;
  if(mp.size() == 2) {
    if(n % 3 == 0 && a[0] == 0 && mp[a[0]] == n / 3)
      return 1;
    else
      return 0;
  }
  if(mp.size() != 3) return 0;
  if((a[0] ^ a[1] ^ a[2]) != 0) return 0;
  if(n % 3 == 0 && mp[a[0]] == n / 3 && mp[a[1]] == n / 3 &&
     mp[a[2]] == n / 3)
    return 1;
  return 0;
}


Measured memory_bytes: 5632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        String [] S = new String [N];
        for(int i=0; i<N; i++){
            S[i] = sc.next();
        }
        Arrays.sort(S);
        String ans="";
        for(int i=0; i<N; i++){
            ans=ans+S[i];
        }
        System.out.println(ans);
    }
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine().Trim();
            int n = int.Parse(a);

            int d = n / 2;
            int i = n % 2;

            Console.Write(((double)d + i) / n);

        }
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> vp;        // Vector of pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define MOD (ll) (1e9 + 7)

int main(void)
{
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    ll prev[k + 1], next[k + 1];
    memset(prev, 0, sizeof(prev));

    for (int i = 0; i < n; i++)
        cin >> arr[i];
    
    prev[k] = 1;

    for (int i = n - 1; i >= 0; i--)
    {
        ll ans = 0;
        queue <ll> q;
        for (int j = k; j >= 0; j--)
        {
            q.push(prev[j] % MOD);

            if (q.size() == arr[i] + 2)
                ans = ((ans % MOD) + ((q.back() - q.front() + MOD) % MOD)) % MOD, q.pop();
            else
                ans = ((ans % MOD) + (q.back() % MOD)) % MOD;

            next[j] = ans % MOD;
        }

        for (int i = 0; i <= k; i++)
            prev[i] = next[i];    
    }
    
    cout << next[0] << "\n";
}

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

int main(){
  string s;
  cin >> s;
  vector<char> a(1000);
  int acnt = 0;
  for(int i=0;i<s.size();i++){
    if(s.at(i) == 'B'){
      if(acnt != 0){
        acnt--;
      }
    }else{
      a.at(acnt) = s.at(i);
      acnt++;
    }
  }
  for(int i=0;i<acnt;i++){
    cout << a.at(i);
  }
}
    
    

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> vec(n);
    for (auto &num : vec) {
        cin >> num;
    }

    int best_sum = 0;
    int curr_sum = 0;

    for (int i = 0; i < n; i += 1) {
        curr_sum += vec[i];
        if (i + 1 >= k) {
            best_sum = max(best_sum, curr_sum);
            curr_sum -= vec[i - k + 1];
        }
    }

    cout << fixed << setprecision(12) << (1.0 * best_sum + k) / 2 << "\n";
    return 0;
}


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

using namespace std;

uint64_t solve() {
  uint64_t N;
  cin >> N;
  if (N % 2 == 1) return 0;
  uint64_t cnt = 0;
  for (uint64_t base = 10; base <= N; base *= 5) {
    cnt += N / base;
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << solve() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<cstring>

using namespace std;
int main (){
int n;
string word;
string  str1= "Sunny";
string  str2=  "Cloudy";
string  str3=  "Rainy";
    cin >> word;

    if( word=="Sunny"){
        cout<< str2 << endl;

    }
    else if (word == "Cloudy") {
        cout<< str3 << endl;

    }
    else{
        if (word=="Rainy"){
        cout<< str1 << endl;

    }
    }




return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mk make_pair

int main()
{
	ll a;
	cin>>a;
	ll b,c;
	cin>>b>>c;
	ll m=b/a,n=c/a;
	if(abs(m-n)>=1)
	cout<<"OK"<<endl;
	else if(abs(m-n)==0&&(b%a==0||c%a==0))
	cout<<"OK"<<endl;
	else
	cout<<"NG"<<endl;
}


Measured memory_bytes: 3624
n = int(input())
a = list(map(int, input().split()))

res = [0] * n
for i in range(n-1, -1, -1):
    res[i] = (a[i] + sum(res[2*i+1:n:i+1])) % 2

print(res.count(1))
for i in range(n):
    if res[i] == 1:
        print(i+1, end=' ')

Measured memory_bytes: 70492
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int test[51];
signed main() {
    int n;
    while (cin >> n) {
        int a = 0;
        if (n >= 512) { test[a] = 512; a++; n -= 512; }
        if (n >= 256) { test[a] = 256; a++; n -= 256; }
        if (n >= 128) { test[a] = 128; a++; n -= 128; }
        if (n >= 64) { test[a] = 64; a++; n -= 64; }
        if (n >= 32) { test[a] = 32; a++; n -= 32; }
        if (n >= 16) { test[a] = 16; a++; n -= 16; }
        if (n >= 8) { test[a] = 8; a++; n -= 8; }
        if (n >= 4) { test[a] = 4; a++; n -= 4; }
        if (n >= 2) { test[a] = 2; a++; n -= 2; }
        if (n >= 1) { test[a] = 1; a++; n -= 1; }
        sort(test, test + a);
        for (int h = 0; h < a; h++) {
            if (h != a - 1)cout << test[h] << ' ';
            else cout << test[h];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(), a.end());
    cout << a.at(a.size()-1) - a.at(0) << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

bool is_prime(ll num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrt_num = sqrt(num);
  for (ll i = 3; i <= sqrt_num; i += 2) {
    if (num % i == 0)
      return false;
  }

  return true;
}

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

  int q;
  cin >> q;
  vector<P> vp(q);
  int min_val = 1e9, max_val = 0;
  rep(i, 0, q) {
    int l, r;
    cin >> l >> r;
    vp[i] = make_pair(l, r);
    chmin(min_val, l);
    chmax(max_val, r);
  }

  bool is_ok[100001] = {};
  for (int i = 1; i <= max_val; i += 2) {
    if (is_prime(i) && is_prime((i + 1) / 2))
      is_ok[i] = true;
  }

  int acc[100001] = {};
  rep(i, 1, 100001) {
    if (is_ok[i])
      acc[i] = acc[i - 1] + 1;
    else
      acc[i] = acc[i - 1];
  }

  rep(i, 0, q) { cout << acc[vp[i].second] - acc[vp[i].first - 1] << endl; }
}


Measured memory_bytes: 1920
n=gets.to_i
xy=n.times.map{gets.split.map(&:to_i)}
 
def dis(p1, p2)
  Math.sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)
end
 
r = c = 0
[*0...n].permutation(n).each do |x|
  x.each_cons(2).each do |p1,p2|
    r += dis(xy[p1], xy[p2])
  end
  c += 1
end
puts r / c


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

int main(){
	int n,a,b;cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;	
}

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

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

    string ans = std::string(s.size(), 'x');
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
using System;

namespace _0019
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long  output = n;
            for (int i = n - 1; i > 0; i--)
            {
                output *= i;
            }
            Console.WriteLine(output);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9152
#include <bits/stdc++.h>
// #define int ll
 
typedef long long ll;
typedef long double ldb;
 
using namespace std;
 
ldb a, b;
int h, m;
 
inline int read() {
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
 
signed main() {
	scanf("%Lf%Lf%d%d",&a,&b,&h,&m);int minutes=h*60+m;
	ldb dis=(ldb)minutes*(ldb)5.5;
	if(dis>360)dis-=(int)(dis/360.0)*360.0;
	if(dis>180)dis=360-dis;
//	ldb ans=cos(90.0/180.0*acos(-1));printf("%Lf\n",ans);
//	printf("%Lf\n",dis);
	ldb ans=(ldb)sqrt(a*a+b*b-2*b*a*cos(dis/180.0*acos(-1)));
//printf("%Lf\n",cos(90.0));
	printf("%.12Lf\n", ans);
	return 0;
}

Measured memory_bytes: 4220
#include<stdio.h>
#define LEN 100000
typedef struct task{
    char name[100];
    int time;
}P;
P tasks[LEN];
int head=0,tail=0;
int n,q;
int fTime=0;
int count;
int min(int x,int y)
{
    return x<y?x:y;
}
void enqueue(P x)
{
    tasks[tail]=x;
    tail++;
    if(tail>n-1) tail=tail-n;
}
void dequeue()
{
    head++;
    if(head>n-1) head=head-n;
}
int main()
{

    scanf("%d%d",&n,&q);
    count=n;
    for(int i=0;i<n;i++)
    {
        P itask;
        scanf("%s",itask.name);
        scanf("%d",&itask.time);
        enqueue(itask);
    }
    while(count>0)
    {

        int flagTime=min(tasks[head].time,q);
        fTime=fTime+flagTime;
        tasks[head].time=tasks[head].time-flagTime;
        if(tasks[head].time==0)
        {
            printf("%s %d\n",tasks[head].name,fTime);
            dequeue();
            count--;
        }
        else
        {
            enqueue(tasks[head]);
            dequeue();
        }
    }

    return 0;
}



Measured memory_bytes: 6836
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i< n; i++) {
            a[i] = sc.nextInt();
        }
        double ans = 0;
        for (int i : a) {
            ans += (double) 1 / i;
        }
        System.out.println((double) 1/ ans);

    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 3e5+3;
vector<int> primes;
bitset<N> bs;

void sieve() {
    bs.set();
    bs[0] = bs[1] = false;
    for(ll i = 2; i <= N; i++) {
        if(bs[i]) {
            for(ll j = i*i; j <= N; j += i) {
                bs[j] = false;
            }
            primes.push_back(i);
        }
    }
}

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

    sieve();
    for(auto i : primes) {
        if(i >= x) {
            cout << i;
            break;
        }
    }
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n; scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= n; ++k) {
	sum += __gcd(__gcd(i, j), k);
      }
    }
  }
  printf("%lld", sum);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3840
def gcd(a,b):
    while True:
        if a > b:
            a %= b
        else:
            b %= a
        if a == 0 or b == 0:
            return max(a,b)

def lcm(a,b,g):
    return int(a*b/g)
from sys import stdin
for l in stdin:
    a,b = list(map(int,l.split()))
    g = gcd(a,b)
    print ("%s %s"%(g,lcm(a,b,g)))

Measured memory_bytes: 7636
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef tuple<int,int,int,int> TP;
typedef vector<vector<ll>> mat;
const int N=1e5+5;
const ll mod=1e9+7;
int n,s[N],t[N],ans;
int s2[N],t2[N];
map<int,int> cnt1,cnt2,par;
int fi(int x)
{
	if(par[x]==x) return x;
	return par[x]=fi(par[x]);
}
void un(int x,int y)
{
	x=fi(x); y=fi(y);
	if(x!=y) par[y]=x;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int i=1;i<=n;i++) cin>>t[i];
	for(int i=1;i<=n;i++){
		s[n+1]^=s[i];
		t[n+1]^=t[i];
	}
	for(int i=1;i<=n+1;i++){
		par[s[i]]=-1;
		par[t[i]]=-1;
	}
	for(int i=1;i<=n+1;i++) cnt1[s[i]]++;
	for(int i=1;i<=n+1;i++) cnt2[t[i]]++;
	for(int i=1;i<=n;i++) if(cnt2[t[i]]!=cnt1[t[i]]){
		cout<<-1;
		return 0;
	}
	bool ok=true;
	for(int i=1;i<=n+1;i++) if(s[i]!=t[i]) ok=false;
	if(ok){
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n+1;i++){
		if(s[i]!=t[i]||i==n+1){
			if(i!=n+1) ans++;
			if(par[s[i]]==-1) par[s[i]]=s[i];
			if(par[t[i]]==-1) par[t[i]]=t[i];
			if(i!=n+1) un(s[i],t[i]);
		}
	}
	for(auto &it : par) if(fi(it.fi)==it.fi) ans++;
	cout<<ans-1;
    return 0;
}

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

using namespace std;

int main()
{
	int N;
	int d[101];
	int dupli_flag = 0;
	int res = 0;

	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> d[i];
	}
	
	for(int i = 1; i <= 100; i++){
		dupli_flag = 0;
		for(int j = 0; j < N; j++){
			if(d[j] == i){
				dupli_flag++;
			}
		}

		if(dupli_flag > 0){
			res++;
		}
	}
	
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef long long ll;

using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n, m;cin >> n >> m;
	vector< pair<ul, int>> p(n);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p.begin(), p.end());
    ul cost = 0;
    rep(i, 1000000){
        if(m - p[i].second > 0){
            m -= p[i].second;
            cost += p[i].first * p[i].second;
        }else{
            cost += m * p[i].first;
            break;
        }
    }
    cout << cost << endl;
	return 0;
}


Measured memory_bytes: 1792
S=input()
RS=S[::-1]

mae=S[0:(len(S)-1)//2]
Rmae=mae[::-1]


usiro=S[(len(S)+1)//2:len(S)]
Rusiro=usiro[::-1]


if S==RS and mae==Rmae and usiro ==Rusiro:
    print("Yes")
else:
    print("No")

#print(mae,usiro)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int phrase[] = {5, 7, 5, 7, 7};

int main() {

	int n;
	while(cin >> n, n){
		vector<int> w(n);
		rep(i, n){
			string s;
			cin >> s;
			w[i] = s.size();
		}
		
		int ans = -1;
		rep(i, n){
			if(ans != -1) break;
			int pos = 0;
			int cnt = 0;
			REP(j, i, n){
				if(cnt + w[j] > phrase[pos]) break;
				else if(cnt + w[j] == phrase[pos]){
					pos++;
					cnt = 0;
				}
				else cnt += w[j];
				
				if(pos == 5) {
					ans = i + 1;
					break;
				}
			}
		}
		cout << ans << endl;
		
		
	}

	return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  ll n;
  cin >> n;
  map<ll,ll> factors;
  for(ll i=2;i<=n;i++){
    ll k = i;
    for(ll j=2;j<=k;j++){
      while(k%j==0){
        factors[j]++;
        k /= j;
      }
    }
    if(k!=1) factors[k]++;
  }

  ll ans = 1;
  for(auto p : factors){
    (ans *= p.sc + 1) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  A[a-1].append((b,i))
ans=[0]*M
for i in range(N):
  d=sorted(A[i])
  n=len(d)
  for j in range(n):
    a,b=d[j]
    D=str(i+1)
    E=str(j+1)
    r=D.zfill(6)+E.zfill(6)
    ans[b]=r
for i in ans:
  print(i)

Measured memory_bytes: 38908
#include <bits/stdc++.h>
using namespace std;
const int md=1000000007;
int n,m,i,j;
long long f[5005][5005],s[5005][5005],pw2[5005],o[5005],k;
long long pw(long long a, int b) {
  if (b==0) return 1LL;
  if (b&1) return (pw(a,b-1)*a)%md;
  long long x=pw(a,b/2);
  return (x*x)%md;
}
int main() {
  scanf("%d%d",&m,&n);
  for (pw2[0]=o[0]=i=1; i<=n; i++) {
    f[0][i]=1;
    pw2[i]=(pw2[i-1]*2)%md;
    o[i]=pw(pw2[i],md-2);
  }
  for (i=1; i<=m; i++) {
    for (k=1; k<=n; k++) s[i-1][k]=(s[i-1][k-1]+((f[i-1][k]*k)%md)*o[k+1])%md;
    for (j=1; j<=n; j++) {
      f[i][j]=(f[i-1][j]*(j+1LL))%md;
      f[i][j]=(f[i][j]+s[i-1][j-1]*pw2[j])%md;
    //f[i][j]=(f[i][j]+s[i-1][j-1]*pw2[j])%md;
    //s[i][j]=(s[i][j-1]+((f[i][j]*j)%md)*o[j+1])%md;
    //s[i][j]=(((f[i][j]*j)%md)*o[j+1])%md;
    //printf("%d %d = %d\n",i,j,f[i][j]);
    }
  }
  printf("%d\n",f[m][n]);
  return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N;
    cin >> N;

    int ans = N / 2 - 1;
    if(N % 2 != 0) { ans = N / 2; }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, sum = 0;
    cin >> a >> b;
    if(a > b){
        sum += a;
        a--;
        if(a >= b){
            sum+=a;
        }
        else{
            sum+=b;
        }
    }
    else if(a == b){
        sum += a;
        a--;
        sum += b;
        b--;
    }
    else{
        sum += b;
        b--;
        if(a >= b){
            sum+=a;
        }
        else{
            sum+=b;
        }
    }
    cout << sum << endl;
}

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

sum_div = 0
for i in range(N):
  temp_div = A[i]
  while True:
    if temp_div%2 == 0:
      sum_div += 1
      temp_div = temp_div//2
    else:
      break
print(sum_div)

Measured memory_bytes: 4148
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e5+5;

int n;
int a[N];
int pre[N];
int tree[N*2];

void add(int x){
	x+=n+1;
	for(;x<=n*2+2;x+=x&-x)tree[x]++;
}

int query(int x){
	int ret=0;
	x+=n+1;
	for(;x;x-=x&-x)ret+=tree[x];
	return ret;
}

bool check(int lim){
	fo(i,1,n){
		pre[i]=pre[i-1];
		if (a[i]<=lim)pre[i]++;
		else pre[i]--;
	}
	fo(i,0,n*2+2)tree[i]=0;
	add(0);
	LL tot=0;
	fo(i,1,n){
		tot+=query(pre[i]-1);
		add(pre[i]);
	}
	LL all=1ll*n*(n+1)/2;
	all=all/2+1;
	return tot>=all;
}

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	int l=1,r=1e9,ans=0;
	while(l<=r){
		int mid=(l+r)/2;
		if (check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n + 2];
            int[] sort = new int[n];
            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;
            long cost = 0;
            int now = 0;
            a[0] = 0;
            a[n + 1] = 0;
            for (int i = 1; i <= n; i++) {
                int tmp = in.nextInt();
                a[i] = tmp;
                cost += Math.abs(tmp - now);
                now = tmp;
            }

            cost += Math.abs(a[n + 1] - now);
            for (int i = 1; i <= n; i++) {
                if ((a[i - 1] < a[i] && a[i] < a[i + 1]) ||
                        (a[i + 1] < a[i] && a[i] < a[i - 1])) {
                    out.println(cost);
                } else {
                    int minus = Math.abs(a[i + 1] - a[i]) + Math.abs(a[i] - a[i - 1]);
                    int plus = Math.abs(a[i + 1] - a[i - 1]);

                    out.println(cost - minus + plus);
                }
            }
        }

    }
}



Measured memory_bytes: 62948
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
AdjList getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;
long long Manhattan_dist(long long x1, long long y1, long long x2, long long y2){return abs(x1-x2) + abs(y1-y2);}

void out(bool ans){
	if(ans == true) cout << "yes" << endl;
	else cout << "no" << endl;
}
void Out(bool ans){
	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}
void OUT(bool ans){
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}
unsigned long long gcd(const unsigned long long a, const unsigned long long b){
	return (b==0) ? a : gcd(b,a%b);
}
int main(){
	int N;
	cin >> N;
	vector<int> a = getv<int>(N);
	sort(a.begin(),a.end());
	cout << a[N-1]-a[0] << endl;
}



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

using namespace std;

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

    int count = 0;

    for(int i=1;i<s.size();i++)
    {
        if(s[i] != s[i-1])
            count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 512
k,a,b = map(int,input().split())

if b-a <= 2:
    print(k+1)
    exit()
    
if k >= a-1:
    if (k-a+1) % 2 == 1:
        bis = a + (b-a)*((k-a+1)//2)
        bis += 1
    else:
        bis = a + (b-a)*((k-a+1)//2)
    print(bis)
    exit()
else:
    bis += a-1
    print(bis)
    exit()


Measured memory_bytes: 3060
#pragma once
#include <sstream>
#include <string>
#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 <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
const int MAX_V = 201;

void LucasNumber() {
	int n;
	cin >> n;
	ll lm2 = 2;
	ll lm1 = 1;
	for (size_t i = 0; i < n; i++)
	{
		ll a = lm2 + lm1;
		lm2 = lm1;
		lm1 = a;
	}
	cout << lm2 << endl;
}
int main() {
	LucasNumber();
	return 0;
}



Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

int n;
vector<int> num;
vector<char> op;

int calc1() {
	vector<int> n = num;
	vector<char> o = op;
	for(int i = 0; i < o.size();) {
		if(o[i] == '*') {
			int m = n[i] * n[i + 1];
			n.erase(n.begin() + i);
			n.erase(n.begin() + i);
			n.insert(n.begin() + i, m);
			o.erase(o.begin() + i);
		}
		else {
			i++;
		}
	}
	int sum = 0;
	for(int i = 0; i < n.size(); i++) {
		sum += n[i];
	}
	return sum;
}

int calc2() {
	int s = num[0];
	for(int i = 0; i < op.size(); i++) {
		if(op[i] == '+') s += num[i + 1];
		else s *= num[i + 1];
	}
	return s;
}

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

	string s;
	while(cin >> s) {
		cin >> n;
		num.clear();
		op.clear();
		for(int i = 0; i < s[i]; i++) {
			if(isdigit(s[i])) num.push_back(s[i] - '0');
			else op.push_back(s[i]);
		}

		bool M = calc1() == n, L = calc2() == n;
		//cout << calc1() << " " << calc2() << endl;
		if(M && L) cout << "U" << endl;
		if(M && !L) cout << "M" << endl;
		if(!M && L) cout << "L" << endl;
		if(!M && !L) cout << "I" << endl;
	}
}

Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,m;
    cin >> n >> m;
    string ans_str(n,'-');
    vector<bool> used(n,false);
    bool ans = true;

    for (int i=0; i<m; i++) {
        int s,c;
        cin >> s >> c;
        s--;
        if (!used[s] || (ans_str[s]-'0' == c)) {
            ans_str[s] = c + '0';
            used[s] = true;
        } else {
            ans = false;
            break;
        }
    }
    if (n>1 && ans_str[0] =='0') ans = false;

    if (ans) {
        if (n>1 && ans_str[0] == '-') ans_str[0] = '1';

        for (int i=0; i<n; i++) {
            if (ans_str[i] == '-') ans_str[i] = '0';
        }
    }


    cout << (ans? ans_str : "-1") << endl;
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli n;

mat tree;
mat cost;
lli a,b,c;
lli q,k;
lli x,y;
vll dist;

void dfs(lli x,lli p,lli d){
  dist[x] = d;
  for(lli i = 0;i < tree[x].size();i++){
    if(tree[x][i] != p) dfs(tree[x][i],x,d+cost[x][i]);
  }
}


int main(){
  cin >> n;
  tree = mat(n+1);
  cost = mat(n+1);
  for(lli i = 0;i < n-1;i++){
    cin >> a >> b >> c;
    tree[a].push_back(b);
    tree[b].push_back(a);
    cost[a].push_back(c);
    cost[b].push_back(c);
  }
  cin >> q >> k;
  dist = vll(n+1);
  dfs(k,0,0);
  for(lli i = 0;i < q;i++){
    cin >> x >> y;
    cout << dist[x]+dist[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 18176
K = int(input())
A = [1,2,3,4,5,6,7,8,9]
for i in range(len(A)):
    if A[i] != 9:
        for j in range(-1,2):
            a = int(str(A[i]) + str(A[i]+j))
            A.append(a)
    else:
        A.append(98)
        A.append(99)
A.append(100)
A.append(101)
L1 = len(A.copy())
for i in range(10, L1):
    B = A[i]
    if B % 10 == 0:
        A.append(int(str(B) + '0'))
        A.append(int(str(B) + '1'))
    elif B % 10 == 9:
        A.append(int(str(B) + '8'))
        A.append(int(str(B) + '9'))
    else:
        for j in range(-1, 2):
            a = int(str(B) + str((B % 10) + j))
            A.append(a)
L2 = len(A.copy())
for i in range(8):
    for i in range(L1,L2):
        B = A[i]
        if B % 10 == 0:
            A.append(int(str(B) + '0'))
            A.append(int(str(B) + '1'))
        elif B % 10 == 9:
            A.append(int(str(B) + '8'))
            A.append(int(str(B) + '9'))
        else:
            for j in range(-1, 2):
                a = int(str(B) + str((B % 10) + j))
                A.append(a)
    L1 = L2
    L2 = len(A.copy())
print(A[K-1])

Measured memory_bytes: 31508
n=int(input())
t=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
c=0
for i in range(n):
    if a[i]<=t[i]+t[i+1]:
        c+=a[i]
    else:
        c+=t[i]+t[i+1]
    if a[i]>=t[i]:
        a[i]-=t[i]
        t[i]=0
    else:
        t[i]-=a[i]
        a[i]=0
    if a[i]>=t[i+1]:
        a[i]-=t[i+1]
        t[i+1]=0
    else:
        t[i+1]-=a[i]
        a[i]=0
print(c)

Measured memory_bytes: 18624
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
    int n, x, t;
    cin >> n >> x >> t;
    int ans = ((n + x - 1) / x) * t;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3592
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	count := 0
	for i := a; i <= b; i++ {
		tmp := strconv.Itoa(i)
		if tmp[0] == tmp[4] && tmp[1] == tmp[3] {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1024
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A_i = []
    for i in range(N):
        A_i.append(int(input_raw[i]))
    print abs(max(A_i) - min(A_i))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
int main(){
	int n,a[31] = {1,1,2};
	for(n=3;n<31;)a[n++]=a[n-1]+a[n-2]+a[n-3];
	for(;scanf("%d",&n),n;)printf("%d\n",a[n]/10/365+1);
return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  string n; cin>>n;
  ans1(n[0]==n[2]);


  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {

  int A[100],minj,i,j,x,N,count=0,flag;

  scanf("%d",&N);
  for(i = 0; i < N; i++) {
    scanf("%d",&A[i]);
  }

  for(i = 0; i < N; i++) {
    minj = i;
    flag = 0;
    for(j = i; j < N; j++) {
      if(A[j] < A[minj]) {
	minj = j; /*最小値があったらその位置を記憶するための動作*/
	flag = 1; /*for文で確かめるなかで、最小値が変わったらflagを1にする。*/
	
      }
    }
    if(flag == 1) {
      x = A[i];
      A[i] = A[minj];
      A[minj] = x;
      count++; /*交換回数を表す。*/
    }
  }

  for(i = 0; i < N; i++) {
    printf("%d",A[i]);
    if(N-1 != i) printf(" ");
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
} 

Measured memory_bytes: 604