akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int h,w,c,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
vector<int> p(64);

int nu(int x,int y,int cl,int t){
  int res=1;
  p[y*w+x]=cl;
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||w<=nx||ny<0||h<=ny||p[ny*w+nx]!=t||p[ny*w+nx]==cl)continue;
    res+=nu(nx,ny,cl,t);
  }
  return res;
}

int dfs(int d){
  vector<int> tp=p;
  int res=0;
  if(d==5){
    if(p[0]==c)res=nu(0,0,7,p[0]);
    return res;
  }
  for(int j=1;j<7;j++){
    nu(0,0,j,p[0]);
    res=max(res,dfs(d+1)),p=tp;
  }
  return res;
}

int main(){
  while(cin>>h>>w>>c,h){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin>>p[i*w+j];
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 222222;
int a[N];
int n, k;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    rep(i, 1, n) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1, std::greater<int>());
    int ans = 0;
    rep(i, k + 1, n) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (;;) {
		int n = 0, s = 0;;
		for (char i = 0; i < 5; i++) {
			int a = in() + in();
			if (!a)
				return 0;
			if (s < a) {
				n = i;
				s = a;
			}
		}
		outl((char)('A' + n), ' ', s);
	}
}


Measured memory_bytes: 2524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    int res=1e+8;
    rep(i,s.size()-2){
        char a=s[i],b=s[i+1],c=s[i+2];
        int A=a-'0',B=b-'0',C=c-'0';
        int tmp=A*100+B*10+C;
        //cout<<tmp<<endl;
        chmin(res,abs(tmp-753));
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    global x,k,d
    i = min(k,abs(x//d))
    if abs(x-d*i)<abs(x+d*i):
        x -= d*i
    else:
        x += d*i
    k -= i
    if k%2==1:
        if abs(x-d)<abs(x+d):
            print(abs(x-d))
        else:
            print(abs(x+d))
    else:
        print(abs(x))
    return

if __name__=='__main__':
    x,k,d = IL()
    solve()

Measured memory_bytes: 9112
h, w, a, b = map(int, input().split())
m = h + w
mod = 10 ** 9 + 7

fac = [1] * (m + 1)
inv = [1] * (m + 1)
for i in range(1, m + 1):
    fac[i] = fac[i - 1] * i % mod
inv[-1] = pow(fac[-1], mod - 2, mod)
for i in range(m - 1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod


def cmb(n, r):
    assert n >= r >= 0
    ret = fac[n] 
    ret *= inv[n - r]
    ret %= mod
    ret *= inv[r]
    return ret % mod


ans = sum(cmb(h - a + i - 1, i) * cmb(a + w - 2 - i, a - 1) % mod for i in range(b, w))
print(ans % mod)

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

int main()
{
    int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='1') ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
p = list(map(int, input().split()))

table = [0 for i in range(102)]
for i in p:
    table[i] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 101-i
    if (table[idx] == 0) and (dis >= abs(idx-x)):
        ans = idx
        dis = abs(idx-x)
print(ans)


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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int N, M, K;
  cin >> N >> M >> K;

  int a = max(N, M);
  int b = min(N, M);
  Rep(i, M+1) {
    Rep(j, N+1) {
      if ( (N * i) + (M - i - i)*j == K ) {
	cout << "Yes" << endl;
	//	cout << i << " " << j << endl;
	return 0;
      }
    }
  }
  Rep(j, N+1) {
    Rep(i, M+1) {
      if ( (M * j) + (N - j - j)*i == K ) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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 gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n;
cin>>n;
double t,a;
cin>>t>>a;
double h;
double ans=inf;
ll out;
for(ll i=0;i<n;i++){
    cin>>h;
    if(chmin(ans,(double)fabs(a-(t-h*0.006)))){
     out=i+1;   
    }
}
cout<<out<<endl;
return 0;
}










Measured memory_bytes: 256
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 ==a or i + 1 == b:
    r -= c * pow(f, M - 2, M)
print(r % M)

Measured memory_bytes: 3064
N, A, B = map(int, input().split())
for i in range(N):
    if(B != A + 1): A += 1
    elif(A != 0): A -= 1
    else: print('Borys'); exit(0)
    if(A != B - 1): B -= 1
    elif(B != N): B += 1
    else: print('Alice'); exit(0)
print('Draw')


Measured memory_bytes: 3060
#coding:utf-8

A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for nA in range(A+1):
    for nB in range(B+1):
        for nC in range(C+1):
            if nA*500 + nB*100 + nC*50 == X:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e5;

int main(){
  int d,n,m;

  while(cin >> d ,d){
    vector<int> cu,sh;
    int c,s;
    sh.push_back(0);

    cin >> n >> m;
    for(int i = 1 ; i < n ; i++){
      cin >> s;
      sh.push_back(s);
    }
    sh.push_back(d);
    for(int i = 0 ; i < m ; i++){
      cin >> c;
      cu.push_back(c);
    }

    int sum = 0;  
    sort(sh.begin(),sh.end());
    sort(cu.begin(),cu.end());
    int pos = 1;
    for(int i = 0 ; i < m ; ){
      if(sh[pos] >= cu[i]){
	sum += min(sh[pos]-cu[i],cu[i]-sh[pos-1]);
	i++;
      }
      else ++pos;
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1732
U = 2*10**6
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
 
for i in range(U,0,-1):
  fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def comb(n,k):
  if k < 0 or k > n:
    return 0
  z = fact[n]
  z *= fact_inv[k]
  z %= MOD
  z *= fact_inv[n-k]
  z %= MOD
  return z

h, w, a, b = map(int, input().split())
ans = 0
for i in range(h-a):
  ans += comb(b+i-1, i) * comb(w+h-b-i-2, h-i-1)
  ans %= MOD
print(ans)

Measured memory_bytes: 161396
MOD = 10**9+7

H, W = map(int, input().split())
a = ['']*H
for i in range(H):
    a[i] = input()

dp = [[0]*W for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if i+1 < H and a[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= MOD
        if j+1 < W and a[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
            dp[i][j+1] %= MOD

print(dp[H-1][W-1])

Measured memory_bytes: 43712
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    
    
    int main(){
        int n;cin>>n;
        int i = 0,a = 1;
        while(n){
            a = a+10;
            int b = pow(a,0.5);
            REP(j,2,b){
                if(a%j == 0)break;
                if(j == b){cout<<a<<" ";;n--;}
            }
            i++;
            if(a>55555)break;
        }
    }
    


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int[] subTreeSize;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		k--;
		int idx = 0;
		for (;idx < s.length() && s.charAt(idx) == '1'; idx++);
		char ans = k < idx ? '1' : s.charAt(idx);
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    vector<ll> ans;
    while (true){
        int n,k;cin>>n>>k;
        if (n==0 && k==0){
            break;
        }
        vector<ll> a(n);
        rep(i,0,n) cin>>a[i];
        vector<ll> b(n+1,0);
        rep(i,0,n) b[i+1] = b[i] + a[i];
        ll num = 0;
        rep(i,0,n-k){
            num = max(num,b[i+k]-b[i]);
        }
        ans.push_back(num);
    }
    for(auto x:ans){
        cout<<x<<endl;
    }
}


Measured memory_bytes: 4372
import java.util.*;

public class Main {

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

        int n = scanner.nextInt();
        int k = scanner.nextInt();

        int ans = 0;

        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt();
            ans += Math.min(x*2, (k - x)*2);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let n: usize = rd.get();
    let x: usize = rd.get();
    let t: usize = rd.get();

    println!("{}", (n + x - 1) / x * t);
}

Measured memory_bytes: 2124
#include <numeric>
#include <iostream>
#include <vector>
#include <algorithm>


using ll = long long int;

ll n, m;
std::vector<ll> vec;
std::vector<ll> diff;
int main() {
    std::cin >> n >> m;
    if (n >= m) {
        std::cout << "0" << std::endl;
        return 0;
    }
    vec.assign(m, 0);
    for (ll i = 0; i < m; i++) {
        std::cin >> vec[i];
    }
    std::sort(vec.begin(), vec.end());
    for (ll i = 1; i < m; i++) {
        diff.push_back(vec[i] - vec[i-1]);
    }
    std::sort(diff.begin(), diff.end());
    for (int i = 0; i < n - 1; i++) {
        diff.pop_back();
    }
    std::cout << std::accumulate(diff.begin(), diff.end(), 0) << std::endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

pair<int,bool> solve(const vector<pair<int,int>>& v) {
  int sh = 0;
  for (auto p : v) {
    int d, h;
    tie(d, h) = p;
    if (d > sh) return make_pair(0, false);
    sh += h;
  }
  return make_pair(sh, true);
}

int main() {
  int n;
  cin>>n;
  vector<pair<int,int>> vp;
  vector<pair<int,int>> vn;
  REP(i,n) {
    string s;
    cin>>s;
    int h = 0;
    int d = 0;
    for(char c:s) {
      if (c == '(') ++h;
      else --h;
      d = min(d, h);
    }
    if (h >= 0) vp.emplace_back(-d, h);
    else vn.emplace_back(h-d, -h);
  }
  sort(ALL(vp));
  sort(ALL(vn));
  int h1, h2;
  bool v1, v2;
  tie(h1, v1) = solve(vp);
  tie(h2, v2) = solve(vn);
  if (h1 != h2 || !v1 || !v2) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <vector>
#include <string>
using namespace std;


int main() {
  int N, X, T;
  cin >> N >> X >> T;

  cout << fixed <<  (int) ceil((float) N / X) * T << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ll long long
#define X first
#define Y second
#define pb push_back
#define E Maxke_pair
#define pii pair<int, int>
#define ls rt << 1
#define rs rt << 1 | 1
#define sz(x) (int)(x).sze()
#define ALL(x) (x).insgin(), (x).end()
#define vi vector<int>
using namespace std;
inline int read()
{
	int 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;
}
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 2e6 + 10;

int main() 
{
	int n = read();
    bool flag = 1;
    int lx = 0, ly = 0, lt = 0;
    rep(i, 1, n)
    {
        int x, y, t;
        t = read();
        x = read();
        y = read();
        if (abs(x - lx) + abs(y - ly) > t - lt || (t - lt - abs(x - lx) - abs(y - ly)) % 2 == 1) flag = 0;
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;


int main(){
    string s;
    cin >> s;
    
    vector<char> data = {};
    
    for(int i = 0; i < s.size(); i++){
        if(data.size() == 0){
            data.push_back(s[i]);
            
        }else{
            if(data.back() != s[i]){
                data.pop_back();
            }else{
                data.push_back(s[i]);
            }
        }
    }
    cout << s.size() - data.size();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int a[n];
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    ll sum = 0;
    for (int i = 0; i < n-k; i++){
        sum += a[i];
    }
    printf("%lld ",sum);
}


Measured memory_bytes: 1024
N, M = [int(s) for s in input().split(' ')]

acd = dict()
pcd = dict()
ac = 0
pc = 0
for i in range(M):
    p, S = input().split(' ')
    if p not in acd:
        if S == 'AC':
            acd[p] = 1
            ac += 1
            if p in pcd:
                pc += pcd[p]
        else:
            if p not in pcd:
                pcd[p] = 1
            else:
                pcd[p] += 1

print("{} {}".format(ac, pc))


Measured memory_bytes: 58200
using System;
using System.Linq;
using System.Text;

namespace ALDS1_6_C {
    public class Card {
        public char Suit { get; set; }
        public int Number { get; set; }

        public override string ToString() {
            return Suit + " " + Number;
        }
    }

    public static class MyExtension {
        public static void QuickSort(this Card[] arr,int p,int r) {
            if (p < r) {
                int q = arr.Pertition(p, r);
                arr.QuickSort(p, q - 1);
                arr.QuickSort(q + 1, r);
            }
        }

        public static int Pertition(this Card[] arr, int p, int r) {
            Card x = arr[r];
            int i = p - 1;
            for (int j = p; j < r; j++) {
                if (arr[j].Number <= x.Number) {
                    i++;
                    arr.Replace(i, j);
                }
            }
            arr.Replace(i + 1, r);
            return i + 1;
        }

        public static void Replace(this Card[] arr, int indexA, int indexB) {
            Card temp = arr[indexA];
            arr[indexA] = arr[indexB];
            arr[indexB] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            Card[] cards = new Card[n];
            for(int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                cards[i] = new Card { Suit = input[0][0], Number = int.Parse(input[1]) };
            }
            Card[] stable = cards.OrderBy(c => c.Number).ToArray();
            cards.QuickSort(0, n - 1);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(IsStable(cards, stable) ? "Stable" : "Not stable");
            foreach (Card card in cards)
                sb.AppendLine(card.ToString());
            Console.Write(sb);
        }

        static bool IsStable(Card[] a, Card[] b) {
            for (int i = 0; i < a.Length; i++)
                if (a[i].Suit != b[i].Suit)
                    return false;
            return true;
        }
    }
}

Measured memory_bytes: 21684
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define MAX_n 105

int n;
int Y[MAX_n],M[MAX_n],D[MAX_n];

void input(){
  cin>>n;
  REP(i,n)  cin>>Y[i]>>M[i]>>D[i];
}

void solve(){
  REP(i,n){
    int keika=0;
    for(int j=1;j<Y[i];j++){
      if(j%3==0) keika+=200;
      else keika+=(20*5+19*5);
    }   
    for(int j=1;j<M[i];j++){
      if(Y[i]%3==0)keika+=20;
      else if(j%2==0)keika+=19;
      else keika+=20;
    }
    keika+=D[i]-1;
    cout<<196470-keika<<endl;
  }
}

int main(){
  input();
  solve();

  return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false),cin.tie(0);
#define ll long long
#define inf 0x3f3f3f3f
const int N=105;
//set<string>b;
//set<string>::iterator it;

int main()
{
	IO;
	double d,t,s,x;
	cin>>d>>t>>s;
	x=1.0*d/s;
	if(x>t) cout<<"No\n";
	else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 3728
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def mcomb(n, k, mod):
    if k == 0: return 1     # １分割の場合は１を返すようにしておく
    def mfac(l, r, mod):
        ans = l
        for i in reversed(range(r, l)):
            ans *= i
            ans %= mod
        return ans

    A = mfac(n, n - k + 1, mod)
    B = mfac(k, 1, mod)
    # B = mpow(B,mod-2,mod)
    B = pow(B, mod - 2, mod)
    return A * B % mod

def solve():
    S = II()
    ans = 0
    MOD = 1000000007
    for n in range(1, S//3+1):
        # print(n)
        # print(mcomb(S-3*n+n-1, n-1, MOD))
        ans += mcomb(S-3*n+n-1, n-1, MOD)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    solve()



Measured memory_bytes: 9284
#include <stdio.h>
#include <string.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int i;
   
    char s[52];
   
      
    scanf("%s", s );
   

    for( i = 0 ; i < strlen(s) - 8 ; i = i + 1 ){

         printf("%c", s[i] );

         }

    printf("\n");

    return 0;
                                                          
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n;
		Double avg, num;
		num = 0.0;
		avg = 0.0;
		StringBuilder sb = new StringBuilder();
		List<Integer> list = new ArrayList<Integer>();

		while (true) {
			n = scan.nextInt();

			// n???0?????¨???????????????
			if (n == 0) {
				break;
			}

			// n????????? n????????????????????????????´?
			for (int count = 0; count < n; count++) {
				list.add(scan.nextInt());
			}
			// ??????????????¨???
			for (int count2 = 0; count2 < n; count2++) {
				avg += list.get(count2);
			}
			avg = avg / n;

			// ?????£????¨???? (s1..sn - avg)^2???????¨?/n
			for (int count3 = 0; count3 < n; count3++) {
				num += (list.get(count3) - avg)*(list.get(count3) - avg);
			}

			// ?¨?????????? ?????????(?????£/n)
			Double d = Math.sqrt(num / n);
			sb.append(d);
			sb.append("\n");

			// ?????¨?????????????????????
			avg = 0.0;
			num = 0.0;
			list.clear();
		}

		// ????????????????????????
		sb.deleteCharAt(sb.length() - 1);
		System.out.print(new String(sb));

	}
}

Measured memory_bytes: 31612
n,k = map(int,input().split())
result = 0
mod = 10**9 + 7


for i in range(k,n+2):
    #print(((n * i) - (i*(i-1)) )+ 1)
    result += ((n * i) - (i*(i-1)) )+ 1


print(result % mod)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,h,w,a,b,ans=0,i;
	cin>>n>>h>>w;
	for (i=0;i<n;i++){
		cin>>a>>b;
		if (a>=h&&b>=w){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.charAt(0) < 97) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }


}

Measured memory_bytes: 35604
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
vector<ll> x;
pair <ll,ll> p[110000];
ll b[110000];
int main(){
  ll n,sum=0,ps=0;
  cin>>n;
  rep(i,0,n-1)cin>>b[i];
  b[n-1]=110000;
  sum=b[0];
  rep(i,0,n){
    sum+=min(b[i-1],b[i]);
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n, l;
	cin >> n >> l;
	V a(n);
	int sum = 0;
	rep(i, n) {
		a[i] = l + i;
		sum += a[i];
	}
	int ans;
	int mini = upper;
	rep(i, n) {
		int tmp = 0;
		rep(j, n) {
			if (i == j) continue;
			tmp += a[j];
		}
		if (chmin(mini, abs(sum-tmp))) ans = tmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	string S;
	cin >> S;

	int cnt0 = 0;
	int cnt1 = 0;

	for (int i = 0; i < S.size(); i++) {
		if (0 == i % 2) {
			if (S[i] == '0') {
				cnt1 += 1;
			}
			else {
				cnt0 += 1;
			}
		}
		else {
			if (S[i] == '0') {
				cnt0 += 1;
			}
			else {
				cnt1 += 1;
			}
		}
		
	}

	cout << min(cnt0, cnt1) << endl;

	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007

int main(void){
  string s;cin >> s;
  s[3]='8';
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int H, W;
	while (true) {
		std::cin >> H >> W;
		if (H==0 && W==0) break;
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				std::cout << "#"; 
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	
	return 0;
}



Measured memory_bytes: 3104
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    ll ans = 0;
    string s;
    cin>>s;
    map<int,int>modp;
    int now=0;
    int n = s.size();
    int p = 2019;
    vector<int>S(n+1,0);


    int ten = 1;
    modp[0]=1;
    for (int i = n-1; i >= 0; --i) {
        int target = s[i]-'0';
        now =  target * ten % p;
        S[i] = (S[i+1] + now) % p;
        ten *= 10;
        ten %= p;
        ans += modp[S[i]];
        modp[S[i]] ++;
    }

    cout<<ans<<endl;
}


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

using namespace std;

int main(){

    int N;
    cin >> N;

    unordered_map<string, int> m;

    for(int i = 0; i < N; i++){
	string s;
	cin >> s;
	if(m.find(s) != m.end()){
	    int v = m.at(s);
	    m.erase(s);
	    m.emplace(s, v+1);
	}else{
	    m.emplace(s, 1);
	}
    }

    int M;
    cin >> M;
    
    for(int i = 0; i < M; i++){
	string s;
	cin >> s;
	if(m.find(s) != m.end()){
	    int v = m.at(s);
	    m.erase(s);
	    m.emplace(s, v-1);
	}else{
	    m.emplace(s, -1);
	}
    }

    string max;
    int max_v = 0;
    for(const auto& p : m){
	if(p.second > max_v){
	    max = p.first;
	    max_v = p.second;
	}
    }
    cout << max_v << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let i = v[1];
	println!("{}", n - i + 1);
}

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

#define rep(i, n) for (int i = 0; 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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int64_t factorial(int64_t n) {
  if (n == 1) {
    return 1;
  }
  int64_t ans = factorial(n-1);
  return ans*n;
}
int64_t gcd(int64_t a, int64_t b) {
  if (a < b) {
    int64_t tmp = a;
    a = b;
    b = tmp;
  }
  int64_t r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

int main() {
  int64_t n;
  cin >> n;
  vector <int64_t> a(n);
  vector <int64_t> b(n);
  rep(i, n) cin >> a.at(i) >> b.at(i);
  int64_t ans = 0;
  rep(i, n) {
    if (i != n-1) {
      if (a.at(n-1-i)%b.at(n-1-i) != 0) {
        ans += b.at(n-1-i) - (a.at(n-1-i)%b.at(n-1-i));
      }
      a.at(n-1-(i+1)) += ans;
    } else {
      if (a.at(n-1-i)%b.at(n-1-i) != 0) {
        ans += b.at(n-1-i) - (a.at(n-1-i)%b.at(n-1-i));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


int main(){
    LL n, m;
    cin >> n >> m;
    vector<vector<LL>> sw(m);
    for(LL i = 0; i < m; ++i){
        LL k;
        cin >> k;
        for(LL j = 0; j < k; ++j){
            LL s;
            cin >> s;
            sw[i].push_back(s-1);
        }
    }
    vector<LL> p(m);
    for(LL i = 0; i < m; ++i){
        cin >> p[i];
    }
    LL ans = 0;
    for(LL i = 0; i < (1<<n); ++i){
        LL cnt = 0;
        for(LL j = 0; j < m; ++j){
            LL st = 0;
            for(LL k = 0; k < sw[j].size(); ++k){
                st += ((i >> sw[j][k]) & 1);
            }
            if(st % 2 == p[j]){
                ++cnt;
            }
        }
        if(cnt == m) ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

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

	int a[100000];

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

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


	cout << cnt / 2 << endl;

//		sort(c, c + n, greater<int>()); //降順ソート

	return 0;
}

Measured memory_bytes: 768
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
ans = 0
for i in range(0,n,2):
    if a[i] %2 == 1:
        ans+=1
print(ans)

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

string shuffle(string word1,int h){
    string head = word1.substr(0,h);
    string tail = word1.substr(h,word1.size()-h);
    return tail + head;
}

int main(){
    int x,y;
    string word;
    while(1){
        cin >> word;
        if(word=="-") break;
        cin >> x;
        for(int i=0;i<x;i++){
            cin >> y;
            word = shuffle(word,y);
        }
        cout << word << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
using namespace std;
int main(){
  int K,S;
  cin>>K>>S;
  int X=0;
  int Y=0;
  int Z=0;
  int res=0;
  
  for (int i=0;i<K+1;++i){
    for (int j=0;j<K+1;++j){
      int k=S-i-j;
      if (k>=0 && k<K+1){
        ++res;
      }
    }
  }
  
  cout<<res<<endl;
} 

Measured memory_bytes: 256
<?php
$input = STDIN;

$N = trim(fgets($input));

$seq = explode(' ', trim(fgets($input)));

// Bubble Sort
$cards_b = $seq;
for ($i = 0; $i < $N; $i++) {
    for ($j = $N - 1; $j > $i; $j--) {
        if ($cards_b[$j][1] < $cards_b[$j-1][1]) {
            list($cards_b[$j-1], $cards_b[$j]) = array($cards_b[$j], $cards_b[$j-1]);
        }
    }
}

// Selection Sort
$cards_s = $seq;
for ($i = 0; $i < $N; $i++) {
    $mini = $i;
    for ($j = $i; $j < $N; $j++) {
        if ($cards_s[$j][1] < $cards_s[$mini][1]) {
            $mini = $j;
        }
    }
    list($cards_s[$i], $cards_s[$mini]) = array($cards_s[$mini], $cards_s[$i]);
}

// Output
print implode(' ', $cards_b) . "\n";
print "Stable\n";

print implode(' ', $cards_s) . "\n";
if ($cards_s != $cards_b) {
    print "Not stable\n";
} else {
    print "Stable\n";
}


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

#define fastread std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ceel(x, y) (x+y-1)/y
#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;
#define inp(ar, l, r) for(int i=l ; i<r ; ++i) cin>>ar[i];
#define inpar(ar) for(int i=0 ; i<n ; ++i) cin>>ar[i];
#define debug(ar, n) for(int i=0 ; i<n ; ++i) cout<<ar[i]<<' ';cout<<endl;
#define debugar(ar) for(int i=0 ; i<n ; ++i) cout<<ar[i]<<' ';cout<<endl;
#define qwer cout<<endl;
#define MOD 1000000007

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

#define pll pair<ll,ll>

const int N = 3001;
ll dp[2][N+1][N+1];     // dp[player][left][right]
ll ar[N+1], n;

ll calc(int left, int right, bool player, ll score1, ll score2)
{
    if(left > right) return 0;  // Base case

    if(dp[player][left][right] != -1)   // Already computed
        return dp[player][left][right];
    
    if(player%2 == 0)   // Player 1
        return dp[player][left][right] = max(calc(left+1, right, player^1, score1+ar[left], score2) + ar[left],
                                        calc(left, right-1, player^1, score1+ar[right], score2) + ar[right]);
    
    // Player 2
    return dp[player][left][right] = min(calc(left+1, right, player^1, score1, score2+ar[left]) - ar[left],
                                        calc(left, right-1, player^1, score1, score2+ar[right]) - ar[right]);
}

void solve()
{
    cin>>n;

    for(int i=0 ; i<n ; ++i)
        cin>>ar[i];
    
    memset(dp, -1, sizeof(dp));

    cout<<calc(0, n-1, 0, 0, 0)<<endl;
}

void preCompute() {}

int main()
{
	fastread;

    preCompute();
	
    ll t = 1, tc;
    
    //cin>>t;
    for(tc=1 ; tc<=t ; ++tc) {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 144696
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n;
int a[3];
signed main(){
    cin>>n;
    rep(i,n){
        int x;
        cin>>x;
        if(x%2)a[0]++;
        else if(x%4)a[1]++;
        else a[2]++;
    }
    if(a[2]>=n/2)puts("Yes");
    else if(a[0]<=a[2])puts("Yes");
    else puts("No");
    return 0;
}



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

g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))

from collections import deque

que = deque()
seen = [0] + [-1]*(n-1)
que.append(0)
while que:
    s = que.popleft()
    for v,w in g[s]:
        if seen[v] != -1:continue
        seen[v] = seen[s]^(w%2)
        que.append(v)
for i in seen:
    print(i)

Measured memory_bytes: 43272
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str = br.readLine();
	    StringTokenizer st = new StringTokenizer(str, " ");

		int a  = Integer.parseInt(st.nextToken());
		int b  = Integer.parseInt(st.nextToken());
		int c  = Integer.parseInt(st.nextToken());

		if(a < b && b < c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 24196
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
ll num[10000005],mul;
ll n,k,K;
void DFS(ll cnt,ll sum)
{

    sum=sum*2;
    cnt++;
   // printf("%lld %lld\n",cnt,sum);
    if(cnt==n){
          num[k++]=sum;

    }
    else{
        DFS(cnt,sum);
    }
    cnt--;
    sum=sum/2;
    sum=sum+K;
    cnt++;
   // printf("%lld %lld\n",cnt,sum);
    if(cnt==n){
        num[k++]=sum;

       }
    else{
        DFS(cnt,sum);
    }
}
int main()
{

      while(scanf("%lld%lld",&n,&K)==2){
        k=0;
        DFS(0,1);
        sort(num,num+k-1);
        printf("%d\n",num[0]);
     }
    return 0;
}


Measured memory_bytes: 128
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  string s, t;
  cin >> s >> t;

  int n = s.size();
  rep(i, n) {
    for (int j = i, k = 0; k <= n; j = (j + 1) % n, k++) {
      if (k == n) {
        cout << "Yes" << endl;
        return 0;
      }
      if (s[j] != t[k]) break;
    }
  }
  cout << "No" << endl;


  
  return 0;
}

Measured memory_bytes: 256
int x, y, w, h, r;
int main(){
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	if(x+r>w || y+r>h || x-r<0 || y-r<0){
		printf("No\n");
	} else{
		printf("Yes\n");
	}
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

set<string> st;

const string t = "AKIHABARA";
void dfs(string const& currstr, int curr) {
  if (t.size() == curr) {
    st.insert(currstr);
    return;
  }
  if (t[curr] == 'A') dfs(currstr, curr + 1);
  dfs(currstr + t[curr], curr + 1);
}

int main() {
  dfs("", 0);
  string s; cin >> s;
  cout << (st.count(s) ? "YES\n" : "NO\n");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	int H[N];
	int i;
	for(i = 0; i< N ; i++)
	{
		scanf("%d",&H[i]);
	}
	
	for(i = 1; i < N; i++)
	{
		if(H[i] > H[i-1])
		{
			H[i]--;
		}
	}
	for(i = 0; i < N-1; i++)
	{
		if(H[i] > H[i+1])
		{
			printf("No");
			return 0;
		}
	}
	/*
	for(i = 0; i < N; i++)
	{
		printf("H[%d] = %d\n",i,H[i]);
	}
	*/
	printf("Yes");
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a, b;
	cin >> a >> b;
	vector<int> V[26];
	int sizea = a.size();
	int sizeb = b.size();
	for(int i=0; i<sizea; i++)
		V[a[i] - 'a'].push_back(i + 1);
	int last = 0, yes = 1;
	long long ans = 0;
	for(int i=0; i<sizeb; i++)
	{
		if(V[b[i] - 'a'].empty())
		{
			yes = 0;
			break;
		}
		int temp = upper_bound(V[b[i] - 'a'].begin(), V[b[i] - 'a'].end(), last) - V[b[i] - 'a'].begin();
		if(temp == V[b[i] - 'a'].size())
		{
			ans -= (long long)last;
			ans += (long long)sizea;
			i--;
			last = 0;
		}
		else
		{
			if(last != 0) ans -= (long long)last;
			ans += (long long)V[b[i] - 'a'][temp];
			last = (long long)V[b[i] - 'a'][temp];
		}
	}
	if(!yes) printf("-1");
	else     printf("%lld",ans);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1216