akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<stack>

using namespace std;

struct Node{
 Node *right;
 Node *left;
 Node *parent;
 int key;
public:
 Node(Node *r,Node *l,Node *p,int k) : right(r), left(l), parent(p), key(k){};
};

class Tree{
 Node *root;
public:
 Tree(){root = 0;}


 void insert(int v){
  Node *z = new Node(0,0,0,v);
  Node *y = 0;
  Node *x = root;
  while(x != 0){
   y = x;
   if(z->key < x->key){
    x = x->left;
   }else{
    x = x->right;
   }
  }
  z->parent = y;
  if( y == 0){
   root = z;
  }else if(z->key < y->key){
   y->left = z;
  }else{
   y->right = z;
  }
 } 

 void mainoutput(Tree tree){
  outputInorder(tree);
  outputPreorder(tree);
 }

 void outputPreorder(Tree tree){
  stack<Node*> pre;
  pre.push(tree.root);
  while(!pre.empty()){
   Node *buf = pre.top(); pre.pop();
   cout <<" "<< buf->key;
   if(buf->right != 0) pre.push(buf->right);
   if(buf->left != 0) pre.push(buf->left);
  }
  cout << '\n';
 }

 void outputInorder(Tree tree){

  if(tree.root == 0) return ;

  Node* cur = tree.root;
  Node* prev = cur->parent;
  while(cur != 0){
   if(cur->parent == prev){

    //Preorder
    //cout << " " << cur->key;

    if(cur->left != 0){
     prev = cur;
     cur = cur->left;
     continue;
    }else{
     prev = cur->left;
    }
   }

   if(prev == cur->left){
    //inorder
    cout << " " << cur->key;

    if(cur->right != 0){
     prev = cur;
     cur = cur->right;
     continue;
    }else{
     prev = cur->right;
    }
   }

   if(prev == cur->right){
    //postorder
    //cout << " " << cur->key;

    prev = cur;
    cur = cur->parent;
   }
  }
 cout << endl;
 }
};

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

 Tree tree;

 int n = 0;
 cin >> n;

 for(int i=0; i < n; i++){
  string str = "";
  int num = -1;
  cin >> str;
  if(str == "insert"){
   cin >> num;
   tree.insert(num); 
  }else if(str == "print"){
   tree.mainoutput(tree); 
  }
 }

 
 return 0;
}

Measured memory_bytes: 24668
/*input
4.56425719433005567605

*/

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

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double s, t;
  s = 2.0*M_PI*(h+m/60.0)/12.0;
  t = 2.0*M_PI*m/60.0;
  double dx, dy;
  dx = a*cos(s)-b*cos(t);
  dy = a*sin(s)-b*sin(t);
  double ans = sqrt(dx*dx+dy*dy);
  // cout << ans << endl;
  printf("%.20lf\n", ans);
  // printf("%.20lf\n", 4.56425719433005567605);
}

Measured memory_bytes: 4024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
#define X real()
#define Y imag()


// ???a??¨???b?????????????????????r????????????????????????
VP circlesPointsRadius(P a, P b, D r) {
    VP cs;
    P abH = (b-a)*0.5;
    D d = abs(abH);
    if (d == 0 || d > r) return cs;	// ???????????? !LE(d,r) ??¨?????????1??????????????´????????????
    D dN = sqrt(r*r - d*d);					// ???????????? max(r*r - d*d, 0) ??¨??????
    P n = abH * P(0,1) * (dN / d);
    cs.push_back(a + abH + n);
    if (dN > 0) cs.push_back(a + abH - n);
    return cs;
}

int N;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    while(cin >> N, N){
        vector<P> points(N);
        for(int i=0; i<N; i++){
            D x, y; cin >> x >> y;
            points[i] = P(x, y);
        }
        
        int ans = 1;
        for(int i=0; i<N; i++)
            for(int j=i+1; j<N; j++){
                VP vs = circlesPointsRadius(points[i], points[j], 1);
                for(auto v: vs){
                    int tans = 0;
                    for(auto p: points)
                        if(LE(abs(p-v), 1))
                            tans++;
                    ans = max(ans, tans);
                }
            }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3296
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	lint A, B;
	cin >> A >> B;
	lint C = A + B;
	if (C & 1) cout << "IMPOSSIBLE" << endl;
	else cout << C/2 << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str;
		String[] st;
		int[] a = new int[4];
		while(sc.hasNext()){
			str = sc.next();
			st = str.split(",",0);
			
			if(st[1].equals("A"))a[0]++;
			if(st[1].equals("B"))a[1]++;
			if(st[1].equals("AB"))a[2]++;
			if(st[1].equals("O"))a[3]++;
		}
		System.out.println(a[0]);
		System.out.println(a[1]);
		System.out.println(a[2]);
		System.out.println(a[3]);
		}
}

Measured memory_bytes: 17148
#include <bits/stdc++.h>
using namespace std;
int h[100002],n,res,m;
bool kt[100002];
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    scanf("%d %d",&n,&m);
    res=n;
    for(int i=1;i<=n;++i) scanf("%d",&h[i]);
    for(int i=0;i<m;++i){
        int q,r;
        scanf("%d %d",&q,&r);
        if(h[q]>h[r]&&!kt[r]){res--; kt[r]=1;}
        if(h[q]<h[r]&&!kt[q]){res--; kt[q]=1;}
        if(h[q]==h[r]){
            if(!kt[q]){res--; kt[q]=1;}
            if(!kt[r]){res--; kt[r]=1;}
        }
    }
    printf("%d",res);
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,c=0;
    cin>>n;
    ll a[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]!=i)
        {
            c++;
        }
    }
    if(c<=2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;

int main(){
  int n,k,i,j;
  int a,b,c;
  long long ans=0;
  cin >> n >> k;
  for(b=1;b<=n;b++){
    i=n/b;
    j=n%b;
    ans+=i*max(0,b-k);
    ans+=max(0,j-k+1);
  }
  if(k==0)ans-=n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

L = [reduce(gcd, A[1:])]
l = A[0]
for i in range(N-1):
    l = gcd(l, A[i])
    L.append(l)

R = [reduce(gcd, A[:N-1])]
r = A[-1]
for i in range(N-1, 0, -1):
    r = gcd(r, A[i])
    R.append(r)

ans = 1
for i in range(N):
    ans = max(ans, gcd(L[i], R[-(i+1)]))

print(ans)

Measured memory_bytes: 16128
#include<iostream>
#include<vector>
using namespace std;

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> ac_cnt(N);
  for(int q = 0; q < Q; q++){
    int a;
    cin >> a;
    ac_cnt[a - 1]++;
  }

  for(int i = 0; i < N; i++){
    if(K - Q + ac_cnt[i] > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}


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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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





int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int x,y;
    cin>>x>>y;

    if((y-x*2>=0)&&(x*4-y>=0)&& (y-2*x)%2 == 0 && (x*4 - y)%2 == 0)flag = true;
    else flag = false;

    //cout <<fixed<<setprecision(16)<< << endl;

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

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,z;cin>>x>>y>>z;
  int t=x-z;
  int s=y+z;
  for(int i=1;;i++){
    if(s*i>t){
      cout<<i-1<<endl;
      return 0;
    }
  }
}

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

for i in range(a):
  if s[i] == '-':
    print('No')
    exit()
if s[a] != '-':
  print('No')
  exit()
for i in range(a+1,a+b+1):
  if s[i] == '-':
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int gcd(int x , int y ){
	if( x < y )
		swap(x,y);
	while( y>0){
		int r = x%y;
		x = y ;
		y = r;
	}
	return x;
}
int main(){
	int x , y;
	cin >> x >> y;
	int n= gcd(x,y);
	cout << n << endl;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
using namespace std;

int n;

void CountingSort(vector<int>& a, vector<int>& b, int k) {
	vector<int> c(k + 1);
	for (int i = 0; i <= k; i++) {
		c[i] = 0;
	}
	for (int j = 1; j <= n; j++) {
		c[a[j]]++;
	}
	for (int i = 1; i <= k; i++) {
		c[i] = c[i] + c[i - 1];
	}
	for (int j = n; j >= 1; j--) {
		b[c[a[j]]] = a[j];
		c[a[j]]--;
	}
}

int main()
{
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	int max = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (max < a[i]) {
			max = a[i];
		}
	}
	CountingSort(a, b, max);
	for (int i = 1; i <= n; i++) {
		cout << b[i];
		if (i < n)
			cout << " ";
		else
		{
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 18408
w = int(input())
n = int(input())

alist = []
blist = []
for _ in range(n):
    a, b = map(int, input().split(","))
    alist.append(a)
    blist.append(b)

ans = [0] * w

for i in range(1, w+1):
    position = i
    for a, b in zip(alist, blist):
        if a == position:
            position = b
        elif b == position:
            position = a

    ans[position-1] = i

for a in ans:
    print(a)



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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define no cout << "No" << endl
#define yes cout << "Yes" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (ll) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(ll i = a ; i < n; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a; --i)
#define db(x) cout << #x << ": " << x << endl;
#define _db(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);
template<typename... T> void read(T&... x) {((cin >> x),...);}

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

    if (500*n >= k) yes;
    else  no;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    long long mod = 1000000007;
    long long dp[n + 1][m + 1];
    for (int i = 0; i < n; i++) dp[i][m] = 0;
    for (int i = 0; i < m; i++) dp[n][i] = 0;
    dp[n - 1][m] = 1;
    for (int i = n - 1; i >= 0; i--){
        for (int j = m - 1; j >= 0; j--){
            if (v[i][j] == '.') dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
            else dp[i][j] = 0;
        }
    }
    cout << dp[0][0] << endl; 
}

Measured memory_bytes: 13224
x, n = map(int,input().split())

if n == 0:
    print(x)
    exit()
    
p = list(map(int,input().split()))



c = 0
while True:
    if not x - c in p:
        print(x-c)
        exit()
    
    elif not x + c in p:
        print(x+c)
        exit()
    
    c += 1

Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>> a >>b >>c ;
	int temp;
	temp=a;
	a=b;
	b=temp;
	temp=a;
	a=c;
	c=temp;
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
long long kazu[30][30];
long long used[20][20][20][20];
int main() {
  int n; cin >>n;
  rep(i,n){
    double x;
    cin>>x;
    long long xl=llround(x*1e9);
    int ni=0,go=0;
    while(xl%2==0){
      ni++;
      xl/=2;
    }
    while(xl%5==0){
      go++;
      xl/=5;
    }
    if(ni>=18)ni=18;
    if(go>=18)go=18;
    kazu[ni][go]++;
    //cout<<kazu[ni][go]<<" "<<ni<<" "<<go<<endl;
  }
  long long kotae=0;
  for(int i=0;i<=18;i++){
    for(int j=0;j<=18;j++){
      for(int k=0;k<=18;k++){
        for(int l=0;l<=18;l++){
          //if(i> k)break;
          if(kazu[i][j]>=2&&i==k&&j==l&&i>=9&&j>=9){
              if(used[i][j][i][j]==0)kotae+=kazu[i][j]*(kazu[i][j]-1)/2;
              used[i][j][i][j]=1;
              //cout<<"b"<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<endl;
          }
          else if(kazu[i][j]>=1&&kazu[k][l]>=1&&i+k>=18&&j+l>=18){
            if(i==k&&j==l)continue;
            if(used[i][j][k][l]==0)kotae+=kazu[i][j]*kazu[k][l];
            used[k][l][i][j]=1;
            used[i][j][k][l]=1;
            //cout<<"a"<<kotae<<" "<<kazu[i][j]<<" "<<kazu[k][l]<<" "<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<endl;            
          }
        }
      }
    }
  }
  cout<<kotae<<endl;
  return 0;
}


Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    vector<vector<ll>> dp(110, vector<ll>(100100, 0));
    vector<ll> w(110), v(110);

    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i < 110; ++i) {
        for (int j = 0; j < 100100; ++j) {
            dp[i][j] = LINF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < 100100; ++sum_v) {
            if (sum_v - v[i] >= 0) {
                chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }

            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }
    ll ans = 0;
    for (int sum_v = 0; sum_v < 100100; ++sum_v) {
        if (dp[N][sum_v] <= W) ans = sum_v;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 87296
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt

  val input = Seq.fill(n, d)(sc.nextInt)
  val result = input.zip(input.tail.tails.toSeq).foldLeft(0) {
    case (count, (base, compareTarget)) =>
      count + compareTarget.count {
        c =>
          math.sqrt {
            (base zip c).map { p =>
              (math.pow(p._1.toDouble - p._2.toDouble, 2))
            }.sum
          }.isValidInt
      }
  }
  println(result)
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll B,W;
ll i, j, k;
ll fa[202020];

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}
int main(){
    scanf("%lld%lld", &B, &W);
    fa[0] = 1;
    fornum(i,0,B+W+10){
        fa[i + 1] = fa[i] * (i + 1) % MOD;
    }
    ll an = moddiv(1,2);
    ll aaa = moddiv(1,2);
    fornum(i,1,B+W){
        printf("%lld\n", aaa);
        an = moddiv(an, 2);
        if(B<=i){
            aaa = (aaa + MOD - an*moddiv(fa[i-1], fa[B-1] * fa[i - B])%MOD)%MOD;
            //printf("%lldb", moddiv(fa[i - 1], fa[B-1] * fa[i - B]));
        }
        if(W<=i){
            aaa = (aaa + an * moddiv(fa[i-1], fa[W-1] * fa[i - W])%MOD) % MOD;
            //printf("%lldw", moddiv(fa[i - 1], fa[W-1] * fa[i - W]));
        }
    }
    printf("%lld", aaa);
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    //int a;cin>>a;
    //char a,b,c;cin>>a>>b>>c;
    string str;cin>>str;
    //cout<<str<<endl;
    rep(i,str.size()){
        if(str[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
 
    return 0;
}

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

int bi[300010];
int rbi[300010];

typedef long long ll;
//a^(p-2)=a^(-1) (mod p)
//(x^n)%mod
ll mod_pow(ll x,ll n,ll mod){
  if(n==0)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}

int rec(int x,int y){
  x--,y--;
  int res=(rbi[x]*rbi[y])%MOD;
  res*=bi[x+y];
  return res%MOD;
}

signed main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;

  int t=1;
  bi[0]=rbi[0]=1;
  for(int i=1;i<300001;i++){
    t*=i;
    t%=MOD;
    bi[i]=t;
    rbi[i]=mod_pow(t,MOD-2,MOD);
  }
  
  int ans=0;
  for(int i=0;i<w-b;i++){
    ans+=(rec(h-a,b+1+i)*rec(a,w-b-i))%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


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

x_list = [a, b]
y_list = [c, d]

ans_list = []
for x in x_list:
    for y in y_list:
        ans = x*y
        ans_list.append(ans)

ans_list.sort()
ans = ans_list[-1]
print(ans)

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

int main() {
    int N; cin >> N;
    int ans[10][10];
    rep(i, 10){
        rep(j, 10){
            ans[i][j] = 0;
        }
    }

    for (int i = 1; i <= N; i++){
        int t = i;
        int l = i%10;
        while (t/10 != 0){
            t /= 10;
        }
        ans[t][l]++;
    }

    ll ANS = 0;
    for (int i = 1; i < 10; i++){
        for (int j = 1; j < 10; j++){
            ANS += ans[i][j] * ans[j][i];
        }
    }

    cout << ANS << endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        n: usize,
        ss: [String; n],
    }
    let ssset: HashSet<_> = ss.into_iter().collect();
    println!("{}", ssset.len());
}


Measured memory_bytes: 21392
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static final String[][] TABLE = {
        {},
        {".", ",", "!", "?", " "},
        {"a", "b", "c"},
        {"d", "e", "f"},
        {"g", "h", "i"},
        {"j", "k", "l"},
        {"m", "n", "o"},
        {"p", "q", "r", "s"},
        {"t", "u", "v"},
        {"w", "x", "y", "z"}
    };
    
    public static void main(String[] args) {
        scn.nextLine();
        while(scn.hasNextLine()) {
            Scanner reader = new Scanner(scn.nextLine());
            reader.useDelimiter("0+");
            StringBuilder sb = new StringBuilder();
            while(reader.hasNext()) {
                String tmp = reader.next();
                int y = Integer.parseInt(tmp.substring(0, 1));
                int x = (tmp.length() - 1) % TABLE[y].length;
                sb.append(TABLE[y][x]);
            }
            System.out.println(sb);
        }
    }
}

Measured memory_bytes: 37416
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int N_MAX = 200001;
int main()
{
  int n,m=0,p,t,u,v,i,xm=0,xp=0,res;
  int rm[N_MAX],rp[N_MAX];
  string s;
  cin >> n >> s;
  for(i=0;i<n;i++)
    if(s[i]=='1')
      m++;
  m--;
  p=m+2;
  if(m>0){
    t=1;
    for(i=0;i<n;i++){
      t%=m;
      rm[i]=t;
      if(s[n-1-i]=='1'){
        xm+=t;
        xm%=m;
      }
      t*=2;
    }
  }
  t=1;
  for(i=0;i<n;i++){
    t%=p;
    rp[i]=t;
    if(s[n-1-i]=='1'){
      xp+=t;
      xp%=p;
    }
    t*=2;
  }
  for(i=0;i<n;i++){
    res=1;
    if(s[i]=='1'){
      if(m==0){
        res=0;
      }else{
        t=xm-rm[n-1-i];
        if(t<0)
          t+=m;
        for(;t>0;res++){
          u=t;
          v=0;
          while(u>0){
            v+=u%2;
            u/=2;
          }
          t=t%v;
        }
      }
    }else{
      t=(xp+rp[n-1-i])%p;
      for(;t>0;res++){
        u=t;
        v=0;
        while(u>0){
          v+=u%2;
          u/=2;
        }
        t=t%v;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 5312
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times {|i|yield(i)}                    end
def repl(st,en,n=1);       n*= -1 if st>en;st.step(en,n){|i|yield(i)} end



s = gc
data = []
rep s.size do |i|
	data.unshift s[s.size-1-i]
	case data.join
	when 'dream'
		data = []
	when 'dreamer'
		data = []
	when 'erase'
		data = []
	when 'eraser'
		data = []
	end
	break if data.size > 7
end

puts data.empty? ? 'YES' : 'NO'



Measured memory_bytes: 19580
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		List<Integer> d = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			d.add(Integer.parseInt(sc.next()));
		}

		long ans = d.stream()
					.distinct()
					.mapToInt(x -> x)
					.count();

		System.out.println(ans);
	}
}


Measured memory_bytes: 27092
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    long long  n = s.length()+1;
    long long *cnt = new long long[n];
    long long k = 0;
    long long l = 0;
    while (k < n-1) {
        long long i = k;
        while (i+1 < n-1 && s[i] == s[i+1])
            i++;
        cnt[l] = i-k+1;
        l++;
        k = i+1;
    }

    long long ans = 0;
    if (s[0] == '<') {
        long long i = 0;
        while (i < l) {
            if (i+1 < l) {
                ans += cnt[i]*(cnt[i]+1)/2 + cnt[i+1]*(cnt[i+1]+1)/2 - min(cnt[i], cnt[i+1]);
            }
            else if (i < l) {
                ans += cnt[i]*(cnt[i]+1)/2;
            }
            i+= 2;
        }
        cout << ans << endl;
    }
    else {
        ans += (cnt[0]+1)*cnt[0]/2;
        long long i = 1;
        while (i < l) {
            if (i+1 < l) {
                ans += cnt[i]*(cnt[i]+1)/2 + cnt[i+1]*(cnt[i+1]+1)/2 - min(cnt[i], cnt[i+1]);
            }
            else if (i < l) {
                ans += cnt[i]*(cnt[i]+1)/2;
            }
            i+= 2;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4472
#include <stdio.h>
int main (){
  int d,e,f,semdesconto,valorfinal;
  int a[112345], b[112345], c[112345][3];

  scanf("%d%d%d", &d,&e,&f);

  scanf("%d", &a[0] );
  int menor=a[0];               //pegando os menores valores para fazer um valor minimo sem desconto.
  for (int i = 1; i < d; i++){
    scanf("%d", &a[i] );
    if(a[i]<menor)
      menor=a[i];
  }
  scanf("%d", &b[0] );
  int menor2=b[0];
  for (int i = 1; i < e; i++){
    scanf("%d", &b[i]);
    if(b[i]<menor2)
      menor2=b[i];
  }
  for (int i=0; i<f; i++){
    for(int j=0; j<3; j++){
      scanf("%d", &c[i][j]);
    }
  }
  semdesconto=menor+menor2;
  valorfinal=semdesconto;      //não simplificado para fins de compreensão.
  //agora pegando os minimos valores com desconto.
  for(int i=0; i<f; i++){
    if(valorfinal > ( a[ c[i][0]-1 ]+b[ c[i][1]-1 ]-c[i][2] ) )
      valorfinal= ( a[ c[i][0]-1 ]+b[ c[i][1]-1 ]-c[i][2] );
  }
  //printf("com desconto : %d\n", comdesconto);

  printf("%d\n", valorfinal);
  return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>

int main(){
	int n=0;

	scanf("%d",&n);

	for(int i=3;i<=n;i++){
		if(i%3==0){
			printf(" %d",i);
			continue;
		}
		else{
			for(int j=i;j>=3;j/=10){
				if(j%10==3){
					printf(" %d",i);
					break;
				}
			}
		}
	}
	puts("");
	return 0;
}



Measured memory_bytes: 2056
N,A,B,C = map(int, input().split())

strs=[]
for _ in range(N):
    s=input()
    if s=='AB':
        strs.append((0,1))
    elif s=='AC':
        strs.append((0,2))
    else: #BC
        strs.append((1,2))

l=[A,B,C]
ans=[]
ds={0:'A',1:'B',2:'C'}

if sum(l)==0:
    print('No')
    exit()

if sum(l)==1:
    for n in range(N):
        i1,i2=strs[n]
        if l[i1]==0 and l[i2]==0:
            break
        else:
            if l[i1]==0:
                l[i1]+=1
                l[i2]-=1
                ans.append(ds[i1])
            else: # l[i2]==0
                l[i1]-=1
                l[i2]+=1
                ans.append(ds[i2])
    else:
        print('Yes')
        print(*ans,sep='\n')
        exit()
    print('No')
    exit()

i1,i2=strs[0]
if l[i1]==0 and l[i2]==0:
    print('No')
else:
    print('Yes')
    for n in range(N):
        i1,i2=strs[n]

        if n < N-1:
            i1_n,i2_n=strs[n+1]
        else:
            i1_n,i2_n=i1,i2
        
        if l[i1]*l[i2]==0:
            if l[i1]==0:
                l[i1]+=1
                l[i2]-=1
                ans.append(ds[i1])
            else:
                l[i1]-=1
                l[i2]+=1
                ans.append(ds[i2])
        elif (l[i1]==1 or l[i2]==1) and n<N-1 and [i1,i2]!=[i1_n,i2_n]:
            if i1==i1_n or i1==i2_n:
                l[i1]+=1
                l[i2]-=1
                ans.append(ds[i1])
            else:
                l[i1]-=1
                l[i2]+=1
                ans.append(ds[i2])
        else:
            l[i1]+=1
            l[i2]-=1
            ans.append(ds[i1])
    print(*ans,sep='\n')

Measured memory_bytes: 12440
#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long
#define cl(x,y) memset(x,y,sizeof(x))
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
const int N=5e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;
struct apple
{
	int w,id;
}a[N];
int cmp(apple x,apple y)
{
	return x.w>y.w;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int x,y,n1,n2,n3,i;
	cin>>x>>y>>n1>>n2>>n3;
	for(i=1;i<=n1+n2+n3;i++)
	{
		cin>>a[i].w;
		if(i<=n1)
			a[i].id=1;
		else if(i<=n1+n2)
			a[i].id=2;
		else
			a[i].id=3;
	}
	sort(a+1,a+n1+n2+n3+1,cmp);
	int r=0,g=0,c=0,sum=0;
	for(i=1;i<=n1+n2+n3;i++)
	{
		if(a[i].id==1 && r<x)
		{
			sum+=a[i].w;
			r++;
		}
		if(a[i].id==2 && g<y)
		{
			sum+=a[i].w;
			g++;
		}
		if(a[i].id==3 && r+g+c<x+y)
		{
			sum+=a[i].w;
			c++;
		}
		if(r+g+c==x+y)
			break;
	}
	cout<<sum<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    string S;
    cin >> S;
    ll N = SZ(S);
    vec csum(N+1, 0);
    ll t = 1;

    REP(i,1,N+1) {
        csum[i] = (csum[i-1] + (t * (S[N-i] - '0'))) % 2019;
        t = (t * 10) % 2019;
    }
    
    sort(ALL(csum));
    vec C;
    ll cnt = 1;
    REP(i,1,N) {
        if(csum[i] == csum[i-1]) ++cnt;
        else {
            C.pb(cnt);
            cnt = 1;
        }
    }
    if(csum[N] == csum[N-1]) ++cnt;
    C.pb(cnt);

    ll sum = 0;
    FORR(c,C) sum += c * (c - 1) / 2;
    _PR(sum);


    return 0;
}

/*



*/

Measured memory_bytes: 5240
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] x = new Integer[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		Arrays.sort(x, Collections.reverseOrder());

		int a = x[0];
		int b = 0;
		int minDif = x[0];
		for(int i = 1; i < n; i++) {
			int dif = Math.abs(a/2 - x[i]);
			if (dif == 0) {
				b = x[i];
				break;
			} else if(dif < minDif) {
				minDif = dif;
				b = x[i];
			}
		}
		System.out.println(a + " " + b);
	}
}


Measured memory_bytes: 60984
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    n = get_int()
    li = get_list()
    if len(li)==len(set(li)):
        print("YES")
    else:print("NO")



''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

int n,flag=0;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    rep(i,1,9)
        if(n%i==0 and n/i<=9)
        {
            flag=1;
            break;
        }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
}




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

int main() {
  int n, w;
  cin >> n >> w;
  long long  dp[n+1][w+1];
  long long  weight[n];
  long long  value[n];
  for (int i = 0; i <= n; i++){
    cin >> weight[i] >> value[i];
    dp[i][0] = 0;
  }
  for (int i = 0; i <= w; i++){
    dp[0][i] = 0;
  }
  for (int i = 0; i < n; i++){
    for (long long  j = 0; j <= w; j++){
      if (j >= weight[i]){
        dp[i+1][j] = max(dp[i][j-weight[i]] + value[i], dp[i][j]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  cout << dp[n][w] << endl;
}


Measured memory_bytes: 79104
#include <iostream>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
  ll L;
  double v;
  cin >>L;
  v=pow((double)L*1.0/3.0,3.0);
  printf("%lf\n",v);

}


Measured memory_bytes: 256
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Fri Jan  4 16:20:38 2019
//
package main

import (
	"fmt"
)

const maxLen = 8000

func canReach(fs []int, at int) bool {
	dp := make([][]bool, len(fs)+1)
	for i := range dp {
		dp[i] = make([]bool, 2*maxLen+1)
	}
	dp[0][maxLen+0] = true

	for i := range fs {
		for f := range dp[i] {
			if dp[i][f] {
				dp[i+1][f-fs[i]] = true
				dp[i+1][f+fs[i]] = true
			}
		}
	}

	fmt.Println(dp[len(fs)])
	return dp[len(fs)][maxLen+at]
}

func splitCommand(s string) (xs []int, ys []int) {
	arms, move := []int{}, 0
	for _, c := range s {
		if c == 'T' {
			arms = append(arms, move)
			move = 0
		} else {
			move++
		}
	}
	arms = append(arms, move)

	for i := range arms {
		if i%2 == 0 {
			xs = append(xs, arms[i])
		} else {
			ys = append(ys, arms[i])
		}
	}
	return xs, ys
}

func main() {
	var s string
	fmt.Scan(&s)
	var x, y int
	fmt.Scan(&x, &y)

	xMoves, yMoves := splitCommand(s)
	dpx := [8001][16005]bool{}
	dpx[0][8000+xMoves[0]] = true
	xMoves = xMoves[1:]
	for i := 0; i < len(xMoves); i++ {
		for j := 0; j < 16005; j++ {
			if dpx[i][j] {
				dist := xMoves[i]
				dpx[i+1][j-dist] = true
				dpx[i+1][j+dist] = true
			}
		}
	}

	dpy := [8001][16005]bool{}
	dpy[0][8000] = true
	for i := 0; i < len(yMoves); i++ {
		for j := 0; j < 16005; j++ {
			if dpy[i][j] {
				dist := yMoves[i]
				dpy[i+1][j-dist] = true
				dpy[i+1][j+dist] = true
			}
		}
	}

	if dpx[len(xMoves)][8000+x] && dpy[len(yMoves)][8000+y] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s,t; cin >> s >> t;
  int sn = (int)s.size(), tn = (int)t.size();
  int ans = 1001001001;
  for(int i = 0; i < sn-tn+1; ++i){
    int cnt = 0;
    for(int j = 0; j < tn; ++j){
      cnt += s[i+j] != t[j];
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
from collections import Counter

n, k = map(int, input().split())
a = list(map(int,input().split()))

c = Counter(a)

ans = 0
balls = []
for i in c.items():
    balls.append(i)

balls.sort(key= lambda x:x[1], reverse=True)
cnt = 0
for i in range(len(balls)):
    cnt += 1
    if cnt <= k:
        continue
    else:
        ans += balls[i][1]

print(ans)


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

//関数宣言
//int func(int x, int y);

int main(void){

  //スカラー入力
  int R,G,B,N;

  scanf("%d %d %d %d", &R, &G, &B, &N);

  int X,Y,Z;

  if(R>=G && R>=B){
    X=R;
    if(G>=B){
      Y=G;
      Z=B;
    }else{
      Y=B;
      Z=G;
    }
  }else if(G>=B && G>=R){
    X=G;
    if(B>=R){
      Y=B;
      Z=R;
    }else{
      Y=R;
      Z=B;
    }
  }else{
      X=B;
      if(R>=G){
        Y=R;
        Z=G;
      }else{
        Y=G;
        Z=R;
    }
   }

  /* printf("%d %d %d\n", X,Y,Z); */

  int Xmax,Ymax,ans;

  ans = 0;
  Xmax = N/X;

  for(int i=0; i<=Xmax; i++){
    Ymax = (N-X*i)/Y;
    for(int j=0; j<=Ymax; j++){
      /* printf("%d %d %d\n", i, j, ) */
      if((N-X*i-Y*j)%Z == 0){
        ans++;
      }
    }
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;


signed main() {
    int N; cin >> N;
    vector< pair<int, int> > arts;
    for(int i=0; i<N; i++) {
        int A, B; cin >> A >> B;
        arts.emplace_back(A, B);
    }
    sort(arts.begin(), arts.end());

    int ans = -INF;
    int sumB = 0, min_val = INF;
    for(int i=0; i<N; i++) {
        int A, B, pre_sumB = sumB; tie(A, B) = arts[i];
        sumB += B;
        min_val = min(min_val, pre_sumB - A);
        ans = max(ans, sumB - A - min_val);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 11184
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

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

int n;
ll arr[3000];
ll dp[3000][3000];


int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%lld", arr + i);
	for (int i = 0; i < n; i++) 
		dp[i][i] = arr[i];
	for (int j = 2; j <= n; j++) {
		for (int i = 0; j + i <= n; i++) {
			dp[i][i + j - 1]= max(-dp[i + 1][i + j - 1] + arr[i], 
				-dp[i][i + j - 2] + arr[i + j - 1]);
			
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

ll n; int ans=0;
void dfs(ll a, int p){
	if(p&1&&p&2&&p&4)
		ans++;
	if(a*10+3<=n)
		dfs(a*10+3,p|1);
	if(a*10+5<=n)
		dfs(a*10+5,p|2);
	if(a*10+7<=n)
		dfs(a*10+7,p|4);
}

int main() {
	cin >> n;
	dfs(0,0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    char alfa; cin >> alfa;
    if(alfa >= 'A'&& alfa <= 'Z') cout << "A" << endl;
    if(alfa >= 'a'&& alfa <= 'z') cout << "a" << endl;
}

Measured memory_bytes: 3632
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)

n,m=map(int,input().split())
s=input()
t=input()
c=0
a=lcm(n,m)//n
b=lcm(n,m)//m

for i in range(n):
  if (i*a)%b==0:
    if s[i]==t[int(i*a/b)]:c+=1
    else:
      break
if c==(int(lcm(n,m)/lcm(a,b))):print(lcm(n,m))
else:print(-1)

Measured memory_bytes: 5340
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<string> v;
  int n,l; cin >> n >> l;
  for(int i=0;i<n;i++){
    string s; cin >> s;
    v.push_back(s);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++){
    cout << v[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
n, T = map(int, input().split())
l = []
for _ in range(n):
    c, t = map(int, input().split())
    l.append([c, t])
    
l.sort()
for i in range(n):
    if l[i][1] <= T:
        print(l[i][0])
        break
    if i == n-1 and l[i][1] > T:
        print('TLE')

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n ;cin >> n;
  vector<int> v(n); cin >> v;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = i+1; j < n; ++j){
      for(int k = j+1; k < n; ++k){
	if(v[i] != v[j] && v[i] != v[k] && v[j] != v[k]){
	  if(v[i] + v[j] > v[k] && v[j]+v[k] > v[i] && v[k]+v[i] > v[j])ans++;
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    vector<ll> dp(5);
    rep(i, N) {
        dp[0] += a[i];
        
        if (a[i] == 0) dp[1] += 2;
        else dp[1] += a[i] % 2;
        
        dp[2] += (a[i] + 1) % 2;
        
        if (a[i] == 0) dp[3] += 2;
        else dp[3] += a[i] % 2;
        
        dp[4] += a[i];
        
        rep(k, 4) dp[k + 1] = min(dp[k + 1], dp[k]);
    }
    cout << dp[4] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;


int main(){

    int N;
    cin >> N;

    map<string, int> dict{};

    string Si;
    for(int i=0;i<N;i++){
        cin >> Si;
        dict[Si] = 1;
    }

    int count=0;
    for(auto itr = dict.begin(); itr != dict.end(); ++itr){
        //key = itr->first;
        //value = itr->second;
        count++;
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 19176
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	long long ans=0, n,x,y;
	bool check = false;
	char c[6];
	cin >> n;
	x = n / 500;
	y = n % 500;
	y /= 5;
	ans = x * 1000 + y * 5;
	cout << ans << endl;
	please AC;
}


Measured memory_bytes: 256