akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int main(){
    long long i,j,mx,mn,a,b,c,d,n;
    cin>>n>>a>>b>>c>>d;
    for(i=0;i<n;i++){
        j=n-1-i;
        mx=i*d-j*c;
        mn=i*c-j*d;
        if(a+mx>=b&&a+mn<=b){printf("YES\n");return 0;}
    }
    printf("NO\n");
    return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll f[4005], fi[4005];

void init(int n) {
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[n] = modpow(f[n], MOD - 2);
    for (int i = n; i > 0; i--) {
        fi[i-1] = fi[i] * i % MOD;
    }
}

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    init(n * 2);

    for (int i = 1; i <= K; i++) {
        int x = K - i;
        int y = n - K - (i - 1);
        if (y < 0) {
            cout << 0 << endl;
            continue;
        }
        cout << comb(y + i, i) * comb(x + i - 1, i - 1) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 384
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d", $x);
fscanf(STDIN, "%d", $y);
$money = 0;
for(;$k<$n;$n--) {
  $money += $y;
}

for(;$n>0;$n--) {
  $money += $x;
}

echo $money;

Measured memory_bytes: 3576
#!/usr/bin/env python3
import bisect
n = int(input())
d = sorted(map(int, input().split()))
m1 = d[n // 2 - 1]
m2 = d[n // 2]
r = d[bisect.bisect_left(d, m2)]
l = d[bisect.bisect_left(d, m1)]
print(r - l)


Measured memory_bytes: 14240
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> neighbors(1e5+1);
    rep(i, n) cin >> a[i];
    for(ll i = 0; i < n; i++){
        if(a[i] != 0){
            neighbors[a[i] - 1]++;
        }
        neighbors[a[i]]++;
        neighbors[a[i] + 1]++;
    }
    sort(all(neighbors), greater<ll>());
    cout << neighbors[0];
    cout << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,sol[205],st,dr,x,y;
int ask1(int pos)
{
	cout<<"?"<<" ";
	for(int i=pos;i<=pos+n-1;i++)
		cout<<i<<" ";
	cout<<endl;
	string ans;
	cin>>ans;
	if(ans=="Red")
		return 0;
	else
		return 1;
}
void ask2(int pos,int start)
{
	cout<<"?"<<" ";
	cout<<pos<<" ";
	for(int i=start;i<=start+n-2;i++)
	{
		if(i>2*n)
			cout<<i-2*n<<" ";
		else
			cout<<i<<" ";
	}
	cout<<endl;
	string ans;
	cin>>ans;
	if(ans=="Red")
		sol[pos]=0;
	else
		sol[pos]=1;
}
int main()
{
	cin>>n;
	if(n<=50)
	{
		for(int i=1;i<=n;i++)
		{
			x=ask1(i);
			y=ask1(i+1);
			if(x+y==1)
			{
				st=i+1;
				dr=i+n-1;
				break;
			}
		}
	}
	else
	{
		st=2;
		dr=n+1;
		x=ask1(1);
		while(st<dr)
		{
			int mid=(st+dr)/2;
			y=ask1(mid);
			if(x!=y)
				dr=mid;
			else
				st=mid+1;
		}
		dr=st+n-2;
	}
	for(int i=1;i<=2*n;i++)
	{
		if(st<=i && i<=dr)
				ask2(i,dr+2);
		else
			ask2(i,st);
	}
	cout<<"!"<<" ";
	for(int i=1;i<=2*n;i++)
	{
		if(sol[i])
			cout<<"B";
		else
			cout<<"R";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int a,b,c;cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;


void solve()
{
   ll a,b,c;
   cin>>a>>b>>c;
   swap(a,b);
   swap(a,c);
   cout<<a<<" "<<b<<" "<<c;
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 764
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    input()
    aa=LI()
    print(max(aa)-min(aa))
main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007

using namespace std;

void solve()
{
    int r;
    cin >> r;
    long double circumference;

    circumference = 2 * (M_PI)*r;
    cout << circumference << "";
}

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

    //int t;
    //cin >> t;

    // while (t--)
    solve();

    return 0;
}

Measured memory_bytes: 3800
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	lint K, A, B;
	cin >> K >> A >> B;
	
	lint diff = B - A;
	
	if (diff <= 2 || K < A) {
		cout << K+1 << endl;
	}
	else {
		lint ans = A;
		K -= (A - 1);
		ans += (K / 2) * diff + (K % 2);
		cout << ans << endl;
	}
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
N=int(input())
S=[]
for i in range(N):
    S.append(tuple(map(int,input().split())))
S_new=[]
for j in range(N):
    S_new.append((S[j][0]-S[j][1],S[j][0]+S[j][1]))
S_new.sort(key=lambda x: x[1])
#print(S)
#print(S_new)

count=1
T=S_new[0][1]
for k in range(1,N):
    if S_new[k][0]<T:
        pass
    else:
        count+=1
        T=S_new[k][1]

print(count)




Measured memory_bytes: 31732
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;int i;
    cin>>s;
    int n=s.size();
    for(i=0;i<n;i++){
        if(s[i]!=s[n-1-i]){
            cout<<"No\n";return 0;
        }
    }
    for(i=0;i<n/2;i++){
        if(s[i]!=s[(n/2)-1-i]){
            cout<<"No\n";return 0;
        }
    }
    for(i=(n/2)+1;i<n;i++){
        if(s[i]!=s[n-1-i]){
            cout<<"No\n";
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){ 
 int R[MAX],n;
 
 cin >> n;
 for(int i = 0; i < n; i++) cin >> R[i];
 
 int maxv = -2000000000;
 int minv = R[0];
	
 for(int i = 1; i < n; i++){
 	maxv = max(maxv,R[i]-minv);
 	minv = min(minv,R[i]);
 }
	
 cout << maxv <<endl;

 return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans;
  if(s=="SUN") ans=7;
  if(s=="MON") ans=6;
  if(s=="TUE") ans=5;
  if(s=="WED") ans=4;
  if(s=="THU") ans=3;
  if(s=="FRI") ans=2;
  if(s=="SAT") ans=1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};

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

	int n,k;
	cin >> n >> k;

	ll x[n];
	int nega=0;
	int ind0;
	long long tmp,ans=LINF;
	for(int i=0;i<n;i++){
		cin >> x[i];
	}

	for(int i=0;i<n-k+1;i++){
		ans = min(ans,abs(x[i])+x[i+k-1]-x[i]);
		ans = min(ans,abs(x[i+k-1])+x[i+k-1]-x[i]);
	}
	cout << ans << "\n";

	return 0;
}

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int k=max(a,b);
    if(k>c)cout<<1<<endl;
    else if(c%k==0)cout<<c/k<<endl;
    else cout<<(c/k)+1<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){

  int a[40],i,j,n,ans,h[5]={5,7,5,7,7};
  char str[10];

  while(scanf("%d",&n),n){

    for(i=0;i<n;i++)a[i]=0;

    for(i=0;i<n;i++){
      scanf("%s",str);
      a[i] = strlen(str);
      // printf("%d\n",a[i]);
    }

    
    int sum,count;
    ans=-1;
    
    for(i=0;i<n;i++){
      sum=0;
      count=0;
      for(j=i;j<n;j++){
	sum+=a[j];
	//printf("%d\n",sum);
	if(sum==h[count]){
	  count++;
	  sum=0;
	}else if(sum>h[count]){
	  break;
	}
	if(count==5){
	  ans=i;
	  break;
	}
      }
      if(ans != -1)break;
    }
    
     printf("%d\n",ans+1);
    
  }
  
  return 0;
  
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=2e5+7;
int points[N];
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	string s; cin>>s;
	for(int i=0; i<n; i++) {
		if(s[i]=='#') {

		}
		else{
			points[i+1]++;
		}
	}
	int ans=INT_MAX;
	for(int i=1; i<=n; i++) {
		points[i]+=points[i-1];
	}

	for(int i=0; i<=n; i++) {
		int left=i-points[i];
		int right=points[n]-points[i];
		ans=min(ans,right+left);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1300
def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


n = int(input())
a = tuple(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * 60
for i in range(n):
    r = a[i]
    for j in range(60):
        if r & 1:
            cnt[j] += 1
        r >>= 1

ans = 0
for i in range(60):
    ans += powmod(2, i, mod) * cnt[i] * (n-cnt[i])
    ans %= mod
print(ans)

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

typedef long long ll;
typedef pair<int,ll> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;
int main() {
	ll n;
	cin>>n;

	ll a[50]={};
	for(int i=0;i<n;++i)cin>>a[i];
	ll k=0;
	bool flg=true;
	while(flg){
		flg=false;
		for(int i=0;i<n;++i){
			if(a[i]>=n){
				flg=true;
				k+=a[i]/n;
				for(int j=0;j<n;++j){
					if(i!=j)a[j]+=a[i]/n;
				}
				a[i]%=n;
			}
		}
	}
	cout<<k<<endl;

	return 0;
}


Measured memory_bytes: 256
n,a,b,c,d=map(int,input().split())
s="0"+input()
x=s[a:c+1]
y=s[b:d+1]
if "##" in s[a:c+1]:
    print("No")
    exit()

if "##" in s[b:d+1]:
    print("No")
    exit()

if c>d:
    if not "..." in s[b-1:d+2]:
        print("No")
        exit()
    
print("Yes")

Measured memory_bytes: 9564
#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする

n=[int(x) for x in list(input())]#それぞれの桁にアクセスするためにイテラブルにする
k=len(n)

#それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意
dp=[[-1,-1] for _ in range(k)]
dp[0]=[min(1+(10-n[0]),n[0]),min(1+(10-n[0]-1),n[0]+1)]
for i in range(1,k):
    dp[i]=[min(dp[i-1][1]+(10-n[i]),dp[i-1][0]+n[i]),min(dp[i-1][1]+(10-n[i]-1),dp[i-1][0]+n[i]+1)]
print(dp[k-1][0])

Measured memory_bytes: 215296
#include <math.h>

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long double A, B, H, M;
  cin >> A >> B >> H >> M;

  long double Ax, Ay, Bx, By;
  Ax = A * cos(M_PI * ((360 * H / 12) + (30 * M / 60)) / 180);
  Ay = A * sin(M_PI * ((360 * H / 12) + (30 * M / 60)) / 180);
  Bx = B * cos(M_PI * 360 * M / 60 / 180);
  By = B * sin(M_PI * 360 * M / 60 / 180);

  long double distance;
  distance = sqrt(pow(Ax - Bx, 2.0) + pow(Ay - By, 2.0));
  printf("%.20Lf\n", distance);
  return 0;
}


Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

bool judge(int x) {
	string str = to_string(x);
	REP(i, str.size() / 2) {
		if (str[i] != str[str.size() - 1 - i]) return false;
	}
	return true;
}

int main() {
	int A, B;
	cin >> A >> B;
	
	int ans = 0;
	FOR(i, A, B + 1) if (judge(i)) ans++;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Char8 as BS
import Data.Char
import Debug.Trace
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector.Unboxed as UV

main = do
    n <- UV.head . UV.unfoldr BS.readInt <$> BS.getLine
    a <- UV.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    b <- UV.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    -- let l = UV.length $ UV.filter not $ UV.zipWith (==) p (UV.fromList [1..n])
    -- putStrLn $ if l <= 2 then "YES" else "NO"
    print $ sub3 0 a b

sub3 :: Int -> UV.Vector Int -> UV.Vector Int -> Int
sub3 m0 a b
    | b == UV.empty = 0
    | otherwise     = minX + sub3 m (UV.tail a) (UV.tail b)
    where t1 = UV.head a - m0
          t2 = UV.last $ UV.take 2 a
          r = UV.head b
          minX = min (t1 + t2) r
          m | r <= t1        = 0
             | r <= (t1 + t2) = r - t1
             | otherwise      = t2


Measured memory_bytes: 9340
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=1e9+7;
int main()
{
    ll n,m;
    cin>>n>>m;
    ll cnt=2*n;
    if(cnt>=m)
        printf("%lld\n",m/2);
    else
        printf("%lld\n",n+(m-cnt)/4);
}


Measured memory_bytes: 256
import math

A, B, K = map(int,input().split())
ct = 0
if K % 2 == 0:
    while(ct < K / 2):
        B += math.floor(A / 2)
        A = math.floor(A / 2)

        A += math.floor(B / 2)
        B = math.floor(B / 2)
        ct += 1
else:
    B += math.floor(A / 2)
    A = math.floor(A / 2)
    while(ct < ((K-1) / 2)):
        A += math.floor(B / 2)
        B = math.floor(B / 2)
        B += math.floor(A / 2)
        A = math.floor(A / 2)
        ct += 1
print(A, B)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] prev = new int[3];
        int[] next = new int[3];
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            next[0] = a+Math.max(prev[1],prev[2]);
            next[1] = b+Math.max(prev[0],prev[2]);
            next[2] = c+Math.max(prev[0],prev[1]);
            int[] tmp = next;
            next = prev;
            prev = tmp;
        }
        System.out.println(Math.max(prev[0],Math.max(prev[1],prev[2])));        
    }
}


Measured memory_bytes: 59024
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int a[N][5];
int dp[N][5];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)   scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    for(int i=n;i>0;i--){
        dp[i][0] = max(dp[i+1][1],dp[i+1][2])+a[i][0];
        dp[i][1] = max(dp[i+1][0],dp[i+1][2])+a[i][1];
        dp[i][2] = max(dp[i+1][0],dp[i+1][1])+a[i][2];
    }
    printf("%d\n",max(dp[1][0],max(dp[1][1],dp[1][2])));
    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007;
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define tz(x) __builtin_ctz(x)
#define csb(x) __builtin_popcount(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;


int32_t main(){
   
string s;cin>>s;
sort(all(s));
if(s[0]==s[2])cout<<"No";
else cout<<"Yes";

}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 405;
const ll mod = 1000000007;
const double PI = acos(-1.0);
 
int n;
int val[maxn];
 
void solve()
{
	int res = 0;
	int i, j, k;
	for(i = 1;i <= 2*n; i++)
	{
		sa(val[i]);
	}
	sort(val + 1, val + 2*n + 1);
	for (i = 1; i <= 2 * n - 1; i = i + 2)
	{
		res += val[i];
	}
	printf("%d\n", res);
}
int main()
{
	while (scanf("%d", &n) != EOF)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define FASTNIBBA   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define lbnd        lower_bound
#define ubnd        upper_bound
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
#define endl        '\n'
const ld PI = acos(-1.0);

void solve()
{
   ll n,p; cin>>n>>p;
   ll ans=1;
   if(n==1 || p==1) {cout<<p; return;}
   ll x=p;
   for(ll i=2; i*i<=p; i++)
   {
     ll cnt=0;
     while(x%i==0)
     {
       cnt++;
       x/=i;
     }
     if(cnt>=n)
     {
       ll r=cnt/n;
       ans*=pow(i,r);
     }
   }
   cout<<ans;   
}
int main()
{
    FASTNIBBA;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
import sys

S = sys.stdin.readline().strip()

N = 2019
L = len(S)
curr = 0
seen = {}
INV = 210
seen[curr] = 1
for i in range(L):
    curr = (curr * 10 + int(S[i])) % N
    t = (curr * pow(10, L-i, N)) %N
    if t not in seen: seen[t] = 0
    seen[t] += 1

res = 0
for i in range(N):
    if i not in seen: continue
    t = seen[i]
    res += t * (t-1)//2
print(res)

Measured memory_bytes: 9252
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long n,a,b,f,m,i;
cin>>n;
cin>>f;
for(i=0;i<f;i++){
	cin>>a>>b;
	if(a>b){
	m=a;
	a=b;
	b=m;
	}
	m=min(a,n+1-b);
	m=m%3;
	if(m==0)m=3;
	cout<<m<<endl;
}
return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <typename T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const vector<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
void ce(void){cerr << '\n';}
template <typename T>
void ce(const T n){cerr << n << '\n';}
template <typename T>
void cesp(const T n){cerr << n << ' ';}
template <typename T>
void ce(initializer_list<T> v){for(T i : v) cesp(i); ce();}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

ll h, w, k;
VecS board;
Vec2<ll> dist;
ll dx[4] = {1, -1, 0, 0};
ll dy[4] = {0, 0, 1, -1};

bool in_board(ll x, ll y){
	return x >= 0 && x < h && y >= 0 && y < w && board[x][y] == '.';
}

void bfs(ll fx, ll fy){
	dist[fx][fy] = 0;
	queue<P> que;
	que.push({fx, fy});
	while(!que.empty()){
		P p = que.front(); que.pop();
		// co(p);
		ll a = p.first, b = p.second;
		rep(i, 4){
			ll x = a, y = b;
			repn(j, k){
				x += dx[i], y += dy[i];
				// co({x, y});
				if(in_board(x, y)){
					if(chmin(dist[x][y], dist[a][b] + 1)){
						que.push({x, y});
					}else if(dist[x][y] == dist[a][b] + 1){
						continue;
					} else break;
				} else break;
			}
		}
	}
}

int main(void){
	cin >> h >> w >> k;
	dist.resize(h);
	rep(i, h) dist[i].resize(w, LINF);
	ll x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1, --y1, --x2, --y2;
	board.resize(h);
	rep(i, h) cin >> board[i];

	bfs(x1, y1);

	ll ans = dist[x2][y2];
	/*
	rep(i, h){
		rep(j, w) cosp(dist[i][j]);
		co();
	}
	*/
	if(ans == LINF) ans = -1;
	co(ans);

	return 0;
}


Measured memory_bytes: 14328
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print(0)


Measured memory_bytes: 37772
n = int(input())
s = input()

if n % 2 == 1:
    print('No')
else:
    cnt = 0
    for i in range(0, n // 2):
        cnt += (s[i] == s[i + n // 2])
    if(cnt == n // 2):
        print('Yes')
    else:
        print('No')




Measured memory_bytes: 9032
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt(); 
		int c = scan.nextInt(); 
		
		System.out.println(c + " " + a + " " + b);
	}
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    bool isPrime[55556];
    for(int i=1;i<=55555;i++){
        isPrime[i] = true;
    }
    isPrime[1] = false;
    for(int i=2;i<=55555;i++){
        if(isPrime[i]){
            for(int j=2;j*i<=55555;j++) isPrime[i*j] = false;
        }
    }
    set<int> prime;
    for(int i=1;i<=55555;i++){
        if(isPrime[i]) prime.insert(i);
    }

    int count = 0;
    for(auto it=prime.begin();it!=prime.end();it++){
        if(*it % 5 == 1){
            count++;
            cout << *it << " \n"[count==N];
        }
        if(count == N) return 0;
    }
    return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import heapq
import fractions
a,b=map(int,input().split())

if a%2==0 and b%2==1:
        if (b-a+1)%4==0:
                print(0)
        else:
                print(1)
elif a%2==0 and b%2==0:
        if (b-1-a+1)%4==0:
                print(b)
        else:
                print(1^b)
elif a%2==1 and b%2==1:
        if (b-1-a+1)%4==0:
                print(a)
        else:
                print(1^a)
elif a%2==1 and b%2==0:
        if (b-1-a)%4==0:
                print(a^b)
        else:
                print(a^b^1)



Measured memory_bytes: 5044
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <tuple>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 100000
#define MAX_M 200000
using namespace std;

class edge{
  public:
    int u, v, c;
    edge(int u, int v, int c): u(u), v(v), c(c){}
    edge(){}
};

vector< edge > graph[MAX_N];

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

  int n, m;
  cin >> n >> m;
  int l[MAX_M], r[MAX_M], d[MAX_M];
  for(int i = 0; i < m; i++){
    cin >> l[i] >> r[i] >> d[i];
    --l[i]; --r[i];
  }

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

  for(int i = 0; i < m; i++){
    graph[l[i]].push_back(edge(l[i], r[i], d[i]));
  }

  int ind[n];
  fill(ind, ind + n, 0);
  for(int i = 0; i < m; i++){
    ind[r[i]]++;
  }

  set< int > zero;
  for(int v = 0; v < n; v++){
    if(ind[v] == 0) zero.insert(v);
  }

  int x[n];
  fill(x, x + n, -1);
  while(!zero.empty()){
    set< int > zero1;
    for(int v: zero){
      if(x[v] == -1) x[v] = 0;
      for(edge e: graph[v]){
        int w = e.v;
        x[w] = x[v] + e.c;
        ind[w]--;
        if(ind[w] == 0) zero1.insert(w);
      }
    }
    zero = zero1;
  }

  bool exist = true;
  for(int i = 0; i < m; i++){
    if(x[r[i]] - x[l[i]] != d[i]){
      exist = false; break;
    }
  }

  if(exist) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

void solve(const vector<int> &a) {
  int ans = 0;
  int n = a.size();
  REP(i, n) ans += abs(a[i]);

  cout << ans << endl;

  int l = a[0];
  int r = a.back();

  int i = 1;
  while (a[i] < 0) {
    cout << r << " " << a[i] << endl;
    r -= a[i];
    i++;
  }
  int j = a.size() - 2;
  while (a[j] > 0) {
    cout << l << " " << a[j] << endl;
    l -= a[j];
    j--;
  }
  // cout << " i j " << i << " " << j << endl;
  while (i <= j) {
    cout << r << " " << 0 << endl;
    i++;
  }
  cout << r << " " << l << endl;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n;
  cin >> n;
  vi a(n);
  cin >> a;

  sort(all(a));

  if (a[0] <= 0 and a.back() >= 0) {
    solve(a);
  } else if (a[0] > 0) {
    int a0 = a[0];
    int a1 = a[1];

    int x = a[0] - a[1];
    a.erase(a.begin());
    a[0] = x;
    // REP(i, a.size()) cout << i << " -> " << a[i] << endl;
    int ans = 0;
    int n = a.size();
    REP(i, n) ans += abs(a[i]);

    cout << ans << endl;

    cout << a0 << " " << a1 << endl;
    int l = a[0];
    int r = a.back();

    int i = 1;
    while (a[i] < 0) {
      cout << r << " " << a[i] << endl;
      r -= a[i];
      i++;
    }
    int j = a.size() - 2;
    while (a[j] > 0) {
      cout << l << " " << a[j] << endl;
      l -= a[j];
      j--;
    }
    // cout << " i j " << i << " " << j << endl;
    while (i <= j) {
      cout << r << " " << 0 << endl;
      i++;
    }
    cout << r << " " << l << endl;
  } else {
    int a0 = a.back();
    int a1 = a[a.size() - 2];

    int x = a.back() - a[a.size() - 2];
    a.erase(a.end() - 1);
    a[a.size() - 1] = x;
    int ans = 0;
    int n = a.size();
    REP(i, n) ans += abs(a[i]);

    cout << ans << endl;
    cout << a0 << " " << a1 << endl;

    int l = a[0];
    int r = a.back();

    int i = 1;
    while (a[i] < 0) {
      cout << r << " " << a[i] << endl;
      r -= a[i];
      i++;
    }
    int j = a.size() - 2;
    while (a[j] > 0) {
      cout << l << " " << a[j] << endl;
      l -= a[j];
      j--;
    }
    // cout << " i j " << i << " " << j << endl;
    while (i <= j) {
      cout << r << " " << 0 << endl;
      i++;
    }
    cout << r << " " << l << endl;
  }

  return 0;
}


Measured memory_bytes: 2304
def f(n, d, points):
  result = 0
  for val in points:
    temp = val[0] * val[0] + val[1] * val[1]
    if d*d >= temp:
      result += 1
  return result

if __name__ == "__main__":
  nd = list(map(int, input().split()))
  n = nd[0]
  d = nd[1]
  points = [list(map(int, input().split())) for _ in range(n)]
  print(f(n, d, points))

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

int n, rev, t, f;
string s;
char c;
deque<char> dq;

int main() {
	int i;
	cin >> s;
	for(i=0; i<s.size(); i++) dq.push_back(s[i]);
	cin >> n;
	while(n--) {
		scanf("%d", &t);
		if(t==1)
			rev ^= 1;
		else {
			cin >> f >> c;
			f--;
			if(rev ^ f)
				dq.push_back(c);
			else
				dq.push_front(c);
		}
	}
	if(rev) {
		while(!dq.empty()) {
			c = dq.back(); dq.pop_back();
			printf("%c", c);
		}
	} else {
		while(!dq.empty()) {
			c = dq.front(); dq.pop_front();
			printf("%c", c);
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int N,K;
ll w[100001],d[100001];
ll ichinum(ll ichimin,ll ichimax){
	if(ichimin+1==ichimax) return ichimax;
	ll ichimid=(ichimin+ichimax)/2;
	ll hanacount=0;
	rep(i,N){
		if(w[i]<=ichimid) hanacount+=(ichimid-w[i])/d[i]+1;
	}
	if(hanacount>=K) return ichinum(ichimin,ichimid);
	else return ichinum(ichimid,ichimax);
}
int main(){
	scan(N);scan(K);
	rep(i,N){
		scan(w[i]);scan(d[i]);
	}
	prin(ichinum(0,INFl*2));
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>

int main(void){
	
	int S; //時間入力
	
	scanf("%d",&S);
	
	int h,m,s;
	
	h = S/3600;
	m = (S%3600)/60;
	s = S%3600%60;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;

}


Measured memory_bytes: 2144
package main

import (
	"fmt"
)

func main(){
	var max, max_i, ans int
	var abc = make([]int, 3)
	fmt.Scan(&abc[0], &abc[1], &abc[2])
	for i:=0; i<3; i++{
		if abc[i] > max{
			max = abc[i]
			max_i = i
		}
	}
	for i:=0; i<3; i++{
		if i == max_i{
			ans += 10*abc[i]
		} else {
			ans += abc[i]
		}
	}
	fmt.Println(ans)
}

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

int main() {
    long n, t, a, ans, h, temp, min = LONG_MAX / 2;
    cin >> n >> t >> a;
    a *= 1000;
    t *= 1000;
    rep(i, n) {
        cin >> h;
        temp = t - 6 * h;
        if(abs(min - a) > abs(temp - a)) {
            min = temp;
            ans = i + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#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>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int x;
vector<bool> expo;
void solve() {
	cin >> x;
	expo.resize(x + 1);
	expo[1] = true;
	for (int i = 2; i <= x; ++i) {
		int num = i * i;
		while(num <= x) {
			expo[num] = true;
			num *= i;
		}
	}
	for (int i = x; i >= 1; --i) {
		if (expo[i]) {
			cout << i << endl;
			return;
		}
	}
	return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
	solve();
}

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

string st;
int len;

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	cin>>st;
}

int main(){
	init();
	len=st.size();
	st='?'+st;
	for(int i=1;i<=len;++i)
	if(st[i]=='1')
	putchar('9');
	else putchar('1');
	puts("");
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}
bool cmp(pair<lli, lli> left, pair<lli, lli> right) {
	if (left.first != right.first)return left.first < right.first;
	else return left.second < right.second;
}

int main() {
	lli n, d, ans = 1;
	cin >> n;
	d = (lli)sqrt(n);
	for (int i = 2; i <= d; i++) {
		lli tmp = 1;
		while (tmp * i <= n)tmp *= i;
		ans = max(tmp, ans);
	}
	cout << ans;

}


Measured memory_bytes: 256
import sys

H, N = map(int, input().split())
ABs = [(0,0)]

for _ in range(N):
  a,b = map(int, input().split())
  ABs.append((a,b))
  
memo = [[sys.maxsize]*(H+1) for _ in range(N+1)]
memo[0][H] = 0

for i in range(1,N+1):
  for j in range(H,0,-1):
    if j + ABs[i][0] <= H:
      memo[i][j] = min(memo[i-1][j], memo[i][j+ ABs[i][0]] + ABs[i][1])
    else:
      memo[i][j] = min(memo[i][j], memo[i-1][j])
    if j - ABs[i][0] <= 0:
      memo[i][0] = min(memo[i-1][0], memo[i][0], memo[i][j]+ABs[i][1])
      
print(memo[N][0])

Measured memory_bytes: 152776
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const int maxn=2E5+5;
int n,q;
ll ans;
bool okA[maxn],okB[maxn];
struct seg
{
	int t[maxn*4];
	void build(int l,int r,int num)
	{
		if(l==r)
		{
			if(l==n)
				t[num]=n;
			return;
		}
		int mid=(l+r)>>1;
		build(l,mid,num<<1),build(mid+1,r,num<<1|1);
		t[num]=max(t[num<<1],t[num<<1|1]);
	}
	int ask(int l,int r,int x,int num)
	{
		if(l==r)
			return l;
		int mid=(l+r)>>1;
		if(t[num<<1]>=x)
			return ask(l,mid,x,num<<1);
		return ask(mid+1,r,x,num<<1|1);
	}
	void change(int l,int r,int pos,int x,int num)
	{
		if(l==r)
		{
			t[num]=x;
			return;
		}
		int mid=(l+r)>>1;
		if(pos<=mid)
			change(l,mid,pos,x,num<<1);
		else
			change(mid+1,r,pos,x,num<<1|1);
		t[num]=max(t[num<<1],t[num<<1|1]);
	}
}A,B;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	n-=1;
	A.build(1,n,1);
	B.build(1,n,1);
	while(q--)
	{
		int opt,x;
		cin>>opt>>x;
		x-=1;
		if(opt==1)
		{
			if(okB[x])
				continue;
			int y=A.ask(1,n,x,1)-1;
			ans+=y;
			B.change(1,n,x,y,1);
			okB[x]=1;
		}
		else
		{
			if(okA[x])
				continue;
			int y=B.ask(1,n,x,1)-1;
			ans+=y;
			A.change(1,n,x,y,1);
			okA[x]=1;
		}
	}
	cout<<(ll)(n-1)*(n-1)-ans<<endl;
	return 0;
}


Measured memory_bytes: 8188
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True



def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, t = LMIIS()
    ab = XLMIIS(n)
    ab.sort()

    dp1 = [[0]*t for _ in range(n+1)]
    for i in range(1, n+1):
        for j in range(1, t):
            if j < ab[i-1][0]:
                dp1[i][j] = dp1[i-1][j]
            else:
                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i-1][0]] + ab[i-1][1])

    ans = 0
    for i in range(n):
        ans = max(ans, dp1[i][t-1] + ab[i][1])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 114908
N = int(input())
list_n = list(map(int, input().split()))
flag = 0
for i in range(N):
  if list_n[i] % 2 == 0:
    if (list_n[i] % 3 != 0) and (list_n[i] % 5 != 0):
      print('DENIED')
      flag = 1
      break
    else:
      continue
if flag == 0:
  print('APPROVED')

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

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

	long long ans;
	ans = n / (a + b) * a;
	long long rem;
	rem = n % (a + b);

	ans += min(a,rem);

	cout << ans << endl;

}


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

y, m, d=map(int, input().split('/'))
d1=date(y, m, d)
d2=date(2019, 4, 30)

if d1 <= d2:
    print('Heisei')
else:
    print('TBD')


Measured memory_bytes: 5884
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef long double ld;


int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(false);

    #ifdef DBG
        freopen("in", "r", stdin);
    #endif
    int a, b;
    string s;
    cin>>a>>b>>s;
    for(int i = 0; i < a+b+1; i++){
        if(i == a){
            if(s[i] == '-') continue;
            else{
                cout<<"No";
                return 0;
            }
        }
        else if(s[i] <= '9' and s[i] >= '0') continue;
        else{
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int n, p[200005], in[200005], ta, tb;
set< int > s[200005];
vector< int > x, y;
bool v[200005];
 
void go(int a) {
	v[a] = 1;
	for (int i = 0; ; i++)
		if (s[a].find(i) == s[a].end()) {
			s[p[a]].insert(i);
			break;
		}
	in[p[a]]--;
	if (in[p[a]] == 0)
		go(p[a]);
}
 
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", p + i);
		in[p[i]]++;
	}
	for (int i = 1; i <= n; i++)
		if (!in[i] && !v[i])
			go(i);
	for (int i = 1; i <= n; i++)
		if (!v[i]) {
			ta = i;
			while (1) {
				x.push_back(ta);
				if (p[ta] == i)
					break;
				ta = p[ta];
			}
			break;
		}
	for (int i = 0; y.size() < 2; i++)
		if (s[x[0]].find(i) == s[x[0]].end())
			y.push_back(i);
	for (int i = 0; i < 2; i++) {
		in[0] = y[i];
		for (int j = 1; j < x.size(); j++)
			for (int k = 0; ; k++)
				if (in[j - 1] != k && s[x[j]].find(k) == s[x[j]].end()) {
					in[j] = k;
					break;
				}
		if (i == 0 && in[x.size() - 1] != y[0]) {
			printf("POSSIBLE\n");
			return 0;
		}
		if (i == 1 && in[x.size() - 1] == y[0]) {
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 19968
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

typedef long long LL;
const int N=20005;

LL a[2][N],f[2][N];

int main(void) {
	int n; scanf("%d",&n);
	rep(i,1,2) rep(j,1,n) scanf("%lld",&a[i][j]);
	rep(i,1,2) rep(j,1,n) f[i][j]=std:: max(f[i-1][j],f[i][j-1])+a[i][j];
	printf("%lld\n", f[2][n]);
	return 0;
}

Measured memory_bytes: 128
<?php
list($n,$k) = explode(" ", trim(fgets(STDIN)));
$ans = $n;
$check_array = array_fill(0, $n, false);
for($i=0; $i<$k; $i++){
	$d =  trim(fgets(STDIN));
	$nums = explode(" ", trim(fgets(STDIN)));
	foreach ($nums as $num) {
		if($check_array[$num-1] === false){
			$ans -=1;
			$check_array[$num-1] = true;
		}
	}
}


echo $ans . "\n";

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

int main() {
  int N, M; cin >> N >> M;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  int sum = 0, count = 0;
  for (int i = 0; i < N; i++) sum += A[i];
  int L = (sum-1)/(4*M)+1;
  for (int i = 0; i < N; i++) {
    if (A[i] >= L) count++;
  }
  if (count >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
if len(str(A)) > len(str(B)):
    print('GREATER')
elif len(str(A)) < len(str(B)):
    print('LESS')
elif A == B:
    print('EQUAL')
else:
    a = [int(i) for i in str(A)]
    b = [int(j) for j in str(B)]
    for i in range(len(str(A))):
        if a[i] > b[i]:
            print('GREATER')
            break
        elif a[i] < b[i]:
            print('LESS')
            break

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

int main(){
    ll a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k; cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

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

int main() {
    int n=0,x=0;
    while(1){
        int ans=0;
        cin >> n >> x;
        if(!n) break;
        for(int i=1;i<=n;++i)
            for(int j=1+i;j<=n;++j)
                for(int k=1+j;k<=n;++k)
                    if(i+j+k==x) ++ans;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3092
n = int(input())
a = list(map(int, input().split()))
cnt = 0
sum = 0
l = []
for i in a:
    sum += i
    l.append(sum)
l2 = [sum - x for x in l]
num = 0
loc = 0
for i in range(n):
    if i == 0:
        num = abs(l[i] - l2[i])
    else:
        if num > abs(l[i] - l2[i]):
            num = abs(l[i] - l2[i])
            loc = i


print(num)


Measured memory_bytes: 29352
#include<bits/stdc++.h>
using namespace std;
#define D(x)    cout << #x " = " <<(x) << endl
#define MAX     100000
typedef long long int LL;


int main()
{
    //freopen("in.txt", "r", stdin);

    int n, k;
    cin >> n >> k;
    cout << (n - 1) / (k - 1) + (bool) ((n - 1) % (k - 1)) << endl;

    return 0;
}



Measured memory_bytes: 256