akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;

int sec(int h,int m,int s){
	return (h*60+m)*60+s;
}
int main(){
	int n;
	while(cin>>n,n){
		map<int,int> mp;
		map<int,int>::iterator it;
		int ans=0;
		for(int i=0;i<n;i++){
			int h,m,s;
			scanf("%d:%d:%d",&h,&m,&s);
			++mp[sec(h,m,s)];
			scanf("%d:%d:%d",&h,&m,&s);
			--mp[sec(h,m,s)];
		}
		int use=0;
		for(it=mp.begin();it!=mp.end();++it){
			use += it->second;
			ans = max(ans,use);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2008
import heapq
H, W = map(int, input().split())
area = ['#']*(W+2)
for i in range(H):
    area += ['#']+list(input())+['#']
area += ['#']*(W+2)
H+=2
W+=2
move = [-1, 1, W, -W]
ans = 0
for i in range(H):
    for j in range(W):
        st = W*i+j
        if area[st]=='#': continue
        hq = []
        dist = [-1]*(H*W)
        dist[st] = 0
        heapq.heappush(hq, (0, st))
        while hq:
            cost, now = heapq.heappop(hq)
            for dx in move:
                nxt = now+dx
                if dist[nxt]>=0 or area[nxt]=='#': continue
                dist[nxt] = dist[now] + 1
                ans = max(ans, dist[nxt])
                heapq.heappush(hq, (dist[nxt], nxt))
print(ans)

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr int MAX = 1e5 + 1;

std::vector<int> g[2][MAX]; //0:x,1:y
bool used[MAX];

std::set<int> set[2];

void dfs(bool xy, int v)
{
    if (xy == 0)
        used[v] = 1;
    set[xy].insert(v);

    for (auto to : g[xy][v])
    {
        if (!set[!xy].count(to))
        {
            dfs(!xy, to);
        }
    }
}

int main()
{
    int n;

    std::cin >> n;

    std::vector<int> xs;

    rep(i, n)
    {
        int x, y;
        std::cin >> x >> y;
        xs.push_back(x);

        g[0][x].push_back(y);
        g[1][y].push_back(x);
    }

    std::sort(rag(xs));
    xs.erase(std::unique(rag(xs)), std::end(xs));

    ll ans = 0;

    rep(i, xs.size())
    {
        if (used[xs[i]])
            continue;
        dfs(0, xs[i]);
        ans += (ll)set[0].size() * (ll)set[1].size();
        set[0].clear();
        set[1].clear();
    }

    std::cout << ans - n << std::endl;

    return 0;
}

Measured memory_bytes: 19888
n, k = map(int, input().split())
a_ls = list(map(int, input().split()))

my_dict = dict()

ptr = 0
cnt = 0

while True:
    if ptr in my_dict:
        break
    else:
        my_dict[ptr] = cnt
        cnt += 1
        ptr = a_ls[ptr] - 1

loop = cnt - my_dict[ptr]

if k > 2 * 10 ** 5:
    k = k % loop + loop * (10 ** 6 // loop)

ptr = 0

for i in range(k):
    ptr = a_ls[ptr] - 1

print(ptr + 1)


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


int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for(int i = 0; i < N; ++i) {
		if(A[i]%2==0){
			if(A[i]%3!=0&&A[i]%5!=0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
}












Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = ReadLine();
        if (N.Length == 1) WriteLine(N);
        else if (N.Count(x => x == '9') == N.Length) WriteLine(N.Select(x => int.Parse(x + "")).Sum());
        else if (N.First() != '9' && N.Count(x => x == '9') == N.Length - 1) WriteLine(N.Select(x => int.Parse(x + "")).Sum());
        else
        {

            WriteLine(((int.Parse(N.First() + "") - 1).ToString() + "99999999999999999999999999999999999999999999".Substring(0, N.Length - 1)).Select(x => long.Parse(x + "")).Sum());
        }
    }
}

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

#define josh 0
#define ll long long
#define llu long long unsigned
#define ii pair<int ,int>
#define iii pair<int, ii>
#define all(v) (v).begin(), (v).end()
#define vout(v) for(auto i:v)cout<<i<<" "; cout<<endl;
#define loop(x, n, p) for(int i=x; p>0 ? i<n : i>=n; i+=p)
#define deb(x) cout<<#x<<" "<<x<<endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define file(x) if(x=="in")freopen("input.txt", "r", stdin); \
                else{freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}



template <typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template <typename T>
T get(T& a){
    read(a);
    return a;
}



struct Converter{
template<typename T>
    T toNum(string s, T& n){
        stringstream ss; ss<<s;
        ss>>n;
        return n;
    }
template <typename T>
    string toString(T& n){
        stringstream ss; ss<<n;
        string s; ss>>s;
        return s;
    }

}convert;

struct Prime{

    bool isPrime[10000007]={0};
    std::vector<int> primeContain;

    void sieve(int n){

        memset(isPrime, true, sizeof(isPrime));

        for (int p=2; p*p<=n; p++){
            if (isPrime[p] == true){
                for (int i=p*p; i<=n; i += p)
                    isPrime[i] = false;
            }
        }
        isPrime[0]=0, isPrime[1]=0;
        loop(2, n+7, 1)
            if(isPrime[i])
                primeContain.push_back(i);

    }


    bool primeDigit(int n){
        while(n){
            int t=n%10;
            if(t!=2 && t!=3 && t!=5 && t!=7)
                return false;
            n/=10;
        }
        return true;
    }


}prime;


struct Algo{

    int josephusDP[100005];

    int josephus(int n, int k){ //O(N)
        if(josephusDP[n]!=-1)return josephusDP[n];
        if(n==1)return 1;  ///return 0;  //for 0 based
        return josephusDP[n] = (josephus(n-1, k)+k-1)%n+1;   ///return (josephus(n-1, k)+k)%n;  //for 0 based
    }

}algo;


void cppCheck(){
    if( __cplusplus == 201103L ) std::cout << "C++11\n" ;
    else if( __cplusplus == 199711L ) std::cout << "C++98\n" ;
    else std::cout << "pre-standard C++\n" ;
}


/*................................let's do it bitch............................................*/








int main(){

    string s; cin>>s;
    ll sum=0;
    loop(0, s.size(), 1){
        sum+=s[i]-'0';
    }
//    deb(sum)
    printf(sum%9==0 ? "Yes" : "No");


return josh;
}















Measured memory_bytes: 13552
import numpy as np
n, k = map(int, input().split())
P = np.array([0] + list(map(int, input().split())))
C = np.cumsum(P)
#print(C)
M = 0
for i in range(n - k + 1):
    #print(C[i + k],C[i])
    M = max(M, C[i + k] - C[i])

ans = (M + k) / 2
print(ans)


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

#define INF 1000050000

int main()
{
	int n;
	int h[100005];
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	int dp[100005][2];
	for(int i = 1; i < n; i++) {
		dp[i][0] = INF;
		dp[i][1] = INF;
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	for(int i = 0; i < n-1; i++) {
		dp[i+1][0] = min(dp[i+1][0], min(dp[i][0], dp[i][1])+abs(h[i+1]-h[i]));
		if(i+2>=n)continue;
		dp[i+2][1] = min(dp[i+2][1], min(dp[i][0], dp[i][1])+abs(h[i+2]-h[i]));
	}
	printf("%d\n", min(dp[n-1][0], dp[n-1][1]) == -1?0:min(dp[n-1][0], dp[n-1][1]));
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll n; cin >> n;
  vll a(n); rep(i, n) cin >> a[i];
  vll P;
  map <ll, ll> ans;
  rep(i, n)
  {
    if(ans.count(a[i]))
    {
      P.push_back(a[i]);
      ans.erase(a[i]);
    }
    else
    {
      ans[a[i]];
    }
  }
  sort(all(P)); reverse(all(P));
  if(P.size() >= 2)
  {
    cout << P[0] * P[1] << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 7296
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String C = sc.next();
		int count = 1;
		for (int i = 1; i < C.length(); i++) {
			if (!C.substring(i - 1, i).equals(C.substring(i, i + 1))) count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 36112
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

void dfs(Graph &G, int p, int v, vector<int> &ans, priority_queue<int> &c) {
	ans[v] = c.top();
	c.pop();

	for(auto nv : G[v]) {
		if(nv==p) continue;
		dfs(G, v, nv, ans, c);
	}
}

int main() {
	int N;
	cin >> N;
	Graph tree(N);
	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		tree[a-1].push_back(b-1);
		tree[b-1].push_back(a-1);	
	}
	priority_queue<int> c;
	int c_max = 0;
	int c_sum = 0;
	rep(i, N) {
		int tmp;
		cin >> tmp;
		c.push(tmp); // 降順
		if(c_max<tmp) c_max = tmp;
		c_sum += tmp;
	}
	
	vector<int> ans(N);

	dfs(tree, -1, 0, ans, c);

	cout << (c_sum - c_max) << endl;
	rep(i, N) {
		cout << ans[i] << ' ';
	}
	cout << endl;
	
	return 0;
}

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

int main(void) {
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (S == U) {
        --A;
    } else {
        --B;
    }
    printf("%d %d\n", A, B);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  int S1 = 0;
  int ans = sum;
  for (int i = 0; i < N; i++) {
    S1 += vec.at(i);
    ans = min(ans, abs(S1-(sum-S1)));
  }
  cout << ans;
}


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

#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rnd(time(0));
#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("avia.in", "r", stdin); freopen("avia.out", "w", stdout);
#define _GLIBCXX_DEBUG
//#define s second
//#define f first
#define pb push_back
#define add insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pii pair<int,int>
#define res resize
#define NO cout<<"NO"<<'\n'; return;
#define YES cout<<"YES"<<'\n'; return;
#define PI acos(-1)
#define gggg cout << "NO";return;
const ll INF = 1e9;//9223372036854775807L; //LONG_MAX;
constexpr ll mod = 1e9 + 7;


void solve() {
    string x;
    cin >> x;
    int ans = 0;
    for (int i = 0; i < x.size(); i++) {
        if (x[i] != x[x.size() - i - 1] && i != x.size() - i - 1){
            ans++;
        }
    }
    cout<<ans/2<<'\n';
}

signed main() {
    ioss
    //file
    //id.resize(3e5);
    int t = 1;                                                                                                                                                                        //ll
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}




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

int main(){
  ll N;
  cin>>N;
  
  string ans="";
  while(N){
    N-=1;
    ans.push_back('a'+N%26);
    N/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}

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

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

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

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i=0; i<n; i++) {
        ll x;
        cin >> x;
        x--;
        a[x]++;
    }

    sort(a.begin(), a.end());
    auto it = upper_bound(a.begin(), a.end(), 0ll);

    ll r = 0;
    while(a.end() - it > k)
        r += *it++;
    cout << r << endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env ruby
# require 'pry'

input = gets.chomp[-1].to_i

hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]

if bon.include?(input)
  puts 'bon'
elsif pon.include?(input)
  puts 'pon'
else
  puts 'hon'
end


Measured memory_bytes: 14304
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <climits>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int main() {
    string s = In<string>(), t = In<string>();
    auto dp = Vec2<int>(s.length() + 1, t.length() + 1, 0);
    for(int i = 0; i < s.length(); i++){
        for(int j = 0; j < t.length(); j++){
            dp[i + 1][j + 1] = (s[i] == t[j]) ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]);
        }
    }
    string ans = "";
    int sc = s.length(), tc = t.length();
    while(sc>0 && tc>0){
        if(dp[sc][tc] == dp[sc][tc-1])
            tc--;
        else if(dp[sc][tc]==dp[sc-1][tc])
            sc--;
        else{
            tc--;
            sc--;
            ans = s[sc] + ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3000 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll INF = 1e18, inf = 1e15;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int dp[maxn][maxn];
int a, b, c, d;
 
void solve() {
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i < maxn; ++i) {
        for (int j = b; j < maxn; ++j) {
            dp[i][j] += dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1) % mod + mod;
            dp[i][j] %= mod;  
        }
    }    
    cout << dp[c][d]; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 74140
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    int n;
    string s, t;
    cin>>n>>s>>t;
    for(int i=0;i<n;i++){
        //cout<<"s.sustr(i)="<<s.substr(i)<<endl;
        //cout<<"t.substr(0, n-i)="<<t.substr(0, n-i)<<endl;
        if(s.substr(i) == t.substr(0, n-i)){
            cout<<i+n<<endl;
            return 0;
        }
    }
    cout<<2*n<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, d, e, ans;
    while(cin >> a >> b)
    {
        c = a + b;
        d = a - b;
        e = a * b;

        ans = max(max(c, d), e);
        cout << ans << endl;
    }
}


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

int main(){
    vector<int> ans;
    for(int i = 1; i < 500; i++){
        ans.push_back(i * i);
    }

    string a, b;
    cin >> a >> b;
    string c = a + b;
    int num = stoi(c);

    for(int i = 0; i < 500; i++){
        if(ans[i] == num){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
string s;
int main(){
	cin>>s;
	int a=0,b=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A')a++;
		else  b++;
	}
	if(a&&b)puts("Yes");
	else puts("No");
	return 0;
}


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

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

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

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

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

    // 素数である
    return 1;
}

   

int main(){
    lint N,y=50;
    cin>>N;
      lint g=N;
    g/=10;
    while(1){
        if(N<y)break;
        g+=N/y;
        y*=5;
    }
    if(N%2==1)cout<<0;
    else cout<<g;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long T = 1;
		long A = 1;
		for (int i = 0; i < n; i++) {
			long t = sc.nextLong(), a = sc.nextLong();
			long x = Math.max(div_ceil(T, t), div_ceil(A, a));
			T = t*x;
			A = a*x;
		}
		System.out.println(T+A);
		sc.close();
	}
	public static long div_ceil(long a, long b) {
		return (a+b-1)/b;
	}
}

Measured memory_bytes: 24416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
	    String[] inputs = Io.read();

        int[] a = parse(inputs[1]);

        int min = Arrays.stream(a).min().getAsInt();
        int max = Arrays.stream(a).max().getAsInt();

        Io.write(max - min);
    }

    private static int[] parse(String line) {
        String[] split = line.split(" ");
        int[] parsed = new int[split.length];

        for (int i = 0; i < split.length; i++) {
            parsed[i] = Integer.parseInt(split[i]);
        }
        return parsed;
    }
}

class Io {

    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    public static void write(int answer)
    {
        System.out.println(answer);
    }
}

Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Complex = complex<double>;
const double PI = acos(-1);

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N), P_(N), Q_(N);
    for (int i = 0; i < N; ++i) {
        int p;
        cin >> p;
        P[i] = P_[i] = p;
    }
    for (int i = 0; i < N; ++i) {
        int p;
        cin >> p;
        Q[i] = Q_[i] = p;
    }

    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());

    int i = 1, ans = 0;
    do {
        bool flag = true;
        for (int j = 0; j < N; ++j) {
            if (P[j] != P_[j]) {
                flag = false;
                ++i;
                break;
            }
        }
        if (flag) {
            ans += i;
            break;
        }
    } while (next_permutation(P.begin(), P.end()));

    i = 1;
    do {
        bool flag = true;
        for (int j = 0; j < N; ++j) {
            if (Q[j] != Q_[j]) {
                flag = false;
                ++i;
                break;
            }
        }
        if (flag) {
            ans -= i;
            break;
        }
    } while (next_permutation(Q.begin(), Q.end()));

    cout << abs(ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>

typedef struct {
	long long x;
	long long y;
}posi_t;

typedef struct {
	long long p;
	long long q;
}pair_t;

int cmp(const void* a, const void* b) {
	if (((pair_t*)a)->p - ((pair_t*)b)->p != 0)
		return ((pair_t*)a)->p - ((pair_t*)b)->p;
	else
		return ((pair_t*)a)->q - ((pair_t*)b)->q;
}

int main(void) {
	long long n;
	posi_t posi[50] = { 0 };
	pair_t pair[2500] = { 0 };
	int cnt = 0, max = 1;
	int temp = 1;

	scanf("%lld", &n);
	for (int i = 0; i < n; i++) 
		scanf("%lld %lld", &posi[i].x,&posi[i].y);

	if (n <= 2)printf("1");
	else {
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				pair[cnt].p = posi[i].x - posi[j].x;
				pair[cnt].q = posi[i].y - posi[j].y;
				if (pair[cnt].p < 0)
					pair[cnt].p *= -1, pair[cnt].q *= -1;
				else if (pair[cnt].p == 0 && pair[cnt].q < 0)
					pair[cnt].q *= -1;
				cnt++;
			}
		}
		qsort(pair, cnt, sizeof(pair_t), cmp);
		for (int i = 0; i <= cnt; i++) {
			if ((pair[i].p != 0 || pair[i].q != 0)&&pair[i].p == pair[i + 1].p &&
					pair[i].q == pair[i + 1].q)
					temp++;
			else {
				if (max < temp) {
					max = temp;
				}
					temp = 1;
				
			}
		}
		printf("%lld", n - max);
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  stable_sort(s.begin(), s.end());
  stable_sort(t.begin(), t.end(), greater<char>());

  if(s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


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

int f(int a){
	int ret = 0;
	while(a){
		ret += a%10;
		a /= 10;
	}
	return ret;
}

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	int sum = 0;
	for(int i = 1;i <= n;i++){
		if(f(i) >= a && f(i) <= b) sum+= i;
	}
	cout << sum << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
//デキューを使うと両端に追加していける
int main() {

    ll N; cin >> N;
    
    deque<ll > deq;

    for(ll i = 0; i < N; i++){
        ll n; cin >> n;
        if(i % 2 == 0){
            if(N % 2 == 0) deq.push_back(n);
            else deq.push_front(n);
        }else{
            if(N % 2 == 0) deq.push_front(n);
            else deq.push_back(n);
            
        }
    }

    for_each(deq.begin(), deq.end(), [](int x) {
        cout << x << " ";
    });

}

Measured memory_bytes: 3840
k = int(input())
 
def gcd2(a,b):
    if b == 0:
        return a
    return gcd2(b,a%b)

def gcd3(a,b,c):
    return gcd2(gcd2(a,b), c)

ans = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b, k+1):
            if a == b == c:
                ans += gcd3(a,b,c)
            elif a == b or b == c:
                ans += gcd3(a,b,c)*3
            else:
                ans += gcd3(a,b,c)*6

print(ans)

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 1)
        cout << "Borys" << endl;
    else
        cout << "Alice" << endl;
}


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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int ans = 0;
  string S; cin>>S;
  int i	= 0, j = S.length() - 1;
  while(i < j) {
    if(S[i] != S[j]) ans++;
    //    cout << i << j << ans << endl;                                                                     
    i++; j--;
  }

  cout << ans << endl;
  return 0;
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)-form-)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };


inline int ri() { int in; int y = scanf("%d", &in); return in; }
inline LL rl() { LL in; int y = scanf("%lld", &in); return in; }
inline void oi(int i) { printf("%d\n", i); }
inline void od(double i) { printf("%.9f\n", i); }


int main() {
	string s; cin >> s;
	bool ok = 1;
	ok &= s.front() == '1';
	ok &= s.back() == '0';
	FOR(i, 1, SZ(s) / 2) {
		int j = SZ(s) - i - 2;
		ok &= s[i] == s[j];
	}
	// 対称っぽいかんじになる
	int N = SZ(s);
	VVI G(N);
	queue <int>q;
	auto insert_edge = [&](int to) {
		while (!q.empty()) {
			int a = q.front(); q.pop();
			G[to].push_back(a);
		}
	};
	FOR(i, 0, N - 1) {
		if (s[i] == '1') {
			insert_edge(i);
		}
		q.push(i);
	}
	insert_edge(N - 1);

	if (!ok) {
		cout << -1 << endl;
		return 0;
	}
	else {
		FOR(i, 0, N) {
			for (auto nx : G[i]) {
				printf("%d %d\n", i + 1, nx + 1);
			}
		}
	}

}

Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair <int, int>;
using vii = vector <pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int a[N];
multiset <int> S;

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n;
    cin>>n;

    for(int i = 0; i < n; i++) {
        cin>>a[i];
        S.insert(a[i]);
    }

    int ans = 0;
    while(!S.empty()) {
        auto it = prev(S.end());
        int x = *it;
        S.erase(it);
        for(int i = 0; i <= 32; i++) {
            int y = (1LL<<i) - x;
            if(S.find(y) != S.end()) {
                S.erase(S.find(y));
                ans++;
                break;
            }
        }
    }

    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>

#define fori(x) for(int i=0;i<x;++i)

// cout << fixed << setprecision(10) << num << endl;

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  int h[220000];
  fori(n)cin>>h[i];
  
  sort(h,h+n,greater<int>());
    
  long long i=0,s=0,t=0;
  for(i=0;i<n;++i){
      if(k>0){
          --k;
          ++t;
          continue;
      }else{
          s+=h[i];
          ++t;
      }
  }
    cout<<i+s-t;
  return 0;
}

Measured memory_bytes: 1024
if __name__ == '__main__':
    n = int(input())

    min_count = n
    for i in range(0, n + 1):
        count = 0

        # pay i yen by 6^p
        t = i
        while t > 0:
            count += t % 6
            t //= 6

        t = n - i
        # pay n - i yen by 9^p
        while t > 0:
            count += t % 9
            t //= 9

        if count < min_count:
            min_count = count

    print(min_count)


Measured memory_bytes: 3060
while True:
    n,big,small = map(int,input().split(" "))
    if n == 0:
        break
    points = []
    for i in range(n):
        points.append(int(input()))

    results = []
    for i in range(big,small+1):
        results.append(points[i-1] - points[i])

    ameba = len(results)
    for i in range(ameba):
        if results[ameba-1-i] == max(results):
            print(ameba-i+big-1)
            break



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505

#define mod 998244353

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

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

ll bexp(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		b >>= 1;
	}
	return res % mod;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	map<ll, ll> mi;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		mi[a[i]]++;
	}
	// cout << mi.size() << "\n";
	int f = 0;
	if(mi.find(0) != mi.end() && mi[0] == n)
	{
		cout << "Yes\n";
		return 0;
	}

	if(n % 3 != 0)
	{
		cout << "No\n";
		return 0;
	}
	vector<ll> al;
	if(mi.size() == 2)
	{
		ll k1 = mi.begin()->ff, l1 = mi.begin()->ss,
		k2 = mi.rbegin()->ff, l2 = mi.rbegin()->ss;
		
		for(auto e : mi)
		{
			for (int i = 0; i < e.ss/(n/3); ++i)
			{
				al.pb(e.ff);
			}
		}
		if(al.size() == 3 && (al[0] ^ al[1] ^ al[2]) == 0)
		{
			f = 1;
		}
	}
	else if(mi.size() == 3)
	{
		ll b[3] = {}, i = 0;
		for(auto e : mi)
		{
			b[i++] = e.ff; 
		}

		if(((b[0] ^ b[1]) == b[2]) && (mi[b[0]] == mi[b[1]]) && (mi[b[0]] == mi[b[2]]))
			f = 1;
	}

	if(f)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
 
 
int main() {
 
 
    string str;
    cin>>str;
    sort(str.begin(), str.end());
 
    if (str[0] == str[1] && str[2] == str[3] && str[1] != str[2]){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
 
    
}

Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=200000+100;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline 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;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int getinv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	void math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=getinv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int n,a[N];
ll sum[N];

ll calc(int l,int r) {return sum[r]-sum[l-1];}

int main()
{
	n=read();
	rep(i,1,n) a[i]=read();
	rep(i,1,n) sum[i]=sum[i-1]+a[i];
	int l=1,r=3;
	ll ans=1e18;
	rep(i,2,n-2)
	{
		while ((l+2<=i) && (abs(calc(1,l)-calc(l+1,i))>abs(calc(1,l+1)-calc(l+2,i)))) l++;
		while ((r+2<=n) && (abs(calc(i+1,r)-calc(r+1,n))>abs(calc(i+1,r+1)-calc(r+2,n)))) r++;
		ll mx=0,mn=1e18,x;
		x=calc(1,l);mx=max(mx,x);mn=min(mn,x);
		x=calc(l+1,i);mx=max(mx,x);mn=min(mn,x);
		x=calc(i+1,r);mx=max(mx,x);mn=min(mn,x);
		x=calc(r+1,n);mx=max(mx,x);mn=min(mn,x);
		ans=min(ans,mx-mn);
	}
	printf("%lld\n",ans);
	return 0;
}
	



Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    int ans = 1e8;
    for ( int i = 1; i < n; ++i ) {
        int a = i;
        int b = n - i;
        int sum = 0;
        while(1) {
            if ( a == 0 ) break;
            sum += a%10;
            a /= 10;
        }
        while(1) {
            if ( b == 0 ) break;
            sum += b%10;
            b /= 10;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


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

#define fast       ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define fs          first
#define sc          second
#define pb         push_back
#define nl          '\n'
#define all(a) a.begin(),a.end()

#define REP(i,start,end) for (int i = start; i <=end; i++)
#define RREP(i,end,start) for (int i=end; i>=start ;i--)

typedef long long LL;

class seq{
    public:
    int low, high, bal, id;
    seq(int a,int b, int c,int d)
    {
        low=a;
        high=b;
        bal=c;
        id=d;
    }
};

bool custom(seq a , seq b)
{
    if(a.low==b.low)
        return a.bal>b.bal;
    return a.low<b.low;
}
bool custom2(seq a , seq b)
{
    if(a.high==b.high)
        return a.bal<b.bal;
    return a.high<b.high;

}
void solve()
{
    int n;
    cin>>n;
    vector<seq> vect1,vect2;
    REP(i,1,n)
    {
        string s;
        cin>>s;
        int low=0;
        int high=0;
        int bal=0;
        REP(j,0,s.size()-1)
        {
            bal+=(s[j]=='(');
            bal-=(s[j]==')');
            low=min(low,bal);
        }
        bal=0;
        RREP(j,s.size()-1,0)
        {
            bal-=(s[j]=='(');
            bal+=(s[j]==')');
            high=min(high,bal);
        }
        seq sq(-low,-high,-bal,i);
        if(bal<0)
            vect1.pb(sq);
        else
            vect2.pb(sq);
    }
    sort(all(vect1), custom);
    sort(all(vect2), custom2);
    int bal=0;
    if(vect1.size()>=1)
    {
        REP(i,0,vect1.size()-1)
        {
            if(vect1[i].low>bal)
            {
                cout<<"No"<<nl;
                return;
            }
            bal+=vect1[i].bal;
            
        }
    }
    int bal2=0;
    if(vect2.size()>=1)
    {
        REP(i,0,vect2.size()-1)
        {
            if(vect2[i].high>bal2)
            {
               
                cout<<"No"<<nl;
                return;
            }
            bal2-=vect2[i].bal;
        }
    }
    if(bal==bal2)
    {
        cout<<"Yes"<<nl;
    } 
    else
        cout<<"No"<<nl;
}
int main()
{
    fast;
        solve();
}


Measured memory_bytes: 18960
#include <stdio.h>

int main(){
	
	int r,c;
	
	scanf("%d %d",&r,&c);
	
	int a[r+1][c+1];
	
	int s,t;
	
	for(s=0;s<=r-1;s++){
        
		a[s][c]=0;
		
		for(t=0;t<=c-1;t++){
			
			scanf("%*c%d",&a[s][t]);
			
			a[s][c]+=a[s][t];
			
		}
		
	}
	
	int b,z;

	for(b=0;b<=c;b++){

	  a[r][b]=0;

	  for(z=0;z<=r-1;z++){

	    a[r][b]+=a[z][b];

	  }

	}
	
	int x,y;
	
	for(x=0;x<=r;x++){
		
		for(y=0;y<=c;y++){
			
			printf("%d",a[x][y]);
			
			if(y!=c)
			
				printf(" ");
			
		}
		
		printf("\n");
		
	}
	
	return 0;
	
}

Measured memory_bytes: 644
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    s = input()
    sl = [i for i in s]
    anslist = [sl[0]]
    n = len(s) - 1
    sublist = [-1]*n
    ans = []
    for i in range(1 << n):
        for j in range(n):
            if i >> j & 1:
                sublist[j] = "+"
        for j in range(n):
            if sublist[j] == "+":
                anslist.append("+")
                anslist.append(sl[j+1])
            else:
                anslist.append(sl[j+1])
        ans.append(eval("".join(anslist)))
        sublist = [-1]*n
        anslist = [sl[0]]
    print(sum(ans))
        
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 13640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#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<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  // https://atcoder.jp/contests/arc097/tasks/arc097_b
  int n,m; cin >> n >>m;
  vector<int> p(n);
  rep(i,n) {cin >> p[i]; p[i]--;}
  vector<pair<int,int>> xy(m);
  rep(i,m) {
    cin >> xy[i].first >> xy[i].second;
    --xy[i].first, --xy[i].second;
  }

  UnionFind uf(n);
  for(auto [x,y] : xy) uf.unite(x,y);

  int ans = 0;
  rep(i,n) ans += uf.find(i, p[i]);
  cout << ans << endl;
}


Measured memory_bytes: 4784
#include <iostream>
using namespace std;
int main()
{
  int a[5];
  for(int i=1;i<=5;i++){
    cin>>a[i];
  }
  int k;
  for(int i=1;i<=5;i++)
  {
    if(a[i]==0)
      k=i;
  }
  cout<<k;
  return 0;
}
 
 
 
  
  


Measured memory_bytes: 3560
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> ans = new ArrayList<Integer>();

        for (int i = 2; i < 300000; i++) {
            if (i % 7 == 1 || i % 7 == 6)
                list.add(i);
        }

        for (int i = 0; i < list.size(); i++) {
            for (int j = i + 1; j < list.size(); j++) {
                if (list.get(j) % list.get(i) == 0) {
                    list.remove(j);
                    j--;
                }
            }
        }

        while (true) {
            int MSPrime = s.nextInt();
            if (MSPrime == 1) break;

            ans.clear();


            for (int i = 0; i < list.size(); i++) {
                int temp = list.get(i);
                if (MSPrime % temp == 0)
                    ans.add(temp);
            }

            System.out.print(MSPrime + ":");
            for (int i = 0; i < ans.size(); i++) {
                System.out.print(" " + ans.get(i));
            }
            System.out.println();

        }
    }
}

Measured memory_bytes: 26768
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

// {{{
struct BIT2D{
    typedef vector<int> vec;
    vector<vec> sums;
    int H, W;

    BIT2D(int h, int w) : sums(h, vec(w)), H(h), W(w) {}

    // v[y][x] += w
    void add(int x, int y, char w) {
        for(int i = y; i < H; i |= i + 1) {
            for(int j = x; j < W; j |= j + 1) {
                sums[i][j] += w;
            }
        }
    }

    // for y in [0, b]:
    //     for x in [0, a]:
    //         ret += v[y][x]
    LL get(int a, int b) {
        LL res = 0;
        for(int i = b; i >= 0; i = (i & (i + 1)) - 1){
            for(int j = a; j >= 0; j = (j & (j + 1)) - 1){
                res += sums[i][j];
            }
        }
        return res;
    }
};
// }}}

// add (x, y, w)
// get(a, b) x in [0, a] y in [0, b]
int main(){
    iostream_init();
    int H, W, Q;
    while(cin >> H >> W >> Q) {
        string s[2021];
        REP(y, H) cin >> s[y];

        BIT2D bitedge(2*H+10, 2*W+10);
        BIT2D bitgrid(2*H+10, 2*W+10);
        REP(y, H) REP(x, W) if(s[y][x] == '1') {
            bitgrid.add(2*x, 2*y, 1);
            if(x + 1 < W && s[y][x+1] == '1') {
                const int bx = 2*x+1;
                const int by = 2*y;
                bitedge.add(bx, by, 1);
            }
            if(y + 1 < H && s[y+1][x] == '1') {
                const int bx = 2*x;
                const int by = 2*y + 1;
                bitedge.add(bx, by, 1);
            }
        }

        while(Q--) {
            int x1, y1, x2, y2;
            cin >> y1 >> x1 >> y2 >> x2;
            x1--; y1--; x2--; y2--;
            x1 *= 2;
            y1 *= 2;
            x2 *= 2;
            y2 *= 2;
            int edge_sum = 0;
            edge_sum += bitedge.get(x2, y2);
            edge_sum -= bitedge.get(x2, y1-1);
            edge_sum -= bitedge.get(x1-1, y2);
            edge_sum += bitedge.get(x1-1, y1-1);
            int grid_sum = 0;
            grid_sum += bitgrid.get(x2, y2);
            grid_sum -= bitgrid.get(x2, y1-1);
            grid_sum -= bitgrid.get(x1-1, y2);
            grid_sum += bitgrid.get(x1-1, y1-1);
            cout << grid_sum - edge_sum << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 133376
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
int n, a[3];
string s[100005];
vector<char> ans;
signed main()
{
	cin>>n>>a[0]>>a[1]>>a[2];
	for (int i=0;i<n;i++){
		cin>>s[i];
	}
	for (int i=0;i<n;i++){
		if (!a[s[i][0]-'A'] && !a[s[i][1]-'A']){
			cout<<"No";
			re 0;
		}
		else if (a[s[i][0]-'A']>a[s[i][1]-'A']){
			ans.pb(s[i][1]);
			a[s[i][0]-'A']--;
			a[s[i][1]-'A']++;
		}
		else if (a[s[i][0]-'A']<a[s[i][1]-'A']){
			ans.pb(s[i][0]);
			a[s[i][0]-'A']++;
			a[s[i][1]-'A']--;
		}
		else if (a[s[i][0]-'A']==a[s[i][1]-'A']){
			if (i==n-1 || s[i+1][0]==s[i][0] || s[i+1][1]==s[i][0]){
				ans.pb(s[i][0]);
				a[s[i][0]-'A']++;
				a[s[i][1]-'A']--;
			}
			else{
				ans.pb(s[i][1]);
				a[s[i][0]-'A']--;
				a[s[i][1]-'A']++;
			}
		}
		//cout<<a[0]<<' '<<a[1]<<' '<<a[2]<<endl;
	}
	cout<<"Yes"<<endl;
	for (int i=0;i<n;i++)
		cout<<ans[i]<<endl;
	re 0;
}

Measured memory_bytes: 6872