akhauriyash/Code-Regression huggingface dataset:
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N;

void dfs(int pos, int num, string s) {
  if (pos == N) {
    writeln(s);
    return;
  }
  foreach (a; 0 .. num) {
    dfs(pos + 1, num, s ~ cast(char)('a' + a));
  }
  dfs(pos + 1, num + 1, s ~ cast(char)('a' + num));
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      dfs(0, 0, "");
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 2556
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2e5 + 5;

int fl[N], fr[N];

void add(int f[], int pos, int val = 1) {
    for (; pos < N; pos |= pos + 1) {
        f[pos] += val;
    }
}

int get(int f[], int pos) {
    int res = 0;
    for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
        res += f[pos];
    }
    return res;
}

int mod = 998244353;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        a[i] = p[i].second;
    }
    sort(a.begin(), a.end());
    map<int, int> mx;
    for (int i = 0; i < n; i++) {
        mx[a[i]] = i;
        add(fr, i);
    }
    for (int i = 0; i < n; i++) {
        p[i].second = mx[p[i].second];
    }
    sort(p.begin(), p.end());
    ll ans = (binpow(2, n) - 1) * n % mod;
    for (int i = 0; i < n; i++) {
        ll cnt[4];
        cnt[0] = get(fl, p[i].second);
        cnt[1] = get(fr, p[i].second) - 1;
        cnt[2] = get(fr, N - 1) - cnt[1] - 1;
        cnt[3] = get(fl, N - 1) - cnt[0];
        for (int j = 0; j < 4; j++) {
            ans = (ans - binpow(2, cnt[j] + cnt[(j + 1) % 4]) + 1 + mod) % mod;
        }
        for (int j = 0; j < 4; j++) {
            ans = (ans + binpow(2, cnt[j]) - 1) % mod;
        }
        add(fl, p[i].second);
        add(fr, p[i].second, -1);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 13568
a, b, m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
xyc = []
for _ in range(m):
    xyc_ = list(map(int, input().split()))
    xyc.append(xyc_)
ans = min(al) + min(bl)
for i in range(m):
    an = xyc[i][0] - 1
    bn = xyc[i][1] - 1
    ans = min(ans, al[an] + bl[bn] - xyc[i][2])
print(ans)

Measured memory_bytes: 38484
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  double tmp;
  cin >> n;
  double sum = 0;
  vector<double> hoge;
  for (int i = 0; i < n; i++){
    cin >> tmp;
    hoge.push_back(tmp);
  }
  sort(hoge.begin(), hoge.end());
  // for (int i = 0; i < hoge.size(); i++){
  //   cout << hoge[i] << endl;
  // }
  
  for (int i = 0; i < hoge.size(); i++){
    if(i == 0){
      sum = (hoge[i] + hoge[i+1])/2;
    }else if(i == 1){
      continue;
    }else{
      sum = (sum + hoge[i])/2;
    }
  }
  // int sum_b = 0;
  // for (int i = n - 1; i >= 0; i--){
  //   if (sum_b)
  //   {
  //     /* code */
  //   }
    
  //   if (i == n-1){
  //     sum_b = (hoge[i] + hoge[i-1])/2;
  //   }else if(i == n - 2){
  //     continue;
  //   }else{
  //     sum_b = (sum_b + hoge[i])/2;
  //   }
  // }
  // cout << fixed << setprecision(8) << max((hoge[n - 1] + hoge[n - 2])/2, sum) << endl;
  // cout << fixed << setprecision(8) << sum << endl;
  cout << sum << endl;
}

Measured memory_bytes: 384
import sys
from io import StringIO
import unittest


def resolve():
    # s = input()
    # n = int(input())
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p.sort()

    print(sum(p[0:k]))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5 3
50 100 80 120 80"""
        output = """210"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 1
1000"""
        output = """1000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main() {
  int N;
  cin >> N;
  int M = N;
  int fx = 0;
  while(M > 0) {
    fx += M % 10;
    M /= 10;
  }
  cout << (N % fx == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define BIG 2000000007
 
#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;
 
typedef struct {
	int a;
	int b;
} hw;
 
#define N_MAX 100000
#define M_MAX 100000
 
ull n, m, k;
ull h, w;
ull va, vb, vc, vd;
ull a[N_MAX];
// sll a[N_MAX];
ull b[N_MAX];
// ull dp[N_MAX][M_MAX + 1];
char s[N_MAX + 1];
// char t[N_MAX + 1];
// hw arr[N_MAX];
 
void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}
 
int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}
 
int min(ull x, ull y){
	return (x < y) ? x : y;
}
 
ull gcd(ull x, ull y){
	if (x < y) {
		return gcd(y, x);
	} else if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}
 
ull bitpow(ull a, ull x){
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= MOD;
		}
		x /= 2;
		a = (a * a) % MOD;
	}
	return result;
}

int comp(const void *left, const void *right){
	if ((*(int*)left) < (*(int*)right)) {
		return -1;
	} else if ((*(int*)left) > (*(int*)right)) {
		return +1;
	} else {
		return 0;
	}
}

// int nextroute(int arr[]){
// 	int i = n - 1;
// 	int j, x;
// 	while (arr[i - 1] > arr[i]) i--;

// 	x = n;
// 	for (j = i; j < n; j++) {
// 		if (arr[j] < arr[i - 1]) continue;
// 		if (x == n || arr[x] > arr[j]) x = j;
// 	}
// 	arr[i - 1] ^= arr[x];
// 	arr[x] ^= arr[i - 1];
// 	arr[i - 1] ^= arr[x];

// 	qsort(&arr[i], n - i, sizeof(int), comp);
// 	return 0;
// }

int nibutan_target(ull target){
	ull maxdist = (target * (target + 1) / 2); // 時刻targetまでに到着できる距離は[-maxdist, maxdist]
	return (n <= maxdist);
}

ull solve(){
	int i, j;

	ull ok = 1000000000;
	ull ng = 0;

	// 到着できる時刻の最小値を求める
	while (ok - ng > 1) {
		ull med = (ok + ng) / 2;
		if (nibutan_target(med)) {
			ok = med;
		} else {
			ng = med;
		}
	}

	printf("%llu\n", ok);

	return 0;
}
 
int main(void){
	int i, j;
	int x;

	scanf("%llu", &n);

	solve();

	return 0;
}


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

typedef long long ll;
const int maxn = 1e3;
int a[maxn];
int ans[maxn], cnt;

int main(){
  int n; scanf("%d", &n);
  ll odd = 0, eve = 0;
  bool check = true; int sm = - (1 << 31);
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
    if(a[i] > 0){
      if(i & 1) odd += a[i];
      else eve += a[i];
      check = false;
    }
    else sm = max(sm, a[i]);
  }
  if(check){
    bool ok = true;
    int sum = n;
    printf("%d\n%d\n", sm, n - 1);
    for(int i = 0; i < n; i++)
      if(ok)
        if(a[i] == sm) ok = false;
        else printf("%d\n", 1), sum--;
      else printf("%d\n", sum), sum--;
    return 0;
  }
  int i = odd > eve;
  if(i) ans[cnt++] = 1;
  while(a[i] < 0) ans[cnt++] = 1, ans[cnt++] = 1, i += 2;
  while(i + 2 < n){
    i += 2;
    if(a[i] >= 0) ans[cnt++] = 2;
    else ans[cnt++] = 3;
  }
  if(!(i == n - 1 && a[i] >= 0)) ans[cnt++] = 2;
  printf("%lld\n%d\n", max(odd, eve), cnt);
  for(int i = 0; i < cnt; i++) printf("%d\n", ans[i]);
  return 0;
}


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

public static partial class Program
{
    public static void Main()
    {
        var n = CRL().ToInt();
        var memo = new List<object[]>();
        for (int i = 0; i < n; i++)
        {
            var sp = CRL().Split();
            memo.Add(new object[]{sp[0], sp[1].ToInt(), i + 1});
        }

        foreach (var obj in memo.OrderByDescending(x => x[1]).OrderBy(x => x[0]))
        {
            CWL(obj[2]);
        }
    }
}

public static partial class Program
{
    //テンプレここから
    public static int Sigma(int n, int next = 1, int val = 0) => next > n ? val : Sigma(n, next + 1, val + next);
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    public static int LCM(int a, int b) => a * b / GCD(a, b);
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static readonly int[] Dx = new[] {0, -1, 0, 1};
    public static readonly int[] Dy = new[] {-1, 0, 1, 0};
    public const int Mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

    public static string JoinToStr(this IEnumerable<int> array, string sep = "")
        => array.Select(x => x.ToString()).Join(sep);

    //テンプレここまで
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int64_t>> a(n, vector<int64_t>(m));
    for (auto i : irange(0L, n)) {
        for (auto j : irange(0L, m)) {
            cin >> a[i][m - j - 1];
            --a[i][m - j - 1];
        }
    }

    int64_t ans = n;
    vector<bool> available(m, true);
    for (auto _ : irange(0L, m)) {
        vector<int64_t> c(m);

        for (const auto& b :
             a | transformed([](const auto& aa) { return aa.back(); })) {
            ++c[b];
        }

        auto b = max_element(c.begin(), c.end()) - c.begin();
        available[b] = false;
        ans = min(ans, c[b]);

        for (auto&& aa : a) {
            while (!aa.empty() && !available[aa.back()]) {
                aa.pop_back();
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    string s[N],t[N];
    int a[N],b[N];
    for(int i=0;i<N;i++){
        cin >> s[i];
        t[i] = s[i];
        a[i] = s[i].at(1);
        b[i] = a[i];
    }

    bool flg = true;
    while(flg){
        flg = false;
        for(int i=N-1;i>0;i--){
            if(a[i] < a[i-1]){
                swap(s[i], s[i-1]);
                swap(a[i], a[i-1]);
                flg = true;
            }
        }
    }
    
    for(int i=0;i<N-1;i++) cout << s[i] << ' ';
    cout << s[N-1] << endl;
    cout << "Stable" << endl;

    for(int i=0;i<N;i++){
        int minj = i;
        for(int j=i;j<N;j++){
            if(b[j] < b[minj]) minj = j;
        }
        swap(t[i], t[minj]);
        swap(b[i], b[minj]);
    }

    for(int i=0;i<N-1;i++) cout << t[i] << ' ';
    cout << t[N-1] << endl;
    bool stable=true;
    for(int i=0;i<N;i++){
        if(s[i] != t[i]) stable = false;
    }
    if(stable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vllp vector< pll >
#define F first
#define S second
#define MAX 1000000007
using namespace std;

ll mini(ll a,ll b)
{
    return a<b?a:b;
}
     
ll maxi(ll a,ll b)
{
    return a>b?a:b;
}

int main()
{
    
    ll n,k;
    cin>>n>>k;
    ll heights[n+1];
    for (int i = 1; i <=n; ++i)
    {
        cin>>heights[i];
    }
  
    ll toreach[n+1]={INT_MAX};
    for (int i = 0; i < n+1; ++i)
    {
        toreach[i]=1000000007;
    }
    toreach[1]=0;
    toreach[0]=0;
    for (int i = 1; i <=n; ++i)
    {
        for (int j =i+1; j<=mini(n,i+k); j++)
        {
            if(toreach[j]!=0)
            toreach[j]=mini(toreach[j],toreach[i]+abs(heights[i]-heights[j]));
        }
    }

    cout<<toreach[n]<<endl;

return 0;
}

Measured memory_bytes: 1792
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

int main() {
	ll a, b;
	cin >> a >> b;
	vector<priority_queue<ll>>pq(a);

	for (int i = 0; i < b; ++i) {
		ll x, y, z;
		cin >> x >> y;
		if (x == 0) {
			cin >> z;
			pq[y].emplace(z);
		}
		else if (x == 1 && pq[y].size() != 0) {
			cout << pq[y].top() << endl;
		}
		else if (x == 2 && pq[y].size() != 0) {
			pq[y].pop();
		}
	}
}


Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double pi = 3.141592653589793;

int main()
{
    ll x, n;

    cin >> x >> n;
    vector<ll> p(n);
    rep(i, n)
    {
        cin >> p[i];
    }
    for (int i = 0;; i++)
    {
        if (p.end() == find(p.begin(), p.end(), x - i))
        {
            cout << x - i << endl;
            break;
        }
        if (p.end() == find(p.begin(), p.end(), x + i))
        {
            cout << x + i << endl;
            break;
        }
    }
    // cout << endl;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i;
	scanf("%d",&n);
	i=1;
	while(1)	{
		if(i*i>n)	{
			i--;
			break;
		}
		i++;
	}
	printf("%d\n",i*i);
	return 0;
}

Measured memory_bytes: 128
//#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>



typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_


int main(void) {
	int X, Y;
	cin >> X;
	cin >> Y;

	int T, K;
	K = (Y - 2 * X) / 2;
	T = X - K;
	
	if ((Y - 2 * X) % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	if (K < 0 || T < 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


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

int main(){
    int box[3];
    scanf("%d",&box[1]);
    scanf("%d",&box[2]);
    scanf("%d",&box[0]);
    for(int i=0;i<3;i++){
        printf("%d ",box[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

inline long long GetMulti(int val)
{
  return (long long)val * val * val * val * val;
}

int main()
{
  unsigned int X;
  std::cin >> X;
  
  for(int A = 0; ; ++A)
  {
    const long long mulA = GetMulti(A);
    const long long result = mulA - X;
    
    if(result < 0)
    {
      long long mulB = 0;
      for(int B = 0; mulB >= result; --B)
      {
        mulB = GetMulti(B);
        if(result == mulB)
        {
          std::cout << A << " " << B << std::endl;
          return 0;
        }
      }
    }
    else
    {
      long long mulB = 0; 
      for(int B = 0; mulB <= result; ++B)
      {
        mulB = GetMulti(B);
        if(result == mulB)
        {
          std::cout << A << " " << B << std::endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll ans[200005];
graph g;
vector<ll> v;
vector<ll> x;

void dfs(int s){
  auto ite = lower_bound(x.begin(),x.end(),v[s]);
  ll n = *ite,p=ite-x.begin();
  x[p] = v[s];
  ans[s] = lower_bound(x.begin(),x.end(),INF)-x.begin();
  for(auto ns:g[s]){
    if(ans[ns]!=0) continue;
    dfs(ns);
  }
  x[p] = n;
}


int main() {
  ll N;
  cin>>N;
  v.resize(N);
  g.resize(N);
  rep(i,N) cin>>v[i];
  rep(i,N-1){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  x.assign(N+1,INF);
  dfs(0);
  rep(i,N) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 27400
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};


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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

int main(void){
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  ll cnt = 0;
  rep(i, N){
    cin >> A[i] >> B[i];
  }
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  rep(i, N){
    if((A[i] + cnt) % B[i] == 0) continue;
    cnt += B[i] - ((A[i] + cnt) % B[i]);
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N;
string t = "MFMFMFMFMFVMFMF";

int query(int x) {
    cout << x << endl;
    string y = ""; 
    // y += t[x]; 
    cin >> y;
    // cout << y << "\n";
    if (y[0] == 'V') exit(0);
    if (y[0] == 'M') return 0;
    return 1;
}

bool bad(pi a, pi b) {
    if ((b.f-a.f)&1) return a.s == b.s;
     return a.s != b.s;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    int x = query(0);
    pl l = {0,x}, r = {N,x};
    while (1) {
        int m = (l.f+r.f)/2;
        int t = query(m);
        //cout << m << " " << t << "\n";
        //exit(0);
        if (bad(l,{m,t})) r = {m,t};
        else l = {m,t};
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 852
def tri(a, b, c):
    if abs(b-c) < a and a < (b + c):
        return True
    else:
         return False

def solve():
    N = input()
    L = list(map(int,input().split()))
    ans = set()
    count = 0
    for i in range(len(L)):
        for j in range((i+1), len(L)):
            for k in range((j+1), len(L)):
                if L[i] == L[j] or L[i] == L[k] or L[j] == L[k]:
                    #print("pass", L[i], L[j], L[k])
                    pass
                elif tri(L[i], L[j], L[k]):
                    #print("l", L[i], L[j], L[k])
                    ans.add((i, j, k))
    #print(ans)
    print(len(ans))


if __name__ == "__main__":
    solve()

Measured memory_bytes: 93068
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			//偶数
			if(a%2==0){
				if(a%3!=0 && a%5!=0){
					System.out.println("DENIED");
					sc.close();
					return;
				}
			}
		}
		sc.close();
		System.out.println("APPROVED");
	}
}

Measured memory_bytes: 23380
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

func nextLine(s *bufio.Scanner) string {
	if !s.Scan() {
		panic("No more line")
	}

	return s.Text()
}

type entry struct {
	length int
	char   byte
	next   *entry
}

func maxEntry(a, b, c *entry) *entry {
	m := a

	if b.length > m.length {
		m = b
	}

	if c.length > m.length {
		m = c
	}

	return m
}

func main() {
	scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))

	s := nextLine(scanner)
	t := nextLine(scanner)

	var dp [][]*entry
	dp = make([][]*entry, len(s)+1)
	for i := 0; i < len(s)+1; i++ {
		dp[i] = make([]*entry, len(t)+1)
	}

	end := &entry{length: 0, char: 0, next: nil}

	for i := 0; i < len(s)+1; i++ {
		dp[i][len(t)] = end
	}
	for i := 0; i < len(t)+1; i++ {
		dp[len(s)][i] = end
	}

	for i := len(s) - 1; i >= 0; i-- {
		for j := len(t) - 1; j >= 0; j-- {
			a := dp[i+1][j+1]
			b := dp[i][j+1]
			c := dp[i+1][j]

			if s[i] == t[j] {
				a = &entry{length: a.length + 1, char: s[i], next: a}
			}

			dp[i][j] = maxEntry(a, b, c)
		}
	}

	var buf bytes.Buffer
	for cur := dp[0][0]; cur.length != 0; cur = cur.next {
		buf.WriteByte(cur.char)
	}
	fmt.Println(buf.String())
}


Measured memory_bytes: 370496
N,K,Q = [int(x) for x in input().split()]
AI = [0]*N
for _ in range(Q):
    ai = int(input())
    AI[ai-1] += 1
sum_a = sum(AI)

for ai in AI:
    if sum_a - ai >= K:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 50392
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main argv =
    let s = read id
    let t = "2019/04/30"
    if s <= t
    then printfn "Heisei"
    else printfn "TBD"
    0

Measured memory_bytes: 14284
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();
		long P = sc.nextLong();
		long num = 1;
		long n = 1;

		if(N==1) {
            System.out.println(P);
            return;
        }

		for (long i = 1; n <= P; i++) {

			if (P%n == 0) {
				num = i;
			}
			n = (long) Math.pow(i+1, N);
		}
		System.out.println(num);
	}
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	ll X=in<ll>(),Y=in<ll>();
	ll num = 0;
	while(X<=Y){
		X *= 2;
		num++;
	}

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


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

int main() {
  int A, B;
  string s;
  cin >> A >> B >> s;
  if (s.size() != A+B+1) cout << "No" << endl;
  else {
    bool is_post = true;
    for (int i=0; i<s.size(); i++) {
      if (i==A) {
        if (s.at(A)!='-') {
          cout << "No" << endl;
          is_post = false;
          break;
        }
      } else if (s.at(i)<'0' || s.at(i)>'9') {
        cout << "No" << endl;
        is_post = false;
        break;
      }
    }
    if (is_post) cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque

n,m,k = map(int,input().split())

f_set = {tuple(map(int,input().split())) for _ in range(m)}

b_set = {tuple(map(int,input().split())) for _ in range(k)}


friends_counts = {key:[] for key in range(1,n+1)}
blocks_counts = {key:[] for key in range(1,n+1)}

for f in f_set:
    friends_counts[f[0]].append(f[1])
    friends_counts[f[1]].append(f[0])

for b in b_set:
    blocks_counts[b[0]].append(b[1])
    blocks_counts[b[1]].append(b[0])



friends_groups_list = [set() for _ in range(n+1)]

#dfs
que = deque()
groups_count = 0
checked_dict = {key:0 for key in range(1,n+1)}
#que.appendleft(1)

for i in range(1,n+1):
    if checked_dict[i] == 1:
        continue
    que.appendleft(i)
    checked_dict[i] = 1

    while que:
        x = que.popleft()
        friends_groups_list[groups_count].add(x)
        for i in range(len(friends_counts[x])):
            if checked_dict[friends_counts[x][i]] == 0:
                que.appendleft(friends_counts[x][i])
            checked_dict[friends_counts[x][i]] = 1

    groups_count += 1



result_list=[0]*n

#print(blocks_counts)
#print(friends_groups_list)

for i in range(len(friends_groups_list)):
    mini_set = friends_groups_list[i]
    for ms in mini_set:
        result_list[ms-1] = len(mini_set) - 1 - len(friends_counts[ms])
        
        block_counter_in_minilist = 0

        for k in blocks_counts[ms]:
            if k in mini_set:
                block_counter_in_minilist += 1
        
        result_list[ms-1] -= block_counter_in_minilist
 
print(" ".join(map(str,result_list)))



#cの配列の解釈が違ったらしい。。。
#f_set = {tuple(map(int,input().split())) for _ in range(m)}
#
#b_set = {tuple(map(int,input().split())) for _ in range(k)}
#
#c_list = [0] * (n-1)
#
#result_dict = {key:0 for key in range(1,n+1)}
#
#for f in f_set:
#    if abs(f[0]-f[1]) == 1:
#        c_list[min(f[0],f[1]) - 1] = 1
#    #ここでelseで飛び石での友達のsetを作ってもよいが、そもそもsetなのでinでの探索にそんなに時間かからないし、いったんこのままやってみる。
#
#for start in range(0,n-2):
#    if c_list[start] == 0:
#        #c[start]が1になるまで飛ばす
#        continue
#
#    for end in range(start+1,n-1):
#        if c_list[end] == 0:
#            #友人同士ではないペアまできたらstartをインクリメント
#            break
#        
#        #もし「友人候補」の候補者が、「友人関係でない」かつ「ブロック関係でない」ことをチェックしている。
#        if not (start+1,end+2) in f_set and not (end+2,start+1) in f_set and not (start+1,end+2) in b_set and not (end+2,start+1) in b_set:
#            result_dict[start+1] += 1
#            result_dict[end+2] += 1
#
#for i in range(1,n+1):
#    print(result_dict[i])
#
#print(c_list)



Measured memory_bytes: 132180
n = int(input())
l = list(map(int,input().split()))
if n<3:
    print(0)
    exit()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            alist = sorted(list(set([l[i],l[j],l[k]])))
            if len(alist)== 3:
                if alist[2] < alist[0]+alist[1]:
                    cnt += 1
print(cnt)

Measured memory_bytes: 68632
loop do
  n,m=gets.split.map(&:to_i)
  break if n==0
  px,py,cnt=0,0,0
  arr=Array.new()
  n.times do 
    arr<<gets.chomp.split("")
  end
  loop do
    case arr[py][px]
    when "<" then px-=1
    when ">" then px+=1
    when "^" then py-=1
    when "v" then py+=1
    else break
    end
    cnt+=1
    break if cnt>n*m
  end
  puts cnt>n*m ? "LOOP": "#{px} #{py}"
end

Measured memory_bytes: 9016
#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

uint64_t gcd(uint64_t a, uint64_t b)
{
    if (a < b)
    {
        return gcd(b, a);
    }
    if (a % b == 0)
    {
        return b;
    }
    else
    {
        return gcd(b, a % b);
    }
}

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

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

    uint64_t ans = 1;
    for (int i = 0; i < n; i++)
    {
        uint64_t v;
        cin >> v;
        ans = lcm(ans, v);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>N>>S;
    ll cnt1=0;
    ll cnt2=0;
    ll rn=0;
    rep(i,N){
        if(S[i]==')'){
            cnt1++;
            if(cnt1>cnt2){
                rn++;
                cnt1--;
            }
        }else{
            cnt2++;
        }
    }
    

    ll ln=2*cnt2+rn-N;
    rep(i,rn){
        cout<<"(";
    }
    cout<<S;
    rep(i,ln){
        cout<<")";
    }
    cout <<  endl;


    return 0;
    

}

Measured memory_bytes: 3612
x,y=list(map(int,input().split()))
def gcd(x,y):
    if x==1 or y==1:
        return 1
    elif x == 0:
        return y
    elif y == 0:
        return x
    elif x >=y:
        return gcd(x%y,y)
    else:
        return gcd(y%x,x)
print(gcd(x,y))


Measured memory_bytes: 5600
#include <iostream>                                     
using namespace std;                                    
                                                        
int main() {                                            
  int W, H, x, y, r;                                    
  cin >> W >> H >> x >> y >> r;                         
  if (x>=r && W-x>=r && y>=r && H-y>=r) {               
    cout << "Yes" << endl;                              
  } else {                                              
    cout << "No" << endl;                               
  }                                                     
  return 0;                                             
}                                                       
     

Measured memory_bytes: 3120
#include <stdio.h>
#include <string.h>
char t1[1510];
char t2[1510];
int main(){
	int n;
	int a=0,b=0;
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",&t1,&t2);
		if(strcmp(t1,t2)==0) a++,b++;
		if(strcmp(t1,t2)>0) a+=3;
		if(strcmp(t1,t2)<0) b+=3;
	}
	printf("%d %d\n",a,b);
	return 0;
}


Measured memory_bytes: 2128
#include <algorithm>
#include <bitset>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pp;       // int aa = pp.first;
typedef tuple<int, int, int> tp; // int aa = get<0>(tp);

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

int all[100100];

class BIT {
public:
  vector<int> bit;
  int M;

  BIT(int M) : bit(vector<int>(M + 1, 0)), M(M) {}

  int get(int i) const {
    if (!i)
      return 0;
    return bit[i] + get(i - (i & -i));
  }

  void add(int i, int x) {
    if (i > M)
      return;
    bit[i] += x;
    add(i + (i & -i), x);
  }
};

void solve(long long N, long long M, vector<long long> l, vector<long long> r) {
  BIT bit(100010);

  vector<tp> vtp;
  REP(i, N) { vtp.push_back(tp(r[i] - l[i] + 1, l[i], r[i])); }
  sort(ALL(vtp));

  int pc = 0;
  FOR(m, 1, M + 1) {
    ll ans = 0;

    while (pc < N && get<0>(vtp[pc]) < m) {
      bit.add(get<1>(vtp[pc]), 1);
      bit.add(get<2>(vtp[pc]) + 1, -1);
      pc++;
    }

    ans += N - pc;

    for (int v = m; v <= 100000; v += m) {
      ans += bit.get(v);
    }

    cout << ans << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  long long M;
  cin >> N;
  vector<long long> r(N - 1 + 1);
  vector<long long> l(N - 1 + 1);
  cin >> M;
  for (int i = 0; i <= N - 1; i++) {
    cin >> l[i];
    cin >> r[i];
  }
  solve(N, M, l, r);
  return 0;
}


Measured memory_bytes: 16368
N,M = map(int,input().split())
if N > M:
    N,M = M,N
if M-N > 1:
    print(0)
    exit()

MOD = 10**9+7

fac = [1]
for n in range(1, M + 2):
    fac.append((fac[-1] * n) % MOD)

if M == N:
    print((fac[M] * fac[N] * 2) % MOD)
else:
    print((fac[M] * fac[N]) % MOD)

Measured memory_bytes: 7060
solve :: Int -> Int -> String
solve x y =
    let ok = not . null . filter f $ [(c, t) | c <- [0..50], t <- [0..25]]
    in if ok then "Yes" else "No"
        where f (c, t) = c + t == x && 2*c + 4*t == y

main :: IO ()
main = do
    [x, y] <- map read . words <$> getLine
    putStrLn $ solve x y

Measured memory_bytes: 3868
// AOJ 1068: School of Killifish
// 2017.12.14 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INF 0x7fffffff

int pool[10000000];
int **seg;
int h, w;
int r1, c1, r2, c2, g;
char buf[10000000], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

void update(int r, int c, int x)
{
	int c2, t, a;

	r += h - 1;
	c += w - 1;
	seg[r][c] = x;

	while (r >= 0) {
		c2 = c;
		while (c2) {
			if (!(c2 & 1)) c2--;
			t = c2, c2 >>= 1;
			a = seg[r][t++]; if (a > seg[r][t]) a = seg[r][t];
			seg[r][c2] = a;
		}
		if (r == 0) break;

		if (!(r & 1)) r--;
		t = r, r >>= 1;
		a = seg[t++][c]; if (a > seg[t][c]) a = seg[t][c];
		seg[r][c] = a;
	}
}
 
int query2(int l, int r, int k)
{
	int m, lmin, rmin;

	if (c2 <= l || r <= c1) return INF;
    if (c1 <= l && r <= c2) return seg[g][k];
     
	k <<= 1, m = (l + r) >> 1;
    lmin = query2(l, m, ++k);
    rmin = query2(m, r, ++k);
    if (lmin > rmin) lmin = rmin; 
    return lmin;
}
 
int query(int l, int r, int k)
{
	int m, lmin, rmin;

    if (r2 <= l || r <= r1) return INF;
    if (r1 <= l && r <= r2) { g = k; return query2(0, w, 0); }
    
	k <<= 1, m = (l + r) >> 1;
    lmin = query(l, m, ++k);
    rmin = query(m, r, ++k);
    if (lmin > rmin) lmin = rmin;
    return lmin;
}
 
int main()
{
	int R, C, Q, h2, w2, r, c, i;

    while (fgets(p=buf, 40, stdin) && *p != '0') {
		R = getint(), C = getint(), Q = getint();

		h = w = 1;
		while (h < R) h <<= 1;
		while (w < C) w <<= 1;

		h2 = (h << 1) - 1, w2 = (w << 1) - 1;

		memset(pool, 0, sizeof(pool));
		seg = malloc(h2 * sizeof(int *));
		for (r = 0; r < h2; r++) seg[r] = pool + r*w2;

        for (r = 0; r < R; r++) {
			fgets(p=buf, 10000000, stdin);
			for (c = 0; c < C; c++)	update(r, c, getint());
        }

        for (i = 0; i < Q; i++) {
			fgets(p=buf, 100, stdin);
			r1 = getint(), c1 = getint(), r2 = getint()+1, c2 = getint()+1;
            printf("%d\n", query(0, h, 0));
        }

		free(seg);
    }
    return 0;
}

Measured memory_bytes: 56876
#xi-xが全部Dの倍数になればいい
n,x=list(map(int, input().split()))
pos = list(map(int, input().split()))
diff_pos = [abs(s-x) for s in pos]
min_diff = min(diff_pos)
#print(min_diff)
ans = 0
def main():
    for i in range(min_diff,0,-1):
        for n in diff_pos:
            if n % i != 0:
                break
            if n == diff_pos[-1]:
                return i
    
    
print(main())

Measured memory_bytes: 20148
#include<bits/stdc++.h>
typedef long long ll;
#define X first
#define Y second
typedef double dbl;
#define forn(i,n,k) for(int i=0;i<n;i=i+k)
#define forpn(p,n,k) for(int i=p;i<n;i+=k)

using namespace std;
long long gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    string s;
  cin>>s;
  if(s=="ARC") cout<<"ABC";
  else cout<<"ARC";
          
    return 0;
}

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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

int trie[8][2] = { {1, 2}, {3, 4}, {5, 6}, {1, 1}, {1, 2}, {7, 2}, {6, 6}, {5, 5} };

ll dp[300000 + 10][8];

char s[300000 + 10];

int main()
{
    scanf("%s", s);
    int lens = strlen(s);
    dp[0][0] = 1;
    for(int i = 0;i < lens; i++)
    {
        for(int j = 0;j <= 7; j++)
        {
            if(s[i] != '1')
            {
                dp[i + 1][trie[j][0]] = (dp[i][j] + dp[i + 1][trie[j][0]]) % MOD;
            }
            if(s[i] != '0')
            {
                dp[i + 1][trie[j][1]] = (dp[i][j] + dp[i + 1][trie[j][1]]) % MOD;
            }
        }
    }
    printf("%lld\n", (dp[lens][2] + dp[lens][6]) % MOD);
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  ll x, y; cin >> x >> y;
  ll result = 0;
  if (x==0) {
    result = (y>0) ? y : -1*y+1;
  }
  else if (y==0) {
    result = (x>0) ? x+1 : -1*x;
  }
  else {
    if (x*y>0) {
      if (x>y) result = x-y+2;
      else result = y-x;
    }
    else {
      result = abs(x+y)+1;
    }
  }
  cout << result << endl;
  return 0;
}

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

int main() {
  string s;
  for (;;) {
    cin >> s;
    if (s == "0") break;
    int sum = 0;
    for (int i = 0; i < s.size(); i++) {
      sum += s.at(i) - '0';
    }
    cout << sum << endl;
  }
}



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



int main(){
    
    ll K; cin >> K;
    string S; cin >> S;
    if(S.size() <= K) cout << S << endl;
    else {
        string T = S.substr(0, K);
        T += "...";
        cout << T << endl;
    }

}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		
		long ans = 1;
		while(H>1) {
			H>>=1;
			ans= ans*2+1;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}





int main(){
string s; cin >>s;
int K; cin >> K;
int N = s.size();
REP(i, N){
    int d = 'z' - s.at(i) + 1;
    if(s.at(i) != 'a' && d <= K){
        s.at(i) = 'a';
        K -= d;
    }
}
K %= 26;
s.at(N - 1) += K;
print(s); 

}

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

int main()
{
    string S;
    bool flag = true;
    cin>>S;
    for(int i=0;i<static_cast<int>(S.length());i++){
        if(i%2==0){
            if(S[i]=='L')flag = false;
        }else{
            if(S[i]=='R')flag = false;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(){
    int n = 0;
    std::vector<int> vect;
    int counter = 0;
    int min_num = 200000+1;
    std::cin >> n;
    for(int i = 0; i < n; ++i){
        int tmp = 0;
        std::cin >> tmp;
        if(min_num >= tmp){
            min_num = tmp;
            ++counter;
        }
        vect.push_back(tmp);
    }

    std::cout << counter << std::endl;

    return 0;
}

Measured memory_bytes: 1400