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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  string w[n]; for(int i = 0; i < n; ++i) cin >> w[i];
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++) {
      if(w[i] == w[j]) {
        cout << "No" << endl;
        return 0;
      } else {
        if(w[i].back() != w[i+1].front()) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}




Measured memory_bytes: 256
import sys
from itertools import accumulate

input = sys.stdin.readline


def main():
    n = int(input())
    w_list = [int(i) for i in input().split()]
    sum_ = sum(w_list)
    min_ = None
    for s1 in accumulate(w_list):
        s2 = sum_ - s1
        s12 = abs(s1 - s2)
        if min_ is None:
            min_ = s12
        if s12 <= min_:
            min_ = s12
        else:
            break
    print(min_)


if __name__ == "__main__":
    main()


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

int main(void) {
  long long int fee;
  scanf("%lld", &fee);

  long long int result = 0;
  result += (fee / 500) * 1000;
  fee %= 500;
  result += (fee / 5) * 5;

  printf("%lld\n", result);

  return 0;
}


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

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=max(max(a*c,a*d),max(b*c,b*d));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
N, A, B, C, D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = list(input())
 
ans = 'Yes'
if C < D:
    for i in range(A , D):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
else:
    for i in range(A, C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D + 1):
        if S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.':
            break
    else:
        ans = 'No'
            
print(ans)

Measured memory_bytes: 61424
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

int N;
int a[5][5];
int score[6];

void drop() {
  rep(j, 5) {
    deque<int> d;
    rep(i, 5) {
      if(a[i][j] != -1) {
        d.push_back(a[i][j]);
      }
    }

    int dsize = d.size();
    for(int i=4; i>=0 && !d.empty(); i--) {
      a[i][j] = d.back();
      d.pop_back();
    }
    rep(i, 5-dsize) {
      a[i][j] = -1;
    }
  }
}

int dist(int num, int i, int j, int dy, int dx, int sum = 0) {
  i += dy, j += dx;
  if(!in_range(i, j, 5, 5)) return sum;
  if(a[i][j] != num) return sum;
  return dist(num, i, j, dy, dx, sum + 1);
}

int simulate() {
  int ret = 0;
  int bonus = 1;

  while(1) {
    set<int> used;
    rep(i, 5) rep(j, 5) {
      if(a[i][j] == -1) continue;
      int movel = dist(a[i][j], i, j, 0, -1);
      int mover = dist(a[i][j], i, j, 0, +1);
      int movet = dist(a[i][j], i, j, -1, 0);
      int moveb = dist(a[i][j], i, j, +1, 0);
      if(mover - movel + 1 >= 3) {
        REP(x, j - movel, j + mover + 1) {
          assert(a[i][x] != -1);
          assert(a[i][x] == a[i][j]);
          used.insert(i*5+x);
        }
      }
      if(moveb - movet + 1 >= 3) {
        REP(y, i - movet, i + moveb + 1) {
          assert(a[y][j] != -1);
          assert(a[y][j] == a[i][j]);
          used.insert(y*5+j);
        }
      }
    }

    for(auto && e: used) {
      ret += score[a[e/5][e%5]] * bonus;
      a[e/5][e%5] = -1;
    }

    bonus ++;
    if(!used.size()) break;
    drop();
  }

  return ret;
}



int dfs(int y, int x, int idx = 0) {
  int aa[5][5]; rep(i, 5) rep(j, 5) aa[i][j] = a[i][j];
  int ret = simulate();
  if(idx < N) {
    rep(k, 4) {
      int ny = y + dy[k], nx = x + dx[k];
      if(!in_range(ny, nx, 5, 5)) continue;
      rep(i, 5) rep(j, 5) a[i][j] = aa[i][j];
      swap(a[y][x], a[ny][nx]);
      maximize(ret, dfs(ny, nx, idx + 1));
    }
  }
  rep(i, 5) rep(j, 5) a[i][j] = aa[i][j];
  return ret;
}

int solve() {
  int ret = 0;
  rep(i, 5) rep(j, 5)  {
    maximize(ret, dfs(i, j));
  }
  return ret;
}

int main() {

  for(; cin >> N && N >= 0;) {
    rep(i, 5) rep(j, 5) cin >> a[i][j];
    rep(i, 5) cin >> score[i+1];
    cout << solve() << endl;
  }
  
  return 0;
}

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

using namespace std;

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

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

    int cnt = 0;
    for(int a = 0; a <= A; a++){
        for(int b = 0; b <= B; b++){
            for(int c = 0; c <= C; c++){
                if(a*500 + b*100 + c*50 == X)
                    cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N;

    cin >> N;

    int p[N];

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

    int count = 0;

    for(int i = 1; i < N - 1; i++){
        if(p[i - 1] < p[i] && p[i] < p[i + 1]){
            count++;
        } else if(p[i - 1] > p[i] && p[i] > p[i + 1]){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  math2do
 *    created: 28.03.2020 18:09:18
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector <int> r(a);
  vector <int> g(b);
  vector <int> n(c);
  for (int &val : r) {
    cin >> val;
  }
  for (int &val : g) {
    cin >> val;
  }
  for (int &val : n) {
    cin >> val;
  }

  sort(r.begin(), r.end(), greater<int>());
  sort(g.begin(), g.end(), greater<int>());
  sort(n.begin(), n.end(), greater<int>());

  vector <int> from;
  for (int i = 0; i < x; i++) {
    from.push_back(r[i]); 
  }
  for (int i = 0; i < y; i++) {
    from.push_back(g[i]); 
  }
  for (int i = 0; i < c; i++) {
    from.push_back(n[i]); 
  }
  sort(from.begin(), from.end(), greater <int>());
  long long ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += from[i];
  } 
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
	int A, B;
	int cnt = 0;

	cin >> A >> B;
	for(int i = A; i <= B; i++) {
		bool flag = false;
		string str = to_string(i);
		int left = 0;
		int right = str.size() - 1;
		while(left < right) {
			if(str[left] != str[right]) {
				flag = true;
				break;
			}
			left++;
			right--;
		}
		if(! flag) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] c = new int[m];
		for(int i=0; i<m; i++){
			c[i] = sc.nextInt();
		}
		int[] dp = new int[n+1];
		for(int i=0; i<n+1; i++){
			dp[i] = i;
		}
		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				if(j+1>=c[i]){
					dp[j+1] = Math.min(dp[j+1-c[i]]+1, dp[j+1]);
				}
			}
		}
		System.out.println(dp[n]);
	}
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t h,a;
  cin >> h >> a;
 
  cout << (h+a-1)/a << endl;
  return 0;
}




Measured memory_bytes: 3580
from itertools import permutations

n, m = map(int, input().split())
links = [[0]*n for i in range(n)]
for i in range(m):
        a, b = map(int, input().split())
        links[a-1][b-1] = links[b-1][a-1] = 1

ans = 0
for path in permutations(range(n)):
        if path[0]: continue
        can = 1
        for i in range(n-1):
                if links[path[i]][path[i+1]]==0: can = 0
        ans += can
print(ans)

Measured memory_bytes: 3064
#include <list>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#define INF (1LL << 60)
using namespace std;
bool used[100]; long long dist[100];
void dijkstra(int V, int E, int s, vector<pair<int, long long> > X[]) {
	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q;
	for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
	dist[s] = 0; Q.push(make_pair(0, s));
	int cnt = 0;
	while (!Q.empty()) {
		if (cnt > E) return; // NEGATIVE_CYCLE
		pair<long long, int> p = Q.top(); used[p.second] = true; Q.pop();
		for (int i = 0; i < X[p.second].size(); i++) {
			int to = X[p.second][i].first; long long leng = X[p.second][i].second;
			if (dist[to] > dist[p.second] + leng && !used[to]) {
				dist[to] = dist[p.second] + leng;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
}
int n, m, q, a, b, c, u, v, w1, w2; vector<pair<int, long long> > G1[100], G2[100];
int main() {
	while(cin >> n >> m, n) {
		for(int i = 0; i < m; i++) G1[i].clear(), G2[i].clear();
		for(int i = 0; i < n; i++) {
			cin >> u >> v >> w1 >> w2; u--, v--;
			G1[u].push_back(make_pair(v, w1));
			G1[v].push_back(make_pair(u, w1));
			G2[u].push_back(make_pair(v, w2));
			G2[v].push_back(make_pair(u, w2));
		}
		cin >> q;
		for(int i = 0; i < q; i++) {
			cin >> a >> b >> c; a--, b--;
			if(c == 0) {
				dijkstra(m, n, a, G1);
				cout << dist[b] << endl;
			}
			else {
				dijkstra(m, n, a, G2);
				cout << dist[b] << endl;
			}
		}
	}
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,l;
  cin>>n>>l;
  vector<Int> v(n),w(n),m(n);
  for(Int i=0;i<n;i++)
    cin>>v[i]>>w[i]>>m[i];

  const Int x=50;
  const Int INF = 1e15;
  vector<Int> dp(n*x*x+1,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++){
    Int s=min(m[i],x);
    m[i]-=s;
    for(Int k=1;;k<<=1){
      chmin(k,s);
      if(!k) break;
      for(Int j=n*x*x;j>=0;j--)
	if(j+k*v[i]<=n*x*x) chmin(dp[j+k*v[i]],dp[j]+k*w[i]);	
      s-=k;      
    }
  }

  vector<Int> ord(n);
  iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](Int a,Int b){
      return v[a]*w[b]>v[b]*w[a];
    });

  Int ans=0;
  for(Int j=0;j<=n*x*x;j++){
    Int lim=l-dp[j];
    if(lim<0) continue;
    Int res=j;
    for(Int i=0;i<n;i++){
      Int k=ord[i];
      Int c=min(m[k],lim/w[k]);
      lim-=w[k]*c;
      res+=v[k]*c;      
    }
    chmax(ans,res);
  }
  
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3884
//In the name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
const bool DEBUG = false;
#define cerr if(DEBUG)cerr
using namespace std;

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

const long long maxn = 2e5 + 5;
const long long INF = 1e18 + 1;
const long long M = 1e9 + 7;
const int lg = 21;

ll n, m;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	if(n > m)
		swap(n, m);
	if(n == 1){
		if(m == 1) return cout << 1 << endl, 0;
		if(m == 2) return cout << 0 << endl, 0;
		return cout << m - 2 << endl, 0;
	}
	if(n == 2) return cout << 0 << endl, 0;
	ll ans = (n - 2) * (m - 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np
import sys
# 距離K以内にxが居ない
# xからの距離を測る

buf = sys.stdin.buffer
R,C = map(int,buf.readline().split())
black = np.zeros((R+2,C+2),dtype=np.bool)
black[1:-1,1:] = (np.frombuffer(buf.read(R*(C+1)),dtype='S1') == b'#').reshape(R,C+1)

INF = 10 ** 9
dist = np.zeros((R,C),dtype=np.int32)
dist[~black[1:-1,1:-1]] = INF

for n in range(1,R):
  np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(R-2,-1,-1):
  np.minimum(dist[n+1]+1,dist[n],out=dist[n])

for n in range(1,C):
  np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(C-2,-1,-1):
  np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

answer = dist.max()
print(answer)


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 3 * n) cin >> a[i];

    sort(all(a));
    reverse(all(a));

    ll ans = 0;
    for (int i = 1; i <= 2 * n; i += 2)
    {
        ans += a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> v(Q);
	REP(i, Q) cin >> v[i];
	vector<int> ans(N+1, K-Q);

	REP(i, Q) ans[v[i]]++;
	REP(i, N){
		if(ans[i+1] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 1408
#include<iostream>
#include<stack>
using namespace std;
int n;
stack<int>st;
int main(){
  while(cin>>n){
    if(n==0){
      cout<<st.top()<<endl;
      st.pop();
    }else{
      st.push(n);
    }    
  }
  return 0;
}

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

int main(){
  int n,h,m,s;
  cin >> n ;
  h = n / 3600;
  m = (n % 3600) / 60;
  s = (n % 3600) % 60;

  cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3112
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for i in range(N)]

ans = float('inf')
for i in range(2**N):
    bit = str(bin(i))[2:].zfill(N)
    result = [0] * M
    cost = 0
    for j in range(N):
        if bit[j] == '1':
            C = CA[j][0]
            A = CA[j][1:]
            cost += C
            for k in range(M):
                result[k] += A[k]
    ok = True
    for j in range(M):
        if result[j] < X:
            ok = False
            break
    if ok:
        ans = min(ans, cost)

if ans == float('inf'):
    print(-1)
else:
    print(ans)

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

int main() {
    int r;
    cin >> r;
    cout << r*r;


}

/*



 */


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

using namespace std;

int main()
{
  int n;
  scanf("%d", &n);
  int sum = 0;
  for(int i = 3; i > 0; n /= 10, i--){
    sum += n % 10;
  }
  printf("%d\n", sum);
  return 0;
}

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

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    bool pok = true;
    rep(i,n-1) {
        if (a[i] > a[i+1]) {
            pok = false;
            break;
        }
    }
    if (pok) {
        cout << "YES" << endl;
        return 0;
    }
    rep(i,n) rep(j,i) {
        vector<int> tmp(n);
        rep(k,n) tmp[k] = a[k];
        swap(tmp[i],tmp[j]);
        bool ok = true;
        rep(k,n-1) {
            if (tmp[k] > tmp[k+1]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    int N;
    vector<int> A, B, C;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        A.push_back(x);
    }
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        B.push_back(x);
    }
    for (int i = 0; i < N - 1; i++) {
        int x;
        cin >> x;
        C.push_back(x);
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += B[i];
        if (i < (N-1) && A[i+1] - A[i] == 1) {
            sum += C[A[i] - 1];
        }
    }
    cout << sum << endl;
    return 0;
    
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.Char

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [n] <- getIntegers
  ; if n == 0 then return ()
    else do
      { print (sum (map digitToInt (show n)))
      ; loop
      }
  }

--
getIntegers :: IO [Integer]
getIntegers = map read . words <$> getLine

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int a,b;

int main() {
    string ans;
    cin >> a >> b;

    if (a <= 8 && b <= 8)
        ans = "Yay!";
    else
        ans = ":(";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.split('')


result = 0
br = false

s.each do |x|
  if x == 'R' && br == true
    br = true
    result += 1
  elsif br == false && x == 'R'
    result = 1
    br = true
  else
    br = false 
  end
end

puts result

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;
const int MAX_M = 212345;
int D[MAX_N];
int W[MAX_M];
int C[MAX_N];

struct E {
  int id;
  int from, to;
};

vector<E> g[MAX_N];


void dfs(int cur, int next_color, int prev) {
  if (C[cur] != 0) return;
  C[cur] = next_color;
  for (E e : g[cur]) if (e.to != prev && W[e.id] >= 0) {
    dfs(e.to, -next_color, cur);
  }
}

int main2() {
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  int M = nextInt();
  REP(i, N) D[i] = nextInt();
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back((E){i, a, b});
    g[b].push_back((E){i, b, a});
  }

  CLR(W, -1);


  bool possible = true;
  REP(i, N) {
    sort(ALL(g[i]), [](const E&a, const E&b){
      if (D[a.to] != D[b.to]) return D[a.to] < D[b.to];
      return a.to < b.to;
    });
    E e = g[i][0];
    W[e.id] = D[i];

    if (D[e.to] > D[i]) possible = false;
  }

  if (!possible) {
    cout << -1 << endl;
    return 0;
  }

  CLR(C, 0);

  REP(i, N) {
    dfs(i, 1, -1);
  }
  REP(i, N) cout << (C[i] == 1 ? "B":"W"); cout << endl;
  REP(i, M) {
    if (W[i] < 0) W[i] = 1000000000;
    cout << W[i] << endl;
  }
  return 0;
}

int main() {

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


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 5e5 + 5;
ll st[N * 4][26], a[26];
void upd(ll type, ll k, ll l, ll r, ll x, ll val){
        if (x > r || x < l) return;
        if (l == r){
                st[k][type] = val;
                return;
        }
        ll mid = (l + r) >> 1;
        upd(type, k << 1, l, mid, x, val);
        upd(type, k << 1 | 1, mid + 1, r, x, val);
        st[k][type] = 0;
        st[k][type] |= st[k << 1][type];
        st[k][type] |= st[k << 1 | 1][type];
}
void get(ll k, ll l, ll r, ll x, ll y){
        if (x > r || y < l) return;
        if (x <= l && y >= r) {
                for (int i = 0; i < 26; i++) a[i] |= st[k][i];
                return;
        }
        ll mid = (l + r) >> 1;
        get(k << 1, l, mid, x, y);
        get(k << 1 | 1, mid + 1, r, x, y);
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        string s;
        cin >> s;
        ll q;
        cin >> q;
        s = " " + s;
        for (int i = 1; i <= n; i++){
                upd(s[i] - 'a', 1, 1, n, i, 1);
        }
        for (int i = 1; i <= q; i++){
                ll task;
                cin >> task;
                if (task == 1){
                        ll x;
                        char y;
                        cin >> x >> y;
                        upd(s[x] - 'a', 1, 1, n, x, 0);
                        s[x] = y;
                        upd(s[x] - 'a', 1, 1, n, x, 1);
                } else {
                        ll l, r;
                        cin >> l >> r;
                        for (int i = 0; i < 26; i++) a[i] = 0;
                        get(1, 1, n, l, r);
                        ll cnt = 0;
                        for (int i = 0; i < 26; i++) if (a[i] == 1) cnt++;
                        cout << cnt << endl;
                }
        }
}


Measured memory_bytes: 215984
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

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

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> p(N); rep(i, 0, N) {
		cin >> p[i];
	}
	vector<int> s = p;
	sort(all(s));
	if (s == p) {
		cout << "YES" << endl;
		return 0;
	}
	rep(i, 0, N)rep(j, i + 1, N) {
		vector<int> p2 = p;
		swap(p2[i], p2[j]);
		if (s == p2) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

tmp = h[0]
cnt = 0
lis = []

for i in range(1, n):
    if h[i] <= tmp:
        cnt += 1
        tmp = h[i]
    else:
        lis.append(cnt)
        cnt = 0
        tmp = h[i]
lis.append(cnt)
print(max(lis))

Measured memory_bytes: 63856
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



ll A, B, C, X, Y;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B >> C >> X >> Y;
    
    ll ans = infl;
    rep(ab, 0, 201010) {
        ll sm = C * ab;

        ll x = X - ab / 2;
        ll y = Y - ab / 2;

        if (0 < x) sm += x * A;
        if (0 < y) sm += y * B;

        chmin(ans, sm);
    }

    cout << ans << endl;
}

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

int main(){
    int n; cin >> n;
    int k; cin >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t; cin >> t;

    vector<vector<int>> dp(n+1, vector<int>(3));
    ll sum = 0;

    vector<bool> skip(n+1, false);
    for(int i=0; i<n-k; i++){
        if(t.at(i)==t.at(i+k) && skip.at(i)==false) skip.at(i+k) = true; 
    }

    //rep(i, n) cout << skip.at(i);

    for(int i=0; i<n; i++){
        if(t.at(i)=='r' && skip.at(i)==false) sum+=p;
        else if(t.at(i)=='p' && skip.at(i)==false) sum+=s;
        else if(t.at(i)=='s' && skip.at(i)==false) sum+=r;
    }

    //cout << endl;
    cout << sum << endl;
} 

Measured memory_bytes: 5888
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <math.h>

#define lli long long int
#define ld long double
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{
    lli n;
    cin>>n;
    lli a[n];
    for(int i = 0; i < n; i ++) cin>>a[i];
    sort(a, a + n);
    bool ok = 0;
    for(int i = 1;i  <n; i ++) {
        if(a[i] == a[i - 1])
            ok = 1;
    }
    if(ok)
        cout<<"NO";
    else
        cout<<"YES";
    cout<<'\n';
    return ;
}



/*
*/

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

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


Measured memory_bytes: 1792
/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
 
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define tr cout<<"\n" 
#define br break
#define all(v) v.begin(),v.end()
#define inf 100005
#define ff first
#define ss second
#define br break
using namespace std;
/*  I know I have that Ability, I can do anything, 
I'll be The _Candidate Master_ 
(Patience and Practice)  */

void Waheguru()
{
    int n;
    cin>>n;
    F(i,n)cout<<"ACL";
    tr;




}
 
 
 
int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    vector<bool> good(N, true);
    rep(i, N)
        cin >> H[i];

    int A, B;
    rep(i, M) {
        cin >> A >> B;
        if(H[A-1] == H[B-1]) {
            good[A-1] = false;
            good[B-1] = false;
            continue;
        }
        if(H[B-1] > H[A-1])
            swap(A, B);
        good[B-1] = false;
    }
    int ret = 0;
    rep(i, N) {
        if(good[i])
            ret++;
    }
    cout << ret << endl;

    return 0;
}


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

using namespace std;

#define int long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define MAX_K 200000
typedef pair< int,pair<int,pair<int, int> > > P3;
typedef pair<int, pair<int, int> > P2;
typedef pair<int, int> P1;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int W1,H1,W2,H2,R;
int sx1,sy1,sx2,sy2;
int fe1[550][550],fe2[550][550];
vector<int> V;
vector<int> S;
map<int,int> level[2];
int ans=INF;
int visit[550][550];

void input(int* W,int* H,int* sx,int* sy,int fe[550][550]){
    scanf("%d%d%d%d",W,H,sx,sy);
    for(int y=0;y<*H;++y)
        for(int x=0;x<*W;++x)scanf("%d",&fe[y][x]);
}

void bfs(int num,int W,int H,int sx,int sy,int fe[550][550]){
    memset(visit,0,sizeof(visit));
    priority_queue<P2,vector<P2>,greater<P2> > que;
    que.push(P2(fe[sy-1][sx-1],P1(sx-1,sy-1)));
    while(!que.empty()){
        P2 p = que.top();
        que.pop();
        int cost=p.first;
        int x=p.second.first;
        int y=p.second.second;
        if(visit[y][x]==1)continue;
        visit[y][x]=1;
        level[num][cost]++;
        for(int i=0;i<4;++i){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||nx>=W||ny<0||ny>=H)continue;
            int maxcost=max(cost,fe[ny][nx]);
            que.push(P2(maxcost,P1(nx,ny)));
        }
    }
}

signed main(){
    while(1){
        cin>>R;
        if(R==0)break;
        input(&W1,&H1,&sx1,&sy1,fe1);
        input(&W2,&H2,&sx2,&sy2,fe2);
        bfs(0,W1,H1,sx1,sy1,fe1);
        bfs(1,W2,H2,sx2,sy2,fe2);

        int sum1=0;

        for(map<int,int>::iterator i=level[0].begin();i!=level[0].end();++i){
            S.PB(i->first);
            V.PB(i->second+sum1);
            sum1+=i->second;
        }

        int sum2=0;
        level[0][0]=0;
        level[1][0]=0;
        for(map<int,int>::iterator i=level[1].begin();i!=level[1].end();++i){
            int cost = i->first;
            int cnt2 = i->second+sum2;
            int cnt1 = *lower_bound(V.begin(),V.end(),R-cnt2);
            ans=min(ans,cost+S[lower_bound(V.begin(),V.end(),R-cnt2)-V.begin()]);
            sum2+=i->second;
        }

        cout<<ans<<endl;
        ans=INF;
        V.clear();
        S.clear();
        level[0].clear();
        level[1].clear();
    }
}

Measured memory_bytes: 26644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> ans;
vector<vector<int>> tree;
vector<ll> a;
ll N; 
const int INF =1001001001;
const int MAXN = 2*(1e5) +5;
ll dp[MAXN];

void dfs(int t,int p){
    int i = lower_bound(dp, dp+MAXN, a[t]) - dp;
    int old = dp[i];
    dp[i] = a[t];
    ans[t] = i;
    if(p>=0){
         ans[t] = max(ans[t],ans[p]);
    }
   
    // cerr << "ans=" <<ans[t] << endl;
   
    for(int child:tree[t]){
        if(child ==p){
            continue;
        }
        dfs(child,t);
    }
    dp[i] = old;
}


int main(){
    scanf("%lld",&N);
    ans.resize(N);
    a.resize(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    tree.resize(N);
    cerr <<"a"  << endl;
    for(int i = 0 ; i < N-1 ; i++){
        int u,v;
        cin >> u >>v;
        --u;--v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    for(ll i=0;i<MAXN;i++){
        dp[i] = INF;
    }
    cerr <<"do dfs" << endl;
    dp[0] = -INF;
    dfs(0,-1);
    for(int i=0;i<N;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

ll ans;
ll N, K;
PLL a[100005];

void solve() {
	ll cnt = 0, i = 0;
	sort(a, a + N);
	for (i = 0; i < N && cnt + a[i].second < K; i++) {
		cnt += a[i].second;
	}
	ans = a[i].first;
	cout << ans << endl;
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a[i].first >> a[i].second;
	}
	solve();
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> line = new ArrayList<>();
		while (sc.hasNext()) {
			line.add(sc.nextInt());
		}
		sc.close();

		int result = 0;

		for (int index = 1 ; index <= n ; index++) {
			int target = 0;
			for (int i = 0 ; i < index ; i++) {
				target = target + line.get(i);
			}
			for (int k = 2 * n - 1 ; k >= n + index - 1 ; k--) {
				target = target + line.get(k);
			}
			if (result <= target) {
				result = target;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 23508
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 3010;
int A[maxn]; LL dp[maxn][maxn][2];

LL dfs(const int i, const int j, const int k)
{
    if (i > j)
        return 0;
    LL& ans = dp[i][j][k];
    if (-1 == ans) {
        const LL a = dfs(i+1,j,k^1) + A[i]*(k?-1:1);
        const LL b = dfs(i,j-1,k^1) + A[j]*(k?-1:1);
        ans = k ? min(a,b) : max(a,b);
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n)
            cin >> A[i];
        cout << dfs(0,n-1,0) << endl;
    }
    return 0;
}


Measured memory_bytes: 142080
#include <stdio.h>

int 
main(){
	long int H,N,Ai;
	long int All,i;
	All=0;
	scanf("%ld%ld",&H,&N);
	
	for(i=0;i<N;i++){
		scanf("%ld",&Ai);
		All += Ai;
		if(All>=H){
			printf("Yes\n");
			return 0;
		}
	}
	
	printf("No\n");
		
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; 
  string s,t;
  cin >>n >>s >>t;
  for(int i = n; 0<=i; i--){
    if(s.substr(n-i)==t.substr(0,i)){
      int ans = 2*n-i;
      cout << ans << endl;
      return 0;
    }
  }
  return 0; 
}

Measured memory_bytes: 3580
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret


def bunsu(n):
    ret = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = 0
            while (True):
                if n % i == 0:
                    tmp += 1
                    n //= i
                else:
                    break
            ret.append((i, tmp))

    ret.append((n, 1))
    return ret

MOD = 998244353
def solve():
    n = getN()
    nums = getList()

    if 0 in nums:
        print(0)
        return
    ans = 1
    for num in nums:
        ans *= num
        if ans > 10 ** 18:
            print(-1)
            return

    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Measured memory_bytes: 86908
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll mod = 1000000007;
ll money[1005];
int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	vector<vector<ll>>a(n);
	for (int i = 0; i < n; i++) {
		cin >> money[i];
		a[i].resize(m);
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	
	ll ans = mod;
	for (int bit = 0; bit < (1 << n); bit++) {
		ll sum = 0;
		vector<ll>alg(m, 0);
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				sum += money[i];
				for (int j = 0; j < m; j++) {
					alg[j] += a[i][j];
				}
			}
		}
		ll check = 0;
		for (int i = 0; i < m; i++) {
			if (alg[i] >= x) {
				check++;
			}
		}
		if (check == m) {
			ans = min(ans, sum);
		}
	}
	if (ans == mod) {
		cout << "-1" << endl;
		return 0;
	}
	cout << ans << endl;

}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
int ctoi(char a) {
	return (int)a - '0';
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m;
int a[100001];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		a[x]++; a[y]++;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] % 2 == 1) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	getchar(); getchar();
}


Measured memory_bytes: 1024
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local N = read.n()
if N <= 999 then
    print("ABC")
else
    print("ABD")
end


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

int main(void) {
	int n, com, x;
	set<int> s;
	scanf("%d", &n);
	while (n--) {
		scanf("%d %d", &com, &x);
		if (com == 0) {
			s.insert(x);
			printf("%d\n", s.size());
		} else {
			if (s.find(x) != s.end())
				printf("1\n");
			else 
				printf("0\n");
		}
	}	
}


Measured memory_bytes: 12572
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

int main()
{
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<long long> s(A);
	vector<long long> t(B);
	vector<long long> x(Q);

	for (auto i = 0; i < A; ++i)
	{
		cin >> s[i];
	}
	for (auto i = 0; i < B; ++i)
	{
		cin >> t[i];
	}
	for (auto i = 0; i < Q; ++i)
	{
		cin >> x[i];
	}

	auto search = [](vector<long long>& list, long long start, long long& west, long long& east)
	{
		auto last = list.size() - 1;
		if (start < list[0])
		{
			west = -1;
			east = list[0];
			return;
		}
		if (start > list[last])
		{
			west = list[last];
			east = -1;
			return;
		}

		auto iter = lower_bound(list.begin(), list.end(), start);
		west = *(iter - 1);
		east = *iter;
	};

	for (auto i = 0; i < Q; ++i)
	{
		long long sWest, sEast, tWest, tEast;
		auto start = x[i];
		search(s, start, sWest, sEast);
		search(t, start, tWest, tEast);

		long long len = 1e11;
		if (sWest >= 0)
		{
			if (tWest >= 0)
			{
				len = min(len, start - min(sWest, tWest));
			}
			if(tEast >= 0)
			{
				len = min(len, tEast - sWest + min(tEast - start, start - sWest));
			}
		}
		if (sEast >= 0)
		{
			if (tWest >= 0)
			{
				len = min(len, sEast - tWest + min(sEast - start, start - tWest));
			}
			if (tEast >= 0)
			{
				len = min(len, max(sEast, tEast) - start);
			}
		}

		cout << len << endl;
	}

	return 0;
}


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

long long a[200100] = {};

int main ()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a+n);
    long long sum = 0;
    for (int i = n-1; i>= 0; i--) {
        if (k > 0) {
            a[i] = 0;
            k--;
        } else {
            sum += a[i];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1792