akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
N, M, Q = map(int, input().split())
D = [[0] * (N + 1) for i in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    D[L][R] += 1
for i in range(N - 1, 0, -1):
    for j in range(1, N + 1):
        D[i][j] += D[i + 1][j]
for i in range(1, N + 1):
    D[i] = list(accumulate(D[i]))
for _ in range(Q):
    p, q = map(int, input().split())
    print(D[p][q])

Measured memory_bytes: 59096
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if(v <= w) {
        out("NO");
        re0;
    }
    
    if(abs(a-b) <= t*(v - w)) {
        out("YES");
    }
    else {
        out("NO");
    }

    re0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

ll gcd(ll a, ll b){
    if(b == 0)return a;
    return gcd(b,a%b);
}
ll num(ll n, ll c, ll d){
    ll g = gcd(c,d);
    ll l = c/g*d;//最小公倍数
    return n - n/c - n/d + n / l;
}
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << num(b, c, d) - num(a-1,c,d) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a - b) % c << endl;
	return 0;
}

//Ctrl+Aを使わない

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

int main() {
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  
  if(A>=K) cout<<K<<endl;
  else if(A+B>=K) cout<<A<<endl;
  else cout<<2*A+B-K<<endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	
	int m1 = H1 * 60 + M1;
	int m2 = H2 * 60 + M2;
	int ans = m2-K-m1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <iomanip>

int main()
{
	int a, b, h, m;
	std::cin >> a >> b >> h >> m;
	
	double pi = std::acos(-1);
	double angle = (m / 60.0 - h / 12.0 - m / 12.0 / 60.0) * 2.0 * pi;
	double a_dot_b = a * b * std::cos(angle);
	double a_minus_b = std::sqrt(a * a - 2 * a_dot_b + b * b);
	
	std::cout << std::setprecision(20) << a_minus_b << std::endl;
	
	return 0;
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  vector<tuple<string,int,int>> v;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    int p; cin >> p;
    v.push_back(make_tuple(s,-p,i+1));
  }
  sort(v.begin(),v.end());
  for(int i = 0; i < n; i++){
    cout << get<2>(v[i]) << endl;
  }

  return 0;
}


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll a, v, b, w, t;
	read(a, v, b, w, t);
	if (w > v) die("NO");
	ll d = (v - w) * t;
	if (abs(b - a) <= d)
		die("YES");
	die("NO");
}


Measured memory_bytes: 3648
#include<iostream>

using namespace std;

int main(){
	int N; string S;
	cin >> N >> S;
	int length = S.length();
	for(int i = 0; i < length; i++){
		S[i]+=N;
		if(S[i] > 'Z')
			S[i] -= 26;
	}
	cout << S << '\n';
	return 0;
}

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

using namespace std;

int main(void)
{
  int ingredients_count;
  vector<int> ingredient_values;
  
  cin >> ingredients_count;

  for(int i = 0; i < ingredients_count; i++){
    int ing;
    cin >> ing;
    ingredient_values.push_back(ing);
  }
  
  sort(ingredient_values.begin(), ingredient_values.end());
  
  double value_ave = ingredient_values[0];
  for(int i = 1; i < ingredients_count; i++){ 
    value_ave = (double)(value_ave + ingredient_values[i]) / 2;
  }
  
  cout << value_ave << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
char s[205];
int l,m,h,i;
void rev(int r,int l)
{
    char x;
    for(;r<l;r++,l--)
    {
        x=s[r];s[r]=s[l];s[l]=x;
    }
}
int main()
{
    for(;scanf("%s",s),s[0]!='-';)
    {
        l=strlen(s)-1;
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            scanf("%d\n",&h);
            rev(0,h-1);
            rev(h,l);
            rev(0,l);
        }
        puts(s);
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int H, W, D;
int M[500][500];
int T[2000][2000];

int main() {
	cin >> H >> W >> D;

	// initialize
	rep(y, 2000) rep(x, 2000) T[y][x] = -1;

	int L;
	if(D % 2 == 1){
		L = 2;
		T[0][0] = 0;
		T[0][1] = 1;
		T[1][0] = 1;
		T[1][1] = 0;
	}
	else{

		L = D * 2;
		vector<int> vs = {0, 1, 2, 3, 1, 0, 3, 2};
		vector<int> xs = {0, 2, 1, 3, 0, 2, 1, 3};
		vector<int> ys = {0, 0, 1, 1, 2, 2, 3, 3};

		rep(i, 8){
			int v = vs[i];
			int x = xs[i] * D / 2;
			int y = ys[i] * D / 2;

			int mnx = 0;
			int mxx = 0;
			for(int yy = 0; yy <= D-2; yy++){
				for(int xx = mnx; xx <= mxx; xx += 2){
					int yyy = (y + yy + L) % L;
					int xxx = (x + xx + L) % L;
					// fprintf(stderr, "%d [%d][%d] %d %d\n", v, yyy, xxx, y, x);
					T[yyy][xxx] = v;
				}
				if(yy < (D-2)/2){
					mnx--;
					mxx++;
				}
				else{
					mnx++;
					mxx--;
				}
			}
		}

		// painting odd
		rep(y, L) rep(x, L){
			int xx = (x - 1 + L) % L;
			int yy = y;
			if(T[y][x] == -1) T[y][x] = T[yy][xx];
		}
	}

	// output;
	rep(y, H) rep(x, W){
		M[y][x] = T[y % L][x % L];
	}

	vector<char> cs = {'R','Y','G','B'};

	// debug
	/*
	rep(y, L){
		rep(x, L) {
			int col = T[y][x];
			cerr << col; // cs[col];
		}
		cerr << endl;
	}
	*/

	rep(y, H){
		rep(x, W) {
			int col = M[y][x];
			cout << cs[col];
		}
		cout << endl;
	}
}

Measured memory_bytes: 17152
n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]

py.sort(key=lambda x:x[0]*10**6+x[1])
ne=[1]*(10**5+1)
ans=[]

for p,_,i in py:
    ans.append((str(p).zfill(6)+str(ne[p]).zfill(6),i))
    ne[p]+=1

ans.sort(key=lambda x:x[1])
for s,_ in ans:
    print(s)

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

using namespace std;

int main() {
    string S;
    string sub_S;

    cin >> S;
    
    int max_size = 0;
    int S_size = S.size();
    int sub_S_size;

    for(int i = 0; i < S_size; i++) {
        sub_S = "";
        for(int j = i; j < S_size; j++) {
            if(S[j] != 'A' && S[j] != 'C' && S[j] != 'G' && S[j] != 'T') {
                break;
            }
            sub_S += S[j];
        }
        sub_S_size = sub_S.size();
        max_size = max(max_size, sub_S_size);       
    }

    cout << max_size << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cstdio>

using namespace std;

double EPS = 1e-10;

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

struct P {
	double x, y;
	P() {}
	P(double x, double y) : x(x), y(y) {
	}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d) {
		return P(x*d, y*d);
	}
	double dot(P p) {
		return add(x*p.x, y*p.y);
	}
	double det(P p) {
		return add(x*p.y, -y*p.x);
	}
};

bool cmp_x(const P& p, const P& q) {
	if (p.x != q.x) {
		return p.x < p.y;
	}
	return p.y < q.y;
}

vector<P> convex_hell(P* ps, int n) {
	sort(ps, ps+n, cmp_x);
	int k = 0;
	vector<P> qs(n*2);
	for (int i = 0; i < n; i++) {
		while (k > 1 && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}

	for (int i = n-2, t = k; i >= 0; i--) {
		while (k > t && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	qs.resize(k-1);
	return qs;
}

double dist(P p, P q) {
	return (p-q).dot(p-q);
}

P ps[25];

int main() {
	char w;
	int i = 0;
	while (cin >> ps[i].x >> w >> ps[i].y) {
		i++;
	}
	vector<P> qs = convex_hell(ps, i);
	double a, b, c, z;
	double sum = 0.0;
	for (int j = 1; j < i-1; j++) {
		a = sqrt(dist(qs[0], qs[j]));
		b = sqrt(dist(qs[0], qs[j+1]));
		c = sqrt(dist(qs[j], qs[j+1]));
		z = (a+b+c)/2.0;
		sum += sqrt(z*(z-a)*(z-b)*(z-c));
	}
	printf("%.6f\n", sum);
	return 0;
}

Measured memory_bytes: 1248
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var a, b int
  fmt.Scan(&a, &b)
  ans := maxInt(a+b, a-b, a*b)
  fmt.Println(ans)
}


Measured memory_bytes: 512
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let a: Vec<usize> = (0..(N - 1))
        .map(
            |_| {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().parse().unwrap()
            }
        )
        .collect();

    // DAGを構成し、DPにより解を求める
    let mut G = vec![vec![]; N + 1];
    for i in 2..(N + 1) {
        G[a[i - 2]].push(i);
    }
    fn f(i: usize, G: &Vec<Vec<usize>>) -> usize {
        if G[i].is_empty() {
            0
        } else {
            let mut xs: Vec<_> = G[i].iter()
                .map(|&c| f(c, &G))
                .collect();
            xs.sort();
            xs.iter().fold(0, |acc, &x| std::cmp::max(acc, x) + 1)
        }
    }
    let ans = std::thread::Builder::new()
        .name("_".into())
        .stack_size(33554432)
        .spawn(move || f(1, &G))
        .unwrap()
        .join()
        .unwrap();
    println!("{}", ans);
}



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

class Program
{
    static void Main(string[] args)
    {
        string str;
        string[] str2 = new string[] { };
        int a, b;
        string tas;
       
        int result = 0;
        var list = new List<int>();

        do
        {
            str = Console.ReadLine();
            str2 = str.Split(' ');
            a = int.Parse(str2[0]);
            b = int.Parse(str2[2]);
            tas = str2[1];


            if (tas == "?")
            {
                break;
            }

            if (tas == "+")
            {
                result = a + b;
            }
            else if (tas == "-")
            {
                result = a - b;
            }
            else if (tas == "*")
            {
                result = a * b;
            }
            else if (tas == "/")
            {
                result = a / b;
            }

            list.Add(result);

        } while (true);

        foreach (var s in list)
        {
            Console.WriteLine(s);
        }
        
    }
}


Measured memory_bytes: 17952
#include <iostream>
#include <cstdio>

const int MAXN = 1e5;

int n;
int a[MAXN | 1];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  int minn = 2e9;
  minn = a[n];
  for (int i = n - 1; i >= 1; --i) {
    if (a[i] - minn >= 2) {
      puts("No");
      return 0;
    }
    minn = std::min(minn, a[i]);
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e18 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int h,w;
  cin >> h >> w;
  string s[h+1];
  vector<vector<ll> > dp(h+1,vector<ll>(w+1,0));

  rep(i,h) {
    cin >> s[i];
  }
  

  dp[0][0] = 1;
  rep(i,h) {
    rep(j,w) {
      if (i != h-1 and s[i+1][j] != '#') {
        dp[i+1][j] += dp[i][j];
        dp[i+1][j] %= MOD;
      }
      if (j != w-1 and s[i][j+1] != '#') {
        dp[i][j+1] += dp[i][j];
        dp[i][j+1] %= MOD;
      }
    }
  }

  cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 9216
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;
 
 
public class Main{
    public static int[] dp=new int[77777777];
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
       int[][] a = new int[2][4];
       int i,j,m;
       long k=1,n=0;
       m = solve(76543210);
       while(s.hasNext()){
       for(i=0;i<2;i++){
           for(j=0;j<4;j++){
        m=s.nextInt();
        n+=k*(long)m;
        k*=10;
       }
    }
 
 
            
       // m = solve(n);
        System.out.println(Main.dp[(int)n]);
        n=0;
        k=1;
}
    }
    public static int solve(long n){
        Queue<Long> qu=new LinkedList<Long>();
        int[] x = {1,-1,0,0},y= {0,0,1,-1};
        long[] zc =new long[50000];
        int[][] arr = new int[2][4];
        int i,j,zh=-5,zw=-5,e,ppp=0,col=0,kri=0;
        long k=n,temp,no;
        boolean ch=false,chk=false;
        qu.add(n);
        while(true){
            if(qu.size()==0)return 0;
        k = qu.remove();
  //      if(k%100000000==76543210)return (int)k/100000000+kri;
        for(i=0;i<2;i++){
            for(j=0;j<4;j++){
                arr[i][j]=(int)k%10;
                k/=10;
                if(arr[i][j]==0){
                    zh=i;
                    zw=j;
                }
            }
        }
   //     System.out.println(k+" " +col);
        if(k==19){
            kri=20;
            k=0;
        }
        else k++;
 
        k*=100000000;
        no = k;
        for(e=0;e<4;e++){
            if(zh+x[e]>=0&&zh+x[e]<2&&zw+y[e]>=0&&zw+y[e]<4){
            arr[zh][zw] = arr[zh+x[e]][zw+y[e]];
            arr[zh+x[e]][zw+y[e]]=0;
        temp =1;
        for(i=0;i<2;i++){
            for(j=0;j<4;j++){
                k+=temp*(long)arr[i][j];
                temp*=10;
            }
        }
       /* for(ppp=0;ppp<col;ppp++)if(zc[ppp]==k%100000000)ch=true;
        if(ch==false){
            zc[col]=k%100000000;
            qu.add(k);
            col++;
        }*/
        if(Main.dp[(int)k%100000000]==0){
            Main.dp[(int)k%100000000]=(int)k/100000000+kri;
            //System.out.println(sep3.dp[(int)k%100000000]+" "+k%100000000);
            qu.add(k);
        }
        else ch = false;
        k = no;
        arr[zh+x[e]][zw+y[e]] = arr[zh][zw];
        arr[zh][zw]=0;
    }
}
    }
}
 
    }



Measured memory_bytes: 346552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
int a[10][1005];
int tot[10];
int main()
{
	int h , w , K;
	scanf("%d %d %d" , &h, &w, &K);
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			scanf("%1d" , &a[i][j]);
	int ans = 1000000000;
	for(int i = 0; i < (1 << (h - 1)); i++)
	{
		memset(tot , 0 , sizeof tot);
		bool pzdc = false;
		int curAns = __builtin_popcount(i);
		for(int j = 0; j < w; j++)
		{
			int cur = 0;
			for(int k = 0; k < h; k++)
			{
				tot[cur] += a[k][j];
				cur += (i >> k) & 1;
			}
			for(int it = 0; it < 10; it++)
				if(tot[it] > K)
				{
					curAns++;
					memset(tot , 0 , sizeof tot);
					cur = 0;
					for(int k = 0; k < h; k++)
					{
						tot[cur] += a[k][j];
						if(tot[cur] > K)
							pzdc = true;
						cur += (i >> k) & 1;
					}
					break;
				}
		}
		
		if(!pzdc)
		{
			ans = min(ans , curAns);
		}
	}
	
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<pi>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int n;
vvl dp;
ll A[3000];
ll f(int l, int r) {
    if(l > r) return 0;
    if(dp[l][r] != INF) return dp[l][r];
    int flg = (l + n - r) % 2;
    if(flg) dp[l][r] = max(f(l + 1, r) + A[l], f(l, r - 1) + A[r]);
    else dp[l][r] = min(f(l + 1, r) - A[l], f(l, r - 1) - A[r]);
    return dp[l][r];
}


int main(){
    cin >> n;
    rep(i, n) cin >> A[i];
    dp.resize(n, vl(n, INF));
    co(f(0, n - 1));
}



Measured memory_bytes: 73932
#include <stdio.h>
#include <math.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define repm(i,l,r) for((i)=(l);(i)<(r);(i)--)
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) ((a)>(0)?(a):-(a))
int main(){
    long long i,j,n,k,ans=10e9,buf=0,buf1,buf2,s;
    scanf("%lld%lld",&n,&k);
    long long x[n],sub[n];
    rep(i,0,n){
        scanf("%lld",&x[i]);
        if(k==1)ans=min(ans,abs(x[i]));
        if(i>0)sub[i-1]=abs(x[i]-x[i-1]);
    }
    if(k>1){
    rep(i,0,n-k+1){
        if(i==0)rep(j,0,k-1)buf+=sub[j];
        else buf=buf+sub[i+k-2]-sub[i-1];
        buf1=abs(x[i]);
        buf2=abs(x[i+k-1]);
        s=min(buf1,buf2);
        ans=min(buf+s,ans);
    }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 1664
import numpy as np
n,m=map(int,input().split())
x=list(map(int,input().split()))

arr=np.sort(np.array(x))
dif=np.diff(arr)

lis=dif.tolist()
lis=sorted(lis)

for i in range(n-1):
    if len(lis)>0:
        lis.pop()

print(sum(lis))

Measured memory_bytes: 23040
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
	int n = 0, x[100] = { 0 }, y[100] = { 0 };
	long s1 = 0, s2 = 0, s3 = 0, si = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}

	for (int i = 0; i < n; i++) {
		s1 += abs(x[i] - y[i]);
		s2 += (x[i] - y[i]) * (x[i] - y[i]);
		s3 += abs(x[i] - y[i]) * abs(x[i] - y[i]) * abs(x[i] - y[i]);
		if(si < abs(x[i] - y[i]))
			si = abs(x[i] - y[i]);
	}

	cout << setprecision(12) << setiosflags(ios::showpoint) << (double) s1 << endl
		 << sqrt(s2) << endl << cbrt(s3) << endl << (double) si << endl;

    return 0;
}

Measured memory_bytes: 3408
while True :
    n, p = map(int, input().split())
    if(n == 0 and p == 0) :
        break
    else :
        stone = [0 for i in range(n)]
        P = p
        cnt = 0
        for i in range(1000000) :
            cnt = cnt % n
            if(p == 0) :
                if(stone[cnt] == P) :
                    print(cnt)
                    break
                else :
                    p = stone[cnt]
                    stone[cnt] = 0
                    cnt += 1
            else :
                stone[cnt] += 1
                p -= 1
                cnt += 1


Measured memory_bytes: 5600
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



S=one_str()

temp = S.split("><")

sums=0
length=len(temp)

for ind, i in enumerate(temp):
    left=i.count(">")
    right=i.count("<")
    
    if len(i)==0:
        right+=1
    
    elif ind==0 and length!=1:
        left = i.count(">")+1
        right= i.count("<")
        
    elif ind==length-1 and length!=1:
        left = i.count(">")
        right= i.count("<")+1
        
    elif ind !=0 and ind != length-1:
        left = i.count(">")+1
        right= i.count("<")+1
    
    maxs = max(left,right)
    mins = min(left,right) 
    maxs_array=[value for value in range(maxs+1)]
    mins_array=[value for value in range(mins)]

    sums += sum(maxs_array)
    sums += sum(mins_array)

print(sums)

Measured memory_bytes: 77132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
char s;
int main(void){
    cin>>s;
    if(s=='A'){
        cout<<'T'<<endl;
    }else if(s=='T'){
        cout<<'A'<<endl;
    }else if(s=='G'){
        cout<<'C'<<endl;
    }else{
        cout<<'G'<<endl;
    }
    

}



Measured memory_bytes: 3604
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
long long X,A,B;
int main(){
	cin>>X>>A>>B;
	if((B-A)<1)cout<<"delicious"<<endl;
	if((B-A)>0&&(B-A)<(X+1))cout<<"safe"<<endl;
	if((B-A)>0&&(B-A)>X)cout<<"dangerous"<<endl;

	return 0;
}



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

typedef long long int ll;
typedef long double ld;

using namespace std;


int main()
{
    ld x,ans, pi = 3.14159266;
    cin>>x;
    ans= 2*pi*x;
    cout<<ans<<endl;

    //cout<<"Case "<<cn<<": "<<"good"<<endl;
    return 0;
}


Measured memory_bytes: 3812
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    map<int, int> mp;
    mp[0]++;
    int a = 1;
    int sum = 0;
    for(int i = sz(s) - 1; i >= 0; --i){
        int tmp = s[i] - '0';
        sum += tmp * a;
        a = (a * 10) % 2019;
        mp[sum % 2019]++;
    }
    int ans = 0;
    for(auto num : mp){
        ans += num.sc * (num.sc - 1) / 2;
    }
    print(ans);

}



Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"YES"<<endl;
}

void no(){
    cout<<"NO"<<endl;
}

void solve(){
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int a,b,i;
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			a = sc.nextInt();
			b = sc.nextInt();
			a = a + b;
			for(i = 0;a > 0;i++){
				a = a / 10;
				
			}
			System.out.println(i);
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};




int main(){
    int N;cin >> N;
    vector<int> vec;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        vec.push_back(-b);
    }
    multiset<int> se;
    se.insert(vec.front());
    for(int i = 1;i < N;i++){
        auto itr = se.upper_bound(vec.at(i));
        if(itr == se.end()){
            se.insert(vec.at(i));
        }else{
            se.erase(itr);
            se.insert(vec.at(i));
        }
    }
    /*
    for(auto a: se){
        cout<<a<<" ";
    }
    */

   // cout<<endl;
    cout<<se.size()<<endl;

}


Measured memory_bytes: 5368
import java.util.*;


public class Main{
           
    public static void main(String[] args){
            
        Scanner sc = new Scanner(System.in);        
       
       int x = sc.nextInt();
       
       String S = "";
       if(x < 1200){
           S = "ABC";
       }else{
           S = "ARC";
       }
        
        System.out.println(S);

    }       
}

Measured memory_bytes: 9680
#include <iostream>

using namespace std;

int main() {
  int a,b;
  char op;
  bool loop = true;
  while (loop) {
    cin >> a >> op >> b;
    switch(op) {
    case '+':
      cout << a+b << endl;
      break;
    case '-':
      cout << a-b << endl;
      break;
    case '*':
      cout << a*b << endl;
      break;
    case '/':
      cout << a/b << endl;
      break;
    case '?':
      loop = false;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Sort the Panels
public class Main{

	int[][] dist;
	int n, M = 20, INF = 1<<29, S, G;
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			char[] t1 = sc.next().toCharArray(), t2 = sc.next().toCharArray();
			S = 0; G = 0;
			for(int i=0;i<n;i++){
				S+=t1[i]=='W'?1<<i:0; G+=t2[i]=='W'?1<<i:0;
			}
			dist = new int[1<<n][n];
			for(int[]a:dist)Arrays.fill(a, INF);
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
//					if(dist[o1/M][o1%M]==dist[o2/M][o2%M]){;
//					int c1 = 0, c2 = 0, v1 = o1/M, v2 = o2/M;
//					for(int i=0;i<n;i++){
//						if((G&(1<<i))!=(v1&(1<<i)))c1++;
//						if((G&(1<<i))!=(v2&(1<<i)))c2++;
//					}
//					//						System.out.println(c1+" "+c2);
//					return c1-c2;
//					}
					return dist[o1/M][o1%M]-dist[o2/M][o2%M];
				}
			});
			for(int i=0;i<n;i++){
				dist[S][i] = 0; q.add(S*M+i);
			}
			while(!q.isEmpty()){
				int V = q.poll();
				int s = V/M, p = V%M;
//				System.out.println(bi(s)+" "+bi(G));
				if(s==G){
					System.out.println(dist[s][p]); break;
				}
				for(int a=0;a<n;a++){
					int pa = s&(1<<a);
					if(pa==(G&(1<<a)))continue;
					for(int b=0;b<n;b++){
						if(a==b||(s&(1<<b))==(G&(1<<b)))continue;
						int w = dist[s][p]+Math.abs(p-a)+Math.abs(a-b);
						int pb = s&(1<<b), ns = s;
						if(pa>0)ns|=1<<b;
						else ns&=~(1<<b);
						if(pb>0)ns|=1<<a;
						else ns&=~(1<<a);
						if(w<dist[ns][b]){
//							q.remove(ns*M+b); 
							dist[ns][b] = w; q.add(ns*M+b);
						}
					}
				}
			}
//			System.out.println("!!");
		}
	}

	String bi(int s){
		StringBuilder sb = new StringBuilder();
		while(s>0){
			sb.append(s%2); s>>=1;
		}
		return sb.reverse().toString();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int             long long int
#define ld              long double
#define F               first
#define S               second
#define pb              push_back
#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpi             vector <pii>
#define vpp             vector <pair<int, pii>>
#define mii             map <int, int>
#define mpi             map <pii, int>
#define spi             set <pii>
#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], i, j, n, m;
vector <int> v[N], dp[N];

int dfs(int i)
{
     if (sz(dp[i]))
          return dp[i][0];

     dp[i].pb(0);
     for (auto x : v[i])
          dp[i].pb(1 + dfs(x));

     sort(dp[i].rbegin(), dp[i].rend());
     return dp[i][0];
}

void solve()
{
     cin >> n >> m;
     for (i = 0; i < m; i++)
     {
          int x, y; cin >> x >> y;
          v[x].pb(y);
     }
     for (i = 1; i <= n; i++)
     {
          if (!sz(dp[i]))
               dfs(i);
     }

     int mx = 0;
     for (int i = 1; i <= n; i++)
          mx = max(dp[i][0], mx);

     cout << mx;

}

int32_t main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 20224
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string parse(string V, int w) {
	while (V.size() >= 2 && V[0] == '(' && V[V.size() - 1] == ')')V = V.substr(1, V.size() - 2);
	if (V.size() == 1)return V;
	int depth = 0;
	string E = "", F = ""; vector<pair<int, string>>v;
	for (int i = 0; i < V.size(); i++) {
		if (V[i] == '(')depth++;
		if (V[i] == ')')depth--; F += V[i];
		if (depth == 0 && ((V[i] >= 'A' && V[i] <= 'Z') || V[i] == ')')) {
			string Y = ""; int c = 0; while (F[c] >= '0' && F[c] <= '9') { Y += F[c]; c++; }
			int D = 1; if (Y.size() >= 1)D = stoi(Y);
			v.push_back(make_pair(D, F.substr(c, F.size() - c))); F = "";
		}
	}
	for (int i = 0; i < v.size(); i++) {
		if (E.size() >= w)break;
		string Z = parse(v[i].second, w);
		for (int j = 0; j < v[i].first; j++) {
			if (E.size() >= w)break;
			E += Z;
		}
	}
	return E.substr(0, min((int)E.size(), w));
}
int main() {
	while (true) {
		string S; int T; cin >> S >> T; if (S == "0" && T == 0)break;
		string U = parse(S, T + 1);
		if (U.size() <= T) { cout << "0" << endl; }
		else cout << U[T] << endl;
	}
	return 0;
}

Measured memory_bytes: 8452
#include<stdio.h>
#include<string.h>
int stricmp(char* ch1,char* ch2)
{
    int ch1_length=0,ch2_length=0,div;
    for(int i=0;ch1[i]!='\0';i++)
        ch1_length++;
     for(int i=0;ch2[i]!='\0';i++)
        ch2_length++;
    if(ch1_length!=ch2_length)
        return -1;
    for(int i=0;ch1[i]!='\0';i++)
    {
        div=ch1[i]-ch2[i];
        if(div!=0&&div!=32&&div!=-32)
            return -1;
    }
    return 0;
}

int main()
{
    char W[11],T[1001];
    int coun=0;
    scanf("%s",W);
    while(true)
    {
        scanf("%s",T);
        if(strcmp("END_OF_TEXT",T)==0)
            break;
        if(stricmp(T,W)==0)
            coun++;
    }
    printf("%d\n",coun);
}


Measured memory_bytes: 2708
n = int(input())
a = list(map(int , input().split()))

a1 = 0
a2 = 0
a4 = 0

for i in a:
    if i % 4 == 0:
        a4 += 1
    elif i % 2 == 0:
        a2 += 1
    else:
        a1 += 1

if a2 == 0 and a4 >= a1 - 1:
    print("Yes")
elif a2 > 0 and a4 >= a1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 15020
s = list(input())
remove = ["A","T","C","G"]
mxm = 0
i = 0
counter = 0
while i < len(s):
    if s[i] in remove:
        counter += 1
        i += 1
    else:
        if counter > mxm:
            mxm = counter
        counter = 0
        i += 1
if counter > mxm:
    mxm = counter
print(mxm)

Measured memory_bytes: 3060
module Main where

-- import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
-- import Data.Array.IO
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

solve :: [(String, String)] -> [Int]
solve [] = []
solve ((x, y):xs)
    | isShorter x y = (lcs x y):solve xs
    | otherwise = (lcs y x):solve xs

isShorter :: String -> String -> Bool
isShorter [] ys = True
isShorter xs [] = False
isShorter (x:xs) (y:ys) = isShorter xs ys 


lcs :: String -> String -> Int
lcs sX sY = iterY sY initialMemo where
    iterY [] m = last m
    iterY (y:ys) m = iterY ys (iterX sX m [0]) where
            iterX _ [a] ac = reverse ac
            iterX (x:xs) (a:nl@(b:ms)) ac@(c:cs) = setXY `seq` iterX xs nl (setXY:ac) where
                    setXY = if x == y then a + 1 else max b c
    initialMemo = replicate ((length sX)+1) 0

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

read2Str:: IO (String, String)
read2Str = do
    a <- getLine
    b <- getLine
    return (a, b)

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n read2Str
    mapM_  print $ solve l



Measured memory_bytes: 7520
#include <bits/stdc++.h>
using namespace std;
struct data{int num,l,r;};
vector<data> At,Bt;

bool check(int s,int t, string &str){
  stack <char> st;
  for(int i=s;i<=t;i++){
    if(str[i]=='(') st.push(str[i]);
    if(str[i]==')'&&st.empty())return 0;  
    if(str[i]==')') st.pop();
  }
  return st.empty();
}

int get_num(string &str,int &idx){
  int res=0;
  while(isdigit(str[idx]))res=res*10+str[idx++]-'0';
  return res;
}


int get_root(int s,int t,string &str){
  stack <char> st;
  for(int i=s;i<=t;i++){
    if(st.empty()&&isdigit(str[i])) return i;
    if(str[i]=='(') st.push(str[i]);
    if(str[i]==')') st.pop();
  }
  assert(0);
}


void make_tree(int s,int t,vector<data>&tree,string &str,int idx){
    while(s<t&&check(s,t,str)) s++,t--;
  if(s>=t)return;
  s--,t++;

  int root=get_root(s,t,str);
  tree.push_back((data){-1,-1,-1});
  tree[idx].l=tree.size()-1;
  make_tree(s,root-2,tree,str,tree.size()-1);

  tree[idx].num=get_num(str,root);

  tree.push_back((data){-1,-1,-1});
  tree[idx].r=tree.size()-1;
  make_tree(root+1,t,tree,str,tree.size()-1);
}

string make_str(int a,int b){
  if(a==-1||b==-1||At[a].num<0||Bt[b].num<0) return "";
  int num=At[a].num+Bt[b].num;
  string str;
  if(num==0)str="0";
  while(num) str=(char)((num%10)+'0')+str,num/=10;

  return "("+make_str(At[a].l,Bt[b].l)+")"+"["+str+"]"+"("+make_str(At[a].r,Bt[b].r)+")";

}
int main(){
  string A,B;
  cin>>A>>B;
  At.push_back((data){-1,-1,-1});
  Bt.push_back((data){-1,-1,-1});
  make_tree(0,A.size()-1,At,A,0);
  make_tree(0,B.size()-1,Bt,B,0);
  cout <<make_str(0,0)<<endl;  
  return 0;
}

Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define fi first
#define se second
#define test ll int t;cin>>t;while(t--)
#define pll pair<long long,long long>
#define icc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
}
int main(){
	icc
	ll n,i,ans=0;
	double d;
	cin>>n>>d;
	for(i=0;i<n;i++){
		double a,b;
		cin>>a>>b;
		double c=sqrt(a*a+b*b);
		if(c<=d)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3860
N = int(input())
strlist = 'abcdefghij'

ans = [['a']]
for i in range(1, N):
  ans.append([])
  for s in ans[i-1]:
    n = ord(max(s)) - 96
    for j in range(n+1):
      ans[i].append(s+strlist[j])

print(*ans[-1], sep='\n')

Measured memory_bytes: 16340
#include<iostream>
using namespace std;
typedef long long int lli;
lli dp[310][310][310];

int main(){
  int n, m;
  int mod = 1e9+7;
  std::cin >> n >> m;
  if(m < n - 1){
    std::cout << 0 << std::endl;
    return 0;
  }
  dp[0][1][1] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if(j + 1 <= n){
          dp[i + 1][j + 1][k] += dp[i][j][k]*(n - j);
          dp[i + 1][j + 1][k] %= mod;
        }
        dp[i + 1][j][k] += dp[i][j][k]*(j - k);
        dp[i + 1][j][j] += dp[i][j][k]*k;
        dp[i + 1][j][k] %= mod;
        dp[i + 1][j][j] %= mod;
      }
    }
  }
  std::cout << dp[m][n][n] << std::endl;
  return 0;
}



Measured memory_bytes: 219392
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
char str[maxn];
int  main(){
    int n;
    cin>>n;
    ll ans=0;
    ans+=(n/500)*1000;
    n%=500;
    ans+=(n/5)*5;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;
  cin>>N;
  int MAX = 0,MIN = INF;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    chmax(MAX,X);
    chmin(MIN,X);
  }
  cout<<MAX-MIN<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  int A[N+10];
  int ct=1,jg=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  ll temp=A[0];
  for(int i=0;i<N;i++){
    if(A[i]==temp) continue;
    else if(A[i]<temp){
      if(jg==0 || jg==1) jg=1;
      else{
        ct++;
        jg=0;
      }
      temp=A[i];
    }
    else{
      if(jg==0 || jg ==2) jg=2;
      else{
        ct++;
        jg=0;
      }
      temp=A[i];
    }
  }
  cout << ct << endl;
  
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long K, std::vector<long long> p){
    sort(all(p));
    int sum=0;
    rep(i,0,K) sum+=p[i];
    cout << sum << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
string S; 
cin >> S; 
int L = S.size(); 
int A = 0; 
int Z = 0; 
for(int i = 0; i < L; i++){
if(S.at(i) == 'A'){
A = i; 
break; 
}
}
for(int i = L-1; i >= 0; i--){
if(S.at(i) == 'Z'){
Z = i; 
break; 
}
}
cout << Z - A + 1 << endl; 
}

Measured memory_bytes: 640
{-# LANGUAGE RecursiveDo        #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE NumericUnderscores #-}

import qualified Data.ByteString.Char8 as C8
import Data.List
import Data.Char

solve :: Int -> Int -> [Int] -> Int
solve d1 d2 [x, y   ] = d2
solve d1 d2 [x, y, z] = dn
  where a  = d1 + abs (z - x)
        b  = d2 + abs (z - y)
        dn = min a b
solve d1 d2 (x:y:z:h) = solve d2 dn (y:z:h)
  where a  = d1 + abs (z - x)
        b  = d2 + abs (z - y)
        dn = min a b

main :: IO ()
main = do
  _ <- getLine
  h@(h0:h1:hs) <- unfoldr (C8.readInt . C8.dropWhile isSpace) <$> C8.getLine
  print $ solve 0 (abs (h0 - h1)) h


Measured memory_bytes: 5952