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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

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

int main(){
	int n;cin>>n;
	vi a1(n),a2(n);
	int sum1[n+1],sum2[n+1];
	sum1[0]=0;sum2[0]=0;
	rep(i,n){cin>>a1[i];sum1[i+1]=sum1[i]+a1[i];}
	rep(i,n){cin>>a2[i];sum2[i+1]=sum2[i]+a2[i];}
	int ans=0;
	for(int i=1;i<=n;++i){
		ans=max(ans,sum1[i]+sum2[n]-sum2[i-1]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;

ll n, k;
ll x1, x2;
ll a[2002];
const ll mod = 1000000007;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i] > a[j])
            {
                x2++;
                if(i < j) x1++;
            }
        }
    }
    ll ans = 0, tmp = 0;
    ans = x1 * k % mod;
    tmp = k * (k-1)/2LL % mod;
    cout << (ans + tmp * x2) % mod;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader fr = new FastReader();
		String s = fr.nextLine();
		long sum = 0;
		int n = s.length() + 1;
		long[] a = new long[n];
		for (int i=1; i<n; i++) {
			if (s.charAt(i-1) == '<') {
				a[i] = a[i-1] + 1;
			} else if (i < n-1 && s.charAt(i-1) == '>' && s.charAt(i) == '<') {
				a[i] = 0;
			}
		}
		for (int i=n-1; i>=0; i--) {
			if (i < n-1 && s.charAt(i) == '>') {
				a[i] = Math.max(a[i], a[i+1]+1);
			}
			sum += a[i];
		}
		System.out.println(sum);
	}
	
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


Measured memory_bytes: 35092
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
#include <ctime>
#include <functional>
#include <cassert>
using namespace std;
const double pi=3.141592653589793238;//三角関数は弧度法
//substr(10,4)は左から11~14番目
//substr(2)は左から3番目〜最後
//max({a1,a2,a3})
//*max_element(c+1,c+10)は配列の1番目から9番目
//大きい順にソートsort(a.begin(), a.end(), greater<int>());
//10と近い順にソートsort(a.begin(), a.end(), cmp);sort(a.begin(), a.end(), 10);
//乱数rand()おまじないsrand((unsigned)time(NULL));mt19937
//clock()で実行時間(10^{-6}秒)
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義する場合priority_queue<int, vector<int>, greater<int>> Q;
// string 型の番地に double 型の変数を記録する場合map<string, double> M;
//lower_bound(a+l, a+r, x) - aa[l] から a[r-1] までの中で初めて x 以上となるようなインデックスを返す
//set.lower_bound(x)集合 a の中で x 以上である最小の要素を指すイテレーターを返す
//count(v.begin(), v.end(), x)xがいくつ含まれるかfindは含まれなければa.end()，含まれるときは最初のイテレーター
//next_permutation(a, a + n)次の順列の作成
//__builtin_popcount(x)xを2進数で表した時に1である様なビットの個数を返す関数
// 例 2: 長さ 8 の bitset を定義する。整数から初期化を行う。
//bitset<8> bs2(131); // 7 ビット目から 0 ビット目への順番で、10000011 となる。
//bitset<8> bs3("10000011"); // 7 ビット目から 0 ビット目への順番で、10000011 となる。
//a.set(x)2^xの位を1に．a.reset(x)2^xの位を0に，a[i]2^iの位にアクセス

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin >> l[i];
    sort(l.begin(),l.end(),greater<int>());
    long long ans=0;
    for(int i=0; i<k; i++){
        ans+=l[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3608
n = int(input())
c = [0 for i in range(4)]
for i in range(n):
    s = input()
    if s=="AC":
        c[0] += 1
    elif s=="WA":
        c[1] += 1
    elif s=="TLE":
        c[2] += 1
    elif s=="RE":
        c[3] += 1

print("AC x", c[0])
print("WA x", c[1])
print("TLE x", c[2])
print("RE x", c[3])


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

    typedef long long ll;
    const ll MOD = 1e9+7;
    const int N = 3005;

    int n;
    double p[N],dp[N][N];

    int main()
    {
        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        cin>>n;
        for(int i=1;i<=n;i++)cin>>p[i];

        dp[0][0]=1.0;

        for(int i=1;i<=n;i++){
            for(int j=0;j<=i;j++){
                if(j)dp[i][j]=1.0*p[i]*dp[i-1][j-1]+1.0*(1.0-p[i])*(dp[i-1][j]);
                else dp[i][j]=1.0*(1-p[i])*dp[i-1][j];
            }
        }

        double ans=0.0;


        for(int i=1;i<=n;i++){
            if(i>n-i)ans+=1.0*dp[n][i];
        }

        cout<<fixed<<setprecision(12)<<ans;
        return 0;
    }


Measured memory_bytes: 69120
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int cnt[1000010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}
int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) {
        cin >> A[i];
        int j = 2;
        int num = A[i];
        while(A[i] >= j * j) {
            int c = 0;
            while(num % j == 0) {
                c++;
                num /= j;
            }
            cnt[j] = max(cnt[j], c);
            j++;
        }
        if (num != 1) cnt[num] = max(cnt[num], 1LL);
    }
    int S = 1;
    REP(i, 2, 1000000) S = (S * power(i, cnt[i])) % mod;
    int ans = 0;
    rep(i, N) ans = (ans + Div(S, A[i])) %mod;
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 6656
# 最大値に近づけるためにそれ以外の二つをインクリメントしていく（二番目に大きいやつと最大値との差ぶんだけ増える）
# 二数が同じ数になったとき最小値は↑を加えたものになっている
# それと最大値との差ぶんだけ+2するが、差が奇数だと越えるので
# いったん最大値を更新してから最初に最大値に到達していた二数をインクリメント
a, b, c = gets.chomp.split.map(&:to_i)
maximum = [a, b, c].max
minimum = [a, b, c].min
mid = (a+b+c)-(maximum+minimum)
aa = maximum-mid
if (maximum - (minimum+aa)).even?
  puts aa+(maximum - (minimum+aa))/2
else
  puts aa+(maximum - (minimum+aa))/2+2
end

Measured memory_bytes: 3836
#include <iostream>

using namespace std;

int main () {
    long long A, B;
    long long ans = 0;
    
    cin >> A >> B;
    if (A%2) {
        ans ^= A-1;
        A--;
    }
    
    while ((B-A+1)%4!=0) {
        ans^=B+1;
        B++;
    }
    
    cout << ans;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define setp setprecision
#define fix fixed
#define db double
#define pb push_back
int main() {
	int n;
	cin>>n;
	int c[n+1];
	int p[n+1],s[n+2];
	p[0]=-1;
	s[n+1]=-1;
	for (int i=1;i<=n;i++) {
		cin>>c[i];
	}
	for (int i=1,j=n;i<=n;i++,j--) {
		p[i]=max(p[i-1],c[i]);
		s[j]=max(s[j+1],c[j]);
	}
	for (int i=1;i<=n;i++) {
		cout<<max(s[i+1],p[i-1])<<endl;
	}
	return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int n=min(a,b);
	int m=max(a,b);
	for(int i=0;i<m;i++)
		cout<<n;
	cout<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    rep(i, N) cin >> X[i] >> Y[i];

    if (N == 2) {
        write(0.5);
        write(0.5);
        return 0;
    }

    vector<double> arg;
    const double PI = acos(-1);
    rep(i, N) {
        arg.resize(0);

        rep(j, N) {
            if (j == i) continue;
            
            double a = 0;
            if (X[j] == X[i]) {
                a = Y[j] > Y[i] ? PI / 2 : 3 * PI / 2;
            }
            else if (X[j] > X[i]) {
                a = atan((double)(Y[j] - Y[i]) / (X[j] - X[i]));
            }
            else {
                a = PI + atan((double)(Y[j] - Y[i]) / (X[j] - X[i]));
            }
            arg.push_back(a);
        }
        sort(all(arg));

        double ma = arg[0] - arg[N - 2] + 2 * PI;
        rep(k, 0, N - 2) {
            ma = max(ma, arg[k + 1] - arg[k]);
        }

        if (ma < PI) write(0.0);
        else write((ma - PI) / (2 * PI));
    }
}

Measured memory_bytes: 256
def rectangle(n, hs):
    stack = []  # (height, pos) 高さと位置が格納される
    ans = 0
    for i, h in enumerate(hs):
        j = i
        while stack and stack[-1][0] > h:
            pre_h, j = stack.pop()
            ans = max(ans, (i - j) * pre_h)

        if not stack or stack[-1][0] < h:
            stack.append((h, j))

    ans = max(ans, max((n - j) * h2 for h2, j in stack))

    return ans


H, W = map(int, input().split())
hist = [0] * W
result = 0
for _ in range(H):
    ht = list(map(int, input().split()))
    hist = list(map(lambda pre, cur: (pre + 1) * (cur ^ 1), hist, ht))
    result = max(result, rectangle(W, hist))

print(result)


Measured memory_bytes: 5680
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  string word[N];
  for(int i=0;i<N;i++)cin>>word[i];
  sort(word,word+N);
  string t="";
  for(int i=0;i<N;i++){
    t.append(word[i]);
  }
  cout<<t<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int S;
ll DP[2001]; // i番目までで総和j使ったときの順列数

ll dfs(ll rest) {
  if (rest==0) return 1ll;
  if (rest<3) return 0ll;
  if (DP[rest]>=0) return DP[rest]; 
  ll ret=0ll;
  for (int r=3; r<=S; r++) {
    ret+=dfs(rest-r);
    ret%=MOD;
  }
  DP[rest] = ret;
  return ret;
}

int main() {
  INCANT;
  cin >> S;
  rep(j, 2001) DP[j] = -1;
  DP[0]=0;DP[1]=0;DP[2]=0;
  cout << dfs(S) << "\n";
  return 0;
}

Measured memory_bytes: 3700
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(s: String, t: String);
    let v_s: Vec<_> = s.chars().collect();

    let v_t: Vec<_> = t.chars().collect();
    let mut count = 0;
    for i in 0..v_s.len() {
        if v_s[i] != v_t[i] {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 4384
# coding:utf-8
n = int(input())
h = list(map(int, input().split()))
counter = 0
 
for i in range(n):
    #print(h[0:i+1])
    h_max = max(h[0:i+1])
    if (h[i] >= h_max) and (h[i] >= h[0]):
        #print(h[i])
        counter += 1
print(counter)

Measured memory_bytes: 3060
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
#include <set>
//#include <string.h>
using namespace std;
using Graph = vector<vector<int>>;
queue<long>que;

int main(){
    int n;
    cin >>n;
    long sum=0;
    rep(i,n+1){
        if(i%15==0)continue;
        else if(i%3==0)continue;
        else if(i%5==0)continue;
        else{
            sum+=i;
        }
    }
    
    cout << sum <<endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool nine = true;
  for (int i = 1; i < n; ++i) {
    if (s[i] == '9')
      continue;
    else
      nine = false;
  }
  int ans = s[0] - '0' + 9 * (n - 1);
  cout << (nine ? ans : ans - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
long long maxx(long long a[],int n){
    sort(a,a+n,greater<long long>());
    return a[0];
}
int main(){
    int n;
    long long c;
    cin >> n >> c;
    long long x[n],v[n];
    long long sum = 0;
    for(int i = 0;i<n;i++){
        cin >> x[i] >> v[i];
        sum+=v[i];
    }
    long long ans = sum-c+max(x[0],c-x[n-1]);
    long long right[n],left[n];
    right[0] = left[0] = 0;
    long long temright = 0;
    long long temleft = 0;
    for(int i = 0;i<n-1;i++){
        temright+=v[i];
        right[i+1] = max(right[i],temright-x[i]);
        temleft+=v[n-i-1];
        left[i+1] = max(left[i],temleft-(c-x[n-i-1]));
    }
    long long tem = 0;
    for(int i = 0;i<n;i++){
        tem+=v[i];
        ans = max(ans,tem-2*x[i]+left[n-1-i]); 
        //cout << ans << endl;
    }
    tem = 0;
    for(int i = n-1;i>=0;i--){
        tem+=v[i];
        ans = max(ans,tem-2*(c-x[i])+right[i]);
        //cout << ans << endl;
    }
    ans = max(ans,max(maxx(right,n),maxx(left,n)));
    cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;

int main() {
    int n, W;
    cin >> n >> W;
    int v[n+1];
    int w[n+1];
    for (int i = 1; i <= n; ++i) {
        cin>>w[i]>>v[i];
    }
    vector<vector<ll> > dp(n + 1, vector<ll>(W + 1, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (j - w[i] >= 0 && dp[i-1][j] < v[i] + dp[i-1][j-w[i]]) {
                dp[i][j] = v[i] + dp[i-1][j-w[i]];
            } else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W];

}


Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String s = scan.next();
	int point = 0;
	for (int i = 0; i < s.length(); i++) {
	    if(s.charAt(i) == 'p') point--;
	}
	point = point + s.length()/2;

	System.out.println(point);
	scan.close();
    }
}


Measured memory_bytes: 25580
use io::*;
use std::cmp::{max,min};

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let h: usize = sc.next();
    let w: usize = sc.next();
    if h * w % 3 == 0 {
        println!("0");
        return;
    }
    let mut ans = min(h,w);
    {
        let k = h / 3;
        let l = w / 2;
        if w % 2 == 0 {
            ans = l;
        } else {
            if h % 3 == 1 {
                ans = min(ans,min(max(k+l+1,2*k+1),max(k+w,2*k)));
            } else {
                ans = min(ans,min(max(k+l+1,2*k+1),max(k+w,2*k)));
            }
        }
    }
    {
        let k = w / 3;
        let l = h / 2;
        if h % 2 == 0 {
            ans = min(ans,l);
        } else {
            if w % 3 == 1 {
                ans = min(ans,min(max(k+l+1,2*k+1),max(k+w,2*k)));
            } else {
                ans = min(ans,min(max(k+l+1,2*k+1),max(k+w,2*k)));
            }
        }
    }
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	ll k;
	cin >> s >> k;
	int n = s.size();
	int p = 0;
	char b = s[0];
	vector<int> cnt(n+1, 0);
	rep(i,n){
		if(s[i] == b) cnt[p]++;
		else{
			cnt[++p]++;
			b = s[i];
		}
	}
	if(p == 0){
		cout << n * k / 2 << endl;
		return 0;
	}
	ll ans = 0;
	rep(i,p+1) ans += cnt[i]/2;
	ans *= k;
	if(s[0] == s[n-1]) ans -= (cnt[0]/2 + cnt[p]/2 - (cnt[0] + cnt[p]) / 2) * (k - 1);
	cout << ans << endl;
	return 0;
}

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

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

    string str;
    vector<string> s;
    for (int i = 0; i < n; ++i) {
        cin >> str;
        s.push_back(str);
    }

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

    for (int i = 0; i < n; ++i) {
        cout << s[i] ;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int N;
	cin>>N;
	int ans=0;
	int hb=0,ta=0,bo=0;
	rep(i,N){
		string S;
		cin>>S;
		int l=sz(S);
		rep(i,l-1)if(S[i]=='A'&&S[i+1]=='B')ans++;
		if(S[0]=='B' && S[l-1]=='A')bo++;
		else if(S[0]=='B')hb++;
		else if(S[l-1]=='A')ta++;
	}
	int con=0;
	if(hb==0 && ta==0)con=max(bo-1,0);
	else{
		con=min(bo+hb,bo+ta);
	}
	ans+=con;
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> t(100);
vector<int> h(100);  
int main() {
  while(cin >> n >> m && n * m != 0)
    {
      for(int i = 0; i < n; i++) {
	cin >> t[i];
      }
      for(int i = 0; i < m; i++) {
	cin >> h[i];
      }
      int q = INT_MAX / 2 - 1;
      int p = INT_MAX / 2 - 1;
      for(int i = 0; i < n; i++) {
	for(int j = 0; j < m; j++) {
	  swap(t[i], h[j]);
	  if(accumulate(t.begin(), t.begin() + n, 0)
	     == accumulate(h.begin(), h.begin() + m, 0)) {
	    if(p + q > i + j) {
	      p = i; q = j;
	    }
	  }
	  swap(t[i], h[j]);
	}
      }
      if(p == INT_MAX / 2 - 1) {
	cout << -1 << endl;
      }else {
	cout << t[p] << " " << h[q] << endl;
      }
    }
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> csum(n+1,0);
    rep(i,n) {
        csum[i+1] = csum[i] + i+1;
    }
    ll res = 0;
    repr(i,k,n+1) {
        ll tmp = 0;
        tmp += csum[n] - csum[n-i] - csum[i-1] + 1;
        res += tmp;
        res %= MOD;
    }
    res++;
    res %= MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4744
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define nl n<<1
#define nr (n<<1)|1
#define first fi
#define second se
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
const ll mod=1e9+7;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' | ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int aa)
{
    if(aa>9)
        Out(aa/10);
    putchar(aa%10+'0');
}
int a[100010];
int main()
{
    int n=read();int sum=0;
    for(int i=1;i<=n;i++)a[i]=read();
    for(int i=1;i<=n;i++)
    {
        if(i==n)
        {
            if(a[i]==i)
                sum++;
            break;
        }
        if(a[i]==i)
        {
            swap(a[i],a[i+1]);
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


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

int main() {
	int n; string s; cin >> n >> s;
	int cnt = 0;
	string ans;
	for (char c : s) {
		if (c == '(')cnt++;
		else cnt--;
		if (cnt < 0) {
			ans = '(' + ans; cnt++;
		}
		ans += c;
	}
	rep(i, cnt)ans += ')';
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
    ll x,y;
    cin>>x>>y;
    x-=((x/y)*y);
    if(abs(x-y)<x)cout<<abs(x-y);
    else cout<<x;
  return 0;
}
//code the AC sol !
// BS/queue/map

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

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

    string t[3];
    int idx = 0;
    for (char c : s) {
        if (c == '/') idx++;
        else t[idx] += c;
    }

    if (t[0] < "2019") {
        cout << "Heisei";
    }
    else if (t[1] < "05") {
        cout << "Heisei";
    }
    else {
        cout << "TBD";
    }
    cout << 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 int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll l = floor(a[0]/2.l);
    ll r = ceil(a[0]/2.l);
    int near_i=-1;
    ll nin = INF;
    for(int i=1;i<n;i++){
        if(nin>abs(r-a[i])+abs(l-a[i])){
            nin = abs(r-a[i])+abs(l-a[i]);
            near_i = i;
        }
    }
    cout << a[0] << ' ' << a[near_i] << endl;
	return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  string s;
  int x, y, n = 0;
  vector<int> X, Y;
  cin >> s;
  cin >> x >> y;
  for (int i=0; i < s.size(); i++) {
    if (s[i]=='T') {
      (X.size() == Y.size() ? X : Y).push_back(n);
      n = 0;
    }
    else n++;
  }
  (X.size() == Y.size() ? X : Y).push_back(n);
  int b = X[0], c = 0;
  sort(X.begin()+1, X.end());
  sort(Y.begin(), Y.end());
  
  for (int i = X.size()-1; i>=1; i--) {
    b += X[i]*(b>x?-1:1);
  }
  for (int i = Y.size()-1; i>=0; i--) {
    c += Y[i]*(c>y?-1:1);
  }
  cout << (b == x && c == y ? "Yes": "No") << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    C = [[0 for _ in range(10)] for __ in range(10)]
    for i in range(1, N+1):
        c = str(i)
        C[int(c[0])][int(c[-1])] += 1
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += C[i][j] * C[j][i]
    print(ans)

if '__main__' == __name__:
    resolve()


Measured memory_bytes: 72776
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        int cnt=0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            if(a[i]<0) cnt++;
        }
        long sum = 0;
        for(int i =0; i<n; i++){
            sum += Math.abs(a[i]);
        }
        long min = 1_000_000_000;
        if(cnt%2==0){
            System.out.println(sum);
            return;
        }else{
            for(int i =0; i<n; i++){
                min = Math.min(Math.abs(a[i]),min);
            }
            System.out.println(sum-min*2);
        }
    }
}


Measured memory_bytes: 62236
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define MOD 1000000007
using namespace std;

int main()
{
	int N;	cin >> N;
	vector<tuple<string, int, int>> v(N);

	for (int i = 0; i < N; i++)
	{
		string s;	cin >> s;
		int p;	cin >> p;
		v[i] = make_tuple(s, -p, i+1);


	}
	sort(v.begin(), v.end());

	for (int i = 0; i < N; i++)
	{
		cout << get<2>(v[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
class edge{
public:
	int from,to;
	string lab;
	edge(){}
	edge(int ff,int tt,string la){
		from=ff;
		to=tt;
		lab=la;
	}
};
int n,a,s,g;
edge G[600];
string dp[600];

bool comp(string A,string B){
	int n=min(A.size(),B.size());
	for(int i=0;i<n;i++){
		if(A[i]>B[i])return true;
		if(A[i]<B[i])return false;
	}
	return A.size()>B.size();
}

string bellman_fold(){
	for(int i=0;i<n;i++){
		dp[i]="INF";
	}
	dp[g]="";
	for(int i=0;i<7*n;i++){
		bool update=false;
		for(int j=0;j<a;j++){
			edge e=G[j];
			if(dp[e.from]!="INF" && (comp(dp[e.to],e.lab+dp[e.from]) || dp[e.to]=="INF")){
				dp[e.to]=e.lab+dp[e.from];
				update=true;
			}
		}
		if(dp[s].size()>6*n)return "NO";
		if(!update)break;
	}
	return dp[s]=="INF"?"NO":dp[s];
}

int main(void){
	while(1){
		scanf("%d%d%d%d",&n,&a,&s,&g);
		if(n+a+s+g==0)break;
		for(int i=0;i<a;i++){
			cin >> G[i].to >> G[i].from >> G[i].lab;
		}
		cout << bellman_fold() << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, K; cin >> N >> K;
    vector<double> P(N+1);
    for(int i=0; i<N; i++) {
        int v; cin >> v;
        P[i+1] = v * (v + 1) / 2.0 / v;
        P[i+1] += P[i];
    }

    double ans = 0;
    for(int i=0; i+K<=N; i++) {
        double S = P[i+K] - P[i];
        chmax(ans, S);
    }
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n&&n){
		vector<pair<int,int> >dat;
		while(n--){
			int mem;
			cin>>mem;
			vector<int> scr;
			int a,b,c;
			for(int i=0;i<10;i++){
				cin>>a;
				scr.PB(a);
				if(a!=10||i==9){
					cin>>b;
					scr.PB(b);
				}else continue;
				if(i==9&&(a+b==10||a==10)){
					cin>>c;
					scr.PB(c);
				}else continue;
			}
			int ans=0,k=0;
			for(int i=0;i<9;i++){
				if(scr[k]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k++;
					continue;
				}
				if(scr[k]+scr[k+1]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k+=2;
					continue;
				}
				ans+=scr[k]+scr[k+1];
				k+=2;
			}
			while(k<scr.size())ans+=scr[k++];
			dat.PB(MP((-1)*ans,mem));
		}
		sort(dat.begin(),dat.end());
		for(int i=0;i<dat.size();i++){
			cout<<dat[i].second<<" "<<dat[i].first*(-1)<<endl;
		}
	}
}

Measured memory_bytes: 1220
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    long double x = sqrt(a * b);
    if (a + b + 2 * x < c) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int A, B;

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

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

int main(){
    cin >> A >> B;
    ll ans;
    ans = lcm(A, B);
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
int a,b,c;
int sort;

scanf("%d %d %d",&a,&b,&c);
if(a > b){
	sort = a;
	a = b;
	b = sort;
}
if(b > c){
	sort = b;
	b = c;
	c = sort;
}
if(a > b){
	sort = a;
	a = b;
	b = sort;
}
printf("%d %d %d\n",a,b,c);
return 0;
}


Measured memory_bytes: 2036
#include <cstdio>

int main(void)
{
    int totalValue=0;
    int commonPart,Apart,Bpart;
    int priceA,priceB,priceMix;

    scanf("%d%d%d",&priceA,&priceB,&priceMix);
    scanf("%d%d",&Apart,&Bpart);

    commonPart=(Apart<Bpart?Apart:Bpart);
    if(2*priceMix<priceA+priceB)
    {
        totalValue=priceMix*2*commonPart;
    }
    else
    {
        totalValue=commonPart*(priceA+priceB);
    }
    if( (Apart-commonPart)*priceA+(Bpart-commonPart)*priceB
            < (Apart-commonPart+Bpart-commonPart)*priceMix*2 )
    {
        totalValue+=(Apart-commonPart)*priceA+(Bpart-commonPart)*priceB;
    }
    else
    {
        totalValue+=(Apart-commonPart+Bpart-commonPart)*priceMix*2;
    }
    printf("%d\n",totalValue);
    return 0;
    

}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define maxn 200005
#define mid ((nl+nr)>>1)
using namespace std;
typedef long long ll;
int n,m;
int fa[maxn];
int getfa(int now)
{
	return fa[now]==now ? now : fa[now]=getfa(fa[now]);
}
int cnt[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int xx=getfa(x),yy=getfa(y);
		if(xx!=yy)
			fa[xx]=yy;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cnt[getfa(i)]++;
		ans=max(ans,cnt[getfa(i)]);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 10740
let m = 1000000007
let ( +^ ) x y = (x + y) mod m

module StringMap = Map.Make (String)

let () = Scanf.scanf "%d" @@ fun n ->
  let dp = Array.make (n + 1) StringMap.empty in
  dp.(3) <-
    List.fold_left (List.fold_left (List.fold_left (List.fold_left (fun m s -> StringMap.add s 1 m)))) StringMap.empty @@
    List.map (fun c1 ->
      List.map (fun c2 ->
        List.map (fun c3 ->
          if
            c1 = 'A' && c2 = 'G' && c3 = 'C' ||
            c1 = 'A' && c3 = 'G' && c2 = 'C' ||
            c2 = 'A' && c1 = 'G' && c3 = 'C'
          then []
          else [String.init 3 (function 0 -> c1 | 1 -> c2 | 2 -> c3)])
      ['A'; 'C'; 'G'; 'T']) ['A'; 'C'; 'G'; 'T']) ['A'; 'C'; 'G'; 'T'];
  for i = 4 to n do
    dp.(i) <- StringMap.fold (fun s n ->
      List.fold_right (fun c m ->
        if 
          s.[1] = 'A' && s.[2] = 'G' && c = 'C' ||
          s.[0] = 'A' && s.[2] = 'G' && c = 'C' ||
          s.[2] = 'A' && s.[1] = 'G' && c = 'C' ||
          s.[0] = 'A' && s.[1] = 'G' && c = 'C' ||
          s.[1] = 'A' && c = 'G' && s.[2] = 'C'
        then m
        else
          let s' = String.sub s 1 2 ^ String.make 1 c in
          StringMap.add s' (n +^ try StringMap.find s' m with Not_found -> 0) m) ['A'; 'C'; 'G'; 'T']) dp.(i - 1) StringMap.empty
  done;
  Printf.printf "%d\n" @@ StringMap.fold (fun _ -> ( +^ )) dp.(n) 0


Measured memory_bytes: 4736
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        
        //面積
        int area = a * b;
        //周囲
        int circumference = 2*(a+b);
        
        System.out.println(area + " " + circumference);
    }
}


Measured memory_bytes: 26000
A, B, C = sorted(list(map(int, input().split())))

p = (C - A) % 2
q = (C - B) % 2

if p == 0 and q == 0:
    print(int((C-A)/2 + (C-B)/2))
elif p != 0 and q != 0:
    A += 1
    B += 1
    print(int((C-A)/2 + (C-B)/2) + 1)
elif p != 0 and q == 0:
    C += 1
    A += 2
    B += 1
    print(int((C-A)/2 + (C-B)/2) + 2)
else:
    C += 1
    A += 1
    B += 2
    print(int((C-A)/2 + (C-B)/2) + 2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	string str;
	cin >> str;
	ll ans = 0;
	for (auto& x : str) {
		ans += x - '0';
	}
	if (ans % 9 == 0) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3748
n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999
# print(a)
l = 0
r = sum(a)
for i in range(n):

    if i == 0:
        if a[i] == 1:
            r -= a[i]
            a[i] = 0
        else:
            a[i] = 1
        l = 0
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    # print(i,l,r,ans)
print(ans)



Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  cout<<A.at(N-1)-A.at(0)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{

 string str;
 cin>>str;
 long long sum=-48*str.length();
 int i=0;
 while(str[i]!='\0')
  {
  sum+=str[i];
  ++i;
  }
if(sum%9==0)cout<<"Yes";
else
cout<<"No";

return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define LL long long
#define N 100010
using namespace std;
int n,m,cnt[N],id[N];
long long a[N];
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++) {
        if (a[i]!=a[i-1]) id[++m]=i;
        cnt[m]++; 
    }
    for (int i=m;i>=1;i--) if (cnt[i]>=2) {
        if (cnt[i]>=4) {
            printf("%lld\n",a[id[i]]*a[id[i]]);
            return 0;
        }
        for (int j=i-1;j>=1;j--) if (cnt[j]>=2){
            printf("%lld\n",a[id[i]]*a[id[j]]);
            return 0;
        }
        printf("0\n");
        return 0;
    }
    printf("0\n");
    return 0;
}

Measured memory_bytes: 1792
/*
	申明：本代码只供学习参考，
	请勿同学抄袭或直接复制代码。
	如发现同学抄袭，必须追究责任！ 
	by 李沐阳
	防伪标识符ppp?!end---%%%&%%%---if!?qqq 
*/
#include <bits/stdc++.h>
using namespace std;
typedef int Int;
#define int long long
using namespace std;
int k[1000001];
#define SUM(i,j) (k[j]-k[i-1])
Int main()
{
	int n;
	cin >> n;
	int num[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>num[i];
		k[i]=k[i-1]+num[i];
	}
	int minv=0x7fffffffff, l1=1, l2=2;
	int ans[4]={0,0,0,0};
	for(int i=2;i<n-1;i++)
	{
		while(l1<i && abs(SUM(1,l1)-SUM(l1+1,i))>=abs(SUM(1,l1+1)-SUM(l1+2,i)))l1++;
		while(l2<n && abs(SUM(i+1,l2)-SUM(l2+1,n))>=abs(SUM(i+1,l2+1)-SUM(l2+2,n)))l2++;
		ans[0]=SUM(1,l1); 
		ans[1]=SUM(l1+1,i);
		ans[2]=SUM(i+1,l2);
		ans[3]=SUM(l2+1,n); 
		sort(ans,ans+4);
		minv=min(minv,ans[3]-ans[0]);
	}
	cout<<minv<<endl;
	return 0;
}





























































































































































































//防伪标识符：ppp?!end---%%%&%%%---if!?qqq 


Measured memory_bytes: 3328
#include <stdio.h>

int main()
{
	int n,i;
	int a[100000],b[100000];
	int sa,sb;
	while(1){	
		sa=0,sb=0;		
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a[i],&b[i]);
			if(a[i]>b[i])sa+=a[i]+b[i];
			else if(a[i]<b[i])sb+=a[i]+b[i];
			else sa+=a[i],sb+=b[i];
		}
		printf("%d %d\n",sa,sb);
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front 
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define int long long int

void solve(){
    string s;
    cin >> s;
    cout << s;
    if(s[s.size()-1] == 's'){
        cout << "es" << nl;
    }
    else cout << "s" << nl;
}
main()
{
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
	int T = 1;
    // cin >> T;
    fo(c, 1, T){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}

Measured memory_bytes: 3616
import sys

sys.setrecursionlimit(200000)
#深さ優先探索
N = int(input())
*H, = map(int, input().split())

dp = [-1]*N

def dfs(n):#nまでにたどり着くにに必要なコスト
    if dp[n]!=-1:
        return dp[n]
    if n==0:
        return 0
    if n-1==0:
        return abs(H[n]-H[n-1])
    ret = min(abs(H[n]-H[n-1])+dfs(n-1), abs(H[n]-H[n-2])+dfs(n-2))
    dp[n] = ret

    return ret

print(dfs(N-1))

Measured memory_bytes: 97072
#include <bits/stdc++.h>
using namespace std;
int k;
int main()
{
	cin >> k;
	if (k <= 500)
	{
		cout << k << endl;
		for (int i = 1; i <= k; i++, cout << endl)
			for (int j = 1; j <= k; j++)
			{
				printf("%d", i);
				if (j != k)putchar(' ');
			}
	}
	else
	{
		int n = ((k + 3) / 4) * 2;
		cout << n << endl;
		for (int i = 1; i <= n; i++, cout << endl)
			for (int j = 1; j <= n; j++)
			{
				int res = (i + j) % n + (i & 1 ? 0 : n) + 1;
				if (res > k) res -= n;
				printf("%d", res);
				if (j != k)putchar(' ');
			}
	}
	return 0;
}

Measured memory_bytes: 1152
/*
    Author:    DreamCat4er
    Created:   22.08.2020 18:18:22
*/
#include <bits/stdc++.h>
using namespace std;

void solve() {
    string s;
    cin >> s;                            
    int sum = 0;
    for (int i = 0; i < (int)(s.size()); ++i)
        sum += (s[i] - '0');

    cout << (sum % 9 ? "No\n" : "Yes\n");
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifdef _LOCAL
        int t;
        cin >> t;
        for (int _t = 0; _t < t; ++_t) {
            cout << "Case " << _t << " :\n";
            solve();
            cout << "\n";
        }
    #else
        solve();
    #endif // _LOCAL

    return 0;
}

Measured memory_bytes: 3720
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if (i + j) % 2 == 0:
                print('#', end="")
            else:
                print('.', end="")
        print()
    print()


Measured memory_bytes: 7000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int a,b;
    cin >> a >> b;
    long long int aa = a, bb = b;
    map<long long int ,long long int> mpa,mpb;
    long long int divi = 2;
    while(aa!=1&&bb!=1&&sqrt(max(aa,bb)+10000)>=divi){
        while(aa%divi==0){
            aa /= divi;
            mpa[divi]++;
        }
        
        while(bb%divi==0){
            bb /= divi;
            mpb[divi]++;
        }

        divi++;
    }
    if(aa!=1){
        mpa[aa]++;
    }
    
    if(bb!=1){
        mpb[bb]++;
    }
    long long int result = 1;
    for(auto x:mpa){
        if(mpb[x.first]){
            result++;
        }
    }
    cout << result << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    if (b % a == 0)
        cout << a + b << endl;
    else
        cout << b - a << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np

#  = int(input())
n, m = map(int, input().split())
s = input()
t = input()
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

g = gcd(n, m) 
a = n // g
b = m // g
for i in range(g):
    if s[i*a] != t[i*b]:
        print(-1)
        break
else:
    print(n * m // g)


Measured memory_bytes: 3700