akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N,Q; cin >> N >> Q;
	V<ll> a(N+1,0),sum(N+1,0),evn(N+1,0),odd(N+1,0),ans;
	FOR(i,1,N+1) cin >> a[i];
	FOR(i,1,N+1) sum[i] += sum[i-1] + a[i];
	FOR(i,1,N+1) evn[i] += evn[i-1] + (i%2?a[i]:0);
	FOR(i,1,N+1) odd[i] += odd[i-1] + (i%2?0:a[i]);

	while(Q--){
		ll X,dx; cin  >> X;
		int ng = 0,ok = N,md;
		while(ok-ng>1){
			md = (ok+ng)/2;
			if(a[md] < X) {
				ng = md;
				continue;
			}
			int ta = N - md  + 1;
			int ao = md - (lower_bound(ALL(a),max(1LL,2*X-a[md])) - a.begin()) + 1;
			(ta>ao?ng:ok)=md;
		}
		ll cnt = sum[N]-sum[ok-1];
		cnt += (N%2?evn[max(N-2*(N-ok+1),0)]:odd[max(N-2*(N-ok+1),0)]);
		ans.push_back(cnt);
	}
	for(auto e:ans) cout << e << endl;
	return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X;
  cin >>N>>X;
  int s = 0;
  int mi = 200000;
  for(int i=0;i<N;i++){
    int a;
    cin >>a;
    mi = min(mi,a);
    X -= a;
  }
  cout << N+X/mi << endl;
}
  

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>

using namespace std;

int main(void) {
	int num, N;
	int cnt4=0, cnt2=0, cnt1=0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &num);
		if (num % 4 == 0) {
			cnt4++;
		}
		else if (num % 2 == 0) {
			cnt2++;
		}
		else {
			cnt1++;
		}
	}
	if (cnt4 >= cnt1) {
		printf("Yes\n");
	}
	else {
		if (cnt2 == 0 && cnt4+1 == cnt1) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int A,B,C,X;

    cin >> A >> B >> C >> X;

    int ans = 0;

    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 == X){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
local mmi, mma = math.min, math.max
local n, k = io.read("*n", "*n")
local h = {0}
for i = 1, n do
  h[i + 1] = io.read("*n")
end
h[n + 2] = 0
local inf = 1000000007 * (n + 2)
local t = {}
for i = 1, n + 2 do
  t[i] = {}
  for j = 1, k + 1 do
    t[i][j] = inf
  end
end
t[1][1] = 0
for dst = 2, n + 2 do
  for src = 1, dst - 1 do
    local midlen = dst - src - 1
    local score = mma(0, h[dst] - h[src])
    for z = 1, k + 1 - midlen do
      t[dst][z + midlen] = mmi(t[dst][z + midlen], t[src][z] + score)
    end
  end
end

local ret = t[n + 2][1]
for i = 2, k + 1 do
  ret = mmi(ret, t[n + 2][i])
end
print(ret)


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
int gcd(int x, int y) {
    if (y == 0)return x;
    else return gcd(y, x % y);
}
signed main(){
    int n;
    cin>>n;
    vector<int> a(n),l(n),r(n);
    for(int i=0;i<n;i++)cin>>a[i];
    l[0]=a[0];
    r[n-1]=a[n-1];
    for(int i=1;i<n;i++)l[i]=gcd(a[i],l[i-1]);
    for(int i=n-2;i>=0;i--)r[i]=gcd(a[i],r[i+1]);
    int res = max(l[n-2],r[1]);
    for(int i=1;i<n-1;i++)res=max(res,gcd(l[i-1],r[i+1]));
    cout<<res<<endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    ll tmp;

    rep(i, n) {
        cin >> tmp;

        if(mp.count(tmp) == 0)
            mp[tmp] = 1;
        else
            mp.erase(tmp);
    }
    cout << mp.size();
}


Measured memory_bytes: 6528
#include<stdio.h>
int main(void){
  int S,K,i;
  char r[15]={'\0'};
  scanf("%d",&S);
  scanf("%s",r);
  scanf("%d",&K);
  for(i=0;i<S;i++){
    if(r[i]!=r[K-1]){
      r[i]='*';
    }
  }
  printf("%s",r);
  return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  
  int array[n];
  REP(i,n) array[i] = i+1;
  vector<int> array1(n);
  vector<int> array2(n);
  
  REP(i,n){
    cin >> array1[i];
  }
  REP(i,n){
    cin  >> array2[i];
  }
  
  int a = 0,b = 0,c = 1;
  do{
    bool can1 = true;
    bool can2 = true;
    /*for(int i=0; i<n; i++){
      cout<<array[i];
      if(i!=n-1)cout<<" ";
    }
    cout << endl;*/
    
    REP(i,n){
      if(array[i] != array1[i]){
        can1 = false;
      }
      if(array[i] != array2[i]){
        can2 = false;
      }
    }
    
    if(can1){
      a = c;
    }
    if(can2){
      b = c;
    }
    //if(can2) b = c;
   /* bool can1 = true;
    bool can2 = true;
    REP(i,n){
      if(array[i] != array1[i]){
        can1 = false;
      }
      if(array[i] != array2[i]){
        can2 = false;
      }
      if(can1) a = c;
      if(can2) b = c;
    }*/
    c++;
    can1 = true;
    can2 = true;
  }while(next_permutation(array,array+n));  
  
  cout << abs(a-b) << endl;
  

  
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int N;
	cin >> N;
	vi a(N);
	cin >> a;
	for (int i = 0; i < N; i++) a[i]--;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int j = a[i];
		if (a[j] == i)
			ans++;
	}
	cout << ans / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 640
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n = int(input())
count = 0
for i in range(1, n+1):
    if i%3!=0 and i%5!=0:
        count+=i
print(count)

Measured memory_bytes: 9132
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    rep(i, w+2) cout << '#';
    cout << endl;
    rep(i, h) {
        cout << '#';
        cout << s[i];
        cout << '#' << endl;
    }
    rep(i, w+2) cout << '#';
    cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long mult_mod(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

// ree always check bounds
// int vs long long
// bitset cheese <3

int src[5003], tgt[5003];
long long dist[2503], cost[5003];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m, p; cin >> n >> m >> p;

    for(int i = 0; i < n; ++i) dist[i] = -1e17;

    for(int i = 0; i < m; ++i){
        cin >> src[i] >> tgt[i] >> cost[i];
        cost[i] -= p;
    }

    dist[1] = 0;

    for(int relax = 0; relax <= n + n; ++relax){
        for(int i = 0; i < m; ++i){
            if(dist[src[i]] == -1e17) continue;
            if(dist[src[i]] + cost[i] > dist[tgt[i]]){
                dist[tgt[i]] = dist[src[i]] + cost[i];
                if(relax >= n){
                    dist[tgt[i]] = 1e12;
                    if(tgt[i] == n){
                        cout << -1;
                        return 0;
                    }
                }
            }
        }
    }

    cout << max(0LL, dist[n]);

    return 0;
}


Measured memory_bytes: 384
// B - Trick or Treat
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,K; cin>>N>>K;
	vi D(K);
	vector<vi> A(K);

	rp(i, 0, K){
		cin>>D[i];
		A[i].resize(D[i]);
		rp(j, 0, D[i]) cin>>A[i][j];
	}

	vi ok(N, 0); // ok=1, ng=0
	rp(i, 0, K) rp(j, 0, D[i]) ok[A[i][j] - 1] = 1;

	ll ans = 0;
	rp(i, 0, N) if(ok[i] == 0) ans++;
	cout<< ans <<endl;
}

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

int main(){
    string s;
    cin >> s;
    vector<int> t(4,0);
    rep(i,s.length()){
        if(s[i] == 'N') t[0] = 1;
        if(s[i] == 'W') t[1] = 1;
        if(s[i] == 'S') t[2] = 1;
        if(s[i] == 'E') t[3] = 1;
    }
    bool can = true;
    if((t[0]^t[2]) || (t[1]^t[3])) can = false;
    cout << (can? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

struct node {
  float x;
  float y;
  float t;
};

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    vector<node> vec(n);
    for (int i = 0; i < n; ++i)
      scanf("%f,%f", &vec[i].x, &vec[i].y);

    sort(vec.begin(), vec.end(),
         [](node const &l, node const &r) { return l.x < r.x; });

    for_each(vec.begin(), vec.end(), [&](node &ele) {
      float x = ele.x - vec[0].x;
      float y = ele.y - vec[0].y;
      ele.t = y / sqrt(x * x + y * y);
    });

    sort(++vec.begin(), vec.end(),
         [](node const &l, node const &r) { return l.t > r.t; });

    vector<node> vec2;
    for (auto &ele : vec) {
      while (2 <= vec2.size()) {
        auto itr1 = vec2.end() - 2;
        auto itr2 = vec2.end() - 1;
        float x1 = itr2->x - itr1->x;
        float y1 = itr2->y - itr1->y;
        float x2 = ele.x - itr1->x;
        float y2 = ele.y - itr1->y;
        if (x1 * y2 - y1 * x2 <= 0)
          break;
        vec2.erase(vec2.end() - 1);
      }
      vec2.push_back(ele);
    }

    cout << vec.size() - vec2.size() << endl;
  }
}


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

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

    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}


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

dp=[100001 for i in range(n+1)]
dp[0]=0

for i in range(1,n+1):
    p=1
    while p<=i:
        dp[i]=min(dp[i],dp[i-p]+1)
        p*=6
    q=1
    while q<=i:
        dp[i]=min(dp[i],dp[i-q]+1)
        q*=9

print(dp[n])

Measured memory_bytes: 3864
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef pair<int,int> P;
struct edge {int to,cap,cost,rev;};
const int MAX_V=6100,INF=1e9;
int V;			//代入!!
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
int top[MAX_V];
int s,t,l,r;
void add_edge(int from, int to, int cap, int cost){
//	printf("%d->%d  cap=%d,cost=%d\n",from,to,cap,cost);
	edge e1={to,cap,cost,G[to].size()},e2={from,0,-cost,G[from].size()};
	G[from].push_back(e1);
	G[to].push_back(e2);
}
int min_cost_flow(int s, int t, int f){
	int res=0;
	fill(h,h+V,0);
	rep(i,V){
		int v=top[i];
		rep(j,G[v].size()){
			edge &e=G[v][j];
			if(e.cap==0) continue;
			int u=e.to;
			h[u]=min(h[u],h[v]+e.cost);
		}
	}
//	rep(i,V) printf("h[%d]=%d\n",i,h[i]);
	while(f>0){
		priority_queue< P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(dist[v]<p.first) continue;
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF) return -1;
		for(int v=0;v<V;v++) h[v]+=dist[v];
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}
int X[3000],T[3000],p[3000];
vector<P> id;
int main(){
	int N,speed,xl,xr;
	scanf("%d%d%d%d",&N,&speed,&xl,&xr);
	rep(i,N) scanf("%d%d%d",X+i,T+i,p+i);
	s=2*N,t=s+1,l=s+2,r=s+3;
	V=r+1;
	rep(i,N){
		id.pb(P(T[i]*2,i));
		id.pb(P(T[i]*2+1,i+N));
	}
	id.pb(P(-2,s));
	id.pb(P(-1,l));
	id.pb(P(-1,r));
	id.pb(P(INF,t));
	sort(all(id));
	rep(i,V) top[i]=id[i].sc;
	rep(i,N) add_edge(i,i+N,1,-p[i]),add_edge(i,i+N,1,0);
	rep(i,N) rep(j,N){
		if(i==j) continue;
		if((T[j]-T[i])*speed>=abs(X[j]-X[i])) add_edge(i+N,j,2,0);
	}
	rep(i,N){
		if(T[i]*speed>=abs(X[i]-xl)) add_edge(l,i,1,0);
		if(T[i]*speed>=abs(X[i]-xr)) add_edge(r,i,1,0);
	}
	rep(i,N) add_edge(i+N,t,2,0);
	add_edge(s,t,2,0);
	add_edge(s,l,1,0);
	add_edge(s,r,1,0);
	cout<<-min_cost_flow(s,t,2)<<endl;
}

Measured memory_bytes: 240364
import fractions
A,B,C,D = map(int,input().split())
g = C * D // fractions.gcd(C,D)
# A
cntA = 0
cntA += (A-1) // C
cntA += (A-1) // D
cntA -= (A-1) // g

# B
cntB = 0
cntB += B // C
cntB += B // D
cntB -= B // g

cnt = cntB - cntA
cnt = (B - A + 1) - cnt

print(cnt)


Measured memory_bytes: 5048
N=int(input())
hyx=[list(map(int,input().split()))[::-1]for _ in range(N)]
R=range(101)
for X in R:
    for Y in R:
        h,y,x=max(hyx)
        H=h+abs(X-x)+abs(Y-y)
        if all(h==max(H-abs(X-x)-abs(Y-y),0)for h,y,x in hyx):
            print(X,Y,H)

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<2||b<2)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<(a-1)*(b-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String[] c;
		c = new String[10000];
		String x = scan.next();
		String mj[] = x.split("");
		int a = scan.nextInt();
		int i,m,b;
		for(i = 1; i <= a; ++i){
			b = 0;
			String str = scan.next();
			int q = scan.nextInt();
			int w = scan.nextInt();
			
			if(str.equals("replace")){
				String e = scan.next();
				String j[] = e.split("");
				for(m = q; m <= w; ++m){
					mj[m] = j[b++];
				}
			}
				else if(str.equals("reverse")){
				for(m = q; m <= w; ++m){
					c[b++] = mj[m];
				}
				b = 0;
				for(m = w; m >= q; --m){
					mj[m] = c[b++];
				}
				}
				else if(str.equals("print")){
				for(m = q; m <= w; ++m){
					System.out.print(mj[m]);
				}
				System.out.println("");
				}
			}
		}
	}

Measured memory_bytes: 34136
from collections import deque
N,K = list(map(int, input().split()))
MOD = int(1e9+7)

l = [[] for i in range(N)]
for i in range(N-1):  #0-originedに注意
  a,b = list(map(int, input().split()))
  l[a-1].append(b-1)
  l[b-1].append(a-1)
#print(l)

pc = [1] * N
pc[0] = 0
  
que = deque()
que.append(0)

ans = K
visited = set()
count = 0
while len(que)>0:
  x = que.pop()
  visited.add(x)
  parent = x
  for p in l[x]:
    if p in visited:
      continue
    #print(parent, p, ans)
    pc[parent] += 1
    ans = ans * (K-pc[parent]) % MOD
    que.append(p)
    
print(ans)

Measured memory_bytes: 36240
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>

using namespace std;
int main() {
	int h, n,sum=0,tmp;
	string ans="No";

	cin >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		sum += tmp;

	}
	if (sum >= h) {
		ans = "Yes";
	}
	
	cout << ans;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string A, B, C;
    cin>>A>>B>>C;
    if(C[0]==B[B.size()-1]&& A[A.size()-1]==B[0]) {
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
-- Vicfred
-- https://atcoder.jp/contests/abc178/tasks/abc178_c
-- math

function binpow(a, b, m)
    a = a % m
    res = 1
    while b > 0 do
        if (b % 2) == 1 then
            res = (res * a) % m
        end
        a = (a * a) % m
        b = b // 2
    end

    return res
end

mod = 1000000007

n = io.read("*n")

ans = binpow(10, n, mod) - binpow(9, n, mod) - binpow(9, n, mod) + binpow(8, n, mod)
ans = ans + mod
ans = ans % mod
print(ans)



Measured memory_bytes: 2760
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
s = sum(a)
f = 1
for i in range(m):
    if a[i]/s < 1/(4*m):
        f = 0
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
N=io.read("n")
t={}
m=0
s=0
for i=1,N do 
  t[i]=io.read("n")
  s=s+t[i]
  if m<t[i] then
    m=t[i]
  end
end
if s-m>m then 
  print("Yes")
  else
  print("No")
end

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >>ty;
  int dx,dy;
  dx=tx-sx;
  dy=ty-sy;
  for(int i=0;i<dx;i++){
    cout << "R";
  }
  for(int i=0;i<dy;i++){
    cout << "U";
  }
  for(int i=0;i<dx;i++){
    cout << "L";
  }
  for(int i=0;i<dy;i++){
    cout << "D";
  }
  cout << "D";
  for(int i=0;i<dx+1;i++){
    cout << "R";
  }
  for(int i=0;i<dy+1;i++){
    cout << "U";
  }
  cout << "L";
  cout << "U";
  for(int i=0;i<dx+1;i++){
    cout << "L";
  }
  for(int i=0;i<dy+1;i++){
    cout << "D";
  }
  cout << "R";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main(){
  FIO;
  // ifstream cin("input");
  ll n,k;
  cin>>n>>k;
  ll a[n+1];
  ll i;
  for(i=1;i<=n;i++){
    cin>>a[i];
  }
  vector<ll> cyclePath;
  ll hashIt[200001];
  for(i=0;i<200001;i++){
    hashIt[i]=0;
  }
  hashIt[1]++;
  i=1;
  while(1){
    hashIt[a[i]]++;
    if(hashIt[a[i]]==2){
      cyclePath.push_back(a[i]);
    }
    if(hashIt[a[i]]==3){
      break;
    }
    i=a[i];
  }
  int destination = cyclePath[0];
  int ans=0;
  i=1;
  vector<int>linearPath;
  while(1){
    if(destination==i){
      break;
    }
    linearPath.push_back(i);
    i=a[i];
    ans++;
  }
  int temp1=k;
  k-=ans;
  if(k<0){
    cout<<linearPath[temp1]<<endl;
    return 0;
  }
  int cycleSize = cyclePath.size();
  int temp= k%cycleSize;
  cout<<cyclePath[temp]<<endl;  
}

Measured memory_bytes: 8324
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False



n = onem()

for i in range(1,10):
    for j in range(1,10):
        if i*j == n:
            print("Yes")
            exit()

print("No")


Measured memory_bytes: 38384
#include <iostream>
 
using namespace std;
 
int
main ()
{
 
  int a = 1;
 
  int b;
  int x;
 
  while (true)
 
    {
     cin >> b, cin >>a;
      if (a > b)
    {
      x = a;
      a = b;
      b = x;
    }
if (a==0 && b == 0) {
    return 0;
}
      cout << a << " " << b << endl;
 
      
}
    }


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


int main(){
	int h,k,d;
	cin>>h>>k;
	int a[h];
	long long c=0;
	for(int i =0 ; i<h ; i++){
		cin>>d;
		a[i]=d;
		}
    sort(a,a+h);
    for(int j=0;j<h-k;j++){
    	c+=a[j];
	}
	if(k>=h){
		cout<<"0";
	}
	else
	cout<<c;
return 0 ;
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 a, b, k;
    cin >> a >> b >> k;
    for (i64 i = 0; i < k; i++) {
        if (i % 2) a += (b /= 2);
        else b += (a /= 2);
    }
    cout << a << " " << b << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second
 
int n, m;
string a[111], b[111];
 
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  REP (i, n) cin >> a[i];
  REP (i, m) cin >> b[i];
  REP (i, n - m + 1) REP (j, n - m + 1) {
  	bool flag = false;
  	REP (ii, m) REP (jj, m) if (b[ii][jj] != a[ii + i][jj + j]) flag = true;
  	if (!flag) {
  		cout << "Yes";
  		return 0;
  	}
  }
  cout << "No";
}

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


int main() {
  string n;
  cin >> n;
  
  int A[stoi(n)];
  for(int i = 0; i < stoi(n); i++) {
    cin >> A[i];
  }
  
  int count = 0;
  
  while(true) {
    
    bool odd = false;
    for(int i = 0; i < stoi(n); i++) {
      if(A[i] % 2 != 0) { odd = true; }
    }
  
    if(odd) { break; }
    
    for(int i = 0; i < stoi(n); i++) {
      A[i] /= 2;
    }
    
    count++;
  
  }
  
  cout << count << endl;
  
}


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

using namespace std;

typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;


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

    vi a(3);
    int k;
    for (int &i:a) cin>>i;
    cin>>k;

    int cnt = 0;
    int id = 0;
    int res = 0;
    while(cnt < k){
        int p = min(a[id],  k - cnt);

        cnt = cnt + p;
        res += (1-id)*p;

        id++;
    }
    cout<<res;

}


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

X = 0
ans = 0
for i in range(40, -1, -1):
    bit = 1 << i
    count = 0
    for a in A:
        if bit & a:
            count += 1
    if N >= count * 2 and (X^bit) <= K:
        X ^= bit
        count = N - count
    ans += count * bit

print(ans)


Measured memory_bytes: 14208
a, b, c, d = [int(_) for _ in input()]

if a+b+c+d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int a,b,c,n,i;
	cin >> n;
	for( i = 0; i < n; i++ ){
		cin >> a >> b >> c;
		if(a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
		
	}
	
	return 0; 
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>
int main(void){
   char s[200];
   int i, j, n, key;
   while ( scanf("%s", s) != EOF) {
       for ( i = 0; i < strlen(s); i++ ) {
           if ( s[i] == '@') {
               i++;
               if ( s[i] == '1') key = 1;
               else if ( s[i] == '2') key = 2;
               else if ( s[i] == '3') key = 3;
               else if ( s[i] == '4') key = 4;
               else if ( s[i] == '5') key = 5;
               else if ( s[i] == '6') key = 6;
               else if ( s[i] == '7') key = 7;
               else if ( s[i] == '8') key = 8;
               else if ( s[i] == '9') key = 9;
               i++;
               for ( j = 0; j < key; j++ ) printf("%c", s[i]);
           }
           else printf("%c", s[i]);
       } 
       printf("\n");
   }
   return 0;
}

Measured memory_bytes: 1816
b = [int(i) for i in "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(",")]
n = int(input())
print(b[n - 1])

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int h = sc.nextInt();
			int w = sc.nextInt();

			if (h == 0 || w == 0) {
				break;
			}

			int map[][] = new int[h][w];
			for(int i = 0 ;i < h ; i++){
				for(int j = 0 ; j < w;  j++){
					map[i][j] = sc.nextInt();
				}
			}
		
			int max = 0;
			for(int d = 1 ;d <= 9 ; d++){
				max = Math.max(findMax(map,d),max);
			}
			System.out.println(max);
		}
	}
	
	int findMax(int[][] map, int d){
		int max = 0;
		for(int i = 1; i < map.length-1; i ++){
			for(int j = 1 ; j < map[0].length-1;j++){
				for(int k = i; k < map.length-1; k++){
					for(int l = j ; l < map[0].length-1;l++){
						int value = makePond(map,i,j,k,l,d);
		//				System.out.println(i+" "+j+" "+k+" "+l+" "+d+" "+value);
						max = Math.max(max, value);
					}
				}
			}
		}
		return max;
	}
	
	int makePond(int map[][],int i,int j, int k,int l,int d){
		int[] x = {i-1,k+1};
		int[] y = {j-1,l+1};
		int res = 0;
		for(int xx : x){
			for(int jj = j -1; jj <= l+1;jj++){
				if(map[xx][jj] < d){
					return 0;
				}
			}
		}
		for(int yy: y){
			for(int ii = i - 1; ii <= k+1; ii++){
				if(map[ii][yy] < d){
					return 0;
				}
			}
		}
		
		for(int ii = i; ii <= k;ii++){
			for(int jj = j ; jj <= l;jj++){
				if(map[ii][jj]>=d){
					return 0;
				}
				res += d-map[ii][jj];
			}
		}
	
		return res;
	}

}



Measured memory_bytes: 60084
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,Q;
int A[200010],B[200010];
int C[200010],X[200010];
int num[200010];
int num2[200010];
bool F[200010];
vector<int> G[200010];

void dfs(int s,int s2){
	F[s]=true;
	s2+=num[s];
	num2[s]=s2;
	REP(i,G[s].size()){
		int e=G[s][i];
		if(F[e]==false){
			dfs(e,s2);
		}
	}
}

signed main(){
	cin>>N>>Q;
	REP(i,N-1){
		cin>>A[i]>>B[i];
	}
	REP(i,Q){
		cin>>C[i]>>X[i];
	}
	REP(i,N-1){
		G[A[i]-1].push_back(B[i]-1);
	}
	REP(i,Q){
		num[C[i]-1]+=X[i];
	}
	dfs(0,0);
	REP(i,N){
		cout<<num2[i];
		if(i<N-1){
			cout<<" ";
		}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 32256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> bs(n-1);
    
    for(int i=0;i<bs.size();i++){
        cin>>bs.at(i);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(i==0)ans+=bs.at(0);
        else if(i==n-1){
            ans+=bs.at(i-1);
        }
        else if(bs.at(i)<=bs.at(i-1)){
            ans+=bs.at(i);
        }else if(bs.at(i)>bs.at(i-1)){
            ans+=bs.at(i-1);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
			#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
			#define endl "\n"

			using namespace std;
	
		int main() {	
			string x; cin >> x;
			bool ok = 0;
			for (int i = 0; i < (int)x.size() - 2; ++i)
				if (x[i] == x[i + 1] && x[i + 1] == x[i + 2]) ok = 1;
			if (ok) cout << "Yes";
			else cout << "No";

			return 0;

			}
	

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define st string
#define pairi pair<int,int>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
		ll n;cin>>n;
		ll arr[n];
		ll m=INT_MIN,x=-1;
		sidha(i,0,n){
			cin>>arr[i];
		}
		ll mx=arr[0];
		ll brr[n];
		brr[0]=arr[0];
		for(int i=0;i<n;i++){
			mx=max(mx,arr[i]);
			brr[i]=max(mx,arr[i]);
			//cout<<brr[i]<<" ";
		}
		//cout<<endl;
		ll sum=0;
		sidha(i,0,n){
			sum+=(brr[i]-arr[i]);
			//cout<<sum<<" ";
		}
		cout<<sum<<endl;
}

Measured memory_bytes: 6764
N = int(input())
S = list(input())

r = S.count('R')
g = S.count('G')
b = S.count('B')

ans = r*g*b

for i in range(0,N):
  for j in range(i,N):
    k = 2*j - i
    if j < k <= N-1:
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans -= 1

print(ans)













Measured memory_bytes: 73748
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint dp[3001][3001], N, arr[3000];
bool flag[3001][3001];

lint dfs(lint l, lint r) {
	if (flag[l][r]) return dp[l][r];
	flag[l][r] = true;
	if (l == r) return dp[l][r] = arr[l];
	return dp[l][r] = max(arr[l] - dfs(l + 1, r), arr[r] - dfs(l, r - 1));
}

int main() {
	cin >> N;
	REP(i, N) {
		cin >> arr[i];
	}
	REP(i, N + 1) REP(j, N + 1) flag[i][j] = false;
	cout << dfs(0, N - 1) << endl;
}


Measured memory_bytes: 58612
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()

	ps := scanInts(n)
	qs := scanInts(n)

	p := 0
	val := 1
	for i := 1; i < n; i++ {
		val*=i
	}
	f := make([]bool, n)
	for i := 0; i < n; i++ {
		c := 0
		for j := 0; j < n; j++ {
			if f[j] {
				continue
			}
			if ps[i]==j+1 {
				f[j] = true
				break
			}
			c++
		}

		p += val*c
		// fmt.Println(p)
		if i == n-1 {
			break
		}
		val/=(n-1-i)
	}

	q := 0
	val = 1
	for i := 1; i < n; i++ {
		val*=i
	}
	f = make([]bool, n)
	for i := 0; i < n; i++ {
		c := 0
		for j := 0; j < n; j++ {
			if f[j] {
				continue
			}
			if qs[i]==j+1 {
				f[j] = true
				break
			}
			c++
		}

		// fmt.Println(c,f)

		q += val*c
		// fmt.Println(q)
		if i == n-1 {
			break
		}
		val/=(n-1-i)
	}

	fmt.Println(abs(p-q))
}

func abs(a int) int {
	if a<0 {
		return -a
	}
	return a
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int N,temp;
	int b,tempb,tempc,ch;
	
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		tempb=0;
		tempc=0;
		ch=0;
		for(int j=0;j<10;j++){
			scanf("%d",&temp);
			if(tempb<temp)
			tempb=temp;
			else if(tempc<temp)
			tempc=temp;
			else{
				ch=1;
			}
		}
		if(ch==0)
		printf("YES\n");
		else
		printf("NO\n");
	}
}

Measured memory_bytes: 3124
from collections import Counter

H, W = map(int, input().split())
c = Counter()
for _ in range(H):
	a = list(input())
	for i in range(W):
		c[a[i]] += 1

ng = False
if H % 2 == 0 and W % 2 == 0:
	for value in c.values():
		if value % 4 != 0:
			ng = True

elif W % 2 == 0:
	two = 0
	for value in c.values():
		if value % 4 != 0:
			if value % 2 != 0:
				ng = True
			else:
				two += 1
	if two > W // 2:
		ng = True

elif H % 2 == 0:
	two = 0
	for value in c.values():
		if value % 4 != 0:
			if value % 2 != 0:
				ng = True
			else:
				two += 1
	if two > H // 2:
		ng = True

else:
	two = 0
	one = 0
	three = 0
	for value in c.values():
		if value % 4 != 0:
			if value % 2 != 0:
				if value % 4 == 1:
					one += 1
				else:
					three += 1
			else:
				two += 1
	if (one+three) > 1:
		ng = True
	elif one:
		if two > H // 2 + W // 2:
			ng = True
	elif three:
		if two+1 > H // 2 + W // 2:
			ng = True

if ng:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 3444
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def main():
    n, k = ns()

    # 使い方
    facts, invs = prepare(n + k - 1, MOD)

    tmp = facts[n + k - 1] * invs[k - 1] * invs[n] % MOD
    print(tmp)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7436
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int[] l = new int[N];
        int[] r = new int[N];
        for (int i = 0; i < N; ++i) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        System.out.println(solve(l, r));

        sc.close();
    }

    static int solve(int[] l, int[] r) {
        return IntStream.range(0, l.length).map(i -> r[i] - l[i] + 1).sum();
    }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

const ll N = 1e5 + 4;

vl g[3 * N], h[3 * N];
bool vis[3 * N];
ll d[3 * N];

int main(){
  fastio

  ll n,m;
  cin >> n >> m;
  ll u,v;
  ll i,j,k;

  forn(0,m,i){
    cin >> u >> v;
    g[u].pb(v + N);
    g[u + N].pb(v + 2 * N);
    g[u + 2 * N].pb(v);
  }
  ll s,t;
  cin >> s >> t;

  fill(d,d + 3 * N, 1e18);

  queue<ll> pq;

  pq.push(s);
  d[s] = 0;
  
  while(!pq.empty()){
    ll u = pq.front();
    pq.pop();
    for(auto x : g[u]){
      if(d[x] > d[u] + 1){
        d[x] = d[u] + 1;
        pq.push(x);
      }
    }
  }

  if(d[t] == 1e18){
    cout << "-1\n";
  }else{
    cout << d[t] / 3 << '\n';
  }


  ktj();
}


Measured memory_bytes: 26368
def resolve():
    import math
    N, D = [int(i) for i in input().split()]
    X = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            sumA = 0
            for k in range(D):
                sumA += (X[j][k] - X[i][k])**2
            if math.sqrt(sumA).is_integer():
                cnt += 1
    print(cnt)


resolve()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main()
{
    int n;
 
 
        cin >> n;
 
        while (n>0)
        {
            if ((n%10)==7)
 
            {
                cout << "Yes"; 
                return 0; 
            }
 
            n = n / 10; 
        }
 
        cout << "No"; 
    return 0;
}

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

int main() {
  string  A,B;
  cin >>A >>B;
  reverse(B.begin(),B.end());
  for(int i=0;i<3;i++){
    if(A.at(i)!=B.at(i)){
      cout <<"NO" <<endl;
      return 0;
    }
  }
  cout <<"YES" <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> d(n,std::vector<ll>(n,MOD));

  std::vector<P> edge(m);

  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    edge[i]={a,b};
    d[a][b]=1;
    d[b][a]=1;
  }

  rep(i,0,n)d[i][i]=0;

  ll ans=0;

  rep(i,0,m){
    std::vector<std::vector<ll>> temp=d;
    temp[edge[i].first][edge[i].second]=MOD;
    temp[edge[i].second][edge[i].first]=MOD;

    rep(j,0,n)rep(k,0,n)rep(l,0,n)chmin(temp[k][l],temp[k][j]+temp[j][l]);

    rep(j,0,n)if(temp[0][j]==MOD){ans++;break;}
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 256