akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }
//priority_queue <int>a;
#define ll long long
const int mod = 1e9 + 7;
const int nax = 1e5 + 5;
int n, m, k, q;

int main(){
	fast();
	cin >> n >> m;
	int t;
	int sum = 0;
	for(int i = 0; i < m; ++i){
		cin >> t;
		sum += t;
	}
	if(sum > n) cout << -1;
	else cout << n - sum;
}



Measured memory_bytes: 3652
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		for(int i = 1; i <= 100000; i++) {
			if((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 35664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;


int main() {

	long long A, B;
	cin >> A >> B;

	if ((A + B) % 2 != 0) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (A + B) / 2 << endl;
	}


}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {

    int N;
    scanf("%d", &N);

    long a[N];
    REP(0, i, N) {
        scanf("%ld", &a[i]);
    }

    int cnt = 0;
    int idx = 0;
    while (true) {
        if (a[idx] % 2 == 0) {
            cnt++;
            a[idx] /= 2;
        } else {
            idx++;
        }

        if (idx == N) {
            break;
        }
    }

    printf("%d\n", cnt);

    return 0;
}


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

int k, s;

int main(){
  cin >> k >> s;
  int ans = 0;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      if(x + y > s || x + y + k < s){
        continue;
      }
     // cerr <<x << " "<<y<<" "<< s - x - y<< endl;
      ans++;
    }
  }   
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in();console.log(e*e)}}]);

Measured memory_bytes: 22076
#include<stdio.h>

int main(void){
       int N,K,i,j,temp;
       int p[1010];

       scanf("%d %d",&N,&K);
       for(i=0;i<N;i++){
              scanf("%d",&p[i]);
       }

       for (i = 0; i < N - 1; i++) {
              for (j = N - 1; j > i; j--) {
                     if (p[j - 1] > p[j]) {  /* 前の要素の方が大きかったら */
                            temp = p[j];        /* 交換する */
                            p[j] = p[j - 1];
                            p[j - 1]= temp;
                     }
              }
       }
       temp = 0;
       for(i=0;i<K;i++){
              temp = temp + p[i];
       }

       printf("%d",temp);

       return 0;
}

Measured memory_bytes: 1732
//ΔABC 070B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a>d||c>b)
		cout<<"0\n";
	else
		cout<<min(b,d)-max(a,c)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>

#define INC(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define DEC(i, a, b) for(int (i) = (a); (i) > (b); --(i))
#define REP(i, n)    INC(i, 0, n)
#define comp(a, b) int comp(const void *(a), const void *(b))

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

int abs(int x){
    return x > 0? x : -x;
}

int max(int a, int b){
    return a > b? a : b;
}

int min(int a, int b){
    return a < b? a : b;
}


int main(){
    int K, N; cin >> N >> K;
    bool b = (N - 1) % (K - 1) == 0;
    int temp;
    REP(i, N) cin >> temp;
    int ans = (N - 1) / (K - 1) + (b? 0 : 1);
    cout << ans << endl;

    return 0;
}
 /*
 (K - 1) * ans + 1 >=N
 */

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	ans := "Good"
	for i := range s {
		if i >= 1 {
			if s[i-1] == s[i] {
				ans = "Bad"
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S, ans; cin >> S;
  if (S == "Sunny") ans = "Cloudy";
  else if (S == "Cloudy") ans = "Rainy";
  else if (S == "Rainy") ans = "Sunny";
  cout << ans << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
AB.sort()
honsu=0
okane=0
for i in range(N):
    if honsu+AB[i][1]<M:
        honsu+=AB[i][1]
        okane+=AB[i][0]*AB[i][1]
    else:
        okane+=AB[i][0]*(M-honsu)
        break
print(okane)

Measured memory_bytes: 27760
// ACPC_AIZUDAI_DROPOUT
// coder : naan

#include <bits/stdc++.h>

int main(){
    using namespace std;
    long T1, T2, R1, R2;
    cin >> T1 >> T2 >> R1 >> R2;
    if(R1 == -1 || R2 == -1){
        puts(T1 < T2 ? "Alice" : T1 == T2 ? "Draw" : "Bob");
    }else{
        puts(R1 > R2 ? "Alice" : R1 == R2 ? "Draw" : "Bob");
    }
    return 0;
}


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

long long cnt[26];

int main(void)
{
	for (int i = 0; i < 26; i++) cnt[i] = 0;

	string A;
	cin >> A;
	long long len = A.length();

	for (int i = 0; i < len; i++) {
		cnt[A.at(i)-(unsigned int)'a']++;
	}

	long long ans = (len) * (len-1) / 2 + 1;
	for (int i = 0; i < 26; i++) {
		long long c = cnt[i];
		if (c == 0) continue;
		ans -= (c*(c-1)/2);
	}

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

Measured memory_bytes: 644
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int h,w,k;
int xx1, yy1, xx2, yy2;

vector<vector<char>> c;
vector<vector<ll>> m;
queue<pair<int, int>> q;

ll move(int px, int py, ll mn) {
  if (px == xx2 && py == yy2) return mn;
//printf("  move(%d,%d): %c,%lld\n", px, py, c[px][py], mn);
  if (c[px][py] == '@') return -1;
  if (m[px][py] == mn) return -2;
  if (m[px][py] != 0 && m[px][py] < mn) return -1;
//printf("push(%d,%d): %lld\n", px, py, mn);
  m[px][py] = mn;
  return 0;

}
ll move() {
  pair<int, int> p;
  int px,py;
  ll mret;

  q.push(make_pair(xx1, yy1));

  while (!q.empty()) {
    p = q.front();
    q.pop();

//printf("(%d,%d)=%lld\n", p.first, p.second, m[p.first][p.second]);
    if (p.first == xx2 && p.second == yy2) {
      return m[p.first][p.second];
    }

    ll mn=m[p.first][p.second]+1;

    //上に移動
    py = p.second;
    for (px=p.first-1; px>=0 && p.first-px<=k; px--) {
      mret = move(px, py, mn);
      if (mret == -1) break;
      if (mret == -2) continue;
      if (mret > 0) return mret;
      q.push(make_pair(px, py));
    }
    //下に移動
    for (px=p.first+1; px<h && px-p.first<=k; px++) {
      mret = move(px, py, mn);
      if (mret == -1) break;
      if (mret == -2) continue;
      if (mret > 0) return mret;
      q.push(make_pair(px, py));
    }
    //左に移動
    px = p.first;
    for (py=p.second-1; py>=0 && p.second-py<=k; py--) {
      mret = move(px, py, mn);
      if (mret == -1) break;
      if (mret == -2) continue;
      if (mret > 0) return mret;
      q.push(make_pair(px, py));
    }
    //右に移動
    for (py=p.second+1; py<w && py-p.second<=k; py++) {
      mret = move(px, py, mn);
      if (mret == -1) break;
      if (mret == -2) continue;
      if (mret > 0) return mret;
      q.push(make_pair(px, py));
    }
  }
  return -1;
}

int main()
{
  ll ans=0;

  cin >> h >> w >> k;
  cin >> xx1 >> yy1 >> xx2 >> yy2;
  xx1--; yy1--; xx2--; yy2--;

  c.resize(h); m.resize(h);
  for (int i=0; i<h; i++) {
    c[i].resize(w); m[i].resize(w);
    for (int j=0; j<w; j++) {
      cin >> c[i][j];
    }
  }
  /*
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      printf("%c", c[i][j]);
    }
    printf("\n");
  }
    */

  m[xx1][yy1] = 0;

  ans = move();

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


Measured memory_bytes: 13084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
 int N,M,ans=0;
  cin>>N>>M;
  vector<int> h(N),v(N);
  rep(i,N){
  cin>>h[i];
    v[i]=-1000;
  }
  rep(i,M){
  int a,b;
    cin>>a>>b;
    a--; b--;
    v[a]=max(h[b],v[a]);
    v[b]=max(h[a],v[b]);
  }
  rep(i,N){
    if(h[i]>v[i])ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4024
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a, b, c = [], [], []
# dp = [[None] * 3 for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]

for i in range(n):
    v1, v2, v3 = map(int, input().split())
    a.append(v1)
    b.append(v2)
    c.append(v3)

dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

for idx in range(1, n):
    # Select A(0)
    a1 = dp[idx - 1][1] + a[idx]
    a2 = dp[idx - 1][2] + a[idx]
    dp[idx][0] = max(a1, a2)

    # Select B(1)
    b1 = dp[idx - 1][0] + b[idx]
    b2 = dp[idx - 1][2] + b[idx]
    dp[idx][1] = max(b1, b2)

    # Select C(2)
    c1 = dp[idx - 1][0] + c[idx]
    c2 = dp[idx - 1][1] + c[idx]
    dp[idx][2] = max(c1, c2)

print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))

Measured memory_bytes: 102600
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    multiset<int> st;
    map<int,int> mp;
    rep(i,0,N){
        /*
        auto itr = st.lower_bound(V[i]);
        if(itr == st.begin()){
            st.insert(V[i]);
            continue;
        }
        itr--;
        auto itr2 = st.find(*itr);
        itr2 = V[i];
        */
        auto itr = mp.lower_bound(V[i]);
        if(itr == mp.begin()){
            mp[V[i]]++;
            continue;
        }
        itr--;
        int x = itr->second;
        if(x == 1){
            mp.erase(itr);
        }else{
            mp[itr->first]--;
        }
        mp[V[i]]++;
    }
    int sum = 0;
    for(auto p:mp){
        sum += p.second;
    }
    cout << sum << endl;
}

Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
ll ans=0,bl,wh;char s;
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
int a[405][405],b[405][405];
void dfs(int x,int y){
    b[x][y]=1;
    if(a[x][y]==1)bl++;
    else if(a[x][y]==-1)wh++;
    for(int i=0;i<4;i++){
        if((a[x][y]+a[x+dx[i]][y+dy[i]]==0)&&!b[x+dx[i]][y+dy[i]])dfs(x+dx[i],y+dy[i]);
	}
	return;
}

int main(void){
    int h,w;cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>s;
            if(s=='#')a[i][j]=1;
            else a[i][j]=-1;
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(a[i][j]==1){
                bl=0;wh=0;
                dfs(i,j);
                ans+=bl*wh;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8960
/**
 *    author:  math2do
 *    created: 04.09.2020 15:17:55 IST
**/

#include <bits/stdc++.h>

using namespace std;

#define max(...) max({__VA_ARGS__})

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m = 3;
  cin >> n;
  vector <vector <int> > mat(n, vector <int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    } 
  } 
  vector <vector <int> > dp(n, vector <int>(m, 0));
  dp[0][0] = mat[0][0];
  dp[0][1] = mat[0][1];
  dp[0][2] = mat[0][2];
  
  for (int i = 1; i < n; i++) {
    dp[i][0] = mat[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = mat[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = mat[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
  } 
  
  cout << max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]) << endl;
  return 0;
}


Measured memory_bytes: 14248
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    K--;
    if (S.at(K) == 'A') {
        S.at(K) = 'a';
    }
    else if (S.at(K) == 'B') {
        S.at(K) = 'b';
    }
    else {
        S.at(K) = 'c';
    }
    cout << S << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

template<typename T>
vector<T>divisor(T n){//約数列挙
    vector<T>v;
    for(T i=1;i*i<=n;++i){
        if(n%i==0){
            if(i!=1)v.push_back(i);
            if(i*i!=n)v.push_back(n/i);
        }
    }
    sort(v.begin(),v.end());
    return v;
}

void solve(){
  ll n;
  cin>>n;
  ll ans=0;
  for(auto d:divisor<ll>(n)){
    ll x=n;
    while(x>=d){
      if(x%d==0)x/=d;
      else x%=d;
    }
    if(x==1)++ans;
  }
  auto d=divisor<ll>(n-1);
  ans+=d.size();
  cout<<ans;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    string s; cin >> s;
    int n = s.size();

    int cur = 1;
    vi a(n+1);
    rep(i,n){
        int c = s[n-i-1] - '0';
        a[i+1] = (cur * c + a[i]) % 2019;
        cur = cur * 10 % 2019;
    }

    int ans = 0;
    vi r(2019);
    rep(i,n+1){
        ans += r[a[i]];
        r[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  vector<ll>a(n),sum(n+1);
  rep(i,n)cin>>a[i];
  rep(i,n)sum[i+1]=sum[i]+a[i];
  ll res=1e15;
  rep(i,n)
  {
    //cout<<i<<endl;
    ll suml=sum[i+1],sumr=sum[n]-sum[i+1];
    auto itl=lower_bound(all(sum),(suml+1)/2);
    ll p=max(suml-*itl,*(itl-1)),q=suml-p;
    auto itr=lower_bound(all(sum),(sumr+1)/2+suml);
    //cout<<*itr<<endl;
    ll r=max(sumr+suml-*itr,*(itr-1)-suml),s=sumr-r;
    //cout<<p<<" "<<q<<" "<<r<<" "<<s<<endl;;
    chmin(res,max({p,q,r,s})-min({p,q,r,s}));

  }
  cout<<res<<endl;
  return 0;

}



Measured memory_bytes: 3456
def main():
    n = int(input())
    a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]
    id = [[0]*n for _ in range(n)]
    V = 0
    for i in range(n):
        for j in range(n):
            if i<j:
                id[i][j] = V
                V += 1
    def toID(i, j):
        if i<j:
            return id[i][j]
        else:
            return id[j][i]
    
    to = [[] for _ in range(V)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] = toID(i, a[i][j])
        for j in range(n-2):
            to[a[i][j+1]].append(a[i][j])

    dp, visited, calculated = [1] * V, [0] * V, [0] * V

    def dfs(v, dp, visited, calculated):
        if visited[v]:
            if not calculated[v]:
                return -1
            return dp[v]
        visited[v] = 1
        for u in to[v]:
            res = dfs(u, dp, visited, calculated)
            if res == -1:
                return -1
            dp[v] = max(dp[v], res+1)
        calculated[v] = 1
        return dp[v]

    ans = 0
    for v in range(V):
        res = dfs(v, dp, visited, calculated)
        if res == -1:
            print(-1)
            return
        ans = max(ans, res)
    print(ans)
    return

main()


Measured memory_bytes: 224476
# class Array
#   def get(idx)
#     if 0 <= idx && idx < self.size
#       self.at(idx)
#     else
#       raise IndexError.new("index #{idx} outside of array bounds: 0...#{self.size}")
#     end
#   end
#
#   # NOTE: Overwrite
#   def [](idx)
#     get(idx)
#   end
# end


def make_2d_array(n, m, init)
  n.times.map{[init] * m}
end

def show_table(table)
  table.each{|row|
    puts(row.map(&:inspect).join(' '))
  }
end

def min(a, b)
  a < b ? a : b
end

n, _   = gets.split(' ').map(&:to_i)
# Available coins
coins = gets.split(' ').map(&:to_i)

# Initialize DP table
dp_table = make_2d_array(coins.size+1, n+1, 0) # (coins.size + 1).times{[nil] * (coins.size + 1)}
(1..n).each{|j|
  dp_table[0][j] = Float::INFINITY
}
dp_table[0][0] = 0


(1..coins.size).each{|i|
  (0..n).each{|j|
    coin = coins[i-1]
    if 0 <= j - coin
      dp_table[i][j] = min(dp_table[i-1][j], dp_table[i][j - coin] + 1)
    else
      dp_table[i][j] = dp_table[i-1][j]
    end
  }
}



puts(dp_table[-1][-1])


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

class Eratosthenes{ //NMAX変更しておｋ
    private:
        const static int NMAX = 200010;
    public:
        vector<bool> prime;
        Eratosthenes(){
            prime.resize(NMAX,true);//一旦全部trueとする(true=素数)
            prime[0] = false;
            prime[1] = false;
            for(int i=2;i*i<=NMAX;i++){
                if(prime[i]){
                    for(int j=2;i*j<=NMAX;j++) prime[i*j] = false;
                }
            }
        }
        inline vector<bool> isPrime(){ return prime; }

};
#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
ll mod = 1e9+7;
ll calc[1100];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n; cin >> n;
    ll ans = 1; //1をいれとく
    Eratosthenes sosu;
    rep(i,2,n+1){
        rep(j,2,i+1){
            ll tmp = i;
            while(tmp != 0 && tmp%j==0 && sosu.prime[j]){
                calc[j]++;
                tmp /= j;
            }
        }
    }
    rep(i,2,n+1){
        (ans *= (calc[i]+1)) %= mod;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(), k=sc.nextInt(),i,tmp,flag;
        int[] d = new int[10];
        int[] cnt = new int[10];
        for(i=0;i<10;i++)
            cnt[i]=0;
        for(i=0;i<k;i++){
            d[i] = sc.nextInt();
            cnt[d[i]]++;
        }
        for(i=n;;i++){
            tmp = i;
            flag = 1;
            for(;;){
                if(tmp==0) break;
                if(cnt[tmp%10]==1){
                    flag = 0;
                    break;
                }
                tmp/=10;
            }
            if(flag==1){
                System.out.println(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 21844
#include<cstdio>

int main(){
  int l, r = 0, t = 0;
  scanf("%d", &l);
  for(; (1<<r) <= l; r++) if(l&(1<<r)) t++;
  printf("%d %d\n", r, 2*r+t-3);
  for(int i = 1; i < r; i++){
    printf("%d %d %d\n%d %d %d\n", i, i+1, 1<<(i-1), i, i+1, 0);
    if(l&(1<<(i-1))) printf("%d %d %d\n", i, r, l-=l&-l);
  }
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QQ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    Console.WriteLine(i+"x"+j+"="+i*j);
                }
            }
        }
    }
}

Measured memory_bytes: 5536
// ABC B
// DeP
#include <cstdio>

typedef long long LL;
const int MAXN = 55;

int n; LL ans;
int D[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", D+i);
    for (int i = 1; i <= n; ++i)
        for (int j = i+1; j <= n; ++j) ans += 1LL * D[i] * D[j];
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

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

	class Edge{
		int from;
		int to;
		public Edge(int from, int to) {
			this.from=from;
			this.to=to;
		}
	}
	ArrayList<ArrayList<Integer>> g = new ArrayList<>();
	ArrayList<Edge> es = new ArrayList<>();
	boolean used[];
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		for(int i=0; i<n; i++) {
			g.add(new ArrayList<>());
		}
		used = new boolean[n];
		for(int i=0; i<m ;i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			a--; b--;
			g.get(a).add(b);
			g.get(b).add(a);
			es.add(new Edge(a,b));
		}

		int ans = 0;
		for(Edge e : es) {
			int a =e.from;
			int b =e.to;
			for(int i=0 ;i<n; i++) {
				used[i]=false;
			}
			int cnt = dfs(0, a, b);
			if(cnt != n) {
				ans++;
			}

		}
		System.out.println(ans);

		sc.close();
	}

	private int dfs(int p, int a, int b) {
		used[p]=true;
		int cnt = 1;
		for(int v : g.get(p)) {
			if((p==a && v==b) || (p==b && v==a)) continue;
			if(!used[v]) {
				cnt += dfs(v,a,b);
			}
		}
		return cnt;
	}
}


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

using namespace std;

const long long INF = 1LL << 60;

int main() {
  int n,k;
  cin >> n >> k;
  int x[n];
  for(int i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long ans = INF;
  for(int i = 0; i <= n-k; i++) {
    long long tmp;
    long long up = x[i+k-1];
    long long low = x[i];
    tmp = min((abs(up) + abs(up-low)), (abs(low) + abs(low-up)));
    ans = min(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;

static const int MAX = 100;
static const long long INFTY = (1LL<<32);


//===================================
// Washall floyd: ワ−シャル・フロイド
// 全点対間の最短経路問題に利用
// O[|v|^3]
// v：頂点数
//===================================


int n;
long long d[MAX][MAX];  //d[i][j]の最短コストを記録するDPテーブル

void floyd() {

  for( int k = 0; k < n; k++){         //経由する頂点数
    for(int i = 0; i < n; i++){         //始点
      if( d[i][k] == INFTY ) continue;

      for(int j = 0; j < n; j++){       //終点
      if( d[k][j] == INFTY ) continue;
      d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

      }
    }
  }
}


int main() {
  int e, u, v, c; //e: 辺の数, 頂点 u --> 頂点 v のコスト ｃ
  cin >> n >> e;

  //隣接行列リストの初期化 始点 --> 始点 を 0 に，　それ以外を　INFTY
  for( int i = 0; i < n; i++){
    for( int j = 0; j < n; j++){
      if(i == j) d[i][j] = 0;
      else d[i][j] = INFTY;
      //d[i][j] = ((i == j) ? 0 : INFTY);
    }
  }

  //隣接行列リストとして入力
  for(int i = 0; i < e; i++){
    cin >> u >> v >> c;
    d[u][v] = c;
  }

  //Washall-Floydによる最短路の検索

  floyd();

  //グラフに負の Closed Loopがないかの確認
  bool negative = false;
  for( int i = 0; i < n; i++ ){
    if( d[i][i] < 0) negative = true;
  }

  //Output
  if( negative ){
    cout << "NEGATIVE CYCLE" << endl;
  }
  else{
    for( int i = 0; i < n; i++){
      for( int j = 0; j < n; j++){
        if( j ) cout << " ";
        if( d[i][j] == INFTY ) cout << "INF";
        else cout << d[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3168
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    
    String s = br.readLine();
    long[] count = new long[26];
    long n = s.length();
    for (int i=0; i<s.length(); i++) {
      count[s.charAt(i)-'a']++;
    }
    long sum = 0;
    for (int i=0; i<26; i++) {
      sum += (count[i]*(count[i]-1))/2;
    }
    System.out.println((n*(n-1))/2 - sum + 1);
  }
}


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

using namespace std;

vector<vector<int> > v;

int main(){
  int a,b,c,x,y,n,m,k;
  cin >> n >> m;
  int arr[30] = {0};
  for(int i = 0; i < n; i++){
    cin >>k;
    for(int j = 0; j < k;j++){
      cin >> a;
      arr[a-1]++;
    }
  }
  int ans =0;
  for(int i = 0 ; i < m ; i++){
    if(arr[i] == n) ans++;
  }
    cout << ans << endl;
}


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


int main(){
    int n, m;
    cin  >> n >> m;
    vector<int> h(n);
    vector<bool> ok(n, true);
    rep(i,n) cin >> h[i];
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        if(h[a] <= h[b]) ok[a] = false;
        if(h[b] <= h[a]) ok[b] = false;
    }
    int ans = 0;
    rep(i,n) if(ok[i]) ans++;
    cout << ans << endl;
	return 0;
}

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

int main()
{
  pair<int,int> pii[100005];
  int n;
  int a[100005];

  cin>>n;

  for(int i=0; i<n; i++){
    cin>>a[i];
    pii[i]=make_pair(a[i],i);
  }
  sort(pii,pii+n);

  for(int i=0; i<n; i++){
    cout<<pii[i].second+1;
    if(i==n-1)cout<<'\n';
    else cout<<' ';
  }


  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> gc(n);
  for(int i = n - 2; i >= 0; i --){
    if(i == n - 2)
    gc[i] = a[i + 1];
    else
    gc[i] = gcd(gc[i + 1], a[i + 1]);
  }
  int g = a[0];
  int ans = -1;
  rep(i, n){
    if(i == 0)
    ans = max(ans, gc[i]);
    else if(i == 1 && i != n - 1){
      g = a[i - 1];
      ans = max(ans, gcd(g, gc[i]));
    }else if(i == n - 1){
      // cout << i << endl;
      g = gcd(g, a[i - 1]);
      ans = max(ans, g);
    }else{
      g = gcd(g, a[i - 1]);
      ans = max(ans, gcd(g, gc[i]));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll N,P;
map<ll,int> m;
int main(){
	cin >> N >> P;
	ll Q = P;
	ll ans = 1ll;
	for(ll i=2ll;i*i<=Q;i++){
		if(P%i==0ll){
			ll k=0ll;
			while(P%i==0ll){
				P/=i;
				k++;
			}
			for(ll j=0ll;j<k/N;j++)ans *= i;
		}
	}
	if(N==1ll)ans *= P;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,sum=0,x;
    scanf("%d",&n);
    int i,j,a[10005];
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    int max=a[0];
    for(j=1;j<=n;j++)
    {
        if(a[j]>max)
        {
            max=a[j];

        }
    }
    x=max/2;
    sum = sum + x - max;

    printf("%d\n",sum);



}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    ll n, k;
    cin >> n >> k;
    ll ans;
    ans = (n%k);
    ans = min(ans, abs(ans-k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
gets

colors = [false] * 8
top = 0

gets.split(" ").each do |e|
    v = e.to_i / 400
    if v <= 7
        colors[v] = true
    else
        top += 1
    end
end

min = [colors.count {|v|v}, 1].max
max = colors.count {|v|v} + top

puts "#{min} #{max}"

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == '1')cnt++;
	}
	cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i, count;
	scanf("%d", &i);
	while(i != 0){
		count = 0;
		i = 1000 - i;
		if(i >= 500){
			i -= 500; count++;
		}
		if(i >= 100){
			count += (i/100); i %= 100;
		}
		if(i >= 50){
			i -= 50; count++;
		}
		if(i >= 10){
			count += (i/10); i %= 10;
		}
		if(i >= 5){
			i -= 5; count++;
		}
		count += i;
		
		printf("%d\n", count);
		
		scanf("%d", &i);
	}
	return 0;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  vector<char> n(4);
  vector<int> j(4);
  j[0] = 0, j[1] = 1, j[2] = 2, j[3] = 3;
  for (int i = 0; i < 4; i++) {
    cin >> n[i];
  }
  do {
    string s = "";
    for (int i = 0; i < 4; i++) {
      s += n[j[i]];
    }
    if (s == "1974") {
      cout << "YES" << endl;
      return 0;
    }
  } while (next_permutation(j.begin(), j.end()));
  cout << "NO" << endl;

  return 0;
}

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

int main() {

    int N, K, S;
    cin >> N >> K >> S;

    vector<int> ans(N, INF);
    if (S == 1) {
        rep(i, K) ans[i] = S;
    } else if (S % 2 == 0) {
        if (S == INF) {
            ans.assign(N, 1);
        }
        if (N == K)
            rep(i, N) ans[i] = S;

        else {
            rep(i, K + 1)
                ans[i] = S / 2;
        }
    } else {
        if (N == K)
            rep(i, N) ans[i] = S;

        else {
            rep(i, K + 1) {
                if (i % 2 == 0)
                    ans[i] = 1;
                else
                    ans[i] = S - 1;
            }
        }
    }

    rep(i, N) {
        cout << ans[i];
        if (i != N - 1)
            cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(ll i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

ll powmod(ll N, ll P){
    N%=mod;
    if(P==0) return 1;
    if(P%2==0){
        ll t = powmod(N, P/2);
        return t*t % mod;
    }
    return N*powmod(N, P-1)%mod;
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    ll sum=powmod(2,n);
    ll ca=1,cb=1;
    ll nua=n,nub=n;
    rep(i,a){
        ca=ca*nua%mod;
        nua--;
    }
    rep(i,b){
        cb=cb*nub%mod;
        nub--;
    }
    ll tema=1,temb=1;
    nua=1;
    nub=1;
    rep(i,a){
        tema=tema*nua%mod;
        nua++;
    }
    rep(i,b){
        temb=temb*nub%mod;
        nub++;
    }
    ll ina,inb;
    ina=powmod(tema,mod-2)%mod;
    inb=powmod(temb,mod-2)%mod;
    ca=ca*ina%mod;
    cb=cb*inb%mod;
    sum-=ca+cb;
    sum+=2*mod-1;
    sum%=mod;
    cout << sum;


    
}

Measured memory_bytes: 256
let S = Array(readLine()!)
let T = Array(readLine()!)

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: S.count + 1), count: T.count + 1)


for i in 1...T.count {
  for j in 1...S.count {
    if T[i-1] == S[j-1] {
      dp[i][j] = dp[i-1][j-1] + 1
    } else {
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
    }
  }
}
var len = dp[T.count][S.count]

var ans: [String] = .init(repeating: "", count: len)

var i = T.count
var j = S.count

while len > 0 {
  if T[i-1] == S[j-1] {
    ans[len - 1] = String(T[i-1])
    i -= 1
    j -= 1
    len -= 1
  } else if dp[i-1][j] > dp[i][j - 1] {
    i -= 1
  } else {
    j -= 1
  }
}

print(ans.joined())

Measured memory_bytes: 78332
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define P 1000000007
int n,m,ans,i;
inline int read()
{
	char ch=getchar();
	int x=0,f=1;
	while (ch<'0'||ch>'9')
		{
			if (ch=='-') f=-1;
			ch=getchar();
		}
	while (ch<='9'&&ch>='0')
		{
			x=x*10+ch-'0';
			ch=getchar();
		}
	return x*f;
}
inline void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>=10) write(x/10);
	putchar(x%10+'0');
}
int main() 
{
	n=read();
	m=read();
	if (n<m) swap(n,m);
	if (n-m>1)
	{
		puts("0");
		return 0; 
	 }
	ans=1;
	if (n==m) ans=2;
	for (i=1;i<=n;i++) ans=1ll*ans*i%P;
	for (i=1;i<=m;i++) ans=1ll*ans*i%P;
	write(ans);
} 

Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int n; cin >> n;
	int gainMoney = n / 15 * 200;
	cout << n * 800 - gainMoney << endl;
	return 0;
}

Measured memory_bytes: 256
printNum::Int->IO()
printNum n = putStrLn $ take n $ repeat '#'


printRec::(Int,Int)->IO ()
printRec (a,b) = sequence_ $ (\x->x++[putStrLn ""]) . take a $ repeat $ printNum b

function::String->IO ()
function x=mapM_ printRec $ takeWhile(/=(0,0))$map (\[x,y]->(read x::Int,read y::Int)) $ map words $ lines x

main = getContents >>= function

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll n; cin >> n;
  Vll a(n); cin >> a;
  map<ll, ll> cnt1, cnt2;

  rep(i, n) {
    ++cnt1[i+a[i]];
    ++cnt2[i-a[i]];
  }

  ll ans = 0;
  for (auto &e : cnt1) {
    ans += e.second * cnt2[e.first];
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 39064
#include <stdio.h>
#include <string.h>
#define L 100005

typedef struct pp
{
  char name[100];
  int t;
} P;

P A[L];
int zyou,ge,n;

void enqueue(P x)
{
  A[ge] = x;
  ge = (ge + 1)% L;
}

P dequeue()
{
  P x = A[zyou];
  zyou =(zyou + 1) % L;
  return x;
}

int min(int x,int y)
{return x < y ? x : y;}

int main()
{
  int e=0, c;
  int i,qqq;

  P u;
  scanf ("%d %d",&n,&qqq);

  for (i=1;i<=n;i++)
    {
      scanf("%s", A[i].name);
      scanf("%d", &A[i].t);
    }
  zyou = 1;
  ge = n+1;

  while(zyou != ge)
    {
      u = dequeue();
      c = min(qqq,u.t);
      u.t -= c;
      e += c;
      if (u.t > 0) enqueue(u);
      else
	{
	  printf("%s %d\n",u.name,e);
	    }
    }

  return 0;
}
	 



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

int main(){
  int N;
  cin >> N;
  for(int i=N;i<=999;i++){
    string s=to_string(i);
    set<char> se;
    for(int j=0;j<3;j++){
      se.insert(s.at(j));
    }
    if(se.size()==1){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let a = [0]
    a.push(...nextIntArray())
    a.push(0)
    let total = 0
    for(let i = 1; i<a.length; i++){
        total += Math.abs(a[i] - a[i-1])
    }
    for(let i = 1; i<a.length-1; i++){
        console.log(total - Math.abs(a[i] - a[i-1]) - Math.abs(a[i+1]-a[i]) + Math.abs(a[i+1] - a[i-1]))
    }
}
Main()



Measured memory_bytes: 49468
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		double pi = Math.PI;
		double area = r * r * pi;
		double length = 2 * r * pi;
		System.out.printf("%f %f\n", area, length);
	}
}

Measured memory_bytes: 28092
from collections import Counter

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
if N % 2:
    if c[0] == 1 and all(c[i] == 2 for i in range(2, N, 2)):
        print(pow(2, (N // 2), MOD))
    else:
        print(0)
else:
    if all(c[i] == 2 for i in range(1, N, 2)):
        print(pow(2, (N // 2), MOD))
    else:
        print(0)

Measured memory_bytes: 14820
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
bool operator<(const edge& rhs) const {
return len > rhs.len;
}
};

ll const MOD = 1e9 + 7;

ll const MAX = 100005;
ll a[MAX];
ll ans[MAX];

int main() {
	ll n;
	cin >> n;
	ll ttl = 0;
	REP(i, 1, n) {
		cin >> a[i];
		ttl += a[i];
	}
	ll v = (n + 1)*n / 2;
	if (ttl%v != 0) {
		cout << "NO" << endl;
		return 0;
	}
	ll times = ttl / v;
	a[0] = a[n];
	REP(i, 1, n) {
		ll dif = a[i] - a[i - 1];
		if (times - dif < 0 || (times - dif) % n != 0) {
			cout << "NO" << endl;
			return 0;
		}
		ans[i] = (times - dif) / n;
	}
	ll times_sum = 0;
	REP(i, 1, n) {
		times_sum += ans[i];
	}
	if (times_sum != times) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif

string s;
cin>>s;
bool flag =1;
forn(i,0,s.sz-1){
    if(s[i]==s[i+1]) flag=0;
}
if(flag){
    cout<<"Good"<<endl;
}else{
    cout<<"Bad"<<endl;
}
}



Measured memory_bytes: 3648