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

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        
        SegmentTree[] st = new SegmentTree[26];
        for(int i = 0; i < 26; i++){
            st[i] = new SegmentTree(n+1);
        }
        for(int i = 1; i <= n; i++){
            st[s[i-1] - 'a'].update(i, 1);
        }
        
        int q = Integer.parseInt(sc.next());
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            if(Integer.parseInt(sc.next()) == 1){
                int iq = Integer.parseInt(sc.next());
                char cq = sc.next().charAt(0);
                st[s[iq-1] - 'a'].update(iq, 0);
                st[cq - 'a'].update(iq, 1);
                s[iq-1] = cq;
            }else{
                int lq = Integer.parseInt(sc.next());
                int rq = Integer.parseInt(sc.next());
                int ans = 0;
                for(int j = 0; j < 26; j++){
                    int k = st[j].getSum(lq, rq+1);
                    if(k > 0) ans++;
                }
                sb.append(ans).append(System.lineSeparator());
            }
        }
        System.out.print(sb);
    }
    
    static class SegmentTree {
        int n;
        int[] node;

        public SegmentTree(int size) {
            n = 1;
            while(n < size) n <<= 1;
            node = new int[2*n-1];
            Arrays.fill(node, 0);
        }
        public SegmentTree(int[] a) {
            n = 1;
            while(n < a.length) n <<= 1;
            node = new int[2*n-1];
            System.arraycopy(a, 0, node, n-1, a.length);
            Arrays.fill(node, n-1+a.length, 2*n-1, 0);
            for(int i = n-2; i >= 0; i--){
                node[i] = node[i*2+1] + node[i*2+2];
            }
        }
        void update(int i, int x){
            i += n-1;
            node[i] = x;
            while(i > 0){
                i = (i-1)/2;
                node[i] = node[i*2+1] + node[i*2+2];
            }
        }
        void add(int i, int x){
            i += n-1;
            node[i] += x;
            while(i > 0){
                i = (i-1)/2;
                node[i] = node[i*2+1] + node[i*2+2];
            }
        }
        int getSum(int a, int b){
            return getSum(a, b, 0, 0, n);
        }
        int getSum(int a, int b, int k, int l, int r){
            if(r <= a || b <= l) return 0;
            if(a <= l && r <= b) return node[k];
            int vl = getSum(a, b, k*2+1, l, (l+r)/2);
            int vr = getSum(a, b, k*2+2, (l+r)/2, r);
            return vl + vr;
        }
    }
}

Measured memory_bytes: 173344
// 5_abc129_e
#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>// 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>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int p ,q, r;
    cin >> p >> q >> r;
    int ans;
    ans = p + q;
    if(ans > q + r) ans = q + r;
    if(ans > r + p) ans = r + p;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  string s;cin>>s;
  if(s=="keyence"){
    cout<<"YES"<<endl;
    return 0;
  }
  int sz=s.size();
  for(int e=1;e<=sz;e++){
    for(int b=0;b<e;b++){
      if(s.substr(0,b)+s.substr(e,sz-e)=="keyence"){
	cout<<"YES"<<endl;
	return 0;
      }
    }
  }
  cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if('a' <= c && c <= 'z')
                c += 'A' - 'a';
            else if('A' <= c && c <= 'Z')
                c -= 'A' - 'a';
            System.out.print(c);
        }
    System.out.println();
    }
}


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

int main() {
	int a, b,time;
	cin >> a >> b;
	time = a + b;
	if (time > 23) {
		time-=24;
	}
	cout << time << endl;
}

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

int k;

int main(){
	cin >> k;
	if (k % 2 == 0) {
		cout << (k / 2)*(k / 2) << endl;
	}
	else {
		cout << (k / 2 + 1)*(k / 2) << endl;
	}
	return 0;
}

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

#define ll long long
#define re register
#define il inline
#define gc getchar
#define pc putchar

template <class T>
void read(T &x) {
  re bool f = 0;
  re char c = gc();
  while ((c < '0' || c > '9') && c != '-') c = gc();
  if (c == '-') f = 1, c = gc();
  x = 0;
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = gc();
  f && (x = -x);
}

template <class T>
void print(T x) {
  if (x < 0) pc('-'), x = -x;
  if (x >= 10) print(x / 10);
  pc((x % 10) ^ 48);
}

#define priln(x) do{print(x);pc('\n');}while(0)
#define prisp(x) do{print(x);pc(' ');}while(0)

int n;
int a[200005];

int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  int m = a[1], ans = 0;
  for (int i = 2; i <= n; ++i) {
    if (m >= a[i]) {
      ans++;
    }
    if (a[i] < m) m = a[i];
  }
  priln(ans + 1);
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String a1 = a.substring(0,1);
    String a2 = a.substring(1,2);
    String a3 = a.substring(2,3);
    String b1 = b.substring(0,1);
    String b2 = b.substring(1,2);
    String b3 = b.substring(2,3);

    if (a1.equals(b3) && a2.equals(b2) && a3.equals(b1)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    ll ans = 0;
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            int b = N - i*R - j*G;
            if(b % B == 0 && b >= 0) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		int s = int.Parse(Console.ReadLine());
		
		int a = s / 100;
		int b = s % 100;
		int hantei = 1;
		
		if(1<=a && a<=12){
			hantei = hantei*2;
		};
		
		if(1<=b && b<=12){
			hantei = hantei*3;
		};
		
		if(hantei == 1){
			Console.WriteLine("NA");
		}else if(hantei == 2){
			Console.WriteLine("MMYY");
		}else if(hantei == 3){
			Console.WriteLine("YYMM");
		}else if(hantei == 6){
			Console.WriteLine("AMBIGUOUS");
		};
		
	}
}

Measured memory_bytes: 11092
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n,l;
	cin >> n >> l;
	vector<string> st;
	REP(i, n)
	{
		string s;
		cin >> s;
		st.push_back(s);
	}
	ALL(sort, st);
	string ans = "";
	REP(i, SIZE(st))
	{
		ans += st[i];
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pii>> vv(n);
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    vv[p - 1].eb(mp(y, i));
  }
  vector<pair<int, pii>> ans;
  rep(i, n) {
    sort(all(vv[i]));
    rep(j, vv[i].size()) { ans.eb(mp(vv[i][j].S, mp(i + 1, j + 1))); }
  }
  sort(all(ans));
  rep(i, ans.size()) { printf("%06d%06d\n", ans[i].S.F, ans[i].S.S); }
}


Measured memory_bytes: 8308
#include <iostream>
#include <string>
#include <functional>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <algorithm>
#include <deque>

using namespace std;

const int N = 200000;

using i64 = long long;

int n, m;

vector<int> e[N], v, re[N];

int ind[N], dis[N], fa[N];

void tsort() {
    int rt = 0;
    for (int i = 0; i < n; i++) if (ind[i] == 0) rt = i;
    deque<int> q;
    q.push_back(rt);
    while (v.size() < n) {
        int x = q[0];
        q.pop_front();
        v.push_back(x);
        for (int i : e[x]) {
            ind[i]--;
            if (ind[i] == 0) q.push_back(i);
        }
    }
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m + n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        e[x].push_back(y);
        re[y].push_back(x);
        ind[y]++;
    }
    tsort();
    for (int i = 1; i < n; i++) {
        int x = v[i];
        // cout << "x = " << x << endl;
        for (int j : re[x]) {
            if (dis[x] < dis[j] + 1) {
                dis[x] = dis[j] + 1;
                fa[x] = j;
            }
        }
    }
    for (int i = 1; i <= n; i++) printf("%d\n", fa[i]);
}

Measured memory_bytes: 18428
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define REP(i,a,n) for(int i = (a);i < (n);i++)
#define PI 3.14159265359
#define MOD 1000000007
#define chmax(a,b) if(a < b)a = b

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 700;
    REP(i, 0, 3){
        if(s[i] == 'o')ans += 100;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 2e5+10;
const int mod = 1e9 + 7;
inline LL qpow(LL a,LL t) {LL ans=1LL;a%=mod;for (;t;t>>=1,a=a*a%mod) if (t&1) ans=ans*a%mod;return ans;}
LL fac[maxn],inv[maxn];
bool vis[maxn];
void init(){
    fac[0]=fac[1]=1;
    for(int i=2;i<maxn;i++) fac[i] = fac[i-1] * i % mod;
    inv[maxn-1]=qpow(fac[maxn-1], mod-2);
    for (int i=maxn-2;i>=0;i--) inv[i] = inv[i+1] * (i+1) % mod;
//    bs[1]=1;
//    for (int i=2;i<maxn;i++) bs[i]=bs[mod%i] * (mod - mod/i) % mod;
}
int n,m;
LL C(int p,int q){
    return fac[p] * inv[q] % mod * inv[p-q] % mod;
}
void work(){
    cin>>n>>m;
    LL ans = 1;
    int ed = sqrt(m);
    for (int i=2;i<=ed && m > 1;i++) if (!vis[i]){
        int cnt = 0;
        while (m % i == 0) {m/=i;cnt++;}
        if (cnt > 0) ans = ans * C(cnt + n - 1,n-1) % mod;
        for (int j=i*i;j <= ed ; j+=i) vis[j] = true;
    }
    if (m > 1) ans = ans * n % mod;
    cout<<ans<<endl;
}
int main(){
    init();
    work();
    return 0;
}


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

int main() {
    int n, sum = 0;
    cin >> n;

    vector<int> w(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i];
        sum += w[i];
    }
    int s1 = 0, s2, goal = sum / 2;
    int i = 0;

    while(1) {
        s1 += w[i];
        if(s1 > goal) {
            s2 = s1 - w[i];
            break;
        }
        i++;
    }
    int ans = min(abs(2 * s1 - sum), abs(2 * s2 - sum));
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cmath>
#include <algorithm>

#define R_MAX 10
#define C_MAX 10000

// ???????£?????????¶?????? 2^r ????????¨??¢?´¢?????????
// ??????????£????????????????????????§???????????§???
// ???????£?????????¶???????±?????????°???????£?????????¶??????????????§??¬???????±????????????????
// ????????????????????§?£???????????????°????????§??????????????????????±??????????
int solve(int senbeis[R_MAX][C_MAX], int r, int c) {
  int result = 0;

  // ???????£?????????¶????????¨??¢?´¢??????
  // i ??? n bit ?????? 1 ?????¨??? n-th row ????????£?????????????????¨?????????
  int bitMax = pow(2, r);
  for (int i = 0; i < bitMax; i++) {
    int baked = 0; // ?£??????????????????°
    for (int j = 0; j < c; j++) {
      int front_senbei = 0; // ??¨?????????????????°
      for (int k = 0; k < r; k++) {
        // i ??? k-th bit ?????????????????????1 ?????? senbeis[k][j] ??? 0,1 ????????¢
        front_senbei += (senbeis[k][j] ^ (i >> k & 1));
      }
      baked += std::max(front_senbei, r - front_senbei);
    }
    result = std::max(result, baked);
  }
  return result;
}

int main() {
  while (true) {
    int senbeis[R_MAX][C_MAX];
    int r, c;

    // input
    scanf(" %d %d", &r, &c);
    if (r == 0 || c == 0) break;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        scanf("%d", &senbeis[i][j]);
      }
    }

    // output
    printf("%d\n", solve(senbeis, r, c));
  }

  return 0;
}

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

#define MAX_N (50)
#define MAX_X (50)
#define MAX_SUM (MAX_N * MAX_X)
#define MAX_SUM_DIV2 (MAX_N * MAX_X / 2)

int main(int argc, char *argv[]) {
  int x[MAX_N], N, A;
  long sum[2][MAX_SUM + 1] = {{}, {}}, *sum_cur = sum[0], *sum_prev = sum[1];
  scanf("%d %d", &N, &A);
  for (int i = 0; i < N; i++)
    scanf("%d", &x[i]);
  for (int i = 0; i < N; i++)
    x[i] -= A;
  sum_cur[0 + MAX_SUM_DIV2] = 1;
  for (int i = 0; i < N; i++) {
    long *tmp = sum_cur;
    sum_cur = sum_prev;
    sum_prev = tmp;
    // don't add x[i]
    for (int j = -MAX_SUM_DIV2; j <= MAX_SUM_DIV2; j++)
      sum_cur[j + MAX_SUM_DIV2] = sum_prev[j + MAX_SUM_DIV2];
    // add x[i]
    int x_i = x[i];
    for (int j = -MAX_SUM_DIV2; j <= MAX_SUM_DIV2; j++) {
      if (j + x_i >= -MAX_SUM_DIV2 && j + x_i <= MAX_SUM_DIV2)
        sum_cur[j + x_i + MAX_SUM_DIV2] += sum_prev[j + MAX_SUM_DIV2];
    }
    // for (int j = -MAX_SUM_DIV2; j <= MAX_SUM_DIV2; j++)
    //   printf("end of i = %d: sum_cur[%d] = %ld\n", i, j, sum_cur[j + MAX_SUM_DIV2]);
  }
  printf("%ld\n", sum_cur[0 + MAX_SUM_DIV2] - 1);
  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val a = br.readLine().toInt()
    val b = br.readLine().toInt()
    val c = br.readLine().toInt()
    val x = br.readLine().toInt()
    var count = 0
    for (s in 0..a) {
        for (t in 0..b) {
            count += (0..c)
                    .filter { s * 500 + t * 100 + it * 50 == x }
                    .count()
        }
    }
    println(count)
}

fun err(print: Any) {
    System.err.println(print)
}

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

int main(){
  int n;
  cin >> n;
  for(int i = 0;i<n;i++){
    int a, b, c;
    cin >> a >> b >> c;
    if(max({a,b,c}) == a && b * b + c * c == a * a){
      cout << "YES" << endl;
    }else if(max({a,b,c}) == b && a * a + c * c == b * b){
      cout << "YES" << endl;
    }else if(max({a,b,c}) == c && a * a + b * b == c * c){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    ll ans = 0;

    {
        ll left = a.back(), right = a.back();
        ll tmp = 0;
        ll li = 0, ri = a.size() - 1;
        while(li < ri){
            if(li + 2 <= ri){
                tmp += max(
                    abs(left - a.at(li)) + abs(right - a.at(li + 1)),
                    abs(left - a.at(li + 1)) + abs(right - a.at(li))
                );
                left = a.at(li);
                right = a.at(li + 1);
                li += 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(li)), abs(right - a.at(li)));
                li += 1;
                break;
            }
            if(li + 2 <= ri){
                tmp += max(
                    abs(left - a.at(ri - 1)) + abs(right - a.at(ri - 2)),
                    abs(left - a.at(ri - 2)) + abs(right - a.at(ri - 1))
                );
                left = a.at(ri - 1);
                right = a.at(ri - 2);
                ri -= 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(ri - 1)), abs(right - a.at(ri - 1)));
                ri -= 1;
                break;
            }
        }
        ans = max(ans, tmp);
    }

    {
        ll left = a.front(), right = a.front();
        ll tmp = 0;
        ll li = 1, ri = a.size();
        while(li < ri){
            if(li + 2 <= ri){
                tmp += max(
                    abs(left - a.at(ri - 1)) + abs(right - a.at(ri - 2)),
                    abs(left - a.at(ri - 2)) + abs(right - a.at(ri - 1))
                );
                left = a.at(ri - 1);
                right = a.at(ri - 2);
                ri -= 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(ri - 1)), abs(right - a.at(ri - 1)));
                ri -= 1;
                break;
            }
            if(li + 2 <= ri){
                tmp += max(
                    abs(left - a.at(li)) + abs(right - a.at(li + 1)),
                    abs(left - a.at(li + 1)) + abs(right - a.at(li))
                );
                left = a.at(li);
                right = a.at(li + 1);
                li += 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(li)), abs(right - a.at(li)));
                li += 1;
                break;
            }
        }
        ans = max(ans, tmp);
    }

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


Measured memory_bytes: 1024
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			String np = "";
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			Map<String, Page> pages = new HashMap<String, Main.Page>();
			while (n-- > 0) {
				Page p = new Page();
				String name = scanner.next();
				if (np.equals(""))
					np = name;
				int b = scanner.nextInt();
				while (b-- > 0) {
					int sx = scanner.nextInt();
					int sy = scanner.nextInt();
					int ex = scanner.nextInt();
					int ey = scanner.nextInt();
					String to = scanner.next();
					Button bn = new Button(sx, sy, ex, ey, to);
					p.buttons.add(bn);
				}
				pages.put(name, p);
			}
			int m = scanner.nextInt();
			List<String> buff = new ArrayList<String>();
			buff.add(np);
			int pi = 0;
			int br = 1;
			while (m-- > 0) {
				String op = scanner.next();
				if (op.equals("click")) {
					int x = scanner.nextInt();
					int y = scanner.nextInt();
					String to = pages.get(buff.get(pi)).click(x, y);
					if (!to.equals("")) {
						pi++;
						if (pi == buff.size())
							buff.add(to);
						else
							buff.set(pi, to);
						br = pi + 1;
					}
				} else if (op.equals("back")) {
					if (pi != 0)
						pi--;
				} else if (op.equals("forward")) {
					if (pi + 1 != br)
						pi++;
				} else
					System.out.println(buff.get(pi));
			}
		}
	}

	class Button {
		int sx, sy, ex, ey;
		String to;

		public Button(int sx, int sy, int ex, int ey, String to) {
			super();
			this.sx = sx;
			this.sy = sy;
			this.ex = ex;
			this.ey = ey;
			this.to = to;
		}

		@Override
		public String toString() {
			return "Button [sx=" + sx + ", sy=" + sy + ", ex=" + ex + ", ey="
					+ ey + ", to=" + to + "]";
		}

		boolean isHit(int x, int y) {
			return sx <= x && x <= ex && sy <= y && y <= ey;
		}
	}

	class Page {
		List<Button> buttons = new ArrayList<Main.Button>();

		String click(int x, int y) {
			for (int i = 0; i < buttons.size(); i++) {
				if (buttons.get(i).isHit(x, y))
					return buttons.get(i).to;
			}
			return "";
		}

		@Override
		public String toString() {
			return "Page [buttons=" + buttons + "]";
		}
	}
}

Measured memory_bytes: 26408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h, w;
		h = scan.nextInt();
		w = scan.nextInt();
		String s;
		char X[][] = new char[h][w];
		for(int i = 0; i < h; i++){
			s = scan.next();
			for(int j = 0; j < w; j++)
				X[i][j] = s.charAt(j);
		}
		scan.close();

		int Y[][] = new int[h+2][w+2];
		for(int i = 0; i < h+2; i++)
			for(int j = 0; j < w+2; j++)
				Y[i][j] = 0;
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(X[i][j]=='#')findBomb(i+1,j+1,Y);
			}
		}
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(X[i][j]=='.')System.out.print(Y[i+1][j+1]);
				else System.out.print('#');
			}
			System.out.println();
		}
		
	}
	
	static void findBomb(int x, int y, int array[][]){
		for(int i = x - 1; i < x + 2; i++)
			for(int j = y - 1; j < y + 2; j++){
				array[i][j]++;
			}
		array[x][y]--;
	}
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 100;
const ll inf = 2e18 + 13;

ll dp[maxn] , partial_min[maxn] , a[maxn];

int main()
{
    fill(dp , dp + maxn , inf);
    ll n , e , T;
    cin >> n >> e >> T;
    e *= 2;
    T *= 2;
    for(int i = 1; i <= n; i++)
        cin >> a[i] , a[i] *= 2;
    dp[0] = 0;
    int pt = 0;
    for(int i = 1; i <= n; i++)
    {
        while(pt + 1 < i && a[pt + 1] <= a[i] - T / 2)
            pt++;
        if(!pt)
            dp[i] = T;
        else
            dp[i] = min(dp[pt] + T , partial_min[pt] + a[i] * 2);
        partial_min[i] = min(partial_min[i - 1] , dp[i - 1] - 2 * a[i]);
    }
    cout << (dp[n] + e) / 2 << endl;
}


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

int n, k, m, b;
long long ans, semi, a[31];

int main() {
    cin >> n >> k;
    for (int i=1; i<k+1; i++) {
        if ((k-i)%2 == 0) semi =1;
        else semi = -1;
        a[0] = i; b = n;
        for (int j=0; b > 0; j++) {
            if (b%2 == 1) semi = (semi*a[j]) % 1000000007;
            a[j+1] = (a[j]*a[j]) % 1000000007;
            b/=2;
        }
        if (2*i > k) m = i;
        else m = k-i;
        for (int j=k; j>m; j--) {
            semi = (semi * j) % 1000000007;
        }
        for (int j=2; j<k-m+1; j++) {
            a[0] = j; b = 1000000005;
            for (int s=0; b>0; s++) {
                if (b%2 == 1) semi = (semi * a[s]) % 1000000007;
                a[s+1] = (a[s]*a[s]) % 1000000007;
                b/=2;
            }
        }
        ans = (ans + semi + 1000000007)%1000000007;
    }
    if (n < k) ans = 0;
    cout << ans << endl;
}


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

int map[21][21];

void search(int a[][21], string d, int i, int *x, int *y) {

	if (d == "N") {
		for (int j = 1; j <= i; j++) a[*y + j][*x] = 2;
		*y += i;
	} else if (d == "S") {
		for (int j = 1; j <= i; j++) a[*y - j][*x] = 2;
		*y -= i;
	} else if (d == "E") {
		for (int j = 1; j <= i; j++) a[*y][*x + j] = 2;
		*x += i;
	} else if (d == "W") {
		for (int j = 1; j <= i; j++) a[*y][*x - j] = 2;
		*x -= i;
	}

}

int judge (int a[][21]) {
	for (int i = 0; i < 21; i++) {
		for (int j = 0; j < 21; j++) {
			if (a[i][j] == 1) return 0;
		}
	}
	return 1;
}

void print (int a[][21]) {
	for (int i = 20; i >= 0; i--) {
		for (int j = 0; j < 21; j++) {
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}


int main(void) {
	int N, x, y, M, i, nowx, nowy;
	string d;

	cin.tie(0);
	//ios::sync_with_stdio(false);

	while (cin >> N, N) {
		nowx = nowy = 10;
		for (int k = 0; k < 21; k++) {
			for (int l = 0; l < 21; l++) {
				map[k][l] = 0;
			}
		}

		//print(map);

		for (int j = 0; j < N; j++) {
			cin >> x >> y;
			map[y][x] = 1;
		}

		map[nowy][nowx] = 2;

		//print(map);

		cin >> M;

		for (int k = 0; k < M; k++) {
			cin >> d >> i;
			search(map, d, i, &nowx, &nowy);
			//print(map);
		}
		cout << (judge(map) == 1 ? "Yes" : "No") << "\n";

	}

	return 0;
}

Measured memory_bytes: 1180
import heapq

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x : x[0])
q = []
heapq.heapify(q)
ind = 0
ans = 0
for i in range(1,m+1):
    ok = True
    while ok:
        if  ind <= n-1 and ab[ind][0] <= i:
            heapq.heappush(q, -1 * ab[ind][1])
            ind += 1
        else:
            ok = False
    if len(q) >= 1:
        ans -= heapq.heappop(q)
print(ans)


Measured memory_bytes: 31924
#include<stdio.h>
int main(void)
{
	int i,j,k,l;
	int cnt;
	int n;

	while(scanf("%d",&n)!=EOF){
		cnt=0;
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				for(k=0;k<10;k++){
					for(l=0;l<10;l++){
						if(i+j+k+l==n){
							cnt++;
						}
					}
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>
#include <string.h>

using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge{
	int dst;
	ll cost;
	edge(int dst, ll cost){
		this->dst=dst; this->cost=cost;
	}

};


 
int V,E;
typedef vector<edge> edges;
vector<edges> g;

int nex[200005][30];
vector<int> dp;;

int main(){
	string s;
	cin >> s;
	dp.resize(s.size() + 5);
	rep(i, 26) {
		nex[s.size()][i] = s.size();
	}
	FORR(i, s.size() - 1, 0) {
		int c = s[i] - 'a';
		rep(j, 26) {
			if (j == c) {
				nex[i][j] = i;
			}
			else {
				nex[i][j] = nex[i + 1][j];
			}
		}

	}
	dp[s.size()] = 1;
	FORR(i, s.size() - 1, 0) {
		int mi = INF;
		rep(j, 26) {
			if (mi > dp[nex[i][j] + 1] + 1) {
				dp[i] = dp[nex[i][j] + 1] + 1;
				mi = dp[nex[i][j] + 1] + 1;
			}
		}
	}
	string ans;
	rep(i, s.size()) {
		int mi = INF;
		rep(j, 26) {
			if (mi > dp[nex[i][j] + 1] + 1) {
				mi = dp[nex[i][j] + 1] + 1;
			}
		}
		rep(j, 26) {
			if (mi == dp[nex[i][j] + 1] + 1) {
				ans += (j + 'a');
				i = nex[i][j];
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 24836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <sstream>
#include <cstdio>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

ll calc( string in, int index, bool& invalid ) {
	ll res = -1, a=0, b=0;
	rep(i, in.length()) if(in[i]=='_') in[i]='-';
	char c = in[index];
	if( c == '+' ) {
		sscanf( in.c_str(), "%lld+%lld", &a, &b );
		res = a + b;
	} else if( c == '-' ) {
		sscanf( in.c_str(), "%lld-%lld", &a, &b );
		res = a - b;
	} else if( c == '*' ) {
		sscanf( in.c_str(), "%lld*%lld", &a, &b );
		res = a * b;
	} else if( c == '/' ) {
		sscanf( in.c_str(), "%lld/%lld", &a, &b );
		if( b != 0 ) {
			res = a / b;
		} else {
			invalid = true;
		}
	}
	return res;
}

void solve( string e, vector<ll>& v ) {
//	cout << e << endl;
	bool br = false;
	int brBeg = 0;
	rep(i, e.length()) {
		if( e[i] == '(' ) {
			br = true;
			brBeg = i;
		}
	}
	if( br ) {
		int cnt = 0;
		int brEnd = 0;
		for(int i=brBeg+1; i<e.length(); i++) {
			if( e[i]==')' ) {
				if( cnt==0 ) {
					brEnd = i;
					break;
				} else {
					cnt--;
				}
			} else if( e[i]=='('){
				cnt++;
			}
		}
		string ne = e.substr(brBeg+1, brEnd-brBeg-1);
		vector<ll> vi;
		solve( ne, vi );
		rep(i, vi.size()) {
			string out = e;
			stringstream ss;
			ss << vi[i];
			string rep;
			ss >> rep;
			if(rep[0] == '-') rep[0] = '_';
			out.replace( brBeg, brEnd-brBeg+1, rep.c_str(), rep.length() );
			solve( out, v );
		}
	} else {
		int pos[10], cnt=0;
		rep(i, e.length()) {
			if( e[i]=='+' || e[i]=='-' || e[i]=='*' || e[i]=='/' ) {
				pos[cnt++] = i;
			}
		}
		rep(i, cnt) {
			int ps=pos[i]-1, pe=pos[i]+1;
			while( 0<=ps && (('0'<=e[ps] && e[ps]<='9') || e[ps]=='_') ) ps--;
			ps++;
			while( pe<e.length() && (('0'<=e[pe] && e[pe]<='9') || e[pe]=='_') ) pe++;
			pe--;
			bool invalid = false;
			ll res = calc( e.substr( ps, pe-ps+1 ), pos[i]-ps, invalid );
			if( invalid ) {
				continue;
			}
			stringstream ss;
			ss << res;
			string o;
			ss >> o;
			if(o[0]=='-') o[0] = '_';
//			cout << "start : " << ps << endl;
//			cout << "end : " << pe-ps+1 << endl;
			string out = e;
//			cout << "o : " << o << endl;
//			cout << "out : " << out << " -> ";
			out.replace( ps, pe-ps+1, o.c_str(), o.length() );
//			cout << out << endl;
			solve( out, v );
		}
		if( cnt == 0 ) {
			stringstream ss;
			if(e[0]=='_') e[0]='-';
			ss << e;
			ll ans;
			ss >> ans;
			v.push_back(ans);
		}
	}
}

int main() {
	string expr;
	while( cin >> expr, expr[0]!='#' ) {
		vector<ll> vi;
		solve(expr, vi);
//		cout << "---answers---" << endl;
//		rep(i, vi.size()) {
//			cout << vi[i] << endl;
//		}
		sort( vi.begin(), vi.end() );
		vi.erase( unique( vi.begin(), vi.end()), vi.end() );
		cout << vi.size() << endl;
	}
	return 0;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N, K;
  cin >> N >> K;
  vector<ll> dp(N, 1000000000000);
  vector<ll> v(N);

  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  dp[0] = 0;
  for(int i = 0; i < N-1; i++){
    for(int j = 1; j <= K; j++){
      if(i+j < N) dp[i+j] = min(dp[i+j], dp[i] + abs(v[i+j] - v[i]));
    }
  }
  cout << dp[N-1] << endl;
}



Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
from sys import setrecursionlimit
setrecursionlimit(100000)

def cal(L):
    if type(L[0][0]) == list:
        L = [[cal(l)*2] for l in L]
    return sum(sorted([-(-l[0]//2) for l in L])[:-(-len(L)//2)])

for _ in range(int(input())):
    print(cal(eval(input().replace("][", "],["))))


Measured memory_bytes: 10908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >>m;
  vector<string> N(n),M(m);
  for(int i = 0;i<n;i++){
    cin >> N.at(i);
  }
  for(int i = 0;i<m;i++){
    cin >>M.at(i);
  }
  vector<string> L(m);
  for(int i= 0;i+m<=n;i++){
    for(int j = 0;j+m<=n;j++){
      for(int k = 0;k<m;k++){
        L.at(k) = N.at(k+i).substr(j,m);
      }
          if(L == M){
      cout << "Yes";
      return 0;
    }


    }
  }
  cout << "No";
}

Measured memory_bytes: 256
var
    c,s,f,t: array[1..500] of Integer;
    n,i,j:Integer;
begin
    readln(n);
    for i := 1 to n-1 do
    begin
        readln(c[i],s[i],f[i]);
    end;
    t[n-1]:=c[n-1]+s[n-1];
    for i := n-2 downto 1 do
    begin
        t[i]:=c[i]+s[i];
        for j := i+1 to n-1 do
        begin
            if t[i]<=s[j] then 
            begin
                t[i]:=s[j]+c[j]//t[i]+s[j]-t[i]+c[j]
            end
            else    
            begin
                t[i]:=t[i]+c[j]+(f[j]-(t[i]-s[j]) mod f[j]) mod f[j];
            end;
        end;
    end;
    for i := 1 to n do
    begin
        writeln(t[i]);
    end;
    readln;
end.

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const string YES = "Yes";
const string NO = "No";

void func(long long X, long long Y) {}

int main() {
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);

    if (Y % 2 == 1) {
        cout << "No" << endl;
    }

    else if (Y < X * 2) {
        cout << "No" << endl;
    }

    else if (Y > X * 4) {
        cout << "No" << endl;
    }

    else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3764
import sys

sys.setrecursionlimit(10 ** 5)


def dfs(v, parent, depth):
    parents[v] = parent
    self_depths[v] = depth
    sd = 0
    for u in links[v]:
        if u == parent:
            continue
        res = dfs(u, v, depth + 1)
        sd = max(sd, res + 1)

    subtree_depths[v] = sd
    return sd


def solve(u):
    catch = self_depths[u] // 2
    while self_depths[parents[u]] > catch:
        u = parents[u]
    return self_depths[u] + subtree_depths[u] - 1


n, u, v = map(int, input().split())
u -= 1
v -= 1
links = [set() for _ in range(n)]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

parents = [-1] * n
self_depths = [0] * n
subtree_depths = [0] * n
dfs(v, -1, 0)
print(solve(u))


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

int a[5];

void slove(int win){
  for(int i=0; i<5; i++){
    if(a[i] == win) cout << "1" << endl;
    else cout << "2" << endl;
  }
}

int main(){
  while(cin >> a[0]){
    if(a[0]==0) break;
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    int count[5],flag=0;
    for(int i=0; i<5; i++) count[i] = 0;
    for(int i=0; i<5; i++){
      count[a[i]]++;
    }
    
    if((count[1]>0 && count[2]>0 && count[3]>0) || count[1]==5 || count[2]==5 || count[3]==5){
      for(int i=0; i<5; i++) cout << "3" << endl;
    }
    else{
      if(count[1] == 0) slove(2);
      if(count[2] == 0) slove(3);
      if(count[3] == 0) slove(1);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll n,a,b,c;
ll m[8],ans=INF;
ll ch[8];
void cal(){
	ll A,B,C;
	A=B=C=0;
	ll sum=-30;
	for(ll i=0;i<n;i++){
		if(ch[i]==1){
			A+=m[i];
		}
		else if(ch[i]==2){
			B+=m[i];
		}
		else if(ch[i]==3){
			C+=m[i];
		}
		if(ch[i]!=0){
			sum+=10;
		}
	}
	if(A==0||B==0||C==0){
		return ;
	}
	sum+=abs(A-a)+abs(B-b)+abs(C-c);
	ans=min(ans,sum);
}
void dep(ll now){
	if(now==n){
		cal();
		return ;
	}
	ch[now]=0;dep(now+1);
	ch[now]=1;dep(now+1);
	ch[now]=2;dep(now+1);
	ch[now]=3;dep(now+1);
}
int main() {
	cin>>n>>a>>b>>c;
	for(ll i=0;i<n;i++){
		cin>>m[i];
	}
	dep(0);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
Vi e[N];int n,m,d[N],id[N],pos[N],col[N],A[N],B[N];bool ok[N];
bool cmp(int x, int y){return d[x]<d[y];}
int main() {
	read(n);read(m);rep(i,1,n)read(d[i]),id[i]=i;
	rep(i,1,m){
		read(A[i]);read(B[i]);
		e[A[i]].pb(B[i]);e[B[i]].pb(A[i]);
	}
	sort(id+1,id+n+1,cmp);
	rep(i,1,n)pos[id[i]]=i;
	rep(i,1,n){
		int x=0;
		rep(j,0,SZ(e[id[i]])-1)if(pos[e[id[i]][j]]<i)
			x=col[e[id[i]][j]]^1;
		rep(j,0,SZ(e[id[i]])-1)if(pos[e[id[i]][j]]<i&&!ok[e[id[i]][j]])
			x=col[e[id[i]][j]]^1;
		col[id[i]]=x;
		rep(j,0,SZ(e[id[i]])-1)if(pos[e[id[i]][j]]<i&&col[e[id[i]][j]]!=x)
			ok[id[i]]=1,ok[e[id[i]][j]]|=d[e[id[i]][j]]==d[id[i]];
	}
	rep(i,1,n)if(!ok[i]){puts("-1");return 0;}
	rep(i,1,n)printf("%c",col[i]?'B':'W');puts("");
	rep(i,1,m)printf("%d\n",max(d[A[i]],d[B[i]]));
	return 0;
}


Measured memory_bytes: 36736
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(void){
    int i,n,x[100],y[100];
    double p_1=0,p_2=0,p_3=0,p_0=0;
 
    scanf("%d",&n);
     
    for(i=0;i<n;i++)
        scanf("%d",&x[i]);
    for(i=0;i<n;i++)
        scanf("%d",&y[i]);
     
    for(i=0;i<n;i++){
         
    //p=1
        p_1 += abs(x[i]-y[i]);
     
    //p=2
        p_2 += pow(fabs((double)x[i]-y[i]),2.0);
     
    //p=3
        p_3 += pow(fabs((double)x[i]-y[i]),3.0);
     
    //p=endless
        if(p_0 < abs(x[i]-y[i])) p_0 = abs(x[i]-y[i]);
         
    }
     
    printf("%lf\n%lf\n%lf\n%lf\n", p_1, pow(p_2,1.0/2), pow(p_3,1.0/3), p_0);
     
     
    return 0;
}


Measured memory_bytes: 2144
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	double a, b, h, m;
	double ans;
	double rad;
	cin >> a >> b >> h >> m;
	rad = (h * 30.00 + 0.5 * m - m * 6);


	ans = sqrt(a * a + b * b - 2.0 * a * b * cos(rad * pai / 180.0));
	cout << setprecision(30) << ans;


}

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

typedef pair<int,int> P;

int main(){
    vector<char>v(300010);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        v.at(i) = s.at(i);
    }
    int top = 0;
    int end = s.size()-1;
    int q;
    cin >> q;
    bool vec = true;
    for (int i = 0; i < q; i++){
        int x;
        cin >> x;
        if (x == 1){

            vec = !vec;

        }else if(x == 2){

            int y;
            cin >> y;
            char cx;
            cin >> cx;
            if ((y == 1 && vec) || (y == 2 && !vec)){

                top--;
                if (top < 0) top = 300009;
                v.at(top) = cx;

            }else{

                end++;
                if (end > 300009) end = 0;
                v.at(end) = cx;

            }   
        }
    }
    if (vec){
        while(1){
            cout << v.at(top);
            if (top == end) break;
            top++;
            if (top > 300009) top = 0;
        }
    }else{
        while(1){
        cout << v.at(end);
        if (top == end) break;
        end--;
        if (end < 0) end = 300009;
        }
    }
    cout << "\n";
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    ll n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
      int N;
      String an = scan.nextLine();
      N = Integer.parseInt(an);
       //System.out.println(N);
      check(N);
        scan.close();
    }
  
  public static void check(int n){
    int c;
    c = n % 10;
    if(c == 3){
       System.out.println("bon");
      return;
    }else if((c == 0)||(c ==1)||(c ==6)||(c ==8)){
      System.out.println("pon");
      return;
    }else{
      System.out.println("hon");
      return;
    }
    
  }
}

Measured memory_bytes: 35756
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            int n = Integer.parseInt(str[0]);
            int y = Integer.parseInt(str[1]);
            boolean flag = false;
            for (int i = n; i >= 0; i--) {
                for (int j = n - i; j >= 0; j--) {
                    for (int k = n - (i + j); k >= 0; k--) {
                        if (i + j + k != n) {
                            continue;
                        } else {
                            if (10000 * i + 5000 * j + 1000 * k == y) {
                                System.out.println(i + " " + j + " " + k);
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (flag) {
                        break;
                    }
                }
                if (flag) {
                    break;
                }
            }
            if (!flag) {
                System.out.println("-1 -1 -1");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 22996
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int R; cin >> R;

    string ans = "";
    if (R < 1200) ans = "ABC";
    else if (R < 2800) ans = "ARC";
    else ans = "AGC";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256