akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define next Next
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=20;
const LL INF=1e18;
int n;
int a[N];
LL dp[N][N][1<<18];
pii p[1<<18];
LL DP(int L,int R,int s){
	LL &v=dp[L][R][s];
	if (~v)
		return v;
	if (L+1==R)
		v=0;
	else {
		v=INF;
		For(m,L+1,R-1)
			v=min(v,DP(L,m,s<<1|1)+DP(m,R,s<<1)+(LL)a[m]*(p[s].fi+p[s].se));
	}
//	printf("DP(%d,%d,(%d,%d)) = %lld\n",L,R,p[s].fi,p[s].se,v);
	return v;
}
int main(){
	n=read();
	For(i,0,n-1)
		a[i]=read();
	p[1]=mp(1,1);
	For(i,2,(1<<n)-1){
		p[i]=p[i>>1];
		if (i&1)
			p[i].se+=p[i].fi;
		else
			p[i].fi+=p[i].se;
	}
	memset(dp,-1,sizeof dp);
	cout<<DP(0,n-1,1)+a[0]+a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 821632
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;


int main(void){
 int x;
 cin>>x;
 if(x==7 || x==5 || x==3)cout<<"YES"<<endl;
 else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, W;
  cin >> N >> W;

  ll w[N+1];
  ll v[N+1];

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

  ll dp[N+1][W+1];
  for (int i = 0; i <= N; i++) {
      dp[i][0] = 0;
  }
  for (int i = 0; i <= W; i++) {
      dp[0][i] = 0;
  }
  for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= W; j++) {
          if (w[i] > j) {
              dp[i][j] = dp[i-1][j];
          } else {
              dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
          }
      }
  }
//   for (int i = 0; i <= N; i++) {
    //   for (int j = 0; j <= W; j++) {
        //   cout << dp[i][j] << " ";
    //   }
    //   cout << "\n";
//   }
  cout << dp[N][W] << "\n";

  return 0;
}

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

int main(){
	string s;
	cin>>s;
	if(s[3]==s[2]&&s[5]==s[4])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
 	li n;

 	cin>>n;

 	li a[n];

 	f(i,0,n-1)
 	{
 		cin>>a[i];
 	}   

 	li ans=0;

 	f(i,1,n-1)
 	{
 		if(a[i]<a[i-1])
 		{
 			ans+=(a[i-1]-a[i]);
 			a[i]=a[i-1];
 		}
 	}

 	cout<<ans;
}

int main()
{    
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 5180
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    a = a + b;
    int n = Integer.parseInt(a);
    for(int i = 1;i<=1000;i++){
      if(n == i*i){
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5+5;
const int mod = 1e9+7;

int n, k, ans = INT_MAX;

void backtrack(int count, int num) {
	if (count == n) {
		ans = min(num, ans);
		return;
	}

	backtrack(count+1, num*2);
	backtrack(count+1, num+k);
}

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//#ifndef ONLINE_JUDGE
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//#endif

	cin >> n >> k;
	backtrack(0, 1);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define M 1000000007
#define deb(x) cout<<#x<<'='<<x<<endl
using namespace std;
const int N=1e6;
signed main()
{
    int r;
    cin>>r;
    double pi=(floor(22)/floor(7));
    double area=pi*r*2;
    cout<<area<<endl;

}

Measured memory_bytes: 3784
#include<stdio.h>

int main(void){


int W,H,x,y,r;


scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


if(H>=y+r&&W>=x+r&&x-r>=0&&y-r>=0)


{


printf("Yes\n");


}


else


{


printf("No\n");


}


return 0;


}

Measured memory_bytes: 584
using System;

namespace _6_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var n = nm[0];
            var m = nm[1];
            var mat = new int[n, m];
            for(var i=0;i<n;i++)
            {
                var s = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                for (var j=0;j<m;j++)
                {
                    mat[i, j] = s[j];
                }
            }
            var sum = 0;
            var row = new int[m];
            for(var i=0;i<m;i++)
            {
                row[i] = int.Parse(Console.ReadLine());
            }
            for(var i=0;i<n;i++)
            {
                sum = 0;
                for(var j=0;j<m;j++)
                {
                    sum += mat[i, j] * row[j];
                }
                Console.WriteLine(sum);
            }
        }
    }
}



Measured memory_bytes: 18012
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a<=100&&a>=1&&b<=100&&b>=1&&c<=100&&c>=1)
    {
    if(a+b==c||a+c==b||b+c==a)
    {
        cout << "Yes";
    }
    else cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from math import hypot
while True:
    d, e = map(int, input().split())
    if d == 0:
        exit()
    ans = 1e5
    for x in range(d + 1):
        y = d - x
        ans = min(ans, abs(hypot(x, y) - e))
    print(ans)



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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert

ll n,m,k;
ll a[15][1005];
ll cur[15];
ll tmp[15];

void solve(){
    cin>>n>>m>>k;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            char ch;
            cin>>ch;
            a[i][j] = ch-'0';
        }
    }
    ll ans=oo;
    for(ll mask=0; mask < (1<<(n-1));mask++){

        ll cuts = __builtin_popcount(mask);
        memset(cur,0,sizeof cur);
        ll flg=1;
        for(ll j=0; j<m and flg ; j++){
            ll ind=0;
            memset(tmp,0,sizeof tmp);
            for(ll i=0;i<n;i++){
                tmp[ind] += a[i][j];
                if((mask>>i)&1)
                    ind++;
            }
            for(ll i=0;i<n;i++){
                if(tmp[i] > k){
                    flg=0;
                    break;
                }
            }

            bool mark=0;
            for(ll i=0;i<n;i++){
                if(cur[i] + tmp[i] > k)
                    mark = 1;
            }
            cuts += mark;
            if(mark){
                for(ll i=0;i<n;i++)
                    cur[i] = tmp[i];
            }
            else{
                for(ll i=0;i<n;i++)
                    cur[i] += tmp[i];
            }

        }
        if(flg)
            ans = min(ans,cuts);
    }

    cout << ans << endl;

}

int main() {
    
    IOS;
    int T=1;
    //cin >> T;
    while(T --){
        solve();
    }
}

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<int> num = {x, y, z};
  vector<ll> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  priority_queue<Data> pq;
  set<Data> st;

  auto add = [&](Data d) {
    int s = d.second[0];
    int t = d.second[1];
    int u = d.second[2];
    rep(i, 3) {
      vector<int> soeji({s, t, u});
      soeji[i]++;
      if(soeji[i] >= num[i]) continue;
      ll sum = a[soeji[0]] + b[soeji[1]] + c[soeji[2]];
      Data d = Data(sum, soeji);
      if(!st.count(d)) st.insert(d), pq.push(d);
    }
  };
  ll sum = a[0] + b[0] + c[0];
  pq.push(Data(sum, vector<int>(3, 0)));
  st.insert(Data(sum, vector<int>(3, 0)));

  rep(i, k) {
    Data d = pq.top(); pq.pop();
    cout << d.first << endl;
    add(d);
  }
}

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

int N;
vector<long long> A(200010, 0);
vector<long long> NA(200010, 0);
long long SA = 0;

int main(){
  cin >> N;
 
  for(int i = 0; i < N; i++){ cin >> A[i]; ++NA[A[i]]; }
  for(int i = 1; i <= N; i++) SA += NA[i] * (NA[i]-1) / 2;

  /*x番目のボールの番号はA[i]、個数はNA[A[i]]*/
  for(int i = 0; i < N; i++) cout << SA - NA[A[i]]+1 << endl;

  return 0;
  
}






Measured memory_bytes: 5760
a, b, c, d = [int(x) for x in input()]

for i in ['-1', '+1']:
    for j in ['-1', '+1']:
        for k in ['-1', '+1']:
            if a + int(i)*b + int(j)*c + int(k)*d == 7:
                print(str(a) + i[0] + str(b) + j[0] + str(c) + k[0] + str(d) + '=7')
                exit()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

int a,b,c,x,y;
int main(){
  std::cin>>a>>b>>c>>x>>y;
  
  long long ans=2*c*std::max<long long>(x,y);
  long long sum=2*c*std::min<long long>(x,y);
  if(x!=y){
    if(x>y)
      sum+=a*(x-y);
    else
      sum+=b*(y-x);
  }
  ans=std::min<long long>(sum,ans);
  ans=std::min<long long>(ans,a*x+b*y);
  
  std::cout<<ans<<std::endl;
  return 0;
}


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

const int am = 1e5;
int n, c[am], arr[2];

int main() {
	cin >> n;
	for (int i = 0, a; i < n; i++)
		cin >> a, a--, c[a]++;

	for (int i = 0; i < am; i++)
		if (c[i])
			arr[c[i] & 1]++;
	cout << arr[0] / 2 * 2 + arr[1] << endl;
}


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

#define _GLIBCXX_DEBUG

using _loop_ll = long long;
#define REP(i,n) for(_loop_ll (i)=0; (i)<(_loop_ll)(n); (i)++)
#define FOR(i,a,b) for(_loop_ll (i)=(_loop_ll)(a); (i)<(_loop_ll)(b); (i)++)
#define FORR(i,a,b) for(_loop_ll (i)=(_loop_ll)(b)-1; (i)>=(_loop_ll)(a); (i)--)
 
#define ALL(v) (v).begin(),(v).end()
 
#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

constexpr long long int MOD = 1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int k, x;
    cin >> k >> x;
    if(500 * k >= x){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }



    return 0;
};


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++) 
using namespace std;

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

void load() {
}

void solve() {
	int n; scanf("%d", &n);
	pii a[n]; FOR(i, n) {
		scanf("%d", &a[i].first);
		a[i].second = i + 1;
	}
	sort(a, a + n);
	FOR(i, n) printf("%d ", a[i].second); printf("\n");
}

int main() {
	load();
	solve();
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::string S)
{
    int cnt_white = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == '.')
            cnt_white++;
    }
    ll ans = INF;
    ll black = 0;
    ll white = 0;
    for (int i = 0; i < N; i++)
    {

        ans = min(ans, black + cnt_white - white);
        if (S[i] == '#')
        {
            black++;
        }
        else
        {
            white++;
        }
    }
    ans = min(ans, black + cnt_white - white);

    if (ans == INF)
    {
        ans = 0;
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 768
#include<cstdio>
#include<vector>
#define MAXN 100006
#include<algorithm>
using namespace std;
int d[MAXN],n,u,v;
vector<int> road[MAXN];
void DFS(int x,int fa)
{
	for(int i=0;i<(int)road[x].size();i++)
	{
		int nex=road[x][i];
		if(nex==fa) continue;
		DFS(nex,x);
		d[x]^=(d[nex]+1);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		road[u].push_back(v);
		road[v].push_back(u);
	}
	DFS(1,0);
	if(d[1]) printf("Alice");
	else printf("Bob");
}

Measured memory_bytes: 12416
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>

using namespace std;

int main(){
	int n;
	long long ans1 = 0LL, ans2 = 0LL;
	cin >> n;
	int m = n / 2;
	vector<long long> a(n), b(m), c(n - m), d(n), e(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	if(n == 2){
		cout << abs(a[0] - a[1]) << endl;
		return 0;
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < m; i++){
		b[i] = a[i];
	}
	for(int i = m; i < n; i++){
		c[i - m] = a[i];
	}
	for(int i = 0; i < n; i++){
		if(i % 2){
			d[i] = b[i / 2];
		} else{
			d[i] = c[i / 2];
		}
	}
	if(n == 3){
		swap(d[1], d[n - 1]);
	} else if(n % 2 == 1){
		swap(d[2], d[n - 1]);
	}
	if(n % 2 == 1){
		b.push_back(c[0]);
		c.erase(c.begin());
	}
	sort(b.begin(), b.end(), greater<long long>());
	sort(c.begin(), c.end(), greater<long long>());
	for(int i = 0; i < n; i++){
		if(i % 2){
			e[i] = c[i / 2];
		} else{
			e[i] = b[i / 2];
		}
	}
	if(n == 3){
		swap(e[1], e[n - 1]);
	}else if(n % 2 == 1){
		swap(e[2], e[n - 1]);
	}
	for(int i = 1; i < n; i++){
		ans1 += abs(d[i] - d[i - 1]);
		ans2 += abs(e[i] - e[i - 1]);
	}
	cout << max(ans1, ans2) << endl;
	return 0;
}

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

long long comb[60][60];

void make_comb_dp(long long n) {
    for (long long i = 0; i < n + 1; ++i) {
        for (long long j = 0; j < n + 1; j++) {
            comb[i][j] = 0;
        }
    }
    for (long long i = 0; i < n + 1; i++) {
        comb[i][0] = comb[i][i] = 1;
    }
    for (long long i = 2; i < n + 1; i++) {
        for (long long j = 1; j < i; j++) {
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
        }
    }
}

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        long long vv;
        cin >> vv;
        v.push_back(vv);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    double av = 0;
    long long sum, avc, sec, sep;
    sum = avc = sep = sec = 0;
    for (int i = 0; i < a; i++) {
        ++avc;
        sum += v[i];
    }
    av = sum / (double)avc;
    for (int i = a; i < n; i++) {
        if (v[i] == v[a - 1]) {
            ++sep;
        } else {
            break;
        }
    }
    for (int i = a - 1; i >= 0; i--) {
        if (v[i] == v[a - 1]) {
            ++sec;
            ++sep;
        } else {
            break;
        }
    }
    long long sel = 0;
    make_comb_dp(50);
    if (v[0] == v[a - 1]) {
        for (long long i = a; i <= min(b, sep); i++) {
            sel += comb[sep][i];
        }

    } else {
        sel = comb[sep][sec];
    }
    printf("%lf\n", av);
    cout << sel << endl;
}

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

long long x,ans,poww[60],cnt;

void dfs()
{
	if(!x) return ;
	ans+=poww[cnt++];
	x/=2;
	dfs();
}

int main()
{
	scanf("%lld",&x);
	poww[0]=1;
	for(int i=1;i<60;++i) poww[i]=poww[i-1]*2ll;
	dfs();
	printf("%lld",ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        Set<Integer> s = new HashSet<Integer>();
        s.add(3);
        s.add(5);
        s.add(7);
        if(s.contains(x))System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 22740
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int K = sc.nextInt();
        sc.nextLine();
        int A = sc.nextInt();
        int B = sc.nextInt();

        for (int i = A; i <= B; i++) {
            if (i % K == 0) {
                System.out.println("OK");
                System.exit(0);
            }
        }

        System.out.println("NG");

    }
}

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

using namespace std;

int main () {
    
    int n, w;
    cin >> n >> w;
    vector<vector<long long>> product(n+1, vector<long long>(2));
    for (int i = 1; i < n+1; ++i) {
        cin >> product[i][1] >> product[i][0];
    }
    vector<vector<long long>> dp(n+1, vector<long long>(w+1));
    for (int i = 1; i < n+1; ++i) {
        for (int j = 1; j < w+1; ++j) {
            // j represents the current max weight of bag
            // i represents the ith product
            long long wt = product[i][1];
            if (wt <= j) { // the i'th product can be picked
                dp[i][j] = max({dp[i][j],
                                product[i][0]+dp[i-1][j - wt],
                                dp[i-1][j]
                            });
            } else { // the i'th product cannot be picked
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str, sa, sb;

vector<ll> adj[maxn];
bool check;
struct dang
{
    ll val, sl;
};
dang st[maxn];
bool lt(const dang &x, const dang &y)
{
    return x.val < y.val;
}
ll ns, nsa, nsb;
void test()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
    }
    ans = 0;
    for(int i = 1; i <= m; i ++)
    {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i = 1; i <= n; i ++)
    {
        check = true;
        sort(adj[i].begin(), adj[i].end());
        for(int j = 0; j < adj[i].size(); j ++)
        {
            t = 1;
            while(adj[i][j] == adj[i][j+1] && j + 1 < adj[i].size())
            {
                ++t;
                ++j;
            }
            if(a[adj[i][j]] >= a[i])
            {
                check = false;
                break;
            }
        }
        if(check)
        {
            ++ans;
            //cout << i <<" ";
        }
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}



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

int main() {
  int N; cin >> N;
  int res=0;
  vector<int> vec(110);
  
  for(int i=0;i<N;++i) {
    int d=0;
    cin >> d;
    vec.at(d) = 1;
  }
  for(int i=0;i<110;++i) {
    if(vec.at(i)>0) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int str1 = sc.nextInt();
		int str2 = sc.nextInt();
		int str3 = sc.nextInt();
		if(str1 <= str3 && str3 <= str2){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	  }
	}

Measured memory_bytes: 21844
# D
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

# pop from left
popleft = [0]*(N+1)
A_LEFT = np.argsort(A[:(2*N)])
ind_left = 1
for i in range(N):
    while popleft[ind_left] > 0:
        ind_left += 1
    if A_LEFT[i] < N:
        popleft[ind_left] = A[A_LEFT[i]]
    else:
        popleft[max(ind_left, A_LEFT[i] - (N-1))] = A[A_LEFT[i]]
left_sum = np.cumsum(A)[(N-1):(2*N)] - np.cumsum(np.array(popleft))

# pop from right
popright = [0]*(N+1)
A_RIGHT = np.argsort(-A[::-1][:(2*N)])
ind_right = 1
for i in range(N):
    while popright[ind_right] > 0:
        ind_right += 1
    if A_RIGHT[i] < N:
        popright[ind_right] = A[3*N - 1 - A_RIGHT[i]]
    else:
        popright[max(ind_right, A_RIGHT[i] - (N-1))] = A[3*N - 1 - A_RIGHT[i]]
right_sum = np.cumsum(A[::-1])[(N-1):(2*N)] - np.cumsum(np.array(popright))

# print(popleft)
# print(popright)
res = (left_sum - right_sum[::-1]).max()
# extreme case
res1 = (np.sort(A[:2*N])[N:]).sum() - A[2*N:].sum()
res2 = A[:N].sum() - (np.sort(A[N:])[:N]).sum()
print(max(res, res1, res2))

Measured memory_bytes: 47368
//
//  minimum_spanning_tree.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/09.
//

#include <stdio.h>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>

#define EMAX 100010
#define VMAX 10010

using namespace std;

typedef long long ll;

struct Path
{
    int from,to,cost;
    
    bool operator<(const Path& rhs)const
    {
        return cost<rhs.cost;
    }
};

struct UF
{
    vector<int> par;
    
    UF(int n):par(n)
    {
        for(int i=0;i<n;i++) par[i]=i;
    }
    
    int root(int x)
    {
        if(par[x]==x) return x;
        else          return par[x]=root(par[x]);
    }
    
    void unite(int x,int y)
    {
        int rx=root(x);
        int ry=root(y);
        
        par[rx]=ry;
    }
    
    bool same(int x,int y)
    {
        int rx=root(x);
        int ry=root(y);
        
        return rx==ry;
    }
};

int main()
{
    int v,e;
    cin>>v>>e;
    vector<Path> p;
    for(int i=0;i<e;i++)
    {
        int s,t,w;
        cin>>s>>t>>w;
        p.push_back({s,t,w});
    }
    sort(p.begin(),p.end());
    UF uf(v);
    
    ll ans=0;
    for(int i=0;i<p.size();i++)
    {
        int from=p[i].from;
        int to=p[i].to;
        int cost=p[i].cost;
        
        if(!uf.same(from,to))
        {
            uf.unite(from,to);
            ans+=cost;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
 
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if ( (b-a)/2 >= k ) {
    rep (i, k) {
      cout << a + i << endl;
    }
    repr (i, k - 1 ) {
      cout << b - i << endl;
    }
  }
  else {
    rep (i, b - a + 1) {
      cout << a + i << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Khela_Sesh ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
const int sz=1e5+100;
int dp[sz][4];
int n,a[sz],b[sz],c[sz];
int cholo(int in,int prev)
{
    int &ret=dp[in][prev];
    if(~ret) return ret;
    if(in==n) return 0;
    ret=0;
    if(prev != 1) ret=max(ret,a[in]+cholo(in+1,1));
    if(prev != 2) ret=max(ret,b[in]+cholo(in+1,2));
    if(prev != 3) ret=max(ret,c[in]+cholo(in+1,3));
    return ret;
}
int main()
{
    Khela_Sesh
    int i,j,k,q,p,x,y,sum,ct,ct1,m,l,r,len,x1,y1,mn,t,mx;
    char ch;
    double d;
    string str1,str2;
    bool bl,bl1;
    while(cin>>n)
    {
        for(i=0;i<n;i++)   cin>>a[i]>>b[i]>>c[i];
        memset(dp,-1,sizeof dp);
        int tl=cholo(0,0);
        pf("%d\n",tl);
    }

}



Measured memory_bytes: 9216
#include <bits/stdc++.h> 
                      
using namespace std;  
                      
int main() {          
  int ans = 0;        
  int N, K;           
  cin >> N >> K;      
  for (int i = 0; i < N; i++) { 
    int h;            
    cin >> h;         
    if (h >= K) ans++; 
  }                   
  cout << ans << endl;
  return 0;           
}

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


int main()
{

    std::string str;
    std::stack<int> st;
    int tmp1, tmp2;

    while (std::cin >> str) {
        if (str[0] == '+') {
            tmp1 = st.top(); st.pop();
            tmp2 = st.top(); st.pop();
            st.push(tmp1+tmp2);
        }
        else if (str[0] == '-') {
           tmp1 = st.top(); st.pop();
           tmp2 = st.top(); st.pop();
           st.push(tmp2 - tmp1);

        }
        else if (str[0] == '*') {
            tmp1 = st.top(); st.pop();
            tmp2 = st.top(); st.pop();
            st.push(tmp1*tmp2);
        }
        else {
            tmp1 = std::atoi(str.c_str());
            st.push(tmp1);
        }
    }
    std::cout << st.top() << std::endl;
    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

int n, k;
int r, s, p;

int return_score(char c) {
  if (c == 'r') return p;
  else if (c == 's')
    return r;
  else
    return s;
}

void solve(istream& cin, ostream& cout) {
  string t;
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
  int ans = 0;
  REP(i, k) {
    char status = 'b';
    for (int j = i; j < n; j += k) {
      if (t[j] == status) {
        status = 'b';
        continue;
      } else {
        ans += return_score(t[j]);
        status = t[j];
      }
    }
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 512
/**
 * 
 */
import java.util.*;
/**
 * @author akira
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		while(scan.hasNextLine()){
			String str = scan.nextLine();
			String winner = "d";
			final int[][] winPattern = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
			for(int i = 0;i < winPattern.length;i++){
				if(str.charAt(winPattern[i][0]) != 's' && str.charAt(winPattern[i][0]) == str.charAt(winPattern[i][1]) && str.charAt(winPattern[i][0]) == str.charAt(winPattern[i][2])){
					winner = "" + str.charAt(winPattern[i][0]);
				}
			}
			System.out.println(winner);
		}
	}

}

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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		String[] tmpArray;
		Node[] nodes = new Node[n];
		for(int i = 0; i < n; i++){
			tmpArray = br.readLine().split(" ");
			
			int id = Integer.parseInt(tmpArray[0]);
			int left = Integer.parseInt(tmpArray[1]);
			int right = Integer.parseInt(tmpArray[2]);
			nodes[id] = new Node(id, left, right);
			nodes[id].nodes = nodes;
		}
		
		//?????¨???????????¨???????¨????
		for(int i = 0 ; i < nodes.length ; i++){
			if(nodes[i].left != -1){
				nodes[nodes[i].left].parent = i;
				nodes[i].degree++;
				if(nodes[i].right != -1){
					nodes[nodes[i].left].sibling = nodes[i].right; 
				}
			}
			if(nodes[i].right != -1){
				nodes[nodes[i].right].parent = i;
				nodes[i].degree++;
				if(nodes[i].left != -1){
					nodes[nodes[i].right].sibling = nodes[i].left;
				}
			}
		}
		
		//root??¢???
		int rootIdx = -1;
		for(int i = 0; i < nodes.length ;i++){
			if(nodes[i].parent == -1){
				rootIdx = i;
				break;
			}
		}
		//??????
		System.out.println("Preorder");
		preorder(nodes, rootIdx);
		System.out.println();
		System.out.println("Inorder");
		inorder(nodes, rootIdx);
		System.out.println();
		System.out.println("Postorder");
		postorder(nodes, rootIdx);
		System.out.println();
		
	}
	
	static void preorder(Node[] nodes, int index){
		System.out.print(" "+nodes[index].id);
		if(nodes[index].left != -1){
			preorder(nodes, nodes[index].left);
		}
		if(nodes[index].right != -1){
			preorder(nodes, nodes[index].right);
		}
	}
	
	static void inorder(Node[] nodes, int index){
		if(nodes[index].left != -1){
			inorder(nodes, nodes[index].left);
		}
		System.out.print(" "+nodes[index].id);
		if(nodes[index].right != -1){
			inorder(nodes, nodes[index].right);
		}
	}
	
	static void postorder(Node[] nodes, int index){
		if(nodes[index].left != -1){
			postorder(nodes, nodes[index].left);
		}
		if(nodes[index].right != -1){
			postorder(nodes, nodes[index].right);
		}		
		System.out.print(" "+nodes[index].id);
	}

}

class Node {
	int id;
	int left = -1;
	int right = -1;
	int parent = -1;
	int sibling = -1;
	int degree = 0;
	Node[] nodes;
	
	public Node (int id, int left, int right){
		this.id =id;
		this.left = left;
		this.right = right;
	}
	
	int getDepth (){
		if(parent == -1){
			return 0;
		}
		return 1 + nodes[parent].getDepth();
	}
	
	int getHeight (){
		if(left == -1 && right == -1){
			return 0;
		}
		
		int heightL = 0;
		if(left != -1){
			heightL = nodes[left].getHeight();
		}
		
		int heightR = 0;
		if(right != -1){
			heightR = nodes[right].getHeight();
		}
		
		return Math.max(heightL, heightR) + 1;
	}
	
	String getType (){
		if(parent == -1){
			return "root";
		}
		else if(left == -1 && right == -1){
			return "leaf";
		}
		else {
			return "internal node";
		}
	}
}

Measured memory_bytes: 24256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int mod;
// const int mod = 998244353;

struct mint {
  long long x;
  mint(long long x = 0) : x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint operator++() const { return mint(*this) += mint(1);}
  mint operator--() const { return mint(*this) -= mint(1);}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int k;cin >> k;
  if(k%2==0 or k%5==0) {
    cout << -1 << endl;
    return 0;
  };

  mod = k;

  mint ten = 10;
  mint a = 7;
  mint now = a;
  orep(i,2*k-1) {
    if(now.x % k == 0) {
      cout << i << endl;
      return 0;
    }
    a *= ten;
    now += a;
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3600
import math
from collections import deque
N,D,A = map(int,input().split())
monsters = sorted([ list(map(int,input().split())) for _ in range(N) ])
monsters = [ [x, math.ceil(h/A)] for x,h in monsters ]
# print(monsters)
que = deque()
cur = 0
ans = 0
for x,h in monsters:
  while que and x > que[0][0]:
    _,n = que.popleft()
    cur -= n

  need = max(0, h-cur)
  ans += need
  cur += need

  if h:
    # 対象のモンスターを最も左端にいることを想定
    que.append([x+2*D, need])

print(ans)

Measured memory_bytes: 144884
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1'000'000'007;

int main() {

    double R;
    cin >> R;
    cout << setprecision(20) << fixed << 2 * R * acos(-1) << endl;

}

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

int main() {
 int N, R;
 cin >> N >> R;
  
  if (1 <= N && N <= 9) {
    cout << R + 100 * (10 - N) << endl;
  }
  else {
    cout << R << endl;
  }
}


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

const int N=1005;
const int MOD=1e9+7;
 

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

 
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/


int x;
cin>>x;
int y=x/500;
y=y*1000;
x=x%500;
int z=x/5;
cout<<y+z*5;
}

Measured memory_bytes: 256
let num_divs x =
  let rec f c i =
    if i > x then c
    else if x mod i = 0 then f (c+1) (i+1)
    else f c (i+1)
  in f 0 1
let () = Scanf.scanf "%d" @@ fun n ->
  Array.init n (fun i -> if (i+1) mod 2 = 1 && num_divs (i+1) = 8 then 1 else 0)
  |> Array.fold_left (+) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 2e3+5;
int dp[maxn][maxn][2];
int N,Z,W, A[maxn];

int dfs(const int i, const int j, const int k)
{
    if (i == N-1)
        return abs(A[N-1]-A[j]);
    int& ans = dp[i][j][k];
    if (-1 == ans) {
        ans = k ? inf : -inf;
        FOR(x,i,N-1) {
            const int res = dfs(x+1,x,k^1);
            if (k)
                ans = min(ans,res);
            else
                ans = max(ans,res);
        }
        if (k)
            ans = min(ans, abs(A[N-1]-A[j]));
        else
            ans = max(ans, abs(A[N-1]-A[j]));
    }
    return ans;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N >> Z >> W) {
        memset(dp,-1,sizeof(dp));
        int i = 0;
        for (; i < N; i++)
            cin >> A[i];
        A[i++] = Z; A[i++] = W;
        const int ans = dfs(0,i-1,0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 31872
#include <stdio.h>

int solve(int,int);
//int makeCombination();
//int rec(int);

int A[2000];  
int n;

int main(){

  int mi[2000];
  int q;
 
  int i;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
    
    if( solve(0, mi[i]) ) printf("yes\n");
    else   printf("no\n");
  }

  return 0;

}
	
int solve(int i, int m){

  if(m == 0) return 1;
  if(i >= n) return 0;

  int res = solve(i+1,m) || solve(i+1,m-A[i]);

  return res;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
const ll mod=1000000007;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  string s;
  rep(i,c-a)
  s+='R';
  rep(i,d-b)
  s+='U';
  rep(i,c-a)
  s+='L';
  rep(i,d-b+1)
  s+='D';

  rep(i,c-a+1)
  s+='R';
  rep(i,d-b+1)
  s+='U';
  s+='L';s+='U';
  rep(i,c-a+1)
  s+='L';
  rep(i,d-b+1)
  s+='D';
  s+='R';

  // int ans=(c-a+d-b)*2+((d-b)+2+(c-a)+2)*2;
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

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

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

int main() {
  long long A, B;
  cin >> A >> B;
  cout << lcm(A,B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;


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

    //compress
    vector<int> hoge;
    rep(i,n) hoge.push_back(a[i]);
    sort(hoge.begin(), hoge.end());
    for (int i = 0; i < n; ++i) {
        int it = lower_bound(hoge.begin(), hoge.end(), a[i]) - hoge.begin();
        a[i] = it;
    }

    int res = 0;
    rep(i,n) {
        if(a[i] & 1) {
            res += (a[i] + i) % 2;//if(i%2 != a[i]%2)
        }
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
  int h, w;
  cin >> h >> w;
  char m[h][w];

  rep(i, h) rep(j, w) cin >> m[i][j];
  rep(i, h) rep(j, w) {
    int cnt = 0;
    char cntc;
    if (m[i][j] == '.') {
      rep(k, 8) if (m[i + dy[k]][j + dx[k]] == '#' && i + dy[k] >= 0 &&
                    i + dy[k] < h && j + dx[k] >= 0 && j + dx[k] < w) cnt++;
      string s = to_string(cnt);
      m[i][j] = s[0];
    }
  }

  rep(i, h) {
    rep(j, w) { cout << m[i][j]; }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())

a = (n-k+2)*(((k+n+1)*(n+1))+2)//2
b = (((n+1)*(n+2)))*(2*n+3)//6
c = (((k-1)*k))*(2*k-1)//6

print((a-b+c)%(10**9+7))

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
read(a);
read(b);
if(a>b){
    cout<<"No"<<endl;
}
else{
    cout<<"Yes"<<endl;
}
    
    
    


   

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

vector<ll> v;

void dfs(string s){
    ll lun=stoll(s);
    if(lun<=3234566667){
        v.push_back(stoll(s));
        rep(i,10){
            int x=s.back()-'0';
            if(abs(x-i)>1) continue;
            char c=char('0'+i);
            dfs(s+c);
        }
    }
    
}

int main(){
    dfs("1");
    dfs("2");
    dfs("3");
    dfs("4");
    dfs("5");
    dfs("6");
    dfs("7");
    dfs("8");
    dfs("9");

    sort(all(v));
    int k;
    cin>>k;
    //rep(i,k) cout<<v[i]<<" ";
    //cout<<endl;
    cout<<v[k-1]<<endl;
}

Measured memory_bytes: 4140
#include<bits/stdc++.h>
#include <math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    int n,d,ans=0,i,j,k,buf;
    cin>>n>>d;
    double x[n][d];
    rep(i,0,n){
        rep(j,0,d)cin>>x[i][j];
    }
    rep(i,0,n-1){
        rep(j,i+1,n){
            buf=0;
            rep(k,0,d) buf+=pow(x[i][k]-x[j][k],2);
            double num=pow(buf,0.5);
            if(ceil(num)==floor(num))ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512