akhauriyash/Code-Regression huggingface dataset:
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);
typedef long long ll;
typedef long double ld;
 
 
 
ll MOD=1e9 + 7;
int OO=1e9 + 1;
const int N=1e3 + 10,M=20;
char arr[N][N];
int vis[N][N];


int n,m,k,T;
int a,b,c,d;
int l,r,mid;

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

queue<pair<int,int>> q;

bool valid(int x,int y){
	return x > -1 && y > -1 && x < n && y < m;
}

void DFS(int u,int v,int val){
	if(!valid(u,v) || arr[u][v] != '.' || vis[u][v] <= val)
		return;
	vis[u][v] = val;
	q.push({u,v});
	for(int i=0;i<4;++i)
		DFS(u+dx[i],v+dy[i],val);
}

int Solve(){
	DFS(a,b,0);
	while(SZ(q)){
		int u = q.front().first;
		int v = q.front().second;
		q.pop();
		for(int i=-2;i<=2;++i){
			for(int j=-2;j<=2;++j){
				int nu = u + i;
				int nv = v + j;
				if(valid(nu,nv) && arr[nu][nv] == '.' && vis[u][v] + 1 < vis[nu][nv])
					DFS(nu,nv,vis[u][v]+1);
				
			}
		}
		
		if(vis[c][d] != OO) return vis[c][d];
	}
	return -1;
}

int main(){
	IO
	//freopen("in.txt","r",stdin);
	
	cin>>n>>m>>a>>b>>c>>d;
	--a,--b,--c,--d;
	for(int i=0;i<n;++i)
		cin>>arr[i];
		
	for(int i=0;i<n;++i)
		fill(vis[i],vis[i]+m,OO);
		
	cout<<Solve()<<endl;

}

 

Measured memory_bytes: 8528
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();

        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }

        Collections.sort(arr);
        int sum = 0;
        for (int i = 0; i<(n-1); i++){
            sum+=arr.get(i);
        }
        if (sum > arr.get(n-1)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35696
import sys
n = list(input())
int_n = int(''.join(n))
if not (111 <= int_n <= 999):
    sys.exit()

result = []
for I in n:
    if I == '1':
        result.append('9')
    elif I == '9':
        result.append('1')
    else:
        result.append(I)
print(int(''.join(result)))

Measured memory_bytes: 9176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 100001;
vector<int> g[MAX_V];

int d[MAX_V];

int N, M;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  fill(d, d + N, INF);

  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      if (d[g[v][i]] == INF) {
        d[g[v][i]] = v;
        q.push(g[v][i]);
      }
    }
  }

  for (int i = 1; i < N; i++) {
    if (d[i] == INF) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << d[i] + 1 << endl;
  }

  return 0;
}


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

r = 0
even = all(n % 2 == 0 for n in A)
while even is True:
    A = [n //2 for n in A]
    r = r +1
    even = all(n % 2 == 0 for n in A)
print(r)

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;

int main() {
    ll x,y;
    cin >> x >> y;
    ll ans=0;
    while(x<=y){
        ans++;
        x *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5+10;
const int M = 1e6+10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
inline ll C(ll y, ll x) { ll ans = 1; if(y < 0 || x < 0 || y < x) return 0; y %= mod; if(!y || !x) return 1; for0(i, x) ans = ans * (y-i) % mod; for1(i, x) ans = ans * Pow(i, mod-2) % mod; return ans; }
//==================================================================================================================================================================//

int n, m, tot, head[N], nex[N], ver[N];
int dp[N], deg[N], ans;
queue<int> q;

void add(int x, int y) {
   ver[++tot] = y, nex[tot] = head[x], head[x] = tot;
}

int main() {
   scanf("%d %d", &n, &m);
   for1(i, m) {
      int x, y;
      scanf("%d %d", &x, &y);
      add(x, y);
      deg[y]++;
   }
   for1(i, n) if(!deg[i]) q.push(i);
   while(!q.empty()) {
      int x = q.front(); q.pop();
      for(int i = head[x]; i; i = nex[i]) {
         int y = ver[i]; deg[y]--;
         dp[y] = max(dp[y], dp[x] + 1);
         if(!deg[y]) q.push(y);
      }
   }
   for1(i, n) ans = max(ans, dp[i]);
   printf("%d\n", ans);
   return 0;
}

Measured memory_bytes: 5776
stdin.ReadLine()
|> fun x ->
    x
    |> Seq.map (string >> int)
    |> Seq.toArray
    |> fun x -> (x.[0], x.[1], x.[2], x.[3])
    |> fun (a, b, c, d) -> (
        match (a, b, c, d) with
        | _ when a + b + c + d = 7 -> sprintf "%d+%d+%d+%d" a b c d
        | _ when a + b + c - d = 7 -> sprintf "%d+%d+%d-%d" a b c d
        | _ when a + b - c + d = 7 -> sprintf "%d+%d-%d+%d" a b c d
        | _ when a + b - c - d = 7 -> sprintf "%d+%d-%d-%d" a b c d
        | _ when a - b + c + d = 7 -> sprintf "%d-%d+%d+%d" a b c d
        | _ when a - b + c - d = 7 -> sprintf "%d-%d+%d-%d" a b c d
        | _ when a - b - c + d = 7 -> sprintf "%d-%d-%d+%d" a b c d
        | _ when a - b - c - d = 7 -> sprintf "%d-%d-%d-%d" a b c d
    )
    |> printfn "%s=7"


Measured memory_bytes: 14300
<?php
  
while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}
#$v2 = str_split($stdin[0]);
#$v2 = explode(" ", $stdin[0]);


$line2 = explode(" ", $stdin[1]);

foreach($line2 as $k => $v){

  $narabi[$k + 1] = $v;
  
}

asort($narabi);

$ans = NULL;

foreach($narabi as $k => $v){
  $ans .= $k . " ";
}

$ans = preg_replace("/ $/","",$ans);


echo $ans . PHP_EOL;




Measured memory_bytes: 33692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  ll n,k;
  cin>>n>>k;
  ll x[100000]={};
  for(ll i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    x[a-1]+=b;
  }
  for(ll i=0;i<100000;i++){
    k-=x[i];
    if (k<=0){
      cout<<i+1<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
   string s;
   cin >> s;
   ll sum = 0;
   rep(i, (int)s.size())sum += s[i] - '0';
   if(sum % 9 == 0)cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
const int M = 5e5+10;
int head[M],fa[M],dep[M];
long long summ[M]={0},sum1[M]={0};
int u[M],v[M],cnt1,n,q;
struct node{
    int to,next,w;
}e[M];

void add(int u,int v){
    e[++cnt1].to=v;e[cnt1].next=head[u];head[u]=cnt1;
    e[++cnt1].to=u;e[cnt1].next=head[v];head[v]=cnt1;
}
void dfs1(int u,int faz,long long sum){
    fa[u] = faz;
    summ[u]+=sum;
    for(int i = head[u];i ;i=e[i].next){
        int v = e[i].to;
        if(v != fa[u]){
            dfs1(v,u,sum+sum1[v]);
        }
    }
}
int main()
{
	scanf("%d %d",&n,&q);
	int c,d;
	for(int i=0;i<n-1;i++)
	{
		scanf("%d %d",&c,&d);
		add(c,d);
	}
	for(int i=0;i<q;i++)
	{
		scanf("%d %d",&c,&d);
		sum1[c]+=d;
	}
	dfs1(1,0,sum1[1]);
	for(int i=1;i<=n;i++)printf("%lld ",summ[i]);
	printf("\n");
}

Measured memory_bytes: 29952
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String half = S.substring(0, N /2);
		if(N % 2 ==0 && S.matches(half.concat(half))){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
fn main() {
    let s = read::<String>();
    let ret;
    if s == "SUN" {
        ret = 7;
    } else if s == "MON" {
        ret = 6;
    } else if s == "TUE" {
        ret = 5;
    } else if s == "WED" {
        ret = 4;
    } else if s == "THU" {
        ret = 3;
    } else if s == "FRI" {
        ret = 2;
    } else {
        ret = 1;
    }

    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


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

asum = sum(a)
num = 0
ai = 0
for i in range(n):
    num += a[i]
    ai = i
    if num * 2 >= asum:
        break

f1 = asum - num
b1 = num

num -= a[ai]
f2 = asum - num
b2 = num

print(min(abs(f1 - b1), abs(b2 - f2)))

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

typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printArray(arr) for (int i = 0; i<size(arr); i++) cout << arr[i] << '\n';cout << '\n'
#define printVerdict(verdict) cout << (verdict ? "YES": "NO") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)

const int inf = 0x3f3f3f3f;

template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) {cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n';}
template <class T1, class T2>
void printPair(pair<T1, T2> p) {cout << p.first << " " << p.second << '\n';}


int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int curr = 0, ret = 0;
	for (int i = 0; i<size(s);i++) {
		if (s[i] == 'S') {
			ret = max(ret, curr);
			curr = 0;
		}
		else curr++;
	}
	ret = max(ret, curr);
	cout << ret << '\n';
}



Measured memory_bytes: 3540
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

int n;
char c[N];
int power(ll x,int b,int mod){
    ll res=1;
    while(b){
        if(b&1) res=res*x%mod;
        x=x*x%mod;
        b/=2;
    }
    return res;
}
int get(int sum){
    int ans=0;
    while(sum){
        int temp=sum,x=0;
        while(temp){
            x+=(temp%2);
            temp/=2;
        }
        sum%=x;
        ans++;
    }
    return ans;
}
signed main(){
    FastIO;
    cin>>n;
    int one=0;
    rep(i,1,n){
        cin>>c[i];
        one+=(c[i]=='1');
    }
    int suma=0,sumb=0,moda=one-1,modb=one+1,pa=1,pb=1;
    repb(i,n,1){
        if(moda) suma=(suma+pa*(c[i]-'0'))%moda;
        sumb=(sumb+pb*(c[i]-'0'))%modb;
        if(moda) pa=pa*2%moda;
        pb=pb*2%modb;
    }
    rep(i,1,n){
        int sum;
        if(c[i]=='1'){
            if(moda==0){
                cout<<"0\n";
                continue;
            }
            sum=(suma-power(2,n-i,moda)+moda)%moda;
        }
        else{
            sum=(sumb+power(2,n-i,modb))%modb;
        }
        cout<<1+get(sum)<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3832
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, x, n);
    VI was(102, 1);
    for(int i = 0; i < n; ++i){
        make(int, q);
        was[q] = 0;
    }
    int ans = 0, df = 1000;
    for(int i = 0; i < was.size(); ++i){
        if (was[i] && abs(i - x) < df){
            df = abs(i - x);
            ans = i;
        }
    }
    cout << ans;


    return 0;
}

Measured memory_bytes: 3656
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  ll n,k;
  double ans = 0;
  cin >> n >> k;
  vector<double> p(n),sum(n+1);
  sum[0] = 0;
  for(int i=0;i<n;i++){
    cin >> p[i];
    sum[i+1] += sum[i];
    p[i] = (p[i]+1)/2;
    sum[i+1] += p[i];
  }
  for(int i=0;i+k<=n;i++){
    ans = max(ans,sum[i+k]-sum[i]);
  }
  printf("%.10lf\n",ans);
}


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

int main() {
    int n;
    cin>>n;
    long int a[n+1]; //n=1だとまずそうなので

    a[0]=2;
    a[1]=1;
    if(n>=2){
        for(int i=2;i<=n;i++){
            a[i]=a[i-1]+a[i-2];
        }
    }

    cout<<a[n]<<endl;
}

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

int main(){
    int n;
    cin>>n;
    string s;
    int a=0,w=0,t=0,r=0;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s == "AC"){
            a++;
        }
        if(s == "WA"){
            w++;
        }
        if(s == "TLE"){
            t++;
        }
        if(s == "RE"){
            r++;
        }
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
//using ll=long long;

int main(){
    int N;
    cin >> N;
    vector<int> a;
    for(int i = 0; i < N; ++i){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    int count = 1;
    vector<pair<int,int> > b;
    if(N == 1){
        b.push_back(make_pair(a[0],count));
    } else {
        for(int i = 0; i < N - 1; ++i){
            if(a[i+1] == a[i]) ++count;
            else{
                b.push_back(make_pair(a[i],count));
                count = 1;
            }
        }
        b.push_back(make_pair(a[N-1],count));
    }
    
    int ans = 0;
    if(b.size()==1){
        ans = b[0].second;
    } else if(b.size()==2){
        if(b[0].first + 3 > b[1].first) ans = b[0].second + b[1].second;
        else ans = max(b[0].second, b[1].second);
    } else {
        for(int i = 0; i < b.size()-2; ++i){
            if(b[i].first + 2 == b[i+2].first){
                int temp = b[i].second + b[i+1].second + b[i+2].second;
                ans = max(temp, ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>

using namespace std;

int main(){
    vector<int> x(3);
    cin >> x[0] >> x[1] >> x[2];

    sort(x.begin(),x.end());

    int ans = x[2] * 10 + x[1] + x[0];

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n;
	cin >> n;
	vector<int> A(n);
	vll pre(n + 1);
	vvll dp(n, vll(n));
	REP(n) {
		cin >> A[i];
		pre[i + 1] = pre[i] + A[i], dp[i][i] = A[i];
	}
	for(int p = 1; p < n; p++) {
		for(int i = 0; i < n - p; i++) {
			int j = i + p;
			dp[i][j] = max(A[i] + pre[j + 1] - pre[i + 1] - dp[i + 1][j],
					A[j] + pre[j] - pre[i] - dp[i][j - 1]);
		}
	}
	cout << 2*dp[0][n - 1] - pre[n] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 73636
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 100050;
int N, M;
long long A[MAX_N];

int main(int argc, char **argv) {
    //std::cout << "ret:" << std::endl;
    std::cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }
    
    int tmp = 0;
    std::vector<int> accum;

    for (int i = 1; i <= N; i++) {
        tmp = tmp % M;
        accum.push_back(tmp);
        tmp += A[i];
    }
    tmp = tmp % M;
    accum.push_back(tmp);

    std::sort(accum.begin(), accum.end());

    long long size = 0;
    tmp = 0;
    long long ret = 0;
    for (int i = 0; i < accum.size(); i++) {
        //std::cout << accum[i] << " ";
        if (accum[i] == tmp) {
            size++;
        } else {
            ret += size * (size - 1) / 2;

            size = 1;
            tmp = accum[i];
        }
    }
    ret += size * (size - 1) / 2;
    
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1660
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = [input() for _ in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i][j:j+2] + S[i+1][j:j+2]
        t.append(r.count('.')%2)
    ts = [T[-1][i] + 1 if not k else 0 for i, k in enumerate(t) ]
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT+[0]):
        dw = -1
        while stack and stack[-1][1] >= l:
            dw, dh = stack.pop()
            ans = max(ans, (dh+1)*(i-dw+1))
        if dw != -1:
            stack.append((dw,l))
            continue
        stack.append((i, l))
print(ans)

Measured memory_bytes: 108632
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    bool match;
    string ans = "No";
    for (int i = 0; i <= n - m; i++) {
        for (int j = 0; j <= n - m; j++) {
            match = true;
            for (int k = 0; k < m; k++) {
                for (int l = 0; l < m; l++) {
                    if (a[i+k][j+l] != b[k][l]) match = false;
                }
            }
            if (match) ans = "Yes";
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
void myInit();
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int MOD = 1000000007;
const int N = 3e5, M = N;
//=========TQR==============
vi g[N];
int a[N];

int main() {
	myInit();
	FIO;
	int k, n, i;
	string s;
	cin >> k >> s;
	n = s.length();
	if (k >= n) {
		cout << s << endl;
		return 0;
	}
	s = s.substr(0, k);
	s += "...";
	cout << s << endl;
	return 0;
}

void myInit() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mpow(int base, int exp) {
	base %= MOD;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % MOD;
		base = ((ll)base * base) % MOD;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		g[u - 1].pb(v - 1);
		g[v - 1].pb(u - 1);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main() {
  int N,B=30;
  cin >> N;
  for(int i=0; i<N; i++){
    int A,C=0;
    cin >> A;
    for(;A%2==0;A/=2)
      C++;
    if(C<B)
      B=C;
  }
  cout << B << endl;
}

Measured memory_bytes: 256
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ps = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int ret = 0;
            for (int i = 0; i < ps.Length -2; i++)
            {
                if (ps[i] < ps[i + 1] && ps[i + 1] < ps[i + 2] ||
                    ps[i] > ps[i + 1] && ps[i + 1] > ps[i + 2])
                {
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

Measured memory_bytes: 11348
fun main(args: Array<String>) {
    var (a, b) = readLine()!!.split(' ').map(String::toInt)
    var x = b
    var cnt = 0
    while(x != 0) {
        a *= 10
        x /= 10
    }

    x = a + b

    for(i in 1..x) {
        if(i * i == x) {
            x = -1
            break
        }
    }
    print(if(x == -1) "Yes" else "No")
}

Measured memory_bytes: 38184
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p, q = 0, 0
for i in range(n):
    if a[i] > b[i]:
        p += a[i] - b[i]
    elif a[i] < b[i]:
        q += (b[i] - a[i]) // 2

if p <= q:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
#include<bits/stdc++.h>
#include<string>
#include<cctype> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  long long X,A,B;
  int a,ans;    
  cin >> X >> A >> B;
  
  a=A+X;
  if(B<=A){
    cout << "delicious" << endl;
  }else if(B<=a){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
   



  return 0;
} 


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

void solve(){
    long long a,b,k;
    cin>>a>>b>>k;
    if(k<=a) cout << a-k << " " << b;
    else if((k-a) <= b) cout << 0 << " " << b-(k-a);
    else cout << 0 << " " << 0;

}


int main(){
   solve();

}

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

int main()
{
	scanf("%d%d",&a,&b);
	if(a>0&&b>0) printf("Positive\n");
	else if(a<0&&b<0){
		if((b-a+1)%2==1) printf("Negative\n");
		else printf("Positive\n");
	}
	else printf("Zero\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int i;

		for(i=1; i<=n; i++){
			if(i > n) break;
			String x = String.valueOf(i);
			if (((i%3) == 0) || ((i%10) == 3) || ((i/10) == 3)) {
				System.out.print(" " + i);
			}
			else if (x.contains("3")) {
				System.out.print(" " + i);
			}
				
		}
		System.out.println();
	}

}

Measured memory_bytes: 29880
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long A[200000];
long long B[200000];
long long cumsum_A[200000];
long long cumsum_B[200000];
int main(){
  int N;
  int M;
  long long K;
  cin >> N >> M >> K;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  cumsum_A[0] = A[0];
  for(int i = 1; i < N; i++){
    cumsum_A[i] = A[i] + cumsum_A[i - 1];
  }
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  cumsum_B[0] = B[0];
  for(int i = 1; i < M; i++){
    cumsum_B[i] = B[i] + cumsum_B[i - 1];
  }

  int ans = 0;
  auto it = upper_bound(cumsum_B, cumsum_B + M, K);
  ans = max(ans, (int) (it - cumsum_B));
  for(int i = 0; i < N; i++){
    if(cumsum_A[i] > K){
      break;
    }
    long long left = K - cumsum_A[i];
    auto it = upper_bound(cumsum_B, cumsum_B + M, left);
    int cur_ans = (i + 1) + (it - cumsum_B);
    ans = max(ans, cur_ans);
  }
  cout << ans << endl;
  return 0;
}


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

struct P {
    int a;
    int b;

    bool operator<(const P &another) const {
        if (b == another.b)
            return a > another.a;
        else
            return b < another.b;
    };
};

int main() {
    int N,M;
    cin >> N >> M;
    vector<P> I;
    rep(i,M){
      int a,b;
      cin >> a >> b;
      a--;b--;
      I.push_back({a,b});
    }
    sort(all(I));

    int ans = 0;
    int mx = 0;
    rep(i,M){
        if(!(I[i].a < mx && mx <= I[i].b)){
          ans++;
          mx = I[i].b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int a, b, c;
	int tmp;
	cin >> a;
	cin >> b;
	cin >> c;
	tmp = a;
	a = b;
	b = tmp;
	tmp = c;
	c = a;
	a = tmp;
	cout << a << " ";
	cout << b << " ";
	cout << c;

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 888
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

ll n,ans=0;
vector<ll> a(n),b(n);
const int M = 2;
void dfs(vector<int> &A) {
    // 終端条件 --- 10 重ループまで回したら処理して打ち切り
    if (A.size() == n) {
        return;
    }

    for (int v = 0; v < M; ++v) {
        A.push_back(v);
        dfs(A);
        A.pop_back(); // これが結構ポイント
    }
}

int main(){
  ll a,b;
  cin>>a>>b;
  // vector<ll> a(n);
  // a.resize(n); b.resize(n);
  // rep(i,n){
  //   cin>>a[i]>>b[i];
  // }

  // vector<int> A;
  // dfs(A);
  

  cout<<a*b;


  return 0;
}

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

using namespace std;


int main() {
    int n,m;
    cin >> n >> m;
    vector<int> ans(n,0);
    for(int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        ans[--a]++;
        ans[--b]++;
    }
    for(int i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

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

int main() {

  int h1, h2, m1, m2, k, minute;
  
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  

  minute = (h2 * 60 + m2) - (h1 * 60 + m1);
  if(minute <= k){
    cout << 0;
  }
  else{
    cout << minute - k;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int,vector<int>,greater<int>> Q;
  rep(i, 0, N) {
    int A; cin >> A;
    Q.push(A);
  }
  using P = pair<int, int>;
  vector<P> D;
  rep(i, 0, M) {
    int B, C;
    cin >> B >> C;
    D.push_back({C, B});
  }
  sort(D.begin(), D.end(), greater<P>());
  ll ans = 0;
  rep(i, 0, M) {
    int n = D[i].second;
    while(!Q.empty() && n && D[i].first > Q.top()) {
      Q.pop();
      n--;
      ans += D[i].first;
    }
  }
  while(!Q.empty()) {
    ans += Q.top();
    Q.pop();
  }
  cout << ans << endl;
  return 0;
}


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


int main()
{
	string s, line[81];
	while (getline(std::cin, s)){
		fill(line, line + 81, "");
		int counter = 0;
		s += "\n";

		//入力内容を配列にとる．
		string word = "";
		for (int i = 0; i < (signed)s.length(); i++){
			if (s[i] == ' ' || s[i] == '\n'){
				line[counter++] = word;
				word = "";
			}
			else{
				word += s[i];
			}
		}



		//ずらす数を探す
		int slide;
		for (int i = 0; i <= 26; i++){
			for (int j = 0; j < counter; j++){
				string word = "";
				for (int k = 0; k < (signed)line[j].length(); k++){
					if (line[j][k] != '.' && line[j][k] != ' '&& line[j][k] != '\n'){
						word += 'a' + (line[j][k] + i - 'a') % 26;
					}
					else{
						word += line[j][k];
					}
				}
				if (word == "the" || word == "this" || word == "that"){
					slide = i;
					goto jump;
				}

			}
		}

	jump:

		//ずらすべき数だけずらす
		for (int i = 0; i < counter; i++){
			for (int j = 0; j < (signed)line[i].length(); j++){
				if (line[i][j] != '.' && line[i][j] != ' '&& line[i][j] != '\n'){
					line[i][j] = 'a' + (line[i][j] + slide - 'a') % 26;
				}
			}
		}

		//出力
		for (int i = 0; i < counter - 1; i++){
			cout << line[i] << " ";
		}
		cout << line[counter - 1] << endl;

	}
	return 0;
}

Measured memory_bytes: 1184
def main():
    S = input()
    T = input()
    ans = len(T)
    for base in range(len(S) - len(T) + 1):
        diff = 0
        for i in range(len(T)):
            if S[base+i] != T[i]:
                diff += 1
        ans = min(ans, diff)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73148
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
// #define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int main(){
	char b; cin>>b;
	if(b=='A')ote('T');
	if(b=='T')ote('A');
	if(b=='C')ote('G');
	if(b=='G')ote('C');
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
using namespace std;

signed main() {
  int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    	string s(a,'0');
    	string t(w-a,'1');
        string ans=s+t;
  		string S(a,'1');
  		string T(w-a,'0');
  		string Ans=S+T;
  for(int i=0;i<h;i++){
    if(i<b){
    	printf("%s\n",ans.c_str());
        //cout<<s<<endl;
    }
    else{
    	printf("%s\n",Ans.c_str());
        //cout<<S<<endl;
    }
  }
}

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

int main() {
  ll n;
  cin >> n;
  int x = 0, nn = n;
  while (nn > 0) {
    x += nn % 10;
    nn /= 10;
  }
  cout << (n % x == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  bool ok = true;
  for (int i = 0; i < s.size(); i++) {
    if (i%2 == 0 && s[i] == 'L') {
      ok = false;
    } else if (i%2 != 0 && s[i] == 'R') {
      ok = false;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll a,b,k;

int main(){
    cin >> a >> b >> k;
    rep(i,k){
        a = a / 2 * 2;
        b += a / 2;
        a /= 2;
        swap(a,b);
    }
    if(k % 2 == 0)cout << a << " " << b << endl;
    else cout << b << " " << a << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
fn main() {
    input! {
        n: usize,
        ss:[String;n],
        m:usize,
        ts:[String;m],
    }
    let mut hms = HashMap::<String, _>::new();
    let mut hmt = HashMap::<String, _>::new();
    for s in ss {
        *hms.entry(s).or_insert(0) += 1;
    }
    for t in ts {
        *hmt.entry(t).or_insert(0) += 1;
    }
    let mut res = 0;
    for (k, v) in hms {
        res = std::cmp::max(res, v - hmt.get(&k).or(Some(&0)).unwrap());
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(){
	int nm,nd,i;
	int M[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	while(1){
		scanf("%d %d",&nm,&nd);
		if(nm==0)break;
		int d=2;
		int m;
		if(0<nm&&nm<13){
			if(0<nd&&nd<M[nm]+1){
				for(i=nm-1;i>0;i--){
					d+=M[i];
				}
				d+=nd;
				if(d%7==0)printf("Monday\n");
				if(d%7==1)printf("Tuesday\n");
				if(d%7==2)printf("Wednesday\n");
				if(d%7==3)printf("Thursday\n");
				if(d%7==4)printf("Friday\n");
				if(d%7==5)printf("Saturday\n");
				if(d%7==6)printf("Sunday\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 580
s = input()
ans_ptn1 = ""
ans_ptn2 = ""

for i in range(len(s)):
    if i % 2 == 0:
        ans_ptn1 += "0"
        ans_ptn2 += "1"
    else:
        ans_ptn1 += "1"
        ans_ptn2 += "0"

ans1 = 0
ans2 = 0
for i in range(len(s)):
    if s[i] == ans_ptn1[i]:
        ans1 += 1
    if s[i] == ans_ptn2[i]:
        ans2 += 1
        
print(min(ans1,ans2))

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


int main() {
  int n, temp;
  cin >> n;
  int ans = 0;
  int p_min = 1000000;
  for (int i=0; i < n; i++) {
    cin >> temp;
    if (p_min >= temp) {
      p_min = temp;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	scanf("%d" , &a);
	scanf("%d" , &b);
	scanf("%d" , &c);
	
	if(a==1)
	{
		printf("Hello World\n");
		return 0;
	}
	else
	{
		printf("%d\n", b+c);
		return 0;
	}
	
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

struct Point {
	int x;
	int y;
	int z;
};
struct Pip {
	int n;
	struct Point p;
};
struct Dice {
	struct Pip pip[6];
};

const struct Point top    = { 0,  0,  1};
const struct Point front  = { 0, -1,  0};
const struct Point right  = { 1,  0,  0};
const struct Point left   = {-1,  0,  0};
const struct Point back   = { 0,  1,  0};
const struct Point bottom = { 0,  0, -1};
const char *d = "NEWSRL";
const int r[6][3][3] = {
	{{ 1,  0,  0}, { 0,  0,  1}, { 0, -1,  0}}, // N
	{{ 0,  0,  1}, { 0,  1,  0}, {-1,  0,  0}}, // E
	{{ 0,  0, -1}, { 0,  1,  0}, { 1,  0,  0}}, // W
	{{ 1,  0,  0}, { 0,  0, -1}, { 0,  1,  0}}, // S
	{{ 0,  1,  0}, {-1,  0,  0}, { 0,  0,  1}}, // R
	{{ 0, -1,  0}, { 1,  0,  0}, { 0,  0,  1}}, // L
};

int comparePoints(struct Point p0, struct Point p1)
{
	if (p0.x == p1.x && p0.y == p1.y && p0.z == p1.z) {
		return 1;
	}
	return 0;
}

void roll(struct Dice *dice, char c)
{
	char *p = strchr(d, c);
	int n = p - d;
	for (int i = 0; i < 6; i++) {
		struct Point *p = &dice->pip[i].p;
		int x = p->x;
		int y = p->y;
		int z = p->z;
		p->x = x * r[n][0][0] + y * r[n][0][1] + z * r[n][0][2];
		p->y = x * r[n][1][0] + y * r[n][1][1] + z * r[n][1][2];
		p->z = x * r[n][2][0] + y * r[n][2][1] + z * r[n][2][2];
	}
}

int getNumber(struct Dice *dice, struct Point p)
{
	int num = 0;
	for (int i = 0; i < 6; i++) {
		struct Pip pip = dice->pip[i];
		if (comparePoints(pip.p, p)) {
			num = pip.n;
			break;
		}
	}
	return num;
}

int main(void)
{
	struct Dice dice = {
		{{1, top}, {2, front}, {3, right},
		{4, left}, {5, back}, {6, bottom}}
	};
	for (int i = 0; i < 6; i++) {
		scanf("%d", &dice.pip[i].n);
	}
	char order[101];
	scanf("%s", order);
	for (char *p = order; *p; p++) {
		roll(&dice, *p);
	}
	printf("%d\n", getNumber(&dice, top));
	return 0;
}



Measured memory_bytes: 2100
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    B = list( map( int, input().split()))
    ans = B[0]+B[-1]
    for i in range(1, N-1):
        ans += min(B[i], B[i-1])
    print(ans)
if __name__ == '__main__':
    main()


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

struct SegmentTree
{
    private:
        int n;
        vector<int> node;
    public:
        SegmentTree(vector<int> v)
        {
            int sz = v.size();
            n = 1;
            while (n < sz) {
                n *= 2;
            }
            node.resize(2 * n - 1, __INT32_MAX__);

            for (int i = 0; i < sz; i++) {
                node[n - 1 + i] = v[i];
            }
            for (int i = n - 2; i >= 0; i--) {
                node[i] = min(node[2 * i + 1], node[2 * i + 2]);
            }
        }

        void update(int x, int val)
        {
            x += (n - 1);
            node[x] = val;
            while (x > 0) {
                x = (x - 1) / 2;
                node[x] = min(node[2 * x + 1], node[2 * x + 2]);
            }
        }

        int getmin(int a, int b, int k = 0, int l = 0, int r = -1) 
        {
            if (r < 0) r = n;
            if (l >= b || r <= a) return __INT32_MAX__;

            if (a <= l && r <= b) return node[k];

            int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }

        void show()
        {
            rep(i, 2 * n - 1) {
                cout << "i: " << i << ", node[i]: " << node[i] << endl;
            }
        }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    SegmentTree seg(vector<int>(N, pow(2, 31) - 1));
    vi C(Q), X(Q), Y(Q);
    rep(i, Q) {
        cin >> C[i] >> X[i] >> Y[i];
    }

    rep(i, Q) {
        if (C[i] == 0) {
            seg.update(X[i], Y[i]);

        } else {
            cout << seg.getmin(X[i], Y[i] + 1) << endl;
        }
    }
}


Measured memory_bytes: 5040
#include <bits/stdc++.h>
#define N 140020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}

int ls[N], rs[N], val[N];

typedef pair<int, int> prpr;
vector<prpr> f[N];

inline bool cmpx(prpr a, prpr b) {
  return a.first < b.first;
}
inline bool cmpy(prpr a, prpr b) {
  return a.second < b.second;
}

int MID, mn[N<<1];

void work(int x) {
  vector<prpr> &f = ::f[x], &ls = ::f[::ls[x]], &rs = ::f[::rs[x]];

  if (ls.size() > rs.size()) {
    swap(ls, rs);
  }

  sort(ls.begin(), ls.end(), cmpy);
  sort(rs.begin(), rs.end(), cmpx);

  mn[0] = rs[0].second;
  for (size_t i = 1; i < rs.size(); ++ i) {
    mn[i] = min(mn[i - 1], rs[i].second);
  }

  for (size_t i = 0, j = rs.size() - 1; i < ls.size(); ++ i) {
    while (~j && ls[i].second + rs[j].first > MID) -- j;
    if (~j) f.push_back(prpr(ls[i].first, mn[j]));
  }

  sort(ls.begin(), ls.end(), cmpx);
  sort(rs.begin(), rs.end(), cmpy);

  mn[0] = rs[0].first;
  for (size_t i = 1; i < rs.size(); ++ i) {
    mn[i] = min(mn[i - 1], rs[i].first);
  }

  for (size_t i = 0, j = rs.size() - 1; i < ls.size(); ++ i) {
    while (~j && ls[i].first + rs[j].second > MID) -- j;
    if (~j) f.push_back(prpr(mn[j], ls[i].second));
  }

}

void dfs(int x) {
  f[x].clear();
  if (!ls[x]) {
    f[x].push_back(prpr(0, 0));
    return;
  }

  dfs(ls[x]);
  dfs(rs[x]);

  for (prpr &pr : f[ls[x]]) {
    pr.first += val[ls[x]];
    pr.second += val[ls[x]];
  }
  for (prpr &pr : f[rs[x]]) {
    pr.first += val[rs[x]];
    pr.second += val[rs[x]];
  }

  work(x);
}

int main(int argc, char const *argv[]) {
  
  int n = read();
  for (int i = 2; i <= n; ++ i) {
    int f = read();
    val[i] = read();
    if (ls[f]) rs[f] = i;
    else ls[f] = i;
  }

  int l = 0, r = 1e9;

  while (l <= r) {
    MID = (l + r) >> 1;
    dfs(1);
    // printf("%d %d\n", MID, f[1].empty());
    if (!f[1].empty()) {
      r = MID - 1;
    } else {
      l = MID + 1;
    }
  }

  printf("%d\n", r + 1);

  return 0;
}
/*

直接 dp.

len[i] -> i 子树中的最长链
ren[i] -> i 子树中的次长链（这两个来自两个不同的儿子）

res[i] -> i 子树中的最大答案


*/

Measured memory_bytes: 18296