akhauriyash/Code-Regression huggingface dataset:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    k=int(input())
    len_s=len(s)
    new_s=""
    for i,ss in enumerate(s[:-1]):
        t=ord('z')-ord(ss)+1
        if t<=k and ss!='a':
            k-=t
            new_s+='a'
        else:
            new_s+=ss
    if ord(s[-1])+k%26<=ord('z'):
        new_s+=chr(ord(s[-1])+k%26)
    else:
        new_s+=chr(ord(s[-1])+k%26-26) 
    print(new_s)

if __name__=='__main__':
    main()

Measured memory_bytes: 3444
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String ps;
		char c;
		String o = sc.next();
		String e = sc.next();
		int idx;
		int l = o.length() + e.length();
		for(int i = 0; i < l; i++) {
			if(i % 2 == 1){
				idx = (i-1)/2;
				//System.out.print(idx);
				c = e.charAt(idx);
			}else{
				idx = i/2;
				c = o.charAt(idx);
			}
			System.out.print(c);
		}
	}
}


Measured memory_bytes: 21716
def main():
    K,N = map(int,input().split())
    A = [int(i) for i in input().split()]
    A = A + [A[0] + K ]
    dis = []
    for i in range(N):
        dis.append(A[i+1] - A[i])
    print(sum(dis) - max(dis))


if __name__ == '__main__':
    main()

Measured memory_bytes: 26444
#include <iostream>
#include <climits>
#include <cstring>

using namespace std;

const int cap = 1e5 + 1;
int N, K;
int H[cap], dp[cap];

int main() {
    scanf("%d %d", &N, &K);
    for (int i = 1; i <= N; ++i)
        scanf(" %d", &H[i]);
    fill(dp, dp + N + 1, INT_MAX);
    dp[1] = 0;
    for (int i = 1; i < N; ++i) {
        for (int j = i + 1; j <= min(i + K, N); ++j)
            dp[j] = min(dp[j], dp[i] + abs(H[i] - H[j]));
    }
    printf("%d\n", dp[N]);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int n = 0;
    char m;
    for (int i = 0; i < 4; ++i) {
        cin >> m;
        if (m == '-') {
            --n;
        } else if (m == '+') {
            ++n;
        }
    }
    cout << n;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n;
    int jap, math, eng;
    int i, j;

    scanf("%d", &n);
    while (n != 0) {
        for (i = 0; i < n; i++) {
            scanf("%d %d %d", &math, &eng, &jap);

            if ((math == 100 || eng == 100 || jap == 100) ||
                (math + eng) >= 180 ||
                math + eng + jap >= 240) {
                printf("A\n");
            } else if ((math + eng + jap) >= 210 ||
                       ((math + eng + jap) >= 150 && (math >= 80 || eng >= 80))) {
                printf("B\n");
            } else {
                printf("C\n");
            }
        }

        scanf("%d", &n);
    }
    

    return 0;
}



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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans=make_divisors(N)

def keta(n):
    for a in range(11):
        if 10**a<=n<10**(a+1):
            return a+1
F=[]
for num in ans:
    a=keta(num)
    b=keta(N//num)
    f=max(a,b)
    F.append(f)

print(min(F))

Measured memory_bytes: 9220
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	vector<int> h(10,0);
	for(int i=0;i<10;i++){
		cin>> h[i];
	}
	sort(h.begin(),h.end());
	
	cout<< h[9]<< "\n"<< h[8]<< "\n"<< h[7]<< endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1212
#include<stdio.h>
int n,d[55],ans;
int main(void)
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&d[i]);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            ans+=d[i]*d[j];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
if n%2==0:
  for i in range(n):
    if a[i]!=(i//2)*2+1:
      print(0)
      exit()
  print(pow(2,n//2,mod))
else:
  for i in range(n):
    if a[i]!=((i+1)//2)*2:
      print(0)
      exit()
  print(pow(2,n//2,mod))

Measured memory_bytes: 52204
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        s: Chars
    };

    if n % 2 == 1 {
        println!("No");
        return;
    }
    let l = n / 2;
    for i in 0..l {
        if s[i] != s[i + l] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2228
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> like(M);
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    
    int temp;
    for (int j = 0; j < K; j++) {
      cin >> temp;
      like[temp - 1]++;
    }
  }
    
  int count = 0;
  for (int i = 0; i < M; i++) {
    if (like[i] == N) {
      count++;
    }
  }
    
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e11 + 7;
const int maxn = 2e5+5;
ll extgcd(ll a, ll b, ll &x, ll &y) {
    //cout << a <<' '<<b<<' '<<x<<' '<<y<<endl;
  if (b == 0){ 
        return x = 1, y = 0, a;
    }
  ll res = extgcd(b, a % b, y, x);
  return y -= a / b * x, res;
}
void solve() {
    ll n;
    cin >> n;
    n <<= 1;
    ll tar = n - 1;
    ll sq = (ll)sqrt(n);
    for (ll i = 2 ; i <= sq ; i++) {
        if (n % i)continue;
        ll x = i, y = n / i;
        if (__gcd(x, y) > 1)continue;
        ll x1,y1;
        extgcd(x,-y,x1,y1);
        tar = min({tar,x*x1,y*y1});
    }
    cout << tar << endl;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


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

int d[205][205];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m,r;
  cin >> n >> m >> r;
  vector<int> R(r), jun(r);
  REP(i,r){
    cin >> R[i]; R[i]--;
    jun[i] = i;
  }
  REP(i,n) REP(j,n){
    if(i==j) d[i][j] = 0;
    else d[i][j] = 1e9;
  }
  REP(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--, b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  REP(k, n) REP(i, n) REP(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int ans = 1e9;
  do{
    int buf = 0;
    REP(i,r-1) buf += d[R[jun[i]]][R[jun[i+1]]];
    ans = min(ans, buf);
  }while(next_permutation(ALL(jun)));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

//	入力の読み込み
		Scanner sc = new Scanner(System.in);
		int total = sc.nextInt();


//	500円玉が取れなくなるまで
		int count500 = 0;
		while(total >= 500) {
			total -= 500;
			count500++;
		}

//	5円玉が取れなくなるまで
		int count5 = 0;
		while(total >= 5){
			total -= 5;
			count5++;
		}

//	嬉しさの合計を表示
		System.out.print(count500*1000 + count5*5);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
int M=1e9+7;
using namespace std;
int main()
{
	ll s;
	cin>>s;
	ll dp[s+1]={0};
	dp[0]=1;
	for(int i=1;i<=s;i++)
	{
		for(int j=3;j<=s;j++)
		{
			if(i-j>=0)
			dp[i]+=dp[i-j];
			dp[i]%=M;
		}
	}
	cout<<dp[s];
	return 0;
}


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

const ll INF = 1LL << 60;
vector<ll> dp(100010,INF);
vector<ll> h(100010);
int K;

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

ll rec(int i) {
    if(dp[i] != INF) return dp[i];
    if(i == 0) return 0;
    ll res = INF;
    for(int j = 1; j <= K; j++) {
        if(i > j - 1) chmin(res,rec(i-j)+abs(h[i-j]-h[i]));
    }
    return res;
}

int main() {
    int N; cin >> N;
    cin >> K;
    rep(i,N) cin >> h.at(i);

    dp[0] = 0;
    for(int i = 1; i < N; i++) {
        for(int j = 1; j <= K; j++) {
            if(i > j-1) chmin(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }

    cout << dp[N-1] << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
const int MAX = 200005;
int parent[MAX];

void parinit(void){
    rep(i,MAX){parent[i]=i;}
}

int root(int a){
    if(parent[a]==a)return a;
    return parent[a] = root(parent[a]);
}

void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    parent[rx] = ry;
}

int main(void) {
    int n,m;
    cin>>n>>m;
    parinit();
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        unite(x,y);
    }
    set<int> roots;
    for(int i=1;i<=n;i++){
        roots.insert(root(i));
    }
    cout << roots.size() << endl;
    return 0;
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

struct Witness {
  int num;
  vector<P> testimonies;

  Witness(long long input_a, vector<P> input_b) {
    num = input_a;
    testimonies = input_b;
  }
};

vector<Witness> v;
int n;

bool check(int bit) {
  auto s = bitset<15>(bit);
  VI is_honest(n, -1);
  REP(i, n) {
    if (s[i]) {
      Witness w = v[i];
      REP(j, w.num) {
        P p = w.testimonies[j];
        if (s[p.first] != p.second) {
          return false;
        }
      }
    }
  }

  return true;
}

int main() {
  cin >> n;
  REP(i, n) {
    int a;
    cin >> a;
    vector<P> t;
    REP(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      P tmp = make_pair(x, y);
      t.push_back(tmp);
    }
    v.push_back(Witness(a, t));
  }

  int ans = 0;
  // {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 0; bit < (1 << n); ++bit) {
    /* bit で表される集合の処理を書く */
    if (check(bit)) {
      ans = max(ans, (int)bitset<15>(bit).count());
    }
  }
  ANS(ans);
  return 0;
}


Measured memory_bytes: 256
import collections
n=int(input())

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

memo = [0]

for i in range(n):
    memo.append(memo[i]+a[i])

c = collections.Counter(memo)

score_sorted = sorted(c.items(), key=lambda x:-x[1])

ans = 0

for k,i in score_sorted:
    ans += i*(i-1)//2
print(ans)


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

int main(void) {
  string a,b,c;
  cin >> a >> b >> c;
  if (a[a.size()-1] == b[0] &&
      b[b.size()-1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
S = input()
array_S = list(S)

if not ( 3 <= N <= 50 and S.isupper() ): sys.exit()

count = 0
for I in range(N-2):
    if ''.join(array_S[I:I+3]) == 'ABC':
        count += 1
print(count)

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

int main(){
    int N, M;
    cin >> N >> M;
    int max = (1 << N);
    vector<int> dp(max, 10e8);

    vector<int> cost(M);
    vector<int> unlock(M, 0);
    for (int i = 0; i < M;i++){
        int b;
        cin >> cost[i] >> b;
        for (int j = 0; j < b;j++){
            int c;
            cin >> c;
            c--;
            unlock[i] |= 1<<c;
        }
    }

    dp[0] = 0;
    for (int i = 0; i < M;i++){
        for (int j = 0; j < max;j++){
            dp[j | unlock[i]] = min(dp[j | unlock[i]], dp[j] + cost[i]);
        }
    }

    if(dp[max-1] >= 10e8){
        cout << -1 << endl;
    }else{
        cout << dp[max - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int weight[10]={1,2,4,8,16,32,64,128,256,512,};
bool weightFlag[10];
int main(){
    int n;
    while(cin>>n){
        if(n>=weight[9]){
            n-=weight[9];
            weightFlag[9]=true;
        }
        if(n>=weight[8]){
            n-=weight[8];
            weightFlag[8]=true;
        }
        if(n>=weight[7]){
            n-=weight[7];
            weightFlag[7]=true;
        }
        if(n>=weight[6]){
            n-=weight[6];
            weightFlag[6]=true;
        }
        if(n>=weight[6]){
            n-=weight[6];
            weightFlag[6]=true;
        }
        if(n>=weight[5]){
            n-=weight[5];
            weightFlag[5]=true;
        }
        if(n>=weight[4]){
            n-=weight[4];
            weightFlag[4]=true;
        }
        if(n>=weight[3]){
            n-=weight[3];
            weightFlag[3]=true;
        }
        if(n>=weight[2]){
            n-=weight[2];
            weightFlag[2]=true;
        }
        if(n>=weight[1]){
            n-=weight[1];
            weightFlag[1]=true;
        }
        if(n>=weight[0]){
            n-=weight[0];
            weightFlag[0]=true;
        }
        for(int i=0;i<10;i++){
            if(weightFlag[i]){
                cout<<weight[i];
                for(int j=i+1;j<10;j++){
                    if(weightFlag[j]){
                        cout<<' ';
                        break;
                    }
                }
            }
        }
        cout<<endl;
        for(int i=0;i<10;i++) weightFlag[i]=false;
    }
    return 0;
}

Measured memory_bytes: 1160
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int n,a[55],b[55],ans;
int main()
{
	fast;
	cin>>n;
	for (int i=1;i<=n;i++)
	   cin>>b[i],a[i]=b[i];
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	   if (a[i]!=b[i])
		    ans++;
	if (ans<=2)
	   cout<<"YES\n";
  else
	   cout<<"NO\n";
	return 0;
}


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


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int z = 0;
	set<int> st;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) z++;
		st.insert(a[i]);
	}

	if (z == n) {
		cout << "Yes" << endl;
		return 0;
	}
	

	if (st.size() == 2 && n % 3 == 0) {
		if (z == n / 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (st.size() == 3) {
		sort(a.begin(), a.end());
		if (a[n / 3 - 1] != a[n / 3] && a[n / 3 * 2 - 1] != a[n / 3 * 2] && ((a[0] ^ a[n / 3]) == a[n - 1])) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	
	
	return 0;
}



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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	int dp[n][3];//dp[i][j] stores the maximum happiness if taro does j on day i+1(j=0:a;etc)
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
		//cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	return 0;
}

Measured memory_bytes: 2560
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    nodes[p-1][1] += q

search_node = [0]

while len(search_node) > 0:
    n = search_node.pop()
    for i in nodes[n][0]:
        nodes[i][1] += nodes[n][1]
        search_node.append(i)


op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)


Measured memory_bytes: 66492
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,k=MI()
lis=LI()
left=0
right=10**9+10
while left+1<right:
    x=(left+right)//2
    count=0
    for i in range(n):
        count+=-(-lis[i]//x)-1
    #print(count)
    if count<=k:
        right=x
    else:
        left=x
print(right)                
        

Measured memory_bytes: 91236
<?php

fscanf(STDIN, "%d %d", $D, $G);
$P = []; $C = [];
for ($i = 0; $i < $D; ++$i) {
    fscanf(STDIN, "%d %d", $x, $y);
    $P[] = $x; $C[] = $y;
}


$min = PHP_INT_MAX;
for ($i = 0; $i < 1<<$D; ++$i) {
    $cnt = 0;
    $point = 0;
    for ($j = 0; $j < $D; ++$j) {
        if ($i & 1<<$j) {
            $point += ($j + 1) * 100 * $P[$j];
            $point += $C[$j];
            $cnt += $P[$j];
        }
    }
/* echo "cnt: $cnt, point: $point", PHP_EOL; */
    if ($point >= $G) {
        $min = min($min, $cnt);
        continue;
    }

    // greedyにポイントの高い方から全探索する
    for ($j = $D - 1; $j >= 0; --$j) {
/* echo "j: $j, k: $k, cnt, $cnt, point: $point, D: $D", PHP_EOL; */
        // コストを加算済みのやつは足さない
        if ($i & 1<<$j) {
            continue;
        }

        for ($k = 0; $k < $P[$j]; ++$k) {
            if ($point >= $G) {
                $min = min($min, $cnt);
                break 2;
            }
            $point += ($j + 1) * 100;
            ++$cnt;
        }
    }
}
echo $min, PHP_EOL;


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

int n, a[11];
int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  
  int sum = 1;
  rep(i, n){
    if(a[i] % 2 == 0){
      sum *= 2;
    }
  }
  cout << pow(3, n) - sum << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N , K ;
    cin >> N >> K;
    cout << N-K+1 << "\n";
}

Measured memory_bytes: 3648
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000
#define mod 1000000007
using namespace std;
ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    ll n,m;
    while(~scanf("%lld%lld",&n,&m))
    {
        if(n<m) swap(n,m);
        int c=(n%2)^(m%2==0);
        if(n==0||m==0) c=1;
        if(n-m<=1) c=0;
        else c=1;
        if(n==m) c=0;
        if(c) puts("Alice");
        else puts("Brown");
    }
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n); rep(i,n) cin>>a[i];
    a.push_back(-1);

    using P = pair<ll,ll>;
    vector<P> vec;
    ll cnt = 1;
    ll l,r;
    l = a[0];
    r = a[0];

    repf(i,1,n+1){
        if(a[i] >= r){
            r = a[i];
            cnt++;
        }else{
            if(cnt == 1){
                l = a[i];
                r = a[i];
                continue;
            }else{
                vec.emplace_back(l,r);
                cnt = 1;
                l = a[i];
                r = a[i];
            }
        }
    }

    // for(auto p:vec){
    //     cout<<p.first<<" "<<p.second<<endl;
    // }

    ll ans = 1000;
    for(auto p:vec){
        ll cnt = ans/p.first;
        ans += cnt*(p.second-p.first);
    }
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 3632
import std.stdio, std.algorithm;
void main() {
	double i;
	while ("%f\n".readf(&i)) {
		double[] a = [i];
		foreach (j; 2..11) a ~= j % 2 == 0 ? a[$-1] * 2.0 : a[$-1] / 3.0;
		"%.8f".writefln(a.reduce!"a+b");
	}
}

Measured memory_bytes: 2520
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(char, a);
    IN(char, b);
    YES(a == 'H' xor b == 'H', "D", "H");
}

Measured memory_bytes: 3608
#  --*-coding:utf-8-*--


def main():
    N = int(input())
    A = list(map(int, input().split()))

    x0 = sum((-1)**i * a for i, a in enumerate(A))
    x = [x0]

    for a in A[:-1]:
        x0 = 2*a - x0
        x.append(x0)

    print(' '.join(map(str, x)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19144
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
XY = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

counts = np.ones(N, dtype=int)
possible = np.zeros(N, dtype=bool)
possible[0] = 1

for x, y in XY:
    x -= 1
    y -= 1
    possible[y] |= possible[x]
    counts[x] -= 1
    counts[y] += 1
    if counts[x] == 0:
        possible[x] = False

ans = possible.sum()
print(ans)


Measured memory_bytes: 37220
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
 
typedef long long int ll;
typedef string str;
 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}
 
ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}
 
void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	
	ll t,n,m,k,i,j,a,b;
	// cin >> t;
	// while(t--)
	// {
        cin >> n;
        str st,s;
 //    }
        m=0;
        k=0;
        for(i=0;i<n;i++)
        {
        	cin >> a >> b;
        	if(a==b)
        		k++;
        	else
        		k=0;
        	if(k>=3)
        		m=1;
        	// cout << 
        }
        if(m)
        	cout << "Yes\n";
        else
        	cout << "No\n";
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
  string s;
  getline(cin, s);
  for(int i=0; i<s.size(); i++)
    if(s[i] >= 'a' && s[i] <= 'z')
      s[i]+='A'-'a';
  cout <<s<<endl;
  return 0;
}

Measured memory_bytes: 1172
using System;

namespace AtCoder
{
    public class Program
    {
        public static void Main()
        {
            string line = System.Console.ReadLine();
            string []input = line.Split(' ');
            if(input[0] == "ABC")
                Console.WriteLine("ARC");
            else
                Console.WriteLine("ABC");
        }
    }
}

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

int main()
{
    long long int i,n,tiles=0;
    string s;
    cin>>s;
   if(s[0]=='0')
   {
       for(i=0;i<s.size();i++)
       {
           if(i%2==0)
           {
               if(s[i]!='0')
                tiles++;
           }
           else if(i%2!=0)
                if(s[i]!='1')
                tiles++;
       }
   }
   else if(s[0]=='1')
   {
       for(i=0;i<s.size();i++)
       {
           if(i%2==0)
           {
               if(s[i]!='1')
                tiles++;
           }
           else if(i%2!=0)
                if(s[i]!='0')
                tiles++;
       }
   }
   cout<<tiles;

}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll x;
ll r[100005]={0};
ll fun(ll t,ll low,ll high)
{
    if(t<low)return low;
    if(t>high)return high;
    return t; 
}
int main()
{
    int q,k;
    scanf("%lld%d",&x,&k);
    for(int i=1;i<=k;i++)
    scanf("%lld",&r[i]);
    scanf("%d",&q);
    ll l=0,h=x;
    ll add=0;
    int now=1;
    int flag=-1;
    while(q--)
    {
        ll tt,a;
        scanf("%lld%lld",&tt,&a);
        while(tt>=r[now]&&now<=k)
        {
            ll xx=flag*(r[now]-r[now-1]);
            add=add+xx;
            h=fun(h+xx,0,x);
            l=fun(l+xx,0,x);
            flag=-1*flag;
            now++;
        }
        ll ans=fun(add+a,l,h);
        ans=fun(ans+flag*(tt-r[now-1]),0,x);
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2048
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(listA[0],listA[1])
N,K=listA[0]
count=0
for h in listA[1]:
  if(K<=h):
    count=count+1
print(count)

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

int main(){

    long long int n,d;
    cin >> n >> d;

    int ans = 0;

    for(int i=0;i<n;i++){
        long long int x,y;
        cin >> x >> y;

        double sr = sqrt(x*x + y*y);
        // cout << sr << endl;

        if(sr <= d) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3692
"""
注意点：ACしていないWAはペナルティ数とはカウントされない
      また、ACの後にペナルティしたものはカウントされない
データ構造：
  WA:dict形式でカウントアップ
  AC:配列で末尾に挿入
一通り舐めた後AD配列をforで回してペナルティ数合計するか？
"""

N,M = list(map(lambda x: int(x), input().split()))
wa_count = [0] * N
ac_list = [False] * N
answer = 0

for _ in range(M):
  p,s = input().split()
  p = int(p)
  if s == 'WA':
    wa_count[p-1] += 1
  if s == 'AC' and ac_list[p-1] == False:
    answer += wa_count[p-1]
    ac_list[p-1] = True

ac_count = ac_list.count(True)

print(ac_count, answer)


Measured memory_bytes: 4596
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n,m = l_in()

#n = 12
#m = n//2-1



i = 1
s = set()
if n%2 == 0:
    s.add(n//2)
    j = n
    for cnt in range(m):
        while True:
            if min(j-i, n-(j-i)) in s:
                j -=1
            else:
                break
            
        print(i,j)
        s.add(min(j-i, n-(j-i)))

        i+=1
        j-=1
        
else:
    j = n-1
    for cnt in range(m):
        print(i,j)
#        print(min(j-i,n-(j-i)))
        i+=1

        j-=1


Measured memory_bytes: 77604
from sys import stdin
import collections

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

people = []

for i in range(N):
    people.append(S[i])

tmp = collections.Counter(people[1:])
num_return = tmp['E']
minv = num_return

for i in range(1, N):
    if people[i] == 'E':
        num_return -= 1
    if people[i-1] == 'W':
        num_return += 1
    if num_return < minv:
        minv = num_return

print(minv)


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

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(int argc, const char * argv[]) {
    ll N;
    string S;
    cin >> N >> S;
    
    ll sum = 1;
    for(ll i=0;i<N-1;i++){
        if(S[i] == S[i+1]) continue;
        sum++;
    }
    
    cout << sum << endl;
    
    return 0;
    
}




Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long long ans = 0;
    cin >> n;
    vector<int> v(n);
    int a, b, c;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        c = a+b;
        v[i] = c;
        ans -= b;
    }
    /*
      for(vector<int> tmp : v) {
          cout << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl;
      }
      */
    sort(v.begin(), v.end(), greater<int>());
    for(int i = 0; i < n; i += 2) {
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}


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

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

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n, m;
    cin >> n >> m;
    vi s(n), t(m);
    rep(i, n) {
        cin >> s[i];
    }
    rep(i, m) {
        cin >> t[i];
    }

    mint ans = 1;

    vector<vector<mint> > dp(n+1, vector<mint>(m+1));
    rep(i, n) {
        rep(j, m) {
            if(s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            dp[i+1][j+1] += dp[i+1][j] + dp[i][j+1] - dp[i][j];
        }
    }

    ans += dp[n][m];
    cout << ans << endl;
}

Measured memory_bytes: 31616
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;
int num[10];
int main() {
  int N; int K; cin >> N >> K;
  int D[10];

  for ( int i = 0; i < K; i++ ) {
    cin >> D[i];
    num[D[i]]++;
  }
  for ( int i = N; i < 100000; i++ ) {
    bool f = true;
    int tmp = i;
    while(tmp>0) {
      if ( num[tmp % 10] ) {
	f = false;
	break;
      } else {
	tmp /= 10;
      }
    }
    if(f) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int maximum_rectangle(const vector<int> &h) {
	int n = h.size();
	stack<int> s;
	vector<int> L(n), R(n);
	for (int i = 0; i < n; i++) {
		while (s.size() && h[s.top()] >= h[i]) s.pop();
		L[i] = s.size() ? (s.top() + 1) : 0;
		s.push(i);
	}
	while (s.size()) s.pop();
	for (int i = n - 1; i >= 0; i--) {
		while (s.size() > 0 && h[s.top()] >= h[i]) s.pop();
		R[i] = s.size() ? s.top() : n;
		s.push(i);
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		res = std::max(res, (h[i] + 1) * (R[i] - L[i] + 1)); //special
	}
	return res;
}

int n, m;
char s[2010][2010];
bool t[2010][2010], c[2010][2010];
int nx[2010][2010];
int ret;

int main() {
	scanf("%d %d", &n, &m);

	rep(i, n) {
		scanf("%s", s[i]);
		rep(j, m-1) {
			t[i][j] = (s[i][j] != s[i][j+1]);
		}
	}

	ret = max(ret, max(m, n));

	--n; --m;

	rep(i, n) {
		rep(j, m) {
			c[i][j] = (t[i][j] != t[i+1][j]);
		}
	}

	rep(j, m) nx[n][j] = n;

	for (int i = n - 1; i >= 0; --i) {
		rep(j, m) {
			nx[i][j] = nx[i+1][j];
			if (c[i][j] == 1) {
				nx[i][j] = i;
			}
		}
	}

	rep(i, n) { //upper
		vi vec(m);
		rep(j, m) vec[j] = nx[i][j] - i;
		ret = max(ret, maximum_rectangle(vec));
	}

	printf("%d\n", ret);


	return 0;
}

Measured memory_bytes: 27904
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    string s; cin>>s;
    sort(all(s));
    if(s=="abc") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
#define ss second
#define ff first
#define ld long double
const ll INF = 1e13;
const ll N = 301;
const ll mod= 1000000007;
bool prime(ll x)
{
	if(x<2) return false;
	for(ll i=2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}
vl fac(N);
void fact()
{
	fac[0]=1;
	loop(i,1,N) fac[i]=(fac[i-1]*i)%mod;
}

void solve()
{
  ll n; 
  cin>>n;
  vl a(n);
  loop(i,0,n) cin>>a[i];
  ll dp[n][n];
  revloop(l,n-1,0)
   loop(r,l,n)
   {
   	if(l==r) dp[l][r] =  a[l];
   	else dp[l][r] = max(a[l]-dp[l+1][r], a[r]-dp[l][r-1]);
   }
   cout<<dp[0][n-1]<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) solve();
 return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  REP(i, N) cin >> h[i];

  vector<int>dp(N);
  dp.at(0) = 0;
  dp.at(1) = abs(h.at(1) - h.at(0));


  for(int i = 2; i < N; i++){
    int a, b;
    a = dp.at(i - 2) + abs(h.at(i) - h.at(i - 2));
    b = dp.at(i - 1) + abs(h.at(i) - h.at(i - 1));
    dp.at(i) = min(a, b);
  }

print(dp.at(N - 1));

}


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

int main() {
  int n,k,ans=0; cin >> n >> k;
  vector<bool> vec(n);
  for(int i=0; i<k; i++) {
    int a; cin >> a;
    for(int j=0; j<a; j++) {
      int b; cin >> b;
      vec[b-1] = true;
    }
  }
  for(int i=0; i<n; i++) {
    if(vec[i]) continue;
    else ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const ll MOD = 1000000007;

int binsearch_lower_bound(vector<int>& vec, int val) {
  int low = 0;            // ???????????????
  int high = vec.size();  // ???????????????????§£???????????° [low, high] ??????????????¨??????
  while (low < high) {
    int mid = (low + high) / 2;  // ??????????????????????£???§????????????????????????????????????
                                 // ??????????????? mid=low+(high-low)/2 ??¨????????????
    int midval = vec[mid];       // ????????§??????

    // ?§£?????????????????????
    if (midval < val) low = mid + 1;
    else high = mid;
  }
  return low;
}

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

  int n,t;
  cin >> n >> t;
  std::vector<int> v;
  for(int i=0;i<n;i++){
    int d;
    cin >> d;
    v.push_back(d);
  }
  sort(v.begin(),v.end());
  ll res=1;
  for(int i=1;i<n;i++){
    if(v[i-1]>=v[i]-t){
      int idx=binsearch_lower_bound(v,v[i]-t);
      res = (res*(i-idx+1))%MOD;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3520
N, D = map(int, input().split())
X = [0 for i in range(N)]
Y = [0 for i in range(N)]
ans = 0
for i in range(N):
    X[i], Y[i] = map(int, input().split())
    if X[i] ** 2 + Y[i] ** 2 <= D ** 2:
        ans += 1
print(ans)

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

#define SIZE 20

int data[SIZE];
char line[SIZE];

int main(){
#ifdef DEBUG
	printf("DEBUGGING ON\n");
#endif
	int A,B,a,s,m,max;
	scanf("%d %d", &A,&B);
	a=A+B;
	s=A-B;
	m=A*B;
	max=a;
	if (max < s) max=s;
	if (max < m) max=m;
	printf("%d",max);
	return (0);
}

Measured memory_bytes: 128
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A')){puts("Aは大文字です");}
/*各位の和　
int sum = 0;
for(int i = 0; i <= 5; i++){
   sum += n%10;
   n /= 10;  
}
*/

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll n;
  cin>>n;
  for (int i = 1; i < n; i++)
  {
    p=n/i;
    if(n%i==0)q+=p-1;
    else q+=p;
  }
  print(q)

}


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

typedef vector<int> vi;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
typedef set<pair<int, int>>::iterator iter;

int N, Q, S, T, X, D;
set<pair<int, pair<int, int>>> events;
multiset<int> active;
vi ans;

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

    cin >> N >> Q;

    rep(i, N)
    {
        cin >> S >> T >> X;
        events.insert({T - X, {0, X}});
        events.insert({S - X, {1, X}});

        if (S - X < 0 && T - X >= 0)
            active.insert(X);
    }

    rep(i, Q)
    {
        cin >> D;
        events.insert({D, {2, i}});
    }

    ans.assign(Q, -1);

    for (auto e : events)
    {
        T = e.second.first;
        X = e.second.second;

        if (T == 0)
            active.erase(X);
        if (T == 1)
            active.insert(X);
        if (T == 2)
            if (!active.empty())
                ans[X] = *active.begin();
    }

    rep(i, Q) cout << ans[i] << '\n';
}

Measured memory_bytes: 48896
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  i64 a, b, x;
  cin >> a >> b >> x;

  auto f = [&x](i64 n) { return (n >= 0)? (n/x + 1) : (0); };

  cout << f(b) - f(a-1) << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
pair<int, int> A[MAXN];
int dp[6005];

int main()
{
	int i, j, T;
	int maxA = 0;
	scanf("%d%d", &N, &T);
	for (i = 1; i <= N; ++i) {
		scanf("%d%d", &A[i].first, &A[i].second);
		maxA = MAX(maxA, A[i].first);
	}
	int Tlim = maxA + T;
	sort(A + 1, A + 1 + N);
	int maxi = 0;
	for (i = 1; i <= N; ++i) {
		for (j = Tlim; j >= 0; --j) {
			if (j - A[i].first <= 0) break;
			if (j - A[i].first < T && dp[j - A[i].first]) {
				dp[j] = MAX(dp[j], dp[j - A[i].first] + A[i].second);
				maxi = MAX(maxi, dp[j]);
			}
		}
		dp[A[i].first] = MAX(dp[A[i].first], A[i].second);
		maxi = MAX(maxi, dp[A[i].first]);
	}
	printf("%d", maxi);
	return 0;
}

Measured memory_bytes: 256