akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long

ll NOD [10000050];

void generateNOD(int N)
{
    for(int i = 1; i <= N; i++)
    {
        for(int j = i; j <= N; j += i)
        {
            NOD[j] += 1;
        }
    }
}

int main()
{
    int n;
    ll sum = 0;
    cin >> n;
    generateNOD(n);
    for(int i = 1, j = n; i <= (int) (n / 2); i++, j--)
    {
        ll x = i * NOD[i];
        ll y = j * NOD[j];
        sum += x;
        sum += y;
    }
    if(n % 2 ==1)
    {
        n /= 2;
        n += 1;
        ll x = n * NOD[n];
        sum += x;
    }
    cout << sum;
}


Measured memory_bytes: 81776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 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 main() {
	int r;
	cin >> r;

	int ans = 3 * r * r;

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll n;
  cin >> n;
  vl x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  vl v(n);
  rep(i, n) v[i] = i;
  int cnt = 0;
  double sum = 0;
  do {
    double dist = 0;
    for (int i = 0; i < n - 1; i++) {
      int a = v[i];
      int b = v[i + 1];
      ll dx = x[a] - x[b];
      ll dy = y[a] - y[b];
      dist += sqrt(dx * dx + dy * dy);
      // cerr << a << "->" << b << ":" << dx << "," << dy << endl;
    }
    // cerr << setprecision(10) << fixed << dist << endl;
    sum += dist;
    cnt++;
  } while (next_permutation(ALL(v)));
  cout << setprecision(10) << fixed << sum / (double)cnt << endl;
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[100010];

int main(void){
	int i;

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

	int N,T;
	cin >> N >> T;
	for(i=1;i<=N;i++) cin >> a[i];
	int mn=a[1],s;
	vector<int>v;
	for(i=2;i<=N;i++){
		if(a[i]>mn){
			s=a[i]-mn;
			v.push_back(s);
		}else{
			mn=a[i];
		}
	}

	sort(v.begin(),v.end());
	int n=v.size();

	int ans=1;
	for(i=n-2;i>=0;i--){
		if(v[i]==v[i+1]) ans++;
		else break;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main(void) {
    int n, cnt[6] = {};
    double h;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h < 165.0) cnt[0]++;
        else if (h < 170.0) cnt[1]++;
        else if (h < 175.0) cnt[2]++;
        else if (h < 180.0) cnt[3]++;
        else if (h < 185.0) cnt[4]++;
        else cnt[5]++;
    }

    for (int i = 0; i < 6; i++) {
        cout << i + 1 << ":";
        for (int j = 0; j < cnt[i]; j++)
            cout << "*";
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3032
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int maxVari= 0;
        int last = 0 ;
        int lastval =0;
        for (int i = 0; i <5 ; i++) {
            int a  =sc.nextInt();
            int val = (int)Math.ceil( (double) a / 10) *10;
            if( val-a > maxVari){
                maxVari = val-a;
                last = a;
                lastval= val;
            }
            ans += val;
        }
        ans = ans -lastval +  last ;

            System.out.println(ans);
    }

}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    for (ll i=0;i<=n;i++){
        for (ll j=0;j<=m;j++){
            if (i*j+(n-i)*(m-j)==k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  const int CMAX = 9;
  vector<int> color(CMAX);
  REP(i,CMAX) color[i] = 0;
  REP(i,n){
    int a;
    cin >> a;
    REP(i,CMAX-1){
      if(a >= 3200) {
        color[8]++;
        break;
      }
      if(a < (i+1)*400) {
        color[i]++;
        break;
      }
    }
  }

  int cnt = 0;
  REP(i,CMAX-1){
    if(color[i] == 0) continue;
    cnt++;
  }
  // for(auto x: color) cout << x << " ";
  // cout << endl;
  int ansmin = max(1,cnt);
  int ansmax = cnt + color[8];
  cout << ansmin <<" " << ansmax << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>

void CountingSort(int *a,int *b,int n,int k){
  int i,j,c[210000]={};

  for(j=1;j<=n;j++) c[a[j]]++;
  for(i=1;i<=k;i++) c[i] = c[i]+c[i-1];

  for(j=n;j>0;j--){
    b[c[a[j]]] = a[j];
    c[a[j]]--;
  }
}

int main(){
  int *a,*b;
  int n,i,k=0;
  
  scanf("%d",&n);
  a = (int *)malloc(sizeof(int)*(n+1));
  b = (int *)malloc(sizeof(int)*(n+1));
  
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
    if(a[i]>k) k=a[i];
  }
  
  
  CountingSort(a,b,n,k);

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

  return 0;
}



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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

int k,x;

int main()
{
  cin >> k >> x;

  for (int i = max(-1000000,x-k+1); i <= min(1000000,x+k-1); i++) {
    cout << i << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/perl

my ($n,$k) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = map {$_ - 0} split(/\s+/o,<STDIN>);

my @za = grep { $_ == 0 } @a;
if( $#za >= 0 ){
  @a = grep { $_ != 0 } @a;
  $k -= (1+$#za);
}

if( $k <= 0 ){
  print "0\n"; exit(0);
}

#print "n,k = $n,$k\n";

my @ma = grep { $_ < 0 } @a;
my @pa = grep { $_ > 0 } @a;
my $minsc = 1000000000;

for(my $i=0;$i<=$#a;$i++){
  $cs = 1000000000;
  $cp = 1000000000;
  my $c_k = $k;
  if( $a[$i]<0 ){
    $cp = 1 + $#ma - $i;
    $cs = - $a[$i];
    if( $cp >= $c_k ){
      $minsc = $cs if $cs < $minsc;
    } elsif( $#pa >= 0 ) {
      $cs += (- $a[$i]);
      $c_k -= $cp;
      if( $#ma + $c_k <= $#a ){
        $cs += $a[$#ma + $c_k];
        $minsc = $cs if $cs < $minsc;
      }
    }
  } else {
    $cp = $i - $#ma;
    $cs = $a[$i];
    if( $cp >= $c_k ){
      $minsc = $cs if $cs < $minsc;
    } elsif( $#ma >= 0 ){
      $cs += $a[$i];
      $c_k -= $cp;
      if( 1+$#ma >= $c_k ){
        $cs += - $a[ 1+$#ma - $c_k];
        $minsc = $cs if $cs < $minsc;
      }
    }
  }
  #print "i=$i, cp =$cp, cs = $cs, minsc=$minsc\n";
}

print "$minsc\n";

exit(0);



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

int main() {
	int N;
	cin >> N;
	long long L0 = 2, L1 = 1;
	for (int i = 2; i <= N; i++) {
		long long buf = L1;
		L1 = L0 + L1;
		L0 = buf;
	}
	cout << L1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		for (int i =1; i<m; i++) {
			int l = scan.nextInt();
			int r = scan.nextInt();
			if(l>a) {
				a=l;
			}
			if(r<b) {
				b=r;
			}
			
		}
		int re = b-a+1;
		if(re<0) {
			System.out.println(0);
		}else {
		System.out.println(b-a+1);
		}

	}
}

Measured memory_bytes: 63352
a = list(map(int, input().split()))
a.sort()
ans = 0
while a[0]+1<a[2]:
    a[0] += 2
    ans += 1
    a.sort()
if a[0]==a[1]==a[2]:
    print(ans)
elif a[0]==a[1]:
    print(ans+1)
else:
    print(ans+2)

Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int d, l;
	cin >> d >> l;
	cout << d / l + d % l << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){

  int n;
  cin >> n;
  vector<int> v(n+1);
  rep(i,n)cin >> v[i+1];
  vector<int> res;
  rep(times,n){
    for(int i = v.size()-1;i > 0;i--){
      if(i == v[i]){
        v.erase(v.begin()+i);
        res.push_back(i);
        break;
      }
    }
  }
  if(res.size() == n)for(int i = n-1;i >= 0;i--)cout << res[i] << endl;
  else cout << -1 << endl;
  


  return 0;
}

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

int main(void){
    long long N;
    cin >> N;
    vector<long long> prime(1, 2);
    for(long long i=3; i<1000000; i+=2){
        bool ifprime = true;
        for(long long p: prime){
            if(i%p==0){
                ifprime = false;
                break;
            }
            if(p*p > i)break;
        }
        if(ifprime)prime.push_back(i);
    }
    vector<int> exponents;
    for(long long p: prime){
        int exponentbuf = 0;
        while(N%p==0){
            N/=p;
            exponentbuf++;
        }
        exponents.push_back(exponentbuf);
    }
    if(N > 1)exponents.push_back(1);
    int res = 0;
    for(int e: exponents){
        res += (int)((-1+sqrt(1+8*e))/2);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4896
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int ap[26];

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

    string s;
    cin >> s;

    long long Sol = 0;

    for (int i = 0; i < s.length(); ++i) {
        Sol += i - ap[s[i] - 'a'];
        ++ap[s[i] - 'a'];
    }

    cout << Sol + 1;

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string s;
    stack<int> st;
    cin >> s;
    int n = s.size();
    for (auto &&i : s)
    {
        if (!st.empty() and st.top() != i)
        {
            st.pop();
        }
        else
            st.push(i);
    }
    cout << n - st.size();
    return 0;
}

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

using  namespace std;

int main(){
	int a[4];
	int b[4];
	int hit, blow;


	while (cin >> a[0]){
		cin >> a[1];
		cin >> a[2];
		cin >> a[3];
		cin >> b[0];
		cin >> b[1];
		cin >> b[2];
		cin >> b[3];
		
		hit = 0;
		blow = 0;
		for (int i = 0; i < 4; i++){
			for (int j = 0; j < 4; j++){
				if (a[i] == b[j] && i == j){
					hit++;
				}
				if (a[i] == b[j] && i != j){
					blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;

	}

}

Measured memory_bytes: 1160
def 一日経過(n):
    return n+1
    
D=int(input())
C=list(map(int,input().split()))
S=[]
Ans=0
last=[0 for i in range(26)]
for i in range(D):
    s=list(map(int,input().split()))
    S.append(s)
for i in range(D):
    last=list(map(一日経過,last))
    t=int(input())-1
    last[t]=0
    Ans+=S[i][t]
    for j in range(26):
        Ans-=C[j]*last[j]
    print(Ans)

Measured memory_bytes: 9316
def task_c():
    n, k = map(int, input().split())
    from math import log2, ceil
    c = 0
    for i in range(1, n+1):
        if i >= k:
            c += 1/n
        else:
            c += 1/n * pow(0.5, ceil(log2(k / i)))
    print(c)
task_c()


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

int main() {
    int count = 0;
    while (true) {
        int x;
        cin >> x;
        
        if (x != 0) {
            ++count;
            cout << "Case " << count << ": " << x << endl;
        } else {
            break;
        }
    }
}


Measured memory_bytes: 3080
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
int64_t x;
mint(int64_t x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n,k,t;
    cin>>n>>k>>t;

    ll ans = 0;
    
    ans = ((n +(k-1))/k)*t;


    cout<<ans<<endl;

}

Measured memory_bytes: 3608
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e4 + 5;
int n;
int a[maxn], b[maxn], c[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  return true;
}

void solve() {
  for (int i = 0; i < n; i++) {
    c[i] = a[i] - b[i];
  }
  long long can = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] < 0) {
      can += -c[i] / 2;
    }
  }
  for (int i = 0; i < n; i++) {
    if (c[i] > 0) {
      if (can < c[i]) {
        printf("No\n");
        return;
      }
      can -= c[i];
    }
  }
  printf("Yes\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		boolean f = false;
		int min = Integer.MAX_VALUE-1;
		int n = scan.nextInt();
		int T = scan.nextInt();
		int[] c = new int[n];
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = scan.nextInt();
			t[i]  = scan.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (t[i] <= T) {
				f = true;
				if (c[i] <= min) {
					min = c[i];
				}
			}
		}
		if (f) {
			System.out.println(min);
		} else {
			System.out.println("TLE");
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
int ncr(int n, int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
map<int, int> dpArr;
int dp(int arr[],int n){
    if(n<=1){
        if( n == 0) return dpArr[0];
        return dpArr[1];
    }
    if(dpArr.count(n)){
        return dpArr[n];
    }
    dpArr[n] =  dp(arr,n-1) + abs(arr[n-1] - arr[n]);
    if(n > 1) dpArr[n] = min(dpArr[n], dp(arr, n-2)+ abs(arr[n-2] - arr[n]));
    return dpArr[n];
}

signed main(){

#ifndef ONLINE_JUDGE
  //  freopen("input.txt","r", stdin);
#endif

    fastIO

    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; i++){
        cin >> arr[i];
    }
    dpArr[0] = 0;
    dpArr[1] = abs(arr[0] - arr[1]);
    cout << dp(arr,n-1);

    return 0;
}


Measured memory_bytes: 15104
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf8");

let lines = [];
var reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on("line", line => {
  lines.push(line);
});

reader.on("close", () => {
  const n = parseInt(lines.shift());
  const v = lines.shift().split(/\s/).map(i => parseInt(i));
  const c = lines.shift().split(/\s/).map(i => parseInt(i));
  let ans = 0;
  for (let i = 0; i < n; i++) {
      if (v[i] > c[i]) ans += v[i] - c[i];
  }
  console.log(ans);
});


Measured memory_bytes: 7628
import java.util.*;

class Main{
	public static void main(String[] args){
		int p=0;
		Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        
        List<Integer> arr = Main.sieve(55555);
        List<Integer> arr2 = new ArrayList<Integer>();
        for(int i = 0; i < arr.size(); i++) {
        	if(arr.get(i) % 5 == 1) arr2.add(arr.get(i));
        }
        for(int i = 0; i < N; i++) {
        	System.out.print(arr2.get(i) + " ");
        }
	}

	static List<Integer> sieve(int N) {
		List<Integer> arr = new ArrayList<Integer>();
		arr.add(2);
		for(int i = 3; i < N; i++) {
			boolean flag = true;
			
			int k = 0;
			while(flag && k < arr.size()) {
				if(i % arr.get(k) == 0) {
					flag = false;
				}
				k++;
			}
			if(flag) {
				arr.add(i);
			}
		}
		return arr;
	}
}

Measured memory_bytes: 23508
s=input()
k=int(input())
a=[]
for i in range(len(s)):
    a.append(s[i:])
a.sort()
x=set()
for i in range(min(5,len(s))):
    for j in range(len(a[i])):
        x.add(a[i][:j+1])
print(sorted(x)[k-1])

Measured memory_bytes: 54128
def c_sum_of_product_of_pairs(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    cumsum = [0]
    for a in A:
        cumsum.append(cumsum[-1] + a)
    return sum([(cumsum[N] - cumsum[i + 1]) * A[i] for i in range(N)]) % MOD

print(c_sum_of_product_of_pairs())

Measured memory_bytes: 39440
#include<iostream>
#include<vector>
#include<map>
#include<iterator>
#include<algorithm>
#include<cstring>
#include<set>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
	long long int n,a, b, c, d, i, j, k;
	vector<long long int >v;
	cin >> n >> k;
	cin >> a;
	v.push_back(a);
	d = -1;
	for (i = 1; i < k; i++)
	{
		cin >> a;
		v.push_back(a);
		d = (d > v[i] - v[i - 1]) ? d : (v[i] - v[i - 1]);
	}
	c = n + v[0] - v[k - 1];
	if (c > d)
		cout << n-c << endl;
	else
	cout << n - d << endl;
	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,n;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	ll tot=n/(a+b)*a;
	n%=a+b;
	if(n>=a) tot+=a;
	else tot+=n;
	printf("%lld",tot);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main() {
    double D,x,y;
    int result = 0,N;
    cin >> N >> D;

    for(int i = 0 ; i < N;i++){
        cin >> x >> y;
        if( pow(x*x + y*y,0.5) <= D ){
            result++;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3196
N = int(input())
S = input().strip()
stack = []
l = 0
for i,c in enumerate(S):
  if c == ')':
    if stack:
      stack.pop()
    else:
      l += 1
  else:
    stack.append(i)
ans = '('*l + S + ')'*len(stack)
print(ans)

Measured memory_bytes: 3060
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

ll N,A,B;
ll ans = 0;

bool isA = false;
int Acount, Bcount = 0;

void _main() {
	cin >> N >> A >> B;

	ll divN = N / (A + B); //商
	ll remN = N % (A + B); //余り

	//商の数＝Aが足された回数
	ans += A * divN;

	//余りはA以上ならAを足す
	if (remN >= A) {
		ans += A;
	}
	//余りがA以下なら余りを足す
	else if (remN < A) {
		ans += remN;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    if(n%2==0) {
        cout << n/2-1 << endl;
    }
    else {
        cout << n/2 << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++)
		cin >> a[i];
	for (int i = 0; i < w + 2; i++)
		cout << "#" << (i == w + 1 ? "\n" : "");
	for (int i = 0; i < h;i++)
		cout << "#" << a[i] << "#" << endl;
	for (int i = 0; i < w + 2; i++)
		cout << "#" << (i == w + 1 ? "\n" : "");

	return 0;
}


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


fun solve() {
    val N  = rd.readInt()
    val A = rd.readLongArray()
    val B = rd.readLongArray()

    if (A.joinToString("") == B.joinToString("")) {
        println("Yes")
        return
    }

    val ASum = A.sum()
    val BSum = B.sum()
    if (ASum > BSum) {
        println("No")
        return
    }

    val needOpA = A.mapIndexed{ i, a ->
        max((B[i]-a)/2, 0)
    }.sum()

    val needOpB = B.mapIndexed{ i, b ->
        max(A[i]-b, 0)
    }.sum()

    val ans = if (needOpA >= needOpB) "Yes"
                    else "No"

    println(ans)
}


//val rd = debug.Reader("etc", "apc001", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 48024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N;
   cin>>N;
   int M=0;
   int sum=0;
   rep(i,N){
       int p;
       cin>>p;
       sum+=p;
       M=max(M,p);
   }
   sum-=M/2;
   cout<<sum<<endl;
   
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll c[27];
ll s[400][27];
ll last[27];
ll score[27];

int main(void){
	int D;
	cin>>D;
	for(int i=1;i<=26;i++)cin>>c[i];
	for(int i=1;i<=D;i++){
		for(int j=1;j<=26;j++){
			cin>>s[i][j];
		}
	}
	for(ll d=1;d<=D;d++){
		ll t;
		cin>>t;
		last[t]=d;
		score[t]+=s[d][t];
		ll ans = 0;
		for(ll j=1;j<=26;j++){
			score[j]-=c[j]*(d-last[j]);
			ans+=score[j];
		}
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 3700
#include<cstdio>
#include<algorithm>
#define MN 210000
using namespace std;

int n,m,a,b;
long long c[MN],x[MN],mmh=1e18;
int main(){
	scanf("%d%d",&n,&m);scanf("%d",&a);
	for (int i=2;i<=n;i++){
		scanf("%d",&b);
		if (a<b){
			c[1]+=b-a;
			c[a+1]-=b-a;
			c[b+1]+=b-a;
			
			c[a+1]+=b+1;c[b+1]-=b+1;x[a+1]--;x[b+1]++;
		}else{
			c[b+1]+=m-a+b;c[a+1]-=m-a+b;
			
			c[a+1]+=b+1+m;x[a+1]--;
			
			c[1]+=b+1;c[b+1]-=b+1;x[1]--;x[b+1]++;
		}
		a=b;
	}
	for (int i=1;i<=m;i++) if (c[i]+=c[i-1],x[i]+=x[i-1],c[i]+x[i]*i<mmh) mmh=c[i]+x[i]*i;
	printf("%lld\n",mmh);
}

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

int main(){

    string s1,s2;
    cin>>s1>>s2;
    if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;








    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val X = readInputLine().toLong()
    
    for (i in LongRange(1, X)) {
        if (i * (i + 1L) / 2L >= X) {
            println(i)
            return
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 31772
import java.util.Scanner;

class Main {
    private static String getMax(String a, String b) {
        int[][] dp = new int[a.length() + 1][b.length() + 1];
        for(int i = 1; i <= a.length(); i++) {
            for(int j = 1; j <= b.length(); j++) {
                if(a.charAt(i - 1) == b.charAt(j - 1)) {
                    dp[i][j] = 1 + dp[i - 1][j - 1];
                }
                else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        int R = a.length();
        int C = b.length();
        StringBuilder ans = new StringBuilder("");
        while(R > 0 && C > 0) {
            if(dp[R][C] == dp[R - 1][C]) {
                R--;
            } else if(dp[R][C] == dp[R][C - 1]) {
                C--;
            } else {
                ans.insert(0, a.charAt(R - 1));
                R--;
                C--;
            }
        }
        return ans.toString();
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        String b = sc.nextLine();
        System.out.println(getMax(a, b));
    }
}


Measured memory_bytes: 80852
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define debug(x) std::cout << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
 
    int N, V, P;
    ll M;
    cin >> N >> M >> V >> P;
    vector<ll> A(N);
    for (auto &x : A) cin >> x;
    sort(all(A));
    reverse(all(A));
 
    auto valid = [&](int k)
    {
        if (k < P)
            return true;
        if (A[k] + M < A[P - 1])
            return false;
        ll sum = 0;
        for (int i = 0; i < P - 1; ++i)
            sum += M;
        for (int i = k; i < N; ++i)
            sum += M;
        for (int i = P - 1; i < k; ++i)
            sum += min(M, A[k] + M - A[i]);
        if (sum < M * V)
            return false;
        return true;
    };
 
    ll vl = -1;
    ll vr = N;
    while (vr - vl > 1)
    {
        int k = (vl + vr) / 2;
        if (valid(k))
            vl = k;
        else
            vr = k;
    }
    cout << vl + 1 << '\n';
 
    return 0;
}

Measured memory_bytes: 1024
def main():
    n = int(input())
    h = [int(i) for i in input().split()]
    # 1マスしかない場合は無条件で単調非減少
    if n == 1:
        print("Yes")
        return
    for i in range(n):
        # 1マス目は無条件で1下げる
        if i == 0:
            h[i] -= 1
        # 1つ前と異なる場合は1下げる
        elif h[i] != h[i-1]:
            h[i] -= 1
            # 単調非減少でないなら終了
            if h[i] < h[i-1]:
                print("No")
                return
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> p(51), b(51);

ll f(ll n, ll x) {
	if (n == 0)
		return (x <= 0) ? 0 : 1;
	if (x <= 1 + b[n-1])
		return f(n-1, x-1);
	if (x == (2 + b[n-1]))
		return p[n-1] + 1;
	if (x <= 2 + 2 * b[n-1])
		return p[n-1] + 1 + f(n-1, x-2-b[n-1]);
	return 2 * p[n-1] + 1;
}

int main() {
	ll n; cin >> n;
	ll x; cin >> x;
	p[0] = b[0] = 1;
	for (int i = 0; i < 50; i++) {
		b[i+1] = b[i] * 2 + 3;
		p[i+1] = p[i] * 2 + 1;
	}
	cout << f(n, x) << '\n';
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

string s;
ll a[500010];
void solve();

void input() {
    cin >> s;
}

void solve() {
    ll ans = 0;
    ll cnt = 0;
    for (int i = 0; i < sz(s) + 1; i++) {
        a[i] = -1;
    }
    for (int i = 0; i < sz(s); i++) {
        if (s[i] == '<') {
            a[i] = cnt;
            cnt++;
        } else {
            cnt = 0;
        }
    }
    // REP(i,sz(s) + 1) {cout << a[i] << " ";}
    // cout << endl;
    cnt = 0;
    for (int i = sz(s) - 1; i >= 0; i--) {
        if (s[i] == '>') {
            a[i + 1] = cnt;
            cnt++;
        } else {
            cnt = 0;
        }
    }
    // REP(i,sz(s) + 1) {cout << a[i] << " ";}
    // cout << endl;
    for (int i = 0; i < sz(s) + 1; i++) {
        if (a[i] != -1) {
            ans += a[i];
        } else {
            ll k = 0;
            if (i - 1 >= 0) k = max(k, a[i - 1]);
            if (i + 1 < sz(s) + 1) k = max(k, a[i + 1]);
            ans += k + 1;
            a[i] = k + 1;
        }
    }
    // REP(i,sz(s) + 1) {cout << a[i] << " ";}
    // cout << endl;
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    input();
    solve();
    return 0;
}


Measured memory_bytes: 4740
#include<iostream>
#include<cstdio>
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;
}
int main()
{
	int a=read(),b=read();
	puts(a%500>b?"No":"Yes");
	return 0;
}



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

int main(){
     int n;
     cin>>n;
     
     int dp[n][3];
     int a[n];
     int b[n];
     int c[n];
     
     for(int i=0;i<n;i++){
          cin>>a[i]>>b[i]>>c[i];
     }
     
     dp[0][0]=a[0];
     dp[0][1]=b[0];
     dp[0][2]=c[0];
     
     for(int i=1;i<n;i++){
          for(int j=0;j<3;j++){
               if(j==0)
                    dp[i][j]=max(a[i]+dp[i-1][j+1],a[i]+dp[i-1][j+2]);
               if(j==1)
                    dp[i][j]=max(b[i]+dp[i-1][j-1],b[i]+dp[i-1][j+1]);
               if(j==2)
                    dp[i][j]=max(c[i]+dp[i-1][j-2],c[i]+dp[i-1][j-1]);
          }
     }
     
     /*for(int i=0;i<n;i++){
          for(int j=0;j<3;j++){
               cout<<dp[i][j]<<" ";
          }
          cout<<endl;
     }*/
     
    
     int ans[3];
     for(int i=0;i<3;i++){
         ans[i]=dp[n-1][i];
     }
     
     
     cout<<*max_element(ans,ans+3)<<endl;
}

Measured memory_bytes: 2560
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

S = input()
if S[0] == S[0].upper():
    print('A')
else:
    print('a')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

const int MAXN = 300010;

int n;
int a[MAXN];

int main()
{
	
	scanf("%d", &n);
	for (int i = 1; i <= 3*n; ++ i)
		scanf("%d", &a[i]);
	sort(a+1, a+3*n+1);
	ll ans = 0;
	for (int i = n+1; i <= 3*n; i += 2)
		ans += a[i];
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    ll N,A,B;
    cin >> N >> A >> B;
    if(A == 0){
        cout << 0 << endl;
        return 0;
    }

    ll wari = N / (A + B);
    ll amari = N % (A + B);

    if(amari == 0){
        cout << wari * A << endl;
        return 0;
    }

    ll a = min(amari, A);
    cout << wari * A + a << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();
    int abc = 0;
    int times = 0;
    for(int i=0;i<=a;i++){
      for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
          abc = 500*i + 100*j + 50*k;
          if(abc == x){
            times++;
          }
        }
      }
    }
    System.out.println(times);
  }
}

Measured memory_bytes: 23252
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {
  val Array(n, s, t) = readLine.trim.split(' ').map(_.toInt)
  val min = ask(s, t)
  val suspects = (1 to n).filterNot(i ⇒ i == s || i == t).map{mid ⇒
    (mid, ask(s, mid), ask(mid, t))
  }.filter{case (i, sm, mt) ⇒ sm + mt == min}.sortBy(_._3).map{case (i, _, mt) ⇒ (i, mt)}
  if (suspects.nonEmpty) {
    val stack = mutable.Stack(suspects.head)
    for (p@(mid, fromStart) ← suspects.tail) {
      val mm = ask(stack.head._1, mid)
      if (fromStart == mm + stack.head._2) {
        stack.push(p)
      }
    }
    println(s"! $s ${stack.map(_._1).mkString(" ")} $t")
  }else {
    println(s"! $s $t")
  }
  def ask(a: Int, b: Int): Int = {
    println(s"? $a $b")
    readInt()
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    def let[A](@inline func: T ⇒ A): A = func(value)
    def also(@inline func: T ⇒ Unit): T = {func(value);value}
    def minOption[A](implicit ev: T ⇒ Iterable[A], ord: Ordering[A]): Option[A] = if (value.isEmpty) None else Some(value.min)
  }
}


Measured memory_bytes: 46104
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    m = set(range(1, n + 1))
    for _ in range(k):
        d = int(input().strip())
        a_l = set(map(int, input().split()))
        m -= a_l
    print(len(m))


if __name__ == '__main__':
    main()


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

typedef long long ll;

const int N = 2e3 + 10;
ll a[N], dp[N][3];

int main()
{
	ll n, x, y;
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++) cin >> a[i];
	//dp[n][1] = abs(a[n] - y); dp[n][2] = abs(x - a[n]);
	for (int i = n; i > 0; i--)
	{
		dp[i][1] = -1e18; dp[i][2] = 1e18;
		ll last_val;
		for (int j = i; j < n; j++)
		{
			dp[i][1] = max(dp[i][1], dp[j + 1][2]);
		}
		if (i == 1) last_val = y;
		else last_val = a[i - 1];
		dp[i][1] = max(dp[i][1], abs(a[n] - last_val));
		for (int j = i; j < n; j++)
		{
			dp[i][2] = min(dp[i][2], dp[j + 1][1]);
		}
		if (i == 1) last_val = x;
		else last_val = a[i - 1];
		dp[i][2] = min(dp[i][2], abs(a[n] - last_val));
	}
	cout << dp[1][1];
}

Measured memory_bytes: 3660
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		int A;
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i=0; i<N; i++) {
			A = in.nextInt();
			if(min > A) {
				min = A;
			}
			if(max < A) {
				max = A;
			}
		}
		
		System.out.println(max - min);
		in.close();
		
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e13;

int N;
long long K;
vector<long long> A;
vector<long long> B;

// 全ての値を X 以下にするまでの最小値
long long Trainin(long long X) {
    long long res = 0;
    for (int i = 0; i < N; i++) {
        long long dis = max(0LL, A[i] * B[i] - X);
        res += (dis + B[i] - 1) / B[i];
    }
    return res;
}

long long Binary_Search(long long ok, long long ng){
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        long long cnt = Trainin(mid);
        if (cnt <= K) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

int main(){
    cin >> N >> K;
    A.resize(N); B.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end());
    
    long long ans = Binary_Search(INF, -1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
using namespace std;

char s[20];

int abs(int x)
{
    if (x > 0) return x;
    return -x;
}
int main()
{
    int cnt, i, j, len;
    int ans = 10000;
    scanf("%s", s);
    len = strlen(s);
    for (i = 0; i < len - 2; ++i)
    {
        cnt = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0';
        if (abs(cnt - 753) < ans) ans = abs(cnt - 753);
    }
    printf("%d", ans);
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
typedef pair<int, int> pii;

void solve() {
    int N;cin>>N;
    int ans = 0;
    while(N>1){
        N=(N+2)/3;
        ans++;
    }
    cout<<ans<<endl;
}

signed main() {
	solve();
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
using namespace std;

int main() {
	int H, W, h, w;
	cin >> H >> W;
	cin >> h >> w;
	cout << H * W - (H * w) - (h * W) + (h * w) << endl;
	return 0;
}

Measured memory_bytes: 256
S = input().rstrip()
N = len(S)


def is_rev(s):
    return tuple(s) == tuple(reversed(s))


if is_rev(S) and is_rev(S[:(N - 1) // 2]) and is_rev(S[(N + 3) // 2 - 1:]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940