akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<int, lld> pil;
typedef pair<pii, int> piii;
int n, m, p;
long long int M = 998244353;
long long int Mp = 476;
long long int wlist[29];
long long int wlist_inv[29];
long long int expp(long long int p, long long int q) {
	long long int r = 1;
	long long int z = p % M;
	while (q) {
		if (q & 1) { r = (r * z) % M; }
		q >>= 1;
		if (q) { z = (z * z) % M; }
	}
	return r;
}
void inil() {
	long long int w = expp(3, Mp);
	wlist[21] = w;
	wlist_inv[21] = expp(w, M - 2);
	for (int i = 20; i >= 0; i--) {
		wlist[i] = (wlist[i + 1] * wlist[i + 1]) % M;
		wlist_inv[i] = (wlist_inv[i + 1] * wlist_inv[i + 1]) % M;
	}
}
void fft(vector <long long int>& a, bool invert)
{
	int n = a.size();
	for (int i = 1, j = 0; i < n; i++) {
		int bit = n >> 1;
		for (; j >= bit; bit >>= 1) j -= bit;
		j += bit;
		if (i < j) swap(a[i], a[j]);
	}
	int li = 1;
	for (int len = 2; len <= n; len <<= 1) {
		long long int wlen = invert ? wlist_inv[li] : wlist[li];
		for (int i = 0; i < n; i += len) {
			long long int w = 1;
			for (int j = 0; j < len / 2; j++) {
				long long int u = a[i + j], v = (a[i + j + len / 2] * w) % M;
				a[i + j] = (u + v) % M;
				a[i + j + len / 2] = (u + M - v) % M;
				w = (w * wlen) % M;
			}
		}
		li++;
	}
	if (invert) {
		static unordered_map<int, long long int> memoi;
		if (memoi.find(n) == memoi.end())memoi[n] = expp(n, M - 2);
		long long int invzn = memoi[n];
		for (int i = 0; i < n; i++) a[i] = (a[i] * invzn) % M;
	}
}

void multiply(const vector<long long int>& a, const vector<long long int>& b, vector<long long int>& res)
{
	vector <long long int> fa(a.begin(), a.end()), fb(b.begin(), b.end());
	int n = 1;
	while (n < a.size() + b.size()) n <<= 1;
	fa.resize(n); fb.resize(n);
	fft(fa, false); fft(fb, false);
	for (int i = 0; i < n; i++) fa[i] = (fa[i] * fb[i]) % M;
	fft(fa, true);
	res.resize(n);
	for (int i = 0; i < n; i++) res[i] = fa[i];
	while (n > 1) { if (res[n - 1] == 0)n--; else break; }
	res.resize(n);
}
vector<lld> a;
void expp_a(lld n) {
	if (n == 0) {
		a.clear();
		a.push_back(1);
		return;
	}
	else if (n & 1) {
		expp_a(n - 1);
		vector<lld> b;
		b.resize(2);
		b[0] = m - 1;
		b[1] = 1;
		multiply(a, b, a);
	}
	else {
		expp_a(n / 2);
		multiply(a, a, a);
	}
}
int main()
{
	inil();
	int i, j, k, l;
	int t = 1, tv = 0;
	while(t--)
	{
		scanf("%d %d %d", &n, &m, &p);
		expp_a(n - 1);
		lld res = 0;
		for (i = 0; i <= p; i++) {
			if (i >= a.size())break;
			res = (res + (lld)m*a[i])%M;
		}
		printf("%lld\n", res);
	}
}

Measured memory_bytes: 11556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s;
  in(s);
  bool h = true;
  if(s[2] != s[3])
    h = false;
  if(s[4] != s[5])
    h = false;
  if(h)
    out("Yes");
  else
    out("No");
  memi;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N = S.size();
  int R = 0;
  int B = 0;
  rep(i,N) 
  {
    if(S[i]=='0')
    {
      R ++;
    }
  }
  B = N - R;
  cout << min(B,R) * 2 << endl;
  return 0;
}


Measured memory_bytes: 512
def get_answer():
  x = int(input())
  
  is_get = False
  for a in range(1000000000):
    if is_get:
      break
    for b in range(-1*a, a, 1):
      if x == a**5 - b**5:
        is_get = True
        break
        
  print(f"{a-1} {b}")

if __name__ == "__main__":
  get_answer()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 

int main(){
	VL A(3);
    cin>>A[0]>>A[1]>>A[2];
    sort(A.begin(),A.end());
    if(A[0]==5&&A[1]==5&&A[2]==7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,m,c,b[20],a[20][20],s=0,k=0,i,j;

	scanf("%d%d%d",&n,&m,&c);
	for(i=0;i<m;i++)
		scanf("%d",&b[i]);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			scanf("%d",&a[i][j]);

	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
			s+=a[i][j]*b[j];
		if(s+c>0)
			k++;
		s=0;
	}
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 128
N,K=(int(x) for x in input().split())
i=1
p=[]
while i<=N:
    p.append(int(input()))
    i=i+1

p.sort()
high=[]
i=0
while i+K<=N:
        L=int(K+i)
        a = p[int(L-1)]
        b = p[i]
        deff = int(a - b)
        high.append(int(deff))
        i = i + 1

print(int(min(high)))

Measured memory_bytes: 11192
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }

template <typename T> struct SegmentTree {
private:
    int n;
    vector<T> node;
public:
    SegmentTree(vector<T> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n - 1, INF<T>());
        for(int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = min(node[2*i + 1], node[2*i + 2]);
    }

    //xをvalに変更する
    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]);
        }
    }
    //[a,b)の最小値を求める
    int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF<T>();
        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);
    }
};

int n, q;

int main() {
    cin >> n >> q;
    SegmentTree<int> seg( vector<int>(n, INF<int>()) );
    for(int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0) seg.update(x, y);
        else cout << seg.getmin(x, y + 1) << endl;
    }
}


Measured memory_bytes: 4084
a, b, c, d = map(int, input().split())

def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

x = (b - (b//c)) + (b - (b//d)) - (b - (b//lcm(c, d)))
y = (a-1 - ((a-1)//c)) + (a-1 - ((a-1)//d)) - (a-1 - ((a-1)//lcm(c, d)))

print(x-y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    vector<char> v(26,'A'),u;//Tで出たら対応するSを入れる
    u=v;
    string s,t;
    cin >> s >> t;
    
    for(int i=0;i < t.size();i++)
    {   
        if(v.at(t.at(i)-'a')=='A'){
            v.at(t.at(i)-'a')=s.at(i);
        }else if(v.at(t.at(i)-'a')!=s.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i=0;i < t.size();i++)
    {   
        if(u.at(s.at(i)-'a')=='A'){
            u.at(s.at(i)-'a')=t.at(i);
        }else if(u.at(s.at(i)-'a')!=t.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}
/*できないとき
違う文字を同じアルファベットにするとき
これで十分か？たぶん*/

Measured memory_bytes: 776
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;

int a[2000],b[2000],c = 0;

int main(){
    for(int p = 0;;p++){
        int n,m;
        scanf("%d%d",&n,&m);
        if(n == 0 && m == 0) {
            c = p;
            break;
        }
        b[p] = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",&a[i]);
        }
        for(int i = 0;i < n;i++){
            for(int j = i + 1;j < n;j++){
                if(a[i] + a[j] <= m){
                    b[p] = max(b[p],a[i] + a[j]);
                }
            }
        }
    }
    for(int i = 0;i < c;i++){
        if(b[i] == 0) printf("NONE\n");
        else printf("%d\n",b[i]);
    }
    

}


Measured memory_bytes: 3192
#require 'prime'
#require 'openssl'
MOD=1000000007;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
s1=gs
s2=gs
putsend 3 if n==1

cnt=0
i=0

if s1[0]==s1[1]
  cnt=6
  i=2
else
  cnt=3
  i=1
end

while i<n
  # == ==
  if i>=2 && s1[i-1]==s1[i-2] && s1[i]==s1[i+1]
    cnt*=3
    i+=2
  # ==|
  elsif i>=2 && s1[i-1]==s1[i-2] && s1[i]!=s1[i+1]
    i+=1
  # |==
  elsif s1[i]==s1[i+1]
    cnt*=2
    i+=2
  # ||
  else
    cnt*=2
    i+=1
  end
end

puts cnt%MOD

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Searching Constellation
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			List<int[]> S = new ArrayList<>();

			for (int i = 0; i < n; i++) {
				line = br.readLine();
				int x, y;
				x = parseInt(line.substring(0, line.indexOf(' ')));
				y = parseInt(line.substring(line.indexOf(' ') + 1));
				S.add(new int[]{x, y});
			}

			int m = parseInt(br.readLine());
			Map<Integer, Set<Integer>> T = new HashMap<>();

			for (int i = 0; i < m; i++) {
				line = br.readLine();
				int x, y;
				x = parseInt(line.substring(0, line.indexOf(' ')));
				y = parseInt(line.substring(line.indexOf(' ') + 1));
				T.putIfAbsent(x, new HashSet<>());
				T.get(x).add(y);
			}

			//solve
			int dx, dy;
			dx = dy = -1;

			outer:
			for (int tx : T.keySet()) {
				for (int ty : T.get(tx)) {
					dx = tx - S.get(0)[0];
					dy = ty - S.get(0)[1];
					for (int i = 1; i < S.size(); i++) {
						int nx, ny;
						nx = S.get(i)[0] + dx;
						ny = S.get(i)[1] + dy;
						if (!T.containsKey(nx) || !T.get(nx).contains(ny)) {
							continue outer;
						}
					}
					break outer;
				}
			}

			System.out.println(dx + " " + dy);

		}
	}
}

Measured memory_bytes: 29504
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;

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


Measured memory_bytes: 256
import Control.Monad
import Data.List
import Data.Array

main = do
  n <- readLn
  xs <- map read . words <$> getLine :: IO [Int]
  let xs_ = sort xs
      m1 = xs_ !! (n `div` 2 - 1)
      m2 = xs_ !! (n `div` 2)
  mapM_ (print . solve (m1, m2) (listArray (1, n+1) xs)) [1..n]

solve (n, m) xs i =
    if xs ! i <= n then m else n

Measured memory_bytes: 146812
#include <stdio.h>
#define n 100005
#define q 50005

int main(){
  int i,j,count=0,S[n],T[q],Ain,Bin,left,right,mid;

  scanf("%d",&Ain);  
  for(i=0;i<Ain;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&Bin);
  for(i=0;i<Bin;i++){
    scanf("%d",&T[i]);
  }
  
  for(i=0;i<Bin;i++){
    left=0;
    right=Ain;
    j=T[i];
    while(left<right){
      mid=(left+right)/2;
      if(S[mid]==j){
	count++;
	break;
      }
      else if(j>S[mid])
	left=mid+1;
      
      else if(j<S[mid])
	right=mid;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1184
N = int(input())
for i in range(N):
    a, b, c = map(int, input().split())
    if (a**2 + b**2 == c**2 or a**2 + c**2 == b**2 or c**2 + b**2 == a**2) :
        print("YES")
    else :
        print("NO")


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}
int main(void){
  ll a,b,c;
  cin >> a >> b >> c;
  if(b*c>=a)cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int x = 0;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'I'){
            x++;
            ans = max(ans, x);
        } else {
            x--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
bool prim[300005];
int main(){
	int n;
	int i,j,k;
	int a,b,c;
	memset(prim,true,sizeof(prim));
	prim[1]=false;
	for(i=2;i<300005;i++){
		if(i%7!=1 && i%7!=6)continue;
		if(!prim[i])continue;
		for(j=i*2;j<300005;j+=i)prim[j]=false;
	}
	while(cin>>n){
		if(n==1)break;
		cout<<n<<":";
		for(i=0;7*i<n;i++){
			a=7*i+1,b=7*i+6;
			if(prim[a] && n%a==0)cout<<" "<<a;
			if(prim[b] && n%b==0)cout<<" "<<b;
		}
		cout<<endl;
	}
}
			



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

long long N;
long long A[100010],sum = 0;
long long cnt = 0;

int main()
{
    scanf("%lld",&N);
    for(int i = 0; i < N; i++)scanf("%lld",A + i);
    for(int i = 0; i < N; i++)sum += A[i];
    long long mem = (N + 1) * N / 2;
    if(sum % mem)
    {
        printf("NO\n");
        return 0;
    }

    for(int i = 0; i < N; i++)
    {
        long long num = (A[(i + 1) % N] - A[i] - sum / mem);
        if(num % N || num > 0)
        {
            printf("NO\n");
            return 0;
        }
        cnt += num / N;
    }
    if(-cnt != sum / mem)
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
	long a=scan.nextInt(),b=scan.nextInt(),c=scan.nextInt(),d=scan.nextInt();
    long  x1,x2;
    x1=Math.max(a*c,a*d);
    x2=Math.max(b*c,b*d);
    x1=Math.max(x1,x2);
    System.out.println(x1);
  }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    vector<vector<int>> a(3,vector<int>(3));
    for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin>>a[i][j];
    int n;
    cin>>n;
    vector<int> b(n);
    for(int i=0; i<n; i++) cin>>b[i];
    vector<vector<bool>> c(3,vector<bool>(3,false));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(b[i]==a[j][k]) c[j][k]=true;
            }
        }
    }
    for(int i=0; i<3; i++){
        if(c[i][0]&&c[i][1]&&c[i][2]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(int i=0; i<3; i++){
        if(c[0][i]&&c[1][i]&&c[2][i]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(c[0][0]&&c[1][1]&&c[2][2]){
        cout<<"Yes"<<endl;
            return 0;
    }
    if(c[0][2]&&c[1][1]&&c[2][0]){
        cout<<"Yes"<<endl;
            return 0;
    }
    cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
# your code goes here
m,n=(int(i) for i in input().split())
m2=1
while n>0:
    m1=m
    l=1
    while l*2<=n:
        m1*=m1
        if m1>1000000007:
            m1%=1000000007
 #       print(m1)
        l*=2
    n-=l
    m2*=m1
    if m2>1000000007:
        m2%=1000000007
#    print(m2)
print(m2)

Measured memory_bytes: 7800
#include<stdio.h>
int main()
{
  int a,b;

  scanf("%d %d",&a,&b);

  if(a > b)
    {
      printf("a > b\n");
    }
  else if(a < b)
    {
      printf("a < b\n");
    }
  else
    {
      printf("a == b\n");
    }
  
      return 0;
}

Measured memory_bytes: 1776
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

tokuhyo = sum(A) / (4 * M)

flag = True

for i in range(M):
    if tokuhyo > A[i]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> e(n+1),w(n+1);
    int E = 0,W = 0;
    for (int i = 0;i < s.size();i++){
        if (s[i] == 'E') e[i+1] = 1;
        if (s[i] == 'W') w[i+1] = 1;

        e[i+1] += e[i];
        w[i+1] += w[i];
    }
    int ans = 1e9,res;
    for (int i = 1;i <= n;i++){
        res = w[i-1] + e[n] - e[i];
        ans = min(ans,res);
    }

    cout << ans << endl;
}

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

int cnt;
vector<vector<int>> G(3e5);
vector<int> seen(3e5,false);

void dfs(int r) {
  stack<int> S;
  seen[r]=true;
  S.push(r);
  cnt++;
  int u;
  while(!S.empty()) {
    u=S.top();
    for(int next:G[u]) {
      if(seen[next]==false) {
        seen[next]=true;
        S.push(next);
        cnt++;
      }
    }
    if(S.top()==u) S.pop();
  }
}

int main() {
  int n,m; cin>>n>>m;
  int a,b,ans=0;
  for(int i=0;i<m;i++) {
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(int i=1;i<=n;i++) {
    if(seen[i]==false) {
      cnt=0;
      dfs(i);
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 18520
n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
b= [int(input()) for _ in range(m)]
c = []

for x in range(n):
    ci = 0
    for y in range(m):
        ci += A[x][y] * b[y]
    c.append(ci)

print(*[ci for ci in c], sep = "\n")

Measured memory_bytes: 8116
#include<stdio.h>

int main(void)
{
  int data[1000][2] = {0};
  int n = 0;
  int i;
  int sum = 0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d%d", &data[i][0], &data[i][1]);
  }

  for(i=0; i<n; i++){
    if(data[i][0] != data[i][1]){
      sum += data[i][1]-data[i][0]+1;
    }else{
      sum += 1;
    }
  }

  printf("%d\n", sum);
  return 0;
}


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

using namespace std;

vector<vector<int>> g;
vector<int> topo;
vector<bool> vis;

void dfs(int node){
	vis[node] = true;
	for(auto i : g[node])if(!vis[i])
		dfs(i);
	topo.push_back(node);
}

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

	int N, M;
	cin >> N >> M;

	int a, b;
	g.resize(N);
	topo.reserve(N);
	vis.resize(N, false);
	for(int i=0; i<M; i++){
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
	}

	for(int i=0; i<N; i++) if(!vis[i])
		dfs(i);

	vector<int> dp(N+1, 0);

	for(auto node : topo){
		for(auto i : g[node])
			dp[node] = max(dp[node], dp[i] + 1);
	}

	cout << *max_element(dp.begin(), dp.end());
}


Measured memory_bytes: 8576
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;

    map<int, int> drink;
    int A, B;
    for (int i = 0; i < N; i++)
    {
        cin >> A >> B;
        drink[A] += B;
    }
    
    long long ans = 0;
    for (auto itr = drink.begin(); itr != drink.end(); itr++)
    {
        if (M > (itr -> second))
        {
            ans += (long long)(itr -> first) * (long long)(itr -> second);
            M -= (itr -> second);
        }else
        {
            ans += (long long)(itr -> first) * M;
            break;
        }
        
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int N, a[200009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
{
    scanf ("%d", &a[i]);
    if (a[i] >= i)
    {
        printf ("-1\n");
        return 0;
    }
}
int mini = N + 1;
long long ans = 0;
for (int i=N; i>=1; i--)
{
    if (i >= mini && i - mini + 1 > a[i])
    {
        printf ("-1\n");
        return 0;
    }
    if (i < mini || i - mini + 1 < a[i])
        mini = min (mini, i - a[i] + 1), ans += a[i];
}
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N, K;
const int MAX_K = 10, MAX_N = 10000;
int D[MAX_K];
bool is_d[MAX_K];


// 1234 -> 4 3 2 1
vector<int> each_digit(int S) {
    int n_len = 0, n_dig[MAX_N];
    while (S > 0) {
        n_dig[n_len++] = S % 10;
        S /= 10;
    }
    vector<int> ret(n_dig, n_dig + n_len);
    return ret;
}

void solve() {
    each_digit(N);
    FOR(n, N, 10 * N) {
        vector<int> dig = each_digit(n);
        bool out = false;
        EACH(d, dig) {
            REP(i, K) {
                if (d == D[i]) {
                    out = true;
                    break;
                }
            }
            if (out) break;
        }
        if (out) continue;
        cout << n << endl;
        return;
    }
}

int main() {
    cin >> N >> K;
    REP(i, K) cin >> D[i];
    solve();
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
r = [True for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    if H[a - 1] > H[b - 1]:
        r[b - 1] = False
    elif H[a - 1] < H[b - 1]:
        r[a - 1] = False
    else:
        r[a - 1], r[b - 1] = False, False

print(sum(r))


Measured memory_bytes: 20116
#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(i,n) for(int i=0;i<n;i++)
#define double long double
#define mod 1000000007
#define F first
#define S second
#define pb push_back

using namespace std;

signed main()
{
	fast;
	int test=1;
	// cin>>test;
	for(int index=0;index<test;index++)
	{
		int n,m;
		cin>>n>>m;
		vector<int> v(m);
		int sum=0;
		for(int i=0;i<m;i++)
		{
			cin>>v[i];
			sum+=v[i];
		}
		if(sum>n) cout<<"-1"<<endl;
		else cout<<n-sum<<endl;

	}
}



Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>
using namespace std;
typedef long long int ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); i++)
#define REPEQ(i, n) FOREQ(i, 0, n)

int main()
{
  int A, B, K;
  cin >> A >> B >> K;

  if (B - A >= 2 * K)
  {
    FOR(i, 0, K)
    {
      cout << A + i << endl;
    }
    FOR(i, 0, K)
    {
      cout << B - (K - i - 1) << endl;
    }
  }
  else
  {
    FOREQ(i, A, B)
    {
      cout << i << endl;
    }
  }

  return 0;
}

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

class Main{

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder sb = new StringBuilder("");
    static StringTokenizer stk = new StringTokenizer("");

    public static void main(String args[]){
        try{
            int N = Integer.parseInt(bf.readLine());
            int arr[][] = new int[N][3];

            for(int i=0;i<N;i++){
                stk = new StringTokenizer(bf.readLine());
                for(int j=0;j<3;j++){
                    arr[i][j] = Integer.parseInt(stk.nextToken());
                }
            }
            System.out.println(solver(N,arr));
          	bf.close();
        }catch(Exception e){
            e.printStackTrace();
        }

    }

    public static int solver(int N,int[][] arr){
        int dp[][]  = new int[N][3];
        int max = 0;
        for(int i=0;i<3;i++){
            dp[0][i] = arr[0][i];
            max = Math.max(max,dp[0][i]); 
        }
        if(N==1)
            return max;
        
        for(int i=1;i<N;i++){
            // System.out.println()
            for(int j=0;j<3;j++){
                if(j==0){
                    dp[i][j] = Math.max(dp[i-1][1] , dp[i-1][2]) + arr[i][j];
                }else if(j==1){
                    dp[i][j] = Math.max(dp[i-1][0] , dp[i-1][2]) + arr[i][j];
                }else{
                    dp[i][j] = Math.max(dp[i-1][0] , dp[i-1][1]) + arr[i][j];
                }
            }
        }
        
        for(int i=0;i<3;i++){
            max = Math.max(max , dp[N-1][i]);
        }
        return max;
    }
}

Measured memory_bytes: 48200
// Create your own template by modifying this file!
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int32_t main() 
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<int> x;
    x.push_back(a*c);
    x.push_back(a*d);
    x.push_back(b*c);
    x.push_back(b*d);
    cout << *max_element(x.begin(), x.end());
}




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

int N, A;
int x[50];
long long int dpp[2500];
long long int dpm[2500];
long long int zero = 0, maxp = 0, maxm = 0;
long long int ret = 0;

int main(){
    for(int i = 0; i < 50; ++i){
        x[i] = 0;
        for(int j = 0; j < 50; ++j){
            dpp[i * 50 + j] = 0;
            dpm[i * 50 + j] = 0;
        }
    }
    dpp[0] = 1;
    dpm[0] = 1;
    cin >> N >> A;
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        x[i] = a - A;
    }
    for(int i = 0; i < N; ++i){
        if(x[i] > 0){
            for(int j = maxp; j >= 0; --j){
                if(dpp[j] != 0 && j + x[i] < 2500){
                    dpp[j + x[i]] += dpp[j];
                }
            }
            maxp += x[i];
        }else if(x[i] < 0){
            for(int j = maxm; j >= 0; --j){
                if(dpm[j] != 0 && j - x[i] < 2500){
                    dpm[j - x[i]] += dpm[j];
                }
            }
            maxm -= x[i];
        }else{
            zero++;
        }
    }
    long long int xeros = ((long long int)(1) << zero);
    ret = xeros - 1;
    for(int i = 1; i < 2500; i++){
        ret += dpp[i] * dpm[i] * xeros;
    }
    cout << ret << endl;
    return 0;
}


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

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

using namespace std;

const int MAX_N = 100000;

int N; // ロボットの個数
int X[MAX_N]; // 座標
int L[MAX_N]; // 腕の長さ

pair<int, int> itv[MAX_N];

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

    for (int i = 0; i < N; i++) {
        itv[i].first = X[i] + L[i] - 1;
        itv[i].second = X[i] - L[i];
    }
    sort(itv, itv + N);

    // tは最後に選んだロボットの手が届く座標の末尾
    int ans = 0, t = 0;
    for (int i = 0; i < N; i++) {
        if (t == 0 || t < itv[i].second) {
            ans++;
            t = itv[i].first;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    string S;
    cin >> S;
    if(S == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }

    vint cnt(26,-1);
    REP(i,S.size()){
        cnt[S[i]-'a'] = i;
    }
    if(S.size() < 26){
        cout << S ;
        REP(i,26){
            if(cnt[i] == -1){
                cout << (char)('a'+i) << endl;;
                break;
            }
        }
        return 0;
    }
    string T = S;
    next_permutation(T.begin(),T.end());
    int idx = -1;
    REP(i,S.size()){
        if(T[i] != S[i]){
            idx = i;
            break;
        }
    }
    cout << T.substr(0,idx+1) << endl;
}

Measured memory_bytes: 3560
#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;
int stones[50];

void solve(int n, int p){
  for(int i = 0; i < n; i++){
      stones[i] = 0;
    }

    int cur_ind = 0;
    int pot = p;
    while(true){
      if(pot == 1 && pot + stones[cur_ind] == p){
        cout << cur_ind << endl;
        return;
      }

      if(pot != 0){
        stones[cur_ind] ++;
        pot --;
      } else {
        pot = stones[cur_ind];
        stones[cur_ind] = 0;
      }
      cur_ind = (cur_ind + 1) % n;
    }
}
int main(){
  
  while(true){
    int n;
    int p;
    cin >> n >> p;
    if(n == 0 && p == 0){
      break;
    }

    solve(n, p);
  }

  return 0;
}


Measured memory_bytes: 2992
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int h, w; cin >> h >> w;
    int d[10][10];
    rep(i, 10){
        rep(j, 10) cin >> d[i][j];
    }
    rep(k, 10){
        rep(i, 10){
            rep(j, 10){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    
    int sum = 0;
    rep(i, h){
        rep(j, w){
            int num; cin >> num;
            if(num == -1) continue;
            sum += d[num][1];
        }
    }

    cout << sum << ln;
}




Measured memory_bytes: 256
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005

int r[4002];
int g[4002];
int b[4002];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j,k,id;
	ll sum=0;
    string s;
    cin>>n;
    cin>>s;
    for(i=n-1;i>=0;--i){
    	if(s[i]=='R'){
    		r[i]=1;
		}
		if(s[i]=='G'){
			g[i]=1;
		}
		if(s[i]=='B'){
			b[i]=1;
		}
	}
	for(i=n-2;i>=0;--i){
		r[i]+=r[i+1];
		b[i]+=b[i+1];
		g[i]+=g[i+1];
	}
	for(i=0;i<n;++i){
		for(j=i+1;j<n;++j){
			if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')){
				id=j-i;
				if((j+1)<n){
					sum+=(ll)g[j+1];
				}
				if((j+id)<n){
					sum-=(ll)g[j+id];
				}
				if((j+id+1)<n){
					sum+=(ll)g[j+id+1];
				}
			}
			if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R')){
				id=j-i;
			    if((j+1)<n){
					sum+=(ll)b[j+1];
				}
				if((j+id)<n){
					sum-=(ll)b[j+id];
				}
				if((j+id+1)<n){
					sum+=(ll)b[j+id+1];
				}	
			}
			if((s[i]=='G' && s[j]=='B') || (s[i]=='B' && s[j]=='G')){
				id=j-i;
			    if((j+1)<n){
					sum+=(ll)r[j+1];
				}
				if((j+id)<n){
					sum-=(ll)r[j+id];
				}
				if((j+id+1)<n){
					sum+=(ll)r[j+id+1];
				}	
			}
		}
	}
	cout<<sum;
}

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

const double PI=acos(-1.0);
#define ll long long


int main()
{

	int n;
	int i,j,k;
	cin>>n;
	using p=pair <int,int>;
	vector < p > f(n),s(n);
	for(i=0;i<n;i++)
	{
		cin>>f[i].first>>f[i].second;
	}
	for(i=0;i<n;i++)
	{
		cin>>s[i].first>>s[i].second;
	}
	sort(f.begin(),f.end());
	sort(s.begin(),s.end());
	int ind,max,ans=0;
	vector<bool> used(n);
	for(i=0;i<n;i++)
	{
		ind=-1;
		max=-1;
		for(j=0;j<n;j++)
		{
			if(!used[j]&&f[j].first<s[i].first&&f[j].second<s[i].second&&max<f[j].second)
			{
				ind=j;
				max=f[j].second;
			}		
		}
		if(ind!=-1){ans++;
		used[ind]=true;}
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int max = 0;
        int sum = 0;
        for (int i = 0; i < p.length; i++) {
            sum += p[i];
            max = Math.max(max, p[i]);
        }
        System.out.println(sum - max + max / 2);
        sc.close();
    }
}

Measured memory_bytes: 21972
def solve():
    from sys import stdin
    f_i = stdin
    
    N = int(f_i.readline())
    A = map(int, f_i.readline().split())
    
    for a in A:
        if a % 2 == 0:
            if a % 3 and a % 5:
                print('DENIED')
                break
    else:
        print('APPROVED')

solve()

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll s,w;
  cin >> s >> w;
  string ans;
  if(s<=w) ans = "unsafe";
  else ans = "safe";
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,1);
  if(input % 2 == 0){
     myout(input + " " + input + " " + input/2);
    return;
     }else{
  for(var i = 1; i <= 3500; i++){
    for(var j = 1; j <= 3500; j++){
      var a = input * i * j / (4 * i * j - input * (i + j));
      if(Number.isInteger(a) && a >= 1 && a != Infinity){
         myout(a + " " + i + " " + j);
        return;
      }
    }
  }
}
}

Main(myin());


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;

int main() {
    int n; 
    cin >> n;
    vector<int> b(n-1);
    int ans = 0;
    rep(i,n-1) {
        cin >> b[i];
    }
    ans += b[0];
    rep(i, n-2) {
        ans += min(b[i], b[i+1]);
    }
    ans += b.back();
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, a; cin >> n >> a;
    int mod = n % 500;
    cout << (mod <= a ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/**
*    created: 28.06.2020 01:42:14
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    if (n % 2 == 0) cout << n << endl;
    else cout << n * 2 << endl;
    return 0;
}

Measured memory_bytes: 3620
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = il()
    return "YES" if sum(A) % 2 == 0 else "NO"


if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 14104
N=int(input())


for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n-N*(n+h)>0 and (N*h*n)%(4*h*n-N*(n+h))==0:
            print(h,n,(N*h*n)//(4*h*n-N*(n+h)))
            exit()

Measured memory_bytes: 3060
o=list(input())
e=list(input())
o.reverse()
e.reverse()
f1=False
f2=False
x=''
while True:
  if len(o)>0:
    x+=o.pop()
  else:
    f1=True
  if len(e)>0:
    x+=e.pop()
  else:
    f2=True
  if f1 and f2:
    break
print(x)



Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC152_a solver = new ABC152_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC152_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            if (N == M) {
                out.println("Yes");
            } else {
                out.println("No");

            }


        }

    }
}



Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N, K;
  cin >> N >> K;
  char S[N+1];
  cin >> S;
  S[K-1] += 32;
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#define M 2000000

int si,d[M+1];

void mH(int i){
  int l,r,largest,t;
  l = 2 *i;
  r = 2*i+1;
  if(l <= si && d[l] > d[i]){
    largest = l;
  }
  else largest = i;

  if(r <= si &&d[r] > d[largest]){
    largest= r;
  }
  if(largest != i){
    t = d[i];
    d[i] = d[largest];
    d[largest] = t;
    mH(largest);
  }
}

int main(){
  int i;
  scanf("%d",&si);


  for(i=1;i<=si;i++){
    scanf("%d",&d[i]);
  }

  for(i=si/2;i>=1;i--){
    mH(i);
  }

  for(i=1;i<=si;i++){
    printf(" %d",d[i]);
  }
  printf("\n");

  return 0;
}
    



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

int main() {
  int H, W;
  cin >>H >>W;
 
  vector<vector<char>> V(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> V.at(i).at(j);
    }
  }

  vector<int> HR(H);
  vector<int> WR(W);
  
  for (int i=0; i<H; i++){
    int A=0;
    for(int j=0; j<W; j++){
      if(V.at(i).at(j) == '#'){
        A++;
        break;
      } 
    }
    if(A == 0){
      HR.at(i) =1;
    }
  }
  
  for (int i=0; i<W; i++){
    int A=0;
    for(int j=0; j<H; j++){
      if(V.at(j).at(i) == '#'){
        A++;
        break;
      } 
    }
    if(A == 0){
      WR.at(i) = 1;
    }
  }
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(HR.at(i) == 1){
        break;
      }
      else if(WR.at(j) == 1){
        continue;
      }
      cout << V.at(i).at(j);
    }
   if(HR.at(i) != 1){
     cout << endl;
   }
  }

}

Measured memory_bytes: 3632
def main():
    S = input()
    
    center = len(S)//2
    F = S[:center]
    B = S[center:][::-1]

    counter = 0
    if not len(F) == len(B): # S is Even
        B = B[:-1]

    for i in range(len(F)):
        if not F[i] == B[i]:
            counter += 1

    print(counter)



main()

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

int main(){
	string S;
	cin >> S;
	int ans = 1000;
	int N = S.size();
	for (int i=0;i<N-2;i++){
		string sub = S.substr(i,3);
		int num = atoi(sub.c_str());
		if (ans > abs(num - 753))
			ans = abs(num - 753);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var min = Number(tmp[0]);
	var max = Number(tmp[1]);
	var ans = 0;
	for(var i = min; i < max + 1; i++){
		var str = i + "";
		var digit = str.length;
		var palindromicFlag = true;
		for(var j = 0; j < Math.floor(digit/2) + 1; j++){
			if(str[j] !== str[digit-1-j]) palindromicFlag = false;
		}
		if(palindromicFlag) ans++;
	}
	console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10828
import java.util.Scanner;

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

        do {
            String s = input.nextLine();
            for (char c : s.toCharArray()){
                if ((c < 'A' || 'Z' < c) && (c < 'a' || 'z' < c)) continue;
                alphabet[Character.toLowerCase(c)- 'a']++;
            }
        } while (input.hasNext());

        for (char c = 'a'; c <= 'z'; c++){
            System.out.println(c + " : " + alphabet[c - 'a']);
        }
    }
}

Measured memory_bytes: 17144
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for(int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(int i = 0; i <S.size();) {
        bool can2 = false;
        for(int j = 0; j < 4; j++) {
            string d = divide[j];
            if(S.substr(i, d.size()) == d ) {
                can2 = true;
                i += d.size();
            }
        }
        if(!can2) {
            can = false;
            break;
        }
    }
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << "\n";
    return 0;
}

Measured memory_bytes: 3636