akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char *argv[]){
    int N,M;
    std::cin >> N >> M;
    std::vector<std::pair<long int,long int> >AB(N);
    for(auto &ab : AB){
        std::cin >> ab.first >> ab.second;
    }

    std::sort(AB.begin(),AB.end(),
        [](const auto &a, const auto &b){
            return (a.first<b.first)||(a.first==b.first && a.second > b.second);
        });
    
    long int money = 0;
    long int nDrink = 0;
    auto iter = AB.begin();
    long int A,B;
    while(nDrink < M){
        A = (*iter).first;
        B = (*iter).second;
        for(int i=0; i<B; ++i){
            ++nDrink;
            money += A;
            if(nDrink >= M){
                break;
            }
        }
        ++iter;
    }
    std::cout << money << std::endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N, K;
  vector<int> A;
  int ans = 0;
  cin >> N >> K;
  for(int i=1; i<=N;i++){
    int a;
    cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  auto it = A.begin();
  for(int i=1; i<=K; i++){
    ans += (*it);
    
    it++;
  }
  
  cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,l;cin >> n >> l;
  vector<int> a(n);
  rep(i,n) a[i] = i+l;
  vector<int> sum(n+1);sum[0]=0;
  rep(i,n) sum[i+1] = sum[i]+a[i];

  int in=1e+9;
  int res;
  rep(i,n){
    int tmp = abs(sum[i+1]-sum[i]);
    if(in>tmp){
      res=sum[n]-sum[i+1]+sum[i];
      in = tmp;
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;

int h,w,a,b,fact[300015]={0};
class DIrohaAndAGrid {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> h >> w >> a >> b;
		fact[0]=1;
		f(i,1,3e5+5)
			fact[i]=(fact[i-1]*i)%MOD;
		vector<int> vals;
		f(i,b,w)
			vals.push_back(nCr_mod(i+(h-a-1),min(i,(h-a-1))));
		int ans=(vals[0]*(nCr_mod((w-b-1)+a,min(w-b-1,a))))%MOD;
		f(i,1,vals.size())
		{
			ans+=((vals[i]-vals[i-1]+2*MOD)*(nCr_mod((w-b-1-i)+a,min(w-b-1-i,a))))%MOD;
			if(ans>=MOD)
				ans%=MOD;
		}
		out << ans << "\n";
	}
	int nCr_mod(int x, int r)
	{
		int num=fact[x];
		int denom=(mod_inv(fact[r])*mod_inv(fact[x-r]))%MOD;
		return (num*denom)%MOD;
	}
	int mod_inv(int x)
	{
		return mod_exp(x,MOD-2);
	}
	int mod_exp(int x,int p)
	{
		int result=1;
		while(p>0)
		{
			if(p&1)
			{
				result*=x;
				if(result>=MOD)
					result%=MOD;
			}
			x*=x;
			if(x>=MOD)
				x%=MOD;
			p/=2;
		}
		return result%MOD;
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	DIrohaAndAGrid solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int N;
	double S=0;
	vector<double> A;
	cin >> N;

	for(int i=0;i<N;i++){
		double t;
		cin >> t;
		S=S+(1/t);
	}
	cout << 1/S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200004],b[200004];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	sort(a+1,a+1+n);sort(b+1,b+1+n);
	if(n%2==1)cout<<b[(n+1)/2]-a[(n+1)/2]+1;
	if(n%2==0){
		cout<<(b[n/2+1]+b[n/2])-(a[n/2+1]+a[n/2])+1;
	}
}

Measured memory_bytes: 5188
#include <stdio.h>

int main(void){

	int i,moji,ccount=0;
	char s[10];
	scanf("%s",s);	
	
	for(moji=0; s[moji]!='\0'; moji++);

	for(i=0; i<moji; i++){
		if((s[i] == 'B') | (s[i]>='D' && s[i]<='Z') | s[0] != 'A'){
			printf("WA\n");
			return 0;
		}
	}
	
	for(i=2; i<moji-1; i++){
		if(s[i] == 'C') ccount++;
		if(ccount >= 2){
			printf("WA\n");
			return 0;
		}
	}
	
	if(ccount == 0){
		printf("WA\n");
		return 0;
	}
	
	printf("AC\n");
	
    return 0;
}

Measured memory_bytes: 128
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

path = [[0]*10 for i in range(10)]
for i in range(10):
    for j in range(10):
        path[i][j] = c[i][j]

for k in range(10):
    for i in range(10):
        for j in range(10):
            path[i][j] = min(path[i][j], path[i][k]+path[k][j])

min_route = []
for i in range(10):
    min_route.append(path[i][1])

wall_num = [0]*10
for a in A:
    for i in range(10):
        wall_num[i] += a.count(i)

ans = 0
for i in range(10):
    ans += wall_num[i] * min_route[i]

print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<typename T, int DEFAULT_SIZE=0, int DEFAULT_MOD=0>
struct BIT {
  int n;
  int mod;
  std::vector<T> d;

  BIT(int n=DEFAULT_SIZE, int mod=DEFAULT_MOD) : n(n), mod(mod), d(n+1) {}

  void init(int size) {
      n = size;
      d = std::vector<T>(size);
  }

  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
      if (mod) {
          d[i] %= mod;
      }
    }
  }

  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
      if (mod) {
          x %= mod;
      }
    }
    return x;
  }

  T range(int from, int to) {
      T x = sum(to) - sum(from-1);
      if (mod) {
          x = (x + mod) % mod;
      }
      return x;
  }

  T val(int i) {
      return range(i, i);
  }
};

typedef BIT<int, 512> Bit;

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

    int N, M, Q;
    cin >> N >> M >> Q;

    vector<Bit> rBit(N);

    rep(i, M) {
        int L, R;
        cin >> L >> R;
        --L; --R;
        rBit[L].add(R);
    }

    rep(i, Q) {
        int p, q;
        cin >> p >> q;
        --p; --q;
        int ans = 0;
        for (int l = p; l <= q; ++l) {
            ans += rBit[l].range(l, q);
        }
        cout << ans << '\n';
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void)
{
	int n;
	int i = 0;
	int *table1, *value;
	int newvalue1, newvalue2;
	
	scanf("%d",&n);
	table1 = (int*)malloc(sizeof(int)*n);
	value = (int*)malloc(sizeof(int)*n);

	while(i < n)
	{
		scanf("%d",&table1[i]);
		i++;
	}
	
	value[0] = 0;
	value[1] = abs(table1[1]-table1[0]);
	
	i = 2;
	while(i != n){
		newvalue1 = value[i-2] + abs(table1[i-2] - table1[i]);
		newvalue2 = value[i-1] + abs(table1[i-1] - table1[i]);
		if(newvalue1 > newvalue2)
		{
			value[i] = newvalue2;
		}else
		{
			value[i] = newvalue1;
		}
		i++;
	}

	printf("%d",value[n-1]);

	free(table1);
	free(value);
	return 0;
}

Measured memory_bytes: 2224
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char a[101];
int main()
{
	scanf("%s",a);
	if(a[2]==a[3]&&a[4]==a[5]&&a[0]!=a[1])
	{
		printf("Yes\n");	
	}else{
		printf("No\n");	
	}
	return 0;
}



Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main(){
    long long int n; cin >> n;
    long long int ans=0,i,k;
    if(n==1){
        cout << ans << endl;
        return 0;
    }
    for(i=1;i*i<=n;i++){
        if(n%i==0){
            k=n/i-1;
            if(n/k == n%k) ans += k;
            if(n/i!=i&&i>1){
                k=i-1;
                if(n/k==n%k) ans += k;
                }
            }
        }
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;
using ll = long long;

int main(void) {
  string s;
  cin >> s;
  for (int n = s.size() - 1; n > 0; n--) {
    if (n % 2 != 0) {
      continue;
    }
    s.erase(n);
    if (s.substr(n/2) == s.substr(0, n/2)) {
      cout << n << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

string s;
int x, y;

bool check(vector<int> &v, int tar) {
	int sum = 0;
	REP(i, v.size()) sum += v[i];
	bitset<10000> bs(1);
	REP(i, v.size()) bs |= bs << v[i];
	
	REP(i, 10000) if (bs[i] && i*2 - sum == tar) return true;
	return false;
}

int main() {
	cin >> s >> x >> y;
	
	int p = 0;
	while (p < s.size() && s[p] == 'F') x--, p++;
	
	vector<int> v[2]; // 0:x, 1:y
	int t = 0;
	
	while (p < s.size()) {
		t ^= 1; p++;
		
		int cnt = 0;
		while (p < s.size() && s[p] == 'F') cnt++, p++;
		v[t].push_back(cnt);
	}
	
	if (check(v[0], x) && check(v[1], y)) puts("Yes");
	else puts("No");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;;
int main(){
  int a,y,x=0,n,l;
  cin >> n>>l;
  for(int i=0;i<n;i++){
    x+=i+l;
    if(l<0){
      if(a*-1>i+l)a=i+l;
    }
  }
  if(l<=0){
    x-=a;
  }
  else{
    x-=l;
  }
  cout << x << endl;
}

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

int main(void) {
    int n, b, f, r, v, i, j, k;
    int ls[4][3][10];
    cin >> n;

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 10; k++) {
                ls[i][j][k] = 0;
            }
        }
    }

    for (i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        ls[b-1][f-1][r-1] += v;
    }

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 10; k++) {
                cout << " " << ls[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) cout << "####################" << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 200005;
int fac[N], ifac[N];
int pwr(int b, int e)
{
	int ans = 1;
	while (e)
	{
		if (e & 1)
			ans = (1LL * ans * b) % MOD;
		b = (1LL * b * b) % MOD;
		e >>= 1;
	}
	return ans;
}
void pre()
{
	fac[0] = ifac[0] = 1;
	for (int i = 1; i < N; ++i)
	{
		fac[i] = (1LL * i * fac[i - 1]) % MOD;
		ifac[i] = (1LL * pwr(i, MOD - 2) * ifac[i - 1]) % MOD;
	}
}
int ncr(int n, int r)
{
	if (r > n)
		return 0;
	int ans = fac[n];
	ans = (1LL * ans * ifac[r]) % MOD;
	ans = (1LL * ans * ifac[n - r]) % MOD;
	return ans;
}
int main(int argc, char const *argv[])
{
	pre();
	int n, m, k, ans = 0;
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i <= k; ++i)
	{
		int c, mul;
		c = ncr(n - 1, i);
		mul = (1LL * m * pwr(m - 1, n - 1 - i)) % MOD;
		c = (1LL * c * mul) % MOD;
		ans = (1LL * ans + c) % MOD;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 5332
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();
		int primeNum = 0;

		for(int i = 0; i < n; i++) {

			int num = sc.nextInt();

			if(isPrime(num)) {
				primeNum++;
			}
		}
		System.out.println(primeNum);
	}

	static boolean isPrime(int num) {

		if(num == 2) {
			return true;
		}

		if(num % 2 == 0) {
			return false;
		}

		int i = 3;
		while(i <= Math.sqrt(num)) {

			if(num % i == 0) {
				return false;
			}

			i += 2;
		}

		return true;
	}
}


Measured memory_bytes: 40912
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll dp[100010];
ll h[100010];
void solve() {

	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> h[i];
	}

	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	if (N >= 3)  dp[3] = min(abs(h[3] - h[1]), abs(h[3] - h[2]) + dp[2]);
	for (int i = 4; i <= N; i++) {
		dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
	}

	cout << dp[N] << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep (i, n) cin >> a[i];

  ll pre = 0;
  rep (i, n - 1) {
    pre = a[i] - pre;
  }
  vl b(n);
  b[0] = (a[n - 1] - pre);
  rep1 (i, n - 1) {
    b[i] = (a[i - 1] - b[i - 1] / 2) * 2;
  }
  rep (i, n) {
    cout << b[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int m;
void link(int x,int y){printf("%d %d\n",x,y);++m;}

int main()
{
	file();
	int n;read(n);
	if ((n&(-n))==n) return puts("No"),0;
	puts("Yes");
	if (n%4==3)
	{
		rep(i,2,n+n) link(i-1,i);
		assert(m==n+n-1);
		return 0;
	}
	if (n%4==1)
	{
		rep(i,2,n-2) link(i-1,i);
		link(n-2,n+1);
		rep(i,2,n-2) link(n+i-1,n+i);
		link(n,1),link(n-1,n);
		link(n+n-1,1),link(n+n,n+n-1);
		assert(m==n+n-1);
		return 0;
	}
	if (n%4==2)
	{
		rep(i,2,n-3) link(i-1,i);
		link(n-3,n+1);
		rep(i,2,n-3) link(n+i-1,n+i);
		link(n-2,1),link(n-1,n-2);
		link(n-1+n,1),link(n-2+n,n-1+n);
		link(n,2),link(n+n,n-1+n);
		assert(m==n+n-1);
		return 0;
	}
	rep(i,2,n-5) link(i-1,i);
	link(n-5,n+1);
	rep(i,2,n-5) link(n+i-1,n+i);
	link(n-4,1),link(n-3,n-4);
	link(n-3+n,1),link(n-4+n,n-3+n);
	link(n-2,2),link(n-2+n,n-3+n);
	int x=n&(-n);
	link(n-1,x-1),link(n,n-1),link(n+n,x),link(n+n-1,n+n);
	assert(m==n+n-1);
	return 0;
}

Measured memory_bytes: 2816
import java.util.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long t = 0;
        long ans = 1;
        for(int i=0; i<n; i++){
            t = sc.nextLong();
            ans = lcm(ans, t);
        }
        System.out.println(ans);
    }
    public static long gcd(long a, long b){
        while(true){
            if(a == 0) return b;
            b %= a;
            if(b == 0) return a;
            a %= b;
        }
    }
    public static long lcm(long a, long b){
        if(gcd(a, b) > 0){
            return a/gcd(a,b)*b;
        }else{
            return 0;
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  long long ans = 0;
  rep(i,n+1) cin >> a[i];
  rep(i,n){
    int b;
    cin >> b;
    ans += min(a[i+1]+a[i],b);
    a[i+1] = clamp(a[i+1]+a[i]-b,0,a[i+1]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3788
N,M=map(int,input().split(' '))
H=list(map(int,input().split(' ')))
AB = [list(map(lambda x:int(x)-1,input().split(' '))) for i in range(M)]
l = [[] for i in range(N)]
for A,B in AB:
    l[A].append(H[B])
    l[B].append(H[A])
ans = 0
for n,i in enumerate(H):
    if (not l[n]) or i > max(l[n]):
        ans += 1
print(ans)

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

int main(){
    int n, m; cin >> n >> m;
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans++;
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = i+1; j < m; j++){
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 2000010;

int a[N], st[N];

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int main() {
    int n;
    cin >> n;
    int sgcd;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        if (i == 1) sgcd = a[i];
        sgcd = gcd(a[i], sgcd);
        ++st[a[i]];
    }
    bool F = true, S = sgcd == 1;
    for (int i = 2; i < N; ++i) {
        int sum = 0;
        for (int j = i; j < N && F; j += i) sum += st[j];
        if (sum > 1) F = false;
    }
    if (F) puts("pairwise coprime");
    else if (S) puts("setwise coprime");
    else puts("not coprime");
    return 0;
}

Measured memory_bytes: 11412
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        double ans = 1;
        for (int i = 1; i < x; i++) {
            for (int j = 2; j < x; j++) {
                if (Math.pow(i, j) > x)
                    break;
                else
                    ans = Math.max(ans, (Math.pow(i, j)));
            }
        }
        System.out.println((int) ans);
    }
}

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

int main(){
  int a,b,c,d,e,T;
  cin >> a >> b >> c >> d >> e;
  T = (c*60+d) - (a*60+b);
  cout << T-e;
  
  return 0;
  
}
  


Measured memory_bytes: 3144
#include <iostream>
using namespace std;
int main(void){
    string S;
    cin>>S;
    long long N,i,sum;
    N=S.length();
    sum=0;
    for(i=0;i<N;i++){
        if(i%2==0){
            if(S[i]=='0'){
                sum++;
            }
        }else{
            if(S[i]=='1'){
                sum++;
            }
        }
    }
    sum=min(sum,N-sum);
    cout<<sum<<endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> xs(n);
    for (auto& x : xs) {
        cin >> x;
    }
    long long best = xs[0] + xs[n-1];
    for (int c = 1; 2*c < n-1; ++c) {
        long long current = xs[0] + xs[n-1];
        int i = 0, j = n-1;
        while (true) {
            i += c;
            if (i == j) {
                break;
            }
            j -= c;
            if (i == j || j <= c) {
                break;
            }
            current += xs[i] + xs[j];
            best = max(best, current);
        }
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
import math
N = input()
A = list(map(int, input().split()))

count = 0
while True:
    for i, a in enumerate(A):
        if a % 2 == 0:
            A[i] = a / 2
        else:
            print(count)
            exit()
    count = count + 1



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

int main() {

	int n; cin >> n;
	int h_max = 0;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		h_max = max(h_max, h[i]);
	}
	vector<vector<int>> c(h_max, vector<int>(n));
	for (int j = 0; j < n; j++) {
		for (int i = 0; i < h_max; i++) {
			if (i <= h[j] - 1) c[i][j] = 1;
		}
	}
	int ans = 0;
	for (int i = h_max - 1; i >= 0; i--) {
		for (int j = 1; j < n; j++) {
			if (c[i][j - 1] == 1 && c[i][j] == 0) {
				ans++;
			}			
		}
		if (c[i][n - 1] == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void){
  int i=0;
  char O[51]={'\0'},E[51]={'\0'};
  char pass[103]={'\0'};
  scanf("%s",O);
  scanf("%s",E);
  while(O[i/2]!='\0' || E[i/2]!='\0'){
    if(i%2==0){
      pass[i]=O[i/2];
    }else{
      pass[i]=E[i/2];
    }
    i++;
  }
  printf("%s\n",pass);
  return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    int m500, m5;
    m500 = x / 500;
    x -= 500*m500;
    m5 = x / 5;
    x -= 5*m5;

    cout << 1000*m500+5*m5 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<ll> ldp(n + 2, 0), rdp(n + 2, 0);
    ll idx = -c - 1;
    rep(i, n) {
        ldp[i + 1] = ldp[i];
        if ((s[i] == 'o') && (idx < (i - c))) {
            ldp[i + 1]++;
            idx = i;
        }
    }
    idx = n + c + 1;
    rrep(i, n) {
        rdp[i + 1] = rdp[i + 2];
        if ((s[i] == 'o') && (idx > (i + c))) {
            rdp[i + 1]++;
            idx = i;
        }
    }
    ldp[n + 1] = ldp[n];
    rdp[0] = rdp[1];
    vector<ll> ans;
    rep(i, n) {
        if ((ldp[i] + rdp[i + 2]) < k) ans.push_back(i + 1);
    }
    rep(i, sz(ans)) printf("%lld\n", ans[i]);
    return 0;
}


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

int main(){
    long long n,k;
    cin >> n >> k;
    int p = 1;
    double ret = 0;
    for(int i = n;i >= 1;i--){
        while(i*p < k){
            p*=2;
        }
        ret += 1.0 / p;
    }
    ret /= n;
    cout << setprecision(12);
    cout << ret << endl;
}

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

using namespace std;

int main() 
{

    string s,t;
    cin>>s;
    cin>>t;
    int x=0;
    if((s.length()+1)!=t.length())cout<<"No"<<endl;
    else
    {
        for(int i=0;i<s.length();i++)
        {
            if(s[i]!=t[i])x=1;
        }
        if(x==0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    ll N, K, S; cin >> N >> K >> S;
    vector<ll> a(N);
    rep(i, K) a[i] = S;

    if(N-K < S) {
        repr(i, K, N) a[i] = 1;
    } else {
        repr(i, K, N) a[i] = 1e9;
    }

    for(int i=0; i<N; ++i) {
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(){
	int a,b;
	int max = 0;

	scanf("%d",&a);
	scanf("%d",&b);

	max = a + a - 1;
	if((a+b) > max) max = a + b;
	if((b+b-1) > max) max = b + b - 1;

	printf("%d\n",max);

	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static int tc=1;
    static String[] s;

    public static long[] ila(String[] s){
        long[] array=new long[s.length];
        for(int i=0;i<array.length;i++)
            array[i]=Long.parseLong(s[i]);
        return array;
    }
    public static long calculate(int val){
    	return ((long)val*(val-1))>>1;
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        tc=1;
        t:
        for(int z=1;z<=tc;z++){
        	int n = Integer.parseInt(br.readLine());
        	HashMap<Integer,Integer> hm=new HashMap<>();
        	String[] s=br.readLine().split(" ");
        	for(int i=0;i<n;i++){
        		int x = Integer.parseInt(s[i]);
        		if(hm.containsKey(x))
        			hm.put(x,hm.get(x)+1);
        		else
        			hm.put(x,1);
        	}
        	long ans = 0;
        	for(Map.Entry<Integer,Integer> x : hm.entrySet()){
        		int val = x.getValue();
        		if(val > 1 )
        		ans += calculate(val);
        	}
        	long actual =0;
        	long calc=0;
        	for(int i=0;i<n;i++){
        		int x = Integer.parseInt(s[i]);
        		int val = hm.get(x);
        		if(val==1){
        		System.out.println(ans);
        		continue;
        		}
        		actual = calculate(val);
        		if(val==2){
        		System.out.println(ans-actual);
        		continue;
        		}
        		calc = calculate(val-1);
        		System.out.println(ans-actual+calc);
        	}
        }
    }
}


Measured memory_bytes: 112520
package main

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

var sc = bufio.NewScanner(os.Stdin)
var inf = 1 << 32
var cnt int

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func mergeSort(A []int, left, right int) {
	if left + 1 < right {
		mid := (left + right) / 2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)
	}
}

func merge(A []int, left, mid, right int) {
	n1 := mid - left
	n2 := right - mid

	L := make([]int, n1 + 1)
	R := make([]int, n2 + 1)

	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}

	L[n1] = inf
	R[n2] = inf

	var i, j int
	for k := left; k < right; k++ {
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
		} else {
			A[k] = R[j]
			j++
			cnt += n1 - i
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	A := make([]int, n)
	for i := 0; i < n; i++ {
		A[i] = nextInt()
	}

	mergeSort(A, 0, n)
	fmt.Println(cnt)
}


Measured memory_bytes: 7912
N = int(input())
xy = [[-1 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        xy[i][x-1] = y

ans = -1
for tf in range((1 << N)):
    
    ls = [0 for i in range(N)]
    for i in range(N):
        if 1 & (tf >> i):
            ls[i] = 1

    can = True
    for j in range(N):
        if ls[j] == 1:
            for k in range(N):
                if xy[j][k] == -1: continue
                if xy[j][k] != ls[k]: can = False

    if can: ans = max(ans, ls.count(1))

print(ans)

Measured memory_bytes: 3064
import numpy as np
a,b,x=list(map(int,input().split()))

if a*a*b == x:
  print(0.0)
else:
  if x <= b*a*a/2:
    l =  2*x/(a*b)
    ans = np.arctan(b/l)
  else:
    l=2*x/a**2-b
    ans=np.arctan((b-l)/a)
  print(180.0*ans/np.pi)

Measured memory_bytes: 12484
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll A, B, C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
void TwoCoins() {
	cin >> A >> B >> C;
	cout << ((A + B) >= C ? "Yes" : "No") << endl;
}
int main() {
	TwoCoins();
	return 0;
}


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

#define ll       long long
#define ull      unsigned ll
#define pii      pair<int, int>
#define pll      pair<ll, ll>
#define mp       make_pair
#define ff       first
#define ss       second
#define sz(x)    (int) x.size()
#define all(v)   v.begin(), v.end()

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}

template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}

const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;

const double pi = acos(-1.0);

int solve() {
    int r; Int(r);
    printf("%.10f\n", 2.0 * pi * r);
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1, tc = 0;
    //Int(test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}


Measured memory_bytes: 3764
#include <iostream>

using namespace std;

int main(){
	int x,a,b;
	cin>>x>>a>>b;
	if(a>=b){
		cout<<"delicious"<<endl;
	}
	else if(a+x>=b){
		cout<<"safe"<<endl;
	}
	else {
		cout<<"dangerous"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll tp; cin>>tp; while(tp--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    ll c=2,ans=0,tmp;
    while(n>=c*c){
        tmp=c;
        while(n%tmp==0){
            n/=tmp;
            ans++;
            tmp*=c;
        }
        while(n%c==0){
            n/=c;
        }
        c++;
    }
    if(n>1)
        ans++;
    cout<<ans;
}

Measured memory_bytes: 3664
X, K, D = map(int, input().split())
X = abs(X)
if K < X//D:
    ans = X - K * D
else:
    K -= X//D
    X -= (X//D) * D
    if K%2 == 0:
        ans = X
    else:
        ans = abs(X-D)
print(ans)

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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = RLong();
            long[] a = RArLong();

            long cntMinus = a.Count(x => x < 0);

            long res = 0;
            res = a.Sum(x => Math.Abs(x));
            if (cntMinus % 2 != 0)
            {
                long absMin = a.Select(x => Math.Abs(x)).OrderBy(x => x).First();
                res -= absMin * 2;
            }
            Console.WriteLine(res);
        }
        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: 31580
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
string s;
bool dp[505][505];
/**********************************************/

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

    cin >> s;

    int n = s.size();
    REP(i, n) REP(j, n) dp[i][j] = false;
    REP(i, n) dp[i][i] = true;

    for(int i = 0; i < n-2; i++){
        if(s.substr(i, 3) == "mew") dp[i][i+2] = true;
    }
    for(int len = 6; len <= n; len += 3){
        REP(l, n){
            int r = l + len - 1;
            if(r > n) break;

            // m ok e ok w
            for(int c = l+1; c < r; c++){
                if(s[l] == 'm' && s[c] == 'e' && s[r] == 'w'){
                    if(l != c-1 && !dp[l+1][c-1]) continue;
                    if(c != r-1 && !dp[c+1][r-1]) continue;
                    dp[l][r] = true;
                }
            }
        }
    }
    if(dp[0][n-1]) cout << "Cat" << endl;
    else cout << "Rabbit" << endl;
}



Measured memory_bytes: 3452
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

bool judge(ll a[], int mid,int n){
    ll sum=0;
    for (int i=0; i<=mid; i++){
        sum+=a[i];
    }
    int j=mid+1;
    while (j<n && 2*sum>=a[j]){
        sum+=a[j];
        j++;
        if (sum>=a[n-1]){
            return true;
        }
    }
    return false;
}

int binary_search(ll a[],int left,int right,int n){
    if (left+1>=right){//ラスト1個
        if (judge(a,left,n)){
            return left;
        }else {
            return right;
        }
    }
    int mid=(left+right)/2;
    if (judge(a,mid,n)){
        binary_search(a,left,mid,n);
    }else {
        binary_search(a,mid,right,n);
    }
}

int main(){
    int n;
    cin >> n;
    ll a[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int k=binary_search(a,0,n,n);
    cout << n-k << endl;
}

Measured memory_bytes: 1024
# coding:utf-8

N, K = map(int, input().split())
H = [int(hi) for hi in input().split()]
dp = [0]*(N+1)


for i in range(1, K+1):
    if i <= N-1:
        dp[i] = abs(H[0]-H[i])

for i in range(K+1, N):
    dp[i] = min([dpk + abs(hk - H[i]) for dpk, hk in zip(dp[i-K:i], H[i-K:i])])


print(dp[N-1])

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

using namespace std;

#define pb push_back
#define mp make_pair
#define bin(x,b) bitset<b> vb(x); cout << vb << '\n';

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

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

const long double EPS = 1e-10;
const ll MOD = 1e9 + 7;
const long double PI = 3.1415926535897932384626433832795028841;

ll powmod(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}


const int maxn = 1e5 + 5;
const int maxm = 1e5 + 5;
const int maxk = 1e5 + 5;

bool has_digit(int i,int a,int b){
	int sum = 0;
	while (i > 0){
		sum += i% 10;
		i /= 10;
	}
	return a <= sum && sum <= b;
}

int main(){
	int n,a,b; cin >> n >> a >> b;
	int sum = 0;
	for (int i = 1;i <= n;i++){
		if (has_digit(i,a,b)) sum += i;
	}
	cout << sum << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

// {{{ Modint
// mint x = 2;
// mint y = mint::P(5, 2);
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
 public:
  int64_t a;
  static std::vector<modint> fact;
  static std::vector<modint> inv_fact;
  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  static modint P(ll n, ll k) {
    if (fact.size() == 0) {
      const ll T = 3000000;
      fact.resize(T, modint(1));
      inv_fact.resize(T, modint(1));
      for (ll i = 2; i < T; i++) fact[i] = fact[i-1] * modint(i);
      for (ll i = 2; i < T; i++) inv_fact[i] = inv_fact[i-1] / modint(i);
    }
    if (n < k) return modint(0);
    if (n < 0 || k < 0) return modint(0);
    return fact[n] * inv_fact[n - k];
  }

  static modint C(ll n, ll k) {
    if (n < k) return modint(0);
    if (n < 0 || k < 0) return modint(0);
    return P(n, k) * inv_fact[k];
  }
};
template <std::int64_t M>
std::vector<modint<M>> modint<M>::fact;
template <std::int64_t M>
std::vector<modint<M>> modint<M>::inv_fact;
// }}}

using mint = modint<1000000007>;
void solve() {
  ll N;
  cin >> N;
  vector<mint> a(N);
  rep(i, N) {
    ll x;
    cin >> x;
    a[i] = mint(x);
  }
  mint ans(0);
  auto p = a[0];
  for (ll i = 1; i < N; i++) {
    ans += p * a[i];
    p += a[i];
  }
  cout << ans.value() << endl;
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 4840
h,w,d = gets.split.map(&:to_i)
a = []
h.times do
  a << gets.split.map(&:to_i)
end
num = Array.new(h*w,nil)
(h*w).times do |i|
  k = a[i/w][i % w]
  num[k] = [i/w,i % w]
end
arr = []
1.upto(d) do |i|
  arr[i] = 0
  j = i
  while j <= h*w-d
    arr[j+d] = arr[j] + (num[j+d][0] - num[j][0]).abs + (num[j+d][1] - num[j][1]).abs
    j += d
  end
end
#p arr
q = gets.to_i

q.times do
  l,r = gets.split.map(&:to_i)
  puts arr[r] - arr[l]
end


Measured memory_bytes: 11844
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e5 + 10;
const long long inf = 1e17 + 7;

int n, E, T, d[N];

struct node {
	int l, r;
	long long max;	
};
	
struct segTree {
	node h[N << 2];
	int p[N];
	
	void build(int x, int l, int r) {
		h[x].l = l; h[x].r = r; h[x].max = -inf;
		if (l == r) {
			p[l] = x;
			return;
		}
		int m = (l + r) / 2, L = x * 2, R = L + 1;
		build(L, l, m); build(R, m + 1, r);
	}
	void init(int n) {
		build(1, 1, n);
	}
	
	void modify(int x, int l, int r, long long k) {
		if (l > r) return;
		if (h[x].l == l && h[x].r == r) {
			h[x].max = max(h[x].max, k);
			return;	
		}
		
		int m = (h[x].l + h[x].r) / 2;
		int L = x * 2, R = L + 1;
		h[L].max = max(h[L].max, h[x].max);
		h[R].max = max(h[R].max, h[x].max);
		
		if (r <= m) modify(L, l, r, k);
		else if (l >= m + 1) modify(R, l, r, k);
		else {
			modify(L, l, m, k);
			modify(R, m + 1, r, k);	
		}
	}
	
	long long getmax(int id) {
		int x = p[id];
		long long res = -inf;
		while (x) {
			res = max(res, h[x].max);
			x /= 2;
		}
		return res;
	}
} a, b;

int Find(int l, int r, long long k) {
	while (l < r) {
		int m = (l + r) / 2;
		if (m == n + 1 || 2 * d[m] >= k) r = m;
		else l = m + 1;
	}
	return l;
}

int main() {
	scanf("%d%d%d", &n, &E, &T);
	d[0] = 0;
	for (int i = 1; i <= n; i++)
		scanf("%d", &d[i]);	
	a.init(n); b.init(n);
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		int t;
		t = Find(i, n + 1, 1LL * T + 2 * d[i]);
		//printf("...%d %d\n", i, t);
		a.modify(1, i, t - 1, ans - 2 * d[i - 1] - T);
		b.modify(1, t, n, ans + 2 * d[i] - 2 * d[i - 1]);
		ans = max(a.getmax(i) + 2 * d[i], b.getmax(i));
		//printf("%d %lld\n", i, ans);
	}
	//printf("%lld\n", ans);
	printf("%lld\n", -ans + 2 * d[n] + E);
	return 0;
}


Measured memory_bytes: 13312
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    a,b,c=map(int,input().split())
    print("bust") if a+b+c>=22 else print("win")




#  print(c)




            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064