akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <queue>
#include <cstring>

using namespace std;

class data{
public:
	int num,t;
	data(int n,int tt){
		num=n;
		t=tt;
	}
};

int n;
int fie[17];
int wait[100];

int enter(int x){
	int f=0,cnt=0;
	for(int i=0;i<17;i++){
		if(fie[i]==-1){
			if(cnt==0)f=i;
			cnt++;
			if(cnt==x)return f;
		}else cnt=0;
	}
	return -1;
}

int main(void){
	queue<data> que;
	memset(fie,-1,sizeof(fie));
	memset(wait,-1,sizeof(wait));
	int i=0;
	while(wait[99]==-1){
		if(i%5==0 && i<500){
			que.push(data(i/5,i));
		}
		for(int j=0;j<17;j++){
			if(fie[j]==i)fie[j]=-1;
		}
		while(1){
			if(que.empty())break;
			data next=que.front();
			int number;
			if(next.num%5==1)number=5;
			else number=2;
			int from=enter(number);
			if(from>=0){
				wait[next.num]=i-next.t;
				for(int j=0;j<number;j++){
					fie[from+j]=i+17*(next.num%2)+3*(next.num%3)+19;
				}
				que.pop();
			}else break;
		}
		i++;
	}
	while(~scanf("%d",&n)){
		printf("%d\n",wait[n]);
	}
	return 0;
}

Measured memory_bytes: 1032
N = gets.to_i
T,A = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)

min_d = 100000
min_di = 0
N.times do |i|
  t = T-(H[i]*0.006)
  if min_d > (A-t).abs
    min_d = (A-t).abs
    min_di = i
  end
end
puts min_di+1

Measured memory_bytes: 1788
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  cout << s << endl;
	return 0;
}



Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {
			double ax, ay, bx, by, cx, cy, dx, dy;
			String points[] = line.split(" ");

			ax = Double.parseDouble(points[0]);
			ay = Double.parseDouble(points[1]);
			bx = Double.parseDouble(points[2]);
			by = Double.parseDouble(points[3]);
			cx = Double.parseDouble(points[4]);
			cy = Double.parseDouble(points[5]);
			dx = Double.parseDouble(points[6]);
			dy = Double.parseDouble(points[7]);

			if (ax == bx && cy == dy) {
				System.out.println("YES");
			} else if (ay == by && cx == dx) {
				System.out.println("YES");
			} else if ((ay - by) * (cy - dy) * -1 == (ax - bx) * (cx - dx)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 17140
#include <bits/stdc++.h>
   
  #define f(i,a,b) for( ll i = a; i < b ; i++ )
  #define af(i,a,b) for( ll i = a; i >= b ; i--)
  #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
  #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
  #define ones(x) (ll) __builtin_popcount(x)
  #define fs first
  #define sc second
  #define pb push_back
  #define po pop_back
  #define mp make_pair  
  #define sz(a) (ll) a.size()
  #define all(a) a.begin(), a.end()
  #define sor(a) sort( a.begin(), a.end() )
  #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
  #define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
  #define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
  #define PI 3.1415926535
  using namespace std;
  typedef long long ll;
  typedef long double ld; 
  typedef pair<ll,ll> ii ;
  typedef vector<ll>  vi ;
  typedef vector<ii> vii ;
  const ll mod = 1e9+7;
  const ll MAX = 21;
  const ll inf = 1e18+7;

  ll n;
  ll a[MAX][MAX];
  ll dp[MAX][1<<MAX];
  ll DP(ll u,ll m){
    if(u == n) return 1;
    ll &ans = dp[u][m];
    if(ans!=-1) return ans;
    ans = 0;
    f(i,0,n){
      if(a[u][i] && (m>>i)&1) {ans = (ans+DP(u+1,m&(~(1 << i))))%mod;}
    }
    return ans;
  }

  int main(){
    fastio;
    cin>>n;
    f(i,0,n){ 
      f(j,0,n) cin>>a[i][j];
    }
    f(i,0,MAX){
      f(j,0,(1<<MAX)) dp[i][j]=-1;
    }
    cout<<DP(0,(1<<n)-1)<<"\n";
    return 0; 
  }

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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int h, m, a, b, ans = 0;
  double t;
  cin >> a >> b >> h >> m;
  //vector<int> v(n), c(n);
  t = abs(m * 6 - h * 30 - m * 0.5);
  printf("%.12lf\n", sqrt(a * a + b * b - 2 * a * b * cos(t * 3.14159265359 / 180)));
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
int a[7]={0,105,135,165,189,195,0x7fffffff};
int n;
int main()
{
//    freopen("105.in","r",stdin);
//    freopen("105.out","w",stdout);
    scanf("%d",&n);
    for(register int i=1;i<=6;i++)
        if(n<a[i])
        {
            printf("%d\n",i-1);
            exit(0);
        }
    return 0;
}

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


signed main() {
  int N, P;
  cin >> N >> P;
  
  if( N == 1 ){
    cout << P << endl;
    return 0;
  }
  
  int A = P;
  int ans = 1;
  for( int i = 2; i <= sqrt(P); i++ ){
    int cnt = 0;
    while( true ){
      if( A % i != 0 ){
        break;
      }
      A /= i;
      cnt++;
      if( cnt == N ){
        ans *= i;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
    
    
}




Measured memory_bytes: 256
l = int(input())
s = input()
h = l // 2
if l % 2 == 1:
  print("No")
else:
  flag = True
  for i in range(0, h):
    if s[i] != s[i + h]:
      flag = False
      break
  if flag:
    print("Yes")
  else:
    print("No")

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

int main(){
    int n,k;
    cin>>n>>k;
    long long ans=0;

    if(k==0) {
        ans=(long long)n*n;
        cout<<ans<<endl;
        return 0;
    }

    for(int i=k+1;i<=n;i++){
        ans+=n/i*(i-k);
        ans+=max(0,n%i-k+1);
        //cerr<<i<<" "<<ans<<endl;
    }
    
    cout<<ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll	long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
int gcd(int a, int b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
int invertBits(int num) 
{  
    int x = log2(num) + 1; 
    for (int i = 0; i < x; i++)  
       num = (num ^ (1 << i));  
   
    return num; 
} 
///////////////////////////////////////////////////////////////////////////////////////////////////////////
class jobs
{
	public:
	ll int a;
	ll int b;	
};
bool cmp(jobs f,jobs s)
{
	if(f.b<s.b)
	{
		return true;
	}
	else if(f.b==s.b)
	{
		if(f.a>s.a)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
int main()
{
	ll int n;
	cin>>n;
	ll int i;
	jobs j[n];
	for(i=0;i<n;i++)
	{
		cin>>j[i].a>>j[i].b;
	}
	sort(j,j+n,cmp);
	ll int t=0;
	for(i=0;i<n;i++)
	{
		t=t+j[i].a;
		if(t>j[i].b)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3328
use proconio::input;
use proconio::marker::Chars;

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

    let iv: Vec<usize> = s
        .iter()
        .map(|&c| match c {
            'R' => 0,
            'G' => 1,
            'B' => 2,
            _ => unreachable!(),
        })
        .collect();
    let mut cv = vec![0_usize; 3];
    for &i in iv.iter() {
        cv[i] += 1;
    }
    // (全体) R の個数 * G の個数 * B の個数
    let u = cv.iter().fold(1_usize, |acc, &c| acc * c);
    // 全体から部分 j - i = k - j を取り除く (j - i != k - j を求める)
    let mut a = 0;
    for i in 0..n {
        for j in i + 1..n {
            let k = 2 * j - i;
            if k < n && (iv[i] != iv[j]) && (iv[i] != iv[k]) && (iv[j] != iv[k]) {
                a += 1;
            }
        }
    }
    let ans = u - a;
    println!("{}", ans);
}


Measured memory_bytes: 2164
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for a_child in range(0, a + 1):
    x_child = x - 500 * a_child
    for b_child in range(0, b + 1):
        x_child_child = x_child - 100 * b_child
        for c_child in range(0, c + 1):
            x_child_child_child = x_child_child - 50 * c_child
            if x_child_child_child == 0:
                count += 1
                # print(a_child,b_child,c_child)
            
print(count)

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
e = m.times.map{gets.split.map(&:to_i)}

d = Array.new(n + 1){Array.new(n + 1, 10 ** 9)}
1.upto(n){|i| d[i][i] = 0}
e.each{|a, b, c| d[a][b] = d[b][a] = c}

1.upto(n) do |k|
  1.upto(n) do |i|
    1.upto(n) do |j|
      d[i][j] = d[i][k] + d[k][j] if d[i][j] > d[i][k] + d[k][j]
    end
  end
end

s = 0
e.each do |a, b, c|
  s += 1 if c > d[a][b]
end

p s


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

int n, s[300004];
string a;

int sum(int x, int y) {
	if (x>y) return 0;
	if (x) return s[y] - s[x-1];
	else return s[y];
}

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

	for (int i=0; i<n; i++) {
		s[i] = (a[i] == 'W');
		if (i) s[i] += s[i-1];
	}

	int ans = 1e8;
	for (int i=0; i<n; i++) {
		ans = min(ans, sum(0, i-1) + (n-i-1) - sum(i+1, n-1));
	}

	cout << ans;
}


Measured memory_bytes: 1796
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#define fl(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define pob pop_back
#define int long long int
#define ff first
#define ss second
#define pi 3.1415926535898
#define vi vector<int>
#define mi map<int,int>
#define umi unordered_map<int,int>
#define endl "\n"
#define w(x) int x; cin>>x; while(x--)
#define db(x) cout<<(#x)<<" "<<(x)<<"\n";
#define ios ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;
//using namespace boost::multiprecision;
int mod=1000000007;
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);
}
void c_p_c(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
}
bool ispalindrome(string s){
	for(int i=0;i<=s.length()/2;i++){
		if(s[i]!=s[s.length()-1-i]){
			return 0;
		}
	}
	return 1;
}
class cust{
public:
	int t;
	int l;
	int h;
};
int32_t main(){

	ios
	//c_p_c();
	//w(t)
	{
		int n;
		cin>>n;
		vi v(n);
		mi mp;
		fl(i,0,n-1){
			cin>>v[i];
			mp[v[i]]++;
		}
		if(mp.size()==n){
			cout<<"YES\n";
		}
		else{
			cout<<"NO\n";
		}

	}

	return 0;
}



Measured memory_bytes: 14336
// AtCoder Regular Contest 067
// D - Walk and Teleport

#include <cstdio>
#include <algorithm>
#define MAX_N 100000
using namespace std;
typedef long long int ll;


int N;
ll A, B;
ll x[MAX_N];
ll ans;

int main() {

  scanf("%d%lld%lld", &N, &A, &B);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
  }

  ans = 0;
  for (int i = 1; i < N; i++) {
    ans += min(A * (x[i] - x[i - 1]), B);
  }

  printf("%lld\n", ans);

  return 0;

}




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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

template <int mod>
struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = 1LL * x * p.x % mod; return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        ll a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(ll n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
};
const int mod = 1000000007;
using mint = ModInt<mod>;

map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> lcm;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];

        auto X = prime_factor(a[i]);
        for (auto &x : X){
            chmax(lcm[x.first], x.second);
        }
    }

    mint l = 1;
    for (auto &x : lcm){
        l *= mint(x.first).pow(x.second);
    }
    mint res = 0;
    for (int i = 0; i < n; ++i) {
        res += mint(a[i]).inverse();
    }
    res *= l;
    cout << res << endl;
}

Measured memory_bytes: 4168
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
vector<int> divi;
int dp[2005];
int pow(int a,int b,int mod){
	if(b==1){
		return a;
	}
	int k=pow(a,b/2,mod)%mod;
	if(b%2==0){
		return (k*k)%mod;
	}
	return ((k*k)%mod*a)%mod;
}
signed main(){
	int n,k,ans=0;
	cin>>n>>k;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			divi.push_back(i);
			divi.push_back(n/i);
			if(i*i==n){
				divi.pop_back();
			}
		}
	}
	sort(divi.begin(),divi.end());
	for(int i=0;i<divi.size();i++){
		dp[i]=pow(k,(divi[i]+1)/2,mod);
		for(int j=0;j<i;j++){
			if(divi[i]%divi[j]==0){
				dp[i]=(dp[i]-dp[j]+mod)%mod;
			}
		}
		if(divi[i]%2==0){
			ans+=1LL*dp[i]*divi[i]/2;
			ans%=mod;
		}
		else{
			ans+=1LL*dp[i]*divi[i];
			ans%=mod;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
set<ll>s;
bool p(ll x){
    if(s.find(x)!=s.end()) return true;
    else return false;
}
int main()
{
    fastio;
    ll ar[3][3];
    for(ll i=0;i<3;++i){
        for(ll j=0;j<3;++j) cin>>ar[i][j];
    }
    ll n=0;
    cin>>n;
    for(ll i=0;i<n;++i){
        ll x=0;
        cin>>x;
        s.insert(x);
    }
    bool f=false;
    for(ll i=0;i<3;++i){
        if(p(ar[i][0]) and p(ar[i][1]) and p(ar[i][2])) f=true;
    }
     for(ll i=0;i<3;++i){
        if(p(ar[0][i]) and p(ar[1][i]) and p(ar[2][i])) f=true;
    }
    if(p(ar[0][0]) and p(ar[1][1]) and p(ar[2][2])) f=true;
    if(p(ar[2][0]) and p(ar[1][1]) and p(ar[0][2])) f=true;
    if(f) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		String a, b;
		Scanner sc = new Scanner(System.in);
		a = sc.next();
		b = sc.next();

		if(a.equals("H")){
			System.out.println(b);
		}else if(a.equals("D") && b.equals("H")){
			System.out.println("D");
		}else{
			System.out.println("H");
		}
	}
}



Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	int ans1 = a + b;
	int ans2 = a - b;
	int ans3 = a * b;
	printf("%d\n", max(max(ans1, ans2),ans3));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,m;
  cin>>n>>m;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  int sum=0;
  for(int a:as) sum+=a;

  int cnt=0;
  for(int a:as) cnt+=a*4*m>=sum;

  cout<<(cnt>=m?"Yes":"No")<<newl;
  return 0;
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, M;
    cin >> N >> M;
    if (N < M)
    {
        vector<int> list(M), dis(M - 1);
        for (int i = 0; i < M; i++)
            cin >> list[i];
        sort(list.begin(), list.end());

        for (int i = 0; i < M - 1; i++)
            dis[i] = list[i + 1] - list[i];
        sort(dis.begin(), dis.end());
        reverse(dis.begin(), dis.end());
        
        int ans = list[M - 1] - list[0];
        for (int i = 0; i < N - 1; i++)
            ans -= dis[i];
        cout << ans;
    }
    else
        cout << 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;

        for (int i=1;i<=n;i++) {
            String s = sc.next();
            if (s.equals("AC")) {
                ac++;
            } else if (s.equals("WA")) {
                wa++;
            } else if (s.equals("TLE")) {
                tle++;
            } else if (s.equals("RE")) {
                re++;
            }
        }

        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
}


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

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

    long long diff = a - k;

    if (a >= k) cout << a - k << " " <<  b << endl;
    else if (b + diff >= 0) cout << 0 << " " << b + diff << endl;
    else cout << 0 << " " << 0 << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N, K;
vector<ll> a;
vector<ll> sum;
vector<ll> v;
int dp[1000][1000];

void init()
{
	cin >> N >> K;
	CINV(a, N);
	sum.RS(N+1);
	sum[0] = 0;
	rep(i, N)  sum[i+1] = sum[i] + a[i];
	rep(i, N) reps(j, i, N) dp[i][j] = 1;
}

bool ch(ll x)
{
	int cnt = 0;
	rep(i, N) {
		reps(j, i, N) {
			if (dp[i][j] == 0) continue;
			ll t = sum[j+1] - sum[i];
			if (t & x) cnt++;
		}
	}
	return cnt >= K;
}

void del(ll x)
{
	rep(i, N) {
		reps(j, i, N) {
			ll t = sum[j+1] - sum[i];
			if ((t & x) == 0) dp[i][j] = 0;
		}
	}
}

ll calc()
{
	bool f = false;
	ll res = 0;
	ll ma;
	for (ll x = 1; x < (1LL << 60); x <<= 1) {
		if (ch(x)) f = true;
		ma = x;
	}
	if (!f) return 0;
	for (; ma; ma >>= 1) {
		if (ch(ma)) {
			del(ma);
			res += ma;
		}
	}
	return res;
}

void solve()
{
	cout << calc() << endl;
}




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

int main(){
	int A,B,M;
	cin >> A >> B>>M;
	vector<int> a(A);
	vector<int> b(B);
	vector< vector<int> > discount(M,vector<int>(3));
	int a_min= 1e6;
	int b_min= 1e6;

	for(int i = 0; i< A; i++){
		cin >> a[i];
		a_min = min(a_min,a[i]); 
	}
	for(int i = 0; i<B;i++){
		cin >> b[i];
		b_min = min(b_min,b[i]);
	}
	for(int i=0;i<M;i++){
		for(int j=0; j<3;j++){
			cin >> discount[i][j];
		}
	}
	ll ans = a_min+b_min;
	for(int i=0;i<M;i++){
		ll val = a[discount[i][0]-1]+b[discount[i][1]-1]-discount[i][2];
		ans = min(ans,val);
	}
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 6528
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] S = sc.next().split("");
    if (S[2].equals(S[3]) && S[4].equals(S[5])) {
      System.out.println("Yes");
    } else {
      System.out.println("No");      
    }
  }
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] S = new long[n];

		for(int i = 0; i < n; i++) {
			S[i] = sc.nextLong();
		}

		int q = sc.nextInt();
		int count = 0;

		for(int j = 0; j < q; j++) {
			long T = sc.nextLong();
			for(int i = 0; i < n; i++) {
				if(T == S[i]) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 81828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; 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 INF 1e9
typedef long long ll;
using namespace std;

int main() {
    string a,b; cin >> a >> b;
    rep(i,a.size()){
        a = a[a.size()-1] + a.substr(0,a.size()-1);
        if(a==b){
            cout << "Yes" << endl;
            goto last;
        }
    }
    cout << "No" << endl;
    last:

    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=pow(10,18);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

bool solve(){
  string s;cin>>s;
  vector<ll>count(26,0);
  ll n=s.size();
  rep(i,n){
    count[s[i]-'a']++;
  }
  if(abs(count[0]-count[1])>1 or abs(count[2]-count[1])>1  or abs(count[2]-count[0])>1){
    cout<<"NO"<<endl;
    return false;
  }
  cout<<"YES"<<endl;
  
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed;
  // cout<<precision(30);
  return solve();
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = RArInt();
            int fee;
            if (vs[0] >= 13)
            {
                fee = vs[1];
            }
            else if (vs[0] >= 6)
            {
                fee = vs[1] / 2;
            }
            else
            {
                fee = 0;
            }               
            Console.WriteLine(fee);
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

vvi dp(3010,vi(3010,0));

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

    char figL[3010];
    int k=0;
    memset(figL,'\0',sizeof(char) *3010);
    for (int i = 0; i < S.size(); i++)
    {
        for (int j = 0; j < T.size(); j++)
        {
            if(S[i] == T[j]){
                dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
            }

            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1]);
        }
        
    }

    int i = S.size();
    int j = T.size();
    while(dp[i][j] > 0)
    {
        if(dp[i-1][j] == dp[i][j])
        {i--;}
        else if(dp[i][j-1] == dp[i][j]){j--;}
        else 
        {
            i--;
            j--;
            figL[k]=S[i];
            k++;
        }

    }
    
    for (int l = dp[S.size()][T.size()]; l >= 0; l--)
    {
        if(figL[l]!='\0')
        printf("%c",figL[l]);
        
    }
    
    
    return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int top, S[1000];

void push(int x)
{
	S[++top] = x;
}

int pop()
{
	top--;
	return S[top+1];
}


int main()
{
	int a, b;
	
	top = 0;
	char s[100];
	
	while (scanf("%s", s) != EOF)
	{
		if (s[0] == '+')
		{
			a = pop();
			b = pop();
			push(a + b);
		} else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		} else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		} else {
			push(atoi(s));
		}
	}
	
	cout << pop() << endl;
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)

const int maxn = 1111;
int R;

signed main() {
  // freopen("in", "r", stdin);
  while(~scanf("%d", &R)) {
    if(R < 1200) {
      printf("ABC\n");
    }
    else if(R >= 1200 && R < 2800) {
      printf("ARC\n");
    }
    else {
      printf("AGC\n");
    }
  }
  return 0;
}


Measured memory_bytes: 256
import numpy

t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())

v1=b1-a1
v2=b2-a2

x1=v1*t1
x2=v2*t2
di = abs(abs(x2)-abs(x1))
if numpy.sign(x1)==numpy.sign(x2):
    print(0)
elif abs(x2)<abs(x1):
    print(0)
elif abs(x1)==abs(x2):
    print("infinity")
else:
    if abs(x1)%di==0:
        print(abs(int(2*(x1/di))))
        #di = abs(x2)-abs(x1)
    else:
        print(abs(int(2*(x1//di)+1)))


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int n, res = 0, tmp;
    cin >> n;
    tmp = n;
    while (tmp > 0)
        res += tmp % 10, tmp /= 10;
    if (n % res == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[10];
    for(int i=0;i<5;i++)
        scanf("%d",&a[i]);
    scanf("%d",&n);
    sort(a,a+5);
    if(a[4]-a[0]>n)
        printf(":(\n");
    else
        printf("Yay!\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if( a+b > c+d ) cout << "Left" << endl;
	else if (a+b == c+d) cout << "Balanced" << endl;
	else cout << "Right" << endl;
}


Measured memory_bytes: 256
from math import factorial
from collections import Counter

n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=True)

ma=sum(v[:a])/a
print(ma)
cnt=Counter(v)

if v[a-1]==v[0]:
    m=cnt[v[0]]
    ans=0
    for i in range(a,min(b,m)+1):
        ans+=factorial(m)//(factorial(i)*factorial(m-i))
    
    print(ans)
else:
    m=cnt[v[a-1]]
    r=Counter(v[:a])[v[a-1]]

    print(factorial(m)//(factorial(r)*factorial(m-r)))


Measured memory_bytes: 66960
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

class Dijkstra {
  private:
    struct Graph {
        int to, cost;
    };
    const long long INF = 4'000'000'000'000'000'000;
    using P             = pair<long long, int>;
    int V;
    vector<vector<Graph>> G;
    vector<long long> dist;

  public:
    Dijkstra(int vertex) {
        V = vertex;
        G.resize(vertex);
        dist.resize(vertex, INF);
    }
    // 無向グラフの構築
    void undirected_update(int x, int y, int cost) {
        G[x].push_back({y, cost});
        G[y].push_back({x, cost});
    }
    // 有向グラフの構築
    void directed_update(int from, int to, int cost) {
        G[from].push_back({to, cost});
    }

    // start からの最短経路計算
    void calc(int start) {
        priority_queue<P, vector<P>, greater<P>> que;
        dist[start] = 0;
        que.push({0, start});

        while (!que.empty()) {
            auto p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first)
                continue;
            for (int i = 0; i < G[v].size(); i++) {
                auto e = G[v][i];
                if (dist[v] + e.cost < dist[e.to]) {
                    dist[e.to] = dist[v] + e.cost;
                    que.push({dist[e.to], e.to});
                }
            }
        }
    }

    // calc で渡した start からの最短経路を返す
    // 最短経路が存在しないとき -1 を返す
    long long min_dist(int to) { return dist[to] != INF ? dist[to] : -1; }
};

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

    int v, e, r;
    cin >> v >> e >> r;
    auto dj = Dijkstra(v);
    REP(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        dj.directed_update(s, t, d);
    }
    dj.calc(r);
    REP(i, v) {
        dj.min_dist(i) == -1 ? std::cout << "INF" << '\n'
                             : std::cout << dj.min_dist(i) << '\n';
    }

    return 0;
}


Measured memory_bytes: 14328
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define first fst
#define second scd
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n,d;
  vector<int> a,b,c;
  int ans=0;
  int p,q;
  cin>>n;
  rep(i,n){cin>>d;a.push_back(d);}
  rep(i,n){cin>>d;b.push_back(d);}
  rep(i,n){cin>>d;c.push_back(d);}
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  rep(i,n){
    int f=b[i];
    p=lower_bound(a.begin(),a.end(),f)-a.begin();
    q=upper_bound(c.begin(),c.end(),f)-c.begin();
    
    
    ans+=p*(n-q);
  }
  cout<<ans<<endl;

  return 0;
}




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


int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if(r <= x && x <= W - r && r <= y && y <= H - r) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 1176
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, K = map(int, input().split())

    ans = 0.0
    for i in range(1, N + 1):
        count = 0
        t = i
        while t < K:
            t *= 2
            count += 1
        ans += 0.5 ** count

    ans = ans / N
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static final int ORIGIN_POINT_X = 0;
	private static final int ORIGIN_POINT_Y = 0;

	public static void main(String[] args) {
		//
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		int[] inputIntArr = null;
		try {
			String[] inputStrArr = (input.readLine()).split(" ");
			inputIntArr = new int[inputStrArr.length];
			for(int i = 0; i < inputIntArr.length; i++) {
				inputIntArr[i] = Integer.parseInt(inputStrArr[i]);
			}

			if (judgeWidth(inputIntArr[2], inputIntArr[4], inputIntArr[0]) && judgeHeight(inputIntArr[3], inputIntArr[4], inputIntArr[1] )) {
				System.out.println("Yes");

			} else {
				System.out.println("No");
			}
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	public static boolean judgeWidth(int x, int r, int W) {
		boolean judgeWidth = false;
		if (((x - r) < ORIGIN_POINT_X ) || ((x + r) > W )) {
			judgeWidth = false;
		} else if (((x - r) >= ORIGIN_POINT_X ) && ((x + r) <= W )) {
			judgeWidth = true;
		}
		return judgeWidth;
	}

	public static boolean judgeHeight(int y, int r, int H) {
		boolean judgeHeight = false;
		if (((y - r) < ORIGIN_POINT_Y ) || ((y + r) > H )) {
			judgeHeight = false;
		} else if (((y - r) >= ORIGIN_POINT_Y ) && ((y + r) <= H )) {
			judgeHeight = true;
		}
		return judgeHeight;
	}

}



Measured memory_bytes: 24372
#include<bits/stdc++.h>
#define MM 1000000007
using namespace std;
int dp[25]={0};
int main(void){
	int n;
	string s,t;
	int i,j;
	cin>>n;
	cin>>s>>t;
	dp[s[0]-'a']=1;
	for(i=1;i<n-1;i++){
		dp[s[i]-'a']+=dp[t[i]-'a'];
		dp[s[i]-'a']%=MM;
	}
	cout<<dp[t[n-1]-'a']<<endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<P> xy(n);
  rep(i, n) cin >> xy[i].first >> xy[i].second;
  int sub = 0;
  rep(i, n) {
    for(int j = 0; j < n; ++j) {
      if(i == j) continue;
      ll p = xy[j].first - xy[i].first;
      ll q = xy[j].second - xy[i].second;
      
      int t = 0;
      rep(k, n) {
        rep(l, n) {
          if(k == l) continue;
          if(xy[k].first - xy[l].first == p && xy[k].second - xy[l].second == q) {
            ++t;
            break;
          }
        }
      }
      sub = max(sub, t);
    }
  }
  if(n == 1) sub = 0;
  
  cout << n - sub << endl;
}

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

int main() {
	char c;
	cin >> c;
	char a = 'a';
	char b = 'e';
	char f = 'i';
	char d = 'o';
	char e = 'u';
	
	if (c == a) {
		cout << "vowel" << endl;
	}
	else if(c == b) {
		cout << "vowel" << endl;
	}
	else if(c == f) {
		cout << "vowel" << endl;
	}
	else if(c == d) {
		cout << "vowel" << endl;
	}
	else if(c == e) {
		cout << "vowel" << endl;
	}
	else{
		cout << "consonant" << endl;
	}
	
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int P = min((N-1),K);
  vector<int> L(N);
  vector<int> C(P);
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  for(int x=0;x<P;x++){
    C.at(x) = 114514;
  }
  H.at(0) = 0;
  
  for(int k=1;k<N;k++){
    for(int h=1;h<P+1;h++){
      if((k-h)>=0){
        C.at(h-1) = H.at(k-h)+abs(L.at(k-h)-L.at(k));
      }

    }
    sort(C.begin(),C.end());
    H.at(k) = C.at(0);
  }
  
  cout << H.at(N-1) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

string s;

int main() {

    cin >> s;

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else if (s == "Rainy") {
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn


object Main extends App {
  val s  = StdIn.readLine()

  def solve(s : String): String = {
    val first = s.slice(0, 2)
    val last = s.slice(2, 4)
    var lm = false
    var fm = false

    // YYMM
    if (1 <= last.toInt && last.toInt <= 12) lm = true
    if (1 <= first.toInt && first.toInt <= 12) fm = true

    if (fm) {
      if (lm) {
        "AMBIGUOUS"
      } else {
        "MMYY"
      }
    } else {
      if (lm) {
        "YYMM"
      } else {
        "NA"
      }
    }

  }


  println(solve(s))

}
  




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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for(int i=0; i<K; i++){
    if(i%2==0){
      if(A%2==0){
       A /= 2;
       B += A;
      }else{
       A--;
       A /= 2;
       B += A;
      }
    }else{
       if(B%2==0){
         B /= 2;
         A += B;
       }else{
         B--;
         B /= 2;
         A += B;
       }
    }
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    long long n, m;
    cin >> n >> m;
    long long ans = 0;
    if (n >= m){
        ans = m / 2;
    }
    else {
        ans += n;
        m -= n*2;
        ans += m / 4;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3536
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main() {
	map<int, string>a;
	for (int i = 0; i < 2; i++) {
		string b, h = "";
		getline(cin, b);
		b += " ";
		int sum = 0, b2[2], c = 0;
		for (int j = 0; j < b.length(); j++) {
			if (b[j] == ' ') {
				if (c != 0) {
					b2[sum] = atoi(h.c_str());
					sum++;
				}
				c++;
				h = "";
			}
			else
				h += b[j];
			if (sum == 2) {
				sum = 0;
				string d = to_string(b2[0]), e = to_string(b2[1]);
				if (e.length() == 1) {
					e = "0" + e;
				}
				int f = b2[0] * 60 + b2[1];
				a.insert(map<int, string>::value_type(f, (d + ":" + e)));
			}
		}
	}
	map<int, string>::iterator it = a.begin();
	int k = 0;
	while (it != a.end()) {
		if (k == 0)cout << (*it).second;
		else cout << " " << (*it).second;
		it++;
		k++;
	}
	cout << endl;
}

Measured memory_bytes: 3212
from random import choice
from random import random
from time import time


class Optimizer:
    def __init__(self, C, S):
        self.C = C
        self.S = S
        X = []
        L = [-1] * 26
        for i in range(365):
            max_diff = -10**10
            best_j = 0
            for j in range(26):
                memo = L[j]
                L[j] = i
                diff = self.S[i][j] - \
                    sum([self.C[jj] * (i - L[jj]) for jj in range(26)])
                if diff > max_diff:
                    max_diff = diff
                    best_j = j
                L[j] = memo
            L[best_j] = i
            X.append(best_j)
        self.X = X

    def calc_score(self):
        score = 0
        L = [-1 for j in range(26)]
        A = [0 for j in range(26)]
        for i in range(365):
            score += self.S[i][self.X[i]]
            A[self.X[i]] += (i - L[self.X[i]]) * \
                (i - L[self.X[i]] - 1) // 2
            L[self.X[i]] = i
        for j in range(26):
            A[j] += (365 - L[j]) * (365 - L[j] - 1) // 2
            score -= self.C[j] * A[j]
        return score

    def optimize(self, temp, threp, interval, start_time, lim=1.8):
        max_score = self.calc_score()
        while True:
            t = (time() - start_time) / 2
            if random() < threp:
                i = choice(range(365))
                j = choice(range(26))
                memo = self.X[i]
                self.X[i] = j
                new_score = self.calc_score()
                if new_score > max_score:
                    max_score = new_score
                elif random() < pow(2.7, (new_score - max_score) / pow(2000, 1 - t)):
                    max_score = new_score
                else:
                    self.X[i] = memo
            else:
                a = choice(range(interval))
                i0 = choice(range(365 - a))
                i1 = i0 + a
                self.X[i0], self.X[i1] = self.X[i1], self.X[i0]
                new_score = self.calc_score()
                if new_score > max_score:
                    max_score = new_score
                elif random() < pow(2.7, (new_score - max_score) / pow(2000, 1 - t)):
                    max_score = new_score
                else:
                    self.X[i0], self.X[i1] = self.X[i1], self.X[i0]
            if time() - start_time > lim:
                break
        return max(max_score + 10**6, 0)


if __name__ == "__main__":
    d = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for i in range(d)]
    opt = Optimizer(C, S)
    opt.optimize(2000, 0.8, 26, time())
    for x in opt.X:
        print(x + 1)
    # print(opt.calc_score())


Measured memory_bytes: 91244
#include<stdio.h>
#define ABS(x) (((x)<0)?(-(x)):(x))

int main(void){
  int i,j,k,n,num,h,w,nownum;
  double now,bmi;

  while(scanf("%d",&n) && n){
    now=100000 ;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&num,&h,&w);
      bmi=10000*w/(double)(h*h);
      if(ABS(22-bmi)<now){
	now=ABS(22-bmi);
	nownum=num;
      }
    }
    printf("%d\n",nownum);
  }
  return 0;
}

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

int main() {
    int64_t A,B,C,X,Y,min,maisu,cost,Am,Bm,ABm;

    cin >> A >> B >> C >> X >> Y;

    if(X<Y)
        maisu = Y;
    else
    {
        maisu = X;
    }
    min = A*X+B*Y;
    for(int i=1;i<=maisu;i++){
        cost = 0;
        Am = X - i;
        Bm = Y - i;
        if(Am<0)
            Am=0;
        if(Bm<0)
            Bm=0;

        cost = Am*A + Bm*B +2*i*C;
        if(min>cost)
            min=cost;
    }
    cout << min <<endl;

    
}

Measured memory_bytes: 3604
import math
[a,b,x] = [int(i) for i in input().split()]
if (a * a * b / 2) <= x:
    ans = 2 * x /(a*a) - b
    #print(ans)
    ans = math.degrees(math.atan((b - ans)/a))
    print(ans)
else:
    ans = 2 * x / (b * a)
    ans = math.degrees(math.atan(b/ans))
    print(ans)

Measured memory_bytes: 3060