akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        //START

        Scanner scan=new Scanner(System.in);
        String str=scan.nextLine();

        String[] steps=str.split("");

        int i=0;
        int c=0;

        String strL="L";
        String strR="R";

        for(i=0;i<steps.length;i++){

            if(i%2==0){
                if(steps[i].equals(strL)){
                    System.out.println("No");
                    c=1;
                    break;
                }
            }else{
                if(steps[i].equals(strR)){
                    System.out.println("No");
                    c=1;
                    break;
                }
            }
        }

        if(c==0){
            System.out.println("Yes");
        }

        //END
    }
}



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

using namespace std;
using ll = long long int;

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

    vector<int> count(n);
    for (int i = 0; i < n - 1; i++)
    {
        int a;
        cin >> a;
        a--;
        count[a]++;
    }

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

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin>>n;
    vector<ll> b(n);
    for(i=0;i<n;i++){
        cin >> b[i];
    }
    ll bs=n;
    vector<ll> ret;
    while(bs>0){
        ll now = -1;
        for(i=0;i<bs;i++){
            if(i+1==b[i])now = i;
        }
        if(now>=0){
            ret.push_back(now+1);
            b.erase(b.begin()+now);
            bs--;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ret.begin(),ret.end());
    for(ll x:ret){
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int arr[26]={0}, c;
  while ((c=getchar())!=EOF) {
    if (c>='a' && c<='z') {
      arr[c-'a']++;
    } else if (c>='A' && c<='Z') {
      arr[c-'A']++;
    }
  }

  for (int i=0; i<26; i++) {
    printf("%c : %d\n", i+'a', arr[i]);
  }
  return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int X = in.nextInt();

            X -= A;

            System.out.println(X >= 0 && B >= X ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 27020
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int e,m,min,x,y,z;
  while(1){
    scanf("%d", &e);
    if(e==0)break;
    min = 10000000;
    for(y=0;y<=1000;y++){
      for(z=0;z<=100;z++){
	x = e-(y*y+z*z*z);
	if(x<0)continue;
	m = x+y+z;
	if(min > m){
	  min = m;
	}
      }
    }
    printf("%d\n", min);
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
using pii = pair<ll, ll>;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define ull unsigned long long
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))

///--------------Graph Moves--------------------------------------
///const ll fx[] = {+1,-1,+0,+0};
///const ll fy[] = {+0,+0,+1,-1};
///const ll fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const ll fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const ll fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const ll fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;

    ll n; cin >> n;
    for(ll i = 1; i <= 9; i++) {
        for(ll j = 1; j <= 9; j++) {
            if((i * j) == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
int a[8],b[8],c[16],d[16];
int e[8][8];
void dfs(int num)
{
    if(num==8)
    {
        for(int i=0; i<8; i++)
        {
            for(int j=0; j<8; j++)
            {
                if (e[i][j])
                {
                    if(a[i]!=j)
                        return;
                }
            }
        }
        for(int i=0; i<8; i++)
        {
            for(int j=0; j<8; j++)
            {
                if(a[i]==j)
                    printf("Q");
                else printf(".");
            }
            printf("\n");
        }
        return;
    }
    for(int j=0; j<8; j++)
    {
        if(b[j]==1||c[num+j]==1||d[num-j+7]==1)
            continue;
        a[num]=j;
        b[j]=c[num+j]=d[num-j+7]=1;
       dfs(num+1);
        a[num]=b[j]=c[num+j]=d[num-j+7]=0;
    }
}

int main()
{
    int n,m,t;
  while(~ scanf("%d",&t))
  {
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    memset(d,0,sizeof(d));
    memset(e,0,sizeof(e));
    for(int i=0; i<t; i++)
    {
        scanf("%d %d",&n,&m);
       e[n][m]=1;
    }
    dfs(0);}
    return 0;
}



Measured memory_bytes: 2128
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
ll po(ll n,ll m){
  ll res = 1;
  rep(i,m) res*= n;
  return res;
}
int main() {
	ll n, p, a;cin >> n >> p;bool b = true;
	rep(i, n) {
		cin >> a;
		if (a % 2 == 1) b = false;
	}
	if (b) {
		if (p) cout << 0 << endl;
		else cout << po(2, n) << endl;
	}
	else {
		cout << po(2,n - 1) << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

double maxv[50000];

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

    int n;
    cin >> n;
    vector<int> t(n + 1), v(n + 1);
    t[0] = 0, v[0] = 0;
    for(int i = 1; i <= n; ++i){
        cin >> t[i];
        t[i] <<= 1;
        t[i] += t[i - 1];
    }
    for(int i = 1; i <= n; ++i){
        cin >> v[i];
        maxv[t[i - 1]] += v[i];
        maxv[t[i]] -= v[i];
    }
    for(int i = 0; i < t[n]; ++i)   maxv[i + 1] += maxv[i];
    for(int i = 1; i + 1 <= n; ++i) maxv[t[i]] = min(v[i], v[i + 1]);
    maxv[0] = 0;
    for(int i = 0; i < t[n]; ++i)   chmin(maxv[i + 1], maxv[i] + 0.5);
    for(int i = t[n] - 1; i >= 0; --i)  chmin(maxv[i], maxv[i + 1] + 0.5);
    double ans = 0;
    for(int i = 0; i < t[n]; ++i)   ans += (maxv[i] + maxv[i + 1]) * 0.25;
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 3976
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char c[999999];
    int i, x;
    x = 0;
    while(scanf("%c", &c[x]))
    {
        if(c[x] == '\n')
        {
            break;
        }
        x++;
    }
    for(i = 0 ; i <= x ; i++)
    {
        if(c[i] >= 65 && c[i] <= 90)
        {
            c[i] += 32;
        }
        else if(c[i] >= 97 && c[i] <= 122)
        {
            c[i] -= 32;
        }
    }
    for(i = 0 ; i <= x ; i++)
    {
        printf("%c", c[i]);
    }
    return 0;
}



Measured memory_bytes: 2036
#include <vector>

template<class T, class E, class U, class To, class Adj, class Ope, class Merge>
std::vector<T> rerooting(const std::vector<std::vector<E>>& G, int r, U ide, To to, Adj adj, Ope ope, Merge merge) {
  int N = G.size();
  std::vector<T> tdp(N);
  std::vector<int> par(N, -1);
  std::vector<int> que(N);
  int qi = 0;
  que[qi++] = r;

  int MAX = 1;
  for(int i = 0;i < qi;i++) {
    int v = que[i];
    for(const auto& e: G[v]) {
      int t = to(e);
      if(t == par[v]) continue;
      par[t] = v;
      que[qi++] = t;
    }
    MAX = std::max(MAX, (int)G[v].size() + 1);
  }

  for(int i = qi; i --> 0;) {
    int v = que[i];
    U sum = ide;
    for(const auto& e : G[v]) {
      int t = to(e);
      if(t == par[v]) continue;
      sum = ope(sum, adj(tdp[t], e));
    }
    tdp[v] = merge(sum, v);
  }

  std::vector<U> f(MAX);
  std::vector<U> b(MAX);

  for(int i = 0; i < qi; i++) {
    int v = que[i];
    for(int j = 0;j < G[v].size();j++) {
      int t = to(G[v][j]);
      f[j + 1] = adj(tdp[t == par[v] ? v : t], G[v][j]);
    }
    b[G[v].size()] = ide;
    for(int j = G[v].size(); j --> 0;) b[j] = ope(f[j + 1], b[j + 1]);
    f[0] = ide;
    for(int j = 0;j < G[v].size(); j++) {
      int t = to(G[v][j]);
      f[j + 1] = ope(f[j], f[j + 1]);
      if(t != par[v]) {
        tdp[t] = merge(ope(f[j], b[j + 1]), v);
      }
    }
    tdp[v] = merge(f[G[v].size()], v);
  }
  return tdp;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }


int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  i64 N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  rep(i,0,N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  auto res = rerooting<i64>(G, 0, 1ll,
        [](int t) { return t; },
        [&](i64 t, i64 e) { return (t + 1) == M ? 0 : t + 1; },
        [&](i64 a, i64 b) { return a * b % M; },
        [](i64 a, i64 v) { return a; }
      );

  rep(i,0,N) {
    cout << res[i] << "\n";
  }
}


Measured memory_bytes: 9208
# -*- coding: utf-8 -*-

a = []
for i in range(4):
    a.append(int(input()))
    
if(a[0] < a[1]):
    cost1 = a[0]
else:
    cost1 = a[1]

if(a[2] < a[3]):
    cost1 += a[2]
else:
    cost1 += a[3]
    
print(cost1)

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    vector<int> s(n),t(n),u(n);
    for(int i=0;i<n;i++){
    cin>>s[i];
    }
    for(int i=0;i<n;i++){
    cin>>t[i];
    }
    for(int i=0;i<n;i++){
    cin>>u[i];
    }
    long long ans=0;
    sort(s.begin(),s.end());
    sort(u.begin(),u.end());
    for(int i=0;i<n;i++){
        ans+=(lower_bound(s.begin(),s.end(),t[i])-s.begin())*(n-(upper_bound(u.begin(),u.end(),t[i])-u.begin()));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <math.h>
#include <utility>

using namespace std;

int main ()
{
  int H, W;
  int count = 0;
  pair<int, int> data[5000];

  while (1) {
    scanf("%d", &H);
    scanf("%d", &W);
    if (H == 0 && W == 0) {
      break;
    }
    data[count].first = H;
    data[count].second = W;
    count++;

  }

  for (int i = 0; i < count; i ++) {
    for (int j = 0; j < data[i].first; j++) {
      for (int k = 0; k < data[i].second; k++) {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 2552
#include <cstdio>

int main()
{
  int n, A, B;
  char s[100001];
  scanf("%d%d%d%s", &n, &A, &B, s);
  int a = 0, b = 0;
  for (char *p = s; *p; ++p)
  {
    if (*p == 'a')
    {
      if (a + b < A + B)
      {
        puts("Yes");
        ++a;
      }
      else
      {
        puts("No");
      }
    }
    else if (*p == 'b')
    {
      if (a + b < A + B && b < B)
      {
        puts("Yes");
        ++b;
      }
      else
      {
        puts("No");
      }
    }
    else puts("No");
  }
  return 0;
}

Measured memory_bytes: 640
def my_index(l, x, default=False):
    if x in l:
        return int(l.index(x))+1
    else:
        return default
 
ans = []
 
num = int(input())
 
for i in range(1,50001):
    ans.append(int(i*1.08))
 
print(my_index(ans,num,":("))

Measured memory_bytes: 41072
#include <bits/stdc++.h>
using namespace std;
int main (void)
{
	int n;
	scanf("%d",&n);
	long long power=1;
	long long mod=1e9+7;
	for(int i=2;i<=n;i++)
	{
		power=(power*i)%mod;
	}
	printf("%lld\n",power);
	return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import qualified Data.IntMap   as M

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
    [n, k] <- readInts
    abs <- replicateM n readInts
    print $ solve k abs

solve :: Int -> [[Int]] -> Int
solve n = go n . M.fromListWith (+) . map (\[x, y] -> (x, y))
  where
    go n mp    
      | v <  n = go (n - v) mp1
      | v >= n = k
      where ((k, v), mp1) = M.deleteFindMin mp


Measured memory_bytes: 99708
#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>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int h, w; cin>>h>>w;
    vector<string> a(h);
    queue<T> que;
    vector<vector<int>> dist(h, vector<int>(w, 1e9));
    for(int i=0; i<h; i++){
        cin>>a[i];
        for(int j=0; j<w; j++){
            if(a[i][j] == '#'){
                que.push(T(i, j, 0));
                dist[i][j] = 0;
            }
        }
    }

    while(que.size()){
        int cy, cx, cnt;
        tie(cy, cx, cnt) = que.front();
        que.pop();

        for(int i=0; i<4; i++){
            int ny = cy + dy[i];
            int nx = cx + dx[i];

            if(0 <= ny && ny < h && 0 <= nx && nx < w){
                if(a[ny][nx] == '.' && dist[cy][cx] + 1 < dist[ny][nx]){
                    dist[ny][nx] = dist[cy][cx] + 1;
                    que.push(T(ny, nx, cnt+1));
                }
            }
        }
    }

    int ans=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            chmax(ans, dist[i][j]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 17424
#include<bits/stdc++.h>
#define for(i,a,b) for(int i=a;i<=b;i++)
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
_inline void read(int &x){
	int res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	x=res*f;
}
inline void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int a,b,c;
int main(){
	read(a),read(b),read(c);
	if(b-a==c-b) puts("YES");
	else puts("NO");
	exit(0);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	int k = scan.nextInt();
	int x = scan.nextInt();
	int y = scan.nextInt();

	if(n <= k){
	    System.out.println(n*x);
	}else{
	    System.out.println(k*x+(n-k)*y);
	}
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	ll k = 2;
	while(k*(k-1)/2 < n){k++;}
	if(k*(k-1)/2 == n){
		ll m = 2*n/k;
		vector<vector<ll>> ans;
		ans.resize(k);
		
		ll num = 1;
		rep(step, 0, m-1){
			rep(i, 1, m-step){
				ans[step].push_back(num);
				ans[step+i].push_back(num);
				num++;
			}
		}
		
		print("Yes")
		print(k)
		rep(i, 0, k-1){
			cout << m;
			rep(j, 0, m-1){
				cout << " " << ans[i][j];
			}
			cout << endl;
		}
	}
	else{
		print("No")
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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(){
	string s;
	cin >> s;
	
	ll ans=0;
	for(int bit=0; bit<(1<<(int)s.size()-1); bit++){
		ll sum=0;
		ll a= s[0] - '0';
		REP(i, (int)s.size()-1){
			if(bit & (1<<i)){
				sum += a;
				a = s[i+1]-'0';
			}else{
				a = 10*a + (s[i+1]-'0');
			}
		}
		sum += a;
		ans += sum;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        boolean flag = false;
        for (int i = 0; i <= x; i++) {
            if ((4 * i) + (2 * (x - i)) == y) {
                flag = true;
                break;
            }
        }
        System.out.println(flag?"Yes":"No");
    }

}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N=(1LL<<18);

int n, storen;
int a[N], ans[N];
priority_queue<pair<int, int> > store[N];
bool vis[N];

priority_queue<pair<int, int> > dfs(int k)
{
	if(vis[k])
		return store[k];
	vis[k]=1;
	priority_queue<pair<int, int> > pq;
	pq.push({a[k], k});
	for(int i=0;i<storen;i++)
	{
		if((k>>i) & 1)
		{
			priority_queue<pair<int, int> > temp=dfs(k&~(1LL<<i));
			while(!temp.empty())
			{
				pq.push(temp.top());
				temp.pop();
			}
		}
	}
	priority_queue<pair<int, int> > pq2;
	set<int> s;
	while(pq.size() && pq2.size()<2)
	{
		if(s.find(pq.top().second)==s.end())
			pq2.push(pq.top());
		s.insert(pq.top().second);
		pq.pop();
	}
	store[k]=pq2;
	ans[k]=pq2.top().first;
	pq2.pop();
	if(pq2.size())
		ans[k]+=pq2.top().first;
	return store[k];
}

int32_t main()
{
	IOS;
	cin>>n;
	storen=n;
	n=(1LL<<n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n-1;i++)
	{
		dfs(i);
		ans[i]=max(ans[i], ans[i-1]);
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 21888
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }
        
        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let n: usize = read_as_vec()[0];
    let b: Vec<i64> = read_as_vec();
    let mut a: Vec<i64> = vec![0;n];

    a[0] = b[0];

    for i in 1..n-1{
        a[i] = cmp::min(b[i-1], b[i]);
    }
    a[n-1] = b[n-2];
    
    println!("{}", a.into_iter().sum::<i64>());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    vector<vector<pll> >G(n);
    vector<ll>visited(n);
    vector<ll>d(n);
    rep(i,m){
        ll r,l,d;cin>>r>>l>>d;
        r--;l--;
        G[l].pb(mp(r,d));
        G[r].pb(mp(l,-d));
    }
    bool f=1;
    rep(i,n){
        if(visited[i])continue;
        visited[i]=1;
        queue<ll>q;
        q.push(i);
        while(!q.empty()){
            ll k=q.front();
            q.pop();
            for(auto e:G[k]){
                if(visited[e.first]){
                    if(d[k]+e.second!=d[e.first])f=0;
                }else{
                    q.push(e.first);
                    visited[e.first]=1;
                    d[e.first]=d[k]+e.second;
                }
            }
        }
    }
    cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 14848
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
int N,su=0;
cin >> N;
  int p[N];    for(int i=0;i<N;i++)  cin >> p[i];

for(int i=0;i<100;i++){
  int cnt=0;
  for(int j=0;j<N;j++){
    if(p[j]%2==0){
      p[j]=p[j]/2;
      cnt++;
    }
  }
  if(cnt==N){
        su++;
    }else{
      break;
    }
}
cout  << su << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,h[100000],cnt,max,i,a;
	scanf("%d",&n);
	scanf("%d",&h[0]);
	max=0;
	cnt=0;
	for(i=1;i<n;i++){
		scanf("%d",&h[i]);
		if(h[i-1]>=h[i]){
			cnt++;
		}
		else{
			cnt=0;
		}
		if(cnt>max){
			max=cnt;
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 512
#C
N, M = map(int, input().split())
Table = [list(map(int, input().split())) for _ in range(M)]
Table.sort(key=lambda x:x[0])
Table.sort(key=lambda x:x[1])
#print(f'Table:{Table}')
first = Table[0][0]
end = Table[0][1]
Table.pop(0)
ans = 1
#print(f'first:{first} end:{end}')
for task in Table:
    #print(f'task:{task}')
    num = task[0]
    #print(f'num:{num}')
    if num <= end:
        if num > first:
            first = num
    else:
        ans = 0
        break
    #print(f'first:{first}')
if ans == 0:
    print(ans)
else:
    print(end-first+1)

Measured memory_bytes: 28980
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
using namespace std;
map<int,int> vis;

int prime(int n)
{
	if(n==1||n==2)
	{
		return 1;
	}
	for(int i=2;i<=sqrt(n);i+=1)
	{
		if(n%i==0)
		{
			return 0;
		}
	}
	return 1;
}

int32_t main()																																	
{
	int a,b,cnt=0;
	cin>>a>>b;
	vector<int> div;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(!(a%i))
		{
			//cout<<i<<" ";
			vis[i]=1;
			if((a/i)!=i)
			{
				vis[a/i]=1;
			}
		}
	}
	//cout<<'\n';
	for(int i=1;i<=sqrt(b);i++)
	{
		if(!(b%i))
		{
			if(vis[i]==1)
			{
				//cout<<i<<" ";
				div.pb(i);
			}
			if(vis[b/i]==1&&((b/i)!=i))
			{
				div.pb(b/i);
			}
		}
	}
	//cout<<'\n';
	for(int i=0;i<div.size();i++)
	{
		//cout<<div[i]<<" ";
		if(prime(div[i]))
		{
			cnt++;
		}
	}
	//cout<<'\n';
	cout<<cnt;
}




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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int M = S.length();
  string ans = S;
  
  for (int i = 0; i < M; i++) {
	int pos = 0;
    if (S[i]=='A') pos = 1;
    else if (S[i]=='B') pos = 2; 
    else if (S[i]=='C') pos = 3;
    else if (S[i]=='D') pos = 4;
    else if (S[i]=='E') pos = 5;
    else if (S[i]=='F') pos = 6;
    else if (S[i]=='G') pos = 7;
    else if (S[i]=='H') pos = 8;
    else if (S[i]=='I') pos = 9;
    else if (S[i]=='J') pos = 10;
    else if (S[i]=='K') pos = 11; 
    else if (S[i]=='L') pos = 12; 
    else if (S[i]=='M') pos = 13;
    else if (S[i]=='N') pos = 14;
    else if (S[i]=='O') pos = 15;
    else if (S[i]=='P') pos = 16;
    else if (S[i]=='Q') pos = 17;
    else if (S[i]=='R') pos = 18;
    else if (S[i]=='S') pos = 19;
    else if (S[i]=='T') pos = 20;
    else if (S[i]=='U') pos = 21; 
    else if (S[i]=='V') pos = 22; 
    else if (S[i]=='W') pos = 23;
    else if (S[i]=='X') pos = 24;
    else if (S[i]=='Y') pos = 25;
    else if (S[i]=='Z') pos = 26;
    
    int pos_new = (pos + N) % 26;
    if (pos_new == 1) ans[i] = 'A'; 
    else if (pos_new == 2) ans[i] = 'B'; 
    else if (pos_new == 3) ans[i] = 'C'; 
    else if (pos_new == 4) ans[i] = 'D'; 
    else if (pos_new == 5) ans[i] = 'E'; 
    else if (pos_new == 6) ans[i] = 'F'; 
    else if (pos_new == 7) ans[i] = 'G'; 
    else if (pos_new == 8) ans[i] = 'H'; 
    else if (pos_new == 9) ans[i] = 'I'; 
    else if (pos_new == 10) ans[i] = 'J'; 
    else if (pos_new == 11) ans[i] = 'K'; 
    else if (pos_new == 12) ans[i] = 'L'; 
    else if (pos_new == 13) ans[i] = 'M'; 
    else if (pos_new == 14) ans[i] = 'N'; 
    else if (pos_new == 15) ans[i] = 'O'; 
    else if (pos_new == 16) ans[i] = 'P'; 
    else if (pos_new == 17) ans[i] = 'Q'; 
    else if (pos_new == 18) ans[i] = 'R'; 
    else if (pos_new == 19) ans[i] = 'S'; 
    else if (pos_new == 20) ans[i] = 'T'; 
    else if (pos_new == 21) ans[i] = 'U'; 
    else if (pos_new == 22) ans[i] = 'V'; 
    else if (pos_new == 23) ans[i] = 'W'; 
    else if (pos_new == 24) ans[i] = 'X'; 
    else if (pos_new == 25) ans[i] = 'Y'; 
    else if (pos_new == 0) ans[i] = 'Z'; 
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
def check(s,t):
    if len(s) != len(t):
        return False
    l = len(s)
    s_t = {}
    t_s = {}
    for i in range(l):
        if s[i] in s_t.keys():
            if s_t[s[i]] != t[i]:
                return False
        else:
            s_t[s[i]] = t[i]
        if t[i] in t_s.keys():
            if t_s[t[i]] != s[i]:
                return False
        else:
            t_s[t[i]] = s[i]
    return True

S=input()
T=input()
if check(S,T):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {

	int n;
	cin >> n;
	vector<double>v(n);

	rep(i, n)
		cin >> v[i];

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

	rep(i, n-1)
		v[i + 1] = (v[i] + v[i + 1]) / 2;

	printf("%.5f\n", v[n - 1]);

	return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll X;
    cin >> X;
    ll A, B;
    for (A = 0; A <= 200; ++A)
    {
        for (B = -100; B <= A - 1; ++B)
        {
            ll a5 = A * A * A * A * A;
            ll b5 = B * B * B * B * B;
            if (a5 - b5 == X) 
            {
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
}


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

int Func_gcd(int num1, int num2){
	int surplus;

	while((surplus=num1%num2) != 0){
		num1 = num2;
		num2 = surplus;
	}
	
	return num2;
}

int main()
{
    int gcd, lcm;
	int num1, num2;
	
	while(cin>>num1>>num2){
		gcd = Func_gcd(num1, num2);
		lcm = num1 / gcd * num2;
				
		cout << gcd << " " << lcm << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1160
s=input()

x=[];
Ccount=0

while(1):

    if s[0]!='A':
        print('WA')
        break

    s=s.strip("A")

    for i in range(1,len(s)-1):
        if s[i]=='C':
            Ccount+=1

    if Ccount!=1:
        print('WA')
        break

    s=s.replace("C","")

    if s.islower()==0:
        print('WA')
        break

    print('AC')
    break


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

using namespace std;

typedef unsigned long long ull;
typedef pair<int, int> P;

int main(){
    int N; cin >> N;
    map<int,int> ans;
    rep(i, N) {
        int A; cin >> A;
        ans.insert({A, (i+1)});
    }

    for (int i=1; i<=N;i++) {
        cout << ans[i] << " ";
    }
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

vector<vector<tuple<int, int, int>>> g;
vector<bool> used;
int dfs(int now, int goal, int flow) {
    if (now == goal)return flow;
    used[now] = true;
    each(next, g[now]) {
        int to, cap, rev; tie(to, cap, rev) = next;
        if (used[to])continue;
        if (cap == 0)continue;

        int d = dfs(to, goal, min(flow, cap));
        if (d == 0)continue;
        get<1>(next) -= d;
        get<1>(g[to][rev]) += d;
        return d;
    }
    return 0;
}
int main() {
    init();

    int n, m; cin >> n >> m;
    g.resize(n);
    FOR(i, 0, m) {
        int s, t, c; cin >> s >> t >> c;
        g[s].emplace_back(t, c, g[t].size());
        g[t].emplace_back(s, 0, g[s].size() - 1);
    }

    int ans = 0;
    while (true) {
        used.assign(n, false);
        int flow = dfs(0, n - 1, INF);
        if (flow == 0)break;
        ans += flow;
    }

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


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

#define FST first
#define SCD second
#define MODP 1000000007

typedef long long LL;
typedef pair<int, int> PA;

int cmp(PA x, PA y) {
    return x.SCD < y.SCD;
}

int f[10][10];

int main() {
#ifdef FDB
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n, m, k, b, d;
    cin>>n;
    vector<int> a;
    m = n;
    k = 0;
    b = 1;
    while (m) {
        a.push_back(m%10);
        m/=10;
        k+=1;
        b*=10;
    }
    b/=100;
    for (int i=1;i<=9;++i) {
        for (int j=1;j<=9;++j) {
            // cout<<i<<", "<<j<<":";
            if (i==j&&i<=n) {
                f[i][j] = 1;
            } else f[i][j] = 0;
            if (n<10) {
                // cout<<f[i][j]<<endl;
                continue;
            }
            if (a[k-1]>i) {
                f[i][j] += b;
            }
            else if (a[k-1]==i) {
                int x = (n - b * 10 * a[k-1] - a[0])/10;
                f[i][j] += x;
                if (j<=a[0]) f[i][j] += 1;
            }
            int k_ = k-1;
            int b_ = b/10;
            while (k_>=2) {
                f[i][j] += b_;
                b_/=10;
                k_--;
            }
            // cout<<f[i][j]<<endl;
        }
    }
    LL ans = 0;
    for (int i=1;i<=9;++i) {
        for (int j=1;j<=9;++j) {
            ans += (LL)f[i][j] * f[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "  = " << x << endl
typedef long long int ll;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

#define dbg2(x, y)                                                       \
    {                                                                    \
        cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; \
    }
#define fo(i, n) for (int i = 0; i < n; i++)
#define fok(i, k, n) for (int i = k; i < n; i++)
#define foA(i, A) for (auto i : A)
const int mxN=403;
const int modd=1e9+7;
const ll mx=1e15;
ll a[mxN];
int n;


int main(){
    cin>>n;
    fo(i, n)cin>>a[i];
    ll dp[n][n];
    ll psum[n];
    psum[0]=a[0];
    for(int i=1;i<n;i++)psum[i]=psum[i-1]+a[i];
    for(int ws=1; ws<=n;ws++){
        for(int i=0;i<n-ws+1;i++){
            int j=i+ws-1;
            if(i==j){dp[i][j]=0; continue;}
            dp[i][j]=mx;
            for(int k=i;k<j;k++){
                dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]);
            }
            dp[i][j]+=(psum[j]-(i==0 ? 0: psum[i-1]));
        }
    }
    ll ans=dp[0][n-1];
    cout<<ans;
}

Measured memory_bytes: 4888
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

class SegmentTree:
    def __init__(self,N,d):
        self.NN = 1
        while self.NN < N:
            self.NN *= 2
        self.SegTree = [d]*(self.NN*2-1)

    def update(self,i,x): #iの値をxに更新
        i += self.NN - 1
        self.SegTree[i] = x
        while i>0:
            i = (i-1)//2
            self.SegTree[i] = self.process(self.SegTree[i*2+1],self.SegTree[i*2+2])

    def query(self,a,b,k=0,l=0,r=None): #[A,B)の値, 呼ぶときはquery(a,b)
        if r == None: r = self.NN
        if r <= a or b <= l: #完全に含まない
            return -1
        elif a <= l and r <= b : #完全に含む
            return self.SegTree[k]
        else: #交差する
            vl = self.query(a,b,k*2+1,l,(l+r)//2)
            vr = self.query(a,b,k*2+2,(l+r)//2,r)
            return(self.process(vl,vr))

    def process(self,x,y): #x,yが子の時，親に返る値
        return max(x,y)

N = inp()
hh = inpl()
aa = inpl()

seg = SegmentTree(N+1,0)

for i in range(N):
    h,a = hh[i], aa[i]
    tmp = seg.query(0,h) + a
    seg.update(h,tmp)

print(seg.query(0,N+1))


Measured memory_bytes: 121220
import java.util.Scanner;

class Main{
        public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int n;
    	int[] Vec_x;
    	int[] Vec_y;
    	double[] D = new double[3];
    	double D_Max = 0.0;
    	
    	n = scan.nextInt();
    	Vec_x = new int[n];
    	Vec_y = new int[n];
    	
    	for(int i = 0; i < n; i++){
    		Vec_x[i] = scan.nextInt();
    	}
    	for(int i = 0; i < n; i++){
    		Vec_y[i] = scan.nextInt();
    	}
    	
    	//p = 1
    	for(int i = 0; i < n; i++){
    		D[0] += Math.abs(Vec_x[i] - Vec_y[i]); 
    	}
    	System.out.println(String.format("%.6f", D[0]));
    	
    	//p = 2
    	for(int i = 0; i < n; i++){
    		D[1] += Math.pow(Math.abs(Vec_x[i] - Vec_y[i]), 2); 
    	}
    	D[1] = Math.pow(D[1], 1.0/2.0);
    	System.out.println(String.format("%.8f", D[1]));
    	//p = 3
    	for(int i = 0; i < n; i++){
    		D[2] += Math.pow(Math.abs(Vec_x[i] - Vec_y[i]), 3); 
    	}
    	D[2] = Math.pow(D[2], 1.0/3.0);
    	System.out.println(String.format("%.8f", D[2]));
    	
    	D_Max = Math.abs(Vec_x[0] - Vec_y[0]);
    	for(int i = 0; i < n; i++){
    		if(D_Max < Math.abs(Vec_x[i] - Vec_y[i])) {
    			D_Max = Math.abs(Vec_x[i] - Vec_y[i]);
    		}
    	}
    	System.out.println(String.format("%.8f", D_Max));
     }
}

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

#define REP(i, a, b) for (ll i = (a); i <= (b); ++i)
#define REV(i, a, b) for (ll i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main()
{
   int N, M;
   cin >> N >> M;
   vector<vector<int>> A(100000);

   int a, b;
   REP(i, 0, N - 1)
   {
      cin >> a >> b;
      A[a - 1].push_back(b);
   }

   int ans = 0;
   std::priority_queue<int> q;
   REP(m, 0, M - 1)
   {
      FORV(a, A[m])
      {
         q.push(a);
      }
      if (!q.empty())
      {
         ans += q.top();
         q.pop();
      }
   }
   cout << ans << endl;
}

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


Measured memory_bytes: 5632
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;
int main() {
	int ans[101] = {},c=0;
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	for (int i = A; i < B; i++)ans[i]++;
	for (int i = C; i < D; i++)ans[i]++;
	for (int i = 0; i < 101; i++)if (ans[i] == 2)c++;
	cout << c;
}


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

using namespace std;
using ll = long long;
vector<int> arr;

void insertion_sort(int start, int end) {
    int j, flag = false;        
    for (int i = start; i <= end; i++) {
        if (flag) cout << endl;
        flag = true;
        int current_element = arr[i];
        j = i - 1;
        while (j >= 0 && arr[j] > current_element) {
            arr[j + 1] = arr[j];
            --j;
        }
        arr[j + 1] = current_element; 
        for (int i = start; i <= end - 1; i++)
            cout << arr[i] << " ";
        cout << arr[end];
    }
}

int main(void) {
    int n; cin >> n;
    arr.resize(n);
    for (int i = 0; i < n; i++)    
        cin >> arr[i];
    insertion_sort(0, n - 1);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<set>
#include<utility>
#include<valarray>
#include<string>
#include<algorithm>

using namespace std;

valarray<int> braces(string s){
  valarray<int> va(3);
  for(auto e:s){
    va[0]+=(e=='(')-(e==')');
    va[1]+=(e=='{')-(e=='}');
    va[2]+=(e=='[')-(e==']');
  }
  return va;
}

int main(){
  for(int p,q;cin>>p>>q,p;){
    vector<pair<valarray<int>,int> > v;
    valarray<int> va(3);
    for(int i=0;i<p;i++){
      string s;
      cin>>s;
      v.emplace_back(va,find_if(begin(s),end(s),[](char c){
	    return c!='.';
	  })-begin(s));
      va+=braces(s);
    }
    vector<vector<int> > fact;
    for(int i=1;i<=20;i++){
      for(int j=1;j<=20;j++){
	for(int k=1;k<=20;k++){
	  bool f=false;
	  for(auto e:v){
	    auto cva=e.first;
	    f|=cva[0]*i+cva[1]*j+cva[2]*k!=e.second;
	  }
	  if(!f){
	    fact.push_back({i,j,k});
	  }
	}
      }
    }
    valarray<int> rva(3);
    while(q--){
      set<int> cand;
      for(auto e:fact){
	cand.insert(e[0]*rva[0]+e[1]*rva[1]+e[2]*rva[2]);
      }
      cout<<((cand.size()==1)?*begin(cand):-1)<<" \n"[q==0];
      string s;
      cin>>s;
      rva+=braces(s);
    }
  }
}
      
      
	
    
    

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

int main(){
    int n, m, i;
    long long a = 1;
    cin >> n >> m;
    if(abs(m-n) > 1){
        cout << 0;
    }else{
        for(i=1; i<=n; i++){
            a *= (long long)i;
            a %= 1000000007;
        }
        for(i=1; i<=m; i++){
            a *= (long long)i;
            a %= 1000000007;
        }
        if(n == m){
            a *= 2;
            a %= 1000000007;
        }
        cout << a;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	N := getStdinInt64()
	A := getStdinIntArr64()
	var i int64 = 0
	var max int64 = 0

	// 最大値を求める
	for i = 0; i < N; i++ {
		if A[i] > max {
			max = A[i]
		}
	}

	// 素数を求める
	isPrime := make([]bool, max+1)
	for i := 2; i < len(isPrime); i++ {
		isPrime[i] = true
	}
	isPrime[0] = false
	isPrime[1] = false
	for i := 2; i < len(isPrime); i++ {
		if isPrime[i] {
			for j := i * 2; j < len(isPrime); j += i {
				isPrime[j] = false
			}
		}
	}
	// 個数
	countMap := make(map[int64]int64)
	for _, a := range A {
		countMap[a]++
	}

	if countMap[1] == 1 {
		// x % 1 == 0 のみ
		fmt.Printf("%d\n", 1)
		return
	}
	if countMap[1] >= 2 {
		// すべてが x % 1 == 0 になってしまう
		fmt.Printf("%d\n", 0)
		return
	}

	var ans int64 = 0
	for _, a := range A {
		if countMap[a] >= 2 {
			// x % x == 0 になってしまう
			continue
		}
		if isPrime[a] {
			// 素数なので明らか
			ans++
			continue
		}

		// 約数を求める
		fac := make([]int64, 0)
		for i = 2; i*i <= a; i++ {
			if a%i == 0 {
				fac = append(fac, i) // 約数
				if i*i != a {
					fac = append(fac, a/i) // 約数で割ったもの
				}
			}
		}

		flag := true
		for _, f := range fac {
			if countMap[f] >= 1 {
				flag = false
				break
			}
		}
		if flag {
			ans++
		}
	}

	fmt.Printf("%d\n", ans)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 22168
package main

import (
    "fmt"
)

func main() {
	var a0, a1, a2 int
	fmt.Scan(&a0)
	fmt.Scan(&a1)
	fmt.Scan(&a2)
	
	d := make([]int, 3)
	d[0] = abs(a0 - a1)
	d[1] = abs(a1 - a2)
	d[2] = abs(a2 - a0)
	
	max := -1
	for _, e := range d {
		if max < e {
			max = e
		}
	}
	
	fmt.Println(max)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

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

int main()
{
int r;
int g;
int b;
int n;
int pattern = 0;
cin >> r >> g >> b >> n;
for (int rbox = 0; rbox < n/r+1; rbox++){
  for (int gbox = 0; gbox < (n - r*rbox)/g+1; gbox++){
    if ((n - r*rbox - g*gbox)%b == 0) {
      pattern++;
    }
  }
}
cout << pattern << endl;
}

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

int main(){
    //入力
    int N,M;
    cin >> N >> M;

    vector<int> ans(N),a(M),b(M);
    for(int i=0;i<M;i++){
        cin >> a.at(i) >> b.at(i);
        ans.at(a.at(i)-1)++;
        ans.at(b.at(i)-1)++;
    }

    //出力
    for(int i=0;i<N;i++){
        cout << ans.at(i) << endl;
    }
}

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

int main()
{
    string a,b;

    cin>>a>>b;
    const char *ai=a.c_str(),*bi=b.c_str();
    int i=a.length();
    int j=b.length();
    for(int s=1;s<=i+j;s++)
    {
        if(s%2)
            printf("%c",ai[(s-1)/2]);
        else
            printf("%c",bi[(s-1)/2]);
    }
    printf("\n");
    return 0;
}


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

int main ()
{
    long long n,m;
    cin >> n >> m;
    if (n==1 || m==1)
    {
        if (n==1 && m==1) cout << 1 <<endl;
        else cout << max(n,m)-2 << endl;
    }
    else
    {
        cout << (n-2)*(m-2) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define Y first
#define X second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

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

int main(){
  int x, y;
  while(scanf("%d%d", &x, &y) && x+y){
    int n, sx, sy;
    scanf("%d", &n);
    vector<pi>s(n);
    rep(i, n){
      scanf("%d%d", &sx, &sy);
      s[i] = make_pair(sy, sx);
    }
    queue<pi>q;
    q.push(make_pair(y, x));
    int c = 0;
    while(!q.empty() && c < n){
      int qsize = (int)q.size();
      rep(i, qsize){
	pi now = q.front(); q.pop();
	//	printf("%d %d %d %d\n", now.Y, now.X, s[c].Y, s[c].X);
	rep(d, 12){
	  int ny = now.Y + dy[d], nx = now.X + dx[d];
	  if(ny < 0 || ny >= 10 || nx < 0 || ny >= 10) continue;
	  //	  printf("%d %d\n", ny, nx);
	  if(ny >= s[c].Y-1 && ny <= s[c].Y + 1 && nx >= s[c].X-1 && nx <= s[c].X+1){
	    //	    printf("%d %d\n", ny, nx);
	    q.push(make_pair(ny, nx));
	  }
	}
      }
      c++;
    }
    //    printf("%d\n", c);
    if(c >= n && !q.empty()) puts("OK");
    else puts("NA");
  }
  return 0;
}

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

int main()
{
ll t ;
cin >> t ;
ll v[t][4]={};
rep(i,t){
  cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3] ;
}
rep(i,t){
  ll a=v[i][0] , b=v[i][1] , c=v[i][2] , d=v[i][3] ;
  if(b>d||a<b){cout << "No" << endl;continue;}
  if(b<=c+1){cout << "Yes" << endl;continue;}
  ll e=__gcd(b,d);
  ll f=a%b;
  if(f>c){cout << "No" << endl;continue;}
  if(b-e<=c){cout << "Yes" << endl;continue;}
  else cout << "No" << endl;
}


return 0;
}


Measured memory_bytes: 256