akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=4005;
int sd[N],size1[N],size2[N],ne[N],n,x,y,tot,fi[N],zz[N];
char s[N];
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
}
void dfs(int x,int y,int z){
	sd[x]=z;if (s[x]=='1')size1[x]=sd[x],size2[x]=1;
	else size1[x]=size2[x]=0;
	for (int i=fi[x];i;i=ne[i])
		if (zz[i]!=y){
			dfs(zz[i],x,z+1);
			size1[x]+=size1[zz[i]];
			size2[x]+=size2[zz[i]];
		}
}
int merge(int x,int y){
	vector<int> v;
	int sum=0,num=0,Max=0;
	for (int i=fi[x];i;i=ne[i])
		if (zz[i]!=y){
			int val=merge(zz[i],x);
			v.push_back(size1[zz[i]]-sd[x]*size2[zz[i]]-val);
			sum+=val;
		}
	for (int i=0;i<v.size();i++)num+=v[i],Max=max(Max,v[i]);
	num-=Max;
	if (Max>num)return num*2+sum;
	else return sum+num+Max-(num+Max)%2;
}
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		jb(x,y);jb(y,x);
	}
	int ans=1e9;
	for (int i=1;i<=n;i++){
		dfs(i,0,0);
		int sum=0,Max=0;
		for (int j=fi[i];j;j=ne[j]){
			sum+=size1[zz[j]];
			if (size1[zz[j]]>size1[Max])Max=zz[j];
		}
		if (sum&1)continue;
		int v1=sum-size1[Max],v2=size1[Max];
		v2-=merge(Max,i);
		if (v1<v2)continue;
		ans=min(ans,sum/2);
	}
	if (ans==1e9)puts("-1");
	else printf("%d\n",ans);
}

Measured memory_bytes: 512
def dis_pair(arr1,n):
    dict1={}
    for i in arr1:
        if i in dict1:
            return "NO"
        else:
            dict1[i]=1
    return "YES"
n=int(input())
arr1=list(map(int,input().strip().split()))[:n]
print(dis_pair(arr1,n))

Measured memory_bytes: 33076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  int N,C;
  cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C));
  vector<vector<int>> c(N, vector<int>(N));
  vector<vector<int>> cell(3);
  repr(i, C, 0) {
    repr(j, C, 0) {
      cin >> D[i][j];
    }
  }
  repr(i, N, 0) {
    repr(j, N, 0) {
      int x=j+1,y=i+1;
      cin >> c[i][j];
      c[i][j]--;
      cell[(x+y)%3].push_back(c[i][j]);
    }
  }
  vector<vector<int>> cost(3, vector<int>(C,0));

  for (int i = 0; i < C; ++i) {
    for (auto itr : cell[0]) { cost[0][i] += D[itr][i]; }
    for (auto itr : cell[1]) { cost[1][i] += D[itr][i]; }
    for (auto itr : cell[2]) { cost[2][i] += D[itr][i]; }
  }

  int ans = numeric_limits<int>::max();
  // 塗り替える色を全探索
  for (int i = 0; i < C; ++i) {
    for (int j = 0; j < C; ++j) {
      if (i == j) continue;
      for (int k = 0; k < C; ++k) {
        int temp = 0;
        if (i == k || j == k) continue;
        temp += cost[0][i];
        temp += cost[1][j];
        temp += cost[2][k];

        chmin(ans, temp);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 5360
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int N; cin >> N;
    int A[1010][1010];
    for(int i=0; i<N; i++){
        for(int j=0; j<N-1; j++){
            int a; cin >> a;
            a--;
            A[i][j] = a;
        }
    }
    
    int cur[1010];
    for(int i=0; i<1010; i++) cur[i]=0;

    
    int cnt = 0;
    while(1){
        
        
        bool nopair = true;

        int used[1010] = {};

        for(int i=0; i<N; i++){
            if(cur[i]==N-1) continue;
            int aite = A[i][cur[i]];
            
            if(used[i] || used[aite]) continue;
            if(i==A[aite][cur[aite]]){
                cur[i]++;
                cur[aite]++;
                used[i] = true;
                used[aite] = true;
                nopair = false;
            }
        }
        
        
        if(nopair){
            cout << -1 << endl;
            return 0;
        }
        
        cnt++;
        
        bool allend = true;
        for(int i=0; i<N; i++){
            if(cur[i]!=N-1) allend = false;
        }
        
        
        if(allend){
            cout << cnt << endl;
            return 0;
        }
        
    }
    
    return 0;
}



Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	map<int, int> mp;
	int dec = 0;
	int n, k, q, x;
	cin>>n>>k>>q;
	REP(i,q)
	{
		cin>>x;
		mp[x]++;
		dec++;
	}
	for(int i=1; i<=n;i++)
	{
		if(k-dec+mp[i]>0)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 8300
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = list(ns())
n = len(s)
k = ni()

for i in range(n):
    if s[i] != 'a':
        if ord('z') + 1 - ord(s[i]) <= k:
            k -= ord('z') + 1 - ord(s[i])
            s[i] = 'a'

if k >= 1:
    s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))

print(*s, sep="")

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

using namespace std;

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

    long long int x;
    cin >> x;

    long long int k = 1;
    while((x*k) % 360 != 0)
        k++;
        
    cout << k << endl;
    
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastio;
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}

Measured memory_bytes: 3616
N, K = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]
E = [(p + 1)/2 for p in P]
sumE = sum(E[0:K])
ans = sumE
for i in range(1, N-K+1):
    sumE = sumE - E[i-1] + E[i+K-1]
    ans = max(ans, sumE)
print(ans)



Measured memory_bytes: 25188
s=input()
t=input()
S=len(s)
T=len(t)
ans=[[0 for e in range(S+1)] for f in range(T+1)]
chk=[]
for a in range(1,T+1):
 for b in range(1,S+1):
  if t[a-1]==s[b-1]:
   ans[a][b]=ans[a-1][b-1]+1
  else:
   if ans[a-1][b]>ans[a][b-1]:
    ans[a][b]=ans[a-1][b]
   else:
    ans[a][b]=ans[a][b-1]
x,y=T,S
while x>0 and y>0:
 if ans[x][y]==ans[x-1][y]:
  x-=1
 elif ans[x][y]==ans[x][y-1]:
  y-=1
 else:
  x-=1
  y-=1
  chk.append(s[y])
chk.reverse()
print("".join(chk))    

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    for(int i=0; i<N; i++) cin >> x[i];

    int ans = 1000000000;
    for(int i=0; i<=N-K; i++){
        ans = min(ans, abs(x[i]) + abs(x[i+K-1]-x[i]));
        ans = min(ans, abs(x[i+K-1]) + abs(x[i+K-1]-x[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
using namespace std;

typedef long long ll;
int modulo = 1000000007; // 10^9 + 7

int main() {
	int N, K; cin >> N >> K;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v.begin(), v.end());
	int ans = v[N - 1];
	for (int i = 0; i < N + 1 - K; i++) {
		ans = min(ans, v[K + i - 1] - v[i]);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>>babo(n, vector<int>(2,1));
	babo.at(0).at(1) = 0;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y , x--, y--;
		babo.at(x).at(0)--;
		babo.at(y).at(0)++;
		if (babo.at(x).at(1) == 0)babo.at(y).at(1) = 0;
		if (babo.at(x).at(0) == 0)babo.at(x).at(1) = 1;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (babo.at(i).at(1) == 0)ans++;
	}
	cout << ans << endl;

}

Measured memory_bytes: 5760
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
int main()
{
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=s.length(); 
	vector<string> a;
	rep(l,n) for(int r=l+1;r<=n&&r-l<=5;r++)
		a.pb(s.substr(l,r-l));
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	cout<<a[k-1]<<endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
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 nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  string S;
  cin >> S;

  auto sa = atcoder::suffix_array(S);
  auto lcp = atcoder::lcp_array(S, sa);

  const ll N = S.size();
  ll ans = N * (N+1) / 2;
  REP(i, lcp.size()) {
    ans -= lcp[i];
  }
  cout << ans << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 15636
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  int n;
  cin >> n;
  VI a(n);
  VI b(n);
  rep(i,n){
      cin >> a.at(i);
      b.at(i)=a.at(i);
  }
  sort(b.begin(),b.end());
  rep(i,n){
      if(a.at(i)==b.at(n-1)){
          cout << b.at(n-2) << endl;
      }
      else{
          cout << b.at(n-1) << endl;
      }
  }
}

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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
using pdd = pair<Double, Double>;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

const int maxn = 1E3 + 10;

struct Circle {
	Double x, y, r;
};

Double dist(Circle a, Circle b) {
	Double d1 = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
	Double d2 = d1 - a.r - b.r;
	return max((Double)0, d2);
}

Double dis[maxn][maxn];
vector<Double> minDist(maxn, 1E20);
bool vis[maxn];
prior<pair<Double, int>> nxt;

void dijk(int now, int goal) {
	for (int i = 1; i <= goal; ++i) {
		if (!vis[i]) {
			minDist[i] = min(minDist[i], minDist[now] + dis[now][i]);
			nxt.push({minDist[now] + dis[now][i], i});
		}
	}

	while (!nxt.empty()) {
		if (vis[nxt.top().Y]) {
			nxt.pop();
			continue;
		}

		vis[nxt.top().Y] = 1;
		dijk(nxt.top().Y, goal);
		break;
	}
}

void solve() {
	Double xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int n;
	cin >> n;

	vector<Circle> cir(n + 2);
	cir[  0  ].x = xs, cir[  0  ].y = ys, cir[  0  ].r = 0.0;
	cir[n + 1].x = xt, cir[n + 1].y = yt, cir[n + 1].r = 0.0;
	for (int i = 1; i <= n; ++i) {
		cin >> cir[i].x >> cir[i].y >> cir[i].r;
	}

	memset(dis, 0, sizeof(dis));
	for (int i = 0; i <= n+1; ++i) {
		for (int j = i+1; j <= n+1; ++j) {
			dis[i][j] = dist(cir[i], cir[j]);
			dis[j][i] = dis[i][j];
		}
	}

	/// run dijkstra from 0 to n+1 ///
	minDist[0] = 0.0; vis[0] = 1;
	dijk(0, n + 1);

	cout << fixed << setprecision(10) << minDist[n + 1] << "\n";
}

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

Measured memory_bytes: 34796
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 

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


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

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

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

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

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int q;
    cin >> q;
    rep(i ,q) {
        string s,s2;
        cin >> s >> s2;
        int dp[1100][1100] = {0};
        rep(i, sz(s)){
          rep(j, sz(s2)){
              if(s[i] == s2[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
              chmax(dp[i + 1][j + 1], dp[i + 1][j]);
              chmax(dp[i + 1][j + 1], dp[i][j + 1]);
          }
        }
        print(dp[sz(s)][sz(s2)]);
    }
}




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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define inf (int)(1e9)
#define INF 1.1529215e+18
#define MAXX 999999
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/
const int MAX_N=1000001;
int main(){
    int n;cin>>n;
    V dp(MAX_N,MAXX);
    dp[0]=0;
    REP(i,n){
        for(int j=1;i-j>=0;j*=6)dp[i]=min(dp[i],dp[i-j]+1);
        for(int k=1;i-k>=0;k*=9)dp[i]=min(dp[i],dp[i-k]+1);
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 4096
//  q2.cpp(2014/10/12-)


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    int n,m,max,max_n,b,a[2][1000]={0};
    
    scanf("%d %d",&n,&m);
    
    for(int i=0;i<n;i++)
        scanf("%d",&a[0][i]);
    
    for(int i=0;i<m;i++){
        scanf("%d",&b);
        for(int j=0;j<n;j++){
            if(a[0][j]<=b){
                a[1][j]++;
                break;
            }
        }
    }
    
    max=0;
    for(int i=0;i<m;i++){
        if(max<a[1][i]){
            max=a[1][i];
            max_n=i;
        }
    }
    printf("%d\n",max_n+1);
    
    return 0;
}

Measured memory_bytes: 1032
import java.util.*;
//import java.util.stream.Collectors;

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 d = Integer.parseInt(sc.next());
		int result = a < b ? a : b;
		result += c < d ? c : d;
		System.out.println(result);
	}
}


Measured memory_bytes: 35752
#include<stdio.h>
#include<string.h>




char s1[2000];
char s2[2000];


int LCS(int length1, int length2){

  int i,j,a;
  int ans[1001][1001];

  a = 0;

  for(i = 0; i < length1; i++){
    ans[i][0] = 0;
  }

  for(i = 0; i < length2; i++){
    ans[0][i] = 0;
  }



  for(i = 0; i < length1; i++){
    for(j = 0; j < length2; j++){
      if(s1[i]==s2[j] && s1[i]!=' ' && s2[i] != ' '){
        if(i == 0 || j == 0){
          ans[i][j] = 1;
        }
        else{
          ans[i][j] = ans[i-1][j-1]+1  ;
        }
      }

      else{
        if(i == 0 && j != 0){
          ans[i][j] = ans[0][j-1];
        }
        else if(i !=0 && j == 0){
          ans[i][j] = ans[i-1][0];
        }
        else if(i == 0 && j == 0){
          ans[0][0] = 0;
        }
        else if(i != 0 && ans[i-1][j] > ans[i][j-1]){
          ans[i][j] = ans[i-1][j];
        }
        else if(ans[i-1][j] <= ans[i][j-1]){
          ans[i][j] = ans[i][j-1];
        }
      }
    }
  }
  return ans[length1-1][length2-1];
}

int main(){
  int sumstring;
  int i,j,k;
  scanf("%d",&sumstring);

  for(i = 0; i < sumstring; i++){
    scanf("%s",s1);
    scanf("%s",s2);
    printf("%d\n",LCS(strlen(s1),strlen(s2)));
  }

  return 0;
}



Measured memory_bytes: 5684
#include <bits/stdc++.h>  // ver2.3.1
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define PI 3.141592653589793238462
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  
  reverse(ALL(s));
  Vi ans(0);
  
  int minn = 0,now;
  
  while(now < n-m) {
    repreq(j,now+m,now+1){
      if(s[j] == '0') {
        ans.pb(j-now);
        now = j;
        minn++;
      }
      if(j==now+1){cout << -1 << endl;return 0;}
    }
  }
  ans.pb(n-now);
  minn++;
  //cerr << minn << endl;
  reverse(ALL(ans));
  Vout(ans);
  
  return 0;
}

Measured memory_bytes: 1480
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
query = [getList() for i in range(N - 1)]

dist = [[] for i in range(N)]
for i in range(N - 1):
    a, b = query[i]
    dist[a - 1].append(b - 1)
    dist[b - 1].append(a - 1)

# nowからNまでのルート
def router(n, sta, end):
    pos = deque([sta])
    ignore = [0] * n
    path = [0] * n
    path[sta] = -1

    while pos[0] != end:
        u = pos.popleft()
        ignore[u] = 1

        for i in dist[u]:
            if ignore[i] != 1:
                path[i] = u
                pos.append(i)

    route = deque([end])
    while True:
        next = path[route[0]]
        route.appendleft(next)
        if route[0] == sta:
            break

    return list(route)

route = router(N, 0, N - 1)

# NG以外のところで辿れるところの数
def dfs_ter(sta, ng):
    pos = deque([sta])

    ignore = [0] * N
    for i in ng:
        ignore[i] = 1

    cnt = 0
    while len(pos) > 0:
        u = pos.popleft()
        ignore[u] = 1
        cnt += 1
        for i in dist[u]:
            if ignore[i] != 1:
                pos.append(i)

    return cnt

L = len(route)
fen_ter = route[:(L + 2 - 1) // 2]
snu_ter = route[(L + 2 - 1) // 2:]

fen_ans = dfs_ter(0, snu_ter)

if fen_ans > N - fen_ans:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 114864
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
  int a, b, c, k;

  cin >> a >> b >> c >> k;

  if (k <= a )
    cout << k;
  else if (k <= a + b)
  {
    cout << a;
  }

  else
  {
    int num;
    num = k - (a + b) ;
    cout << a - num;
  }

}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class357
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var S = new long[N];
            var E = new long[N];
            for(int i = 0; i < N; i++)
            {
                var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
                S[i] = r[0] - r[1];
                E[i] = r[0] + r[1];
            }
            Array.Sort(E, S);

            int count = 0;
            long last = int.MinValue;
            for(int i = 0; i < N; i++)
            {
                if (S[i] >= last)
                {
                    count++;
                    last = E[i];
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 19000
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(10);
	ll x,y,k;
	cin>>k>>x>>y;
	ll ans=0;
	for(int a=x;a<=y;a++)
	{
		if(a%k==0)
		{
			ans=1;
			break;
		}
	}
	if(ans==1)
	cout<<"OK";
	else
	cout<<"NG";
	return 0;
}

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

const int INF = 1001001001;

void warshall_floyd(int n, vector<vector<int> > &D) {
  rep(k,n) rep(i,n) rep(j,n) {
    D[i][j] = min(D[i][j], D[i][k]+D[k][j]);
  }
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int> > c(10, vector<int>(10));
  rep(i,10)rep(j,10) cin >> c[i][j];
  warshall_floyd(10, c);
  vector<vector<int> > A(H, vector<int>(W));
  int ans = 0;
  rep(i,H)rep(j,W) {
    int a;
    cin >> a;
    A[i][j] = a;
    if (a > -1) ans += c[a][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
// ABC109_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

template <typename T>
T gcd(T a, T b) {
    if (a <= 0 || b <= 0) {
        // どちらかが 0 以下であれば -1 を返す
        return -1;
    } else if (a == 1 || b == 1) {
        // どちらかが 1 であれば，最小公約数は 1
        return 1;
    } else {
        if (a < b) swap(a, b);
        if (a%b == 0) return b;
        return gcd(b, a%b);
    }
}

int main() {
    // input
    ll N, X;
    cin >> N >> X;
    vector<ll> vec(N);
    REP(i, N) cin >> vec[i];
    sort(vec.begin(), vec.end());
    
    // calculation
    if (N == 1) {
        cout << abs(X - vec[0]) << "\n";
    } else {
        auto iter = lower_bound(vec.begin(), vec.end(), X);
        vec.insert(vec.begin()+IDX(vec, iter), X);
    
        vector<ll> diff(N);
        for (ll i = 0; i < N; ++i) {
            diff[i] = vec[i+1] - vec[i];
        }
        
        // diff の最大公約数をとる
        
        ll res = gcd(diff[1], diff[0]);
        for (ll i = 1; i < N; ++i) {
            res = gcd(diff[i], res);
        }
        
        cout << res << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

int q;
int main() {
	cin >> q;
	for (int i = 0; i < q; i++) {
		string x, y;
		cin >> x >> y;
		int m = x.size();
		int n = y.size();
		x = ' ' + x;
		y = ' ' + y;
		int maxl = 0;
		int c[1001][1001] = {};
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				if (x[i] == y[j]) {
					c[i][j] = c[i-1][j-1] + 1;
				} else {
					c[i][j] = max(c[i][j - 1], c[i - 1][j]);
				}
			}
		}
		cout << c[m][n] << endl;
	}
	return 0;
}

Measured memory_bytes: 5132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const ll mod = 1000000007;

ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret*=x) %= mod;
        (x*=x) %= mod;
        n>>=1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x,mod-2);
}

const int F = 200010;
ll f[F], invf[F];
ll C(int n, int r){
    ll ret = f[n];
    (ret *= invf[r]) %= mod;
    (ret *= invf[n-r]) %= mod;
    return ret;
}

const int N = 3003;
ll dp[N][2];

int main(){
    f[0] = 1;
    for(int i=1; i<F; ++i) f[i] = (f[i-1]*i)%mod;

    invf[F-1] = mod_inv(f[F-1]);
    for(int i=F-2; i>=0; --i) invf[i] = (invf[i+1]*(i+1))%mod;

    int h,w,n;
    cin >>h >>w >>n;

    vector<pi> b(n);
    rep(i,n){
        int r,c;
        cin >>r >>c;
        b[i] = {r-1, c-1};
    }
    b.pb({0,0});
    b.pb({h-1,w-1});
    sort(all(b));

    auto ok = [&](int from, int to){
        pi p = b[from], q = b[to];
        return p.fi<=q.fi && p.se<=q.se;
    };

    n += 2;
    dp[0][1] = 1;
    rep(i,n)rep(j,2)if(dp[i][j]){
        for(int k=i+1; k<n; ++k)if(ok(i,k)){
            int r = b[k].fi - b[i].fi;
            int c = b[k].se - b[i].se;
            (dp[k][!j] += dp[i][j]*C(r+c,r)) %= mod;
        }
    }

    ll ans = (dp[n-1][0] - dp[n-1][1] + mod) % mod;
    cout << ans << endl;
    return 0;
}


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

ll h,n;
ll a[1111];
ll b[1111];

int main(){
    cin >> h >> n;
    for(ll i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    vector<ll> dp(h+1,1e9);
    dp[0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=h;j++){
            if(j-a[i]<=0) dp[j]=min(dp[j],b[i]);
            else if(j-a[i]>0) dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    cout << dp[h] << endl;
    return 0;
}  


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <cstring>
#include <ctype.h>
#include<stdlib.h>

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;
int gcd(int x,int y)
{        
    return x ? gcd(y%x,x) : y;   
}  

int findGCD(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
}
int main()
{
    fastio;
    int n,k;
    cin>>n>>k;
    int a[n];
    
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
       
    }


    int g=findGCD(a,n);
    if(n==1 and k==a[0])cout<<"POSSIBLE\n";
    else if(k%g==0 and k<=*max_element(a,a+n))cout<<"POSSIBLE\n";
    else cout<<"IMPOSSIBLE\n";
    // cout<<g<<nl<<k<<nl<<*max_element(a,a+n)<<nl;
    bdyptb;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(ll i=ll(x);i<(ll)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7 
#define LONFINF 1e16
using ll = long long;
using P = pair<ll, ll>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll>x, y;
    y.push_back(0);
    rep(i, n) {
        ll a;
        cin >> a;
        if (a < 0)x.push_back(-a);
        else y.push_back(a);
    }

    x.push_back(0);//bannpei
    sort(x.begin(), x.end());
    int ms = min(k, (ll)y.size()-1);
    ll ans = LONFINF;
    for (int i = ms; i >= 0; i--) {
        if (k - i >= x.size())break;
        ans = min(ans, 2*y[i] + x[k - i]);
        ans = min(ans, 2 * x[k - i] + y[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1656
#include <cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<sstream>     
#include<map>
#include<iomanip>
#include<cctype>
#include<vector>
#include<set>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	string s1 = "ABC", s2 = "ARC", s3 = "AGC";
	int rank;
	while (cin>>rank)
	{
		if (rank < 1200)
			cout << s1 << endl;
		else if (rank < 2800)
			cout << s2 << endl;
		else
			cout << s3 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC156A - Beginner

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int r = sc.nextInt();

        int rate = (n >= 10) ? r : r + (100 * (10 - n));

        System.out.println(rate);
    }
}

Measured memory_bytes: 22608
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  if(s.at(0)==t.at(2)&&s.at(1)==t.at(1)&&s.at(2)==t.at(0)){cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
}

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

int main() {
  string s;
  cin >> s;
  int w;
  cin >> w;
  for(int i = 0; i < (int) s.size(); i += w) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, a: "List[int]"):

    target = int(round(sum(a)/N))

    s = 0
    for aa in a:
        s += (target-aa)**2
    print(s)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

int main() {
    int n;
    cin >> n;
    vll nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    vll t1;
    vll t2;
    ll ans = 0;
    t1.push_back(nums[0]);
    t2.push_back(nums[0]);
    int l = 1;
    int r = nums.size() - 1;
    bool right = true;
    while (l <= r) {
        if (right) {
            if (t1.size() == t2.size() && l == r) {
                if (t1.back() < t2.back()) {
                    t1.push_back(nums[r--]);
                } else {
                    t2.push_back(nums[r--]);
                }
            } else {
                t1.push_back(nums[r--]);
                t2.push_back(nums[r--]);
            }
            right = false;
        } else {
            if (t1.size() == t2.size() && l == r) {
                if (t1.back() > t2.back()) {
                    t1.push_back(nums[l++]);
                } else {
                    t2.push_back(nums[l++]);
                }
            } else {
                t1.push_back(nums[l++]);
                t2.push_back(nums[l++]);
            }
            right = true;
        }
    }
    for (int i = 0; i < t1.size() - 1; ++i) {
        ans += abs(t1[i] - t1[i + 1]);
    }
    for (int i = 0; i < t2.size() - 1; ++i) {
        ans += abs(t2[i] - t2[i + 1]);
    }
    reverse(nums.begin(), nums.end());
    ll ans1 = 0;
    t1.clear();
    t2.clear();
    t1.push_back(nums[0]);
    t2.push_back(nums[0]);
    l = 1;
    r = nums.size() - 1;
    right = true;
    while (l <= r) {
        if (right) {
            if (t1.size() == t2.size() && l == r) {
                if (t1.back() > t2.back()) {
                    t1.push_back(nums[r--]);
                } else {
                    t2.push_back(nums[r--]);
                }
            } else {
                t1.push_back(nums[r--]);
                t2.push_back(nums[r--]);
            }
            right = false;
        } else {
            if (t1.size() == t2.size() && l == r) {
                if (t1.back() < t2.back()) {
                    t1.push_back(nums[l++]);
                } else {
                    t2.push_back(nums[l++]);
                }
            } else {
                t1.push_back(nums[l++]);
                t2.push_back(nums[l++]);
            }
            right = true;
        }
    }
    for (int i = 0; i < t1.size() - 1; ++i) {
        ans1 += abs(t1[i] - t1[i + 1]);
    }
    for (int i = 0; i < t2.size() - 1; ++i) {
        ans1 += abs(t2[i] - t2[i + 1]);
    }
    ans = max(ans, ans1);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 2044
s=input()
a=int(s[:2])
b=int(s[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= a <= 12:
    print("MMYY")
elif 1 <= b <= 12:
    print("YYMM")
else:
    print("NA") 

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array

int main() {
	int n;
	cin >> n;
	ll a[n];
	for (int i=0; i<n; i++) cin >> a[i];
	ll left[n+1]={}, ans=0;
	for (int i=0; i<n; i++) {
		if (left[i]>a[i]) ans+=left[i]-a[i];
		left[i+1]=max(left[i], a[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, A, B;
	cin >> n >> A >> B;
	string s;
	cin >> s;
	int a = 0, b = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'a') {
			if (a + b < A + B) {
				cout << "Yes" << endl;
				++a;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b') {
			if (a + b < A + B && b < B) {
				cout << "Yes" << endl;
				++b;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Exercise1
    {
        static int a = 0;
        static int b = 0;
        static int c = 0;
        static int xx = 0;
        static int yy = 0;
        static void Main()
        {
            String input = Console.ReadLine();
            try
            {
                a = Int32.Parse(input.Split(' ')[0]);
                b = Int32.Parse(input.Split(' ')[1]);
                c = Int32.Parse(input.Split(' ')[2]);
                xx = Int32.Parse(input.Split(' ')[3]);
                yy = Int32.Parse(input.Split(' ')[4]);
            }
            catch (Exception)
            {
                Console.ReadLine();
                return;
            }
            
            bool shouldAB = (a + b) > 2 * c;
            bool shouldBuyA = a < c * 2;
            bool shouldBuyB = b < c * 2;
            int result = 0;
            if (!shouldAB)
            {
                result = xx * a + yy * b;
            } else
            {
                if (xx > yy)
                {
                    result = 2 * c * yy;
                    if (shouldBuyA)
                    {
                        result += (xx - yy) * a;
                    } else
                    {
                        result += (xx - yy) * 2 * c;
                    }
                } else
                {
                    result = 2 * c * xx;
                    if (shouldBuyB)
                    {
                        result += (yy - xx) * b;
                    }
                    else
                    {
                        result += (yy - xx) * 2 * c;
                    }
                }
                
            }
            Console.WriteLine(result);
            Console.ReadLine();
        }
    }

Measured memory_bytes: 11220
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ary = new int[n];
        long sum = 0;
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
            sum+=ary[i];
        }
        
        Arrays.sort(ary);
        long a = ary[n-m]*4*m;
        if(a<sum){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }

    }    
    
}







Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint bik[400001];
mint comb(int a, int b){
	return bik[a] / bik[b] / bik[a-b];
}
mint p[200001];

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

	bik[0]=1;
	for(int i=1; i<2*n+1; i++) bik[i]=bik[i-1]*i;

	if(k>n) k=n;

	mint ans=0;
	for(int z=0; z<=k; z++){
		int r=n-z;
		int sep=r-1;
		int tama=n-(sep+1);
		ans+= comb(sep+tama, tama)* comb(n, z);
	}

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


Measured memory_bytes: 8328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    vector<ll> memo(n);
    for(int i = 0; i < n; i++) memo[i] = (ll)x[i]+y[i];
    sort(memo.begin(), memo.end());
    ll ans =  abs(memo[n-1]-memo[0]);
    for(int i = 0; i < n; i++) memo[i] = (ll)x[i]-y[i];
    sort(memo.begin(), memo.end());
    if(ans < abs(memo[n-1]-memo[0])) ans = abs(memo[n-1]-memo[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6412
#!/usr/bin/env python3
import sys
n=int(input())
a=list(map(int,input().split()))
ans=1
 
for i in range(n):
    if a[i]==0:
        print(0)
        sys.exit()

for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        sys.exit()
 
print(ans)


Measured memory_bytes: 84676
#include "iostream"
using namespace std;

int del(int a, int b)
{
	if (b == 0 || a==0) return a;
	else return del(b,a%b);
}

int main()
{
	int a, b;
	cin >> a >> b;
	if (a > b)
	{
		int s = a;
		a = b;
		b = s;
	}
	cout << del(a, b)<<endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, s = 0;
  cin >> n;
  vector<ll> a(n);

  rep(i, n) cin >> a[i], s ^= a[i];
  rep(i, n) cout << (a[i] ^ s) << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 4824
import sys
x = int(input())

for i in range(1000):
    for j in range(1000):
        if i**5 + j**5 ==x:
            print(i,end=" ")
            print(-j)
            sys.exit()

        if i**5 - j**5 ==x:
            print(i,end=" ")
            print(j)
            sys.exit()

Measured memory_bytes: 9192