akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int dp[100005];
int vis[100005];
vector<int> v[100005];
int dfs(int ver)
{
	vis[ver]=1;
	for(int i=0;i<v[ver].size();i++)
	{
		if(vis[v[ver][i]]==0)
			dfs(v[ver][i]);
dp[ver]=max(dp[ver],dp[v[ver][i]]+1);
	}
	return dp[ver];
}


 
int main()
{
	ll n,m;
	cin>>n>>m;
	char a[n][m];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	}
	int dp[n][m];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<n;i++)
	{
		if(a[i][0]=='#')
			dp[i][0]=0;
		else
			dp[i][0]=dp[i-1][0];
	}
	for(int i=1;i<m;i++)
	{
		if(a[0][i]=='#')
			dp[0][i]=0;
		else
			dp[0][i]=dp[0][i-1];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(a[i][j]=='#')
				dp[i][j]=0;
			else
				dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
		}
	}
	cout<<dp[n-1][m-1];
	

	
	
	
	
 
	return 0;
}

Measured memory_bytes: 7424
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 300111;
int n;
ll L, L2, a[maxn], b[maxn], ans;
int ty[maxn]; //0 .  1 <-  2 ->  3 o
vector<int> v[4];
int main()
{
	getii(n, L);
	L2 = L+L;
	for (int i=1; i<=n; i++) geti(a[i]);
	for (int i=1; i<=n; i++) geti(b[i]);
	for (int i=1; i<=n; i++)
	{
		ll K = b[i]/L2;
		b[i] %= L2;
		ans += K*2;
	}
	for (int i=1; i<=n; i++)
	{
		ll A = (a[i])*2;
		ll B = (L-a[i])*2;
		if (b[i]==0)
		{
			ty[i] = 0;
		}
		else if (b[i]<=A&&b[i]<=B)
		{
			ty[i] = 3;
			ans++;
		}
		else if (b[i]>min(A, B)&&b[i]<=max(A, B))
		{
			if (A<B) ty[i] = 1;
			else ty[i] = 2;
			ans++;
		}
		else if (b[i]>A&&b[i]>B)
		{
			ty[i] = 0;
			ans += 2;
		}
	}	
	if (ty[n]==1||ty[n]==3)
	{
		n--;
		ans--;
	}
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i=1; i<=n; i++)
	{
		if (ty[i]==0) continue;
		if (ty[i]==1)
		{
			if (v[2].size()>0) v[2].pop_back();
			else if (v[3].size()>0) v[3].pop_back();
			else v[1].PB(i);
		}
		else if (ty[i]==2)
		{
			v[2].PB(i);
		}
		else if (ty[i]==3)
		{
			v[3].PB(i);
		}
	}
	while (v[3].size())
	{
		int x = v[3].back();
		while (v[2].size()&&v[2].back()>x) v[2].pop_back(), ans++;
		if (v[2].size()>0)
		{
			v[3].pop_back();
			v[2].pop_back();
		}
		else break;
	}
	cnt1 = v[1].size(); cnt2 = v[2].size(); cnt3 = v[3].size();
//	cerr<<"cnt1="<<cnt1<<" cnt2="<<cnt2<<" cnt3="<<cnt3<<endl;
	ans += cnt1+cnt2+cnt3%2+2;
	assert(ans%2==0);
	cout<<ans*L<<endl;
	return 0;
}

Measured memory_bytes: 8436
#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)

int main() {
  
  int X,Y; cin >> X >> Y;

  REP(i,1000)REP(j,1000){
    if(i+j == X){
      if(2*i + 4*j == Y){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
 cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>

int main(void) {
  int n, i, p[10000], d1[10000], d2[10000], sum[10000], max, maxat;

  while (1) {
    scanf("%d", &n);
    if (n == 0) break;

    for (i = 0; i < n; i++) {
      scanf("%d%d%d", &p[i], &d1[i], &d2[i]);
      sum[i] = d1[i] + d2[i];
    }

    max = sum[0];
    maxat = 0;
    for (i = 1; i < n; i++) {
      if (sum[i] > max) {
	max = sum[i];
	maxat = i;
      }
    }

    printf("%d %d\n", p[maxat], sum[maxat]);
  }
  return 0;
}

Measured memory_bytes: 756
#include <bits/stdc++.h>
  
using namespace std;
  
bool flg;
  
void init(char field[8][8],bool can[8][8]){
  flg = false;
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      field[i][j] = '.';
      can[i][j] = true;
    }
  }
}
  
bool inField(int y,int x){
  return 0 <= y && y < 8 && 0 <= x && x < 8;
}
  
void putQ(int r,int c,bool can[8][8]){
  const int dx[4] = {-1,1,1,-1};
  const int dy[4] = {-1,-1,1,1};
  for(int i = 0 ; i < 8 ; i++){
    can[r][i] = can[i][c] = false;
  }
  for(int i = 0 ; i < 4 ; i++){
    int x = c, y = r;
    while(inField(y,x)){
      can[y][x] = false;
      x += dx[i]; y += dy[i];
    }
  }
}
  
void print(char field[8][8]){
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      cout << field[i][j];
    }
    cout << endl;
  }
}
  
void copy(bool a[8][8],bool b[8][8]){
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      a[i][j] = b[i][j];
    }
  }
}
  
void solve(int now,int S,bool can[8][8],char field[8][8]){
  if(now == 8){
    print(field);
    flg = true;
    return;
  }
  if((S >> now) & 1){
    solve(now+1,S,can,field);
  }else{
    bool tmp[8][8];
    for(int i = 0 ; i < 8 ; i++){
      if(can[now][i]){
    copy(tmp,can);
    field[now][i] = 'Q';
    putQ(now,i,can);
    solve(now+1,S,can,field);
    if(flg) return;
    copy(can,tmp);
    field[now][i] = '.';
      }
    }
  }
}
  
int main(){
  int N,r,c,S = 0;
  bool can[8][8];
  char field[8][8];
  
  init(field,can);
  
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> r >> c;
    S |= 1<<r;
    field[r][c] = 'Q';
    putQ(r,c,can);
  }
  solve(0,S,can,field);
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    map<int,int>maps;
	while(n%2==0){
		maps[2]++;
	   	n/=2;
	}
	for(int i=3;i*i<=n;i++){
	   	while(n%i==0){
	   		maps[i]++;
	   		n/=i;
	   	}
	}
	if(n>1)
	   	maps[n]++;
	int ans = 0;
	for(auto s : maps){
		int a = s.second;
		if(a == 1){
			ans++;
		}
		else{
			int ind = 1;
			f(i,1,500){
				if(i*(i+1) > 2*a){
					break;
				}
				else{
					ind = i;
				}
			}
			ans += ind;
		}
	}
	cout << ans << "\n";
    return 0;
}
 

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

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

typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;

signed main(){
	int n,m;
	cin>>n>>m;
	vector<PII> pai(n);
	for (int i = 0; i < n; ++i){
		cin>>pai[i].first>>pai[i].second;
	}
 
	sort(all(pai));
	unsigned long ans=0,buy=0;
	for (int i = 0; i < n; ++i){
		while(pai[i].second){
			ans+=pai[i].first;
			pai[i].second--;
			buy++;
			if(buy==m){
				cout<<ans<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 1024
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb push_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

const long long llinf = 1145141919810931LL;

struct edge{
  int to;
  int cost;
};

int N;
vector<edge> graph[100000];
int d[100000];

void bfs(){
  REP(i, N) d[i] = llinf;
  d[0] = 0;
  queue<int> que; que.push(0);
  while(!que.empty()){
    int pos = que.front(); que.pop();
    REP(i, graph[pos].size()){
      edge e = graph[pos][i];
      if(d[e.to] == llinf){
        d[e.to] = d[pos] + e.cost;
        que.push(e.to);
      }
    }
  }
}

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

  cin >> N;
  int a, b, c;
  REP(i, N-1){
    cin >> a >> b >> c;
    graph[a-1].pb({b-1, c});
    graph[b-1].pb({a-1, c});
  }
  bfs();
  REP(i, N){
    if(d[i] % 2 == 0) cout << 0 << endl;
    else cout << 1 << endl;
  }
}

Measured memory_bytes: 8704
def main():
    N, M = map( int, input().split())
    S = [ int(s) for s in input()][::-1]
    ANS = []
    t = 0
    while t < N:
        for i in range( min(M, N-t),0,-1):
            if S[t+i] == 0:
                ANS.append(i)
                t += i
                break
        else:
            print(-1)
            return
    if sum(ANS) == N:
        print( " ".join( map( str,ANS[::-1])))
    else:
        print(-1)
                

if __name__ == '__main__':
    main()


Measured memory_bytes: 11656
#include <stdio.h>

int main(void)
{
	int n, i, tmp;
	long long sum = 0;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &tmp);
		sum += tmp;
	}
	printf("%d\n", sum / n);
	
	return (0);
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
  ll N, K;
  cin >> N >> K;
  
  vector<ll> p(N);
  REP(i, N) { 
      cin >> p[i];
  }
  sort(ALL(p));
  ll ans = 0;
  REP(i, K) ans += p[i];
  PRINT(ans);
  return 0;
} 


Measured memory_bytes: 3604
#include<stdio.h>
int N=100;

int min(int a,int b){return a<b?a:b;}

int main(){
  int i,j,n,k,l,p[N],m[N][N];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=0;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = (1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j] = min(m[i][j],m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}



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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	long long a[n];
	long long b[n+1] = {};
	for(int i=0;i<n;i++){
		cin >> a[i];
		b[a[i]]++;
	}
	// keisan
	long long sum=0;
	for(int i=0;i<n+1;i++){
		if(b[i] > 1){
			sum += b[i]*(b[i] - 1)/2;
		}
	}
	for(int i=0;i<n;i++){
		long long outsum = sum;
		if(b[a[i]] < 2){
			cout << sum << endl;
		}else{
			outsum = sum - (b[a[i]] - 1);
			cout << outsum << endl;
		}
	}
	// syutsuryoku
}

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

vector<int> co;

int main(){
    for(int i=1;i<=17;i++){
        co.push_back(i*i);
    }
    int dp[310]={};
    dp[0]=1;
    for(int i=0;i<17;i++){
        for(int j=0;j<=300;j++){
            if(j+co[i]>300) break;
            dp[j+co[i]] += dp[j];
        }
    }
    int n;
    while(cin>>n,n){
        cout << dp[n] << endl;
    }
    return 0;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  
  for(int i = a; i <= b; ++i){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3560
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=list(map(int,readline().split()))

    s=bin(max(k,max(a)))[2:]
    l=len(s)
    cnt_one=[0]*l

    for i in range(n):
        b=a[i]
        for j in range(l):
            if b&1==1:
                cnt_one[j]+=1
            b>>=1

    cnt_one.reverse()
    k_bin=bin(k)[2:]
    dp=[[-float("inf"),-float("inf")] for _ in range(l+1)]
    dp[0][0]=0
    for i in range(l):
        j=l-i
        if len(k_bin)<j:
            dp[i+1][0]=dp[i][0]+cnt_one[i]*2**(j-1)
        else:
            if k_bin[len(k_bin)-j]=="1":
                dp[i+1][0]=dp[i][0]+(n-cnt_one[i])*2**(j-1)
                if cnt_one[i]>=n//2:  #1の数が半数以上
                    dp[i+1][1]=max(dp[i][0]+cnt_one[i]*2**(j-1),dp[i][1]+cnt_one[i]*2**(j-1))
                else:  #1の数が半数未満
                    dp[i+1][1]=max(dp[i][0]+cnt_one[i]*2**(j-1),dp[i][1]+(n-cnt_one[i])*2**(j-1))
            else:
                dp[i+1][0]=dp[i][0]+cnt_one[i]*2**(j-1)
                if cnt_one[i]>=(n+1)//2:  #1の数が半数以上
                    dp[i+1][1]=dp[i][1]+cnt_one[i]*2**(j-1)
                else:  #1の数が半数未満
                    dp[i+1][1]=dp[i][1]+(n-cnt_one[i])*2**(j-1)

    print(max(dp[l][0],dp[l][1]))

if __name__=="__main__":
    main()

Measured memory_bytes: 14748
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

int main(){
	IOS
	int n,k;
	int our[3];
	cin>>n>>k;
	string t;
	fo(i,3) cin>>our[i];
	cin>>t;
	
	std::vector<int> visited(n,0);
	int ans=0;
	int a,b,c,na,nb,nc;
	fo(i,n){
		if(visited[i]) continue;
	    a=0,b=0,c=0;
		int index=i;
		while(index<n){
			visited[index]=1;
		    na=0,nb=0,nc=0;
			if(t[index]=='r'){
				na=max(b,c);
				nb=max(a,c);
				nc=max(a+our[2],b+our[2]);
			}
			if(t[index]=='s'){
				nc=max(a,b);
				nb=max(a,c);
				na=max(b+our[0],c+our[0]);
			}
			if(t[index]=='p'){
				na=max(b,c);
				nc=max(a,b);
				nb=max(a+our[1],c+our[1]);
			}
			a=na,b=nb,c=nc;
			index=index+k;



		}
		ans=ans+max(a,max(b,c));


	}
	cout<<ans<<endl;


	

}

Measured memory_bytes: 848
#include <cstdio>
#include <vector>
#include <queue>

#define mp std::make_pair

typedef std::pair<int,int> Pair;
typedef std::pair<double,Pair> Q;

const double INF = 1e20;

int N, M, P, A, B;
int T[8];
std::vector<Pair> es[31];
double d[31][1<<8];
std::priority_queue<Q, std::vector<Q>, std::greater<Q>> q;

int main(){
    while(scanf("%d %d %d %d %d", &N, &M, &P, &A, &B), N || M || P || A || B){
        for(int i=1;i<=M;i++){
            es[i].clear();
        }
        
        for(int i=0;i<N;i++){
            scanf("%d", T+i);
        }
        for(int i=0;i<P;i++){
            int x, y, z;
            scanf("%d %d %d", &x, &y, &z);

            es[x].push_back(mp(y, z));
            es[y].push_back(mp(x, z));
        }

        for(int i=1;i<=M;i++){
            for(int j=0;j<1<<N;j++){
                d[i][j] = INF;
            }
        }
        d[A][0] = 0.0;
        q.push(mp(0.0, mp(A, 0)));

        while(!q.empty()){
            Q q_ = q.top(); q.pop();
            double cost = q_.first;
            int u = q_.second.first, horse = q_.second.second;

            if(cost > d[u][horse]){continue;}

            for(auto e : es[u]){
                for(int i=0;i<N;i++){
                    if(horse >> i & 1){continue;}

                    int n_horse = horse | (1 << i);
                    if(d[e.first][n_horse] > d[u][horse] + 1. * e.second / T[i]){
                        d[e.first][n_horse] = d[u][horse] + 1. * e.second / T[i];
                        q.push(mp(d[e.first][n_horse], mp(e.first, n_horse)));
                    }
                }
            }
        }

        double res = 1e20;
        for(int i=0;i<1<<N;i++){
            res = std::min(res, d[B][i]);
        }

        if(res < INF){
            printf("%.6f\n", res);
        }else{
            puts("Impossible");
        }
    }
}

Measured memory_bytes: 2240
/***************************************************************
	File name: D.cpp
	Author: ljfcnyali
	Create time: 2019年08月04日 星期日 19时58分09秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

const int maxn = 100010;

char s[maxn];
int a[maxn], R[maxn], L[maxn], n, ans[maxn];

int main()
{
    scanf("%s", s); n = str(s);
    REP(i, 0, n - 1) if ( s[i] == 'L' ) a[i + 1] = 1; else a[i + 1] = 2;
    REP(i, 2, n) if ( a[i - 1] == 2 && a[i] == 1 ) L[i] = i; else L[i] = L[i - 1];
    for ( int i = n - 1; i >= 1; -- i ) if ( a[i + 1] == 1 && a[i] == 2 ) R[i] = i; else R[i] = R[i + 1];
    REP(i, 1, n)
    {
        int x;
        if ( a[i] == 1 ) { x = i - L[i]; if ( x & 1 ) ++ ans[L[i] - 1]; else ++ ans[L[i]]; }
        else { x = R[i] - i; if ( x & 1 ) ++ ans[R[i] + 1]; else ++ ans[R[i]]; }
    }
    REP(i, 1, n) printf("%d ", ans[i]); puts("");
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
#include <map>
#include <queue>

using namespace std;
const int N = 4;
const int N2 = 16;

static const int dx[] = {0, -1, 0, 1};
static const int dy[] = {1, 0, -1, 0};
static const char dir[] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

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

struct Puzzle{
    int f[N2], space, MD;
    int cost;

    bool operator<(const Puzzle &p) const{
        rep(i, N2){
            if(f[i] == p.f[i]) continue;
            return f[i] < p.f[i];
        }
        return false;
    }
};

struct State{
    Puzzle puzzle;
    int estimated;
    bool operator<(const State &s) const{
        return estimated > s.estimated;
    }
};

int getAllMD(Puzzle pz)
{
    int sum = 0;
    rep(i, N2){
        if(pz.f[i] == N2) continue;
        sum += MDT[i][pz.f[i] - 1];
    }
    return sum;
}

int astar(Puzzle s)
{
    priority_queue<State> PQ;
    s.MD = getAllMD(s);
    s.cost = 0;
    map<Puzzle, bool> V;
    Puzzle u, v;
    State initial;
    initial.puzzle = s;
    initial.estimated = getAllMD(s);
    PQ.push(initial);

    while(!PQ.empty())
    {
        State st = PQ.top();  PQ.pop();
        u = st.puzzle;

        if(u.MD == 0) return u.cost;
        V[u] = true;

        int sx = u.space / N;
        int sy = u.space % N;

        for(int r=0;r<4;++r){
            int tx = sx + dx[r];
            int ty = sy + dy[r];

            if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;

            v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
            v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];

            swap(v.f[sx * N + sy], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if(! V[v])
            {
                v.cost++;
                State news;
                news.puzzle = v;
                news.estimated = v.cost + v.MD;
                PQ.push(news);
            }
        }
    }
    return -1;
}

int main()
{
    rep(i, N2)
        rep(j, N2)
            MDT[i][j] = abs(i % N - j % N) + abs(i / N - j / N);

    Puzzle in;

    rep(i, N2){
        cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    cout << astar(in) << endl;
}



Measured memory_bytes: 257604
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,l1,l2;
string s,t,ans="}",cur,now;
int main()
{
	cin>>n>>s>>t;
	if (s+t<t+s) swap(s,t);
	l1=s.length();l2=t.length();
	for (i=0;i*l1<=n;i++)
	{
		if ((n-i*l1)%l2==0)
		{
			while (now.length()+i*l1<n) now+=t;
			now+=cur;
			ans=min(ans,now);
			cout<<ans;
			return 0; 
		}
		cur+=s;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1544
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
int main(){
  string s;
  cin >> s;
  ll cnt = 0;
  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == 'T' && cnt > 0) cnt--;
    if (s[i] == 'S') cnt++;
  }
  cout << 2 * cnt << endl;
}

Measured memory_bytes: 640
def solve():
    N, M = list(map(int, input().split()))
    number = [-1] * N
    for i in range(M):
        s, c = list(map(int, input().split()))
        s = s - 1
        if number[s] == -1 or number[s] == c:
            number[s] = c
        else:
            return -1

    if N != 1 and number[0] == 0:
        return -1

    if number[0] == -1:
        if N == 1:
            number[0] = 0
        else:
            number[0] = 1

    for i in range(1, N):
        if number[i] == -1:
            number[i] = 0

    return int(''.join(map(str, number)))


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 38256
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair <int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<63)-1;
const int N = 1e5+5;

int n;
vector<int>E[N];
int col[N];

void dfs(int u, int fa){
    for(auto v : E[u]){
        if(v == fa)continue;
        dfs(v, u);
    }
    if(!col[u] && !col[fa])col[u] = col[fa] = 1;
}

int  main(){
    scanf("%d", &n);
    for(int i=1; i<n; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        E[u].pb(v);
        E[v].pb(u);
    }
    col[0] = 1;
    dfs(1, 0);
    int fg = 0;
    for(int i=1; i<=n; i++)if(!col[i])fg = 1;
    puts(fg?"First":"Second");
    return 0;
}


// lower_bound()
// __builtin_popcount()
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// const double eps=1e-12;
// #pragma comment(linker,"/STACK:102400000,102400000")


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

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n){
		cin >> a[i];
	}
	rep(i,n){
		if(i>0) a[i] += a[i-1];
	}
	
	ll ans = abs(a[0]-(a[n-1]-a[0]));
	
	rep(i,n-1){
		ans = min(ans, abs(a[i]-(a[n-1]-a[i])));
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
function main(input) {
    'use strict'
    const N = parseInt(input.split(' ')[0], 10);
    const A = parseInt(input.split(' ')[1], 10);
    const B = parseInt(input.split(' ')[2], 10);

    let total = 0;
    for (let i = 1; i <= N; i++) {
        let ketaTotal = 0;
        for (let j = 0; j < String(i).length; j++) {
            ketaTotal += parseInt(String(i).substr(j,1),10)
        }

        if(ketaTotal >= A && ketaTotal <= B) {
            total += i;
        }
    }
  console.log(total);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 8360
N, Y = map(int, input().split())
ans_a = -1
ans_b = -1
ans_c = -1
for a in range(N+1):
  for b in range(N - a + 1):
    c = N - a - b
    if Y == 10000*a + 5000*b + 1000*c:
      ans_a = a
      ans_b = b
      ans_c = c
print(ans_a, ans_b, ans_c)

Measured memory_bytes: 3060
#include <iostream>
#include<string>
//#include <cstdio>
//#include <sstream>
using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define int long long

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

const int MAXN = 200200, MAXS = 2020;
const int mod = 1e9 + 7;

int qpow (int x, int y) {
    int ret = 1;
    while (y) {
        if (y & 1) ret = ret * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ret;
}
int inv (int x) { return qpow(x, mod - 2); }

int fac[MAXS << 3] = {};
int binom (int x, int y) { return fac[x] * inv(fac[y]) % mod * inv(fac[x - y]) % mod; }

int n;
int a[MAXN], b[MAXN];

int dp[MAXS << 1][MAXS << 1];

signed main () {
    n = read();
    int i, j;
    fac[0] = 1;
    for (i = 1; i <= n; i++) a[i] = read(), b[i] = read(), dp[MAXS - a[i]][MAXS - b[i]]++;
    for (i = 1; i <= (MAXS << 3); i++) fac[i] = fac[i - 1] * i % mod;
    for (i = 1; i <= MAXS + 2000; i++) for (j = 1; j <= MAXS + 2000; j++) 
        dp[i][j] += dp[i - 1][j] + dp[i][j - 1], dp[i][j] %= mod;
    int ans = 0;
    for (i = 1; i <= n; i++) {
        ans = (ans + dp[MAXS + a[i]][MAXS + b[i]]) % mod;
        ans = (ans - binom((a[i] + b[i]) * 2, a[i] * 2) + mod) % mod;
    }
    ans = ans * 500000004 % mod;
    printf("%lld\n", ans);
    return 0;
}

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

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

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

  int maxv = a[n - 1];
  int halfv = 1e9;
  int halfk;
  for (int i = 0; i < n - 1; i++) {
    ll tmp = abs(maxv - a[i] * 2);
    if(tmp < halfv) {
      halfv = tmp;
      halfk = i;
    }
  }

  cout << maxv << " " << a[halfk] << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ans = 0
temp = A[0]
for i in range(N) :
    if B[i] <= temp :
        ans += B[i]
        temp = A[i+1]
    else :
        ans += temp
        if B[i] - temp <= A[i+1] :
            ans += B[i] - temp
            temp = A[i+1] - (B[i] - temp)
        else :
            ans += A[i+1]
            temp = 0

print(ans)


Measured memory_bytes: 19376
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
using namespace std;

bool check(int m, int hit, int d, vector<string> amida){
	for(int i = d-1; i >= 0; i--){
		if(amida[i][hit-1] == '1'){
			hit--;
		}else if(amida[i][hit] == '1'){
			hit++;
		}
	}

	return hit == m;
}

int main(){
	int n, m, hit, d;
	bool b;

	while(cin >> n, n){
		cin >> m >> hit >> d;
		vector<string> amida(d);
		vector<int> mp(n+1);

		for(int i = 0; i < d; i++){
			cin >> amida[i];
			amida[i] = "0" + amida[i] + "0";
		}

		b = check(m, hit, d, amida);
		pair<int, int> add;
		add.first = 0;

		for(int i = 0; i < d && !b; i++){
			for(int j = 1; j < n && !b; j++){
				if(amida[i][j] == '0' && amida[i][j-1] == '0' && amida[i][j+1] == '0'){
					amida[i][j] = '1';
					b = check(m, hit, d, amida);
					if(b){
						add.first = i+1;
						add.second = j;
					}
					amida[i][j] = '0';
				}
			}			
		}

		if(b){
			if(add.first != 0){
				cout << add.first << ' ' << add.second << endl;
			}else{
				cout << '0' << endl; 
			}
		}else{
			cout << '1' << endl; 
		}

	}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,k,l,r;
  cin>>n>>k>>l>>r;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  Int h=20;
  if(n<=h){
    Int ans=0;
    for(Int b=0;b<(1<<n);b++){
      Int c=0,s=0;
      for(Int i=0;i<n;i++)
	if((b>>i)&1) c++,s+=a[i];
      if(c==k&&l<=s&&s<=r) ans++;
    }
    cout<<ans<<endl;
    return 0;
  }

  vector<vector<Int> > v(h+1);
  for(Int b=0;b<(1<<h);b++){
    Int c=0,s=0;
    for(Int i=0;i<n;i++)
      if((b>>i)&1) c++,s+=a[i];
    v[c].emplace_back(s);
  }
  for(Int i=0;i<=h;i++) sort(v[i].begin(),v[i].end());
  //cout<<"OK"<<endl;
  
  Int ans=0;
  for(Int b=0;b<(1<<(n-h));b++){
    Int c=0,s=0;
    for(Int i=0;i<(n-h);i++)
      if((b>>i)&1) c++,s+=a[h+i];
    if(c>k||k-c>h) continue;
    //cout<<c<<" "<<s<<":"<<k<<endl;
    auto latte=upper_bound(v[k-c].begin(),v[k-c].end(),r-s);
    auto malta=lower_bound(v[k-c].begin(),v[k-c].end(),l-s);
    ans+=latte-malta;
  }

  cout<<ans<<endl;
  return 0;
}



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

int main() {
    string S1, T;
    cin >> S1;
    cin >> T;
    string S;
    S = S1;
    bool hantei = true;
    vector<string> s;
    for (int i = 0; i < S.size() - T.size() + 1; i++)
    {
        S = S1;
        hantei = true;
       for (int j = 0; j < i; j++)
       {
           /* code */
          if (S[j] == '?')
          {
              /* code */
              S[j] = 'a';
          }
          
       }
       
       for (int k = 0; k < T.size(); k++)
       {
           /* code */
           if (S[i + k] == T[k])
           {
               /* code */
           }else if (S[i + k] != T[k] && S[i + k] != '?')
           {
               /* code */
                hantei = false;
                break;
           }
           
           else if (S[i + k] == '?')
           {
               /* code */
               S[i + k] = T[k]; 
           }
           
       }
       for (int l = T.size() + i; l < S.size(); l++)
       {
           if (S[l] == '?')
           {
               S[l] = 'a';
           }
           
       }
       
       if (hantei)
       {
          s.push_back(S);
       }
       
    }

    if(s.size() == 0) cout << "UNRESTORABLE" << endl;
    else { sort(s.begin(), s.end()); cout << s[0] << endl; }
    
    
    return 0;

}

Measured memory_bytes: 3620
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

//# include <ext/pb_ds/assoc_container.hpp>
//# include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	shuffle(permutation.begin(), permutation.end(), rng);



int main () {
	cin >> n;
	double x = n;
	x/=3;
	cout << fixed << setprecision(14) << x * x * x;
	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <bits/stdc++.h>
 
using namespace std;
 
 
 
int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long N;
    cin >> N;
    vector<long long> A(N), B(N), C(N);
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    sort(B.begin(), B.end());
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    sort(C.begin(), C.end());
    
    long long cases = 0;
    
     for (int i = 0; i < N; i++) {
        auto lowa = lower_bound(A.begin(), A.end(), B[i]);  //B[i]以上
        auto lowc = upper_bound(C.begin(), C.end(), B[i]);  //B[i]より大きい
        long long k = lowa - A.begin();
        long long m = C.end() - lowc;
        //cout << *lowa << " " << B[i] << " " << *lowc << endl;
        //cout << k << " " << m << endl;
        cases += k * m;
    }
    
    cout << cases << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 5548
#include <iostream>
#include <string>

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    int ans = 0;
    rep(i, N) {
        if(i > 0 && S[i] == 'L' && S[i - 1] == 'L') {
            ans++;
        } else if(i < N - 1 && S[i] == 'R' && S[i + 1] == 'R') {
            ans++;
        }
    }
    int sw = 0;
    rep(i, N - 1) {
        if(S[i] != S[i + 1]) {
            sw++;
        }
    }

    cout << ans + min(K * 2, sw) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
	int n,k;
	cin >> n >> k;
	int h[n + k + 1];
	REP(i,n){
		cin >> h[i];
	}
	vector<int> dp(n + k + 1, INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= k; j++){
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

set<char> countStr(string s) {
    set<char> a;
    rep(i, s.size()) { a.insert(s[i]); }
    return a;
}

int main() {
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    for (int i = 1; i < n; i++) {
        int match = 0;
        set<char> L = countStr(s.substr(0, i));
        set<char> R = countStr(s.substr(i, n));
        for (auto l : L) {
            for (auto r : R) {
                if (l == r) match++;
            }
        }
        ans = max(ans, match);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N= int(input())
red=[list(map(int,input().split())) for i in range(N)]
red.sort()
blue=[list(map(int,input().split())) for i in range(N)]
blue.sort()
ans=0
from operator import itemgetter
for i in range(N):
   x,y=blue[i]
   l=[]
   for j in range(N):
      try:
         if x>red[j][0] and y>red[j][1]:
            l.append(red[j])
      except IndexError:
         break
   try:
      l.sort(key=itemgetter(1),reverse=True)
      red.remove(l[0])
   except IndexError:
      pass
print(N-len(red))

Measured memory_bytes: 9252
#include<iostream>
using namespace std;
int n,a[100001],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)   cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i)
		{
			ans++;
			i++;
		}
	}
	cout<<ans;
	return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long D, std::vector<long long> X, std::vector<long long> Y){
    int answer = 0;
    rep(i,0,N) {
        if (X[i] * X[i] + Y[i] * Y[i] <= D * D) answer++;
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<long long> X(N);
    std::vector<long long> Y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
    }
    solve(N, D, std::move(X), std::move(Y));
    return 0;
}


Measured memory_bytes: 6448
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int N;
	cin >> N;
	vector<vector<int> > A(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> A[i][j];
		}
	}
	vector<int> c(1 << N);
	for (int i = 1; i < 1 << N; ++i) {
		c[i] = c[i >> 1] + (i & 1);
	}
	vector<modulo> dp(1 << N);
	dp[0] = 1;
	for (int i = 1; i < 1 << N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (((i >> j) & 1) && A[c[i] - 1][j] == 1) {
				dp[i] += dp[i - (1 << j)];
			}
		}
	}
	cout << dp[(1 << N) - 1].get() << '\n';
	return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>

int main(void)
{
	int b, adm = 0;

	scanf("%d", &b); adm += (b ? 1 : 0);
	scanf("%d", &b); adm += (b ? 1 : 0);
	scanf("%d", &b); adm += (b ? 2 : 0);

	if (adm == 2) puts("Open");
	else puts("Close");

	return 0;
}

Measured memory_bytes: 584
#include <iostream>

using namespace std;

const int max_lim = 50001;
bool prime[max_lim];

void init()
{
    for (int i = 0; i < max_lim; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < max_lim; i++) 
        for (int j = 2 * i; j < max_lim; j += i)
            prime[j] = false;
}

int main()
{
    int n;

    init();
    while (cin >> n, n) {
        int ans = 0;
        for (int i = 2; 2 * i <= n; i++) 
            if (prime[i] && prime[n - i] && n - i > 0) 
                ans++;
        cout << ans << endl;
    }

    return 0;
}

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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

ll N,ct,ans,pos;

ll M(int pos) {
	return (pos+1)/2;
}

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

	ans=1;
	cin >> N;
	for (int i=0;i<N;i++) {
		ct++;
		cin >> pos;
		while (M(pos)<ct) {
			ans=ans*ct%mod;
			ct--;
		}
	}

	while (ct) {
		ans=ans*ct%mod;
		ct--;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final String YES = "Yes";
	private static final String NO = "No";

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		int[] a = new int[N];
		int zeroCnt = 0;
		int oneCnt = 0;
		int twoCnt = 0;

		for (int i = 0; i < N; i++) {
			int ai = sc.nextInt();
			a[i] = ai;
			if (ai % 4 == 0) {
				twoCnt++;
			} else if (ai % 2 == 0) {
				oneCnt++;
			} else {
				zeroCnt++;
			}
		}
		boolean ok;
		if (zeroCnt > 0) {
			ok = fourAdjacent(0, zeroCnt - 1, oneCnt, twoCnt);
		} else if (oneCnt > 0) {
			ok = fourAdjacent(1, zeroCnt, oneCnt - 1, twoCnt);
		} else {
			ok = fourAdjacent(2, zeroCnt, oneCnt, twoCnt-1);
		}
		if(ok) {
			System.out.println(YES);
		}
		else {
			System.out.println(NO);
		}
		sc.close();
	}

	private boolean fourAdjacent(int last, int zero, int one, int two) {
		if (zero == 0 && one == 0 && two == 0) {
			return true;
		}
		switch (last) {
		case 0:
			if (two > 0) {
				return fourAdjacent(2, zero, one, two - 1);
			} else {
				return false;
			}
		case 1:
			if (one > 0) {
				return fourAdjacent(1, zero, one - 1, two);
			} else if (two > 0) {
				return fourAdjacent(2, zero, one, two - 1);
			} else {
				return false;
			}
		case 2:
			if (zero > 0) {
				return fourAdjacent(0, zero - 1, one, two);
			} else if (one > 0) {
				return fourAdjacent(1, zero, one - 1, two);
			} else if (two > 0) {
				return fourAdjacent(2, zero, one, two - 1);
			} else {
				throw new RuntimeException("Not Reachable");
			}
		}
		return false;
	}

}


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

int main() {
  string a, b;
  cin >> a >> b;
  if (a.length() > b.length())
    cout << "GREATER" << endl;
  else if (a.length() < b.length())
    cout << "LESS" << endl;
  else if (a > b)
    cout << "GREATER" << endl;
  else if (a < b)
    cout << "LESS" << endl;
  else if (a == b)
    cout << "EQUAL" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;

bool num[1000001];
int coun[1000001];

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

	bool is_pairwise = true;
	bool is_setwise = true;

	for (int i = 0; i < n; i++){
		int tmp = a[i];
		for (int k = 2; k*k <= tmp; k++){
			if (tmp % k == 0){
				if (num[k] == true) is_pairwise = false;
				num[k] = true;
				coun[k]++;
				while(tmp % k == 0){
					tmp /= k;
				}
			}
		}
		if (tmp != 1){
			if (num[tmp] == true) is_pairwise = false;
			else is_setwise = true;
			num[tmp] = true;
			coun[tmp]++;
		}
	}

	for (int i = 1; i <= 1000000; i++){
		if (coun[i] == n) is_setwise = false;
	}
	if (is_pairwise) cout << "pairwise coprime" << endl;
	else if (is_setwise) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
	return 0;
}



Measured memory_bytes: 11816
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> P;
int main(void)
{
	int n,i,a;
	P p[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d",&a);
		p[i].first=a;
		p[i].second=i+1;
	}
	sort(p,p+n);
	printf("%d",p[0].second);
	for(i=1;i<n;i++)	printf(" %d",p[i].second);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
"use strict";

var main = function main(input) {
  var N = parseInt(input.split(" ")[0]);
  var A = parseInt(input.split(" ")[1]);
  var B = parseInt(input.split(" ")[2]);
  var count = 0;

  for (var i = 1; i <= N; i++) {
    var sum = 0;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = i.toString().split("")[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var c = _step.value;
        sum += parseInt(c, 10);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    if (sum <= B && sum >= A) {
      count += i;
    }
  }

  console.log(count);
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 24080
n,k = map(int,input().split())
w=[]
v=[]
dp =[[0 for i in range(k+1)] for j in range(n+1)]

for i in range(n):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
for i in range(n):
    for sum_w in range(k+1):
        if sum_w - w[i] >=0:
            dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w - w[i]] + v[i])
        else:
            dp[i+1][sum_w]=dp[i][sum_w]

print(dp[-1][-1])

Measured memory_bytes: 171268