akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(ll i = 0; i<n; i++)
#define rep_s(i, start, n) for(ll i= start;  i<n; i++)
#define rep_down(i, n) for(ll i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(ll i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
#define print(ans) cout << ans << endl;
#define MOD 1000000007
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
 
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;
 
}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];
 
void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}
 
ll keta_num(ll num){
  ll total = 0;
  while(num){
    num /= 10;
    total++;
  }
}
 
 
ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}
 
bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}
 
ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
 
ll fibonacchi(ll num){
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while(count<num){
    f2 = f0+f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
 
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
 
int main(void){
  ll N, K, A, B;
  string S, T;
  cin >>A>> B;
  
  cout << A*B << endl;
 
 
}

Measured memory_bytes: 3620
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

inline int getPrice(int p, int x){ return p * (100 + x) / 100; }

int main()
{
  int x, y, s;
  while (x = in(), y = in(), s = in()){
    int maxi = 0;
    for (int i = 1; i < s; i++){
      for (int j = 1; j < s; j++){
        if (getPrice(i, x) + getPrice(j, x) == s){
          maxi = max(maxi, getPrice(i, y) + getPrice(j, y));
        }
      }
    }
    cout << maxi << endl;
  }

  return 0;
}

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

#define A first
#define B second

const int MAXN = 100005;

vector<pii> g[MAXN];
ll d[MAXN], n, sz[MAXN], c1 = -1, c2 = -1;

void dfs(int v, int f = -1) {
    sz[v] = 1;
    for (pii u : g[v]) {
        if (u.A != f) {
            dfs(u.A, v);
            sz[v] += sz[u.A];
        }
    }

    bool z = 1;
    for (pii u : g[v])
        if (u.A != f && sz[u.A] > n/2)
            z = 0;
    if (n-sz[v] > n/2)
        z = 0;
    if (z) {
        if (c1 == -1)
            c1 = v;
        else
            c2 = v;
    }
}

void dfsd(int v, int f = -1) {
    for (pii u : g[v])
        if (u.A != f) {
            d[u.A] = u.B + d[v];
            dfsd(u.A, v);
        }
}

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

    for (int i = 0; i < n-1; ++i) {
        int a, b, w;
        cin >> a >> b >> w;
        a--; b--;
        g[a].push_back(pii(b, w));
        g[b].push_back(pii(a, w));
    }

    dfs(0);
    if (c2 != -1) {
        ll dist = -1;
        for (pii u : g[c1])
            if (u.A == c2)
                dist = u.B;
        dfsd(c1, c2);
        dfsd(c2, c1);
        ll ans = 0;
        for (int i = 0; i < n; ++i)
            ans += 2*d[i];
        cout << ans + (n-1)*dist << endl;
    } else {
        dfsd(c1, -1);
        ll dist = (1LL<<60);
        for (pii u : g[c1])
            dist = min(dist, u.B);
        ll ans = 0;

        for (int i = 0; i < n; ++i)
            ans += 2*d[i];
        cout << ans - dist << endl;
    }
}

Measured memory_bytes: 17408
n,a = map(int,input().split())

X = [int(i)-a for i in input().split()]
dp = [[0]*(100*n+1) for i in range(n+1)]
dp[0][50*n] = 1

for i in range(n):
    for j in range(50,100*n+1-50):
        dp[i+1][j] = dp[i][j]+dp[i][j-X[i]]

print(dp[n][50*n]-1)

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int maxn = 2e5+10;

int v[maxn];

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>v[i];
	}
	int tot=0;
	for(int i=1,j=1;i<=n;++i){
		if(v[i]==j){
			++j;
			++tot;
		}
	}
	if(tot==0){
		cout<<-1<<endl;
	}
	else{
		cout<<n-tot<<endl;
	}
	return 0;
}

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

#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)

using ll = long long;
#define INF 1e9

ll N;
vector<ll> L, R;
vector<pair<ll, ll>> LR, ruis, rruis;

bool cmp(const pair<ll, ll> l, const pair<ll, ll> r){
  if(l.first != r.first){
    return l.first < r.first;
  }
  return l.second < r.second;
}
int main(){ 
  cin >> N;
  L.resize(N), R.resize(N), LR.resize(N);
  ll maxd = 0;
  REP(i, N){
    cin >> L[i] >> R[i];
    LR[i] = {L[i], R[i]};
    maxd = max(maxd, R[i] - L[i] + 1);
  }
  sort(LR.begin(), LR.end(), cmp);
  ruis.resize(N), rruis.resize(N);
  ruis[0] = LR[0], rruis[N-1] = LR[N-1];
  FOR(i, 1, N){
    ll l = max(ruis[i-1].first, LR[i].first), r = min(ruis[i-1].second, LR[i].second);
    ruis[i] = {l,r};
  }
  for(int i = N-2; i >= 0; i--){
    ll l = max(rruis[i+1].first, LR[i].first), r = min(rruis[i+1].second, LR[i].second);
    rruis[i] = {l, r};
  }
  ll ans = 0;
  // REP(i, N){
  //   cout << ruis[i].first << " " << ruis[i].second << " " << ruis[i].second - ruis[i].first+1 << " " << rruis[i].first << " " << rruis[i].second << " " << rruis[i].second - rruis[i].first + 1 << endl;
  // }
  REP(i, N-1){
    if(ruis[i].first > ruis[i].second) continue;
    if(rruis[i+1].first > rruis[i+1].second) continue;
    ll fun = ruis[i].second - ruis[i].first + 1 + rruis[i+1].second - rruis[i+1].first + 1;
    // int first = ruis[i].second - ruis[i].first + 1, second = rruis[i+1].second - rruis[i+1].first + 1;
    // cout << "i:" << i << " fun: " << fun << " first: " << first << " second: " << second << endl;
    ans = max(ans, fun);
  }
  ans = max(ans, LR[0].second - LR[0].first + 1 + rruis[1].second - rruis[1].first + 1);
  ans = max(ans, LR[N-1].second - LR[N-1].first + 1 + ruis[N-2].second - ruis[N-2].first + 1);
  FOR(i, 1, N-1){
    ll fun = LR[i].second - LR[i].first + 1;
    ll l = max(ruis[i-1].first, rruis[i+1].first), r = min(ruis[i-1].second, rruis[i+1].second);
    if(l > r) continue;
    fun += r - l + 1;
    ans = max(ans, fun);
  }
  cout << max(ans, maxd) << endl;
}


Measured memory_bytes: 6528
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, K; cin >> N >> K;
    unordered_map<int, int> ht_valNum;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        ++ht_valNum[ a ];
    }
    if((int)ht_valNum.size() <= K){ cout << 0 << endl; return 0; }
    
    vector<int> vNum;
    for(auto itr=ht_valNum.begin(); itr!=ht_valNum.end(); ++itr){
        vNum.push_back( itr->second );
    }
    sort(vNum.begin(), vNum.end());
    
    int sum=0;
    for(int i=0; i<(int)vNum.size()-K; ++i){
        sum += vNum[i];
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 10312
package main

import (
	"container/heap"
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var N, M int
	fmt.Scanf("%d %d\n", &N, &M)

	points := make([]QS, M+1)
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		if a > M {
			continue
		}
		points[a] = append(points[a], &Q{value: b, a: a, b: b})
	}
	sum := 0

	queue := QS{}
	heap.Init(&queue)
	for i := 1; i <= M; i++ {
		for _, p := range points[i] {
			heap.Push(&queue, p)
		}

		if queue.Len() == 0 {
			continue
		}
		q := heap.Pop(&queue).(*Q)
		sum += q.value
	}
	fmt.Println(sum)

}


Measured memory_bytes: 16128
h, w = map(int, input().split())

lall = list()
for i in range(h):
    l = list(input())
    if l != ["."] * w:
        lall.append(l)

for i in range(w):
    j = 0
    while j < len(lall) and i < len(lall[j]) and lall[j][i] == ".":
        j += 1
        if j == len(lall):
            for k in range(len(lall)):
                lall[k][i] = "0"
            break    

for i in range(len(lall)):
    print(''.join([j for j in lall[i] if j != "0"]))


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){cout << "Yes" << endl;}
inline void No(){cout << "No" << endl;}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){cout << "YES" << endl;}
inline void NO(){cout << "NO" << endl;}
inline void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    
    int n, m;
    scanf("%d%d", &n, &m);  
    ppp(max(0, n-m*2)); 
    
    
    
    return 0;
}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A+B<C+D){
    cout << "Right" << endl;
  }
  else if(A+B>C+D){
    cout << "Left" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){  
  int s;
  cin >> s;
  if(s<105){ cout << 0 << endl; return 0;}
  if(s<135){ cout << 1 << endl; return 0;}
  if(s<165){ cout << 2 << endl; return 0;}
  if(s<189){ cout << 3 << endl; return 0;}
  if(s<195){ cout << 4 << endl; return 0;}
  if(s<=200){ cout << 5 << endl; return 0;}
  return 0;
}

Measured memory_bytes: 256
n,l = gets.split(" ").map(&:to_i)
ary = []

n.times do |i|
  ary.push(str=gets.chomp)
end

ary.sort! do |a, b|
  ret = a.casecmp(b)
  ret == 0 ? a <=> b : ret
end

puts ary.join("")


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  string A,B,C;cin>>A>>B>>C;
  queue<char> sa,sb,sc;
  int n =A.size(),m=B.size(),l=C.size();
  rep(i,A.size()){
    sa.push(A[i]);
  }
  rep(i,B.size()){
    sb.push(B[i]);
  }
  rep(i,C.size()){
    sc.push(C[i]);
  }
  char win ='A';
  char now ='a';
  now= sa.front();
  while(1){
    if(now=='a'){
      if(sa.empty()){
        win ='A';
        break;   
      }
      now=sa.front();sa.pop();
          
    }
    else if(now=='b'){
      if(sb.empty()){
        win='B';
        break;
      }
      now=sb.front();sb.pop();
    

    }
    else if(now=='c'){
      if(sc.empty()){
        win='C';
        break;
      }
      now=sc.front();sc.pop();
   
      
    }
    
  }
  cout<<win<<endl;
}



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

int max(int a,int b)
{
	if (a>=b)
	{
		return a;
	}	
	
	else
	{
		return b;
	}
}

int main()
{	
	char a1[100][11],a2[100][11],a3[11];
	int result=0,j,n,m,i,res=0;
	
	for (i=0;i<100;i++)
	{
		strcpy(a1[i],"##########");
		strcpy(a2[i],"##########");
	}
	
	while (scanf("%d",&n)==1)
	{
		for (i=0;i<n;i++)
		{
			scanf("%s",a1[i]);
		}
		
		scanf("%d",&m);
		
		for (i=0;i<m;i++)
		{
			scanf("%s",a2[i]);
		}
		
		for (i=0;i<n;i++)
		{
			result=0;
			
			if (strcmp(a1[i],"##########")==0)
			{
				break;
			}
			
			strcpy(a3,a1[i]);
			
			for (j=0;j<n;j++)
			{
				if (strcmp(a3,a1[j])==0)
				{
					result++;
				}
			}
			
			for (j=0;j<m;j++)
			{
				if (strcmp(a3,a2[j])==0)
				{
					result--;
				}
			}
			
			if (result>=res)
			{
				res=result;
			}
			
		}
		
		printf("%d",res);
		res=0;
		
//		for (i=0;i<max(n,m);i++)
//		{
//			printf("%s  %s\n",a1[i],a2[i]);
//		}
	}
		
	return 0;
 } 

Measured memory_bytes: 128
from collections import deque

S = input()
Q = int(input())

isNormal = 1

D = deque(list(S))

for i in range(Q):
    t = tuple(input().split())
    if t[0] == '1':
        isNormal ^= 1
    else:
        a = int(t[1]) + isNormal
        # aが奇数ならば末尾
        if a % 2:
            D.append(t[2])
        else:
            D.appendleft(t[2])

SS = ""
if isNormal % 2:
    SS = ''.join(list(D))
else:
    SS = ''.join(reversed(D))

print(SS)



Measured memory_bytes: 73192
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1e3 + 5;
char grid[N][N];
int h, w;

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

int bfs() {
  int level = 0;

  queue<pair<int, int>> q;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (grid[i][j] == '#') {
        q.emplace(i, j);
      }
    }
  }

  while (!q.empty()) {
    int sz = q.size();

    while (sz--) {
      auto curr = q.front();
      q.pop();

      for (int i = 0; i < 4; ++i) {
        int nxt_x = curr.first + dx[i];
        int nxt_y = curr.second + dy[i];
        if (nxt_x >= 0 && nxt_y >= 0 && grid[nxt_x][nxt_y] == '.') {
          grid[nxt_x][nxt_y] = '#';
          q.emplace(nxt_x, nxt_y);
        }
      }
    }

    ++level;
  }

  return level - 1;
}

int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> grid[i][j];
    }
  }

  cout << bfs() << endl;
}


Measured memory_bytes: 9488
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.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;}

using ll=long long;
using R=long double;
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));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

using pii = pair<int,int>;
vector<pii> ary;
set<int> block;

const int limit = 200010;
int s[limit], t[limit], x[limit], e[limit];

int main(void){
	int n,q;
	scanf("%d %d", &n, &q);
	rep(i, n){
		scanf("%d %d %d", s + i, t + i, x + i);
		s[i] -= x[i];
		t[i] -= x[i];
		ary.push_back(pii(s[i], i));
		ary.push_back(pii(t[i], i));
	}

	rep(i, q) scanf("%d", e + i);

	sort(begin(ary), end(ary));
	const int m = ary.size();
	int pos = 0;

	rep(i, q){
		while(pos < m and ary[pos].first <= e[i]){
			const int idx = ary[pos].second;
			if(block.find(x[idx]) != end(block))
				block.erase(x[idx]);
			else
				block.insert(x[idx]);
			pos++;
		}
		if(block.empty())
			puts("-1");
		else
			printf("%d\n", *begin(block));
	}

	return 0;
}

Measured memory_bytes: 17516
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int a;
   string s;
   cin >> a;
   cin >> s;
   if (a >= 3200) cout << s << endl;
   else cout << "red" << endl;
   return 0;
}


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

using namespace std;

const int N = 25;

int a[N], b[N], c[N];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i < n; i++) {
    cin >> c[i];
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += b[a[i]];
    if (a[i - 1] == a[i] - 1) {
      sum += c[a[i] - 1];
    }
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double a,b,c,d;
  cin>>a>>b>>c>>d;
  double s=ceil(a/d);
  double t=ceil(c/b);
  if(t<=s) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <limits>
#include <cassert>

using namespace std;

#define inf numeric_limits<int>::max()
#define double_inf numeric_limits<double>::infinity();

typedef long long int lli;
typedef unsigned long long int ulli;


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N = 0;
	int loc_max = 0;
	ulli total_sum = 0;
	vector<int> A;
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
		loc_max = max(A[i], loc_max);
		total_sum += (loc_max>A[i] ? loc_max-A[i] : 0);
	}
	cout << total_sum << endl;
	return 0;
}

Measured memory_bytes: 3984
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String[] s = r.readLine().split(" ");
		int[] a = {Integer.valueOf(s[0]), Integer.valueOf(s[1]), Integer.valueOf(s[2]), Integer.valueOf(s[3]), Integer.valueOf(s[4])};
		Arrays.sort(a);
		for(int i = 4; i > 0; i--) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[0]);
	}
}

Measured memory_bytes: 9344
#include <iostream>
using namespace std;
int min(int x, int y){return x < y ? x : y;}
int max(int x, int y){return x > y ? x : y;}
int main(){
	int n, m; cin >> n >> m;
	int max_L = 0, min_R = 100010;
	int l, r;
	for(int i = 0; i < m; i++){
		cin >> l >> r;
		max_L = max(max_L, l);
		min_R = min(min_R, r);
	}
	if(min_R - max_L < 0) cout << 0 << endl;
	else cout << min_R - max_L + 1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
char s[50][50];
int i,j;
int f(int a,int b){
	return s[i][j]==s[a][b];
}
int main(void){
	int h,w,num;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j]=='#'){
				num=f(i-1,j)+f(i+1,j)+f(i,j-1)+f(i,j+1);
				if(!num){
					printf("No");
					return 0;
				}
			}
		}
	}
	printf("Yes");
	return 0;
}

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

int kaijou(int x){
  int a = 1;
  while(x>=1){
    a *= x;
    x--;
  }
  return a;
}

int main(){
  int n; cin >> n;
  vector<bool>  p(n,0);
  int pans = 0;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    a--;
    p.at(a) = 1;
    int count = 0;
    for(int j=0;j<a;j++){
      if(p.at(j)) count++;
    }
    pans += (a-count) * kaijou(n-i-1);
  }

  vector<bool>  q(n,0);
  int qans = 0;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    a--;
    q.at(a) = 1;
    int count = 0;
    for(int j=0;j<a;j++){
      if(q.at(j)) count++;
    }
    qans += (a-count) * kaijou(n-i-1);
  }
  cout << abs(pans-qans) << endl;

}

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

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	if(n == 1 || m == 1){
		cout << "Yes" << endl;
		return 0;
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			if(i * (m - j) + j * (n - i) == k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if(s=="SUN") cout << 7 ENDL;
    if(s=="MON") cout << 6 ENDL;
    if(s=="TUE") cout << 5 ENDL;
    if(s=="WED") cout << 4 ENDL;
    if(s=="THU") cout << 3 ENDL;
    if(s=="FRI") cout << 2 ENDL;
    if(s=="SAT") cout << 1 ENDL;
    return 0;
}

Measured memory_bytes: 3540
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s = gets.chomp

    loop do
      s.slice!(s.length-2, 2)

      sl = s.slice(0, s.length / 2)
      sr = s.slice(s.length / 2, s.length / 2)

      if sl == sr
        puts s.length
        return
      end
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

int main(){
	int n,m;
	int a[1002],b[1002];
	scanf("%d%d",&n,&m);
	rep1(i,n)scanf("%d",&a[i]);
	rep1(i,m)scanf("%d",&b[i]);
	
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	a[0] = -1;
	b[0] = -1;
	
	ll ret = 1;
	ll X = 0, Y = 0;
	for(int i = n*m ; i >= 1 ; i --){
		if(a[n-X] == i && b[m-Y] == i){
			X ++;
			Y ++;
		}
		else if(a[n-X] == i && b[m-Y] != i){
			ret *= Y;
			ret %= M;
			X ++;
		}
		else if(a[n-X] != i && b[m-Y] == i){
			ret *= X;
			ret %= M;
			Y ++;
		}
		else {
			ret *= (X*Y)-(n*m-i);
			ret %= M;
		}
		//cout << X << " " << Y << " " << ret << endl;
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

void warshall_floyd(vector<vector<int>> &d, int n) {
    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> d = a;
    warshall_floyd(d, n);
    if(d != a) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            bool ok = true;
            for(int k = 0; k < n; k++) {
                if(k == i || k == j) {
                    continue;
                }
                if(d[i][j] == d[i][k] + d[k][j]) {
                    ok = false;
                }
            }
            ans += (ok ? d[i][j] : 0);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int main(){
    int a[3][3],b[3][3];
    for(int i=0 ; i < 3 ; i++){
    	for(int j=0 ; j < 3 ; j++){
    	cin >> b[i][j];
    	  a[i][j]=0;
      }
	}
	int q; cin >> q ;
	while(q--){
		int x; cin >> x ;
		for(int i=0 ; i < 3 ; i++){
			for(int j=0 ; j < 3 ; j++){
				if(b[i][j]==x)
				   a[i][j]=1;
			}
		}
	}
	if(a[0][0] == 1 && a[1][1]==1 && a[2][2]==1 || a[0][2] == 1 && a[1][1]==1 && a[2][0]==1)
	 cout << "Yes" << endl;
	 else if(a[0][0]==1 && a[0][1]==1 && a[0][2]==1 || a[1][0]==1 && a[1][1]==1 && a[1][2]==1 ||a[2][0]==1 && a[2][1]==1 && a[2][2]==1 ) 
	 cout << "Yes" << endl;
	 else if(a[0][0]==1 && a[1][0]==1 && a[2][0]==1 ||a[0][1]==1 && a[1][1]==1 && a[2][1]==1 ||a[0][2]==1 && a[1][2]==1 && a[2][2]==1 )
	 cout << "Yes" << endl;
	 else cout << "No";
}

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

int main(){
    long long n, u, v, res; cin >> n;
    res = n * (n + 1) * (n + 2) / 6;
    while(cin >> u >> v) res -= min(u, v) * (n + 1 - max(u, v));
    cout << res << '\n';
}

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

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

	vector<stack<long> > a(n);

	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;
		
		if (s == 0) {
			long x;
			cin >> x;
			a[t].push(x);
		}
		else if (s == 1 && !a[t].empty())
			cout << a[t].top() << endl;
		else if (s == 2 && !a[t].empty())
			a[t].pop();
	}

	return 0;
}


Measured memory_bytes: 5260
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<map>
#include <algorithm>
#include <vector>

using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64, i64>;


constexpr i64 MAX = 100000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i32 n, k;
    cin >> n >> k;
    vector<i64> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    i64 ans = 0;
    COMinit();
    i64 ma_sum = 0,mi_sum = 0;
    rep(i,n - k + 1) {
        i64 f = COM(n - i - 1,k - 1);
        ma_sum += (a[n - i - 1] * f) % MOD;
        mi_sum += (a[i] * f) % MOD;
    }
    ans = ma_sum - mi_sum;
    while(ans < 0) ans += MOD;
    ans %= MOD;
    cout << ans << endl;
}


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

#define name "lqdoj"
#define long long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inoutf ifstream fi(name".inp"); ofstream fo(name".out");

using namespace std;

const int N = 3000;
long d[N][N];

int main(){
    fastio;
    inoutf;

    int n;
    cin >> n;
    long a[n];
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for (int i = n - 1; i >= 0; --i){
        for (int j = 0; j < n; ++j){
            if (i == j) d[i][j] = a[i];
            else
                if (i > j) d[i][j] = 0;
                else d[i][j] = max((a[i] - d[i + 1][j]),(a[j] - d[i][j - 1]));
        }
    }
    cout << d[0][n - 1];

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int MAX=0;
  int SUM=0;
  
  for(int i=0;i<N;i++){
    int L;
    cin >> L;
    
    if(L>MAX){
      MAX=L;
    }
    SUM+=L;
  }
  
  if(MAX>=SUM-MAX){
    cout << "No" <<endl;
  }
  else{
    cout << "Yes" <<endl;
  }
}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    static int h;

    private static void maxHeapify(int[] a, int i) {
        int l = i * 2;
        int r = i * 2 + 1;

        int largest = (l <= h && a[l] > a[i])? l : i;
        if(r <= h && a[r] > a[largest]) largest = r;

        if(largest != i) {
            int tmp = a[i];
            a[i] = a[largest];
            a[largest] = tmp;
            maxHeapify(a, largest);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
        while(true) {
            String cmd = sc.next();
            if(cmd.equals("insert")) pq.add(sc.nextInt());
            else if(cmd.equals("extract")) System.out.println(pq.poll());
            else break;
        }

        sc.close();
    }
}



Measured memory_bytes: 581544
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string calc(string s, string t) {
  int l=max(s.size(),t.size())+1;
  while(s.size()<l) s='0'+s;
  while(t.size()<l) t='0'+t;
  string ans="";
  int k=0;
  for(int i=l-1; i>=0; i--) {
    int a=s[i]+t[i]-'0'*2+k;
    ans=(char)(a%10+'0')+ans;
    if(a>=10) k=1;
    else k=0;
  }
  while(ans[0]=='0'&& ans.size()>1) ans=ans.substr(1);
  return ans;
}

int main() {
  string s;
  while(cin >> s) {
    int p,q;
    rep(i,s.size()) {
      if(s[i]=='+') p=i;
      if(s[i]=='=') q=i;
    }
    int ans=-1;
    rep(i,10) {
      string t=s;
      if(i==0 && ((t[0]=='X' && t[1]!='+') || (t[p+1]=='X' && t[p+2]!='=') || (t[q+1]=='X' && q+2!=t.size()))) continue;
      rep(j,t.size()) {
	if(t[j]=='X') t[j]=(char)(i+'0');
      }
      string a=t.substr(0,p),b=t.substr(p+1,q-p-1),c=t.substr(q+1);
      if(calc(a,b)==c) ans=i;
    }
    if(ans==-1) pr("NA");
    else pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1200
//Problem C
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cost = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<Integer> numList = new ArrayList<>();
		
		for(int i = 0; i < k; i++) {
			numList.add(sc.nextInt());
		}
		
		boolean flag = true;
		cost--;
		while(flag) {
			flag = false;
			cost++;
			int tmp = cost;
			while(tmp > 0) {
				if (numList.contains(tmp % 10)) {
					flag = true;
					break;
				}
				tmp /= 10;
			}
		}
		System.out.println(cost);
	}
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

struct Dice {
	int num[6]; // top, bottom, front, back, right, left;
	static const int rd[3][4]; //?????¢??????
	
	Dice(int top, int bottom, int front, int back, int right, int left) {
		num[0] = top;		num[1] = bottom;
		num[2] = front;	num[3] = back;
		num[4] = right;	num[5] = left;
	}
	Dice(const Dice &d) {
		copy(d.num, d.num + 6, num);
	}
	
	bool operator < (const Dice &d) const {
		REP(i, 6) if (num[i] != d.num[i]) {
			return num[i] < d.num[i];
		}
		return false;
	}
	
	void X(int cnt = 1) { cnt %= 4; REP(i, cnt) rotate(0); }
	void Y(int cnt = 1) { cnt %= 4; REP(i, cnt) rotate(1); }
	void Z(int cnt = 1) { cnt %= 4; REP(i, cnt) rotate(2); }
	
	void rotate(int p) {
		int tmp = num[rd[p][0]];
		
		REP(i, 3) num[rd[p][i]] = num[rd[p][i + 1]];
		num[rd[p][3]] = tmp;
	}
	
	Dice unique() {
		Dice now = *this;
		
		Dice mi(*this);
		
		REP(i, 4) {
			REP(j, 4) {
				REP(k, 4) {
					if (now < mi) mi = now;
					now.X();
				}
				now.Y();
			}
			now.Z();
		}
		return mi;
	}
	
	void print() {
		REP(i, 6) printf("%d%c", num[i], i == 5 ? '\n' : ' ');
	}
};

const int Dice::rd[3][4] = {
	{2,1,3,0}, // x
	{2,4,3,5}, // y
	{0,5,1,4}, // z
};

int main() {
	int num[6];
	REP(i, 6) scanf("%d", num + i);
	
	Dice dice(num[0], num[5], num[1], num[4], num[2], num[3]);
	
	int n; cin >> n;
	
	while (n--) {
		int a, b; cin >> a >> b;
		
		Dice now = dice;
		bool ok = false;
		REP(i, 4) {
			REP(j, 4) {
				REP(k, 4) {
					if (now.num[0] == a && now.num[2] == b && !ok) {
						printf("%d\n", now.num[4]);
						ok = true;
					}
					now.X();
				}
				now.Y();
			}
			now.Z();
		}
		
		
	}
	
	return 0;
}

Measured memory_bytes: 3172
from collections import deque

n,q = map(int,input().split())
E = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
 

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

def bfs(i):
    s = -1
    q = deque([])
    q.append((i-1,s))
    while q:
        
        num,bef = q.pop()
        for j in E[num]:
            if j == bef:
                continue
            else:
                score[j] += score[num]
                q.append((j,num))
            
    return score
print(*bfs(1))


    




Measured memory_bytes: 62236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }

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

    int N; cin >> N;
    rep(i,N) {
        ll a; cin >> a;
        if(a % 2 == 1) {cout << "first" << endl; return 0;}
    }
    cout << "second" << endl;
    return 0;
}



Measured memory_bytes: 256
program main
implicit none
integer,dimension(11)::p
integer::h,hp,n,i,x,total

read(*,*) n

do i=1,n
read(*,*) p(i)
end do
if (n<10) then
do i=n+1,11
p(i)=0
end do
end if
hp=p(1)
x=1
do i=1,n
if (hp<p(i)) then
hp=p(i)
x=i
end if
end do

total=0

do i=1,n
total=total+p(i)
end do

total= total-p(x)+0.5*p(x)

write(*,*) total

end program main




Measured memory_bytes: 768
def o():return map(int,input().split())
n,q=o()
a=[[]for i in range(n)]
x=[0]*n
for i in range(n-1):
  u,v=o()
  a[u-1]+=[v-1]
  a[v-1]+=[u-1]
for i in range(q):
  u,v=o()
  x[u-1]+=v
p=[[0,0]]
s=0
while p:
  r,s=p.pop()
  for i in a[r]:
    if i!=s:
      p+=[[i,r]]
      x[i]+=x[r]
print(*x)

Measured memory_bytes: 116352
N ,Q = map(int,input().split())
S = input()
lst = []
for i in range(Q):
    s,e = map(int,input().split())
    lst.append([s-1,e-1])
#print(lst)

cum = [0]*N
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        cum[i] = cum[i-1] + 1
    else:
        cum[i] = cum[i - 1]

for v in lst:
    print(cum[v[1]] - cum[v[0]])

Measured memory_bytes: 22900
local s = io.read()
local t = io.read()
local n, m = #s, #t
local ret = {}
for i = 1, n * m do ret[i] = "" end
local ss = {}
for i = 1, n do ss[i] = s:sub(i, i) end
local ts = {}
for i = 1, m do ts[i] = t:sub(i, i) end

local str_s = ss[1]
if ts[1] == str_s then
  ret[1] = str_s
end
for i_t = 2, m do
  if ts[i_t] == str_s then
    ret[i_t] = str_s
  else
    ret[i_t] = ret[i_t - 1]
  end
end
for i_s = 2, n do
  str_s = ss[i_s]
  if ts[1] == str_s then
    ret[(i_s - 1) * m + 1] = str_s
  end
  for i_t = 2, m do
    local idx = (i_s - 1) * m + i_t
    if #ret[idx - 1] < #ret[idx - m] then
      ret[idx] = ret[idx - m]
    else
      ret[idx] = ret[idx - 1]
    end
    if ts[i_t] == str_s then
      if #ret[idx] < #ret[idx - m - 1] + 1 then
        ret[idx] = ret[idx - m - 1] .. str_s
      end
    end
  end
end
print(ret[n * m])


Measured memory_bytes: 899820