akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as BC
import qualified Data.Sequence as S
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List

main = do
  n <- readLn :: IO Int
  t <- map (\[x,y,z] -> (x,y,z)) <$> getInt2DListBC
  if solve (0, 0, 0) t
    then putStrLn "Yes"
    else putStrLn "No"

solve :: (Int, Int, Int) -> [(Int, Int, Int)] -> Bool
solve (_, _, _) [] = True
solve (t1, x1, y1) ((t2, x2, y2):s) =
  let t = t2 - t1
      x = abs $ x2 - x1
      y = abs $ y2 - y1
  in if t < x + y || mod (t-(x+y)) 2 /= 0
       then False
       else solve (t2, x2, y2) s


bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getInt2DListBC :: IO [[Int]]
getInt2DListBC = map (map bsToInt . BC.words) . BC.lines <$> BC.getContents


Measured memory_bytes: 4476
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(void){
    int num_student;
    int *data;
    int i,j;
    double alpha, alpha_square = 0 , m = 0, sum = 0;
     
    while(1){  
        scanf("%d", &num_student);
        if(num_student == 0)
            return 0;
         
        data = malloc(sizeof(int) * num_student);
         
        for(i=0 ; i < num_student ; i++){
            scanf("%d", &data[i]);
            m += data[i];
        }
        m /= num_student;
        //printf("m=%f\n", m);
         
        for(i=0 ; i < num_student ; i++){
            sum += pow(data[i] - m, 2);
            //printf("i=%d:sum=%f\n", i, sum);
        }
        alpha_square = sum / num_student;
        //printf("alpha_square=%f\n", alpha_square);
         
        alpha = sqrt(alpha_square);
        printf("%f\n", alpha);
         
        alpha = 0;
        alpha_square = 0;
        m = 0;
        sum = 0;
        free(data);
         
    }
    return 0;
}

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

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

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> h(n);
  int sum = 0;
  rep(i, n) {
    std::cin >> h[i];
    sum += h[i];
  }

  int num = 0;
  rep(i, n - 1) {
    if (h[i] > h[i + 1]) {
      num += h[i] - h[i + 1];
    }
  }
  num += h[n - 1];

  std::cout << num << std::endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll m = 100;
  ll x;
  int ans = 0;
  cin >> x;
  while(m < x) {
    ll a = (m / 100);
    m += a;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	long n;
	cin >> n;
	long tPoint = 0, hPoint = 0;
	for (long i = 0; i < n; i++){
		string tarou, hanako;
		cin >> tarou >> hanako;
		if (tarou < hanako) hPoint += 3;
		else if (tarou == hanako){
			tPoint++;
			hPoint++;
		}
		else tPoint += 3;
	}
	cout << tPoint << " " << hPoint << endl;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

bool sorted[200010];

template<class T>
class SegTree {
public:
    int n;
    vector<T> nodes;
    T ini;
    function<T(T,T)> fn;
    SegTree(int _n, T ini, function<T(T,T)> fn): ini(ini), fn(fn) {
        n = 1 << (int)ceil(log2(_n));
        nodes.resize(n*2-1, ini);
    }
    void update(int i, T x) {
        i += n-1;
        nodes[i] = x;
        while (i > 0) {
            i = (i-1) / 2;
            nodes[i] = fn(nodes[i*2+1], nodes[i*2+2]);
        }
    }
    T query(int l, int r) {
        return query(l, r, 0, n, 0);
    }
private:
    T query(int l, int r, int tl, int tr, int k) {
        if (tr <= l || r <= tl) return ini;
        if (l <= tl && tr <= r) return nodes[k];
        return fn(
            query(l, r, tl, (tl+tr)/2, 2*k+1),
            query(l, r, (tl+tr)/2, tr, 2*k+2)
        );
    }
};

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (int i=0; i<N; ++i) cin >> P[i];

    int res = 0;
    int cnt = 0;
    for (int i=0; i<N; ++i) {
        if (i == 0 || P[i-1] < P[i]) cnt ++;
        else cnt = 1;
        if (K <= cnt) {
            sorted[i-K+1] = true;
            res = 1;
        };
    }

    SegTree<int> segmin(N, INT_MAX, [](int a, int b){ return min(a, b); });
    SegTree<int> segmax(N, -INT_MAX, [](int a, int b){ return max(a, b); });

    for (int i=0; i<N; ++i) {
        segmin.update(i, P[i]);
        segmax.update(i, P[i]);
    }

    if (!sorted[0]) res ++;
    for (int i=1; i+K-1<N; ++i) {
        if (sorted[i]) continue;
        int mn = segmin.query(i-1, i+K);
        int mx = segmax.query(i-1, i+K);
        if (P[i-1] == mn && P[i+K-1] == mx) continue;
        res ++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5376
using System;
using System.Collections.Generic;

namespace AtCoder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
			string[] input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);
			int field = (a - 1) * (b - 1);

			Console.WriteLine(field.ToString());
		}
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

using namespace std;

#define ll long long

int main(){
	int n;
	cin >> n;
	string in;
	int ans = 0;
	int ba = 0;
	int xa = 0;
	int bx = 0;
	for(int i = 0;i < n;i++){
		cin >> in;
		for(int j = 1;j < in.size();j++){
			if(in[j] == 'B' && in[j-1] == 'A')ans++;
		}
		char first = in[0];
		char last = in[in.size()-1];
		if(first == 'B' && last == 'A'){
			ba++;
		}else if(first == 'B'){
			bx++;
		}else if(last == 'A'){
			xa++;
		}
	}
	if(ba != 0){//baをまず設置
		ans += (ba-1);
		if(bx!=0){
			ans++;
			bx--;
		}
		if(xa!=0){
			ans++;
			xa--;
		}	
	}
	ans += min(xa,bx);
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int   N      =    2005    ;
const int   mod    =    1e9 + 7 ;

int n, k, a[N], sA[N], sB[N], bit[N];

int get(int id) {
    int ret = 0;
    for (; id; id -= id & -id)
        ret += bit[id];
    return ret;
}

void upd(int id) {
    for (; id < N; id += id & -id)
        bit[id] ++;
}

signed main() {
    //freopen("in.inp", "r", stdin);
    //freopen("ou.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> k;
    int ans = 0;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++) {
        upd(a[i]);
        sA[i] = get(a[i] - 1);
    }
    memset(bit, 0, sizeof bit);
    for (int i = n; i >= 1; i--) {
        upd(a[i]);
        sB[i] = get(a[i] - 1);
    }
    for (int i = 1; i <= n; i++) {
        int mulA = ((k * (k - 1) / 2) % mod );
        int mulB = ((k * (k + 1) / 2) % mod );
        ans += mulA * sA[i] % mod; ans %= mod;
        ans += mulB * sB[i] % mod; ans %= mod;
    }

    cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359

int main() {
    ll n,ans=1,a[100010];
    cin >> n;
    bool flag = true,ff = false;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i] == 0)ff = true;
    }

    for(int i=0;i<n;i++){
        ll hoge = a[i];
        if(hoge > 1000000000000000000/ans){
            flag = false;
            break;
        }
        ans = hoge*ans;
    }
    if(ff) cout << 0 << endl;
    else if(flag) cout << ans;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 4404
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    string S;
    cin >> S;
    
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '1') {
            S[i] = '9';
            continue;
        }
        if (S[i] == '9') {
            S[i] = '1';
            continue;
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	 
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c = in.next().toCharArray();
		int[] num = new int[26];
		
		for (int i = 0; i < c.length; i++) {
			num[c[i] - 'a']++;
		}
		
		boolean isBeautiful = true;
		for (int i = 0; i < num.length; i++) {
			if (num[i] % 2 != 0) {
				isBeautiful = false;
				break;
			}
		}
		
		System.out.println(isBeautiful ? "Yes" : "No");
	}
}

Measured memory_bytes: 22868
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    int N;
    cin >> N;
    vector<int> B(N-1),A(N);
    for(int i=0;i<N-1;i++)
    {
        cin >> B[i];
    }
    
    A[0] = B[0];
    for(int i=1; i<=N-2; i++)
    {
        A[i] = min(B[i-1], B[i]);
    }
    A[N-1] = B[N-2];
    
    cout << accumulate(A.begin(), A.end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 5e5 + 5;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	for (int i = 1; i < 6; i++) {
		int x;
		cin >> x;
		if (x == 0) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstring>
#include <algorithm>
#define MAX 1000
using namespace std;

int main(void){

  int n,W;
  int w[MAX+1];
  int v[MAX+1];
  int dp[MAX+1][MAX+1];
  char ten;
  int cnt = 1;

  while( cin >> W , W ){
    cin >> n;
    for( int i = 0 ; i < n ; i++ ){
      cin >> v[i] >> ten >> w[i];
    }

    for( int i = 0 ; i < MAX ; i++ ){
      for( int j = 0 ; j < MAX ; j++ ){
	dp[i][j] = 0;
      }
    }

    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j <= W ; j++ ){
	if(j < w[i] ) dp[i+1][j] = dp[i][j];
	else dp[i+1][j] = max( dp[i][j] , dp[i][j-w[i]] + v[i] );
      }
    }
    
    cout << "Case " << cnt++ << ":" << endl;
    for( int i = W ; i >= 0 ; i-- ){
      if( dp[n][i] != dp[n][W] ){
	cout << dp[n][W] << endl << i+1 << endl;
	break;
      }
    }
  }  
  return 0;
}

Measured memory_bytes: 5080
import java.util.Scanner;

class Main {

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

	long N = sc.nextLong();
	long n = (long)(Math.sqrt(N));

	long x = 1;
	long y = 1;
	for (long i = n; i > 0; i--) {
	    if (N % i == 0) {
		x = i;
		y = N / i;
		break;
	    }
	}

	System.out.println(x + y - 2);
    }
}

Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		
		int temp;
		
		if(a>b) {
			temp = a;
			a = b;
			b = temp;
		} 
		if(b>c) {
			temp = b;
			b = c;
			c = temp;
		}
		if(a>b) {
			temp = a;
			a = b;
			b = temp;
		} 
		System.out.println(a+" "+b+" "+c);

	}

}

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

int main(){
	int D,N;

	cin >> D;
	cin >> N;

	if (D==0) {
		if (N<100)
			cout << N << endl;
		else
			cout << N+1 << endl;
	} 
		
	else if (D==1) {
		if (N<100)
			cout << N*100 << endl;
		else
			cout << N*101 << endl;
	}

	else {
		if (N<100)
			cout << N*10000 << endl;
		else
			cout << N*10100 << endl;
	}
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())

arr = make_divisors(n)
#print(arr)
useIndex = int(len(arr)/2)
#print(useIndex)

x = arr[useIndex - 1] - 1
y = arr[useIndex] - 1
#print(x,y)
print(x + y)

Measured memory_bytes: 3264
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

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

	if (w % 3 == 0 || h % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}

	if (w < h) {
		
	}

	ll ans = 200000000000;
	for(int i = 0; i < 2; i++) {
		for(ll cw = max(w / 3 - 10 ,0LL); cw <= min(w / 3 + 10, w); cw++) {
			ll a = cw * h;
			ll w0 = w - cw; 

			for (ll ch = max(h / 2 - 10, 0LL) ; ch <= min(h / 2 + 10, h); ch++) {
				ll b = ch * w0;
				ll c = (h - ch) * w0;
				ll cur = max(abs(a - b), abs(b - c));
				cur = max(cur, abs(c - a));
				ans = min(ans, cur);
			}
		}

	
		for(ll cw = max(w / 3 - 2 ,0LL); cw <= min(w / 3 + 2, w); cw++) {
			ll a = cw * h;

			for (ll cw2 = max(w / 3 - 2, 0LL) ; cw2 <= min(w / 3 + 2, w); cw2++) {
				ll b = cw2 * h;
				ll c = (w - cw - cw2) * h;
				if (c <= 0) {
					continue;
				}
				ll cur = max(abs(a - b), abs(b - c));
				cur = max(cur, abs(c - a));
				ans = min(ans, cur);
			}
		}
		
		swap( h, w);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  map<int, long> a;
  long long sum = 0;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    a[x]++;
    sum += x;
  }
  int q; cin >> q;
  for(int i = 0; i < q; i++){
    int b,c; cin >> b >> c;
    //printf("%d %d\n",b,a[b]);
    if(a.count(b)){
      sum -= b * a[b];
      sum += c * a[b];
      a[c] += a[b];
      a.erase(b);
    }
    cout << sum << endl;
  }
  
}

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

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

    int match = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (!(a % 3 == 0 || a % 5 == 0)) {
                match = 0;
            }
        }
    }

    cout << (match ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static void main(String []args){
        Scanner in = new Scanner(System.in);
        String s, t;
        s = in.next();
        t = in.next();
        int [][]dp = new int[s.length()+1][t.length()+1];
        for(int i=0;i<s.length();i++)
            dp[i][0] = 0;
        for(int i=0;i<t.length();i++)
            dp[0][i] = 0;
        for(int i=1;i<=s.length();i++){
            for(int j=1;j<=t.length();j++){
                if(s.charAt(i-1) != t.charAt(j-1))
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                else
                    dp[i][j] = dp[i-1][j-1]+1;
            }
        }
        if(dp[s.length()][t.length()] == 0){
            System.out.println();
            System.exit(0);
        }
        //Now to find the largest common subsquence
        StringBuilder ss = new StringBuilder();
        int i = s.length(), j = t.length();
        while(i != 0 && j!= 0){
            if(dp[i][j] == dp[i][j-1]){
                j -= 1;
            }
            else if(dp[i][j] == dp[i-1][j]){
                i -= 1;
            }
            else if(dp[i][j] == dp[i-1][j-1]+1){
                ss.append(t.charAt(j-1));
                i -= 1;
                j -= 1;
            }
        }

        ss.reverse();
        String ans = ss.toString();
        System.out.println(ans);
    }
}


Measured memory_bytes: 83264
#include <iostream>

int main(){
    using namespace std;

    int a = 0;
    int b = 0;
    cin >> a >> b;

    if( a < b ){
        cout << "a < b" << endl;
    }else if( a > b ){
        cout << "a > b" << endl;
    }else {
        cout << "a == b" << endl;
    }
}

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

int main(){
    long long int a,b;
    cin >> a >> b;
    long long int kotae;
    if(a==1 || b==1){cout  << 1 << endl; return 0;}
    if(a%2==0){kotae=a*b/2;}
    if(a%2!=0 && b%2!=0){kotae=((a-1)/2)*b +(b/2)+1;}    
    if(a%2!=0 && b%2==0){kotae=((a-1)/2)*b +(b/2);}   
    cout  << kotae << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
void initArray(int a[], int len);
int main(void)
{
    int n;
    scanf("%d\n", &n);
    char s[n];
    int alf[26];
    for (int i = 0; i < n; i++)
    {
        scanf("%c", &s[i]);
    }

    int mid = 1, max = 0;
    while (mid < n)
    {
        initArray(alf, 26);
        int num = 0;
        for (int i = 0; i < mid; i++)
        {
            int tmp = s[i] - 'a';
            alf[tmp] = 1;
        }
        for (int j = mid; j < n; j++)
        {
            int tmp = s[j] - 'a';
            if (alf[tmp] == 1)
            {
                alf[tmp]++;
            }
        }
        for (int k = 0; k < n; k++)
        {
            if (alf[k] == 2)
            {
                num++;
            }
        }
        if (num > max)
        {
            max = num;
        }
        mid++;
        // for(int i = 0; i< 26;i++)
        // {
        //     printf("%d ",alf[i]);
        // }
        // puts("");
    }

    printf("%d\n", max);
    return 0;
}

void initArray(int a[], int len)
{
    for (int i = 0; i < len; i++)
    {
        a[i] = 0;
    }
}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k=0;
    cin >> n;
    vector<vector<int> > g(n);
    vector<pair<int, int> > ed(n-1);
    vector<int> deg(n, 0);
    for(int i=0, u, v; i<n-1; i++){
        cin >> u >> v;
        --u; --v;
        ed[i] = {u, v};
        g[u].push_back(v);
        g[v].push_back(u);
        deg[u]++; deg[v]++;
        k = max(k, max(deg[u], deg[v]));
    }
    cout << k << endl;
    map<int, map<int, int> > mp;
    vector<set<int> > s(n);
    for(int i=0; i<n; i++){
        int c = 1;
        for(auto x : g[i])if(!mp[i][x]){
            while(s[x].find(c)!=s[x].end()||s[i].find(c)!=s[i].end()) c++;
            mp[x][i]=mp[i][x]=c;
            s[i].insert(c);
            s[x].insert(c);
            c++;
        }
    }
    for(auto x : ed)
        cout << mp[x.first][x.second] << endl;
    return 0;
}


Measured memory_bytes: 40064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

vec l(2e5+50),r(2e5+50);
vec a(2e5+50);

ll cal(ll x) {
  if(x<3) {
    return 0;
  }
  return max(max(l[x-1],r[x-1]),cal(x-2)+a[x-1]);
}

int main() {
  ll n;
  cin >> n;
  for(ll i=0;i<n;i++) cin >> a[i];
  for(ll i=2;i<=n;i+=2){
    l[i]=l[i-2]+a[i-2];
    r[i]=max(r[i-2],l[i-2])+a[i-1];
  }
  if(n%2) {
    cout << cal(n) << endl;
  }
  else {
    cout << max(l[n],r[n]) << endl;
  }
}

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

int main(void) {
    int N,K;
    cin >> N >> K;
    int ans = 1;
    for (int i=0; i<N; i++) {
        if (ans < K) ans *= 2;
        else ans += K;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
#define pi pair<ll,ll>
ll a[800001],  b[500009], lastcall[800000], value[500000];
string s;
vector<ll>v;
map<ll, ll>mp;
int main()
{
    IO;
    ll j=1, n, m, k, kk=1, m1=0, a1=8, grtr=0, a2=20, l, t, ds,r,mx=0, cnt=0, mn=INT_MAX, h=0, mod=1e9+7, i; char ch;
    cin>>n;
    for(i=1; i<=n; i++) {
            cin>>a[i]; cnt+=a[i]; mp[a[i]]++;
    }
    cin>>m;
    for(i=1; i<=m; i++){
        cin>>j>>k;
        cnt+=mp[j]*k-mp[j]*j; mp[k]+=mp[j]; mp[j]=0;
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 10292
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int solve(int a, int b){
    return max(a - b, 0);
}

int main(){
    int a, b;
    cin >> a >> b;

    int ans = solve(a, b);

    cout << ans << endl;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
  static char[] colors = {'.', '#'};

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    Main tenkaC = new Main();
    System.out.println(tenkaC.solve(n, s));
  }

  public int solve(int n, String s) {
    int whiteNum = 0;
    int blackNum = 0;
    int[] whiteNums = new int[n];
    int[] blackNums = new int[n];
    for(int i = 0; i< n; i++ ){
      if(s.charAt(i) == '.' ){
        whiteNum += 1;
      } else {
        blackNum += 1;
      }
      whiteNums[i] = whiteNum;
      blackNums[i] = blackNum;
    }
    int ans = whiteNum;
    for(int i = 0; i < n; i++ ){
      ans = Math.min(ans, blackNums[i] + whiteNum - whiteNums[i]);
    }
    return ans;
  }
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int A = H1 * 60 + M1;
    int B = H2 * 60 + M2;
    if (A <= B) {
        cout << max(0, B - A - K) << endl;
    }
    else {
        B += 60 * 24;
        cout << max(0, B - A - K) << endl;        
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    int n; cin >> n;
    vector<vector<ld> > dp(n+3, vector<ld>(n+3, 0));
    ld a; cin >> a;
    dp[1][1] = a;
    dp[1][0] = (1-a);
    REP(i, 1, n){
        cin >> a;
        REP(l, 0, n){
            dp[i+1][l+1] += dp[i][l] * a;
            dp[i+1][l] += dp[i][l] * (1-a);
        }
    }
    ld ans = 0;
    REP(i, n/2+1, n+1){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 141184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] h = new long[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextLong();
        }
        boolean[] flags = new boolean[n];
        for (int i = 0; i < flags.length; i++) {
            flags[i] = true;
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (h[a-1] < h[b-1]) {
                flags[a-1] = false;
            } else if (h[a-1] > h[b-1]) {
                flags[b-1] = false;
            } else {
                flags[a-1] = false;
                flags[b-1] = false;
            }
        }
        sc.close();

        int count = 0;
        for (int i = 0; i < flags.length; i++) {
            if (flags[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 51336
while True:
    n=int(input())
    if(n==0):
        exit()
    w=list(map(int,input().split()))
    c=[[False]*n for _ in range(n)]
    dp=[0]*(n+1)
    for i in range(n-1):
        if abs(w[i]-w[i+1])<=1:
            c[i][i+1]=True
    for i in range(3,n,2):
        for l in range(n-i):
            r=l+i
            for k in range(l+1,r):
                if not c[l][r] and c[l][k] and c[k+1][r]:
                    c[l][r]=True
                    break
            if (not c[l][r]) and c[l+1][r-1] and abs(w[l]-w[r])<=1:
                c[l][r]=True
    for i in range(n):
        for j in range(n):
            if c[j][i]:
                dp[i]=max(dp[i],dp[j-1]+i-j+1)
        dp[i]=max(dp[i],dp[i-1])
    print(dp[n-1])


Measured memory_bytes: 7100
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define pi 3.14159265358979
#define de(x) if(x==MODE && x!=0)

#define MODE 1

using namespace std;

int main()
{
    int i,j;
    double a,b,x;

    scanf("%lf %lf %lf", &a, &b, &x);
    double u = a*b;
    double l = x/a;
    if( l >= u/2)
    {
        printf("%.9f\n", atan(2*(u-l)/(a*a)) * (180/pi) );
    }
    else
    {
        printf("%.9f\n", 90 - atan(2*l/(b*b)) * (180/pi) );
    }



    return 0;
}


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

bool compare(pair<long long,long long> a,pair<long long,long long> b)
{
    if(a.first!=b.first) return a.first>b.first;
    else return a.second<b.second;
}

int main()
{
    long long n,m;
    cin>>n>>m;
    long long a[n];
    priority_queue <long long, vector<long long>, greater<long long>> p;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        p.push(a[i]);
    }
    vector<pair<long long,long long> >v;
    for(int i=0; i<m; i++)
    {
        long long a,b;
        cin>>a>>b;
        v.push_back(make_pair(b,a));
    }
    sort(v.begin(),v.end(),compare);
    for(int i=0; i<m; i++)
    {
        //cout<<v[i].second<<" "<<v[i].first<<endl;
        long long x=v[i].second;
        while(p.top()<v[i].first && x>0)
        {
            //cout<<p.top()<<endl;
            p.pop();
            p.push(v[i].first);
            x--;
        }
    }
    long long ans=0;
    while(!p.empty())
    {
        ans+=p.top();
        p.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <random>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ;
	vll a(n),b(n) ;
	for(int i=0;i<n;i++){
		ll x,y ;
		cin >> x >> y ;
		a[i] = x-y ;
		b[i] = x+y ;
	}
	sort(all(a)) ;
	sort(all(b)) ;
	cout << max(a[n-1]-a[0],b[n-1]-b[0]) ;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 10e9
#define INFL 10e18;
#define mod 1000000007
//#define mod 998244353
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum=0;
    if(a>=k)
    {
    	cout<<k;
	}
	else
	{
		sum+=a;
	    k=k-a;
	    if(b>=k)
	    {
	    	cout<<sum;
		}
		else
		{
			k=k-b;
			if(c>=k)
			{
				cout<<sum-k;
			}
			
		}
	}

}

Measured memory_bytes: 3600
#include<iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b && (a - 1) > b) {
		cout << 2 * a - 1 << endl;
		return 0;
	}
	if (b > a && (b - 1) > a) {
		cout << 2 * b - 1 << endl;
		return 0;
	}
	else {
		cout << a + b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

ll powMod(ll x, ll n) {
  if (n == 0) return 1;
  ll r = powMod(x, n / 2);
  if (n % 2 == 0) return (r * r) % MOD;
  return (r * r % MOD) * x % MOD;
}


int main(void) {

  char s;
  cin >> s;
  cout << char(s + 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
#define cl(x,y) memset(x,y,sizeof(x))
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
const int N=2e3+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;
int a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x,y,i,j;
	cin>>n>>x>>y;
	for(i=1;i<n;i++)
		a[i]=n-i;
	int p=y-(y-x)/2;
	for(i=1;i<p;i++)
		for(j=p+1;j<=n;j++)
		{
			if(abs(j-i)>abs(x-i)+1+abs(j-y))
			{
				a[abs(j-i)]--;
				a[abs(x-i)+1+abs(j-y)]++;
			}				
		}
	for(i=1;i<n;i++)
		cout<<a[i]<<endl;
	return 0;
}


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

ans = -1
for i in range(1251):
    atax = int(i*0.08)
    btax = int(i*0.1)
    if atax == a and btax == b:
        ans = 0
        break
if ans == 0:
    print(i)
else:
    print(ans)

Measured memory_bytes: 38640
#include<cstdio>
#define ll long long
#define clz 998244353
ll a,b,k;
ll fac[300010];
ll ca[300010],cb[300010];
int n,p;
ll inv(ll x){ 
    if(x==1) return 1;  
    return (clz-clz/x)*inv(clz%x)%clz;  
}
ll C(ll n,ll m){
	ll x=(fac[m]*fac[n-m])%clz;
	return (fac[n]*inv(x))%clz;
}
int main(){
	fac[0]=fac[1]=1ll;
	for(int i=2;i<=300001;i++) fac[i]=(fac[i-1]*i)%clz;
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
	for(int i=0;i<=n;i++){
		if(k-i*a>=0&&(k-i*a)%b==0&&(k-i*a)/b<=n){
			ca[++p]=i;
			cb[p]=(k-i*a)/b; 
		}
	}
	ll ans=0;
	for(int i=1;i<=p;i++) ans=(ans+C(n,ca[i])*C(n,cb[i])%clz)%clz;
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 6912
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
inline deque<int> cl() {
	size_t count{};
	cin >> count;
	deque<int> lst(count);
	for (size_t i = 0; i < count; ++i) {
		cin >> lst.at(i);
	}
	return lst;
}
int main() {
	auto a = cl();
	auto b = a;
	copy(a.begin(), a.end(), b.begin());
	sort(b.begin(), b.end());
	int r{};
	for (int i = 0; i < a.size(); ++i) {
		if (a.at(i) != b.at(i))
			++r;
	}
	cout<<((r<3)?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int sum[3][4040];char ch[4040];
char s[3]={'R','G','B'};
int main(){
	int n;scanf("%d%s",&n,ch+1);
	for(int i=1;i<=n;i++){ 
		for(int j=0;j<3;j++) sum[j][i]=sum[j][i-1];
		if(ch[i]=='R') sum[0][i]++;
		if(ch[i]=='G') sum[1][i]++;
		if(ch[i]=='B') sum[2][i]++;
	}ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){ int tmp=j-i;
			if(ch[i]!=ch[j]){
				for(int k=0;k<3;k++){
					if(s[k]!=ch[i]&&s[k]!=ch[j]){
						ans+=sum[k][n]-sum[k][j];
						if(j+tmp<=n&&ch[j+tmp]==s[k]) ans--;break;
					}
				}
			}
		}
	}printf("%lld\n",ans);
}

Measured memory_bytes: 3880
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        mut a: [usize;n],
    }

    a.sort();
    a.push(0);
    let mut now = a[0];
    let mut next = a[1];
    let mut cnt = 0;
    let mut ret: Vec<usize> = Vec::new();
    for i in 0..n{
        now = a[i];
        next = a[i+1];
        cnt += 1;
        if now!=next {
            ret.push(cnt);
            cnt = 0;
        }
    }

    ret.sort();
    let mut ans = 0;
    if ret.len() > k {
        for i in 0..ret.len()-k {
            ans += ret[i];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6964
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

const int MX = 2005;
bool d[3][3][MX];

void test_case(){
	vector<string> s(3);
	for(int i = 0 ; i < 3 ; i++)
		cin >> s[i];
	sort(s.begin(),s.end());
	int ans = MX*3;
	do{
		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 3 ; j++){
				for(int k = 0 ; k < (int) s[i].size() ; k++){
					if(i >= j)
						continue;
					bool ok = true;
					for(int ni = k ; ni < (int)s[i].size() ; ni++){
						int nj = ni - k;
						if(nj >= (int)s[j].size())
							break;
						if(s[i][ni] == '?' || s[j][nj] == '?')
							continue;
						if(s[i][ni] != s[j][nj])
							ok = false;
					}
					d[i][j][k] = ok;
				}
			}
		}
		auto f = [&](int i , int j , int k){
			if(k >= (int)s[i].size())
				return true;
			return d[i][j][k];
		};
		for(int x = 0 ; x < MX ; x++){
			for(int y = 0 ; y < MX ; y++){
				if(!f(0,1,x))
					continue;
				if(!f(1,2,y))
					continue;
				if(!f(0,2,x+y))
					continue;
				int now = 0;
				now = max<int>(now,int(s[0].size()));
				now = max<int>(now,int(x+s[1].size()));
				now = max<int>(now,x+y+s[2].size());
				ans = min(ans,now);
			}
		} 
		
	}while(next_permutation(s.begin(),s.end()));
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3680
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    vector<int> a(N), b(N);
    int t;
    for(int i=0; i!=N; i++){
        scanf("%d", &t);
        a[i]=t;
    }

    int i=N-1, j=0;
    for(; i>=0; i-=2){
        b[j++]=a[i];
    }
    if(i==-2) i=1;
    else i=0;
    for(; i<N; i+=2) b[j++]=a[i];

    for(i=0; i!=N; i++){
        printf("%d ", b[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3712
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 200010;

ll a[Maxn], idx[Maxn], l[Maxn], r[Maxn];

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        idx[a[i]] = i;
    }

    set<ll> s;
    s.insert(-1);
    s.insert(n);
    for (int v = 1; v <= n; ++v) {
        int i = idx[v];
        auto itr = s.upper_bound(i);
        r[i] = *itr;
        --itr;
        l[i] = *itr;
        s.insert(i);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += a[i] * (i - l[i]) * (r[i] - i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 15872
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int a[3010];
LL f[3010][3010];
bool visited[3010][3010];
int n;

LL dp(int l, int r) {
    if (visited[l][r]) {
        return f[l][r];
    }

    visited[l][r] = true;
    if (l == r) {
        return f[l][r] = a[l];
    }

    return f[l][r] = max((LL)a[l] - dp(l + 1, r), (LL)a[r] - dp(l, r - 1));
}

inline void work() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    cout << dp(1, n) << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 78592
a[256],n,x,y;main(i){while(scanf("%d ",&n),n){memset(a,0,1024);while(n--)scanf("%c %c ",&x,&y),a[x]=y;scanf("%d ",&n);while(n--)scanf("%c ",&x),putchar(a[x]?a[x]:x);puts("");}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pii pair <int,int>
#define reset(x) memset(x, 0,sizeof(x))
#define PB push_back
#define mp make_pair
#define maxn 1000005

using namespace std;
int n,cnt,p[maxn],res,rk[maxn];
struct data
{
    int x,y,id;
} a[maxn],b[maxn];
bool cmp1(data a,data b)
{
    return a.x<b.x;
}
bool cmp2(data a,data b)
{
    return a.y<b.y;
}
bool cmp3(data a,data b)
{
    return a.id<b.id;
}
int FIND(int u)
{
    int v=p[u];
    while(v!=u)
    {
        u=v;
        v=p[u];
    }
    return u;
}
void Union(int u,int v)
{
    int x=FIND(u);
    int y=FIND(v);
    if(x==y)
        return;
    else
    {
        if(rk[x]>rk[y])
            p[y]=x;
        if(rk[x]<rk[y])
            p[x]=y;
        if(rk[x]==rk[y])
        {
            p[y]=x;
            rk[x]++;
            return ;
        }
    }
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    //freopen("built.inp","r",stdin);
    //freopen("built.out","w",stdout);
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i].x>>a[i].y;
        a[i].id=i;
    }
    sort(a+1,a+1+n,cmp1);
    for(int i=1; i<n; i++)
    {
        b[++cnt].x=a[i].id;
        b[cnt].y=a[i+1].id;
        b[cnt].id=min(abs(a[i].x-a[i+1].x),abs(a[i].y-a[i+1].y));
    }
    sort(a+1,a+1+n,cmp2);
    for(int i=1; i<n; i++)
    {
        b[++cnt].x=a[i].id;
        b[cnt].y=a[i+1].id;
        b[cnt].id=min(abs(a[i].x-a[i+1].x),abs(a[i].y-a[i+1].y));
    }
    sort(b+1,b+1+cnt,cmp3);
    for(int i=1; i<=cnt; i++)
        p[i]=i;
    for(int i=1; i<=cnt; i++)
        if(FIND(b[i].x)!=FIND(b[i].y))
        {
            Union(b[i].x,b[i].y);
            res+=b[i].id;
        }
    cout<<res;

}


Measured memory_bytes: 12544
n, *a = $stdin.read.split.map(&:to_i)
a.sort!.reverse!
def gcd(a, b)
  b == 0 ? a : gcd(b, a % b)
end
res = gcd(a[0], a[1])
(2..n-1).each { |i| res = gcd(res, a[i]) }
puts res

Measured memory_bytes: 10096
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n, k;
int main(void) {
	
	cin >> n >> k;
	int ans = k;
	for (int i = 1; i < n; i++)
	{
		ans = ans * (k - 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >


using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10,mod=1e9+7;

ll __lcm(ll x,ll y){
    return x*y/__gcd(x,y);
}
int main ()
{
    FASTIO
    ll n , m;
    cin >> n >> m;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    ll lcm=1;
    for(int i=0;i<n;i++){
        lcm = __lcm(lcm,a[i]/2);
    }
    for(int i=0;i<n;i++){
        if((2*lcm/a[i])%2==0)return cout << 0 << endl,0;
    }
    ll ans = ceil(1.0*(m-lcm+1)/(2*lcm));
    cout << ans << endl;


    return 0;
}
/**

*/


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class ADiagonalString {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a1 = in.next();
            String a2 = in.next();
            String a3 = in.next();
            out.print(a1.charAt(0) + "" + a2.charAt(1) + "" + a3.charAt(2));
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public void close() {
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o set
int D;
int c[26];
int s[365][26];
void input(){
    scanf("%d",&D);
    for(int i=0;i<26;i++) scanf("%d",&c[i]);
    for(int i=0;i<D;i++) for(int j=0;j<26;j++) scanf("%d",&s[i][j]);
}

vector<int> calc(vector<int> d){
    vector<int> last(26,0);
    vector<int> ret;
    int res=0;
    for(int i=0;i<D;i++){
        res+=s[i][d[i]];
        last[d[i]]=i+1;
        for(int j=0;j<26;j++){
            res-=c[j]*(i+1-last[j]);
        }
        ret.pb(res);
    }
    return ret;
}
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    input();
    vector<int> d(D);
    rep(i,D){
        scanf("%d",&d[i]);
        d[i]--;
    }
    vector<int> ans=calc(d);
    for(int u:ans) cout << u << endl;
}


Measured memory_bytes: 3760
A, B = map(int, input().split())

if A == B:
    print('1')
    
elif B == 1:
    print('0')
    
else:
    AAA = 1
    C = 0
    
    while B > AAA:
        AAA = AAA + A - 1
        C += 1
        
    print(C)

Measured memory_bytes: 3316