akhauriyash/Code-Regression huggingface dataset:
// Bubble sort
#include <stdio.h>

int bubble_sort(int *A, int N)
{
    int flag = 1, i = 0, cnt = 0;
    int j, tmp;
    while(flag){
        flag = 0;
        for(j=N-1; j>=i+1; j--){
            if(A[j] < A[j-1]){
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                cnt++;
            }
        }
        i++;
    }
    return cnt;
}

int main(void)
{
    int n, i;
    int cnt = 0;
    scanf("%d", &n);
    int A[n];
    for(i=0; i<n; i++){
        scanf("%d", &A[i]);
    }
    cnt = bubble_sort(A, n);
    for(i=0; i<n; i++){
        if(i==n-1){
            printf("%d", A[i]);
        }else{
            printf("%d ", A[i]);
        }
    }
    printf("\n");
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 998244353
#define ld long double
#define pll pair<ll,ll>
using namespace std;

ll powa(ll a,ll b)
{
	a%=mod;
	if(a==0)return 0;
	ll ans=1;

	while(b>0)
	{
		if(b&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main()
{ 
fast;
ll n,s;
cin>>n>>s;

ll a[n+1];
for(ll i=1;i<=n;i++)
cin>>a[i];

vector<ll> dp(s+1,0);
dp[0]=2;
if(a[1]<=s)dp[a[1]]=1;

for(ll i=2;i<=n;i++)
{
	vector<ll> tempdp(s+1,0);

	for(ll j=0;j<=s;j++)
		tempdp[j]=(2*dp[j])%mod;
	
	for(ll j=s;j>-1;j--)
		if(j+a[i]<=s)
			tempdp[j+a[i]]=(dp[j]+tempdp[j+a[i]])%mod;

		for(ll j=0;j<=s;j++)
			dp[j]=(tempdp[j])%mod;
}
cout<<dp[s]<<endl;
}


Measured memory_bytes: 3712
package main

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

var S string

func readVariables() {
	S = nextStr()
}

func main() {
	readVariables()
	for i := 0; i < len(S); i++ {
		fmt.Print("x")
	}
	fmt.Println()
}

/* 以下、テンプレート*/

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}


Measured memory_bytes: 640
n, m = map(int, input().split())

hList = list(map(int, input().split()))

workList = [1] * n

for i in range(m):
    a, b = map(int, input().split())
    if(hList[a-1] <= hList[b-1]):
        workList[a-1] = 0
    if(hList[a-1] >= hList[b-1]):
        workList[b-1] = 0

print(sum(workList))


Measured memory_bytes: 20108
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  if( (abs(a-b)-1)%2 == 0){
    cout << "Borys" << endl;
  }else{
    cout << "Alice" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main () {
  string S ;
  int N ;
  cin >> S >> N ;
  for(int i = 0 ; i < N ; i++ ){
    string op ;
    int a , b ;
    cin >> op >> a >> b ;
    if(op=="print"){
      string ans ;
      ans = S.substr(a,b-a+1) ;
      cout << ans << endl ;
    } else if (op=="reverse"){
      string ans ;
      ans = S.substr(a,b-a+1) ;
      reverse(ans.begin(),ans.end());
      S=S.replace(a,b-a+1,ans);
    } else if(op=="replace"){
      string p ;
      cin >> p ;
      S=S.replace(a,b-a+1,p);
    }
  }
}


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

int main() {
  int A , B , C , D;
  cin >> A >> B >> C >> D;
  
  while (true) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	int n, a[100];
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	int min = 1000;
	int max = 0;
	for (int i = 0;i < n;i++) {
		if (min > a[i]) {
			min = a[i];
		}
		if (max < a[i]) {
			max = a[i];
		}
	}
	std::cout << max - min << std::endl;
	return 0;
}
	


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

int main(void) {
  string s;
  cin >> s;

  string ans;
  for (int i = 1; i <= s.length(); i++) {
    if (i % 2 == 1) {
      ans += s[i-1];
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,i;string s,t;cin >> n >> s >> t;
  for(i=n;i>=0;i--){
    if(s.substr(n-i,i) == t.substr(0,i)){
      cout << n*2-i << endl;break;
    }
  }
}
  

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a, b,result;
    scanf("%d%d", &a, &b);
  if(a>=13){
    result = b;
  }else if(a>=6 && a<=12){
    result = b/2;
  }else{
    result = 0;
  }
    printf("%d",result);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

// ein: 区間スタート, aus: 区間終了, durch: チェック
const int ein = 0;
const int aus = 1;
const int durch = 2;

struct datei{
	// zeit: そのクエリの時刻
	// art: クエリの種類
	// pos: クエリの情報（ein/aus なら道路工事をする座標，durch なら人の index）
	int zeit;
	int art; 
	int pos;
	bool operator<( const datei& anders ) const{
		if( zeit != anders.zeit ){
			return zeit < anders.zeit;
		} else if( art != anders.art ){
			return art < anders.art;
		} else {
			return pos < anders.pos;
		}
	}
};

int main(){
	int n, q; cin >> n >> q;
	vector<datei> dt;
	for( int i = 0; i < n; ++i ){
		int s, t, x; cin >> s >> t >> x;
		dt.push_back( (datei){ max(0, s-x), ein, x } );
		dt.push_back( (datei){ max(0, t-x), aus, x } );
	}
	for( int i = 0; i < q; ++i ){
		int d; cin >> d;
		dt.push_back( (datei){ d, durch, i } );
	}
	sort( dt.begin(), dt.end() );
	multiset<int> candy;
	vector<int> ans(q);
	for( int i = 0; i < 2*n+q; ++i ){
		 if( dt[i].art == ein ){
			 candy.insert(dt[i].pos);
		 } else if( dt[i].art == aus ){
			 // erase に値を指定するとその値を持つ要素が全部消える
			 // find() はイテレータを返し，計算量は O(logN)
			 candy.erase(candy.find(dt[i].pos));
		 } else {
			 if( !candy.empty() ){
				 ans.at(dt[i].pos) = *candy.begin();
			 } else ans.at(dt[i].pos) = -1;
		 }
		// cout << dt[i].zeit << ' ' << dt[i].art << ' ' << dt[i].pos << endl;
	}
	for( auto &k : ans ){
		cout << k << endl;
	}
	return 0;
}

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

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

    vector<int> index;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        index.push_back(i);
        cin >> x[i] >> y[i];
    }

    double cnt = 0.0;
    double dist = 0.0;
    do {
        for (int i = 1; i < n; i++) {
            dist += sqrt((x[index[i - 1]] - x[index[i]]) * (x[index[i - 1]] - x[index[i]]) + (y[index[i - 1]] - y[index[i]]) * (y[index[i - 1]] - y[index[i]]));
        }
        cnt += 1.0;
    } while (next_permutation(index.begin(), index.end()));

    dist /= cnt;

    printf("%.8lf\n", dist);
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = "RGB";
    int K = (int) t.size();
    map<char, int> char_to_int;
    for (int j = 0; j < K; ++j) {
        char_to_int[t[j]] = j;
    }
    vector<vector<int>> colors(K);
    for (int i = 0; i < K * n; ++i) {
        colors[char_to_int[s[i]]].push_back(i);
    }
    vector<int> order(K * n, 0);
    for (int i = 0; i < n; ++i) {
        vector<int> run(K);
        for (int j = 0; j < K; ++j) {
            run[j] = colors[j][i];
        }
        sort(run.begin(), run.end());
        for (int j = 0; j < K; ++j) {
            order[run[j]] = j;
        }
    }
    long long prime = 998244353;
    vector<int> counters(K + 1, 0);
    counters[0] = n;
    long long answer = 1;
    for (int i = 0; i < K * n; ++i) {
        int multiplier = counters[order[i]] - counters[order[i]+1];
        answer = (answer * multiplier) % prime;
        ++counters[order[i]+1];
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int a, b; cin >> a >> b;

  int ans = INF;
  for(int i = 1000000; i >= 0; i--){
    int t = 1.0 * i * 0.08;
    int t2 = 1.0 * i * 0.10;
    if(t == a && t2 == b) ans = i;
    //cout << t << " " << t2 << endl;
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<double> p(n+1);
    double dp[n+1][n+1];
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            dp[i][j]=0.0;
        }
    }
    dp[1][0]=1.0-p[1];
    for(int i=2;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1.0-p[i]);
    }
    dp[1][1]=p[1];
    for(int i=2;i<=n;i++)
    {
        dp[i][i]=dp[i-1][i-1]*p[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            dp[i][j]=dp[i-1][j]*(1.0-p[i])+dp[i-1][j-1]*p[i];
        }
    }
    double sum=0.0;
    for(int i=n/2+1;i<=n;i++)
    {
        sum+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<sum<<endl;
    return 0;
}


Measured memory_bytes: 74076
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let s: u32 = s.trim().parse().unwrap();

    let mut ans: u32 = 0;

    for x in 1..1001 {
        for y in 2..1001 {
            let x = x as u32;
            let y = y as u32;

            if x > s {
                break;
            }

            let z = x.pow(y) as u32;

            if z > s {
                break;
            }
            if z <= s && ans < z {
                ans = z;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

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

	int u,v;
	while(cin>>u){
		cin>>v;
		ConnectNodeInfo connect(110);
		while(true){
			if(!u && !v) break;
			connect.AddNonDirectionalConnection(u-1,v-1,1);
			cin>>u>>v;
		}
		int odd = 0;
		for(int i=0;i<110;i++){
			if(connect[i].size()%2){
				odd++;
			}
		}
		out((connect[0].size()%2 && connect[1].size()%2 && odd==2)?"OK":"NG");
	}
	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
int main(void){
 int a[100],N,i,b=0;
 scanf("%d",&N);
 for(i=0;i<N;i++){
  scanf("%d",&a[i]);
 }
 for(i=1;i<N;i++){
  if(a[i-1]==a[i]){
   a[i]=a[i-1]+a[i+1];
   b++;
  }
 }
 printf("%d\n",b);
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    rep(i,S.size()){
        if((int)S[i] + N <= 90){
        S[i] = S[i] + N;
        }
        else{
            S[i] = 'A' + ((int)S[i] + N - 91);
        }
    }
    
    cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e9)
#define s second
#define f first
#define N 15
using namespace std;
typedef pair<double,int> P;
typedef pair<P,int> P1;
int n,num[N],d[N],c[N],mintim,prev,prevs;
P1 dp[(1<<N)][N];
vector<int> ans;

double cal(double w,double dis){
  return dis/(2000/(70+20*w));
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>num[i]>>d[i]>>c[i];
  for(int i=0;i<(1<<n);i++)
    for(int j=0;j<n;j++)
      dp[i][j]=P1(P(INF,INF),INF);
  for(int i=0;i<n;i++)
    dp[(1<<i)][i]=P1(P(0,c[i]),-1);
  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if(!(i&(1<<j)))continue;
      if(dp[i][j].second==INF)continue;
      for(int k=0;k<n;k++){
	if((i&(1<<k)))continue;
	double tim=dp[i][j].f.f;
	int dis=abs(d[j]-d[k]);
	int w=dp[i][j].f.s;
	double r=tim+cal(w+c[j],dis);
	dp[(i|(1<<k))][k]=min(dp[(i|(1<<k))][k],P1(P(r,w+c[j]),j));
      }
    }
  }
  int last=0;
  mintim=dp[(1<<n)-1][0].f.f;
  prev=dp[(1<<n)-1][0].s;
  prevs=((1<<n)-1)-(1<<0);
  for(int i=1;i<n;i++)
    if(mintim>dp[(1<<n)-1][i].f.f){
      mintim=dp[(1<<n)-1][i].f.f;
      prev=dp[(1<<n)-1][i].s;
      prevs=((1<<n)-1)-(1<<i);
      last=i;
    }
  ans.push_back(last);
  while(1){
    int ima=prev;
    ans.push_back(prev);
    prev=dp[prevs][prev].s;
    if(prev==-1)break;
    prevs=prevs-(1<<ima);
  }
  reverse(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++){
    if(i)cout<<' ';
    cout<<num[ans[i]];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 12736
n,m = map(int,input().split())
a = []
b = []
for _ in range(n):
  a.append(input())
for _ in range(m):
  b.append(input())
for i in range(n-m+1):
  if b[i] in a[i]:
    for x in range(m-1):
      if b[i+x] not in a[i+x]:
        print("No")
        exit()
    print("Yes")
    exit()
  else:
    print("No")
    exit()

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) //cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 5e5 + 10;
const ll INF = (ll) LONG_LONG_MAX / 100;
const ld EPS = (ld) 1e-8;
const ll P = 104107;

ll mul(ll a, ll b){
	return (a * b) % MOD;
}

ll pw(ll b, ll p){
	if(p == 0) return 1;
	if(p & 1) return mul(b, pw(b, p - 1));
	return pw(mul(b, b), p / 2);
}
ll inv(ll x){
	return pw(x, MOD - 2);
}

ll a[MAXN];

map<ll, vector<ll>> mp;
ll dp[MAXN];
ll ps[MAXN], ps2[MAXN];

int main(){
	ll n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	ps[1] = a[1];
	for(int i = 2; i <= n; i++) ps[i] = ps[i - 1] ^ a[i];
	for(int i = 1; i <= n; i++) mp[ps[i]].pb(i);
	for(int i = 1; i <= n; i++) ps2[i] = ps2[i - 1] + (ps[i] == 0);
	
	ll m , cnt,s, ans = 0;
	for(auto x : mp){
		debug(x.F);
		if(x.F == 0) continue;
		if(ps[n] != 0 and ps[n] != x.F) continue;
		m = x.S.size();
		s = 1;
		ll lt = -1;
		dp[0] = 1;
		if(ps[n] == 0) ans ++;
		lt = 0;
		for(int i = 1; i < m; i ++){
			debug(i);
			cnt = 0;
			if(lt != -1) cnt = ps2[x.S[i]] - ps2[x.S[lt]];
			
			dp[i] = (dp[i - 1] - 1ll) + (cnt * s) + 1ll;
			dp[i] %= MOD;
			if(ps[n] == 0) ans += dp[i];
			ans %= MOD;
			s += dp[i];
			s %= MOD;
			lt = i;
		}
		if(ps[n] != 0) ans += dp[m - 1];
		ans %= MOD;
	}
	debug(ans);
	if(ps[n] == 0) ans += pw(2, mp[0].size() - 1);
	cout << ((ans % MOD) + MOD) % MOD;
	return 0;
}


/*
fuck hashal
*/



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  array<string, 3> S;
  cin >> S[0] >> S[1] >> S[2];
  sort(ALL(S));

  llong ans = S[0].size() + S[1].size() + S[2].size();
  do {
    set<int> sz2o, so2t, sz2t;
    for (int i = 0; i < 2000; ++i) {
      bool same = true;
      for (int j = 0; i + j < S[0].size() && S[1][j]; ++j) {
        same &= S[0][i + j] == '?' || S[1][j] == '?' || S[0][i + j] == S[1][j];
      }
      if (same) {
        sz2o.insert(i);
      }
    }
    for (int i = 0; i < 2000; ++i) {
      bool same = true;
      for (int j = 0; i + j < S[0].size() && S[2][j]; ++j) {
        same &= S[0][i + j] == '?' || S[2][j] == '?' || S[0][i + j] == S[2][j];
      }
      if (same) {
        sz2t.insert(i);
      }
    }
    for (int i = 0; i < 2000; ++i) {
      bool same = true;
      for (int j = 0; i + j < S[1].size() && S[2][j]; ++j) {
        same &= S[1][i + j] == '?' || S[2][j] == '?' || S[1][i + j] == S[2][j];
      }
      if (same) {
        so2t.insert(i);
      }
    }

    for (auto z2o: sz2o) {
      ans = min(ans, llong{S[2].size() + llong{max(S[0].size(), z2o + S[1].size())}});
      for (auto o2t: so2t) {
        if (sz2t.count(z2o + o2t) || z2o + o2t >= S[0].size()) {
          ans = min(ans, llong{max({S[0].size(), z2o + S[1].size(), z2o + o2t + S[2].size()})});
        }
      }
    }

  } while (next_permutation(ALL(S)));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n;cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];

    vi cnt(n+1,0);
    rep(i,n) cnt[a[i]]++;


    rep(i,n) if(i and i%2!=n%2){
        if(cnt[i]!=2){
            cout << 0 << endl;
            return 0;
        }
    }

    if(n%2){
        if(cnt[0]!=1){
            cout << 0 << endl;
            return 0;
        }
    }else{
        if(cnt[0]!=0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;
    rep(i,n/2){
        ans <<= 1;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18
 
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;
 
typedef pair<int, P> iP;
 
iP ch[100001];
int imos[200001];
 
signed main() {
	int n, c;
	cin >> n >> c;
	rep(i, n) cin >> ch[i].second.first >> ch[i].second.second >> ch[i].first;
	sort(ch, ch + n);
	int s = ch[0].second.first, t = ch[0].second.second;
	FOR(i, 1, n) {
		if(ch[i].first == ch[i - 1].first && ch[i].second.first == ch[i - 1].second.second) {
			t = ch[i].second.second;
		}
		else {
			++imos[s * 2 - 1];
			--imos[t * 2];
			s = ch[i].second.first;
			t = ch[i].second.second;
		}
	}
	++imos[s * 2 - 1];
	--imos[t * 2];
	FOR(i, 1, 200001) {
		//cout << imos[i] << endl;
		imos[i] += imos[i - 1];
	}
	int res = 0;
	rep(i, 200001) res = max(res, imos[i]);
	cout << res << endl;
	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int solve(int a, int b, int c, vector<int>& l) {
    //sort(l.begin(), l.end());
    int n = l.size();
    int best = 1000000;
    for(int i = 0; i < n; ++i) {
        int li = l[i];
        for(int j = 0; j < n; ++j) {
            int lj = l[j];
            for(int k = 0; k < n; ++k) {
                int lk = l[k];
                if(i != j && i != k && j != k) {
                    int cand = abs(li-a)+abs(lj-b)+abs(lk-c);
                    best = min(best, cand);
                }
            }
        }
    }
    return best;
}

int dfs(int a, int b, int c, vector<int>& l) {
    int cand = solve(a, b, c, l);
    if((int)l.size() > 3LL) {
        int n = l.size();
        for(int i = 0; i < n; ++i) {
            for(int j = i+1; j < n; ++j) {
                vector<int> nl(l);
                int elt = nl[i]+nl[j];
                nl.erase(nl.begin()+j);
                nl.erase(nl.begin()+i);
                nl.push_back(elt);
                cand = min(cand, 10+dfs(a, b, c, nl));
            }
        }
    }
    return cand;
}

int32_t main() {

    int n, a, b, c; cin >> n >> a >> b >> c;
    vector<int> l(n);
    for(int i = 0; i < n; ++i) {
        cin >> l[i];
    }

    int ans = dfs(a, b, c, l);

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N;
	double mizuhasu = 0;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int A;
		if (scanf("%d", &A) != 1) return 1;
		mizuhasu += 1.0 / A;
	}
	printf("%.15f\n", 1.0 / mizuhasu);
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    unordered_map<string,int> mp;
    rep(i,n) {
        string si;
        cin >> si;
        sort(si.begin(),si.end());
        if(mp.count(si)) mp[si]++;
        else mp.insert({si,1});
    }

    ll ans = 0;
    for(auto& i:mp) {
        ll cnt = i.second;
        ans += cnt*(cnt-1)/2;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10660
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    }

    public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

}

Measured memory_bytes: 24460
n = gets.chomp.to_i
spn_arr = n.times.map { |i| gets.chomp.split(' ') + [i + 1] }
sorted = spn_arr.sort do |lhs, rhs|
    ls, lp = lhs
    rs, rp = rhs
    (ls != rs) ? (ls < rs ? 0 : 1) : (rp.to_i - lp.to_i)
end

sorted.each do |s, pt, n|
    puts n
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s;
	cin >> s;
	
	int n = (int)s.size();
	int left = 0, right = n - 1;
	int ans = 0;
	
	while( left < right ) {
		if( s[left] == s[right] ) {
			left++;
			right--;
		} else if( s[left] == 'x' ) {
			left++;
			ans++;
		} else if( s[right] == 'x' ) {
			right--;
			ans++;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3680
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int val = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = vals[0];
		//string res="";

		//int y = vals[0];
		//int x = vals[1];

		string res = "EQUAL";

		string a = Console.ReadLine();
		string b = Console.ReadLine();

		if (a == b) { res = "EQUAL"; } else {
			if (a.Length > b.Length) { res = "GREATER"; } else if (a.Length < b.Length) { res = "LESS"; } 
			else if (a.Length == b.Length) {
				for (int i = 0; i < a.Length; i++) {
					if (a[i] > b[i]) { res = "GREATER"; break; }
					if (a[i] < b[i]) { res = "LESS"; break; }
				}

			}
		}


		Console.WriteLine(res);


		return;
	}



	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryl(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}



	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

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

int main() {
  int N;
  cin >> N;
  vector<int>vec(N);
  int ans = 0;
  
  for (int i = 0; i < N; i++)
  {
    cin >> vec.at(i);
  }
  
  for (int i = 0; i < N; i++)
  {
    bool res = true;
    for (int j = 0; j < i; j++)
    {
      if (vec.at(i) - vec.at(j) < 0)
      {
        res = false;
      }
    }
    if (res == true)
    {
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
# ABC133B - Good Distance
def main():
    N, D, *X = map(int, open(0).read().split())
    X = tuple(zip(*[iter(X)] * D))
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            r = sum(abs(a - b) ** 2 for a, b in zip(X[i], X[j]))
            ans += 1 if r ** 0.5 == int(r ** 0.5) else 0
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

//////////////////////////////////////////


int X, Y;
ll f[1000002];

ll modInverse(ll x, ll y, ll m) {

    if(y == 0) return 1;

    ll p = modInverse(x, y/2, m);
    p = (p * p) % MOD;

    if(y & 1) p = (p * x) % MOD;

    return p;

}
void Input() {

    cin >> X >> Y;
}



void Solve() {


    if((X+Y) % 3) {

        cout << "0" << endl;
        return;
    }

    ll a = Y - (X+Y)/3;
    ll b = X - (X+Y)/3;

    if(a < 0 || b < 0) {

        cout << "0" << endl;
        return;
    }

    f[0] = 1;
    for(ll i = 1; i <= a+b; i++) {

        f[i] = i * f[i-1] % MOD;
    }

    cout << f[a+b] * modInverse(f[a], MOD-2, MOD) % MOD * modInverse(f[b], MOD-2, MOD) % MOD << endl;

}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

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

#define PI acos(-1.0)
#define INF 10e7+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

string s;
priority_queue<int> que;

int main(){
	while (cin >> s&&s != "end"){
		if (s == "insert"){
			int n;
			cin >> n;
			que.push(n);
		}
		else{
			cout << que.top() << endl;
			que.pop();
		}
	}
}

Measured memory_bytes: 7048
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    rep(i,3)
    {
        string s;
        cin >> s;
        cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k,l,p;
    cin>>n;
    int a[n];
    k=0;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]%2!=0 && i%2==0)
        {
            k++;
        }
    }
    cout<<k<<endl;
}



Measured memory_bytes: 3632
#include <stdio.h>

int mygcd(int a,int b);

int main () {
    int a,b;
    int gcd_main;
    scanf ("%d %d",&a,&b); //two natural numbers
    gcd_main = mygcd(a,b);
    
    printf ("%d\n",gcd_main);
    
    return 0;
}
    
int mygcd(int a,int b) {
    int c,d,i,ans;
    int r;
    
    if (a >= b) {
        c = a;
        d = b;
    } else {
        c = b;
        d = a;
    }
    while (d > 0) {
        r = c % d;
        c = d;
        d = r;
    }
    return c;
}


Measured memory_bytes: 2068
# スペース区切りの整数の入力（別変数に格納）
N,L = map(int, input().split())
# N=30
# L=-50

a=[]
check=L
min_i=0
for i in range(N):
    a.append(L+i)
#     print(a[i], check)
    if(abs(a[i])<abs(check)):
        check=abs(a[i])
        min_i=i
    
print(sum(a)-a[min_i])

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int result = 0;
		for(int a=0; a<10; a++){
			for(int b=0; b<10; b++){
				for(int c=0; c<10; c++){
					for(int d=0; d<10; d++){
						if(a+b+c+d == n){
							++result;
						}
					}
				}
			}
		}
		cout<<result<<endl;
	}
}

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

const int NOT_FOUND=-1;

int linearSearch(int key,int A[],int n)
{
	int i=0;
	A[n]=key;

	while(A[i]!=key){
		i++;
	}

	if(i==n){
		return NOT_FOUND;
	}
	return i;
}

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

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

	int q;
	cin>>q;

	int T[500];
	for(int i=0;i<q;i++){
		cin>>T[i];
	}

	int C=0;
	for(int i=0;i<q;i++){
		if(linearSearch(T[i],S,n)!=NOT_FOUND){
			C++;
		}
	}

	cout<<C<<endl;
	return 0;
}

Measured memory_bytes: 3076
a = []
for i in range(3):
    a.append(map(int,raw_input().split()))
n = input()
for j in range(n):
    b = input()
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0

diag1 = [a[0][0],a[1][1],a[2][2]]
diag2 = [a[0][2],a[1][1],a[2][0]]
res = 'No'
if sum(diag1) ==0 or sum(diag2) ==0:
    res ='Yes'

rowsum = [sum(a[i]) for i in range(3) ]
if 0 in rowsum:
    res = 'Yes'

colSum = [sum([a[j][i] for j in range(3)]) for i in range(3)]
if 0 in colSum:
    res = 'Yes'

print res

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"

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

    // solution comes here
    ll a, b;
    cin >> a >> b;
    cout << (((a*b)%2) ? "Odd" : "Even") << nl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(void){
    std::string s;
    std::cin>>s;
    int alp[26];
    int nf=0;
    for(int i=0;i!=26;i++){
        alp[i]=0;
    }
    for(auto &x : s){
        alp[(int)x - 97]++;
    }
    for(int i=0;i!=26;i++){
        if(alp[i]==0){
            std::cout<<(char)(i+97)<<std::endl;
            break;
        }else if(i==25){
            nf++;
        }
    }
    if(nf!=0){
        std::cout<<"None"<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 512
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 or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimensi0n, default_val) assert(type(default_val) ~= 'table') local n=dimensi0n local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local function tostringxx(o, depth) depth = depth or 0 if depth > 10 then return "<too deep!>" end if o == _G then return "<_G>" end local indent0 = (" "):rep((depth) * 2) local indent1 = (" "):rep((depth+1) * 2) local indent2= (" "):rep((depth+2) * 2) if type(o) == 'table' then local keys = {} local types = {} for k in pairs(o) do types[type(k)] = true table.insert(keys, k) end local types_count = 0 local lasttype for k in pairs(types) do types_count = types_count + 1 lasttype = k end if types_count == 1 and (lasttype == 'string' or lasttype == 'number') then table.sort(keys) end local inside = {} for i=1,#keys do local k = keys[i] local v = o[k] if type(k) == 'string' then k = string.format('%q', k) end table.insert(inside, indent1 .. '['..tostring(k)..'] = ' .. tostringxx(v, depth + 1)) end return '{\n' .. table.concat(inside, ',\n') .. '\n' .. indent0 .. '}' else if type(o) == 'string' then o = string.format('%q', o) end return tostring(o) end end
local function richtraceback() local x = 2 while true do local info = debug.getinfo(x) if not info then break end local fname = '<' .. info.short_src .. ":" .. info.linedefined .. ">" if info.name then fname = info.name end print(info.short_src .. ":" .. info.currentline .. ": in " .. ("%q"):format(fname)) print(" LOCALS:") local p = 1 while true do local name, val = debug.getlocal(x,p) if not name then break end print(" " .. name .. ": " .. tostringxx(val, 3)) p = p + 1 end print(" UPVALUES:") for p=1,info.nups do local name, val = debug.getupvalue(info.func,p) if not name then break end print(" " .. name .. ": " .. tostringxx(val, 3)) end x = x + 1 end end
local function myassert(b) if not b then richtraceback() error("assertion failed") end end 
--
local N = read.n()
local r = N % 1000
if r == 0 then
    print(0)
else
    print(1000 - r)
end

Measured memory_bytes: 2752
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var i in r)e.d(n,i,function(t){return r[t]}.bind(null,i));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){"use strict";var n=e(1),i=new(e(2))(n.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));e(4)(i)},function(r,t){r.exports=require("fs")},function(r,t,e){"use strict";var n=e(3);r.exports=class{constructor(r){this.inp=new n(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}add(r){this.inp.enq(r)}}},function(r,t,e){"use strict";r.exports=class{constructor(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=r.length,this.items=r,this.ind=0}enq(r){this.size+=1,this.items.push(r)}deq(){var r=this.items[this.ind];return this.size-=1,this.ind+=1,r}}},function(r,t,e){"use strict";r.exports=function(r){for(var t=r.in(),e=r.in(),n=new Array(t),i=new Array(t),o=0;o<t;o++){var u=r.inr();n[o]=u,i[o]=new Array(e);for(var s=0;s<e;s++)i[o][s]={l:0,r:0,u:0,d:0},"#"!=n[o][s]&&(s>0&&(i[o][s].l=i[o][s-1].l),o>0&&(i[o][s].u=i[o-1][s].u),i[o][s].l++,i[o][s].u++)}for(var c=0,f=t-1;f>=0;f--)for(var l=e-1;l>=0;l--)if("#"!=n[f][l]){l<e-1&&(i[f][l].r=i[f][l+1].r),f<t-1&&(i[f][l].d=i[f+1][l].d),i[f][l].r++,i[f][l].d++;var a=i[f][l].l+i[f][l].r+i[f][l].u+i[f][l].d-3;c<a&&(c=a)}console.log(c)}}]);

Measured memory_bytes: 285188
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static long help(int[] arr,long[][] dp,int i, int j){
	if(i>j||j<=0||i>arr.length-1){return 0;}
	if(dp[i][j]!=0){return dp[i][j];}
	long x=arr[i]+Math.min(help(arr,dp,i+2,j),help(arr,dp,i+1,j-1));
	long y=arr[j]+Math.min(help(arr,dp,i+1,j-1),help(arr,dp,i,j-2));
	return dp[i][j]=Math.max(x,y);
}
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt();
       long[][] dp=new long[n+1][n+1];
       int[] arr=new int[n+1];
       long sum=0;
       for(int i=1;i<=n;i++){arr[i]=s.nextInt();sum+=arr[i];}       
         out.write((2*help(arr,dp,1,n)-sum)+"\n");       
        out.flush();
  }
}


Measured memory_bytes: 130472
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  a--;b--;c--;d--;
  string s;cin>>s;
  bool ans=true;
  rep(i,n-1){
    if((i>a||i>b)&&(i+1<c||i+1<d)){
      if(s[i]=='#'&&s[i+1]=='#')ans=false;
    }
  }
  if(c>d){
    bool reverse=false;
    rep(i,n-2){
      if((i>=a&&i+1>=b)&&(i+1<=d)){
        if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')reverse=true;
      }
    }
    if(reverse==false)ans=false;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
    
  

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int N;
  int P=0;
  char str[50];
  scanf("%d",&N);
  for(int i=0; i<N; i++){
    scanf("%s",str);
  }
  for(int i=0; i<N; i++){
    if((str[i]=='A')&&(str[i+1]=='B')&&(str[i+2]=='C')){
      P=P+1;
    }
  }
  printf("%d",P);
}

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

using namespace std;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define pb push_back
#define mk make_pair

#define flu(i, s, e) for(int i = s; i < e; i++)
#define fld(i, s, e) for(int i = s; i >= e; i--)


int main(){
	fast;

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

	int n, m; cin >> n >> m;
	cout << n * m << endl;

	return 0;
}

Measured memory_bytes: 3652
grades = []
m, f, r = map(int, input().split())

while (m != -1 or f != -1 or r != -1):
    if (m == -1 or f == -1):
        grades.append('F')
    elif (m +f >= 80):
        grades.append('A')
    elif (m +f >= 65 and m +f < 80):
        grades.append('B')
    elif (m +f >= 50 and m +f < 65):
        grades.append('C')
    elif (m +f >= 30 and m +f < 50):
        if (r >= 50):
            grades.append('C')
        else :
            grades.append('D')
    else :
        grades.append('F')
    m, f, r = map(int, input().split())

for i in grades:
    print(i)





Measured memory_bytes: 5596
n, m, l = list(map(int, input().split()))
A = []
B = []
C = []
for i in range(n):
    A.append(list(map(int, input().split())))
for i in range(m):
    B.append(list(map(int, input().split())))
for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(sum(A[i][k] * B[k][j] for k in range(m)))
for i in range(n):
    print(" ".join(list(map(str, C[i]))))

Measured memory_bytes: 8928
def f(n):
    res = set()
    for i in range(2, int(n ** 0.5)):
        if n % i: continue
        while not n % i: n //= i
        res.add(i)
    return res | {n}
 
a, b = map(int,input().split())
print(len(f(a) & f(b) | {1}))

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let x:i64 = read();
    let mut v = vec![x];
    for _ in 0..n {
        v.push(read());
    }
    v.sort();
    let mut ans = v[1] - v[0];
    for i in 1..=n {
        ans = gcd(ans, v[i]-v[i-1]);
    }
    println!("{}", ans);
}

fn gcd(a:i64, b:i64) ->i64 {
    if b == 0 {
        return a
    }
    return gcd(b, a%b)
}

Measured memory_bytes: 3200
n,m = map(int,input().split())
lists = list(map(int, input().split()))
lists.sort()

#print(lists)
sums = sum(lists)/4/m
#print(sums)
lens = len(lists)
state = 0
for i in range(m):
    if lists[lens-1-i] < sums:
        state = 1        
        break
if state ==1:
  	print("No")
else:
  	print("Yes")

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n + 1, vector<int>(0));
    vector<int> h(n + 1);
    for(int i = 1; i <= n; ++i) {
        cin >> h[i];
    }

    for(int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int res = 0;
    for(int i = 1; i <= n; ++i) {
        bool check = true;
        for(auto v : G[i]) {
            if(h[v] >= h[i]) {
                check = false;
            }
        }
        if(check) {res++;}
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 8764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int d = sc.nextInt();
		int n = sc.nextInt();
        int value = d == 0 ? 1 : (int)Math.pow(100, d);
        int minStandard = n;
        if (n == 100) {
          minStandard++;
        }
    
		// 出力
		System.out.println(value * minStandard);
	}
}


Measured memory_bytes: 24148
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  int n;std::cin >> n;
  vector<int> cost(n, 1000000000);
  deque<pair<int, int>> q;
  q.push_back(make_pair(1, 1));
  while(!q.empty()){
    pair<int, int> tmp = q.front();q.pop_front();
    if(cost[tmp.first]<=tmp.second) continue;
    cost[tmp.first] = tmp.second;
    q.push_back(make_pair((tmp.first+1)%n, tmp.second+1));
    q.push_back(make_pair((tmp.first*10)%n, tmp.second));
  }
  std::cout << cost[0] << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;

int main() {
    string s;
    cin >> s;
    bool c[26] = {false};
    rep(i, s.size()) {
        c[s[i] - 97] = true;
    }
    int n = 26;
    rep(i, n) {
        if (c[i] == false) {
            char b = i + 'a';
            cout << b << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>　　　 
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int N=5010;
const ll INF=1e18;
#define N 5005 
int n;
struct node{
	ll h,p;
}a[N];
ll dp[N];
int ans;
bool cmp(node x,node y){
    return x.h+x.p<y.h+y.p;
}
int main(){
    scanf("%d",&n);
	for (int i=1; i<=n; i++)
        scanf("%d%d",&a[i].h,&a[i].p);
	sort(a+1,a+n+1,cmp);
	for (int i=1; i<=n; i++)
		dp[i]=INF; 
	dp[0]=0;
	for (int i=1; i<=n; i++)
		for (int j=i; j>=1; j--)
            if (dp[j-1]<=a[i].h) 
                dp[j]=min(dp[j],dp[j-1]+a[i].p);
	for (int i=0; i<=n; i++) 
        if (dp[i]<INF) ans=i;
	printf("%d\n",ans);
	return 0; 
}

Measured memory_bytes: 3320
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,cnt,sE[300002],sW[300002],ans=3*1e6+2;
char c;
int main(){
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='E'){
			sE[i]=sE[i-1]+1;
			sW[i]=sW[i-1];	
		}else {
			sE[i]=sE[i-1];
			sW[i]=sW[i-1]+1;
		}
	}
//	for(int i=1;i<=n;i++)
//		printf("%d %d\n",sW[i],sE[i]);
	for(int i=1;i<=n;i++){
		cnt=sW[i-1]+sE[n]-sE[i];
		ans=min(ans,cnt);
	}
	printf("%d",ans);
} 

Measured memory_bytes: 2560