akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set 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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll A, B; 
    cin >> A >> B;

    if(A>9 || B>9){
      p(-1);
    }else{
      p(A*B);
    }
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    int k;
    cin >> k;

    string s;
    cin >> s;

    if(s.size() > k){
        cout << s.substr(0,k) << "..." << endl;
    }else{
        cout << s << endl;
    }

    return 0;
}


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

	int a[100000];

int main(){
	int h,n,i;
	cin >> h >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		h-=a[i];
	}
	if(h<=0)
		cout << "Yes";
	else
		cout << "No";
}		

Measured memory_bytes: 640
import numpy as np
import itertools

h, w, k = list(map(int, input().split()))
def convert(char):
  if char == '.':
    return 0
  else:
    return 1

def add_elements(c, row, column):
  s = 0
  for i in range(h):
    for j in range(w):
      if (i not in row) and (j not in column):
        s += c[i,j]
  return s

c = np.empty((h, w))

ans = 0

for i in range(h):
  line = list(map(convert, list(input())))
  c[i,:] = np.array(line)

for i in range(h+1):
  for j in range(w+1):
    rows = list(itertools.combinations(range(h),i))
    columns = list(itertools.combinations(range(w),j))
    for row in rows:
      for column in columns:
        s = add_elements(c, row, column)
        if s == k:
          ans += 1

print(ans)

Measured memory_bytes: 27116
#include <iostream>
using namespace std;
int main()
{
  
  int n,i;
  long sum=0,max,min,numb;
  cin>>n;
  if(n==0)return 0;
  
  for(i=0; i<n; i++){
  
    cin>>numb;
    if(i==0)max=min=numb;
    if(numb>max)max=numb;
    if(numb<min)min=numb;
    sum+=numb;
   
  }
  
  cout<<min<<" "<<max<<" "<<sum<<"\n";
  
}

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

int n, y;
int main() {
	//freopen("in.txt", "r", stdin);
	scanf("%d %d", &n, &y);
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {

			int k = n - i - j;
			if(k<0)
				continue;
			int res = i * 10000 + j * 5000 + k * 1000;
			if (res == y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <algorithm>
#include <iostream>
using namespace std;
long long C(int n, int k) {
    long long ans = 1;
    for (int i = 0; i < k; i++) ans = ans * (n - i) / (i + 1);
    return ans;
}

int main(int argc, char** argv) {
    int n, a, b; cin >> n >> a >> b;
    long long v[n]; for (int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    long long numer = 0, denom = 1, count = 0;
    for (int k = a; k <= b; k++) {
        long long x = v[n-k];
        int left = lower_bound(v, v+n, x) - v;
        int right = upper_bound(v, v+n, x) - v;
        long long sum = accumulate(v+n-k, v+n, 0LL);
        if (numer * k < sum * denom) {
            numer = sum; denom = k; count = C(right - left, right - n + k);
        }
        else if (numer * k == sum * denom) count += C(right - left, right - n + k);
    }
    printf("%.6f\n%lld\n", (double)numer/denom, count);
}


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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

long long x;
int ans;

int main() {

	scanf("%lld", &x);	
	++x;
	while (x >= 10) x /= 10, ans += 9;
	ans += x - 1;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let n = get!(i32);
    let k = get!(i32);
    let x = get!(i32);
    let y = get!(i32);

    println!("{}", cmp::min(n, k) * x + cmp::max(0, n - k) * y);
}

Measured memory_bytes: 4476
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	char s[5]; cin >> s;

	ll k = 0;
	rep(i, 0, 4) {
		if (s[i] == '+') {
			k++;
		}
		else {
			k--;
		}
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
edges = []
$graph = Array.new(n).map{Array.new()}

m.times {
  a, b = gets.chomp.split.map(&:to_i)
  a -= 1; b-= 1;
  edges.push( [a, b] )
  $graph[a].push(b)
  $graph[b].push(a)
}

def dfs(u, v, n)
  is_visited = [ false ]*n
  st = [ 0 ]
  while not st.empty?
    cur = st.pop
    is_visited[cur] = true
    for adj in $graph[cur] do
      if is_visited[adj] == true ||
          cur == u && adj == v ||
          cur == v && adj == u then
        next
      end
      st.push(adj)
    end
  end
  return is_visited.all?
end

ans = 0
m.times { |i|
  u = edges[i][0]
  v = edges[i][1]
  if dfs(u, v, n) == false
    ans += 1
  end
}

p ans


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll rep = (n-1)/(a+b);
    ll ans = a * rep;
    n -= rep*(a+b);
    if (n <= a) {
        cout << ans + n << endl;
    } else {
        cout << ans + a << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include<math.h>
#include<stdio.h>
#include<utility>
#include<algorithm>

int main() {
	int a, b, c;
	char op;
	op = '+';
	while (op != '?') {
		scanf("%d %c %d", &a, &op, &b);
		if (op == '+') {
			c = a + b;
		}
		if (op == '-') {
			c = a - b;
		}
		if (op == '*') {
			c = a*b;
		}
		if (op == '/') {
			c = a / b;
		}
		if (op != '?') {
			printf("%d\n", c);
		}
	}
}

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

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

ll const MOD = 1e9 + 7;

ll binpow(ll x, ll p)
{
    ll r = 1;
    while (p) {
        if (p & 1) {
            --p;
            r *= x;
            r %= MOD;
        } else {
            p /= 2;
            x *= x;
            x %= MOD;
        }
    }
    return r;
}

ll fact[200001];

inline ll rev(ll x)
{
    return binpow(x, MOD-2);
}

ll C(int n, int m)
{
    ll x = 1;
    for (int i = n-m+1; i <= n; i++) {
        x *= i;
        x %= MOD;
    }
    return x * rev(fact[m]) % MOD;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, a, b;
    cin >> n >> a >> b;
    fact[0] = 1;
    for (int i = 1; i <= max(a, b); i++)
        fact[i] = (fact[i-1] * i) % MOD;
    ll x = (binpow(2, n)-1) - C(n, a) - C(n, b);
    while (x < 0)
        x += MOD;
    cout << x;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n,C;
int fld[30][100001];
int ans;

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

	cin>>n>>C;
	REP(i,n) {
		int s,t,c; cin>>s>>t>>c;
		c--;
		fld[c][s-1]++,fld[c][t]--;
	}

	REP(i,30) {
		REP(j,100000) {
			fld[i][j+1]+=fld[i][j];
		}
	}

	REP(i,100001) {
		int cnt=0;
		REP(j,30) {
			if(fld[j][i]) cnt++;
		}
		ans=max(ans,cnt);
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define fast_cin() ios_base::sync_with_stdio(0); cin.tie(0);
#define F first
#define S second
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = n-1; i>=0 ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define sz(a) int(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define present(container, element) (container.find(element) != container.end())
#define vpresent(container, element) (find(all(container),element) != container.end()) //for vectors

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif*/
    fast_cin();
    ll n;cin>>n;
    if(n==1)
    	cout<<0;
    else
    {
    	cout<<(n*(n-1))/2;
    }
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
sa = [x2-x1, y2-y1]
x3, y3 = x2-sa[1], y2+sa[0]
x4, y4 = x1-sa[1], y1+sa[0]
print(x3, y3, x4, y4)

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

int main() {
	ios :: sync_with_stdio(0);

	int x; string s;
	map <string, int> mp;
	while(cin >> x >> s)
		mp[s.substr(1)] ++;
	cout << mp["A"] << '\n';
	cout << mp["B"] << '\n';
	cout << mp["AB"] << '\n';
	cout << mp["O"] << '\n';

	return 0;
}

Measured memory_bytes: 3144
n = int(input())
s = []
for i in range(n):
  s.append(list(input()))
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
  if s[i][0] == 'B' and s[i][-1] == 'A':
    c1 += 1
  elif s[i][0] == 'B':
    c2 += 1
  elif s[i][-1] == 'A':
    c3 += 1
if c3 == 0 and c2 == 0 and c1 > 0:
  c1 -= 1
min = min(c1+c2, c1+c3)
ans = 0
for i in range(n):
  for j in range(len(s[i])-1):
    if s[i][j] == 'A' and s[i][j+1] == 'B':
      ans += 1
print(ans+min)

Measured memory_bytes: 48088
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	q := scanInt()
	query := make([][3]int, q)
	as := []int{}
	for i := 0; i < q; i++ {
		query[i][0] = scanInt()
		if query[i][0] == 1 {
			query[i][1] = scanInt()
			as = append(as, query[i][1])
			query[i][2] = scanInt()
		}
	}

	sort.Ints(as)

	n := len(as)
	cnt := make(BIT, n+1)

	ans := 0
	b := 0
	c := 0
	mid := 0
	for i := 0; i < q; i++ {
		if query[i][0] == 1 {
			a := query[i][1]
			b += query[i][2]

			idx := sort.Search(n, func(idx int) bool { return a <= as[idx] })
			cnt.Add(idx, 1)
			c++

			idx = sort.Search(n, func(idx int) bool { return (c+1)/2 <= cnt.Sum(idx) })
			if c&1 == 0 {
				ans += abs(mid-as[idx])
			}
			mid = as[idx]
			ans += abs(mid-a)
		} else {
			idx := sort.Search(n, func(idx int) bool { return (c+1)/2 <= cnt.Sum(idx) })
			fmt.Fprintln(wr, as[idx], ans+b)
		}
	}

}

// BIT type
type BIT []int

// Sum function calculates a sum to i
func (t BIT) Sum(i int) int {
	s := 0
	for i++; i > 0; i -= i & -i {
		s += t[i]
	}
	return s
}

// Add function add x to i
func (t BIT) Add(i, x int) {
	for i++; i < len(t); i += i & -i {
		t[i] += x
	}
}


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

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

    priority_queue<int> que;
    for (int i = 0; i < N; i++)
    {
        int A;
        cin >> A;

        que.push(A);
    }

    for (int i = 0; i < M; i++)
    {
        int a = que.top();
        que.pop();
        que.push(a / 2);
    }

    long long ans = 0;
    while (!que.empty())
    {
        ans += que.top();
        que.pop();
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  while(1){
    int n, l, r;
    cin>>n>>l>>r;
    if(n == 0 && l == 0 && r == 0) break;
    vector<int> A(n);
    cin>>A;

    auto isUru = [&](int x){
      for(int i=0;i<n;i++){
	if(x % A[i] == 0) return i % 2 == 0;
      }
      return n % 2 == 0;
    };

    int ans = 0;
    for(int x = l; x <= r; x++) ans += isUru(x);
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int n, a;
/**********************************************/

signed main(){
    cin >> n >> a;

    if(a >= 500){
        cout << "Yes" << endl;
    }else if(n % 500 <= a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <queue>

int main(){
  int N,M;
  std::cin >> N >> M;

  std::priority_queue<long long> pq;
  for(int i = 0 ; i < N; i++){
    int A;
    std::cin >> A;
    pq.push(A);
  }
  for(int i = 0; i < M; i++){
    int A = pq.top();
    pq.pop();
    pq.push(A/2);
  }

  long long ans = 0;
  for(int i = 0; i < N; i++){
    ans += pq.top();
    pq.pop();
  }

  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 1400
def resolve():
    ss = input()
    t = input()

    Srev = ss[::-1]
    Trev = t[::-1]

    initial_T = -1

    for i in range(len(Srev) - len(Trev) + 1):
        flg = True
        for j in range(len(Trev)):
            if Srev[i + j] != Trev[j] and Srev[i + j] != '?':
                flg = False
                break

        if flg:
            initial_T = i
            break

    Srep = Srev[:initial_T] + Trev + Srev[initial_T + len(Trev):]
    ans = Srep.replace('?', 'a')[::-1]

    if initial_T == -1:
        print('UNRESTORABLE')
    else:
        print(ans)

resolve()

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];
		int min = Integer.MAX_VALUE;
		int sub = 0;
		
		for(int i=0; i<N; i++) {
			h[i]= sc.nextInt();
		}
      	//低い順に並べる
		Arrays.sort(h);
        //N-K+1通りのパターンでK本のうちで左から順に
        //最高から最低の木の高さを減算して最小値を求める
		for(int i=0; i<N-K+1; i++) {
			sub = h[i+K-1] - h[i];
			min = Math.min(min, sub);
		}
		System.out.println(min);
    }
}

Measured memory_bytes: 59820
class BingoCard:
    def __init__(self, bingolist):
        self.bingocard = bingolist

    def call(self, b):
        for i in range(3):
            for j in range(3):
                if b == self.bingocard[i][j]:
                    self.bingocard[i][j] = 0

    def check_bingo(self):
        bingo = False
        # check row
        for row in self.bingocard:
            if row[0] + row[1] + row[2] == 0:
                bingo = True
        # check column
        for i in range(3):
            if self.bingocard[0][i] == 0:
                if self.bingocard[1][i] + self.bingocard[2][i] == 0:
                    bingo = True
        # check diagonal
        if self.bingocard[1][1] == 0:
            if self.bingocard[0][0] + self.bingocard[2][2] == 0 or\
                self.bingocard[0][2] + self.bingocard[2][0] == 0:
                bingo = True
        return bingo

# prepare bingo card
bingo0 = list(map(int, input().split(" ")))
bingo1 = list(map(int, input().split(" ")))
bingo2 = list(map(int, input().split(" ")))

bc = BingoCard([bingo0, bingo1, bingo2])

# get N
n = int(input())

while n:
    b = int(input())
    bc.call(b)
    n -= 1

if bc.check_bingo():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def main():
    n = int(input())
    A = [1] * (n + 1)
    ans = 1
    for i in range(2, n + 1):
        if A[i] == 1:
            m = i ** 2
            j = 2
            for a in range(i, n + 1, i):
                if a == m:
                    A[a] *= (j + 1)
                    m *= i
                    j += 1
                else:
                    count = 1
                    k = a // i
                    while k % i == 0:
                        k = k // i
                        count += 1
                    A[a] *= (count + 1)
            ans += 2 * i
        else:
            ans += A[i] * i
    print(ans)
if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    cin>>n;
    set<string>s;
    string prev_word,word;
    cin>>word;
    s.insert(word);
    --n;
    bool ans = true;
    while(n--)
    {
        prev_word = word;
        cin>>word;
        if(s.count(word)!=0)
            ans = false;
        if(prev_word[prev_word.size()-1]!=word[0])
            ans = false;
        s.insert(word);
    }
    if(ans)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3628
//code by parshuram_84
#include <bits/stdc++.h>
#define floop(i,a,n) for (int i=a;i<n;i++)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvl vector<vector<long long> >
#define vp vector<pair<long long,long long>>
#define vpp vector<pair<pair<long long,long long>,long long>>
#define mp make_pair
#define all(c) c.begin(),c.end()
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin();it != container.end(); it++)
typedef std::numeric_limits< double > dbl;
using namespace std;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }

int32_t main() {
	IOS;
	ll t,f,i,j,k,n,x,y,z;
	string s;
	cin>>t;
	f=0;x=0;
	for(i=0;i<t;i++)
	{
		cin>>y>>z;
		if(y==z) x++;
		else x=0;
		if(x==3) f=1;
	}
	if(f==0) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    bool ans = false;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i * j == N){
                ans = true;
            }
        }
    }
    Yes(ans);
}


Measured memory_bytes: 256
import math
n=int(input())
def factorization(num):
    factor = []
    flag = True
    is_Prime= True
    if num == 1:
        is_Prime = False
    while num > 1 and flag:
        flag = False
        for i in range(int(math.sqrt(num))+2):
            k = i + 2
            if num % k == 0:
                factor.append(k)
                num = int(num / k)
                is_Prime = False
                flag = True
                break
    if is_Prime or num > 1:
        factor.append(num)
    return factor
a = factorization(n)
from collections import Counter
co = Counter(a)
result = 0
for k, num in co.items():
    c = 0
    for i in range(1, num+1):
        c += i
        result += 1
        if c > num:
            result -= 1
            break
print(result)


Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

int main()
{
  ll n,a,b;
  cin>>n>>a>>b;

  if(a>b) swap(a,b);
  if((b-a)%2){
    cout<<min(min(b-1,n-a),min(a+(b-a-1)/2,n-b+1+(-a+b-1)/2))<<endl;
  }else{
    cout<<(b-a)/2<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int count=700;
  if(S[0]=='o'){count += 100;}
  if(S[1]=='o'){count += 100;}
  if(S[2]=='o'){count += 100;}
  cout << count <<  endl;
}

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


int main(){
	int M, D;
	cin >> M >> D;
	int ans = 0;
	for(int i = 1; i <= M; ++i){
		for(int j = 1; j <= D; ++j) {
			int d1, d2;
			d1 = j % 10;
			d2 = j / 10 % 10;
			if(d1==1||d2==1) continue;
			if(d1*d2==i){
			   	ans++;
			}
		}
	}
	cout << ans << endl;
}









Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<string>
#include<math.h>
using namespace std;
int main()
{
    int a,b,c,d,e,i,j,m=-11,n,x,y,z,k=0;
    cin>>a>>b;
     if((a>=1&&a<10)&&(b>=1&&b<10))
     {
         printf("%d\n",a*b);
     }
     else cout<<"-1"<<endl;

}


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

int main(){
    int n;  cin >> n; 
    string s;   cin >> s;
    //solve
    int ans = 1;
    char tmp = s[0];
    for(int ptr = 0; ptr < n; ptr++){
        if(tmp != s[ptr]){
            tmp = s[ptr];
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
 
    int main(){
      string s;
      cin >> s;
      rep(i,5) cout << s[i];
      cout << ' ' ;
      REP(i,6,13) cout << s[i];
      cout << ' ' ;
      REP(i,14,s.size()) cout << s[i];
      cout << endl;
      return 0;}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstring>
#include<functional>
namespace IO
{
    char ibuf[(1<<21)+1],obuf[(1<<21)+1],st[15],*iS,*iT,*oS=obuf,*oT=obuf+(1<<21);
    char Get(){return (iS==iT? (iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT? EOF:*iS++)):*iS++);}
    void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
    void Put(char x){*oS++=x;if(oS==oT)Flush();}
    int read(){int x=0,c=Get();while(!isdigit(c))c=Get();while(isdigit(c))x=x*10+c-48,c=Get();return x;}
    void write(int x){int top=0;while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put('\n');}
}using namespace IO;
using std::vector;
using std::priority_queue;
int min(int a,int b){return a<b? a:b;}
const int N=500007,inf=0x7f7f7f7f;
vector<int>e[N];priority_queue<int,vector<int>,std::greater<int>>Q;
int n,k,p[N],q[N],mn[N<<2],deg[N];
#define ls p<<1
#define rs p<<1|1
#define mid ((l+r)>>1)
void pushup(int p){mn[p]=min(mn[ls],mn[rs]);}
void update(int p,int l,int r,int x,int v)
{
    if(r==l) return (void)(mn[p]=v);
    (x<=mid? update(ls,l,mid,x,v):update(rs,mid+1,r,x,v)),pushup(p);
}
int query(int p,int l,int r,int L,int R)
{
    if(r<L||R<l) return inf;
    if(L<=l&&r<=R) return mn[p];
    return min(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R));
}
int main()
{
    int n=read(),k=read(),m=0;memset(mn,0x7f,sizeof mn);
    for(int i=1;i<=n;++i) q[read()]=i;
    for(int i=n,j;i>=1;--i)
    {
	if((j=query(1,1,n,q[i]+1,q[i]+k-1))^inf) ++deg[q[j]],e[q[i]].push_back(q[j]);
	if((j=query(1,1,n,q[i]-k+1,q[i]-1))^inf) ++deg[q[j]],e[q[i]].push_back(q[j]);
	update(1,1,n,q[i],i);
    }
    for(int i=1;i<=n;++i) if(!deg[i]) Q.push(i);
    for(int u;!Q.empty();)
    {
	q[++m]=u=Q.top(),Q.pop();
	for(int v:e[u]) if(!--deg[v]) Q.push(v);
    }
    for(int i=1;i<=n;++i) p[q[i]]=i;
    for(int i=1;i<=n;++i) write(p[i]);
    return Flush(),0;
}

Measured memory_bytes: 49068
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 8/23/2020
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
const double PI = acos(-1);
const int MOD = 1000000007;

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

	string n;
	cin >> n;
	ll sum = 0;
	for(char& k : n) sum += (k-'0');
	cout << (sum%9 ? "No" : "Yes");

	return 0;
}


Measured memory_bytes: 3732
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

// to format a document: ctrl + K -> ctrl + D

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

    for (int i = 0; i < S.length(); i++) {
        
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        
        string tmp;
        tmp.push_back(S.back());
        S.insert(0, tmp);
        S.pop_back();
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,m,s,t;
struct edge{ll to,cost;};
ll V;
const ll MAX_V=100100;
vector<edge> G1[MAX_V];
ll d1[MAX_V];
vector<edge> G2[MAX_V];
ll d2[MAX_V];

void dijkstra1(int s){
	priority_queue<Pi,vector<Pi>,greater<Pi> >que;
	fill(d1,d1+V,1e15);
	d1[s]=0;
	que.push(Pi(0,s));
	while(!que.empty()){
		Pi p=que.top();que.pop();
		int v=p.second;
		if(d1[v]<p.first)continue;
		for(int i=0;i<G1[v].size();i++){
			edge e=G1[v][i];
			if(d1[e.to]>d1[v]+e.cost){
				d1[e.to]=d1[v]+e.cost;
				que.push(Pi(d1[e.to],e.to));
			}
		}
	}
}
void dijkstra2(int s){
	priority_queue<Pi,vector<Pi>,greater<Pi> >que;
	fill(d2,d2+V,1e15);
	d2[s]=0;
	que.push(Pi(0,s));
	while(!que.empty()){
		Pi p=que.top();que.pop();
		int v=p.second;
		if(d2[v]<p.first)continue;
		for(int i=0;i<G2[v].size();i++){
			edge e=G2[v][i];
			if(d2[e.to]>d2[v]+e.cost){
				d2[e.to]=d2[v]+e.cost;
				que.push(Pi(d2[e.to],e.to));
			}
		}
	}
}
ll ans[100100];
int main(){
	cin>>n>>m>>s>>t;
	V=n;
	s--,t--;
	REP(i,m){
		int u1,v1,a1,b1;
		cin>>u1>>v1>>a1>>b1;
		u1--,v1--;
		G1[u1].push_back(edge{v1,a1});
		G1[v1].push_back(edge{u1,a1});
		G2[u1].push_back(edge{v1,b1});
		G2[v1].push_back(edge{u1,b1});
	}
	dijkstra1(s);
	dijkstra2(t);
	ans[n-1]=d1[n-1]+d2[n-1];
	for(int i=n-2;i>=0;i--){
		ans[i]=min(ans[i+1],d1[i]+d2[i]);
	}
	REP(i,n){
		ll ta=1e15-ans[i];
		cout<<ta<<endl;
	}
	return 0;
}

Measured memory_bytes: 19140
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

inline lnt ceildiv(lnt a, lnt b) { return (a+b-1)/b; }


int main() {
	lnt n;
	std::cin >> n;
	std::vector<lnt> a(n+1);
	rep(i,n+1) std::cin >> a[i];
	if(n==0&&a[0]==1) {
		print(1);
		return 0;
	}
	if(a[0]!=0) {
		print(-1);
		return 0;
	}
	// go up from leaves and get the max amount of nodes
	// and go down from root and get max amount of nodes
	std::vector<lnt> up(n+1);
	std::vector<lnt> upm(n+1); // min with leaves
	upm[n]=a[n];
	up[n]=a[n];
	lnt ups=a[n];
	for(int i=n-1;i>=0;i--) {
		ups+=a[i];
		up[i]=ups;
		upm[i]=ceildiv(upm[i+1],2)+a[i];
	}
	lnt sum=1;
	lnt cur=1;
	for(int i=1;i<=n;i++) {
		cur*=2;
		if(up[i]<cur) {
			cur=up[i];
		}
		if(cur<upm[i]) {
			print(-1);
			return 0;
		}
		sum+=cur;
		cur-=a[i];
		debug(sum,cur,up[i]);
	}
	print(sum);
}


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

int main()
{
    ll n,i,j;
    cin>>n;
    ll a[n],pre[n+1]={0};
    pre[0]=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        pre[i+1]=pre[i]+a[i];
    }
    /*for(i=0;i<=n;i++)
    {
        cout<<pre[i]<<" ";
    }
    cout<<endl;*/
    ll dp[n+1][n+1],dp1[n+1][n+1];
    memset(dp,0,sizeof(dp));
    memset(dp1,0,sizeof(dp1));

    for(ll k=1;k<=n;k++)
    {
        for(i=1,j=k;i<=n && j<=n;i++,j++)
        {
            if(i==j)
            {
                dp[i][j]=a[i-1];
                dp1[i][j]=0;
            }
            else
            {
                dp[i][j]=max(a[i-1]+dp1[i+1][j],a[j-1]+dp1[i][j-1]);
                dp1[i][j]=pre[j]-dp[i][j]-pre[i-1];
            }
        }
    }
    cout<<dp[1][n]-dp1[1][n]<<endl;
}

Measured memory_bytes: 141056
import java.util.Scanner;
import java.util.Stack;

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

	while(sc.hasNext()){
	    
	    char[] charData = sc.nextLine().toCharArray();
	     
	    if(charData[0] == '.') break;

	    Stack<Character> st = new Stack<Character>();
	    
	    /*
	    // ティツ。ツィテァツ、ツコテ」ツ?療」ツ?ヲテ」ツ?ソテ」ツつ?
	    System.out.print("[");
	    for(int i = 0;i<charData.length;i++){
		System.out.print(charData[i] + " ");
	    }
	    System.out.println("]");
	    */
	    
	    for(int i = 0;i<charData.length;i++){
		if(charData[i] == '(') st.push('(');
		if(charData[i] == '[') st.push('[');
		if(!st.empty()){ // テ、ツクツ?・ツ?凝」ツ?ァテ」ツつ?[テ」ツ?古」ツ?づ」ツ?セテ」ツ?」テ」ツ?ヲテ」ツ?淌」ツつ?
		    if(charData[i] == ')' && st.peek().equals('(')){ // テヲツ慊?・ツセツ古」ツ?ォテヲツ崢エテヲツ鳴ーテ」ツ?陛」ツつ古」ツ?淌」ツ?ョテ」ツ??テ」ツ?ァテ」ツ??テ」ツ?古・ツ?・テ・ツ環崚」ツ?陛」ツつ古」ツ?淌」ツ?ィテ」ツ??
			st.pop();
		    }else if(charData[i] == ')') check = false; // )テ」ツ?古」ツ?催」ツ?淌」ツ?妥」ツ?ゥテヲツ慊?・ツセツ古」ツ?ョテヲツ崢エテヲツ鳴ーテ」ツ??テ」ツ?佚」ツつε」ツ?ェテ」ツ?凝」ツ?」テ」ツ?淌」ツ?ィテ」ツ?催」ツ?ッテ」ツ?敕」ツ?ョテヲツ卍づァツつケテ」ツ?ァcheck=falseテ」ツ?ォテ」ツ?療」ツ?ヲテ」ツ?甘」ツ??
		    if(charData[i] == ']' && st.peek().equals('[')){
			st.pop();
		    }else if(charData[i] == ']') check = false;
		}else{ // [(テ」ツ?古」ツ?催」ツ?ヲテ」ツ?ェテ」ツ??」ツ?ョテ」ツ?ォ)]テ」ツ?古」ツ?催」ツ?淌・ツ?エテ・ツ青?
		    if(charData[i] == ')'){
			check = false;
		    }
		    if(charData[i] == ']'){
			check = false;
		    }
		}
	    }
	    
	    System.out.println(st.empty() && check ? "yes" : "no");

	    check=true;
	}
    }
}

Measured memory_bytes: 36208
import itertools
n, k = map(int, input().split())
d = []
a = []
n_1=[i for i in range(1,n+1)]
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))
a_1 = list(itertools.chain.from_iterable(a))
c=list(set(n_1)-set(a_1))
print(len(c))
  

Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  ll a=0;
  while(3*a<=n){
    a++;
  }
  cout << a-1 << endl;

}

Measured memory_bytes: 3600
#include<stdio.h>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
long long s[4000];
P p[4000];
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,i;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<4000;i++){
			s[i]=0;
			p[i].first=5000;
			p[i].second=i;
		}
		for(i=0;i<n;i++){
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			s[a-1]+=(long long)b*c;
			p[a-1].first=min(p[a-1].first,i);
		}
		sort(p,p+4000);
		bool f=true;
		for(i=0;i<4000;i++){
			if(p[i].first==5000)break;
			if(s[p[i].second]>=1000000){
				printf("%d\n",p[i].second+1);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
}

Measured memory_bytes: 1100
#include "bits/stdc++.h"
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vso(x) sort( x.begin() , x.end() )
#define vre(x) reverse( x.begin() , x.end() ) ;
#define aso(x) sort( x , x + x.size() )
#define are(x) reverse( x , x + x.size() )
#define print(x) cout << x << endl 
#define no cout << "NO\n" 
#define yes cout << "YES\n"
typedef long long ll ; 
typedef unsigned long long ull ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("problem_name.out", "w", stdout) ;
    //freopen("problem_name.in", "r", stdin) ;
    //ull h = 798568968205 ; srand(h) ;
    //int t ; cin >> t ; while(t--){}
    
    ll x ; cin >> x ; 
    ll a = 1000*(x/500) ;
    x = x % 500 ;
    ll b = 5*(x/5) ;
    print(a+b) ;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
char s;
cin >> s;
if (isupper(s)) cout << "A" << endl;
else
    cout << "a" << endl;
}

Measured memory_bytes: 3632
// Copyright: lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int maxn = 100100;
int n, x, nw;
ll rem, ans;
int b[maxn], l[maxn], r[maxn], a[maxn];
vector<pair<ll, int> > vec;

void work() {
	n = read(), x = read();
	rep(i, 1, n) b[i] = read(), l[i] = read(), r[i] = read();
	rep(i, 1, n) vec.pb(mp(x * 1ll * r[i] - b[i] * 1ll * (r[i] - l[i]), i));
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	rep(i, 1, n) rem += b[i] * 1ll * l[i];
	rep(i, 0, vec.size() - 1) {
		int ind = vec[i].se;
		rem -= vec[i].fi;
		if (rem <= 0) {
			nw = i;
			break;
		}
		ans += x;
	}
	ll mn = 1e9, rr = rem;
	rep(i, 0, vec.size() - 1) {
		if (i <= nw) rem = rr + vec[i].fi;
		else rem = rr + vec[nw].fi;
		int ind = vec[i].se;
		mn = min(mn, (rem - 1) / l[ind] + 1);
		ll tmp = b[ind] * 1ll * (r[ind] - l[ind]);
		rem += tmp;
		tmp = rem / r[ind];
		if (tmp * r[ind] < rem) tmp++;
		mn = min(mn, tmp);
	}
	printf("%lld\n", ans + mn);
}

int main(){
	#ifdef LZT
		freopen("in","r",stdin);
	#endif

	work();

	#ifdef LZT
		Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
	#endif
}


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

long long ans(long long c,long long d){
  
  if ( c > d ){
    return ( c / d ) + 1;
  }else if ( c == d ){
    return 2;
  }else{
    return 1;
  } 
  
}


int main() {
  
  long long a,b,x;
  cin >> a >> b >> x;
  
  if ( a == 0 ){
    cout << ans(b,x) << endl;
  }else{
    cout << ans(b,x)-ans(a-1,x) << endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<set>
#define mk make_pair
using namespace std;
long long  n;
set<pair<int,int> > s;
int main()
{
	scanf("%lld",&n);
	int ma;
	for(ma=1;(1LL<<ma)<n;ma++);ma--;
	for(int i=1;i<=ma;i++)
	s.insert(mk(i,i));
	for(int i=1;i<=ma;i++)
	s.insert(mk(i+ma,i));
	s.insert(mk(ma+ma+1,ma+1));
	s.insert(mk(ma+ma+2,ma+1));
	int sz=ma+ma+2,nm=ma+1;
	for(int i=ma-1;~i;i--)
	if(n&(1LL<<i))
	{
		nm++;
		s.insert(mk(i,nm));
		s.insert(mk(sz,nm));
	}
	printf("%d\n",s.size());
	for(set<pair<int,int> >::iterator it=s.begin();it!=s.end();it++)
	printf("%d ",(*it).second);
	return 0;
}
	

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
　const N=input[0]-0;
  var sum=0;
  var nums=input[1].split(" ");
  for(var i=0;i<nums.length;i++){
    sum+=(nums[i]-0);
  }
  var x=Math.round(sum/N);
  sum=0;
  for(var i=0;i<nums.length;i++){
    sum+=(nums[i]-x)**2;
  }
  console.log(sum);
}

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

Measured memory_bytes: 29656