akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define rrep(i , n) for ( int i = n-1; i >=0 ; i--)

#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	ull size_; 
	std::vector<ull> par, rank, count;

public:
	UnionFind() : size_(0), par(std::vector<ull>()), rank(std::vector<ull>()), count(std::vector<ull>()) {};
	UnionFind(ull size__) : size_(size__) {
		par.resize(size_); rank.resize(size_); count.resize(size__);
		for (ull i = 0; i < size_; i++) par[i] = i, rank[i] = 0, count[i] = 1;
	}
	ull size() { return size_; }
	// ull root(ull x) { return par[x] == x ? x : par[x] = root(par[x]); }
	
	ull root(ull x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	
	bool same(ull x, ull y) { return root(x) == root(y); }

	void unite(ull x, ull y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y, count[y]+=count[x], count[x]=0;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++, count[x]+=count[y], count[y]=0;
		else par[y] = x, count[x] += count[y], count[y] = 0;
	}

	ull size__(ull x)
	{
		return count[root(x)];
	}

	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
/*
maybe sth wrong 
got wa in one problem
*/
ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}

int main()
{
	ll A, B;
	
	cin >> A >> B;

	ll sum = 0;

	ll tmp1, tmp2;

	int ra= A % 4;
	int rb = (B+1) % 4;

	if (ra == 0)
	{
		tmp1 = 0;
	}
	else if (ra == 1)
	{
		tmp1 = A - 1;
	}
	else if (ra == 2)
	{
		tmp1 = 1;
	}
	else if (ra == 3)
	{
		tmp1 = 1 ^ (A-1);
	}


	if (rb == 0)
	{
		tmp2 = 0;
	}
	else if (rb == 1)
	{
		tmp2 = B;
	}
	else if (rb == 2)
	{
		tmp2 = 1;
	}
	else if (rb == 3)
	{
		tmp2 = 1 ^ B;
	}

	cout << (tmp1 ^ tmp2) << endl;

	
	return 0;
}



Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
GC027 C
"""

n,m = map(int,input().split())
s = bytearray(input(),'utf-8')
ali = [0 for i in range(n)]
bli = [0 for i in range(n)]
from collections import defaultdict
graphAB = defaultdict(list)

for i in range(m):
    u,v=map(int,input().split())
    graphAB[u].append(v)
    graphAB[v].append(u)



def incrementAB(node,adj):
    if s[adj-1] == 65:
        ali[node-1]+=1
    if s[adj-1] == 66:
        bli[node-1]+=1

def decrementAB(node,adj):
    if s[adj-1] == 65:
        ali[node-1]-=1
    if s[adj-1] == 66:
        bli[node-1]-=1



graphvers = set(graphAB.keys())
visitset = set()
for i in range(1,n+1):
    if not i in graphvers:
        s[i-1] = 67
    else:
        for j in graphAB[i]:
            incrementAB(i,j)
        if not (ali[i-1] and bli[i-1]):
            visitset.add(i)

while bool(visitset):
    #print(graphAB)
    #print(graphABopp)
    #print(abli)
    i = visitset.pop()
    for j in filter(lambda x: s[x-1]!=67,graphAB[i]):
        decrementAB(j,i)
        if not (ali[j-1] and bli[j-1]):
            visitset.add(j)
    s[i-1] = 67

#print(graphAB)
#print(graphABopp)

sset= set(s)
sset.add(67)
sset.remove(67)
if bool(sset):
    print('Yes')
else:
    print('No')





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

template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);

struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator << (pair<c, d> e) {
	return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator << (c a) {
	cerr << boolalpha << a;
	return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator << (c a) {
	*this << "[";
	for (auto it = a.begin(); it != a.end(); ++it)
		*this << ","[1 - (it != a.begin())] << *it;
	return *this << "]";
}
#else
template<class c> debug& operator << (c) {
	return *this;
}
#endif
};

#define aty(x) " [" << #x ": " << x << "] "

using ll = long long;






int main() {
    int n, m;
    cin >> n >> m;
    int h, w;
    cin >> h >> w;
    int tot = n * m;
    tot -= h * m;
    tot -= w * n;
    tot += w * h;
    cout << tot << endl;
}


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

using namespace std;

int main(){
    long n,k;
    cin >> n >> k;
    long mod_0 = 0;
    long mod_half = 0;
    for(long i = 1; i <= n; i++){
        if(i%k == 0) mod_0++;
        if(k%2 == 0 && i%k == k/2) mod_half++;
    }

    cout << mod_0*mod_0*mod_0 + mod_half*mod_half*mod_half << endl;
    return 0;
}


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

int main() {
  int r, D, x;
  cin >> r >> D >> x;
  
  x = r*x - D;
  cout << x << endl;
  
  x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
  
   x = r*x - D;
  cout << x << endl;
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  
  int total = 0;
  for (int i = 0; i < N; ++i) {
    total += A[i];
  }
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] * 4 * M < total) break;
    ++cnt;
  }

  if (cnt >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>(b);i--)
    typedef long long ll;
    using namespace std;

    typedef double dd;

    int main(){
         ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,t;
    cin>>n>>x>>t;
    if((n%x)!=0) cout<<t*((n/x)+1);
    else {cout<<t*((n/x));return 0;}



        return 0;
    }


Measured memory_bytes: 3628
use proconio::input;
use std::num::*;

fn main() {
    input!{
        x: i64,
    }

    for a in -150i64..150i64 {
        for b in -150i64..150i64 {
            if a.pow(5u32) - b.pow(5u32) == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n,s) for (int i=a;i<n;i+=s)
#define rep(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>inline bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10, mod = 1e9+7; const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head



int main(){
  int n,m;
  while (1){
    int count = 0;
    cin >> m >> n;
    if ( n== 0 && m == 0){ return 0;}
    vector<bool> is_taikutu(7400000,true);
    rep(i,m,7400000){
      if (!is_taikutu[i]){ continue;}
      count ++;
      if ( count > n){ cout << i << endl;break;}
      // if (i > 3000){ continue;}
      rep(j,i*2,7400000,i){
        is_taikutu[j] = false;
      }

    }
  }
}


Measured memory_bytes: 3996
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;
    lint f = N / K;
    lint ret = f * f * f;
    if (K % 2 == 0) {
        lint g = (N / (K / 2) + 1) / 2;
        ret += g * g * g;
    }

    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define max_value 2147483647
using namespace std;
int n,h,k;
int values[100005];
int dp[100005];

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

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

    for(int i = 0;i < n;i++)
        dp[i] = max_value;
    dp[0] = 0;

    for(int i = 0;i < n;i++)
        for(int j = 1;j <= k && i+j < n;j++)
            dp[i+j] = min(dp[i+j],dp[i] + abs(values[i]-values[i+j]));

    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    int A[N];
    A[0] = 0;
    for(int i = 1; i < N; i++){
    	cin >> A[i];
    }
    int p[N] = {0};
    for(int i = 1; i < N; i++){
        p[A[i]-1]++;
    }
    for(int i = 0; i < N; i++){
    	cout << p[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)

#define ll long long

int main() {

	ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // freopen("input.in", "r", stdin);

    int d,t,s;
    cin>>d>>t>>s;

    double r = (double)d/s;

    if (r-t<0.0000001) {
        cout<<"Yes\n";
    } else
        cout<<"No\n";

    return 0;
}

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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long c;
    if (n % (a + b) >= a) {
        c = a;
    } else {
        c = n % (a + b);
    }
    cout << n / (a + b) * a + c << endl;
    return 0;
}


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

#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'

typedef long long int ll ;

void solve()
{
	ll n , w ;
  	cin >> n >> w ;
  	ll wt[n] , val[n] ;
  	for ( ll i = 0 ; i < n ; i++ ) cin >> wt[i] >> val[i] ;
  	ll dp[n + 1][w + 1] ; 
  	for ( ll i = 0 ; i <= n ; i++ )
    {
    	for ( ll weight = 0 ; weight <= w ; weight++ )
        {
      	 	 if ( i == 0 || weight == 0 ) 
                 dp[i][weight] = 0 ;
          	 else if ( wt[i - 1] <= weight )
              	 dp[i][weight] = max ( dp[i - 1][weight - wt[i - 1]] + val[i - 1] , dp[i - 1][weight] ) ;
          	 else 
      		     dp[i][weight] = dp[i - 1][weight] ;
     		}
	}
	cout << dp[n][w] << endl ;
}

int main()
{	 
	 ios ; 
  	 solve() ; 
}

Measured memory_bytes: 82548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+10;
ll a[N],sum[N];
map<ll, int>mp;
int main()
{
    ll  n,k;
    scanf("%lld%lld",&n,&k);
    set<ll>S;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum[i]=(a[i]+sum[i-1])%k;
        mp[sum[i]]++;
        S.insert(sum[i]);
    }
    /*for(int i=1;i<=n;i++){
        printf("%d\n",sum[i]);
    }*/
    ll ans=mp[0];
    set<ll> ::iterator it=S.begin();
    for( ; it!=S.end();it++){
        int cur=*it;
        ll t=mp[cur];
        ans+=(t*(t-1))/2;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 12032
#include <iostream>

using namespace std;

int main(){
	int n, m;
	while(cin >> n >> m && n && m){
		int t[n], h[m];
		int ts = 0, hs = 0;
		for(int i = 0; i < n; i++){
			cin >> t[i]; 
			ts += t[i];
		}
		for(int i = 0; i < m; i++){
			cin >> h[i];
			 hs += h[i];
		}
		int dd = hs + ts;
		int dt, dts = 201;
		int I, J;
		if(dd % 2){
			cout << "-1" << endl;
			continue;
		}
		dd /= 2;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				dt = t[i] - h[j];
				if(dd == hs + dt && dts > t[i] + h[j]){
					dts = t[i] + h[j];
					I = i;
					J = j;	
				}
			}
		}
		if(dts == 201) cout << "-1" << endl;
		else cout << t[I] << " " << h[J] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	char a[20];
	scanf("%s",&a);
	int len=strlen(a);
	int cnt=0;
	for(int i=0;i<len;i++){
		if(a[i]=='x'){
			cnt++;
		}
	}
	int m=15-cnt;
	if(m>=8){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

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

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        string tmp = "";
        for (int j = i; j < s.size(); j++) {
            tmp += s[j];
        }
        for (int j = 0; j < i; j++) {
            tmp += s[j];
        }
        if (tmp == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main(){
    vector<int> vec ={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};

    int K;
    cin >> K;
    cout << vec.at(K-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <math.h>

using namespace std;

int koch(int d, double p1x, double p1y, double p2x, double p2y)
{
  double sx, sy, ux, uy, tx, ty;
  
  if(d == 0){
    return 0;
  }

  sx = (2 * p1x + p2x) / 3;
  sy = (2 * p1y + p2y) / 3;
  tx = (p1x + 2 * p2x) / 3;
  ty = (p1y + 2 * p2y) / 3;
  ux = (tx - sx) * cos(M_PI / 3) - (ty - sy) * sin(M_PI / 3) + sx;
  uy = (tx - sx) * sin(M_PI / 3) + (ty - sy) * cos(M_PI / 3) + sy;

  koch(d - 1, p1x, p1y, sx, sy);
  cout << sx << ' ' << sy << endl;
  koch(d - 1, sx, sy, ux, uy);
  cout << ux << ' '  << uy << endl;
  koch(d - 1, ux, uy, tx, ty);
  cout << tx << ' ' << ty << endl;
  koch(d - 1, tx, ty, p2x, p2y);
}

int main(void){
  int n;

  cin >> n;

  cout << 0 << ' ' << 0 << endl;

  koch(n, 0, 0, 100, 0);

  cout << 100 << ' ' << 0 << endl;
  
  return 0;
}



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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int ans=0,x=a[0];
    for (int i = 0; i < n; ++i) {
        if(x>b[i])
        {
            ans+=b[i];
            x=a[i+1];
        }
        else
        {
            ans+=x;
            b[i]-=x;
            ans+=min(a[i+1],b[i]);
            x=a[i+1]-min(a[i+1],b[i]);
        }

    }
    cout<<ans;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime;

namespace Csharponly
{
    class Program
    {
        static public void Main()
        {
            int K = Oneint();
		int[] AB = Arrayint();

		string ans = "OK";
		if((AB[0]-1)/K == AB[1]/K )
		{
			ans = "NG";
		}
		
		Console.WriteLine(ans);

        }

　　　　//一つの文字列を受け渡す
        static string Onestring()
        {
            return Console.ReadLine();
        }

        //複数の文字列を配列で受け渡す
        //文字列と文字列の間は" "で区切る
        static string[] Arraystring()
        {
            return Console.ReadLine().Split(' ');
        }

        //一つの数字を受け渡す
        static int Oneint()
        {
            return int.Parse(Console.ReadLine());
        }

        //複数の数字を配列で受け渡す
        //数字と数字の間は" "で区切る
        static int[] Arrayint()
        {
            String[] input_line = Console.ReadLine().Split(' ');
            int[] input_num = new int[input_line.Length];
            for (int i = 0; i < input_line.Length; i++)
            {
                input_num[i] = int.Parse(input_line[i]);
            }
            return input_num;
        }
    }
}

Measured memory_bytes: 27384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
const int N = 6010;
ll fact[N], invf[N];
ll dp[N][N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
    ll n, x;
    cin >> n >> x;

    fact[0] = invf[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
        invf[i] = divll(invf[i-1], i);
    }

    dp[0][0] = 1;
    REP(i,n) REP(j,N-2){
        dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
        dp[i+1][j+2] = (dp[i+1][j+2] + dp[i][j]) % mod;
    }

    ll ans = 1;
    FOR(m,1,n){
        // cout << "m " << m << endl;
        ll tmp = 0;
        REP(j,x) tmp = (tmp + dp[m][j]) % mod;
        FOR(t,1,(m-1)/2){
            ll d = x - 1 - 2 * t;
            if (d > 0 && d < 2 * (m - 2 * t)) tmp = (tmp + dp[m - 2 * t][d]) % mod;
            // if (2 * t == x) break;
            // ll nn = m - 2 * t;
            // for (ll xx = x - 3; xx > 0 && xx + 4 * t >= x; xx -= 2){
            //     ll d = 0;
            //     if (nn == 1){
            //         if (xx == 1) d = 1;
            //     }else{
            //         d = dp[nn][xx];
            //         if (xx >= 4) d = (d - dp[nn-2][xx-4]) % mod;
            //     }
            //     tmp += d;
            //     cout << nn << " " << xx << " " << d << endl;
            // }
            // cout << d << " " << m - 2 * t << " " << dp[m - 2 * t][d] << endl;
        }
        if (x % 2 == 1 && 2 * m > x) tmp++;
        // cout << tmp << endl;
        ans = (ans + tmp * nCr(n, m)) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 141568
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main() {
    int n, p;
    while(cin >> n >> p, n || p){
        vi cand(n,0);
        int turn = 0;
        int st = p;
        while(1){
            if(st == 1 && cand[turn%n] == p-1){
                cout << turn%n << endl;
                break;
            }
            if(st == 0){
                st = cand[turn%n];
                cand[turn%n] = 0;
            }
            else{
                st--;
                cand[turn%n]++;
            }
            turn++;
        }
    }
    return 0;
}

Measured memory_bytes: 1196
// AOJ 2153: Mirror Cave
// 2017.11.11 bal4u@uu

#include <stdio.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define QMAX 150000
typedef struct { char lr, lc, rr, rc; } Q;
Q q[QMAX+2]; int top, end;

char ml[50][51], mr[50][51];
char mk[50][50][50][50];
int mvl[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int mvr[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};

int main()
{
	int w, h, r, c, lr, lc, rr, rc, lr2, lc2, rr2, rc2, i, f;
	int slr, slc, srr, src;
#if TM
	clock_t start, end;
	start = clock();
#endif

	while (scanf("%d%d", &w, &h) && w > 0) {
		for (f = 0, r = 0; r < h; r++) {
			scanf("%s%s", ml[r], mr[r]);
			if (f < 3) for (c = 0; c < w; c++) {
				if (ml[r][c] == 'L') slr = r, slc = c, f |= 1;
				if (mr[r][c] == 'R') srr = r, src = c, f |= 2;
			}
		}
		memset(mk, 0, sizeof(mk));
		q[0].lr = slr, q[0].lc = slc, q[0].rr = srr, q[0].rc = src, top = 0, end = 1;
		mk[slr][slc][srr][src] = 1;
		f = 0;
		while (top != end) {
			lr = q[top].lr, lc = q[top].lc, rr = q[top].rr, rc = q[top].rc; if (++top == QMAX) top = 0;
			if (ml[lr][lc] == '%' && mr[rr][rc] == '%') { f = 1; break; }
			if (ml[lr][lc] == '%' || mr[rr][rc] == '%') continue;

			for (i = 0; i < 4; i++) {
				lr2 = lr + mvl[i][0], lc2 = lc + mvl[i][1];
				rr2 = rr + mvr[i][0], rc2 = rc + mvr[i][1];
				if (lr2 < 0 || lr2 >= h || lc2 < 0 || lc2 >= w || ml[lr2][lc2] == '#')
					lr2 = lr, lc2 = lc;
				if (rr2 < 0 || rr2 >= h || rc2 < 0 || rc2 >= w || mr[rr2][rc2] == '#')
					rr2 = rr, rc2 = rc;
				if (mk[lr2][lc2][rr2][rc2]) continue;
				mk[lr2][lc2][rr2][rc2] = 1;
				q[end].lr = lr2, q[end].lc = lc2, q[end].rr = rr2, q[end].rc = rc2; if (++end == QMAX) end = 0;
			}
		}
		puts(f ? "Yes" : "No");
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

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

int main()
{
	int d;
	cin>>d;
	
	if(d==25) cout<<"Christmas"<<endl;
	else if(d==24) cout<<"Christmas Eve"<<endl;
	else if(d==23) cout<<"Christmas Eve Eve"<<endl;
	else if(d==22) cout<<"Christmas Eve Eve Eve"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int onaji(char *t,char *p,int i,int pl){
  int j;
  for(j=0;j<pl;j++){
    if(t[i+j]!=p[j]) return 0;
  }
   
  return 1;
}
int main(){
  char t[1000];
  char p[1000];
  int i,j;
  int tl;
  int pl;
  scanf("%s",t);
  scanf("%s",p);
  tl=strlen(t);
  pl=strlen(p);
  for(i=0;i<tl;i++){
    if(onaji(t,p,i,pl)){
      printf("%d\n",i);
    }     
  }
  return 0;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll a,p;
	cin >> a >>p;
	cout << (a*3 + p)/2 << endl;
}
    // Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
ll a[MAXN], b[MAXN], s[MAXN];
map <int, int> mp; int n, m;
pair <int, int> x[MAXN];
int main() {
	read(n), m = 0;
	ll sa = 0, sb = 0;
	for (int i = 1; i <= n; i++) {
		read(a[i]), read(b[i]);
		sa += a[i], sb += b[i];
		x[++m] = make_pair(a[i], i);
		x[++m] = make_pair(b[i], i);
	}
	sort(x + 1, x + m + 1);
	for (int i = 1; i <= m; i++) {
		mp[x[i].first] = i;
		s[i] = s[i - 1] + x[i].first;
	}
	ll ans = min(sa, sb);
	for (int i = 1; i <= n; i++) {
		int x = mp[a[i]], y = mp[b[i]];
		ll cur = a[i] + b[i]; int pos = n - 2;
		if (x > y) swap(x, y), swap(a[i], b[i]);
		if (x <= pos) {
			cur -= a[i];
			pos++;
		}
		if (y <= pos) {
			cur -= b[i];
			pos++;
		}
		chkmin(ans, cur + s[pos]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15744
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	string T, P; cin >> T >> P;
	for (int i = 0; i < T.size(); i++) {
		for (int j = 0; j < P.size(); j++) {
			if (T[i + j] != P[j])break;
			else if (j == P.size() - 1) {
				cout << i << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1188
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;
vector < int > adj[N];
int vis1[N] , vis2[N];
int dp[N];
void dfs ( int u , int par = 0  ){
 int ret = 0 ;
 dp[u] = ( vis1[u] <= vis2[u] ? 1 : -1 );
 if ( u == 1 || u == n ) dp[u] = 0;
 for ( auto v : adj[u] ){
    if ( v != par ){
        dfs (v,u);
        dp[u] += dp[v];
    }
 }
 return ;
}
int main ( ){
 scanf("%d",&n);
 int x ,y ;
 for ( int i = 1;  i < n; i++ ){
     scanf("%d%d",&x,&y);
     adj[x].push_back(y);
     adj[y].push_back(x);
 }
 memset( vis1 , -1 , sizeof vis1 );
 memset( vis2 , -1 , sizeof vis2 );
 queue < int > q ;
 q.push(1);
 vis1[1] = 0 ;
 while ( q.size() ){
    int u = q.front(); q.pop();
    for ( auto v : adj[u]){
        if ( vis1[v] == -1 ){
            vis1[v] = vis1[u] + 1 ;
            q.push(v);
        }
    }
 }
 q.push(n);
 vis2[n] = 0 ;
 while ( q.size() ){
    int u = q.front(); q.pop();
    for ( auto v : adj[u]){
        if ( vis2[v] == -1 ){
            vis2[v] = vis2[u] + 1 ;
            q.push(v);
        }
    }
 }
  dfs(1);
  for ( int i = 1 ; i <= n ;i++ )
    cerr << dp[i] <<endl;
  if ( dp[1] >= 1  ) printf("Fennec");
  else printf("Snuke");
return 0 ;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    vector<int> ans;
    rep(i, n) {
        for (int j = n - 1 - i; j >= 0; j--) {
            if (j + 1 == a[j]) {
                ans.push_back(j + 1);
                a.erase(a.begin() + j);
                break;
            }
            if (j == 0) {
                cout << -1 << endl;
                exit(0);
            }
        }
    }
    reverse(all(ans));
    rep(i, n) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pq 	priority_queue<int, vector<int>, greater<int> >
using namespace std;

int main()
{
ll n,k;
cin>>n>>k;

ll h[n+1];h[0]=0;

for(ll i=1;i<n+1;i++)

{
cin>>h[i];}
ll dp[n+5]={0};
dp[1]=0;
dp[2]=abs(h[1]-h[2]);
for(ll i=3;i<n+1;i++)
{ll l;l=k;
	if(i<k+1)l=i-1;pq w;
	for(ll j=1;j<l+1;j++)
	{
		w.push(abs(h[i]-h[i-j])+dp[i-j]);
	
	}
	dp[i]=w.top();
}

cout<<dp[n];
	
	return 0;
}

Measured memory_bytes: 1792
def main():
    L,R = list(map(int,input().split()))

    ans = float('inf')
    if R-L >= 672:
        ans = 0
        print(ans)
        return
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans = min(ans, i*j%2019)
            if ans == 1:
                print(ans)
                return
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>

int A[10000 + 1];

int search(int *A, int n, int key)
{
	A[n] = key;
	int i = 0;
	while (A[i] != key)
	{
		i++;
	}
	if (i != n) return 1;
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);

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

	int m, key, sum = 0;
	scanf("%d", &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d", &key);
		if (search(A, n, key) == 1) sum++;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 2712
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	int X;
	cin >> X;
	if(X>=30){
		cout << "Yes";
	}else{
		cout << "No";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

void upd(ll i, ll n, ll ft[], ll val)
{
    if(i<0)
        return;
    if(i>=n)
        return;
    i++;
    while(i<=n)
    {
        ft[i]+=val;
        i+=(i&(-i));
    }
}

ll sum(ll i, ll ft[])
{
    if(i<0)
        return 0;
    i++;
    ll ans = 0;
    while(i>0)
    {
        ans+=ft[i];
        i-=(i&(-i));
    }
    return ans;
}

int main()
{
  FAST/**/
   
   ll n,q;
   cin>>n>>q;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   
   ll last[n+1];
   memset(last,-1,sizeof(last));
   
   ll ft[n+2];
   memset(ft,0,sizeof(ft));
   
   vector<pair<pair<ll,ll>,ll>> que;
   rep(q)
   {
       ll l,r;
       cin>>l>>r;
       l--,r--;
       l--;
       //cout<<l<<" "<<r<<"\n";
       que.pb(mp(mp(r,l),i));
   }
   
   sort(que.begin(),que.end());
   ll ptr = 0;
   ll ans[q];
   
   rep(n)
   {
       upd(last[arr[i]],n,ft,-1ll);
       last[arr[i]] = i;
       upd(i,n,ft,1ll);
       
       while(ptr<q && que[ptr].ff.ff == i)
       {
           ll l = que[ptr].ff.ss;
           ll r = que[ptr].ff.ff;
           // cout<<r+1<<" ";
           ll id = que[ptr].ss;
           //cout<<"at "<<id+1<<"\n";
           ans[id] = sum(r,ft) - sum(l,ft);
           //cout<<"at "<<r+1<<" = "<<sum(r,ft)<<' ';
           //cout<<"at "<<l+1<<" = "<<sum(l,ft)<<'\n';
           ptr++;
       }
       
   }
   
   rep(q)
        cout<<ans[i]<<"\n";
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 31304
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

vvint vp(100010);
vint dp(100010), used(100010);

int dfs(int v){
	if(used[v])	return dp[v];
	if(vp[v].size() == 0)	return 0;
	used[v] = 1;
	int d = 0;
	for(auto g : vp[v]){
		d = max(d, dfs(g));
	}
	return dp[v] = (d+1);
}
int main(){
	int N, M;
	cin >> N >> M;
	for(int i = 0;i < M;i++){
		int xi, yi;
		cin >> xi >> yi;
		vp[xi-1].push_back(yi-1);
	}
	for(int i = 0;i < N;i++)	dfs(i);
	int ans = 0;
	for(int i = 0;i < N;i++)	ans = max(ans, dp[i]);
	cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//substr

int main(){
    string s;
    cin >> s;
    int ans = 1000;

    for(int i=0;i<s.size()-2;i++){
        string x = s.substr(i,3);
        int y = stoi(x);
        ans = min(ans,abs(y-753));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP(i, 1, n+1)
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int main() {
    int A,B,H,M;
    cin>>A>>B>>H>>M;
    double radH = ((double)H*360/12+(double)M/2)*3.14159265358979/180;
    double radM = (double)M*360/60*3.14159265358979/180;
    //cout << (A*cos(radH)-B*cos(radM)) << endl;
    double l2 = (A*cos(radH)-B*cos(radM))*(A*cos(radH)-B*cos(radM)) + (A*sin(radH)-B*sin(radM))*(A*sin(radH)-B*sin(radM));
    cout << std::fixed << std::setprecision(15)<<sqrt(l2);
    
    return 0;
}

Measured memory_bytes: 4068
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

long test () {
  int n, k;
  readf (" %d %d", &n, &k);
  int[] neg, pos;
  foreach (t; 0 .. n) {
    int x;
    readf (" %d", &x);
    if (x < 0) neg ~= -x;
    else if (x > 0) pos ~= x;
    else --k;
  }
  if (k <= 0) return 0;
  reverse (neg);
  auto nl = neg.length;
  auto pl = pos.length;
  long res = long.max;
  void upd (ulong x) {
    if (res > x) res = x;
  }
  if (k <= nl) upd (neg[k-1]);
  if (k <= pl) upd (pos[k-1]);
  debug stderr.writeln (neg);
  debug stderr.writeln (pos);

  foreach (i; 1 .. min (k, nl+1)) {
    auto j = k - i;
    if (j <= pl) {
      upd (2 * neg[i-1] + pos[j-1]);
      upd (neg[i-1] + 2 * pos[j-1]);
    }
  }
  return res;
}

void main() {
  writeln (test ());
}



Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(c>=a&&c<=b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys
n=int(input())
nt,nx,ny=0,0,0
for i in range(n):
    t,tx,ty=map(int,input().split())
    dis=abs(tx-nx)+abs(ty-ny)
    if dis>(t-nt):
        print("No")
        sys.exit()
    if dis%2!=(t-nt)%2:
        print("No")
        sys.exit()
    nt,nx,ny=t,tx,ty
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;

class SegmentTree {
public:
  int N;
  VI node, lazy;
  SegmentTree(const VI& a) {
    int sz = a.size();
    for (N = 1; N < sz; N *= 2);
    node.resize(2 * N - 1);
    lazy.resize(2 * N - 1);
    REP (i, sz) node[N - 1 + i] = a[i];
    for (int i = N - 2; i >= 0; i--) node[i] = node[2 * i + 1] + node[2 * i + 2];
  }
  SegmentTree(int n) {
    for (N = 1; N < n; N *= 2);
    node.resize(2 * N - 1);
    lazy.resize(2 * N - 1);
  }
  // k番目のノードにのlazyを伝搬
  void eval(int k) {
    if (lazy[k] == 0) return;
    node[k] += lazy[k];
    if (k < N - 1) {
      // 最下段でなければ下のlazyに伝搬
      lazy[2 * k + 1] += lazy[k] / 2;
      lazy[2 * k + 2] += lazy[k] / 2;
    }
    lazy[k] = 0;
  }
  // k番目のノード[l, r)について、[a, b)にxを加算
  void add(int a, int b, int x, int k, int l, int r) {
    eval(k);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += (r - l) * x;
      eval(k);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = node[2 * k + 1] + node[2 * k + 2];
    }
  }
  // [a, b)にxを加算
  void add(int a, int b, int x) {
    add(a, b, x, 0, 0, N);
  }
  // k番目のノード[l, r)について、[a, b)のクエリを求める
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    eval(k);
    if (a <= l && r <= b) return node[k];
    int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
  }
  // [a, b)
  int query(int a, int b) {
    return query(a, b, 0, 0, N);
  }
};
signed main() {
  int n, q; cin >> n >> q;
  SegmentTree seg(n);
  while (q--) {
    int z; cin >> z;
    if (z == 0) {
      int s, t, x; cin >> s >> t >> x;
      seg.add(s - 1, t, x);
    } else {
      int s, t; cin >> s >> t;
      cout << seg.query(s - 1, t) << endl;
    }
  }
}



Measured memory_bytes: 7060
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


void sort(int *height, int num){
  int max=0;
  int tmpi;
  for(int i=0;i<num;i++){
    if(max<height[i]){
      max = height[i];
      tmpi = i;
    }
  }

  //  cout << "max: " << max << endl;
  
  //i??¨num?????????
  int tmp = height[num-1];
  height[num-1] = height[tmpi];
  height[tmpi] = tmp;
}

int main(){
  int height[10];
  for(int i=0;i<10;i++){
    cin >> height[i];
  }

  sort(height, 10);
  sort(height, 9);
  sort(height, 8);

  //  cout << endl;
  
  for(int i=9;i>6;i--){
    cout << height[i] << endl;
  }


  
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int N=100005;
int a[N];
int n;
int main()
{
	scanf("%d",&n);
	int lst=0,ans=0;
	for (int u=1;u<=n;u++)
	{
		int x;
		scanf("%d",&x);
		int i=0,j=1;
		while (j*2<=x)	{j<<=1;i++;}
		if (i<lst)	lst=i;
		else
		{
			if (j!=x) i++;
			ans=ans+i-lst;
			lst=i;
		}
		//printf("%d %d %d %d\n",u,lst,i,j);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
        m: u64,
    }
    println!("{}", (n-1)*(m-1));
}


Measured memory_bytes: 4352
N, A, B, C = map(int, input().split())
bamboo = [int(input()) for _ in range(N)]
INF = 10 ** 9


def dfs(depth, a, b, c):
    if depth == N:
        # 最初は竹を結合していないためABC各々で１０ずつ合計３０のマイナス
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(depth + 1, a, b, c)  # depth本目の竹を使わない
    ret1 = dfs(depth + 1, a + bamboo[depth], b, c) + 10  # depth本目の竹をAに使う
    ret2 = dfs(depth + 1, a, b + bamboo[depth], c) + 10  # depth本目の竹をBに使う
    ret3 = dfs(depth + 1, a, b, c + bamboo[depth]) + 10  # depth本目の竹をCに使う
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
int main(){
	reg int n;scanf("%d",&n);
	reg ll Ans=0;
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=n;j++)
			for(reg int k=1;k<=n;k++)
				Ans+=__gcd(__gcd(i,j),k);
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 3824