akhauriyash/Code-Regression huggingface dataset:
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
    int n,m,x;
    cin >> n >> m >> x;
    int c[n + 1];
    int a[n + 1][m + 1];
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    ll ret = 1200001;
    for (int i = 0; i <= 4095; i++) {
        ll cost = 0;
        ll skill[m + 1];
        for (int j = 1; j <= m; j++) {
            skill[j] = 0;
        }
        int icp = i;
        for (int k = 1; k <= n; k++){
            if ((icp&1) == 1) {
                cost += c[k];
                for (int l = 1; l <= m; l++) {
                    skill[l] += a[k][l];
                }
            }
            icp = icp >> 1;
        }
        bool ok = true;
        for (int p = 1; p <= m; p++){
            if (skill[p] < x){
                ok = false;
            }
        }
        if (ok) {
            if (ret > cost) {
                ret = cost;
            }
        }    
    }
    if (ret == 1200001) {
        cout << -1;
    }
    else {
        cout << ret;
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

    static boolean f(int[] h, int a, int b, int k) {
        int n = h.length;
        int d = a - b;
        long p = 0, q = 0;
        for (int i=0; i<n; i++) {
            long x = h[i] - (long)b*k;
            if (x > 0) {
                p += x;
                q += ((x-1) / d + 1)*d - x;
                // out.println(x+" "+((x / d + 1)*d - x));
                // if (x <= 0) return false;
                // int y = -1;
                // for (int j=1; j<=x; j++) {
                //     if (p <= j*d) {
                //         y = j;
                //         break;
                //     }
                // }
                // if (y == -1) {
                //     return false;
                // }
                // x -= y;
            }
        }
        // out.println(p+" "+((long)k*d - q));
        return p <= (long)k*d - q;
        // return true;
    }

	static void solve() {
		int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) {
            h[i] = in.nextInt();
        }
        Arrays.sort(h);
        int l = -1, r = 1_000_000_001;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (f(h, a, b, m)) r = m;
            else l = m;
        }
        // out.println(f(h, a, b, 2));

        for (int i=Math.max(0, l-3); i<Math.min(1_000_000_001, r+3); i++) {
            if (f(h, a, b, i)) {
                out.println(i);
                return;
            }
        }
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 50756
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // AGC003B - Simplified mahjong
  ll N; cin >> N;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
  }

  ll ans = 0;
  REP(i, N){
    ans += A[i] / 2;
    if(A[i] % 2 == 1 && i != N-1){
      if(A[i+1] > 0){
        ans++;
        A[i+1]--;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x+r>W || y+r>H){
		printf("No\n");
	}
	else if(x-r<0 || y-r<0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
 
using namespace std;
 
int n;
string s[100005];
 
int main(void)
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> s[i];
     
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j+2 < s[i].size(); j++){
            if(s[i].substr(j, 3) == "AOR") ans++;
        }
    }
     
    int Ocnt = 0, _A = 0, _AO = 0, R_ = 0, OR_ = 0, R_A = 0, OR_A = 0, R_AO = 0, OR_AO = 0;
    for(int i = 1; i <= n; i++){
        int l = s[i].size();
        if(s[i] == "O") Ocnt++;
        if(s[i].substr(l-1, 1) == "A")_A++;
        if(l >= 2 && s[i].substr(l-2, 2) == "AO") _AO++;
        if(s[i].substr(0, 1) == "R") R_++;
        if(l >= 2 && s[i].substr(0, 2) == "OR") OR_++;
        if(l >= 2 && s[i].substr(0, 1) == "R" && s[i].substr(l-1, 1) == "A") R_A++;
        if(l >= 3 && s[i].substr(0, 2) == "OR" && s[i].substr(l-1, 1) == "A") OR_A++;
        if(l >= 3 && s[i].substr(0, 1) == "R" && s[i].substr(l-2, 2) == "AO") R_AO++;
        if(l >= 4 && s[i].substr(0, 2) == "OR" && s[i].substr(l-2, 2) == "AO") OR_AO++;
    }
    int gomi = _A+_AO+R_+OR_ - (R_A+OR_A+R_AO+OR_AO) + Ocnt;
    gomi = n - gomi;
     
    int mx = 0;
    for(int i = 0; i <= min(Ocnt, _A); i++){
        int tmp1 = min(_A-i, OR_);
        if(tmp1 && OR_A == _A && OR_A == OR_ && i == 0) tmp1--;
         
        int tmp2 = min(_AO+i, R_);
        if(tmp2 && R_AO == _AO && R_AO == R_ && i == 0) tmp2--;
         
        mx = max(mx, tmp1+tmp2);
        //cout << tmp1 << " " << tmp2 << endl;
    }
    if(mx && mx == n-(Ocnt+gomi)) mx--;
    ans += mx;
     
    cout << ans << endl;
     
    return 0;
}


Measured memory_bytes: 9936
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static int N;

  public static void main(String[] args) {
    N = sc.nextInt();
    int D1 = sc.nextInt();
    int D2 = sc.nextInt();
    int[][] f1 = solve(D1);
    int[][] f2 = solve(D2);
    PrintWriter writer = new PrintWriter(System.out);
    int c = 0;
    for (int i = 0; i < 2 * N && c < N * N; i++) {
      for (int j = 0; j < 2 * N && c < N * N; j++) {
        if (f1[i][j] == 1 && f2[i][j] == 1) {
          ++c;
          writer.println(i + " " + j);
        }
      }
    }
    writer.flush();
  }

  static int[][] solve(int d) {
    ArrayList<Pair> pairs = new ArrayList<>();
    for (int i = 0; i * i <= d; i++) {
      if (isSq(d - i * i)) {
        int j = (int) Math.sqrt(d - i * i);
        pairs.add(new Pair(i, j));
        pairs.add(new Pair(i, -j));
        pairs.add(new Pair(-i, j));
        pairs.add(new Pair(-i, -j));
      }
    }
    int[][] f = new int[2 * N][2 * N];
    for (int y = 0; y < 2 * N; y++) {
      for (int x = 0; x < 2 * N; x++) {
        if (f[y][x] != 0) continue;
        ArrayList<Integer> cur = new ArrayList<>();
        cur.add((y << 16) | x);
        f[y][x] = 1;
        for (int i = 0; !cur.isEmpty(); i++) {
          ArrayList<Integer> next = new ArrayList<>();
          for (int pos : cur) {
            int cy = pos >> 16;
            int cx = pos & 0xFFFF;
            for (Pair p : pairs) {
              int ny = cy + p.s;
              int nx = cx + p.e;
              if (0 <= ny && ny < 2 * N && 0 <= nx && nx < 2 * N && f[ny][nx] == 0) {
                next.add((ny << 16) | nx);
                f[ny][nx] = i % 2 == 0 ? -1 : 1;
              }
            }
          }
          cur = next;
        }
      }
    }
    return f;
  }

  static boolean isSq(int v) {
    if (v < 0) return false;
    int sqrt = (int) Math.sqrt(v);
    return sqrt * sqrt == v;
  }

  static class Pair {
    int s, e;

    Pair(int s, int e) {
      this.s = s;
      this.e = e;
    }
  }
}


Measured memory_bytes: 63192
using System;
using System.Linq;
public class Test{
    public static void Main(){
        var xs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        Console.WriteLine((xs[0] * xs[1]).ToString() + " " + (xs[0] * 2 + xs[1] * 2).ToString());
    }
}


Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
ll arr[N];
ll n;

int main() {
    cin >> n;
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
    }
    ll ans = 0;
    ll left = 0;
    ll curr = 0;
    for(int i = 0; i < n; i ++) {
        for(;left < n && !(curr &arr[left]); left ++) {
            curr ^= arr[left];
        }
        ans += (left - i);
        curr ^= arr[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		int n = sc.nextInt();
		long minus[] = new long[n];
		HashMap<Long, Integer> plus = new HashMap<Long, Integer>();

		for (int i = 0; i < n; i++) {
			long a = sc.nextInt();
			minus[i] = i - a;
			if (Objects.nonNull(plus.get(i + a))) {
				plus.put(i + a, plus.get(i + a) + 1);
			} else {
				plus.put(i + a, 1);
			}
		}

		long pair = 0;
		for (int i = 0; i < n; i++) {
			if (Objects.nonNull(plus.get(minus[i]))) {
				pair += plus.get(minus[i]);
			}
		}

		// 出力
		System.out.println(pair);
		sc.close();
	}
}


Measured memory_bytes: 72292
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&b==c&&c==a){
			printf("1\n");
	}
	else if(a==b||b==c||c==a){
			printf("2\n");
	}
	else{
			printf("3\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 200010

using namespace std;

int n;
int a[N],p[N],t[N],f[N];

inline bool in_cyclic(int a,int b,int c){
	return (a<b&&b<c)||(b<c&&c<a)||(c<a&&a<b);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),p[a[i]]=i;
	t[n]=f[n]=0;
	for(int i=n-1;i;i--){
		if(t[i+1]==0)
			if(p[i]>p[i+1]) t[i]=1,f[i]=i+1;
			else t[i]=f[i]=0;
		else
			if(in_cyclic(p[f[i+1]],p[i],p[i+1])) t[i]=t[i+1],f[i]=f[i+1];
			else t[i]=t[i+1]+1,f[i]=i+1;
	}
	printf("%d\n",t[1]);
	return 0;
}

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


int main(){
  ll x;
  cin >> x;
  ll money = 100;
  ll cnt = 0;
  while(money<x){
    money += money/100;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int N;
	bool flag = true;
	cin >> N;

	vector<string> list;
	string word;

	for (int i = 0; i < N; i++)
	{
		cin >> word;

		for (int k = 0; k < list.size(); k++)
		{
			if (word == list[k])
			{
				flag = false;
			}
		}

		list.push_back(word);
	}

	for (int i = 1; i < N; i++)
	{
		if (list[i - 1].back() != list[i].front())
		{
			flag = false;
		}
	}

	if (flag)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[105][10005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  dp[0][0]=1;
  rep(i,n){
    for(ll j=0; j<=10000; j++){
      if(dp[i][j]==0) continue;
      dp[i+1][j]=dp[i][j];
      dp[i+1][j+a[i]]=dp[i][j];
    }
  }
  
  ll ans=0;
  for(ll i=0; i<=10000; i++) if(dp[n][i] && i%10!=0) ans=i;
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 7912
#include <stdio.h>

int A[20];
int n;

int solve(int p, int t);
int sort(void *a, void *b);

int main(void) {
	int i, q, M;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	
	qsort(A, n, sizeof(A[0]), sort);
	
	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &M);
		if (solve(-1, M)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

int solve(int p, int t) {
	if ((p == n) || (t == 0)) return t == 0;
	if (A[p + 1] > t) return 0;
	if (solve(p + 1, t - A[p + 1])) return 1;
	return solve(p + 1, t);
}

int sort(void *a, void *b) {
	return *(int*)a - *(int*)b;
}

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

/*-------------------------- HRIDOY ROY -------------------------*/

#define     fRead           freopen("input.txt","r",stdin)
#define     fWrite          freopen("output.txt","w",stdout)

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     PLL             pair<lld,lld>
#define     MAX             100000000000014
#define     MIN             -100000000000014
#define     gti             greater<int>
#define     gtL             greater<lld>
#define     PI1             acos(-1.0)
int arr[200005];

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

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

    for(int i = 1; i <= n; i++)
        printf("%d\n",arr[i]);
}



Measured memory_bytes: 4472
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, c, k; cin>>n>>c>>k;
    vector<int> t(n);
    for(int i=0; i<n; i++) cin>>t[i];
    sort(t.begin(), t.end());

    int ans = 0;
    for(int i=0; i<n; i++){
        int start_time = t[i];
        int cnt = 0;
        while(i < n && cnt < c && t[i] - start_time <= k){
            cnt++;
            i++;
        }

        i--;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = GetDounble();
            Console.WriteLine("{0:F7} {1:F7}", num * num * Math.PI, 2 * num * Math.PI);
        }

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbers()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

Measured memory_bytes: 9476
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <cstdio>
#include <string>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;
//ABC082.c

int main(void) {
	int N,t;
	cin >> N;
	cin >> t;
	int a=N+t;
	if (a % 2 == 0)printf("%d\n", a / 2);
	else printf("%d\n", a / 2+1);
	/* //C
	vector<int>b(N+1,0);
	int change = 0;
	
	for (int i = 1; i < N+1; i++) {
		cin >> t;
		if (t > N)change++;
		else b[t]++;
	}
	for (int i = 1; i < N+1; i++) {
		if (b[i] != i &&b[i]!=0) {
			if(b[i]>i)
			change +=abs( b[i] - i);
			else change += b[i];
		}
	}
	printf("%d", change);
	*/
	return 0;
}

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

i = 0
while True:
    if a <= 0:
        print('No')
        exit()
    elif c <= 0:
        print('Yes')
        exit()
    if i % 2 == 0:
        c -= b
    else:
        a -= d
    i += 1

Measured memory_bytes: 61588
#!/usr/local/bin/ruby

while true do
    h,w=gets.split(" ")
    h=h.to_i
    w=w.to_i
    if h==0 and w== 0 then
        break
    end
    h.times{
        w.times{
            print "#"
        }
        print "\n"
    }
    print "\n"
end

Measured memory_bytes: 8720
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e2 + 5;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll x , k , d;
    cin >> x >> k >> d;
    ll cnt = (abs(x) + d - 1) / d;
    if(k < cnt) {
        if(x < 0)
            return cout << abs(x + k * d) , 0;
        else
            return cout << abs(x - k * d) , 0;
    }
    if(x < 0) {
        if((cnt & 1) == (k & 1))
            cout << abs(x + cnt * d);
        else
            cout << abs(x + (cnt - 1) * d);
    } else {
        if((cnt & 1) == (k & 1))
            cout << abs(x - cnt * d);
        else
            cout << abs(x - (cnt - 1) * d);
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define d double
#define INF INT_MAX
#define output for(int i=0;i<sizex;i++) { for(int j=0;j<sizey;j++) { cout << moveChart[i][j] << " "; }cout<<endl; }cout<<endl;

int n, k;
int arr[100000];
int dp[100000];

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

    cin >> n >> k;
    for( int i=0;i<n;i++ ) cin >> arr[i];

    for( int i=1;i<n;i++ ) dp[i] = INF;
    dp[0] = 0;

    for(int i=0;i<n;i++){

        for(int j=i+1;j<n && j<i+1+k;j++){

            dp[j] = min( dp[j], dp[i] + abs( arr[j] - arr[i] ) );

        }

    }

    cout << dp[n-1] << endl;

}

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

int main(){
  int n,c,aa,bb;
  cin >> n;
  c=1;aa=0;bb=0;
  vector<int> p(n);
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  	p[i]=i+1;
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  while(next_permutation(p.begin(),p.end())){
    if(a==p)aa=c;
    if(b==p)bb=c;
    c++;
  }
  cout << abs(aa-bb);
  return 0;
}

Measured memory_bytes: 256
def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return count

def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
    return 0



n=int(input())
a=list(map(int,input().split()))
ans=mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(ans)


Measured memory_bytes: 66684
h, w, d = gets.chomp.split(' ').map(&:to_i)
arr = Array.new(h)
h.times do |i|
  row = gets.chomp.split(' ').map(&:to_i)
  row.each_with_index do |v, j|
    arr[v - 1] = [i + 1, j + 1]
  end
end
sums = Array.new(h * w, 0)
(d...(h * w)).each do |i|
  sums[i] = sums[i - d] + (arr[i][0] - arr[i - d][0]).abs + (arr[i][1] - arr[i - d][1]).abs
end
q = gets.chomp.to_i
q.times do
  l, r = gets.chomp.split(' ').map { |i| i.to_i - 1 }
  puts sums[r] - sums[l]
end

Measured memory_bytes: 11644
N = int(input())
A = list(map(int,input().split()))

S = sum(map(abs,A))

if all([a>0 for a in A]):
    print(S-2*min(A))
    A = sorted(A)
    B = [A[0]]
    for i in range(1,N):
        B.append(B[-1]-A[i])
    for i in range(N-2):
        print(B[i],A[i+1])
    print(A[N-1],B[N-2])

elif all([a<0 for a in A]):
    print(S+2*max(A))
    A = sorted(A)
    B = [A[-1]]
    for i in range(N-1):
        B.append(B[-1]-A[i])
    for i in range(N-1):
        print(B[i],A[i])

else:
    print(S)
    A = sorted(A)
    B = [A[0]]
    for i in range(N):
        if N-1-2-i<0 or A[-2-i]<0:
            print(A[-1-i],B[-1])
            B.append(A[-1-i]-B[-1])
            break
        print(B[-1],A[-1-i])
        B.append(B[-1]-A[-1-i])
    C = [B[-1]]
    for i in range(1,N):
        if A[i]>=0:
            break
        print(C[-1],A[i])
        C.append(C[-1]-A[i])

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

class Dice{
	  public:
      int f[7];
      Dice(){}
      void roll_n(){roll(1, 2, 6, 5);}
      void roll_w(){roll(1, 3, 6, 4);}
      void roll(int a, int b, int c, int d){
      int p = f[a]; f[a] = f[b]; f[b] = f[c]; 
      f[c] = f[d]; f[d] = p;
      }
      void move(char poi){
          if(poi == 'N') roll_n();
          if(poi == 'S')
           for(int i = 0;i < 3;++i) roll_n();
          if(poi == 'W') roll_w();
          if(poi == 'E')
           for(int i = 0;i < 3;++i) roll_w();   
      }
};

int main(){
   Dice g;
   string lm;
   for(int r = 1;r < 7;++r) cin >> g.f[r];   
   cin >> lm;
   for(int d = 0;d < lm.size();++d){
     g.move(lm[d]);
  }      
  cout << g.f[1] << endl;
  return 0;
}

Measured memory_bytes: 1204
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var a1 = input[0].split(" ");
	var a2 = input[1].split(" ");
	var a3 = input[2].split(" ");
	var n = input[3];

	var b1=[0,0,0];
	var b2=[0,0,0];
	var b3=[0,0,0];
	
	for(var i = 0; i<n; i++){
		var b = input[4+i];
		for(var j=0;j<3;j++){
			if(a1[j]==b){
				b1[j]+=1;
			}else{
				b1[j]+=0;
			}
			if(a2[j]==b){
				b2[j]+=1;
			}else{
				b2[j]+=0;
			}
			if(a3[j]==b){
				b3[j]+=1;
			}else{
				b3[j]+=0;
			}

		}
			
		

	}

	if(b1[0]>=1&b1[1]>=1&b1[2]>=1){
		//出力
		console.log('Yes');
	}else if(b2[0]>=1&b2[1]>=1&b2[2]>=1){
		//出力
		console.log('Yes');

	}else if(b3[0]>=1&b3[1]>=1&b3[2]>=1){
		//出力
		console.log('Yes');

	}else if(b1[0]>=1&b2[0]>=1&b3[0]>=1){
		//出力
		console.log('Yes');

	}else if(b1[1]>=1&b2[1]>=1&b3[1]>=1){
		//出力
		console.log('Yes');

	}else if(b1[2]>=1&b2[2]>=1&b3[2]>=1){
		//出力
		console.log('Yes');

	}else if(b1[0]>=1&b2[1]>=1&b3[2]>=1){
		//出力
		console.log('Yes');

	}else if(b1[2]>=1&b2[1]>=1&b3[0]>=1){
		//出力
		console.log('Yes');

	}else{
		//出力
		console.log('No');
	}
}

	
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(void) {
  int n, m, x;
  int a;
  int i;
  int cost_0 = 0;
  int cost_m = 0;
  
  scanf("%d %d %d", &n, &m, &x);
  
  for (i = 0; i < m; i++) {
    scanf("%d", &a);
    if (a < x)
      cost_0++;
    else if (a > x)
      cost_m++;
  }
  
  printf("%d\n", cost_0 < cost_m ? cost_0 : cost_m);
  
  return 0;
}

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

int main(){
  int N,T;
  cin>>N>>T;
  int num[N][2];
  int minnum = 1001;
  for(int i=0;i<N;i++){
    cin>>num[i][0]>>num[i][1];
    if(num[i][1] <= T){
      minnum = min(minnum,num[i][0]);
    }
  }if(minnum==1001){
    cout<<"TLE"<<endl;
    return 0;
  }cout<<minnum<<endl;
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 400000;

int n, m;
char st[N + 5];
int vis[N + 5];

struct edge {
    int u, v, ty;
};

int e;
edge E[N + 5];
vector<int> G[N + 5][4];

inline void addedge(int u, int v) {
    int ty = -1;
    if(st[u] == 'A') {
        if(st[v] == 'A') ty = 0; else ty = 1;
    } else {
        if(st[v] == 'B') ty = 2; else ty = 3;
    }

    E[++ e] = (edge) { u, v, ty };
    G[u][ty].pb(e);
}

int su, sc;
void dfs(int eid) {
    if(vis[eid] == 2) {
        puts("Yes");
        exit(0);
    }
    if(vis[eid] == 1) {
        return;
    }

    vis[eid] = 2;
    int u = E[eid].v;

    for(auto v : G[u][(E[eid].ty+1)%4]) {
        dfs(v);
    }
    vis[eid] = 1;
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n), read(m);
    scanf("%s", st + 1);

    for(int i = 1; i <= m; ++i) {
        static int u, v;
        read(u), read(v);
        addedge(u, v), addedge(v, u);
    }

    for(int i = 1; i <= 2*m; ++i) if(!vis[i]) {
        su = i;
        dfs(i); 
    }
    printf("No\n");

    return 0;
}


Measured memory_bytes: 55552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());

		int max = Math.max(Math.max(A, B), C);
		int min = Math.min(Math.min(A, B), C);
		System.out.println(max - min);
		sc.close();

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  string s;
  cin>>s;
  map<char,int>M;
  M[')']=0;
  M['(']=0;
  for(int i=0;i<N;i++){
  if(s.at(i)=='(')
    M.at('(')++;
    else{
    if(M.at('(')==0)
      M.at(')')++;
      else
        M.at('(')--;
    
    }
  
  }int R=M.at(')');
  int L=M.at('(');
  for(int i=0;i<R;i++)
    s='('+s;
  for(int i=0;i<L;i++)
    s+=')';
  cout<<s<<endl;
  
   return 0;
}

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

#define INF 1LL << 60
#define MOD 1000000007;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, b, e) for (int i = b; i <= e; i++)
#define PRINT(x) cout << x << endl

int A, B, C;

string solve() {
    if (A > B) {
        return A > C && C > B ? "Yes" : "No";
    } else {
        return B > C && C > A ? "Yes" : "No";
    }
}

int main() {
    cin >> A >> B >> C;
    cout << solve() << endl;
    return 0;
}

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

using namespace std;
#define ll long long
#define f first
#define s second

int main()
{
    vector <pair<ll,ll > > vec;
    ll n,tmp,tmp2,c=0,c2=0,mn=999999999999999;
    cin >> n;
    for (ll i=1; i*i<=n; i++)
    {
        if (n%i==0) vec.push_back({i , n/i});
    }

    for (int i=0; i<vec.size(); i++)
    {

            tmp = vec[i].f , tmp2=vec[i].s , c=0 , c2=0;
            while(tmp)
            {
                c++ , tmp /=10;
            }
            while(tmp2)
            {
                c2++ , tmp2 /=10;
            }
            mn = min(mn , max(c,c2));
    }

    cout << mn << "\n";

    return 0;
}


Measured memory_bytes: 256
/*** 𝕒𝕜𝕤𝕙𝕒𝕪𝕜𝕦𝕞𝕒𝕣𝟡𝟡 ***/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll k,a,b;
    cin>>k>>a>>b;
    ll z=a/k;
    if(a%k!=0)
        z++;
    z=(z)*k;
    if(z<=b || a%k==0)
    {
        cout<<"OK\n";
    }
    else
        cout<<"NG\n";


}

int32_t main()
{
    IOS();
    
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3608
N=int(input())
A=""
for i in range(N):
    k=input()
    A+=k[0]
m=A.count("M")
a=A.count("A")
r=A.count("R")
c=A.count("C")
h=A.count("H")
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
int main()
{
    io();
    string x;
    int n, l;
    cin >> n >> l;
    vector<string>v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    for (auto i : v)
        cout << i;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin >> n;
	vector<int> R(n);
	rep(i, n)
		cin >> R[i];
	int maxv = -1000000000;
	int minv = R[0];
	for(int i=1;i<n;i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	}


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

const double EPS = 1e-10;

ll N, A[20];
bool dp[21][200001];

bool ok(double x) {
  REP(i, 0, N + 1) REP(j, 0, 200001) dp[i][j] = false;
  REP(i, 0, 200001) dp[0][i] = true;

  REP(i, 0, N) {
    REP(j, 1, 200001) if(dp[i][j]) {
      double e = (double) abs(A[i] - j) / A[i];
      if(e < x + EPS) {
        for(ll k = j; k < 200001; k += j) {
          dp[i + 1][k] = true;
        }
      }
    }
  }

  bool ret = false;
  REP(i, 0, 200001) ret = ret || dp[N][i];
  return ret;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  double l = -1, h = 1e20;
  REP(_, 0, 100) {
    double m = (l + h) / 2;
    if(ok(m)) h = m; else l = m;
  }
  printf("%.15lf\n", h);
}


Measured memory_bytes: 7224
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    vector<int> c(9);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (a <= 399) {
            c[0]++;
        } else if (a <= 799) {
            c[1]++;
        } else if (a <= 1199) {
            c[2]++;
        } else if (a <= 1599) {
            c[3]++;
        } else if (a <= 1999) {
            c[4]++;
        } else if (a <= 2399) {
            c[5]++;
        } else if (a <= 2799) {
            c[6]++;
        } else if (a <= 3199) {
            c[7]++;
        } else {
            c[8]++;
        }
    }

    int ansmin = 0, ansmax = 0;
    for (int i = 0; i < 8; i++) {
        if (c[i] != 0) {
            ansmin++;
        }
    }
    ansmax += ansmin;
    if (c[8] != 0) {
        ansmax += c[8];
    }
    if (c[8] == n) {
        ansmin = 1;
    }

    cout << ansmin << ' ' << ansmax << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    var lastIndex = -1
    outer@for (i in 0..s.length-t.length) {
        val ss = s.slice(i until i+t.length)
        for (j in t.indices) {
            if (ss[j] != t[j] && ss[j] != '?') continue@outer
        }
        // found
        lastIndex = i
    }

    if (lastIndex == -1) {
        println("UNRESTORABLE")
        return
    }

    val ans = s.toMutableList()
    for (i in ans.indices) {
        if (i >= lastIndex && i <= lastIndex+t.length-1) {
            ans[i] = t[i-lastIndex]
        } else if (ans[i] == '?') {
            ans[i] = 'a'
        }
    }

    println(ans.joinToString(""))
}

Measured memory_bytes: 32020
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std; 

int
main(int argc, char const *argv[])
{
    int64_t n, k;
    string s;
    cin >> n >> k >> s;
    auto c = s[k-1];
    s[k-1] = c - 'A' + 'a';
    cout << s << endl;
    return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

ll N,H;
ll a[100000], b[100000];

int main(){
    cin>>N>>H;
    rep(i,N) cin>>a[i]>>b[i];

    ll amax=0;
    rep(i,N) amax=max(amax,a[i]);

    vector<ll> x;
    rep(i,N){
        if(b[i]>amax) x.push_back(b[i]);
    }
    sort(x.begin(),x.end(),greater<ll>());

    ll ans=0;
    rep(i,(int)x.size()){
        H-=x[i];
        ans++;
        if(H<=0){
            cout<<ans<<endl;
            return 0;
        }
    }

    ans+=(H-1)/amax+1;

    cout<<ans<<endl;
}

Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int  a[N],flag[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int n,ans=0;
	cin>>n;
	while(n>=500)
	{
		n-=500;
		ans+=1000;
	}
	while(n>5)
	{
		n-=5;
		ans+=5;
	}
	cout<<ans;
		return 0;
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int n;
ll a, ab, abc, total = 1;
string s;

int main(void) {
  cin >> s;
  n = sz(s);
  rep (i, 0, n) {
    char ch = s[i];
    if (ch=='A') {
      a += total;
      a %= MOD;
    } else if (ch=='B') {
      ab += a;
      ab %= MOD;
    } else if (ch=='C') {
      abc += ab;
      abc %= MOD;
    } else {
      
      abc = abc*3+ab;
      ab = ab*3+a;
      a = a*3+total;
      total *= 3;
      abc %= MOD;
      ab %= MOD;
      a %= MOD;
      total %= MOD;
    }
  
  }
    
    cout << abc % MOD<< "\n";

    return 0;
}



Measured memory_bytes: 512
import sys
N, x = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
minus_count = 0
for i in range(N-1):
    temp_sum = a[i] + a[i+1]
    minus_target = temp_sum - x
    if minus_target <= 0:
        continue
    else:
        minus_count += minus_target
        a[i+1] = a[i+1] - minus_target
        if a[i+1] < 0:
            a[i+1] = 0

print(minus_count)


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec,x)  (find(all(vec),x)!=(vec).end())
#define present(myset,x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl
#define trace2(x,y) cout<<x<<" "<<y<<endl;
#define trace3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define trace4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl;
ll mod = 1e9+7;
const int MAX = 1e5+5;

using namespace std;

int n;
vll a(3005);
ll dp[3005][3005];


ll solve(int i, int j){
    if(!((i>=0 && i<n) &&(j>=0 && j<n) && i<=j))
    {
        return -1e15;
    }
    if(i==j){
        dp[i][j]=a[i];
        return a[i];
    }

    if(j==i+1){
        dp[i][j]=max(a[i],a[j])-min(a[i],a[j]);
        return dp[i][j];
    }

    ll &ans=dp[i][j];
    if(ans!=-1)
        return ans;

    ll x=0; ll y=0;
    ll ans1=1e15; ll ans2=1e15;
    if(i<n){
        x=a[i];
        if(i+1<n){
            y=a[i+1];
            //cout<<"1";
            ll diff = solve(i+2,j);
            //cout<<diff<<" "<<x<<" "<<y;nl;
            ans1=min(ans1,diff+x-y);
        }

        if(j>=0){
            y=a[j];
            //cout<<"2";
            ll diff = solve(i+1,j-1);
            //cout<<diff<<" "<<x<<" "<<y;nl;
            ans1=min(ans1,diff+x-y);
        }
    }

    if(j>=0){
        x=a[j];
        if(i<n){
            y=a[i];
            ll diff = solve(i+1,j-1);
            //cout<<diff<<" "<<x<<" "<<y;nl;
            ans2=min(ans2,diff+x-y);
        }

        if(j-1>=0){
            y=a[j-1];
            //cout<<'4';
            ll diff = solve(i,j-2);
            //cout<<diff<<" "<<x<<" "<<y;nl;
            ans2=min(ans2,diff+x-y);
        }
    }
    ans=max(ans1,ans2);
    //cout<<i<<" "<<j<<" "<<ans;nl;
    //cout<<"///";nl;

    return ans;


}


int main()
{
    FAST_IO;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    ll ans=solve(0,n-1);
    cout<<ans;
    return 0;

}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ; 
ll _abs (ll x ) { return (x>0?x:-x); }

const int N=1e3+5;
int a[N][N];
ll dp[N][N] ;  
int H , W ; 
const int mod =1e9+7; 
void prop(int i , int j , ll val ){
    if( i <= H && j <= W && j >= 0 && i >= 0 && dp[i][j]!=-1)
        dp[i][j] = (dp[i][j]+val+mod)%mod; 
}
int main(){
    fastio ; 
    cin>>H>>W ; 
    for(int i = 1 ; i <= H ; i++ ){
        for(int j = 1 ; j <= W ; j++ ){
            char c ; 
            cin>> c; 
            if( c== '#' )dp[i][j]=-1; 
        }
    }
    dp[1][1] = 1; 
    for(int i=1;i<=H;i++ ){
        for(int j=1;j<=W;j++){
            if( dp[i][j]!=-1 ){
            ll curr = dp[i][j]; 
            prop(i+1,j,curr); 
            prop(i,j+1,curr); 
            prop(i-1,j,curr); 
            prop(i,j-1,curr) ; 
            }
        }
    }
    //for(int i=1;i<=H;i++ ){for(int j=1;j<=W;j++)cout<<dp[i][j]<<" ";cout<<endl;} 
    cout<<dp[H][W] ; 
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

struct rangetree{
  int size;
  vector<vector<int> > dat;
  rangetree(){}

  void init(vector<int> nums){
    int n=nums.size();
    size=1;
    while(size<n)size*=2;
    dat.resize(size*2);

    for(int i=0;i<size*2;i++)dat[i].clear();

    for(int i=0;i<n;i++){
      dat[i+size-1].push_back(nums[i]);
    }

    for(int i=size-2;i>=0;i--){
      int lc=i*2+1,rc=i*2+2;
      dat[i].resize(dat[lc].size()+dat[rc].size());
      merge(dat[lc].begin(),dat[lc].end(),dat[rc].begin(),dat[rc].end(),dat[i].begin());
    }
  }

  int query(int a,int b,int t,int k,int l,int r){
    if(b<=l||r<=a)return 0;
    if(a<=l&&r<=b){
      return upper_bound(dat[k].begin(),dat[k].end(),t)-dat[k].begin();
    }
    return query(a,b,t,k*2+1,l,(l+r)/2)+query(a,b,t,k*2+2,(l+r)/2,r);
  }

  int query(int a,int b,int t){
    return query(a,b,t,0,0,size);
  }
};

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll N;
ll X[200010],Y[200010];
vector<ll> xs,ys;
vector<P> ps;
vector<int> yys;

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

  cin>>N;
  rep(i,N){
    cin>>X[i]>>Y[i];
    xs.push_back(X[i]);
    ys.push_back(Y[i]);
  }
  sort(all(xs)); sort(all(ys));

  rep(i,N){
    X[i]=lower_bound(all(xs),X[i])-xs.begin();
    Y[i]=lower_bound(all(ys),Y[i])-ys.begin();
    ps.push_back(P(X[i],Y[i]));
  }
  sort(all(ps));
  rep(i,N)yys.push_back(ps[i].se);

  rangetree sgt;
  sgt.init(yys);

  ll res=0;
  rep(i,N){
    (res+=mod_pow(2,N-1))%=mod;
    ll p1,p2,p3,p4;
    p4=sgt.query(X[i]+1,N,Y[i]);
    p1=sgt.query(X[i]+1,N,N)-p4;
    p3=sgt.query(0,X[i],Y[i]);
    p2=sgt.query(0,X[i],N)-p3;
    ll A=((mod_pow(2,p1)-1+mod)*(mod_pow(2,p3)-1+mod)%mod)*mod_pow(2,N-1-p1-p3)%mod;
    ll B=((mod_pow(2,p2)-1+mod)*(mod_pow(2,p4)-1+mod)%mod)*mod_pow(2,N-1-p2-p4)%mod;
    ll C=((mod_pow(2,p1)-1+mod)*(mod_pow(2,p2)-1+mod)%mod)*((mod_pow(2,p3)-1+mod)*(mod_pow(2,p4)-1+mod)%mod)%mod;

    (res+=A+B-C+mod)%=mod;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 48608
/*
      author  : nishi5451
      created : 12.08.2020 22:05:46
*/

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


int main(){
    int k,s;
    cin >> k >> s;
    int ans = 0;
    for(int i=0; i<=k; i++)
        for(int j=0; j<=k; j++)
            if(s-i-j>=0 && s-i-j<=k) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> vec;
int main()
{
    int n, x, y, t, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        vec.push_back(t);
        sum += vec[i];
    }
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        cout << sum - vec[x - 1] + y << endl;
    }
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int di[10][10];

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

    int H, W;
    std::cin >> H >> W;

    for(int i=0;i<=9;++i){
        for(int j=0;j<=9;++j){
            std::cin >> di[i][j];
        }
    }

    for(int k=0;k<=9;++k){
        for(int i=0;i<=9;++i){
            for(int j=0;j<=9;++j){
                di[i][j] = min(di[i][j], di[i][k] + di[k][j]);
            }
        }
    }

    ll cost = 0ll;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            int a;
            std::cin >> a;

            if(a == -1){continue;}
            // std::cout << di[a][1] << std::endl;
            cost += di[a][1];
        }
    }

    std::cout << cost << std::endl;
}


Measured memory_bytes: 256
// 200219.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

int main()
{
    int N;
    int X[100];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    int min_sum = 0;
    for (int P = 1; P <= 100; P++) {
        int sum = 0;
        for (int i = 0; i < N; i++) {
            sum += (X[i] - P) * (X[i] - P);
        }
        if (P == 1) {
            min_sum = sum;
        }
        else {
            if (sum < min_sum) {
                min_sum = sum;
            }
        }
    }
    cout << min_sum << endl;
    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256