akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[200010], pr[200010], mem[200010][2], n;
ll dp(int x, int l){
    if(x==0)
        return 0;
    if(mem[x][l]!=-1)
        return mem[x][l];
    ll res=0;
    if(l){
        if(a[x]%2){
            res=min(1+pr[x-1], 1+dp(x-1, 1));
        }
        else if(a[x]==0){
            res=min(pr[x], 2+dp(x-1, 1));
        }
        else{
            res=min(pr[x-1], dp(x-1, 1));
        }
    }
    else{
        if(a[x]%2){
            res=dp(x-1, 0);
        }
        else if(a[x]==0){
            res=min(dp(x-1, 0)+1, pr[x]);
        }
        else{
            res=min(pr[x-1], min(dp(x-1, 0)+1, dp(x-1, 1)));
        }
    }
    mem[x][l]=res;
    return res;
}
ll mem2[200010][2], sf[200010];
ll dp2(int x, int l){
    if(x==n+1){
        return 0;
    }
    if(mem2[x][l]!=-1)
        return mem2[x][l];
    ll res;
    if(l){
        if(a[x]==0){
            res=2+min(sf[x+1], dp2(x+1, 1));
        }
        else if(a[x]%2==0){
            res=min(sf[x+1], dp2(x+1, 1));
        }
        else{
            res=min(sf[x+1]+1, 1+dp2(x+1, 1));
        }
    }
    else{
        if(a[x]%2){
            res=min(sf[x+1], min(dp2(x+1, 1),dp2(x+1, 0)));
        }
        else if(a[x]==0){
            res=min(1+min(dp2(x+1, 0), dp2(x+1, 1)), sf[x+1]+1);
        }
        else{
            res=min(sf[x+1], min(dp2(x+1, 0)+1, dp2(x+1, 1)));
        }
    }
    mem2[x][l]=res;
//    cout<<x<<" "<<l<<"::::"<<res<<endl;
    return res;
}
 
int main(){
    while(cin>>n){
        ll ans=0;
        for(int i=1; i<=n; ++i){
            scanf("%lld",a+i);
        }
        for(int i=1; i<=n; ++i){
            pr[i]=pr[i-1]+a[i];
        }
        sf[n+1]=0;
        for(int i=n; i>=0; --i){
            sf[i]=sf[i+1]+a[i];
        }
        memset(mem, -1, sizeof mem);
        memset(mem2, -1, sizeof mem2);
        ans=1e17;
        ll tmp=0;
        for(int i=n; i>=0; --i){
 
            ans=min(ans, tmp+dp(i, 0));
          if(a[i]==0){tmp=min(tmp+2,sf[i]);}
          else
            tmp+=a[i]%2;
        }
        tmp=0;
        for(int i=0; i<=n; ++i){
            ++a[i];
            mem2[i][0]=mem2[i][1]=-1;
            ans=min(ans, tmp+min(dp2(i, 1), dp2(i, 0)));
//            cout<<dp2(i, 1)<<" "<<dp2(i, 0)<<endl;
//cout<<"******"<<endl;
            --a[i];
            tmp+=a[i];
        }
        cout<<ans<<endl;
    }
  return 0;
}


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

int main(){
    string s; cin >> s;
    
    int result=0;
    int n=(int)(s.length());
    
    for(int i=0;i<n;i++){
        int cnt=0;
        if(s[i]!='A'&&s[i]!='T'&&s[i]!='C'&&s[i]!='G')continue;
        for(int j=i;j<n;j++){
             if(s[j]!='A'&&s[j]!='T'&&s[j]!='C'&&s[j]!='G') break;
             else cnt++;
        }
        result=max(result,cnt);
    }
    
    cout<<result<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n, y;
    cin >> n >> y;
    y /= 1000;
    for (int a = 0, d; d=y-n-9*a, d>=0; ++a) {
        if (d%4==0) {
            int b = d/4;
            int c = n-a-b;
            if (c < 0) continue;
            cout << a << " " << d/4 << " " << c << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
S = list(str(input()))

if int(S[0]+S[1]) > 12 and int(S[2]+S[3]) > 12: 
    print("NA")
elif int(S[0]+S[1]) > 12 and int(S[2]+S[3]) == 0:
    print("NA")
elif int(S[0]+S[1]) == 0 and int(S[2]+S[3]) > 12:
    print("NA")
elif int(S[0]+S[1]) == 0 and int(S[2]+S[3]) == 0:
    print("NA")
elif int(S[0]+S[1]) > 12 or int(S[0]+S[1]) == 0 :
    print("YYMM")
elif int(S[2]+S[3]) > 12 or int(S[2]+S[3]) == 0:
    print("MMYY")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
import math

def main():
    l,r=map(int,input().split())
    m = 2020
    for i in range(l, r):
        for j in range(i+1, r+1):
            n = (i*j) % 2019
            m = min(m, n)
            if m == 0:
                print(m)
                return
    print(m)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

int main(){
    int n,k;

    cin >> n;
    cin >> k;

    vector<int> v(n);
    vector<int> dp(n, INT_MAX);

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

    dp[0] = 0;
    for(int i = 1;i<n;i++){
        for(int j = 1;j <= k && i-j>=0;j++){
            dp[i] = min(dp[i-j] + abs(v[i] - v[i-j]), dp[i]);
        }
    }

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

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string N;cin>>N;
  ll ans=0, l=N.length();
  lvector v(l+1,0);
  rep(i,l) v[i+1]=N[i]-'0';
  rep(i,l+1) {
    ll pos=l-i;
    if(v[pos]<5) ans+=v[pos];
    else if(pos-1>=0){
      ll pattern1=10-v[pos]+min(v[pos-1]+1ll,10ll-(v[pos-1]+1ll));
      ll pattern2=v[pos]+min(v[pos-1],10ll-v[pos-1]);
      if(pattern1<=pattern2) {
        ans+=10-v[pos];
        v[pos-1]+=1;
      }
      else {
        ans+=v[pos];
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 9244
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef vector<LL> VL;

int main() {
	string s, t;
	cin >> s >> t;

	VI x(29, -1), y(29, -1);
	bool flag = true;
	rep(i, sz(s)) {
		int a = s[i] - 'a';
		int b = t[i] - 'a';
		if (x[a] != -1 || y[b] != -1)if (x[a] != b || y[b] != a)flag = false;
		x[a] = b, y[b] = a;
	}
	puts(flag ? "Yes" : "No");
}

Measured memory_bytes: 776
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int a,b,c;
  cin>>a>>b>>c;

  if((a==b && b==c)||(a!=b && b!=c && a!=c)){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }

}


Measured memory_bytes: 256
n = int(input())

pre_t, pre_x, pre_y = [0, 0, 0]
ok = True
for i in range(n):
  t, x, y = map(int, input().split())
  if (((t-pre_t) - (abs(x-pre_x) + abs(y-pre_y))) < 0
      or ((t-pre_t) - (abs(x-pre_x) + abs(y-pre_y))) % 2 != 0):
    ok = False
    break
  pre_t, pre_x, pre_y = [t, x, y]
  
if ok:
  print("Yes")
else:
  print("No")

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

using namespace std;
typedef long long ll;
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
const ll INF=1000000000000000;
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}

int main(){
	ll A,B; cin>>A>>B;
	if((A*B)%2==1) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

LL s[2002];
LL t[2002];
int n, m;

LL sum[2002][2002];
LL dp[2002][2002];

void init() {

}

void input() {
  cin >> n >> m;
  REP(i, n) cin >> s[i];
  REP(i, m) cin >> t[i];
}

void solve() {
  REP(i, n) REP(j, m) {
    if (i == 0 || j == 0) {
      if (s[i] == t[j]) {
        dp[i][j] = 1;
      } else {
        dp[i][j] = 0;
      }
      if (i > 0) sum[i][j] = dp[i][j] + sum[i-1][j];
      if (j > 0) sum[i][j] = dp[i][j] + sum[i][j-1];
      if (i == 0 && j == 0) sum[i][j] = dp[i][j] + 1;
    } else {
      if (s[i] == t[j]) dp[i][j] = sum[i-1][j-1];
      else dp[i][j] = 0;
      sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + dp[i][j] + 1000000007) % 1000000007;
    }
    // OUT2(i, j);
    // OUT2(dp[i][j], sum[i][j]);
  }
  cout << (sum[n-1][m-1]) % 1000000007 << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 62848
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define all(v)          v.begin(),v.end()

#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

// inline int setBit(int n,int pos) { return n = n | (1 << pos); }
// inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
// inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }

// int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
// int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// unsigned int num = rng();
// shuffle(V.begin(), V.end(), rng);

/******************************************************************************************/

//const int MAX = 500010;
//const int INF = 0x3f3f3f3f;
//const int MOD = 1000000007;


//inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
//inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
//inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }


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

   	/*#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin); 
	// freopen("out", "w", stdout);
	clock_t st = clock();
	#endif*/

	ll x;
	cin >> x;

	ll ans = 0;
	ans += 1000LL * (x / 500);
	x %= 500;
	ans += 5LL * (x / 5LL);

	cout << ans << endl;


	/*#ifndef ONLINE_JUDGE
    cerr << "\nTime taken: " << setprecision(5) << fixed << (clock() - st * 1.0) / CLOCKS_PER_SEC;
    #endif*/
    return 0;
}


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

using namespace std;


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

    vector<long long> x(n), y(n);
    for (int i=0; i<n; i++) {
        cin >> x.at(i) >> y.at(i);
    }

    for (int i=0; i<n-1; i++) {
        for (int j=i+1; j<n; j++) {
            sum += sqrt( pow( x.at(j) - x.at(i), 2) + pow( y.at(j) - y.at(i), 2));
        }
    }
    
    printf("%.10f\n", sum * 2 / n);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
    int x,y,d,step,k;
    node(int x=0,int y=0,int d=0,int step=0,int k=0):
    x(x),y(y),d(d),step(step),k(k){}
    bool operator<(const node&o)const
    {
        if(step!=o.step) return step>o.step;
        return k<o.k;
    }
};
int sx,sy,ex,ey;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int main()
{
    int h,w,k;scanf("%d%d%d",&h,&w,&k);
    scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
    char s[h+5][w+5];
    for(int i=1;i<=h;i++)
        scanf("%s",s[i]+1);
    int f[h+5][w+5][4],g[h+5][w+5][4];
    bool vis[h+5][w+5][4];
    memset(vis,false,sizeof(vis));
    memset(f,inf,sizeof(f));
    memset(g,0,sizeof(g));
    priority_queue<node>q;
    for(int i=0;i<4;i++)
    {
        f[sx][sy][i]=1;
        g[sx][sy][i]=k;
        q.push(node(sx,sy,i,1,k));
    }
    while(!q.empty())
    {
        int x=q.top().x,y=q.top().y,d=q.top().d;q.pop();
        if(vis[x][y][d]) continue;
        vis[x][y][d]=true;
        for(int i=0;i<4;i++)
        {
            int xx=x+dx[i];
            int yy=y+dy[i];
            if(xx<1||x>h||yy<1||yy>w||s[xx][yy]=='@') continue;
            int ff=f[x][y][d]+(i!=d);
            int gg=i==d?g[x][y][d]-1:k-1;
            if(gg==-1) ff++,gg=k-1;
            if(f[xx][yy][i]>ff||f[xx][yy][i]==ff&&g[xx][yy][i]<gg)
                f[xx][yy][i]=ff,g[xx][yy][i]=gg,q.push(node(xx,yy,i,ff,gg));
        }
    }
    int ans=inf;
    for(int i=0;i<4;i++) ans=min(ans,f[ex][ey][i]);
    if(ans==inf) ans=-1;
    printf("%d\n",ans);
}


Measured memory_bytes: 215716
n, y = gets.split.map(&:to_i)

cuty = y / 1000

for a in 0..n
  for b in 0..n
    next if (c = n - a - b)<0
    if ((10 * a) + (b * 5) + c)==cuty
        puts [a, b, c].join(" ")
        exit
    end
   end
end

puts "-1 -1 -1"


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

//13 min -> しゃくとり法
//60 min -> 実装とバグ取り
int main(){
  int n;cin >> n;
  vector<int> v;
  rep(i,n){
    int l; cin >> l;
    v.push_back(l);
  }
  v.push_back(0);
  v.resize(n+1);
  sort(v.begin(), v.end(), greater<int>());
  int dest=0;
  for(int i=0;i<n;i++){
    int edge=n;
    for(int j=i+1; j<n;j++){
      edge=max(edge, j+1);
      for(int k=edge;k>j;k--){
        if(v[i]<v[j]+v[k]/*&&v[j]<v[k]+v[i]&&v[k]<v[i]+v[j]*/){
          dest+=k-j;
          edge=k+1;
          break;
        }
      }
    }
  }
  cout << dest << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,d,e=0;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        if(500*i+100*j+50*k==d){e++;}
      }
    }
  }
  printf("%d",e);
  return 0;}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,c;cin>>n>>c;
    vector<pll> xv(n);
    vector<vector<ll> >memo(n+2,vector<ll>(6));
    rep(i,n){
        ll x,v;cin>>x>>v;
        xv[i]=mp(x,v);
    }
    ll ma1=0,ma2=0;
    ll cnt1=0,cnt2=0;
    ll k=0LL;
    rep(i,n){
        cnt1+=xv[i].second-(xv[i].first-k);
        ma1=max(ma1,cnt1);
        memo[i+1][0]=cnt1;
        memo[i+1][4]=ma1;
        memo[i+1][1]=xv[i].first;
        k=xv[i].first;
    }
    reverse(all(xv));
    k=0LL;
    rep(i,n){
        cnt2+=xv[i].second-(c-xv[i].first-k);
        ma2=max(ma2,cnt2);
        memo[n-i][2]=cnt2;
        memo[n-i][5]=ma2;
        memo[n-i][3]=c-xv[i].first;
        k=c-xv[i].first;
    }
    ll ma=0; 
    REP(i,1,n+1){
        ma=max(ma,max(max(memo[i][4],memo[i][0]-memo[i][1]+memo[i+1][5])
        ,max(memo[i][2]-memo[i][3]+memo[i-1][4],memo[i][5])));
    }
    cout<<ma<<endl;
}

Measured memory_bytes: 10368
# D
N = int(input())
A = list(map(int, input().split()))

counts = [0] * 20

res = 0
left = 0
right = 0

r = bin(A[right])
for i in range(len(r)-2):
    counts[i] += int(r[-(i+1)])

while left < N and right < N:
    if max(counts) >= 2:
        r = bin(A[left])
        for i in range(len(r)-2):
            counts[i] -= int(r[-(i+1)])
        left += 1
    else:
        res += right - left + 1
        # print(left, right)
        right += 1
        if right < N:
            r = bin(A[right])
            for i in range(len(r)-2):
                counts[i] += int(r[-(i+1)])

print(res)

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

int main()
{
    int n;
    map<int,int> add;
    vector<int> sub;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
        int temp;
        cin>>temp;
            add[temp+i]++;
            sub.push_back(i-temp);
    }
   long long int ans=0;
    for(int i=1;i<sub.size();i++)
        ans+=add[sub[i]];

    cout<<ans<<endl;
}


Measured memory_bytes: 20816
#include<iostream>
using namespace std;
 
int main(){
 
  int c[3][3], a[3], b[3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> c[i][j];
    }
  }
 
  a[0]=0;
 
  for(int i=0; i<3; i++){
    b[i]=c[0][i]-a[0];
  }
 
  for(int i=1; i<3; i++){
    a[i]=c[i][0]-b[0];
  }
 
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(c[i][j]!=a[i]+b[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
 
  cout << "Yes" << endl;
 
  return 0;
}

Measured memory_bytes: 256
n = int(input())
x = 0
ans = 0
for i in range(n):
    d0,d1 = map(int,input().split())
    if d0 == d1:
        x += 1
    else:
        x = 0
    
    if x == 3:
        ans = 1
        break
print(["No","Yes"][ans])

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

main(){
    ll n;
    cin >> n;
    ll x, y;
    cin >> x >> y;
    ll s = 0;
    for(ll i = 1;i  <= n-2; i++)
        {ll a; cin >> a; s ^= a;}

    if((x + y - s)%2 || x + y < s) {
        cout<<-1<<endl;
        return 0;
    }
    ll An = (x + y - s)/2;
    ll Or = (x + y + s)/2;
    if((An & Or) != An) {
        cout << -1 << endl;
        return 0;
    }
    ll U = 0, C = 0;
    vector<ll> v;
    for(ll i = 0; i < 50; i++){
        ll A =0,O=0;
        if((1ll <<i) & An) A = 1;
        if((1ll << i) & Or) O =1;
        if(!A && !O) continue;
        if(A && O) U += (1ll<<i); else
        C += (1ll << i),v.push_back(i);
    }
    if(U + C < y){
        cout << -1 << endl;
        return 0;
    }
    if(U >= y){
        if(U-y < x)
        cout << U-y<<endl;
    else cout<<-1<<endl;
        return 0;
    }

    y -= U;
    if((y & C) == y){
        cout << 0 << endl;
        return 0;
    }
    reverse(v.begin(),v.end());
    ll Z = 0;
    ll ans = C;
    for(ll i : v){
        if(Z + (1ll << i) >= y){
            ans = min(ans, Z + (1ll << i));
        }
        if((1ll << i) & y) Z += (1ll << i);
    }
    if(ans - y == x){
        cout << -1 << endl;
        return 0;

    }
    cout<<ans -y<<endl;

}


Measured memory_bytes: 3544
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a > b) {
      System.out.println(a - 1);
    }
    else {
      System.out.println(a);
    }
  }
}

Measured memory_bytes: 20820
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((b1[:, :], i8, i8, i8, i8), cache=True)
def main(wall, Sx, Sy, Tx, Ty):
    INF = 1 << 30
    H, W = wall.shape
    S = Sx * W + Sy
    T = Tx * W + Ty
    dist = np.full(H * W, INF, np.int64)
    deq = np.empty(2 * H * W + 100, np.int64)
    dist[S] = 0
    deq[H * W], l, r = S, H * W, H * W + 1
    while l < r:
        v, l = deq[l], l + 1
        vx, vy = divmod(v, W)
        # そのままあるく
        for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            wx, wy = vx + dx, vy + dy
            if not (0 <= wx < H):
                continue
            if not (0 <= wy < W):
                continue
            if wall[wx, wy]:
                continue
            w = wx * W + wy
            if dist[w] <= dist[v]:
                continue
            dist[w] = dist[v]
            deq[l - 1], l = w, l - 1
        # ワープする
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                wx, wy = vx + dx, vy + dy
                if not (0 <= wx < H):
                    continue
                if not (0 <= wy < W):
                    continue
                if wall[wx, wy]:
                    continue
                w = wx * W + wy
                if dist[w] <= dist[v] + 1:
                    continue
                dist[w] = dist[v] + 1
                deq[r], r = w, r + 1
    ans = dist[T]
    if ans == INF:
        ans = -1
    return ans

H, W = map(int, readline().split())
Sx, Sy = map(lambda x: int(x) - 1, readline().split())
Tx, Ty = map(lambda x: int(x) - 1, readline().split())
wall = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W] == b'#'

print(main(wall, Sx, Sy, Tx, Ty))


Measured memory_bytes: 118384
count = 0
input()
num = [int(n) for n in input().split()]
for i in range(len(num)):
    minj = i
    for j in range(i, len(num)):
        if num[j] < num[minj]:
            minj = j
    if minj != i:
        num[i], num[minj] = num[minj], num[i]
        count += 1
print(*num)
print(count)

Measured memory_bytes: 7744
import java.util.*;

class Main {
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        
        int num = sc.nextInt();

        String design;
        int number;
        int[] s_num = {1,2,3,4,5,6,7,8,9,10,11,12,13};
        int[] d_num = {1,2,3,4,5,6,7,8,9,10,11,12,13};
        int[] h_num = {1,2,3,4,5,6,7,8,9,10,11,12,13};
        int[] c_num = {1,2,3,4,5,6,7,8,9,10,11,12,13};

        for(int i = 0;i < num;i++){
            design = sc.next();
            number = sc.nextInt();
            switch(design){
                case "S":
                    for(int j = 0;j < 13;j++){
                        if(s_num[j] == number)  s_num[j] = 0;
                    }
                    break;
                case "D":
                    for(int j = 0;j < 13;j++){
                        if(d_num[j] == number)  d_num[j] = 0;
                    }
                    break; 
                case "H":
                    for(int j = 0;j < 13;j++){
                        if(h_num[j] == number)  h_num[j] = 0;
                    }
                    break;     
                case "C":
                    for(int j = 0;j < 13;j++){
                        if(c_num[j] == number)  c_num[j] = 0;
                    }
                    break;     
            }
        }

    
        for(int i = 0;i < 4;i++){
            switch (i){
                case 0:
                    for(int j = 0;j < 13;j++){
                        if(s_num[j] != 0)   System.out.println("S "+s_num[j]);
                    }
                    break;
                case 1:
                    for(int j = 0;j < 13;j++){
                        if(h_num[j] != 0)   System.out.println("H "+h_num[j]);
                    }
                    break;
                case 2:
                    for(int j = 0;j < 13;j++){
                        if(c_num[j] != 0)   System.out.println("C "+c_num[j]);
                    }
                    break;
                case 3:
                    for(int j = 0;j < 13;j++){
                        if(d_num[j] != 0)   System.out.println("D "+d_num[j]);
                    }
                    break;
            }
        }
    }
}



Measured memory_bytes: 26236
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int n, k;
    cin >> n >> k;
    map<char, bool> d;
    rep(i, k) {
        string x;
        cin >> x;
        d[x[0]] = true;
    }

    for(int i=n;;++i) {
        string s = to_string(i);
        bool flag = true;
        rep(j, s.size()) {
            if(d[s[j]]) {
                flag = false;
            }
        }
        if(flag) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX 200

int n, m, s[MAX];

int main() {
	while (1) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)
			return 0;

		for (int i = 0; i < n + m; i++)
			scanf("%d", s + i);

		int sum = 0;
		for (int i = 0; i < n; i++)
			sum += s[i];
		for (int i = 0; i < m; i++)
			sum -= s[i + n];

		int taro = -1, hanako = -1;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if (sum == (s[i] - s[j + n]) * 2)
					if (taro < 0 || s[i] + s[j + n] < taro + hanako) {
						taro = s[i];
						hanako = s[j + n];
					}

		printf(taro < 0 ? "-1\n" : "%d %d\n", taro, hanako);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//FILE *fi = freopen("1.txt", "r", stdin);
//FILE *fo = freopen("1", "w", stdout);
//FILE *fi = freopen("P.inp", "r", stdin);
//FILE *fo = freopen("P.out", "w", stdout);
int n, Q;
int c[500001];
typedef pair<int, int> ii;
vector<ii> q[500001];
int bit[500001];
void update(int pos, int val)
{
    for (int i = pos; i <= n; i += i & -i)
        bit[i] += val;
}
int Get(int pos)
{
    int ans = 0;
    for (int i = pos; i; i -= i & -i)
        ans += bit[i];
    return ans;
}
int ans[500001];
int b[500001];
int main()
{
    //------------------------------
    // Faster
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //------------------------------
    cin >> n >> Q;
    for (int i = 1; i <= n; i++)
    {
        cin >> c[i];
    }
    int id = 0;
    for (int i = 1; i <= Q; i++)
    {
        int l, r;
        ++id;
        cin >> l >> r;
        q[r].push_back({l, id});
    }
    for (int i = 1; i <= n; i++)
    {
        int x = c[i];
        if (b[x])
            update(b[x], -1);
        b[x] = i;
        update(b[x], 1);
        for (auto Q : q[i])
        {
            ans[Q.second] = Get(n) - Get(Q.first - 1);
        }
    }
    for (int i = 1; i <= Q; i++)
        cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 33208
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if ((x-r)<0 || (x+r)>W) {
            System.out.println("No");
        } else if ((y-r)<0 || (y+r)>H) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int x,y; cin>>x>>y;
  int ans = max(0, x-y);
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break

    ma = 0
    mi = 1000
    s = 0

    for i in range(n):
        x = int(input())
        if ma < x:
            ma = x
        if mi > x:
            mi = x
        s += x

    
    print ((s - ma - mi) // (n - 2))

Measured memory_bytes: 6240
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
//#define double float

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const double EPS = 1e-6;
const int MAX = 300 + 47;
const int MIN = 50 + 7;
const int MOD = INF;


int A[MAX][MAX];
int U[MAX];
int F[MAX];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    FOR(i, 0, n)
        FOR(j, 0, m)
            scanf("%d", &A[i][j]), A[i][j]--;
    
    int ans = INF;
    FOR(it, 0, m)
    {
        FILL(F, 0);
        FOR(i, 0, n)
            FOR(j, 0, m)
            {
                int id = A[i][j];
                if (U[id])continue;
                F[id]++;
                break;
            }
        int idx = -1;
        FOR(i, 0, m)
                if (idx == -1 || F[i] > F[idx])
                    idx = i;
        ans = min(ans, F[idx]);
        U[idx] = 1;
    }
    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const ll mod=1e9+7;
ll Gcd(ll A,ll B){
  if(B==0)return A;
  return Gcd(B,A%B);	
}

int main(){
	ll A,B;
	sl(A);
	sl(B);
	cout<<(A*B)/Gcd(A,B)<<endl;
	
  return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

string S;
int N;
// pos
vector<set<int>> v;

ll go() {
    ll ans = 0;
    for(const auto &i:v[0]) {
        // find start
        auto sj = upper_bound(ALL(v[1]),i);

        for(auto j = sj; j != v[1].end(); j ++) {
            // find start
            auto sk= upper_bound(ALL(v[2]),*j);
            int sa  = distance(sk,v[2].end());
            if(sa == 0) break;
            ans += sa;
            int nk = 2*(*j) - i;
            // j-i = k-jを満たし、i,j,kの中にあるものがあるかどうか
            if (  sa >0 && *j < nk && v[2].count(nk) == 1)  ans--;

        }
    }
    return ans;
}

ll go2() {
    ll ans = 0;
    for(const auto &i:v[0]) {
        // find start
        auto sj = upper_bound(ALL(v[1]),i);
        for(auto j = sj; j != v[1].end(); j ++) {
            int nk = 2*(*j) - i;
            if (   *j < nk && v[2].count(nk) == 1)  ans--;
        }
    }
    return ans;
}


void solve() {
    v.resize(3);
    cin >> N;
    cin >> S;
    REP(i,N) {
        if (S[i]== 'R') v[0].insert(i);
        if (S[i]=='G') v[1].insert(i);
        if (S[i]=='B') v[2].insert(i);
    }
    ll ans = 0;
    REP(i,3) {
        ans += go();
        iter_swap(v.begin()+1,v.begin()+2);
        ans += go();
        iter_swap(v.begin(),v.begin()+1);
    }
    cout << ans << endl;

}

void solve2() {
    v.resize(3);
    cin >> N;
    cin >> S;
    REP(i,N) {
        if (S[i]== 'R') v[0].insert(i);
        if (S[i]=='G') v[1].insert(i);
        if (S[i]=='B') v[2].insert(i);
    }
    ll ans = v[0].size()*v[1].size()*v[2].size();
    REP(i,3) {
        ans += go2();
        iter_swap(v.begin()+1,v.begin()+2);
        ans += go2();
        iter_swap(v.begin(),v.begin()+1);
    }
    cout << ans << endl;

}

int main() {
    solve2();
    return 0;
}


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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int k = 1; k <= M; k++) {
		for (int i = 0; i + 1 < N; i++) {
			if (A[i] % k > A[i + 1] % k) {
				swap(A[i], A[i + 1]);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << A[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3096
n, t = map(int, input().split())
T = list(map(int, input().split()))

counter = 0
for i in range(len(T) - 1):
  if T[i+1] - T[i] < t:
    counter += T[i+1] - T[i]
  else:
    counter += t
counter += t
print(counter)

Measured memory_bytes: 86608
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;



int main() {
    int a,b;
    while(true){
        cin>>a>>b;
        if(a==0&&b==0)break;
        int orit=a*a+b*b;
        int a1=0,a2=0;
        int mint=10000000;
        int minh=0;
        for(int i=1;i<=150;i++){

            for(int j=1;j<150;j++){
                if(i!=j&&i<j){
                    int tai=i*i+j*j;
                    if(tai>orit&&tai<mint){
                        a1=i;
                        a2=j;
                        mint=tai;
                    }else if(tai==mint){
                        if(a1>i) {
                            a1 = i;
                            a2=j;
                            mint=tai;
                        }
                    }else if(tai==orit){
                        if(a+1<=i){
                            mint=tai;
                            a1=i;
                            a2=j;
                        }
                    }
                }
            }
        }





        cout<<a1<<" "<<a2<<endl;




    }

    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

void darts();

void longest_dis();

void sum_of_three_integers();

int main()
{
  //darts();
  //longest_dis();
  sum_of_three_integers();
}


void darts()
{
  while (true)
  {
    int n, m;
    cin >> n >> m;

    // stop cond
    if (n == 0) break;

    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];

    // 2 darts combination
    // p = q, 0, p + q
    vector<int> q = p;
    q.push_back(0);
    for (int i = 0; i < n; ++i)
    {
      for (int j = 0; j <= i; ++j)
      {
        q.push_back(p[i] + p[j]);
      }
    }

    sort(q.begin(), q.end());

    // q's size = 1 + n + n(n + 1) / 2
    //cout << q.size() << "\n";
    //for (auto x : q) cout << x << " ";

    int ret = 0;
    int j = q.size() - 1;
    //i:q linear scan
    for (int i = 0; i < q.size(); ++i)
    {
      if (q[i] > m) break;
      while (q[i] + q[j] > m) --j;
      ret = max(ret, q[i] + q[j]);
    }

    cout << ret << "\n";
  }
}

void longest_dis()
{
  int n;
  cin >> n;

  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;

  double v_max = 0.0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if ((p[i].first - p[j].first) * (p[i].first - p[j].first)
        + (p[i].second - p[j].second) * (p[i].second - p[j].second)
        >  v_max * v_max)
      {
        v_max = sqrt((p[i].first - p[j].first) * (p[i].first - p[j].first)
          + (p[i].second - p[j].second) * (p[i].second - p[j].second));
      }
    }
  }

  cout << v_max << "\n";
}

void sum_of_three_integers()
{
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  //for (int i = 0; i <= k; ++i)
  //{
  //  for (int j = 0; j <= k; ++j)
  //  {
  //    for (int m = 0; m <= k; ++m)
  //    {
  //      if (i + j + m == s) ++cnt;
  //    }
  //  }
  //}
  for (int i = 0; i <= k; ++i)
  {
    for (int j = 0; j <= k; ++j)
    {
      int m = s - i - j;
      if (0 <= m && m <= k) ++cnt;
    }
  }

  cout << cnt << "\n";
}

Measured memory_bytes: 3168
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int m = a[n-1];
        int d = Math.min(a[0], m-a[0]);
        int ans = a[0];
        for (int i = 0; i < n-1; i++) {
            int min = Math.min(a[i], m-a[i]);
            if(d < min){
                ans = a[i]; d = min;
            }
        }
        System.out.println(m + " " + ans);
        sc.close();

    }

}


Measured memory_bytes: 50640
# coding: utf-8
import math
number = list(map(int,input().split()))
n = number[0]
d = number[1]
number_list = []
for i in range(n):
    number_list.append(list(map(int,input().split())))
count = 0
sum = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            sum += (number_list[i][k]-number_list[j][k])**2
        distance = math.sqrt(sum)
        if list(str(distance))[-1] == "0":
            count += 1
        sum = 0
print(count)

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1


#ifndef ONLINE_JUDGE
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
						 stringstream _ss(_s); \
						 istream_iterator<string> _it(_ss); \
						 err(_it, args); }
#else
#define error(args...)		42
#endif


void err(istream_iterator<string> it) { cerr << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "; ";
	err(++it, args...);
}


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
#endif
}

int ceil2(int a, int b){
    int c = a / b;
    if (c * b < a) c++;
    return c;
}


int32_t main()
{
	c_p_c();

	int n; cin>>n;

	int dp_a[n], dp_b[n], dp_c[n];

	int a,b,c;

	cin>>dp_a[0]>>dp_b[0]>>dp_c[0];

	for (int i = 1; i < n; ++i)
	{
		cin>>a>>b>>c;

		dp_a[i] = a + max(dp_b[i-1], dp_c[i-1]);
		dp_b[i] = b + max(dp_a[i-1], dp_c[i-1]);
		dp_c[i] = c + max(dp_a[i-1], dp_b[i-1]);
	}

	cout << max({dp_a[n-1], dp_b[n-1], dp_c[n-1]});
	
	return 0;
}

Measured memory_bytes: 5888
from sys import stdin

in_n = int(stdin.readline())
in_a = []
in_a.append([ int(e) for e in stdin.readline().split(' ')])
in_a.append([ int(e) for e in stdin.readline().split(' ')])

out_a = [
  [ -1 for _ in range(in_n) ] + [0],
  [ -1 for _ in range(in_n) ] + [0]
]

for j in reversed(range(in_n)):
  for i in reversed(range(2)):
    if i == 1:
      out_a[i][j] = in_a[i][j] + out_a[i][j+1]
    else:
      out_a[i][j] = in_a[i][j] + max(out_a[i][j+1], out_a[i+1][j])

print(out_a[0][0])

Measured memory_bytes: 3064
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

A, B, C = list(map(int, input().split()))     # スペース区切り連続数字
K = int(input())    # 数字

r = 0
while A >= B:
    B *= 2
    r += 1

while B >= C:
    C *= 2
    r += 1

if r <= K:
    print("Yes")
else:
    print("No")


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

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << a*b / gcd(a, b) << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int t = Integer.parseInt(sa[1]);
		Obj[] arr = new Obj[n];
		for (int i = 0; i < arr.length; i++) {
			Obj o = new Obj();
			sa = br.readLine().split(" ");
			o.i = i;
			o.a = Integer.parseInt(sa[0]);
			o.b = Integer.parseInt(sa[1]);
			arr[i] = o;
		}
		br.close();

		Arrays.parallelSort(arr, (o1, o2) -> o1.a - o2.a);
		int[][] dp = new int[n + 1][t];
		for (int i = 0; i < n; i++) {
			int a = arr[i].a;
			int b = arr[i].b;
			for (int j = 0; j < t; j++) {
				if (j >= a && dp[i][j] < dp[i][j - a] + b) {
					dp[i + 1][j] = dp[i][j - a] + b;
				} else {
					dp[i + 1][j] = dp[i][j];
				}
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			int val = dp[i][t - 1];
			int bmax = 0;
			for (int j = i; j < n; j++) {
				bmax = Math.max(bmax, arr[j].b);
			}
			val += bmax;
			ans = Math.max(ans, val);
		}
		System.out.println(ans);
	}

	static class Obj {
		int i, a, b;
	}
}


Measured memory_bytes: 82004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n,l;
	scanf("%d",&n);
	scanf("%d",&l);
	char s[n][l+1];//EOS
	int i;
	for(i = 0; i < n; i++){
		scanf("%s",s[i]);
	}
	char a[l+1];
	
	int p,q;
	int j;
	for(p = 0; p < n; p++){
		for(q = 0; q < n-1-p; q++){
		j = 0;
		while(s[q][j] == s[q+1][j]){
			j = j+1;
		}
		if(s[q][j] > s[q+1][j]){
			strcpy(a,s[q]);
			strcpy(s[q],s[q+1]);
			strcpy(s[q+1],a);
			}
		}
	}
	
	int r;
	for(r = 0; r < n; r++){
		printf("%s",s[r]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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

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

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    cin >>N;
    set<string> S;
    rep(i,N) {
        string s;
        cin >>s;
        S.insert(s);
    }
    cout << S.size() << endl;
}

Measured memory_bytes: 19540
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N, M;
int sx[60], sy[60], cx[60], cy[60];

int main() {
  while (cin >> N >> M) {
	for (int i = 0; i < N; ++i) cin >> sx[i] >> sy[i];
	for (int i = 0; i < M; ++i) cin >> cx[i] >> cy[i];

	for (int i = 0; i < N; ++i) {
	  int res = 1<<30, pres = -1;
	  for (int j = 0; j < M; ++j) {
		if (chmin(res, abs(cx[j] - sx[i]) + abs(cy[j] - sy[i]))) {
		  pres = j;
		}
	  }
	  cout << pres + 1 << endl;
	}
  }
}
								 
								  
																				   


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

using namespace std;

#define MAX_N 25

int n;
queue<int> que;

struct Island{
	int treasure;
	int bridge;

	bool operator<(const Island& right)const{
		return bridge > right.bridge;
	}

};

int main(){
	int x;
	do{
		cin >> x;
		que.push(x);
	} while (x);

	do{
		n = que.front();
		que.pop();
		if (n == 0)break;
		vector <Island> x(n);

		for (int i = 0; i < n; i++){
			x[i].treasure = que.front();
			que.pop();
			x[i].bridge = que.front();
			que.pop();
		}

		sort(x.begin(), x.end());
		bool ok=true;
		for (int i = 0; i < n; i++){
			int sum = 0;
			for (int j = i; j < n; j++){
				sum += x[j].treasure;
			}
			if (x[i].bridge < sum){
				ok = false;
			}
		}
		if (ok){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}

	} while (1);

	return 0;
}

Measured memory_bytes: 1216
import math
def j(s):
    n = len(s)
    if s[:n//2]==s[math.ceil(n/2):][::-1]:
        return True
    else:
        return False


s = input()
n = len(s)

if not j(s):
    print("No")
    exit()
if not j(s[:n//2]):
    print("No")
    exit()
if not j(s[n//2+1:]):
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 3188
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local N = read.n()
local B = {}
for i=1,N-1 do B[i] = read.n() end

local A = {}
A[N] = B[N-1]
local ans = A[N]
for i=N-1,2,-1 do
    A[i] = math.min(B[i-1], B[i])
    ans = ans + A[i]
end
A[1] = B[1]
ans = ans + A[1]
--print(table.concat(A, "\t"))
--print(table.concat(B, "\t"))
print(ans)

Measured memory_bytes: 888
<?php
fscanf(STDIN, "%d %d", $n, $m);
for ($i = 0; $i < $m; $i++) {
	fscanf(STDIN, "%d %d %d", $x, $y, $z);
	$e[$x][$y] = $e[$y][$x] = 1;
}
$x = $n - count($e);
foreach ($e as $i => $d) {
	if (isset($f[$i])) continue;
	$f[$i] = 1;
	$t = [$i];
	while ($t) {
		$j = array_pop($t);
		foreach ($e[$j] as $k => $d) {
			if (!isset($f[$k])) {
				$f[$k] = 1;
				$t[] = $k;
			}
		}
	}
	$x++;
}
echo $x;

Measured memory_bytes: 58104